bool hasCallee() const { return begin() != end(); }
- std::string getName(ASTContext &Ctx) { return F.getPrintableName(Ctx); }
+ std::string getName() { return F.getPrintableName(); }
};
class CallGraph {
Decl *getDecl(ASTContext &AST);
/// \brief Get a printable name for debugging purpose.
- std::string getPrintableName(ASTContext &Ctx);
+ std::string getPrintableName();
/// \brief Get an Entity associated with the given Decl.
/// \returns Null if an Entity cannot refer to this Decl.
void CallGraph::print(llvm::raw_ostream &os) {
for (iterator I = begin(), E = end(); I != E; ++I) {
if (I->second->hasCallee()) {
- ASTContext &Ctx = *CallerCtx[I->second];
- os << "function: " << I->first.getPrintableName(Ctx).c_str()
+ os << "function: " << I->first.getPrintableName()
<< " calls:\n";
for (CallGraphNode::iterator CI = I->second->begin(),
CE = I->second->end(); CI != CE; ++CI) {
- os << " " << CI->second->getName(Ctx).c_str();
+ os << " " << CI->second->getName().c_str();
}
os << '\n';
}
return EntityGetter(Prog).Visit(D);
}
+std::string EntityImpl::getPrintableName() {
+ return std::string(Id->getKeyData(), Id->getKeyData() + Id->getKeyLength());
+}
+
//===----------------------------------------------------------------------===//
// Entity Implementation
//===----------------------------------------------------------------------===//
return Val.get<EntityImpl *>()->getDecl(AST);
}
-std::string Entity::getPrintableName(ASTContext &Ctx) {
- if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(getDecl(Ctx))) {
- return ND->getNameAsString();
+std::string Entity::getPrintableName() {
+ if (isInvalid())
+ return "<< Invalid >>";
+
+ if (Decl *D = Val.dyn_cast<Decl *>()) {
+ if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
+ return ND->getNameAsString();
+ else
+ return std::string();
}
- return std::string();
+
+ return Val.get<EntityImpl *>()->getPrintableName();
}
/// \brief Get an Entity associated with the given Decl.
/// \brief Get an Entity associated with the given Decl.
/// \returns Null if an Entity cannot refer to this Decl.
static Entity get(Decl *D, ProgramImpl &Prog);
+
+ std::string getPrintableName();
void Profile(llvm::FoldingSetNodeID &ID) const {
Profile(ID, Parent, Id, IdNS);