diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/Performance.java b/src/org/rascalmpl/core/library/lang/rascalcore/Performance.java new file mode 100644 index 00000000..55b2ebba --- /dev/null +++ b/src/org/rascalmpl/core/library/lang/rascalcore/Performance.java @@ -0,0 +1,47 @@ +package org.rascalmpl.core.library.lang.rascalcore; + +import java.util.Objects; + +import io.usethesource.vallang.IBool; +import io.usethesource.vallang.ISourceLocation; +import io.usethesource.vallang.IValueFactory; + +public class Performance { + private final IValueFactory vf; + + public Performance(IValueFactory vf) { + this.vf = vf; + } + + private static boolean isSameFile(ISourceLocation inner, ISourceLocation outer) { + return Objects.equals(inner.getScheme(), outer.getScheme()) + && Objects.equals(inner.getAuthority(), outer.getAuthority()) + && Objects.equals(inner.getPath(), outer.getPath()) + && Objects.equals(inner.getQuery(), outer.getQuery()) + ; + } + + public IBool isStrictlyContainedIn2(ISourceLocation inner, ISourceLocation outer) { + if (!isSameFile(inner, outer)) { + return vf.bool(false); + } + // original code would also do full equality, but we don't need that due to the logic in the outer & inner offset compares + if (inner.hasOffsetLength()) { + int innerOffset = inner.getOffset(); + int innerLength = inner.getLength(); + if (outer.hasOffsetLength()) { + int outerOffset = outer.getOffset(); + int outerLength = outer.getLength(); + return vf.bool( + innerOffset == outerOffset && innerOffset + innerLength < outerOffset + outerLength + || innerOffset > outerOffset && innerOffset + innerLength <= outerOffset + outerLength + ); + } + else { + return vf.bool(innerOffset > 0); + } + } + return vf.bool(false); + } + +} diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/ADTandGrammar.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/ADTandGrammar.rsc index 77eb2736..07681eca 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/ADTandGrammar.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/ADTandGrammar.rsc @@ -136,6 +136,8 @@ void addCommonKeywordFields(Solver s){ list[&T <: node ] unsetRec(list[&T <: node] args) = [unsetRec(a) | a <- args]; bool isManualLayout(AProduction p) = (p has attributes && atag("manual"()) in p.attributes); +@javaClass{org.rascalmpl.core.library.lang.rascalcore.Performance} +java bool isStrictlyContainedIn2(loc a, loc b); tuple[TModel, ModuleStatus] addGrammar(str qualifiedModuleName, set[str] imports, set[str] extends, map[str,TModel] transient_tms, ModuleStatus ms){ try { @@ -155,7 +157,7 @@ tuple[TModel, ModuleStatus] addGrammar(str qualifiedModuleName, set[str] imports prodLocs1 = { k | loc k <- facts, aprod(_) := facts[k] }; // filter out productions contained in priority/associativity declarations - prodLocs2 = { k | k <- prodLocs1, !any(l <- prodLocs1, k != l, isStrictlyContainedIn(k, l)) }; + prodLocs2 = { k | k <- prodLocs1, !any(l <- prodLocs1, k != l, isStrictlyContainedIn2(k, l)) }; definedProductions += {