/**
   * resolves n to node of type R, via declaration if n is an identifier, via simple cast otherwise
   * returns null if n's declaration or n can't be cast to R or S
   */
  public Pair<R, S> resolve(BaseNode n, BaseNode parent) {
    if (n instanceof IdentNode) {
      Pair<R, S> pair = resolve((IdentNode) n);
      if (pair != null) {
        assert pair.fst == null || pair.snd == null;
        parent.becomeParent(pair.fst);
        parent.becomeParent(pair.snd);
      }
      return pair;
    }

    Pair<R, S> pair = new Pair<R, S>();
    if (clsR.isInstance(n)) {
      pair.fst = clsR.cast(n);
    }
    if (clsS.isInstance(n)) {
      pair.snd = clsS.cast(n);
    }
    if (pair.fst != null || pair.snd != null) {
      assert pair.fst == null || pair.snd == null;
      return pair;
    }

    n.reportError(
        "\""
            + n
            + "\" is a "
            + n.getUseString()
            + " but a "
            + Util.getStrListWithOr(classes, BaseNode.class, "getUseStr")
            + " is expected");
    return null;
  }
Beispiel #2
0
  /**
   * Make a new cast node with a target type and an expression, which is immediately marked as
   * resolved Only to be called by type adjusting, after tree was already resolved
   *
   * @param coords The source code coordinates.
   * @param targetType The target type.
   * @param expr The expression to be casted.
   * @param resolveResult Resolution result (should be true)
   */
  public CastNode(Coords coords, TypeNode targetType, ExprNode expr, BaseNode parent) {
    this(coords, targetType, expr);
    parent.becomeParent(this);

    resolve();
    check();
  }
Beispiel #3
0
 /** @see de.unika.ipd.grgen.ast.BaseNode#resolveLocal() */
 @Override
 protected boolean resolveLocal() {
   boolean successfullyResolved = true;
   if (typeUnresolved instanceof PackageIdentNode)
     Resolver.resolveOwner((PackageIdentNode) typeUnresolved);
   else fixupDefinition(typeUnresolved, typeUnresolved.getScope());
   type = typeResolver.resolve(typeUnresolved, this);
   successfullyResolved = type != null && successfullyResolved;
   return successfullyResolved;
 }