Пример #1
0
  public SixModelObject get_attribute_boxed(
      ThreadContext tc, SixModelObject class_handle, String name, long hint) {
    SixModelObject member = memberCache.get(name);
    if (member != null) return member;

    CStructREPRData data = (CStructREPRData) class_handle.st.REPRData;
    AttrInfo info = data.fieldTypes.get(name);

    Object o = storage.readField(name);
    if (info.inlined == 0) {
      if (info.argType == ArgType.CSTRUCT) {
        Class<?> structClass = ((CStructREPRData) info.type.st.REPRData).structureClass;
        o = (Object) Structure.newInstance(structClass, ((Pointer) o));
      } else if (info.argType == ArgType.CPPSTRUCT) {
        Class<?> structClass = ((CPPStructREPRData) info.type.st.REPRData).structureClass;
        o = (Object) Structure.newInstance(structClass, ((Pointer) o));
      } else if (info.argType == ArgType.CUNION) {
        Class<?> structClass = ((CUnionREPRData) info.type.st.REPRData).structureClass;
        o = (Object) Union.newInstance(structClass, ((Pointer) o));
      }
    }

    member = NativeCallOps.toNQPType(tc, info.argType, info.type, o);
    memberCache.put(name, member);
    return member;
  }
Пример #2
0
  public void get_attribute_native(
      ThreadContext tc, SixModelObject class_handle, String name, long hint) {
    CStructREPRData data = (CStructREPRData) class_handle.st.REPRData;
    AttrInfo info = data.fieldTypes.get(name);

    Object o = storage.readField(name);
    switch (info.argType) {
      case CHAR:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Byte) o).byteValue();
        break;
      case SHORT:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Short) o).shortValue();
        break;
      case INT:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Integer) o).intValue();
        break;
      case LONG:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Long) o).longValue();
        break;
      case FLOAT:
        tc.native_type = ThreadContext.NATIVE_NUM;
        tc.native_n = ((Float) o).floatValue();
        break;
      case DOUBLE:
        tc.native_type = ThreadContext.NATIVE_NUM;
        tc.native_n = ((Double) o).doubleValue();
        break;
      default:
        ExceptionHandling.dieInternal(
            tc, String.format("CStruct.get_attribute_native: Can't handle %s", info.argType));
    }
  }