/** * Returns the a reference to the {@link Label} with the given name. * * @param name * the name of the label. * * @return the {@link LabelReference} found, can not be null. * * @throws OutOfScopeException * if label with the given name can not be found. */ public LabelReference getLabel(final String name) { checkThread(); Label found = null; Context ctx = this; do { if (ctx.labels != null) { found = ctx.labels.get(name); } } while (found == null && (ctx = ctx.parent) != null); if (found == null) { throw new OutOfScopeException("Label not found: " + name); } return found.getReference(); }
/** * Returns the a reference to the {@link Label} with the given name. * * @param name * the name of the label. * * @return the {@link LabelReference} found, can not be null. * * @throws OutOfScopeException * if label with the given name can not be found. */ public LabelReference getLabel(final String name) { checkThread(); Label found = null; Context ctx = this; do { if (ctx.labels != null) { found = ctx.labels.get(name); } } while (found == null && (ctx = ctx.parent) != null); if (found == null) { throw new OutOfScopeException("Label not found: " + name); } return found.getReference(); }
private VariableReference getVariable(final String name, final boolean mustBeClassMember) { checkThread(); Variable found = null; Context ctx = this; do { if (ctx.variables != null) { final Variable var = ctx.variables.get(name); found = (mustBeClassMember && var != null && !variables.containsKey(var.getName())) ? null : var; } } while (found == null && (ctx = ctx.parent) != null); if (found == null) { missingSymbols.add(name); if (GenUtil.isPermissiveMode()) { return Variable.create(name, Object.class).getReference(); } else { throw new OutOfScopeException((mustBeClassMember) ? "this." + name : name + " not found.\nScope:\n" + this); } } return found.getReference(); }
private VariableReference getVariable(final String name, final boolean mustBeClassMember) { checkThread(); Variable found = null; Context ctx = this; do { if (ctx.variables != null) { final Variable var = ctx.variables.get(name); found = (mustBeClassMember && var != null && !variables.containsKey(var.getName())) ? null : var; } } while (found == null && (ctx = ctx.parent) != null); if (found == null) { missingSymbols.add(name); if (GenUtil.isPermissiveMode()) { return Variable.create(name, Object.class).getReference(); } else { throw new OutOfScopeException((mustBeClassMember) ? "this." + name : name + " not found.\nScope:\n" + this); } } return found.getReference(); }
public static Statement generate(final Context context, final Object o) { if (o instanceof VariableReference) { return context.getVariable(((VariableReference) o).getName()); } else if (o instanceof Variable) { final Variable v = (Variable) o; if (context.isScoped(v)) { return v.getReference(); } else { if (context.isPermissiveMode()) { return v.getReference(); } else { throw new OutOfScopeException("variable cannot be referenced from this scope: " + v.getName()); } } } else if (o instanceof Statement) { ((Statement) o).generate(context); return (Statement) o; } else { return LiteralFactory.getLiteral(context, o); } }
public static Statement generate(final Context context, final Object o) { if (o instanceof VariableReference) { return context.getVariable(((VariableReference) o).getName()); } else if (o instanceof Variable) { final Variable v = (Variable) o; if (context.isScoped(v)) { return v.getReference(); } else { if (context.isPermissiveMode()) { return v.getReference(); } else { throw new OutOfScopeException("variable cannot be referenced from this scope: " + v.getName()); } } } else if (o instanceof Statement) { ((Statement) o).generate(context); return (Statement) o; } else { return LiteralFactory.getLiteral(context, o); } }