summaryrefslogtreecommitdiffstats
path: root/lib/Index/SelectorMap.cpp
blob: 0f11e31a0dec9f13fdec9806a229d4d4d4d2553c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//===- SelectorMap.cpp - Maps selectors to methods and messages -*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  SelectorMap creates a mapping from selectors to ObjC method declarations
//  and ObjC message expressions.
//
//===----------------------------------------------------------------------===//

#include "clang/Index/SelectorMap.h"
#include "ASTVisitor.h"
using namespace clang;
using namespace idx;

namespace {

class SelMapper : public ASTVisitor<SelMapper> {
  SelectorMap::SelMethMapTy &SelMethMap;
  SelectorMap::SelRefMapTy &SelRefMap;

public:
  SelMapper(SelectorMap::SelMethMapTy &MethMap,
            SelectorMap::SelRefMapTy &RefMap)
    : SelMethMap(MethMap), SelRefMap(RefMap) { }

  void VisitObjCMethodDecl(ObjCMethodDecl *D);
  void VisitObjCMessageExpr(ObjCMessageExpr *Node);
  void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
};

} // anonymous namespace

//===----------------------------------------------------------------------===//
// SelMapper Implementation
//===----------------------------------------------------------------------===//

void SelMapper::VisitObjCMethodDecl(ObjCMethodDecl *D) {
  if (D->getCanonicalDecl() == D)
    SelMethMap.insert(std::make_pair(D->getSelector(), D));
  Base::VisitObjCMethodDecl(D);
}

void SelMapper::VisitObjCMessageExpr(ObjCMessageExpr *Node) {
  ASTLocation ASTLoc(CurrentDecl, Node);
  SelRefMap.insert(std::make_pair(Node->getSelector(), ASTLoc));
}

void SelMapper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
  ASTLocation ASTLoc(CurrentDecl, Node);
  SelRefMap.insert(std::make_pair(Node->getSelector(), ASTLoc));
}

//===----------------------------------------------------------------------===//
// SelectorMap Implementation
//===----------------------------------------------------------------------===//

SelectorMap::SelectorMap(ASTContext &Ctx) {
  SelMapper(SelMethMap, SelRefMap).Visit(Ctx.getTranslationUnitDecl());
}

SelectorMap::method_iterator
SelectorMap::methods_begin(Selector Sel) const {
  return method_iterator(SelMethMap.lower_bound(Sel));
}

SelectorMap::method_iterator
SelectorMap::methods_end(Selector Sel) const {
  return method_iterator(SelMethMap.upper_bound(Sel));
}

SelectorMap::astlocation_iterator
SelectorMap::refs_begin(Selector Sel) const {
  return astlocation_iterator(SelRefMap.lower_bound(Sel));
}

SelectorMap::astlocation_iterator
SelectorMap::refs_end(Selector Sel) const {
  return astlocation_iterator(SelRefMap.upper_bound(Sel));
}
OpenPOWER on IntegriCloud