summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndreas Fried <andreas.fried@kit.edu>2019-07-29 22:23:46 +0200
committerAndreas Fried <andreas.fried@kit.edu>2019-07-29 22:33:48 +0200
commitadfc5720ffff0a4925cd854cfe42dbe970728c3f (patch)
tree4479deca0c59c7419718c7cb7df8c8368d59f40d
parent53bdf665a81f275bae9df686bfe70fd046df2866 (diff)
Make find_compound_entry global.
-rw-r--r--src/ast/entity.c24
-rw-r--r--src/ast/entity_t.h2
2 files changed, 26 insertions, 0 deletions
diff --git a/src/ast/entity.c b/src/ast/entity.c
index 16dd112..52519d6 100644
--- a/src/ast/entity.c
+++ b/src/ast/entity.c
@@ -10,6 +10,7 @@
#include "adt/strutil.h"
#include "adt/util.h"
#include "ast_t.h"
+#include "type_t.h"
const char *get_entity_kind_name(entity_kind_t kind)
{
@@ -116,3 +117,26 @@ unsigned get_declaration_alignment(const declaration_t *declaration)
return get_type_alignment_compound(type);
return get_ctype_alignment(type);
}
+
+entity_t *find_compound_entry(compound_t *compound, symbol_t *symbol)
+{
+ for (entity_t *iter = compound->members.first_entity; iter != NULL;
+ iter = iter->base.next) {
+ if (iter->kind != ENTITY_COMPOUND_MEMBER)
+ continue;
+
+ if (iter->base.symbol == symbol) {
+ return iter;
+ } else if (iter->base.symbol == NULL) {
+ /* search in anonymous structs and unions */
+ type_t *type = skip_typeref(iter->declaration.type);
+ if (is_type_compound(type)
+ && find_compound_entry(type->compound.compound, symbol) != NULL)
+ return iter;
+
+ continue;
+ }
+ }
+
+ return NULL;
+}
diff --git a/src/ast/entity_t.h b/src/ast/entity_t.h
index 1f259b6..8d4002c 100644
--- a/src/ast/entity_t.h
+++ b/src/ast/entity_t.h
@@ -298,4 +298,6 @@ elf_visibility_t get_elf_visibility_from_string(const char *string);
entity_t *skip_unnamed_bitfields(entity_t*);
+entity_t *find_compound_entry(compound_t *compound, symbol_t *symbol);
+
#endif