Skip to content

Commit

Permalink
minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Sep 20, 2023
1 parent 921639d commit a443cca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/org/rascalmpl/values/parsetrees/ProductionAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public static IConstructor getType(IConstructor tree) {
}

public static IConstructor getDefined(IConstructor tree) {
return (IConstructor) tree.get("def");
return (IConstructor) tree.get(0);
}

public static IConstructor setDefined(IConstructor tree, IConstructor sym) {
return (IConstructor) tree.set("def", sym);
return (IConstructor) tree.set(0 /*def */, sym);
}

public static IList getSymbols(IConstructor tree) {
if (isDefault(tree)) {
return (IList) tree.get("symbols");
return (IList) tree.get(1 /*symbols */);
}
return null;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public static String getSortName(IConstructor tree) {

public static ISet getAttributes(IConstructor tree) {
if (isDefault(tree)) {
return (ISet) tree.get("attributes");
return (ISet) tree.get(2 /* "attributes" */);
}

return ValueFactoryFactory.getValueFactory().set();
Expand Down
15 changes: 5 additions & 10 deletions src/org/rascalmpl/values/parsetrees/SymbolAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private SymbolAdapter() {

public static IConstructor delabel(IConstructor sym) {
if (isLabel(sym)) {
return (IConstructor) sym.get("symbol"); // do not use getSymbol() here!
return (IConstructor) sym.get(1 /*symbol*/); // do not use getSymbol() here!
}
return sym;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public static boolean isStartSort(IConstructor tree) {
public static IConstructor getStart(IConstructor tree) {
if (isStartSort(tree)) {
tree = delabel(tree);
return (IConstructor) tree.get("symbol");
return (IConstructor) tree.get(0 /* symbol */);
}
throw new ImplementationError("Symbol does not have a child named symbol: " + tree);
}
Expand All @@ -160,7 +160,7 @@ public static IConstructor getLabeledSymbol(IConstructor tree) {
public static IConstructor getSymbol(IConstructor tree) {
tree = delabel(tree);
if (isOpt(tree) || isIterPlus(tree) || isIterStar(tree) || isIterPlusSeps(tree) || isIterStarSeps(tree) || isMeta(tree) || isConditional(tree)) {
return ((IConstructor) tree.get("symbol"));
return ((IConstructor) tree.get(0 /*"symbol" */));
}

throw new ImplementationError("Symbol does not have a child named symbol: " + tree);
Expand Down Expand Up @@ -653,11 +653,6 @@ public static boolean isParameter(IConstructor symbol) {
return symbol.getConstructorType() == Symbol_Parameter;
}

public static IConstructor getRhs(IConstructor symbol) {
symbol = delabel(symbol);
return (IConstructor) symbol.get("rhs");
}

public static boolean isIterStarSeps(IConstructor rhs) {
rhs = delabel(rhs);
return rhs.getConstructorType() == Symbol_IterStarSeps;
Expand Down Expand Up @@ -1075,11 +1070,11 @@ private static IConstructor range(int begin, int end) {
}

private static int rangeBegin(IConstructor range) {
return ((IInteger) range.get("begin")).intValue();
return ((IInteger) range.get(0 /*begin */)).intValue();
}

private static int rangeEnd(IConstructor range) {
return ((IInteger) range.get("end")).intValue();
return ((IInteger) range.get(1 /*end*/)).intValue();
}

public static boolean isParametrizableType(IConstructor sort) {
Expand Down

0 comments on commit a443cca

Please sign in to comment.