private static void gatherSlotsUsed(Expression exp, IntHashSet slots) { if (exp instanceof VariableReference) { Binding binding = ((VariableReference)exp).getBinding(); if (binding == null) { throw new NullPointerException("Unbound variable at line " + exp.getLineNumber()); } if (!binding.isGlobal()) { int slot = binding.getLocalSlotNumber(); if (slot != -1) { if (!slots.contains(slot)) { slots.add(slot); } } } } else { Iterator iter = exp.iterateSubExpressions(); while (iter.hasNext()) { Expression sub = (Expression)iter.next(); gatherSlotsUsed(sub, slots); } } }
private static void gatherSlotsUsed(Expression exp, IntHashSet slots) { if (exp instanceof VariableReference) { Binding binding = ((VariableReference)exp).getBinding(); if (binding == null) { throw new NullPointerException("Unbound variable at line " + exp.getLineNumber()); } if (!binding.isGlobal()) { int slot = binding.getLocalSlotNumber(); if (slot != -1) { if (!slots.contains(slot)) { slots.add(slot); } } } } else { Iterator iter = exp.iterateSubExpressions(); while (iter.hasNext()) { Expression sub = (Expression)iter.next(); gatherSlotsUsed(sub, slots); } } }
/** * Replace this VariableReference where appropriate by a more efficient implementation. This * can only be done after all slot numbers are allocated. The efficiency is gained by binding the * VariableReference directly to a local or global slot, rather than going via the Binding object * @param parent the parent expression of this variable reference */ public void refineVariableReference(Expression parent) { if (binding instanceof Assignation || binding instanceof LocalParam || binding instanceof UserFunctionParameter) { // A LocalVariableReference can be evaluated directly, without going via the Binding object. int slot = binding.getLocalSlotNumber(); if (slot < 0) { // if slots haven't been allocated yet, we've come here too early. // See test group036 with -T option for an example. return; } LocalVariableReference ref = new LocalVariableReference(); ref.setSlotNumber(slot); ref.binding = binding; ref.staticType = staticType; ref.displayName = displayName; ExpressionTool.copyLocationInfo(this, ref); boolean found = parent.replaceSubExpression(this, ref); if (!found) { throw new IllegalStateException("Child expression not found in parent"); } } }
/** * Replace this VariableReference where appropriate by a more efficient implementation. This * can only be done after all slot numbers are allocated. The efficiency is gained by binding the * VariableReference directly to a local or global slot, rather than going via the Binding object * @param parent the parent expression of this variable reference */ public void refineVariableReference(Expression parent) { if (binding instanceof Assignation || binding instanceof LocalParam || binding instanceof UserFunctionParameter) { // A LocalVariableReference can be evaluated directly, without going via the Binding object. int slot = binding.getLocalSlotNumber(); if (slot < 0) { // if slots haven't been allocated yet, we've come here too early. // See test group036 with -T option for an example. return; } LocalVariableReference ref = new LocalVariableReference(); ref.setSlotNumber(slot); ref.binding = binding; ref.staticType = staticType; ref.displayName = displayName; ExpressionTool.copyLocationInfo(this, ref); boolean found = parent.replaceSubExpression(this, ref); if (!found) { throw new IllegalStateException("Child expression not found in parent"); } } }
Binding binding = var.getBinding(); if (exp instanceof LocalVariableReference) { ((LocalVariableReference)var).setSlotNumber(binding.getLocalSlotNumber()); if (binding instanceof Assignation && binding.getLocalSlotNumber() < 0) {
Binding binding = var.getBinding(); if (exp instanceof LocalVariableReference) { ((LocalVariableReference)var).setSlotNumber(binding.getLocalSlotNumber()); if (binding instanceof Assignation && binding.getLocalSlotNumber() < 0) {