Beispiel #1
0
  // can this func be called using a call with signature callSig?
  // if callSig.returnType is any, then ignore return type compatibility
  // (NB: this doesn't consider implicit argument conversions, use
  // TypeManager.isMatchingFunc() for that)
  public boolean callCompatible(final FuncInfo callSig) {
    Debug.Assert(callSig != null);

    if (callSig.numArgs() < numRequiredArgs()) {
      return false; // not enough args
    }
    if (callSig.numArgs() > numArgs()) {
      return false; // too many args
    }

    // check types
    for (int a = 0; a < callSig.numArgs(); a++) {
      if (!_paramTypes[a].equals(callSig._paramTypes[a])) {
        return false;
      }
    }

    if (callSig.getReturnType() != null) {
      if (!callSig.getReturnType().equals(TypeSpec.typeOf("any"))) {
        if (!_returnType.equals(callSig.getReturnType())) {
          return false;
        }
      }
    }

    return true;
  }
Beispiel #2
0
  public void printDelegatedMethod(PrintWriter ps) {
    ps.print("\tpublic " + opTypeSpec.toString() + " " + name + "(");

    Enumeration e = paramDecls.elements();
    if (e.hasMoreElements()) ((ParamDecl) e.nextElement()).print(ps);

    for (; e.hasMoreElements(); ) {
      ps.print(", ");
      ((ParamDecl) e.nextElement()).print(ps);
    }

    ps.print(")");
    raisesExpr.print(ps);
    ps.println(Environment.NL + "\t{");

    if (opAttribute == NO_ATTRIBUTE && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
      ps.print("\t\treturn ");
    }

    ps.print("_delegate." + name + "(");
    e = paramDecls.elements();
    if (e.hasMoreElements()) ps.print(((ParamDecl) e.nextElement()).simple_declarator);

    for (; e.hasMoreElements(); ) {
      ps.print(",");
      ps.print(((ParamDecl) e.nextElement()).simple_declarator);
    }
    ps.println(");");
    ps.println("\t}" + Environment.NL);
  }
Beispiel #3
0
  /**
   * get resource value by string-format via resourceId.
   *
   * @param resourceId
   * @param resourceTable
   * @param locale
   * @return
   */
  public static String getResourceByid(
      long resourceId, boolean isStyle, ResourceTable resourceTable, Locale locale) {
    //        An Android Resource id is a 32-bit integer. It comprises
    //        an 8-bit Package id [bits 24-31]
    //        an 8-bit Type id [bits 16-23]
    //        a 16-bit Entry index [bits 0-15]

    // android system styles.
    if (isStyle
        && (resourceId & AndroidConstants.STYLE_ID_START) == AndroidConstants.STYLE_ID_START) {
      return "@android:style/" + ResourceTable.styleMap.get((int) resourceId);
    }

    String str = "resourceId:0x" + Long.toHexString(resourceId);
    if (resourceTable == null) {
      return str;
    }

    short packageId = (short) (resourceId >> 24 & 0xff);
    short typeId = (short) ((resourceId >> 16) & 0xff);
    int entryIndex = (int) (resourceId & 0xffff);
    ResourcePackage resourcePackage = resourceTable.getPackage(packageId);
    if (resourcePackage == null) {
      return str;
    }
    TypeSpec typeSpec = resourcePackage.getTypeSpec(typeId);
    List<Type> types = resourcePackage.getTypes(typeId);
    if (typeSpec == null || types == null) {
      return str;
    }
    if (!typeSpec.exists(entryIndex)) {
      return str;
    }

    // read from type resource
    String result = null;
    String ref = null;
    int currentLevel = -1;
    for (Type type : types) {
      ResourceEntry resource = type.getResourceEntry(entryIndex);
      if (resource == null) {
        continue;
      }
      int level = locale.match(type.locale);
      if (level == 2) {
        ref = resource.key;
        result = resource.toString();
        break;
      } else if (level > currentLevel) {
        ref = resource.key;
        result = resource.toString();
      }
    }
    if (locale.equals(Locale.none) || result == null) {
      result = "@" + typeSpec.name + "/" + ref;
    }
    return result;
  }
 // Type
 @Override
 public Node visitType_spec(IDLParser.Type_specContext ctx) {
   TypeSpec typeSpec = new TypeSpec(ctx.id.getText());
   if (ctx.template() != null) {
     Node template = visitTemplate(ctx.template());
     assert (template instanceof TypeSpec.Template);
     typeSpec.setTemplate((TypeSpec.Template) template);
   }
   return typeSpec;
 }
