Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ 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;
Expand Down
161 changes: 80 additions & 81 deletions protobuf/runtime/src/com/google/protobuf/FieldTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,15 @@
#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 TYPE_RETAIN_Retainable(value) RETAIN_(value)

#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)
#define TYPE_ASSIGN_Retainable(assignee, value) (AUTORELEASE(assignee), assignee = RETAIN_(value))

#define HASH_Int(value) value
#define HASH_Long(value) (int)((uint64_t)value ^ ((uint64_t)value >> 32))
Expand Down Expand Up @@ -117,79 +108,77 @@

// 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
Expand Down Expand Up @@ -218,15 +207,17 @@ 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 <NSCopying>

#pragma mark Public

- (ComGoogleProtobufDescriptors_FieldDescriptor_JavaType *)getJavaType;

- (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

Expand All @@ -241,7 +232,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);
Expand Down Expand Up @@ -315,13 +307,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)

Expand All @@ -337,7 +333,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 <NSCopying>

#pragma mark Package-Private

Expand All @@ -352,7 +348,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);
Expand Down Expand Up @@ -393,10 +390,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__
24 changes: 13 additions & 11 deletions protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -508,7 +508,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; \
}); \
}
Expand All @@ -520,8 +521,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; \
}); \
}
Expand Down Expand Up @@ -572,12 +573,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)
Expand Down
Loading