Skip to content

Commit

Permalink
Abstract syntax change. make clean comes highly recommended.
Browse files Browse the repository at this point in the history
- Class annotations are now stored as a list of annotations at the end of a class (like the Modelica3 grammar says except we allow multiple annotations).
  - This is a transition so we can create warnings or errors later on.
  - No major changes can be seen except when using OMEdit or API that lists the position of annotations


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15922 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Apr 26, 2013
1 parent c47607e commit 6d99b6c
Show file tree
Hide file tree
Showing 60 changed files with 1,276 additions and 2,936 deletions.
24 changes: 3 additions & 21 deletions Compiler/BackEnd/EvaluateParameter.mo
Original file line number Diff line number Diff line change
Expand Up @@ -251,32 +251,14 @@ protected function hasEvaluateAnnotation
algorithm
select := match(inVar)
local
SCode.Comment comment;
SCode.Annotation anno;
// Parameter with evaluate=true
case BackendDAE.VAR(comment=SOME(comment))
then hasEvaluateAnnotation1(comment);
case BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_=SOME(anno))))
then SCode.hasBooleanNamedAnnotation({anno},"Evaluate");
else then false;
end match;
end hasEvaluateAnnotation;

protected function hasEvaluateAnnotation1
input SCode.Comment comment;
output Boolean select;
algorithm
select := match(comment)
local
SCode.Annotation anno;
list<SCode.Annotation> annos;
case (SCode.COMMENT(annotation_=SOME(anno)))
then
SCode.hasBooleanNamedAnnotation({anno},"Evaluate");
case(SCode.CLASS_COMMENT(annotations=annos))
then
SCode.hasBooleanNamedAnnotation(annos,"Evaluate");
else then false;
end match;
end hasEvaluateAnnotation1;

protected function getParameterIncidenceMatrix
input tuple<BackendDAE.Var,tuple<BackendDAE.Variables,Integer,selectParameterFunc,list<Integer>,Integer,array<Integer>,BackendDAE.IncidenceMatrix,BackendDAE.IncidenceMatrixT>> inTp;
output tuple<BackendDAE.Var,tuple<BackendDAE.Variables,Integer,selectParameterFunc,list<Integer>,Integer,array<Integer>,BackendDAE.IncidenceMatrix,BackendDAE.IncidenceMatrixT>> outTpl;
Expand Down
135 changes: 107 additions & 28 deletions Compiler/FrontEnd/Absyn.mo
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ uniontype ClassDef
list<NamedArg> classAttrs "optimization Op (objective=...) end Op. A list arguments attributing a
class declaration. Currently used only for Optimica extensions";
list<ClassPart> classParts;
list<Annotation> ann "Modelica2 allowed multiple class-annotations";
Option<String> comment;
end PARTS;

Expand All @@ -199,10 +200,11 @@ uniontype ClassDef
end OVERLOAD;

record CLASS_EXTENDS
Ident baseClassName "name of class to extend" ;
list<ElementArg> modifications "modifications to be applied to the base class";
Option<String> comment "comment";
list<ClassPart> parts "class parts";
Ident baseClassName "name of class to extend" ;
list<ElementArg> modifications "modifications to be applied to the base class";
Option<String> comment "comment";
list<ClassPart> parts "class parts";
list<Annotation> ann;
end CLASS_EXTENDS;

record PDER
Expand Down Expand Up @@ -296,10 +298,6 @@ uniontype ElementItem "An element item is either an element or an annotation"
Element element;
end ELEMENTITEM;

record ANNOTATIONITEM
Annotation annotation_ ;
end ANNOTATIONITEM;

record LEXER_COMMENT
String comment;
end LEXER_COMMENT;
Expand Down Expand Up @@ -457,10 +455,6 @@ uniontype EquationItem "Several component declarations can be grouped together i
Info info "line number" ;
end EQUATIONITEM;

record EQUATIONITEMANN
Annotation annotation_ "annotation" ;
end EQUATIONITEMANN;

record EQUATIONITEMCOMMENT
String comment;
end EQUATIONITEMCOMMENT;
Expand All @@ -475,10 +469,6 @@ uniontype AlgorithmItem "Info specific for an algorithm item."
Info info "line number" ;
end ALGORITHMITEM;

