41 for (
const auto& f : files)
43 std::cout <<
"INFO\t Parsing '" << f <<
"'\n";
44 auto cppAst = parser.
parseFile(f.c_str());
60 fileAsts_.emplace_back(std::move(cppAst));
65 if (compound->
name().empty())
67 auto& childNode = parentTypeNode->
children[compound->
name()];
68 childNode.cppObjSet.insert(compound);
69 childNode.parent = parentTypeNode;
83 if (cppCompound == NULL)
99 childNode.
parent = typeNode;
107 childNode.
parent = typeNode;
115 childNode.
parent = typeNode;
122 childNode.
parent = typeNode;
128 if (!(fwdCls->attr() &
kFriend))
132 childNode.
parent = typeNode;
145 if (typeNode ==
nullptr)
147 size_t nameBegPos = 0;
148 size_t nameEndPos =
name.find(
"::", nameBegPos);
149 if (nameEndPos == std::string::npos)
151 for (; typeNode != NULL; typeNode = typeNode->
parent)
153 CppTypeTree::const_iterator itr = typeNode->
children.find(
name);
154 if (itr != typeNode->
children.end())
161 auto nameToLookFor =
name.substr(nameBegPos, nameEndPos - nameBegPos);
162 typeNode =
nameLookup(nameToLookFor, typeNode);
167 nameBegPos = nameEndPos + 2;
168 nameEndPos =
name.find(
"::", nameBegPos);
169 if (nameEndPos == std::string::npos)
170 nameEndPos =
name.length();
171 nameToLookFor =
name.substr(nameBegPos, nameEndPos - nameBegPos);
172 auto itr = typeNode->
children.find(nameToLookFor);
173 if (itr == typeNode->
children.end())
175 typeNode = &itr->second;
176 }
while (nameEndPos <
name.length());
183 std::vector<const CppTypeTreeNode*> nextLevelNodes(1, parentNode ? parentNode : &
cppTypeTreeRoot_);
187 std::vector<const CppTypeTreeNode*> currentLevelNodes;
188 currentLevelNodes.swap(nextLevelNodes);
189 assert(nextLevelNodes.empty());
190 for (
const auto* node : currentLevelNodes)
192 for (
const auto& child : node->children)
194 if (child.first ==
name)
195 return &(child.second);
196 nextLevelNodes.push_back(&(child.second));
199 }
while (!nextLevelNodes.empty());
Parses C++ source and generates an AST.
CppCompoundPtr parseFile(const std::string &filename)
Represents an entire C++ program.
CppProgram(const std::string &folder, CppParser parser=CppParser(), const CppProgFileSelecter &fileSelector=selectHeadersOnly)
CppCompoundArray fileAsts_
Array of all top level ASTs corresponding to files.
CppTypeTreeNode cppTypeTreeRoot_
Repository of all compound objects arranged as type-tree.
void addCppAst(CppCompoundPtr cppAst)
Adds a new file AST to this program.
void addCompound(CppCompound *compound, CppCompound *parent)
void loadType(CppCompound *cppCompound, CppTypeTreeNode *typeNode)
const CppTypeTreeNode * nameLookup(const std::string &name, const CppTypeTreeNode *beginFrom=nullptr) const
Finds the CppTypeTreeNode object corresponding to a given name.
const CppTypeTreeNode * searchTypeNode(const std::string &name, const CppTypeTreeNode *parentNode=nullptr) const
Searches down (in breadth first manner) the CppTypeTreeNode object corresponding to a given name.
CppObjToTypeNodeMap cppObjToTypeNode_
std::unique_ptr< CppCompound > CppCompoundPtr
bool forEachMember(CppCompoundEPtr compound, std::function< bool(CppObj *)> visitor)
bool isCppFile(CppCompoundEPtr compound)
bool isFwdClsDecl(CppObj *cppObj)
bool isEnum(CppObj *cppObj)
bool isUsingDecl(CppObj *cppObj)
bool isCompound(CppObj *cppObj)
bool isTypedefName(CppObj *cppObj)
bool isFunctionPtr(CppObj *cppObj)
std::function< bool(const std::string &)> CppProgFileSelecter
std::string & name(CppVar *var)
All classes, structs, unions, and namespaces can be classified as a Compound object.
Function pointer type definition using typedef, e.g.
An abstract class that is used as base class of all other classes.
CppObjSet cppObjSet
This needs to be a set because same namespace can be defined multiple times.
void collectFiles(std::vector< std::string > &files, const fs::path &path, const CppProgFileSelecter &fileSelector)