Beispiel #1
0
 private static boolean hasEnum(Method m) {
   boolean result = (Type.ENUM == m.getReturnType().getDetailedType());
   Iterator i = m.getArgumentList().iterator();
   while (!result && i.hasNext()) {
     Argument arg = (Argument) i.next();
     result = (arg.getType().getDetailedType() == Type.ENUM);
   }
   return result;
 }
Beispiel #2
0
 public static String getArgumentWithFormal(
     Argument arg, Context context, boolean objPtr, boolean inStub, boolean isExec)
     throws CodeGenerationException {
   final Type type = arg.getType();
   if (Type.ENUM == type.getDetailedType()) {
     return getEnumName(type.getSymbolID())
         + ((arg.getMode() != Argument.IN) ? "* " : " ")
         + arg.getFormalName();
   } else {
     return IOR.getArgumentWithFormal(arg, context, objPtr, inStub, isExec);
   }
 }
Beispiel #3
0
 /**
  * Create a comment to describe the SIDL type for the C signature.
  *
  * @param arg the argument to make a comment from
  * @return usually this is just the mode as a string. For arrays and rarrays more information is
  *     returned.
  */
 public static String argComment(Argument arg) {
   final Type argType = arg.getType();
   if (Type.ARRAY == argType.getDetailedType()) {
     StringBuffer buf = new StringBuffer(arg.getModeString());
     if (argType.isRarray()) {
       buf.append(" rarray[");
       Iterator i = argType.getArrayIndexExprs().iterator();
       while (i.hasNext()) {
         AssertionExpression ae = (AssertionExpression) i.next();
         buf.append(ae.accept(new CExprString(), null).toString());
         if (i.hasNext()) buf.append(',');
       }
       buf.append(']');
     } else {
       buf.append(' ');
       buf.append(argType.getTypeString());
     }
     return buf.toString();
   } else {
     return arg.getModeString();
   }
 }
Beispiel #4
0
  /**
   * Generate the specified argument list.
   *
   * @param writer the language writer.
   * @param self the String representing the method's self argument name.
   * @param args the basic argument list for the method.
   * @param isStatic the boolean indicating whether the method is static.
   * @param excVar the variable to be used for the exception argument; NULL if no exception argument
   *     to be generated.
   * @param returnType the return type of the method OR null if the method return type should not be
   *     included.
   * @param objPtr TRUE if the object pointer type should be returned; FALSE otherwise.
   * @param doRaw the boolean indicating if special raw array argument handling is needed.
   * @param deref_inout if true, out and inout arguments are dereferenced in passing. (Used for pre
   *     and post hooks)
   * @exception gov.llnl.babel.backend.CodeGenerationException this is a catch all exception. It can
   *     be caused by I/O trouble or violations of the data type invariants.
   */
  public static void generateArguments(
      LanguageWriterForC writer,
      Context context,
      String self,
      List args,
      boolean isStatic,
      String excVar,
      Type returnType,
      boolean addType,
      boolean objPtr,
      boolean doRaw,
      boolean deref_inout)
      throws CodeGenerationException {
    boolean doThrows = (excVar != null) && !excVar.equals("");
    boolean doReturn = false; // (returnType != null)
    // && (returnType.getType() != Type.VOID);

    /*
     * If the method is not static, then it will begin with an
     * object reference.
     */
    if (!isStatic) {
      if (addType) {
        writer.print("/* in */ ");
      }
      writer.print(self);
      if ((args.size() > 0) || doThrows || doReturn) {
        writer.println(",");
      }
    } else if (addType && (args.size() == 0) && !doThrows && !doReturn) {
      writer.print("void");
    }

    /*
     * Output each argument in turn.
     */
    for (Iterator a = args.iterator(); a.hasNext(); ) {
      Argument arg = (Argument) a.next();
      boolean isRaw = doRaw && arg.getType().isRarray();

      if (addType) {
        writer.print("/* " + argComment(arg) + " */ ");
        if (deref_inout && arg.getMode() != Argument.IN) {
          writer.print(" *");
        }
        writer.print(C.getArgumentWithFormal(arg, context, objPtr, isRaw, false));
      } else if (isRaw) {
        if (arg.getMode() == Argument.INOUT) {
          writer.print("&");
        }
        writer.print(arg.getFormalName() + RAW_ARRAY_EXT);
      } else {
        if (deref_inout && arg.getMode() != Argument.IN) {
          writer.print(" *");
        }
        if ((arg.getMode() != Argument.IN) && (arg.getType().getDetailedType() == Type.ENUM)) {
          writer.print("&_proxy_");
        }
        writer.print(arg.getFormalName());
      }
      if (a.hasNext() || doThrows || doReturn) {
        writer.println(",");
      }
    }

    /*
     * If there is a throws clause that is to be included, return the
     * exception type as the last item in the argument list associated with
     * the method.
     */
    if (doThrows) {
      if (addType) {
        writer.print("/* out */ ");
        if (objPtr) {
          writer.print(s_exceptionObjPtr + " *");
        } else {
          writer.print(s_exceptionType + " *");
        }
      }
      writer.print(excVar);
      if (doReturn) {
        writer.println(",");
      }
    }

    /*
     * Finally, the return type (if appropriate).
     */
    if (doReturn) {
      if (addType) {
        writer.print("/* in */ ");
        writer.print(C.getReturnString(returnType, context, objPtr, false));
      }
      writer.print(" " + FUNCTION_RESULT);
    }
  }