record ALGORITHMITEMANN
Annotation annotation_ "annotation" ;
end ALGORITHMITEMANN;

record ALGORITHMITEMCOMMENT "A comment from the lexer"
String comment;
end ALGORITHMITEMCOMMENT;
Expand Down Expand Up @@ -1128,16 +1118,17 @@ protected import Error;

public constant TimeStamp dummyTimeStamp = TIMESTAMP(0.0,0.0);

public constant ClassDef dummyParts = PARTS({},{},{},{},NONE());
public constant Info dummyInfo = INFO("",false,0,0,0,0,dummyTimeStamp);
public constant TimeStamp newTimeStamp = TIMESTAMP(0.0,1.0);

public function getNewTimeStamp
"function: getNewTimeStamp
generate a new timestamp with edittime>buildtime."
output TimeStamp ts;
annotation(__OpenModelica_EarlyInline = true);
algorithm
ts := newTimeStamp;
annotation(__OpenModelica_EarlyInline = true);
end getNewTimeStamp;

public function setTimeStampBool ""
Expand Down Expand Up @@ -2336,9 +2327,6 @@ algorithm
then
(EQUATIONITEM(eq, cmt, info), tup);

case (EQUATIONITEMANN(annotation_ = _), _)
then (inEquationItem, inTuple);

end match;
end traverseEquationItemBidir;

Expand Down Expand Up @@ -2451,18 +2439,18 @@ end traverseEquationBidirElse;
public function makeIdentPathFromString ""
input String s;
output Path p;
annotation(__OpenModelica_EarlyInline = true);
algorithm
p := IDENT(s);
annotation(__OpenModelica_EarlyInline = true);
end makeIdentPathFromString;

public function makeQualifiedPathFromStrings ""
input String s1;
input String s2;
output Path p;
annotation(__OpenModelica_EarlyInline = true);
algorithm
p := QUALIFIED(s1,IDENT(s2));
annotation(__OpenModelica_EarlyInline = true);
end makeQualifiedPathFromStrings;

public function setTimeStampEdit "Function: getNewTimeStamp
Expand Down Expand Up @@ -2570,9 +2558,9 @@ end expCref;
public function crefExp "returns the componentRef of an expression if matches."
input ComponentRef cr;
output Exp exp;
annotation(__OpenModelica_EarlyInline = true);
algorithm
exp := CREF(cr);
annotation(__OpenModelica_EarlyInline = true);
end crefExp;

public function expComponentRefStr ""
Expand Down Expand Up @@ -5358,9 +5346,9 @@ public function makeCons
input Exp e1;
input Exp e2;
output Exp e;
annotation(__OpenModelica_EarlyInline = true);
algorithm
e := CONS(e1,e2);
annotation(__OpenModelica_EarlyInline = true);
end makeCons;

public function crefIdent
Expand Down Expand Up @@ -5682,8 +5670,9 @@ algorithm
list<ElementArg> modifications;
list<ClassPart> parts;
list<NamedArg> classAttrs;
case PARTS(typeVars,classAttrs,parts,_) then PARTS(typeVars,classAttrs,parts,NONE());
case CLASS_EXTENDS(baseClassName,modifications,_,parts) then CLASS_EXTENDS(baseClassName,modifications,NONE(),parts);
list<Annotation> ann;
case PARTS(typeVars,classAttrs,parts,ann,_) then PARTS(typeVars,classAttrs,parts,ann,NONE());
case CLASS_EXTENDS(baseClassName,modifications,_,parts,ann) then CLASS_EXTENDS(baseClassName,modifications,NONE(),parts,ann);
case DERIVED(typeSpec,attributes,arguments,_) then DERIVED(typeSpec,attributes,arguments,NONE());
case ENUMERATION(enumLiterals,_) then ENUMERATION(enumLiterals,NONE());
case OVERLOAD(functionNames,_) then OVERLOAD(functionNames,NONE());
Expand All @@ -5706,10 +5695,10 @@ algorithm
list<ElementItem> elts;
FunctionRestriction funcRest;
list<NamedArg> classAttr;
case CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(funcRest),PARTS(typeVars,classAttr,classParts,_),info)
case CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(funcRest),PARTS(typeVars,classAttr,classParts,_,_),info)
equation
(elts as _::_) = List.fold(listReverse(classParts),getFunctionInterfaceParts,{});
then CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(funcRest),PARTS(typeVars,classAttr,PUBLIC(elts)::{},NONE()),info);
then CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(funcRest),PARTS(typeVars,classAttr,PUBLIC(elts)::{},{},NONE()),info);
end match;
end getFunctionInterface;

