コード例 #1
0
ファイル: ConstDecl.java プロジェクト: SteveOss/JacORB
  public void parse() {
    const_expr.setDeclaration(this);
    try {
      NameTable.define(full_name(), IDLTypes.CONSTANT);
    } catch (NameAlreadyDefined p) {
      parser.error("Constant " + full_name() + " already defined", token);
    }
    const_type.parse();
    const_expr.parse();
    t.typeName = name;
    values.put(t.resolvedName() + (contained() ? "" : ".value"), const_expr.toString());

    if (logger.isDebugEnabled()) {
      logger.debug(
          "ConstDecl.parse, put value: "
              + t.resolvedName()
              + (contained() ? "" : ".value")
              + " , "
              + const_expr);
    }

    declarations.put(t.resolvedName(), this);
  }
コード例 #2
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;
  }
コード例 #3
0
ファイル: OpDecl.java プロジェクト: aabykov/JacORB
  public void parse() {
    if (enclosing_symbol == null)
      throw new RuntimeException("Compiler Error: enclosing symbol in parse is null!");

    myInterface = enclosing_symbol;

    if (opAttribute == ONEWAY) {
      if (!raisesExpr.empty())
        parser.error("Oneway operation " + full_name() + " may not define a raises clause.", token);

      if (!(opTypeSpec.typeSpec() instanceof VoidTypeSpec))
        parser.error(
            "Oneway operation " + full_name() + " may only define void as return type.", token);
    }

    try {
      NameTable.define(full_name(), IDLTypes.OPERATION);
    } catch (NameAlreadyDefined nad) {
      parser.error("Operation " + full_name() + " already defined", token);
    }

    for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
      ParamDecl param = (ParamDecl) e.nextElement();

      if (parser.strict_identifiers) {
        String typeN =
            (param.paramTypeSpec.typeName().indexOf(".") < 0
                ? param.paramTypeSpec.typeName()
                : param
                    .paramTypeSpec
                    .typeName()
                    .substring(param.paramTypeSpec.typeName().lastIndexOf(".") + 1));
        if ((parser.strict_names
                && typeN.toUpperCase().equals(param.simple_declarator.toString().toUpperCase()))
            || typeN.equals(param.simple_declarator.toString())) {
          parser.error(
              "In operation "
                  + full_name()
                  + " argument "
                  + param.simple_declarator
                  + " clashes with type "
                  + param.paramTypeSpec.typeName());
        }
      }

      param.parse();

      try {
        NameTable.define(full_name() + "." + param.simple_declarator.name(), IDLTypes.ARGUMENT);
      } catch (NameAlreadyDefined nad) {
        parser.error(
            "Argument "
                + param.simple_declarator.name()
                + " already defined in operation "
                + full_name(),
            token);
      }

      if (param.paramAttribute != ParamDecl.MODE_IN) {
        // for out and inout params
        myInterface.addImportedNameHolder(param.paramTypeSpec.holderName());
      }
      if (!(param.paramTypeSpec.typeSpec() instanceof BaseType)) {

        if (logger.isInfoEnabled())
          logger.info("classname: " + param.paramTypeSpec.typeSpec().getClass().getName());

        myInterface.addImportedName(
            param.paramTypeSpec.typeSpec().full_name(), param.paramTypeSpec.typeSpec());
      }
      if (param.paramTypeSpec.typeSpec() instanceof ConstrTypeSpec
          && ((ConstrTypeSpec) param.paramTypeSpec.typeSpec()).c_type_spec instanceof StructType
          && ((StructType) ((ConstrTypeSpec) param.paramTypeSpec.typeSpec()).c_type_spec).exc
              == true) {
        parser.error("Can't pass an exception as a parameter.");
      }
    }

    if (opTypeSpec.typeSpec() instanceof ScopedName) {
      TypeSpec ts = ((ScopedName) opTypeSpec.typeSpec()).resolvedTypeSpec();

      if (ts != null) opTypeSpec = ts;

      myInterface.addImportedName(opTypeSpec.typeName());
    }
    raisesExpr.parse();
  }
