use of com.googlecode.aviator.parser.VariableMeta in project aviatorscript by killme2008.
the class BaseExpression method populateFullNames.
private void populateFullNames() {
if (this.varFullNames == null) {
Map<String, VariableMeta> fullNames = getFullNameMetas();
final ArrayList<VariableMeta> metas = new ArrayList<>(fullNames.values());
Collections.sort(metas, new Comparator<VariableMeta>() {
@Override
public int compare(final VariableMeta o1, final VariableMeta o2) {
return Integer.compare(o1.getFirstIndex(), o2.getFirstIndex());
}
});
List<String> newFullNames = new ArrayList<>(fullNames.size());
for (VariableMeta meta : metas) {
newFullNames.add(meta.getName());
}
this.varFullNames = newFullNames;
}
}
use of com.googlecode.aviator.parser.VariableMeta in project aviatorscript by killme2008.
the class BaseExpression method getFullNameMetas.
public Map<String, VariableMeta> getFullNameMetas() {
Map<String, VariableMeta> fullNames = new LinkedHashMap<>(this.vars.size());
Set<String> parentVars = new HashSet<>(this.vars.size());
Set<String> definedVars = new HashSet<>();
for (VariableMeta m : this.vars) {
final String name = m.getName();
String[] tmps = Constants.SPLIT_PAT.split(name);
if (!m.isInit() && !definedVars.contains(tmps[0]) && !definedVars.contains(name) && m.getFirstIndex() >= 0) {
fullNames.put(name, m);
} else if (m.getFirstIndex() >= 0) {
// It's defined in current scope
definedVars.add(name);
definedVars.add(tmps[0]);
}
parentVars.add(name);
}
afterPopulateFullNames(fullNames, parentVars);
return fullNames;
}
use of com.googlecode.aviator.parser.VariableMeta in project aviatorscript by killme2008.
the class InterpretCodeGenerator method getResult.
@Override
public Expression getResult(final boolean unboxObject) {
final List<IR> instruments = this.instruments;
// for (IR ir : instruments) {
// System.out.println(ir);
// }
optimize(instruments);
resolveLabels(instruments);
final InterpretExpression exp = new InterpretExpression(this.instance, new ArrayList<VariableMeta>(this.variables.values()), this.constantPool, this.symbolTable, instruments, unboxObject);
exp.setLambdaBootstraps(this.lambdaBootstraps);
exp.setSourceFile(this.sourceFile);
exp.setFuncsArgs(this.funcsArgs);
return exp;
}
use of com.googlecode.aviator.parser.VariableMeta in project aviatorscript by killme2008.
the class InterpretCodeGenerator method onConstant.
@Override
public void onConstant(final Token<?> lookhead) {
if (LOAD_CONSTANTS_TYPE.contains(lookhead.getType())) {
VariableMeta meta = null;
if (lookhead.getType() == TokenType.Variable) {
meta = this.variables.get(lookhead.getLexeme());
}
emit(new LoadIR(this.sourceFile, lookhead, meta, this.constantPool.contains(lookhead)));
}
}
use of com.googlecode.aviator.parser.VariableMeta in project aviatorscript by killme2008.
the class BaseExpression method populateNames.
private void populateNames() {
if (this.varNames == null) {
if (this.varFullNames == null) {
populateFullNames();
}
List<String> newVarNames = new ArrayList<>(this.varFullNames.size());
Set<String> nameSet = new HashSet<>();
Set<String> parentInitNames = new HashSet<>();
for (VariableMeta m : this.vars) {
if (m.isInit() && !m.getName().contains(".") && m.getFirstIndex() >= 0) {
parentInitNames.add(m.getName());
}
}
for (String fName : this.varFullNames) {
String[] tmps = Constants.SPLIT_PAT.split(fName);
String sName = tmps[0];
if (!nameSet.contains(sName) && !parentInitNames.contains(sName)) {
newVarNames.add(sName);
nameSet.add(sName);
}
}
this.varNames = newVarNames;
}
}
Aggregations