hokein created this revision.
hokein added reviewers: sammccall, usaxena95.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: clang-tools-extra.

See https://reviews.llvm.org/D130626 for details;

A prototype to eliminate "local" identifier ambiguties in the grammar:

- use a unified type-name instead, and remove all different type rules ( 
class-name/enum-name/typedef-name), this eliminates the top#1 type-name 
ambiguity;
- use a generic identifier for nested-name-specifier, and don't distinguish 
with the type-name and namespace-name cases;
- remove template-name rule, it is mainly used for the template argument 
deduction in simple-type-specifier, it has the same syntax with type-name, 
merged with type-name case;

After this patch, remaining ambiguities are real ambiguities in C++:
Some numbers with this patch:

| file                 | ambiguous nodes | forest size      | glrParse 
performance |
| SemaCodeComplete.cpp | 1.1w -> 2k      | 10.4MB -> 7.12MB | 7.1MB/s -> 11MB/s 
   |
| AST.cpp              | 1.3k -> 286     | 0.99MB -> 0.68MB | 6.7MB/s -> 
9.9MB/s   |


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130747

Files:
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf

Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===================================================================
--- clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -34,15 +34,15 @@
 _ := declaration-seq
 
 # gram.key
-typedef-name := IDENTIFIER
-typedef-name := simple-template-id
+#typedef-name := IDENTIFIER
+#typedef-name := simple-template-id
 namespace-name := IDENTIFIER
-namespace-name := namespace-alias
-namespace-alias := IDENTIFIER
-class-name := IDENTIFIER
-class-name := simple-template-id
-enum-name := IDENTIFIER
-template-name := IDENTIFIER
+#namespace-name := namespace-alias
+#namespace-alias := IDENTIFIER
+#class-name := IDENTIFIER
+#class-name := simple-template-id
+#enum-name := IDENTIFIER
+#template-name := IDENTIFIER
 
 # gram.basic
 #! Custom modifications to eliminate optional declaration-seq
@@ -69,8 +69,10 @@
 unqualified-id := template-id
 qualified-id := nested-name-specifier TEMPLATE_opt unqualified-id
 nested-name-specifier := :: [guard]
-nested-name-specifier := type-name ::
-nested-name-specifier := namespace-name ::
+#nested-name-specifier := type-name ::
+#nested-name-specifier := namespace-name ::
+nested-name-specifier := IDENTIFIER ::
+nested-name-specifier := simple-template-id ::
 nested-name-specifier := decltype-specifier ::
 nested-name-specifier := nested-name-specifier IDENTIFIER ::
 nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id ::
@@ -374,7 +376,7 @@
 simple-type-specifier := nested-name-specifier TEMPLATE simple-template-id
 simple-type-specifier := decltype-specifier
 simple-type-specifier := placeholder-type-specifier
-simple-type-specifier := nested-name-specifier_opt template-name
+#simple-type-specifier := nested-name-specifier_opt template-name
 simple-type-specifier := builtin-type
 builtin-type := CHAR
 builtin-type := CHAR8_T
@@ -390,9 +392,12 @@
 builtin-type := FLOAT
 builtin-type := DOUBLE
 builtin-type := VOID
-type-name := class-name
-type-name := enum-name
-type-name := typedef-name
+#type-name := class-name
+#type-name := enum-name
+#type-name := typedef-name
+type-name := IDENTIFIER
+type-name := simple-template-id
+
 elaborated-type-specifier := class-key nested-name-specifier_opt IDENTIFIER
 elaborated-type-specifier := class-key simple-template-id
 elaborated-type-specifier := class-key nested-name-specifier TEMPLATE_opt simple-template-id
@@ -550,7 +555,8 @@
 class-specifier := class-head { member-specification_opt [recover=Brackets] }
 class-head := class-key class-head-name class-virt-specifier_opt base-clause_opt
 class-head := class-key base-clause_opt
-class-head-name := nested-name-specifier_opt class-name
+class-head-name := nested-name-specifier_opt IDENTIFIER
+class-head-name := nested-name-specifier_opt simple-template-id
 class-virt-specifier := contextual-final
 class-key := CLASS
 class-key := STRUCT
@@ -674,7 +680,7 @@
 type-parameter-key := TYPENAME
 type-constraint := nested-name-specifier_opt concept-name
 type-constraint := nested-name-specifier_opt concept-name < template-argument-list_opt >
-simple-template-id := template-name < template-argument-list_opt >
+simple-template-id := IDENTIFIER < template-argument-list_opt >
 template-id := simple-template-id
 template-id := operator-function-id < template-argument-list_opt >
 template-id := literal-operator-id < template-argument-list_opt >
@@ -684,7 +690,7 @@
 template-argument := type-id
 template-argument := id-expression
 constraint-expression := logical-or-expression
-deduction-guide := explicit-specifier_opt template-name ( parameter-declaration-list_opt ) -> simple-template-id ;
+deduction-guide := explicit-specifier_opt IDENTIFIER ( parameter-declaration-list_opt ) -> simple-template-id ;
 concept-definition := CONCEPT concept-name = constraint-expression ;
 concept-name := IDENTIFIER
 typename-specifier := TYPENAME nested-name-specifier IDENTIFIER
Index: clang-tools-extra/pseudo/lib/cxx/CXX.cpp
===================================================================
--- clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -235,10 +235,8 @@
 
       // simple-type-specifier
       case rule::simple_type_specifier::type_name:
-      case rule::simple_type_specifier::template_name:
       case rule::simple_type_specifier::builtin_type:
       case rule::simple_type_specifier::nested_name_specifier__TEMPLATE__simple_template_id:
-      case rule::simple_type_specifier::nested_name_specifier__template_name:
       case rule::simple_type_specifier::nested_name_specifier__type_name:
       case rule::simple_type_specifier::decltype_specifier:
       case rule::simple_type_specifier::placeholder_type_specifier:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to