com.google.javascript.jscomp.type.ReverseAbstractInterpreter Java Examples

The following examples show how to use com.google.javascript.jscomp.type.ReverseAbstractInterpreter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Nopol2017_0029_t.java    From coming with MIT License 6 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    MemoizedScopeCreator scopeCreator,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = reportUnknownTypes;
  this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
 
Example #2
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    ScopeCreator scopeCreator,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = reportUnknownTypes;
  this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
 
Example #3
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    ScopeCreator scopeCreator,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = reportUnknownTypes;
  this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
 
Example #4
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    MemoizedScopeCreator scopeCreator,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = reportUnknownTypes;
  this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
 
Example #5
Source File: Closure_2_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    MemoizedScopeCreator scopeCreator,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = reportUnknownTypes;
  this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
 
Example #6
Source File: TypeCheck.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    MemoizedScopeCreator scopeCreator,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = reportUnknownTypes;
  this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
 
Example #7
Source File: Nopol2017_0029_s.java    From coming with MIT License 6 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    MemoizedScopeCreator scopeCreator,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = reportUnknownTypes;
  this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
 
Example #8
Source File: TypeInference.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
TypeInference(AbstractCompiler compiler, ControlFlowGraph<Node> cfg,
              ReverseAbstractInterpreter reverseInterpreter,
              Scope functionScope,
              Map<String, AssertionFunctionSpec> assertionFunctionsMap) {
  super(cfg, new LinkedFlowScope.FlowScopeJoinOp());
  this.compiler = compiler;
  this.registry = compiler.getTypeRegistry();
  this.reverseInterpreter = reverseInterpreter;
  this.unknownType = registry.getNativeObjectType(UNKNOWN_TYPE);

  this.syntacticScope = functionScope;
  inferArguments(functionScope);

  this.functionScope = LinkedFlowScope.createEntryLattice(functionScope);
  this.assertionFunctionsMap = assertionFunctionsMap;

  // For each local variable declared with the VAR keyword, the entry
  // type is VOID.
  Iterator<Var> varIt =
      functionScope.getDeclarativelyUnboundVarsWithoutTypes();
  while (varIt.hasNext()) {
    Var var = varIt.next();
    if (isUnflowable(var)) {
      continue;
    }

    this.functionScope.inferSlotType(
        var.getName(), getNativeType(VOID_TYPE));
  }

  this.bottomScope = LinkedFlowScope.createEntryLattice(
      Scope.createLatticeBottom(functionScope.getRootNode()));
}
 
Example #9
Source File: TypeInferencePass.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
TypeInferencePass(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    Scope topScope, MemoizedScopeCreator scopeCreator) {
  this.compiler = compiler;
  this.reverseInterpreter = reverseInterpreter;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;

  assertionFunctionsMap = Maps.newHashMap();
  for (AssertionFunctionSpec assertionFucntion :
      compiler.getCodingConvention().getAssertionFunctions()) {
    assertionFunctionsMap.put(assertionFucntion.getFunctionName(),
        assertionFucntion);
  }
}
 
Example #10
Source File: Compiler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ReverseAbstractInterpreter getReverseAbstractInterpreter() {
  if (abstractInterpreter == null) {
    ChainableReverseAbstractInterpreter interpreter =
        new SemanticReverseAbstractInterpreter(
            getCodingConvention(), getTypeRegistry());
    if (options.closurePass) {
      interpreter = new ClosureReverseAbstractInterpreter(
          getCodingConvention(), getTypeRegistry())
          .append(interpreter).getFirst();
    }
    abstractInterpreter = interpreter;
  }
  return abstractInterpreter;
}
 
Example #11
Source File: TypeCheck.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride, reportUnknownTypes);
}
 
Example #12
Source File: CompilerTestCase.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Returns a newly created TypeCheck. */
private static TypeCheck createTypeCheck(Compiler compiler,
    CheckLevel level) {
  ReverseAbstractInterpreter rai =
      new SemanticReverseAbstractInterpreter(compiler.getCodingConvention(),
          compiler.getTypeRegistry());

  return new TypeCheck(compiler, rai, compiler.getTypeRegistry(),
      level, CheckLevel.OFF);
}
 
