Skip to content

Commit

Permalink
- Added list API to get short class definitions only
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10796 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 20, 2011
1 parent cb88204 commit c8b7740
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 16 deletions.
47 changes: 47 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -5393,6 +5393,53 @@ algorithm
ge := not pathLt(path1,path2);
end pathGe;

public function getShortClass "Strips out long class definitions"
input Class cl;
output Class o;
algorithm
o := match cl
local
Ident name;
Boolean pa, fi, en;
Restriction re;
ClassDef body;
Info info;
case CLASS(body=PARTS(comment=_)) then fail();
case CLASS(body=CLASS_EXTENDS(comment=_)) then fail();
case CLASS(name,pa,fi,en,re,body,info)
equation
body = stripClassDefComment(body);
then CLASS(name,pa,fi,en,re,body,info);
end match;
end getShortClass;

protected function stripClassDefComment "Strips out long class definitions"
input ClassDef cl;
output ClassDef o;
algorithm
o := match cl
local
EnumDef enumLiterals;
TypeSpec typeSpec;
ElementAttributes attributes;
list<ElementArg> arguments;
list<Path> functionNames;
Path functionName;
list<Ident> vars;
list<String> typeVars;
Ident baseClassName;
list<ElementArg> modifications;
list<ClassPart> parts;
case PARTS(typeVars,parts,_) then PARTS(typeVars,parts,NONE());
case CLASS_EXTENDS(baseClassName,modifications,_,parts) then CLASS_EXTENDS(baseClassName,modifications,NONE(),parts);
case DERIVED(typeSpec,attributes,arguments,_) then DERIVED(typeSpec,attributes,arguments,NONE());
case ENUMERATION(enumLiterals,_) then ENUMERATION(enumLiterals,NONE());
case OVERLOAD(functionNames,_) then OVERLOAD(functionNames,NONE());
case PDER(functionName,vars,_) then PDER(functionName,vars,NONE());
else cl;
end match;
end stripClassDefComment;

public function getFunctionInterface "Strips out the parts of a function definition that are not needed for the interface"
input Class cl;
output Class o;
Expand Down
15 changes: 10 additions & 5 deletions Compiler/FrontEnd/Dump.mo
Expand Up @@ -103,17 +103,22 @@ public function unparseStr
"function: unparseStr
Prettyprints the Program, i.e. the whole AST, to a string."
input Absyn.Program inProgram;
input Boolean inBoolean "Used by MathCore, and dependencies to other modules requires this to also be in OpenModelica. Contact peter.aronsson@mathcore.com for
explanation";
input Boolean markup "
Used by MathCore, and dependencies to other modules requires this to also be in OpenModelica.
Contact peter.aronsson@mathcore.com for an explanation.
Note: This will be used for a different purpose in OpenModelica once we redesign Dump to use templates
... by sending in DumpOptions (for example to add markup, etc)
";
output String outString;
algorithm
outString := matchcontinue (inProgram,inBoolean)
outString := matchcontinue (inProgram,markup)
local
Ident s1,s2,str;
list<Absyn.Class> cs;
Absyn.Within w;
case (Absyn.PROGRAM(classes = {}),_) then "";
case (Absyn.PROGRAM(classes = cs,within_ = w),_)
case (Absyn.PROGRAM(classes = cs,within_ = w),markup)
equation
s1 = unparseWithin(0, w);
s2 = unparseClassList(0, cs);
Expand All @@ -124,7 +129,7 @@ algorithm
end matchcontinue;
end unparseStr;

