Skip to content

Commit

Permalink
Fix for #2705:
Browse files Browse the repository at this point in the history
- Propagate inline annotations in derived component functions.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20867 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed May 28, 2014
1 parent 350780d commit 666cd0f
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
73 changes: 73 additions & 0 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -3778,6 +3778,79 @@ algorithm
end match;
end getEvaluateAnnotation;

public function getInlineTypeAnnotationFromCmt
input Comment inComment;
output Option<Annotation> outAnnotation;
algorithm
outAnnotation := match(inComment)
local
Annotation ann;

case COMMENT(annotation_ = SOME(ann)) then getInlineTypeAnnotation(ann);
else NONE();
end match;
end getInlineTypeAnnotationFromCmt;

protected function getInlineTypeAnnotation
input Annotation inAnnotation;
output Option<Annotation> outAnnotation;
algorithm
outAnnotation := matchcontinue(inAnnotation)
local
list<SubMod> submods;
SubMod inline_mod;
Final fp;
Each ep;
Absyn.Info info;

case ANNOTATION(MOD(fp, ep, submods, _, info))
equation
inline_mod = List.selectFirst(submods, isInlineTypeSubMod);
then
SOME(ANNOTATION(MOD(fp, ep, {inline_mod}, NONE(), info)));

else NONE();
end matchcontinue;
end getInlineTypeAnnotation;

protected function isInlineTypeSubMod
input SubMod inSubMod;
output Boolean outIsInlineType;
algorithm
outIsInlineType := match(inSubMod)
case NAMEMOD(ident = "Inline") then true;
case NAMEMOD(ident = "LateInline") then true;
case NAMEMOD(ident = "InlineAfterIndexReduction") then true;
end match;
end isInlineTypeSubMod;

public function appendAnnotationToComment
input Annotation inAnnotation;
input Comment inComment;
output Comment outComment;
algorithm
outComment := match(inAnnotation, inComment)
local
Option<String> cmt;
SCode.Final fp;
Each ep;
list<SubMod> mods1, mods2;
Option<tuple<Absyn.Exp, Boolean>> b;
Absyn.Info info;

case (_, COMMENT(NONE(), cmt))
then COMMENT(SOME(inAnnotation), cmt);

case (ANNOTATION(modification = MOD(subModLst = mods1)),
COMMENT(SOME(ANNOTATION(MOD(fp, ep, mods2, b, info))), cmt))
equation
mods2 = listAppend(mods1, mods2);
then
COMMENT(SOME(ANNOTATION(MOD(fp, ep, mods2, b, info))), cmt);

end match;
end appendAnnotationToComment;

public function getModifierInfo
input Mod inMod;
output Absyn.Info outInfo;
Expand Down
29 changes: 27 additions & 2 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -6996,16 +6996,17 @@ algorithm
// enableTrace();
// change the class name from gravityAcceleration to be world.gravityAcceleration
name = componentName +& "__" +& name;
// lookup the derived class
(_, extendedClass, _) = Lookup.lookupClass(cache, classEnv, extendsPath, true);
// remove modifications as they are added via transformModificationsToNamedArguments
// also change extendsPath to world.gravityAccelerationTypes
extendsCn = componentName +& "__" +& Absyn.pathString(extendsPath);
newExtendsPath = Absyn.IDENT(extendsCn);
comment = propagateDerivedInlineAnnotation(extendedClass, comment);
sc = SCode.CLASS(name, prefixes, encapsulatedPrefix, partialPrefix, restriction,
SCode.DERIVED(Absyn.TPATH(newExtendsPath, arrayDim), SCode.NOMOD(), attributes), comment,info);
// add the class function to the environment
env = Env.extendFrameC(env, sc);
// lookup the derived class
(_, extendedClass, _) = Lookup.lookupClass(cache, classEnv, extendsPath, true);
// construct the extended class gravityAccelerationType
// with a different name: world.gravityAccelerationType
SCode.CLASS(name, prefixes, encapsulatedPrefix, partialPrefix, restriction, classDef, cmt, info) = extendedClass;
Expand All @@ -7032,6 +7033,30 @@ algorithm
end matchcontinue;
end addComponentFunctionsToCurrentEnvironment;

protected function propagateDerivedInlineAnnotation
"Inserts an inline annotation from the given class into the given comment, if
the comment doesn't already have such an annotation."
input SCode.Element inExtendedClass;
input SCode.Comment inComment;
output SCode.Comment outComment;
algorithm
outComment := matchcontinue(inExtendedClass, inComment)
local
SCode.Comment cmt;
SCode.Annotation ann;

case (SCode.CLASS(cmt = cmt), _)
equation
NONE() = SCode.getInlineTypeAnnotationFromCmt(inComment);
SOME(ann) = SCode.getInlineTypeAnnotationFromCmt(cmt);
cmt = SCode.appendAnnotationToComment(ann, cmt);
then
cmt;

else inComment;
end matchcontinue;
end propagateDerivedInlineAnnotation;

public function elabCallArgs "
function: elabCallArgs
Given the name of a function and two lists of expression and
Expand Down

0 comments on commit 666cd0f

Please sign in to comment.