コード例 #1
0
 static int getArgumentsStackSize(Method method) {
   int total = 0;
   Type[] paramTypes = method.getGenericParameterTypes();
   Annotation[][] anns = method.getParameterAnnotations();
   for (int iArg = 0, nArgs = paramTypes.length; iArg < nArgs; iArg++) {
     Class<?> paramType = getTypeClass(paramTypes[iArg]);
     if (paramType == int.class) {
       total += 4;
     } else if (paramType == long.class) {
       Annotation[] as = anns[iArg];
       if (isAnnotationPresent(Ptr.class, as)
           || isAnnotationPresent(
               org.bridj.ann.CLong.class,
               as)) // if (hasInstance(anns[iArg], Ptr.class, CLong.class))
       {
         total += Pointer.SIZE;
       } else {
         total += 8;
       }
     } else if (paramType == float.class) {
       total += 4;
     } else if (paramType == double.class) {
       total += 8;
     } else if (paramType == byte.class) {
       total += 1;
     } else if (paramType == char.class) {
       total += Platform.WCHAR_T_SIZE;
     } else if (paramType == CLong.class) {
       total += Platform.CLONG_SIZE;
     } else if (paramType == SizeT.class) {
       total += Platform.SIZE_T_SIZE;
     } else if (paramType == TimeT.class) {
       total += Platform.TIME_T_SIZE;
     } else if (paramType == short.class) {
       total += 2;
     } else if (paramType == boolean.class) {
       total += 1;
     } else if (Pointer.class.isAssignableFrom(paramType)) {
       total += Pointer.SIZE;
     } else if (NativeObject.class.isAssignableFrom(paramType)) {
       total += ((CRuntime) BridJ.getRuntime(paramType)).sizeOf(paramTypes[iArg], null);
     } else if (FlagSet.class.isAssignableFrom(paramType)) {
       total += 4; // TODO
     } else {
       throw new RuntimeException("Type not handled : " + paramType.getName());
     }
   }
   return total;
 }