Skip to content

Commit

Permalink
- move unused packages to Compiler/Unused
Browse files Browse the repository at this point in the history
SCodeInst 
- add class name to basic type and complex class
- union the inputs/outputs/locals when extending (fixes Modelica.Utilities.Files.loadResource)
- InstUtil.mergeDirection ignore several input or output if they are the same (fixes input Modelica.Blocks.Intefaces.RealInput used in HumMod)
- do not fail if class is partial in SCodeCheck.mo (should be put back) 
- fix a bug in inst of WHEN equations 

SCodeSimplify.mo
- removed contents and added a simplify phase to get rid of extends *Icons* to make debugging easier.

SCodeTransform.mo
- preliminary InstTypes -> SCode transformer

ComponentReference/Expression 
- handle more in unelabCref/unelabExp and add error printing on failtrace.



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13422 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 17, 2012
1 parent c1e89d5 commit eeccff4
Show file tree
Hide file tree
Showing 39 changed files with 1,535 additions and 711 deletions.
17 changes: 10 additions & 7 deletions Compiler/FrontEnd/Absyn.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3259,24 +3259,27 @@ end crefRemovePrefix;
public function pathContains "
Author BZ,
checks if one Absyn.IDENT(..) is contained in path."
input Path p1,p2;
input Path fullPath;
input Path pathId;
output Boolean b;
algorithm
b := match (p1,p2)
b := match (fullPath,pathId)
local
String str1,str2;
Path qp;
Boolean b1,b2;
case(IDENT(str1),IDENT(str2))
then stringEq(str1,str2);
case(QUALIFIED(str1,qp),(p2 as IDENT(str2)))

case(IDENT(str1),IDENT(str2)) then stringEq(str1,str2);

case(QUALIFIED(str1,qp),IDENT(str2))
equation
b1 = stringEq(str1,str2);
b2 = pathContains(qp,p2);
b2 = pathContains(qp,pathId);
b1 = boolOr(b1,b2);
then
b1;
case(FULLYQUALIFIED(qp),p2) then pathContains(qp,p2);

case(FULLYQUALIFIED(qp),_) then pathContains(qp,pathId);
end match;
end pathContains;

Expand Down
27 changes: 21 additions & 6 deletions Compiler/FrontEnd/ComponentReference.mo
Original file line number Diff line number Diff line change
Expand Up @@ -294,29 +294,44 @@ public function unelabCref
input ComponentRef inComponentRef;
output Absyn.ComponentRef outComponentRef;
algorithm
outComponentRef := match (inComponentRef)
outComponentRef := matchcontinue (inComponentRef)
local
list<Absyn.Subscript> subs_1;
DAE.Ident id;
list<DAE.Subscript> subs;
Absyn.ComponentRef cr_1;
ComponentRef cr;

// iterators
case (DAE.CREF_ITER(ident = id, subscriptLst = subs))
equation
subs_1 = unelabSubscripts(subs);
then
Absyn.CREF_IDENT(id ,subs_1);

// identifiers
case (DAE.CREF_IDENT(ident = id,subscriptLst = subs))
case (DAE.CREF_IDENT(ident = id, subscriptLst = subs))
equation
subs_1 = unelabSubscripts(subs);
then
Absyn.CREF_IDENT(id,subs_1);
Absyn.CREF_IDENT(id, subs_1);

// qualified
case (DAE.CREF_QUAL(ident = id,subscriptLst = subs,componentRef = cr))
case (DAE.CREF_QUAL(ident = id, subscriptLst = subs, componentRef = cr))
equation
cr_1 = unelabCref(cr);
subs_1 = unelabSubscripts(subs);
then
Absyn.CREF_QUAL(id,subs_1,cr_1);
end match;
Absyn.CREF_QUAL(id, subs_1, cr_1);

case _
equation
true = Flags.isSet(Flags.FAILTRACE);
print("ComponentReference.unelabCref failed on: " +& printComponentRefStr(inComponentRef) +& "\n");
then
fail();

end matchcontinue;
end unelabCref;

protected function unelabSubscripts
Expand Down
6 changes: 6 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ algorithm
then
Absyn.CALL(acref, Absyn.FOR_ITER_FARG(ae1, aiters));

case(_)
equation
true = Flags.isSet(Flags.FAILTRACE);
print("Expression.unelabExp failed on: " +& ExpressionDump.printExpStr(inExp) +& "\n");
then
fail();
end matchcontinue;
end unelabExp;

Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4096,6 +4096,11 @@ algorithm
true = Types.basicType(t1);
true = Types.basicType(t2);

// TODO: FIXME!
// adrpo 2012-10-14: should we not prefix here??!!
//(cache,c1) = PrefixUtil.prefixCref(cache,env,ih,pre, c1);
//(cache,c2) = PrefixUtil.prefixCref(cache,env,ih,pre, c2);