Beispiel #5
0
  private String getValue() {
    TypeSpec ts = const_type.symbol.typeSpec();
    while (ts instanceof AliasTypeSpec) {
      ts = ((AliasTypeSpec) ts).originalType();
    }

    if (logger.isDebugEnabled()) {
      logger.debug("ConstDecl(" + name + ": " + ts.getClass() + ") = " + const_type.toString());
    }

    // Bugzilla #851 - Infinity values wrapping
    String exprStr = const_expr.toString();
    if (exprStr != null && exprStr.contains("Infinity")) {
      logger.warn(
          "["
              + token.line_no
              + ":"
              + token.char_pos
              + "]"
              + "Infinity value used in const declaration");
      if (exprStr.startsWith("-")) {
        exprStr = "Double.NEGATIVE_INFINITY";
      } else {
        exprStr = "Double.POSITIVE_INFINITY";
      }
    }

    if (ts instanceof ShortType) {
      // short constant values have to be cast explicitly
      return ("(short)(" + exprStr + ")");
    } else if (ts instanceof FloatType) {
      // float constant values have to be cast explicitly
      return ("(float)(" + exprStr + ")");
    } else if (ts instanceof OctetType) {
      // byte constant values have to be cast explicitly
      return ("(byte)(" + exprStr + ")");
    } else if (ts instanceof FixedPointConstType || ts instanceof FixedPointType) {
      return ("new java.math.BigDecimal (" + exprStr + ")");
    } else if (ts instanceof LongLongType) {
      String cast = "";
      try {
        if (const_expr.or_expr.xor_expr.and_expr.shift_expr.operator != null
            || const_expr.or_expr.xor_expr.and_expr.shift_expr.add_expr.operator != null
            || const_expr.or_expr.xor_expr.and_expr.shift_expr.add_expr.mult_expr.operator
                != null) {
          cast = "(long)";
        }
      } catch (Exception e) {
        // Don't care if any of the above cause null ptr - just won't do cast.
      }
      return (cast + const_expr.toString());
    } else {
      return exprStr;
    }
  }
Beispiel #6
0
  /** @return true if this is a Pascal string type. */
  public boolean isPascalString() {
    if (form == ARRAY) {
      TypeSpec elmtType = (TypeSpec) getAttribute(ARRAY_ELEMENT_TYPE);
      TypeSpec indexType = (TypeSpec) getAttribute(ARRAY_INDEX_TYPE);

      return (elmtType.baseType() == Predefined.charType)
          && (indexType.baseType() == Predefined.integerType);
    } else {
      return false;
    }
  }
Beispiel #7
0
  /**
   * Constructor.
   *
   * @param value a string value.
   */
  public TypeSpecImpl(String value) {
    this.form = ARRAY;

    TypeSpec indexType = new TypeSpecImpl(SUBRANGE);
    indexType.setAttribute(SUBRANGE_BASE_TYPE, Predefined.integerType);
    indexType.setAttribute(SUBRANGE_MIN_VALUE, 1);
    indexType.setAttribute(SUBRANGE_MAX_VALUE, value.length());

    setAttribute(ARRAY_INDEX_TYPE, indexType);
    setAttribute(ARRAY_ELEMENT_TYPE, Predefined.charType);
    setAttribute(ARRAY_ELEMENT_COUNT, value.length());
  }
Beispiel #8
0
 private void emitLiteral(Object o) throws IOException {
   if (o instanceof TypeSpec) {
     TypeSpec typeSpec = (TypeSpec) o;
     typeSpec.emit(this, null, Collections.<Modifier>emptySet());
   } else if (o instanceof AnnotationSpec) {
     AnnotationSpec annotationSpec = (AnnotationSpec) o;
     annotationSpec.emit(this, true);
   } else if (o instanceof CodeBlock) {
     CodeBlock codeBlock = (CodeBlock) o;
     emit(codeBlock);
   } else {
     emitAndIndent(String.valueOf(o));
   }
 }
Beispiel #9
0
  public void printMethod(PrintWriter ps, String classname, boolean is_local, boolean is_abstract) {
    /* in some cases generated name have an underscore prepended for the
    mapped java name. On the wire, we must use the original name */

    String idl_name = (name.startsWith("_") ? name.substring(1) : name);

    ps.print("\tpublic " + opTypeSpec.toString() + " " + name + "(");

    Enumeration e = paramDecls.elements();
    if (e.hasMoreElements()) ((ParamDecl) e.nextElement()).print(ps);

    for (; e.hasMoreElements(); ) {
      ps.print(", ");
      ((ParamDecl) e.nextElement()).print(ps);
    }

    ps.print(")");
    raisesExpr.print(ps);
    ps.println(Environment.NL + "\t{");

    if (parser.generateDiiStubs) {
      printDIIBody(ps, classname, idl_name, is_local, is_abstract);
    } else {
      printStreamBody(ps, classname, idl_name, is_local, is_abstract);
    }

    ps.println("\t}" + Environment.NL); // end method^M
  }
Beispiel #10
0
  // are func types equivelent? (same arg types & return type?)
  // NB: doens't consider param names or default values
  @Override
  public boolean equals(final Object o) {
    if (o == null) {
      return false;
    }
    if (!(o instanceof FuncInfo)) {
      return false;
    }

    final FuncInfo f = (FuncInfo) o;

    if (!equalsParams(f)) {
      return false;
    }

    if ((_returnType == null) && (f._returnType != null)) {
      return false;
    }
    if (_returnType != null) {
      if (!_returnType.equals(f._returnType)) {
        return false;
      }
    }

    return true;
  }
 @Override
 public void digest(MessageDigest digest) {
   annotations.stream().forEachOrdered(annotation -> annotation.digest(digest));
   type.digest(digest);
   inheritance.stream().forEachOrdered(typeSpec -> typeSpec.digest(digest));
   functions.stream().forEachOrdered(function -> function.digest(digest));
   structs.stream().forEachOrdered(struct -> struct.digest(digest));
 }
