コード例 #1
0
ファイル: DirectiveBuilder.java プロジェクト: gaoxiaojun/dync
  private void writeDirectiveFile() {
    try (DirectiveWriter dirFile = new DirectiveWriter(fileName)) {
      for (MethodDescriptor matchDescriptor : matchBlocks.keySet()) {
        // Write match block with all options converted from commands
        dirFile.match(matchDescriptor);
        for (CompileCommand compileCommand : matchBlocks.get(matchDescriptor)) {
          handleCommand(dirFile, compileCommand);
        }
        if ("Inlinee.caller()".matches(matchDescriptor.getRegexp()) && !inlines.isEmpty()) {
          // Got a *.* match block, where inline would be written
          writeInlines(dirFile);
          inlines.clear();
        }
        dirFile.end(); // ends match block
      }

      /*
       * Write inline directive in the end to the latest match block
       * if we didn't do this before
       * Inlinee caller methods should match this block only
       */
      if (!inlines.isEmpty()) {
        Pair<Executable, Callable<?>> pair = METHODS.get(0);
        MethodDescriptor md = MethodGenerator.anyMatchDescriptor(pair.first);
        CompileCommand cc = new CompileCommand(Command.QUIET, md, null, Scenario.Type.DIRECTIVE);
        List<CompileCommand> commands = new ArrayList<>();

        // Add appropriate "*.*" match block
        commands.add(cc);
        matchBlocks.put(md, commands);
        // Add match block for this descriptor with inlines
        dirFile.match(md);
        writeInlines(dirFile);
        dirFile.end();
      }
      if (!matchBlocks.isEmpty()) {
        // terminates file
        dirFile.end();
      }
    }
  }
コード例 #2
0
ファイル: DirectiveBuilder.java プロジェクト: gaoxiaojun/dync
  @Override
  public void add(CompileCommand compileCommand) {
    isFileValid &= compileCommand.isValid();
    MethodDescriptor methodDescriptor = compileCommand.methodDescriptor;

    switch (compileCommand.command) {
      case INLINE:
      case DONTINLINE:
        inlines.add(compileCommand);
        break;
    }
    for (MethodDescriptor md : matchBlocks.keySet()) {
      if (methodDescriptor.getCanonicalString().matches(md.getRegexp())) {
        matchBlocks.get(md).add(compileCommand);
      }
    }
    if (!matchBlocks.containsKey(compileCommand.methodDescriptor)) {
      List<CompileCommand> commands = new ArrayList<>();
      commands.add(compileCommand);
      matchBlocks.put(compileCommand.methodDescriptor, commands);
    }
  }
コード例 #3
0
ファイル: DirectiveBuilder.java プロジェクト: gaoxiaojun/dync
  private State getState(Pair<Executable, Callable<?>> pair) {
    State state = null;
    MethodDescriptor execDesc = MethodGenerator.commandDescriptor(pair.first);
    boolean isMatchFound = false;

    if (stateMap.containsKey(pair.first)) {
      state = stateMap.get(pair.first);
    }
    for (MethodDescriptor matchDesc : matchBlocks.keySet()) {
      if (execDesc.getCanonicalString().matches(matchDesc.getRegexp())) {
        /*
         * if executable matches regex
         * then apply commands from this match to the state
         */
        for (CompileCommand cc : matchBlocks.get(matchDesc)) {
          if (state == null) {
            state = new State();
          }
          if (!isMatchFound) {
            // this is a first found match, apply all commands
            state.apply(cc);
          } else {
            // apply only inline directives
            switch (cc.command) {
              case INLINE:
              case DONTINLINE:
                state.apply(cc);
                break;
            }
          }
        }
        isMatchFound = true;
      }
    }
    return state;
  }