File: TestTU.h

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (107 lines) | stat: -rw-r--r-- 3,890 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//===--- TestTU.h - Scratch source files for testing -------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Many tests for indexing, code completion etc are most naturally expressed
// using code examples.
// TestTU lets test define these examples in a common way without dealing with
// the mechanics of VFS and compiler interactions, and then easily grab the
// AST, particular symbols, etc.
//
//===---------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H
#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H

#include "../TidyProvider.h"
#include "Compiler.h"
#include "FeatureModule.h"
#include "ParsedAST.h"
#include "TestFS.h"
#include "index/Index.h"
#include "support/Path.h"
#include "llvm/ADT/StringMap.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>

namespace clang {
namespace clangd {

struct TestTU {
  static TestTU withCode(llvm::StringRef Code) {
    TestTU TU;
    TU.Code = std::string(Code);
    return TU;
  }

  static TestTU withHeaderCode(llvm::StringRef HeaderCode) {
    TestTU TU;
    TU.HeaderCode = std::string(HeaderCode);
    return TU;
  }

  // The code to be compiled.
  std::string Code;
  std::string Filename = "TestTU.cpp";

  // Define contents of a header which will be implicitly included by Code.
  std::string HeaderCode;
  std::string HeaderFilename = "TestTU.h";

  // Name and contents of each file.
  llvm::StringMap<std::string> AdditionalFiles;

  // Extra arguments for the compiler invocation.
  std::vector<std::string> ExtraArgs;

  TidyProvider ClangTidyProvider = {};
  // Index to use when building AST.
  const SymbolIndex *ExternalIndex = nullptr;

  // Simulate a header guard of the header (using an #import directive).
  bool ImplicitHeaderGuard = true;

  // Whether to use overlay the TestFS over the real filesystem. This is
  // required for use of implicit modules.where the module file is written to
  // disk and later read back.
  // FIXME: Change the way reading/writing modules work to allow us to keep them
  // in memory across multiple clang invocations, at least in tests, to
  // eliminate the need for real file system here.
  // Please avoid using this for things other than implicit modules. The plan is
  // to eliminate this option some day.
  bool OverlayRealFileSystemForModules = false;

  FeatureModuleSet *FeatureModules = nullptr;

  // By default, build() will report Error diagnostics as GTest errors.
  // Suppress this behavior by adding an 'error-ok' comment to the code.
  // The result will always have getDiagnostics() populated.
  ParsedAST build() const;
  std::shared_ptr<const PreambleData>
  preamble(PreambleParsedCallback PreambleCallback = nullptr) const;
  ParseInputs inputs(MockFS &FS) const;
  SymbolSlab headerSymbols() const;
  RefSlab headerRefs() const;
  std::unique_ptr<SymbolIndex> index() const;
};

// Look up an index symbol by qualified name, which must be unique.
const Symbol &findSymbol(const SymbolSlab &, llvm::StringRef QName);
// Look up an AST symbol by qualified name, which must be unique and top-level.
const NamedDecl &findDecl(ParsedAST &AST, llvm::StringRef QName);
// Look up an AST symbol that satisfies \p Filter.
const NamedDecl &findDecl(ParsedAST &AST,
                          std::function<bool(const NamedDecl &)> Filter);
// Look up an AST symbol by unqualified name, which must be unique.
const NamedDecl &findUnqualifiedDecl(ParsedAST &AST, llvm::StringRef Name);

} // namespace clangd
} // namespace clang

#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTTU_H