Skip to content

Commit

Permalink
Fix for big #1224:
Browse files Browse the repository at this point in the history
- Added dumping of function comments to DAEDump.
- Updated test suit.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8883 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed May 9, 2011
1 parent eeee312 commit 1d08c18
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 31 deletions.
15 changes: 9 additions & 6 deletions Compiler/BackEnd/PartFn.mo
Expand Up @@ -732,21 +732,23 @@ algorithm
DAE.ExternalDecl ed;
DAE.InlineType inlineType;
DAE.ElementSource source "the origin of the element";
Option<SCode.Comment> cmt;

case ({},dae) then ({},dae);
case(DAE.FUNCTION(p,{DAE.FUNCTION_DEF(elts)},fullType,pp,inlineType,source) :: cdr,dae)
case(DAE.FUNCTION(p,{DAE.FUNCTION_DEF(elts)},fullType,pp,inlineType,source,cmt) :: cdr,dae)
equation
(elts_1,dae) = elabElements(elts,dae);
(cdr_1,dae) = elabFunctions(cdr,dae);
fn = DAE.FUNCTION(p,{DAE.FUNCTION_DEF(elts_1)},fullType,pp,inlineType,source);
fn = DAE.FUNCTION(p,{DAE.FUNCTION_DEF(elts_1)},fullType,pp,inlineType,source,cmt);
dae = replaceFnInFnLst(fn,dae);
then
(fn :: cdr_1,dae);

case(DAE.FUNCTION(p,{DAE.FUNCTION_EXT(elts,ed)},fullType,pp,inlineType,source) :: cdr,dae)
case(DAE.FUNCTION(p,{DAE.FUNCTION_EXT(elts,ed)},fullType,pp,inlineType,source,cmt) :: cdr,dae)
equation
(elts_1,dae) = elabElements(elts,dae);
(cdr_1,dae) = elabFunctions(cdr,dae);
fn = DAE.FUNCTION(p,{DAE.FUNCTION_EXT(elts_1,ed)},fullType,pp,inlineType,source);
fn = DAE.FUNCTION(p,{DAE.FUNCTION_EXT(elts_1,ed)},fullType,pp,inlineType,source,cmt);
dae = replaceFnInFnLst(fn,dae);
then
(fn :: cdr_1,dae);
Expand Down Expand Up @@ -1129,12 +1131,13 @@ algorithm
list<DAE.Var> vars;
DAE.InlineType inlineType;
DAE.ElementSource source "the origin of the element";
Option<SCode.Comment> cmt;

case(bigfn as DAE.FUNCTION(current,{DAE.FUNCTION_DEF(fnparts)},ty,pp,inlineType,source),smallfn,p,dae,numArgs)
case(bigfn as DAE.FUNCTION(current,{DAE.FUNCTION_DEF(fnparts)},ty,pp,inlineType,source,cmt),smallfn,p,dae,numArgs)
equation
(fnparts_1,vars) = buildNewFunctionParts(fnparts,smallfn,dae,numArgs,current);
ty = buildNewFunctionType(ty,vars);
res = DAE.FUNCTION(p,{DAE.FUNCTION_DEF(fnparts_1)},ty,pp,inlineType,source);
res = DAE.FUNCTION(p,{DAE.FUNCTION_DEF(fnparts_1)},ty,pp,inlineType,source,cmt);
then
res;
case(_,_,_,_,_)
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -290,6 +290,7 @@ public uniontype Function
Boolean partialPrefix "MetaModelica extension";
InlineType inlineType;
ElementSource source "the origin of the component/equation/algorithm";
Option<SCode.Comment> comment;
end FUNCTION;

record RECORD_CONSTRUCTOR "A Modelica record constructor. The function can be generated from the Path and Type alone."
Expand Down
16 changes: 11 additions & 5 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -534,8 +534,8 @@ algorithm
case DAE.COMP(ident = n,dAElist = l, comment = c)
equation
Print.printBuf("class ");
dumpCommentOption(c);
Print.printBuf(n);
dumpCommentOption(c);
Print.printBuf("\n");
dumpElements(l);
Print.printBuf("end ");
Expand Down Expand Up @@ -1328,14 +1328,16 @@ algorithm
DAE.Type t;
DAE.InlineType inlineType;
String lang;
Option<SCode.Comment> c;

case DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_DEF(body = daeElts)::_),type_ = t)
case DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_DEF(body = daeElts)::_),type_ = t, comment = c)
equation
Print.printBuf("function ");
fstr = Absyn.pathStringNoQual(fpath);
Print.printBuf(fstr);
inlineTypeStr = dumpInlineTypeStr(inlineType);
Print.printBuf(inlineTypeStr);
Print.printBuf(dumpCommentOptionStr(c));
Print.printBuf("\n");
dumpFunctionElements(daeElts);
Print.printBuf("end ");
Expand All @@ -1348,13 +1350,14 @@ algorithm
then
();

case DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_EXT(body = daeElts, externalDecl = DAE.EXTERNALDECL(language=lang))::_),type_ = t)
case DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_EXT(body = daeElts, externalDecl = DAE.EXTERNALDECL(language=lang))::_),type_ = t, comment = c)
equation
Print.printBuf("function ");
fstr = Absyn.pathStringNoQual(fpath);
Print.printBuf(fstr);
inlineTypeStr = dumpInlineTypeStr(inlineType);
Print.printBuf(inlineTypeStr);
Print.printBuf(dumpCommentOptionStr(c));
Print.printBuf("\n");
dumpFunctionElements(daeElts);
Print.printBuf("\n external \"C\";\n");
Expand Down Expand Up @@ -3331,13 +3334,15 @@ algorithm
DAE.Type tp;
DAE.InlineType inlineType;
IOStream.IOStream str;
Option<SCode.Comment> c;

case (DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_DEF(body = daeElts)::_),type_ = t), str)
case (DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_DEF(body = daeElts)::_),type_ = t, comment = c), str)
equation
fstr = Absyn.pathStringNoQual(fpath);
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, "\n");
str = dumpFunctionElementsStream(daeElts, str);
str = IOStream.append(str, "end ");
Expand All @@ -3350,12 +3355,13 @@ algorithm
then
str;

case (DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_EXT(body = daeElts, externalDecl = DAE.EXTERNALDECL(language=lang))::_),type_ = t), str)
case (DAE.FUNCTION(path = fpath,inlineType=inlineType,functions = (DAE.FUNCTION_EXT(body = daeElts, externalDecl = DAE.EXTERNALDECL(language=lang))::_),type_ = t, comment = c), str)
equation
fstr = Absyn.pathStringNoQual(fpath);
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, "\n");
str = dumpFunctionElementsStream(daeElts, str);
str = IOStream.appendList(str, {"\n external \"",lang,"\";\nend ",fstr,";\n\n"});
Expand Down
11 changes: 6 additions & 5 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -3616,16 +3616,17 @@ algorithm
list<DAE.FunctionDefinition> derFuncs;
DAE.InlineType inlineType;
DAE.ElementSource source "the origin of the element";
Option<SCode.Comment> cmt;

case(DAE.FUNCTION(path,(DAE.FUNCTION_DEF(body = elist)::derFuncs),ftp,partialPrefix,inlineType,source),func,extraArg)
case(DAE.FUNCTION(path,(DAE.FUNCTION_DEF(body = elist)::derFuncs),ftp,partialPrefix,inlineType,source,cmt),func,extraArg)
equation
(elist2,extraArg) = traverseDAE2(elist,func,extraArg);
then (DAE.FUNCTION(path,DAE.FUNCTION_DEF(elist2)::derFuncs,ftp,partialPrefix,inlineType,source),extraArg);
then (DAE.FUNCTION(path,DAE.FUNCTION_DEF(elist2)::derFuncs,ftp,partialPrefix,inlineType,source,cmt),extraArg);

case(DAE.FUNCTION(path,(DAE.FUNCTION_EXT(body = elist,externalDecl=extDecl)::derFuncs),ftp,partialPrefix,inlineType,source),func,extraArg)
case(DAE.FUNCTION(path,(DAE.FUNCTION_EXT(body = elist,externalDecl=extDecl)::derFuncs),ftp,partialPrefix,inlineType,source,cmt),func,extraArg)
equation
(elist2,extraArg) = traverseDAE2(elist,func,extraArg);
then (DAE.FUNCTION(path,DAE.FUNCTION_EXT(elist2,extDecl)::derFuncs,ftp,partialPrefix,DAE.NO_INLINE(),source),extraArg);
then (DAE.FUNCTION(path,DAE.FUNCTION_EXT(elist2,extDecl)::derFuncs,ftp,partialPrefix,DAE.NO_INLINE(),source,cmt),extraArg);

case(DAE.RECORD_CONSTRUCTOR(path,tp,source),func,extraArg)
then (DAE.RECORD_CONSTRUCTOR(path,tp,source),extraArg);
Expand Down Expand Up @@ -5590,4 +5591,4 @@ algorithm
DAE.SOURCE(operations=ops) := source;
end getSymbolicTransformations;

