Referring to types from other namespaces in C++ now works correctly.

Previously, it would ignore the fact that the type comes from a
different namespace. Now they are pre-declared in their own namespace,
and referenced with a qualified name if necessary.

Bug: 16851682
Change-Id: I5cb625b86d28e7436b9e93c70a0fa16a600d9884
Tested: on Linux
This commit is contained in:
Wouter van Oortmerssen
2014-08-19 16:37:46 -07:00
parent be894f09df
commit c2ba7fd251
7 changed files with 158 additions and 77 deletions

View File

@@ -647,6 +647,7 @@ StructDef *Parser::LookupCreateStruct(const std::string &name) {
structs_.Add(name, struct_def);
struct_def->name = name;
struct_def->predecl = true;
struct_def->defined_namespace = namespaces_.back();
}
return struct_def;
}
@@ -838,9 +839,10 @@ bool Parser::Parse(const char *source, const char *filepath) {
while (token_ != kTokenEof) {
if (token_ == kTokenNameSpace) {
Next();
name_space_.clear();
auto ns = new Namespace();
namespaces_.push_back(ns);
for (;;) {
name_space_.push_back(attribute_);
ns->components.push_back(attribute_);
Expect(kTokenIdentifier);
if (!IsNext('.')) break;
}