diff options
Diffstat (limited to 'compiler/ex-gather-symbols.c')
-rw-r--r-- | compiler/ex-gather-symbols.c | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/compiler/ex-gather-symbols.c b/compiler/ex-gather-symbols.c new file mode 100644 index 0000000..dc326f2 --- /dev/null +++ b/compiler/ex-gather-symbols.c @@ -0,0 +1,189 @@ +#include "ex-compiler.h" + +static void gather_symbols_uses_clause (ExUsesClause *clause); +static void gather_symbols_definition (ExDefinition *definition); +static void gather_symbols_namespace (ExNamespace *namespace); +static void gather_symbols_extension (ExExtension *extension); +static void gather_symbols_request (ExRequest *request); +static void gather_symbols_event (ExEvent *event); +static void gather_symbols_type_def (ExTypeDef *type_def); +static void gather_symbols_identifier (ExIdentifier *identifier); +static void gather_symbols_type (ExType *type); +static void gather_symbols_field (ExField *field); +static void gather_symbols_error (ExError *error); + +void +ex_gather_symbols (ExSpec *spec) +{ + if (!spec) + return; + + gather_symbols_uses_clause (spec->uses_clauses); + gather_symbols_definition (spec->definitions); +} + +static void +gather_symbols_uses_clause (ExUsesClause *clause) +{ + if (!clause) + return; + + gather_symbols_uses_clause (clause->next); +} + +static void +gather_symbols_definition (ExDefinition *definition) +{ + if (!definition) + return; + + switch (definition->type) + { + case EX_DEFINITION_NAMESPACE: + gather_symbols_namespace (definition->u.namespace); + break; + + case EX_DEFINITION_EXTENSION: + gather_symbols_extension (definition->u.extension); + break; + + case EX_DEFINITION_REQUEST: + gather_symbols_request (definition->u.request); + break; + + case EX_DEFINITION_TYPE_DEF: + gather_symbols_type_def (definition->u.type_def); + break; + + case EX_DEFINITION_ERROR: + gather_symbols_error (definition->u.error); + break; + + case EX_DEFINITION_EVENT: + gather_symbols_event (definition->u.event); + break; + } + + gather_symbols_definition (definition->next); +} + +static void +gather_symbols_namespace (ExNamespace *namespace) +{ + if (!namespace) + return; + + gather_symbols_definition (namespace->definitions); +} + +static void +gather_symbols_extension (ExExtension *extension) +{ + if (!extension) + return; + + gather_symbols_definition (extension->definitions); +} + +static void +gather_symbols_request (ExRequest *request) +{ + if (!request) + return; + + gather_symbols_field (request->parameters); + gather_symbols_field (request->reply); + gather_symbols_identifier (request->errors); +} + +static void +gather_symbols_type_def (ExTypeDef *type_def) +{ + if (!type_def) + return; + + gather_symbols_type (type_def->type); +} + +static void +gather_symbols_error (ExError *error) +{ + if (!error) + return; +} + +static void +gather_symbols_event (ExEvent *event) +{ + if (!event) + return; + + gather_symbols_field (event->fields); +} + +static void +gather_symbols_identifier (ExIdentifier *identifier) +{ + if (!identifier) + return; + + gather_symbols_identifier (identifier->next); +} + +static void +gather_symbols_type (ExType *type) +{ + if (!type) + return; + + switch (type->type) + { + case EX_TYPE_UNION: + gather_symbols_field (type->u._struct.fields); + break; + + case EX_TYPE_LIST: + gather_symbols_type (type->u._list.type); + break; + + case EX_TYPE_ENUM: + gather_symbols_identifier (type->u._enum.identifiers); + break; + + case EX_TYPE_STRUCT: + gather_symbols_field (type->u._struct.fields); + break; + + case EX_TYPE_BITS: + gather_symbols_identifier (type->u.bits.fields); + break; + + case EX_TYPE_MASKED_LIST: + gather_symbols_field (type->u.masked_list.fields); + break; + + case EX_TYPE_CARD8: + case EX_TYPE_CARD16: + case EX_TYPE_CARD32: + case EX_TYPE_CARD64: + case EX_TYPE_INT8: + case EX_TYPE_INT16: + case EX_TYPE_INT32: + case EX_TYPE_INT64: + case EX_TYPE_BOOLEAN: + case EX_TYPE_IDENTIFIER: + case EX_TYPE_XID: + case EX_TYPE_DERIVED_BITS: + break; + } +} + +static void +gather_symbols_field (ExField *field) +{ + if (!field) + return; + + gather_symbols_type (field->type); + gather_symbols_field (field->next); +} |