Ejemplo n.º 1
0
  public String toString() {
    Name name = name();

    if (kind() == null) {
      return "<unknown class " + name + typeParameterString() + ">";
    }

    if (kind() == ANONYMOUS) {
      if (interfaces != null && !interfaces.isEmpty()) {
        return isFunction()
            ? "" + interfaces.get(0)
            : "<anonymous subtype of " + interfaces.get(0) + typeParameters() + ">";
      }
      if (superType != null) {
        return "<anonymous subclass of " + superType + ">" + typeParameterString();
      }
    }

    if (kind() == TOP_LEVEL) {
      Package p = Types.get(package_());
      return (p != null ? p.toString() + "." : "") + name + typeParameterString();
    } else if (kind() == MEMBER) {
      ClassDef outer = Types.get(outer());
      return (outer != null ? outer.toString() + "." : "") + name + typeParameterString();
    } else {
      return name.toString() + typeParameterString();
    }
  }
Ejemplo n.º 2
0
 private static void addTypeToWorkList(ArrayList<ClassDef> worklist, Ref<? extends Type> ref) {
   Type sup = Types.get(ref);
   sup = Types.baseType(sup);
   // can be a parameter type
   if (sup instanceof ParameterType) return;
   if (!(sup instanceof X10ParsedClassType)) assert sup instanceof X10ParsedClassType;
   worklist.add(((X10ParsedClassType) sup).def());
 }
Ejemplo n.º 3
0
  public X10ClassType asType() {

    if (asType == null) {
      asType = ts.createClassType(position(), errorPosition(), Types.ref(this));
    }
    return (X10ClassType) asType;
  }
Ejemplo n.º 4
0
  /** Get the full name of the class, if possible. */
  public QName fullName() {
    Name name = name();

    if (kind() == TOP_LEVEL) {
      Package p = Types.get(package_());
      return QName.make(p != null ? p.fullName() : null, name);
    } else if (kind() == MEMBER) {
      ClassDef outer = Types.get(outer());
      return QName.make(outer != null ? outer.fullName() : null, name);
    } else if (kind() == LOCAL) {
      return QName.make(null, name);
    } else if (kind() == ANONYMOUS) {
      return QName.make(null, Name.make("<anonymous class>"));
    } else {
      return QName.make(null, Name.make("<unknown class>"));
    }
  }
Ejemplo n.º 5
0
 @Override
 public Type instantiate(Type t) throws SemanticException {
   Type n = super.instantiate(t);
   // Also check that the name is simple.
   if (n instanceof MacroType) {
     MacroType mt = (MacroType) n;
     if (mt.formalTypes().size() != 0) return null;
     if (mt.typeParameters().size() != 0) return null;
   }
   // Need to replace the outer type of n with container.
   // container may have clauses that need to be part of n.
   // e.g. A{self.i==3}.Inner will return A.Inner{A.self.i==3}.
   n = Types.addInOuterClauses(n, container);
   return n;
 }
Ejemplo n.º 6
0
  @Override
  public Node typeCheck(ContextVisitor tc) throws SemanticException {
    RuleDef sym = null;

    MethodInstance mi = call.methodInstance();
    IbexClassType ct = (IbexClassType) mi.container();
    for (RuleInstance rule : ct.rules()) {
      if (rule.name() == mi.name()) sym = rule.def();
    }

    if (sym == null) throw new SemanticException("Cannot find rule for " + mi);

    RhsInvoke n = (RhsInvoke) symbol(sym.asNonterminal()).type(call.type());

    if (assocTag) {
      Context c = tc.context();
      CodeDef code = c.currentCode();
      if (code instanceof RuleDef) {
        RuleDef rd = (RuleDef) code;
        if (rd != sym)
          throw new SemanticException(
              "Associativity annotation must be self-recursive.", position());
      }
    }

    if (!call.type().isVoid()) {
      TypeSystem ts = tc.typeSystem();
      LocalDef li = ts.localDef(position(), Flags.FINAL, Types.ref(call.type()), call.name().id());
      // Formal parameters are never compile-time constants.
      li.setNotConstant();

      IbexNodeFactory nf = (IbexNodeFactory) tc.nodeFactory();
      LocalDecl ld =
          nf.LocalDecl(
              position(),
              nf.FlagsNode(position(), li.flags()),
              nf.CanonicalTypeNode(position(), li.type()),
              nf.Id(position(), li.name()));
      ld = ld.localDef(li);
      ld = ld.init(n);

      return nf.RhsSyntheticBind(position(), ld).type(n.type());
    }

    return n;
  }
Ejemplo n.º 7
0
 public Ref<? extends ContainerType> container() {
   return Types.<ClassType>ref(ts.createClassType(position(), errorPosition(), this.outer));
 }
Ejemplo n.º 8
0
 public Ref<TypeConstraint> typeGuard() {
   return new LazyRef_c<TypeConstraint>(Types.parameterBounds(asType()));
 }