Skip to content

Commit

Permalink
- Added printing of class comments and annotations to DAEDump.
Browse files Browse the repository at this point in the history
- Updated test cases.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6124 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 14, 2010
1 parent 807192b commit fa6eaf0
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 44 deletions.
1 change: 1 addition & 0 deletions Compiler/DAE.mo
Expand Up @@ -222,6 +222,7 @@ public uniontype Element
Ident ident;
list<Element> dAElist "a component with subelements, normally only used at top level.";
ElementSource source "the origin of the component/equation/algorithm"; // we might not this here.
Option<SCode.Comment> comment;
end COMP;

record FUNCTION " A Modelica function"
Expand Down
58 changes: 51 additions & 7 deletions Compiler/DAEDump.mo
Expand Up @@ -512,9 +512,11 @@ algorithm
local
String n;
list<DAE.Element> l;
case DAE.COMP(ident = n,dAElist = l)
Option<SCode.Comment> c;
case DAE.COMP(ident = n,dAElist = l, comment = c)
equation
Print.printBuf("class ");
dumpCommentOption(c);
Print.printBuf(n);
Print.printBuf("\n");
dumpElements(l);
Expand Down Expand Up @@ -840,19 +842,44 @@ algorithm
local
String str,cmt;
Option<SCode.Annotation> annopt;
list<SCode.Annotation> annl;
Option<SCode.Comment> cmtopt;
list<String> ann_strl;
// No comment.
case (NONE) then "";
// String comment with possible annotation.
case (SOME(SCode.COMMENT(annopt,SOME(cmt))))
equation
str = Util.stringAppendList({" \"",cmt,"\""});
str = str +& dumpAnnotationOptionStr(annopt);
then
str;
// No string comment, but possible annotation.
case (SOME(SCode.COMMENT(annopt,NONE)))
equation
str = dumpAnnotationOptionStr(annopt);
then
str;
end matchcontinue;
// Class comment, show annotations enabled.
case (SOME(SCode.CLASS_COMMENT(annotations = annl, comment = cmtopt)))
equation
true = RTOpts.showAnnotations();
str = dumpCommentOptionStr(cmtopt);
ann_strl = Util.listMap1(Util.listMap(annl, dumpAnnotationStr),
stringAppend, ";");
// If there is only one annotations, print it immediately after the
// class name, otherwise print them in a list below the class name.
str = str +& Util.if_((listLength(ann_strl) > 1), "\n ", "");
str = str +& Util.stringDelimitList(ann_strl, "\n ");
then
str;
// Class comment, show annotations disabled.
case (SOME(SCode.CLASS_COMMENT(comment = cmtopt)))
equation
str = dumpCommentOptionStr(cmtopt);
then
str;
end matchcontinue;
end dumpCommentOptionStr;

protected function dumpAnnotationOptionStr
Expand All @@ -861,19 +888,34 @@ protected function dumpAnnotationOptionStr
algorithm
outString := matchcontinue(inAnnotationOpt)
local
SCode.Mod ann_mod;
SCode.Annotation ann;
String s;
case SOME(SCode.ANNOTATION(modification = ann_mod))
case SOME(ann)
equation
true = RTOpts.showAnnotations();
s = SCode.printModStr(ann_mod);
s = " annotation" +& s;
s = dumpAnnotationStr(ann);
then
s;
case _ then "";
end matchcontinue;
end dumpAnnotationOptionStr;

protected function dumpAnnotationStr
input SCode.Annotation inAnnotation;
output String outString;
algorithm
outString := matchcontinue(inAnnotation)
local
SCode.Mod ann_mod;
String s;
case SCode.ANNOTATION(modification = ann_mod)
equation
s = " annotation" +& SCode.printModStr(ann_mod);
then
s;
end matchcontinue;
end dumpAnnotationStr;

protected function dumpCommentOption "function: dumpCommentOption_str
Dump Comment option."
input Option<SCode.Comment> comment;
Expand Down Expand Up @@ -2642,12 +2684,14 @@ algorithm
local
String n;
list<DAE.Element> l;
Option<SCode.Comment> c;
IOStream.IOStream str;

case (DAE.COMP(ident = n,dAElist = l), str)
case (DAE.COMP(ident = n,dAElist = l,comment = c), str)
equation
str = IOStream.append(str, "class ");
str = IOStream.append(str, n);
str = IOStream.append(str, dumpCommentOptionStr(c));
str = IOStream.append(str, "\n");
str = dumpElementsStream(l, str);
str = IOStream.append(str, "end ");
Expand Down
29 changes: 16 additions & 13 deletions Compiler/DAEUtil.mo
Expand Up @@ -241,6 +241,7 @@ algorithm
String id;
DAE.ElementSource source "the origin of the element";
DAE.FunctionTree funcs,funcs1,funcs2;
Option<SCode.Comment> cmt;

