Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Reject models that contain external declarations


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10862 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 5, 2012
1 parent c094e25 commit 0a154cf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
40 changes: 36 additions & 4 deletions Compiler/FrontEnd/ClassInf.mo
Expand Up @@ -171,6 +171,8 @@ uniontype Event "- Events"

record FOUND_CONSTRAINT "There are constranit (equations) inside the current definition" end FOUND_CONSTRAINT;

record FOUND_EXT_DECL "There is an external declaration inside the current definition" end FOUND_EXT_DECL;

record NEWDEF "A definition with elements, i.e. a long definition" end NEWDEF;

record FOUND_COMPONENT " A Definition that contains components"
Expand Down Expand Up @@ -362,10 +364,12 @@ algorithm
str := match (inEvent)
local
String name;
case FOUND_EQUATION() then "FOUND_EQUATION";
case FOUND_CONSTRAINT() then "FOUND_CONSTRAINT";
case NEWDEF() then "NEWDEF";
case FOUND_COMPONENT(name) then "FOUND_COMPONENT(" +& name +& ")";
case FOUND_EQUATION() then "equation";
case FOUND_CONSTRAINT() then "constraint";
case NEWDEF() then "new definition";
case FOUND_COMPONENT(name) then "component " +& name;
case FOUND_EXT_DECL() then "external function declaration";
else "Unknown event";
end match;
end printEventStr;

Expand Down Expand Up @@ -484,6 +488,9 @@ algorithm
case (HAS_RESTRICTIONS(path=p,hasEquations=b1,hasAlgorithms=b2,hasConstraints=b3),FOUND_CONSTRAINT()) then HAS_RESTRICTIONS(p,b1,b2,true);
case (HAS_RESTRICTIONS(path=p,hasEquations=b1,hasAlgorithms=b2,hasConstraints=b3),FOUND_ALGORITHM()) then HAS_RESTRICTIONS(p,b1,true,b3);

case (FUNCTION(path = p),FOUND_EXT_DECL()) then inState;
case (_,FOUND_EXT_DECL()) then fail();

case (_,FOUND_EQUATION()) then fail();
case (_,FOUND_CONSTRAINT()) then fail();

Expand Down Expand Up @@ -587,6 +594,31 @@ algorithm
end matchcontinue;
end assertValid;

public function assertTrans "function: assertTrans
This function has the same semantical meaning as the function
`trans\'. However, it prints an error message when it fails."
input State inState;
input Event event;
input Absyn.Info info;
output State outState;
algorithm
outState := matchcontinue (inState,event,info)
local
State st;
String str1,str2,str3;
case (st,event,info)
then trans(st, event);
case (st,event,info)
equation
str1 = Absyn.pathString(getStateName(st));
str2 = printStateStr(st);
str3 = printEventStr(event);
Error.addSourceMessage(Error.TRANS_VIOLATION, {str1,str2,str3}, info);
then
fail();
end matchcontinue;
end assertTrans;

public function matchingState "function: matchingState

Finds a State in the list that matches the state given as first argument.
Expand Down
6 changes: 5 additions & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -3483,6 +3483,7 @@ algorithm
list<DAE.ComponentRef> connect_crefs;
Absyn.Path fullEnvPath;
UnitAbsyn.InstStore store;
Option<SCode.ExternalDecl> ed;

/*// uncomment for debugging
case (cache,env,ih,store,mods,pre,csets,ci_state,className,inClassDef6,
Expand Down Expand Up @@ -3543,7 +3544,9 @@ algorithm
case (cache,env,ih,store,mods,pre,ci_state,className,
SCode.PARTS(elementLst = els,
normalEquationLst = eqs, initialEquationLst = initeqs,
normalAlgorithmLst = alg, initialAlgorithmLst = initalg),
normalAlgorithmLst = alg, initialAlgorithmLst = initalg,
externalDecl = ed
),
re,vis,_,_,inst_dims,impl,callscope,graph,csets,instSingleCref,info,stopInst)
equation
false = Util.getStatefulBoolean(stopInst);
Expand Down Expand Up @@ -3708,6 +3711,7 @@ algorithm

// Search for equalityConstraint
eqConstraint = equalityConstraint(env5, els, info);
ci_state6 = Debug.bcallret3(Util.isSome(ed),ClassInf.assertTrans,ci_state6,ClassInf.FOUND_EXT_DECL(),info,ci_state6);
then
(cache,env5,ih,store,dae,csets5,ci_state6,vars,MetaUtil.fixUniontype(ci_state6,NONE()/* no basictype bc*/,inClassDef6),NONE(),eqConstraint,graph);

Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -566,6 +566,8 @@ public constant Message UNKNOWN_OPTION = MESSAGE(210, SCRIPTING(), ERROR(),
"Unknown option %s.");
public constant Message SUBSCRIPTED_MODIFIER = MESSAGE(211, TRANSLATION(), ERROR(),
"Subscripted modifier is illegal.");
public constant Message TRANS_VIOLATION = MESSAGE(212, TRANSLATION(), ERROR(),
"Restriction violation: %s is a %s, which may not contain an %s.");
public constant Message UNBOUND_PARAMETER_WARNING = MESSAGE(500, TRANSLATION(), WARNING(),
"Parameter %s has neither value nor start value, and is fixed during initialization (fixed=true)");
public constant Message BUILTIN_FUNCTION_SUM_HAS_SCALAR_PARAMETER = MESSAGE(501, TRANSLATION(), WARNING(),
Expand Down

0 comments on commit 0a154cf

Please sign in to comment.