public function unparseClassList
protected function unparseClassList
"function: unparseClassList
Prettyprints a list of classes"
input Integer inInteger;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1627,6 +1627,7 @@ end stringReplace;
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";
output String contents;
external "builtin";
annotation(Documentation(info="<html>
Expand All @@ -1635,6 +1636,7 @@ Pretty-prints a class definition.
<blockquote>
<pre><b>list</b>(Modelica.Math.sin)</pre>
<pre><b>list</b>(Modelica.Math.sin,interfaceOnly=true)</pre>
</blockquote>
<h4>Description</h4>
<p>list() pretty-prints the whole of the loaded AST while list(className) lists a class and its children.
It keeps all annotations and comments intact but strips out any comments and normalizes white-space.</p>
Expand Down
7 changes: 4 additions & 3 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -764,7 +764,7 @@ algorithm
list<String> vars_1,vars_2,args,strings,strVars,strs,visvars;
Real t1,t2,time,timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2;
Interactive.Statements istmts;
Boolean bval, b, externalWindow, legend, grid, logX, logY, points, gcc_res, omcfound, rm_res, touch_res, uname_res, extended, insensitive,ifcpp, sort, builtin;
Boolean bval, b, b1, b2, externalWindow, legend, grid, logX, logY, points, gcc_res, omcfound, rm_res, touch_res, uname_res, extended, insensitive,ifcpp, sort, builtin;
Env.Cache cache;
list<Interactive.LoadedFile> lf;
AbsynDep.Depends aDep;
Expand Down Expand Up @@ -993,10 +993,11 @@ algorithm
then
(cache,Values.STRING(str),st);

case (cache,env,"list",{Values.CODE(Absyn.C_TYPENAME(path)),Values.BOOL(b)},(st as Interactive.SYMBOLTABLE(ast = p)),msg)
case (cache,env,"list",{Values.CODE(Absyn.C_TYPENAME(path)),Values.BOOL(b1),Values.BOOL(b2)},(st as Interactive.SYMBOLTABLE(ast = p)),msg)
equation
absynClass = Interactive.getPathedClassInProgram(path, p);
absynClass = Debug.bcallret1(b,Absyn.getFunctionInterface,absynClass,absynClass);
absynClass = Debug.bcallret1(b1,Absyn.getFunctionInterface,absynClass,absynClass);
absynClass = Debug.bcallret1(b2,Absyn.getShortClass,absynClass,absynClass);
str = Dump.unparseStr(Absyn.PROGRAM({absynClass},Absyn.TOP(),Absyn.TIMESTAMP(0.0,0.0)),false) ;
then
(cache,Values.STRING(str),st);
Expand Down
46 changes: 38 additions & 8 deletions Examples/GenerateDoc.mos
Expand Up @@ -30,7 +30,7 @@
*/

/*
* Generates Modelica documentation automatically in about 30 minutes
* Generates Modelica documentation automatically in about 8 minutes on Linux, 30 on Windows
* Includes Modelica standard libraries
* Most Modelica builtin operators
* Some non-Modelica-but-used-in-MSL operators
Expand Down Expand Up @@ -113,7 +113,10 @@ function head
protected
String compound := \"\", file;
algorithm
head := \"<title>\"+sum(s + \".\" for s in strs[1:end-1])+strs[end]+\"</title>\n<h1><a href = \\\"index.html\\\">.</a>\";
head :=
\" <link href=\\\"style.css\\\" rel=\\\"stylesheet\\\" type=\\\"text/css\\\" />
<title>\"+sum(s + \".\" for s in strs[1:end-1])+strs[end]+\"</title>
<h1><a href = \\\"index.html\\\">.</a>\";
for ident in strs[1:end-1] loop
compound := if compound == \"\" then ident else compound+\".\"+ident;
file := compound+\".html\";
Expand All @@ -130,10 +133,10 @@ protected
String docInfo, revision;
algorithm
docInfo := if item.docInfo[1] == \"\" or (not OpenModelica.Scripting.regexBool(docInfo,\"^.*<[Hh][Tt][Mm][Ll]>.*$\"))
then preSuffixIfNotEmpty(\"<pre>\", item.comment, \"</pre>\")
else item.docInfo[1];
then preSuffixIfNotEmpty(\"<h2>Information:</h2><pre>\", item.comment, \"</pre>\")
else \"<h2>Information:</h2>\" + item.docInfo[1];
revision := if item.docInfo[2] <> \"\" then \"<h2>Revisions:</h2>\" + item.docInfo[2] else \"\";
res := item.head + docInfo + item.interface + item.contents + revision + version;
res := item.head + docInfo + item.interface + item.short + item.contents + revision + version;
end itemString;

function itemFile
Expand All @@ -148,6 +151,7 @@ record Item
String contents;
String comment;
String interface;
String short;
end Item;
");

Expand All @@ -166,7 +170,8 @@ items:={Item(
"</table>"
),
OpenModelica.Scripting.getClassComment(c),
preSuffixIfNotEmpty("\n<h4>Interface</h4>\n<blockquote><pre>",OpenModelica.Scripting.list(c,interfaceOnly=true),"</pre></blockquote>")
preSuffixIfNotEmpty("\n<h4>Interface</h4>\n<blockquote><pre>",OpenModelica.Scripting.list(c,interfaceOnly=true),"</pre></blockquote>"),
preSuffixIfNotEmpty("\n<h4>Definition</h4>\n<blockquote><pre>",OpenModelica.Scripting.list(c,shortOnly=true),"</pre></blockquote>")
) for c in b};
print("Start writing items to file");
echo(true);
Expand All @@ -177,7 +182,7 @@ getErrorString();
dirs := "";
replaceCommands := "";
filetmp := "index.html";
writeFile(filetmp, "<html><head><title>Modelica Documentation</title></head><body><h1>Modelica Documentation</h1>\n");
writeFile(filetmp, "<html><head><title>Modelica Documentation</title><link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" /></head><body><h1>Modelica Documentation</h1>\n");
writeFile(filetmp, "<p>This is a listing of builtin Modelica functions, libraries shipped with OpenModelica and the documentation for OpenModelica-specific scripting.</p>\n", append = true);
writeFile(filetmp, "<h2>Contents</h2>\n", append = true);
writeFile(filetmp, "<table><tr><th>Name</th><th>Description</th><th>Version</th></tr>", append = true);
Expand Down Expand Up @@ -256,6 +261,31 @@ for f in `cat tmp`; do
done
");

writeFile("style.css","
table
{
border-color: black;
border-width: 1px 1px 1px 1px;
border-style: solid;
border-spacing: 0;
border-collapse: collapse;
}

table td,th
{
border-color: black;
border-width: 1px 1px 1px 1px;
border-style: solid;
margin: 0;
padding: 4px;
}

pre
{
white-space: pre-wrap; /* CSS 3 */
}
");

system("rm -f tidy.log tidy.2.log");
system("mkdir -p old-html-tmp");
system("cp *.html old-html-tmp/");
Expand All @@ -267,6 +297,6 @@ system("rm -f ModelicaDocumentation.tar.xz");
system("mkdir -p " + dirs);
"tar";
dirs;
cmd := "tar cJf ModelicaDocumentation.tar.xz --dereference *.html " + dirs + " GenerateDoc.mos FindFiles.log tidy.log";
cmd := "tar cJf ModelicaDocumentation.tar.xz --dereference style.css *.html " + dirs + " GenerateDoc.mos FindFiles.log tidy.log";
system(cmd);
getErrorString();

0 comments on commit c8b7740

Please sign in to comment.