コード例 #4
0
ファイル: Member.java プロジェクト: pombredanne/Harpoon-1
  /** Parsing members means creating new members for definitions with more than one declarator. */
  public void parse() {
    boolean clone_and_parse = true;

    if (extendVector == null) throw new RuntimeException("Compiler Error: extendVector not set!");

    if (type_spec.typeSpec() instanceof ScopedName) {
      token = type_spec.typeSpec().get_token();
      type_spec = ((ScopedName) type_spec.typeSpec()).resolvedTypeSpec();
      clone_and_parse = false;
      if (type_spec instanceof ConstrTypeSpec) {
        if (((ConstrTypeSpec) type_spec.typeSpec()).c_type_spec instanceof StructType) {
          //	System.out.println("Struct " + containing_struct.typeName() + " contains struct " +
          // ((ConstrTypeSpec)type_spec.typeSpec()).typeName());
          if (((ConstrTypeSpec) type_spec.typeSpec())
              .c_type_spec
              .typeName()
              .equals(containing_struct.typeName())) {
            parser.fatal_error(
                "Illegal recursion in struct (use sequence<"
                    + containing_struct.typeName()
                    + "> instead)",
                token);
          }
        }
      }

    } else if (type_spec.typeSpec() instanceof SequenceType) {
      TypeSpec ts = ((SequenceType) type_spec.typeSpec()).elementTypeSpec().typeSpec();
      SequenceType seqTs = (SequenceType) type_spec.typeSpec();
      while (ts instanceof SequenceType) {
        seqTs = (SequenceType) ts;
        ts = ((SequenceType) ts.typeSpec()).elementTypeSpec().typeSpec();
      }

      //           if( ts.typeName().equals( containing_struct.typeName()) ||
      if (ScopedName.isRecursionScope(ts.typeName())) {
        seqTs.setRecursive();
      }
    } else if (type_spec instanceof ConstrTypeSpec) {
      type_spec.parse();
    }

    for (Enumeration e = declarators.v.elements(); e.hasMoreElements(); ) {
      Declarator d = (Declarator) e.nextElement();

      // we don't parse the declarator itself
      // as that would result in its name getting defined
      // we define the declarator's name as a type name indirectly
      // through the cloned type specs.

      Member m = new Member(new_num());
      m.declarator = d;

      TypeSpec ts = type_spec.typeSpec();

      /* create a separate type spec copy for every declarator
         if the type spec is a new type definition, i.e. a
         struct, enum, union, sequence or the declarator is
         an array declarator
      */

      //			if( clone_and_parse && !(ts instanceof BaseType) )
      if (clone_and_parse || d.d instanceof ArrayDeclarator) {
        /* arrays need special treatment */

        if (d.d instanceof ArrayDeclarator) {
          ts = new ArrayTypeSpec(new_num(), ts, (ArrayDeclarator) d.d, pack_name);
          ts.parse();
        } else if (!(ts instanceof BaseType)) {
          ts = (TypeSpec) ts.clone();
          if (!(ts instanceof ConstrTypeSpec)) ts.set_name(d.name());

          /* important: only parse type specs once (we do it for the last
          declarator only) */
          if (!e.hasMoreElements()) ts.parse();
        }
      }

      //            else
      if (!(d.d instanceof ArrayDeclarator)) {
        try {
          NameTable.define(containing_struct + "." + d.name(), "declarator");
        } catch (NameAlreadyDefined nad) {
          parser.error("Declarator " + d.name() + " already defined in scope.", token);
        }
      }

      /* if the type spec is a scoped name, it is already parsed and
       * the type name is defined
       */
      //			if( clone_and_parse )
      //				ts.parse();

      m.type_spec = ts;
      m.pack_name = this.pack_name;
      m.name = this.name;
      extendVector.addElement(m);
    }
    declarators = null;
  }
コード例 #5
0
ファイル: NameTable.java プロジェクト: SteveOss/JacORB
  /**
   * copy names declared in an ancestor interface to the local scope
   *
   * @throws NameAlreadyDefined
   */
  public static synchronized void inheritFrom(String name, SymbolList ancestors)
      throws NameAlreadyDefined {
    Hashtable /*<String, IDLTypes>*/ shadowNames = new Hashtable /*<String, IDLTypes>*/();
    for (Enumeration e = names.keys(); e.hasMoreElements(); ) {
      String key = (String) e.nextElement();
      String s = null;
      if (key.indexOf('.') > 0) {
        s = key.substring(0, key.lastIndexOf('.'));
      } else {
        continue;
      }

      for (Enumeration i = ancestors.v.elements(); i.hasMoreElements(); ) {
        String anc = ((ScopedName) (i.nextElement())).resolvedName();
        if (s.equals(anc)) {
          IDLTypes kind = (IDLTypes) names.get(key);
          if (logger.isDebugEnabled()) {
            logger.debug(
                "NameTable.inheritFrom ancestor " + anc + " : key " + key + " kind " + kind);
          }

          String shadowKey = name + key.substring(key.lastIndexOf('.'));
          shadowNames.put(shadowKey, kind);

          // if the name we inherit is a typedef'd name, we need
          // to typedef the inherited name as well

          if (IDLTypes.isTypeKind(kind)) {
            if (logger.isDebugEnabled()) logger.debug("- NameTable.inherit type from:  " + key);

            TypeSpec t = TypeMap.map(anc + key.substring(key.lastIndexOf('.')));

            // t can be null for some cases where we had to put
            // Java type names (e.g. for sequence s) into the
            // name table. These need not be typedef'd again here

            if (t != null) {
              TypeMap.typedef(name + key.substring(key.lastIndexOf('.')), t);
            }
            shadowNames.put(name + key.substring(key.lastIndexOf('.')), kind);
          } else if (kind == IDLTypes.OPERATION) {
            if (logger.isDebugEnabled())
              logger.debug("- NameTable.inherit operation from:  " + key);

            NameTable.defineInheritedOperation(name + key.substring(key.lastIndexOf('.')), anc);
          } else {
            if (logger.isDebugEnabled()) {
              logger.debug("- NameTable.inherit " + kind.name() + " from:  " + key);
            }
          }

          if (!isDefined(key)) {
            throw new RuntimeException("CompilerError!");
          }
        }
      }
    }

    /* update the hashtable */

    try {
      defineShadows(shadowNames);
    } catch (NameAlreadyDefined nad) {
      if (logger.isDebugEnabled()) logger.debug("Exception ", nad);
    }
  }