Example #1
0
  public Node leaveCall(Node parent, Node old, Node n, NodeVisitor v) {

    if (!(n.ext() instanceof X10Ext)) {
      return n;
    }

    List<AnnotationNode> annotations = ((X10Ext) n.ext()).annotations();

    for (Iterator<AnnotationNode> i = annotations.iterator(); i.hasNext(); ) {
      AnnotationNode a = i.next();
      TypeNode tn = a.annotationType();
      if (!(tn instanceof AmbMacroTypeNode_c)) {
        continue;
      }
      AmbMacroTypeNode_c at = (AmbMacroTypeNode_c) tn;
      if (!"Ifndef".equals(at.name().toString())) {
        continue;
      }
      List<Expr> l = at.args();
      if (l.size() != 1
          || !l.get(0).isConstant()
          || !l.get(0).type().isSubtype(ts.String(), context)) {
        Errors.issue(
            job, new SemanticException("@Ifndef must have a unique constant String parameter"), n);
        continue;
      }
      String macro = ((StringValue) l.get(0).constantValue()).value();
      if (job.extensionInfo().getOptions().macros.contains(macro)) {
        return null;
      }
    }

    boolean ifdef = true;
    for (Iterator<AnnotationNode> i = annotations.iterator(); i.hasNext(); ) {
      AnnotationNode a = i.next();
      TypeNode tn = a.annotationType();
      if (!(tn instanceof AmbMacroTypeNode_c)) {
        continue;
      }
      AmbMacroTypeNode_c at = (AmbMacroTypeNode_c) tn;
      if (!"Ifdef".equals(at.name().toString())) {
        continue;
      }
      ifdef = false;
      List<Expr> l = at.args();
      if (l.size() != 1
          || !l.get(0).isConstant()
          || !l.get(0).type().isSubtype(ts.String(), context)) {
        Errors.issue(
            job, new SemanticException("@Ifdef must have a unique constant String parameter"), n);
        continue;
      }
      String macro = ((StringValue) l.get(0).constantValue()).value();
      if (job.extensionInfo().getOptions().macros.contains(macro)) {
        return n;
      }
    }

    return ifdef ? n : null;
  }
Example #2
0
  /** Type check the source file. */
  public Node typeCheck(ContextVisitor tc) {
    boolean hasPublic = false;

    // Override method to not check for duplicate declarations. This will be
    // caught during type building. But, we need to allow duplicates to handle
    // overloaded typedefs.
    for (TopLevelDecl d : decls) {
      if (d instanceof X10ClassDecl && d.flags().flags().isPublic()) {
        if (hasPublic) {
          Errors.issue(
              tc.job(), new Errors.SourceContainsMoreThanOnePublicDeclaration(d.position()), this);
        }
        hasPublic = true;
      }
    }

    return this.hasBeenTypeChecked(true);
  }