namespace clang {
class Decl;
class Stmt;
+ class SourceRange;
namespace idx {
bool isValid() const { return D != 0; }
bool isInvalid() const { return !isValid(); }
- bool hasStmt() const { return Stm != 0; }
+ bool isDecl() const { return isValid() && Stm == 0; }
+ bool isStmt() const { return isValid() && Stm != 0; }
+
+ SourceRange getSourceRange() const;
/// \brief Checks that D is the immediate Decl parent of Node.
static bool isImmediateParent(Decl *D, Stmt *Node);
return D == FindImmediateParent(D, Node);
}
+SourceRange ASTLocation::getSourceRange() const {
+ return isDecl() ? getDecl()->getSourceRange() : getStmt()->getSourceRange();
+}
+
void ASTLocation::print(llvm::raw_ostream &OS) {
assert(isValid() && "ASTLocation is not valid");
OS << "] <";
- SourceRange Range = hasStmt() ? getStmt()->getSourceRange()
- : getDecl()->getSourceRange();
+ SourceRange Range = getSourceRange();
SourceManager &SourceMgr = getDecl()->getASTContext().getSourceManager();
Range.getBegin().print(OS, SourceMgr);
OS << ", ";