Skip to content

Commit

Permalink
ticket:4132
Browse files Browse the repository at this point in the history
Added pathStripSamePrefix function for addComponent API. Makes the path relative to class.
  • Loading branch information
adeas31 authored and OpenModelica-Hudson committed Nov 11, 2016
1 parent 7f31e31 commit ba31924
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -2993,6 +2993,31 @@ algorithm
end match;
end pathRest;

public function pathStripSamePrefix
"strips the same prefix paths and returns the stripped path. e.g pathStripSamePrefix(P.M.A, P.M.B) => A"
input Absyn.Path inPath1;
input Absyn.Path inPath2;
output Absyn.Path outPath;
algorithm
outPath := matchcontinue(inPath1, inPath2)
local
Ident ident1, ident2;
Absyn.Path path1, path2;

case (_, _)
equation
ident1 = pathFirstIdent(inPath1);
ident2 = pathFirstIdent(inPath2);
true = stringEq(ident1, ident2);
path1 = stripFirst(inPath1);
path2 = stripFirst(inPath2);
then
pathStripSamePrefix(path1, path2);

else inPath1;
end matchcontinue;
end pathStripSamePrefix;

public function pathPrefix
"Returns the prefix of a path, i.e. this.is.a.path => this.is.a"
input Path path;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -9002,7 +9002,7 @@ algorithm
newcdef = addToPublic(cdef,
Absyn.ELEMENTITEM(
Absyn.ELEMENT(false,redecl,io,
Absyn.COMPONENTS(attr,Absyn.TPATH(tppath,NONE()),{
Absyn.COMPONENTS(attr,Absyn.TPATH(Absyn.pathStripSamePrefix(tppath,modelpath),NONE()),{
Absyn.COMPONENTITEM(Absyn.COMPONENT(name,{},modification),NONE(),annotation_)}),
SOURCEINFO(filename,false,0,0,0,0,0.0),NONE())));
newp = updateProgram(Absyn.PROGRAM({newcdef},w), p);
Expand Down

0 comments on commit ba31924

Please sign in to comment.