[pseudo] Handle the language predefined identifier __func__
authorHaojian Wu <hokein.wu@gmail.com>
Fri, 3 Jun 2022 19:47:11 +0000 (21:47 +0200)
committerHaojian Wu <hokein.wu@gmail.com>
Tue, 7 Jun 2022 08:34:37 +0000 (10:34 +0200)
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

clang-tools-extra/pseudo/lib/cxx.bnf
clang-tools-extra/pseudo/test/cxx/predefined-identifier.cpp [new file with mode: 0644]

index 16d639b..f0d666d 100644 (file)
@@ -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 (file)
index 0000000..1a05672
--- /dev/null
@@ -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]
+}