Skip to content

Commit 599ce04

Browse files
committed
- Translate Absyn.ConstrainClass into SCode.ConstrainClass in
translateAbsyn2SCode. - Updated some redeclare test cases. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9136 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 5601057 commit 599ce04

File tree

6 files changed

+100
-32
lines changed

6 files changed

+100
-32
lines changed

Compiler/FrontEnd/Inst.mo

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7004,7 +7004,7 @@ algorithm
70047004
Env.Cache cache;
70057005
InstanceHierarchy ih;
70067006

7007-
Option<Absyn.ConstrainClass> cc;
7007+
Option<SCode.ConstrainClass> cc;
70087008
list<SCode.Element> compsOnConstrain;
70097009
Absyn.InnerOuter io;
70107010
SCode.Attributes at;
@@ -7037,7 +7037,7 @@ algorithm
70377037
SCode.COMPONENT(name = n2,
70387038
prefixes = SCode.PREFIXES(
70397039
finalPrefix = SCode.NOT_FINAL(),
7040-
replaceablePrefix = repl2 as SCode.REPLACEABLE((cc as SOME(Absyn.CONSTRAINCLASS(elementSpec=_)))),
7040+
replaceablePrefix = repl2 as SCode.REPLACEABLE((cc as SOME(_))),
70417041
visibility = vis2),
70427042
typeSpec = t2,
70437043
modifications = old_mod),
@@ -7206,36 +7206,35 @@ protected function extractConstrainingComps
72067206
"Author: BZ, 2009-07
72077207
This function examines a optional Absyn.ConstrainClass argument.
72087208
If there is a constraining class, lookup the class and return its elements."
7209-
input Option<Absyn.ConstrainClass> cc;
7209+
input Option<SCode.ConstrainClass> cc;
72107210
input Env.Env env;
72117211
input Prefix.Prefix pre;
72127212
output list<SCode.Element> elems;
72137213
algorithm
72147214
elems := matchcontinue(cc,env,pre)
72157215
local
7216-
Absyn.Path path,derP;
7217-
list<Absyn.ElementArg> args;
7218-
Env.Env clenv;
7216+
Absyn.Path path;
72197217
SCode.Element cl;
72207218
String name;
72217219
list<SCode.Element> selems,extendselts,compelts,extcompelts,classextendselts;
72227220
list<tuple<SCode.Element, DAE.Mod>> extcomps;
7223-
Option<Absyn.Annotation> annOpt;
7224-
7221+
SCode.Mod mod;
7222+
Option<SCode.Comment> cmt;
7223+
72257224
case(NONE(),_,_) then {};
7226-
case(SOME(Absyn.CONSTRAINCLASS(elementSpec = Absyn.EXTENDS(path,args,annOpt))),env,pre)
7225+
case(SOME(SCode.CONSTRAINCLASS(constrainingClass = path)),env,pre)
72277226
equation
7228-
(_,(cl as SCode.CLASS(name = name, classDef = SCode.PARTS(elementLst=selems))) ,clenv) = Lookup.lookupClass(Env.emptyCache(),env,path,false);
7227+
(_,(cl as SCode.CLASS(name = name, classDef = SCode.PARTS(elementLst=selems))), _) = Lookup.lookupClass(Env.emptyCache(),env,path,false);
72297228
(_,classextendselts,extendselts,compelts) = splitElts(selems);
72307229
(_,_,_,_,extcomps,_,_,_,_) = InstExtends.instExtendsAndClassExtendsList(Env.emptyCache(), env, InnerOuter.emptyInstHierarchy, DAE.NOMOD(), pre, extendselts, classextendselts, ClassInf.UNKNOWN(Absyn.IDENT("")), name, true, false);
72317230
extcompelts = Util.listMap(extcomps,Util.tuple21);
72327231
compelts = listAppend(compelts,extcompelts);
72337232
then
72347233
compelts;
7235-
case(SOME(Absyn.CONSTRAINCLASS(elementSpec = Absyn.EXTENDS(path,args,annOpt))),env,pre)
7234+
case (SOME(SCode.CONSTRAINCLASS(path, mod, cmt)), _, _)
72367235
equation
7237-
(_,(cl as SCode.CLASS(classDef = SCode.DERIVED(typeSpec = Absyn.TPATH(path = derP)))) ,clenv) = Lookup.lookupClass(Env.emptyCache(),env,path,false);
7238-
compelts = extractConstrainingComps(SOME(Absyn.CONSTRAINCLASS(Absyn.EXTENDS(derP,{},annOpt),NONE())),env,pre);
7236+
(_,(cl as SCode.CLASS(classDef = SCode.DERIVED(typeSpec = Absyn.TPATH(path = path)))),_) = Lookup.lookupClass(Env.emptyCache(),env,path,false);
7237+
compelts = extractConstrainingComps(SOME(SCode.CONSTRAINCLASS(path, mod, cmt)),env,pre);
72397238
then
72407239
compelts;
72417240
end matchcontinue;

