Skip to content

Commit

Permalink
- Guard some macros in f2c.h so they don't mess with C++ headers
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5969 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 27, 2010
1 parent fcd11b3 commit 99c1416
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Compiler/SimCodeC.mo
Expand Up @@ -6995,6 +6995,7 @@ public function functionsFile
algorithm
out_txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({
"#include \"modelica.h\"\n",
"#include <algorithm>\n",
"#include <stdio.h>\n",
"#include <stdlib.h>\n",
"#include <errno.h>\n",
Expand Down Expand Up @@ -22187,7 +22188,7 @@ algorithm
equation
(i_var1, i_preExp, i_varDecls) = daeExp(emptyTxt, i_e1, i_context, i_preExp, i_varDecls);
(i_var2, i_preExp, i_varDecls) = daeExp(emptyTxt, i_e2, i_context, i_preExp, i_varDecls);
txt = Tpl.writeTok(txt, Tpl.ST_STRING("max("));
txt = Tpl.writeTok(txt, Tpl.ST_STRING("std::max("));
txt = Tpl.writeText(txt, i_var1);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(","));
txt = Tpl.writeText(txt, i_var2);
Expand All @@ -22207,7 +22208,7 @@ algorithm
equation
(i_var1, i_preExp, i_varDecls) = daeExp(emptyTxt, i_e1, i_context, i_preExp, i_varDecls);
(i_var2, i_preExp, i_varDecls) = daeExp(emptyTxt, i_e2, i_context, i_preExp, i_varDecls);
txt = Tpl.writeTok(txt, Tpl.ST_STRING("min("));
txt = Tpl.writeTok(txt, Tpl.ST_STRING("std::min("));
txt = Tpl.writeText(txt, i_var1);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(","));
txt = Tpl.writeText(txt, i_var2);
Expand Down
6 changes: 4 additions & 2 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -1759,6 +1759,7 @@ template functionsFile(list<Function> functions,
::=
<<
#include "modelica.h"
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand Down Expand Up @@ -3976,12 +3977,12 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
path=IDENT(name="max"), expLst={e1,e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
let var2 = daeExp(e2, context, &preExp, &varDecls)
'max(<%var1%>,<%var2%>)'
'std::max(<%var1%>,<%var2%>)'
case CALL(tuple_=false, builtin=true,
path=IDENT(name="min"), expLst={e1,e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
let var2 = daeExp(e2, context, &preExp, &varDecls)
'min(<%var1%>,<%var2%>)'
'std::min(<%var1%>,<%var2%>)'
case CALL(tuple_=false, builtin=true,
path=IDENT(name="abs"), expLst={e1}, ty = ET_INT()) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
Expand Down Expand Up @@ -4063,6 +4064,7 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
let &preExp += '<%tvar%> = MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(<%expPart%>), <%i%>));<%\n%>'
tvar
case CALL(tuple_=false, builtin=true, path=IDENT(name = "mmc_unbox_record"),

expLst={s1}, ty=ty) then
let argStr = daeExp(s1, context, &preExp, &varDecls)
unboxRecord(argStr, ty, &preExp, &varDecls)
Expand Down
2 changes: 2 additions & 0 deletions c_runtime/f2c.h
Expand Up @@ -174,6 +174,7 @@ struct Namelist {
};
typedef struct Namelist Namelist;

#ifndef __cplusplus
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (doublereal)abs(x)
#define min(a,b) ((a) <= (b) ? (a) : (b))
Expand All @@ -183,6 +184,7 @@ typedef struct Namelist Namelist;
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#endif

/* procedure parameter types for -A and -C++ */

Expand Down
8 changes: 4 additions & 4 deletions c_runtime/meta_modelica_builtin.cpp
Expand Up @@ -86,12 +86,12 @@ intMod_rettype intMod(modelica_integer i1, modelica_integer i2)

intMax_rettype intMax(modelica_integer i1, modelica_integer i2)
{
return max(i1,i2);
return i1 > i2 ? i1 : i2;
}

intMin_rettype intMin(modelica_integer i1, modelica_integer i2)
{
return min(i1,i2);
return i1 < i2 ? i1 : i2;
}

intLt_rettype intLt(modelica_integer i1, modelica_integer i2)
Expand Down Expand Up @@ -182,12 +182,12 @@ realPow_rettype realPow(modelica_real r1, modelica_real r2)

realMax_rettype realMax(modelica_real r1, modelica_real r2)
{
return max(r1,r2);
return r1 > r2 ? r1 : r2;
}

realMin_rettype realMin(modelica_real r1, modelica_real r2)
{
return min(r1,r2);
return r1 < r2 ? r1 : r2;
}

realAbs_rettype realAbs(modelica_real r)
Expand Down
2 changes: 1 addition & 1 deletion c_runtime/modelica.h
Expand Up @@ -65,9 +65,9 @@ typedef void(* modelica_fnptr) (void); /*MetaModelica extension, function pointe

#include <assert.h>
#include "read_write.h"
#include "matrix.h"
#include "meta_modelica.h"
#include "meta_modelica_builtin.h"
#include "matrix.h"


typedef real_array_t real_array;
Expand Down

0 comments on commit 99c1416

Please sign in to comment.