/** @see de.unika.ipd.grgen.ast.BaseNode#resolveLocal() */
 @Override
 protected boolean resolveLocal() {
   boolean res = true;
   for (TypeNode typeNode : getType()) {
     res &= typeNode.resolve();
   }
   return res;
 }
Ejemplo n.º 2
0
  /**
   * Check the types of this cast. Check if the expression can be casted to the given type.
   *
   * @see de.unika.ipd.grgen.ast.BaseNode#typeCheckLocal()
   */
  private boolean typeCheckLocal() {
    TypeNode fromType = expr.getType();
    if (fromType instanceof NodeTypeNode && type instanceof NodeTypeNode) {
      // we support up- and down-casts, but no cross-casts of nodes
      HashSet<TypeNode> supertypesOfFrom = new HashSet<TypeNode>();
      ((NodeTypeNode) fromType).doGetCompatibleToTypes(supertypesOfFrom);
      HashSet<TypeNode> supertypesOfTo = new HashSet<TypeNode>();
      ((NodeTypeNode) type).doGetCompatibleToTypes(supertypesOfTo);
      return fromType.equals(type)
          || supertypesOfFrom.contains(type)
          || supertypesOfTo.contains(fromType);
    }
    if (fromType instanceof EdgeTypeNode && type instanceof EdgeTypeNode) {
      // we support up- and down-casts, but no cross-casts of edges
      HashSet<TypeNode> supertypesOfFrom = new HashSet<TypeNode>();
      ((EdgeTypeNode) fromType).doGetCompatibleToTypes(supertypesOfFrom);
      HashSet<TypeNode> supertypesOfTo = new HashSet<TypeNode>();
      ((EdgeTypeNode) type).doGetCompatibleToTypes(supertypesOfTo);
      return fromType.equals(type)
          || supertypesOfFrom.contains(type)
          || supertypesOfTo.contains(fromType);
    }
    if (fromType instanceof ObjectTypeNode
        && !(type instanceof NodeTypeNode)
        && !(type instanceof EdgeTypeNode))
      return true; // object is castable to anything besides nodes and edges
    if (type instanceof ObjectTypeNode
        && !(fromType instanceof NodeTypeNode)
        && !(fromType instanceof EdgeTypeNode))
      return true; // anything besides nodes and edges can be casted into an object
    if (fromType instanceof ExternalTypeNode && type instanceof ExternalTypeNode) {
      // we support up- and down-casts, but no cross-casts of external types
      HashSet<TypeNode> supertypesOfFrom = new HashSet<TypeNode>();
      ((ExternalTypeNode) fromType).doGetCompatibleToTypes(supertypesOfFrom);
      HashSet<TypeNode> supertypesOfTo = new HashSet<TypeNode>();
      ((ExternalTypeNode) type).doGetCompatibleToTypes(supertypesOfTo);
      return fromType.equals(type)
          || supertypesOfFrom.contains(type)
          || supertypesOfTo.contains(fromType);
    }

    boolean result = fromType.isCastableTo(type);
    if (!result) {
      reportError("Illegal cast from \"" + expr.getType() + "\" to \"" + type + "\"");
    }

    return result;
  }
Ejemplo n.º 3
0
  /** @see de.unika.ipd.grgen.ast.BaseNode#checkLocal() */
  @Override
  protected boolean checkLocal() {
    boolean res = true;
    TypeNode type = getType();
    int arity = OperatorSignature.getArity(opId);

    if (children.size() != arity) {
      reportError("Wrong operator arity: " + children.size());
      res = false;
    }

    // Here the error must have been already reported
    if (type.isEqual(BasicTypeNode.errorType)) res = false;

    return res;
  }