Search in sources :

Example 1 with VariableMeta

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;
    }
}
Also used : ArrayList(java.util.ArrayList) VariableMeta(com.googlecode.aviator.parser.VariableMeta)

Example 2 with VariableMeta

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;
}
Also used : VariableMeta(com.googlecode.aviator.parser.VariableMeta) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 3 with VariableMeta

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;
}
Also used : InterpretExpression(com.googlecode.aviator.InterpretExpression) AssertTypeIR(com.googlecode.aviator.code.interpreter.ir.AssertTypeIR) NewLambdaIR(com.googlecode.aviator.code.interpreter.ir.NewLambdaIR) BranchUnlessIR(com.googlecode.aviator.code.interpreter.ir.BranchUnlessIR) LoadIR(com.googlecode.aviator.code.interpreter.ir.LoadIR) GotoIR(com.googlecode.aviator.code.interpreter.ir.GotoIR) OperatorIR(com.googlecode.aviator.code.interpreter.ir.OperatorIR) VisitLabelIR(com.googlecode.aviator.code.interpreter.ir.VisitLabelIR) ClearIR(com.googlecode.aviator.code.interpreter.ir.ClearIR) JumpIR(com.googlecode.aviator.code.interpreter.ir.JumpIR) PopIR(com.googlecode.aviator.code.interpreter.ir.PopIR) BranchIfIR(com.googlecode.aviator.code.interpreter.ir.BranchIfIR) SendIR(com.googlecode.aviator.code.interpreter.ir.SendIR) VariableMeta(com.googlecode.aviator.parser.VariableMeta)

Example 4 with VariableMeta

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)));
    }
}
Also used : LoadIR(com.googlecode.aviator.code.interpreter.ir.LoadIR) VariableMeta(com.googlecode.aviator.parser.VariableMeta)

Example 5 with VariableMeta

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;
    }
}
Also used : ArrayList(java.util.ArrayList) VariableMeta(com.googlecode.aviator.parser.VariableMeta) HashSet(java.util.HashSet)

Aggregations

VariableMeta (com.googlecode.aviator.parser.VariableMeta)6 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LoadIR (com.googlecode.aviator.code.interpreter.ir.LoadIR)2 LinkedHashMap (java.util.LinkedHashMap)2 BaseExpression (com.googlecode.aviator.BaseExpression)1 Expression (com.googlecode.aviator.Expression)1 InterpretExpression (com.googlecode.aviator.InterpretExpression)1 LiteralExpression (com.googlecode.aviator.LiteralExpression)1 AssertTypeIR (com.googlecode.aviator.code.interpreter.ir.AssertTypeIR)1 BranchIfIR (com.googlecode.aviator.code.interpreter.ir.BranchIfIR)1 BranchUnlessIR (com.googlecode.aviator.code.interpreter.ir.BranchUnlessIR)1 ClearIR (com.googlecode.aviator.code.interpreter.ir.ClearIR)1 GotoIR (com.googlecode.aviator.code.interpreter.ir.GotoIR)1 JumpIR (com.googlecode.aviator.code.interpreter.ir.JumpIR)1 NewLambdaIR (com.googlecode.aviator.code.interpreter.ir.NewLambdaIR)1 OperatorIR (com.googlecode.aviator.code.interpreter.ir.OperatorIR)1 PopIR (com.googlecode.aviator.code.interpreter.ir.PopIR)1 SendIR (com.googlecode.aviator.code.interpreter.ir.SendIR)1 VisitLabelIR (com.googlecode.aviator.code.interpreter.ir.VisitLabelIR)1