瀏覽代碼

cppparser: fix issues when parsing templated constructor definition

rdb 7 年之前
父節點
當前提交
30721ba33b
共有 3 個文件被更改,包括 253 次插入229 次删除
  1. 224 222
      dtool/src/cppparser/cppBison.cxx.prebuilt
  2. 2 2
      dtool/src/cppparser/cppBison.h.prebuilt
  3. 27 5
      dtool/src/cppparser/cppBison.yxx

文件差異過大導致無法顯示
+ 224 - 222
dtool/src/cppparser/cppBison.cxx.prebuilt


+ 2 - 2
dtool/src/cppparser/cppBison.h.prebuilt

@@ -1,8 +1,8 @@
-/* A Bison parser, made by GNU Bison 3.0.4.  */
+/* A Bison parser, made by GNU Bison 3.0.5.  */
 
 /* Bison interface for Yacc-like parsers in C
 
-   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
+   Copyright (C) 1984, 1989-1990, 2000-2015, 2018 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

+ 27 - 5
dtool/src/cppparser/cppBison.yxx

@@ -1185,14 +1185,27 @@ constructor_prototype:
 /* Functions with implicit return types, and constructors */
         IDENTIFIER '('
 {
-  push_scope($1->get_scope(current_scope, global_scope));
+  // Create a scope for this function.
+  CPPScope *scope = new CPPScope($1->get_scope(current_scope, global_scope),
+                                 $1->_names.back(), 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);
 }
         function_parameter_list ')' function_post
 {
+  CPPScope *scope = $1->get_scope(current_scope, global_scope);
   CPPType *type;
-  if ($1->get_simple_name() == current_scope->get_simple_name() ||
-      $1->get_simple_name() == string("~") + current_scope->get_simple_name()) {
-    // This is a constructor, and has no return.
+  std::string simple_name = $1->get_simple_name();
+  if (!simple_name.empty() && simple_name[0] == '~') {
+    // A destructor has no return type.
+    type = new CPPSimpleType(CPPSimpleType::T_void);
+  } else if (scope != nullptr && simple_name == scope->get_simple_name()) {
+    // Neither does a constructor.
     type = new CPPSimpleType(CPPSimpleType::T_void);
   } else {
     // This isn't a constructor, so it has an implicit return type of
@@ -1209,7 +1222,16 @@ constructor_prototype:
 }
         | TYPENAME_IDENTIFIER '('
 {
-  push_scope($1->get_scope(current_scope, global_scope));
+  // Create a scope for this function.
+  CPPScope *scope = new CPPScope($1->get_scope(current_scope, global_scope),
+                                 $1->_names.back(), 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);
 }
         function_parameter_list ')' function_post
 {

部分文件因文件數量過多而無法顯示