Example #13
Source File: Closure_2_TypeCheck_t.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride, reportUnknownTypes);
}
 
Example #14
Source File: TypeInferenceTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void inFunction(String js) {
  // Parse the body of the function.
  String thisBlock = assumedThisType == null
      ? ""
      : "/** @this {" + assumedThisType + "} */";
  Node root = compiler.parseTestCode(
      "(" + thisBlock + " function() {" + js + "});");
  assertEquals("parsing error: " +
      Joiner.on(", ").join(compiler.getErrors()),
      0, compiler.getErrorCount());

  Node n = root.getFirstChild().getFirstChild();
  // Create the scope with the assumptions.
  TypedScopeCreator scopeCreator = new TypedScopeCreator(compiler);
  Scope assumedScope = scopeCreator.createScope(
      n, scopeCreator.createScope(root, null));
  for (Map.Entry<String,JSType> entry : assumptions.entrySet()) {
    assumedScope.declare(entry.getKey(), null, entry.getValue(), null, false);
  }
  // Create the control graph.
  ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, false);
  cfa.process(null, n);
  ControlFlowGraph<Node> cfg = cfa.getCfg();
  // Create a simple reverse abstract interpreter.
  ReverseAbstractInterpreter rai = compiler.getReverseAbstractInterpreter();
  // Do the type inference by data-flow analysis.
  TypeInference dfa = new TypeInference(compiler, cfg, rai, assumedScope,
      ASSERTION_FUNCTION_MAP);
  dfa.analyze();
  // Get the scope of the implicit return.
  BranchedFlowState<FlowScope> rtnState =
      cfg.getImplicitReturn().getAnnotation();
  returnScope = rtnState.getIn();
}
 
Example #15
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride, reportUnknownTypes);
}
 
Example #16
Source File: Closure_112_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
TypeInference(AbstractCompiler compiler, ControlFlowGraph<Node> cfg,
              ReverseAbstractInterpreter reverseInterpreter,
              Scope functionScope,
              Map<String, AssertionFunctionSpec> assertionFunctionsMap) {
  super(cfg, new LinkedFlowScope.FlowScopeJoinOp());
  this.compiler = compiler;
  this.registry = compiler.getTypeRegistry();
  this.reverseInterpreter = reverseInterpreter;
  this.unknownType = registry.getNativeObjectType(UNKNOWN_TYPE);

  this.syntacticScope = functionScope;
  inferArguments(functionScope);

  this.functionScope = LinkedFlowScope.createEntryLattice(functionScope);
  this.assertionFunctionsMap = assertionFunctionsMap;

  // For each local variable declared with the VAR keyword, the entry
  // type is VOID.
  Iterator<Var> varIt =
      functionScope.getDeclarativelyUnboundVarsWithoutTypes();
  while (varIt.hasNext()) {
    Var var = varIt.next();
    if (isUnflowable(var)) {
      continue;
    }

    this.functionScope.inferSlotType(
        var.getName(), getNativeType(VOID_TYPE));
  }

  this.bottomScope = LinkedFlowScope.createEntryLattice(
      Scope.createLatticeBottom(functionScope.getRootNode()));
}
 
Example #17
Source File: CompilerTestCase.java    From ng-closure-runner with MIT License 5 votes vote down vote up
/** Returns a newly created TypeCheck. */
private static TypeCheck createTypeCheck(Compiler compiler,
    CheckLevel level) {
  ReverseAbstractInterpreter rai =
      new SemanticReverseAbstractInterpreter(compiler.getCodingConvention(),
          compiler.getTypeRegistry());

  return new TypeCheck(compiler, rai, compiler.getTypeRegistry(), level);
}
 
