Skip to content

Commit

Permalink
generate documentation folder if Documentation annotation is present (O…
Browse files Browse the repository at this point in the history
…penModelica#12547)

* fix segmentation fault
* export model version to modeldescription.xml
* expected output
  • Loading branch information
arun3688 committed Jun 11, 2024
1 parent 597ea33 commit e2c9283
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 16 deletions.
4 changes: 3 additions & 1 deletion OMCompiler/Compiler/NSimCode/NSimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ public
record MODEL_INFO
Absyn.Path name;
String description;
String version;
String directory;
SimVars vars;
VarInfo varInfo;
Expand Down Expand Up @@ -618,7 +619,7 @@ public
VarInfo info;
algorithm
info := VarInfo.create(vars, eventInfo, simCodeIndices);
modelInfo := MODEL_INFO(name, "", directory, vars, info, functions, {}, {}, {}, 0, 0, 0, true, linearLoops, nonlinearLoops);
modelInfo := MODEL_INFO(name, "", "", directory, vars, info, functions, {}, {}, {}, 0, 0, 0, true, linearLoops, nonlinearLoops);
end create;

function setSeedVars
Expand Down Expand Up @@ -648,6 +649,7 @@ public
oldModelInfo := OldSimCode.MODELINFO(
name = modelInfo.name,
description = modelInfo.description,
version = modelInfo.version,
directory = modelInfo.directory,
varInfo = VarInfo.convert(modelInfo.varInfo),
vars = SimVar.SimVars.convert(modelInfo.vars),
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Script/Interactive.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7493,7 +7493,7 @@ algorithm
end matchcontinue;
end getDefaultAttr;

protected function getDefaultComponentPrefixesModStr "Extractor function for defaultComponentPrefixes modifier"
public function getDefaultComponentPrefixesModStr "Extractor function for defaultComponentPrefixes modifier"
input Option<Absyn.Modification> mod;
output String docStr;
algorithm
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/SimCode/SimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ uniontype ModelInfo "Container for metadata about a Modelica model."
record MODELINFO
Absyn.Path name;
String description;
String version;
String directory;
VarInfo varInfo;
SimCodeVar.SimVars vars;
Expand Down
30 changes: 21 additions & 9 deletions OMCompiler/Compiler/SimCode/SimCodeMain.mo
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ algorithm
String str, newdir, newpath, resourcesDir, dirname, htmlFile;
String fmutmp;
String guid;
Boolean b;
Boolean b, exportDocumentation;
Boolean needSundials = false;
String fileprefix;
String install_include_omc_dir, install_include_omc_c_dir, install_share_buildproject_dir, install_fmu_sources_dir, fmu_tmp_sources_dir;
Expand Down Expand Up @@ -834,10 +834,12 @@ algorithm
end if;

// create optional html documentation directory
Util.createDirectoryTree(fmutmp + "/documentation/");
htmlFile := exportHTMLDocumentation(program, simCode.modelInfo.name, FMUVersion);
if 0 <> System.systemCall("mv '" + htmlFile + "' '" + fmutmp + "/documentation/" + "'") then
Error.addInternalError("Failed to move documentation file " + htmlFile + "", sourceInfo());
(htmlFile, exportDocumentation) := exportHTMLDocumentation(program, simCode, FMUVersion);
if exportDocumentation then
Util.createDirectoryTree(fmutmp + "/documentation/");
if 0 <> System.systemCall("mv '" + htmlFile + "' '" + fmutmp + "/documentation/" + "'") then
Error.addInternalError("Failed to move documentation file " + htmlFile + "", sourceInfo());
end if;
end if;

SimCodeUtil.resetFunctionIndex();
Expand Down Expand Up @@ -1042,24 +1044,34 @@ protected function exportHTMLDocumentation
__OpenModelica_infoHeader = \"<html> </html>\"))
"
input Absyn.Program program;
input Absyn.Path className;
input SimCode.SimCode simCode;
input String FMUVersion;
output String fileName;
output Boolean export = true;
protected
File.File file;
String info, revisions, infoHeader;
algorithm
(info, revisions, infoHeader) := Interactive.getNamedAnnotation(className, program, Absyn.IDENT("Documentation"), SOME(("","","")),Interactive.getDocumentationAnnotationString);
(info, revisions, infoHeader) := Interactive.getNamedAnnotation(simCode.modelInfo.name, program, Absyn.IDENT("Documentation"), SOME(("","","")),Interactive.getDocumentationAnnotationString);

// do not export if Documentation annotation does not exist
if (stringEmpty(info) and stringEmpty(revisions) and stringEmpty(infoHeader)) then
export := false;
end if;

if (FMUVersion == "1.0") then
fileName := "_main.html";
else
fileName := "index.html";
end if;

file := File.File();
File.open(file, fileName, File.Mode.Write);
File.write(file, infoHeader + "\n");
File.write(file, "<h4> Information </h4>" + info + "\n");
File.write(file, "<h4> Revisions </h4>" + revisions + "\n");
File.write(file, "<h1>" + AbsynUtil.pathString(simCode.modelInfo.name) + "</h1>\n");
File.write(file, "<p> <i>" + simCode.modelInfo.description + "</i> </p> \n");
File.write(file, "<h4> <u> Information </u> </h4>" + info + "\n");
File.write(file, "<h4> <u> Revisions </u> </h4>" + revisions + "\n");
end exportHTMLDocumentation;

protected function callTargetTemplatesXML
Expand Down
6 changes: 4 additions & 2 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ import ZeroCrossings;
import ReduceDAE;
import Settings;
import UnorderedSet;
import Interactive;

protected constant String UNDERLINE = "========================================";

Expand Down Expand Up @@ -7676,7 +7677,7 @@ public function createModelInfo
input list<SimCodeVar.SimVar> tempVars;
output SimCode.ModelInfo modelInfo;
protected
String description, directory;
String description, directory, version;
SimCode.VarInfo varInfo;
SimCodeVar.SimVars vars;
Integer nx, ny, ndy, np, na, next, numOutVars, numInVars, ny_int, np_int, na_int, ny_bool, np_bool, dim_1, dim_2, numOptimizeConstraints, numOptimizeFinalConstraints, numRealInputVars;
Expand All @@ -7690,6 +7691,7 @@ algorithm
try
// name = AbsynUtil.pathStringNoQual(class_);
directory := System.trim(fileDir, "\"");
version := System.trim(Interactive.getNamedAnnotation(class_, program, Absyn.IDENT("version"), SOME(""), Interactive.getDefaultComponentPrefixesModStr), "\"");
(vars, unitDefinitions) := createVars(dlow, inInitDAE, tempVars);

if debug then execStat("simCode: createVars"); end if;
Expand Down Expand Up @@ -7721,7 +7723,7 @@ algorithm
if debug then execStat("simCode: createVarInfo"); end if;
hasLargeEqSystems := hasLargeEquationSystems(dlow, inInitDAE);
if debug then execStat("simCode: hasLargeEquationSystems"); end if;
modelInfo := SimCode.MODELINFO(class_, dlow.shared.info.description, directory, varInfo, vars, functions,
modelInfo := SimCode.MODELINFO(class_, dlow.shared.info.description, version, directory, varInfo, vars, functions,
labels,
if Flags.getConfigBool(Flags.BUILDING_FMU) then getResources(program.classes, dlow, inInitDAE) else {},
List.sort(program.classes, AbsynUtil.classNameGreater),
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/Template/CodegenFMU2.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ case SIMCODE(modelInfo = MODELINFO(varInfo = vi as VARINFO(__), vars = SIMVARS(s
let fmiVersion = '2.0'
let modelName = dotPath(modelInfo.name)
let description = modelInfo.description
let version = modelInfo.version
let generationTool= 'OpenModelica Compiler <%getVersionNr()%>'
let generationDateAndTime = xsdateTime(getCurrentDateTime())
let variableNamingConvention = 'structured'
Expand All @@ -122,6 +123,7 @@ case SIMCODE(modelInfo = MODELINFO(varInfo = vi as VARINFO(__), vars = SIMVARS(s
modelName="<%Util.escapeModelicaStringToXmlString(modelName)%>"
guid="{<%guid%>}"
description="<%Util.escapeModelicaStringToXmlString(description)%>"
version="<%Util.escapeModelicaStringToXmlString(version)%>"
generationTool="<%Util.escapeModelicaStringToXmlString(generationTool)%>"
generationDateAndTime="<%Util.escapeModelicaStringToXmlString(generationDateAndTime)%>"
variableNamingConvention="<%variableNamingConvention%>"
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/Template/SimCodeTV.mo
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ package SimCode
record MODELINFO
Absyn.Path name;
String description;
String version;
String directory;
VarInfo varInfo;
SimCodeVar.SimVars vars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"LocalIOs.System\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"ArrayEquationsTest\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ getErrorString();
// fmiVersion=\"2.0\"
// modelName=\"CSTRModel\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"SubClocks\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ val(evaporator_qm_S, 100);
// fmiVersion=\"2.0\"
// modelName=\"DrumBoilerModel\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"3\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"SIDTest\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ readFile("fmi_attributes_15_tmp.xml")
// fmiVersion=\"2.0\"
// modelName=\"fmi_attributes_15\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// teardown_command: rm -rf fmi_attributes_23.fmu fmi_attributes_23.log fmi_attributes_23_index.html fmi_attributes_23_info.json

loadString("
model fmi_attributes_23
model fmi_attributes_23 \"model description text example \"
parameter Real A = 2;
output Real B;
equation
Expand Down Expand Up @@ -46,10 +46,12 @@ readFile("fmi_attributes_23_index.html"); getErrorString();
// 0
// ""
// "<html><h2>TestModel</h2></html>
// <h4> Information </h4><html>
// <h1>fmi_attributes_23</h1>
// <p> <i>model description text example </i> </p>
// <h4> <u> Information </u> </h4><html>
// <p>The linear resistor connects the branch voltage <em>v</em> with the branch current <em>i</em> by <em>i*R = v</em>. The Resistance <em>R</em> is allowed to be positive, zero, or negative.</p>
// </html>
// <h4> Revisions </h4><html>
// <h4> <u> Revisions </u> </h4><html>
// <ul>
// <li><em> August 07, 2009 </em>
// by Anton Haumer<br> temperature dependency of resistance added<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"test_Bug2764\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"1\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"test_Bug3049\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"testDID\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ readFile("modelDescription.tmp.xml");
// fmiVersion=\"2.0\"
// modelName=\"testDID\"
// description=\"\"
// version=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
Expand Down

0 comments on commit e2c9283

Please sign in to comment.