use of com.google.javascript.jscomp.NodeUtil.AllVarsDeclaredInFunction in project closure-compiler by google.
the class ReachingUseDefTester method computeReachingUses.
/**
* Runs `MaybeReachingVariableUse` pass to compute and store the may-be-reaching uses for all
* definitions of each variable in the test source.
*/
void computeReachingUses(String src, boolean async) {
Node script = parseScript(src, async);
root = script.getFirstChild();
Scope funcBlockScope = computeFunctionBlockScope(script, root);
ControlFlowGraph<Node> cfg = computeCfg(root);
HashSet<Var> escaped = new HashSet<>();
AllVarsDeclaredInFunction allVarsDeclaredInFunction = NodeUtil.getAllVarsDeclaredInFunction(compiler, scopeCreator, funcBlockScope.getParent());
Map<String, Var> allVarsInFn = allVarsDeclaredInFunction.getAllVariables();
DataFlowAnalysis.computeEscaped(funcBlockScope.getParent(), escaped, compiler, scopeCreator, allVarsInFn);
reachingUse = new MaybeReachingVariableUse(cfg, escaped, allVarsInFn);
reachingUse.analyze();
}
use of com.google.javascript.jscomp.NodeUtil.AllVarsDeclaredInFunction in project closure-compiler by google.
the class LiveVariablesAnalysisTest method computeLiveness.
private static LiveVariablesAnalysis computeLiveness(String src, boolean async) {
// Set up compiler
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setLanguage(LanguageMode.UNSUPPORTED);
options.setCodingConvention(new GoogleCodingConvention());
compiler.initOptions(options);
compiler.setLifeCycleStage(LifeCycleStage.NORMALIZED);
// Set up test case
src = (async ? "async " : "") + "function _FUNCTION(param1, param2 = 1, ...param3){" + src + "}";
Node n = compiler.parseTestCode(src).removeFirstChild();
checkState(n.isFunction(), n);
Node script = new Node(Token.SCRIPT, n);
script.setInputId(new InputId("test"));
assertThat(compiler.getErrors()).isEmpty();
// Create scopes
SyntacticScopeCreator scopeCreator = new SyntacticScopeCreator(compiler);
Scope scope = scopeCreator.createScope(n, Scope.createGlobalScope(script));
Scope childScope = scopeCreator.createScope(NodeUtil.getFunctionBody(n), scope);
// Control flow graph
ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, true);
cfa.process(null, n);
ControlFlowGraph<Node> cfg = cfa.getCfg();
// All variables declared in function
AllVarsDeclaredInFunction allVarsDeclaredInFunction = NodeUtil.getAllVarsDeclaredInFunction(compiler, scopeCreator, scope);
// Compute liveness of variables
LiveVariablesAnalysis analysis = new LiveVariablesAnalysis(cfg, scope, childScope, compiler, scopeCreator, allVarsDeclaredInFunction);
analysis.analyze();
return analysis;
}
Aggregations