Index: include-fixer/InMemoryXrefsDB.cpp =================================================================== --- include-fixer/InMemoryXrefsDB.cpp +++ include-fixer/InMemoryXrefsDB.cpp @@ -21,16 +21,17 @@ llvm::SmallVector 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; + // Since we don't have all symbol information here, we just construct a + // dummy SymbolInfo with the given contexts and header path. + std::vector Contexts; for (auto IdentiferContext = Names.rbegin() + 1; IdentiferContext != Names.rend(); ++IdentiferContext) { - Info.Contexts.push_back( + Contexts.push_back( {SymbolInfo::ContextType::Namespace, *IdentiferContext}); } + SymbolInfo Info = + SymbolInfo::CreateClassSymbolInfo(Names.back(), Header, Contexts, 1); + this->LookupTable[Info.Name].push_back(Info); } } Index: include-fixer/find-all-symbols/SymbolInfo.h =================================================================== --- include-fixer/find-all-symbols/SymbolInfo.h +++ include-fixer/find-all-symbols/SymbolInfo.h @@ -21,7 +21,6 @@ namespace find_all_symbols { /// \brief Contains all information for a Symbol. -// FIXME: add static members for creating complete instances. struct SymbolInfo { enum SymbolKind { Function, @@ -87,6 +86,33 @@ bool operator==(const SymbolInfo &Symbol) const; bool operator<(const SymbolInfo &Symbol) const; + + static SymbolInfo + CreateFunctionSymbolInfo(const std::string &Name, const std::string &FilePath, + const std::vector &Contexts, int LineNumber, + const FunctionInfo &FuncInfo); + + static SymbolInfo CreateClassSymbolInfo(const std::string &Name, + const std::string &FilePath, + const std::vector &Contexts, + int LineNumber); + + static SymbolInfo + CreateVariableSymbolInfo(const std::string &Name, const std::string &FilePath, + const std::vector &Contexts, int LineNumber, + const VariableInfo &VarInfo); + + static SymbolInfo + CreateTypedefNameSymbolInfo(const std::string &Name, + const std::string &FilePath, + const std::vector &Contexts, + int LineNumber, const TypedefNameInfo &TDInfo); + +private: + static void SetCommonInfo(const std::string &Name, SymbolKind Kind, + const std::string &FilePath, + const std::vector &Contexts, + int LineNumber, SymbolInfo *Info); }; /// \brief Write SymbolInfos to a stream (YAML format). Index: include-fixer/find-all-symbols/SymbolInfo.cpp =================================================================== --- include-fixer/find-all-symbols/SymbolInfo.cpp +++ include-fixer/find-all-symbols/SymbolInfo.cpp @@ -87,6 +87,57 @@ namespace clang { namespace find_all_symbols { +void SymbolInfo::SetCommonInfo(const std::string &Name, + SymbolKind Kind, const std::string &FilePath, + const std::vector &Contexts, + int LineNumber, SymbolInfo *Info) { + Info->Name = Name; + Info->Type = Kind; + Info->FilePath = FilePath; + Info->Contexts = Contexts; + Info->LineNumber = LineNumber; +} + +SymbolInfo SymbolInfo::CreateFunctionSymbolInfo( + const std::string &Name, const std::string &FilePath, + const std::vector &Contexts, int LineNumber, + const FunctionInfo &FuncInfo) { + + SymbolInfo Ret; + SetCommonInfo(Name, Function, FilePath, Contexts, LineNumber, &Ret); + Ret.FunctionInfos = FuncInfo; + return Ret; +} + +SymbolInfo SymbolInfo::CreateClassSymbolInfo( + const std::string &Name, const std::string &FilePath, + const std::vector &Contexts, int LineNumber) { + + SymbolInfo Ret; + SetCommonInfo(Name, Class, FilePath, Contexts, LineNumber, &Ret); + return Ret; +} + +SymbolInfo SymbolInfo::CreateVariableSymbolInfo( + const std::string &Name, const std::string &FilePath, + const std::vector &Contexts, int LineNumber, + const VariableInfo &VarInfo) { + SymbolInfo Ret; + SetCommonInfo(Name, Variable, FilePath, Contexts, LineNumber, &Ret); + Ret.VariableInfos = VarInfo; + return Ret; +} + +SymbolInfo SymbolInfo::CreateTypedefNameSymbolInfo( + const std::string &Name, const std::string &FilePath, + const std::vector &Contexts, int LineNumber, + const TypedefNameInfo &TDInfo) { + SymbolInfo Ret; + SetCommonInfo(Name, TypedefName, FilePath, Contexts, LineNumber, &Ret); + Ret.TypedefNameInfos = TDInfo; + return Ret; +} + bool SymbolInfo::operator==(const SymbolInfo &Symbol) const { return Name == Symbol.Name && FilePath == Symbol.FilePath && LineNumber == Symbol.LineNumber && Contexts == Symbol.Contexts;