Skip to content

Commit

Permalink
- consider that functions containing external declarations are complete.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15810 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Apr 14, 2013
1 parent e833582 commit 1597b90
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Compiler/FrontEnd/Inline.mo
Expand Up @@ -1522,6 +1522,7 @@ algorithm
VarTransform.VariableReplacements repl;
Boolean generateEvents,b;
Option<SCode.Comment> comment;

case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_)))
equation
false = Config.acceptMetaModelicaGrammar();
Expand All @@ -1545,6 +1546,7 @@ algorithm
((newExp1,(fns1,b))) = Expression.traverseExp(newExp,forceInlineCall,(fns,true));
then
((newExp1,(fns,b)));

else inTuple;
end matchcontinue;
end forceInlineCall;
Expand Down Expand Up @@ -2032,7 +2034,7 @@ algorithm
list<DAE.Subscript> subs;
case({},_)
equation
Debug.fprintln(Flags.FAILTRACE,"Inline.getExpFromArgMap failed");
Debug.fprintln(Flags.FAILTRACE,"Inline.getExpFromArgMap failed with empty argmap and cref: " +& ComponentReference.printComponentRefStr(inComponentRef));
then
fail();
case((cref,exp) :: cdr,key)
Expand Down
9 changes: 9 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2028,6 +2028,15 @@ external "builtin";
annotation(preferredView="text");
end simulate;

function moveClass
"moves a class up or down depending on the given direction,
it returns true if the move was performed or false if we
could not move the class"
input TypeName className "the class that should be moved";
input String direction "up or down";
output Boolean result;
end moveClass;

function linearize "creates a model with the symbolic linearization matrixes.
At stopTime the linearization matrixes are evaluated and a modelica model is created.
The only required argument is the className, while all others have some efault values.
Expand Down
95 changes: 94 additions & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -871,7 +871,7 @@ algorithm
title,xLabel,yLabel,filename2,varNameStr,xml_filename,xml_contents,visvar_str,pwd,omhome,omlib,omcpath,os,
platform,usercflags,senddata,res,workdir,gcc,confcmd,touch_file,uname,filenameprefix,compileDir,libDir,exeDir,configDir,from,to,
legendStr, gridStr, logXStr, logYStr, x1Str, x2Str, y1Str, y2Str,scriptFile,logFile, simflags2, outputFile,
systemPath, gccVersion, gd, strlinearizeTime;
systemPath, gccVersion, gd, strlinearizeTime, direction;
list<Values.Value> vals;
Absyn.Path path,classpath,className,baseClassPath;
SCode.Program scodeP,sp;
Expand Down Expand Up @@ -1461,6 +1461,43 @@ algorithm
then
(cache,simValue,st);

// adrpo: see if the model exists before moving!
case (cache,env,"moveClass",vals as {Values.CODE(Absyn.C_TYPENAME(className)),
Values.STRING(direction)},
st as Interactive.SYMBOLTABLE(ast = p),_)
equation
crefCName = Absyn.pathToCref(className);
false = Interactive.existClass(crefCName, p);
simValue = Values.BOOL(false);
then
(cache,simValue,st);

// everything should work fine here
case (cache,env,"moveClass",vals as {Values.CODE(Absyn.C_TYPENAME(className)),
Values.STRING(direction)},
st as Interactive.SYMBOLTABLE(ast = p),_)
equation
crefCName = Absyn.pathToCref(className);
true = Interactive.existClass(crefCName, p);
p = moveClass(className, direction, p);
st = Interactive.setSymbolTableAST(st, p);
simValue = Values.BOOL(true);
then
(cache,simValue,st);

// adrpo: some error happened!
case (cache,env,"moveClass",vals as {Values.CODE(Absyn.C_TYPENAME(className)),
Values.STRING(direction)},
st as Interactive.SYMBOLTABLE(ast = p),_)
equation
crefCName = Absyn.pathToCref(className);
true = Interactive.existClass(crefCName, p);
errMsg = "moveClass Error: Could not move the model " +& Absyn.pathString(className) +& ". Unknown error.";
Error.addMessage(Error.INTERNAL_ERROR, {errMsg});
simValue = Values.BOOL(false);
then
(cache,simValue,st);

case (cache,env,"linearize",(vals as Values.CODE(Absyn.C_TYPENAME(className))::_),st_1,_)
equation

Expand Down Expand Up @@ -3392,6 +3429,55 @@ algorithm
end matchcontinue;
end getListNthShowError;

protected function moveClass
input Absyn.Path inClassName;
input String inDirection;
input Absyn.Program inProg;
output Absyn.Program outProg;
algorithm
outProg := matchcontinue(inClassName, inDirection, inProg)
local
Absyn.Path c, parent;
Absyn.Program p;
list<Absyn.Class> cls;
Absyn.Within w;
Absyn.TimeStamp gbt;
String name;
Absyn.Class parentClass;

case (Absyn.FULLYQUALIFIED(c), _, _)
equation
p = moveClass(c, inDirection, inProg);
then
p;

case (Absyn.IDENT(name), _, Absyn.PROGRAM(cls, w, gbt))
equation
cls = moveClassInList(name, cls, inDirection);
p = Absyn.PROGRAM(cls, w, gbt);
then
p;

case (Absyn.QUALIFIED(_, _), _, p)
equation
name = Absyn.pathLastIdent(inClassName);
parent = Absyn.stripLast(inClassName);
parentClass = Interactive.getPathedClassInProgram(parent, p);
then
p;

end matchcontinue;
end moveClass;

protected function moveClassInList
input String inClassName;
input list<Absyn.Class> inCls;
input String inDirection;
output list<Absyn.Class> outCls;
algorithm
outCls := inCls;
end moveClassInList;

protected function buildModel "function buildModel
author: x02lucpo
translates and builds the model by running compiler script on the generated makefile"
Expand Down Expand Up @@ -6954,6 +7040,13 @@ algorithm
Env.Env env;
Absyn.Path fpath;

// external functions are complete :)
case (cache, env, fpath)
equation
(_, SCode.CLASS(classDef = SCode.PARTS(externalDecl = SOME(_))), _) = Lookup.lookupClass(cache, env, fpath, false);
then
true;

// if is partial instantiation no function evaluation/generation
case (cache, env, fpath)
equation
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -2372,6 +2372,11 @@ package ComponentReference
input DAE.ComponentRef inRef;
output DAE.Type res;
end crefLastType;

function crefTypeConsiderSubs
input DAE.ComponentRef cr;
output DAE.Type res;
end crefTypeConsiderSubs;

function appendStringCref
input String str;
Expand Down

0 comments on commit 1597b90

Please sign in to comment.