1 //===- TreeTestBase.h -----------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file provides the test infrastructure for syntax trees. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_UNITTESTS_TOOLING_SYNTAX_TREETESTBASE_H 14 #define LLVM_CLANG_UNITTESTS_TOOLING_SYNTAX_TREETESTBASE_H 15 16 #include "clang/Basic/LLVM.h" 17 #include "clang/Frontend/CompilerInvocation.h" 18 #include "clang/Testing/TestClangConfig.h" 19 #include "clang/Tooling/Syntax/Nodes.h" 20 #include "clang/Tooling/Syntax/Tokens.h" 21 #include "clang/Tooling/Syntax/Tree.h" 22 #include "llvm/ADT/StringRef.h" 23 #include "llvm/Testing/Support/Annotations.h" 24 #include "gtest/gtest.h" 25 26 namespace clang { 27 namespace syntax { 28 class SyntaxTreeTest : public ::testing::Test, 29 public ::testing::WithParamInterface<TestClangConfig> { 30 protected: 31 // Build a syntax tree for the code. 32 TranslationUnit *buildTree(StringRef Code, 33 const TestClangConfig &ClangConfig); 34 35 /// Finds the deepest node in the tree that covers exactly \p R. 36 /// FIXME: implement this efficiently and move to public syntax tree API. 37 syntax::Node *nodeByRange(llvm::Annotations::Range R, syntax::Node *Root); 38 39 // Data fields. 40 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); 41 IntrusiveRefCntPtr<DiagnosticsEngine> Diags = 42 new DiagnosticsEngine(new DiagnosticIDs, DiagOpts.get()); 43 IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS = 44 new llvm::vfs::InMemoryFileSystem; 45 IntrusiveRefCntPtr<FileManager> FileMgr = 46 new FileManager(FileSystemOptions(), FS); 47 IntrusiveRefCntPtr<SourceManager> SourceMgr = 48 new SourceManager(*Diags, *FileMgr); 49 std::shared_ptr<CompilerInvocation> Invocation; 50 // Set after calling buildTree(). 51 std::unique_ptr<syntax::TokenBuffer> TB; 52 std::unique_ptr<syntax::Arena> Arena; 53 }; 54 55 std::vector<TestClangConfig> allTestClangConfigs(); 56 } // namespace syntax 57 } // namespace clang 58 #endif // LLVM_CLANG_UNITTESTS_TOOLING_SYNTAX_TREETESTBASE_H 59