diff --git a/protobuf/runtime/src/com/google/protobuf/Descriptors_PackagePrivate.h b/protobuf/runtime/src/com/google/protobuf/Descriptors_PackagePrivate.h index 5829afda29..f0b1bf30c1 100644 --- a/protobuf/runtime/src/com/google/protobuf/Descriptors_PackagePrivate.h +++ b/protobuf/runtime/src/com/google/protobuf/Descriptors_PackagePrivate.h @@ -160,26 +160,13 @@ typedef struct CGPOneofData { @end -// Functions that convert a value from its field storage type to the type -// expected by a reflection accessor. (accessing with a descriptor) -// For enums, the reflection type is a EnumValueDescriptor. -#define CGPToReflectionTypeInt(value, field) [JavaLangInteger valueOfWithInt:value] -#define CGPToReflectionTypeLong(value, field) [JavaLangLong valueOfWithLong:value] -#define CGPToReflectionTypeFloat(value, field) [JavaLangFloat valueOfWithFloat:value] -#define CGPToReflectionTypeDouble(value, field) [JavaLangDouble valueOfWithDouble:value] -#define CGPToReflectionTypeBool(value, field) [JavaLangBoolean valueOfWithBoolean:value] -#define CGPToReflectionTypeEnum(value, field) \ - ((CGPEnumDescriptor *)field->valueType_)->values_->buffer_[[(JavaLangEnum *)value ordinal]] -#define CGPToReflectionTypeRetainable(value, field) RETAIN_AND_AUTORELEASE(value) - CF_EXTERN_C_BEGIN NS_RETURNS_RETAINED CGPDescriptor *CGPInitDescriptor(Class messageClass, Class builderClass, CGPMessageFlags flags, size_t storageSize); -void CGPInitFields( - CGPDescriptor *descriptor, jint fieldCount, CGPFieldData *fieldData, - jint oneofCount, const CGPOneofData *oneofData); +void CGPInitFields(CGPDescriptor *descriptor, jint fieldCount, CGPFieldData *fieldData, + jint oneofCount, const CGPOneofData *oneofData); CGP_ALWAYS_INLINE BOOL CGPIsExtendable(const CGPDescriptor *descriptor) { return descriptor->flags_ & CGPMessageFlagExtendable; @@ -306,4 +293,85 @@ J2OBJC_FIELD_SETTER(ComGoogleProtobufDescriptors_FieldDescriptor_Type, javaType_ J2OBJC_FIELD_SETTER(ComGoogleProtobufDescriptors_FieldDescriptor_JavaType, defaultDefault_, id) +// Functions that box a value from its field storage type into an object type. +// For enums, the boxed type is a Java enum object. +CGP_ALWAYS_INLINE JavaLangInteger *CGPBoxedValueInt(jint value) { + return [JavaLangInteger valueOfWithInt:value]; +} +CGP_ALWAYS_INLINE JavaLangLong *CGPBoxedValueLong(jlong value) { + return [JavaLangLong valueOfWithLong:value]; +} +CGP_ALWAYS_INLINE JavaLangFloat *CGPBoxedValueFloat(jfloat value) { + return [JavaLangFloat valueOfWithFloat:value]; +} +CGP_ALWAYS_INLINE JavaLangDouble *CGPBoxedValueDouble(jdouble value) { + return [JavaLangDouble valueOfWithDouble:value]; +} +CGP_ALWAYS_INLINE JavaLangBoolean *CGPBoxedValueBool(bool value) { + return [JavaLangBoolean valueOfWithBoolean:value]; +} +CGP_ALWAYS_INLINE JavaLangEnum *CGPBoxedValueEnum( + JavaLangEnum *value) { + return value; +} +CGP_ALWAYS_INLINE id CGPBoxedValueId(id value) { return value; } + +// Functions that unbox a value into its primitive type. +CGP_ALWAYS_INLINE jint CGPUnboxValueInt(JavaLangInteger *value) { return [value intValue]; } +CGP_ALWAYS_INLINE jlong CGPUnboxValueLong(JavaLangLong *value) { return [value longLongValue]; } +CGP_ALWAYS_INLINE jfloat CGPUnboxValueFloat(JavaLangFloat *value) { return [value floatValue]; } +CGP_ALWAYS_INLINE jdouble CGPUnboxValueDouble(JavaLangDouble *value) { return [value doubleValue]; } +CGP_ALWAYS_INLINE bool CGPUnboxValueBool(JavaLangBoolean *value) { return [value booleanValue]; } +CGP_ALWAYS_INLINE JavaLangEnum *CGPUnboxValueEnum( + JavaLangEnum *value) { + return value; +} +CGP_ALWAYS_INLINE id CGPUnboxValueRetainable(id value) { return value; } + +// Functions that convert a value from its reflection to its storage type. +CGP_ALWAYS_INLINE jint CGPFromReflectionTypeInt(JavaLangInteger *value) { return [value intValue]; } +CGP_ALWAYS_INLINE jlong CGPFromReflectionTypeLong(JavaLangLong *value) { + return [value longLongValue]; +} +CGP_ALWAYS_INLINE jfloat CGPFromReflectionTypeFloat(JavaLangFloat *value) { + return [value floatValue]; +} +CGP_ALWAYS_INLINE jdouble CGPFromReflectionTypeDouble(JavaLangDouble *value) { + return [value doubleValue]; +} +CGP_ALWAYS_INLINE bool CGPFromReflectionTypeBool(JavaLangBoolean *value) { + return [value booleanValue]; +} +CGP_ALWAYS_INLINE id CGPFromReflectionTypeEnum(CGPEnumValueDescriptor *value) { + return value->enum_; +} +CGP_ALWAYS_INLINE id CGPFromReflectionTypeRetainable(id value) { return value; } + +// Functions that convert a value from its field storage type to the type +// expected by a reflection accessor. (accessing with a descriptor) +// For enums, the reflection type is a EnumValueDescriptor. +CGP_ALWAYS_INLINE JavaLangInteger *CGPToReflectionTypeInt(jint value, CGPFieldDescriptor *field) { + return [JavaLangInteger valueOfWithInt:value]; +} +CGP_ALWAYS_INLINE JavaLangLong *CGPToReflectionTypeLong(jlong value, CGPFieldDescriptor *field) { + return [JavaLangLong valueOfWithLong:value]; +} +CGP_ALWAYS_INLINE JavaLangFloat *CGPToReflectionTypeFloat(jfloat value, CGPFieldDescriptor *field) { + return [JavaLangFloat valueOfWithFloat:value]; +} +CGP_ALWAYS_INLINE JavaLangDouble *CGPToReflectionTypeDouble(jdouble value, + CGPFieldDescriptor *field) { + return [JavaLangDouble valueOfWithDouble:value]; +} +CGP_ALWAYS_INLINE JavaLangBoolean *CGPToReflectionTypeBool(bool value, CGPFieldDescriptor *field) { + return [JavaLangBoolean valueOfWithBoolean:value]; +} +CGP_ALWAYS_INLINE CGPEnumValueDescriptor *CGPToReflectionTypeEnum( + JavaLangEnum *value, CGPFieldDescriptor *field) { + return ((CGPEnumDescriptor *)field->valueType_)->values_->buffer_[[value ordinal]]; +} +CGP_ALWAYS_INLINE id CGPToReflectionTypeRetainable(id value, CGPFieldDescriptor *field) { + return RETAIN_AND_AUTORELEASE(value); +} + #endif // __ComGoogleProtobufDescriptors_PackagePrivate_H__ diff --git a/protobuf/runtime/src/com/google/protobuf/FieldTypes.h b/protobuf/runtime/src/com/google/protobuf/FieldTypes.h index 5c61026278..e4efd714e6 100644 --- a/protobuf/runtime/src/com/google/protobuf/FieldTypes.h +++ b/protobuf/runtime/src/com/google/protobuf/FieldTypes.h @@ -36,6 +36,7 @@ #define __ComGoogleProtobufFieldTypes_H__ #import "com/google/protobuf/ProtocolMessageEnum.h" +#import "com/google/protobuf/common.h" #import "java/lang/Boolean.h" #import "java/lang/Double.h" #import "java/lang/Enum.h" @@ -46,150 +47,124 @@ @class ComGoogleProtobufDescriptors_FieldDescriptor_JavaType; @class ComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type; -#define TYPE_Int jint -#define TYPE_Long jlong -#define TYPE_Float jfloat -#define TYPE_Double jdouble -#define TYPE_Bool bool -#define TYPE_Enum id -#define TYPE_Id id -#define TYPE_Retainable id - -#define TYPE_RETAIN_Int(value) value -#define TYPE_RETAIN_Long(value) value -#define TYPE_RETAIN_Float(value) value -#define TYPE_RETAIN_Double(value) value -#define TYPE_RETAIN_Bool(value) value -#define TYPE_RETAIN_Enum(value) value -#if __has_feature(objc_arc) -#define TYPE_RETAIN_Retainable(value) value -#else -#define TYPE_RETAIN_Retainable(value) [value retain] -#endif - -#define TYPE_ASSIGN_Int(assignee, value) assignee = value -#define TYPE_ASSIGN_Long(assignee, value) assignee = value -#define TYPE_ASSIGN_Float(assignee, value) assignee = value -#define TYPE_ASSIGN_Double(assignee, value) assignee = value -#define TYPE_ASSIGN_Bool(assignee, value) assignee = value -#define TYPE_ASSIGN_Enum(assignee, value) assignee = value -#if __has_feature(objc_arc) -#define TYPE_ASSIGN_Retainable(assignee, value) assignee = value -#else -#define TYPE_ASSIGN_Retainable(assignee, value) \ - ([assignee autorelease], assignee = [value retain]) -#endif - -#define HASH_Int(value) value -#define HASH_Long(value) (int)((uint64_t)value ^ ((uint64_t)value >> 32)) -#define HASH_Float(value) *(int *)&value -#define HASH_Double(value) (int)(*(uint64_t *)&value ^ (*(uint64_t *)&value >> 32)) -#define HASH_Bool(value) (value ? 1231 : 1237) -#define HASH_Id(value) (int)[value hash] - -// Functions that box a value from its field storage type into an object type. -// For enums, the boxed type is the same as its storage type. (a Java enum -// object) -#define CGPBoxedValueInt(value) [JavaLangInteger valueOfWithInt:value] -#define CGPBoxedValueLong(value) [JavaLangLong valueOfWithLong:value] -#define CGPBoxedValueFloat(value) [JavaLangFloat valueOfWithFloat:value] -#define CGPBoxedValueDouble(value) [JavaLangDouble valueOfWithDouble:value] -#define CGPBoxedValueBool(value) [JavaLangBoolean valueOfWithBoolean:value] -#define CGPBoxedValueId(value) value - -// Functions that unbox a value into its primitive type. -#define CGPUnboxValueInt(value) [value intValue] -#define CGPUnboxValueLong(value) [value longLongValue] -#define CGPUnboxValueFloat(value) [value floatValue] -#define CGPUnboxValueDouble(value) [value doubleValue] -#define CGPUnboxValueBool(value) [value booleanValue] -#define CGPUnboxValueEnum(value) value -#define CGPUnboxValueRetainable(value) value - -// Functions that convert a value from its reflection to its storage type. -#define CGPFromReflectionTypeInt(value) [value intValue] -#define CGPFromReflectionTypeLong(value) [value longLongValue] -#define CGPFromReflectionTypeFloat(value) [value floatValue] -#define CGPFromReflectionTypeDouble(value) [value doubleValue] -#define CGPFromReflectionTypeBool(value) [value booleanValue] -#define CGPFromReflectionTypeEnum(value) ((CGPEnumValueDescriptor *)value)->enum_ -#define CGPFromReflectionTypeRetainable(value) value +typedef jint TYPE_Int; +typedef jlong TYPE_Long; +typedef jfloat TYPE_Float; +typedef jdouble TYPE_Double; +typedef bool TYPE_Bool; +typedef id TYPE_Enum; +typedef id TYPE_Id; +typedef id TYPE_Retainable; + +CGP_ALWAYS_INLINE jint TYPE_RETAIN_Int(jint value) { return value; } +CGP_ALWAYS_INLINE jlong TYPE_RETAIN_Long(jlong value) { return value; } +CGP_ALWAYS_INLINE jfloat TYPE_RETAIN_Float(jfloat value) { return value; } +CGP_ALWAYS_INLINE jdouble TYPE_RETAIN_Double(jdouble value) { return value; } +CGP_ALWAYS_INLINE bool TYPE_RETAIN_Bool(bool value) { return value; } +CGP_ALWAYS_INLINE id TYPE_RETAIN_Enum(id value) { return value; } +CGP_ALWAYS_INLINE id TYPE_RETAIN_Retainable(id value) { return RETAIN_(value); } + +CGP_ALWAYS_INLINE void TYPE_ASSIGN_Int(jint *assignee, jint value) { *assignee = value; } +CGP_ALWAYS_INLINE void TYPE_ASSIGN_Long(jlong *assignee, jlong value) { *assignee = value; } +CGP_ALWAYS_INLINE void TYPE_ASSIGN_Float(jfloat *assignee, jfloat value) { *assignee = value; } +CGP_ALWAYS_INLINE void TYPE_ASSIGN_Double(jdouble *assignee, jdouble value) { *assignee = value; } +CGP_ALWAYS_INLINE void TYPE_ASSIGN_Bool(bool *assignee, bool value) { *assignee = value; } +CGP_ALWAYS_INLINE void TYPE_ASSIGN_Enum(id *assignee, id value) { *assignee = value; } +CGP_ALWAYS_INLINE void TYPE_ASSIGN_Retainable(id *assignee, id value) { + __unused id unused = AUTORELEASE(*assignee); + *assignee = RETAIN_(value); +} + +CGP_ALWAYS_INLINE int HASH_Int(jint value) { return value; } +CGP_ALWAYS_INLINE int HASH_Long(jlong value) { + return (int)((uint64_t)value ^ ((uint64_t)value >> 32)); +} +CGP_ALWAYS_INLINE int HASH_Float(jfloat value) { + uint32_t bits; + memcpy(&bits, &value, sizeof(bits)); + return bits; +} +CGP_ALWAYS_INLINE int HASH_Double(jdouble value) { + uint64_t bits; + memcpy(&bits, &value, sizeof(bits)); + return (int)(bits ^ (bits >> 32)); +} +CGP_ALWAYS_INLINE int HASH_Bool(bool value) { return (value ? 1231 : 1237); } +CGP_ALWAYS_INLINE int HASH_Id(id value) { return (int)[value hash]; } // Creates a switch statement over the java types grouping enums together with // the other object types. -#define SWITCH_TYPES_NO_ENUM(type, CASE_MACRO) \ - switch (type) { \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_INT: \ - CASE_MACRO(Int) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_LONG: \ - CASE_MACRO(Long) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_FLOAT: \ - CASE_MACRO(Float) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_DOUBLE: \ - CASE_MACRO(Double) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_BOOLEAN: \ - CASE_MACRO(Bool) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_STRING: \ +#define SWITCH_TYPES_NO_ENUM(type, CASE_MACRO) \ + switch (type) { \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_INT: \ + CASE_MACRO(Int) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_LONG: \ + CASE_MACRO(Long) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_FLOAT: \ + CASE_MACRO(Float) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_DOUBLE: \ + CASE_MACRO(Double) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_BOOLEAN: \ + CASE_MACRO(Bool) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_STRING: \ case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_BYTE_STRING: \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_ENUM: \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_MESSAGE: \ - CASE_MACRO(Id) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_ENUM: \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_MESSAGE: \ + CASE_MACRO(Id) \ } // Creates a switch statement over the java types separating enums from the // other object types. -#define SWITCH_TYPES_WITH_ENUM(type, CASE_MACRO) \ - switch (type) { \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_INT: \ - CASE_MACRO(Int) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_LONG: \ - CASE_MACRO(Long) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_FLOAT: \ - CASE_MACRO(Float) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_DOUBLE: \ - CASE_MACRO(Double) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_BOOLEAN: \ - CASE_MACRO(Bool) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_STRING: \ +#define SWITCH_TYPES_WITH_ENUM(type, CASE_MACRO) \ + switch (type) { \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_INT: \ + CASE_MACRO(Int) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_LONG: \ + CASE_MACRO(Long) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_FLOAT: \ + CASE_MACRO(Float) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_DOUBLE: \ + CASE_MACRO(Double) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_BOOLEAN: \ + CASE_MACRO(Bool) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_STRING: \ case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_BYTE_STRING: \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_MESSAGE: \ - CASE_MACRO(Retainable) \ - case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_ENUM: \ - CASE_MACRO(Enum) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_MESSAGE: \ + CASE_MACRO(Retainable) \ + case ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_ENUM: \ + CASE_MACRO(Enum) \ } - // Declares the given macro once for each java field type, grouping enums and // the other object types together as "Id". Non-retainable types use the // PRIMITIVE_TYPE_MACRO, retainable types use the RETAINABLE_TYPE_MACRO #define FOR_EACH_TYPE_NO_ENUM(PRIMITIVE_TYPE_MACRO, RETAINABLE_TYPE_MACRO) \ - PRIMITIVE_TYPE_MACRO(Int) \ - PRIMITIVE_TYPE_MACRO(Long) \ - PRIMITIVE_TYPE_MACRO(Float) \ - PRIMITIVE_TYPE_MACRO(Double) \ - PRIMITIVE_TYPE_MACRO(Bool) \ + PRIMITIVE_TYPE_MACRO(Int) \ + PRIMITIVE_TYPE_MACRO(Long) \ + PRIMITIVE_TYPE_MACRO(Float) \ + PRIMITIVE_TYPE_MACRO(Double) \ + PRIMITIVE_TYPE_MACRO(Bool) \ RETAINABLE_TYPE_MACRO(Id) - // Declares the given macro once for each java field type, declaring it // separately for enums (as "Enum) and the other object types (as "Retainable"). #define FOR_EACH_TYPE_WITH_ENUM(MACRO) \ - MACRO(Int) \ - MACRO(Long) \ - MACRO(Float) \ - MACRO(Double) \ - MACRO(Bool) \ - MACRO(Enum) \ + MACRO(Int) \ + MACRO(Long) \ + MACRO(Float) \ + MACRO(Double) \ + MACRO(Bool) \ + MACRO(Enum) \ MACRO(Retainable) // Declares the given macro once for each java field type except for retainable -//types. +// types. #define FOR_EACH_TYPE_NO_RETAINABLE(MACRO) \ - MACRO(Int) \ - MACRO(Long) \ - MACRO(Float) \ - MACRO(Double) \ - MACRO(Bool) \ + MACRO(Int) \ + MACRO(Long) \ + MACRO(Float) \ + MACRO(Double) \ + MACRO(Bool) \ MACRO(Enum) // The remainder of this file is copied from the translation of the types @@ -218,7 +193,7 @@ typedef NS_ENUM(NSUInteger, ComGoogleProtobufDescriptors_FieldDescriptor_Type_En typedef ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum CGPFieldType; -@interface ComGoogleProtobufDescriptors_FieldDescriptor_Type : JavaLangEnum < NSCopying > +@interface ComGoogleProtobufDescriptors_FieldDescriptor_Type : JavaLangEnum #pragma mark Public @@ -226,7 +201,9 @@ typedef ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum CGPFieldType; - (ComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type *)toProto; -+ (ComGoogleProtobufDescriptors_FieldDescriptor_Type *)valueOfWithComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type:(ComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type *)type; ++ (ComGoogleProtobufDescriptors_FieldDescriptor_Type *) + valueOfWithComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type: + (ComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type *)type; #pragma mark Package-Private @@ -241,7 +218,8 @@ typedef ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum CGPFieldType; J2OBJC_STATIC_INIT(ComGoogleProtobufDescriptors_FieldDescriptor_Type) /*! INTERNAL ONLY - Use enum accessors declared below. */ -FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type *ComGoogleProtobufDescriptors_FieldDescriptor_Type_values_[]; +FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type + *ComGoogleProtobufDescriptors_FieldDescriptor_Type_values_[]; inline ComGoogleProtobufDescriptors_FieldDescriptor_Type * ComGoogleProtobufDescriptors_FieldDescriptor_Type_get_DOUBLE(void); @@ -315,13 +293,17 @@ inline ComGoogleProtobufDescriptors_FieldDescriptor_Type * ComGoogleProtobufDescriptors_FieldDescriptor_Type_get_SINT64(void); J2OBJC_ENUM_CONSTANT(ComGoogleProtobufDescriptors_FieldDescriptor_Type, SINT64) -FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type *ComGoogleProtobufDescriptors_FieldDescriptor_Type_valueOfWithComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type_(ComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type *type); +FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type * +ComGoogleProtobufDescriptors_FieldDescriptor_Type_valueOfWithComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type_( + ComGoogleProtobufDescriptorProtos_FieldDescriptorProto_Type *type); FOUNDATION_EXPORT IOSObjectArray *ComGoogleProtobufDescriptors_FieldDescriptor_Type_values(void); -FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type *ComGoogleProtobufDescriptors_FieldDescriptor_Type_valueOfWithNSString_(NSString *name); +FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type * +ComGoogleProtobufDescriptors_FieldDescriptor_Type_valueOfWithNSString_(NSString *name); -FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type *ComGoogleProtobufDescriptors_FieldDescriptor_Type_fromOrdinal(NSUInteger ordinal); +FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_Type * +ComGoogleProtobufDescriptors_FieldDescriptor_Type_fromOrdinal(NSUInteger ordinal); J2OBJC_TYPE_LITERAL_HEADER(ComGoogleProtobufDescriptors_FieldDescriptor_Type) @@ -337,7 +319,7 @@ typedef NS_ENUM(NSUInteger, ComGoogleProtobufDescriptors_FieldDescriptor_JavaTyp ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_MESSAGE = 8, }; -@interface ComGoogleProtobufDescriptors_FieldDescriptor_JavaType : JavaLangEnum < NSCopying > +@interface ComGoogleProtobufDescriptors_FieldDescriptor_JavaType : JavaLangEnum #pragma mark Package-Private @@ -352,7 +334,8 @@ typedef NS_ENUM(NSUInteger, ComGoogleProtobufDescriptors_FieldDescriptor_JavaTyp J2OBJC_STATIC_INIT(ComGoogleProtobufDescriptors_FieldDescriptor_JavaType) /*! INTERNAL ONLY - Use enum accessors declared below. */ -FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_JavaType *ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_values_[]; +FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_JavaType + *ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_values_[]; inline ComGoogleProtobufDescriptors_FieldDescriptor_JavaType * ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_get_INT(void); @@ -393,10 +376,12 @@ J2OBJC_ENUM_CONSTANT(ComGoogleProtobufDescriptors_FieldDescriptor_JavaType, MESS FOUNDATION_EXPORT IOSObjectArray *ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_values( void); -FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_JavaType *ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_valueOfWithNSString_(NSString *name); +FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_JavaType * +ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_valueOfWithNSString_(NSString *name); -FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_JavaType *ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_fromOrdinal(NSUInteger ordinal); +FOUNDATION_EXPORT ComGoogleProtobufDescriptors_FieldDescriptor_JavaType * +ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_fromOrdinal(NSUInteger ordinal); J2OBJC_TYPE_LITERAL_HEADER(ComGoogleProtobufDescriptors_FieldDescriptor_JavaType) -#endif // __ComGoogleProtobufFieldTypes_H__ +#endif // __ComGoogleProtobufFieldTypes_H__ diff --git a/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm b/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm index 0027d399ff..6889cb3238 100644 --- a/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm +++ b/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm @@ -71,8 +71,8 @@ #define NIL_CHECK_Float(value) #define NIL_CHECK_Double(value) #define NIL_CHECK_Bool(value) -#define NIL_CHECK_Enum(value) (void)nil_chk(value); -#define NIL_CHECK_Retainable(value) (void)nil_chk(value); +#define NIL_CHECK_Enum(value) (void)nil_chk(value) +#define NIL_CHECK_Retainable(value) (void)nil_chk(value) // Forward declarations. class CGPExtensionValue; @@ -125,7 +125,7 @@ static void MessageToString(id msg, CGPDescriptor *descriptor, NSMutableString * TYPE_##NAME value) { \ CGPRepeatedFieldCheckBounds(field, idx); \ TYPE_##NAME *ptr = &((TYPE_##NAME *)field->data->buffer)[idx]; \ - TYPE_ASSIGN_##NAME(*ptr, value); \ + TYPE_ASSIGN_##NAME(ptr, value); \ } FOR_EACH_TYPE_WITH_ENUM(REPEATED_FIELD_SETTER_IMP) @@ -302,15 +302,19 @@ static inline BOOL ClearPreviousOneof(id msg, CGPHasLocator loc, uintptr_t ptr) return wasCleared; } -#define REPEATED_FIELD_PTR(msg, offset) ((CGPRepeatedField *)((uint8_t *)msg + offset)) -#define MAP_FIELD_PTR(msg, offset) ((CGPMapField *)((uint8_t *)msg + offset)) +CGP_ALWAYS_INLINE CGPRepeatedField *REPEATED_FIELD_PTR(id msg, ptrdiff_t offset) { + return (CGPRepeatedField *)((uint8_t *)msg + offset); +} +CGP_ALWAYS_INLINE CGPMapField *MAP_FIELD_PTR(id msg, ptrdiff_t offset) { + return (CGPMapField *)((uint8_t *)msg + offset); +} #define FIELD_PTR(TYPE, msg, offset) ((TYPE *)((uint8_t *)msg + offset)) #define SINGULAR_SETTER_IMP(NAME) \ static void SingularSet##NAME(id msg, TYPE_##NAME value, size_t offset, CGPHasLocator hasLoc) { \ TYPE_##NAME *ptr = FIELD_PTR(TYPE_##NAME, msg, offset); \ ClearPreviousOneof(msg, hasLoc, (uintptr_t)ptr); \ - TYPE_ASSIGN_##NAME(*ptr, value); \ + TYPE_ASSIGN_##NAME(ptr, value); \ SetHas(msg, hasLoc); \ } @@ -508,7 +512,8 @@ static BOOL AddClearMethod(Class cls, SEL sel, CGPFieldDescriptor *field) { #define GET_SINGULAR_SETTER_IMP(NAME) \ static IMP GetSingularSetterImp##NAME(size_t offset, CGPHasLocator hasLoc) { \ return imp_implementationWithBlock(^id(id msg, TYPE_##NAME value) { \ - NIL_CHECK_##NAME(value) SingularSet##NAME(msg, value, offset, hasLoc); \ + NIL_CHECK_##NAME(value); \ + SingularSet##NAME(msg, value, offset, hasLoc); \ return msg; \ }); \ } @@ -520,8 +525,8 @@ static BOOL AddClearMethod(Class cls, SEL sel, CGPFieldDescriptor *field) { #define GET_REPEATED_SETTER_IMP(NAME) \ static IMP GetRepeatedSetterImp##NAME(size_t offset) { \ return imp_implementationWithBlock(^id(id msg, jint idx, TYPE_##NAME value) { \ - NIL_CHECK_##NAME(value) \ - CGPRepeatedFieldSet##NAME(REPEATED_FIELD_PTR(msg, offset), idx, value); \ + NIL_CHECK_##NAME(value); \ + CGPRepeatedFieldSet##NAME(REPEATED_FIELD_PTR(msg, offset), idx, value); \ return msg; \ }); \ } @@ -572,12 +577,13 @@ static BOOL AddBuilderSetterMethod(Class cls, SEL sel, CGPFieldDescriptor *field return class_addMethod(cls, sel, imp, "@@:@"); } -#define GET_ADDER_IMP(NAME) \ - static IMP GetAdderImp##NAME(size_t offset) { \ - return imp_implementationWithBlock(^id(id msg, TYPE_##NAME value) { \ - NIL_CHECK_##NAME(value) CGPRepeatedFieldAdd##NAME(REPEATED_FIELD_PTR(msg, offset), value); \ - return msg; \ - }); \ +#define GET_ADDER_IMP(NAME) \ + static IMP GetAdderImp##NAME(size_t offset) { \ + return imp_implementationWithBlock(^id(id msg, TYPE_##NAME value) { \ + NIL_CHECK_##NAME(value); \ + CGPRepeatedFieldAdd##NAME(REPEATED_FIELD_PTR(msg, offset), value); \ + return msg; \ + }); \ } FOR_EACH_TYPE_WITH_ENUM(GET_ADDER_IMP) @@ -1501,10 +1507,10 @@ static void MergeFieldsFromMessage(id msg, id other, CGPDescriptor *descriptor) } ClearPreviousOneof(msg, hasLoc, fieldPtr); -#define MERGE_FIELD_CASE(NAME) \ - { \ - TYPE_ASSIGN_##NAME(*(TYPE_##NAME *)fieldPtr, *(TYPE_##NAME *)otherFieldPtr); \ - break; \ +#define MERGE_FIELD_CASE(NAME) \ + { \ + TYPE_ASSIGN_##NAME((TYPE_##NAME *)fieldPtr, *(TYPE_##NAME *)otherFieldPtr); \ + break; \ } SWITCH_TYPES_WITH_ENUM(type, MERGE_FIELD_CASE) @@ -3193,13 +3199,13 @@ static void MessageToString(id msg, CGPDescriptor *descriptor, NSMutableString * // ********** isEqual and hash ************************************************* // ***************************************************************************** -#define FieldIsEqualInt(a, b) a == b -#define FieldIsEqualLong(a, b) a == b -#define FieldIsEqualFloat(a, b) a == b -#define FieldIsEqualDouble(a, b) a == b -#define FieldIsEqualBool(a, b) a == b -#define FieldIsEqualEnum(a, b) a == b -#define FieldIsEqualRetainable(a, b) a == b || [a isEqual:b] +CGP_ALWAYS_INLINE BOOL FieldIsEqualInt(jint a, jint b) { return a == b; } +CGP_ALWAYS_INLINE BOOL FieldIsEqualLong(jlong a, jlong b) { return a == b; } +CGP_ALWAYS_INLINE BOOL FieldIsEqualFloat(jfloat a, jfloat b) { return a == b; } +CGP_ALWAYS_INLINE BOOL FieldIsEqualDouble(jdouble a, jdouble b) { return a == b; } +CGP_ALWAYS_INLINE BOOL FieldIsEqualBool(bool a, bool b) { return a == b; } +CGP_ALWAYS_INLINE BOOL FieldIsEqualEnum(id a, id b) { return a == b; } +CGP_ALWAYS_INLINE BOOL FieldIsEqualRetainable(id a, id b) { return a == b || [a isEqual:b]; } static BOOL FieldIsEqual(id self, id other, size_t offset, CGPFieldJavaType type) { #define IS_FIELD_EQUAL_CASE(NAME) \ diff --git a/protobuf/runtime/src/com/google/protobuf/RepeatedField.m b/protobuf/runtime/src/com/google/protobuf/RepeatedField.m index 90a090af6d..3951b872b2 100644 --- a/protobuf/runtime/src/com/google/protobuf/RepeatedField.m +++ b/protobuf/runtime/src/com/google/protobuf/RepeatedField.m @@ -82,8 +82,8 @@ void CGPRepeatedFieldCopyData(CGPRepeatedField *field, CGPFieldJavaType type) { } } -void CGPRepeatedFieldAppendOther( - CGPRepeatedField *field, CGPRepeatedField *other, CGPFieldJavaType type) { +void CGPRepeatedFieldAppendOther(CGPRepeatedField *field, CGPRepeatedField *other, + CGPFieldJavaType type) { uint32_t otherSize = CGPRepeatedFieldSize(other); if (otherSize == 0) { return; @@ -130,7 +130,7 @@ id CGPRepeatedFieldGet(CGPRepeatedField *field, jint index, CGPFieldDescriptor * CGPRepeatedFieldCheckBounds(field, index); #define REPEATED_GET_CASE(NAME) \ - return CGPToReflectionType##NAME(((TYPE_##NAME *)field->data->buffer)[index], descriptor); \ + return CGPToReflectionType##NAME(((TYPE_##NAME *)field->data->buffer)[index], descriptor); SWITCH_TYPES_WITH_ENUM(CGPFieldGetJavaType(descriptor), REPEATED_GET_CASE) @@ -143,9 +143,7 @@ void CGPRepeatedMessageFieldRemove(CGPRepeatedField *field, jint index) { id *msgBuffer = (id *)field->data->buffer; AUTORELEASE(msgBuffer[index]); if (count > (uint32_t)index + 1) { - memmove(&(msgBuffer[index]), - &(msgBuffer[index + 1]), - sizeof(id) * (count - (index + 1))); + memmove(&(msgBuffer[index]), &(msgBuffer[index + 1]), sizeof(id) * (count - (index + 1))); } field->data->size -= 1; } @@ -153,11 +151,11 @@ void CGPRepeatedMessageFieldRemove(CGPRepeatedField *field, jint index) { void CGPRepeatedFieldSet(CGPRepeatedField *field, jint index, id value, CGPFieldJavaType type) { CGPRepeatedFieldCheckBounds(field, index); -#define REPEATED_SET_CASE(NAME) \ - { \ +#define REPEATED_SET_CASE(NAME) \ + { \ TYPE_##NAME *ptr = &((TYPE_##NAME *)field->data->buffer)[index]; \ - TYPE_ASSIGN_##NAME(*ptr, CGPFromReflectionType##NAME(value)); \ - break; \ + TYPE_ASSIGN_##NAME(ptr, CGPFromReflectionType##NAME(value)); \ + break; \ } SWITCH_TYPES_WITH_ENUM(type, REPEATED_SET_CASE) @@ -167,8 +165,8 @@ void CGPRepeatedFieldSet(CGPRepeatedField *field, jint index, id value, CGPField // Make sure to reserve enough space in the buffer BEFORE calling this. static void CGPRepeatedFieldAddUnsafe(CGPRepeatedFieldData *data, id value, CGPFieldJavaType type) { -#define REPEATED_ADD_CASE(NAME) \ - ((TYPE_##NAME *)data->buffer)[data->size++] = \ +#define REPEATED_ADD_CASE(NAME) \ + ((TYPE_##NAME *)data->buffer)[data->size++] = \ TYPE_RETAIN_##NAME(CGPFromReflectionType##NAME(value)); \ break; @@ -185,8 +183,8 @@ void CGPRepeatedFieldAdd(CGPRepeatedField *field, id value, CGPFieldJavaType typ CGPRepeatedFieldAddUnsafe(field->data, value, type); } -void CGPRepeatedFieldAssignFromList( - CGPRepeatedField *field, id list, CGPFieldJavaType type) { +void CGPRepeatedFieldAssignFromList(CGPRepeatedField *field, id list, + CGPFieldJavaType type) { CGPRepeatedFieldClear(field, type); CGPRepeatedFieldReserve(field, [list size], CGPGetTypeSize(type)); @@ -203,10 +201,10 @@ void CGPRepeatedFieldAssignFromList( return newList; } -#define REPEATED_COPY_ELEM_CASE(NAME) \ - for (uint32_t i = 0; i < data->size; i++) { \ +#define REPEATED_COPY_ELEM_CASE(NAME) \ + for (uint32_t i = 0; i < data->size; i++) { \ [newList addWithId:CGPToReflectionType##NAME(((TYPE_##NAME *)data->buffer)[i], descriptor)]; \ - } \ + } \ break; SWITCH_TYPES_WITH_ENUM(CGPFieldGetJavaType(descriptor), REPEATED_COPY_ELEM_CASE) @@ -254,7 +252,7 @@ @interface CGPRepeatedFieldList : JavaUtilAbstractList { @end // We need a subclass for String fields which must implement the ProtocolStringList interface. -@interface CGPRepeatedStringFieldList : CGPRepeatedFieldList < ComGoogleProtobufProtocolStringList > +@interface CGPRepeatedStringFieldList : CGPRepeatedFieldList @end @interface CGPStringAsByteStringList : JavaUtilAbstractList { @@ -265,8 +263,9 @@ @interface CGPStringAsByteStringList : JavaUtilAbstractList { id CGPNewRepeatedFieldList(CGPRepeatedField *field, CGPFieldJavaType type) { CGPRepeatedFieldList *list = - type == ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_STRING ? - [[CGPRepeatedStringFieldList alloc] init] : [[CGPRepeatedFieldList alloc] init]; + type == ComGoogleProtobufDescriptors_FieldDescriptor_JavaType_Enum_STRING + ? [[CGPRepeatedStringFieldList alloc] init] + : [[CGPRepeatedFieldList alloc] init]; CGPRepeatedFieldData *data = field->data; if (data != NULL) { list->field_.data = data; @@ -293,7 +292,7 @@ - (id)getWithInt:(jint)index { CGPRepeatedFieldCheckBounds(&field_, index); #define REPEATED_LIST_GET_CASE(NAME) \ - return CGPBoxedValue##NAME(((TYPE_##NAME *)field_.data->buffer)[index]); \ + return CGPBoxedValue##NAME(((TYPE_##NAME *)field_.data->buffer)[index]); SWITCH_TYPES_NO_ENUM(type_, REPEATED_LIST_GET_CASE)