Skip to content

Commit e2545be

Browse files
author
Peter Aronsson
committed
Fixed bug with fully qualified names (which are created during instantiation) not possible to look up over encapsulated boundaries: Introduced new record FULLYQUALIFIED in Absyn.Path for this.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2657 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 9e4e4b2 commit e2545be

File tree

10 files changed

+100
-17
lines changed

10 files changed

+100
-17
lines changed

Compiler/Absyn.mo

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,12 @@ uniontype Path "The type `Path\', on the other hand,
913913
Ident name "name" ;
914914
end IDENT;
915915

916+
record FULLYQUALIFIED "Used during instantiation for names that are fully qualified,
917+
i.e. the names are looked up from top scope directly like for instance Modelica.SIunits.Voltage
918+
Note: Not created during parsing, only during instantation to speedup/simplify lookup.
919+
"
920+
Path path;
921+
end FULLYQUALIFIED;
916922
end Path;
917923

918924
public
@@ -1070,6 +1076,10 @@ algorithm
10701076
ss = stringAppend(s1, ns);
10711077
then
10721078
ss;
1079+
case(FULLYQUALIFIED(path=n),str)
1080+
equation
1081+
ss = pathString2(n,str);
1082+
then ss;
10731083
end matchcontinue;
10741084
end pathString2;
10751085

@@ -1085,6 +1095,11 @@ algorithm
10851095
local
10861096
Ident res,n;
10871097
Path p;
1098+
case (FULLYQUALIFIED(path = p))
1099+
equation
1100+
res = pathLastIdent(p);
1101+
then
1102+
res;
10881103
case (QUALIFIED(path = p))
10891104
equation
10901105
res = pathLastIdent(p);
@@ -1106,6 +1121,7 @@ algorithm
11061121
local
11071122
Ident n;
11081123
Path p;
1124+
case (FULLYQUALIFIED(path = p)) then pathFirstIdent(p);
11091125
case (QUALIFIED(name = n,path = p)) then n;
11101126
case (IDENT(name = n)) then n;
11111127
end matchcontinue;
@@ -1122,6 +1138,8 @@ algorithm
11221138
equation
11231139
true = ModUtil.pathEqual(suffix_path,path);
11241140
then true;
1141+
case(suffix_path,FULLYQUALIFIED(path = p))
1142+
then pathSuffixOf(suffix_path,p);
11251143
case(suffix_path,QUALIFIED(name=_,path = p))
11261144
then pathSuffixOf(suffix_path,p);
11271145
case(_,_) then false;
@@ -1154,6 +1172,8 @@ public function removePrefix "removes the prefix_path from path, and returns the
11541172
algorithm
11551173
newPath := matchcontinue(prefix_path,path)
11561174
local Path p,p2; Ident id1,id2;
1175+
case (p,FULLYQUALIFIED(p2))
1176+
then removePrefix(p,p2);
11571177
case (QUALIFIED(name=id1,path=p),QUALIFIED(name=id2,path=p2)) equation
11581178
equality(id1=id2);
11591179
then removePrefix(p,p2);
@@ -1377,6 +1397,8 @@ algorithm
13771397
p_1 = joinPaths(p, p2);
13781398
then
13791399
QUALIFIED(str,p_1);
1400+
case(FULLYQUALIFIED(p),p2) then joinPaths(p,p2);
1401+
case(p,FULLYQUALIFIED(p2)) then joinPaths(p,p2);
13801402
end matchcontinue;
13811403
end joinPaths;
13821404

@@ -1423,6 +1445,9 @@ algorithm
14231445
p_1 = stripLast(p);
14241446
then
14251447
QUALIFIED(str,p_1);
1448+
case (FULLYQUALIFIED(p)) equation
1449+
p_1 = stripLast(p);
1450+
then FULLYQUALIFIED(p_1);
14261451
end matchcontinue;
14271452
end stripLast;
14281453

@@ -1439,6 +1464,7 @@ algorithm
14391464
local
14401465
Path p;
14411466
case (QUALIFIED(name = _,path = p)) then p;
1467+
case(FULLYQUALIFIED(p)) then stripFirst(p);
14421468
end matchcontinue;
14431469
end stripFirst;
14441470

@@ -1486,6 +1512,8 @@ algorithm
14861512
c = pathToCref(p);
14871513
then
14881514
CREF_QUAL(i,{},c);
1515+
case(FULLYQUALIFIED(p))
1516+
then pathToCref(p);
14891517
end matchcontinue;
14901518
end pathToCref;
14911519