Compiler/FrontEnd/SCode.mo

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,18 @@ uniontype Redeclare "the redeclare prefix"
425425
record NOT_REDECLARE "a non redeclare prefix" end NOT_REDECLARE;
426426
end Redeclare;
427427

428+
public uniontype ConstrainClass
429+
record CONSTRAINCLASS
430+
Absyn.Path constrainingClass;
431+
Mod modifier;
432+
Option<Comment> comment;
433+
end CONSTRAINCLASS;
434+
end ConstrainClass;
435+
428436
public
429437
uniontype Replaceable "the replaceable prefix"
430438
record REPLACEABLE "a replaceable prefix containing an optional constraint"
431-
Option<Absyn.ConstrainClass> cc "the constraint class";
439+
Option<ConstrainClass> cc "the constraint class";
432440
end REPLACEABLE;
433441
record NOT_REPLACEABLE "a non replaceable prefix" end NOT_REPLACEABLE;
434442
end Replaceable;
@@ -3098,18 +3106,18 @@ end replaceableBool;
30983106

30993107
public function replaceableOptConstraint
31003108
input Replaceable inReplaceable;
3101-
output Option<Absyn.ConstrainClass> outOptConstrainClass;
3109+
output Option<ConstrainClass> outOptConstrainClass;
31023110
algorithm
31033111
outOptConstrainClass := match(inReplaceable)
3104-
local Option<Absyn.ConstrainClass> cc;
3112+
local Option<ConstrainClass> cc;
31053113
case (REPLACEABLE(cc)) then cc;
31063114
case (NOT_REPLACEABLE()) then NONE();
31073115
end match;
31083116
end replaceableOptConstraint;
31093117

31103118
public function boolReplaceable
31113119
input Boolean inBoolReplaceable;
3112-
input Option<Absyn.ConstrainClass> inOptConstrainClass;
3120+
input Option<ConstrainClass> inOptConstrainClass;
31133121
output Replaceable outReplaceable;
31143122
algorithm
31153123
outReplaceable := matchcontinue(inBoolReplaceable, inOptConstrainClass)
@@ -3317,13 +3325,16 @@ public function replaceableEqual "Returns true if two replaceable attributes are
33173325
algorithm
33183326
equal := matchcontinue(r1,r2)
33193327
local
3320-
Absyn.ElementSpec e1, e2;
3328+
Absyn.Path p1, p2;
3329+
Mod m1, m2;
33213330

33223331
case(NOT_REPLACEABLE(),NOT_REPLACEABLE()) then true;
33233332

3324-
case(REPLACEABLE(SOME(Absyn.CONSTRAINCLASS(elementSpec=e1))),REPLACEABLE(SOME(Absyn.CONSTRAINCLASS(elementSpec=e2))))
3333+
case(REPLACEABLE(SOME(CONSTRAINCLASS(constrainingClass = p1, modifier = m1))),
3334+
REPLACEABLE(SOME(CONSTRAINCLASS(constrainingClass = p2, modifier = m2))))
33253335
equation
3326-
true = valueEq(e1, e2);
3336+
true = Absyn.pathEqual(p1, p2);
3337+
true = modEqual(m1, m2);
33273338
then
33283339
true;
33293340

