Skip to content

Commit

Permalink
- start to copy all functions do something with a ComponentRef from E…
Browse files Browse the repository at this point in the history
…xp into ComponentReference

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6548 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 24, 2010
1 parent 30f895f commit 32c2df8
Show file tree
Hide file tree
Showing 15 changed files with 2,750 additions and 2,742 deletions.
5 changes: 3 additions & 2 deletions Compiler/Ceval.mo
Expand Up @@ -56,6 +56,7 @@ package Ceval

public import Absyn;
public import AbsynDep;
public import ComponentReference;
public import DAE;
public import Env;
public import Interactive;
Expand Down Expand Up @@ -232,14 +233,14 @@ algorithm
// MetaModelica Partial Function. sjoelund
case (cache,env,DAE.CREF(componentRef = cr, ty = DAE.ET_FUNCTION_REFERENCE_VAR()),impl,st,_,MSG())
equation
str = Exp.crefStr(cr);
str = ComponentReference.crefStr(cr);
Error.addMessage(Error.META_CEVAL_FUNCTION_REFERENCE, {str});
then
fail();

case (cache,env,DAE.CREF(componentRef = cr, ty = DAE.ET_FUNCTION_REFERENCE_FUNC(builtin = _)),impl,st,_,MSG())
equation
str = Exp.crefStr(cr);
str = ComponentReference.crefStr(cr);
Error.addMessage(Error.META_CEVAL_FUNCTION_REFERENCE, {str});
then
fail();
Expand Down
144 changes: 143 additions & 1 deletion Compiler/ComponentReference.mo
Expand Up @@ -45,10 +45,152 @@ public import Absyn;
public import ClassInf;
public import DAE;
public import Graphviz;
public import System;

protected import Exp;
protected import RTOpts;
protected import Util;
protected import Exp;


public function crefPrependIdent "prepends (e..g as a suffix) an identifier to a component reference, given the identifier, subscript and the type
author: PA

Example
crefPrependIdent(a.b,c,{},Real) => a.b.c [Real]
crefPrependIdent(a,c,{1},Integer[1]) => a.c[1] [Integer[1]]

alternative names: crefAddSuffix, crefAddIdent
"
input DAE.ComponentRef cr;
input String ident;
input list<DAE.Subscript> subs;
input DAE.ExpType tp;
output DAE.ComponentRef newCr;
algorithm
newCr := matchcontinue(cr,ident,subs,tp)
local DAE.ExpType tp1; String id1; list<DAE.Subscript> subs1;
case(DAE.CREF_IDENT(id1,tp1,subs1),ident,subs,tp) then DAE.CREF_QUAL(id1,tp1,subs1,DAE.CREF_IDENT(ident,tp,subs));
case(DAE.CREF_QUAL(id1,tp1,subs1,cr),ident,subs,tp)
equation
cr = crefPrependIdent(cr,ident,subs,tp);
then DAE.CREF_QUAL(id1,tp1,subs1,cr);
end matchcontinue;
end crefPrependIdent;


public function crefToPath
"function: crefToPath
This function converts a ComponentRef to a Path, if possible.
If the component reference contains subscripts, it will silently
fail."
input DAE.ComponentRef inComponentRef;
output Absyn.Path outPath;
algorithm
outPath:=
matchcontinue (inComponentRef)
local
DAE.Ident i;
Absyn.Path p;
DAE.ComponentRef c;
case DAE.CREF_IDENT(ident = i,subscriptLst = {}) then Absyn.IDENT(i);
case DAE.CREF_QUAL(ident = i,subscriptLst = {},componentRef = c)
equation
p = crefToPath(c);
then
Absyn.QUALIFIED(i,p);
end matchcontinue;
end crefToPath;

public function pathToCref
"function: pathToCref
This function converts a Absyn.Path to a ComponentRef."
input Absyn.Path inPath;
output DAE.ComponentRef outComponentRef;
algorithm
outComponentRef:=
matchcontinue (inPath)
local
DAE.Ident i;
DAE.ComponentRef c;
Absyn.Path p;
case Absyn.IDENT(name = i) then DAE.CREF_IDENT(i,DAE.ET_OTHER(),{});
case (Absyn.FULLYQUALIFIED(p)) then pathToCref(p);
case Absyn.QUALIFIED(name = i,path = p)
equation
c = pathToCref(p);
then
DAE.CREF_QUAL(i,DAE.ET_OTHER(),{},c);
end matchcontinue;
end pathToCref;

public function crefLastPath
"Returns the last identifier of a cref as an Absyn.IDENT."
input DAE.ComponentRef inComponentRef;
output Absyn.Path outPath;
algorithm
outPath := matchcontinue(inComponentRef)
local
DAE.Ident i;
DAE.ComponentRef c;
case DAE.CREF_IDENT(ident = i, subscriptLst = {}) then Absyn.IDENT(i);
case DAE.CREF_QUAL(componentRef = c, subscriptLst = {}) then crefLastPath(c);
end matchcontinue;
end crefLastPath;

