Skip to content

Commit

Permalink
Small fixes for last commit.
Browse files Browse the repository at this point in the history
Changed where double-modification control is triggered(from SCode to Inst.instelementlist)

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@4149 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Björn Zachrisson committed Aug 5, 2009
1 parent bd83821 commit a9c7a26
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Compiler/Error.mo
Expand Up @@ -477,7 +477,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
"Identificator %s of implicit for iterator must be present as array subscript in the loop body."),

(MULTIPLE_MODIFIER,TRANSLATION(),ERROR(),
"Multiple modifers in same scope for component %s, modifiers: %s"),
"Multiple modifers in same scope for element %s, %s"),

(STRUCT_SINGULAR_SYSTEM_INITIALIZATION,TRANSLATION(),ERROR(),
"The initialization problem of model is structurally singular, error found sorting equations %s for variables %s"),
Expand Down
68 changes: 64 additions & 4 deletions Compiler/Inst.mo
Expand Up @@ -1178,7 +1178,7 @@ algorithm

case (cache,env,store,mods,pre,csets,ci_state,(c as SCode.CLASS(name = n,restriction = r,classDef = d)),prot,inst_dims,impl,graph,_)
equation
//print("instClassIn(");print(n);print("failed\n");
//print("instClassIn(");print(n);print(") failed\n");
//Debug.fprintln("failtrace", "- Inst.instClassIn failed" +& n);
then
fail();
Expand Down Expand Up @@ -3926,7 +3926,7 @@ algorithm
path = Absyn.IDENT(str);
path = Prefix.prefixPath(path,pre);
str = Absyn.pathString(path);

verifySingleMod(mod,pre,str);
/*
classmod = Mod.lookupModificationP(mods, t);
mm = Mod.lookupCompModification(mods, n);
Expand All @@ -3946,12 +3946,74 @@ mm = Mod.lookupCompModification(mods, n);
(cache,dae,env_2,store,csets_2,ci_state_2,tys,graph);
case (_,_,_,_,_,_,_,els,_,_,_)
equation
//print("instElementList failed\n ");
Debug.fprintln("failtrace", "- Inst.instElementList failed");
then
fail();
end matchcontinue;
end instElementList;

protected function verifySingleMod "
Author BZ
Checks so that we only have one modifier for each element.
Fails on; a(x=3, redeclare Integer x)
"
input Mod m;
input Prefix.Prefix pre;
input String str;
algorithm _ := matchcontinue(m,pre,str)
local
list<Types.SubMod> subs;
case(Types.MOD(_,_,subs,_),pre,str)
equation
verifySingleMod2(subs,{},pre,str);
then
();
case(Types.NOMOD,pre,str) then ();
case(Types.REDECL(finalPrefix=_),pre,str) then ();
end matchcontinue;
end verifySingleMod;

protected function verifySingleMod2 "
helper function for verifySingleMod
"
input list<Types.SubMod> subs;
input list<String> prior;
input Prefix.Prefix pre;
input String str;
algorithm _ := matchcontinue(subs,prior,pre,str)
local String n,s1;
case({},_,pre,str) then ();
case(Types.NAMEMOD(ident = n)::subs,prior,pre,str)
equation
false = Util.listContainsWithCompareFunc(n,prior,stringEqual);
verifySingleMod2(subs,n::prior,pre,str);
then
();
case(Types.NAMEMOD(ident = n)::subs,prior,pre,str)
equation
true = Util.listContainsWithCompareFunc(n,prior,stringEqual);
s1 = makePrefixString(pre);
Error.addMessage(Error.MULTIPLE_MODIFIER, {n,s1});
then
fail();
end matchcontinue;
end verifySingleMod2;

protected function makePrefixString "
helper function for verifySingleMod, pretty output
"
input Prefix.Prefix pre;
output String str;
algorithm str := matchcontinue(pre)
case(Prefix.NOPRE()) then "from top scope";
case(pre)
equation
str = "from calling scope: " +& Prefix.printPrefixStr(pre);
then str;
end matchcontinue;
end makePrefixString;

protected function classdefElts2
"function: classdeElts2
author: PA
Expand Down Expand Up @@ -5289,8 +5351,6 @@ algorithm
m_2 = Mod.merge(compMod, innerCompMod, env_1, pre);
then
(cache,redComp,m_2,env_1,csets);
//(cache,redecl,m_2,env_1,csets);


// no constraining type on comp, throw away modifiers prior to redeclaration
case (cache,(m as Types.REDECL(tplSCodeElementModLst = (((redecl as
Expand Down
97 changes: 2 additions & 95 deletions Compiler/SCode.mo
Expand Up @@ -668,28 +668,11 @@ algorithm
els_1 = listAppend(es_1, els);
then
els_1;
case (cp :: rest) /* ignore all other than PUBLIC and PROTECTED, i.e. elements */
equation
false = isPubOrProt(cp);
els = elabClassdefElements(rest);
then
els;
case (_ :: rest) /* ignore all other than PUBLIC and PROTECTED, i.e. elements */
then elabClassdefElements(rest);
end matchcontinue;
end elabClassdefElements;