Beispiel #12
0
  public void setPackage(String s) {
    s = parser.pack_replace(s);
    if (pack_name.length() > 0) pack_name = new String(s + "." + pack_name);
    else pack_name = s;

    type_spec.setPackage(s);
    declarators.setPackage(s);
  }
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(type_spec.toString());
   for (Enumeration e = declarators.v.elements(); e.hasMoreElements(); ) {
     sb.append(e.nextElement());
   }
   return sb.toString();
 }
 public void setPackage(String s) {
   s = parser.pack_replace(s);
   type_spec.setPackage(s);
   for (Enumeration e = declarators.v.elements(); e.hasMoreElements(); ) {
     Declarator d = (Declarator) e.nextElement();
     d.setPackage(s);
   }
 }
Beispiel #15
0
 public FuncInfo() {
   // default to noarg, any return
   _paramNames = new String[0];
   _paramTypes = new TypeSpec[0];
   _paramDefaults = new Object[0];
   _paramHasDefault = new boolean[0];
   _returnType = TypeSpec.typeOf("any");
 }
Beispiel #16
0
  public String toStringArgs(final Object[] args) {
    boolean haveArgs = (args != null);
    if (haveArgs) {
      if (args.length < _paramNames.length) {
        haveArgs = false;
      }
    }
    String s = "func(";
    for (int i = 0; i < _paramNames.length; i++) {
      if (_paramNames[i] != null) {
        s += _paramNames[i] + ":";
      }
      s += _paramTypes[i].typeName();
      if (!haveArgs) {
        if (_paramHasDefault[i]) {
          if (_paramDefaults[i] != null) {
            String str = null;
            try {
              str = _paramDefaults[i].toString();
            } catch (final java.lang.Exception e) {
            }
            if (str != null) {
              s += " =" + str;
            } else {
              s += " =?";
            }
          } else {
            s += " =null";
          }
        }
      } else {
        final Object a = args[i];
        if (a != null) {
          String str = null;
          try {
            str = a.toString();
          } catch (final java.lang.Exception e) {
          }
          if (str != null) {
            s += " =<" + str + ">";
          } else {
            s += " =<?>";
          }
        } else {
          s += " =<null>";
        }
      }
      if (i != _paramNames.length - 1) {
        s += ", ";
      }
    }
    if (_returnType != null) {
      s += " -> " + _returnType.typeName();
    }
    s += ")";

    return s;
  }
Beispiel #17
0
  // construct from types of an argument list
  public FuncInfo(final ArrayList args) {
    if (args == null) {
      // default to noarg, any return
      _paramNames = new String[0];
      _paramTypes = new TypeSpec[0];
      _paramDefaults = new Object[0];
      _paramHasDefault = new boolean[0];
      _returnType = TypeSpec.typeOf("any");
    } else {
      final int n = args.size();
      _paramNames = new String[n];
      _paramTypes = new TypeSpec[n];
      _paramDefaults = new Object[n];
      _paramHasDefault = new boolean[n];
      _returnType = TypeSpec.typeOf("any");
      for (int a = 0; a < n; a++) {
        _paramNames[a] = null;
        _paramTypes[a] = null;
        if (args.get(a) instanceof Value) {
          // if an arg is null and is an LValue, extract it's declared
          // type
          final Value v = (Value) args.get(a);
          final boolean isNull =
              (v.getValue() == null)
                  || ((v.getValue() instanceof Any) && (((Any) v.getValue()).value == null));
          if (isNull && v.isLValue()) {
            _paramTypes[a] = v.getLValue().getSymbol().getType();
          }
          // if we have an Any value, try to deduce the type from the
          // actual value within
          else if (v.getValue() instanceof Any) { // if we have an Any
            if (v.getValue() != null) {
              _paramTypes[a] = TypeSpec.typeOf(((Any) v.getValue()).value);
            }
          }
        }
        if (_paramTypes[a] == null) {
          _paramTypes[a] = TypeSpec.typeOf(args.get(a));
        }

        _paramDefaults[a] = null;
        _paramHasDefault[a] = false;
      }
    }
  }
Beispiel #18
0
  public void print(PrintWriter ps) {
    if (is_pseudo) ps.print("\tpublic abstract " + opTypeSpec.toString());
    else ps.print("\t" + opTypeSpec.toString());
    ps.print(" ");
    ps.print(name);

    ps.print("(");
    Enumeration e = paramDecls.elements();
    if (e.hasMoreElements()) ((ParamDecl) e.nextElement()).print(ps);

    for (; e.hasMoreElements(); ) {
      ps.print(", ");
      ((ParamDecl) e.nextElement()).print(ps);
    }
    ps.print(")");
    raisesExpr.print(ps);
    ps.println(";");
  }
