[clang-tools-extra] r269162 - [find-all-symbols] Slim SymbolInfo.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed May 11 01:38:21 PDT 2016
Author: hokein
Date: Wed May 11 03:38:21 2016
New Revision: 269162
URL: http://llvm.org/viewvc/llvm-project?rev=269162&view=rev
Log:
[find-all-symbols] Slim SymbolInfo.
Summary:
SymbolInfo has some optional fields, which is a bad-smell
implementation. For now, we
* remove the optional field since we don't need them (we can probably
add them back if we actually need them in the future)
* make SymbolInfo to be a class.
By this change, the code is more simplified.
Reviewers: klimek
Subscribers: cfe-commits, ioeric, bkramer
Differential Revision: http://reviews.llvm.org/D20095
Modified:
clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp
clang-tools-extra/trunk/include-fixer/XrefsDBManager.cpp
clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp
clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
Modified: clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp?rev=269162&r1=269161&r2=269162&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp Wed May 11 03:38:21 2016
@@ -21,17 +21,15 @@ InMemoryXrefsDB::InMemoryXrefsDB(
llvm::SmallVector<llvm::StringRef, 8> Names;
Identifier.split(Names, "::");
for (const auto &Header : Entry.second) {
- // FIXME: create a complete instance with static member function when it
- // is implemented.
- SymbolInfo Info;
- Info.Name = Names.back();
- Info.FilePath = Header;
+ std::vector<SymbolInfo::Context> Contexts;
for (auto IdentiferContext = Names.rbegin() + 1;
IdentiferContext != Names.rend(); ++IdentiferContext) {
- Info.Contexts.push_back(
- {SymbolInfo::ContextType::Namespace, *IdentiferContext});
+ Contexts.emplace_back(SymbolInfo::ContextType::Namespace,
+ *IdentiferContext);
}
- this->LookupTable[Info.Name].push_back(Info);
+
+ SymbolInfo Symbol(Names.back(), SymbolInfo::Class, Header, Contexts, 1);
+ this->LookupTable[Symbol.getName()].push_back(Symbol);
}
}
}
Modified: clang-tools-extra/trunk/include-fixer/XrefsDBManager.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/XrefsDBManager.cpp?rev=269162&r1=269161&r2=269162&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/XrefsDBManager.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/XrefsDBManager.cpp Wed May 11 03:38:21 2016
@@ -36,13 +36,13 @@ XrefsDBManager::search(llvm::StringRef I
std::vector<std::string> Results;
for (const auto &Symbol : Symbols) {
// Match the identifier name without qualifier.
- if (Symbol.Name == Names.back()) {
+ if (Symbol.getName() == Names.back()) {
bool IsMatched = true;
- auto SymbolContext = Symbol.Contexts.begin();
+ auto SymbolContext = Symbol.getContexts().begin();
// Match the remaining context names.
for (auto IdentiferContext = Names.rbegin() + 1;
IdentiferContext != Names.rend() &&
- SymbolContext != Symbol.Contexts.end();
+ SymbolContext != Symbol.getContexts().end();
++IdentiferContext, ++SymbolContext) {
if (SymbolContext->second != *IdentiferContext) {
IsMatched = false;
@@ -56,10 +56,10 @@ XrefsDBManager::search(llvm::StringRef I
// need to be changed.
// FIXME: if the file path is a system header name, we want to use angle
// brackets.
- Results.push_back(
- (Symbol.FilePath[0] == '"' || Symbol.FilePath[0] == '<')
- ? Symbol.FilePath
- : "\"" + Symbol.FilePath + "\"");
+ std::string FilePath = Symbol.getFilePath().str();
+ Results.push_back((FilePath[0] == '"' || FilePath[0] == '<')
+ ? FilePath
+ : "\"" + FilePath + "\"");
}
}
}
Modified: clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp?rev=269162&r1=269161&r2=269162&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp Wed May 11 03:38:21 2016
@@ -50,7 +50,7 @@ YamlXrefsDB::createFromDirectory(llvm::S
std::vector<SymbolInfo> YamlXrefsDB::search(llvm::StringRef Identifier) {
std::vector<SymbolInfo> Results;
for (const auto &Symbol : Symbols) {
- if (Symbol.Name == Identifier)
+ if (Symbol.getName() == Identifier)
Results.push_back(Symbol);
}
return Results;
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp?rev=269162&r1=269161&r2=269162&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp Wed May 11 03:38:21 2016
@@ -15,6 +15,7 @@
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
@@ -23,7 +24,8 @@ using namespace clang::ast_matchers;
namespace clang {
namespace find_all_symbols {
namespace {
-void SetContext(const NamedDecl *ND, SymbolInfo *Symbol) {
+std::vector<SymbolInfo::Context> GetContexts(const NamedDecl *ND) {
+ std::vector<SymbolInfo::Context> Contexts;
for (const auto *Context = ND->getDeclContext(); Context;
Context = Context->getParent()) {
if (llvm::isa<TranslationUnitDecl>(Context) ||
@@ -33,54 +35,65 @@ void SetContext(const NamedDecl *ND, Sym
assert(llvm::isa<NamedDecl>(Context) &&
"Expect Context to be a NamedDecl");
if (const auto *NSD = dyn_cast<NamespaceDecl>(Context)) {
- Symbol->Contexts.emplace_back(
- SymbolInfo::Namespace,
- NSD->isAnonymousNamespace() ? "" : NSD->getName().str());
+ Contexts.emplace_back(SymbolInfo::Namespace, NSD->isAnonymousNamespace()
+ ? ""
+ : NSD->getName().str());
} else {
const auto *RD = cast<RecordDecl>(Context);
- Symbol->Contexts.emplace_back(SymbolInfo::Record, RD->getName().str());
+ Contexts.emplace_back(SymbolInfo::Record, RD->getName().str());
}
}
+ return Contexts;
}
-bool SetCommonInfo(const MatchFinder::MatchResult &Result,
- const NamedDecl *ND, SymbolInfo *Symbol) {
- SetContext(ND, Symbol);
-
- Symbol->Name = ND->getNameAsString();
+llvm::Optional<SymbolInfo> CreateSymbolInfo(const NamedDecl *ND,
+ const SourceManager &SM) {
+ SymbolInfo::SymbolKind Type;
+ if (llvm::isa<VarDecl>(ND)) {
+ Type = SymbolInfo::Variable;
+ } else if (llvm::isa<FunctionDecl>(ND)) {
+ Type = SymbolInfo::Function;
+ } else if (llvm::isa<TypedefNameDecl>(ND)) {
+ Type = SymbolInfo::TypedefName;
+ } else {
+ assert(llvm::isa<RecordDecl>(ND) && "Matched decl must be one of VarDecl, "
+ "FunctionDecl, TypedefNameDecl and "
+ "RecordDecl!");
+ // C-style record decl can have empty name, e.g "struct { ... } var;".
+ if (ND->getName().empty())
+ return llvm::None;
+ Type = SymbolInfo::Class;
+ }
- const SourceManager *SM = Result.SourceManager;
- SourceLocation Loc = SM->getExpansionLoc(ND->getLocation());
+ SourceLocation Loc = SM.getExpansionLoc(ND->getLocation());
if (!Loc.isValid()) {
llvm::errs() << "Declaration " << ND->getNameAsString() << "("
<< ND->getDeclKindName()
<< ") has invalid declaration location.";
- return false;
+ return llvm::None;
}
-
- Symbol->LineNumber = SM->getExpansionLineNumber(Loc);
-
- llvm::StringRef FilePath = SM->getFilename(Loc);
+ llvm::StringRef FilePath = SM.getFilename(Loc);
if (FilePath.empty())
- return false;
+ return llvm::None;
llvm::SmallString<128> AbsolutePath;
if (llvm::sys::path::is_absolute(FilePath)) {
AbsolutePath = FilePath;
} else {
- auto WorkingDir = SM->getFileManager()
+ auto WorkingDir = SM.getFileManager()
.getVirtualFileSystem()
->getCurrentWorkingDirectory();
if (!WorkingDir)
- return false;
+ return llvm::None;
AbsolutePath = *WorkingDir;
llvm::sys::path::append(AbsolutePath, FilePath);
}
llvm::sys::path::remove_dots(AbsolutePath, true);
- Symbol->FilePath = AbsolutePath.str();
- return true;
+ return SymbolInfo(ND->getNameAsString(), Type, AbsolutePath.str(),
+ GetContexts(ND), SM.getExpansionLineNumber(Loc));
}
+
} // namespace
void FindAllSymbols::registerMatchers(MatchFinder *MatchFinder) {
@@ -173,39 +186,10 @@ void FindAllSymbols::run(const MatchFind
assert(ND && "Matched declaration must be a NamedDecl!");
const SourceManager *SM = Result.SourceManager;
- SymbolInfo Symbol;
- if (!SetCommonInfo(Result, ND, &Symbol))
- return;
-
- if (const auto *VD = llvm::dyn_cast<VarDecl>(ND)) {
- Symbol.Type = SymbolInfo::Variable;
- SymbolInfo::VariableInfo VI;
- VI.Type = VD->getType().getAsString();
- Symbol.VariableInfos = VI;
- } else if (const auto *FD = llvm::dyn_cast<FunctionDecl>(ND)) {
- Symbol.Type = SymbolInfo::Function;
- SymbolInfo::FunctionInfo FI;
- FI.ReturnType = FD->getReturnType().getAsString();
- for (const auto *Param : FD->params())
- FI.ParameterTypes.push_back(Param->getType().getAsString());
- Symbol.FunctionInfos = FI;
- } else if (const auto *TD = llvm::dyn_cast<TypedefNameDecl>(ND)) {
- Symbol.Type = SymbolInfo::TypedefName;
- SymbolInfo::TypedefNameInfo TI;
- TI.UnderlyingType = TD->getUnderlyingType().getAsString();
- Symbol.TypedefNameInfos = TI;
- } else {
- assert(
- llvm::isa<RecordDecl>(ND) &&
- "Matched decl must be one of VarDecl, FunctionDecl, and RecordDecl!");
- // C-style record decl can have empty name, e.g "struct { ... } var;".
- if (ND->getName().empty())
- return;
- Symbol.Type = SymbolInfo::Class;
- }
-
- const FileEntry *FE = SM->getFileEntryForID(SM->getMainFileID());
- Reporter->reportResult(FE->getName(), Symbol);
+ llvm::Optional<SymbolInfo> Symbol = CreateSymbolInfo(ND, *SM);
+ if (Symbol)
+ Reporter->reportResult(
+ SM->getFileEntryForID(SM->getMainFileID())->getName(), *Symbol);
}
} // namespace find_all_symbols
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp?rev=269162&r1=269161&r2=269162&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp Wed May 11 03:38:21 2016
@@ -33,9 +33,6 @@ template <> struct MappingTraits<SymbolI
io.mapRequired("FilePath", Symbol.FilePath);
io.mapRequired("LineNumber", Symbol.LineNumber);
io.mapRequired("Type", Symbol.Type);
- io.mapOptional("Variable", Symbol.VariableInfos);
- io.mapOptional("Function", Symbol.FunctionInfos);
- io.mapOptional("TypedefName", Symbol.TypedefNameInfos);
}
};
@@ -62,39 +59,40 @@ template <> struct MappingTraits<SymbolI
}
};
-template <> struct MappingTraits<SymbolInfo::FunctionInfo> {
- static void mapping(IO &io, SymbolInfo::FunctionInfo &Value) {
- io.mapRequired("ReturnType", Value.ReturnType);
- io.mapRequired("ParameterTypes", Value.ParameterTypes);
- }
-};
-
-template <> struct MappingTraits<SymbolInfo::VariableInfo> {
- static void mapping(IO &io, SymbolInfo::VariableInfo &Value) {
- io.mapRequired("VariableType", Value.Type);
- }
-};
-
-template <> struct MappingTraits<SymbolInfo::TypedefNameInfo> {
- static void mapping(IO &io, SymbolInfo::TypedefNameInfo &Value) {
- io.mapRequired("TypedefNameType", Value.UnderlyingType);
- }
-};
-
} // namespace yaml
} // namespace llvm
namespace clang {
namespace find_all_symbols {
+SymbolInfo::SymbolInfo(llvm::StringRef Name, SymbolKind Type,
+ llvm::StringRef FilePath,
+ const std::vector<Context> &Contexts, int LineNumber)
+ : Name(Name), Type(Type), FilePath(FilePath), Contexts(Contexts),
+ LineNumber(LineNumber) {}
+
+llvm::StringRef SymbolInfo::getName() const { return Name; }
+
+SymbolKind SymbolInfo::getSymbolKind() const { return Type; }
+
+llvm::StringRef SymbolInfo::getFilePath() const { return FilePath; }
+
+const std::vector<SymbolInfo::Context> &SymbolInfo::getContexts() const {
+ return Contexts;
+}
+
+int SymbolInfo::getLineNumber() const { return LineNumber; }
+
bool SymbolInfo::operator==(const SymbolInfo &Symbol) const {
- return Name == Symbol.Name && FilePath == Symbol.FilePath &&
- LineNumber == Symbol.LineNumber && Contexts == Symbol.Contexts;
+ return std::tie(Name, Type, FilePath, LineNumber, Contexts) ==
+ std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.LineNumber,
+ Symbol.Contexts);
}
bool SymbolInfo::operator<(const SymbolInfo &Symbol) const {
- return std::tie(Name, FilePath, LineNumber) <
- std::tie(Symbol.Name, Symbol.FilePath, Symbol.LineNumber);
+ return std::tie(Name, Type, FilePath, LineNumber, Contexts) <
+ std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.LineNumber,
+ Symbol.Contexts);
}
bool WriteSymbolInfosToStream(llvm::raw_ostream &OS,
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h?rev=269162&r1=269161&r2=269162&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h Wed May 11 03:38:21 2016
@@ -12,6 +12,7 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include <set>
#include <string>
@@ -21,20 +22,55 @@ namespace clang {
namespace find_all_symbols {
/// \brief Contains all information for a Symbol.
-// FIXME: add static members for creating complete instances.
-struct SymbolInfo {
+class SymbolInfo {
+public:
+ /// \brief The SymbolInfo Type.
enum SymbolKind {
Function,
Class,
Variable,
TypedefName,
+ Unknown,
};
+ /// \brief The Context Type.
enum ContextType {
Namespace, // Symbols declared in a namespace.
Record, // Symbols declared in a class.
};
+ /// \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.
+ SymbolInfo() : Type(Unknown), LineNumber(-1) {};
+
+ SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
+ const std::vector<Context> &Contexts, int LineNumber);
+
+ /// \brief Get symbol name.
+ llvm::StringRef getName() const;
+
+ /// \brief Get symbol type.
+ SymbolKind getSymbolKind() const;
+
+ /// \brief Get the file path where symbol comes from
+ llvm::StringRef getFilePath() const;
+
+ /// \brief Get symbol contexts.
+ const std::vector<SymbolInfo::Context> &getContexts() const;
+
+ /// \brief Get a 1-based line number of the symbol's declaration.
+ int getLineNumber() const;
+
+ bool operator<(const SymbolInfo &Symbol) const;
+
+ bool operator==(const SymbolInfo &Symbol) const;
+
+private:
+ friend struct llvm::yaml::MappingTraits<SymbolInfo>;
+
/// \brief Identifier name.
std::string Name;
@@ -44,9 +80,6 @@ struct SymbolInfo {
/// \brief The file path where the symbol comes from.
std::string FilePath;
- /// \brief A pair of <ContextType, ContextName>.
- typedef std::pair<ContextType, std::string> Context;
-
/// \brief Contains information about symbol contexts. Context information is
/// stored from the inner-most level to outer-most level.
///
@@ -61,32 +94,6 @@ struct SymbolInfo {
/// \brief The 1-based line number of of the symbol's declaration.
int LineNumber;
-
- struct FunctionInfo {
- std::string ReturnType;
- std::vector<std::string> ParameterTypes;
- };
-
- struct TypedefNameInfo {
- std::string UnderlyingType;
- };
-
- struct VariableInfo {
- std::string Type;
- };
-
- /// \brief The function information.
- llvm::Optional<FunctionInfo> FunctionInfos;
-
- /// \brief The typedef information.
- llvm::Optional<TypedefNameInfo> TypedefNameInfos;
-
- /// \brief The variable information.
- llvm::Optional<VariableInfo> VariableInfos;
-
- bool operator==(const SymbolInfo &Symbol) const;
-
- bool operator<(const SymbolInfo &Symbol) const;
};
/// \brief Write SymbolInfos to a stream (YAML format).
Modified: clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp?rev=269162&r1=269161&r2=269162&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp Wed May 11 03:38:21 2016
@@ -46,18 +46,6 @@ public:
return false;
}
- bool getSymbolExtraInfo(SymbolInfo *Symbol) {
- for (const auto &S : Symbols) {
- if (S == *Symbol) {
- Symbol->FunctionInfos = S.FunctionInfos;
- Symbol->TypedefNameInfos = S.TypedefNameInfos;
- Symbol->VariableInfos = S.VariableInfos;
- return true;
- }
- }
- return false;
- }
-
private:
std::vector<SymbolInfo> Symbols;
};
@@ -68,10 +56,6 @@ public:
return Reporter.hasSymbol(Symbol);
}
- bool getSymbolExtraInfo(SymbolInfo &Symbol) {
- return Reporter.getSymbolExtraInfo(&Symbol);
- }
-
bool runFindAllSymbols(StringRef Code) {
FindAllSymbols matcher(&Reporter);
clang::ast_matchers::MatchFinder MatchFinder;
@@ -87,7 +71,7 @@ public:
clang::tooling::newFrontendActionFactory(&MatchFinder);
tooling::ToolInvocation Invocation(
{std::string("find_all_symbols"), std::string("-fsyntax-only"),
- FileName},
+ std::string("-std=c++11"), FileName},
Factory->create(), Files.get(),
std::make_shared<PCHContainerOperations>());
@@ -105,17 +89,10 @@ private:
MockReporter Reporter;
};
-SymbolInfo
-CreateSymbolInfo(StringRef Name, SymbolInfo::SymbolKind Type,
- const std::string FilePath, int LineNumber,
- const std::vector<SymbolInfo::Context> &Contexts) {
- SymbolInfo Symbol;
- Symbol.Name = Name;
- Symbol.Type = Type;
- Symbol.FilePath = FilePath;
- Symbol.LineNumber = LineNumber;
- Symbol.Contexts = Contexts;
- return Symbol;
+SymbolInfo CreateSymbolInfo(StringRef Name, SymbolInfo::SymbolKind Type,
+ StringRef FilePath, int LineNumber,
+ const std::vector<SymbolInfo::Context> &Contexts) {
+ return SymbolInfo(Name, Type, FilePath, Contexts, LineNumber);
}
TEST_F(FindAllSymbolsTest, VariableSymbols) {
@@ -127,29 +104,18 @@ TEST_F(FindAllSymbolsTest, VariableSymbo
})";
runFindAllSymbols(Code);
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("xargc", SymbolInfo::Variable, HeaderName, 2, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.VariableInfos.getValue().Type);
- }
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("SSSS", SymbolInfo::Variable, HeaderName, 4,
- {{SymbolInfo::Namespace, "na"}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("_Bool", Symbol.VariableInfos.getValue().Type);
- }
- {
- SymbolInfo Symbol = CreateSymbolInfo(
- "XXXX", SymbolInfo::Variable, HeaderName, 5,
- {{SymbolInfo::Namespace, "nb"}, {SymbolInfo::Namespace, "na"}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("const long long *", Symbol.VariableInfos.getValue().Type);
- }
+ SymbolInfo Symbol =
+ CreateSymbolInfo("xargc", SymbolInfo::Variable, HeaderName, 2, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("SSSS", SymbolInfo::Variable, HeaderName, 4,
+ {{SymbolInfo::Namespace, "na"}});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo(
+ "XXXX", SymbolInfo::Variable, HeaderName, 5,
+ {{SymbolInfo::Namespace, "nb"}, {SymbolInfo::Namespace, "na"}});
+ EXPECT_TRUE(hasSymbol(Symbol));
}
TEST_F(FindAllSymbolsTest, ExternCSymbols) {
@@ -162,19 +128,12 @@ TEST_F(FindAllSymbolsTest, ExternCSymbol
})";
runFindAllSymbols(Code);
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("C_Func", SymbolInfo::Function, HeaderName, 3, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.FunctionInfos.getValue().ReturnType);
- EXPECT_TRUE(Symbol.FunctionInfos.getValue().ParameterTypes.empty());
- }
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("C_struct", SymbolInfo::Class, HeaderName, 4, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- }
+ SymbolInfo Symbol =
+ CreateSymbolInfo("C_Func", SymbolInfo::Function, HeaderName, 3, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("C_struct", SymbolInfo::Class, HeaderName, 4, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
}
TEST_F(FindAllSymbolsTest, CXXRecordSymbols) {
@@ -193,16 +152,13 @@ TEST_F(FindAllSymbolsTest, CXXRecordSymb
)";
runFindAllSymbols(Code);
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("Glob", SymbolInfo::Class, HeaderName, 2, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- }
- {
- SymbolInfo Symbol = CreateSymbolInfo("A", SymbolInfo::Class, HeaderName, 6,
- {{SymbolInfo::Namespace, "na"}});
- EXPECT_TRUE(hasSymbol(Symbol));
- }
+ SymbolInfo Symbol =
+ CreateSymbolInfo("Glob", SymbolInfo::Class, HeaderName, 2, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("A", SymbolInfo::Class, HeaderName, 6,
+ {{SymbolInfo::Namespace, "na"}});
+ EXPECT_TRUE(hasSymbol(Symbol));
}
TEST_F(FindAllSymbolsTest, CXXRecordSymbolsTemplate) {
@@ -223,11 +179,9 @@ TEST_F(FindAllSymbolsTest, CXXRecordSymb
)";
runFindAllSymbols(Code);
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("T_TEMP", SymbolInfo::Class, HeaderName, 3, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- }
+ SymbolInfo Symbol =
+ CreateSymbolInfo("T_TEMP", SymbolInfo::Class, HeaderName, 3, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
}
TEST_F(FindAllSymbolsTest, FunctionSymbols) {
@@ -246,43 +200,22 @@ TEST_F(FindAllSymbolsTest, FunctionSymbo
)";
runFindAllSymbols(Code);
- {
- SymbolInfo Symbol = CreateSymbolInfo("gg", SymbolInfo::Class, HeaderName, 3,
- {{SymbolInfo::Namespace, "na"}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.FunctionInfos.getValue().ReturnType);
- EXPECT_EQ(1u, Symbol.FunctionInfos.getValue().ParameterTypes.size());
- EXPECT_EQ("int", Symbol.FunctionInfos.getValue().ParameterTypes[0]);
- }
- {
- SymbolInfo Symbol = CreateSymbolInfo("f", SymbolInfo::Class, HeaderName, 4,
- {{SymbolInfo::Namespace, "na"}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.FunctionInfos.getValue().ReturnType);
- EXPECT_EQ(1u, Symbol.FunctionInfos.getValue().ParameterTypes.size());
- EXPECT_EQ("const int &", Symbol.FunctionInfos.getValue().ParameterTypes[0]);
- }
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("SSSFFF", SymbolInfo::Class, HeaderName, 5,
- {{SymbolInfo::Namespace, "na"}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("void", Symbol.FunctionInfos.getValue().ReturnType);
- EXPECT_TRUE(Symbol.FunctionInfos.getValue().ParameterTypes.empty());
- }
- {
- SymbolInfo Symbol = CreateSymbolInfo(
- "fun", SymbolInfo::Class, HeaderName, 10,
- {{SymbolInfo::Namespace, "nb"}, {SymbolInfo::Namespace, "na"}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("void", Symbol.FunctionInfos.getValue().ReturnType);
- EXPECT_EQ(1u, Symbol.FunctionInfos.getValue().ParameterTypes.size());
- EXPECT_EQ("T", Symbol.FunctionInfos.getValue().ParameterTypes[0]);
- }
+ SymbolInfo Symbol = CreateSymbolInfo("gg", SymbolInfo::Function, HeaderName,
+ 3, {{SymbolInfo::Namespace, "na"}});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("f", SymbolInfo::Function, HeaderName, 4,
+ {{SymbolInfo::Namespace, "na"}});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("SSSFFF", SymbolInfo::Function, HeaderName, 5,
+ {{SymbolInfo::Namespace, "na"}});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo(
+ "fun", SymbolInfo::Function, HeaderName, 10,
+ {{SymbolInfo::Namespace, "nb"}, {SymbolInfo::Namespace, "na"}});
+ EXPECT_TRUE(hasSymbol(Symbol));
}
TEST_F(FindAllSymbolsTest, NamespaceTest) {
@@ -294,49 +227,31 @@ TEST_F(FindAllSymbolsTest, NamespaceTest
)";
runFindAllSymbols(Code);
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("X1", SymbolInfo::Variable, HeaderName, 2, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.VariableInfos.getValue().Type);
- }
- {
- SymbolInfo Symbol = CreateSymbolInfo("X2", SymbolInfo::Variable, HeaderName,
- 3, {{SymbolInfo::Namespace, ""}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.VariableInfos.getValue().Type);
- }
- {
- SymbolInfo Symbol = CreateSymbolInfo(
- "X3", SymbolInfo::Variable, HeaderName, 4,
- {{SymbolInfo::Namespace, ""}, {SymbolInfo::Namespace, ""}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.VariableInfos.getValue().Type);
- }
- {
- SymbolInfo Symbol = CreateSymbolInfo(
- "X4", SymbolInfo::Variable, HeaderName, 5,
- {{SymbolInfo::Namespace, "nb"}, {SymbolInfo::Namespace, ""}});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("int", Symbol.VariableInfos.getValue().Type);
- }
+ SymbolInfo Symbol =
+ CreateSymbolInfo("X1", SymbolInfo::Variable, HeaderName, 2, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("X2", SymbolInfo::Variable, HeaderName, 3,
+ {{SymbolInfo::Namespace, ""}});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo(
+ "X3", SymbolInfo::Variable, HeaderName, 4,
+ {{SymbolInfo::Namespace, ""}, {SymbolInfo::Namespace, ""}});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo(
+ "X4", SymbolInfo::Variable, HeaderName, 5,
+ {{SymbolInfo::Namespace, "nb"}, {SymbolInfo::Namespace, ""}});
+ EXPECT_TRUE(hasSymbol(Symbol));
}
TEST_F(FindAllSymbolsTest, DecayedTypeTest) {
static const char Code[] = "void DecayedFunc(int x[], int y[10]) {}";
runFindAllSymbols(Code);
SymbolInfo Symbol =
- CreateSymbolInfo("DecayedFunc", SymbolInfo::Class, HeaderName, 1, {});
+ CreateSymbolInfo("DecayedFunc", SymbolInfo::Function, HeaderName, 1, {});
EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("void", Symbol.FunctionInfos.getValue().ReturnType);
- EXPECT_EQ(2u, Symbol.FunctionInfos.getValue().ParameterTypes.size());
- EXPECT_EQ("int *", Symbol.FunctionInfos.getValue().ParameterTypes[0]);
- EXPECT_EQ("int *", Symbol.FunctionInfos.getValue().ParameterTypes[1]);
}
TEST_F(FindAllSymbolsTest, CTypedefTest) {
@@ -347,28 +262,15 @@ TEST_F(FindAllSymbolsTest, CTypedefTest)
)";
runFindAllSymbols(Code);
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("size_t_", SymbolInfo::TypedefName, HeaderName, 2, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("unsigned int",
- Symbol.TypedefNameInfos.getValue().UnderlyingType);
- }
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("X", SymbolInfo::TypedefName, HeaderName, 3, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("struct X", Symbol.TypedefNameInfos.getValue().UnderlyingType);
- }
- {
- SymbolInfo Symbol =
- CreateSymbolInfo("XX", SymbolInfo::TypedefName, HeaderName, 4, {});
- EXPECT_TRUE(hasSymbol(Symbol));
- getSymbolExtraInfo(Symbol);
- EXPECT_EQ("X", Symbol.TypedefNameInfos.getValue().UnderlyingType);
- }
+ SymbolInfo Symbol =
+ CreateSymbolInfo("size_t_", SymbolInfo::TypedefName, HeaderName, 2, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("X", SymbolInfo::TypedefName, HeaderName, 3, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+
+ Symbol = CreateSymbolInfo("XX", SymbolInfo::TypedefName, HeaderName, 4, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
}
} // namespace find_all_symbols
More information about the cfe-commits
mailing list