コード例 #1
0
ファイル: ConstDecl.java プロジェクト: SteveOss/JacORB
 public void setPackage(String s) {
   s = parser.pack_replace(s);
   super.setPackage(s);
   const_type.setPackage(s);
   const_expr.setPackage(s);
   t.typeName = name;
   t.setPackage(s);
 }
コード例 #2
0
ファイル: FixedPointType.java プロジェクト: SteveOss/JacORB
  public String helperName() {
    if (pack_name.length() > 0) {
      String s = ScopedName.unPseudoName(pack_name + "." + name);

      return getFullName(s);
    } else {
      return ScopedName.unPseudoName(name);
    }
  }
コード例 #3
0
ファイル: Interface.java プロジェクト: aabykov/JacORB
  /** generate the operations Java interface (not for pseudo interfaces) */
  protected void printOperations() {
    PrintWriter ps = openOutput(name + "Operations");
    if (ps == null) {
      return;
    }

    printPackage(ps);
    printSuperclassImports(ps);
    printImport(ps);
    printClassComment("interface", name, ps);

    ps.println("public interface " + name + "Operations");

    if (inheritanceSpec.v.size() > 0) {
      ps.print("\textends ");
      Enumeration e = inheritanceSpec.v.elements();

      do {
        ScopedName sne = (ScopedName) e.nextElement();

        // See description of abstractInterfaces for logic here.
        if (abstractInterfaces != null && abstractInterfaces.contains(sne.toString())) {
          ps.print(sne);
        } else {
          if (sne.resolvedTypeSpec() instanceof ReplyHandlerTypeSpec
              && parser.generate_ami_callback) {
            ps.print(sne + "Operations");
          } else {
            ConstrTypeSpec ts = unwindTypedefs(sne);
            ps.print(ts + "Operations");
          }
        }

        if (e.hasMoreElements()) {
          ps.print(" , ");
        }
      } while (e.hasMoreElements());

      ps.print(Environment.NL);
    }

    ps.println("{");

    if (body != null) {
      // forward declaration
      body.printConstants(ps);
      body.printOperationSignatures(ps);
    }

    ps.println("}");
    ps.close();
  }
コード例 #4
0
ファイル: ConstDecl.java プロジェクト: SteveOss/JacORB
 public static String namedValue(ScopedName sn) {
   String resolvedName = sn.resolvedName();
   if (values.containsKey(resolvedName)) {
     return (String) values.get(resolvedName);
   }
   return resolvedName;
 }
コード例 #5
0
ファイル: Interface.java プロジェクト: aabykov/JacORB
  /**
   * If this interface inherits from classes in the unnamed package, generate explicit import
   * statements for them.
   */
  protected void printSuperclassImports(PrintWriter ps) {
    if (inheritanceSpec.v.isEmpty()) {
      return;
    }

    if ("".equals(pack_name)) {
      return;
    }

    for (final Iterator i = inheritanceSpec.v.iterator(); i.hasNext(); ) {
      final ScopedName sn = (ScopedName) i.next();

      if (sn.resolvedName().indexOf('.') < 0) {
        ps.print("import ");
        ps.print(sn.toString());
        ps.println(';');
      }
    }
  }
コード例 #6
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);
  }
コード例 #7
0
ファイル: ConstDecl.java プロジェクト: SteveOss/JacORB
  /** prints a constant declaration outside of an enclosing interface into a separate interface */
  public void print(PrintWriter ps) {
    if (contained() || (included && !generateIncluded())) return;

    try {
      String fullName = ScopedName.unPseudoName(full_name());
      String className;
      if (fullName.indexOf('.') > 0) {
        pack_name = fullName.substring(0, fullName.lastIndexOf('.'));
        className = fullName.substring(fullName.lastIndexOf('.') + 1);
      } else {
        pack_name = "";
        className = fullName;
      }

      String path = parser.out_dir + fileSeparator + pack_name.replace('.', fileSeparator);
      File dir = new File(path);
      if (!dir.exists()) {
        if (!dir.mkdirs()) {
          org.jacorb.idl.parser.fatal_error("Unable to create " + path, null);
        }
      }

      String fname = className + ".java";
      File f = new File(dir, fname);

      if (GlobalInputStream.isMoreRecentThan(f)) {
        PrintWriter pw = new PrintWriter(new java.io.FileWriter(f));

        if (logger.isDebugEnabled()) logger.debug("ConstDecl.print " + fname);

        if (!pack_name.equals("")) pw.println("package " + pack_name + ";");

        printClassComment("const", className, pw);

        pw.println("public interface " + className);
        pw.println("{");

        pw.print("\t" + const_type.toString() + " value = ");

        pw.print(getValue());
        pw.println(";");

        pw.println("}");
        pw.close();
      }
    } catch (java.io.IOException i) {
      throw new RuntimeException("File IO error" + i);
    }
  }
