From b94ea8b3ebc16504b668fd7086de544637e0cd53 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 18 Jul 2022 09:56:54 +0200 Subject: [PATCH] [pseudo] Add bracket recovery for function parameters. --- clang-tools-extra/pseudo/lib/cxx/cxx.bnf | 2 +- clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp | 2 +- .../pseudo/test/cxx/recovery-func-parameters.cpp | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 clang-tools-extra/pseudo/test/cxx/recovery-func-parameters.cpp diff --git a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf index 204b816..b80dfd9 100644 --- a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf +++ b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf @@ -412,7 +412,7 @@ noptr-declarator := declarator-id noptr-declarator := noptr-declarator parameters-and-qualifiers noptr-declarator := noptr-declarator [ constant-expression_opt ] noptr-declarator := ( ptr-declarator ) -parameters-and-qualifiers := ( parameter-declaration-clause_opt ) cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt +parameters-and-qualifiers := ( parameter-declaration-clause_opt [recover=Brackets] ) cv-qualifier-seq_opt ref-qualifier_opt noexcept-specifier_opt trailing-return-type := -> type-id ptr-operator := * cv-qualifier-seq_opt ptr-operator := & diff --git a/clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp b/clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp index 18584de..1426f4e0 100644 --- a/clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp +++ b/clang-tools-extra/pseudo/test/cxx/parameter-decl-clause.cpp @@ -4,7 +4,7 @@ void foo2(int, ...); // CHECK-NEXT: ├─decl-specifier-seq~VOID := // CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator parameters-and-qualifiers // CHECK-NEXT: │ ├─noptr-declarator~IDENTIFIER := -// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause ) +// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause [recover=Brackets] ) // CHECK-NEXT: │ ├─( := // CHECK-NEXT: │ ├─parameter-declaration-clause := parameter-declaration-list , ... // CHECK-NEXT: │ │ ├─parameter-declaration-list~INT := diff --git a/clang-tools-extra/pseudo/test/cxx/recovery-func-parameters.cpp b/clang-tools-extra/pseudo/test/cxx/recovery-func-parameters.cpp new file mode 100644 index 0000000..d3007c3 --- /dev/null +++ b/clang-tools-extra/pseudo/test/cxx/recovery-func-parameters.cpp @@ -0,0 +1,13 @@ +// RUN: clang-pseudo -grammar=cxx -source=%s --print-forest | FileCheck %s +void foo(complete garbage???) {} +// CHECK: translation-unit~function-definition := decl-specifier-seq declarator function-body +// CHECK-NEXT: ├─decl-specifier-seq~VOID := tok[0] +// CHECK-NEXT: ├─declarator~noptr-declarator := noptr-declarator parameters-and-qualifiers +// CHECK-NEXT: │ ├─noptr-declarator~IDENTIFIER := tok[1] +// CHECK-NEXT: │ └─parameters-and-qualifiers := ( parameter-declaration-clause [recover=Brackets] ) +// CHECK-NEXT: │ ├─( := tok[2] +// CHECK-NEXT: │ ├─parameter-declaration-clause := +// CHECK-NEXT: │ └─) := tok[8] +// CHECK-NEXT: └─function-body~compound-statement := { } +// CHECK-NEXT: ├─{ := tok[9] +// CHECK-NEXT: └─} := tok[10] -- 2.7.4