116c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===//
216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//                     The LLVM Compiler Infrastructure
416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// This file is distributed under the University of Illinois Open Source
616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// License. See LICENSE.TXT for details.
716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===----------------------------------------------------------------------===//
916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
102e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// This file defines routines for manipulating CXCursors. It should be the
112e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// only file that has internal knowledge of the encoding of the data in
122e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// CXCursor.
1316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
1416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===----------------------------------------------------------------------===//
1516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
160a90d32523bfe5fa63e11b648686c9699f786d15Ted Kremenek#include "CXTranslationUnit.h"
1716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "CXCursor.h"
18ed122735639d83c10f18c28c7fd117bfcd0f62cbTed Kremenek#include "CXString.h"
19f59edb96b2d0bfe612b732f19519ab84bb995bd4Chandler Carruth#include "CXType.h"
20f59edb96b2d0bfe612b732f19519ab84bb995bd4Chandler Carruth#include "clang-c/Index.h"
210b5ca510fb00eeb19ab82ebfd3c2585404bc9aa8David Blaikie#include "clang/AST/Attr.h"
2216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "clang/AST/Decl.h"
236931900f43cea558c6974075256c07728dbfecc6Douglas Gregor#include "clang/AST/DeclCXX.h"
24283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/DeclObjC.h"
25aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis#include "clang/AST/DeclTemplate.h"
26283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/Expr.h"
271f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor#include "clang/AST/ExprCXX.h"
28aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis#include "clang/AST/ExprObjC.h"
29f59edb96b2d0bfe612b732f19519ab84bb995bd4Chandler Carruth#include "clang/Frontend/ASTUnit.h"
30edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek#include "llvm/Support/ErrorHandling.h"
3116c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
3216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenekusing namespace clang;
331f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorusing namespace cxcursor;
3416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
35bbf66ca1dad17773cc682d69b8482c4e179aeaebTed KremenekCXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) {
365bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor  assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid);
37ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  CXCursor C = { K, 0, { nullptr, nullptr, TU } };
385bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor  return C;
3916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek}
4016c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
41e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenekstatic CXCursorKind GetCursorKind(const Attr *A) {
42e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  assert(A && "Invalid arguments!");
43e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  switch (A->getKind()) {
44e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek    default: break;
45387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt    case attr::IBAction: return CXCursor_IBActionAttr;
46387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt    case attr::IBOutlet: return CXCursor_IBOutletAttr;
47387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt    case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
486639e9255489ad8e10278d5658fdd4b3c0e1e4cdArgyrios Kyrtzidis    case attr::Final: return CXCursor_CXXFinalAttr;
496639e9255489ad8e10278d5658fdd4b3c0e1e4cdArgyrios Kyrtzidis    case attr::Override: return CXCursor_CXXOverrideAttr;
505f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen    case attr::Annotate: return CXCursor_AnnotateAttr;
5184b796492de8a708150dd3f86ae191041d42eef9Argyrios Kyrtzidis    case attr::AsmLabel: return CXCursor_AsmLabelAttr;
52513371129c834c143a50c3ca09bb581b7f0f6344Argyrios Kyrtzidis    case attr::Packed: return CXCursor_PackedAttr;
536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    case attr::Pure: return CXCursor_PureAttr;
546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    case attr::Const: return CXCursor_ConstAttr;
556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    case attr::NoDuplicate: return CXCursor_NoDuplicateAttr;
56ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    case attr::CUDAConstant: return CXCursor_CUDAConstantAttr;
57ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    case attr::CUDADevice: return CXCursor_CUDADeviceAttr;
58ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr;
59ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    case attr::CUDAHost: return CXCursor_CUDAHostAttr;
60e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  }
61e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
62e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  return CXCursor_UnexposedAttr;
63e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek}
64e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
6505756dc8d11cd2054e0cb94f0302e4eb39acc68eDmitri GribenkoCXCursor cxcursor::MakeCXCursor(const Attr *A, const Decl *Parent,
66a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                CXTranslationUnit TU) {
67e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  assert(A && Parent && TU && "Invalid arguments!");
683315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { GetCursorKind(A), 0, { Parent, A, TU } };
69e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  return C;
70e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek}
71e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
7267812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri GribenkoCXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU,
73aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                                SourceRange RegionOfInterest,
74007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek                                bool FirstInDeclGroup) {
7554d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(D && TU && "Invalid arguments!");
76aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis
77aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  CXCursorKind K = getCursorKindForDecl(D);
78aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis
79aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  if (K == CXCursor_ObjCClassMethodDecl ||
80aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      K == CXCursor_ObjCInstanceMethodDecl) {
81aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    int SelectorIdIndex = -1;
82aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    // Check if cursor points to a selector id.
83aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    if (RegionOfInterest.isValid() &&
84aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis        RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
85aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      SmallVector<SourceLocation, 16> SelLocs;
86aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs);
8709d19efaa147762f84aed55efa7930bb3616a4e5Craig Topper      SmallVectorImpl<SourceLocation>::iterator
88aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis        I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
89aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      if (I != SelLocs.end())
90aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis        SelectorIdIndex = I - SelLocs.begin();
91aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    }
92aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    CXCursor C = { K, SelectorIdIndex,
93aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                   { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
94aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    return C;
95aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  }
96aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis
97aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
985bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor  return C;
99edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek}
100edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek
10105756dc8d11cd2054e0cb94f0302e4eb39acc68eDmitri GribenkoCXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
10267812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko                                CXTranslationUnit TU,
103aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                                SourceRange RegionOfInterest) {
10454d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(S && TU && "Invalid arguments!");
10597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  CXCursorKind K = CXCursor_NotImplemented;
10697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
10797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  switch (S->getStmtClass()) {
10897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::NoStmtClass:
10997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
11042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
11197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CaseStmtClass:
11242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CaseStmt;
11342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
11442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
11597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::DefaultStmtClass:
11642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_DefaultStmt;
11742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
11842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
11942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::IfStmtClass:
12042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_IfStmt;
12142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
12242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
12342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::SwitchStmtClass:
12442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SwitchStmt;
12542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
12642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
12742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::WhileStmtClass:
12842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_WhileStmt;
12942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
13042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
13142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DoStmtClass:
13242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_DoStmt;
13342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
13442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
13542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ForStmtClass:
13642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ForStmt;
13742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
13842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
13942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::GotoStmtClass:
14042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_GotoStmt;
14142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
14242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
14397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::IndirectGotoStmtClass:
14442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_IndirectGotoStmt;
14542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
14642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
14742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ContinueStmtClass:
14842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ContinueStmt;
14942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
15042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
15142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BreakStmtClass:
15242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_BreakStmt;
15342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
15442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
15542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ReturnStmtClass:
15642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ReturnStmt;
15742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
15842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
159df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  case Stmt::GCCAsmStmtClass:
160df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    K = CXCursor_GCCAsmStmt;
16142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
1628cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1638cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  case Stmt::MSAsmStmtClass:
1648cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    K = CXCursor_MSAsmStmt;
1658cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier    break;
16642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
16742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtTryStmtClass:
16842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtTryStmt;
16942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
17042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
17142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtCatchStmtClass:
17242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtCatchStmt;
17342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
17442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
17542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtFinallyStmtClass:
17642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtFinallyStmt;
17742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
17842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
17942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtThrowStmtClass:
18042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtThrowStmt;
18142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
18242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
18342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtSynchronizedStmtClass:
18442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtSynchronizedStmt;
18542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
18642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
18742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAutoreleasePoolStmtClass:
18842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAutoreleasePoolStmt;
18942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
19042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
19197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::ObjCForCollectionStmtClass:
19242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCForCollectionStmt;
19342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
19442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
19597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXCatchStmtClass:
19642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXCatchStmt;
19742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
19842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
19942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXTryStmtClass:
20042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXTryStmt;
20142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
20242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
20342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXForRangeStmtClass:
20442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXForRangeStmt;
20542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
20642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
20728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  case Stmt::SEHTryStmtClass:
20842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SEHTryStmt;
20942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
21042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
21128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  case Stmt::SEHExceptStmtClass:
21242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SEHExceptStmt;
21342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
21442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
21528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  case Stmt::SEHFinallyStmtClass:
21642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SEHFinallyStmt;
21742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
218ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
219ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  case Stmt::SEHLeaveStmtClass:
220ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    K = CXCursor_SEHLeaveStmt;
221ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    break;
22242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
22342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ArrayTypeTraitExprClass:
22442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::AsTypeExprClass:
225276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  case Stmt::AtomicExprClass:
22642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BinaryConditionalOperatorClass:
2274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  case Stmt::TypeTraitExprClass:
22842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXBindTemporaryExprClass:
22942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDefaultArgExprClass:
230c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  case Stmt::CXXDefaultInitExprClass:
2317c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  case Stmt::CXXStdInitializerListExprClass:
23242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXScalarValueInitExprClass:
23342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXUuidofExprClass:
23442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ChooseExprClass:
23542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DesignatedInitExprClass:
23642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ExprWithCleanupsClass:
23742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ExpressionTraitExprClass:
23842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ExtVectorElementExprClass:
23942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ImplicitCastExprClass:
24042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ImplicitValueInitExprClass:
24103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  case Stmt::MaterializeTemporaryExprClass:
24242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCIndirectCopyRestoreExprClass:
24342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::OffsetOfExprClass:
24442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ParenListExprClass:
24542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::PredefinedExprClass:
24642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ShuffleVectorExprClass:
247414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel  case Stmt::ConvertVectorExprClass:
24842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::UnaryExprOrTypeTraitExprClass:
24942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::VAArgExprClass:
250b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek  case Stmt::ObjCArrayLiteralClass:
251b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek  case Stmt::ObjCDictionaryLiteralClass:
252eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  case Stmt::ObjCBoxedExprClass:
253b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek  case Stmt::ObjCSubscriptRefExprClass:
25442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_UnexposedExpr;
25542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
25642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
2574b9c2d235fb9449e249d74f48ecfec601650de93John McCall  case Stmt::OpaqueValueExprClass:
2584b9c2d235fb9449e249d74f48ecfec601650de93John McCall    if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr())
2594b9c2d235fb9449e249d74f48ecfec601650de93John McCall      return MakeCXCursor(Src, Parent, TU, RegionOfInterest);
2604b9c2d235fb9449e249d74f48ecfec601650de93John McCall    K = CXCursor_UnexposedExpr;
2614b9c2d235fb9449e249d74f48ecfec601650de93John McCall    break;
2624b9c2d235fb9449e249d74f48ecfec601650de93John McCall
2634b9c2d235fb9449e249d74f48ecfec601650de93John McCall  case Stmt::PseudoObjectExprClass:
2644b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(),
2654b9c2d235fb9449e249d74f48ecfec601650de93John McCall                        Parent, TU, RegionOfInterest);
2664b9c2d235fb9449e249d74f48ecfec601650de93John McCall
26742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CompoundStmtClass:
26842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CompoundStmt;
26997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
270534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
27142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::NullStmtClass:
27242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_NullStmt;
27336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor    break;
274534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
27542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::LabelStmtClass:
27642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_LabelStmt;
27742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
278534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
279534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  case Stmt::AttributedStmtClass:
280534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    K = CXCursor_UnexposedStmt;
281534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    break;
282534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
28342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DeclStmtClass:
28442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_DeclStmt;
28542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
286534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
287051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj  case Stmt::CapturedStmtClass:
288051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    K = CXCursor_UnexposedStmt;
289051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj    break;
290051303ce09291dfbed537fa33b0d8a4d92c82b75Tareq A. Siraj
29142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::IntegerLiteralClass:
29242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_IntegerLiteral;
29342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
29442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
29542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::FloatingLiteralClass:
29642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_FloatingLiteral;
29742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
29842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
29942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ImaginaryLiteralClass:
30042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ImaginaryLiteral;
30142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
30242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
30342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::StringLiteralClass:
30442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_StringLiteral;
30542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
30642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
30742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CharacterLiteralClass:
30842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CharacterLiteral;
30942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
31042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
31142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ParenExprClass:
31242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ParenExpr;
31342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
31442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
3158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  case Stmt::UnaryOperatorClass:
31642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_UnaryOperator;
31742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
318534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
31942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXNoexceptExprClass:
32042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_UnaryExpr;
32142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
32242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
32342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ArraySubscriptExprClass:
32442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ArraySubscriptExpr;
32542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
32642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
32742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BinaryOperatorClass:
32842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_BinaryOperator;
32942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
33042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
33197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CompoundAssignOperatorClass:
33242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CompoundAssignOperator;
33342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
33442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
33542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ConditionalOperatorClass:
33642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ConditionalOperator;
33742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
33842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
33997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CStyleCastExprClass:
34042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CStyleCastExpr;
34142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
34242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
34342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CompoundLiteralExprClass:
34442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CompoundLiteralExpr;
34542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
34642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
34742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::InitListExprClass:
34842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_InitListExpr;
34942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
35042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
35142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::AddrLabelExprClass:
35242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_AddrLabelExpr;
35342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
35442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
35542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::StmtExprClass:
35642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_StmtExpr;
35742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
35842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
359f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  case Stmt::GenericSelectionExprClass:
36042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_GenericSelectionExpr;
36142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
36242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
36342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::GNUNullExprClass:
36442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_GNUNullExpr;
36542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
36642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
36742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXStaticCastExprClass:
36842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXStaticCastExpr;
36942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
37042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
37142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDynamicCastExprClass:
37242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXDynamicCastExpr;
37342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
37442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
37542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXReinterpretCastExprClass:
37642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXReinterpretCastExpr;
37742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
37842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
37942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXConstCastExprClass:
38042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXConstCastExpr;
38142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
38242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
38397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXFunctionalCastExprClass:
38442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXFunctionalCastExpr;
38542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
38642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
38742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXTypeidExprClass:
38842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXTypeidExpr;
38942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
39042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
39142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXBoolLiteralExprClass:
39242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXBoolLiteralExpr;
39342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
39442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
39542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXNullPtrLiteralExprClass:
39642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXNullPtrLiteralExpr;
39742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
39842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
39942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXThisExprClass:
40042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXThisExpr;
40142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
40242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
40342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXThrowExprClass:
40442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXThrowExpr;
40542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
40642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
40742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXNewExprClass:
40842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXNewExpr;
40942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
41042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
41142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDeleteExprClass:
41242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXDeleteExpr;
41342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
41442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
41542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCStringLiteralClass:
41642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCStringLiteral;
41742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
41842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
41942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCEncodeExprClass:
42042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCEncodeExpr;
42142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
42242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
42342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCSelectorExprClass:
42442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCSelectorExpr;
42542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
42642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
42742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCProtocolExprClass:
42842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCProtocolExpr;
42942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
430b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek
431b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek  case Stmt::ObjCBoolLiteralExprClass:
432b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek    K = CXCursor_ObjCBoolLiteralExpr;
433b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek    break;
434b3f7542a950ac0d585a7783e825cfe670e05c553Ted Kremenek
435f85e193739c953358c865005855253af4f68a497John McCall  case Stmt::ObjCBridgedCastExprClass:
43642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCBridgedCastExpr;
43742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
43842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
43942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BlockExprClass:
44042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_BlockExpr;
44142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
44242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
443be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  case Stmt::PackExpansionExprClass:
44442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_PackExpansionExpr;
44542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
44642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
447ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  case Stmt::SizeOfPackExprClass:
44842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SizeOfPackExpr;
44997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
45042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
451edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis  case Stmt::DeclRefExprClass:
452edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis    if (const ImplicitParamDecl *IPD =
453edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis         dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) {
454edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis      if (const ObjCMethodDecl *MD =
455edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis            dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) {
456edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis        if (MD->getSelfDecl() == IPD) {
457edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis          K = CXCursor_ObjCSelfExpr;
458edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis          break;
459edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis        }
460edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis      }
461edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis    }
462edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis
463edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis    K = CXCursor_DeclRefExpr;
464edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis    break;
465edab047e10d745a65d12c8cb36be2ba9e96c9e0eArgyrios Kyrtzidis
46642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DependentScopeDeclRefExprClass:
46791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  case Stmt::SubstNonTypeTemplateParmExprClass:
468c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  case Stmt::SubstNonTypeTemplateParmPackExprClass:
4699a4db032ecd991626d236a502e770126db32bd31Richard Smith  case Stmt::FunctionParmPackExprClass:
47042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::UnresolvedLookupExprClass:
47197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_DeclRefExpr;
47297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
47397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
47442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDependentScopeMemberExprClass:
47542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXPseudoDestructorExprClass:
47697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::MemberExprClass:
47776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  case Stmt::MSPropertyRefExprClass:
47842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCIsaExprClass:
47997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::ObjCIvarRefExprClass:
48097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::ObjCPropertyRefExprClass:
48142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::UnresolvedMemberExprClass:
48297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_MemberRefExpr;
48397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
48497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
48597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CallExprClass:
48697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXOperatorCallExprClass:
48797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXMemberCallExprClass:
488e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  case Stmt::CUDAKernelCallExprClass:
48997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXConstructExprClass:
49097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXTemporaryObjectExprClass:
49142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXUnresolvedConstructExprClass:
4929fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  case Stmt::UserDefinedLiteralClass:
49397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_CallExpr;
49497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
49597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
496011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor  case Stmt::LambdaExprClass:
497011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor    K = CXCursor_LambdaExpr;
498011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor    break;
499011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor
500ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  case Stmt::ObjCMessageExprClass: {
50197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_ObjCMessageExpr;
502aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    int SelectorIdIndex = -1;
503aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    // Check if cursor points to a selector id.
504aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    if (RegionOfInterest.isValid() &&
505aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis        RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
506aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      SmallVector<SourceLocation, 16> SelLocs;
507aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs);
50809d19efaa147762f84aed55efa7930bb3616a4e5Craig Topper      SmallVectorImpl<SourceLocation>::iterator
509aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis        I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
510aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      if (I != SelLocs.end())
511aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis        SelectorIdIndex = I - SelLocs.begin();
512aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    }
513aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    CXCursor C = { K, 0, { Parent, S, TU } };
514aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    return getSelectorIdentifierCursor(SelectorIdIndex, C);
51597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  }
516ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
517ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  case Stmt::MSDependentExistsStmtClass:
518ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    K = CXCursor_UnexposedStmt;
519ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    break;
5204fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev  case Stmt::OMPParallelDirectiveClass:
5214fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev    K = CXCursor_OMPParallelDirective;
5224fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev    break;
523651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  case Stmt::OMPSimdDirectiveClass:
524651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    K = CXCursor_OMPSimdDirective;
525651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    break;
526ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  case Stmt::OMPForDirectiveClass:
527ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    K = CXCursor_OMPForDirective;
528ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    break;
529ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  case Stmt::OMPSectionsDirectiveClass:
530ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    K = CXCursor_OMPSectionsDirective;
531ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    break;
532ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  case Stmt::OMPSectionDirectiveClass:
533ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    K = CXCursor_OMPSectionDirective;
534ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    break;
535ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  case Stmt::OMPSingleDirectiveClass:
536ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    K = CXCursor_OMPSingleDirective;
537ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    break;
538ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  case Stmt::OMPParallelForDirectiveClass:
539ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    K = CXCursor_OMPParallelForDirective;
540ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    break;
541ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  case Stmt::OMPParallelSectionsDirectiveClass:
542ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    K = CXCursor_OMPParallelSectionsDirective;
543ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    break;
544ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
545651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
546aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  CXCursor C = { K, 0, { Parent, S, TU } };
54797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  return C;
54897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor}
54997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
5502e331b938b38057e333fab0ba841130ea8467794Douglas GregorCXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
551b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor                                               SourceLocation Loc,
552a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
55354d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(Super && TU && "Invalid arguments!");
554cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
555aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } };
5562e331b938b38057e333fab0ba841130ea8467794Douglas Gregor  return C;
5572e331b938b38057e333fab0ba841130ea8467794Douglas Gregor}
5582e331b938b38057e333fab0ba841130ea8467794Douglas Gregor
55967812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const ObjCInterfaceDecl *, SourceLocation>
5602e331b938b38057e333fab0ba841130ea8467794Douglas Gregorcxcursor::getCursorObjCSuperClassRef(CXCursor C) {
5612e331b938b38057e333fab0ba841130ea8467794Douglas Gregor  assert(C.kind == CXCursor_ObjCSuperClassRef);
56267812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
56362d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
5642e331b938b38057e333fab0ba841130ea8467794Douglas Gregor}
5652e331b938b38057e333fab0ba841130ea8467794Douglas Gregor
5664e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios KyrtzidisCXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
567b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor                                             SourceLocation Loc,
568a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                             CXTranslationUnit TU) {
5694e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios Kyrtzidis  assert(Proto && TU && "Invalid arguments!");
570cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
5713315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } };
57278db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  return C;
57378db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor}
57478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor
57567812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const ObjCProtocolDecl *, SourceLocation>
57678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorcxcursor::getCursorObjCProtocolRef(CXCursor C) {
57778db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  assert(C.kind == CXCursor_ObjCProtocolRef);
57867812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]),
57962d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
58078db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor}
58178db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor
5824e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios KyrtzidisCXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
583b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor                                          SourceLocation Loc,
584a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                          CXTranslationUnit TU) {
585ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek  // 'Class' can be null for invalid code.
586ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek  if (!Class)
587ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek    return MakeCXCursorInvalid(CXCursor_InvalidCode);
588ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek  assert(TU && "Invalid arguments!");
589cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
5903315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } };
5911adb082a709f7b588f03672999294e061234b2cfDouglas Gregor  return C;
5921adb082a709f7b588f03672999294e061234b2cfDouglas Gregor}
5931adb082a709f7b588f03672999294e061234b2cfDouglas Gregor
59467812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const ObjCInterfaceDecl *, SourceLocation>
5951adb082a709f7b588f03672999294e061234b2cfDouglas Gregorcxcursor::getCursorObjCClassRef(CXCursor C) {
5961adb082a709f7b588f03672999294e061234b2cfDouglas Gregor  assert(C.kind == CXCursor_ObjCClassRef);
59767812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
59862d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
5991adb082a709f7b588f03672999294e061234b2cfDouglas Gregor}
6001adb082a709f7b588f03672999294e061234b2cfDouglas Gregor
6014e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios KyrtzidisCXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
602a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                     CXTranslationUnit TU) {
60354d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(Type && TU && "Invalid arguments!");
604cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
6053315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } };
6067d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor  return C;
6077d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor}
6087d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor
60967812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const TypeDecl *, SourceLocation>
6107d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregorcxcursor::getCursorTypeRef(CXCursor C) {
6117d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor  assert(C.kind == CXCursor_TypeRef);
61267812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const TypeDecl *>(C.data[0]),
61362d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
6147d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor}
6157d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor
616b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios KyrtzidisCXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template,
617a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                         SourceLocation Loc,
618a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                         CXTranslationUnit TU) {
6190b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  assert(Template && TU && "Invalid arguments!");
620cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
6213315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } };
6220b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  return C;
6230b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor}
6240b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor
62567812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const TemplateDecl *, SourceLocation>
6260b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregorcxcursor::getCursorTemplateRef(CXCursor C) {
6270b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  assert(C.kind == CXCursor_TemplateRef);
62867812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]),
62962d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
6300b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor}
6310b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor
632b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios KyrtzidisCXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS,
633b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios Kyrtzidis                                          SourceLocation Loc,
634a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                          CXTranslationUnit TU) {
6356931900f43cea558c6974075256c07728dbfecc6Douglas Gregor
6366931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
6376931900f43cea558c6974075256c07728dbfecc6Douglas Gregor         "Invalid arguments!");
638cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
6393315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } };
6406931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  return C;
6416931900f43cea558c6974075256c07728dbfecc6Douglas Gregor}
6426931900f43cea558c6974075256c07728dbfecc6Douglas Gregor
64367812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const NamedDecl *, SourceLocation>
6446931900f43cea558c6974075256c07728dbfecc6Douglas Gregorcxcursor::getCursorNamespaceRef(CXCursor C) {
6456931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  assert(C.kind == CXCursor_NamespaceRef);
64667812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const NamedDecl *>(C.data[0]),
64762d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
6486931900f43cea558c6974075256c07728dbfecc6Douglas Gregor}
6496931900f43cea558c6974075256c07728dbfecc6Douglas Gregor
650011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas GregorCXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
651011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor                                         CXTranslationUnit TU) {
652011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor
653011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor  assert(Var && TU && "Invalid arguments!");
654cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
6553315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } };
656011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor  return C;
657011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor}
658011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor
65967812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const VarDecl *, SourceLocation>
660011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregorcxcursor::getCursorVariableRef(CXCursor C) {
661011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor  assert(C.kind == CXCursor_VariableRef);
66267812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const VarDecl *>(C.data[0]),
66362d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
664011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor}
665011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor
666b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios KyrtzidisCXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
667a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                       CXTranslationUnit TU) {
668a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor
669a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  assert(Field && TU && "Invalid arguments!");
670cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
6713315618561d19c99a7a52c72a31fb182111da716Dmitri Gribenko  CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } };
672a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  return C;
673a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor}
674a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor
67567812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const FieldDecl *, SourceLocation>
676a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregorcxcursor::getCursorMemberRef(CXCursor C) {
677a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  assert(C.kind == CXCursor_MemberRef);
67867812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const FieldDecl *>(C.data[0]),
67962d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
680a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor}
681a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor
6822957e6f8c4c2e58a4b9cb639949fea801970fe36Argyrios KyrtzidisCXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
683a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                              CXTranslationUnit TU){
684ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, nullptr, TU } };
6853064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek  return C;
6863064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek}
6873064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek
68867812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkoconst CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
6893064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek  assert(C.kind == CXCursor_CXXBaseSpecifier);
69067812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return static_cast<const CXXBaseSpecifier*>(C.data[0]);
6913064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek}
6923064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek
6939f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorCXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
694a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                                    CXTranslationUnit TU) {
695aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  CXCursor C = { CXCursor_PreprocessingDirective, 0,
696cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko                 { Range.getBegin().getPtrEncoding(),
697cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko                   Range.getEnd().getPtrEncoding(),
6989f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor                   TU }
6999f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor               };
7009f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor  return C;
7019f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor}
7029f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor
7039f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorSourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
7049f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor  assert(C.kind == CXCursor_PreprocessingDirective);
70562d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko  SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]),
70662d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                    SourceLocation::getFromPtrEncoding(C.data[1]));
707ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis  ASTUnit *TU = getCursorASTUnit(C);
708ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis  return TU->mapRangeFromPreamble(Range);
7094807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor}
7104807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor
71167812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri GribenkoCXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinition *MI,
712a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                             CXTranslationUnit TU) {
713ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  CXCursor C = { CXCursor_MacroDefinition, 0, { MI, nullptr, TU } };
714572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor  return C;
715572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor}
716572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor
71767812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkoconst MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
718572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor  assert(C.kind == CXCursor_MacroDefinition);
71967812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return static_cast<const MacroDefinition *>(C.data[0]);
720572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor}
721572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor
7229e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler CarruthCXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
7239e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth                                            CXTranslationUnit TU) {
724ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  CXCursor C = { CXCursor_MacroExpansion, 0, { MI, nullptr, TU } };
7254807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor  return C;
7264807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor}
7274807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor
728664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios KyrtzidisCXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinition *MI,
729664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis                                            SourceLocation Loc,
730664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis                                            CXTranslationUnit TU) {
731664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  assert(Loc.isValid());
732664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  CXCursor C = { CXCursor_MacroExpansion, 0, { MI, Loc.getPtrEncoding(), TU } };
733664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  return C;
734664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis}
735664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis
736664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidisconst IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const {
737664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  if (isPseudo())
738664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis    return getAsMacroDefinition()->getName();
739664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  return getAsMacroExpansion()->getName();
740664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis}
74167812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkoconst MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const {
742664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  if (isPseudo())
743664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis    return getAsMacroDefinition();
744664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  return getAsMacroExpansion()->getDefinition();
745664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis}
746664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios KyrtzidisSourceRange cxcursor::MacroExpansionCursor::getSourceRange() const {
747664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  if (isPseudo())
748664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis    return getPseudoLoc();
749664b06f9bd2ea83443ddc8553feba8ba48880752Argyrios Kyrtzidis  return getAsMacroExpansion()->getSourceRange();
7509f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor}
7519f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor
752ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas GregorCXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
753a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                                CXTranslationUnit TU) {
754ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  CXCursor C = { CXCursor_InclusionDirective, 0, { ID, nullptr, TU } };
755ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor  return C;
756ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor}
757ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
75867812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkoconst InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
759ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor  assert(C.kind == CXCursor_InclusionDirective);
76067812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return static_cast<const InclusionDirective *>(C.data[0]);
761ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor}
762ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
76336897b05ca2886e287f01802614bc10cbadcec22Douglas GregorCXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
764a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                      CXTranslationUnit TU) {
76536897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor
76636897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  assert(Label && TU && "Invalid arguments!");
767cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
768aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } };
76936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  return C;
77036897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor}
77136897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor
77267812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenkostd::pair<const LabelStmt *, SourceLocation>
77336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregorcxcursor::getCursorLabelRef(CXCursor C) {
77436897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  assert(C.kind == CXCursor_LabelRef);
77567812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(static_cast<const LabelStmt *>(C.data[0]),
77662d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
77736897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor}
77836897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor
779e22339c44bb28d71a2cc97c840d3da0c4bdb4909Dmitri GribenkoCXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E,
780a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
7811f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(E && TU && "Invalid arguments!");
7821f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  OverloadedDeclRefStorage Storage(E);
783cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = E->getNameLoc().getPtrEncoding();
7841f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  CXCursor C = {
785aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                 CXCursor_OverloadedDeclRef, 0,
7861f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                 { Storage.getOpaqueValue(), RawLoc, TU }
7871f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor               };
7881f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  return C;
7891f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
7901f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
791e22339c44bb28d71a2cc97c840d3da0c4bdb4909Dmitri GribenkoCXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D,
7921f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                                               SourceLocation Loc,
793a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
7941f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(D && TU && "Invalid arguments!");
795cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
7961f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  OverloadedDeclRefStorage Storage(D);
7971f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  CXCursor C = {
798aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    CXCursor_OverloadedDeclRef, 0,
7991f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor    { Storage.getOpaqueValue(), RawLoc, TU }
8001f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  };
8011f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  return C;
8021f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
8031f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
8041f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
8051f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                                               SourceLocation Loc,
806a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
8071f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
808cb6bcf1c6392398ce9fccb4a0881dd4149568dcfDmitri Gribenko  void *RawLoc = Loc.getPtrEncoding();
8091f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
8101f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  CXCursor C = {
811aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    CXCursor_OverloadedDeclRef, 0,
8121f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor    { Storage.getOpaqueValue(), RawLoc, TU }
8131f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  };
8141f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  return C;
8151f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
8161f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
8171f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorstd::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
8181f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorcxcursor::getCursorOverloadedDeclRef(CXCursor C) {
8191f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(C.kind == CXCursor_OverloadedDeclRef);
82067812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(
82167812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko                                       const_cast<void *>(C.data[0])),
82262d0f569360a664018316e4a21a4e960560b271dDmitri Gribenko                        SourceLocation::getFromPtrEncoding(C.data[1]));
8231f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
8241f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
825e22339c44bb28d71a2cc97c840d3da0c4bdb4909Dmitri Gribenkoconst Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
826e22339c44bb28d71a2cc97c840d3da0c4bdb4909Dmitri Gribenko  return static_cast<const Decl *>(Cursor.data[0]);
827283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
828283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
829ff74f9683943c0db9cb075423596b00ea3b38c5dDmitri Gribenkoconst Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
830283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor  return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
831283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
832283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
833ff74f9683943c0db9cb075423596b00ea3b38c5dDmitri Gribenkoconst Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
83478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
8351adb082a709f7b588f03672999294e061234b2cfDouglas Gregor      Cursor.kind == CXCursor_ObjCProtocolRef ||
8361adb082a709f7b588f03672999294e061234b2cfDouglas Gregor      Cursor.kind == CXCursor_ObjCClassRef)
837ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    return nullptr;
8382e331b938b38057e333fab0ba841130ea8467794Douglas Gregor
839ff74f9683943c0db9cb075423596b00ea3b38c5dDmitri Gribenko  return static_cast<const Stmt *>(Cursor.data[1]);
840283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
841283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
8427d91438047450869d7b881e1c63868c4b52a3cc2Dmitri Gribenkoconst Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
8437d91438047450869d7b881e1c63868c4b52a3cc2Dmitri Gribenko  return static_cast<const Attr *>(Cursor.data[1]);
84495f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek}
84595f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek
846404628caa53a3f898047d73b38647d6fbb827e00Dmitri Gribenkoconst Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
847404628caa53a3f898047d73b38647d6fbb827e00Dmitri Gribenko  return static_cast<const Decl *>(Cursor.data[0]);
8488ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis}
8498ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis
850f46034af49435a4d1a0085a4738343122aeb6521Douglas GregorASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
851b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor  return getCursorASTUnit(Cursor)->getASTContext();
852b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor}
85397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
854b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas GregorASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
85546f92523918fd4ac4df5489265c7f85c1b28baeaDmitri Gribenko  CXTranslationUnit TU = getCursorTU(Cursor);
8564451746d8f658b51eaf15dd24664a488457063a9Argyrios Kyrtzidis  if (!TU)
857ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    return nullptr;
8585694feb5ccd6eb862cb600b55753cecc13794471Dmitri Gribenko  return cxtu::getASTUnit(TU);
859a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek}
860a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek
861a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
86267812b2f94f4b5e7d2596db1705ffa1149ddc45aDmitri Gribenko  return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2]));
863283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
864283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
865e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidisvoid cxcursor::getOverriddenCursors(CXCursor cursor,
866e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis                                    SmallVectorImpl<CXCursor> &overridden) {
867e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  assert(clang_isDeclaration(cursor.kind));
86821c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis  const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor));
869e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  if (!D)
870e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis    return;
871e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis
872e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  CXTranslationUnit TU = getCursorTU(cursor);
87321c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis  SmallVector<const NamedDecl *, 8> OverDecls;
87421c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis  D->getASTContext().getOverriddenMethods(D, OverDecls);
875e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis
87609d19efaa147762f84aed55efa7930bb3616a4e5Craig Topper  for (SmallVectorImpl<const NamedDecl *>::iterator
87721c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis         I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) {
87805756dc8d11cd2054e0cb94f0302e4eb39acc68eDmitri Gribenko    overridden.push_back(MakeCXCursor(*I, TU));
879e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  }
880e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis}
881e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis
882aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidisstd::pair<int, SourceLocation>
883aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidiscxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) {
884aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  if (cursor.kind == CXCursor_ObjCMessageExpr) {
885aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    if (cursor.xdata != -1)
886aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      return std::make_pair(cursor.xdata,
887aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                            cast<ObjCMessageExpr>(getCursorExpr(cursor))
888aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                                                ->getSelectorLoc(cursor.xdata));
889aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
890aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis             cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
891aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis    if (cursor.xdata != -1)
892aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis      return std::make_pair(cursor.xdata,
893aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                            cast<ObjCMethodDecl>(getCursorDecl(cursor))
894aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis                                                ->getSelectorLoc(cursor.xdata));
895aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  }
896aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis
897aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis  return std::make_pair(-1, SourceLocation());
898aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis}
899aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis
900aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios KyrtzidisCXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) {
901aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis