Skip to content

Commit

Permalink
- Added API call saveTotalSCode to dump the result of SCodeFlatten to…
Browse files Browse the repository at this point in the history
… file.

- Use the +showAnnotations flag in SCodeDump to determine whether to dump
  annotations and comments or not.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9424 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Jul 6, 2011
1 parent 51ff596 commit 8b3d1a2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
7 changes: 7 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1011,6 +1011,13 @@ function save
external "builtin";
end save;

function saveTotalSCode
input String fileName;
input TypeName className;
output Boolean success;
external "builtin";
end saveTotalSCode;

function translateGraphics
input TypeName className;
output String result;
Expand Down
15 changes: 15 additions & 0 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -3507,7 +3507,22 @@ algorithm
end match;
end isConnector;

public function removeBuiltinsFromTopScope
input Program inProgram;
output Program outProgram;
algorithm
outProgram := Util.listFilter(inProgram, isNotBuiltinClass);
end removeBuiltinsFromTopScope;

protected function isNotBuiltinClass
input Element inClass;
algorithm
_ := match(inClass)
case CLASS(classDef = PARTS(externalDecl =
SOME(EXTERNALDECL(lang = SOME("builtin"))))) then fail();
else ();
end match;
end isNotBuiltinClass;

end SCode;

18 changes: 17 additions & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -87,6 +87,8 @@ protected import Parser;
protected import Print;
protected import Refactor;
protected import RTOpts;
protected import SCodeDump;
protected import SCodeFlatten;
protected import SimCode;
protected import System;
protected import Static;
Expand Down Expand Up @@ -725,7 +727,7 @@ algorithm
String functionName;
list<Values.Value> vals;
Absyn.Path path,p1,classpath,className;
list<SCode.Element> scodeP,sp;
SCode.Program scodeP,sp;
Option<list<SCode.Element>> fp;
list<Env.Frame> env;
SCode.Element c;
Expand Down Expand Up @@ -1468,6 +1470,20 @@ algorithm
then
(cache,Values.BOOL(false),st);

case (cache, env, "saveTotalSCode",
{Values.STRING(filename), Values.CODE(Absyn.C_TYPENAME(classpath))}, st, msg)
equation
(scodeP, st) = Interactive.symbolTableToSCode(st);
scodeP = SCodeFlatten.flattenClassInProgram(classpath, scodeP);
scodeP = SCode.removeBuiltinsFromTopScope(scodeP);
str = SCodeDump.programStr(scodeP);
System.writeFile(filename, str);
then
(cache, Values.BOOL(true), st);

case (cache, env, "saveTotalSCode", _, st, msg)
then (cache, Values.BOOL(false), st);

case (cache,env,"getAstAsCorbaString",{Values.STRING("<interactive>")},st as Interactive.SYMBOLTABLE(ast=p),msg)
equation
Print.clearBuf();
Expand Down
29 changes: 17 additions & 12 deletions Compiler/susan_codegen/SimCode/SCodeDumpTpl.tpl
Expand Up @@ -895,12 +895,16 @@ end dumpAnnotationOpt;

template dumpAnnotation(SCode.Annotation annotation)
::=
match annotation
case ANNOTATION(__) then ' annotation<%dumpModifier(modification)%>'
if RTOpts.showAnnotations() then
match annotation
case ANNOTATION(__) then ' annotation<%dumpModifier(modification)%>'
end dumpAnnotation;

template dumpAnnotationElement(SCode.Annotation annotation)
::= '<%dumpAnnotation(annotation)%>;'
::=
let annstr = '<%dumpAnnotation(annotation)%>'
if annstr then
'<%annstr%>;'
end dumpAnnotationElement;

template dumpExternalDeclOpt(Option<ExternalDecl> externalDecl)
Expand All @@ -925,15 +929,16 @@ end dumpCommentOpt;

template dumpComment(SCode.Comment comment)
::=
match comment
case COMMENT(__) then
let ann_str = dumpAnnotationOpt(annotation_)
let cmt_str = dumpCommentStr(comment)
'<%cmt_str%><%ann_str%>'
case CLASS_COMMENT(__) then
let annl_str = (annotations |> ann => dumpAnnotation(ann) ;separator="\n")
let cmt_str = dumpCommentOpt(comment)
'<%cmt_str%><%annl_str%>'
if RTOpts.showAnnotations() then
match comment
case COMMENT(__) then
let ann_str = dumpAnnotationOpt(annotation_)
let cmt_str = dumpCommentStr(comment)
'<%cmt_str%><%ann_str%>'
case CLASS_COMMENT(__) then
let annl_str = (annotations |> ann => dumpAnnotation(ann) ;separator="\n")
let cmt_str = dumpCommentOpt(comment)
'<%cmt_str%><%annl_str%>'
end dumpComment;

template dumpCommentStr(Option<String> comment)
Expand Down
6 changes: 6 additions & 0 deletions Compiler/susan_codegen/SimCode/SCodeTV.mo
Expand Up @@ -771,4 +771,10 @@ package Tpl
end addTemplateError;
end Tpl;

package RTOpts
function showAnnotations
output Boolean show;
end showAnnotations;
end RTOpts;

end SCodeTV;

0 comments on commit 8b3d1a2

Please sign in to comment.