Beispiel #19
0
  /** collect Interface Repository information in the argument hashtable */
  public void getIRInfo(Hashtable irInfoTable) {
    StringBuffer sb = new StringBuffer();

    TypeSpec ts = opTypeSpec.typeSpec();

    if (ts instanceof AliasTypeSpec) {
      //             if( ((AliasTypeSpec)ts).originalType.typeSpec() instanceof FixedPointType )
      //              {
      sb.append(ts.full_name());
      //             }
    }
    sb.append("(");

    for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
      ParamDecl param = (ParamDecl) e.nextElement();
      if (param.paramAttribute == ParamDecl.MODE_INOUT) {
        sb.append("inout:" + param.simple_declarator.name + " ");
      } else if (param.paramAttribute == ParamDecl.MODE_OUT) {
        sb.append("out:" + param.simple_declarator.name + " ");
      } else // MODE_IN
      sb.append("in:" + param.simple_declarator.name + " ");

      ts = param.paramTypeSpec.typeSpec();

      if (ts instanceof AliasTypeSpec) {
        sb.append(ts.full_name());
      }

      sb.append(",");
    }

    if (paramDecls.size() > 0) {
      // remove extra trailing ","
      sb.deleteCharAt(sb.length() - 1);
    }
    sb.append(")");

    if (opAttribute == ONEWAY) sb.append("-oneway");

    //       if( enter )
    irInfoTable.put(name, sb.toString());

    if (logger.isDebugEnabled()) logger.debug("OpInfo for " + name + " : " + sb.toString());
  }
Beispiel #20
0
  public void setPackage(String s) {
    s = parser.pack_replace(s);

    if (pack_name.length() > 0) pack_name = s + "." + pack_name;
    else pack_name = s;
    opTypeSpec.setPackage(s);

    for (Enumeration e = paramDecls.elements();
        e.hasMoreElements();
        ((ParamDecl) e.nextElement()).setPackage(s)) ;
    raisesExpr.setPackage(s);
  }
Beispiel #21
0
  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;
  }
Beispiel #22
0
  /** @param printModifiers whether "public abstract" should be added */
  public void printSignature(PrintWriter ps, boolean printModifiers) {
    ps.print("\t");
    if (printModifiers) ps.print("public abstract ");

    ps.print(opTypeSpec.toString() + " " + name + "(");

    for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
      ((ParamDecl) e.nextElement()).print(ps);
      if (e.hasMoreElements()) ps.print(", ");
    }

    ps.print(")");
    raisesExpr.print(ps);
    ps.println(";");
  }
Beispiel #23
0
  public void member_print(PrintWriter ps, String prefix) {
    /* only print members that are not interfaces */

    if (type_spec.typeSpec() instanceof ConstrTypeSpec
            && !(((ConstrTypeSpec) type_spec.typeSpec()).c_type_spec.declaration()
                instanceof Interface)
        || type_spec.typeSpec() instanceof SequenceType
        || type_spec.typeSpec() instanceof ArrayTypeSpec) {
      type_spec.print(ps);
    }

    if (type_spec.typeSpec() instanceof StringType)
      ps.print(prefix + type_spec.toString() + " " + declarator.toString() + " = \"\";");
    else ps.print(prefix + type_spec.toString() + " " + declarator.toString() + ";");
  }
Beispiel #24
0
 public java.lang.Class[] getExternParamTypes() {
   final java.lang.Class[] eParamTypes = new java.lang.Class[_paramTypes.length];
   for (int i = 0; i < _paramTypes.length; i++) {
     final TypeSpec type = _paramTypes[i];
     if (type.isBuiltin() || type.isBuiltinClass()) {
       eParamTypes[i] = (java.lang.Class) type.getSysType();
     } else {
       if (type.isClassOrInterface()) {
         final ClassInfo ci = type.getClassInfo();
         if (ci.isExternal()) {
           eParamTypes[i] = (java.lang.Class) ci.getSysType();
         } else {
           eParamTypes[i] = Class.class;
         }
       } else {
         eParamTypes[i] = Func.class;
       }
     }
   }
   return eParamTypes;
 }
Beispiel #25
0
  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();
  }