protected function isPubOrProt "
Author: BZ
Helper function for elabClassdefElements, verify a fail
"
input Absyn.ClassPart cp;
output Boolean ob;
algorithm ob := matchcontinue(cp)
case(Absyn.PUBLIC(contents = _)) then true;
case(Absyn.PROTECTED(contents = _)) then true;
case(_) then false;
end matchcontinue;
end isPubOrProt;

protected function elabClassdefEquations
"function: elabClassdefEquations
Convert an Absyn.ClassPart list to an Equation list."
Expand Down Expand Up @@ -1264,87 +1247,11 @@ algorithm
case (SOME(Absyn.CLASSMOD(l,NONE)),finalPrefix,each_)
equation
subs = buildArgs(l);
true = verifyNonMultipleMods(l);
then
MOD(finalPrefix,each_,subs,NONE);
end matchcontinue;
end buildMod;

protected function verifyNonMultipleMods "
Author: BZ, 2008-07
This function checks that we do not have multiple modifiers on same component.
Ex 'myModel mo(C=3.15,redeclare Modelica.Resistor C)' should generate an error.
"
input list<Absyn.ElementArg> elems;
output Boolean succ;
algorithm succ := matchcontinue(elems)
case(elems) equation true = listLength(elems) <=1; then true;

case(elems)
local
String errorString,errorComp;
Absyn.ComponentRef cr;
equation
(errorString,(cr as Absyn.CREF_IDENT(errorComp,_))) = getDoubleMods(elems,{});
false = intEq(stringLength(errorString),0);
Error.addMessage(Error.MULTIPLE_MODIFIER, {errorComp,errorString});
then
false;

case(elems) then true;
end matchcontinue;
end verifyNonMultipleMods;

protected function getDoubleMods "
Author BZ
Helper function for verifyNonMultipleMods
"
input list<Absyn.ElementArg> elems;
input list<Absyn.ComponentRef> crefs;
output String double;
output Absyn.ComponentRef double;
algorithm double := matchcontinue(elems,crefs)
local
Absyn.ComponentRef cr,doubleCr;
Absyn.ElementArg ea;
String error,n,error2;
Absyn.ElementSpec spec;
Option<Absyn.Modification> oam;
case({},cr::_) then ("", cr);
case((ea as Absyn.MODIFICATION(componentReg = cr,modification=oam))::elems,crefs)
equation
false = Util.listContainsWithCompareFunc(cr,crefs,Absyn.crefEqual);
(error, doubleCr) = getDoubleMods(elems,cr::crefs);
error2 = prettyPrintElementModifier(ea);
error = error +& Util.if_(boolAnd(stringLength(error)>0,Absyn.crefEqual(doubleCr,cr))," and " +& error2 ,"");
then
(error,cr);

case((ea as Absyn.MODIFICATION(componentReg = cr,modification=oam))::elems,crefs)
equation
true = Util.listContainsWithCompareFunc(cr,crefs,Absyn.crefEqual);
error = prettyPrintElementModifier(ea);
then
(error,cr);
case(Absyn.REDECLARATION(elementSpec = spec)::elems,crefs)
equation
n = Absyn.elementSpecName(spec);
cr = Absyn.CREF_IDENT(n,{});
false = Util.listContainsWithCompareFunc(cr,crefs,Absyn.crefEqual);
(error, doubleCr) = getDoubleMods(elems,cr::crefs);
error = error +& Util.if_(boolAnd(stringLength(error)>0,Absyn.crefEqual(doubleCr,cr))," and Redeclaration of component " +& n,"");
then
(error,cr);
case(Absyn.REDECLARATION(elementSpec = spec)::elems,crefs)
equation
n = Absyn.elementSpecName(spec);
cr = Absyn.CREF_IDENT(n,{});
true = Util.listContainsWithCompareFunc(cr,crefs,Absyn.crefEqual);
then
("Redeclaration of component "+&n,cr);
end matchcontinue;
end getDoubleMods;

protected function prettyPrintOptModifier "
Author BZ, 2008-07
Pretty print SCode.Mod
Expand Down

0 comments on commit a9c7a26

Please sign in to comment.