aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/Syntax/TreeTest.cpp
diff options
context:
space:
mode:
authorMarcel Hlopko <hlopko@google.com>2020-03-19 17:23:42 +0100
committerDmitri Gribenko <gribozavr@gmail.com>2020-03-19 17:43:07 +0100
commit88bf9b3d26f06eaf33972d1f371edc4cb187ff1a (patch)
treeea054df45d2ce40fac91de013452c3625dfa446b /clang/unittests/Tooling/Syntax/TreeTest.cpp
parentc13aa36bb7d196643be0066404a8e7915a21a3f0 (diff)
downloadllvm-88bf9b3d26f06eaf33972d1f371edc4cb187ff1a.zip
llvm-88bf9b3d26f06eaf33972d1f371edc4cb187ff1a.tar.gz
llvm-88bf9b3d26f06eaf33972d1f371edc4cb187ff1a.tar.bz2
[Syntax] Build template declaration nodes
Summary: Rollforward of https://reviews.llvm.org/rGdd12826808f9079e164b82e64b0697a077379241 after temporarily adding -fno-delayed-template-parsing to the TreeTest. Original summary: > Copy of https://reviews.llvm.org/D72334, submitting with Ilya's permission. > > Handles template declaration of all kinds. > > Also builds template declaration nodes for specializations and explicit > instantiations of classes. > > Some missing things will be addressed in the follow-up patches: > > * specializations of functions and variables, > * template parameters. Reviewers: gribozavr2 Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76418
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TreeTest.cpp')
-rw-r--r--clang/unittests/Tooling/Syntax/TreeTest.cpp209
1 files changed, 208 insertions, 1 deletions
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 6e914b6..cfed1ee 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -99,6 +99,7 @@ protected:
Diags->setClient(new IgnoringDiagConsumer);
// Prepare to run a compiler.
std::vector<const char *> Args = {"syntax-test", "-std=c++11",
+ "-fno-delayed-template-parsing",
"-fsyntax-only", FileName};
Invocation = createInvocationFromCommandLine(Args, Diags, FS);
assert(Invocation);
@@ -678,6 +679,212 @@ struct {} *a1;
`-;
)txt"},
{R"cpp(
+template <class T> struct cls {};
+template <class T> int var = 10;
+template <class T> int fun() {}
+ )cpp",
+ R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+| |-struct
+| |-cls
+| |-{
+| |-}
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-var
+| | |-=
+| | `-UnknownExpression
+| | `-10
+| `-;
+`-TemplateDeclaration
+ |-template
+ |-<
+ |-UnknownDeclaration
+ | |-class
+ | `-T
+ |->
+ `-SimpleDeclaration
+ |-int
+ |-SimpleDeclarator
+ | |-fun
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ `-}
+)txt"},
+ {R"cpp(
+template <class T>
+struct X {
+ template <class U>
+ U foo();
+};
+ )cpp",
+ R"txt(
+*: TranslationUnit
+`-TemplateDeclaration
+ |-template
+ |-<
+ |-UnknownDeclaration
+ | |-class
+ | `-T
+ |->
+ `-SimpleDeclaration
+ |-struct
+ |-X
+ |-{
+ |-TemplateDeclaration
+ | |-template
+ | |-<
+ | |-UnknownDeclaration
+ | | |-class
+ | | `-U
+ | |->
+ | `-SimpleDeclaration
+ | |-U
+ | |-SimpleDeclarator
+ | | |-foo
+ | | `-ParametersAndQualifiers
+ | | |-(
+ | | `-)
+ | `-;
+ |-}
+ `-;
+)txt"},
+ {R"cpp(
+template <class T> struct X {};
+template <class T> struct X<T*> {};
+template <> struct X<int> {};
+
+template struct X<double>;
+extern template struct X<float>;
+)cpp",
+ R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-}
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+| |-struct
+| |-X
+| |-<
+| |-T
+| |-*
+| |->
+| |-{
+| |-}
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |->
+| `-SimpleDeclaration
+| |-struct
+| |-X
+| |-<
+| |-int
+| |->
+| |-{
+| |-}
+| `-;
+|-ExplicitTemplateInstantiation
+| |-template
+| `-SimpleDeclaration
+| |-struct
+| |-X
+| |-<
+| |-double
+| |->
+| `-;
+`-ExplicitTemplateInstantiation
+ |-extern
+ |-template
+ `-SimpleDeclaration
+ |-struct
+ |-X
+ |-<
+ |-float
+ |->
+ `-;
+)txt"},
+ {R"cpp(
+template <class T> struct X { struct Y; };
+template <class T> struct X<T>::Y {};
+ )cpp",
+ R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-struct
+| | |-Y
+| | `-;
+| |-}
+| `-;
+`-TemplateDeclaration
+ |-template
+ |-<
+ |-UnknownDeclaration
+ | |-class
+ | `-T
+ |->
+ `-SimpleDeclaration
+ |-struct
+ |-X
+ |-<
+ |-T
+ |->
+ |-::
+ |-Y
+ |-{
+ |-}
+ `-;
+ )txt"},
+ {R"cpp(
namespace ns {}
using namespace ::ns;
)cpp",
@@ -726,7 +933,7 @@ template <class T> struct X {
)cpp",
R"txt(
*: TranslationUnit
-`-UnknownDeclaration
+`-TemplateDeclaration
|-template
|-<
|-UnknownDeclaration