Beispiel #26
0
  public void printInvocation(PrintWriter ps) {
    if (!raisesExpr.empty()) {
      ps.println("\t\t\ttry");
      ps.println("\t\t\t{");
    }

    /* read args */

    int argc = 0;

    if (parser.hasObjectCachePlugin()) {
      parser.getObjectCachePlugin().printPreParamRead(ps, paramDecls);
    }

    for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
      ParamDecl p = (ParamDecl) e.nextElement();
      TypeSpec ts = p.paramTypeSpec.typeSpec();

      boolean is_wstring = ((ts instanceof StringType) && (((StringType) ts).isWide()));

      boolean is_wchar = ((ts instanceof CharType) && (((CharType) ts).isWide()));

      if (p.paramAttribute == ParamDecl.MODE_IN) {
        ps.println(
            "\t\t\t\t"
                + ts.toString()
                + " _arg"
                + (argc++)
                + "="
                + ts.printReadExpression("_input")
                + ";");
      } else {
        ps.println(
            "\t\t\t\t" + ts.holderName() + " _arg" + (argc++) + "= new " + ts.holderName() + "();");
        if (p.paramAttribute == ParamDecl.MODE_INOUT) {
          // wchars and wstrings are contained in CharHolder and
          // StringHolder and so cannot be inserted via _read operation
          // on holder. Instead value of holder needs to be set directly
          // from correct type explicitly read from stream.

          if (is_wchar) {
            ps.println("\t\t\t\t_arg" + (argc - 1) + ".value = _input.read_wchar ();");
          } else if (is_wstring) {
            ps.println("\t\t\t\t_arg" + (argc - 1) + ".value = _input.read_wstring ();");
          } else {
            ps.println("\t\t\t\t_arg" + (argc - 1) + "._read (_input);");
          }
        }
      }
    }

    if (parser.hasObjectCachePlugin()) {
      parser.getObjectCachePlugin().printPostParamRead(ps, paramDecls);
    }

    boolean complex =
        (opTypeSpec.typeSpec() instanceof ArrayTypeSpec)
            || (opTypeSpec.typeSpec() instanceof FixedPointType);

    String write_str = null, write_str_prefix = null, write_str_suffix = null;

    //  if( (!(opTypeSpec.typeSpec() instanceof VoidTypeSpec ))    || holders )
    //  {
    ps.println("\t\t\t\t_out = handler.createReply();");
    if (!(opTypeSpec.typeSpec() instanceof VoidTypeSpec) && !complex) {
      write_str = opTypeSpec.typeSpec().printWriteStatement("**", "_out");
      int index = write_str.indexOf("**");
      write_str_prefix = write_str.substring(0, index);
      write_str_suffix = write_str.substring(index + 2);
      ps.print("\t\t\t\t" + write_str_prefix);
    } else ps.print("\t\t\t\t");
    //  }

    if (complex) ps.print(opTypeSpec.typeSpec().typeName() + " _result = ");

    ps.print(name + "(");

    for (int i = 0; i < argc; i++) {
      ps.print("_arg" + i);
      if (i < argc - 1) ps.print(",");
    }

    /*

    Enumeration e = paramDecls.elements();
    if(e.hasMoreElements())
    {
    TypeSpec ts = ((ParamDecl)e.nextElement()).paramTypeSpec;
    ps.print(ts.printReadExpression("input"));
    }

    for(; e.hasMoreElements();)
    {
    TypeSpec ts = ((ParamDecl)e.nextElement()).paramTypeSpec;
    ps.print("," + ts.printReadExpression("input"));
    }
    */

    if (!(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) ps.print(")");

    if (!complex) {
      if (opTypeSpec.typeSpec() instanceof VoidTypeSpec) ps.println(");");
      else ps.println(write_str_suffix);
    } else {
      ps.println(";");
      ps.println(opTypeSpec.typeSpec().printWriteStatement("_result", "_out"));
    }

    /* write holder values */

    argc = 0;
    for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
      ParamDecl p = (ParamDecl) e.nextElement();
      if (p.paramAttribute != ParamDecl.MODE_IN) {
        ps.println("\t\t\t\t" + p.printWriteStatement(("_arg" + (argc)), "_out"));
      }
      argc++;
    }

    if (parser.hasObjectCachePlugin()) {
      parser.getObjectCachePlugin().printSkeletonCheckin(ps, paramDecls, "_arg");
    }

    if (!raisesExpr.empty()) {
      ps.println("\t\t\t}");
      String[] excepts = raisesExpr.getExceptionNames();
      String[] classNames = raisesExpr.getExceptionClassNames();
      for (int i = 0; i < excepts.length; i++) {
        ps.println("\t\t\tcatch(" + excepts[i] + " _ex" + i + ")");
        ps.println("\t\t\t{");
        ps.println("\t\t\t\t_out = handler.createExceptionReply();");
        ps.println("\t\t\t\t" + classNames[i] + "Helper.write(_out, _ex" + i + ");");

        if (parser.generatedHelperPortability == parser.HELPER_JACORB) {
          ps.println(
              "\t\t\t\tif (handler instanceof org.jacorb.orb.dsi.ServerRequest && !"
                  + classNames[i]
                  + "Helper.id().equals(_ex"
                  + i
                  + ".getMessage()))");
          ps.println("\t\t\t\t{");
          ps.println(
              "\t\t\t\t\t((org.jacorb.orb.giop.ReplyOutputStream)_out).addServiceContext (org.jacorb.orb.dsi.ServerRequest.createExceptionDetailMessage (_ex"
                  + i
                  + ".getMessage()));");
          ps.println("\t\t\t\t}");
        }

        ps.println("\t\t\t}");
      }
    }
  }