case(DAE.DAE({},funcs)) then (DAE.DAE({},funcs),DAE.DAE({},funcs));

Expand All @@ -250,12 +251,12 @@ algorithm
then (DAE.DAE(v::elts2,funcs),DAE.DAE(elts3,funcs));

// adrpo: TODO! FIXME! a DAE.COMP SHOULD NOT EVER BE HERE!
case(DAE.DAE(DAE.COMP(id,elts1,source)::elts2,funcs))
case(DAE.DAE(DAE.COMP(id,elts1,source,cmt)::elts2,funcs))
equation
(DAE.DAE(elts11,_),DAE.DAE(elts3,_)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts1,funcs));
(DAE.DAE(elts22,_),DAE.DAE(elts33,_)) = splitDAEIntoVarsAndEquations(DAE.DAE(elts2,funcs));
elts3 = listAppend(elts3,elts33);
then (DAE.DAE(DAE.COMP(id,elts11,source)::elts22,funcs),DAE.DAE(elts3,funcs));
then (DAE.DAE(DAE.COMP(id,elts11,source,cmt)::elts22,funcs),DAE.DAE(elts3,funcs));

case(DAE.DAE((e as DAE.EQUATION(exp=_))::elts2,funcs))
equation
Expand Down Expand Up @@ -409,6 +410,7 @@ algorithm
list<DAE.Element> rest, els, elist;
DAE.Element e,v; String id;
DAE.ElementSource source "the origin of the element";
Option<SCode.Comment> cmt;

// empty case
case({},_) then {};
Expand All @@ -432,12 +434,12 @@ algorithm
v::els;

// handle components
case(DAE.COMP(id,elist,source)::rest, variableNames)
case(DAE.COMP(id,elist,source,cmt)::rest, variableNames)
equation
elist = removeVariablesFromElements(elist, variableNames);
els = removeVariablesFromElements(rest, variableNames);
then
DAE.COMP(id,elist,source)::els;
DAE.COMP(id,elist,source,cmt)::els;

// anything else, just keep it
case(v::rest, variableNames)
Expand All @@ -460,6 +462,7 @@ algorithm
DAE.Element e,v; String id;
DAE.ElementSource source "the origin of the element";
DAE.FunctionTree funcs;
Option<SCode.Comment> cmt;

case(var,DAE.DAE({},funcs)) then DAE.DAE({},funcs);

Expand All @@ -468,11 +471,11 @@ algorithm
true = Exp.crefEqual(var,cr);
then DAE.DAE(elist,funcs);

case(var,DAE.DAE(DAE.COMP(id,elist,source)::elist2,funcs))
case(var,DAE.DAE(DAE.COMP(id,elist,source,cmt)::elist2,funcs))
equation
DAE.DAE(elist,_) = removeVariable(var,DAE.DAE(elist,funcs));
DAE.DAE(elist2,_) = removeVariable(var,DAE.DAE(elist2,funcs));
then DAE.DAE(DAE.COMP(id,elist,source)::elist2,funcs);
then DAE.DAE(DAE.COMP(id,elist,source,cmt)::elist2,funcs);

case(var,DAE.DAE(e::elist,funcs))
equation
Expand Down Expand Up @@ -532,11 +535,11 @@ algorithm
then
DAE.DAE(DAE.VAR(cr,kind,dir,prot,tp,bind,dim,flow_,st,source,attr,cmt,io2)::elist,funcs);

case(var,DAE.DAE(DAE.COMP(id,elist,source)::elist2,funcs))
case(var,DAE.DAE(DAE.COMP(id,elist,source,cmt)::elist2,funcs))
equation
DAE.DAE(elist,_) = removeInnerAttr(var,DAE.DAE(elist,funcs));
DAE.DAE(elist2,_) = removeInnerAttr(var,DAE.DAE(elist2,funcs));
then DAE.DAE(DAE.COMP(id,elist,source)::elist2,funcs);
then DAE.DAE(DAE.COMP(id,elist,source,cmt)::elist2,funcs);

case(var,DAE.DAE(e::elist,funcs))
equation
Expand Down Expand Up @@ -1931,12 +1934,12 @@ algorithm
then
(DAE.INITIALALGORITHM(a,source) :: elts_1);

