[clang-tools-extra] 90dab04 - [pseudo] Handle the language predefined identifier __func__
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 7 01:34:51 PDT 2022
Author: Haojian Wu
Date: 2022-06-07T10:34:37+02:00
New Revision: 90dab0473ef0141c3cdbacc9990f98db8c956f90
URL: https://github.com/llvm/llvm-project/commit/90dab0473ef0141c3cdbacc9990f98db8c956f90
DIFF: https://github.com/llvm/llvm-project/commit/90dab0473ef0141c3cdbacc9990f98db8c956f90.diff
LOG: [pseudo] Handle the language predefined identifier __func__
The clang lexer lexes it as a dedicated token kind (rather than
identifier), we extend the grammar to handle it.
Differential Revision: https://reviews.llvm.org/D126996
Added:
clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
Modified:
clang-tools-extra/pseudo/lib/cxx.bnf
Removed:
################################################################################
diff --git a/clang-tools-extra/pseudo/lib/cxx.bnf b/clang-tools-extra/pseudo/lib/cxx.bnf
index 16d639bc7770..f0d666d5b54e 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -750,3 +750,8 @@ export-keyword := IDENTIFIER
#! split it into two tokens to make the GLR parser aware of the nested-template
#! case.
greatergreater := > >
+
+#! C++ predefined identifier, __func__ [dcl.fct.def.general] p8
+#! FIXME: add other (MSVC, GNU extension) predefined identifiers.
+primary-expression := predefined-expression
+predefined-expression := __FUNC__
diff --git a/clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp b/clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
new file mode 100644
index 000000000000..1a05672835a7
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+void s() {
+ __func__;
+ // CHECK: expression~__FUNC__ := tok[5]
+}
More information about the cfe-commits
mailing list