[cfe-commits] r74858 - in /cfe/trunk: include/clang/AST/ASTLocation.h include/clang/AST/ASTNode.h include/clang/AST/DeclReferenceMap.h include/clang/Frontend/Utils.h lib/AST/ASTLocation.cpp lib/AST/ASTNode.cpp lib/AST/CMakeLists.txt lib/AST/DeclReferenceMap.cpp lib/Frontend/ResolveLocation.cpp tools/index-test/index-test.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Mon Jul 6 14:34:22 PDT 2009
Author: akirtzidis
Date: Mon Jul 6 16:34:20 2009
New Revision: 74858
URL: http://llvm.org/viewvc/llvm-project?rev=74858&view=rev
Log:
Rename 'ASTNode' -> 'ASTLocation'.
ASTLocation is a much better name for its intended purpose which to represent a "point" into the AST.
Added:
cfe/trunk/include/clang/AST/ASTLocation.h
- copied, changed from r74833, cfe/trunk/include/clang/AST/ASTNode.h
cfe/trunk/lib/AST/ASTLocation.cpp
- copied, changed from r74833, cfe/trunk/lib/AST/ASTNode.cpp
Removed:
cfe/trunk/include/clang/AST/ASTNode.h
cfe/trunk/lib/AST/ASTNode.cpp
Modified:
cfe/trunk/include/clang/AST/DeclReferenceMap.h
cfe/trunk/include/clang/Frontend/Utils.h
cfe/trunk/lib/AST/CMakeLists.txt
cfe/trunk/lib/AST/DeclReferenceMap.cpp
cfe/trunk/lib/Frontend/ResolveLocation.cpp
cfe/trunk/tools/index-test/index-test.cpp
Copied: cfe/trunk/include/clang/AST/ASTLocation.h (from r74833, cfe/trunk/include/clang/AST/ASTNode.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTLocation.h?p2=cfe/trunk/include/clang/AST/ASTLocation.h&p1=cfe/trunk/include/clang/AST/ASTNode.h&r1=74833&r2=74858&rev=74858&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTNode.h (original)
+++ cfe/trunk/include/clang/AST/ASTLocation.h Mon Jul 6 16:34:20 2009
@@ -1,4 +1,4 @@
-//===--- ASTNode.h - A <Decl, Stmt> pair ------------------------*- C++ -*-===//
+//===--- ASTLocation.h - A <Decl, Stmt> pair --------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
//
-// ASTNode is Decl or a Stmt and its immediate Decl parent.
+// ASTLocation is Decl or a Stmt and its immediate Decl parent.
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_AST_ASTNODE_H
-#define LLVM_CLANG_AST_ASTNODE_H
+#ifndef LLVM_CLANG_AST_ASTLOCATION_H
+#define LLVM_CLANG_AST_ASTLOCATION_H
#include <cassert>
@@ -26,14 +26,14 @@
/// \brief Represents a Decl or a Stmt and its immediate Decl parent. It's
/// immutable.
-class ASTNode {
+class ASTLocation {
Decl *D;
Stmt *Stm;
public:
- ASTNode() : D(0), Stm(0) {}
+ ASTLocation() : D(0), Stm(0) {}
- explicit ASTNode(const Decl *d, const Stmt *stm = 0)
+ explicit ASTLocation(const Decl *d, const Stmt *stm = 0)
: D(const_cast<Decl*>(d)), Stm(const_cast<Stmt*>(stm)) {
assert((Stm == 0 || isImmediateParent(D, Stm)) &&
"The Decl is not the immediate parent of the Stmt.");
@@ -51,10 +51,10 @@
/// \brief Checks that D is the immediate Decl parent of Node.
static bool isImmediateParent(Decl *D, Stmt *Node);
- friend bool operator==(const ASTNode &L, const ASTNode &R) {
+ friend bool operator==(const ASTLocation &L, const ASTLocation &R) {
return L.D == R.D && L.Stm == R.Stm;
}
- friend bool operator!=(const ASTNode &L, const ASTNode &R) {
+ friend bool operator!=(const ASTLocation &L, const ASTLocation &R) {
return !(L == R);
}
Removed: cfe/trunk/include/clang/AST/ASTNode.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNode.h?rev=74857&view=auto
==============================================================================
--- cfe/trunk/include/clang/AST/ASTNode.h (original)
+++ cfe/trunk/include/clang/AST/ASTNode.h (removed)
@@ -1,66 +0,0 @@
-//===--- ASTNode.h - A <Decl, Stmt> pair ------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// ASTNode is Decl or a Stmt and its immediate Decl parent.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_AST_ASTNODE_H
-#define LLVM_CLANG_AST_ASTNODE_H
-
-#include <cassert>
-
-namespace llvm {
- class raw_ostream;
-}
-
-namespace clang {
- class Decl;
- class Stmt;
-
-/// \brief Represents a Decl or a Stmt and its immediate Decl parent. It's
-/// immutable.
-class ASTNode {
- Decl *D;
- Stmt *Stm;
-
-public:
- ASTNode() : D(0), Stm(0) {}
-
- explicit ASTNode(const Decl *d, const Stmt *stm = 0)
- : D(const_cast<Decl*>(d)), Stm(const_cast<Stmt*>(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; }
-
- bool isValid() const { return D != 0; }
- bool isInvalid() const { return !isValid(); }
- bool hasStmt() const { return Stm != 0; }
-
- /// \brief Checks that D is the immediate Decl parent of Node.
- static bool isImmediateParent(Decl *D, Stmt *Node);
-
- friend bool operator==(const ASTNode &L, const ASTNode &R) {
- return L.D == R.D && L.Stm == R.Stm;
- }
- friend bool operator!=(const ASTNode &L, const ASTNode &R) {
- return !(L == R);
- }
-
- void print(llvm::raw_ostream &OS);
-};
-
-} // namespace clang
-
-#endif
Modified: cfe/trunk/include/clang/AST/DeclReferenceMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclReferenceMap.h?rev=74858&r1=74857&r2=74858&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclReferenceMap.h (original)
+++ cfe/trunk/include/clang/AST/DeclReferenceMap.h Mon Jul 6 16:34:20 2009
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
//
-// DeclReferenceMap creates a mapping from Decls to the ASTNodes that
+// DeclReferenceMap creates a mapping from Decls to the ASTLocations that
// reference them.
//
//===----------------------------------------------------------------------===//
@@ -15,14 +15,14 @@
#ifndef LLVM_CLANG_AST_DECLREFERENCEMAP_H
#define LLVM_CLANG_AST_DECLREFERENCEMAP_H
-#include "clang/AST/ASTNode.h"
+#include "clang/AST/ASTLocation.h"
#include <map>
namespace clang {
class ASTContext;
class NamedDecl;
-/// \brief Maps NamedDecls with the ASTNodes that reference them.
+/// \brief Maps NamedDecls with the ASTLocations that reference them.
///
/// References are mapped and retrieved using the primary decls
/// (see Decl::getPrimaryDecl()).
@@ -30,47 +30,47 @@
public:
explicit DeclReferenceMap(ASTContext &Ctx);
- typedef std::multimap<NamedDecl*, ASTNode> MapTy;
+ typedef std::multimap<NamedDecl*, ASTLocation> MapTy;
- class astnode_iterator {
+ class astlocation_iterator {
MapTy::iterator I;
- astnode_iterator(MapTy::iterator i) : I(i) { }
+ astlocation_iterator(MapTy::iterator i) : I(i) { }
friend class DeclReferenceMap;
public:
- typedef ASTNode value_type;
- typedef ASTNode& reference;
- typedef ASTNode* pointer;
+ typedef ASTLocation value_type;
+ typedef ASTLocation& reference;
+ typedef ASTLocation* pointer;
typedef MapTy::iterator::iterator_category iterator_category;
typedef MapTy::iterator::difference_type difference_type;
- astnode_iterator() { }
+ astlocation_iterator() { }
reference operator*() const { return I->second; }
pointer operator->() const { return &I->second; }
- astnode_iterator& operator++() {
+ astlocation_iterator& operator++() {
++I;
return *this;
}
- astnode_iterator operator++(int) {
- astnode_iterator tmp(*this);
+ astlocation_iterator operator++(int) {
+ astlocation_iterator tmp(*this);
++(*this);
return tmp;
}
- friend bool operator==(astnode_iterator L, astnode_iterator R) {
+ friend bool operator==(astlocation_iterator L, astlocation_iterator R) {
return L.I == R.I;
}
- friend bool operator!=(astnode_iterator L, astnode_iterator R) {
+ friend bool operator!=(astlocation_iterator L, astlocation_iterator R) {
return L.I != R.I;
}
};
- astnode_iterator refs_begin(NamedDecl *D) const;
- astnode_iterator refs_end(NamedDecl *D) const;
+ astlocation_iterator refs_begin(NamedDecl *D) const;
+ astlocation_iterator refs_end(NamedDecl *D) const;
bool refs_empty(NamedDecl *D) const;
private:
Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=74858&r1=74857&r2=74858&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Mon Jul 6 16:34:20 2009
@@ -36,7 +36,7 @@
class Stmt;
class ASTContext;
class SourceLocation;
-class ASTNode;
+class ASTLocation;
/// ProcessWarningOptions - Initialize the diagnostic client and process the
/// warning options specified on the command line.
@@ -103,7 +103,7 @@
/// Pointing at '100' will return a <VarDecl 'foo', IntegerLiteral '100'> pair.
/// Pointing at '++foo' will return a <FunctionDecl 'f', UnaryOperator> pair.
///
-ASTNode ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc);
+ASTLocation ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc);
} // end namespace clang
Copied: cfe/trunk/lib/AST/ASTLocation.cpp (from r74833, cfe/trunk/lib/AST/ASTNode.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTLocation.cpp?p2=cfe/trunk/lib/AST/ASTLocation.cpp&p1=cfe/trunk/lib/AST/ASTNode.cpp&r1=74833&r2=74858&rev=74858&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTNode.cpp (original)
+++ cfe/trunk/lib/AST/ASTLocation.cpp Mon Jul 6 16:34:20 2009
@@ -1,4 +1,4 @@
-//===--- ASTNode.h - A <Decl, Stmt> pair ------------------------*- C++ -*-===//
+//===--- ASTLocation.h - A <Decl, Stmt> pair --------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,11 +7,11 @@
//
//===----------------------------------------------------------------------===//
//
-// ASTNode is Decl or a Stmt and its immediate Decl parent.
+// ASTLocation is Decl or a Stmt and its immediate Decl parent.
//
//===----------------------------------------------------------------------===//
-#include "clang/AST/ASTNode.h"
+#include "clang/AST/ASTLocation.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/Expr.h"
@@ -60,13 +60,13 @@
return 0;
}
-bool ASTNode::isImmediateParent(Decl *D, Stmt *Node) {
+bool ASTLocation::isImmediateParent(Decl *D, Stmt *Node) {
assert(D && Node && "Passed null Decl or null Stmt");
return D == FindImmediateParent(D, Node);
}
-void ASTNode::print(llvm::raw_ostream &OS) {
- assert(isValid() && "ASTNode is not valid");
+void ASTLocation::print(llvm::raw_ostream &OS) {
+ assert(isValid() && "ASTLocation is not valid");
OS << "[Decl: " << getDecl()->getDeclKindName() << " ";
if (NamedDecl *ND = dyn_cast<NamedDecl>(getDecl()))
Removed: cfe/trunk/lib/AST/ASTNode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTNode.cpp?rev=74857&view=auto
==============================================================================
--- cfe/trunk/lib/AST/ASTNode.cpp (original)
+++ cfe/trunk/lib/AST/ASTNode.cpp (removed)
@@ -1,90 +0,0 @@
-//===--- ASTNode.h - A <Decl, Stmt> pair ------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// ASTNode is Decl or a Stmt and its immediate Decl parent.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/AST/ASTNode.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/Stmt.h"
-#include "clang/AST/Expr.h"
-using namespace clang;
-
-static bool isContainedInStatement(Stmt *Node, Stmt *Parent) {
- assert(Node && Parent && "Passed null Node or Parent");
-
- if (Node == Parent)
- return true;
-
- for (Stmt::child_iterator
- I = Parent->child_begin(), E = Parent->child_end(); I != E; ++I) {
- if (isContainedInStatement(Node, *I))
- return true;
- }
-
- return false;
-}
-
-static Decl *FindImmediateParent(Decl *D, Stmt *Node) {
- assert(D && Node && "Passed null Decl or null Stmt");
-
- if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
- Expr *Init = VD->getInit();
- if (Init == 0)
- return 0;
- return isContainedInStatement(Node, Init) ? D : 0;
- }
-
- if (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);
- if (Child)
- return Child;
- }
-
- assert(FD->getBody() && "If not definition we should have exited already");
- return isContainedInStatement(Node, FD->getBody()) ? D : 0;
- }
-
- return 0;
-}
-
-bool ASTNode::isImmediateParent(Decl *D, Stmt *Node) {
- assert(D && Node && "Passed null Decl or null Stmt");
- return D == FindImmediateParent(D, Node);
-}
-
-void ASTNode::print(llvm::raw_ostream &OS) {
- assert(isValid() && "ASTNode is not valid");
-
- OS << "[Decl: " << getDecl()->getDeclKindName() << " ";
- if (NamedDecl *ND = dyn_cast<NamedDecl>(getDecl()))
- OS << ND->getNameAsString();
-
- if (getStmt()) {
- ASTContext &Ctx = getDecl()->getASTContext();
- OS << " | Stmt: " << getStmt()->getStmtClassName() << " ";
- getStmt()->printPretty(OS, Ctx, 0, PrintingPolicy(Ctx.getLangOptions()));
- }
-
- OS << "] <";
-
- SourceRange Range = hasStmt() ? getStmt()->getSourceRange()
- : getDecl()->getSourceRange();
- SourceManager &SourceMgr = getDecl()->getASTContext().getSourceManager();
- Range.getBegin().print(OS, SourceMgr);
- OS << ", ";
- Range.getEnd().print(OS, SourceMgr);
- OS << ">\n";
-}
Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=74858&r1=74857&r2=74858&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Mon Jul 6 16:34:20 2009
@@ -4,7 +4,7 @@
APValue.cpp
ASTConsumer.cpp
ASTContext.cpp
- ASTNode.cpp
+ ASTLocation.cpp
CFG.cpp
DeclarationName.cpp
DeclBase.cpp
Modified: cfe/trunk/lib/AST/DeclReferenceMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclReferenceMap.cpp?rev=74858&r1=74857&r2=74858&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclReferenceMap.cpp (original)
+++ cfe/trunk/lib/AST/DeclReferenceMap.cpp Mon Jul 6 16:34:20 2009
@@ -7,15 +7,15 @@
//
//===----------------------------------------------------------------------===//
//
-// DeclReferenceMap creates a mapping from Decls to the ASTNodes that
-// references them.
+// DeclReferenceMap creates a mapping from Decls to the ASTLocations that
+// reference them.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/DeclReferenceMap.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Stmt.h"
-#include "clang/AST/ASTNode.h"
+#include "clang/AST/ASTLocation.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "llvm/Support/Compiler.h"
@@ -65,7 +65,7 @@
void StmtMapper::VisitDeclRefExpr(DeclRefExpr *Node) {
NamedDecl *PrimD = cast<NamedDecl>(Node->getDecl()->getPrimaryDecl());
- Map.insert(std::make_pair(PrimD, ASTNode(Parent, Node)));
+ Map.insert(std::make_pair(PrimD, ASTLocation(Parent, Node)));
}
void StmtMapper::VisitStmt(Stmt *Node) {
@@ -113,16 +113,16 @@
DeclMapper(Map).Visit(Ctx.getTranslationUnitDecl());
}
-DeclReferenceMap::astnode_iterator
+DeclReferenceMap::astlocation_iterator
DeclReferenceMap::refs_begin(NamedDecl *D) const {
NamedDecl *Prim = cast<NamedDecl>(D->getPrimaryDecl());
- return astnode_iterator(Map.lower_bound(Prim));
+ return astlocation_iterator(Map.lower_bound(Prim));
}
-DeclReferenceMap::astnode_iterator
+DeclReferenceMap::astlocation_iterator
DeclReferenceMap::refs_end(NamedDecl *D) const {
NamedDecl *Prim = cast<NamedDecl>(D->getPrimaryDecl());
- return astnode_iterator(Map.upper_bound(Prim));
+ return astlocation_iterator(Map.upper_bound(Prim));
}
bool DeclReferenceMap::refs_empty(NamedDecl *D) const {
Modified: cfe/trunk/lib/Frontend/ResolveLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ResolveLocation.cpp?rev=74858&r1=74857&r2=74858&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ResolveLocation.cpp (original)
+++ cfe/trunk/lib/Frontend/ResolveLocation.cpp Mon Jul 6 16:34:20 2009
@@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Frontend/Utils.h"
-#include "clang/AST/ASTNode.h"
+#include "clang/AST/ASTLocation.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Lex/Lexer.h"
@@ -321,11 +321,11 @@
/// \brief Returns the AST node that a source location points to.
///
-ASTNode clang::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) {
+ASTLocation clang::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) {
if (Loc.isInvalid())
- return ASTNode();
+ return ASTLocation();
DeclLocResolver DLR(Ctx, Loc);
DLR.Visit(Ctx.getTranslationUnitDecl());
- return ASTNode(DLR.getDecl(), DLR.getStmt());
+ return ASTLocation(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=74858&r1=74857&r2=74858&view=diff
==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Mon Jul 6 16:34:20 2009
@@ -22,13 +22,13 @@
// specified, prints some info about it.
//
// -print-refs
-// Print ASTNodes that reference the -point-at node
+// Print ASTLocations that reference the -point-at node
//
// -print-defs
-// Print ASTNodes that define the -point-at node
+// Print ASTLocations that define the -point-at node
//
// -print-decls
-// Print ASTNodes that declare the -point-at node
+// Print ASTLocations that declare the -point-at node
//
//===----------------------------------------------------------------------===//
@@ -41,7 +41,7 @@
#include "clang/Frontend/CommandLineSourceLoc.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/ASTNode.h"
+#include "clang/AST/ASTLocation.h"
#include "clang/AST/DeclReferenceMap.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
@@ -107,7 +107,7 @@
return;
DeclReferenceMap RefMap(ND->getASTContext());
- for (DeclReferenceMap::astnode_iterator
+ for (DeclReferenceMap::astlocation_iterator
I = RefMap.refs_begin(ND), E = RefMap.refs_end(ND); I != E; ++I)
I->print(OS);
break;
@@ -126,29 +126,29 @@
}
if (DefD)
- ASTNode(DefD).print(OS);
+ ASTLocation(DefD).print(OS);
break;
}
case PrintDecls :
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
while (FD) {
- ASTNode(FD).print(OS);
+ ASTLocation(FD).print(OS);
FD = FD->getPreviousDeclaration();
}
} else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
while (VD) {
- ASTNode(VD).print(OS);
+ ASTLocation(VD).print(OS);
VD = VD->getPreviousDeclaration();
}
} else
- ASTNode(D).print(OS);
+ ASTLocation(D).print(OS);
break;
}
}
-static void ProcessNode(ASTNode Node, IndexProvider &IdxProvider) {
+static void ProcessNode(ASTLocation Node, IndexProvider &IdxProvider) {
assert(Node.isValid());
Decl *D = 0;
@@ -214,7 +214,7 @@
IdxProvider.IndexAST(TU);
}
- ASTNode Node;
+ ASTLocation Node;
const std::string &FirstFile = TUnits[0]->Filename;
ASTUnit *FirstAST = TUnits[0]->AST.get();
More information about the cfe-commits
mailing list