Skip to content

Commit

Permalink
- escape string literals when generating C code as they might have \n…
Browse files Browse the repository at this point in the history
… in them which will fail to compile

  with a syntactic error.
- added Util.escapeModelicaStringToCString to Util.mo

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/OpenModelica1.5.0@4326 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 10, 2009
1 parent ae99f50 commit e7272b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
23 changes: 2 additions & 21 deletions Compiler/Codegen.mo
Expand Up @@ -51,37 +51,17 @@ public import Absyn;
public import Convert;
public import MetaUtil;

public
public
type Ident = String;

public
type ReturnType = String;

public
type FunctionName = String;

public
type ArgumentDeclaration = String;

public
type VariableDeclaration = String;

public
type InitStatement = String;

public
type Statement = String;

public
type CleanupStatement = String;

public
type ReturnTypeStruct = list<String>;

public
type Include = String;

public
type Lib = String;

public
Expand Down Expand Up @@ -3963,6 +3943,7 @@ algorithm
local String stmt,tvar_data; CFunction cfn;
equation
(decl,tvar,tnr1_1) = generateTempDecl("modelica_string", tnr);
s = Util.escapeModelicaStringToCString(s);
stmt = Util.stringAppendList({"init_modelica_string(&",tvar,",\"",s,"\");"});
cfn = cAddStatements(cEmptyFunction, {stmt});
cfn = cAddVariables(cfn, {decl});
Expand Down
16 changes: 16 additions & 0 deletions Compiler/Util.mo
Expand Up @@ -5041,5 +5041,21 @@ algorithm
out;
end matchcontinue;
end listProduct_acc;

public function escapeModelicaStringToCString
input String modelicaString;
output String cString;
algorithm
cString := matchcontinue (modelicaString)
local
String s, sOut;
case (s)
equation
sOut = System.stringReplace(s, "\n", "\\n");
then
sOut;
end matchcontinue;
end escapeModelicaStringToCString;

end Util;

0 comments on commit e7272b4

Please sign in to comment.