// set the source of this element
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), SOME((c1,c2)), NONE());

Expand Down
7 changes: 4 additions & 3 deletions Compiler/FrontEnd/InstSymbolTable.mo
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,17 @@ algorithm
list<Equation> eq, ieq;
list<list<Statement>> al, ial;
SymbolTable st;
Absyn.Path name;

// A basic type doesn't have any elements, nothing to add.
case (InstTypes.BASIC_TYPE(), st) then (inClass, st);
case (InstTypes.BASIC_TYPE(name), st) then (inClass, st);

// A complex class, add it's elements to the symboltable.
case (InstTypes.COMPLEX_CLASS(comps, eq, ieq, al, ial), st)
case (InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), st)
equation
(comps, st) = addElements(comps, st);
then
(InstTypes.COMPLEX_CLASS(comps, eq, ieq, al, ial), st);
(InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), st);

end match;
end addClass;
Expand Down
5 changes: 4 additions & 1 deletion Compiler/FrontEnd/InstTypes.mo
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ end Element;

public uniontype Class
record COMPLEX_CLASS
Absyn.Path name;
list<Element> components;
list<Equation> equations;
list<Equation> initialEquations;
list<list<Statement>> algorithms;
list<list<Statement>> initialAlgorithms;
end COMPLEX_CLASS;

record BASIC_TYPE end BASIC_TYPE;
record BASIC_TYPE
Absyn.Path name;
end BASIC_TYPE;
end Class;

public uniontype Function
Expand Down
78 changes: 64 additions & 14 deletions Compiler/FrontEnd/InstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public type Statement = InstTypes.Statement;
public type SymbolTable = InstSymbolTable.SymbolTable;

public function makeClass
input Absyn.Path inName;
input list<Element> inElements;
input list<Equation> inEquations;
input list<Equation> inInitialEquations;
Expand All @@ -86,7 +87,7 @@ public function makeClass
output Class outClass;
output DAE.Type outClassType;
algorithm
(outClass, outClassType) := match(inElements, inEquations, inInitialEquations,
(outClass, outClassType) := match(inName, inElements, inEquations, inInitialEquations,
inAlgorithms, inInitialAlgorithms, inState, inContainsSpecialExtends)
local
list<Element> elems;
Expand All @@ -96,14 +97,14 @@ algorithm
DAE.Type ty;
list<DAE.Var> vars;

case (elems, eq, ieq, al, ial, _, false)
case (_, elems, eq, ieq, al, ial, _, false)
equation
vars = List.accumulateMap(elems, makeDaeVarsFromElement);
ty = DAE.T_COMPLEX(inState, vars, NONE(), DAE.emptyTypeSource);
then
(InstTypes.COMPLEX_CLASS(elems, eq, ieq, al, ial), ty);
(InstTypes.COMPLEX_CLASS(inName, elems, eq, ieq, al, ial), ty);

case (_, {}, {}, {}, {}, _, true)
case (_, _, {}, {}, {}, {}, _, true)
equation
(InstTypes.EXTENDED_ELEMENTS(cls = cls, ty = ty), elems) =
getSpecialExtends(inElements);
Expand Down Expand Up @@ -152,7 +153,7 @@ algorithm
local
list<Element> elems;

case (InstTypes.BASIC_TYPE(), _) then inAccumVars;
case (InstTypes.BASIC_TYPE(_), _) then inAccumVars;
case (InstTypes.COMPLEX_CLASS(components = elems), _)
then List.accumulateMapAccum(elems, makeDaeVarsFromElement, inAccumVars);

Expand Down Expand Up @@ -338,22 +339,23 @@ algorithm
list<Element> el;
list<Equation> eq, ieq;
list<list<Statement>> al, ial;
Absyn.Path name;

case (_, InstTypes.COMPLEX_CLASS(el, eq, ieq, al, ial))
case (_, InstTypes.COMPLEX_CLASS(name, el, eq, ieq, al, ial))
equation
el = listAppend(inElements, el);
then
InstTypes.COMPLEX_CLASS(el, eq, ieq, al, ial);
InstTypes.COMPLEX_CLASS(name, el, eq, ieq, al, ial);

case (_, InstTypes.BASIC_TYPE())
case (_, InstTypes.BASIC_TYPE(name))
equation
Error.addMessage(Error.INTERNAL_ERROR,
{"SCodeInst.addElementsToClass: Can't add elements to basic type.\n"});
then
fail();

end match;
end addElementsToClass;
end addElementsToClass;

public function getComponentName
input Component inComponent;
Expand Down Expand Up @@ -1094,6 +1096,9 @@ algorithm
Absyn.Info info1, info2;
String dir_str1, dir_str2, el_name;

// if they are the same, doesn't matter
case ((Absyn.INPUT(),_), (Absyn.INPUT(), _), _, _) then inOuterDirection;
case ((Absyn.OUTPUT(),_), (Absyn.OUTPUT(), _), _, _) then inOuterDirection;
// If either prefix is unset, return the other.
case (_, (Absyn.BIDIR(), _), _, _) then inOuterDirection;
case ((Absyn.BIDIR(), _), _, _, _) then inInnerDirection;
Expand Down Expand Up @@ -1337,12 +1342,13 @@ algorithm
list<Element> comps;
list<Equation> eq, ieq;
list<list<Statement>> al, ial;
Absyn.Path name;

case (InstTypes.COMPLEX_CLASS(comps, eq, ieq, al, ial), _)
case (InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), _)
equation
comps = List.map1(comps, prefixElement, inPrefix);
then
InstTypes.COMPLEX_CLASS(comps, eq, ieq, al, ial);
InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial);