Compiler/Ceval.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5197,7 +5197,7 @@ algorithm
51975197
resstr = Util.stringDelimitList(calledfuncsstrs_1, "\n\n");
51985198
then
51995199
(cache,resstr,(path :: gflist));
5200-
case (_,_,_,_)
5200+
case (_,_,env,_)
52015201
equation
52025202
Debug.fprint("failtrace", "/*- ceval_generate_function_str failed*/\n");
52035203
then

Compiler/Derive.mo

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ algorithm
697697
matchcontinue (inPath)
698698
case (Absyn.IDENT(name = "tanh")) then ();
699699
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "tanh")))) then ();
700+
case (Absyn.FULLYQUALIFIED(inPath)) equation isTanh(inPath); then ();
700701
end matchcontinue;
701702
end isTanh;
702703

@@ -707,6 +708,7 @@ algorithm
707708
matchcontinue (inPath)
708709
case (Absyn.IDENT(name = "cosh")) then ();
709710
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "cosh")))) then ();
711+
case (Absyn.FULLYQUALIFIED(inPath)) equation isCosh(inPath); then ();
710712
end matchcontinue;
711713
end isCosh;
712714

@@ -717,6 +719,7 @@ algorithm
717719
matchcontinue (inPath)
718720
case (Absyn.IDENT(name = "arccos")) then ();
719721
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "acos")))) then ();
722+
case (Absyn.FULLYQUALIFIED(inPath)) equation isACos(inPath); then ();
720723
end matchcontinue;
721724
end isACos;
722725

@@ -727,6 +730,7 @@ algorithm
727730
matchcontinue (inPath)
728731
case (Absyn.IDENT(name = "arcsin")) then ();
729732
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "asin")))) then ();
733+
case (Absyn.FULLYQUALIFIED(inPath)) equation isASin(inPath); then ();
730734
end matchcontinue;
731735
end isASin;
732736

@@ -737,6 +741,7 @@ algorithm
737741
matchcontinue (inPath)
738742
case (Absyn.IDENT(name = "arctan")) then ();
739743
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "atan")))) then ();
744+
case (Absyn.FULLYQUALIFIED(inPath)) equation isATan(inPath); then ();
740745
end matchcontinue;
741746
end isATan;
742747

@@ -747,6 +752,7 @@ algorithm
747752
matchcontinue (inPath)
748753
case (Absyn.IDENT(name = "arctan2")) then ();
749754
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "atan2")))) then ();
755+
case (Absyn.FULLYQUALIFIED(inPath)) equation isATan2(inPath); then ();
750756
end matchcontinue;
751757
end isATan2;
752758

@@ -757,6 +763,7 @@ algorithm
757763
matchcontinue (inPath)
758764
case (Absyn.IDENT(name = "sinh")) then ();
759765
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "sinh")))) then ();
766+
case (Absyn.FULLYQUALIFIED(inPath)) equation isSinh(inPath); then ();
760767
end matchcontinue;
761768
end isSinh;
762769

@@ -767,6 +774,7 @@ algorithm
767774
matchcontinue (inPath)
768775
case (Absyn.IDENT(name = "sin")) then ();
769776
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "sin")))) then ();
777+
case (Absyn.FULLYQUALIFIED(inPath)) equation isSin(inPath); then ();
770778
end matchcontinue;
771779
end isSin;
772780

@@ -777,6 +785,7 @@ algorithm
777785
matchcontinue (inPath)
778786
case (Absyn.IDENT(name = "cos")) then ();
779787
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "cos")))) then ();
788+
case (Absyn.FULLYQUALIFIED(inPath)) equation isCos(inPath); then ();
780789
end matchcontinue;
781790
end isCos;
782791

@@ -787,6 +796,7 @@ algorithm
787796
matchcontinue (inPath)
788797
case (Absyn.IDENT(name = "exp")) then ();
789798
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "exp")))) then ();
799+
case (Absyn.FULLYQUALIFIED(inPath)) equation isExp(inPath); then ();
790800
end matchcontinue;
791801
end isExp;
792802

@@ -796,7 +806,8 @@ algorithm
796806
_:=
797807
matchcontinue (inPath)
798808
case (Absyn.IDENT(name = "log")) then ();
799-
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "log")))) then ();
809+
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "log")))) then ();
810+
case (Absyn.FULLYQUALIFIED(inPath)) equation isLog(inPath); then ();
800811
end matchcontinue;
801812
end isLog;
802813

