Browse Source

cppparser: fix issue with templated external method definitions

rdb 9 years ago
parent
commit
d54d43ac34

+ 10 - 1
dtool/src/cppparser/cppBison.cxx.prebuilt

@@ -5426,7 +5426,16 @@ yyreduce:
   case 174:
 #line 1619 "dtool/src/cppparser/cppBison.yxx" /* yacc.c:1646  */
     {
-  push_scope((yyvsp[-1].u.inst_ident)->get_scope(current_scope, global_scope));
+  // Create a scope for this function (in case it is a function)
+  CPPScope *scope = new CPPScope((yyvsp[-1].u.inst_ident)->get_scope(current_scope, global_scope),
+                                 CPPNameComponent(""), V_private);
+
+  // It still needs to be able to pick up any template arguments, if this is
+  // a definition for a method template.  Add a fake "using" declaration to
+  // accomplish this.
+  scope->_using.insert(current_scope);
+
+  push_scope(scope);
 }
 #line 5432 "built/tmp/cppBison.yxx.c" /* yacc.c:1646  */
     break;

+ 10 - 1
dtool/src/cppparser/cppBison.yxx

@@ -1617,7 +1617,16 @@ instance_identifier:
 }
         | instance_identifier '('
 {
-  push_scope($1->get_scope(current_scope, global_scope));
+  // Create a scope for this function (in case it is a function)
+  CPPScope *scope = new CPPScope($1->get_scope(current_scope, global_scope),
+                                 CPPNameComponent(""), V_private);
+
+  // It still needs to be able to pick up any template arguments, if this is
+  // a definition for a method template.  Add a fake "using" declaration to
+  // accomplish this.
+  scope->_using.insert(current_scope);
+
+  push_scope(scope);
 }
         formal_parameter_list ')' function_post
 {

+ 5 - 6
dtool/src/cppparser/cppClassTemplateParameter.cxx

@@ -42,15 +42,14 @@ is_fully_specified() const {
 void CPPClassTemplateParameter::
 output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
   if (complete) {
-    if (_ident != NULL) {
-      out << "class ";
-      _ident->output(out, scope);
-    } else {
-      out << "class";
-    }
+    out << "class";
     if (_packed) {
       out << "...";
     }
+    if (_ident != NULL) {
+      out << " ";
+      _ident->output(out, scope);
+    }
     if (_default_type) {
       out << " = ";
       _default_type->output(out, indent_level, scope, false);

+ 3 - 2
dtool/src/cppparser/cppScope.h

@@ -139,11 +139,12 @@ public:
   Templates _templates;
   CPPNameComponent _name;
 
+  typedef set<CPPScope *> Using;
+  Using _using;
+
 protected:
   CPPScope *_parent_scope;
   CPPStructType *_struct_type;
-  typedef set<CPPScope *> Using;
-  Using _using;
   CPPVisibility _current_vis;
 
 private: