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);