@@ -807,6 +818,7 @@ algorithm
807818
matchcontinue (inPath)
808819
case (Absyn.IDENT(name = "log10")) then ();
809820
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "log10")))) then ();
821+
case (Absyn.FULLYQUALIFIED(inPath)) equation isLog10(inPath); then ();
810822
end matchcontinue;
811823
end isLog10;
812824

@@ -817,6 +829,7 @@ algorithm
817829
matchcontinue (inPath)
818830
case (Absyn.IDENT(name = "sqrt")) then ();
819831
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "sqrt")))) then ();
832+
case (Absyn.FULLYQUALIFIED(inPath)) equation isSqrt(inPath); then ();
820833
end matchcontinue;
821834
end isSqrt;
822835

@@ -827,6 +840,7 @@ algorithm
827840
matchcontinue (inPath)
828841
case (Absyn.IDENT(name = "tan")) then ();
829842
case (Absyn.QUALIFIED(name = "Modelica",path = Absyn.QUALIFIED(name = "Math",path = Absyn.IDENT(name = "tan")))) then ();
843+
case (Absyn.FULLYQUALIFIED(inPath)) equation isTan(inPath); then ();
830844
end matchcontinue;
831845
end isTan;
832846
end Derive;

Compiler/Exp.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ algorithm
524524
ComponentRef c;
525525
Absyn.Path p;
526526
case Absyn.IDENT(name = i) then CREF_IDENT(i,{});
527+
case (Absyn.FULLYQUALIFIED(p)) then pathToCref(p);
527528
case Absyn.QUALIFIED(name = i,path = p)
528529
equation
529530
c = pathToCref(p);

Compiler/Inst.mo

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,20 @@ algorithm
447447
String name2,n,name;
448448
SCode.Class cdef;
449449
Env.Cache cache;
450+
DAE.DAElist daelst;
451+
// Fully qualified paths
452+
case (cache,cdecls,Absyn.FULLYQUALIFIED(path))
453+
equation
454+
(cache,daelst,env) = instantiateFunctionImplicit(cache,cdecls,path);
455+
then
456+
(cache,daelst,env);
457+
450458
case (cache,{},cr)
451459
equation
452460
Error.addMessage(Error.NO_CLASSES_LOADED, {});
453461
then
454462
fail();
463+
455464
case (cache,(cdecls as (_ :: _)),(path as Absyn.IDENT(name = name2))) /* top level class */
456465
equation
457466
(cache,env) = Builtin.initialEnv(cache);
@@ -470,9 +479,9 @@ algorithm
470479
cdef, {});
471480
then
472481
(cache,DAE.DAE(dae),env);
473-
case (_,_,_)
482+
case (_,_,path)
474483
equation
475-
print("-instantiateFunctionImplicit failed\n");
484+
print("-instantiateFunctionImplicit ");print(Absyn.pathString(path));print(" failed\n");
476485
then
477486
fail();
478487
end matchcontinue;
@@ -1470,6 +1479,17 @@ algorithm
14701479
Error.addMessage(Error.LOOKUP_ERROR, {cns,scope_str});
14711480
then
14721481
fail();
1482+
1483+
case (cache,env,mods,pre,csets,ci_state,SCode.DERIVED(Absyn.TPATH(path = cn, arrayDim = ad),mod = mod),re,prot,inst_dims,impl)
1484+
equation
1485+
failure((_,_,_) = Lookup.lookupClass(cache,env, cn, false));
1486+
Debug.fprint("failtrace", "- inst_classdef DERIVED( ");
1487+
Debug.fprint("failtrace", Absyn.pathString(cn));
1488+
Debug.fprint("failtrace", ") lookup failed\n ENV:");
1489+
Debug.fprint("failtrace",Env.printEnvStr(env));
1490+
then
1491+
fail();
1492+
14731493
case (_,env,_,_,_,_,_,_,_,_,_)
14741494
equation
14751495
Debug.fprint("failtrace", "- inst_classdef failed\n class :");
@@ -5484,15 +5504,7 @@ algorithm
54845504
NONE = Env.getEnvPath(env);
54855505
then
54865506
(cache,path);
5487-
5488-
/* case (cache,env,path)
5489-
local Absyn.Path envpath,newPath;
5490-
equation
5491-
SOME(envpath) = Env.getEnvPath(env);
5492-
newPath = Absyn.pathContainedIn(path,envpath);
5493-
//print("makeFullyQualified( contained =");print(Absyn.pathString(newPath));print("\n");
5494-
then (cache,newPath);*/
5495-
5507+
54965508
case (cache,env,path) /* To make a class fully qualified, the class path
54975509
is looked up in the environment.
54985510
The FQ path consist of the simple class name
@@ -5505,7 +5517,7 @@ algorithm
55055517
class_name = Absyn.pathLastIdent(path);
55065518
path_2 = Absyn.joinPaths(path_1, Absyn.IDENT(class_name));
55075519
then
5508-
(cache,path_2);
5520+
(cache,Absyn.FULLYQUALIFIED(path_2));
55095521
case (cache,env,path) then (cache,path); /* If it fails, leave name unchanged. */
55105522
end matchcontinue;
55115523
end makeFullyQualified;