コード例 #8
0
ファイル: Interface.java プロジェクト: aabykov/JacORB
  private ConstrTypeSpec unwindTypedefs(ScopedName scopedName) {
    TypeSpec resolvedTSpec = scopedName.resolvedTypeSpec();
    // unwind any typedefs
    while (resolvedTSpec instanceof AliasTypeSpec) {
      resolvedTSpec = ((AliasTypeSpec) resolvedTSpec).originalType();
    }

    if (!(resolvedTSpec instanceof ConstrTypeSpec)) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Illegal inheritance spec in Interface.unwindTypeDefs, not a constr. type but "
                + resolvedTSpec.getClass()
                + ", name "
                + scopedName);
      }
      parser.fatal_error(
          "Illegal inheritance spec in Interface.unwindTypeDefs (not a constr. type): "
              + inheritanceSpec,
          token);
    }

    return (ConstrTypeSpec) resolvedTSpec;
  }
コード例 #9
0
ファイル: Interface.java プロジェクト: aabykov/JacORB
  /** generate the signature interface */
  protected void printInterface() {
    PrintWriter ps = openOutput(name);
    if (ps == null) {
      return;
    }

    printPackage(ps);
    printSuperclassImports(ps);
    printClassComment("interface", name, ps);

    if (is_pseudo) {
      ps.println("public abstract class " + name);

      if (inheritanceSpec.v.size() > 0) {
        StringBuffer pseudo_bases = new StringBuffer();
        StringBuffer regular_bases = new StringBuffer();
        String comma = " ";

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

          if (sn.is_pseudo()) {
            pseudo_bases.append(comma + name);
          } else {
            regular_bases.append(comma + name);
          }

          if (inheritanceSpec.v.size() > 1) comma = ",";
        }

        if (pseudo_bases.length() > 0) ps.println("\textends " + pseudo_bases.toString());

        if (regular_bases.length() > 0) ps.println("\timplements " + regular_bases.toString());
      }
    } else {
      ps.println("public interface " + name);

      if (is_abstract) {
        ps.print("\textends org.omg.CORBA.portable.IDLEntity");
      } else {
        ps.print("\textends " + name + "Operations");

        if (is_local) {
          // Looking at RTF work it
          // seems a new interface 'LocalInterface' will be used for this purpose.

          ps.print(", org.omg.CORBA.LocalInterface, org.omg.CORBA.portable.IDLEntity");
        } else {
          ps.print(", org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity");
        }
      }

      if (inheritanceSpec.v.size() > 0) {
        Enumeration e = inheritanceSpec.v.elements();

        while (e.hasMoreElements()) {
          ScopedName sne = (ScopedName) e.nextElement();
          if (sne.resolvedTypeSpec() instanceof ReplyHandlerTypeSpec
              && parser.generate_ami_callback) {
            ps.print(", " + sne);
          } else {
            ConstrTypeSpec ts = unwindTypedefs(sne);
            ps.print(", " + ts);
          }
        }
      }
    }

    ps.println(Environment.NL + "{");

    if (is_pseudo) {
      printSerialVersionUID(ps);
    }

    // body can be null for forward declaration
    if (body != null) {
      body.printInterfaceMethods(ps);

      // for an abstract interface, the generated abstract class contains
      // the operation signatures since there is no separate signature
      // interface
      if (is_abstract) {
        body.printConstants(ps);
        body.printOperationSignatures(ps);
      }
    }

    ps.println("}");
    ps.close();
  }
コード例 #10
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;
  }
コード例 #11
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;
  }