2016-05-20 16:04:36 +08:00
|
|
|
//===-- SymbolInfo.h - Symbol Info ------------------------------*- C++ -*-===//
|
2016-04-27 22:27:05 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-05-13 17:27:54 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOLINFO_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOLINFO_H
|
2016-04-27 22:27:05 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-05-11 16:38:21 +08:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2016-04-29 18:16:28 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2016-04-27 22:27:05 +08:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace find_all_symbols {
|
|
|
|
|
|
|
|
/// \brief Contains all information for a Symbol.
|
2016-05-11 16:38:21 +08:00
|
|
|
class SymbolInfo {
|
|
|
|
public:
|
|
|
|
/// \brief The SymbolInfo Type.
|
2016-05-13 17:15:37 +08:00
|
|
|
enum class SymbolKind {
|
2016-04-27 22:27:05 +08:00
|
|
|
Function,
|
|
|
|
Class,
|
|
|
|
Variable,
|
|
|
|
TypedefName,
|
2016-05-13 17:15:37 +08:00
|
|
|
EnumDecl,
|
|
|
|
EnumConstantDecl,
|
2016-05-20 16:04:36 +08:00
|
|
|
Macro,
|
2016-05-11 16:38:21 +08:00
|
|
|
Unknown,
|
2016-04-27 22:27:05 +08:00
|
|
|
};
|
|
|
|
|
2016-05-11 16:38:21 +08:00
|
|
|
/// \brief The Context Type.
|
2016-05-13 17:15:37 +08:00
|
|
|
enum class ContextType {
|
2016-04-27 22:27:05 +08:00
|
|
|
Namespace, // Symbols declared in a namespace.
|
|
|
|
Record, // Symbols declared in a class.
|
2016-05-13 17:15:37 +08:00
|
|
|
EnumDecl, // Enum constants declared in a enum declaration.
|
2016-04-27 22:27:05 +08:00
|
|
|
};
|
|
|
|
|
2016-05-11 16:38:21 +08:00
|
|
|
/// \brief A pair of <ContextType, ContextName>.
|
|
|
|
typedef std::pair<ContextType, std::string> Context;
|
|
|
|
|
|
|
|
// The default constructor is required by YAML traits in
|
|
|
|
// LLVM_YAML_IS_DOCUMENT_LIST_VECTOR.
|
[include-fixer] Fix broken dependency shared build
Summary:
The shared build is broken (again).
To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```
Errors:
```
tools/clang/tools/extra/include-fixer/tool/CMakeFiles/clang-include-fixer.dir/ClangIncludeFixer.cpp.o: In function `(anonymous namespace)::includeFixerMain(int, char const**)':
ClangIncludeFixer.cpp:(.text._ZN12_GLOBAL__N_116includeFixerMainEiPPKc+0xbe9): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
collect2: error: ld returned 1 exit status
```
```
tools/clang/tools/extra/unittests/include-fixer/CMakeFiles/IncludeFixerTests.dir/IncludeFixerTest.cpp.o: In function `clang::include_fixer::(anonymous namespace)::runIncludeFixer(llvm::StringRef, std::vector<std::string, std::allocator<std::string> > const&)':
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x10e): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x1dc): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x2f3): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x40e): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x526): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
```
Reviewers: bkramer, hokein
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D20245
llvm-svn: 269441
2016-05-14 01:38:22 +08:00
|
|
|
SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
|
2016-05-11 16:38:21 +08:00
|
|
|
|
|
|
|
SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
|
2016-05-31 20:01:48 +08:00
|
|
|
int LineNumber, const std::vector<Context> &Contexts,
|
|
|
|
unsigned NumOccurrences = 0);
|
2016-05-11 16:38:21 +08:00
|
|
|
|
|
|
|
/// \brief Get symbol name.
|
2016-05-31 22:40:10 +08:00
|
|
|
llvm::StringRef getName() const { return Name; }
|
2016-05-11 16:38:21 +08:00
|
|
|
|
|
|
|
/// \brief Get symbol type.
|
2016-05-31 22:40:10 +08:00
|
|
|
SymbolKind getSymbolKind() const { return Type; }
|
2016-05-11 16:38:21 +08:00
|
|
|
|
2016-05-11 19:50:08 +08:00
|
|
|
/// \brief Get a relative file path where symbol comes from.
|
2016-05-31 22:40:10 +08:00
|
|
|
llvm::StringRef getFilePath() const { return FilePath; }
|
2016-05-11 16:38:21 +08:00
|
|
|
|
|
|
|
/// \brief Get symbol contexts.
|
2016-05-31 22:40:10 +08:00
|
|
|
const std::vector<SymbolInfo::Context> &getContexts() const {
|
|
|
|
return Contexts;
|
|
|
|
}
|
2016-05-11 16:38:21 +08:00
|
|
|
|
|
|
|
/// \brief Get a 1-based line number of the symbol's declaration.
|
2016-05-31 22:40:10 +08:00
|
|
|
int getLineNumber() const { return LineNumber; }
|
2016-05-11 16:38:21 +08:00
|
|
|
|
2016-05-31 20:01:48 +08:00
|
|
|
/// \brief The number of times this symbol was found during an indexing run.
|
2016-05-31 22:40:10 +08:00
|
|
|
unsigned getNumOccurrences() const { return NumOccurrences; }
|
2016-05-31 20:01:48 +08:00
|
|
|
|
2016-05-11 16:38:21 +08:00
|
|
|
bool operator<(const SymbolInfo &Symbol) const;
|
|
|
|
|
|
|
|
bool operator==(const SymbolInfo &Symbol) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend struct llvm::yaml::MappingTraits<SymbolInfo>;
|
|
|
|
|
2016-04-27 22:27:05 +08:00
|
|
|
/// \brief Identifier name.
|
|
|
|
std::string Name;
|
|
|
|
|
|
|
|
/// \brief Symbol type.
|
|
|
|
SymbolKind Type;
|
|
|
|
|
2016-05-11 19:50:08 +08:00
|
|
|
/// \brief The file path where the symbol comes from. It's a relative file
|
|
|
|
/// path based on the build directory.
|
2016-04-27 22:27:05 +08:00
|
|
|
std::string FilePath;
|
|
|
|
|
|
|
|
/// \brief Contains information about symbol contexts. Context information is
|
|
|
|
/// stored from the inner-most level to outer-most level.
|
|
|
|
///
|
|
|
|
/// For example, if a symbol 'x' is declared as:
|
|
|
|
/// namespace na { namespace nb { class A { int x; } } }
|
|
|
|
/// The contexts would be { {RECORD, "A"}, {NAMESPACE, "nb"}, {NAMESPACE,
|
|
|
|
/// "na"} }.
|
|
|
|
/// The name of an anonymous namespace is "".
|
|
|
|
///
|
|
|
|
/// If the symbol is declared in `TranslationUnitDecl`, it has no context.
|
|
|
|
std::vector<Context> Contexts;
|
|
|
|
|
|
|
|
/// \brief The 1-based line number of of the symbol's declaration.
|
|
|
|
int LineNumber;
|
2016-05-31 20:01:48 +08:00
|
|
|
|
|
|
|
/// \brief The number of times this symbol was found during an indexing
|
|
|
|
/// run. Populated by the reducer and used to rank results.
|
|
|
|
unsigned NumOccurrences;
|
2016-04-27 22:27:05 +08:00
|
|
|
};
|
|
|
|
|
2016-04-29 18:16:28 +08:00
|
|
|
/// \brief Write SymbolInfos to a stream (YAML format).
|
|
|
|
bool WriteSymbolInfosToStream(llvm::raw_ostream &OS,
|
|
|
|
const std::set<SymbolInfo> &Symbols);
|
2016-04-27 22:27:05 +08:00
|
|
|
|
|
|
|
/// \brief Read SymbolInfos from a YAML document.
|
|
|
|
std::vector<SymbolInfo> ReadSymbolInfosFromYAML(llvm::StringRef Yaml);
|
|
|
|
|
|
|
|
} // namespace find_all_symbols
|
|
|
|
} // namespace clang
|
|
|
|
|
2016-05-13 17:27:54 +08:00
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOLINFO_H
|