Compiler/Lookup.mo

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,13 @@ algorithm
239239
//print(Env.printCacheStr(cache));
240240
then
241241
(cache,c,env);
242-
242+
// Fully qualified names are looked up in top scope.
243+
case (cache,env,Absyn.FULLYQUALIFIED(path),msg) equation
244+
f = Env.topFrame(env);
245+
(cache,c,env_1) = lookupClass2(cache,{f},path,msg);
246+
then
247+
(cache,c,env_1);
248+
243249
// Qualified names first identifier cached
244250
case (cache,env,(p as Absyn.QUALIFIED(name = pack,path = path)),msgflag)
245251
equation
@@ -1171,6 +1177,10 @@ algorithm
11711177
(cache,classEnv,_) = Inst.partialInstClassIn(cache,cenv_2, Types.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
11721178
new_ci_state, c, false, {});
11731179
then (cache,classEnv);
1180+
case(cache,env,path,msg)
1181+
equation
1182+
Debug.fprint("failtrace", "-lookupAndInstantiate failed\n");
1183+
then fail();
11741184
end matchcontinue;
11751185
end lookupAndInstantiate;
11761186

Compiler/Mod.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ algorithm
862862
mod = lookupCompModification(m, n);
863863
then
864864
mod;
865+
case (m,Absyn.FULLYQUALIFIED(p)) then lookupModificationP(m,p);
865866
case (m,Absyn.QUALIFIED(name = n,path = p))
866867
equation
867868
mod = lookupCompModification(m, n);

Compiler/ModUtil.mo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ algorithm
478478
String s,ns,s1,ss,str;
479479
Absyn.Path n;
480480
case (Absyn.IDENT(name = s),_) then s;
481+
case(Absyn.FULLYQUALIFIED(n),str) then pathString2(n,str);
481482
case (Absyn.QUALIFIED(name = s,path = n),str)
482483
equation
483484
ns = pathString2(n, str);
@@ -502,22 +503,30 @@ algorithm
502503
String id1,id2;
503504
Boolean res;
504505
Absyn.Path path1,path2;
506+
507+
case (Absyn.FULLYQUALIFIED(path1),path2) then pathEqual(path1,path2);
508+
509+
case (path1,Absyn.FULLYQUALIFIED(path2)) then pathEqual(path1,path2);
510+
505511
case (Absyn.IDENT(name = id1),Absyn.IDENT(name = id2))
506512
equation
507513
equality(id1 = id2);
508514
then
509515
true;
516+
510517
case (Absyn.IDENT(name = id1),Absyn.IDENT(name = id2))
511518
equation
512519
failure(equality(id1 = id2));
513520
then
514521
false;
522+
515523
case (Absyn.QUALIFIED(name = id1,path = path1),Absyn.QUALIFIED(name = id2,path = path2))
516524
equation
517525
equality(id1 = id2);
518526
res = pathEqual(path1, path2);
519527
then
520528
res;
529+
521530
case (Absyn.QUALIFIED(name = id1,path = path1),Absyn.QUALIFIED(name = id2,path = path2))
522531
equation
523532
failure(equality(id1 = id2));

Compiler/Static.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4911,6 +4911,7 @@ algorithm
49114911
Ident s,id;
49124912
Exp.ComponentRef cref;
49134913
Absyn.Path path;
4914+
case (Absyn.FULLYQUALIFIED(path)) then pathToComponentRef(path);
49144915
case (Absyn.IDENT(name = s)) then Exp.CREF_IDENT(s,{});
49154916
case (Absyn.QUALIFIED(name = id,path = path))
49164917
equation

0 commit comments

Comments
 (0)