else inClass;

Expand All @@ -1358,7 +1364,7 @@ algorithm
list<Element> comps;
Integer count;

case InstTypes.BASIC_TYPE() then 0;
case InstTypes.BASIC_TYPE(_) then 0;

case InstTypes.COMPLEX_CLASS(components = comps)
equation
Expand Down Expand Up @@ -1555,12 +1561,13 @@ algorithm
list<Element> comps;
list<Equation> eq, ieq;
list<list<Statement>> al, ial;
Absyn.Path name;

case (InstTypes.COMPLEX_CLASS(comps, eq, ieq, al, ial), arg, _)
case (InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), arg, _)
equation
(comps, arg) = traverseClassComponents2(comps, arg, inFunc, {});
then
(InstTypes.COMPLEX_CLASS(comps, eq, ieq, al, ial), arg);
(InstTypes.COMPLEX_CLASS(name, comps, eq, ieq, al, ial), arg);

else (inClass, inArg);

Expand Down Expand Up @@ -1952,4 +1959,47 @@ algorithm
end matchcontinue;
end toConst;

public function setClassName
input Class inClass;
input Absyn.Path inClassName;
output Class outClass;
algorithm
outClass := match(inClass, inClassName)
local
list<Element> el;
list<Equation> eq, ieq;
list<list<Statement>> al, ial;
Absyn.Path name;

case (InstTypes.COMPLEX_CLASS(_, el, eq, ieq, al, ial), _)
then
InstTypes.COMPLEX_CLASS(inClassName, el, eq, ieq, al, ial);

case (InstTypes.BASIC_TYPE(_), _)
then
InstTypes.BASIC_TYPE(inClassName);

end match;
end setClassName;

public function getClassName
input Class inClass;
output Absyn.Path outClassName;
algorithm
outClassName := match(inClass)
local
Absyn.Path name;

case (InstTypes.COMPLEX_CLASS(name = name))
then
name;

case (InstTypes.BASIC_TYPE(name))
then
name;

end match;
end getClassName;


end InstUtil;
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/SCodeCheck.mo
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ algorithm
equation
Error.addSourceMessage(Error.INST_PARTIAL_CLASS, {name}, inInfo);
then
fail();
(); // fail();

else ();
end match;
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/SCodeEnv.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,7 @@ algorithm
tree := addDummyClassToTree("time", tree);
tree := addDummyClassToTree("String", tree);
tree := addDummyClassToTree("Integer", tree);
tree := addDummyClassToTree("Real", tree);
tree := addDummyClassToTree("spliceFunction", tree);

outInitialEnv := {FRAME(NONE(), NORMAL_SCOPE(), tree, exts, imps, SOME(is_used))};
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/SCodeExpand.mo
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ algorithm
list<Equation> eq;
list<list<Statement>> al;

case (InstTypes.BASIC_TYPE(), _, _) then inAccumEl;
case (InstTypes.BASIC_TYPE(_), _, _) then inAccumEl;

case (InstTypes.COMPLEX_CLASS(components = comps, equations = eq, algorithms = al), _, _)
equation
Expand Down Expand Up @@ -205,7 +205,7 @@ algorithm
DAE.Type ty;
DAE.Dimensions dims;

case (InstTypes.ELEMENT(component = comp, cls = InstTypes.BASIC_TYPE()), _, _, _)
case (InstTypes.ELEMENT(component = comp, cls = InstTypes.BASIC_TYPE(_)), _, _, _)
equation
el = expandComponent(comp, inKind, inSubscripts, inAccumEl);
then
Expand Down
1 change: 0 additions & 1 deletion Compiler/FrontEnd/SCodeFlatten.mo
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public import SCode;
public import SCodeDependency;
public import SCodeEnv;
public import SCodeFlattenImports;
public import SCodeFlattenExtends;

protected import Debug;
protected import Flags;
Expand Down

0 comments on commit eeccff4

Please sign in to comment.