Beispiel #27
0
  /** Writes the DII-based Body of the Method for the stub */
  private void printDIIBody(
      PrintWriter ps, String classname, String idl_name, boolean is_local, boolean is_abstract) {
    ps.println("\t\torg.omg.CORBA.Request _request = _request( \"" + idl_name + "\" );");
    ps.println("");

    // set return type
    if (opAttribute == NO_ATTRIBUTE && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
      // old version
      // ps.println( "\t\t_r.set_return_type(" + opTypeSpec.typeSpec().getTypeCodeExpression() +
      // ");");
      // new version, distinguishes different types
      if (opTypeSpec.typeSpec() instanceof BaseType) {
        BaseType bt = (BaseType) opTypeSpec.typeSpec();
        ps.println("\t\t_request.set_return_type( " + bt.getTypeCodeExpression() + " );");
      } else if (opTypeSpec.typeSpec() instanceof StringType) {
        StringType st = (StringType) opTypeSpec.typeSpec();
        ps.println("\t\t_request.set_return_type( " + st.getTypeCodeExpression() + " );");
      } else {
        try {
          // if there is a helper-class, use it to get the TypeCode for the return value
          String helperName = opTypeSpec.typeSpec().helperName();
          ps.println("\t\t_request.set_return_type(" + helperName + ".type()" + ");");
        } catch (NoHelperException e) {
          // otherwise use typeCodeExpression
          // (the old version)
          ps.println(
              "\t\t_request.set_return_type("
                  + opTypeSpec.typeSpec().getTypeCodeExpression()
                  + ");");
        }
      }
    } else {
      // return type void
      ps.println(
          "\t\t_request.set_return_type(_orb().get_primitive_tc(org.omg.CORBA.TCKind.tk_void));");
    }
    ps.println("");

    // put parameters into the request
    for (Enumeration e2 = paramDecls.elements(); e2.hasMoreElements(); ) {
      ParamDecl p = ((ParamDecl) e2.nextElement());
      p.printAddArgumentStatement(ps, "_request");
      ps.println("");
    }

    // add exceptions
    if (!raisesExpr.empty()) {
      String[] exceptions = raisesExpr.getExceptionClassNames();
      for (int i = 0; i < exceptions.length; i++) {
        ps.println("\t\t_request.exceptions().add(" + exceptions[i] + "Helper.type());");
      }
      ps.println("");
    }

    // invoke
    ps.println("\t\t_request.invoke();");
    ps.println("");

    // get Exception
    ps.println("\t\tjava.lang.Exception _exception = _request.env().exception();");
    ps.println("\t\tif (_exception != null)");
    ps.println("\t\t{");
    if (!raisesExpr.empty()) {
      ps.println("\t\t\tif(_exception instanceof org.omg.CORBA.UnknownUserException)");
      ps.println("\t\t\t{");
      ps.println(
          "\t\t\t\torg.omg.CORBA.UnknownUserException _userException = (org.omg.CORBA.UnknownUserException) _exception;");
      ps.print("\t\t\t\t");
      String[] raisesExceptions = raisesExpr.getExceptionClassNames();
      for (int i = 0; i < raisesExceptions.length; i++) {
        ps.println(
            "if (_userException.except.type().equals(" + raisesExceptions[i] + "Helper.type()))");
        ps.println("\t\t\t\t{");
        ps.println(
            "\t\t\t\t\tthrow " + raisesExceptions[i] + "Helper.extract(_userException.except);");
        ps.println("\t\t\t\t}");
        ps.println("\t\t\t\telse");
      }
      ps.println("\t\t\t\t{");
      ps.println("\t\t\t\t\tthrow new org.omg.CORBA.UNKNOWN();");
      ps.println("\t\t\t\t}");
      ps.println("\t\t\t}");
    }

    ps.println("\t\t\tthrow (org.omg.CORBA.SystemException) _exception;");
    ps.println("\t\t}");
    ps.println("");

    // Get out and inout parameters!
    for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
      ParamDecl p = ((ParamDecl) e.nextElement());
      if (p.paramAttribute != ParamDecl.MODE_IN) {
        p.printExtractArgumentStatement(ps);
      }
    }

    // get the result
    if (opAttribute == NO_ATTRIBUTE && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
      ps.println("\t\t" + opTypeSpec.toString() + " _result;");
      opTypeSpec
          .typeSpec()
          .printExtractResult(ps, "_result", "_request.return_value()", opTypeSpec.toString());
      ps.println("\t\treturn _result;");
    } else ps.println("\t\treturn;");
  }