end DAEUtil;
end DAEUtil;
9 changes: 5 additions & 4 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -507,21 +507,22 @@ algorithm
DAE.InlineType inlineType;
list<DAE.FunctionDefinition> funcDefs;
DAE.ElementSource source "the origin of the element";
Option<SCode.Comment> cmt;

case({},_) then {};

case(DAE.FUNCTION(p,DAE.FUNCTION_DEF(body = elist)::funcDefs,t,partialPrefix,inlineType,source) :: cdr,fns)
case(DAE.FUNCTION(p,DAE.FUNCTION_DEF(body = elist)::funcDefs,t,partialPrefix,inlineType,source,cmt) :: cdr,fns)
equation
elist_1 = inlineDAEElements(elist,fns);
res = DAE.FUNCTION(p,DAE.FUNCTION_DEF(elist_1)::funcDefs,t,partialPrefix,inlineType,source);
res = DAE.FUNCTION(p,DAE.FUNCTION_DEF(elist_1)::funcDefs,t,partialPrefix,inlineType,source,cmt);
cdr_1 = inlineCallsInFunctions(cdr,fns);
then
res :: cdr_1;
// external functions
case(DAE.FUNCTION(p,DAE.FUNCTION_EXT(elist,ext)::funcDefs,t,partialPrefix,inlineType,source) :: cdr,fns)
case(DAE.FUNCTION(p,DAE.FUNCTION_EXT(elist,ext)::funcDefs,t,partialPrefix,inlineType,source,cmt) :: cdr,fns)
equation
elist_1 = inlineDAEElements(elist,fns);
res = DAE.FUNCTION(p,DAE.FUNCTION_EXT(elist_1,ext)::funcDefs,t,partialPrefix,inlineType,source);
res = DAE.FUNCTION(p,DAE.FUNCTION_EXT(elist_1,ext)::funcDefs,t,partialPrefix,inlineType,source,cmt);
cdr_1 = inlineCallsInFunctions(cdr,fns);
then
res :: cdr_1;
Expand Down
18 changes: 11 additions & 7 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -10326,7 +10326,7 @@ algorithm
case (cache,env,ih,mod,pre,csets,(c as SCode.CLASS(name = n,restriction = SCode.R_RECORD())),inst_dims)
equation
(cache,c,cenv) = Lookup.lookupRecordConstructorClass(cache,env,Absyn.IDENT(n));
(cache,env,ih,{DAE.FUNCTION(fpath,_,ty1,false,_,source)}) = implicitFunctionInstantiation2(cache,cenv,ih,mod,pre,csets,c,inst_dims);
(cache,env,ih,{DAE.FUNCTION(fpath,_,ty1,false,_,source,_)}) = implicitFunctionInstantiation2(cache,cenv,ih,mod,pre,csets,c,inst_dims);
fun = DAE.RECORD_CONSTRUCTOR(fpath,ty1,source);
cache = Env.addDaeFunction(cache, {fun});
then (cache,env,ih);
Expand Down Expand Up @@ -10396,6 +10396,7 @@ algorithm
DAE.InlineType inlineType;
SCode.ClassDef cd;
Boolean partialPrefixBool;
Option<SCode.Comment> cmt;

/* normal functions */
case (cache,env,ih,mod,pre,csets,(c as SCode.CLASS(classDef=cd,partialPrefix = partialPrefix, name = n,restriction = SCode.R_FUNCTION(),info = info)),inst_dims)
Expand All @@ -10416,12 +10417,13 @@ algorithm
// set the source of this element
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), NONE(), NONE());
partialPrefixBool = SCode.partialBool(partialPrefix);
cmt = extractClassDefComment(cache, env, cd);
then
(cache,env_1,ih,{DAE.FUNCTION(fpath,DAE.FUNCTION_DEF(daeElts)::derFuncs,ty1,partialPrefixBool,inlineType,source)});
(cache,env_1,ih,{DAE.FUNCTION(fpath,DAE.FUNCTION_DEF(daeElts)::derFuncs,ty1,partialPrefixBool,inlineType,source,cmt)});

