[cfe-commits] r74798 - in /cfe/trunk: include/clang/Frontend/Utils.h lib/Frontend/ResolveLocation.cpp tools/index-test/index-test.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Sun Jul 5 15:21:40 PDT 2009
Author: akirtzidis
Date: Sun Jul 5 17:21:40 2009
New Revision: 74798
URL: http://llvm.org/viewvc/llvm-project?rev=74798&view=rev
Log:
Make use of ASTNode for return value of clang::ResolveLocationInAST() and in the index-test tool.
Modified:
cfe/trunk/include/clang/Frontend/Utils.h
cfe/trunk/lib/Frontend/ResolveLocation.cpp
cfe/trunk/tools/index-test/index-test.cpp
Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=74798&r1=74797&r2=74798&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Sun Jul 5 17:21:40 2009
@@ -36,6 +36,7 @@
class Stmt;
class ASTContext;
class SourceLocation;
+class ASTNode;
/// ProcessWarningOptions - Initialize the diagnostic client and process the
/// warning options specified on the command line.
@@ -102,8 +103,7 @@
/// Pointing at '100' will return a <VarDecl 'foo', IntegerLiteral '100'> pair.
/// Pointing at '++foo' will return a <FunctionDecl 'f', UnaryOperator> pair.
///
-std::pair<Decl *, Stmt *> ResolveLocationInAST(ASTContext &Ctx,
- SourceLocation Loc);
+ASTNode ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc);
} // end namespace clang
Modified: cfe/trunk/lib/Frontend/ResolveLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ResolveLocation.cpp?rev=74798&r1=74797&r2=74798&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ResolveLocation.cpp (original)
+++ cfe/trunk/lib/Frontend/ResolveLocation.cpp Sun Jul 5 17:21:40 2009
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Frontend/Utils.h"
+#include "clang/AST/ASTNode.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Lex/Lexer.h"
@@ -313,12 +314,11 @@
/// \brief Returns the AST node that a source location points to.
///
-std::pair<Decl *, Stmt *>
-clang::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) {
+ASTNode clang::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) {
if (Loc.isInvalid())
- return std::make_pair((Decl*)0, (Stmt*)0);
+ return ASTNode();
DeclLocResolver DLR(Ctx, Loc);
DLR.Visit(Ctx.getTranslationUnitDecl());
- return DLR.getResult();
+ return ASTNode(DLR.getDecl(), DLR.getStmt());
}
Modified: cfe/trunk/tools/index-test/index-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/index-test/index-test.cpp?rev=74798&r1=74797&r2=74798&view=diff
==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Sun Jul 5 17:21:40 2009
@@ -28,6 +28,7 @@
#include "clang/Frontend/CommandLineSourceLoc.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Stmt.h"
+#include "clang/AST/ASTNode.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/STLExtras.h"
@@ -77,13 +78,7 @@
return 1;
}
- struct ASTPoint {
- Decl *D;
- Stmt *Node;
- ASTPoint() : D(0), Node(0) {}
- };
-
- ASTPoint Point;
+ ASTNode Node;
if (!PointAtLocation.empty()) {
const std::string &Filename = PointAtLocation[0].FileName;
@@ -114,30 +109,31 @@
return 1;
}
- llvm::tie(Point.D, Point.Node) =
- ResolveLocationInAST(AST->getASTContext(), Loc);
- if (Point.D == 0) {
+ Node = ResolveLocationInAST(AST->getASTContext(), Loc);
+ if (Node.isInvalid()) {
llvm::errs() << "[" << InFile << "] Error: " <<
"Couldn't resolve source location (no declaration found)\n";
return 1;
}
}
- if (Point.D) {
+ if (Node.isValid()) {
llvm::raw_ostream &OS = llvm::outs();
- OS << "Declaration node at point: " << Point.D->getDeclKindName() << " ";
- if (NamedDecl *ND = dyn_cast<NamedDecl>(Point.D))
+ OS << "Declaration node at point: " << Node.getDecl()->getDeclKindName()
+ << " ";
+ if (NamedDecl *ND = dyn_cast<NamedDecl>(Node.getDecl()))
OS << ND->getNameAsString();
OS << "\n";
- if (const char *Comment = AST->getASTContext().getCommentForDecl(Point.D))
+ if (const char *Comment =
+ AST->getASTContext().getCommentForDecl(Node.getDecl()))
OS << "Comment associated with this declaration:\n" << Comment << "\n";
- if (Point.Node) {
- OS << "Statement node at point: " << Point.Node->getStmtClassName()
+ if (Node.getStmt()) {
+ OS << "Statement node at point: " << Node.getStmt()->getStmtClassName()
<< " ";
- Point.Node->printPretty(OS, AST->getASTContext(), 0,
- PrintingPolicy(AST->getASTContext().getLangOptions()));
+ Node.getStmt()->printPretty(OS, AST->getASTContext(), 0,
+ PrintingPolicy(AST->getASTContext().getLangOptions()));
OS << "\n";
}
}
More information about the cfe-commits
mailing list