Example #18
Source File: Closure_112_TypeInference_t.java    From coming with MIT License 5 votes vote down vote up
TypeInference(AbstractCompiler compiler, ControlFlowGraph<Node> cfg,
              ReverseAbstractInterpreter reverseInterpreter,
              Scope functionScope,
              Map<String, AssertionFunctionSpec> assertionFunctionsMap) {
  super(cfg, new LinkedFlowScope.FlowScopeJoinOp());
  this.compiler = compiler;
  this.registry = compiler.getTypeRegistry();
  this.reverseInterpreter = reverseInterpreter;
  this.unknownType = registry.getNativeObjectType(UNKNOWN_TYPE);

  this.syntacticScope = functionScope;
  inferArguments(functionScope);

  this.functionScope = LinkedFlowScope.createEntryLattice(functionScope);
  this.assertionFunctionsMap = assertionFunctionsMap;

  // For each local variable declared with the VAR keyword, the entry
  // type is VOID.
  Iterator<Var> varIt =
      functionScope.getDeclarativelyUnboundVarsWithoutTypes();
  while (varIt.hasNext()) {
    Var var = varIt.next();
    if (isUnflowable(var)) {
      continue;
    }

    this.functionScope.inferSlotType(
        var.getName(), getNativeType(VOID_TYPE));
  }

  this.bottomScope = LinkedFlowScope.createEntryLattice(
      Scope.createLatticeBottom(functionScope.getRootNode()));
}
 
Example #19
Source File: Closure_25_TypeInference_t.java    From coming with MIT License 5 votes vote down vote up
TypeInference(AbstractCompiler compiler, ControlFlowGraph<Node> cfg,
              ReverseAbstractInterpreter reverseInterpreter,
              Scope functionScope,
              Map<String, AssertionFunctionSpec> assertionFunctionsMap) {
  super(cfg, new LinkedFlowScope.FlowScopeJoinOp());
  this.compiler = compiler;
  this.registry = compiler.getTypeRegistry();
  this.reverseInterpreter = reverseInterpreter;
  this.syntacticScope = functionScope;
  this.functionScope = LinkedFlowScope.createEntryLattice(functionScope);
  this.assertionFunctionsMap = assertionFunctionsMap;

  // For each local variable declared with the VAR keyword, the entry
  // type is VOID.
  Iterator<Var> varIt =
      functionScope.getDeclarativelyUnboundVarsWithoutTypes();
  while (varIt.hasNext()) {
    Var var = varIt.next();
    if (isUnflowable(var)) {
      continue;
    }

    this.functionScope.inferSlotType(
        var.getName(), getNativeType(VOID_TYPE));
  }

  this.bottomScope = LinkedFlowScope.createEntryLattice(
      new Scope(functionScope.getRootNode(), functionScope.getTypeOfThis()));
}
 
Example #20
Source File: Nopol2017_0029_t.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride, reportUnknownTypes);
}
 
Example #21
Source File: Closure_25_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
TypeInference(AbstractCompiler compiler, ControlFlowGraph<Node> cfg,
              ReverseAbstractInterpreter reverseInterpreter,
              Scope functionScope,
              Map<String, AssertionFunctionSpec> assertionFunctionsMap) {
  super(cfg, new LinkedFlowScope.FlowScopeJoinOp());
  this.compiler = compiler;
  this.registry = compiler.getTypeRegistry();
  this.reverseInterpreter = reverseInterpreter;
  this.syntacticScope = functionScope;
  this.functionScope = LinkedFlowScope.createEntryLattice(functionScope);
  this.assertionFunctionsMap = assertionFunctionsMap;

  // For each local variable declared with the VAR keyword, the entry
  // type is VOID.
  Iterator<Var> varIt =
      functionScope.getDeclarativelyUnboundVarsWithoutTypes();
  while (varIt.hasNext()) {
    Var var = varIt.next();
    if (isUnflowable(var)) {
      continue;
    }

    this.functionScope.inferSlotType(
        var.getName(), getNativeType(VOID_TYPE));
  }

  this.bottomScope = LinkedFlowScope.createEntryLattice(
      new Scope(functionScope.getRootNode(), functionScope.getTypeOfThis()));
}
 
Example #22
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride, reportUnknownTypes);
}
 
Example #23
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride, reportUnknownTypes);
}
 
