コード例 #1
0
  private void readInstantiatedField(Field field, TypeInstantiation inst) {
    CompoundType compound = inst.getBaseType();

    buffer.append(AccessorNameEmitter.getSetterName(field));
    buffer.append("(new ");
    buffer.append(compound.getName());
    buffer.append("(__in, __cc");
    appendArguments(buffer, inst);
    buffer.append("));");
  }
コード例 #2
0
  /**
   * Emits a type cast for passing an argument to a parameterized type.
   *
   * @param type compound type with parameters
   * @param expr argument expression in type instantiation
   * @param paramIndex index of argument in argument list
   */
  private static boolean emitTypeCast(
      StringBuilder buffer, CompoundType type, Expression expr, int paramIndex) {
    boolean cast = false;
    Parameter param = type.getParameterAt(paramIndex);
    TypeInterface paramType = TypeReference.getBaseType(param.getType());

    if (paramType instanceof StdIntegerType) {
      StdIntegerType intType = (StdIntegerType) paramType;
      switch (intType.getType()) {
        case DataScriptParserTokenTypes.INT8:
          buffer.append("(byte)(");
          cast = true;
          break;

        case DataScriptParserTokenTypes.UINT8:
        case DataScriptParserTokenTypes.INT16:
          buffer.append("(short)(");
          cast = true;
          break;
        default:
          // nothing
      }
    }
    return cast;
  }
コード例 #3
0
  public void buildParameterLists() {
    StringBuilder formal = new StringBuilder();
    StringBuilder actual = new StringBuilder();
    CompoundType compound = getCompoundType();
    for (Parameter param : compound.getParameters()) {
      String paramName = param.getName();
      TypeInterface paramType = TypeReference.getBaseType(param.getType());

      String typeName = TypeNameEmitter.getTypeName(paramType);
      formal.append(", ");
      formal.append(typeName);
      formal.append(" ");
      formal.append(paramName);

      actual.append(", ");
      actual.append(paramName);
    }
    formalParams = formal.toString();
    actualParams = actual.toString();
  }
コード例 #4
0
 private void setParameters(String lhs, TypeInstantiation inst) {
   CompoundType compound = inst.getBaseType();
   Iterable<Expression> arguments = inst.getArguments();
   if (arguments != null) {
     int argIndex = 0;
     for (Expression arg : arguments) {
       Parameter param = compound.getParameterAt(argIndex);
       String setter = AccessorNameEmitter.getSetterName(param);
       buffer.append(lhs);
       buffer.append(".");
       buffer.append(setter);
       buffer.append("(");
       boolean cast = emitTypeCast(buffer, compound, arg, argIndex);
       String javaArg = exprEmitter.emit(arg);
       buffer.append(javaArg);
       if (cast) {
         buffer.append(")");
       }
       buffer.append(");\n                ");
       argIndex++;
     }
   }
 }
コード例 #5
0
 private void readCompoundField(Field field, CompoundType type) {
   buffer.append(AccessorNameEmitter.getSetterName(field));
   buffer.append("(new ");
   buffer.append(type.getName());
   buffer.append("(__in, __cc));");
 }