case ((DAE.COMP(ident = id,dAElist = elts2,source = source) :: elts))
case ((DAE.COMP(ident = id,dAElist = elts2,source = source, comment = comment) :: elts))
equation
elts2 = toModelicaFormElts(elts2);
elts_1 = toModelicaFormElts(elts);
then
(DAE.COMP(id,elts2,source) :: elts_1);
(DAE.COMP(id,elts2,source,comment) :: elts_1);

case ((DAE.FUNCTION(path = p,functions = (DAE.FUNCTION_DEF(elts2)::derFuncs),
type_ = t,partialPrefix=partialPrefix,inlineType = inlineType,source = source) :: elts))
Expand Down Expand Up @@ -2659,7 +2662,7 @@ algorithm
equation
DAE.DAE(sublist_result,_) = transformIfEqToExpr(DAE.DAE(sublist,funcs),onlyConstantEval);
DAE.DAE(rest_result,funcs) = transformIfEqToExpr(DAE.DAE(rest,funcs),onlyConstantEval);
subresult = DAE.COMP(name,sublist_result,source);
subresult = DAE.COMP(name,sublist_result,source,NONE);
result = DAE.DAE((subresult :: rest_result),funcs);
then
result;
Expand Down Expand Up @@ -3543,11 +3546,11 @@ algorithm (traversedDaeList,oextraArg) := matchcontinue(daeList,func,extraArg)
(dae2,extraArg) = traverseDAE2(dae,func,extraArg);
then (DAE.INITIAL_COMPLEX_EQUATION(e11,e22,source)::dae2,extraArg);

case(DAE.COMP(id,elist,source)::dae,func,extraArg)
case(DAE.COMP(id,elist,source,cmt)::dae,func,extraArg)
equation
(elist2,extraArg) = traverseDAE2(elist,func,extraArg);
(dae2,extraArg) = traverseDAE2(dae,func,extraArg);
then (DAE.COMP(id,elist2,source)::dae2,extraArg);
then (DAE.COMP(id,elist2,source,cmt)::dae2,extraArg);

case(DAE.FUNCTION(path,(DAE.FUNCTION_DEF(body = elist)::derFuncs),ftp,partialPrefix,inlineType,source)::dae,func,extraArg)
equation
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Inline.mo
Expand Up @@ -668,10 +668,10 @@ algorithm
then
res :: cdr_1;

case(DAE.COMP(i,elist,source) :: cdr,fns)
case(DAE.COMP(i,elist,source,absynCommentOption) :: cdr,fns)
equation
elist_1 = inlineDAEElements(elist,fns);
res = DAE.COMP(i,elist_1,source);
res = DAE.COMP(i,elist_1,source,absynCommentOption);
cdr_1 = inlineDAEElements(cdr,fns);
then
res :: cdr_1;
Expand Down
8 changes: 4 additions & 4 deletions Compiler/InnerOuter.mo
Expand Up @@ -1366,12 +1366,12 @@ public function switchInnerToOuterAndPrefix
v :: r_1;

/* Traverse components */
case ((DAE.COMP(ident = idName,dAElist = lst,source = source) :: r),io,pre)
case ((DAE.COMP(ident = idName,dAElist = lst,source = source,comment = comment) :: r),io,pre)
equation
lst_1 = switchInnerToOuterAndPrefix(lst, io, pre);
r_1 = switchInnerToOuterAndPrefix(r, io, pre);
then
(DAE.COMP(idName,lst_1,source) :: r_1);
(DAE.COMP(idName,lst_1,source,comment) :: r_1);

case ((x :: r),io, pre)
equation
Expand Down Expand Up @@ -1433,12 +1433,12 @@ public function prefixOuterDaeVars
(DAE.VAR(cr,vk,dir,prot,t,e,id,flowPrefix,streamPrefix,source,dae_var_attr,comment,io) :: r_1);

// Traverse components
case ((DAE.COMP(ident = idName,dAElist = lst,source = source) :: r),crefPrefix)
case ((DAE.COMP(ident = idName,dAElist = lst,source = source,comment = comment) :: r),crefPrefix)
equation
lst_1 = prefixOuterDaeVars(lst, crefPrefix);
r_1 = prefixOuterDaeVars(r, crefPrefix);
then
(DAE.COMP(idName,lst_1,source) :: r_1);
(DAE.COMP(idName,lst_1,source,comment) :: r_1);

case ((x :: r),crefPrefix)
equation
Expand Down

0 comments on commit fa6eaf0

Please sign in to comment.