Example #24
Source File: Closure_31_Compiler_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public ReverseAbstractInterpreter getReverseAbstractInterpreter() {
  if (abstractInterpreter == null) {
    ChainableReverseAbstractInterpreter interpreter =
        new SemanticReverseAbstractInterpreter(
            getCodingConvention(), getTypeRegistry());
    if (options.closurePass) {
      interpreter = new ClosureReverseAbstractInterpreter(
          getCodingConvention(), getTypeRegistry())
          .append(interpreter).getFirst();
    }
    abstractInterpreter = interpreter;
  }
  return abstractInterpreter;
}
 
Example #25
Source File: Closure_31_Compiler_s.java    From coming with MIT License 5 votes vote down vote up
@Override
public ReverseAbstractInterpreter getReverseAbstractInterpreter() {
  if (abstractInterpreter == null) {
    ChainableReverseAbstractInterpreter interpreter =
        new SemanticReverseAbstractInterpreter(
            getCodingConvention(), getTypeRegistry());
    if (options.closurePass) {
      interpreter = new ClosureReverseAbstractInterpreter(
          getCodingConvention(), getTypeRegistry())
          .append(interpreter).getFirst();
    }
    abstractInterpreter = interpreter;
  }
  return abstractInterpreter;
}
 
Example #26
Source File: Nopol2017_0029_s.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride,
    CheckLevel reportUnknownTypes) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride, reportUnknownTypes);
}
 
Example #27
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    CheckLevel reportMissingOverride) {
  this(compiler, reverseInterpreter, typeRegistry, null, null,
      reportMissingOverride);
}
 
Example #28
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 5 votes vote down vote up
public TypeCheck(AbstractCompiler compiler,
    ReverseAbstractInterpreter reverseInterpreter,
    JSTypeRegistry typeRegistry,
    Scope topScope,
    MemoizedScopeCreator scopeCreator,
    CheckLevel reportMissingOverride) {
  this.compiler = compiler;
  this.validator = compiler.getTypeValidator();
  this.reverseInterpreter = reverseInterpreter;
  this.typeRegistry = typeRegistry;
  this.topScope = topScope;
  this.scopeCreator = scopeCreator;
  this.reportMissingOverride = reportMissingOverride;
  this.reportUnknownTypes = ((Compiler) compiler).getOptions().enables(
      DiagnosticGroups.REPORT_UNKNOWN_TYPES);
  this.inferJSDocInfo = new InferJSDocInfo(compiler);

  ClassLoader classLoader = TypeCheck.class.getClassLoader();
  try {
    Class<?> c = classLoader.loadClass(
        "com.google.common.string.EditDistance");
    editDistance = c.getDeclaredMethod(
        "getEditDistance", String.class, String.class, boolean.class);
  } catch (Exception ignored) {
    editDistance = null;
  }
}
 
Example #29
Source File: Closure_18_Compiler_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public ReverseAbstractInterpreter getReverseAbstractInterpreter() {
  if (abstractInterpreter == null) {
    ChainableReverseAbstractInterpreter interpreter =
        new SemanticReverseAbstractInterpreter(
            getCodingConvention(), getTypeRegistry());
    if (options.closurePass) {
      interpreter = new ClosureReverseAbstractInterpreter(
          getCodingConvention(), getTypeRegistry())
          .append(interpreter).getFirst();
    }
    abstractInterpreter = interpreter;
  }
  return abstractInterpreter;
}
 
Example #30
Source File: Closure_18_Compiler_s.java    From coming with MIT License 5 votes vote down vote up
@Override
public ReverseAbstractInterpreter getReverseAbstractInterpreter() {
  if (abstractInterpreter == null) {
    ChainableReverseAbstractInterpreter interpreter =
        new SemanticReverseAbstractInterpreter(
            getCodingConvention(), getTypeRegistry());
    if (options.closurePass) {
      interpreter = new ClosureReverseAbstractInterpreter(
          getCodingConvention(), getTypeRegistry())
          .append(interpreter).getFirst();
    }
    abstractInterpreter = interpreter;
  }
  return abstractInterpreter;
}