diff --git a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf --- a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf +++ b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf @@ -34,14 +34,9 @@ _ := declaration-seq # gram.key -typedef-name := IDENTIFIER -typedef-name := simple-template-id +#! we don't distinguish between namespaces and namespace aliases, as it's hard +#! and uninteresting. namespace-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 @@ -391,9 +386,12 @@ builtin-type := FLOAT builtin-type := DOUBLE builtin-type := VOID -type-name := class-name -type-name := enum-name -type-name := typedef-name +#! Unlike C++ standard grammar, we don't distinguish the underlying type (class, +#! enum, typedef) of the IDENTIFIER, as these ambiguities are "local" and don't +#! affect the final parse tree. Eliminating them gives a significant performance +#! boost to the parser. +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 @@ -551,7 +549,7 @@ 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 type-name class-virt-specifier := contextual-final class-key := CLASS class-key := STRUCT diff --git a/clang-tools-extra/pseudo/test/glr.cpp b/clang-tools-extra/pseudo/test/glr.cpp --- a/clang-tools-extra/pseudo/test/glr.cpp +++ b/clang-tools-extra/pseudo/test/glr.cpp @@ -12,10 +12,7 @@ // CHECK-NEXT: │ └─; := tok[8] // CHECK-NEXT: └─statement~simple-declaration := decl-specifier-seq init-declarator-list ; // CHECK-NEXT: ├─decl-specifier-seq~simple-type-specifier := -// CHECK-NEXT: │ ├─simple-type-specifier~type-name := -// CHECK-NEXT: │ │ ├─type-name~IDENTIFIER := tok[5] -// CHECK-NEXT: │ │ ├─type-name~IDENTIFIER := tok[5] -// CHECK-NEXT: │ │ └─type-name~IDENTIFIER := tok[5] +// CHECK-NEXT: │ ├─simple-type-specifier~IDENTIFIER := tok[5] // CHECK-NEXT: │ └─simple-type-specifier~IDENTIFIER := tok[5] // CHECK-NEXT: ├─init-declarator-list~ptr-declarator := ptr-operator ptr-declarator // CHECK-NEXT: │ ├─ptr-operator~* := tok[6] @@ -23,12 +20,11 @@ // CHECK-NEXT: └─; := tok[8] } -// CHECK: 3 Ambiguous nodes: +// CHECK: 2 Ambiguous nodes: // CHECK-NEXT: 1 simple-type-specifier // CHECK-NEXT: 1 statement -// CHECK-NEXT: 1 type-name // CHECK-EMPTY: // CHECK-NEXT: 0 Opaque nodes: // CHECK-EMPTY: -// CHECK-NEXT: Ambiguity: 0.40 misparses/token +// CHECK-NEXT: Ambiguity: 0.20 misparses/token // CHECK-NEXT: Unparsed: 0.00%