Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #352 from kastiglione/indexstore-flag_enum2
Browse files Browse the repository at this point in the history
Mark indexstore enum flag types with flag_enum attribute
  • Loading branch information
benlangmuir authored Oct 9, 2019
2 parents 9ebee0a + f17afab commit 89e5753
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
4 changes: 2 additions & 2 deletions include/clang/Index/IndexDataStoreSymbolUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ indexstore_symbol_subkind_t getIndexStoreSubKind(SymbolSubKind K);
indexstore_symbol_language_t getIndexStoreLang(SymbolLanguage L);

/// Map a SymbolPropertySet to its indexstore representation.
uint64_t getIndexStoreProperties(SymbolPropertySet Props);
indexstore_symbol_property_t getIndexStoreProperties(SymbolPropertySet Props);

/// Map a SymbolRoleSet to its indexstore representation.
uint64_t getIndexStoreRoles(SymbolRoleSet Roles);
indexstore_symbol_role_t getIndexStoreRoles(SymbolRoleSet Roles);

} // end namespace index
} // end namespace clang
Expand Down
38 changes: 29 additions & 9 deletions include/indexstore/indexstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@
# define INDEXSTORE_NOESCAPE
#endif

#if __has_attribute(flag_enum)
# define INDEXSTORE_FLAG_ENUM_ATTR __attribute__((flag_enum))
#else
# define INDEXSTORE_FLAG_ENUM_ATTR
#endif

#if __has_attribute(enum_extensibility)
# define INDEXSTORE_OPEN_ENUM_ATTR __attribute__((enum_extensibility(open)))
#else
# define INDEXSTORE_OPEN_ENUM_ATTR
#endif

#define INDEXSTORE_OPTIONS_ATTRS INDEXSTORE_OPEN_ENUM_ATTR INDEXSTORE_FLAG_ENUM_ATTR

#if __has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum)
# define INDEXSTORE_OPTIONS(_type, _name) enum INDEXSTORE_OPTIONS_ATTRS _name : _type _name; enum INDEXSTORE_OPTIONS_ATTRS _name : _type
#else
# define INDEXSTORE_OPTIONS(_type, _name) _type _name; enum INDEXSTORE_OPTIONS_ATTRS
#endif

INDEXSTORE_BEGIN_DECLS

typedef void *indexstore_error_t;
Expand Down Expand Up @@ -266,7 +286,7 @@ typedef enum {
INDEXSTORE_SYMBOL_SUBKIND_SWIFTACCESSORMODIFY = 1015,
} indexstore_symbol_subkind_t;

