Skip to content

Commit

Permalink
+ Handle protected elements too when evaluating records.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14927 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Jan 25, 2013
1 parent 4924382 commit 708ea57
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -18562,7 +18562,7 @@ algorithm
(inputs,locals) = List.extractOnTrue(vars, Types.isModifiableTypesVar);
inputs = List.map(inputs,Types.setVarDefaultInput);
locals = List.map(locals,Types.setVarProtected);
vars = List.union(inputs,locals);
vars = listAppend(inputs,locals);

// path = Env.joinEnvPath(recordEnv, path);
path = Absyn.makeFullyQualified(path);
Expand Down
22 changes: 22 additions & 0 deletions Compiler/FrontEnd/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3094,6 +3094,28 @@ algorithm
end matchcontinue;
end isModifiableTypesVar;

public function getBindingExp
input DAE.Var inVar;
input Absyn.Path inPath;
output DAE.Exp outExp;
algorithm
outExp := match(inVar, inPath)
local
DAE.Exp exp;
String str;
Ident name;

case(DAE.TYPES_VAR(binding=DAE.EQBOUND(exp=exp)), _) then exp;
case(DAE.TYPES_VAR(name=name, binding=DAE.UNBOUND()), _)
equation
str = "Record '" +& Absyn.pathString(inPath) +& "' member '" +& name +& "' has no default value and is not modifiable by a constructor function.\n";
Error.addCompilerWarning(str);
then
DAE.ICONST(0);
end match;
end getBindingExp;


public function isConstAttr
input Attributes inAttributes;
output Boolean outIsPublic;
Expand Down
17 changes: 11 additions & 6 deletions Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6840,13 +6840,13 @@ algorithm
DAE.Exp e;
Absyn.Path funcpath;
list<DAE.Exp> expl;
list<Values.Value> vallst;
list<Values.Value> vallst, pubVallst, proVallst;
Ceval.Msg msg;
Env.Cache cache;
Option<Interactive.SymbolTable> st;
Absyn.Path complexName;
list<Expression.Var> varLst;
list<String> varNames;
list<Expression.Var> pubVarLst, proVarLst, varLst;
list<String> pubVarNames, proVarNames, varNames;
DAE.Type ty;
Absyn.Info info;
String str;
Expand All @@ -6866,12 +6866,17 @@ algorithm
fail();

// Record constructors
case(cache,env,(e as DAE.CALL(path = funcpath,attr = DAE.CALL_ATTR(ty = DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(complexName), varLst=varLst)))),vallst,_,st,msg)
case(cache,env,(e as DAE.CALL(path = funcpath,attr = DAE.CALL_ATTR(ty = DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(complexName), varLst=varLst)))),pubVallst,_,st,msg)
equation
Debug.fprintln(Flags.DYN_LOAD, "CALL: record constructor: func: " +& Absyn.pathString(funcpath) +& " type path: " +& Absyn.pathString(complexName));
true = Absyn.pathEqual(funcpath,complexName);
varLst = List.filterOnTrue(varLst,Types.isPublicVar);
varNames = List.map(varLst,Expression.varName);
(pubVarLst,proVarLst) = List.splitOnTrue(varLst,Types.isPublicVar);
expl = List.map1(proVarLst, Types.getBindingExp, funcpath);
(cache,proVallst,st) = cevalList(cache, env, expl, impl, st, msg);
pubVarNames = List.map(pubVarLst,Expression.varName);
proVarNames = List.map(proVarLst,Expression.varName);
varNames = listAppend(pubVarNames, proVarNames);
vallst = listAppend(pubVallst, proVallst);
Debug.fprintln(Flags.DYN_LOAD, "CALL: record constructor: [success] func: " +& Absyn.pathString(funcpath));
then
(cache,Values.RECORD(funcpath,vallst,varNames,-1),st);
Expand Down

0 comments on commit 708ea57

Please sign in to comment.