public function crefSortFunc "A sorting function (greatherThan) for crefs"
input DAE.ComponentRef cr1;
input DAE.ComponentRef cr2;
output Boolean greaterThan;
algorithm
greaterThan := System.strcmp(Exp.printComponentRefStr(cr1),Exp.printComponentRefStr(cr2)) > 0;
end crefSortFunc;

public function crefToStr
"function: crefStr
This function converts a ComponentRef to a String.
It is a tail recursive implementation, because of that it
neads inPreString. Use inNameSeperator to define the
Separator inbetween and between the namespace names and the name"
input String inPreString;
input DAE.ComponentRef inComponentRef "The ComponentReference";
input String inNameSeparator "The Separator between the Names";
output String outString;
algorithm
outString:=
matchcontinue (inPreString,inComponentRef,inNameSeparator)
local
DAE.Ident s,ns,s1,ss;
DAE.ComponentRef n;
case (inPreString,DAE.CREF_IDENT(ident = s),_)
equation
ss = stringAppend(inPreString, s);
then ss;
case (inPreString,DAE.CREF_QUAL(ident = s,componentRef = n),inNameSeparator)
equation
ns = System.stringAppendList({inPreString, s, inNameSeparator});
ss = crefToStr(ns,n,inNameSeparator);
then
ss;
end matchcontinue;
end crefToStr;

public function crefStr
"function: crefStr
This function simply converts a ComponentRef to a String."
input DAE.ComponentRef inComponentRef;
output String outString;
algorithm
outString:= crefToStr("",inComponentRef,".");
end crefStr;

public function crefModelicaStr
"function: crefModelicaStr
Same as crefStr, but uses _ instead of . "
input DAE.ComponentRef inComponentRef;
output String outString;
algorithm
outString:= crefToStr("",inComponentRef,"_");
end crefModelicaStr;


end ComponentReference;
Expand Down
3 changes: 2 additions & 1 deletion Compiler/DAELowUtil.mo
Expand Up @@ -48,6 +48,7 @@ package DAELowUtil
in the BLT sorting."

public import DAE;
public import ComponentReference;
public import Exp;
public import Util;
public import DAELow;
Expand Down Expand Up @@ -81,7 +82,7 @@ algorithm
equation
print("Error in Exp ");
print(Exp.printExpStr(e));print("\n Variables: ");
strcrefs = Util.listMap(crefs,Exp.crefStr);
strcrefs = Util.listMap(crefs,ComponentReference.crefStr);
print(Util.stringDelimitList(strcrefs,", "));print("\nnot found in DAELow object.\n");
printcheckDEALowWithErrorMsg(res);
then
Expand Down
137 changes: 0 additions & 137 deletions Compiler/Exp.mo
Expand Up @@ -217,143 +217,6 @@ algorithm
print("--------------------\n");
end dumpExp;

public function crefPrependIdent "prepends (e..g as a suffix) an identifier to a component reference, given the identifier, subscript and the type
author: PA

Example
crefPrependIdent(a.b,c,{},Real) => a.b.c [Real]
crefPrependIdent(a,c,{1},Integer[1]) => a.c[1] [Integer[1]]

alternative names: crefAddSuffix, crefAddIdent
"
input ComponentRef cr;
input String ident;
input list<DAE.Subscript> subs;
input DAE.ExpType tp;
output ComponentRef newCr;
algorithm
newCr := matchcontinue(cr,ident,subs,tp)
local DAE.ExpType tp1; String id1; list<DAE.Subscript> subs1;
case(DAE.CREF_IDENT(id1,tp1,subs1),ident,subs,tp) then DAE.CREF_QUAL(id1,tp1,subs1,DAE.CREF_IDENT(ident,tp,subs));
case(DAE.CREF_QUAL(id1,tp1,subs1,cr),ident,subs,tp) equation
cr = crefPrependIdent(cr,ident,subs,tp);
then DAE.CREF_QUAL(id1,tp1,subs1,cr);
end matchcontinue;
end crefPrependIdent;

public function crefToPath
"function: crefToPath
This function converts a ComponentRef to a Path, if possible.
If the component reference contains subscripts, it will silently
fail."
input ComponentRef inComponentRef;
output Absyn.Path outPath;
algorithm
outPath:=
matchcontinue (inComponentRef)
local
Ident i;
Absyn.Path p;
ComponentRef c;
case DAE.CREF_IDENT(ident = i,subscriptLst = {}) then Absyn.IDENT(i);
case DAE.CREF_QUAL(ident = i,subscriptLst = {},componentRef = c)
equation
p = crefToPath(c);
then
Absyn.QUALIFIED(i,p);
end matchcontinue;
end crefToPath;

public function crefLastPath
"Returns the last identifier of a cref as an Absyn.IDENT."
input ComponentRef inComponentRef;
output Absyn.Path outPath;
algorithm
outPath := matchcontinue(inComponentRef)
local
Ident i;
ComponentRef c;
case DAE.CREF_IDENT(ident = i, subscriptLst = {}) then Absyn.IDENT(i);
case DAE.CREF_QUAL(componentRef = c, subscriptLst = {}) then crefLastPath(c);
end matchcontinue;
end crefLastPath;