typedef enum {
typedef INDEXSTORE_OPTIONS(uint64_t, indexstore_symbol_property_t) {
INDEXSTORE_SYMBOL_PROPERTY_GENERIC = 1 << 0,
INDEXSTORE_SYMBOL_PROPERTY_TEMPLATE_PARTIAL_SPECIALIZATION = 1 << 1,
INDEXSTORE_SYMBOL_PROPERTY_TEMPLATE_SPECIALIZATION = 1 << 2,
Expand All @@ -276,7 +296,7 @@ typedef enum {
INDEXSTORE_SYMBOL_PROPERTY_GKINSPECTABLE = 1 << 6,
INDEXSTORE_SYMBOL_PROPERTY_LOCAL = 1 << 7,
INDEXSTORE_SYMBOL_PROPERTY_PROTOCOL_INTERFACE = 1 << 8,
} indexstore_symbol_property_t;
};

typedef enum {
INDEXSTORE_SYMBOL_LANG_C = 0,
Expand All @@ -286,7 +306,7 @@ typedef enum {
INDEXSTORE_SYMBOL_LANG_SWIFT = 100,
} indexstore_symbol_language_t;

typedef enum {
typedef INDEXSTORE_OPTIONS(uint64_t, indexstore_symbol_role_t) {
INDEXSTORE_SYMBOL_ROLE_DECLARATION = 1 << 0,
INDEXSTORE_SYMBOL_ROLE_DEFINITION = 1 << 1,
INDEXSTORE_SYMBOL_ROLE_REFERENCE = 1 << 2,
Expand All @@ -310,7 +330,7 @@ typedef enum {
INDEXSTORE_SYMBOL_ROLE_REL_CONTAINEDBY = 1 << 16,
INDEXSTORE_SYMBOL_ROLE_REL_IBTYPEOF = 1 << 17,
INDEXSTORE_SYMBOL_ROLE_REL_SPECIALIZATIONOF = 1 << 18,
} indexstore_symbol_role_t;
};

INDEXSTORE_PUBLIC indexstore_symbol_language_t
indexstore_symbol_get_language(indexstore_symbol_t);
Expand All @@ -321,13 +341,13 @@ indexstore_symbol_get_kind(indexstore_symbol_t);
INDEXSTORE_PUBLIC indexstore_symbol_subkind_t
indexstore_symbol_get_subkind(indexstore_symbol_t);

INDEXSTORE_PUBLIC uint64_t
INDEXSTORE_PUBLIC indexstore_symbol_property_t
indexstore_symbol_get_properties(indexstore_symbol_t);

INDEXSTORE_PUBLIC uint64_t
INDEXSTORE_PUBLIC indexstore_symbol_role_t
indexstore_symbol_get_roles(indexstore_symbol_t);

INDEXSTORE_PUBLIC uint64_t
INDEXSTORE_PUBLIC indexstore_symbol_role_t
indexstore_symbol_get_related_roles(indexstore_symbol_t);

INDEXSTORE_PUBLIC indexstore_string_ref_t
Expand All @@ -341,7 +361,7 @@ indexstore_symbol_get_codegen_name(indexstore_symbol_t);

typedef void *indexstore_symbol_relation_t;

INDEXSTORE_PUBLIC uint64_t
INDEXSTORE_PUBLIC indexstore_symbol_role_t
indexstore_symbol_relation_get_roles(indexstore_symbol_relation_t);

INDEXSTORE_PUBLIC indexstore_symbol_t
Expand All @@ -363,7 +383,7 @@ indexstore_occurrence_relations_apply_f(indexstore_occurrence_t,
void *context,
INDEXSTORE_NOESCAPE bool(*applier)(void *context, indexstore_symbol_relation_t symbol_rel));

INDEXSTORE_PUBLIC uint64_t
INDEXSTORE_PUBLIC indexstore_symbol_role_t
indexstore_occurrence_get_roles(indexstore_occurrence_t);

INDEXSTORE_PUBLIC void
Expand Down
8 changes: 4 additions & 4 deletions lib/Index/IndexDataStoreUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ indexstore_symbol_language_t index::getIndexStoreLang(SymbolLanguage L) {
}

/// Map a SymbolPropertySet to its indexstore representation.
uint64_t index::getIndexStoreProperties(SymbolPropertySet Props) {
indexstore_symbol_property_t index::getIndexStoreProperties(SymbolPropertySet Props) {
uint64_t storeProp = 0;
applyForEachSymbolProperty(Props, [&](SymbolProperty prop) {
switch (prop) {
Expand Down Expand Up @@ -445,11 +445,11 @@ uint64_t index::getIndexStoreProperties(SymbolPropertySet Props) {
break;
}
});
return storeProp;
return static_cast<indexstore_symbol_property_t>(storeProp);
}

/// Map a SymbolRoleSet to its indexstore representation.
uint64_t index::getIndexStoreRoles(SymbolRoleSet Roles) {
indexstore_symbol_role_t index::getIndexStoreRoles(SymbolRoleSet Roles) {
uint64_t storeRoles = 0;
applyForEachSymbolRole(Roles, [&](SymbolRole role) {
switch (role) {
Expand Down Expand Up @@ -518,5 +518,5 @@ uint64_t index::getIndexStoreRoles(SymbolRoleSet Roles) {
break;
}
});
return storeRoles;
return static_cast<indexstore_symbol_role_t>(storeRoles);
}
10 changes: 5 additions & 5 deletions tools/IndexStore/IndexStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,17 @@ indexstore_symbol_get_language(indexstore_symbol_t sym) {
return getIndexStoreLang(static_cast<IndexRecordDecl *>(sym)->SymInfo.Lang);
}

uint64_t
indexstore_symbol_property_t
indexstore_symbol_get_properties(indexstore_symbol_t sym) {
return getIndexStoreProperties(static_cast<IndexRecordDecl *>(sym)->SymInfo.Properties);
}

uint64_t
indexstore_symbol_role_t
indexstore_symbol_get_roles(indexstore_symbol_t sym) {
return getIndexStoreRoles(static_cast<IndexRecordDecl *>(sym)->Roles);
}

uint64_t
indexstore_symbol_role_t
indexstore_symbol_get_related_roles(indexstore_symbol_t sym) {
return getIndexStoreRoles(static_cast<IndexRecordDecl *>(sym)->RelatedRoles);
}
Expand All @@ -354,7 +354,7 @@ indexstore_symbol_get_codegen_name(indexstore_symbol_t sym) {
return toIndexStoreString(D->CodeGenName);
}

uint64_t
indexstore_symbol_role_t
indexstore_symbol_relation_get_roles(indexstore_symbol_relation_t sym_rel) {
return getIndexStoreRoles(static_cast<IndexRecordRelation *>(sym_rel)->Roles);
}
Expand Down Expand Up @@ -394,7 +394,7 @@ indexstore_occurrence_relations_apply_f(indexstore_occurrence_t occur,
return true;
}

uint64_t
indexstore_symbol_role_t
indexstore_occurrence_get_roles(indexstore_occurrence_t occur) {
return getIndexStoreRoles(static_cast<IndexRecordOccurrence*>(occur)->Roles);
}
Expand Down

0 comments on commit 89e5753

Please sign in to comment.