/* External functions should also have their type in env, but no dae. */
case (cache,env,ih,mod,pre,csets,(c as SCode.CLASS(partialPrefix=partialPrefix,name = n,restriction = (restr as SCode.R_EXT_FUNCTION()),
classDef = (parts as SCode.PARTS(elementLst = els)), info=info)),inst_dims)
classDef = cd as (parts as SCode.PARTS(elementLst = els)), info=info)),inst_dims)
equation
(cache,cenv,ih,_,DAE.DAE(daeElts),csets_1,ty,st,_,_) =
instClass(cache,env,ih, UnitAbsynBuilder.emptyInstStore(),mod, pre,
Expand All @@ -10445,8 +10447,9 @@ algorithm
// set the source of this element
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), NONE(), NONE());
partialPrefixBool = SCode.partialBool(partialPrefix);
cmt = extractClassDefComment(cache, env, cd);
then
(cache,env_1,ih,{DAE.FUNCTION(fpath,DAE.FUNCTION_EXT(daeElts,extdecl)::derFuncs,ty1,partialPrefixBool,DAE.NO_INLINE(),source)});
(cache,env_1,ih,{DAE.FUNCTION(fpath,DAE.FUNCTION_EXT(daeElts,extdecl)::derFuncs,ty1,partialPrefixBool,DAE.NO_INLINE(),source,cmt)});

/* Instantiate overloaded functions */
case (cache,env,ih,mod,pre,csets,(c as SCode.CLASS(name = n,restriction = (restr as SCode.R_FUNCTION()),
Expand Down Expand Up @@ -10544,14 +10547,15 @@ algorithm
Boolean part;
DAE.InlineType inlineType;
DAE.ElementSource source;
Option<SCode.Comment> cmt;

case({},path) then {};

case(DAE.FUNCTION(p,funcs,tp,part,inlineType,source)::elts,path)
case(DAE.FUNCTION(p,funcs,tp,part,inlineType,source,cmt)::elts,path)
equation
elts = addNameToDerivativeMapping(elts,path);
funcs = addNameToDerivativeMappingFunctionDefs(funcs,path);
then DAE.FUNCTION(p,funcs,tp,part,inlineType,source)::elts;
then DAE.FUNCTION(p,funcs,tp,part,inlineType,source,cmt)::elts;

case(elt::elts,path)
equation
Expand Down Expand Up @@ -11172,7 +11176,7 @@ algorithm
// set the of this element
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), NONE(), NONE(), NONE());
partialPrefixBool = SCode.partialBool(partialPrefix);
resfn = DAE.FUNCTION(fpath,{DAE.FUNCTION_DEF(daeElts)},ty,partialPrefixBool,DAE.NO_INLINE(),source);
resfn = DAE.FUNCTION(fpath,{DAE.FUNCTION_DEF(daeElts)},ty,partialPrefixBool,DAE.NO_INLINE(),source,NONE());
then
(cache,env_2,ih,resfn::resfns);

Expand Down
10 changes: 6 additions & 4 deletions Compiler/Util/VarTransform.mo
Expand Up @@ -405,19 +405,21 @@ algorithm
DAE.ElementSource source;
Absyn.Path path;
DAE.ExternalDecl extdecl;
case(DAE.FUNCTION(path,DAE.FUNCTION_DEF(elist)::derFuncs,ftp,partialPrefix,inlineType,source)::dae,repl,condExpFunc)
Option<SCode.Comment> cmt;

case(DAE.FUNCTION(path,DAE.FUNCTION_DEF(elist)::derFuncs,ftp,partialPrefix,inlineType,source,cmt)::dae,repl,condExpFunc)
equation
elist2 = applyReplacementsDAEElts(elist,repl,condExpFunc);
dae2 = applyReplacementsFunctions(dae,repl,condExpFunc);
then
DAE.FUNCTION(path,DAE.FUNCTION_DEF(elist2)::derFuncs,ftp,partialPrefix,inlineType,source)::dae2;
DAE.FUNCTION(path,DAE.FUNCTION_DEF(elist2)::derFuncs,ftp,partialPrefix,inlineType,source,cmt)::dae2;

case(DAE.FUNCTION(path,DAE.FUNCTION_EXT(elist,extdecl)::derFuncs,ftp,partialPrefix,inlineType,source)::dae,repl,condExpFunc)
case(DAE.FUNCTION(path,DAE.FUNCTION_EXT(elist,extdecl)::derFuncs,ftp,partialPrefix,inlineType,source,cmt)::dae,repl,condExpFunc)
equation
elist2 = applyReplacementsDAEElts(elist,repl,condExpFunc);
dae2 = applyReplacementsFunctions(dae,repl,condExpFunc);
then
DAE.FUNCTION(path,DAE.FUNCTION_EXT(elist2,extdecl)::derFuncs,ftp,partialPrefix,inlineType,source)::dae2;
DAE.FUNCTION(path,DAE.FUNCTION_EXT(elist2,extdecl)::derFuncs,ftp,partialPrefix,inlineType,source,cmt)::dae2;
end matchcontinue;
end applyReplacementsFunctions;

Expand Down

0 comments on commit 1d08c18

Please sign in to comment.