Argyrios Kyrtzidis | 557b1d2 | 2009-07-29 23:40:58 +0000 | [diff] [blame] | 1 | //===- SelectorMap.cpp - Maps selectors to methods and messages -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // SelectorMap creates a mapping from selectors to ObjC method declarations |
| 11 | // and ObjC message expressions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Index/SelectorMap.h" |
| 16 | #include "ASTVisitor.h" |
| 17 | #include "llvm/Support/Compiler.h" |
| 18 | using namespace clang; |
| 19 | using namespace idx; |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | class VISIBILITY_HIDDEN SelMapper : public ASTVisitor<SelMapper> { |
| 24 | SelectorMap::SelMethMapTy &SelMethMap; |
| 25 | SelectorMap::SelRefMapTy &SelRefMap; |
| 26 | |
| 27 | public: |
| 28 | SelMapper(SelectorMap::SelMethMapTy &MethMap, |
| 29 | SelectorMap::SelRefMapTy &RefMap) |
| 30 | : SelMethMap(MethMap), SelRefMap(RefMap) { } |
| 31 | |
| 32 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 33 | void VisitObjCMessageExpr(ObjCMessageExpr *Node); |
| 34 | void VisitObjCSelectorExpr(ObjCSelectorExpr *Node); |
| 35 | }; |
| 36 | |
| 37 | } // anonymous namespace |
| 38 | |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | // SelMapper Implementation |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | |
| 43 | void SelMapper::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 44 | if (D->getCanonicalDecl() == D) |
| 45 | SelMethMap.insert(std::make_pair(D->getSelector(), D)); |
| 46 | Base::VisitObjCMethodDecl(D); |
| 47 | } |
| 48 | |
| 49 | void SelMapper::VisitObjCMessageExpr(ObjCMessageExpr *Node) { |
| 50 | ASTLocation ASTLoc(CurrentDecl, Node); |
| 51 | SelRefMap.insert(std::make_pair(Node->getSelector(), ASTLoc)); |
| 52 | } |
| 53 | |
| 54 | void SelMapper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { |
| 55 | ASTLocation ASTLoc(CurrentDecl, Node); |
| 56 | SelRefMap.insert(std::make_pair(Node->getSelector(), ASTLoc)); |
| 57 | } |
| 58 | |
| 59 | //===----------------------------------------------------------------------===// |
| 60 | // SelectorMap Implementation |
| 61 | //===----------------------------------------------------------------------===// |
| 62 | |
| 63 | SelectorMap::SelectorMap(ASTContext &Ctx) { |
| 64 | SelMapper(SelMethMap, SelRefMap).Visit(Ctx.getTranslationUnitDecl()); |
| 65 | } |
| 66 | |
| 67 | SelectorMap::method_iterator |
| 68 | SelectorMap::methods_begin(Selector Sel) const { |
| 69 | return method_iterator(SelMethMap.lower_bound(Sel)); |
| 70 | } |
| 71 | |
| 72 | SelectorMap::method_iterator |
| 73 | SelectorMap::methods_end(Selector Sel) const { |
| 74 | return method_iterator(SelMethMap.upper_bound(Sel)); |
| 75 | } |
| 76 | |
| 77 | SelectorMap::astlocation_iterator |
| 78 | SelectorMap::refs_begin(Selector Sel) const { |
| 79 | return astlocation_iterator(SelRefMap.lower_bound(Sel)); |
| 80 | } |
| 81 | |
| 82 | SelectorMap::astlocation_iterator |
| 83 | SelectorMap::refs_end(Selector Sel) const { |
| 84 | return astlocation_iterator(SelRefMap.upper_bound(Sel)); |
| 85 | } |