Compiler/FrontEnd/SCodeDependency.mo

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ algorithm
699699
Absyn.Info info;
700700
SCode.Attributes attr;
701701
Option<Absyn.Exp> cond_exp;
702-
Option<Absyn.ConstrainClass> cc;
702+
Option<SCode.ConstrainClass> cc;
703703
SCode.Element cls;
704704
Item ty_item;
705705
Env ty_env;
@@ -932,13 +932,25 @@ end analyseRedeclare;
932932

933933
protected function analyseConstrainClass
934934
"Analyses a constrain class, i.e. given by constrainedby."
935-
input Option<Absyn.ConstrainClass> inCC;
935+
input Option<SCode.ConstrainClass> inCC;
936936
input Env inEnv;
937937
input Absyn.Info inInfo;
938938
algorithm
939939
_ := match(inCC, inEnv, inInfo)
940-
// TODO Add code here.
941-
case (_, _, _) then ();
940+
local
941+
Absyn.Path path;
942+
SCode.Mod mod;
943+
Env env;
944+
945+
case (SOME(SCode.CONSTRAINCLASS(constrainingClass = path, modifier = mod)), _, _)
946+
equation
947+
analyseClass(path, inEnv, inInfo);
948+
(_, _, env) = SCodeLookup.lookupClassName(path, inEnv, inInfo);
949+
analyseModifier(mod, inEnv, env, inInfo);
950+
then
951+
();
952+
953+
else ();
942954
end match;
943955
end analyseConstrainClass;
944956

@@ -1715,7 +1727,7 @@ protected
17151727
SCodeEnv.Frame class_frame;
17161728
Env class_env;
17171729
Absyn.Path cls_path;
1718-
Option<Absyn.ConstrainClass> cc;
1730+
Option<SCode.ConstrainClass> cc;
17191731
algorithm
17201732
SCode.CLASS(name, prefixes, ep, pp, res, cdef, info) := inClass;
17211733
// TODO! FIXME! add cc to the used classes!

Compiler/FrontEnd/SCodeDump.mo

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,17 @@ public function replaceableStr
958958
output String strConstraint;
959959
algorithm
960960
(strReplaceable, strConstraint) := match(inReplaceable)
961-
local Absyn.ConstrainClass cc;
962-
case (SCode.REPLACEABLE(SOME(cc))) then ("replaceable ", Dump.unparseConstrainclassStr(cc));
961+
local
962+
Absyn.Path path;
963+
SCode.Mod mod;
964+
String path_str, mod_str;
965+
966+
case (SCode.REPLACEABLE(SOME(SCode.CONSTRAINCLASS(
967+
constrainingClass = path, modifier = mod))))
968+
equation
969+
path_str = Absyn.pathString(path);
970+
mod_str = printModStr(mod);
971+
then ("replaceable ", path_str +& "(" +& mod_str +& ")");
963972
case (SCode.REPLACEABLE(NONE())) then ("replaceable ", "");
964973
case (SCode.NOT_REPLACEABLE()) then ("", "");
965974
end match;

Compiler/FrontEnd/SCodeFlatDump.mo

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,16 @@ public function replaceableStr
355355
output String strReplaceable;
356356
algorithm
357357
strReplaceable := match(inReplaceable)
358-
local Absyn.ConstrainClass cc;
359-
case (SCode.REPLACEABLE(SOME(cc))) then "{r:" +& Dump.unparseConstrainclassStr(cc) +& "}";
358+
local
359+
Absyn.Path cc_path;
360+
SCode.Mod cc_mod;
361+
String path_str, mod_str;
362+
363+
case (SCode.REPLACEABLE(SOME(SCode.CONSTRAINCLASS(cc_path, cc_mod, _))))
364+
equation
365+
path_str = Absyn.pathString(cc_path);
366+
mod_str = SCodeDump.printModStr(cc_mod);
367+
then "{r:" +& path_str +& "(" +& mod_str +& ")}";
360368
case (SCode.REPLACEABLE(NONE())) then "{r:}";
361369
case (SCode.NOT_REPLACEABLE()) then "{}";
362370
end match;
@@ -444,4 +452,4 @@ algorithm
444452
end match;
445453
end restrictionStr;
446454

