コード例 #1
0
  /**
   * Determine whether the specified identifier names a type.
   *
   * @param id The identifier.
   * @return <code>true</code> if the specified identifier names a type.
   */
  public boolean isType(String id) {
    // If we have already parsed a type specifier, the identifier does
    // not name a type.
    if (top.isSet(FLAG_TYPE_SPEC)) {
      if (DEBUG) System.out.println("isType(" + id + ") -> false");
      return false;
    }

    // Otherwise, we consult the symbol table.
    Context c = top;

    do {
      while (!c.isSet(FLAG_SCOPE)) {
        c = c.next;
      }

      Boolean value = c.bindings.get(id);
      if (null != value) {
        boolean type = value.booleanValue();
        if (DEBUG) System.out.println("isType(" + id + ") -> " + type);
        return type;
      }

      c = c.next;
    } while (null != c);

    if (DEBUG) System.out.println("isType(" + id + ") -> false");
    return false;
  }
コード例 #2
0
  /**
   * Implicitly bind the specified identifier. Depending on the current parsing context, the
   * identifier is either bound as a type or as an object/function/constant.
   *
   * @param id The identifier.
   */
  public void bind(String id) {
    // Ignore the binding if a function parameter list has already
    // been parsed or the binding appears inside a structure
    // declaration list.
    if (top.next.isSet(FLAG_PARAMS) || top.next.isSet(FLAG_STRUCTURE)) {
      if (DEBUG) {
        System.out.println("ignoring bind(" + id + ", " + top.isSet(FLAG_TYPEDEF) + ")");
      }
      return;
    } else if (DEBUG) {
      System.out.println("bind(" + id + ", " + top.isSet(FLAG_TYPEDEF) + ")");
    }

    // Get the top-most scope.
    Context c = top;
    while (!c.isSet(FLAG_SCOPE)) {
      c = c.next;
    }

    // Record the name.
    if (c.bindings.containsKey(id)) {
      if (DEBUG) {
        System.out.println("ignoring rebinding of " + id);
      }
    } else {
      c.bindings.put(id, top.isSet(FLAG_TYPEDEF) ? Boolean.TRUE : Boolean.FALSE);
      c.set(FLAG_MODIFIED);
    }
  }
コード例 #3
0
  public void abort() {
    if (DEBUG) {
      if (top.isSet(FLAG_SCOPE)) {
        System.out.println("implied exitScope(" + nesting + ")");
      }
      System.out.println("abort(" + nesting + ")");
      nesting--;
    }

    addToPool(pop());
  }
コード例 #4
0
  /**
   * Explicitly bind the specified identifier.
   *
   * @param id The identifier.
   * @param isType The flag for whether the identifier represents a type.
   */
  public void bind(String id, boolean isType) {
    if (DEBUG) {
      System.out.println("bind(" + id + ", " + isType + ')');
    }

    // Get the top-most scope.
    Context c = top;
    while (!c.isSet(FLAG_SCOPE)) {
      c = c.next;
    }

    // Record the name.
    if (c.bindings.containsKey(id)) {
      if (DEBUG) {
        System.out.println("ignoring rebinding of " + id);
      }
    } else {
      c.bindings.put(id, isType ? Boolean.TRUE : Boolean.FALSE);
      c.set(FLAG_MODIFIED);
    }
  }
コード例 #5
0
 /**
  * Determine whether a declaration actually is a declaration. This method determines whether the
  * sequence
  *
  * <pre>
  *   DeclarationSpecifiers l:InitializedDeclaratorList?
  * </pre>
  *
  * can actually represent a declaration. It assumes that any type specifier encountered while
  * parsing <code>DeclarationSpecifiers</code> has been marked through {@link #typeSpecifier()}.
  *
  * @param idl The result of parsing the optional initialized declarator list.
  * @return <code>true</code> if the declaration is a declaration.
  */
 public boolean isValid(Node idl) {
   return top.isSet(FLAG_TYPE_SPEC) || (null != idl);
 }