Skip to content

Commit

Permalink
Refactor the File module
Browse files Browse the repository at this point in the history
The C-code was much larger than the Modelica code (and contained much
duplicated boilerplate code); it has been moved to its own file.

The File constructor was changed back to only taking one input (an
opaque pointer); it is no longer is passed NONE() but instead is passed
NULL (`File.noReference()`).
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Feb 21, 2017
1 parent a06724a commit 5aeafb1
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 445 deletions.
2 changes: 1 addition & 1 deletion Compiler/SimCode/SerializeInitXML.mo
Expand Up @@ -72,7 +72,7 @@ protected
ModelInfo modelInfo;
VarInfo vi;
SimulationSettings s;
File.File file = File.File(NONE(), simCode.fileNamePrefix + "_init.xml", true);
File.File file = File.File();
algorithm
try
File.open(file, simCode.fileNamePrefix + "_init.xml", File.Mode.Write);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/SimCode/SerializeModelInfo.mo
Expand Up @@ -66,7 +66,7 @@ function serializeWork "Always succeeds in order to clean-up external objects"
output Boolean success; // We always need to return in order to clean up external objects
output String fileName;
protected
File.File file = File.File(NONE(), code.fileNamePrefix + "_info.json", true);
File.File file = File.File();
algorithm
(success,fileName) := matchcontinue code
local
Expand Down
54 changes: 6 additions & 48 deletions Compiler/Template/Tpl.mo
Expand Up @@ -1031,7 +1031,7 @@ protected function tokFileText
input StringToken inStringToken;
input Boolean doHandleTok=true;
protected
File.File file = File.File(getTextOpaqueFile(inText), File.getFilename(getTextOpaqueFile(inText)), false);
File.File file = File.File(getTextOpaqueFile(inText));
Integer nchars, aind;
Boolean isstart;
algorithm
Expand Down Expand Up @@ -2462,7 +2462,7 @@ public function redirectToFile
input output Text text;
input String fileName;
protected
File.File file = File.File(NONE(), fileName, true);
File.File file = File.File();
algorithm
if Config.getRunningTestsuite() then
System.appendFile(Config.getRunningTestsuiteFile(), fileName + "\n");
Expand All @@ -2475,7 +2475,7 @@ public function closeFile
"Magic sourceInfo() function implementation"
input output Text text;
protected
File.File file = File.File(getTextOpaqueFile(text), File.getFilename(getTextOpaqueFile(text)), false);
File.File file = File.File(getTextOpaqueFile(text));
algorithm
File.releaseReference(file);
text := emptyTxt;
Expand Down Expand Up @@ -2507,7 +2507,7 @@ protected function stringFile "Like ST_STRING or ST_LINE"
input Boolean line;
input Boolean recurseSeparator=true;
protected
File.File file = File.File(getTextOpaqueFile(inText), File.getFilename(getTextOpaqueFile(inText)), false);
File.File file = File.File(getTextOpaqueFile(inText));
Integer nchars;
IterOptions iopts;
StringToken septok;
Expand Down Expand Up @@ -2543,7 +2543,7 @@ end stringFile;
protected function newlineFile "Like ST_NEWLINE"
input Text inText;
protected
File.File file = File.File(getTextOpaqueFile(inText), File.getFilename(getTextOpaqueFile(inText)), false);
File.File file = File.File(getTextOpaqueFile(inText));
Integer nchars;
algorithm
_ := match inText
Expand All @@ -2560,15 +2560,14 @@ protected function textFileTell
input Text inText;
output Integer tell;
protected
File.File file = File.File(getTextOpaqueFile(inText), File.getFilename(getTextOpaqueFile(inText)), false);
File.File file = File.File(getTextOpaqueFile(inText));
algorithm
tell := File.tell(file);
end textFileTell;

protected function handleTok "Handle a new token, for example separators"
input Text txt;
protected
// File.File file = File.File(getTextOpaqueFile(inText), File.getFilename(getTextOpaqueFile(inText)), false);
StringToken septok;
array<Option<StringToken>> aseptok;
algorithm
Expand All @@ -2593,46 +2592,5 @@ algorithm
end match;
end handleTok;

/*
protected function handleSeparatorTextFile
input Text txt;
input IterOptions iopts;
protected
File.File file = File.File(getTextOpaqueFile(inText), File.getFilename(getTextOpaqueFile(inText)), false);
Integer nchars, aind;
Boolean isstart;
algorithm
_ := match inText
case FILE_TEXT()
algorithm
nchars := arrayGet(inText.nchars, 1);
aind := arrayGet(inText.aind, 1);
isstart := arrayGet(inText.isstart, 1);
(nchars, isstart, aind) := handleSeparatorFile(file, iopts, nchars, isstart, aind);
arrayUpdate(inText.nchars, 1, nchars);
arrayUpdate(inText.aind, 1, aind);
arrayUpdate(inText.isstart, 1, isstart);
then ();
end match;
end handleSeparatorTextFile;
protected function handleSeparatorFile
input File.File file;
input IterOptions iopts;
input output Integer nchars;
input output Boolean isstart;
input output Integer aind;
algorithm
(nchars,isstart,aind) := match (iopts.separator, iopts.alignNum, iopts.wrapWidth)
case (NONE(),_,_) then (nchars,isstart,aind);
case (SOME(septok),0,0) then (nchars,isstart,aind);
else
algorithm
Error.addInternalError("haveSeparatorFile failed", sourceInfo());
then fail();
end match;
end handleSeparatorFile;
*/

annotation(__OpenModelica_Interface="susan");
end Tpl;

0 comments on commit 5aeafb1

Please sign in to comment.