Skip to content

Commit

Permalink
- Fixed output of class annotations when +showAnnotations is used.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15975 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed May 3, 2013
1 parent cba6967 commit 05c95cb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 68 deletions.
134 changes: 69 additions & 65 deletions Compiler/FrontEnd/DAEDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ algorithm
ExpressionDump.printExp(e);
Print.printBuf(",dims=");
Dump.printList(dims, ExpressionDump.printSubscript, ", ");
comment_str = dumpCommentOptionStr(comment) " dump_start_value start &" ;
comment_str = dumpCommentAnnotationStr(comment) " dump_start_value start &" ;
Print.printBuf(" comment:");
Print.printBuf(comment_str);
Print.printBuf(", ");
Expand All @@ -348,7 +348,7 @@ algorithm
Print.printBuf("((" +& s1);
Print.printBuf("))");
*/
comment_str = dumpCommentOptionStr(comment) " dump_start_value start &" ;
comment_str = dumpCommentAnnotationStr(comment) " dump_start_value start &" ;
Print.printBuf(" comment:");
Print.printBuf(comment_str);
Print.printBuf(", ");
Expand Down Expand Up @@ -1122,78 +1122,77 @@ algorithm
end match;
end dumpVarParallelismStr;

public function dumpCommentOptionStr "function: dumpCommentOptionStr
Dump Comment option to a string."
input Option<SCode.Comment> inAbsynCommentOption;
protected function dumpCommentStr
"Dumps a comment to a string."
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString:=
matchcontinue (inAbsynCommentOption)
outString := match(inComment)
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 = 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;
end dumpCommentOptionStr;
String cmt;

protected function dumpAnnotationOptionStr
input Option<SCode.Annotation> inAnnotationOpt;
case SOME(SCode.COMMENT(comment = SOME(cmt)))
then stringAppendList({" \"", cmt, "\""});

else "";

end match;
end dumpCommentStr;

protected function dumpClassAnnotationStr
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString := matchcontinue(inAnnotationOpt)
local
SCode.Annotation ann;
String s;
case SOME(ann)
equation
true = Config.showAnnotations();
s = dumpAnnotationStr(ann);
then
s;
case _ then "";
end matchcontinue;
end dumpAnnotationOptionStr;
outString := dumpAnnotationStr(inComment, " ", ";\n");
end dumpClassAnnotationStr;

protected function dumpCompAnnotationStr
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString := dumpAnnotationStr(inComment, " ", "");
end dumpCompAnnotationStr;

protected function dumpAnnotationStr
input SCode.Annotation inAnnotation;
input Option<SCode.Comment> inComment;
input String inPrefix;
input String inSuffix;
output String outString;
algorithm
outString := match(inAnnotation)
outString := matchcontinue(inComment, inPrefix, inSuffix)
local
String ann;
SCode.Mod ann_mod;
String s;
case SCode.ANNOTATION(modification = ann_mod)

case (SOME(SCode.COMMENT(annotation_ = SOME(SCode.ANNOTATION(ann_mod)))), _, _)
equation
s = " annotation" +& SCodeDump.printModStr(ann_mod);
true = Config.showAnnotations();
ann = inPrefix +& "annotation" +& SCodeDump.printModStr(ann_mod) +& inSuffix;
then
s;
end match;
ann;

else "";

end matchcontinue;
end dumpAnnotationStr;

public function dumpCommentAnnotationStr
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString := match(inComment)
case NONE() then "";
else dumpCommentStr(inComment) +& dumpCompAnnotationStr(inComment);
end match;
end dumpCommentAnnotationStr;

protected function dumpCommentOption "function: dumpCommentOption_str
Dump Comment option."
input Option<SCode.Comment> comment;
protected
String str;
algorithm
str := dumpCommentOptionStr(comment);
str := dumpCommentAnnotationStr(comment);
Print.printBuf(str);
end dumpCommentOption;

