Mercurial > hg > truffle
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/GuardExpression.java @ 16851:2db61eddcb97
Truffle-DSL: argument syntax support for guards
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 18 Aug 2014 18:41:16 +0200 |
parents | 90984ae0eaa8 |
children | c88ab4f1f04a |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/GuardExpression.java Mon Aug 18 17:44:42 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/GuardExpression.java Mon Aug 18 18:41:16 2014 +0200 @@ -27,18 +27,43 @@ public final class GuardExpression { private GuardData resolvedGuard; + private NodeExecutionData[] resolvedChildren; private final String guardName; private final boolean negated; + private final String[] childNames; - public GuardExpression(String expression) { - if (expression.startsWith("!")) { - guardName = expression.substring(1, expression.length()); + public GuardExpression(String expression, boolean allowArguments) { + String exp = expression; + if (exp.startsWith("!")) { + exp = exp.substring(1, exp.length()); negated = true; } else { - guardName = expression; negated = false; } + + int argumentStart = exp.indexOf('('); + int endIndex = exp.lastIndexOf(')'); + if (allowArguments && argumentStart != -1 && endIndex != -1) { + guardName = exp.substring(0, argumentStart).trim(); + String arguments = exp.substring(argumentStart + 1, endIndex); + String[] children = arguments.split(","); + for (int i = 0; i < children.length; i++) { + children[i] = children[i].trim(); + } + if (children.length == 1 && children[0].isEmpty()) { + childNames = new String[0]; + } else { + childNames = children; + } + } else { + guardName = exp; + childNames = null; + } + } + + public String[] getChildNames() { + return childNames; } public boolean isResolved() { @@ -49,18 +74,32 @@ return guardName; } - public void setGuard(GuardData guard) { + public NodeExecutionData[] getResolvedChildren() { + return resolvedChildren; + } + + public void setResolvedChildren(NodeExecutionData[] resolvedChildren) { + this.resolvedChildren = resolvedChildren; + } + + public void setResolvedGuard(GuardData guard) { this.resolvedGuard = guard; } @Override public boolean equals(Object obj) { - if (obj instanceof GuardExpression) { + if (this == obj) { + return true; + } else if (obj instanceof GuardExpression) { GuardExpression other = (GuardExpression) obj; if (isResolved() && other.isResolved()) { - return resolvedGuard.equals(other.resolvedGuard) && negated == other.negated; + return resolvedGuard.equals(other.resolvedGuard) && negated == other.negated && Arrays.equals(resolvedChildren, other.resolvedChildren); } else { - return guardName.equals(other.guardName) && negated == other.negated; + boolean equal = guardName.equals(other.guardName) && negated == other.negated; + if (childNames != null && other.childNames != null) { + equal &= Arrays.equals(childNames, other.childNames); + } + return equal; } } return false; @@ -68,18 +107,13 @@ @Override public int hashCode() { - return Objects.hash(guardName, negated, resolvedGuard); + return Objects.hash(guardName, negated, resolvedGuard, resolvedChildren); } public final boolean implies(GuardExpression other) { - if (other == this) { + if (equals(other)) { return true; } - if (getGuardName().equals(other.getGuardName())) { - if (isNegated() == other.isNegated()) { - return true; - } - } if (isResolved() && other.isResolved()) { for (GuardExpression implies : getResolvedGuard().getImpliesExpressions()) {