public function pathToCref
"function: pathToCref
This function converts a Absyn.Path to a ComponentRef."
input Absyn.Path inPath;
output ComponentRef outComponentRef;
algorithm
outComponentRef:=
matchcontinue (inPath)
local
Ident i;
ComponentRef c;
Absyn.Path p;
case Absyn.IDENT(name = i) then DAE.CREF_IDENT(i,DAE.ET_OTHER(),{});
case (Absyn.FULLYQUALIFIED(p)) then pathToCref(p);
case Absyn.QUALIFIED(name = i,path = p)
equation
c = pathToCref(p);
then
DAE.CREF_QUAL(i,DAE.ET_OTHER(),{},c);
end matchcontinue;
end pathToCref;

public function crefSortFunc "A sorting function (greatherThan) for crefs"
input ComponentRef cr1;
input ComponentRef cr2;
output Boolean greaterThan;
algorithm
greaterThan := System.strcmp(printComponentRefStr(cr1),printComponentRefStr(cr2)) > 0;
end crefSortFunc;

public function crefToStr
"function: crefStr
This function converts a ComponentRef to a String.
It is a tail recursive implementation, because of that it
neads inPreString. Use inNameSeperator to define the
Separator inbetween and between the namespace names and the name"
input String inPreString;
input ComponentRef inComponentRef "The ComponentReference";
input String inNameSeparator "The Separator between the Names";
output String outString;
algorithm
outString:=
matchcontinue (inPreString,inComponentRef,inNameSeparator)
local
Ident s,ns,s1,ss;
ComponentRef n;
case (inPreString,DAE.CREF_IDENT(ident = s),_)
equation
ss = stringAppend(inPreString, s);
then ss;
case (inPreString,DAE.CREF_QUAL(ident = s,componentRef = n),inNameSeparator)
equation
ns = System.stringAppendList({inPreString, s, inNameSeparator});
ss = crefToStr(ns,n,inNameSeparator);
then
ss;
end matchcontinue;
end crefToStr;

public function crefStr
"function: crefStr
This function simply converts a ComponentRef to a String."
input ComponentRef inComponentRef;
output String outString;
algorithm
outString:= crefToStr("",inComponentRef,".");
end crefStr;

public function crefModelicaStr
"function: crefModelicaStr
Same as crefStr, but uses _ instead of . "
input ComponentRef inComponentRef;
output String outString;
algorithm
outString:= crefToStr("",inComponentRef,"_");
end crefModelicaStr;

public function crefLastIdent
"function: crefLastIdent
Expand Down
1 change: 1 addition & 0 deletions Compiler/InnerOuter.mo
Expand Up @@ -37,6 +37,7 @@ package InnerOuter
RCS: $Id: InnerOuter.mo 4847 2010-01-21 22:45:09Z adrpo $"

import Absyn;
import ComponentReference;
import DAE;
import Env;
import Prefix;
Expand Down
7 changes: 4 additions & 3 deletions Compiler/Inst.mo
Expand Up @@ -83,6 +83,7 @@ public import Absyn;
public import ClassInf;
public import Connect;
public import ConnectionGraph;
public import ComponentReference;
public import DAE;
public import Env;
public import InnerOuter;
Expand Down Expand Up @@ -9806,7 +9807,7 @@ algorithm
// A package constant, first try to look it up local(top frame)
case (cache,(f::fs) ,path)
equation
crPath = Exp.pathToCref(path);
crPath = ComponentReference.pathToCref(path);
(cache,_,_,_,_,_,env,_,name) = Lookup.lookupVarInternal(cache, {f}, crPath, Lookup.SEARCH_ALSO_BUILTIN());
path3 = makeFullyQualified2(env,name);
then
Expand All @@ -9815,7 +9816,7 @@ algorithm
// TODO! FIXME! what do we do here??!!
case (cache,env,path)
equation
crPath = Exp.pathToCref(path);
crPath = ComponentReference.pathToCref(path);
(cache,env,_,_,_,_,_,_,name) = Lookup.lookupVarInPackages(cache, env, crPath, {}, Util.makeStatefulBoolean(false));
path3 = makeFullyQualified2(env,name);
then
Expand Down Expand Up @@ -11600,7 +11601,7 @@ algorithm
equation
finst_dims = Util.listFlatten(inst_dims);
dae_var_attr = DAEUtil.setFinalAttr(dae_var_attr,finalPrefix);
path = Exp.crefToPath(vn);
path = ComponentReference.crefToPath(vn);
ty = (tty,SOME(path));
then DAE.DAE({DAE.VAR(vn,kind,dir,prot,ty,e,finst_dims,fl,st,source,dae_var_attr,comment,io)});

Expand Down

0 comments on commit 32c2df8

Please sign in to comment.