Expand Down Expand Up @@ -5917,4 +5906,94 @@ algorithm
end match;
end importName;

public function mergeAnnotations
"function: mergeAnnotations
This function takes an old annotation as first argument and a new
annotation as second argument and merges the two.
Annotation \"parts\" that exist in both the old and the new annotation
will be changed according to the new definition. For instance,
merge_annotations(annotation(x=1,y=2),annotation(x=3))
=> annotation(x=3,y=2)"
input Annotation inAnnotation1;
input Annotation inAnnotation2;
output Annotation outAnnotation;
algorithm
outAnnotation:=
matchcontinue (inAnnotation1,inAnnotation2)
local
list<ElementArg> neweltargs,oldrest,eltargs,eltargs_1;
ElementArg mod;
Annotation a;
Path p;
case (ANNOTATION(elementArgs = ((mod as MODIFICATION(path = p)) :: oldrest)),ANNOTATION(elementArgs = eltargs))
equation
failure(_ = removeModificationInElementargs(eltargs, p));
ANNOTATION(neweltargs) = mergeAnnotations(ANNOTATION(oldrest), ANNOTATION(eltargs));
then
ANNOTATION((mod :: neweltargs));
case (ANNOTATION(elementArgs = ((mod as MODIFICATION(path = p)) :: oldrest)),ANNOTATION(elementArgs = eltargs))
equation
eltargs_1 = removeModificationInElementargs(eltargs, p);
ANNOTATION(neweltargs) = mergeAnnotations(ANNOTATION(oldrest), ANNOTATION(eltargs));
then ANNOTATION(neweltargs);
case (ANNOTATION(elementArgs = {}),a) then a;
end matchcontinue;
end mergeAnnotations;

protected function removeModificationInElementargs
"function: removeModificationInElementargs
This function removes the class modification named by the second argument.
If no such class modification is found thefunction fails.
Currently, only identifiers are allowed as class modifiers,
i.e. a(...) and not a.b(...)"
input list<ElementArg> inAbsynElementArgLst;
input Path inPath;
output list<ElementArg> outAbsynElementArgLst;
algorithm
outAbsynElementArgLst := matchcontinue (inAbsynElementArgLst,inPath)
local
String id1,id2;
ElementArg m;
list<ElementArg> res,xs;

case ({MODIFICATION(path = IDENT(name = id1))},IDENT(name = id2))
equation
true = stringEq(id1, id2);
then {};

case ({(m as MODIFICATION(path = IDENT(name = id1)))},IDENT(name = id2))
equation
false = stringEq(id1, id2);
then
fail();

case ((MODIFICATION(path = IDENT(name = id1)) :: xs),IDENT(name = id2))
equation
true = stringEq(id1, id2);
res = removeModificationInElementargs(xs, inPath);
then
res;

case (((m as MODIFICATION(path = IDENT(name = id1))) :: xs),IDENT(name = id2))
equation
false = stringEq(id1, id2);
res = removeModificationInElementargs(xs, inPath);
then
(m :: res);

case (((m as MODIFICATION(path = IDENT(name = id1))) :: xs),IDENT(name = id2))
equation
res = removeModificationInElementargs(xs, inPath);
then
(m :: res);
end matchcontinue;
end removeModificationInElementargs;

public function annotationToElementArgs
input Annotation ann;
output list<ElementArg> args;
algorithm
ANNOTATION(args) := ann;
end annotationToElementArgs;

end Absyn;

0 comments on commit 6d99b6c

Please sign in to comment.