Skip to content

Commit

Permalink
- Added check for components with the same name is it's type specifier.
Browse files Browse the repository at this point in the history
- Enabled testcase mofiles/Lookup8.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9931 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 26, 2011
1 parent 0bd84d8 commit b44374d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
22 changes: 22 additions & 0 deletions Compiler/FrontEnd/SCodeCheck.mo
Expand Up @@ -560,4 +560,26 @@ algorithm
end matchcontinue;
end checkRecursiveComponentDeclaration;

public function checkIdentNotEqTypeName
"Checks that a simple identifier is not the same as a type name."
input String inIdent;
input Absyn.TypeSpec inTypeName;
input Absyn.Info inInfo;
output Boolean outIsNotEq;
algorithm
outIsNotEq := matchcontinue(inIdent, inTypeName, inInfo)
local
String id, ty;

case (id, Absyn.TPATH(path = Absyn.IDENT(ty)), _)
equation
true = stringEq(id, ty);
Error.addSourceMessage(Error.LOOKUP_TYPE_FOUND_COMP, {id}, inInfo);
then
false;

else true;
end matchcontinue;
end checkIdentNotEqTypeName;

end SCodeCheck;
1 change: 0 additions & 1 deletion Compiler/FrontEnd/SCodeFlattenImports.mo
Expand Up @@ -662,7 +662,6 @@ algorithm
case ((Absyn.CALL(function_ = cref, functionArgs = args),
tup as (env, info)))
equation
//cref = SCodeLookup.lookupComponentRefForceQualified(cref, env, info);
cref = SCodeLookup.lookupComponentRef(cref, env, info);
// TODO: handle function arguments
then
Expand Down
23 changes: 17 additions & 6 deletions Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -137,12 +137,19 @@ algorithm
end translate2;

public function translateClass
"function: translateClass
This functions converts an Absyn.Class to a SCode.Class."
input Absyn.Class inClass;
output SCode.Element outClass;
algorithm
outClass := matchcontinue (inClass)
outClass := translateClass2(inClass, Error.getNumMessages());
end translateClass;

protected function translateClass2
"This functions converts an Absyn.Class to a SCode.Class."
input Absyn.Class inClass;
input Integer inNumMessages;
output SCode.Element outClass;
algorithm
outClass := matchcontinue (inClass, inNumMessages)
local
SCode.ClassDef d_1;
SCode.Restriction r_1;
Expand All @@ -157,7 +164,7 @@ algorithm
SCode.Encapsulated sEnc;
SCode.Partial sPar;

case (c as Absyn.CLASS(name = n,partialPrefix = p,finalPrefix = f,encapsulatedPrefix = e,restriction = r,body = d,info = file_info))
case (c as Absyn.CLASS(name = n,partialPrefix = p,finalPrefix = f,encapsulatedPrefix = e,restriction = r,body = d,info = file_info), _)
equation
// Debug.fprint("translate", "Translating class:" +& n +& "\n");
r_1 = translateRestriction(c, r); // uniontype will not get translated!
Expand All @@ -182,14 +189,17 @@ algorithm
then
scodeClass;

case (c as Absyn.CLASS(name = n,partialPrefix = p,finalPrefix = f,encapsulatedPrefix = e,restriction = r,body = d,info = file_info))
case (c as Absyn.CLASS(name = n,partialPrefix = p,finalPrefix = f,encapsulatedPrefix = e,restriction = r,body = d,info = file_info), _)
equation
// Print out an internal error msg only if no other errors have already
// been printed.
true = intEq(Error.getNumMessages(), inNumMessages);
n = "SCodeUtil.translateAbsyn2SCodeClass failed: " +& n;
Error.addSourceMessage(Error.INTERNAL_ERROR,{n},file_info);
then
fail();
end matchcontinue;
end translateClass;
end translateClass2;

// Changed to public! krsta
public function translateRestriction
Expand Down Expand Up @@ -1197,6 +1207,7 @@ algorithm
(attr as Absyn.ATTR(flowPrefix = fl,streamPrefix=st,variability = variability,direction = di,arrayDim = ad)),typeSpec = t,
components = (Absyn.COMPONENTITEM(component = Absyn.COMPONENT(name = n,arrayDim = d,modification = m),comment = comment,condition=cond) :: xs)),info)
equation
true = SCodeCheck.checkIdentNotEqTypeName(n, t, info);
// Debug.fprintln("translate", "translating component: " +& n +& " final: " +& SCode.finalStr(SCode.boolFinal(finalPrefix)));
setHasInnerOuterDefinitionsHandler(io); // signal the external flag that we have inner/outer definitions
setHasStreamConnectorsHandler(st); // signal the external flag that we have stream connectors
Expand Down

0 comments on commit b44374d

Please sign in to comment.