diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-06 21:34:47 +0000 | 
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-06 21:34:47 +0000 | 
| commit | 63afa49add07b89829b83291b914a280d41debbd (patch) | |
| tree | 4e95bacf03c047453419abd28b59b2ff83bf8590 /clang/lib/AST | |
| parent | b0048027bae25332369080c6b73faab4143ed3e6 (diff) | |
| download | bcm5719-llvm-63afa49add07b89829b83291b914a280d41debbd.tar.gz bcm5719-llvm-63afa49add07b89829b83291b914a280d41debbd.zip  | |
Move ASTLocation and DeclReferenceMap from the AST library to the Index library.
llvm-svn: 74859
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/ASTLocation.cpp | 90 | ||||
| -rw-r--r-- | clang/lib/AST/DeclReferenceMap.cpp | 131 | 
2 files changed, 0 insertions, 221 deletions
diff --git a/clang/lib/AST/ASTLocation.cpp b/clang/lib/AST/ASTLocation.cpp deleted file mode 100644 index e72acf07935..00000000000 --- a/clang/lib/AST/ASTLocation.cpp +++ /dev/null @@ -1,90 +0,0 @@ -//===--- ASTLocation.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. -// -//===----------------------------------------------------------------------===// -// -//  ASTLocation is Decl or a Stmt and its immediate Decl parent. -// -//===----------------------------------------------------------------------===// - -#include "clang/AST/ASTLocation.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 ASTLocation::isImmediateParent(Decl *D, Stmt *Node) { -  assert(D && Node && "Passed null Decl or null Stmt"); -  return D == FindImmediateParent(D, Node); -} - -void ASTLocation::print(llvm::raw_ostream &OS) { -  assert(isValid() && "ASTLocation 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"; -} diff --git a/clang/lib/AST/DeclReferenceMap.cpp b/clang/lib/AST/DeclReferenceMap.cpp deleted file mode 100644 index 41f53fdd524..00000000000 --- a/clang/lib/AST/DeclReferenceMap.cpp +++ /dev/null @@ -1,131 +0,0 @@ -//===--- DeclReferenceMap.h - Map Decls to their references -----*- C++ -*-===// -// -//                     The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -//  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/ASTLocation.h" -#include "clang/AST/DeclVisitor.h" -#include "clang/AST/StmtVisitor.h" -#include "llvm/Support/Compiler.h" -using namespace clang; - -namespace { - -class VISIBILITY_HIDDEN StmtMapper : public StmtVisitor<StmtMapper> { -  DeclReferenceMap::MapTy ⤅ -  Decl *Parent; - -public: -  StmtMapper(DeclReferenceMap::MapTy &map, Decl *parent) -    : Map(map), Parent(parent) { } - -  void VisitDeclStmt(DeclStmt *Node); -  void VisitDeclRefExpr(DeclRefExpr *Node); -  void VisitStmt(Stmt *Node); -}; - -class VISIBILITY_HIDDEN DeclMapper : public DeclVisitor<DeclMapper> { -  DeclReferenceMap::MapTy ⤅ -   -public: -  DeclMapper(DeclReferenceMap::MapTy &map) -    : Map(map) { } - -  void VisitDeclContext(DeclContext *DC); -  void VisitVarDecl(VarDecl *D); -  void VisitFunctionDecl(FunctionDecl *D); -  void VisitBlockDecl(BlockDecl *D); -  void VisitDecl(Decl *D); -}; - -} // anonymous namespace - -//===----------------------------------------------------------------------===// -// StmtMapper Implementation -//===----------------------------------------------------------------------===// - -void StmtMapper::VisitDeclStmt(DeclStmt *Node) { -  DeclMapper Mapper(Map); -  for (DeclStmt::decl_iterator -         I = Node->decl_begin(), E = Node->decl_end(); I != E; ++I) -    Mapper.Visit(*I); -} - -void StmtMapper::VisitDeclRefExpr(DeclRefExpr *Node) { -  NamedDecl *PrimD = cast<NamedDecl>(Node->getDecl()->getPrimaryDecl()); -  Map.insert(std::make_pair(PrimD, ASTLocation(Parent, Node))); -} - -void StmtMapper::VisitStmt(Stmt *Node) { -  for (Stmt::child_iterator -         I = Node->child_begin(), E = Node->child_end(); I != E; ++I) -    Visit(*I); -} - -//===----------------------------------------------------------------------===// -// DeclMapper Implementation -//===----------------------------------------------------------------------===// - -void DeclMapper::VisitDeclContext(DeclContext *DC) { -  for (DeclContext::decl_iterator -         I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) -    Visit(*I); -} - -void DeclMapper::VisitFunctionDecl(FunctionDecl *D) { -  if (!D->isThisDeclarationADefinition()) -    return; -   -  StmtMapper(Map, D).Visit(D->getBody()); -} - -void DeclMapper::VisitBlockDecl(BlockDecl *D) { -  StmtMapper(Map, D).Visit(D->getBody()); -} - -void DeclMapper::VisitVarDecl(VarDecl *D) { -  if (Expr *Init = D->getInit()) -    StmtMapper(Map, D).Visit(Init); -} - -void DeclMapper::VisitDecl(Decl *D) { -  if (DeclContext *DC = dyn_cast<DeclContext>(D)) -    VisitDeclContext(DC); -} - -//===----------------------------------------------------------------------===// -// DeclReferenceMap Implementation -//===----------------------------------------------------------------------===// - -DeclReferenceMap::DeclReferenceMap(ASTContext &Ctx) { -  DeclMapper(Map).Visit(Ctx.getTranslationUnitDecl()); -} - -DeclReferenceMap::astlocation_iterator -DeclReferenceMap::refs_begin(NamedDecl *D) const { -  NamedDecl *Prim = cast<NamedDecl>(D->getPrimaryDecl()); -  return astlocation_iterator(Map.lower_bound(Prim));   -} - -DeclReferenceMap::astlocation_iterator -DeclReferenceMap::refs_end(NamedDecl *D) const { -  NamedDecl *Prim = cast<NamedDecl>(D->getPrimaryDecl()); -  return astlocation_iterator(Map.upper_bound(Prim));   -} - -bool DeclReferenceMap::refs_empty(NamedDecl *D) const { -  NamedDecl *Prim = cast<NamedDecl>(D->getPrimaryDecl()); -  return refs_begin(Prim) == refs_end(Prim);   -}  | 

