mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
Fixed namespace code generation for C++
The code generator was assuming all declarations for the current file sit in the same namepace. Now uses the "on demand" namespace switching we had for the forward declarations. Also fixed a bug related to namespace lookup. Change-Id: Ib54a3efbc752cbb9590302fa0707c0c73448db3d Tested: on Linux.
This commit is contained in:
@@ -981,15 +981,26 @@ CheckedError Parser::ParseSingleValue(Value &e) {
|
||||
StructDef *Parser::LookupCreateStruct(const std::string &name,
|
||||
bool create_if_new, bool definition) {
|
||||
std::string qualified_name = namespaces_.back()->GetFullyQualifiedName(name);
|
||||
// See if it exists pre-declared by an unqualified use.
|
||||
auto struct_def = structs_.Lookup(name);
|
||||
if (struct_def && struct_def->predecl) {
|
||||
if (definition) {
|
||||
// Make sure it has the current namespace, and is registered under its
|
||||
// qualified name.
|
||||
struct_def->defined_namespace = namespaces_.back();
|
||||
structs_.Move(name, qualified_name);
|
||||
}
|
||||
return struct_def;
|
||||
}
|
||||
// See if it exists pre-declared by an qualified use.
|
||||
struct_def = structs_.Lookup(qualified_name);
|
||||
if (struct_def && struct_def->predecl) {
|
||||
if (definition) {
|
||||
// Make sure it has the current namespace.
|
||||
struct_def->defined_namespace = namespaces_.back();
|
||||
}
|
||||
return struct_def;
|
||||
}
|
||||
if (!definition) {
|
||||
// Search thru parent namespaces.
|
||||
for (size_t components = namespaces_.back()->components.size();
|
||||
|
||||
Reference in New Issue
Block a user