Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.41.2</version>
<version>0.41.3-RC4</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/typepal/AType.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module analysis::typepal::AType
import List;

extend analysis::typepal::GetLoc;
extend analysis::typepal::TModel;
import analysis::typepal::TModel;

data AType
= tvar(loc tname) // type variable, used for type inference
Expand Down
7 changes: 0 additions & 7 deletions src/analysis/typepal/Collector.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ import analysis::typepal::Messenger;
extend analysis::typepal::ConfigurableScopeGraph;
extend analysis::typepal::ICollector;

// TODO: remove these temporary copies of isContainedIn and isBefore
// (needed to break deployment cycle). They should reside in Location.rsc
private bool isContainedIn(loc inner, loc outer, map[loc,loc] m)
= isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer);
bool isBefore(loc inner, loc outer, map[loc,loc] m)
= isBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer);

// Extract (nested) tree locations and type variables from a list of dependencies
list[loc] dependenciesAslocList(list[value] dependencies){
return
Expand Down
31 changes: 0 additions & 31 deletions src/analysis/typepal/Inspect.rsc

This file was deleted.

5 changes: 0 additions & 5 deletions src/analysis/typepal/StringSimilarity.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ list[str] similarWords(str w, set[str] vocabulary, int maxDistance)
= sort({ <v, d> | str v <- vocabulary, d := lev(w, v), d <= maxDistance },
bool (WordSim x, WordSim y){ return x.sim < y.sim;}).word;

// TODO: remove this temporary copy of isContainedIn (needed to break deployment cycle)
// should reside in Location.rsc
private bool isContainedIn(loc inner, loc outer, map[loc,loc] m)
= isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer);

@synopsis{Find in TModel tm, names similar to Use u. Max edit distance comes from TypePal Configuration.}
list[str] similarNames(Use u, TModel tm){
w = getOrgId(u);
Expand Down
79 changes: 79 additions & 0 deletions src/analysis/typepal/TModel.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ module analysis::typepal::TModel
It can be extended to suit the needs of a specific type checker.
*/
import String;
import Location;
import Message;
import Node;
import IO;

import analysis::typepal::Version;
import analysis::typepal::AType;

data AType;

Expand Down Expand Up @@ -117,6 +119,83 @@ data TModel (
TypePalConfig config = tconfig()
) = tmodel();

@synopsis{Convert logical locations in a TModel to physical locations}
// This function can be written with a single (expensive) visit
// For efficiency reasons, this version avoids visits as much as possible
TModel convertTModel2PhysicalLocs(TModel tm){
if(tm.usesPhysicalLocs) return tm;

locMap = tm.logical2physical;
defines = {};
definitions = ();
for(d:<loc scope, str _, str _, IdRole _, loc defined, DefInfo defInfo> <- tm.defines){
defi = visit(defInfo){ case loc l => locMap[l] when l in locMap };
d1 = d[scope=(scope in locMap ? locMap[scope] : scope)]
[defined=(defined in locMap ? locMap[defined] : defined)]
[defInfo=defi];
defines += d1;
definitions[d1.defined] = d1;
}
tm.defines = defines;
tm.definitions = definitions;

tm.scopes = ( (outer in locMap ? locMap[outer] : outer) : (inner in locMap ? locMap[inner] : inner)
| loc outer <- tm.scopes, loc inner := tm.scopes[outer]
);
tm.paths = { <(from in locMap ? locMap[from] : from),
pathRole,
(to in locMap ? locMap[to] : to)>
| <loc from, PathRole pathRole, loc to> <- tm.paths
};

tm.referPaths = visit(tm.referPaths){ case loc l => locMap[l] when l in locMap };
tm.uses = visit(tm.uses){ case loc l => locMap[l] when l in locMap };
tm.definesMap = visit(tm.definesMap){ case loc l => locMap[l] when l in locMap };
tm.moduleLocs = ( key : (l in locMap ? locMap[l] : l)
| key <- tm.moduleLocs, l := tm.moduleLocs[key]
);
facts = tm.facts;
tm.facts = ((l in locMap ? locMap[l] : l)
: ( (overloadedAType(rel[loc, IdRole, AType] overloads) := atype)
? overloadedAType({ <(l in locMap ? locMap[l] : l), idr, at> | <l, idr, at> <- overloads })
: atype)
| l <- facts, atype := facts[l]
);
//tm.facts = visit(tm.facts){ case loc l => locMap[l] ? l };
tm.specializedFacts =
((l in locMap ? locMap[l] : l)
: ( (overloadedAType(rel[loc, IdRole, AType] overloads) := atype)
? overloadedAType({ <(l in locMap ? locMap[l] : l), idr, at> | <l, idr, at> <- overloads })
: atype)
| l <- tm.specializedFacts, atype := tm.specializedFacts[l]
);
//tm.specializedFacts = visit(tm.specializedFacts){ case loc l => locMap[l] ? l };
tm.useDef = { < (f in locMap ? locMap[f] : f),
(t in locMap ? locMap[t] : t) >
| <f, t> <- tm.useDef };
// Exlude messages from conversion: otherwise users would see logical locations
//tm.messages = visit(tm.messages){ case loc l => locMap[l] ? l };
tm.store = visit(tm.store){ case loc l => locMap[l] when l in locMap};
tm.config = visit(tm.config){ case loc l => locMap[l] when l in locMap};

tm.usesPhysicalLocs = true;
return tm;
}

@synopsis{Convert the logical locations in an arbitrary value to physical locations}
value convert2PhysicalLocs(value v, TModel tm){
locMap = tm.logical2physical;
return visit(v) { case loc l => locMap[l] when l in locMap};
}

// Generalized versions of isContainedIn and isBefore that take
// a logical -> physical mapping into account.
bool isContainedIn(loc inner, loc outer, map[loc,loc] m)
= isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer);

bool isBefore(loc inner, loc outer, map[loc,loc] m)
= isBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer);

void printTModel(TModel tm){
println("TModel(");
println(" defines = {");
Expand Down
Loading