diff --git a/pom.xml b/pom.xml
index bdf05d0..0a3cf67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -183,7 +183,7 @@
org.rascalmpl
rascal
- 0.41.2
+ 0.41.3-RC4
provided
diff --git a/src/analysis/typepal/AType.rsc b/src/analysis/typepal/AType.rsc
index f492193..77cb095 100644
--- a/src/analysis/typepal/AType.rsc
+++ b/src/analysis/typepal/AType.rsc
@@ -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
diff --git a/src/analysis/typepal/Collector.rsc b/src/analysis/typepal/Collector.rsc
index ba7d534..7966b9b 100644
--- a/src/analysis/typepal/Collector.rsc
+++ b/src/analysis/typepal/Collector.rsc
@@ -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
diff --git a/src/analysis/typepal/Inspect.rsc b/src/analysis/typepal/Inspect.rsc
deleted file mode 100644
index 1e4f762..0000000
--- a/src/analysis/typepal/Inspect.rsc
+++ /dev/null
@@ -1,31 +0,0 @@
-@license{
-Copyright (c) 2017, Paul Klint
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-}
-module analysis::typepal::Inspect
-
-import analysis::typepal::Collector;
-import String;
-import IO;
-import ValueIO;
-
-void show(loc tmodelLoc, str _key){
-
- if(!endsWith(tmodelLoc.path, ".tpl")){
- println("Can only show files with `tpl` extension");
- return;
- }
- tm = readBinaryValueFile(#TModel, tmodelLoc);
- for(/Tree t := tm) iprintln(t);
- //for(d <- tm.defines, d.id == key){
- // iprintln(d, lineLimit=10000);
- //}
-}
\ No newline at end of file
diff --git a/src/analysis/typepal/StringSimilarity.rsc b/src/analysis/typepal/StringSimilarity.rsc
index 1283a4e..05c6541 100644
--- a/src/analysis/typepal/StringSimilarity.rsc
+++ b/src/analysis/typepal/StringSimilarity.rsc
@@ -67,11 +67,6 @@ list[str] similarWords(str w, set[str] vocabulary, int maxDistance)
= sort({ | 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);
diff --git a/src/analysis/typepal/TModel.rsc b/src/analysis/typepal/TModel.rsc
index fa84df9..75bb7ab 100644
--- a/src/analysis/typepal/TModel.rsc
+++ b/src/analysis/typepal/TModel.rsc
@@ -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;
@@ -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: <- 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)>
+ | <- 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> | <- 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> | <- 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) >
+ | <- 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 = {");