Ejemplo n.º 1
0
 private void addPositionMetadata(Context cx, DefinitionNode def) {
   MetaDataNode mn = cx.getNodeFactory().metaData(null, -1);
   mn.id = "__go_to_definition_help";
   mn.values = new Value[2];
   mn.values[0] = new KeyValuePair("file", cx.getErrorOrigin());
   mn.values[1] = new KeyValuePair("pos", String.valueOf(def.pos()));
   def.addMetaDataNode(mn);
 }
Ejemplo n.º 2
0
  public Value evaluate(Context cx, MetaDataNode node) {
    current = node;

    if (node.data == null || node.data.elementlist == null) {
    } else if (node.data.elementlist.size() > 1) {
      cx.error(node.pos() - 1, kError_MetaDataAttributesHasMoreThanOneElement);
    } else if (node.data.elementlist.items.get(0) instanceof MemberExpressionNode) {
      MemberExpressionNode men = ((MemberExpressionNode) node.data.elementlist.items.get(0));
      SelectorNode selector = (men != null) ? men.selector : null;

      if (selector != null) {
        if (selector instanceof CallExpressionNode) {
          CallExpressionNode call = (CallExpressionNode) selector;

          if (call.expr != null) {
            KeylessValue val = (KeylessValue) call.expr.evaluate(cx, this);
            // node.values.add(val);
            current.id = val.obj;
          }

          if (call.args != null) {
            int length = call.args.size();
            node.values = new Value[length];
            for (int i = 0; i < length; i++) {
              Node n = call.args.items.get(i);
              Value value = n.evaluate(cx, this);
              if (value == null) {
                cx.error(n.pos() - 1, kError_InvalidMetaData);
              }
              node.values[i] = value;
            }
          }
        }

        if (selector instanceof GetExpressionNode) {
          // This is a metadatadata node for something like [Foo], with no arguments, so don't fill
          // in
          // the values, otherwise this case is indistinquishable from [Foo("Foo")] which will be
          // handled
          // by the CallExpressionNode block above.
          GetExpressionNode getexpr = (GetExpressionNode) selector;

          if (getexpr != null && getexpr.expr != null) {
            KeylessValue value = (KeylessValue) getexpr.expr.evaluate(cx, this);
            current.id = value.obj;
          }
        }
      }
    } else {
      if (node.data.elementlist.items.get(0) != null) {
        cx.error(node.data.elementlist.items.get(0).pos() - 1, kError_InvalidMetaData);
      } else {
        cx.error(node.pos() - 1, kError_InvalidMetaData);
      }
    }

    return null;
  }
Ejemplo n.º 3
0
  public Value evaluate(Context cx, ClassDefinitionNode node) {
    if (doing_class) return null;
    doing_class =
        true; // inner classes are included multiple times in node->staticinits.  Don't double
              // evaluate them.

    cx.pushStaticClassScopes(node);

    if (node.statements != null) node.statements.evaluate(cx, this);

    // now do the nested classes
    doing_class = false;
    {
      for (ClassDefinitionNode it : node.clsdefs) {
        it.evaluate(cx, this);
      }
    }

    cx.pushScope(node.iframe);

    {
      for (Node init : node.instanceinits) {
        if (cx.statics.es4_nullability && !init.isDefinition()) node.iframe.setInitOnly(true);

        init.evaluate(cx, this);

        if (cx.statics.es4_nullability && !init.isDefinition()) node.iframe.setInitOnly(false);
      }
    }

    cx.popScope(); // iframe
    cx.popStaticClassScopes(node);

    ClassDefinitionNode cdn = node;
    ReferenceValue ref = cdn.ref;
    Slot classSlot = null;
    if (ref != null) classSlot = ref.getSlot(cx);
    if (debugging) {
      addPositionMetadata(cx, cdn);
    }
    if (classSlot != null && classSlot.getMetadata() == null && cdn.metaData != null)
      for (Node meta_node : cdn.metaData.items) {
        if (meta_node instanceof MetaDataNode) {
          addMetadataToSlot(cx, classSlot, (MetaDataNode) meta_node);
          int i = isVersionMetadata(cx, (MetaDataNode) meta_node);
          if (i > -1) cdn.version = i;
        }
      }

    return null;
  }
Ejemplo n.º 4
0
  public Value evaluate(Context cx, VariableBindingNode node) {
    if (node.variable != null) node.variable.evaluate(cx, this);

    if (cx.statics.es4_nullability && cx.scope().builder instanceof InstanceBuilder) {
      cx.scope().setInitOnly(true);
    }

    if (node.initializer != null) node.initializer.evaluate(cx, this);

    if (cx.statics.es4_nullability && cx.scope().builder instanceof InstanceBuilder) {
      cx.scope().setInitOnly(false);
    }

    return null;
  };
