public void visitVariable(Variable variable) { List<VariableElement> lookupVariables; DSLExpression receiver = variable.getReceiver(); if (variable.getName().equals("null")) { variable.setResolvedVariable(new CodeVariableElement(new CodeTypeMirror(TypeKind.NULL), "null")); } else { if (receiver == null) { if (variableElement.getSimpleName().toString().equals(variable.getName())) { variable.setResolvedVariable(variableElement); break; if (variable.getResolvedVariable() == null) { throw new InvalidExpressionException(String.format("%s cannot be resolved.", variable.getName()));
private static Map<Variable, CodeTree> castBoundTypes(Map<Variable, LocalVariable> bindings) { Map<Variable, CodeTree> resolvedBindings = new HashMap<>(); for (Variable variable : bindings.keySet()) { LocalVariable localVariable = bindings.get(variable); CodeTree resolved = localVariable.createReference(); TypeMirror sourceType = localVariable.getTypeMirror(); TypeMirror targetType = variable.getResolvedTargetType(); if (targetType == null) { targetType = variable.getResolvedType(); } if (!ElementUtils.isAssignable(sourceType, targetType)) { resolved = CodeTreeBuilder.createBuilder().cast(targetType, resolved).build(); } resolvedBindings.put(variable, resolved); } return resolvedBindings; }
Parameter resolvedParameter = specialization.findByVariable(variable.getResolvedVariable()); if (resolvedParameter != null) { LocalVariable localVariable;
public void visitVariable(Variable variable) { List<VariableElement> lookupVariables; DSLExpression receiver = variable.getReceiver(); if (variable.getName().equals("null")) { variable.setResolvedVariable(new CodeVariableElement(new CodeTypeMirror(TypeKind.NULL), "null")); } else { if (receiver == null) { if (variableElement.getSimpleName().toString().equals(variable.getName())) { variable.setResolvedVariable(variableElement); break; if (variable.getResolvedVariable() == null) { throw new InvalidExpressionException(String.format("%s cannot be resolved.", variable.getName()));
public void visitVariable(Variable variable) { VariableElement resolvedVariable = variable.getResolvedVariable(); CodeTree tree; if (variable.getResolvedType().getKind() == TypeKind.NULL) { tree = CodeTreeBuilder.singleString("null"); } else if (variable.getReceiver() == null) { if (isStatic(resolvedVariable)) { tree = staticReference(resolvedVariable); } else { tree = bindings.get(variable); boolean bound = true; if (tree == null) { tree = string(resolvedVariable.getSimpleName().toString()); bound = false; } if (root != null && !bound) { tree = combine(root, string("."), tree); } } } else { if (isStatic(resolvedVariable)) { throw new AssertionError("Static variables cannot have receivers."); } tree = combine(pop(), string("."), string(resolvedVariable.getSimpleName().toString())); } push(tree); }
DSLExpression MemberExpression(DSLExpression receiver) { DSLExpression result; result = null; Expect(1); Variable variable = new Variable(receiver, t.val); result = variable; if (la.kind == 11) { Get(); List<DSLExpression> parameters = new ArrayList<>(); DSLExpression parameter; if (StartOf(2)) { parameter = Expression(); parameters.add(parameter); while (la.kind == 13) { Get(); parameter = Expression(); parameters.add(parameter); } } Expect(12); result = new Call(variable.getReceiver(), variable.getName(), parameters); } if (la.kind == 14) { Get(); result = MemberExpression(result); } return result; }
private static Map<Variable, LocalVariable> bindExpressionValues(DSLExpression expression, SpecializationData specialization, LocalContext currentValues) throws AssertionError { Map<Variable, LocalVariable> bindings = new HashMap<>(); Set<Variable> boundVariables = expression.findBoundVariables(); if (specialization == null && !boundVariables.isEmpty()) { throw new AssertionError("Cannot bind guard variable in non-specialization group. yet."); } // resolve bindings for local context for (Variable variable : boundVariables) { Parameter resolvedParameter = specialization.findByVariable(variable.getResolvedVariable()); if (resolvedParameter != null) { LocalVariable localVariable; if (resolvedParameter.getSpecification().isSignature()) { NodeExecutionData execution = resolvedParameter.getSpecification().getExecution(); localVariable = currentValues.getValue(execution); } else { localVariable = currentValues.get(resolvedParameter.getLocalName()); } if (localVariable != null) { bindings.put(variable, localVariable); } } } return bindings; }
DSLExpression MemberExpression(DSLExpression receiver) { DSLExpression result; result = null; Expect(1); Variable variable = new Variable(receiver, t.val); result = variable; if (la.kind == 11) { Get(); List<DSLExpression> parameters = new ArrayList<>(); DSLExpression parameter; if (StartOf(2)) { parameter = Expression(); parameters.add(parameter); while (la.kind == 13) { Get(); parameter = Expression(); parameters.add(parameter); } } Expect(12); result = new Call(variable.getReceiver(), variable.getName(), parameters); } if (la.kind == 14) { Get(); result = MemberExpression(result); } return result; }
public void visitVariable(Variable variable) { VariableElement resolvedVariable = variable.getResolvedVariable(); CodeTree tree; if (variable.getResolvedType().getKind() == TypeKind.NULL) { tree = CodeTreeBuilder.singleString("null"); } else if (variable.getReceiver() == null) { if (isStatic(resolvedVariable)) { tree = staticReference(resolvedVariable); } else { tree = bindings.get(variable); boolean bound = true; if (tree == null) { tree = string(resolvedVariable.getSimpleName().toString()); bound = false; } if (root != null && !bound) { tree = combine(root, string("."), tree); } } } else { if (isStatic(resolvedVariable)) { throw new AssertionError("Static variables cannot have receivers."); } tree = combine(pop(), string("."), string(resolvedVariable.getSimpleName().toString())); } push(tree); }
@Override public DSLExpression visitBinary(Binary binary) { // signature: value == value can be folded to true if (IDENTITY_FOLD_OPERATORS.contains(binary.getOperator())) { if (binary.getLeft() instanceof Variable && binary.getRight() instanceof Variable) { Variable leftVar = ((Variable) binary.getLeft()); Variable rightVar = ((Variable) binary.getRight()); if (leftVar.equals(rightVar)) { // double and float cannot be folded as NaN is never identity equal if (!ElementUtils.typeEquals(leftVar.getResolvedType(), context.getType(float.class)) && !ElementUtils.typeEquals(leftVar.getResolvedType(), context.getType(double.class))) { return new BooleanLiteral(true); } } } } return super.visitBinary(binary); } });
private boolean isVariableAccessMember(Variable variable) { if (variable.getName().equals("null") && variable.getReceiver() == null) { return false; } Parameter p = specialization.findByVariable(variable.getResolvedVariable()); if (p == null && !variable.getResolvedVariable().getModifiers().contains(STATIC)) { DSLExpression receiver = variable.getReceiver(); if (receiver instanceof Variable) { return isVariableAccessMember((Variable) receiver); } else if (receiver instanceof Call) { return isMethodAccessMember((Call) receiver); } return true; } else if (p != null && p.getSpecification().isCached()) { return true; } return false; }
private static Map<Variable, CodeTree> castBoundTypes(Map<Variable, LocalVariable> bindings) { Map<Variable, CodeTree> resolvedBindings = new HashMap<>(); for (Variable variable : bindings.keySet()) { LocalVariable localVariable = bindings.get(variable); CodeTree resolved = localVariable.createReference(); TypeMirror sourceType = localVariable.getTypeMirror(); TypeMirror targetType = variable.getResolvedTargetType(); if (targetType == null) { targetType = variable.getResolvedType(); } if (!ElementUtils.isAssignable(sourceType, targetType)) { resolved = CodeTreeBuilder.createBuilder().startParantheses().cast(targetType, resolved).end().build(); } resolvedBindings.put(variable, resolved); } return resolvedBindings; }
@Override public DSLExpression visitVariable(Variable binary) { // on the slow path we can assume all cache expressions inlined. for (CacheExpression cache : source.getCaches()) { if (ElementUtils.variableEquals(cache.getParameter().getVariableElement(), binary.getResolvedVariable())) { return cache.getExpression(); } } return super.visitVariable(binary); }
@Override public void visitVariable(Variable variable) { if (variable.getReceiver() == null) { variables.add(variable); } }
@Override public DSLExpression reduce(DSLExpressionReducer reducer) { DSLExpression newReceiver = null; if (receiver != null) { newReceiver = receiver.reduceImpl(reducer); } Variable c = this; if (newReceiver != receiver) { c = new Variable(newReceiver, getName()); c.setResolvedTargetType(getResolvedTargetType()); c.setResolvedVariable(getResolvedVariable()); } return reducer.visitVariable(c); }
@Override public void visitVariable(Variable variable) { if (variable.getReceiver() == null) { variables.add(variable); } }
@Override public void visitVariable(Variable variable) { if (variable.getReceiver() == null) { variables.add(variable.getResolvedVariable()); } }
@Override public void visitVariable(Variable variable) { if (variable.getReceiver() == null) { variables.add(variable.getResolvedVariable()); } }