From 5582e174b6b37b66393e0480f0e7c56fc9c2d072 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 4 Jun 2018 17:30:02 +0200 Subject: [PATCH] cppparser: fix issue with typedefs to forward declared templates I don't know if this is the right solution, but it does fix an issue accessing std::ios::openmode caused by the ios typedef being defined before ios_base is fully specified. --- dtool/src/cppparser/cppIdentifier.cxx | 4 ++-- dtool/src/cppparser/cppScope.cxx | 20 ++++++++++++++------ dtool/src/cppparser/cppScope.h | 3 ++- dtool/src/interrogate/interrogateBuilder.cxx | 4 ++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/dtool/src/cppparser/cppIdentifier.cxx b/dtool/src/cppparser/cppIdentifier.cxx index 8ffb6cefd8..9fd7b500c8 100644 --- a/dtool/src/cppparser/cppIdentifier.cxx +++ b/dtool/src/cppparser/cppIdentifier.cxx @@ -252,7 +252,7 @@ get_scope(CPPScope *current_scope, CPPScope *global_scope, } while (i + 1 < (int)_names.size() && scope != nullptr) { - CPPScope *next_scope = scope->find_scope(_names[i].get_name()); + CPPScope *next_scope = scope->find_scope(_names[i].get_name(), global_scope); if (next_scope == nullptr) { if (error_sink != nullptr) { error_sink->error("Symbol " + _names[i].get_name() + @@ -511,7 +511,7 @@ find_scope(CPPScope *current_scope, CPPScope *global_scope, if (scope == nullptr) { return nullptr; } - return scope->find_scope(get_simple_name()); + return scope->find_scope(get_simple_name(), global_scope); } diff --git a/dtool/src/cppparser/cppScope.cxx b/dtool/src/cppparser/cppScope.cxx index 34f2d47c7f..878daa8812 100644 --- a/dtool/src/cppparser/cppScope.cxx +++ b/dtool/src/cppparser/cppScope.cxx @@ -605,7 +605,7 @@ find_type(const string &name, CPPDeclaration::SubstDecl &subst, * */ CPPScope *CPPScope:: -find_scope(const string &name, bool recurse) const { +find_scope(const string &name, CPPScope *global_scope, bool recurse) const { Namespaces::const_iterator ni = _namespaces.find(name); if (ni != _namespaces.end()) { return (*ni).second->get_scope(); @@ -617,13 +617,21 @@ find_scope(const string &name, bool recurse) const { ti = _types.find(name); if (ti != _types.end()) { type = (*ti).second; - // Resolve if this is a typedef or const. + // Resolve if this is a typedef or const, or a TBD type. while (type->get_subtype() == CPPDeclaration::ST_const || - type->get_subtype() == CPPDeclaration::ST_typedef) { + type->get_subtype() == CPPDeclaration::ST_typedef || + type->get_subtype() == CPPDeclaration::ST_tbd) { if (type->as_typedef_type() != nullptr) { type = type->as_typedef_type()->_type; - } else { + } else if (type->as_const_type() != nullptr) { type = type->as_const_type()->_wrapped_around; + } else { + CPPType *new_type = type->resolve_type((CPPScope *)this, global_scope); + if (new_type != type) { + type = new_type; + } else { + break; + } } } @@ -653,14 +661,14 @@ find_scope(const string &name, bool recurse) const { Using::const_iterator ui; for (ui = _using.begin(); ui != _using.end(); ++ui) { - CPPScope *scope = (*ui)->find_scope(name, false); + CPPScope *scope = (*ui)->find_scope(name, global_scope, false); if (scope != nullptr) { return scope; } } if (recurse && _parent_scope != nullptr) { - return _parent_scope->find_scope(name); + return _parent_scope->find_scope(name, global_scope); } return nullptr; diff --git a/dtool/src/cppparser/cppScope.h b/dtool/src/cppparser/cppScope.h index 76539bff3b..d7df06b481 100644 --- a/dtool/src/cppparser/cppScope.h +++ b/dtool/src/cppparser/cppScope.h @@ -87,7 +87,8 @@ public: CPPDeclaration::SubstDecl &subst, CPPScope *global_scope, bool recurse = true) const; - CPPScope *find_scope(const string &name, bool recurse = true) const; + CPPScope *find_scope(const string &name, CPPScope *global_scope, + bool recurse = true) const; CPPScope *find_scope(const string &name, CPPDeclaration::SubstDecl &subst, CPPScope *global_scope, diff --git a/dtool/src/interrogate/interrogateBuilder.cxx b/dtool/src/interrogate/interrogateBuilder.cxx index 1e3fdacaa7..f320a66943 100644 --- a/dtool/src/interrogate/interrogateBuilder.cxx +++ b/dtool/src/interrogate/interrogateBuilder.cxx @@ -2267,6 +2267,10 @@ get_type(CPPType *type, bool global) { return 0; } + if (type->get_subtype() == CPPType::ST_tbd) { + type = type->resolve_type(&parser, &parser); + } + TypeIndex index = 0; // First, check to see if it's already there.