Ejemplo n.º 5
0
  public Value evaluate(Context cx, IncludeDirectiveNode node) {
    if (!node.in_this_include) {
      node.in_this_include = true;
      node.prev_cx = new Context(cx.statics);
      node.prev_cx.switchToContext(cx);

      // DANGER: it may not be obvious that we are setting the
      // the context of the outer statementlistnode here
      cx.switchToContext(node.cx);
    } else {
      node.in_this_include = false;
      cx.switchToContext(node.prev_cx); // restore prevailing context
      node.prev_cx = null;
    }
    return null;
  };
Ejemplo n.º 6
0
  /** add style into unit-wide list */
  private void registerStyle(Context context, MetaDataNode metaDataNode, String name, MetaData md) {
    try {
      unit.styles.addStyle(name, md, unit.getSource());
    } catch (StyleConflictException e) {
      context.localizedWarning2(metaDataNode.pos(), e);

      if (Trace.error) e.printStackTrace();
    }
  }
Ejemplo n.º 7
0
  public Value evaluate(Context context, MetaDataNode node) {
    if ("Style".equals(node.getId())) {
      if (NodeMagic.isClassDefinition(node)) {
        processStyle(context, node);
      } else {
        context.localizedError2(node.pos(), new StyleMustAnnotateAClass());
      }
    }

    return null;
  }
Ejemplo n.º 8
0
  private void error(int kind, String arg) {
    StringBuilder out = new StringBuilder();

    String origin = this.input.origin;

    int errPos = input.positionOfMark(); // note use of source adjusted position
    int ln = input.getLnNum(errPos);
    int col = input.getColPos(errPos);

    String msg =
        (ContextStatics.useVerboseErrors ? "[Compiler] Error #" + kind + ": " : "")
            + ctx.errorString(kind);

    if (debug) {
      msg = "[Scanner] " + msg;
    }

    int nextLoc = Context.replaceStringArg(out, msg, 0, arg);
    if (nextLoc != -1) // append msg remainder after replacement point, if any
    out.append(msg.substring(nextLoc, msg.length()));

    ctx.localizedError(origin, ln, col, out.toString(), input.getLineText(errPos), kind);
    skiperror(kind);
  }
Ejemplo n.º 9
0
  private void processStyle(Context context, MetaDataNode metaDataNode) {
    MetaData metaData = new MetaData(metaDataNode);
    String styleName = metaData.getValue("name");
    String typeName = metaData.getValue("type");

    if (styleName == null) {
      // preilly: we should report this earlier in the process.
      context.localizedError2(metaDataNode.pos(), new StyleHasMissingName());
    }

    if (typeName != null) {
      unit.expressions.add(NameFormatter.toMultiName(typeName));
    }

    registerStyle(context, metaDataNode, styleName, metaData);
  }
Ejemplo n.º 10
0
 private int isVersionMetadata(Context cx, MetaDataNode metadata) {
   if (cx.checkVersion()) {
     if ("Version".equals(metadata.id) && metadata.values != null && metadata.values.length == 1) {
       KeylessValue k =
           metadata.values[0] instanceof KeylessValue ? (KeylessValue) metadata.values[0] : null;
       if (k != null) {
         int i = -1;
         try {
           i = Integer.valueOf(k.obj);
         } catch (NumberFormatException nfe) {
           // not an integer
         }
         return i;
       }
     }
   }
   return -1;
 }
Ejemplo n.º 11
0
 public Value evaluate(Context cx, Node node) {
   cx.internalError("error: undefined meta data method");
   return null;
 }
Ejemplo n.º 12
0
 public Node initializerStatement(Context cx) {
   return cx.getNodeFactory().emptyStatement();
 }
Ejemplo n.º 13
0
 private void error(String msg) {
   ctx.internalError(msg);
   error(kError_Lexical_General, msg);
 }
Ejemplo n.º 14
0
 /**
  * This contructor is used by Flex direct AST generation. It allows Flex to pass in a specialized
  * InputBuffer.
  */
 public Scanner(Context cx, InputBuffer input) {
   init(cx, true);
   this.input = input;
   cx.input = input; // so now we get to look around to find out who does this...
 }
Ejemplo n.º 15
0
 public Scanner(Context cx, String in, String origin, boolean save_comments) {
   init(cx, save_comments);
   this.input = new InputBuffer(in, origin);
   cx.input = this.input; // FIXME: how nicely external state altering.
 }
Ejemplo n.º 16
0
 public Scanner(
     Context cx, InputStream in, String encoding, String origin, boolean save_comments) {
   init(cx, save_comments);
   this.input = new InputBuffer(in, encoding, origin);
   cx.input = this.input;
 }