Skip to content

Commit

Permalink
Fix for #2836:
Browse files Browse the repository at this point in the history
- Handle builtin types better in NFSCodeDependency.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22429 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 24, 2014
1 parent c6d215b commit c612384
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
43 changes: 26 additions & 17 deletions Compiler/FrontEnd/NFSCodeDependency.mo
Expand Up @@ -95,7 +95,7 @@ algorithm

case (_, _, _)
equation
(item, env) = lookupClass(inClassName, inEnv, inInfo,
(item, env) = lookupClass(inClassName, inEnv, true, inInfo,
SOME(Error.LOOKUP_ERROR));
checkItemIsClass(item);
analyseItem(item, env);
Expand All @@ -120,26 +120,27 @@ protected function lookupClass
them as used."
input Absyn.Path inPath;
input Env inEnv;
input Boolean inBuiltinPossible "True if the path can be a builtin, otherwise false.";
input Absyn.Info inInfo;
input Option<Error.Message> inErrorType;
output Item outItem;
output Env outEnv;
algorithm
(outItem, outEnv) := matchcontinue(inPath, inEnv, inInfo, inErrorType)
(outItem, outEnv) := matchcontinue(inPath, inEnv, inBuiltinPossible, inInfo, inErrorType)
local
Item item;
Env env;
String name_str, env_str;
Error.Message error_id;

case (_, _, _, _)
case (_, _, _, _, _)
equation
(item, env) = lookupClass2(inPath, inEnv, inInfo, inErrorType);
(item, env) = lookupClass2(inPath, inEnv, inBuiltinPossible, inInfo, inErrorType);
(item, env, _) = NFSCodeEnv.resolveRedeclaredItem(item, env);
then
(item, env);

case (_, _, _, SOME(error_id))
case (_, _, _, _, SOME(error_id))
equation
name_str = Absyn.pathString(inPath);
env_str = NFSCodeEnv.getEnvName(inEnv);
Expand All @@ -153,34 +154,42 @@ protected function lookupClass2
"Help function to lookupClass, does the actual look up."
input Absyn.Path inPath;
input Env inEnv;
input Boolean inBuiltinPossible;
input Absyn.Info inInfo;
input Option<Error.Message> inErrorType;
output Item outItem;
output Env outEnv;
algorithm
(outItem, outEnv) := match(inPath, inEnv, inInfo, inErrorType)
(outItem, outEnv) := match(inPath, inEnv, inBuiltinPossible, inInfo, inErrorType)
local
Item item;
Env env;
String id;
Absyn.Path rest_path;

case (Absyn.IDENT(name = _), _, _, _)
case (Absyn.IDENT(name = _), _, true, _, _)
equation
(item, _, env) =
NFSCodeLookup.lookupNameSilent(inPath, inEnv, inInfo);
then
(item, env);

case (Absyn.IDENT(name = _), _, false, _, _)
equation
(item, _, env) =
NFSCodeLookup.lookupNameSilentNoBuiltin(inPath, inEnv, inInfo);
then
(item, env);

// Special case for the baseclass of a class extends. Should be looked up
// among the inherited elements of the enclosing class.
case (Absyn.QUALIFIED(name = "$ce", path = Absyn.IDENT(name = id)), _ :: env, _, _)
case (Absyn.QUALIFIED(name = "$ce", path = Absyn.IDENT(name = id)), _ :: env, _, _, _)
equation
(item, env) = NFSCodeLookup.lookupInheritedName(id, env);
then
(item, env);

case (Absyn.QUALIFIED(name = id, path = rest_path), _, _, _)
case (Absyn.QUALIFIED(name = id, path = rest_path), _, _, _, _)
equation
(item, _, env) =
NFSCodeLookup.lookupNameSilent(Absyn.IDENT(id), inEnv, inInfo);
Expand All @@ -190,10 +199,10 @@ algorithm
then
(item, env);

case (Absyn.FULLYQUALIFIED(path = rest_path), _, _, _)
case (Absyn.FULLYQUALIFIED(path = rest_path), _, _, _, _)
equation
env = NFSCodeEnv.getEnvTopScope(inEnv);
(item, env) = lookupClass2(rest_path, env, inInfo, inErrorType);
(item, env) = lookupClass2(rest_path, env, false, inInfo, inErrorType);
then
(item, env);

Expand Down Expand Up @@ -223,7 +232,7 @@ algorithm
case (_, NFSCodeEnv.VAR(var = SCode.COMPONENT(typeSpec =
Absyn.TPATH(path = type_path), modifications = mods, info = info)), _, _)
equation
(item, type_env) = lookupClass(type_path, inEnv, info, inErrorType);
(item, type_env) = lookupClass(type_path, inEnv, true, info, inErrorType);
redeclares = NFSCodeFlattenRedeclare.extractRedeclaresFromModifier(mods);
(item, type_env, _) = NFSCodeFlattenRedeclare.replaceRedeclaredElementsInEnv(
redeclares, item, type_env, inEnv, NFInstPrefix.emptyPrefix);
Expand All @@ -234,7 +243,7 @@ algorithm
case (_, NFSCodeEnv.CLASS(cls = SCode.CLASS(info = info), env = {class_env}), _, _)
equation
env = NFSCodeEnv.enterFrame(class_env, inEnv);
(item, env) = lookupClass(inName, env, info, inErrorType);
(item, env) = lookupClass(inName, env, false, info, inErrorType);
then
(item, env);

Expand Down Expand Up @@ -296,7 +305,7 @@ algorithm
case (NFSCodeEnv.CLASS(classType = NFSCodeEnv.BASIC_TYPE()), _) then ();

// A normal class, mark it and it's environment as used, and recursively
// analyse it's contents.
// analyse its contents.
case (NFSCodeEnv.CLASS(cls = cls as SCode.CLASS(classDef = cdef,
restriction = res, info = info, cmt = cmt), env = {cls_env}), env)
equation
Expand Down Expand Up @@ -1047,7 +1056,7 @@ protected
Item item;
Env env;
algorithm
(item, env) := lookupClass(inClassName, inEnv, inInfo, NONE());
(item, env) := lookupClass(inClassName, inEnv, true, inInfo, NONE());
analyseItem(item, env);
end analyseExtends;

Expand Down Expand Up @@ -1145,7 +1154,7 @@ algorithm
case (SOME(SCode.CONSTRAINCLASS(constrainingClass = path, modifier = mod)), _, _)
equation
analyseClass(path, inEnv, inInfo);
(_, env) = lookupClass(path, inEnv, inInfo, SOME(Error.LOOKUP_ERROR));
(_, env) = lookupClass(path, inEnv, true, inInfo, SOME(Error.LOOKUP_ERROR));
analyseModifier(mod, inEnv, env, inInfo);
then
();
Expand Down Expand Up @@ -1590,7 +1599,7 @@ algorithm
// We want to use lookupClass since we need the item and environment, and
// we don't care about any subscripts, so convert the cref to a path.
path = Absyn.crefToPathIgnoreSubs(inCref);
(item, env) = lookupClass(path, inEnv, inInfo, NONE());
(item, env) = lookupClass(path, inEnv, true, inInfo, NONE());
analyseItem(item, env);
then
();
Expand Down
12 changes: 12 additions & 0 deletions Compiler/FrontEnd/NFSCodeLookup.mo
Expand Up @@ -1436,6 +1436,18 @@ algorithm
LOOKUP_ANY(), inInfo, NONE());
end lookupNameSilent;

public function lookupNameSilentNoBuiltin
input Absyn.Path inName;
input Env inEnv;
input Absyn.Info inInfo;
output Item outItem;
output Absyn.Path outName;
output Env outEnv;
algorithm
(outItem, outName, outEnv) := lookupName(inName, inEnv,
NO_BUILTIN_TYPES(), inInfo, NONE());
end lookupNameSilentNoBuiltin;

public function lookupClassName
"Calls lookupName with the 'Class not found' error message."
input Absyn.Path inName;
Expand Down

0 comments on commit c612384

Please sign in to comment.