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

Commit e3d42ec

Browse files
perostOpenModelica-Hudson
authored andcommitted
Implement --showStructuralAnnotations flag.
Belonging to [master]: - #2897 - OpenModelica/OpenModelica-testsuite#1113
1 parent 547468f commit e3d42ec

6 files changed

Lines changed: 84 additions & 11 deletions

File tree

Compiler/FrontEnd/DAEDump.mo

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,18 @@ algorithm
748748
SCode.Mod ann_mod;
749749

750750
case (SOME(SCode.COMMENT(annotation_ = SOME(SCode.ANNOTATION(ann_mod)))), _, _)
751-
equation
752-
true = Config.showAnnotations();
753-
ann = inPrefix + "annotation" + SCodeDump.printModStr(ann_mod,SCodeDump.defaultOptions) + inSuffix;
751+
algorithm
752+
if Config.showAnnotations() then
753+
ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix;
754+
elseif Config.showStructuralAnnotations() then
755+
ann_mod := filterStructuralMods(ann_mod);
756+
757+
if not SCode.isEmptyMod(ann_mod) then
758+
ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix;
759+
end if;
760+
else
761+
ann := "";
762+
end if;
754763
then
755764
ann;
756765

@@ -759,6 +768,27 @@ algorithm
759768
end matchcontinue;
760769
end dumpAnnotationStr;
761770

771+
public function filterStructuralMods
772+
input output SCode.Mod mod;
773+
algorithm
774+
mod := SCode.filterSubMods(mod, filterStructuralMod);
775+
end filterStructuralMods;
776+
777+
public function filterStructuralMod
778+
input SCode.SubMod mod;
779+
output Boolean keep;
780+
algorithm
781+
keep := match mod.ident
782+
case "Evaluate" then true;
783+
case "Inline" then true;
784+
case "LateInline" then true;
785+
case "derivative" then true;
786+
case "inverse" then true;
787+
case "smoothOrder" then true;
788+
else false;
789+
end match;
790+
end filterStructuralMod;
791+
762792
public function dumpCommentAnnotationStr
763793
input Option<SCode.Comment> inComment;
764794
output String outString;

Compiler/FrontEnd/SCode.mo

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,30 @@ algorithm
656656
end match;
657657
end stripSubmod;
658658

659+
function filterSubMods
660+
"Removes submods from a modifier based on a filter function."
661+
input output Mod mod;
662+
input FilterFunc filter;
663+
664+
partial function FilterFunc
665+
input SubMod submod;
666+
output Boolean keep;
667+
end FilterFunc;
668+
algorithm
669+
mod := match mod
670+
case MOD()
671+
algorithm
672+
mod.subModLst := list(m for m guard filter(m) in mod.subModLst);
673+
then
674+
match mod
675+
case MOD(subModLst = {}, binding = NONE()) then NOMOD();
676+
else mod;
677+
end match;
678+
679+
else mod;
680+
end match;
681+
end filterSubMods;
682+
659683
public function getElementNamed
660684
"Return the Element with the name given as first argument from the Class."
661685
input Ident inIdent;

Compiler/Template/DAEDumpTV.mo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ package Config
130130
output Boolean outShowAnnotations;
131131
end showAnnotations;
132132

133+
function showStructuralAnnotations
134+
output Boolean outShowAnnotations;
135+
end showStructuralAnnotations;
136+
133137
function showStartOrigin
134138
output Boolean show;
135139
end showStartOrigin;
@@ -216,6 +220,10 @@ uniontype functionList
216220
end FUNCTION_LIST;
217221
end functionList;
218222

223+
function filterStructuralMods
224+
input SCode.Mod mod;
225+
output SCode.Mod outMod;
226+
end filterStructuralMods;
219227

220228
end DAEDump;
221229

Compiler/Template/DAEDumpTpl.tpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,19 +1032,19 @@ template dumpCompAnnotation(Option<SCode.Comment> comment)
10321032
end dumpCompAnnotation;
10331033

10341034
template dumpCommentAnnotation(Option<SCode.Comment> comment)
1035-
::=
1036-
if Config.showAnnotations() then
1037-
match comment
1038-
case SOME(cmt) then
1039-
dumpCommentAnnotationNoOpt(cmt)
1035+
::= match comment case SOME(cmt) then dumpCommentAnnotationNoOpt(cmt)
10401036
end dumpCommentAnnotation;
10411037

10421038
template dumpCommentAnnotationNoOpt(SCode.Comment comment)
10431039
::=
1044-
if Config.showAnnotations() then
10451040
match comment
10461041
case SCode.COMMENT(annotation_ = SOME(SCode.ANNOTATION(modification = ann_mod))) then
1047-
'annotation<%SCodeDumpTpl.dumpModifier(ann_mod, SCodeDump.defaultOptions)%>'
1042+
if Config.showAnnotations() then
1043+
'annotation<%SCodeDumpTpl.dumpModifier(ann_mod, SCodeDump.defaultOptions)%>'
1044+
else if Config.showStructuralAnnotations() then
1045+
let ann_str = SCodeDumpTpl.dumpModifier(DAEDump.filterStructuralMods(ann_mod), SCodeDump.defaultOptions)
1046+
if ann_str then
1047+
'annotation<%ann_str%>'
10481048
end dumpCommentAnnotationNoOpt;
10491049

10501050
template dumpCommentOpt(Option<SCode.Comment> comment)

Compiler/Util/Config.mo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ algorithm
249249
Flags.setConfigBool(Flags.SHOW_ANNOTATIONS, show);
250250
end setShowAnnotations;
251251

252+
public function showStructuralAnnotations
253+
output Boolean show;
254+
algorithm
255+
show := Flags.getConfigBool(Flags.SHOW_STRUCTURAL_ANNOTATIONS);
256+
end showStructuralAnnotations;
257+
252258
public function showStartOrigin
253259
output Boolean show;
254260
algorithm

Compiler/Util/Flags.mo

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,10 @@ constant ConfigFlag SINGLE_INSTANCE_AGLSOLVER = CONFIG_FLAG(127, "singleInstance
14771477
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
14781478
Util.gettext("Sets to instantiate only one algebraic loop solver all algebraic loops"));
14791479

1480+
constant ConfigFlag SHOW_STRUCTURAL_ANNOTATIONS = CONFIG_FLAG(128, "showStructuralAnnotations",
1481+
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
1482+
Util.gettext("Show annotations affecting the solution process in the flattened code."));
1483+
14801484
protected
14811485
// This is a list of all configuration flags. A flag can not be used unless it's
14821486
// in this list, and the list is checked at initialization so that all flags are
@@ -1608,7 +1612,8 @@ constant list<ConfigFlag> allConfigFlags = {
16081612
POST_OPT_MODULES_DAE,
16091613
EVAL_LOOP_LIMIT,
16101614
EVAL_RECURSION_LIMIT,
1611-
SINGLE_INSTANCE_AGLSOLVER
1615+
SINGLE_INSTANCE_AGLSOLVER,
1616+
SHOW_STRUCTURAL_ANNOTATIONS
16121617
};
16131618

16141619
public function new

0 commit comments

Comments
 (0)