1 //===- SelectorMap.cpp - Maps selectors to methods and messages -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // SelectorMap creates a mapping from selectors to ObjC method declarations
11 // and ObjC message expressions.
13 //===----------------------------------------------------------------------===//
15 #include "clang/Index/SelectorMap.h"
16 #include "ASTVisitor.h"
17 using namespace clang
;
22 class SelMapper
: public ASTVisitor
<SelMapper
> {
23 SelectorMap::SelMethMapTy
&SelMethMap
;
24 SelectorMap::SelRefMapTy
&SelRefMap
;
27 SelMapper(SelectorMap::SelMethMapTy
&MethMap
,
28 SelectorMap::SelRefMapTy
&RefMap
)
29 : SelMethMap(MethMap
), SelRefMap(RefMap
) { }
31 void VisitObjCMethodDecl(ObjCMethodDecl
*D
);
32 void VisitObjCMessageExpr(ObjCMessageExpr
*Node
);
33 void VisitObjCSelectorExpr(ObjCSelectorExpr
*Node
);
36 } // anonymous namespace
38 //===----------------------------------------------------------------------===//
39 // SelMapper Implementation
40 //===----------------------------------------------------------------------===//
42 void SelMapper::VisitObjCMethodDecl(ObjCMethodDecl
*D
) {
43 if (D
->getCanonicalDecl() == D
)
44 SelMethMap
.insert(std::make_pair(D
->getSelector(), D
));
45 Base::VisitObjCMethodDecl(D
);
48 void SelMapper::VisitObjCMessageExpr(ObjCMessageExpr
*Node
) {
49 ASTLocation
ASTLoc(CurrentDecl
, Node
);
50 SelRefMap
.insert(std::make_pair(Node
->getSelector(), ASTLoc
));
53 void SelMapper::VisitObjCSelectorExpr(ObjCSelectorExpr
*Node
) {
54 ASTLocation
ASTLoc(CurrentDecl
, Node
);
55 SelRefMap
.insert(std::make_pair(Node
->getSelector(), ASTLoc
));
58 //===----------------------------------------------------------------------===//
59 // SelectorMap Implementation
60 //===----------------------------------------------------------------------===//
62 SelectorMap::SelectorMap(ASTContext
&Ctx
) {
63 SelMapper(SelMethMap
, SelRefMap
).Visit(Ctx
.getTranslationUnitDecl());
66 SelectorMap::method_iterator
67 SelectorMap::methods_begin(Selector Sel
) const {
68 return method_iterator(SelMethMap
.lower_bound(Sel
));
71 SelectorMap::method_iterator
72 SelectorMap::methods_end(Selector Sel
) const {
73 return method_iterator(SelMethMap
.upper_bound(Sel
));
76 SelectorMap::astlocation_iterator
77 SelectorMap::refs_begin(Selector Sel
) const {
78 return astlocation_iterator(SelRefMap
.lower_bound(Sel
));
81 SelectorMap::astlocation_iterator
82 SelectorMap::refs_end(Selector Sel
) const {
83 return astlocation_iterator(SelRefMap
.upper_bound(Sel
));