Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 570e9f0

Browse files
adeas31OpenModelica-Hudson
authored andcommitted
Option to filter the nested classes when dumping the class via listFile
Belonging to [master]: - #2950 - OpenModelica/OpenModelica-testsuite#1143
1 parent 04df807 commit 570e9f0

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Compiler/FrontEnd/Absyn.mo

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5582,6 +5582,52 @@ algorithm
55825582
end match;
55835583
end filterAnnotationItem;
55845584

5585+
public function filterNestedClasses
5586+
"Filter outs the nested classes from the class if any."
5587+
input Class cl;
5588+
output Class o;
5589+
algorithm
5590+
o := match cl
5591+
local
5592+
Ident name;
5593+
Boolean partialPrefix, finalPrefix, encapsulatedPrefix;
5594+
Restriction restriction;
5595+
list<String> typeVars;
5596+
list<NamedArg> classAttrs;
5597+
list<ClassPart> classParts;
5598+
list<Annotation> annotations;
5599+
Option<String> comment;
5600+
Info info;
5601+
case CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,restriction,PARTS(typeVars,classAttrs,classParts,annotations,comment),info)
5602+
equation
5603+
(classParts as _::_) = List.fold(listReverse(classParts),filterNestedClassesParts,{});
5604+
then CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,restriction,PARTS(typeVars,classAttrs,classParts,annotations,comment),info);
5605+
else cl;
5606+
end match;
5607+
end filterNestedClasses;
5608+
5609+
protected function filterNestedClassesParts
5610+
"Helper funciton for filterNestedClassesParts."
5611+
input ClassPart classPart;
5612+
input list<ClassPart> inClassParts;
5613+
output list<ClassPart> outClassPart;
5614+
algorithm
5615+
outClassPart := match (classPart, inClassParts)
5616+
local
5617+
list<ClassPart> classParts;
5618+
list<ElementItem> elts;
5619+
case (PUBLIC(elts), classParts)
5620+
equation
5621+
classPart.contents = List.filterOnFalse(elts, isElementItemClass);
5622+
then classPart::classParts;
5623+
case (PROTECTED(elts), classParts)
5624+
equation
5625+
classPart.contents = List.filterOnFalse(elts, isElementItemClass);
5626+
then classPart::classParts;
5627+
else classPart::inClassParts;
5628+
end match;
5629+
end filterNestedClassesParts;
5630+
55855631
public function getExternalDecl
55865632
"@author: adrpo
55875633
returns the EXTERNAL form parts if there is any.

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,7 @@ end list;
22932293

22942294
function listFile "Lists the contents of the file given by the class."
22952295
input TypeName class_;
2296+
input Boolean nestedClasses = true;
22962297
output String contents;
22972298
external "builtin";
22982299
annotation(Documentation(info="<html>

Compiler/Script/CevalScript.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ algorithm
781781

782782
case (cache,_,"list",_,_) then (cache,Values.STRING(""));
783783

784-
case (cache,_,"listFile",{Values.CODE(Absyn.C_TYPENAME(className))},_)
784+
case (cache,_,"listFile",{Values.CODE(Absyn.C_TYPENAME(className)),Values.BOOL(b)},_)
785785
equation
786786
path = match className
787787
case Absyn.FULLYQUALIFIED() then className.path;
@@ -790,6 +790,7 @@ algorithm
790790
// handle encryption
791791
Values.ENUM_LITERAL(index=access) = Interactive.checkAccessAnnotationAndEncryption(path, SymbolTable.getAbsyn());
792792
(absynClass as Absyn.CLASS(restriction=restriction, info=SOURCEINFO(fileName=str))) = Interactive.getPathedClassInProgram(className, SymbolTable.getAbsyn());
793+
absynClass = if b then absynClass else Absyn.filterNestedClasses(absynClass);
793794
/* If the class has Access.packageText annotation or higher
794795
* If the class has Access.nonPackageText annotation or higher and class is not a package
795796
*/

0 commit comments

Comments
 (0)