Expand Down Expand Up @@ -1634,9 +1633,10 @@ algorithm
Print.printBuf(fstr);
inlineTypeStr = dumpInlineTypeStr(inlineType);
Print.printBuf(inlineTypeStr);
Print.printBuf(dumpCommentOptionStr(c));
Print.printBuf(dumpCommentStr(c));
Print.printBuf("\n");
dumpFunctionElements(daeElts);
Print.printBuf(dumpClassAnnotationStr(c));
Print.printBuf("end ");
Print.printBuf(fstr);
Print.printBuf(";\n\n");
Expand All @@ -1657,11 +1657,12 @@ algorithm
Print.printBuf(fstr);
inlineTypeStr = dumpInlineTypeStr(inlineType);
Print.printBuf(inlineTypeStr);
Print.printBuf(dumpCommentOptionStr(c));
Print.printBuf(dumpCommentStr(c));
Print.printBuf("\n");
dumpFunctionElements(daeElts);
ext_decl_str = dumpExtDeclStr(ext_decl);
Print.printBuf("\n " +& ext_decl_str +& "\n");
Print.printBuf(dumpClassAnnotationStr(c));
Print.printBuf("end ");
Print.printBuf(fstr);
Print.printBuf(";\n\n");
Expand Down Expand Up @@ -2504,7 +2505,7 @@ algorithm
ComponentReference.printComponentRef(cr);
Print.printBuf(", ");
dumpKind(vk);
comment_str = dumpCommentOptionStr(comment);
comment_str = dumpCommentAnnotationStr(comment);
Print.printBuf(" comment:");
Print.printBuf(comment_str);
tmp_str = dumpVariableAttributesStr(dae_var_attr);
Expand All @@ -2525,7 +2526,7 @@ algorithm
dumpKind(vk);
Print.printBuf(", binding: ");
ExpressionDump.printExp(e);
comment_str = dumpCommentOptionStr(comment);
comment_str = dumpCommentAnnotationStr(comment);
Print.printBuf(" comment:");
Print.printBuf(comment_str);
tmp_str = dumpVariableAttributesStr(dae_var_attr);
Expand Down Expand Up @@ -3222,9 +3223,10 @@ algorithm
equation
str = IOStream.append(str, "class ");
str = IOStream.append(str, n);
str = IOStream.append(str, dumpCommentOptionStr(c));
str = IOStream.append(str, dumpCommentStr(c));
str = IOStream.append(str, "\n");
str = dumpElementsStream(l, str);
str = IOStream.append(str, dumpClassAnnotationStr(c));
str = IOStream.append(str, "end ");
str = IOStream.append(str, n);
str = IOStream.append(str, ";\n");
Expand Down Expand Up @@ -3749,7 +3751,7 @@ algorithm
s4 = ComponentReference.printComponentRefStr(id);
s7 = dumpVarVisibilityStr(prot);
sPrl = dumpVarParallelismStr(prl);
comment_str = dumpCommentOptionStr(comment);
comment_str = dumpCommentAnnotationStr(comment);
s5 = dumpVariableAttributesStr(dae_var_attr);
str = IOStream.appendList(str, {" ",s7,sFinal,sPrl,s1,s2,s3,s3_subs," ",s4,s5,comment_str,";\n"});
then
Expand All @@ -3774,7 +3776,7 @@ algorithm
s3_subs = unparseDimensions(dims, printTypeDimension);
s4 = ComponentReference.printComponentRefStr(id);
s5 = ExpressionDump.printExpStr(e);
comment_str = dumpCommentOptionStr(comment);
comment_str = dumpCommentAnnotationStr(comment);
s6 = dumpVariableAttributesStr(dae_var_attr);
sPrl = dumpVarParallelismStr(prl);
s7 = dumpVarVisibilityStr(prot);
Expand Down Expand Up @@ -3904,7 +3906,7 @@ protected function dumpFunctionStream
algorithm
outStream := matchcontinue (inElement, inStream)
local
String fstr, ext_decl_str, impureStr;
String fstr, ext_decl_str, impureStr, ann_str;
Absyn.Path fpath;
list<DAE.Element> daeElts;
DAE.Type t;
Expand All @@ -3925,9 +3927,10 @@ algorithm
str = IOStream.append(str, "function ");
str = IOStream.append(str, fstr);
str = IOStream.append(str, dumpInlineTypeStr(inlineType));
str = IOStream.append(str, dumpCommentOptionStr(c));
str = IOStream.append(str, dumpCommentStr(c));
str = IOStream.append(str, "\n");
str = dumpFunctionElementsStream(daeElts, str);
str = IOStream.append(str, dumpClassAnnotationStr(c));
str = IOStream.append(str, "end ");
str = IOStream.append(str, fstr);
str = IOStream.append(str, ";\n\n");
Expand All @@ -3947,11 +3950,12 @@ algorithm
str = IOStream.append(str, "function ");
str = IOStream.append(str, fstr);
str = IOStream.append(str, dumpInlineTypeStr(inlineType));
str = IOStream.append(str, dumpCommentOptionStr(c));
str = IOStream.append(str, dumpCommentStr(c));
str = IOStream.append(str, "\n");
str = dumpFunctionElementsStream(daeElts, str);
ext_decl_str = dumpExtDeclStr(ext_decl);
str = IOStream.appendList(str, {"\n ", ext_decl_str, "\nend ", fstr, ";\n\n"});
ann_str = dumpClassAnnotationStr(c);
str = IOStream.appendList(str, {"\n ", ext_decl_str, "\n", ann_str, "end ", fstr, ";\n\n"});
then
str;

Expand Down Expand Up @@ -4106,13 +4110,13 @@ algorithm

case ({c})
equation
str = dumpCommentOptionStr(SOME(c));
str = dumpCommentAnnotationStr(SOME(c));
then
str;

case (c::rest)
equation
str = dumpCommentOptionStr(SOME(c));
str = dumpCommentAnnotationStr(SOME(c));
str = str +& " " +& cmtListToString(rest);
then
str;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ algorithm
// set the source of this element
source = DAEUtil.addElementSourcePartOfOpt(DAE.emptyElementSource, Env.getEnvPath(env));
daeElts = DAEUtil.daeElements(dae);
cmt = SCode.stripAnnotationFromComment(SCode.getElementComment(cdef));
cmt = SCode.getElementComment(cdef);
dae = DAE.DAE({DAE.COMP(pathstr,daeElts,source,cmt)});
//System.stopTimer();
//print("\nSetSource+DAE: " +& realString(System.getTimerIntervalTime()));
Expand Down Expand Up @@ -586,7 +586,7 @@ algorithm
// set the source of this element
source = DAEUtil.addElementSourcePartOfOpt(DAE.emptyElementSource, Env.getEnvPath(env));
daeElts = DAEUtil.daeElements(dae);
cmt = SCode.stripAnnotationFromComment(SCode.getElementComment(cdef));
cmt = SCode.getElementComment(cdef);
dae = DAE.DAE({DAE.COMP(pathstr,daeElts,source,cmt)});
then
(cache,env_2,ih,dae);
Expand Down Expand Up @@ -789,7 +789,7 @@ algorithm
dae = reEvaluateInitialIfEqns(cache, env, dae, true);
elts = DAEUtil.daeElements(dae);

cmt = SCode.stripAnnotationFromComment(SCode.getElementComment(cls));
cmt = SCode.getElementComment(cls);
dae = DAE.DAE({DAE.COMP(name, elts, inSource, cmt)});
then
(cache, env, ih, dae);
Expand Down

0 comments on commit 05c95cb

Please sign in to comment.