Package joust.optimisers.finalfold

Source Code of joust.optimisers.finalfold.FinalValueFinder

package joust.optimisers.finalfold;

import com.sun.tools.javac.code.Flags;
import joust.tree.annotatedtree.AJCTreeVisitor;
import joust.utils.logging.LogUtils;
import joust.utils.tree.evaluation.EvaluationContext;
import joust.utils.tree.evaluation.Value;
import lombok.experimental.ExtensionMethod;
import lombok.extern.java.Log;

import java.util.HashMap;
import java.util.logging.Logger;

import static joust.tree.annotatedtree.AJCTree.*;
import static com.sun.tools.javac.code.Symbol.*;

@Log
@ExtensionMethod({Logger.class, LogUtils.LogExtensions.class})
public class FinalValueFinder extends AJCTreeVisitor {
    public HashMap<VarSymbol, Value> values = new HashMap<VarSymbol, Value>();

    @Override
    protected void visitClassDef(AJCClassDecl that) {
        for (AJCVariableDecl varDef : that.fields) {
            if (varDef.getInit().isEmptyExpression()) {
                continue;
            }

            VarSymbol vSym = varDef.getTargetSymbol();

            if ((vSym.flags() & Flags.STATIC) != 0
             && (vSym.flags() & Flags.FINAL) != 0) {

                // Try to evaluate the initialiser expression now.
                // If the index is something we can evaluate at compile-time, we're okay.
                EvaluationContext context = new EvaluationContext();
                Value index = context.evaluate(varDef.getInit());

                if (index != Value.UNKNOWN) {
                    values.put(vSym, index);
                }
            }
        }
    }
}
TOP

Related Classes of joust.optimisers.finalfold.FinalValueFinder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.