Skip to content

Commit

Permalink
Fixed stack overflow bug in mofiles/DependsRecursive.mo
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2443 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jul 7, 2006
1 parent 27385ec commit cd4c59c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Compiler/Error.mo
Expand Up @@ -272,6 +272,8 @@ public constant ErrorID DUPLICATE_ELEMENTS_NOT_IDENTICAL=89;

public constant ErrorID PACKAGE_VARIABLE_NOT_CONSTANT=90;

public constant ErrorID RECURSIVE_DEFINITION= 91;

public constant ErrorID UNBOUND_PARAMETER_WARNING=500;

public constant ErrorID BUILTIN_FUNCTION_SUM_HAS_SCALAR_PARAMETER=501;
Expand Down Expand Up @@ -453,6 +455,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(DUPLICATE_ELEMENTS_NOT_IDENTICAL,TRANSLATION(),ERROR(),
"Error duplicate elements (due to inherited elements) not identical, first element is: %s, second element is: %s"),
(PACKAGE_VARIABLE_NOT_CONSTANT, TRANSLATION(),ERROR(),"Variable %s in package %s is not constant"),
(RECURSIVE_DEFINITION,TRANSLATION(),ERROR(),"Class %s has a recursive definition, i.e. contains an instance of itself"),
(UNBOUND_PARAMETER_WARNING,TRANSLATION(),WARNING(),
"Warning, parameter %s has no value."),
(BUILTIN_FUNCTION_SUM_HAS_SCALAR_PARAMETER(),TRANSLATION(),WARNING(),
Expand Down
26 changes: 26 additions & 0 deletions Compiler/Inst.mo
Expand Up @@ -3180,6 +3180,7 @@ algorithm
local String s;
equation
checkMultiplyDeclared(cache,env,mods,pre,csets,ci_state,(comp,cmod),inst_dims,impl); // Fails if multiple decls not identical
checkRecursiveDefinition(env,t);
vn = Prefix.prefixCref(pre, Exp.CREF_IDENT(n,{})) "//Debug.fprint(\"insttr\", \"Instantiating component \") &
//Debug.fprint(\"insttr\", n) & //Debug.fprint(\"insttr\", \"\\n\") &" ;
classmod = Mod.lookupModificationP(mods, t) "The class definition is fetched from the environment. Then the set of modifications is calculated. The modificions is the result of merging the modifications from several sources. The modification stored with the class definition is put in the variable `classmod\', the modification passed to the function_ is extracted and put in the variable `mm\', and the modification that is included in the variable declaration is in the variable `m\'. All of these are merged so that the correct precedence rules are followed." ;
Expand Down Expand Up @@ -3245,6 +3246,31 @@ algorithm
end matchcontinue;
end instElement;

protected function checkRecursiveDefinition "Checks that a class does not have a recursive definition,
i.e. an instance of itself. This is not allowed in Modelica."
input Env.Env env;
input Absyn.Path tp;
algorithm
_ := matchcontinue(env,tp)
local Absyn.Path envPath;
// No envpath, nothing to check.
case(env,tp) equation
NONE = Env.getEnvPath(env);
then ();
// No recursive definition, succed.
case(env,tp) equation
SOME(envPath) = Env.getEnvPath(env);
false = Absyn.pathSuffixOf(tp,envPath);
then ();
case(env,tp) local String s; equation
SOME(envPath) = Env.getEnvPath(env);
true= Absyn.pathSuffixOf(tp,envPath);
s = Absyn.pathString(tp);
Error.addMessage(Error.RECURSIVE_DEFINITION,{s});
then fail();
end matchcontinue;
end checkRecursiveDefinition;

protected function checkMultiplyDeclared "Check if variable is multiply declared and that
all declarations are identical if so."
input Env.Cache cache;
Expand Down

0 comments on commit cd4c59c

Please sign in to comment.