/**
   * Creates an intrument functions compiler pass.
   *
   * @param compiler The JSCompiler
   * @param functionNames Assigned function identifiers.
   * @param templateFilename Template filename; for use during error reporting only.
   * @param appNameStr String to pass to appNameSetter.
   * @param readable Instrumentation template protobuf text.
   */
  InstrumentFunctions(
      AbstractCompiler compiler,
      FunctionNames functionNames,
      String templateFilename,
      String appNameStr,
      Readable readable) {
    this.compiler = compiler;
    this.functionNames = functionNames;
    this.templateFilename = templateFilename;
    this.appNameStr = appNameStr;

    Instrumentation.Builder builder = Instrumentation.newBuilder();
    try {
      TextFormat.merge(readable, builder);
    } catch (IOException e) {
      compiler.report(
          JSError.make(
              RhinoErrorReporter.PARSE_ERROR,
              "Error reading instrumentation template protobuf at " + templateFilename));
      this.initCodeSource = "";
      this.definedFunctionName = "";
      this.reportFunctionName = "";
      this.reportFunctionExitName = "";
      this.appNameSetter = "";
      this.declarationsToRemove = Lists.newArrayList();
      return;
    }

    Instrumentation template = builder.build();

    StringBuilder initCodeSourceBuilder = new StringBuilder();
    for (String line : template.getInitList()) {
      initCodeSourceBuilder.append(line).append("\n");
    }
    this.initCodeSource = initCodeSourceBuilder.toString();

    this.definedFunctionName = template.getReportDefined();
    this.reportFunctionName = template.getReportCall();
    this.reportFunctionExitName = template.getReportExit();
    this.appNameSetter = template.getAppNameSetter();

    this.declarationsToRemove = ImmutableList.copyOf(template.getDeclarationToRemoveList());
  }
  /**
   * Creates an instrument functions compiler pass.
   *
   * @param compiler The JSCompiler
   * @param functionNames Assigned function identifiers.
   * @param template Instrumentation template; for use during error reporting only.
   * @param appNameStr String to pass to appNameSetter.
   */
  InstrumentFunctions(
      AbstractCompiler compiler,
      FunctionNames functionNames,
      Instrumentation template,
      String appNameStr) {
    this.compiler = compiler;
    this.functionNames = functionNames;
    this.appNameStr = appNameStr;

    StringBuilder initCodeSourceBuilder = new StringBuilder();
    for (String line : template.getInitList()) {
      initCodeSourceBuilder.append(line).append("\n");
    }
    this.initCodeSource = initCodeSourceBuilder.toString();

    this.definedFunctionName = template.getReportDefined();
    this.reportFunctionName = template.getReportCall();
    this.reportFunctionExitName = template.getReportExit();
    this.appNameSetter = template.getAppNameSetter();

    this.declarationsToRemove = ImmutableList.copyOf(template.getDeclarationToRemoveList());
  }