Skip to content

Commit

Permalink
Changing list(exportAsCode=true) to list(exportKind=...)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16140 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 28, 2013
1 parent e84d301 commit f47473b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
5 changes: 4 additions & 1 deletion Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1821,11 +1821,13 @@ external "builtin";
annotation(preferredView="text");
end stringReplace;

type ExportKind = enumeration(Absyn "Normal Absyn",SCode "Normal SCode",Internal "True unparsing of the Absyn");

function list "Lists the contents of the given class, or all loaded classes."
input TypeName class_ := $TypeName(AllLoadedClasses);
input Boolean interfaceOnly := false;
input Boolean shortOnly := false "only short class definitions";
input Boolean exportAsCode := false "true if we want a true unparsing of the program";
input ExportKind exportKind := ExportKind.Absyn;
output String contents;
external "builtin";
annotation(Documentation(info="<html>
Expand All @@ -1845,6 +1847,7 @@ empty string is returned.</p>
</html>",revisions="<html>
<table>
<tr><th>Revision</th><th>Author</th><th>Comment</th></tr>
<tr><td>16124</td><td>sjoelund.se</td><td>Added replaced exportAsCode option with exportKind (selecting which kind of unparsing to use)</td></tr>
<tr><td>10796</td><td>sjoelund.se</td><td>Added shortOnly option</td></tr>
<tr><td>10756</td><td>sjoelund.se</td><td>Added interfaceOnly option</td></tr>
</table>
Expand Down
22 changes: 19 additions & 3 deletions Compiler/FrontEnd/SCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,27 @@ public function translateAbsyn2SCode
input Absyn.Program inProgram;
output SCode.Program outProgram;
algorithm
outProgram := match(inProgram)
outProgram := translateAbsyn2SCode2(inProgram,true);
end translateAbsyn2SCode;

public function translateAbsyn2SCode2
"function: translateAbsyn2SCode2
This function takes an Absyn.Program
and constructs a SCode.Program from it.
This particular version of translate tries to fix any uniontypes
in the inProgram before translating further. This should probably
be moved into Parser.parse since you have to modify the tree every
single time you translate..."
input Absyn.Program inProgram;
input Boolean withInitial;
output SCode.Program outProgram;
algorithm
outProgram := match(inProgram,withInitial)
local
SCode.Program spInitial, spAbsyn, sp;
list<Absyn.Class> inClasses,initialClasses;

case _
case (_,_)
equation
setGlobalRoot(Global.instHashIndex, Inst.emptyInstHashTable());
setGlobalRoot(Global.typesIndex, Types.createEmptyTypeMemory());
Expand All @@ -87,6 +102,7 @@ algorithm
Absyn.PROGRAM(classes=inClasses) = MetaUtil.createMetaClassesInProgram(inProgram);

Absyn.PROGRAM(classes=initialClasses) = Builtin.getInitialFunctions();
initialClasses = Util.if_(withInitial,initialClasses,{});

// set the external flag that signals the presence of inner/outer components in the model
System.setHasInnerOuterDefinitions(false);
Expand All @@ -109,7 +125,7 @@ algorithm
then
sp;
end match;
end translateAbsyn2SCode;
end translateAbsyn2SCode2;

public function translate2
"Folds an Absyn.Program into SCode.Program."
Expand Down
18 changes: 11 additions & 7 deletions Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1102,21 +1102,25 @@ algorithm
then
(cache,Values.BOOL(true),newst);

case (cache,env,"list",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT("AllLoadedClasses"))),Values.BOOL(false),Values.BOOL(false),Values.BOOL(anyCode)},(st as Interactive.SYMBOLTABLE(ast = p)),_)
case (cache,env,"list",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT("AllLoadedClasses"))),Values.BOOL(false),Values.BOOL(false),Values.ENUM_LITERAL(name=path)},(st as Interactive.SYMBOLTABLE(ast = p)),_)
equation
str = Debug.bcallret2(not anyCode, Dump.unparseStr, p, false, "");
str = Debug.bcallret1(anyCode, System.anyStringCode, p, str);
name = Absyn.pathLastIdent(path);
str = Debug.bcallret2(name ==& "Absyn", Dump.unparseStr, p, false, "");
str = Debug.bcallret1(name ==& "Internal", System.anyStringCode, p, str);
then
(cache,Values.STRING(str),st);

case (cache,env,"list",{Values.CODE(Absyn.C_TYPENAME(path)),Values.BOOL(b1),Values.BOOL(b2),Values.BOOL(anyCode)},(st as Interactive.SYMBOLTABLE(ast = p)),_)
case (cache,env,"list",{Values.CODE(Absyn.C_TYPENAME(className)),Values.BOOL(b1),Values.BOOL(b2),Values.ENUM_LITERAL(name=path)},(st as Interactive.SYMBOLTABLE(ast = p)),_)
equation
absynClass = Interactive.getPathedClassInProgram(path, p);
name = Absyn.pathLastIdent(path);
absynClass = Interactive.getPathedClassInProgram(className, p);
absynClass = Debug.bcallret1(b1,Absyn.getFunctionInterface,absynClass,absynClass);
absynClass = Debug.bcallret1(b2,Absyn.getShortClass,absynClass,absynClass);
p = Absyn.PROGRAM({absynClass},Absyn.TOP(),Absyn.TIMESTAMP(0.0,0.0));
str = Debug.bcallret2(not anyCode, Dump.unparseStr, p, false, "");
str = Debug.bcallret1(anyCode, System.anyStringCode, p, str);
str = Debug.bcallret2(name ==& "Absyn", Dump.unparseStr, p, false, "");
str = Debug.bcallret1(name ==& "Internal", System.anyStringCode, p, str);
scodeP = Debug.bcallret2(name ==& "SCode", SCodeUtil.translateAbsyn2SCode2, p, false, {});
str = Debug.bcallret1(name ==& "SCode", SCodeDump.programStr, scodeP, str);
then
(cache,Values.STRING(str),st);

Expand Down

0 comments on commit f47473b

Please sign in to comment.