447-
end SCodeFlatDump;
455+
end SCodeFlatDump;

Compiler/FrontEnd/SCodeUtil.mo

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ algorithm
11441144
SCode.Visibility vis;
11451145
SCode.Flow sFl;
11461146
SCode.Stream sSt;
1147+
Option<SCode.ConstrainClass> scc;
11471148

11481149
case (cc,finalPrefix,_,repl,vis, Absyn.CLASSDEF(replaceable_ = rp, class_ = (cl as Absyn.CLASS(name = n,partialPrefix = pa,finalPrefix = fi,encapsulatedPrefix = e,restriction = re,body = de,info = i))),_)
11491150
equation
@@ -1153,7 +1154,8 @@ algorithm
11531154
(_, redecl) = translateRedeclarekeywords(repl);
11541155
sRed = SCode.boolRedeclare(redecl);
11551156
sFin = SCode.boolFinal(finalPrefix);
1156-
sRep = Util.if_(rp,SCode.REPLACEABLE(cc),SCode.NOT_REPLACEABLE());
1157+
scc = translateConstrainClass(cc);
1158+
sRep = Util.if_(rp,SCode.REPLACEABLE(scc),SCode.NOT_REPLACEABLE());
11571159
sEnc = SCode.boolEncapsulated(e);
11581160
sPar = SCode.boolPartial(pa);
11591161
cls = SCode.CLASS(
@@ -1197,7 +1199,8 @@ algorithm
11971199
comment_1 = translateComment(comment);
11981200
sFin = SCode.boolFinal(finalPrefix);
11991201
sRed = SCode.boolRedeclare(redecl);
1200-
sRep = Util.if_(repl_1,SCode.REPLACEABLE(cc),SCode.NOT_REPLACEABLE());
1202+
scc = translateConstrainClass(cc);
1203+
sRep = Util.if_(repl_1,SCode.REPLACEABLE(scc),SCode.NOT_REPLACEABLE());
12011204
sFl = SCode.boolFlow(fl);
12021205
sSt = SCode.boolStream(st);
12031206
then
@@ -1306,6 +1309,32 @@ algorithm
13061309
end match;
13071310
end translateRedeclarekeywords;
13081311

1312+
protected function translateConstrainClass
1313+
input Option<Absyn.ConstrainClass> inConstrainClass;
1314+
output Option<SCode.ConstrainClass> outConstrainClass;
1315+
algorithm
1316+
outConstrainClass := match(inConstrainClass)
1317+
local
1318+
Absyn.Path cc_path;
1319+
list<Absyn.ElementArg> eltargs;
1320+
Option<Absyn.Comment> cmt;
1321+
Option<SCode.Comment> cc_cmt;
1322+
Absyn.Modification mod;
1323+
SCode.Mod cc_mod;
1324+
1325+
case SOME(Absyn.CONSTRAINCLASS(elementSpec =
1326+
Absyn.EXTENDS(path = cc_path, elementArg = eltargs), comment = cmt))
1327+
equation
1328+
mod = Absyn.CLASSMOD(eltargs, Absyn.NOMOD());
1329+
cc_mod = translateMod(SOME(mod), SCode.NOT_FINAL(), SCode.NOT_EACH());
1330+
cc_cmt = translateComment(cmt);
1331+
then
1332+
SOME(SCode.CONSTRAINCLASS(cc_path, cc_mod, cc_cmt));
1333+
1334+
else NONE();
1335+
end match;
1336+
end translateConstrainClass;
1337+
13091338
protected function translateVariability
13101339
"function: translateVariability
13111340
Converts an Absyn.Variability to SCode.Variability."

0 commit comments

Comments
 (0)