Ejemplo n.º 1
0
  @Override
  public boolean shouldBreak(Statement statement, Statement previousStatement) {
    if (statement.getPosition() == null) {
      return false;
    }

    if (!this.regexp.matcher(statement.getPosition().getFileName()).matches()) {
      return false;
    }

    boolean result = false;

    if (this.line >= 0) {
      if (this.line <= statement.getPosition().getLine()) {
        if (previousStatement == null) {
          result = true;
        } else {
          result = (this.line > (previousStatement.getPosition().getLine() - 1));
        }
      } else {
        result = false;
      }
    }

    return result;
  }
Ejemplo n.º 2
0
 @Override
 public CodeBlock getCodeBlock() {
   return CodeBlock.newCodeBlock()
       .append(propertyName.getCodeBlock())
       .append(expr.getCodeBlock())
       .invokeinterface(
           DynJSCompiler.Types.Scope, "define", sig(void.class, String.class, Object.class));
 }
Ejemplo n.º 3
0
  void interpretedStatement(Statement statement, boolean strict) {
    Entry entry = getBlockManager().retrieve(statement.getStatementNumber());
    InterpretedBasicBlock interpreted =
        new InterpretedBasicBlock(this.interpFactory, statement, strict);
    entry.setCompiled(interpreted);

    aload(Arities.EXECUTION_CONTEXT);
    ldc(statement.getStatementNumber());
    invokevirtual(p(ExecutionContext.class), "retrieveBlockEntry", sig(Entry.class, int.class));
    invokevirtual(p(Entry.class), "getCompiled", sig(BasicBlock.class));
    // object
    aload(Arities.EXECUTION_CONTEXT);
    // obj context
    invokeinterface(p(BasicBlock.class), "call", sig(Completion.class, ExecutionContext.class));
    // completion
  }
  public JSFunction compile(
      final CompilationContext context,
      final String identifier,
      final String[] formalParameters,
      final Statement body,
      final boolean strict) {
    int statementNumber = body.getStatementNumber();
    BlockManager.Entry entry = context.getBlockManager().retrieve(statementNumber);
    BasicBlock code = entry.getCompiled();
    if (code == null) {
      code = new InterpretedBasicBlock(this.factory, body, strict);
      entry.setCompiled(code);
    }

    LexicalEnvironment lexEnv = null;

    if (identifier != null) {
      LexicalEnvironment funcEnv =
          LexicalEnvironment.newDeclarativeEnvironment(context.getLexicalEnvironment());
      ((DeclarativeEnvironmentRecord) funcEnv.getRecord()).createImmutableBinding(identifier);
      lexEnv = funcEnv;
    } else {
      lexEnv = context.getLexicalEnvironment();
    }

    JavascriptFunction function =
        new JavascriptFunction(
            context.getGlobalObject(), identifier, code, lexEnv, strict, formalParameters);
    if (identifier != null) {
      ((DeclarativeEnvironmentRecord) lexEnv.getRecord())
          .initializeImmutableBinding(identifier, function);
    }
    function.setDebugContext("<anonymous>");
    return function;
  }
Ejemplo n.º 5
0
 public static void injectLineNumber(CodeBlock block, Statement statement) {
   Position position = statement.getPosition();
   if (position != null) {
     LabelNode lineLabel = new LabelNode();
     block.line(position.getLine(), lineLabel);
     block.label(lineLabel);
   }
 }
Ejemplo n.º 6
0
  public void compiledFunction(
      final String identifier,
      final String[] formalParams,
      final Statement block,
      final boolean strict) {

    int statementNumber = block.getStatementNumber();
    Entry entry = blockManager.retrieve(statementNumber);

    // Stash statement if required
    if (entry.statement == null) {
      entry.statement = block;
    }

    // ----------------------------------------
    // ----------------------------------------

    aload(Arities.EXECUTION_CONTEXT);
    // context
    ldc(statementNumber);
    // context statement-number

    invokevirtual(p(ExecutionContext.class), "retrieveBlockEntry", sig(Entry.class, int.class));
    // entry

    aload(Arities.EXECUTION_CONTEXT);
    // entry context

    invokevirtual(p(ExecutionContext.class), "getCompiler", sig(JSCompiler.class));
    // entry compiler

    swap();
    // compiler entry

    getfield(p(Entry.class), "statement", ci(Statement.class));
    // compiler statement

    aload(Arities.EXECUTION_CONTEXT);
    // compiler statement context
    swap();
    // compiler context statement

    if (identifier != null) {
      ldc(identifier);
    } else {
      aconst_null();
    }
    // compiler context statement identifier
    swap();
    // compiler context identifier statement

    checkcast(p(BlockStatement.class));

    bipush(formalParams.length);
    // compiler context identifier statement params-en
    anewarray(p(String.class));
    // compiler context identifier statement params

    for (int i = 0; i < formalParams.length; ++i) {
      dup();
      bipush(i);
      ldc(formalParams[i]);
      aastore();
    }
    // compiler context identifier statement params
    swap();
    // compiler context identifier params statement

    if (strict) {
      iconst_1();
    } else {
      iconst_0();
    }

    // compiler context identifer params statement bool

    invokevirtual(
        p(JSCompiler.class),
        "compileFunction",
        sig(
            JSFunction.class,
            ExecutionContext.class,
            String.class,
            String[].class,
            Statement.class,
            boolean.class));
    // fn
  }
Ejemplo n.º 7
0
  public void compiledStatementBlock(
      final String grist, final Statement block, final boolean strict) {
    int statementNumber = block.getStatementNumber();
    Entry entry = blockManager.retrieve(statementNumber);

    // Stash statement if required
    if (entry.statement == null) {
      entry.statement = block;
    }

    // ----------------------------------------
    // ----------------------------------------

    aload(Arities.EXECUTION_CONTEXT);
    // context
    ldc(statementNumber);
    // context statement-num
    invokevirtual(p(ExecutionContext.class), "retrieveBlockEntry", sig(Entry.class, int.class));
    // entry

    aload(Arities.EXECUTION_CONTEXT);
    // entry context

    invokevirtual(p(ExecutionContext.class), "getCompiler", sig(JSCompiler.class));
    // entry compiler

    swap();
    // compiler entry

    aload(Arities.EXECUTION_CONTEXT);
    // compiler entry context

    swap();
    // compiler context entry

    ldc(grist);
    // compiler context entry grist

    swap();
    // compiler context grist entry

    getfield(p(Entry.class), "statement", ci(Statement.class));
    // compiler context grist statement

    if (strict) {
      iconst_1();
    } else {
      iconst_0();
    }

    // compiler context grist statement strict

    invokevirtual(
        p(JSCompiler.class),
        "compileBasicBlock",
        sig(
            BasicBlock.class,
            ExecutionContext.class,
            String.class,
            Statement.class,
            boolean.class));
    // basic-block

  }