diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-09-29 19:39:53 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-09-29 19:39:53 +0000 |
commit | 1ebd7405be6dbea497d5ec72ab15e65debb0d72e (patch) | |
tree | 9080907d503407d1453fe7e1f7c60296c01d09cb | |
parent | a92ba278fd0cc1679a9e3b6ca9aaf0713cd8fe6e (diff) |
Add more const-goodness to ASTLocation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83087 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Index/ASTLocation.h | 15 | ||||
-rw-r--r-- | lib/Analysis/CallGraph.cpp | 2 | ||||
-rw-r--r-- | lib/Index/ASTLocation.cpp | 24 |
3 files changed, 20 insertions, 21 deletions
diff --git a/include/clang/Index/ASTLocation.h b/include/clang/Index/ASTLocation.h index 60af9e672c..ba213052ab 100644 --- a/include/clang/Index/ASTLocation.h +++ b/include/clang/Index/ASTLocation.h @@ -37,22 +37,21 @@ namespace idx { /// like the declaration context, ASTContext, etc. /// class ASTLocation { - Decl *D; - Stmt *Stm; + const Decl *D; + const Stmt *Stm; public: ASTLocation() : D(0), Stm(0) {} - explicit ASTLocation(const Decl *d, const Stmt *stm = 0) - : D(const_cast<Decl*>(d)), Stm(const_cast<Stmt*>(stm)) { + explicit ASTLocation(const Decl *d, const Stmt *stm = 0) : D(d), Stm(stm) { assert((Stm == 0 || isImmediateParent(D, Stm)) && "The Decl is not the immediate parent of the Stmt."); } const Decl *getDecl() const { return D; } const Stmt *getStmt() const { return Stm; } - Decl *getDecl() { return D; } - Stmt *getStmt() { return Stm; } + Decl *getDecl() { return const_cast<Decl*>(D); } + Stmt *getStmt() { return const_cast<Stmt*>(Stm); } bool isValid() const { return D != 0; } bool isInvalid() const { return !isValid(); } @@ -72,8 +71,8 @@ public: SourceRange getSourceRange() const; /// \brief Checks that D is the immediate Decl parent of Node. - static bool isImmediateParent(Decl *D, Stmt *Node); - static Decl *FindImmediateParent(Decl *D, Stmt *Node); + static bool isImmediateParent(const Decl *D, const Stmt *Node); + static const Decl *FindImmediateParent(const Decl *D, const Stmt *Node); friend bool operator==(const ASTLocation &L, const ASTLocation &R) { return L.D == R.D && L.Stm == R.Stm; diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp index fdca1dc2f4..f605bd98f5 100644 --- a/lib/Analysis/CallGraph.cpp +++ b/lib/Analysis/CallGraph.cpp @@ -52,7 +52,7 @@ void CGBuilder::VisitCallExpr(CallExpr *CE) { Entity Ent = Entity::get(CalleeDecl, G.getProgram()); CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent); - Decl *Parent = ASTLocation::FindImmediateParent(FD, CE); + const Decl *Parent = ASTLocation::FindImmediateParent(FD, CE); CallerNode->addCallee(ASTLocation(Parent, CE), CalleeNode); } diff --git a/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp index d6f5cc7cfb..7bad129d6c 100644 --- a/lib/Index/ASTLocation.cpp +++ b/lib/Index/ASTLocation.cpp @@ -47,13 +47,13 @@ Decl *ASTLocation::getReferencedDecl() { } -static bool isContainedInStatement(Stmt *Node, Stmt *Parent) { +static bool isContainedInStatement(const Stmt *Node, const Stmt *Parent) { assert(Node && Parent && "Passed null Node or Parent"); if (Node == Parent) return true; - for (Stmt::child_iterator + for (Stmt::const_child_iterator I = Parent->child_begin(), E = Parent->child_end(); I != E; ++I) { if (*I) if (isContainedInStatement(Node, *I)) @@ -63,23 +63,23 @@ static bool isContainedInStatement(Stmt *Node, Stmt *Parent) { return false; } -Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) { +const Decl *ASTLocation::FindImmediateParent(const Decl *D, const Stmt *Node) { assert(D && Node && "Passed null Decl or null Stmt"); - if (VarDecl *VD = dyn_cast<VarDecl>(D)) { - Expr *Init = VD->getInit(); + if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { + const Expr *Init = VD->getInit(); if (Init == 0) return 0; return isContainedInStatement(Node, Init) ? D : 0; } - if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { if (!FD->isThisDeclarationADefinition()) return 0; for (DeclContext::decl_iterator I = FD->decls_begin(), E = FD->decls_end(); I != E; ++I) { - Decl *Child = FindImmediateParent(*I, Node); + const Decl *Child = FindImmediateParent(*I, Node); if (Child) return Child; } @@ -88,13 +88,13 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) { return isContainedInStatement(Node, FD->getBody()) ? D : 0; } - if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { + if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { if (!MD->getBody()) return 0; for (DeclContext::decl_iterator I = MD->decls_begin(), E = MD->decls_end(); I != E; ++I) { - Decl *Child = FindImmediateParent(*I, Node); + const Decl *Child = FindImmediateParent(*I, Node); if (Child) return Child; } @@ -103,10 +103,10 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) { return isContainedInStatement(Node, MD->getBody()) ? D : 0; } - if (BlockDecl *BD = dyn_cast<BlockDecl>(D)) { + if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { for (DeclContext::decl_iterator I = BD->decls_begin(), E = BD->decls_end(); I != E; ++I) { - Decl *Child = FindImmediateParent(*I, Node); + const Decl *Child = FindImmediateParent(*I, Node); if (Child) return Child; } @@ -118,7 +118,7 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) { return 0; } -bool ASTLocation::isImmediateParent(Decl *D, Stmt *Node) { +bool ASTLocation::isImmediateParent(const Decl *D, const Stmt *Node) { assert(D && Node && "Passed null Decl or null Stmt"); return D == FindImmediateParent(D, Node); } |