private static void generateBufferParameterAddresses(
     TypeMap type_map, PrintWriter writer, MethodDeclaration method, Mode mode) {
   boolean loopDeclared = false;
   for (ParameterDeclaration param : method.getParameters())
     if (Utils.isAddressableType(param.getType()) && param.getAnnotation(Result.class) == null)
       loopDeclared =
           generateBufferParameterAddress(type_map, writer, method, param, mode, loopDeclared);
 }
 private static void generateCallParameter(
     PrintWriter writer, TypeMap type_map, ParameterDeclaration param) {
   boolean is_indirect = param.getAnnotation(Indirect.class) != null;
   if (is_indirect || param.getAnnotation(StringList.class) != null) {
     writer.print("(");
     NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
     param.getType().accept(translator);
     writer.print(translator.getSignature());
     writer.print("*)");
   }
   if (param.getAnnotation(GLpointer.class) != null)
     writer.print("(" + param.getAnnotation(GLpointer.class).value() + ")(intptr_t)");
   if (param.getAnnotation(Result.class) != null || is_indirect) writer.print("&");
   if (param.getAnnotation(Result.class) != null) {
     writer.print(Utils.RESULT_VAR_NAME);
   } else {
     writer.print(param.getSimpleName());
     if (param.getAnnotation(StringList.class) != null) writer.print(STRING_LIST_POSTFIX);
     else if (Utils.isAddressableType(param.getType())) writer.print(BUFFER_ADDRESS_POSTFIX);
   }
 }
Пример #3
0
  private static void printParameterChecks(
      PrintWriter writer,
      ExecutableElement method,
      Map<VariableElement, TypeInfo> typeinfos,
      Mode mode,
      final boolean generate_error_checks) {
    if (mode == Mode.NORMAL) {
      final GenerateAutos gen_autos_annotation = method.getAnnotation(GenerateAutos.class);
      if (gen_autos_annotation != null && gen_autos_annotation.sizeVariables().length > 0) {
        // For the auto-generated parameters, declare and init a size variable (that can be reused
        // by @Code)
        for (final VariableElement param : method.getParameters()) {
          if (Arrays.binarySearch(
                  gen_autos_annotation.sizeVariables(), param.getSimpleName().toString())
              >= 0) {
            final int shifting = getBufferElementSizeExponent(typeinfos.get(param).getType());
            final Check check_annotation = param.getAnnotation(Check.class);

            writer.print("\t\tlong " + param.getSimpleName() + "_size = ");
            if (check_annotation == null || !check_annotation.canBeNull()) {
              writer.println(param.getSimpleName() + ".remaining() << " + shifting + ";");
            } else {
              writer.println(
                  param.getSimpleName()
                      + " == null ? 0 : "
                      + param.getSimpleName()
                      + ".remaining() << "
                      + shifting
                      + ";");
            }
          }
        }
      }
    }

    for (VariableElement param : method.getParameters()) {
      Class java_type = Utils.getJavaType(param.asType());
      if (java_type.isArray()
          || (Utils.isAddressableType(java_type)
              && (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null)
              && (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null)
              && param.getAnnotation(Result.class) == null
              && !Utils.isReturnParameter(method, param))) {
        String check_value = null;
        boolean can_be_null = false;
        Check check_annotation = param.getAnnotation(Check.class);
        if (check_annotation != null) {
          check_value = check_annotation.value();
          can_be_null = check_annotation.canBeNull();
        }
        if ((Buffer.class.isAssignableFrom(java_type)
                || PointerBuffer.class.isAssignableFrom(java_type))
            && param.getAnnotation(Constant.class) == null) {
          TypeInfo typeinfo = typeinfos.get(param);
          printParameterCheck(
              writer,
              method,
              param.getSimpleName().toString(),
              typeinfo.getType().getSimpleName(),
              check_value,
              can_be_null,
              param.getAnnotation(NullTerminated.class),
              generate_error_checks);
        } else if (String.class.equals(java_type)) {
          if (!can_be_null) {
            writer.println("\t\tBufferChecks.checkNotNull(" + param.getSimpleName() + ");");
          }
        } else if (java_type.isArray()) {
          printArrayParameterCheck(
              writer, param.getSimpleName().toString(), check_value, can_be_null);
        }
      }
    }
    if (method.getAnnotation(CachedResult.class) != null) {
      printParameterCheck(
          writer, method, Utils.CACHED_BUFFER_NAME, null, null, true, null, generate_error_checks);
    }
  }