+ /* we should optimize here, if scope grows above a certain size we should
+ construct a hashmap here... */
+ entity_t *entity = scope->entities;
+ for ( ; entity != NULL; entity = entity->base.next) {
+ if (entity->base.symbol == symbol && entity->base.namespc == namespc)
+ break;
+ }
+
+ return entity;
+}
+
+static entity_t *parse_qualified_identifier(void)
+{
+ /* namespace containing the symbol */
+ symbol_t *symbol;
+ source_position_t pos;
+ const scope_t *lookup_scope = NULL;
+
+ if (next_if(T_COLONCOLON))
+ lookup_scope = &unit->scope;
+
+ entity_t *entity;
+ while (true) {
+ if (token.type != T_IDENTIFIER) {
+ parse_error_expected("while parsing identifier", T_IDENTIFIER, NULL);
+ return create_error_entity(sym_anonymous, ENTITY_VARIABLE);
+ }
+ symbol = token.v.symbol;
+ pos = *HERE;
+ next_token();
+
+ /* lookup entity */
+ entity = lookup_entity(lookup_scope, symbol, NAMESPACE_NORMAL);
+
+ if (!next_if(T_COLONCOLON))
+ break;
+
+ switch (entity->kind) {
+ case ENTITY_NAMESPACE:
+ lookup_scope = &entity->namespacee.members;
+ break;
+ case ENTITY_STRUCT:
+ case ENTITY_UNION:
+ case ENTITY_CLASS:
+ lookup_scope = &entity->compound.members;
+ break;
+ default:
+ errorf(&pos, "'%Y' must be a namespace, class, struct or union (but is a %s)",
+ symbol, get_entity_kind_name(entity->kind));
+ goto end_error;
+ }
+ }