[cfe-commits] r75221 - /cfe/trunk/lib/Index/ResolveLocation.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Thu Jul 9 20:41:28 PDT 2009
Author: akirtzidis
Date: Thu Jul 9 22:41:26 2009
New Revision: 75221
URL: http://llvm.org/viewvc/llvm-project?rev=75221&view=rev
Log:
Simplify a bit by using functions instead of checking enum values. No functionality change.
Modified:
cfe/trunk/lib/Index/ResolveLocation.cpp
Modified: cfe/trunk/lib/Index/ResolveLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ResolveLocation.cpp?rev=75221&r1=75220&r2=75221&view=diff
==============================================================================
--- cfe/trunk/lib/Index/ResolveLocation.cpp (original)
+++ cfe/trunk/lib/Index/ResolveLocation.cpp Thu Jul 9 22:41:26 2009
@@ -40,6 +40,21 @@
RangePos CheckRange(Decl *D) { return CheckRange(D->getSourceRange()); }
RangePos CheckRange(Stmt *Node) { return CheckRange(Node->getSourceRange()); }
+ template <typename T>
+ bool isBeforeLocation(T *Node) {
+ return CheckRange(Node) == BeforeLoc;
+ }
+
+ template <typename T>
+ bool ContainsLocation(T *Node) {
+ return CheckRange(Node) == ContainsLoc;
+ }
+
+ template <typename T>
+ bool isAfterLocation(T *Node) {
+ return CheckRange(Node) == AfterLoc;
+ }
+
public:
LocResolverBase(ASTContext &ctx, SourceLocation loc)
: Ctx(ctx), Loc(loc) {}
@@ -83,8 +98,8 @@
} // anonymous namespace
ASTLocation StmtLocResolver::VisitDeclStmt(DeclStmt *Node) {
- assert(CheckRange(Node) == ContainsLoc
- && "Should visit only after verifying that loc is in range");
+ assert(ContainsLocation(Node) &&
+ "Should visit only after verifying that loc is in range");
// Search all declarations of this DeclStmt.
for (DeclStmt::decl_iterator
@@ -100,8 +115,8 @@
}
ASTLocation StmtLocResolver::VisitStmt(Stmt *Node) {
- assert(CheckRange(Node) == ContainsLoc
- && "Should visit only after verifying that loc is in range");
+ assert(ContainsLocation(Node) &&
+ "Should visit only after verifying that loc is in range");
// Search the child statements.
for (Stmt::child_iterator
@@ -132,8 +147,8 @@
}
ASTLocation DeclLocResolver::VisitFunctionDecl(FunctionDecl *D) {
- assert(CheckRange(D) == ContainsLoc
- && "Should visit only after verifying that loc is in range");
+ assert(ContainsLocation(D) &&
+ "Should visit only after verifying that loc is in range");
// First, search through the parameters of the function.
for (FunctionDecl::param_iterator
@@ -170,31 +185,31 @@
// Finally, search through the body of the function.
Stmt *Body = D->getBody();
assert(Body && "Expected definition");
- assert(CheckRange(Body) != BeforeLoc
- && "This function is supposed to contain the loc");
- if (CheckRange(Body) == AfterLoc)
+ assert(!isBeforeLocation(Body) &&
+ "This function is supposed to contain the loc");
+ if (isAfterLocation(Body))
return ASTLocation(D);
// The body contains the location.
- assert(CheckRange(Body) == ContainsLoc);
+ assert(ContainsLocation(Body));
return StmtLocResolver(Ctx, Loc, D).Visit(Body);
}
ASTLocation DeclLocResolver::VisitVarDecl(VarDecl *D) {
- assert(CheckRange(D) == ContainsLoc
- && "Should visit only after verifying that loc is in range");
+ assert(ContainsLocation(D) &&
+ "Should visit only after verifying that loc is in range");
// Check whether the location points to the init expression.
Expr *Init = D->getInit();
- if (Init && CheckRange(Init) == ContainsLoc)
+ if (Init && ContainsLocation(Init))
return StmtLocResolver(Ctx, Loc, D).Visit(Init);
return ASTLocation(D);
}
ASTLocation DeclLocResolver::VisitDecl(Decl *D) {
- assert(CheckRange(D) == ContainsLoc
- && "Should visit only after verifying that loc is in range");
+ assert(ContainsLocation(D) &&
+ "Should visit only after verifying that loc is in range");
return ASTLocation(D);
}
More information about the cfe-commits
mailing list