Beispiel #28
0
  /** Writes the Stream-based Body of the Method for the stub */
  public void printStreamBody(
      PrintWriter ps, String classname, String idl_name, boolean is_local, boolean is_abstract) {
    ps.println("\t\twhile(true)");
    ps.println("\t\t{");
    // remote part, not for locality constrained objects
    //
    if (!is_local) {
      ps.println("\t\t\tif(! this._is_local())");
      ps.println("\t\t\t{");
      ps.println("\t\t\t\torg.omg.CORBA.portable.InputStream _is = null;");
      ps.println("\t\t\t\torg.omg.CORBA.portable.OutputStream _os = null;");
      ps.println("\t\t\t\ttry");
      ps.println("\t\t\t\t{");
      ps.print("\t\t\t\t\t_os = _request( \"" + idl_name + "\",");

      if (opAttribute == NO_ATTRIBUTE) ps.println(" true);");
      else ps.println(" false);");

      //  arguments..

      for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
        ParamDecl p = ((ParamDecl) e.nextElement());
        if (p.paramAttribute != ParamDecl.MODE_OUT)
          ps.println("\t\t\t\t\t" + p.printWriteStatement("_os"));
      }

      ps.println("\t\t\t\t\t_is = _invoke(_os);");

      if (opAttribute == 0 && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
        ps.println(
            "\t\t\t\t\t"
                + opTypeSpec.toString()
                + " _result = "
                + opTypeSpec.typeSpec().printReadExpression("_is")
                + ";");
      }

      for (Enumeration e2 = paramDecls.elements(); e2.hasMoreElements(); ) {
        ParamDecl p = (ParamDecl) e2.nextElement();
        if (p.paramAttribute != ParamDecl.MODE_IN) {
          ps.println(
              "\t\t\t\t\t"
                  + p.simple_declarator
                  + ".value = "
                  + p.printReadExpression("_is")
                  + ";");
        }
      }

      if (opAttribute == NO_ATTRIBUTE && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
        ps.println("\t\t\t\t\treturn _result;");
      } else ps.println("\t\t\t\t\treturn;");

      /* catch exceptions */

      ps.println("\t\t\t\t}");
      ps.println("\t\t\t\tcatch( org.omg.CORBA.portable.RemarshalException _rx )");
      ps.println("\t\t\t\t\t{");
      ps.println("\t\t\t\t\t\tcontinue;");
      ps.println("\t\t\t\t\t}");
      ps.println("\t\t\t\tcatch( org.omg.CORBA.portable.ApplicationException _ax )");
      ps.println("\t\t\t\t{");
      ps.println("\t\t\t\t\tString _id = _ax.getId();");

      if (!raisesExpr.empty()) {
        String[] exceptIds = raisesExpr.getExceptionIds();
        String[] classNames = raisesExpr.getExceptionClassNames();

        ps.println("\t\t\t\t\ttry");
        ps.println("\t\t\t\t\t{");

        for (int i = 0; i < exceptIds.length; i++) {
          ps.println("\t\t\t\t\t\tif( _id.equals(\"" + exceptIds[i] + "\"))");
          ps.println("\t\t\t\t\t\t{");
          ps.println("\t\t\t\t\t\t\tthrow " + classNames[i] + "Helper.read(_ax.getInputStream());");
          ps.println("\t\t\t\t\t\t}");
          ps.println("\t\t\t\t\t\telse ");
        }
        ps.println("\t\t\t\t\t\t{");
        ps.println("\t\t\t\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + _id );");
        ps.println("\t\t\t\t\t\t}");
        ps.println("\t\t\t\t\t}");
        ps.println("\t\t\t\t\tfinally");
        ps.println("\t\t\t\t\t{");
        ps.println("\t\t\t\t\t\ttry");
        ps.println("\t\t\t\t\t\t{");
        ps.println("\t\t\t\t\t\t\t_ax.getInputStream().close();");
        ps.println("\t\t\t\t\t\t}");
        ps.println("\t\t\t\t\t\tcatch (java.io.IOException e)");
        ps.println("\t\t\t\t\t\t{");
        ps.println(
            "\t\t\t\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + e.toString() );");
        ps.println("\t\t\t\t\t\t}");
        ps.println("\t\t\t\t\t}");
      } else {
        ps.println("\t\t\t\t\ttry");
        ps.println("\t\t\t\t\t{");
        ps.println("\t\t\t\t\t\t\t_ax.getInputStream().close();");
        ps.println("\t\t\t\t\t}");
        ps.println("\t\t\t\t\tcatch (java.io.IOException e)");
        ps.println("\t\t\t\t\t{");
        ps.println(
            "\t\t\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + e.toString() );");
        ps.println("\t\t\t\t\t}");
        ps.println("\t\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + _id );");
      }
      ps.println("\t\t\t}");
      ps.println("\t\t\tfinally");
      ps.println("\t\t\t{");
      ps.println("\t\t\t\tif (_os != null)");
      ps.println("\t\t\t\t{");
      ps.println("\t\t\t\t\ttry");
      ps.println("\t\t\t\t\t{");
      ps.println("\t\t\t\t\t\t_os.close();");
      ps.println("\t\t\t\t\t}");
      ps.println("\t\t\t\t\tcatch (java.io.IOException e)");
      ps.println("\t\t\t\t\t{");
      ps.println(
          "\t\t\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + e.toString() );");
      ps.println("\t\t\t\t\t}");
      ps.println("\t\t\t\t}");
      ps.println("\t\t\t\tthis._releaseReply(_is);");
      ps.println("\t\t\t}");

      ps.println("\t\t}");
      // local part
      ps.println("\t\telse");
      ps.println("\t\t{");
    }

    ps.println(
        "\t\t\torg.omg.CORBA.portable.ServantObject _so = _servant_preinvoke( \""
            + idl_name
            + "\", _opsClass );");

    ps.println("\t\t\tif( _so == null )");
    ps.println("\t\t\t\tcontinue;");

    if (is_abstract) {
      ps.println("\t\t\t" + classname + " _localServant = (" + classname + ")_so.servant;");
    } else {
      ps.println(
          "\t\t\t"
              + classname
              + "Operations _localServant = ("
              + classname
              + "Operations)_so.servant;");
    }

    if (opAttribute == 0 && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
      ps.println("\t\t\t" + opTypeSpec.toString() + " _result;");
    }

    ps.println("\t\t\ttry");
    ps.println("\t\t\t{");

    if (opAttribute == 0 && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
      ps.print("\t\t\t\t_result = ");
    } else {
      ps.print("\t\t\t\t");
    }

    ps.print("_localServant." + name + "(");

    for (Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) {
      ParamDecl p = ((ParamDecl) e.nextElement());
      ps.print(p.simple_declarator.toString());
      if (e.hasMoreElements()) ps.print(",");
    }
    ps.println(");");

    ps.println("\t\t\t\tif ( _so instanceof org.omg.CORBA.portable.ServantObjectExt) ");
    ps.println("\t\t\t\t\t((org.omg.CORBA.portable.ServantObjectExt)_so).normalCompletion();");

    if (opAttribute == 0 && !(opTypeSpec.typeSpec() instanceof VoidTypeSpec)) {
      ps.println("\t\t\t\treturn _result;");
    } else {
      ps.println("\t\t\t\treturn;");
    }

    ps.println("\t\t\t}");

    if (!raisesExpr.empty()) {
      String[] exceptIds = raisesExpr.getExceptionIds();
      String[] classNames = raisesExpr.getExceptionClassNames();

      for (int i = 0; i < exceptIds.length; i++) {
        ps.println("\t\t\tcatch (" + classNames[i] + " ex) ");
        ps.println("\t\t\t{");
        ps.println("\t\t\t\tif ( _so instanceof org.omg.CORBA.portable.ServantObjectExt) ");
        ps.println(
            "\t\t\t\t\t((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(ex);");
        ps.println("\t\t\t\tthrow ex;");
        ps.println("\t\t\t}");
      }
    }

    ps.println("\t\t\tcatch (RuntimeException re) ");
    ps.println("\t\t\t{");
    ps.println("\t\t\t\tif ( _so instanceof org.omg.CORBA.portable.ServantObjectExt) ");
    ps.println(
        "\t\t\t\t\t((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(re);");
    ps.println("\t\t\t\tthrow re;");
    ps.println("\t\t\t}");
    ps.println("\t\t\tcatch (java.lang.Error err) ");
    ps.println("\t\t\t{");
    ps.println("\t\t\t\tif ( _so instanceof org.omg.CORBA.portable.ServantObjectExt) ");
    ps.println(
        "\t\t\t\t\t((org.omg.CORBA.portable.ServantObjectExt)_so).exceptionalCompletion(err);");
    ps.println("\t\t\t\tthrow err;");
    ps.println("\t\t\t}");
    ps.println("\t\t\tfinally");
    ps.println("\t\t\t{");
    ps.println("\t\t\t\t_servant_postinvoke(_so);");
    ps.println("\t\t\t}");

    if (!is_local) ps.println("\t\t}" + Environment.NL);

    ps.println("\t\t}" + Environment.NL); // end while
  }
  /**
   * Parse type definitions.
   *
   * @param token the initial token.
   * @throws Exception if an error occurred.
   */
  public void parse(Token token) throws Exception {
    token = synchronize(IDENTIFIER_SET);

    // Loop to parse a sequence of type definitions
    // separated by semicolons.
    while (token.getType() == IDENTIFIER) {
      String name = token.getText().toLowerCase();
      SymTabEntry typeId = symTabStack.lookupLocal(name);

      // Enter the new identifier into the symbol table
      // but don't set how it's defined yet.
      if (typeId == null) {
        typeId = symTabStack.enterLocal(name);
        typeId.appendLineNumber(token.getLineNumber());
      } else {
        errorHandler.flag(token, IDENTIFIER_REDEFINED, this);
        typeId = null;
      }

      token = nextToken(); // consume the identifier token

      // Synchronize on the = token.
      token = synchronize(EQUALS_SET);
      if (token.getType() == EQUALS) {
        token = nextToken(); // consume the =
      } else {
        errorHandler.flag(token, MISSING_EQUALS, this);
      }

      // Parse the type specification.
      TypeSpecificationParser typeSpecificationParser = new TypeSpecificationParser(this);
      TypeSpec type = typeSpecificationParser.parse(token);

      // Set identifier to be a type and set its type specificationt.
      if (typeId != null) {
        typeId.setDefinition(TYPE);
      }

      // Cross-link the type identifier and the type specification.
      if (type != null && typeId != null) {
        if (type.getIdentifier() == null) {
          type.setIdentifier(typeId);
        }
        typeId.setTypeSpec(type);
      } else {
        token = synchronize(FOLLOW_SET);
      }

      token = currentToken();
      TokenType tokenType = token.getType();

      // Look for one or more semicolons after a definition.
      if (tokenType == SEMICOLON) {
        while (token.getType() == SEMICOLON) {
          token = nextToken(); // consume the ;
        }
      }

      // If at the start of the next definition or declaration,
      // then missing a semicolon.
      else if (NEXT_START_SET.contains(tokenType)) {
        errorHandler.flag(token, MISSING_SEMICOLON, this);
      }

      token = synchronize(IDENTIFIER_SET);
    }
  }
Beispiel #30
0
  /** 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;
  }