Skip to content

Commit

Permalink
Add convertedToPhysical to TModel, maintains its state of conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Oct 29, 2024
1 parent 794ff25 commit 27364db
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
32 changes: 20 additions & 12 deletions src/analysis/typepal/Collector.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,26 @@ loc convertLoc(loc l, map[loc,loc] locMap)
= locMap[l] ? l;
TModel convertTModel2PhysicalLocs(TModel tm){
logical2physical = tm.logical2physical;
tm.logical2physical = ();
tm = convertLocs(tm, logical2physical);
tm.logical2physical = logical2physical;
if(!tm.convertedToPhysical){
logical2physical = tm.logical2physical;
tm.logical2physical = ();
tm = convertLocs(tm, logical2physical);
tm.logical2physical = logical2physical;
tm.convertedToPhysical = true;
}
return tm;
}
TModel convertTModel2LogicalLocs(TModel tm, map[str,TModel] tmodels){
tmodels[tm.modelName] = tm;
physical2logical = invertUnique((() | it + tm1.logical2physical | tm1 <- range(tmodels)));
logical2physical = tm.logical2physical;
tm.logical2physical = ();
tm = convertLocs(tm, physical2logical);
tm.logical2physical = logical2physical;
if(tm.convertedToPhysical){
tmodels[tm.modelName] = tm;
physical2logical = invertUnique((() | it + tm1.logical2physical | tm1 <- range(tmodels)));
logical2physical = tm.logical2physical;
tm.logical2physical = ();
tm = convertLocs(tm, physical2logical);
tm.logical2physical = logical2physical;
tm.convertedToPhysical = false;
}
return tm;
}
Expand Down Expand Up @@ -969,12 +975,14 @@ Collector newCollector(str modelName, map[str,Tree] namedTrees, TypePalConfig co
return extra_defines;
}

// We don't convert here logical/physical locations and just reuse
void collector_addTModel(TModel tm){
if(!isValidTplVersion(tm.version)){
throw wrongTplVersion("TModel for <tm.modelName> uses TPL version <tm.version>, but <getCurrentTplVersion()> is required");
}

//tm = convertTModel2PhysicalLocs(tm);
if(!tm.convertedToPhysical){
tm = convertTModel2PhysicalLocs(tm);
}

logical2physical += tm.logical2physical;
messages += tm.messages;
Expand Down
23 changes: 12 additions & 11 deletions src/analysis/typepal/Solver.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -1618,19 +1618,20 @@ Solver newSolver(map[str,Tree] namedTrees, TModel tm){

ldefines = for(tup: <loc _, str _, str _, IdRole _, loc defined, DefInfo defInfo> <- tm.defines){
if(defInfo has tree){
try {
dt = defType(tm.facts[getLoc(defInfo.tree)]);
l = getLoc(defInfo.tree);
if(tm.facts[l]?){
dt = defType(tm.facts[l]);
tup.defInfo = setKeywordParameters(dt, getKeywordParameters(defInfo));
} catch NoSuchKey(_): {
continue;
}
} else {
continue;
}
} else {
try {
dt = defType(tm.facts[defined]);
tup.defInfo = setKeywordParameters(dt, getKeywordParameters(defInfo));
} catch NoSuchKey(_): {
continue;
}
if(tm.facts[defined]?){
dt = defType(tm.facts[defined]);
tup.defInfo = setKeywordParameters(dt, getKeywordParameters(defInfo));
} else {
continue;
}
}
append tup;
};
Expand Down
17 changes: 9 additions & 8 deletions src/analysis/typepal/TModel.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data IdRole
str prettyRole(IdRole idRole){
stripped1 = replaceAll(getName(idRole), "Id", "");
return visit(stripped1) { case /<ch:[A-Z]>/ => toLowerCase(ch) };
}
}

// PathRole: the various (language-specific) labelled semantic paths
// between program parts
Expand All @@ -37,9 +37,9 @@ data PathRole;
data ScopeRole
= anonymousScope()
;

// Applied occurrence (use) of id for given IdRoles
// IdRoles are used to fold multiple scopeGraphs into one
// IdRoles are used to fold multiple scopeGraphs into one
// (e.g., one for class and package names, one for variable names etc.)
data Use
= use(str id, str orgId, loc occ, loc scope, set[IdRole] idRoles)
Expand Down Expand Up @@ -86,29 +86,30 @@ data TModel (
str version = getCurrentTplVersion(),
Defines defines = {},
Scopes scopes = (),
Paths paths = {},
Paths paths = {},
ReferPaths referPaths = {},
Uses uses = [],
map[loc, map[str, rel[IdRole idRole, loc defined]]] definesMap = (),
str modelName = "",
map[str,loc] moduleLocs = (),
set[Calculator] calculators = {},
map[loc,AType] facts = (),
map[loc,AType] specializedFacts = (),
map[loc,AType] facts = (),
map[loc,AType] specializedFacts = (),
set[Requirement] requirements = {},
rel[loc, loc] useDef = {},
list[Message] messages = [],
map[str,value] store = (),
map[loc, Define] definitions = (),
map[loc,loc] logical2physical = (),
bool convertedToPhysical = true, // Are locations in physical format?
TypePalConfig config = tconfig()
) = tmodel();

void printTModel(TModel tm){
println("TModel(");
println(" defines = {");
for(Define d <- tm.defines){
println(" \<<d.scope>, <d.id>, <d.idRole>, <d.defined>\>");
println(" \<<d.scope>, <d.id>, <d.idRole>, <d.defined>\>");
}
println(" },");
println(" facts = (");
Expand Down

0 comments on commit 27364db

Please sign in to comment.