コード例 #1
0
ファイル: Interface.java プロジェクト: aabykov/JacORB
  public void parse() {
    boolean justAnotherOne = false;

    if (parsed) {
      // there are occasions where the compiler may try to parse
      // an Interface type spec for a second time, viz if it is
      // referred to through a scoped name in another struct member.
      // that's not a problem, but we have to skip parsing again!
      // Fixes bug #629, copied from fix for bug #84
      return;
    }

    escapeName();

    ConstrTypeSpec ctspec = new ConstrTypeSpec(new_num());

    if (is_abstract) {
      if (logger.isDebugEnabled()) {
        logger.debug("Adding " + full_name() + " to abstract interface list");
      }

      if (abstractInterfaces == null) {
        abstractInterfaces = new HashSet();
      }

      abstractInterfaces.add(full_name());
    }

    try {
      ScopedName.definePseudoScope(full_name());
      ctspec.c_type_spec = this;

      if (is_pseudo) NameTable.define(full_name(), IDLTypes.PSEUDO_INTERFACE);
      else NameTable.define(full_name(), IDLTypes.INTERFACE);

      TypeMap.typedef(full_name(), ctspec);
    } catch (IllegalRedefinition ill) {
      parser.fatal_error(
          "Cannot redefine " + token.str_val + " in nested scope as " + ill.newDef, token);
    } catch (NameAlreadyDefined nad) {
      // if we get here, there is already a type spec for this interface
      // in the global type table for a forward declaration of this
      // interface. We must replace that table entry with this type spec
      // unless this is yet another forward declaration

      Object forwardDeclaration = parser.get_pending(full_name());

      if (forwardDeclaration != null) {
        if (!(forwardDeclaration instanceof Interface)) {
          parser.error(
              "Forward declaration types mismatch for "
                  + full_name()
                  + ": name already defined with another type",
              token);
        }

        if (body == null) {
          justAnotherOne = true;
        }

        // else actual definition

        if ((!(full_name().equals("CORBA.TypeCode")
                || full_name().equals("org.omg.CORBA.TypeCode")))
            && body != null) {
          TypeMap.replaceForwardDeclaration(full_name(), ctspec);
        }
      } else {
        // this is another forward declaration, ignore
      }
    }

    if (body != null) {
      if (inheritanceSpec != null && inheritanceSpec.v.size() > 0) {
        if (logger.isDebugEnabled()) logger.debug("Checking inheritanceSpec of " + full_name());

        HashSet h = new HashSet();

        for (Enumeration e = inheritanceSpec.v.elements(); e.hasMoreElements(); ) {
          ScopedName name = (ScopedName) e.nextElement();

          ConstrTypeSpec ts = unwindTypedefs(name);

          if (ts.declaration() instanceof Interface) {
            if (h.contains(ts.full_name())) {
              parser.fatal_error(
                  "Illegal inheritance spec: "
                      + inheritanceSpec
                      + " (repeated inheritance not allowed).",
                  token);
            }

            // else:
            h.add(ts.full_name());

            continue;
          }

          // else:
          parser.fatal_error(
              "Illegal inheritance spec: "
                  + inheritanceSpec
                  + " (ancestor "
                  + ts.full_name()
                  + " not an interface)",
              token);
        }

        body.set_ancestors(inheritanceSpec);
      }

      body.parse();
      NameTable.parsed_interfaces.put(full_name(), "");

      if (parser.generate_ami_callback) {
        replyHandler = new ReplyHandler(this);
        replyHandler.parse();
      }

    } else if (!justAnotherOne) {
      // i am forward declared, must set myself as
      // pending further parsing
      parser.set_pending(full_name(), this);
    }

    parsed = true;
  }