Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1 | //===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===// |
| 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 | // This file implements the main API hooks in the Clang-C Source Indexing |
| 11 | // library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 15 | #include "CIndexDiagnostic.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 16 | #include "CIndexer.h" |
Chandler Carruth | 4b41745 | 2013-01-19 08:09:44 +0000 | [diff] [blame] | 17 | #include "CLog.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 18 | #include "CXCursor.h" |
| 19 | #include "CXSourceLocation.h" |
| 20 | #include "CXString.h" |
| 21 | #include "CXTranslationUnit.h" |
| 22 | #include "CXType.h" |
| 23 | #include "CursorVisitor.h" |
David Blaikie | 0a4e61f | 2013-09-13 18:32:52 +0000 | [diff] [blame] | 24 | #include "clang/AST/Attr.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 25 | #include "clang/AST/StmtVisitor.h" |
| 26 | #include "clang/Basic/Diagnostic.h" |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 27 | #include "clang/Basic/DiagnosticCategories.h" |
| 28 | #include "clang/Basic/DiagnosticIDs.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 29 | #include "clang/Basic/Version.h" |
| 30 | #include "clang/Frontend/ASTUnit.h" |
| 31 | #include "clang/Frontend/CompilerInstance.h" |
| 32 | #include "clang/Frontend/FrontendDiagnostic.h" |
Argyrios Kyrtzidis | ca741ce | 2016-02-14 22:30:14 +0000 | [diff] [blame] | 33 | #include "clang/Index/CodegenNameGenerator.h" |
Dmitri Gribenko | 9e60511 | 2013-11-13 22:16:51 +0000 | [diff] [blame] | 34 | #include "clang/Index/CommentToXML.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 35 | #include "clang/Lex/HeaderSearch.h" |
| 36 | #include "clang/Lex/Lexer.h" |
| 37 | #include "clang/Lex/PreprocessingRecord.h" |
| 38 | #include "clang/Lex/Preprocessor.h" |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 39 | #include "clang/Serialization/SerializationDiagnostic.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 40 | #include "llvm/ADT/Optional.h" |
| 41 | #include "llvm/ADT/STLExtras.h" |
| 42 | #include "llvm/ADT/StringSwitch.h" |
Alp Toker | 1d257e1 | 2014-06-04 03:28:55 +0000 | [diff] [blame] | 43 | #include "llvm/Config/llvm-config.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Compiler.h" |
| 45 | #include "llvm/Support/CrashRecoveryContext.h" |
Chandler Carruth | 4b41745 | 2013-01-19 08:09:44 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Format.h" |
Chandler Carruth | 37ad258 | 2014-06-27 15:14:39 +0000 | [diff] [blame] | 47 | #include "llvm/Support/ManagedStatic.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 48 | #include "llvm/Support/MemoryBuffer.h" |
| 49 | #include "llvm/Support/Mutex.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 50 | #include "llvm/Support/Program.h" |
| 51 | #include "llvm/Support/SaveAndRestore.h" |
| 52 | #include "llvm/Support/Signals.h" |
Adrian Prantl | bc06858 | 2015-07-08 01:00:30 +0000 | [diff] [blame] | 53 | #include "llvm/Support/TargetSelect.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 54 | #include "llvm/Support/Threading.h" |
| 55 | #include "llvm/Support/Timer.h" |
| 56 | #include "llvm/Support/raw_ostream.h" |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 57 | |
Alp Toker | 1a86ad2 | 2014-07-06 06:24:00 +0000 | [diff] [blame] | 58 | #if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__) |
| 59 | #define USE_DARWIN_THREADS |
| 60 | #endif |
| 61 | |
| 62 | #ifdef USE_DARWIN_THREADS |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 63 | #include <pthread.h> |
| 64 | #endif |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 65 | |
| 66 | using namespace clang; |
| 67 | using namespace clang::cxcursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 68 | using namespace clang::cxtu; |
| 69 | using namespace clang::cxindex; |
| 70 | |
David Blaikie | ea4395e | 2017-01-06 19:49:01 +0000 | [diff] [blame^] | 71 | CXTranslationUnit cxtu::MakeCXTranslationUnit(CIndexer *CIdx, |
| 72 | std::unique_ptr<ASTUnit> AU) { |
Dmitri Gribenko | d36209e | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 73 | if (!AU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 74 | return nullptr; |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 75 | assert(CIdx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 76 | CXTranslationUnit D = new CXTranslationUnitImpl(); |
| 77 | D->CIdx = CIdx; |
David Blaikie | ea4395e | 2017-01-06 19:49:01 +0000 | [diff] [blame^] | 78 | D->TheASTUnit = AU.release(); |
Dmitri Gribenko | 7489521 | 2013-02-03 13:52:47 +0000 | [diff] [blame] | 79 | D->StringPool = new cxstring::CXStringPool(); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 80 | D->Diagnostics = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 81 | D->OverridenCursorsPool = createOverridenCXCursorsPool(); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 82 | D->CommentToXML = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 83 | return D; |
| 84 | } |
| 85 | |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 86 | bool cxtu::isASTReadError(ASTUnit *AU) { |
| 87 | for (ASTUnit::stored_diag_iterator D = AU->stored_diag_begin(), |
| 88 | DEnd = AU->stored_diag_end(); |
| 89 | D != DEnd; ++D) { |
| 90 | if (D->getLevel() >= DiagnosticsEngine::Error && |
| 91 | DiagnosticIDs::getCategoryNumberForDiag(D->getID()) == |
| 92 | diag::DiagCat_AST_Deserialization_Issue) |
| 93 | return true; |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 98 | cxtu::CXTUOwner::~CXTUOwner() { |
| 99 | if (TU) |
| 100 | clang_disposeTranslationUnit(TU); |
| 101 | } |
| 102 | |
| 103 | /// \brief Compare two source ranges to determine their relative position in |
| 104 | /// the translation unit. |
| 105 | static RangeComparisonResult RangeCompare(SourceManager &SM, |
| 106 | SourceRange R1, |
| 107 | SourceRange R2) { |
| 108 | assert(R1.isValid() && "First range is invalid?"); |
| 109 | assert(R2.isValid() && "Second range is invalid?"); |
| 110 | if (R1.getEnd() != R2.getBegin() && |
| 111 | SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin())) |
| 112 | return RangeBefore; |
| 113 | if (R2.getEnd() != R1.getBegin() && |
| 114 | SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin())) |
| 115 | return RangeAfter; |
| 116 | return RangeOverlap; |
| 117 | } |
| 118 | |
| 119 | /// \brief Determine if a source location falls within, before, or after a |
| 120 | /// a given source range. |
| 121 | static RangeComparisonResult LocationCompare(SourceManager &SM, |
| 122 | SourceLocation L, SourceRange R) { |
| 123 | assert(R.isValid() && "First range is invalid?"); |
| 124 | assert(L.isValid() && "Second range is invalid?"); |
| 125 | if (L == R.getBegin() || L == R.getEnd()) |
| 126 | return RangeOverlap; |
| 127 | if (SM.isBeforeInTranslationUnit(L, R.getBegin())) |
| 128 | return RangeBefore; |
| 129 | if (SM.isBeforeInTranslationUnit(R.getEnd(), L)) |
| 130 | return RangeAfter; |
| 131 | return RangeOverlap; |
| 132 | } |
| 133 | |
| 134 | /// \brief Translate a Clang source range into a CIndex source range. |
| 135 | /// |
| 136 | /// Clang internally represents ranges where the end location points to the |
| 137 | /// start of the token at the end. However, for external clients it is more |
| 138 | /// useful to have a CXSourceRange be a proper half-open interval. This routine |
| 139 | /// does the appropriate translation. |
| 140 | CXSourceRange cxloc::translateSourceRange(const SourceManager &SM, |
| 141 | const LangOptions &LangOpts, |
| 142 | const CharSourceRange &R) { |
| 143 | // We want the last character in this location, so we will adjust the |
| 144 | // location accordingly. |
| 145 | SourceLocation EndLoc = R.getEnd(); |
| 146 | if (EndLoc.isValid() && EndLoc.isMacroID() && !SM.isMacroArgExpansion(EndLoc)) |
| 147 | EndLoc = SM.getExpansionRange(EndLoc).second; |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 148 | if (R.isTokenRange() && EndLoc.isValid()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 149 | unsigned Length = Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc), |
| 150 | SM, LangOpts); |
| 151 | EndLoc = EndLoc.getLocWithOffset(Length); |
| 152 | } |
| 153 | |
Bill Wendling | eade362 | 2013-01-23 08:25:41 +0000 | [diff] [blame] | 154 | CXSourceRange Result = { |
Dmitri Gribenko | f930448 | 2013-01-23 15:56:07 +0000 | [diff] [blame] | 155 | { &SM, &LangOpts }, |
Bill Wendling | eade362 | 2013-01-23 08:25:41 +0000 | [diff] [blame] | 156 | R.getBegin().getRawEncoding(), |
| 157 | EndLoc.getRawEncoding() |
| 158 | }; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 159 | return Result; |
| 160 | } |
| 161 | |
| 162 | //===----------------------------------------------------------------------===// |
| 163 | // Cursor visitor. |
| 164 | //===----------------------------------------------------------------------===// |
| 165 | |
| 166 | static SourceRange getRawCursorExtent(CXCursor C); |
| 167 | static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr); |
| 168 | |
| 169 | |
| 170 | RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) { |
| 171 | return RangeCompare(AU->getSourceManager(), R, RegionOfInterest); |
| 172 | } |
| 173 | |
| 174 | /// \brief Visit the given cursor and, if requested by the visitor, |
| 175 | /// its children. |
| 176 | /// |
| 177 | /// \param Cursor the cursor to visit. |
| 178 | /// |
| 179 | /// \param CheckedRegionOfInterest if true, then the caller already checked |
| 180 | /// that this cursor is within the region of interest. |
| 181 | /// |
| 182 | /// \returns true if the visitation should be aborted, false if it |
| 183 | /// should continue. |
| 184 | bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) { |
| 185 | if (clang_isInvalid(Cursor.kind)) |
| 186 | return false; |
| 187 | |
| 188 | if (clang_isDeclaration(Cursor.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 189 | const Decl *D = getCursorDecl(Cursor); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 190 | if (!D) { |
| 191 | assert(0 && "Invalid declaration cursor"); |
| 192 | return true; // abort. |
| 193 | } |
| 194 | |
| 195 | // Ignore implicit declarations, unless it's an objc method because |
| 196 | // currently we should report implicit methods for properties when indexing. |
| 197 | if (D->isImplicit() && !isa<ObjCMethodDecl>(D)) |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | // If we have a range of interest, and this cursor doesn't intersect with it, |
| 202 | // we're done. |
| 203 | if (RegionOfInterest.isValid() && !CheckedRegionOfInterest) { |
| 204 | SourceRange Range = getRawCursorExtent(Cursor); |
| 205 | if (Range.isInvalid() || CompareRegionOfInterest(Range)) |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | switch (Visitor(Cursor, Parent, ClientData)) { |
| 210 | case CXChildVisit_Break: |
| 211 | return true; |
| 212 | |
| 213 | case CXChildVisit_Continue: |
| 214 | return false; |
| 215 | |
| 216 | case CXChildVisit_Recurse: { |
| 217 | bool ret = VisitChildren(Cursor); |
| 218 | if (PostChildrenVisitor) |
| 219 | if (PostChildrenVisitor(Cursor, ClientData)) |
| 220 | return true; |
| 221 | return ret; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | llvm_unreachable("Invalid CXChildVisitResult!"); |
| 226 | } |
| 227 | |
| 228 | static bool visitPreprocessedEntitiesInRange(SourceRange R, |
| 229 | PreprocessingRecord &PPRec, |
| 230 | CursorVisitor &Visitor) { |
| 231 | SourceManager &SM = Visitor.getASTUnit()->getSourceManager(); |
| 232 | FileID FID; |
| 233 | |
| 234 | if (!Visitor.shouldVisitIncludedEntities()) { |
| 235 | // If the begin/end of the range lie in the same FileID, do the optimization |
| 236 | // where we skip preprocessed entities that do not come from the same FileID. |
| 237 | FID = SM.getFileID(SM.getFileLoc(R.getBegin())); |
| 238 | if (FID != SM.getFileID(SM.getFileLoc(R.getEnd()))) |
| 239 | FID = FileID(); |
| 240 | } |
| 241 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 242 | const auto &Entities = PPRec.getPreprocessedEntitiesInRange(R); |
| 243 | return Visitor.visitPreprocessedEntities(Entities.begin(), Entities.end(), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 244 | PPRec, FID); |
| 245 | } |
| 246 | |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 247 | bool CursorVisitor::visitFileRegion() { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 248 | if (RegionOfInterest.isInvalid()) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 249 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 250 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 251 | ASTUnit *Unit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 252 | SourceManager &SM = Unit->getSourceManager(); |
| 253 | |
| 254 | std::pair<FileID, unsigned> |
| 255 | Begin = SM.getDecomposedLoc(SM.getFileLoc(RegionOfInterest.getBegin())), |
| 256 | End = SM.getDecomposedLoc(SM.getFileLoc(RegionOfInterest.getEnd())); |
| 257 | |
| 258 | if (End.first != Begin.first) { |
| 259 | // If the end does not reside in the same file, try to recover by |
| 260 | // picking the end of the file of begin location. |
| 261 | End.first = Begin.first; |
| 262 | End.second = SM.getFileIDSize(Begin.first); |
| 263 | } |
| 264 | |
| 265 | assert(Begin.first == End.first); |
| 266 | if (Begin.second > End.second) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 267 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 268 | |
| 269 | FileID File = Begin.first; |
| 270 | unsigned Offset = Begin.second; |
| 271 | unsigned Length = End.second - Begin.second; |
| 272 | |
| 273 | if (!VisitDeclsOnly && !VisitPreprocessorLast) |
| 274 | if (visitPreprocessedEntitiesInRegion()) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 275 | return true; // visitation break. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 276 | |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 277 | if (visitDeclsFromFileRegion(File, Offset, Length)) |
| 278 | return true; // visitation break. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 279 | |
| 280 | if (!VisitDeclsOnly && VisitPreprocessorLast) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 281 | return visitPreprocessedEntitiesInRegion(); |
| 282 | |
| 283 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static bool isInLexicalContext(Decl *D, DeclContext *DC) { |
| 287 | if (!DC) |
| 288 | return false; |
| 289 | |
| 290 | for (DeclContext *DeclDC = D->getLexicalDeclContext(); |
| 291 | DeclDC; DeclDC = DeclDC->getLexicalParent()) { |
| 292 | if (DeclDC == DC) |
| 293 | return true; |
| 294 | } |
| 295 | return false; |
| 296 | } |
| 297 | |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 298 | bool CursorVisitor::visitDeclsFromFileRegion(FileID File, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 299 | unsigned Offset, unsigned Length) { |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 300 | ASTUnit *Unit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 301 | SourceManager &SM = Unit->getSourceManager(); |
| 302 | SourceRange Range = RegionOfInterest; |
| 303 | |
| 304 | SmallVector<Decl *, 16> Decls; |
| 305 | Unit->findFileRegionDecls(File, Offset, Length, Decls); |
| 306 | |
| 307 | // If we didn't find any file level decls for the file, try looking at the |
| 308 | // file that it was included from. |
| 309 | while (Decls.empty() || Decls.front()->isTopLevelDeclInObjCContainer()) { |
| 310 | bool Invalid = false; |
| 311 | const SrcMgr::SLocEntry &SLEntry = SM.getSLocEntry(File, &Invalid); |
| 312 | if (Invalid) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 313 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 314 | |
| 315 | SourceLocation Outer; |
| 316 | if (SLEntry.isFile()) |
| 317 | Outer = SLEntry.getFile().getIncludeLoc(); |
| 318 | else |
| 319 | Outer = SLEntry.getExpansion().getExpansionLocStart(); |
| 320 | if (Outer.isInvalid()) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 321 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 322 | |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 323 | std::tie(File, Offset) = SM.getDecomposedExpansionLoc(Outer); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 324 | Length = 0; |
| 325 | Unit->findFileRegionDecls(File, Offset, Length, Decls); |
| 326 | } |
| 327 | |
| 328 | assert(!Decls.empty()); |
| 329 | |
| 330 | bool VisitedAtLeastOnce = false; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 331 | DeclContext *CurDC = nullptr; |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 332 | SmallVectorImpl<Decl *>::iterator DIt = Decls.begin(); |
| 333 | for (SmallVectorImpl<Decl *>::iterator DE = Decls.end(); DIt != DE; ++DIt) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 334 | Decl *D = *DIt; |
| 335 | if (D->getSourceRange().isInvalid()) |
| 336 | continue; |
| 337 | |
| 338 | if (isInLexicalContext(D, CurDC)) |
| 339 | continue; |
| 340 | |
| 341 | CurDC = dyn_cast<DeclContext>(D); |
| 342 | |
| 343 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) |
| 344 | if (!TD->isFreeStanding()) |
| 345 | continue; |
| 346 | |
| 347 | RangeComparisonResult CompRes = RangeCompare(SM, D->getSourceRange(),Range); |
| 348 | if (CompRes == RangeBefore) |
| 349 | continue; |
| 350 | if (CompRes == RangeAfter) |
| 351 | break; |
| 352 | |
| 353 | assert(CompRes == RangeOverlap); |
| 354 | VisitedAtLeastOnce = true; |
| 355 | |
| 356 | if (isa<ObjCContainerDecl>(D)) { |
| 357 | FileDI_current = &DIt; |
| 358 | FileDE_current = DE; |
| 359 | } else { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 360 | FileDI_current = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true)) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 364 | return true; // visitation break. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | if (VisitedAtLeastOnce) |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 368 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 369 | |
| 370 | // No Decls overlapped with the range. Move up the lexical context until there |
| 371 | // is a context that contains the range or we reach the translation unit |
| 372 | // level. |
| 373 | DeclContext *DC = DIt == Decls.begin() ? (*DIt)->getLexicalDeclContext() |
| 374 | : (*(DIt-1))->getLexicalDeclContext(); |
| 375 | |
| 376 | while (DC && !DC->isTranslationUnit()) { |
| 377 | Decl *D = cast<Decl>(DC); |
| 378 | SourceRange CurDeclRange = D->getSourceRange(); |
| 379 | if (CurDeclRange.isInvalid()) |
| 380 | break; |
| 381 | |
| 382 | if (RangeCompare(SM, CurDeclRange, Range) == RangeOverlap) { |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 383 | if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true)) |
| 384 | return true; // visitation break. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | DC = D->getLexicalDeclContext(); |
| 388 | } |
Argyrios Kyrtzidis | 951f61f | 2013-03-08 20:42:33 +0000 | [diff] [blame] | 389 | |
| 390 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | bool CursorVisitor::visitPreprocessedEntitiesInRegion() { |
| 394 | if (!AU->getPreprocessor().getPreprocessingRecord()) |
| 395 | return false; |
| 396 | |
| 397 | PreprocessingRecord &PPRec |
| 398 | = *AU->getPreprocessor().getPreprocessingRecord(); |
| 399 | SourceManager &SM = AU->getSourceManager(); |
| 400 | |
| 401 | if (RegionOfInterest.isValid()) { |
| 402 | SourceRange MappedRange = AU->mapRangeToPreamble(RegionOfInterest); |
| 403 | SourceLocation B = MappedRange.getBegin(); |
| 404 | SourceLocation E = MappedRange.getEnd(); |
| 405 | |
| 406 | if (AU->isInPreambleFileID(B)) { |
| 407 | if (SM.isLoadedSourceLocation(E)) |
| 408 | return visitPreprocessedEntitiesInRange(SourceRange(B, E), |
| 409 | PPRec, *this); |
| 410 | |
| 411 | // Beginning of range lies in the preamble but it also extends beyond |
| 412 | // it into the main file. Split the range into 2 parts, one covering |
| 413 | // the preamble and another covering the main file. This allows subsequent |
| 414 | // calls to visitPreprocessedEntitiesInRange to accept a source range that |
| 415 | // lies in the same FileID, allowing it to skip preprocessed entities that |
| 416 | // do not come from the same FileID. |
| 417 | bool breaked = |
| 418 | visitPreprocessedEntitiesInRange( |
| 419 | SourceRange(B, AU->getEndOfPreambleFileID()), |
| 420 | PPRec, *this); |
| 421 | if (breaked) return true; |
| 422 | return visitPreprocessedEntitiesInRange( |
| 423 | SourceRange(AU->getStartOfMainFileID(), E), |
| 424 | PPRec, *this); |
| 425 | } |
| 426 | |
| 427 | return visitPreprocessedEntitiesInRange(SourceRange(B, E), PPRec, *this); |
| 428 | } |
| 429 | |
| 430 | bool OnlyLocalDecls |
| 431 | = !AU->isMainFileAST() && AU->getOnlyLocalDecls(); |
| 432 | |
| 433 | if (OnlyLocalDecls) |
| 434 | return visitPreprocessedEntities(PPRec.local_begin(), PPRec.local_end(), |
| 435 | PPRec); |
| 436 | |
| 437 | return visitPreprocessedEntities(PPRec.begin(), PPRec.end(), PPRec); |
| 438 | } |
| 439 | |
| 440 | template<typename InputIterator> |
| 441 | bool CursorVisitor::visitPreprocessedEntities(InputIterator First, |
| 442 | InputIterator Last, |
| 443 | PreprocessingRecord &PPRec, |
| 444 | FileID FID) { |
| 445 | for (; First != Last; ++First) { |
| 446 | if (!FID.isInvalid() && !PPRec.isEntityInFileID(First, FID)) |
| 447 | continue; |
| 448 | |
| 449 | PreprocessedEntity *PPE = *First; |
Argyrios Kyrtzidis | 1030f26 | 2013-05-07 20:37:17 +0000 | [diff] [blame] | 450 | if (!PPE) |
| 451 | continue; |
| 452 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 453 | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(PPE)) { |
| 454 | if (Visit(MakeMacroExpansionCursor(ME, TU))) |
| 455 | return true; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 456 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 457 | continue; |
| 458 | } |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 459 | |
| 460 | if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(PPE)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 461 | if (Visit(MakeMacroDefinitionCursor(MD, TU))) |
| 462 | return true; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 463 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 464 | continue; |
| 465 | } |
| 466 | |
| 467 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) { |
| 468 | if (Visit(MakeInclusionDirectiveCursor(ID, TU))) |
| 469 | return true; |
| 470 | |
| 471 | continue; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | /// \brief Visit the children of the given cursor. |
| 479 | /// |
| 480 | /// \returns true if the visitation should be aborted, false if it |
| 481 | /// should continue. |
| 482 | bool CursorVisitor::VisitChildren(CXCursor Cursor) { |
| 483 | if (clang_isReference(Cursor.kind) && |
| 484 | Cursor.kind != CXCursor_CXXBaseSpecifier) { |
| 485 | // By definition, references have no children. |
| 486 | return false; |
| 487 | } |
| 488 | |
| 489 | // Set the Parent field to Cursor, then back to its old value once we're |
| 490 | // done. |
| 491 | SetParentRAII SetParent(Parent, StmtParent, Cursor); |
| 492 | |
| 493 | if (clang_isDeclaration(Cursor.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 494 | Decl *D = const_cast<Decl *>(getCursorDecl(Cursor)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 495 | if (!D) |
| 496 | return false; |
| 497 | |
| 498 | return VisitAttributes(D) || Visit(D); |
| 499 | } |
| 500 | |
| 501 | if (clang_isStatement(Cursor.kind)) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 502 | if (const Stmt *S = getCursorStmt(Cursor)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 503 | return Visit(S); |
| 504 | |
| 505 | return false; |
| 506 | } |
| 507 | |
| 508 | if (clang_isExpression(Cursor.kind)) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 509 | if (const Expr *E = getCursorExpr(Cursor)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 510 | return Visit(E); |
| 511 | |
| 512 | return false; |
| 513 | } |
| 514 | |
| 515 | if (clang_isTranslationUnit(Cursor.kind)) { |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 516 | CXTranslationUnit TU = getCursorTU(Cursor); |
| 517 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 518 | |
| 519 | int VisitOrder[2] = { VisitPreprocessorLast, !VisitPreprocessorLast }; |
| 520 | for (unsigned I = 0; I != 2; ++I) { |
| 521 | if (VisitOrder[I]) { |
| 522 | if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() && |
| 523 | RegionOfInterest.isInvalid()) { |
| 524 | for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(), |
| 525 | TLEnd = CXXUnit->top_level_end(); |
| 526 | TL != TLEnd; ++TL) { |
Argyrios Kyrtzidis | e7c9104 | 2016-07-01 19:10:54 +0000 | [diff] [blame] | 527 | const Optional<bool> V = handleDeclForVisitation(*TL); |
| 528 | if (!V.hasValue()) |
| 529 | continue; |
| 530 | return V.getValue(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 531 | } |
| 532 | } else if (VisitDeclContext( |
| 533 | CXXUnit->getASTContext().getTranslationUnitDecl())) |
| 534 | return true; |
| 535 | continue; |
| 536 | } |
| 537 | |
| 538 | // Walk the preprocessing record. |
| 539 | if (CXXUnit->getPreprocessor().getPreprocessingRecord()) |
| 540 | visitPreprocessedEntitiesInRegion(); |
| 541 | } |
| 542 | |
| 543 | return false; |
| 544 | } |
| 545 | |
| 546 | if (Cursor.kind == CXCursor_CXXBaseSpecifier) { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 547 | if (const CXXBaseSpecifier *Base = getCursorCXXBaseSpecifier(Cursor)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 548 | if (TypeSourceInfo *BaseTSInfo = Base->getTypeSourceInfo()) { |
| 549 | return Visit(BaseTSInfo->getTypeLoc()); |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | if (Cursor.kind == CXCursor_IBOutletCollectionAttr) { |
Dmitri Gribenko | e4baea6 | 2013-01-26 18:08:08 +0000 | [diff] [blame] | 555 | const IBOutletCollectionAttr *A = |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 556 | cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(Cursor)); |
Richard Smith | b1f9a28 | 2013-10-31 01:56:18 +0000 | [diff] [blame] | 557 | if (const ObjCObjectType *ObjT = A->getInterface()->getAs<ObjCObjectType>()) |
Richard Smith | b87c465 | 2013-10-31 21:23:20 +0000 | [diff] [blame] | 558 | return Visit(cxcursor::MakeCursorObjCClassRef( |
| 559 | ObjT->getInterface(), |
| 560 | A->getInterfaceLoc()->getTypeLoc().getLocStart(), TU)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 563 | // If pointing inside a macro definition, check if the token is an identifier |
| 564 | // that was ever defined as a macro. In such a case, create a "pseudo" macro |
| 565 | // expansion cursor for that token. |
| 566 | SourceLocation BeginLoc = RegionOfInterest.getBegin(); |
| 567 | if (Cursor.kind == CXCursor_MacroDefinition && |
| 568 | BeginLoc == RegionOfInterest.getEnd()) { |
| 569 | SourceLocation Loc = AU->mapLocationToPreamble(BeginLoc); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 570 | const MacroInfo *MI = |
| 571 | getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor), TU); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 572 | if (MacroDefinitionRecord *MacroDef = |
| 573 | checkForMacroInMacroDefinition(MI, Loc, TU)) |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 574 | return Visit(cxcursor::MakeMacroExpansionCursor(MacroDef, BeginLoc, TU)); |
| 575 | } |
| 576 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 577 | // Nothing to visit at the moment. |
| 578 | return false; |
| 579 | } |
| 580 | |
| 581 | bool CursorVisitor::VisitBlockDecl(BlockDecl *B) { |
| 582 | if (TypeSourceInfo *TSInfo = B->getSignatureAsWritten()) |
| 583 | if (Visit(TSInfo->getTypeLoc())) |
| 584 | return true; |
| 585 | |
| 586 | if (Stmt *Body = B->getBody()) |
| 587 | return Visit(MakeCXCursor(Body, StmtParent, TU, RegionOfInterest)); |
| 588 | |
| 589 | return false; |
| 590 | } |
| 591 | |
Ted Kremenek | 0332558 | 2013-02-21 01:29:01 +0000 | [diff] [blame] | 592 | Optional<bool> CursorVisitor::shouldVisitCursor(CXCursor Cursor) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 593 | if (RegionOfInterest.isValid()) { |
| 594 | SourceRange Range = getFullCursorExtent(Cursor, AU->getSourceManager()); |
| 595 | if (Range.isInvalid()) |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 596 | return None; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 597 | |
| 598 | switch (CompareRegionOfInterest(Range)) { |
| 599 | case RangeBefore: |
| 600 | // This declaration comes before the region of interest; skip it. |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 601 | return None; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 602 | |
| 603 | case RangeAfter: |
| 604 | // This declaration comes after the region of interest; we're done. |
| 605 | return false; |
| 606 | |
| 607 | case RangeOverlap: |
| 608 | // This declaration overlaps the region of interest; visit it. |
| 609 | break; |
| 610 | } |
| 611 | } |
| 612 | return true; |
| 613 | } |
| 614 | |
| 615 | bool CursorVisitor::VisitDeclContext(DeclContext *DC) { |
| 616 | DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end(); |
| 617 | |
| 618 | // FIXME: Eventually remove. This part of a hack to support proper |
| 619 | // iteration over all Decls contained lexically within an ObjC container. |
| 620 | SaveAndRestore<DeclContext::decl_iterator*> DI_saved(DI_current, &I); |
| 621 | SaveAndRestore<DeclContext::decl_iterator> DE_saved(DE_current, E); |
| 622 | |
| 623 | for ( ; I != E; ++I) { |
| 624 | Decl *D = *I; |
| 625 | if (D->getLexicalDeclContext() != DC) |
| 626 | continue; |
Argyrios Kyrtzidis | e7c9104 | 2016-07-01 19:10:54 +0000 | [diff] [blame] | 627 | const Optional<bool> V = handleDeclForVisitation(D); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 628 | if (!V.hasValue()) |
| 629 | continue; |
Argyrios Kyrtzidis | e7c9104 | 2016-07-01 19:10:54 +0000 | [diff] [blame] | 630 | return V.getValue(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 631 | } |
| 632 | return false; |
| 633 | } |
| 634 | |
Argyrios Kyrtzidis | e7c9104 | 2016-07-01 19:10:54 +0000 | [diff] [blame] | 635 | Optional<bool> CursorVisitor::handleDeclForVisitation(const Decl *D) { |
| 636 | CXCursor Cursor = MakeCXCursor(D, TU, RegionOfInterest); |
| 637 | |
| 638 | // Ignore synthesized ivars here, otherwise if we have something like: |
| 639 | // @synthesize prop = _prop; |
| 640 | // and '_prop' is not declared, we will encounter a '_prop' ivar before |
| 641 | // encountering the 'prop' synthesize declaration and we will think that |
| 642 | // we passed the region-of-interest. |
| 643 | if (auto *ivarD = dyn_cast<ObjCIvarDecl>(D)) { |
| 644 | if (ivarD->getSynthesize()) |
| 645 | return None; |
| 646 | } |
| 647 | |
| 648 | // FIXME: ObjCClassRef/ObjCProtocolRef for forward class/protocol |
| 649 | // declarations is a mismatch with the compiler semantics. |
| 650 | if (Cursor.kind == CXCursor_ObjCInterfaceDecl) { |
| 651 | auto *ID = cast<ObjCInterfaceDecl>(D); |
| 652 | if (!ID->isThisDeclarationADefinition()) |
| 653 | Cursor = MakeCursorObjCClassRef(ID, ID->getLocation(), TU); |
| 654 | |
| 655 | } else if (Cursor.kind == CXCursor_ObjCProtocolDecl) { |
| 656 | auto *PD = cast<ObjCProtocolDecl>(D); |
| 657 | if (!PD->isThisDeclarationADefinition()) |
| 658 | Cursor = MakeCursorObjCProtocolRef(PD, PD->getLocation(), TU); |
| 659 | } |
| 660 | |
| 661 | const Optional<bool> V = shouldVisitCursor(Cursor); |
| 662 | if (!V.hasValue()) |
| 663 | return None; |
| 664 | if (!V.getValue()) |
| 665 | return false; |
| 666 | if (Visit(Cursor, true)) |
| 667 | return true; |
| 668 | return None; |
| 669 | } |
| 670 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 671 | bool CursorVisitor::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 672 | llvm_unreachable("Translation units are visited directly by Visit()"); |
| 673 | } |
| 674 | |
Sergey Kalinichev | 8f3b187 | 2015-11-15 13:48:32 +0000 | [diff] [blame] | 675 | bool CursorVisitor::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 676 | if (VisitTemplateParameters(D->getTemplateParameters())) |
| 677 | return true; |
| 678 | |
| 679 | return Visit(MakeCXCursor(D->getTemplatedDecl(), TU, RegionOfInterest)); |
| 680 | } |
| 681 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 682 | bool CursorVisitor::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 683 | if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo()) |
| 684 | return Visit(TSInfo->getTypeLoc()); |
| 685 | |
| 686 | return false; |
| 687 | } |
| 688 | |
| 689 | bool CursorVisitor::VisitTypedefDecl(TypedefDecl *D) { |
| 690 | if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo()) |
| 691 | return Visit(TSInfo->getTypeLoc()); |
| 692 | |
| 693 | return false; |
| 694 | } |
| 695 | |
| 696 | bool CursorVisitor::VisitTagDecl(TagDecl *D) { |
| 697 | return VisitDeclContext(D); |
| 698 | } |
| 699 | |
| 700 | bool CursorVisitor::VisitClassTemplateSpecializationDecl( |
| 701 | ClassTemplateSpecializationDecl *D) { |
| 702 | bool ShouldVisitBody = false; |
| 703 | switch (D->getSpecializationKind()) { |
| 704 | case TSK_Undeclared: |
| 705 | case TSK_ImplicitInstantiation: |
| 706 | // Nothing to visit |
| 707 | return false; |
| 708 | |
| 709 | case TSK_ExplicitInstantiationDeclaration: |
| 710 | case TSK_ExplicitInstantiationDefinition: |
| 711 | break; |
| 712 | |
| 713 | case TSK_ExplicitSpecialization: |
| 714 | ShouldVisitBody = true; |
| 715 | break; |
| 716 | } |
| 717 | |
| 718 | // Visit the template arguments used in the specialization. |
| 719 | if (TypeSourceInfo *SpecType = D->getTypeAsWritten()) { |
| 720 | TypeLoc TL = SpecType->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 721 | if (TemplateSpecializationTypeLoc TSTLoc = |
| 722 | TL.getAs<TemplateSpecializationTypeLoc>()) { |
| 723 | for (unsigned I = 0, N = TSTLoc.getNumArgs(); I != N; ++I) |
| 724 | if (VisitTemplateArgumentLoc(TSTLoc.getArgLoc(I))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 725 | return true; |
| 726 | } |
| 727 | } |
Alexander Kornienko | 1a9f184 | 2015-12-28 15:24:08 +0000 | [diff] [blame] | 728 | |
| 729 | return ShouldVisitBody && VisitCXXRecordDecl(D); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | bool CursorVisitor::VisitClassTemplatePartialSpecializationDecl( |
| 733 | ClassTemplatePartialSpecializationDecl *D) { |
| 734 | // FIXME: Visit the "outer" template parameter lists on the TagDecl |
| 735 | // before visiting these template parameters. |
| 736 | if (VisitTemplateParameters(D->getTemplateParameters())) |
| 737 | return true; |
| 738 | |
| 739 | // Visit the partial specialization arguments. |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 740 | const ASTTemplateArgumentListInfo *Info = D->getTemplateArgsAsWritten(); |
| 741 | const TemplateArgumentLoc *TemplateArgs = Info->getTemplateArgs(); |
| 742 | for (unsigned I = 0, N = Info->NumTemplateArgs; I != N; ++I) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 743 | if (VisitTemplateArgumentLoc(TemplateArgs[I])) |
| 744 | return true; |
| 745 | |
| 746 | return VisitCXXRecordDecl(D); |
| 747 | } |
| 748 | |
| 749 | bool CursorVisitor::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 750 | // Visit the default argument. |
| 751 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) |
| 752 | if (TypeSourceInfo *DefArg = D->getDefaultArgumentInfo()) |
| 753 | if (Visit(DefArg->getTypeLoc())) |
| 754 | return true; |
| 755 | |
| 756 | return false; |
| 757 | } |
| 758 | |
| 759 | bool CursorVisitor::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 760 | if (Expr *Init = D->getInitExpr()) |
| 761 | return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest)); |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
Argyrios Kyrtzidis | 2ec7674 | 2013-04-05 21:04:10 +0000 | [diff] [blame] | 766 | unsigned NumParamList = DD->getNumTemplateParameterLists(); |
| 767 | for (unsigned i = 0; i < NumParamList; i++) { |
| 768 | TemplateParameterList* Params = DD->getTemplateParameterList(i); |
| 769 | if (VisitTemplateParameters(Params)) |
| 770 | return true; |
| 771 | } |
| 772 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 773 | if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo()) |
| 774 | if (Visit(TSInfo->getTypeLoc())) |
| 775 | return true; |
| 776 | |
| 777 | // Visit the nested-name-specifier, if present. |
| 778 | if (NestedNameSpecifierLoc QualifierLoc = DD->getQualifierLoc()) |
| 779 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 780 | return true; |
| 781 | |
| 782 | return false; |
| 783 | } |
| 784 | |
Benjamin Kramer | 4cadf29 | 2014-03-07 21:51:58 +0000 | [diff] [blame] | 785 | /// \brief Compare two base or member initializers based on their source order. |
| 786 | static int CompareCXXCtorInitializers(CXXCtorInitializer *const *X, |
| 787 | CXXCtorInitializer *const *Y) { |
| 788 | return (*X)->getSourceOrder() - (*Y)->getSourceOrder(); |
| 789 | } |
| 790 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 791 | bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) { |
Argyrios Kyrtzidis | 2ec7674 | 2013-04-05 21:04:10 +0000 | [diff] [blame] | 792 | unsigned NumParamList = ND->getNumTemplateParameterLists(); |
| 793 | for (unsigned i = 0; i < NumParamList; i++) { |
| 794 | TemplateParameterList* Params = ND->getTemplateParameterList(i); |
| 795 | if (VisitTemplateParameters(Params)) |
| 796 | return true; |
| 797 | } |
| 798 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 799 | if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) { |
| 800 | // Visit the function declaration's syntactic components in the order |
| 801 | // written. This requires a bit of work. |
| 802 | TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 803 | FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 804 | |
| 805 | // If we have a function declared directly (without the use of a typedef), |
| 806 | // visit just the return type. Otherwise, just visit the function's type |
| 807 | // now. |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 808 | if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL.getReturnLoc())) || |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 809 | (!FTL && Visit(TL))) |
| 810 | return true; |
| 811 | |
| 812 | // Visit the nested-name-specifier, if present. |
| 813 | if (NestedNameSpecifierLoc QualifierLoc = ND->getQualifierLoc()) |
| 814 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 815 | return true; |
| 816 | |
| 817 | // Visit the declaration name. |
Argyrios Kyrtzidis | 4a4d2b4 | 2014-02-09 08:13:47 +0000 | [diff] [blame] | 818 | if (!isa<CXXDestructorDecl>(ND)) |
| 819 | if (VisitDeclarationNameInfo(ND->getNameInfo())) |
| 820 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 821 | |
| 822 | // FIXME: Visit explicitly-specified template arguments! |
| 823 | |
| 824 | // Visit the function parameters, if we have a function type. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 825 | if (FTL && VisitFunctionTypeLoc(FTL, true)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 826 | return true; |
| 827 | |
Bill Wendling | 4442605 | 2012-12-20 19:22:21 +0000 | [diff] [blame] | 828 | // FIXME: Attributes? |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | if (ND->doesThisDeclarationHaveABody() && !ND->isLateTemplateParsed()) { |
| 832 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ND)) { |
| 833 | // Find the initializers that were written in the source. |
| 834 | SmallVector<CXXCtorInitializer *, 4> WrittenInits; |
Aaron Ballman | 0ad7830 | 2014-03-13 17:34:31 +0000 | [diff] [blame] | 835 | for (auto *I : Constructor->inits()) { |
| 836 | if (!I->isWritten()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 837 | continue; |
| 838 | |
Aaron Ballman | 0ad7830 | 2014-03-13 17:34:31 +0000 | [diff] [blame] | 839 | WrittenInits.push_back(I); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | // Sort the initializers in source order |
Benjamin Kramer | 4cadf29 | 2014-03-07 21:51:58 +0000 | [diff] [blame] | 843 | llvm::array_pod_sort(WrittenInits.begin(), WrittenInits.end(), |
| 844 | &CompareCXXCtorInitializers); |
| 845 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 846 | // Visit the initializers in source order |
| 847 | for (unsigned I = 0, N = WrittenInits.size(); I != N; ++I) { |
| 848 | CXXCtorInitializer *Init = WrittenInits[I]; |
| 849 | if (Init->isAnyMemberInitializer()) { |
| 850 | if (Visit(MakeCursorMemberRef(Init->getAnyMember(), |
| 851 | Init->getMemberLocation(), TU))) |
| 852 | return true; |
| 853 | } else if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) { |
| 854 | if (Visit(TInfo->getTypeLoc())) |
| 855 | return true; |
| 856 | } |
| 857 | |
| 858 | // Visit the initializer value. |
| 859 | if (Expr *Initializer = Init->getInit()) |
| 860 | if (Visit(MakeCXCursor(Initializer, ND, TU, RegionOfInterest))) |
| 861 | return true; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | if (Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest))) |
| 866 | return true; |
| 867 | } |
| 868 | |
| 869 | return false; |
| 870 | } |
| 871 | |
| 872 | bool CursorVisitor::VisitFieldDecl(FieldDecl *D) { |
| 873 | if (VisitDeclaratorDecl(D)) |
| 874 | return true; |
| 875 | |
| 876 | if (Expr *BitWidth = D->getBitWidth()) |
| 877 | return Visit(MakeCXCursor(BitWidth, StmtParent, TU, RegionOfInterest)); |
| 878 | |
| 879 | return false; |
| 880 | } |
| 881 | |
| 882 | bool CursorVisitor::VisitVarDecl(VarDecl *D) { |
| 883 | if (VisitDeclaratorDecl(D)) |
| 884 | return true; |
| 885 | |
| 886 | if (Expr *Init = D->getInit()) |
| 887 | return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest)); |
| 888 | |
| 889 | return false; |
| 890 | } |
| 891 | |
| 892 | bool CursorVisitor::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 893 | if (VisitDeclaratorDecl(D)) |
| 894 | return true; |
| 895 | |
| 896 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) |
| 897 | if (Expr *DefArg = D->getDefaultArgument()) |
| 898 | return Visit(MakeCXCursor(DefArg, StmtParent, TU, RegionOfInterest)); |
| 899 | |
| 900 | return false; |
| 901 | } |
| 902 | |
| 903 | bool CursorVisitor::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 904 | // FIXME: Visit the "outer" template parameter lists on the FunctionDecl |
| 905 | // before visiting these template parameters. |
| 906 | if (VisitTemplateParameters(D->getTemplateParameters())) |
| 907 | return true; |
| 908 | |
| 909 | return VisitFunctionDecl(D->getTemplatedDecl()); |
| 910 | } |
| 911 | |
| 912 | bool CursorVisitor::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 913 | // FIXME: Visit the "outer" template parameter lists on the TagDecl |
| 914 | // before visiting these template parameters. |
| 915 | if (VisitTemplateParameters(D->getTemplateParameters())) |
| 916 | return true; |
| 917 | |
| 918 | return VisitCXXRecordDecl(D->getTemplatedDecl()); |
| 919 | } |
| 920 | |
| 921 | bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 922 | if (VisitTemplateParameters(D->getTemplateParameters())) |
| 923 | return true; |
| 924 | |
| 925 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited() && |
| 926 | VisitTemplateArgumentLoc(D->getDefaultArgument())) |
| 927 | return true; |
| 928 | |
| 929 | return false; |
| 930 | } |
| 931 | |
Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 932 | bool CursorVisitor::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 933 | // Visit the bound, if it's explicit. |
| 934 | if (D->hasExplicitBound()) { |
| 935 | if (auto TInfo = D->getTypeSourceInfo()) { |
| 936 | if (Visit(TInfo->getTypeLoc())) |
| 937 | return true; |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | return false; |
| 942 | } |
| 943 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 944 | bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 945 | if (TypeSourceInfo *TSInfo = ND->getReturnTypeSourceInfo()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 946 | if (Visit(TSInfo->getTypeLoc())) |
| 947 | return true; |
| 948 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 949 | for (const auto *P : ND->parameters()) { |
Aaron Ballman | 43b68be | 2014-03-07 17:50:17 +0000 | [diff] [blame] | 950 | if (Visit(MakeCXCursor(P, TU, RegionOfInterest))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 951 | return true; |
| 952 | } |
| 953 | |
Alexander Kornienko | 1a9f184 | 2015-12-28 15:24:08 +0000 | [diff] [blame] | 954 | return ND->isThisDeclarationADefinition() && |
| 955 | Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | template <typename DeclIt> |
| 959 | static void addRangedDeclsInContainer(DeclIt *DI_current, DeclIt DE_current, |
| 960 | SourceManager &SM, SourceLocation EndLoc, |
| 961 | SmallVectorImpl<Decl *> &Decls) { |
| 962 | DeclIt next = *DI_current; |
| 963 | while (++next != DE_current) { |
| 964 | Decl *D_next = *next; |
| 965 | if (!D_next) |
| 966 | break; |
| 967 | SourceLocation L = D_next->getLocStart(); |
| 968 | if (!L.isValid()) |
| 969 | break; |
| 970 | if (SM.isBeforeInTranslationUnit(L, EndLoc)) { |
| 971 | *DI_current = next; |
| 972 | Decls.push_back(D_next); |
| 973 | continue; |
| 974 | } |
| 975 | break; |
| 976 | } |
| 977 | } |
| 978 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 979 | bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
| 980 | // FIXME: Eventually convert back to just 'VisitDeclContext()'. Essentially |
| 981 | // an @implementation can lexically contain Decls that are not properly |
| 982 | // nested in the AST. When we identify such cases, we need to retrofit |
| 983 | // this nesting here. |
| 984 | if (!DI_current && !FileDI_current) |
| 985 | return VisitDeclContext(D); |
| 986 | |
| 987 | // Scan the Decls that immediately come after the container |
| 988 | // in the current DeclContext. If any fall within the |
| 989 | // container's lexical region, stash them into a vector |
| 990 | // for later processing. |
| 991 | SmallVector<Decl *, 24> DeclsInContainer; |
| 992 | SourceLocation EndLoc = D->getSourceRange().getEnd(); |
| 993 | SourceManager &SM = AU->getSourceManager(); |
| 994 | if (EndLoc.isValid()) { |
| 995 | if (DI_current) { |
| 996 | addRangedDeclsInContainer(DI_current, DE_current, SM, EndLoc, |
| 997 | DeclsInContainer); |
| 998 | } else { |
| 999 | addRangedDeclsInContainer(FileDI_current, FileDE_current, SM, EndLoc, |
| 1000 | DeclsInContainer); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | // The common case. |
| 1005 | if (DeclsInContainer.empty()) |
| 1006 | return VisitDeclContext(D); |
| 1007 | |
| 1008 | // Get all the Decls in the DeclContext, and sort them with the |
| 1009 | // additional ones we've collected. Then visit them. |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1010 | for (auto *SubDecl : D->decls()) { |
| 1011 | if (!SubDecl || SubDecl->getLexicalDeclContext() != D || |
| 1012 | SubDecl->getLocStart().isInvalid()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1013 | continue; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1014 | DeclsInContainer.push_back(SubDecl); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | // Now sort the Decls so that they appear in lexical order. |
| 1018 | std::sort(DeclsInContainer.begin(), DeclsInContainer.end(), |
Benjamin Kramer | bbdd764 | 2014-03-01 14:48:57 +0000 | [diff] [blame] | 1019 | [&SM](Decl *A, Decl *B) { |
| 1020 | SourceLocation L_A = A->getLocStart(); |
| 1021 | SourceLocation L_B = B->getLocStart(); |
| 1022 | assert(L_A.isValid() && L_B.isValid()); |
| 1023 | return SM.isBeforeInTranslationUnit(L_A, L_B); |
| 1024 | }); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1025 | |
| 1026 | // Now visit the decls. |
| 1027 | for (SmallVectorImpl<Decl*>::iterator I = DeclsInContainer.begin(), |
| 1028 | E = DeclsInContainer.end(); I != E; ++I) { |
| 1029 | CXCursor Cursor = MakeCXCursor(*I, TU, RegionOfInterest); |
Ted Kremenek | 0332558 | 2013-02-21 01:29:01 +0000 | [diff] [blame] | 1030 | const Optional<bool> &V = shouldVisitCursor(Cursor); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1031 | if (!V.hasValue()) |
| 1032 | continue; |
| 1033 | if (!V.getValue()) |
| 1034 | return false; |
| 1035 | if (Visit(Cursor, true)) |
| 1036 | return true; |
| 1037 | } |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
| 1041 | bool CursorVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { |
| 1042 | if (Visit(MakeCursorObjCClassRef(ND->getClassInterface(), ND->getLocation(), |
| 1043 | TU))) |
| 1044 | return true; |
| 1045 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1046 | if (VisitObjCTypeParamList(ND->getTypeParamList())) |
| 1047 | return true; |
| 1048 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1049 | ObjCCategoryDecl::protocol_loc_iterator PL = ND->protocol_loc_begin(); |
| 1050 | for (ObjCCategoryDecl::protocol_iterator I = ND->protocol_begin(), |
| 1051 | E = ND->protocol_end(); I != E; ++I, ++PL) |
| 1052 | if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) |
| 1053 | return true; |
| 1054 | |
| 1055 | return VisitObjCContainerDecl(ND); |
| 1056 | } |
| 1057 | |
| 1058 | bool CursorVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { |
| 1059 | if (!PID->isThisDeclarationADefinition()) |
| 1060 | return Visit(MakeCursorObjCProtocolRef(PID, PID->getLocation(), TU)); |
| 1061 | |
| 1062 | ObjCProtocolDecl::protocol_loc_iterator PL = PID->protocol_loc_begin(); |
| 1063 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
| 1064 | E = PID->protocol_end(); I != E; ++I, ++PL) |
| 1065 | if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) |
| 1066 | return true; |
| 1067 | |
| 1068 | return VisitObjCContainerDecl(PID); |
| 1069 | } |
| 1070 | |
| 1071 | bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) { |
| 1072 | if (PD->getTypeSourceInfo() && Visit(PD->getTypeSourceInfo()->getTypeLoc())) |
| 1073 | return true; |
| 1074 | |
| 1075 | // FIXME: This implements a workaround with @property declarations also being |
| 1076 | // installed in the DeclContext for the @interface. Eventually this code |
| 1077 | // should be removed. |
| 1078 | ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(PD->getDeclContext()); |
| 1079 | if (!CDecl || !CDecl->IsClassExtension()) |
| 1080 | return false; |
| 1081 | |
| 1082 | ObjCInterfaceDecl *ID = CDecl->getClassInterface(); |
| 1083 | if (!ID) |
| 1084 | return false; |
| 1085 | |
| 1086 | IdentifierInfo *PropertyId = PD->getIdentifier(); |
| 1087 | ObjCPropertyDecl *prevDecl = |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 1088 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(ID), PropertyId, |
| 1089 | PD->getQueryKind()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1090 | |
| 1091 | if (!prevDecl) |
| 1092 | return false; |
| 1093 | |
| 1094 | // Visit synthesized methods since they will be skipped when visiting |
| 1095 | // the @interface. |
| 1096 | if (ObjCMethodDecl *MD = prevDecl->getGetterMethodDecl()) |
| 1097 | if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl) |
| 1098 | if (Visit(MakeCXCursor(MD, TU, RegionOfInterest))) |
| 1099 | return true; |
| 1100 | |
| 1101 | if (ObjCMethodDecl *MD = prevDecl->getSetterMethodDecl()) |
| 1102 | if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl) |
| 1103 | if (Visit(MakeCXCursor(MD, TU, RegionOfInterest))) |
| 1104 | return true; |
| 1105 | |
| 1106 | return false; |
| 1107 | } |
| 1108 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1109 | bool CursorVisitor::VisitObjCTypeParamList(ObjCTypeParamList *typeParamList) { |
| 1110 | if (!typeParamList) |
| 1111 | return false; |
| 1112 | |
| 1113 | for (auto *typeParam : *typeParamList) { |
| 1114 | // Visit the type parameter. |
| 1115 | if (Visit(MakeCXCursor(typeParam, TU, RegionOfInterest))) |
| 1116 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | return false; |
| 1120 | } |
| 1121 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1122 | bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| 1123 | if (!D->isThisDeclarationADefinition()) { |
| 1124 | // Forward declaration is treated like a reference. |
| 1125 | return Visit(MakeCursorObjCClassRef(D, D->getLocation(), TU)); |
| 1126 | } |
| 1127 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1128 | // Objective-C type parameters. |
| 1129 | if (VisitObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 1130 | return true; |
| 1131 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1132 | // Issue callbacks for super class. |
| 1133 | if (D->getSuperClass() && |
| 1134 | Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(), |
| 1135 | D->getSuperClassLoc(), |
| 1136 | TU))) |
| 1137 | return true; |
| 1138 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1139 | if (TypeSourceInfo *SuperClassTInfo = D->getSuperClassTInfo()) |
| 1140 | if (Visit(SuperClassTInfo->getTypeLoc())) |
| 1141 | return true; |
| 1142 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1143 | ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(); |
| 1144 | for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(), |
| 1145 | E = D->protocol_end(); I != E; ++I, ++PL) |
| 1146 | if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) |
| 1147 | return true; |
| 1148 | |
| 1149 | return VisitObjCContainerDecl(D); |
| 1150 | } |
| 1151 | |
| 1152 | bool CursorVisitor::VisitObjCImplDecl(ObjCImplDecl *D) { |
| 1153 | return VisitObjCContainerDecl(D); |
| 1154 | } |
| 1155 | |
| 1156 | bool CursorVisitor::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 1157 | // 'ID' could be null when dealing with invalid code. |
| 1158 | if (ObjCInterfaceDecl *ID = D->getClassInterface()) |
| 1159 | if (Visit(MakeCursorObjCClassRef(ID, D->getLocation(), TU))) |
| 1160 | return true; |
| 1161 | |
| 1162 | return VisitObjCImplDecl(D); |
| 1163 | } |
| 1164 | |
| 1165 | bool CursorVisitor::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 1166 | #if 0 |
| 1167 | // Issue callbacks for super class. |
| 1168 | // FIXME: No source location information! |
| 1169 | if (D->getSuperClass() && |
| 1170 | Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(), |
| 1171 | D->getSuperClassLoc(), |
| 1172 | TU))) |
| 1173 | return true; |
| 1174 | #endif |
| 1175 | |
| 1176 | return VisitObjCImplDecl(D); |
| 1177 | } |
| 1178 | |
| 1179 | bool CursorVisitor::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PD) { |
| 1180 | if (ObjCIvarDecl *Ivar = PD->getPropertyIvarDecl()) |
| 1181 | if (PD->isIvarNameSpecified()) |
| 1182 | return Visit(MakeCursorMemberRef(Ivar, PD->getPropertyIvarDeclLoc(), TU)); |
| 1183 | |
| 1184 | return false; |
| 1185 | } |
| 1186 | |
| 1187 | bool CursorVisitor::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1188 | return VisitDeclContext(D); |
| 1189 | } |
| 1190 | |
| 1191 | bool CursorVisitor::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1192 | // Visit nested-name-specifier. |
| 1193 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
| 1194 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 1195 | return true; |
| 1196 | |
| 1197 | return Visit(MakeCursorNamespaceRef(D->getAliasedNamespace(), |
| 1198 | D->getTargetNameLoc(), TU)); |
| 1199 | } |
| 1200 | |
| 1201 | bool CursorVisitor::VisitUsingDecl(UsingDecl *D) { |
| 1202 | // Visit nested-name-specifier. |
| 1203 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) { |
| 1204 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 1205 | return true; |
| 1206 | } |
| 1207 | |
| 1208 | if (Visit(MakeCursorOverloadedDeclRef(D, D->getLocation(), TU))) |
| 1209 | return true; |
| 1210 | |
| 1211 | return VisitDeclarationNameInfo(D->getNameInfo()); |
| 1212 | } |
| 1213 | |
| 1214 | bool CursorVisitor::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 1215 | // Visit nested-name-specifier. |
| 1216 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
| 1217 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 1218 | return true; |
| 1219 | |
| 1220 | return Visit(MakeCursorNamespaceRef(D->getNominatedNamespaceAsWritten(), |
| 1221 | D->getIdentLocation(), TU)); |
| 1222 | } |
| 1223 | |
| 1224 | bool CursorVisitor::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
| 1225 | // Visit nested-name-specifier. |
| 1226 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) { |
| 1227 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 1228 | return true; |
| 1229 | } |
| 1230 | |
| 1231 | return VisitDeclarationNameInfo(D->getNameInfo()); |
| 1232 | } |
| 1233 | |
| 1234 | bool CursorVisitor::VisitUnresolvedUsingTypenameDecl( |
| 1235 | UnresolvedUsingTypenameDecl *D) { |
| 1236 | // Visit nested-name-specifier. |
| 1237 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
| 1238 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 1239 | return true; |
| 1240 | |
| 1241 | return false; |
| 1242 | } |
| 1243 | |
Olivier Goffart | 8197801 | 2016-06-09 16:15:55 +0000 | [diff] [blame] | 1244 | bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1245 | if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest))) |
| 1246 | return true; |
Richard Trieu | f3b7766 | 2016-09-13 01:37:01 +0000 | [diff] [blame] | 1247 | if (StringLiteral *Message = D->getMessage()) |
| 1248 | if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest))) |
| 1249 | return true; |
Olivier Goffart | 8197801 | 2016-06-09 16:15:55 +0000 | [diff] [blame] | 1250 | return false; |
| 1251 | } |
| 1252 | |
Olivier Goffart | d211c64 | 2016-11-04 06:29:27 +0000 | [diff] [blame] | 1253 | bool CursorVisitor::VisitFriendDecl(FriendDecl *D) { |
| 1254 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| 1255 | if (Visit(MakeCXCursor(FriendD, TU, RegionOfInterest))) |
| 1256 | return true; |
| 1257 | } else if (TypeSourceInfo *TI = D->getFriendType()) { |
| 1258 | if (Visit(TI->getTypeLoc())) |
| 1259 | return true; |
| 1260 | } |
| 1261 | return false; |
| 1262 | } |
| 1263 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1264 | bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) { |
| 1265 | switch (Name.getName().getNameKind()) { |
| 1266 | case clang::DeclarationName::Identifier: |
| 1267 | case clang::DeclarationName::CXXLiteralOperatorName: |
| 1268 | case clang::DeclarationName::CXXOperatorName: |
| 1269 | case clang::DeclarationName::CXXUsingDirective: |
| 1270 | return false; |
| 1271 | |
| 1272 | case clang::DeclarationName::CXXConstructorName: |
| 1273 | case clang::DeclarationName::CXXDestructorName: |
| 1274 | case clang::DeclarationName::CXXConversionFunctionName: |
| 1275 | if (TypeSourceInfo *TSInfo = Name.getNamedTypeInfo()) |
| 1276 | return Visit(TSInfo->getTypeLoc()); |
| 1277 | return false; |
| 1278 | |
| 1279 | case clang::DeclarationName::ObjCZeroArgSelector: |
| 1280 | case clang::DeclarationName::ObjCOneArgSelector: |
| 1281 | case clang::DeclarationName::ObjCMultiArgSelector: |
| 1282 | // FIXME: Per-identifier location info? |
| 1283 | return false; |
| 1284 | } |
| 1285 | |
| 1286 | llvm_unreachable("Invalid DeclarationName::Kind!"); |
| 1287 | } |
| 1288 | |
| 1289 | bool CursorVisitor::VisitNestedNameSpecifier(NestedNameSpecifier *NNS, |
| 1290 | SourceRange Range) { |
| 1291 | // FIXME: This whole routine is a hack to work around the lack of proper |
| 1292 | // source information in nested-name-specifiers (PR5791). Since we do have |
| 1293 | // a beginning source location, we can visit the first component of the |
| 1294 | // nested-name-specifier, if it's a single-token component. |
| 1295 | if (!NNS) |
| 1296 | return false; |
| 1297 | |
| 1298 | // Get the first component in the nested-name-specifier. |
| 1299 | while (NestedNameSpecifier *Prefix = NNS->getPrefix()) |
| 1300 | NNS = Prefix; |
| 1301 | |
| 1302 | switch (NNS->getKind()) { |
| 1303 | case NestedNameSpecifier::Namespace: |
| 1304 | return Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(), Range.getBegin(), |
| 1305 | TU)); |
| 1306 | |
| 1307 | case NestedNameSpecifier::NamespaceAlias: |
| 1308 | return Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(), |
| 1309 | Range.getBegin(), TU)); |
| 1310 | |
| 1311 | case NestedNameSpecifier::TypeSpec: { |
| 1312 | // If the type has a form where we know that the beginning of the source |
| 1313 | // range matches up with a reference cursor. Visit the appropriate reference |
| 1314 | // cursor. |
| 1315 | const Type *T = NNS->getAsType(); |
| 1316 | if (const TypedefType *Typedef = dyn_cast<TypedefType>(T)) |
| 1317 | return Visit(MakeCursorTypeRef(Typedef->getDecl(), Range.getBegin(), TU)); |
| 1318 | if (const TagType *Tag = dyn_cast<TagType>(T)) |
| 1319 | return Visit(MakeCursorTypeRef(Tag->getDecl(), Range.getBegin(), TU)); |
| 1320 | if (const TemplateSpecializationType *TST |
| 1321 | = dyn_cast<TemplateSpecializationType>(T)) |
| 1322 | return VisitTemplateName(TST->getTemplateName(), Range.getBegin()); |
| 1323 | break; |
| 1324 | } |
| 1325 | |
| 1326 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1327 | case NestedNameSpecifier::Global: |
| 1328 | case NestedNameSpecifier::Identifier: |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 1329 | case NestedNameSpecifier::Super: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1330 | break; |
| 1331 | } |
| 1332 | |
| 1333 | return false; |
| 1334 | } |
| 1335 | |
| 1336 | bool |
| 1337 | CursorVisitor::VisitNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier) { |
| 1338 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| 1339 | for (; Qualifier; Qualifier = Qualifier.getPrefix()) |
| 1340 | Qualifiers.push_back(Qualifier); |
| 1341 | |
| 1342 | while (!Qualifiers.empty()) { |
| 1343 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 1344 | NestedNameSpecifier *NNS = Q.getNestedNameSpecifier(); |
| 1345 | switch (NNS->getKind()) { |
| 1346 | case NestedNameSpecifier::Namespace: |
| 1347 | if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(), |
| 1348 | Q.getLocalBeginLoc(), |
| 1349 | TU))) |
| 1350 | return true; |
| 1351 | |
| 1352 | break; |
| 1353 | |
| 1354 | case NestedNameSpecifier::NamespaceAlias: |
| 1355 | if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(), |
| 1356 | Q.getLocalBeginLoc(), |
| 1357 | TU))) |
| 1358 | return true; |
| 1359 | |
| 1360 | break; |
| 1361 | |
| 1362 | case NestedNameSpecifier::TypeSpec: |
| 1363 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1364 | if (Visit(Q.getTypeLoc())) |
| 1365 | return true; |
| 1366 | |
| 1367 | break; |
| 1368 | |
| 1369 | case NestedNameSpecifier::Global: |
| 1370 | case NestedNameSpecifier::Identifier: |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 1371 | case NestedNameSpecifier::Super: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1372 | break; |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | return false; |
| 1377 | } |
| 1378 | |
| 1379 | bool CursorVisitor::VisitTemplateParameters( |
| 1380 | const TemplateParameterList *Params) { |
| 1381 | if (!Params) |
| 1382 | return false; |
| 1383 | |
| 1384 | for (TemplateParameterList::const_iterator P = Params->begin(), |
| 1385 | PEnd = Params->end(); |
| 1386 | P != PEnd; ++P) { |
| 1387 | if (Visit(MakeCXCursor(*P, TU, RegionOfInterest))) |
| 1388 | return true; |
| 1389 | } |
| 1390 | |
| 1391 | return false; |
| 1392 | } |
| 1393 | |
| 1394 | bool CursorVisitor::VisitTemplateName(TemplateName Name, SourceLocation Loc) { |
| 1395 | switch (Name.getKind()) { |
| 1396 | case TemplateName::Template: |
| 1397 | return Visit(MakeCursorTemplateRef(Name.getAsTemplateDecl(), Loc, TU)); |
| 1398 | |
| 1399 | case TemplateName::OverloadedTemplate: |
| 1400 | // Visit the overloaded template set. |
| 1401 | if (Visit(MakeCursorOverloadedDeclRef(Name, Loc, TU))) |
| 1402 | return true; |
| 1403 | |
| 1404 | return false; |
| 1405 | |
| 1406 | case TemplateName::DependentTemplate: |
| 1407 | // FIXME: Visit nested-name-specifier. |
| 1408 | return false; |
| 1409 | |
| 1410 | case TemplateName::QualifiedTemplate: |
| 1411 | // FIXME: Visit nested-name-specifier. |
| 1412 | return Visit(MakeCursorTemplateRef( |
| 1413 | Name.getAsQualifiedTemplateName()->getDecl(), |
| 1414 | Loc, TU)); |
| 1415 | |
| 1416 | case TemplateName::SubstTemplateTemplateParm: |
| 1417 | return Visit(MakeCursorTemplateRef( |
| 1418 | Name.getAsSubstTemplateTemplateParm()->getParameter(), |
| 1419 | Loc, TU)); |
| 1420 | |
| 1421 | case TemplateName::SubstTemplateTemplateParmPack: |
| 1422 | return Visit(MakeCursorTemplateRef( |
| 1423 | Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(), |
| 1424 | Loc, TU)); |
| 1425 | } |
| 1426 | |
| 1427 | llvm_unreachable("Invalid TemplateName::Kind!"); |
| 1428 | } |
| 1429 | |
| 1430 | bool CursorVisitor::VisitTemplateArgumentLoc(const TemplateArgumentLoc &TAL) { |
| 1431 | switch (TAL.getArgument().getKind()) { |
| 1432 | case TemplateArgument::Null: |
| 1433 | case TemplateArgument::Integral: |
| 1434 | case TemplateArgument::Pack: |
| 1435 | return false; |
| 1436 | |
| 1437 | case TemplateArgument::Type: |
| 1438 | if (TypeSourceInfo *TSInfo = TAL.getTypeSourceInfo()) |
| 1439 | return Visit(TSInfo->getTypeLoc()); |
| 1440 | return false; |
| 1441 | |
| 1442 | case TemplateArgument::Declaration: |
| 1443 | if (Expr *E = TAL.getSourceDeclExpression()) |
| 1444 | return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest)); |
| 1445 | return false; |
| 1446 | |
| 1447 | case TemplateArgument::NullPtr: |
| 1448 | if (Expr *E = TAL.getSourceNullPtrExpression()) |
| 1449 | return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest)); |
| 1450 | return false; |
| 1451 | |
| 1452 | case TemplateArgument::Expression: |
| 1453 | if (Expr *E = TAL.getSourceExpression()) |
| 1454 | return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest)); |
| 1455 | return false; |
| 1456 | |
| 1457 | case TemplateArgument::Template: |
| 1458 | case TemplateArgument::TemplateExpansion: |
| 1459 | if (VisitNestedNameSpecifierLoc(TAL.getTemplateQualifierLoc())) |
| 1460 | return true; |
| 1461 | |
| 1462 | return VisitTemplateName(TAL.getArgument().getAsTemplateOrTemplatePattern(), |
| 1463 | TAL.getTemplateNameLoc()); |
| 1464 | } |
| 1465 | |
| 1466 | llvm_unreachable("Invalid TemplateArgument::Kind!"); |
| 1467 | } |
| 1468 | |
| 1469 | bool CursorVisitor::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 1470 | return VisitDeclContext(D); |
| 1471 | } |
| 1472 | |
| 1473 | bool CursorVisitor::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 1474 | return Visit(TL.getUnqualifiedLoc()); |
| 1475 | } |
| 1476 | |
| 1477 | bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
| 1478 | ASTContext &Context = AU->getASTContext(); |
| 1479 | |
| 1480 | // Some builtin types (such as Objective-C's "id", "sel", and |
| 1481 | // "Class") have associated declarations. Create cursors for those. |
| 1482 | QualType VisitType; |
| 1483 | switch (TL.getTypePtr()->getKind()) { |
| 1484 | |
| 1485 | case BuiltinType::Void: |
| 1486 | case BuiltinType::NullPtr: |
| 1487 | case BuiltinType::Dependent: |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 1488 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 1489 | case BuiltinType::Id: |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 1490 | #include "clang/Basic/OpenCLImageTypes.def" |
NAKAMURA Takumi | 288c42e | 2013-02-07 12:47:42 +0000 | [diff] [blame] | 1491 | case BuiltinType::OCLSampler: |
Guy Benyei | 1b4fb3e | 2013-01-20 12:31:11 +0000 | [diff] [blame] | 1492 | case BuiltinType::OCLEvent: |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 1493 | case BuiltinType::OCLClkEvent: |
| 1494 | case BuiltinType::OCLQueue: |
| 1495 | case BuiltinType::OCLNDRange: |
| 1496 | case BuiltinType::OCLReserveID: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1497 | #define BUILTIN_TYPE(Id, SingletonId) |
| 1498 | #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: |
| 1499 | #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: |
| 1500 | #define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id: |
| 1501 | #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id: |
| 1502 | #include "clang/AST/BuiltinTypes.def" |
| 1503 | break; |
| 1504 | |
| 1505 | case BuiltinType::ObjCId: |
| 1506 | VisitType = Context.getObjCIdType(); |
| 1507 | break; |
| 1508 | |
| 1509 | case BuiltinType::ObjCClass: |
| 1510 | VisitType = Context.getObjCClassType(); |
| 1511 | break; |
| 1512 | |
| 1513 | case BuiltinType::ObjCSel: |
| 1514 | VisitType = Context.getObjCSelType(); |
| 1515 | break; |
| 1516 | } |
| 1517 | |
| 1518 | if (!VisitType.isNull()) { |
| 1519 | if (const TypedefType *Typedef = VisitType->getAs<TypedefType>()) |
| 1520 | return Visit(MakeCursorTypeRef(Typedef->getDecl(), TL.getBuiltinLoc(), |
| 1521 | TU)); |
| 1522 | } |
| 1523 | |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
| 1527 | bool CursorVisitor::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 1528 | return Visit(MakeCursorTypeRef(TL.getTypedefNameDecl(), TL.getNameLoc(), TU)); |
| 1529 | } |
| 1530 | |
| 1531 | bool CursorVisitor::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 1532 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
| 1533 | } |
| 1534 | |
| 1535 | bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) { |
| 1536 | if (TL.isDefinition()) |
| 1537 | return Visit(MakeCXCursor(TL.getDecl(), TU, RegionOfInterest)); |
| 1538 | |
| 1539 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
| 1540 | } |
| 1541 | |
| 1542 | bool CursorVisitor::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 1543 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
| 1544 | } |
| 1545 | |
| 1546 | bool CursorVisitor::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 1547 | return Visit(MakeCursorObjCClassRef(TL.getIFaceDecl(), TL.getNameLoc(), TU)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 1550 | bool CursorVisitor::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 1551 | if (Visit(MakeCursorTypeRef(TL.getDecl(), TL.getLocStart(), TU))) |
| 1552 | return true; |
| 1553 | for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { |
| 1554 | if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I), |
| 1555 | TU))) |
| 1556 | return true; |
| 1557 | } |
| 1558 | |
| 1559 | return false; |
| 1560 | } |
| 1561 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1562 | bool CursorVisitor::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 1563 | if (TL.hasBaseTypeAsWritten() && Visit(TL.getBaseLoc())) |
| 1564 | return true; |
| 1565 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1566 | for (unsigned I = 0, N = TL.getNumTypeArgs(); I != N; ++I) { |
| 1567 | if (Visit(TL.getTypeArgTInfo(I)->getTypeLoc())) |
| 1568 | return true; |
| 1569 | } |
| 1570 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1571 | for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { |
| 1572 | if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I), |
| 1573 | TU))) |
| 1574 | return true; |
| 1575 | } |
| 1576 | |
| 1577 | return false; |
| 1578 | } |
| 1579 | |
| 1580 | bool CursorVisitor::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 1581 | return Visit(TL.getPointeeLoc()); |
| 1582 | } |
| 1583 | |
| 1584 | bool CursorVisitor::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 1585 | return Visit(TL.getInnerLoc()); |
| 1586 | } |
| 1587 | |
| 1588 | bool CursorVisitor::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 1589 | return Visit(TL.getPointeeLoc()); |
| 1590 | } |
| 1591 | |
| 1592 | bool CursorVisitor::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 1593 | return Visit(TL.getPointeeLoc()); |
| 1594 | } |
| 1595 | |
| 1596 | bool CursorVisitor::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 1597 | return Visit(TL.getPointeeLoc()); |
| 1598 | } |
| 1599 | |
| 1600 | bool CursorVisitor::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 1601 | return Visit(TL.getPointeeLoc()); |
| 1602 | } |
| 1603 | |
| 1604 | bool CursorVisitor::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 1605 | return Visit(TL.getPointeeLoc()); |
| 1606 | } |
| 1607 | |
| 1608 | bool CursorVisitor::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 1609 | return Visit(TL.getModifiedLoc()); |
| 1610 | } |
| 1611 | |
| 1612 | bool CursorVisitor::VisitFunctionTypeLoc(FunctionTypeLoc TL, |
| 1613 | bool SkipResultType) { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 1614 | if (!SkipResultType && Visit(TL.getReturnLoc())) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1615 | return true; |
| 1616 | |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 1617 | for (unsigned I = 0, N = TL.getNumParams(); I != N; ++I) |
| 1618 | if (Decl *D = TL.getParam(I)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1619 | if (Visit(MakeCXCursor(D, TU, RegionOfInterest))) |
| 1620 | return true; |
| 1621 | |
| 1622 | return false; |
| 1623 | } |
| 1624 | |
| 1625 | bool CursorVisitor::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 1626 | if (Visit(TL.getElementLoc())) |
| 1627 | return true; |
| 1628 | |
| 1629 | if (Expr *Size = TL.getSizeExpr()) |
| 1630 | return Visit(MakeCXCursor(Size, StmtParent, TU, RegionOfInterest)); |
| 1631 | |
| 1632 | return false; |
| 1633 | } |
| 1634 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 1635 | bool CursorVisitor::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 1636 | return Visit(TL.getOriginalLoc()); |
| 1637 | } |
| 1638 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 1639 | bool CursorVisitor::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 1640 | return Visit(TL.getOriginalLoc()); |
| 1641 | } |
| 1642 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1643 | bool CursorVisitor::VisitTemplateSpecializationTypeLoc( |
| 1644 | TemplateSpecializationTypeLoc TL) { |
| 1645 | // Visit the template name. |
| 1646 | if (VisitTemplateName(TL.getTypePtr()->getTemplateName(), |
| 1647 | TL.getTemplateNameLoc())) |
| 1648 | return true; |
| 1649 | |
| 1650 | // Visit the template arguments. |
| 1651 | for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I) |
| 1652 | if (VisitTemplateArgumentLoc(TL.getArgLoc(I))) |
| 1653 | return true; |
| 1654 | |
| 1655 | return false; |
| 1656 | } |
| 1657 | |
| 1658 | bool CursorVisitor::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
| 1659 | return Visit(MakeCXCursor(TL.getUnderlyingExpr(), StmtParent, TU)); |
| 1660 | } |
| 1661 | |
| 1662 | bool CursorVisitor::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
| 1663 | if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo()) |
| 1664 | return Visit(TSInfo->getTypeLoc()); |
| 1665 | |
| 1666 | return false; |
| 1667 | } |
| 1668 | |
| 1669 | bool CursorVisitor::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 1670 | if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo()) |
| 1671 | return Visit(TSInfo->getTypeLoc()); |
| 1672 | |
| 1673 | return false; |
| 1674 | } |
| 1675 | |
| 1676 | bool CursorVisitor::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 1677 | return VisitNestedNameSpecifierLoc(TL.getQualifierLoc()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | bool CursorVisitor::VisitDependentTemplateSpecializationTypeLoc( |
| 1681 | DependentTemplateSpecializationTypeLoc TL) { |
| 1682 | // Visit the nested-name-specifier, if there is one. |
| 1683 | if (TL.getQualifierLoc() && |
| 1684 | VisitNestedNameSpecifierLoc(TL.getQualifierLoc())) |
| 1685 | return true; |
| 1686 | |
| 1687 | // Visit the template arguments. |
| 1688 | for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I) |
| 1689 | if (VisitTemplateArgumentLoc(TL.getArgLoc(I))) |
| 1690 | return true; |
| 1691 | |
| 1692 | return false; |
| 1693 | } |
| 1694 | |
| 1695 | bool CursorVisitor::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
| 1696 | if (VisitNestedNameSpecifierLoc(TL.getQualifierLoc())) |
| 1697 | return true; |
| 1698 | |
| 1699 | return Visit(TL.getNamedTypeLoc()); |
| 1700 | } |
| 1701 | |
| 1702 | bool CursorVisitor::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 1703 | return Visit(TL.getPatternLoc()); |
| 1704 | } |
| 1705 | |
| 1706 | bool CursorVisitor::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 1707 | if (Expr *E = TL.getUnderlyingExpr()) |
| 1708 | return Visit(MakeCXCursor(E, StmtParent, TU)); |
| 1709 | |
| 1710 | return false; |
| 1711 | } |
| 1712 | |
| 1713 | bool CursorVisitor::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 1714 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
| 1715 | } |
| 1716 | |
| 1717 | bool CursorVisitor::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 1718 | return Visit(TL.getValueLoc()); |
| 1719 | } |
| 1720 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 1721 | bool CursorVisitor::VisitPipeTypeLoc(PipeTypeLoc TL) { |
| 1722 | return Visit(TL.getValueLoc()); |
| 1723 | } |
| 1724 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1725 | #define DEFAULT_TYPELOC_IMPL(CLASS, PARENT) \ |
| 1726 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ |
| 1727 | return Visit##PARENT##Loc(TL); \ |
| 1728 | } |
| 1729 | |
| 1730 | DEFAULT_TYPELOC_IMPL(Complex, Type) |
| 1731 | DEFAULT_TYPELOC_IMPL(ConstantArray, ArrayType) |
| 1732 | DEFAULT_TYPELOC_IMPL(IncompleteArray, ArrayType) |
| 1733 | DEFAULT_TYPELOC_IMPL(VariableArray, ArrayType) |
| 1734 | DEFAULT_TYPELOC_IMPL(DependentSizedArray, ArrayType) |
| 1735 | DEFAULT_TYPELOC_IMPL(DependentSizedExtVector, Type) |
| 1736 | DEFAULT_TYPELOC_IMPL(Vector, Type) |
| 1737 | DEFAULT_TYPELOC_IMPL(ExtVector, VectorType) |
| 1738 | DEFAULT_TYPELOC_IMPL(FunctionProto, FunctionType) |
| 1739 | DEFAULT_TYPELOC_IMPL(FunctionNoProto, FunctionType) |
| 1740 | DEFAULT_TYPELOC_IMPL(Record, TagType) |
| 1741 | DEFAULT_TYPELOC_IMPL(Enum, TagType) |
| 1742 | DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParm, Type) |
| 1743 | DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParmPack, Type) |
| 1744 | DEFAULT_TYPELOC_IMPL(Auto, Type) |
| 1745 | |
| 1746 | bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 1747 | // Visit the nested-name-specifier, if present. |
| 1748 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
| 1749 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 1750 | return true; |
| 1751 | |
| 1752 | if (D->isCompleteDefinition()) { |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1753 | for (const auto &I : D->bases()) { |
| 1754 | if (Visit(cxcursor::MakeCursorCXXBaseSpecifier(&I, TU))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1755 | return true; |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | return VisitTagDecl(D); |
| 1760 | } |
| 1761 | |
| 1762 | bool CursorVisitor::VisitAttributes(Decl *D) { |
Aaron Ballman | b97112e | 2014-03-08 22:19:01 +0000 | [diff] [blame] | 1763 | for (const auto *I : D->attrs()) |
| 1764 | if (Visit(MakeCXCursor(I, D, TU))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1765 | return true; |
| 1766 | |
| 1767 | return false; |
| 1768 | } |
| 1769 | |
| 1770 | //===----------------------------------------------------------------------===// |
| 1771 | // Data-recursive visitor methods. |
| 1772 | //===----------------------------------------------------------------------===// |
| 1773 | |
| 1774 | namespace { |
| 1775 | #define DEF_JOB(NAME, DATA, KIND)\ |
| 1776 | class NAME : public VisitorJob {\ |
| 1777 | public:\ |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1778 | NAME(const DATA *d, CXCursor parent) : \ |
| 1779 | VisitorJob(parent, VisitorJob::KIND, d) {} \ |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1780 | static bool classof(const VisitorJob *VJ) { return VJ->getKind() == KIND; }\ |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1781 | const DATA *get() const { return static_cast<const DATA*>(data[0]); }\ |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1782 | }; |
| 1783 | |
| 1784 | DEF_JOB(StmtVisit, Stmt, StmtVisitKind) |
| 1785 | DEF_JOB(MemberExprParts, MemberExpr, MemberExprPartsKind) |
| 1786 | DEF_JOB(DeclRefExprParts, DeclRefExpr, DeclRefExprPartsKind) |
| 1787 | DEF_JOB(OverloadExprParts, OverloadExpr, OverloadExprPartsKind) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1788 | DEF_JOB(SizeOfPackExprParts, SizeOfPackExpr, SizeOfPackExprPartsKind) |
| 1789 | DEF_JOB(LambdaExprParts, LambdaExpr, LambdaExprPartsKind) |
| 1790 | DEF_JOB(PostChildrenVisit, void, PostChildrenVisitKind) |
| 1791 | #undef DEF_JOB |
| 1792 | |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 1793 | class ExplicitTemplateArgsVisit : public VisitorJob { |
| 1794 | public: |
| 1795 | ExplicitTemplateArgsVisit(const TemplateArgumentLoc *Begin, |
| 1796 | const TemplateArgumentLoc *End, CXCursor parent) |
| 1797 | : VisitorJob(parent, VisitorJob::ExplicitTemplateArgsVisitKind, Begin, |
| 1798 | End) {} |
| 1799 | static bool classof(const VisitorJob *VJ) { |
| 1800 | return VJ->getKind() == ExplicitTemplateArgsVisitKind; |
| 1801 | } |
| 1802 | const TemplateArgumentLoc *begin() const { |
| 1803 | return static_cast<const TemplateArgumentLoc *>(data[0]); |
| 1804 | } |
| 1805 | const TemplateArgumentLoc *end() { |
| 1806 | return static_cast<const TemplateArgumentLoc *>(data[1]); |
| 1807 | } |
| 1808 | }; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1809 | class DeclVisit : public VisitorJob { |
| 1810 | public: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1811 | DeclVisit(const Decl *D, CXCursor parent, bool isFirst) : |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1812 | VisitorJob(parent, VisitorJob::DeclVisitKind, |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1813 | D, isFirst ? (void*) 1 : (void*) nullptr) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1814 | static bool classof(const VisitorJob *VJ) { |
| 1815 | return VJ->getKind() == DeclVisitKind; |
| 1816 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1817 | const Decl *get() const { return static_cast<const Decl *>(data[0]); } |
Dmitri Gribenko | e5423a7 | 2015-03-23 19:23:50 +0000 | [diff] [blame] | 1818 | bool isFirst() const { return data[1] != nullptr; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1819 | }; |
| 1820 | class TypeLocVisit : public VisitorJob { |
| 1821 | public: |
| 1822 | TypeLocVisit(TypeLoc tl, CXCursor parent) : |
| 1823 | VisitorJob(parent, VisitorJob::TypeLocVisitKind, |
| 1824 | tl.getType().getAsOpaquePtr(), tl.getOpaqueData()) {} |
| 1825 | |
| 1826 | static bool classof(const VisitorJob *VJ) { |
| 1827 | return VJ->getKind() == TypeLocVisitKind; |
| 1828 | } |
| 1829 | |
| 1830 | TypeLoc get() const { |
| 1831 | QualType T = QualType::getFromOpaquePtr(data[0]); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1832 | return TypeLoc(T, const_cast<void *>(data[1])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1833 | } |
| 1834 | }; |
| 1835 | |
| 1836 | class LabelRefVisit : public VisitorJob { |
| 1837 | public: |
| 1838 | LabelRefVisit(LabelDecl *LD, SourceLocation labelLoc, CXCursor parent) |
| 1839 | : VisitorJob(parent, VisitorJob::LabelRefVisitKind, LD, |
| 1840 | labelLoc.getPtrEncoding()) {} |
| 1841 | |
| 1842 | static bool classof(const VisitorJob *VJ) { |
| 1843 | return VJ->getKind() == VisitorJob::LabelRefVisitKind; |
| 1844 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1845 | const LabelDecl *get() const { |
| 1846 | return static_cast<const LabelDecl *>(data[0]); |
| 1847 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1848 | SourceLocation getLoc() const { |
| 1849 | return SourceLocation::getFromPtrEncoding(data[1]); } |
| 1850 | }; |
| 1851 | |
| 1852 | class NestedNameSpecifierLocVisit : public VisitorJob { |
| 1853 | public: |
| 1854 | NestedNameSpecifierLocVisit(NestedNameSpecifierLoc Qualifier, CXCursor parent) |
| 1855 | : VisitorJob(parent, VisitorJob::NestedNameSpecifierLocVisitKind, |
| 1856 | Qualifier.getNestedNameSpecifier(), |
| 1857 | Qualifier.getOpaqueData()) { } |
| 1858 | |
| 1859 | static bool classof(const VisitorJob *VJ) { |
| 1860 | return VJ->getKind() == VisitorJob::NestedNameSpecifierLocVisitKind; |
| 1861 | } |
| 1862 | |
| 1863 | NestedNameSpecifierLoc get() const { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1864 | return NestedNameSpecifierLoc( |
| 1865 | const_cast<NestedNameSpecifier *>( |
| 1866 | static_cast<const NestedNameSpecifier *>(data[0])), |
| 1867 | const_cast<void *>(data[1])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1868 | } |
| 1869 | }; |
| 1870 | |
| 1871 | class DeclarationNameInfoVisit : public VisitorJob { |
| 1872 | public: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1873 | DeclarationNameInfoVisit(const Stmt *S, CXCursor parent) |
Dmitri Gribenko | dd7dacf | 2013-02-03 13:19:54 +0000 | [diff] [blame] | 1874 | : VisitorJob(parent, VisitorJob::DeclarationNameInfoVisitKind, S) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1875 | static bool classof(const VisitorJob *VJ) { |
| 1876 | return VJ->getKind() == VisitorJob::DeclarationNameInfoVisitKind; |
| 1877 | } |
| 1878 | DeclarationNameInfo get() const { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1879 | const Stmt *S = static_cast<const Stmt *>(data[0]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1880 | switch (S->getStmtClass()) { |
| 1881 | default: |
| 1882 | llvm_unreachable("Unhandled Stmt"); |
| 1883 | case clang::Stmt::MSDependentExistsStmtClass: |
| 1884 | return cast<MSDependentExistsStmt>(S)->getNameInfo(); |
| 1885 | case Stmt::CXXDependentScopeMemberExprClass: |
| 1886 | return cast<CXXDependentScopeMemberExpr>(S)->getMemberNameInfo(); |
| 1887 | case Stmt::DependentScopeDeclRefExprClass: |
| 1888 | return cast<DependentScopeDeclRefExpr>(S)->getNameInfo(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1889 | case Stmt::OMPCriticalDirectiveClass: |
| 1890 | return cast<OMPCriticalDirective>(S)->getDirectiveName(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1891 | } |
| 1892 | } |
| 1893 | }; |
| 1894 | class MemberRefVisit : public VisitorJob { |
| 1895 | public: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1896 | MemberRefVisit(const FieldDecl *D, SourceLocation L, CXCursor parent) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1897 | : VisitorJob(parent, VisitorJob::MemberRefVisitKind, D, |
| 1898 | L.getPtrEncoding()) {} |
| 1899 | static bool classof(const VisitorJob *VJ) { |
| 1900 | return VJ->getKind() == VisitorJob::MemberRefVisitKind; |
| 1901 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1902 | const FieldDecl *get() const { |
| 1903 | return static_cast<const FieldDecl *>(data[0]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1904 | } |
| 1905 | SourceLocation getLoc() const { |
| 1906 | return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t) data[1]); |
| 1907 | } |
| 1908 | }; |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1909 | class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1910 | friend class OMPClauseEnqueue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1911 | VisitorWorkList &WL; |
| 1912 | CXCursor Parent; |
| 1913 | public: |
| 1914 | EnqueueVisitor(VisitorWorkList &wl, CXCursor parent) |
| 1915 | : WL(wl), Parent(parent) {} |
| 1916 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1917 | void VisitAddrLabelExpr(const AddrLabelExpr *E); |
| 1918 | void VisitBlockExpr(const BlockExpr *B); |
| 1919 | void VisitCompoundLiteralExpr(const CompoundLiteralExpr *E); |
| 1920 | void VisitCompoundStmt(const CompoundStmt *S); |
| 1921 | void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */ } |
| 1922 | void VisitMSDependentExistsStmt(const MSDependentExistsStmt *S); |
| 1923 | void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E); |
| 1924 | void VisitCXXNewExpr(const CXXNewExpr *E); |
| 1925 | void VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); |
| 1926 | void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *E); |
| 1927 | void VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E); |
| 1928 | void VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E); |
| 1929 | void VisitCXXTypeidExpr(const CXXTypeidExpr *E); |
| 1930 | void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *E); |
| 1931 | void VisitCXXUuidofExpr(const CXXUuidofExpr *E); |
| 1932 | void VisitCXXCatchStmt(const CXXCatchStmt *S); |
Argyrios Kyrtzidis | 9989124 | 2014-11-13 09:03:21 +0000 | [diff] [blame] | 1933 | void VisitCXXForRangeStmt(const CXXForRangeStmt *S); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1934 | void VisitDeclRefExpr(const DeclRefExpr *D); |
| 1935 | void VisitDeclStmt(const DeclStmt *S); |
| 1936 | void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E); |
| 1937 | void VisitDesignatedInitExpr(const DesignatedInitExpr *E); |
| 1938 | void VisitExplicitCastExpr(const ExplicitCastExpr *E); |
| 1939 | void VisitForStmt(const ForStmt *FS); |
| 1940 | void VisitGotoStmt(const GotoStmt *GS); |
| 1941 | void VisitIfStmt(const IfStmt *If); |
| 1942 | void VisitInitListExpr(const InitListExpr *IE); |
| 1943 | void VisitMemberExpr(const MemberExpr *M); |
| 1944 | void VisitOffsetOfExpr(const OffsetOfExpr *E); |
| 1945 | void VisitObjCEncodeExpr(const ObjCEncodeExpr *E); |
| 1946 | void VisitObjCMessageExpr(const ObjCMessageExpr *M); |
| 1947 | void VisitOverloadExpr(const OverloadExpr *E); |
| 1948 | void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E); |
| 1949 | void VisitStmt(const Stmt *S); |
| 1950 | void VisitSwitchStmt(const SwitchStmt *S); |
| 1951 | void VisitWhileStmt(const WhileStmt *W); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1952 | void VisitTypeTraitExpr(const TypeTraitExpr *E); |
| 1953 | void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E); |
| 1954 | void VisitExpressionTraitExpr(const ExpressionTraitExpr *E); |
| 1955 | void VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U); |
| 1956 | void VisitVAArgExpr(const VAArgExpr *E); |
| 1957 | void VisitSizeOfPackExpr(const SizeOfPackExpr *E); |
| 1958 | void VisitPseudoObjectExpr(const PseudoObjectExpr *E); |
| 1959 | void VisitOpaqueValueExpr(const OpaqueValueExpr *E); |
| 1960 | void VisitLambdaExpr(const LambdaExpr *E); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1961 | void VisitOMPExecutableDirective(const OMPExecutableDirective *D); |
Alexander Musman | 3aaab66 | 2014-08-19 11:27:13 +0000 | [diff] [blame] | 1962 | void VisitOMPLoopDirective(const OMPLoopDirective *D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1963 | void VisitOMPParallelDirective(const OMPParallelDirective *D); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1964 | void VisitOMPSimdDirective(const OMPSimdDirective *D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1965 | void VisitOMPForDirective(const OMPForDirective *D); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1966 | void VisitOMPForSimdDirective(const OMPForSimdDirective *D); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1967 | void VisitOMPSectionsDirective(const OMPSectionsDirective *D); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1968 | void VisitOMPSectionDirective(const OMPSectionDirective *D); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1969 | void VisitOMPSingleDirective(const OMPSingleDirective *D); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1970 | void VisitOMPMasterDirective(const OMPMasterDirective *D); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1971 | void VisitOMPCriticalDirective(const OMPCriticalDirective *D); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1972 | void VisitOMPParallelForDirective(const OMPParallelForDirective *D); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1973 | void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1974 | void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1975 | void VisitOMPTaskDirective(const OMPTaskDirective *D); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1976 | void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D); |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1977 | void VisitOMPBarrierDirective(const OMPBarrierDirective *D); |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1978 | void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1979 | void VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *D); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1980 | void |
| 1981 | VisitOMPCancellationPointDirective(const OMPCancellationPointDirective *D); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1982 | void VisitOMPCancelDirective(const OMPCancelDirective *D); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1983 | void VisitOMPFlushDirective(const OMPFlushDirective *D); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1984 | void VisitOMPOrderedDirective(const OMPOrderedDirective *D); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1985 | void VisitOMPAtomicDirective(const OMPAtomicDirective *D); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1986 | void VisitOMPTargetDirective(const OMPTargetDirective *D); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1987 | void VisitOMPTargetDataDirective(const OMPTargetDataDirective *D); |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1988 | void VisitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective *D); |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1989 | void VisitOMPTargetExitDataDirective(const OMPTargetExitDataDirective *D); |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1990 | void VisitOMPTargetParallelDirective(const OMPTargetParallelDirective *D); |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1991 | void |
| 1992 | VisitOMPTargetParallelForDirective(const OMPTargetParallelForDirective *D); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1993 | void VisitOMPTeamsDirective(const OMPTeamsDirective *D); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1994 | void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1995 | void VisitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective *D); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1996 | void VisitOMPDistributeDirective(const OMPDistributeDirective *D); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1997 | void VisitOMPDistributeParallelForDirective( |
| 1998 | const OMPDistributeParallelForDirective *D); |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1999 | void VisitOMPDistributeParallelForSimdDirective( |
| 2000 | const OMPDistributeParallelForSimdDirective *D); |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2001 | void VisitOMPDistributeSimdDirective(const OMPDistributeSimdDirective *D); |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2002 | void VisitOMPTargetParallelForSimdDirective( |
| 2003 | const OMPTargetParallelForSimdDirective *D); |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2004 | void VisitOMPTargetSimdDirective(const OMPTargetSimdDirective *D); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2005 | void VisitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective *D); |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 2006 | void VisitOMPTeamsDistributeSimdDirective( |
| 2007 | const OMPTeamsDistributeSimdDirective *D); |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2008 | void VisitOMPTeamsDistributeParallelForSimdDirective( |
| 2009 | const OMPTeamsDistributeParallelForSimdDirective *D); |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 2010 | void VisitOMPTeamsDistributeParallelForDirective( |
| 2011 | const OMPTeamsDistributeParallelForDirective *D); |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2012 | void VisitOMPTargetTeamsDirective(const OMPTargetTeamsDirective *D); |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 2013 | void VisitOMPTargetTeamsDistributeDirective( |
| 2014 | const OMPTargetTeamsDistributeDirective *D); |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 2015 | void VisitOMPTargetTeamsDistributeParallelForDirective( |
| 2016 | const OMPTargetTeamsDistributeParallelForDirective *D); |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 2017 | void VisitOMPTargetTeamsDistributeParallelForSimdDirective( |
| 2018 | const OMPTargetTeamsDistributeParallelForSimdDirective *D); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2019 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2020 | private: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2021 | void AddDeclarationNameInfo(const Stmt *S); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2022 | void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier); |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 2023 | void AddExplicitTemplateArgs(const TemplateArgumentLoc *A, |
| 2024 | unsigned NumTemplateArgs); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2025 | void AddMemberRef(const FieldDecl *D, SourceLocation L); |
| 2026 | void AddStmt(const Stmt *S); |
| 2027 | void AddDecl(const Decl *D, bool isFirst = true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2028 | void AddTypeLoc(TypeSourceInfo *TI); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2029 | void EnqueueChildren(const Stmt *S); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2030 | void EnqueueChildren(const OMPClause *S); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2031 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 2032 | } // end anonyous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2033 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2034 | void EnqueueVisitor::AddDeclarationNameInfo(const Stmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2035 | // 'S' should always be non-null, since it comes from the |
| 2036 | // statement we are visiting. |
| 2037 | WL.push_back(DeclarationNameInfoVisit(S, Parent)); |
| 2038 | } |
| 2039 | |
| 2040 | void |
| 2041 | EnqueueVisitor::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier) { |
| 2042 | if (Qualifier) |
| 2043 | WL.push_back(NestedNameSpecifierLocVisit(Qualifier, Parent)); |
| 2044 | } |
| 2045 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2046 | void EnqueueVisitor::AddStmt(const Stmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2047 | if (S) |
| 2048 | WL.push_back(StmtVisit(S, Parent)); |
| 2049 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2050 | void EnqueueVisitor::AddDecl(const Decl *D, bool isFirst) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2051 | if (D) |
| 2052 | WL.push_back(DeclVisit(D, Parent, isFirst)); |
| 2053 | } |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 2054 | void EnqueueVisitor::AddExplicitTemplateArgs(const TemplateArgumentLoc *A, |
| 2055 | unsigned NumTemplateArgs) { |
| 2056 | WL.push_back(ExplicitTemplateArgsVisit(A, A + NumTemplateArgs, Parent)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2057 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2058 | void EnqueueVisitor::AddMemberRef(const FieldDecl *D, SourceLocation L) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2059 | if (D) |
| 2060 | WL.push_back(MemberRefVisit(D, L, Parent)); |
| 2061 | } |
| 2062 | void EnqueueVisitor::AddTypeLoc(TypeSourceInfo *TI) { |
| 2063 | if (TI) |
| 2064 | WL.push_back(TypeLocVisit(TI->getTypeLoc(), Parent)); |
| 2065 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2066 | void EnqueueVisitor::EnqueueChildren(const Stmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2067 | unsigned size = WL.size(); |
Benjamin Kramer | 642f173 | 2015-07-02 21:03:14 +0000 | [diff] [blame] | 2068 | for (const Stmt *SubStmt : S->children()) { |
| 2069 | AddStmt(SubStmt); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2070 | } |
| 2071 | if (size == WL.size()) |
| 2072 | return; |
| 2073 | // Now reverse the entries we just added. This will match the DFS |
| 2074 | // ordering performed by the worklist. |
| 2075 | VisitorWorkList::iterator I = WL.begin() + size, E = WL.end(); |
| 2076 | std::reverse(I, E); |
| 2077 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2078 | namespace { |
| 2079 | class OMPClauseEnqueue : public ConstOMPClauseVisitor<OMPClauseEnqueue> { |
| 2080 | EnqueueVisitor *Visitor; |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 2081 | /// \brief Process clauses with list of variables. |
| 2082 | template <typename T> |
| 2083 | void VisitOMPClauseList(T *Node); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2084 | public: |
| 2085 | OMPClauseEnqueue(EnqueueVisitor *Visitor) : Visitor(Visitor) { } |
| 2086 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2087 | void Visit##Class(const Class *C); |
| 2088 | #include "clang/Basic/OpenMPKinds.def" |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2089 | void VisitOMPClauseWithPreInit(const OMPClauseWithPreInit *C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2090 | void VisitOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2091 | }; |
| 2092 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2093 | void OMPClauseEnqueue::VisitOMPClauseWithPreInit( |
| 2094 | const OMPClauseWithPreInit *C) { |
| 2095 | Visitor->AddStmt(C->getPreInitStmt()); |
| 2096 | } |
| 2097 | |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2098 | void OMPClauseEnqueue::VisitOMPClauseWithPostUpdate( |
| 2099 | const OMPClauseWithPostUpdate *C) { |
Alexey Bataev | 37e594c | 2016-03-04 07:21:16 +0000 | [diff] [blame] | 2100 | VisitOMPClauseWithPreInit(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2101 | Visitor->AddStmt(C->getPostUpdateExpr()); |
| 2102 | } |
| 2103 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2104 | void OMPClauseEnqueue::VisitOMPIfClause(const OMPIfClause *C) { |
| 2105 | Visitor->AddStmt(C->getCondition()); |
| 2106 | } |
| 2107 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2108 | void OMPClauseEnqueue::VisitOMPFinalClause(const OMPFinalClause *C) { |
| 2109 | Visitor->AddStmt(C->getCondition()); |
| 2110 | } |
| 2111 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 2112 | void OMPClauseEnqueue::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) { |
| 2113 | Visitor->AddStmt(C->getNumThreads()); |
| 2114 | } |
| 2115 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2116 | void OMPClauseEnqueue::VisitOMPSafelenClause(const OMPSafelenClause *C) { |
| 2117 | Visitor->AddStmt(C->getSafelen()); |
| 2118 | } |
| 2119 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2120 | void OMPClauseEnqueue::VisitOMPSimdlenClause(const OMPSimdlenClause *C) { |
| 2121 | Visitor->AddStmt(C->getSimdlen()); |
| 2122 | } |
| 2123 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2124 | void OMPClauseEnqueue::VisitOMPCollapseClause(const OMPCollapseClause *C) { |
| 2125 | Visitor->AddStmt(C->getNumForLoops()); |
| 2126 | } |
| 2127 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2128 | void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) { } |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 2129 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2130 | void OMPClauseEnqueue::VisitOMPProcBindClause(const OMPProcBindClause *C) { } |
| 2131 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2132 | void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) { |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2133 | VisitOMPClauseWithPreInit(C); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2134 | Visitor->AddStmt(C->getChunkSize()); |
| 2135 | } |
| 2136 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2137 | void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *C) { |
| 2138 | Visitor->AddStmt(C->getNumForLoops()); |
| 2139 | } |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2140 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2141 | void OMPClauseEnqueue::VisitOMPNowaitClause(const OMPNowaitClause *) {} |
| 2142 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 2143 | void OMPClauseEnqueue::VisitOMPUntiedClause(const OMPUntiedClause *) {} |
| 2144 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2145 | void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {} |
| 2146 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 2147 | void OMPClauseEnqueue::VisitOMPReadClause(const OMPReadClause *) {} |
| 2148 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2149 | void OMPClauseEnqueue::VisitOMPWriteClause(const OMPWriteClause *) {} |
| 2150 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 2151 | void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {} |
| 2152 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 2153 | void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {} |
| 2154 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 2155 | void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} |
| 2156 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2157 | void OMPClauseEnqueue::VisitOMPThreadsClause(const OMPThreadsClause *) {} |
| 2158 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2159 | void OMPClauseEnqueue::VisitOMPSIMDClause(const OMPSIMDClause *) {} |
| 2160 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 2161 | void OMPClauseEnqueue::VisitOMPNogroupClause(const OMPNogroupClause *) {} |
| 2162 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 2163 | void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) { |
| 2164 | Visitor->AddStmt(C->getDevice()); |
| 2165 | } |
| 2166 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 2167 | void OMPClauseEnqueue::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) { |
| 2168 | Visitor->AddStmt(C->getNumTeams()); |
| 2169 | } |
| 2170 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 2171 | void OMPClauseEnqueue::VisitOMPThreadLimitClause(const OMPThreadLimitClause *C) { |
| 2172 | Visitor->AddStmt(C->getThreadLimit()); |
| 2173 | } |
| 2174 | |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2175 | void OMPClauseEnqueue::VisitOMPPriorityClause(const OMPPriorityClause *C) { |
| 2176 | Visitor->AddStmt(C->getPriority()); |
| 2177 | } |
| 2178 | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2179 | void OMPClauseEnqueue::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) { |
| 2180 | Visitor->AddStmt(C->getGrainsize()); |
| 2181 | } |
| 2182 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2183 | void OMPClauseEnqueue::VisitOMPNumTasksClause(const OMPNumTasksClause *C) { |
| 2184 | Visitor->AddStmt(C->getNumTasks()); |
| 2185 | } |
| 2186 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2187 | void OMPClauseEnqueue::VisitOMPHintClause(const OMPHintClause *C) { |
| 2188 | Visitor->AddStmt(C->getHint()); |
| 2189 | } |
| 2190 | |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 2191 | template<typename T> |
| 2192 | void OMPClauseEnqueue::VisitOMPClauseList(T *Node) { |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 2193 | for (const auto *I : Node->varlists()) { |
Aaron Ballman | 2205d2a | 2014-03-14 15:55:35 +0000 | [diff] [blame] | 2194 | Visitor->AddStmt(I); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 2195 | } |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 2196 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2197 | |
| 2198 | void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) { |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 2199 | VisitOMPClauseList(C); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 2200 | for (const auto *E : C->private_copies()) { |
| 2201 | Visitor->AddStmt(E); |
| 2202 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2203 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2204 | void OMPClauseEnqueue::VisitOMPFirstprivateClause( |
| 2205 | const OMPFirstprivateClause *C) { |
| 2206 | VisitOMPClauseList(C); |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 2207 | VisitOMPClauseWithPreInit(C); |
| 2208 | for (const auto *E : C->private_copies()) { |
| 2209 | Visitor->AddStmt(E); |
| 2210 | } |
| 2211 | for (const auto *E : C->inits()) { |
| 2212 | Visitor->AddStmt(E); |
| 2213 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2214 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2215 | void OMPClauseEnqueue::VisitOMPLastprivateClause( |
| 2216 | const OMPLastprivateClause *C) { |
| 2217 | VisitOMPClauseList(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 2218 | VisitOMPClauseWithPostUpdate(C); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 2219 | for (auto *E : C->private_copies()) { |
| 2220 | Visitor->AddStmt(E); |
| 2221 | } |
| 2222 | for (auto *E : C->source_exprs()) { |
| 2223 | Visitor->AddStmt(E); |
| 2224 | } |
| 2225 | for (auto *E : C->destination_exprs()) { |
| 2226 | Visitor->AddStmt(E); |
| 2227 | } |
| 2228 | for (auto *E : C->assignment_ops()) { |
| 2229 | Visitor->AddStmt(E); |
| 2230 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2231 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2232 | void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) { |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 2233 | VisitOMPClauseList(C); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2234 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2235 | void OMPClauseEnqueue::VisitOMPReductionClause(const OMPReductionClause *C) { |
| 2236 | VisitOMPClauseList(C); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 2237 | VisitOMPClauseWithPostUpdate(C); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 2238 | for (auto *E : C->privates()) { |
| 2239 | Visitor->AddStmt(E); |
| 2240 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 2241 | for (auto *E : C->lhs_exprs()) { |
| 2242 | Visitor->AddStmt(E); |
| 2243 | } |
| 2244 | for (auto *E : C->rhs_exprs()) { |
| 2245 | Visitor->AddStmt(E); |
| 2246 | } |
| 2247 | for (auto *E : C->reduction_ops()) { |
| 2248 | Visitor->AddStmt(E); |
| 2249 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2250 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2251 | void OMPClauseEnqueue::VisitOMPLinearClause(const OMPLinearClause *C) { |
| 2252 | VisitOMPClauseList(C); |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 2253 | VisitOMPClauseWithPostUpdate(C); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 2254 | for (const auto *E : C->privates()) { |
| 2255 | Visitor->AddStmt(E); |
| 2256 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 2257 | for (const auto *E : C->inits()) { |
| 2258 | Visitor->AddStmt(E); |
| 2259 | } |
| 2260 | for (const auto *E : C->updates()) { |
| 2261 | Visitor->AddStmt(E); |
| 2262 | } |
| 2263 | for (const auto *E : C->finals()) { |
| 2264 | Visitor->AddStmt(E); |
| 2265 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2266 | Visitor->AddStmt(C->getStep()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 2267 | Visitor->AddStmt(C->getCalcStep()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2268 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2269 | void OMPClauseEnqueue::VisitOMPAlignedClause(const OMPAlignedClause *C) { |
| 2270 | VisitOMPClauseList(C); |
| 2271 | Visitor->AddStmt(C->getAlignment()); |
| 2272 | } |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 2273 | void OMPClauseEnqueue::VisitOMPCopyinClause(const OMPCopyinClause *C) { |
| 2274 | VisitOMPClauseList(C); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 2275 | for (auto *E : C->source_exprs()) { |
| 2276 | Visitor->AddStmt(E); |
| 2277 | } |
| 2278 | for (auto *E : C->destination_exprs()) { |
| 2279 | Visitor->AddStmt(E); |
| 2280 | } |
| 2281 | for (auto *E : C->assignment_ops()) { |
| 2282 | Visitor->AddStmt(E); |
| 2283 | } |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 2284 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2285 | void |
| 2286 | OMPClauseEnqueue::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) { |
| 2287 | VisitOMPClauseList(C); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 2288 | for (auto *E : C->source_exprs()) { |
| 2289 | Visitor->AddStmt(E); |
| 2290 | } |
| 2291 | for (auto *E : C->destination_exprs()) { |
| 2292 | Visitor->AddStmt(E); |
| 2293 | } |
| 2294 | for (auto *E : C->assignment_ops()) { |
| 2295 | Visitor->AddStmt(E); |
| 2296 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2297 | } |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2298 | void OMPClauseEnqueue::VisitOMPFlushClause(const OMPFlushClause *C) { |
| 2299 | VisitOMPClauseList(C); |
| 2300 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2301 | void OMPClauseEnqueue::VisitOMPDependClause(const OMPDependClause *C) { |
| 2302 | VisitOMPClauseList(C); |
| 2303 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2304 | void OMPClauseEnqueue::VisitOMPMapClause(const OMPMapClause *C) { |
| 2305 | VisitOMPClauseList(C); |
| 2306 | } |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2307 | void OMPClauseEnqueue::VisitOMPDistScheduleClause( |
| 2308 | const OMPDistScheduleClause *C) { |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2309 | VisitOMPClauseWithPreInit(C); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2310 | Visitor->AddStmt(C->getChunkSize()); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2311 | } |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2312 | void OMPClauseEnqueue::VisitOMPDefaultmapClause( |
| 2313 | const OMPDefaultmapClause * /*C*/) {} |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 2314 | void OMPClauseEnqueue::VisitOMPToClause(const OMPToClause *C) { |
| 2315 | VisitOMPClauseList(C); |
| 2316 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2317 | void OMPClauseEnqueue::VisitOMPFromClause(const OMPFromClause *C) { |
| 2318 | VisitOMPClauseList(C); |
| 2319 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 2320 | void OMPClauseEnqueue::VisitOMPUseDevicePtrClause(const OMPUseDevicePtrClause *C) { |
| 2321 | VisitOMPClauseList(C); |
| 2322 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 2323 | void OMPClauseEnqueue::VisitOMPIsDevicePtrClause(const OMPIsDevicePtrClause *C) { |
| 2324 | VisitOMPClauseList(C); |
| 2325 | } |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 2326 | } |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 2327 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2328 | void EnqueueVisitor::EnqueueChildren(const OMPClause *S) { |
| 2329 | unsigned size = WL.size(); |
| 2330 | OMPClauseEnqueue Visitor(this); |
| 2331 | Visitor.Visit(S); |
| 2332 | if (size == WL.size()) |
| 2333 | return; |
| 2334 | // Now reverse the entries we just added. This will match the DFS |
| 2335 | // ordering performed by the worklist. |
| 2336 | VisitorWorkList::iterator I = WL.begin() + size, E = WL.end(); |
| 2337 | std::reverse(I, E); |
| 2338 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2339 | void EnqueueVisitor::VisitAddrLabelExpr(const AddrLabelExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2340 | WL.push_back(LabelRefVisit(E->getLabel(), E->getLabelLoc(), Parent)); |
| 2341 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2342 | void EnqueueVisitor::VisitBlockExpr(const BlockExpr *B) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2343 | AddDecl(B->getBlockDecl()); |
| 2344 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2345 | void EnqueueVisitor::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2346 | EnqueueChildren(E); |
| 2347 | AddTypeLoc(E->getTypeSourceInfo()); |
| 2348 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2349 | void EnqueueVisitor::VisitCompoundStmt(const CompoundStmt *S) { |
Pete Cooper | 57d3f14 | 2015-07-30 17:22:52 +0000 | [diff] [blame] | 2350 | for (auto &I : llvm::reverse(S->body())) |
| 2351 | AddStmt(I); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2352 | } |
| 2353 | void EnqueueVisitor:: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2354 | VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2355 | AddStmt(S->getSubStmt()); |
| 2356 | AddDeclarationNameInfo(S); |
| 2357 | if (NestedNameSpecifierLoc QualifierLoc = S->getQualifierLoc()) |
| 2358 | AddNestedNameSpecifierLoc(QualifierLoc); |
| 2359 | } |
| 2360 | |
| 2361 | void EnqueueVisitor:: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2362 | VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 2363 | if (E->hasExplicitTemplateArgs()) |
| 2364 | AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2365 | AddDeclarationNameInfo(E); |
| 2366 | if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc()) |
| 2367 | AddNestedNameSpecifierLoc(QualifierLoc); |
| 2368 | if (!E->isImplicitAccess()) |
| 2369 | AddStmt(E->getBase()); |
| 2370 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2371 | void EnqueueVisitor::VisitCXXNewExpr(const CXXNewExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2372 | // Enqueue the initializer , if any. |
| 2373 | AddStmt(E->getInitializer()); |
| 2374 | // Enqueue the array size, if any. |
| 2375 | AddStmt(E->getArraySize()); |
| 2376 | // Enqueue the allocated type. |
| 2377 | AddTypeLoc(E->getAllocatedTypeSourceInfo()); |
| 2378 | // Enqueue the placement arguments. |
| 2379 | for (unsigned I = E->getNumPlacementArgs(); I > 0; --I) |
| 2380 | AddStmt(E->getPlacementArg(I-1)); |
| 2381 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2382 | void EnqueueVisitor::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *CE) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2383 | for (unsigned I = CE->getNumArgs(); I > 1 /* Yes, this is 1 */; --I) |
| 2384 | AddStmt(CE->getArg(I-1)); |
| 2385 | AddStmt(CE->getCallee()); |
| 2386 | AddStmt(CE->getArg(0)); |
| 2387 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2388 | void EnqueueVisitor::VisitCXXPseudoDestructorExpr( |
| 2389 | const CXXPseudoDestructorExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2390 | // Visit the name of the type being destroyed. |
| 2391 | AddTypeLoc(E->getDestroyedTypeInfo()); |
| 2392 | // Visit the scope type that looks disturbingly like the nested-name-specifier |
| 2393 | // but isn't. |
| 2394 | AddTypeLoc(E->getScopeTypeInfo()); |
| 2395 | // Visit the nested-name-specifier. |
| 2396 | if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc()) |
| 2397 | AddNestedNameSpecifierLoc(QualifierLoc); |
| 2398 | // Visit base expression. |
| 2399 | AddStmt(E->getBase()); |
| 2400 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2401 | void EnqueueVisitor::VisitCXXScalarValueInitExpr( |
| 2402 | const CXXScalarValueInitExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2403 | AddTypeLoc(E->getTypeSourceInfo()); |
| 2404 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2405 | void EnqueueVisitor::VisitCXXTemporaryObjectExpr( |
| 2406 | const CXXTemporaryObjectExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2407 | EnqueueChildren(E); |
| 2408 | AddTypeLoc(E->getTypeSourceInfo()); |
| 2409 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2410 | void EnqueueVisitor::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2411 | EnqueueChildren(E); |
| 2412 | if (E->isTypeOperand()) |
| 2413 | AddTypeLoc(E->getTypeOperandSourceInfo()); |
| 2414 | } |
| 2415 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2416 | void EnqueueVisitor::VisitCXXUnresolvedConstructExpr( |
| 2417 | const CXXUnresolvedConstructExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2418 | EnqueueChildren(E); |
| 2419 | AddTypeLoc(E->getTypeSourceInfo()); |
| 2420 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2421 | void EnqueueVisitor::VisitCXXUuidofExpr(const CXXUuidofExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2422 | EnqueueChildren(E); |
| 2423 | if (E->isTypeOperand()) |
| 2424 | AddTypeLoc(E->getTypeOperandSourceInfo()); |
| 2425 | } |
| 2426 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2427 | void EnqueueVisitor::VisitCXXCatchStmt(const CXXCatchStmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2428 | EnqueueChildren(S); |
| 2429 | AddDecl(S->getExceptionDecl()); |
| 2430 | } |
| 2431 | |
Argyrios Kyrtzidis | 9989124 | 2014-11-13 09:03:21 +0000 | [diff] [blame] | 2432 | void EnqueueVisitor::VisitCXXForRangeStmt(const CXXForRangeStmt *S) { |
Argyrios Kyrtzidis | cde7069 | 2014-11-13 09:50:19 +0000 | [diff] [blame] | 2433 | AddStmt(S->getBody()); |
Argyrios Kyrtzidis | 9989124 | 2014-11-13 09:03:21 +0000 | [diff] [blame] | 2434 | AddStmt(S->getRangeInit()); |
Argyrios Kyrtzidis | cde7069 | 2014-11-13 09:50:19 +0000 | [diff] [blame] | 2435 | AddDecl(S->getLoopVariable()); |
Argyrios Kyrtzidis | 9989124 | 2014-11-13 09:03:21 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2438 | void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 2439 | if (DR->hasExplicitTemplateArgs()) |
| 2440 | AddExplicitTemplateArgs(DR->getTemplateArgs(), DR->getNumTemplateArgs()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2441 | WL.push_back(DeclRefExprParts(DR, Parent)); |
| 2442 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2443 | void EnqueueVisitor::VisitDependentScopeDeclRefExpr( |
| 2444 | const DependentScopeDeclRefExpr *E) { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 2445 | if (E->hasExplicitTemplateArgs()) |
| 2446 | AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2447 | AddDeclarationNameInfo(E); |
| 2448 | AddNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 2449 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2450 | void EnqueueVisitor::VisitDeclStmt(const DeclStmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2451 | unsigned size = WL.size(); |
| 2452 | bool isFirst = true; |
Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 2453 | for (const auto *D : S->decls()) { |
| 2454 | AddDecl(D, isFirst); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2455 | isFirst = false; |
| 2456 | } |
| 2457 | if (size == WL.size()) |
| 2458 | return; |
| 2459 | // Now reverse the entries we just added. This will match the DFS |
| 2460 | // ordering performed by the worklist. |
| 2461 | VisitorWorkList::iterator I = WL.begin() + size, E = WL.end(); |
| 2462 | std::reverse(I, E); |
| 2463 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2464 | void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2465 | AddStmt(E->getInit()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 2466 | for (const DesignatedInitExpr::Designator &D : |
| 2467 | llvm::reverse(E->designators())) { |
| 2468 | if (D.isFieldDesignator()) { |
| 2469 | if (FieldDecl *Field = D.getField()) |
| 2470 | AddMemberRef(Field, D.getFieldLoc()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2471 | continue; |
| 2472 | } |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 2473 | if (D.isArrayDesignator()) { |
| 2474 | AddStmt(E->getArrayIndex(D)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2475 | continue; |
| 2476 | } |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 2477 | assert(D.isArrayRangeDesignator() && "Unknown designator kind"); |
| 2478 | AddStmt(E->getArrayRangeEnd(D)); |
| 2479 | AddStmt(E->getArrayRangeStart(D)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2480 | } |
| 2481 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2482 | void EnqueueVisitor::VisitExplicitCastExpr(const ExplicitCastExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2483 | EnqueueChildren(E); |
| 2484 | AddTypeLoc(E->getTypeInfoAsWritten()); |
| 2485 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2486 | void EnqueueVisitor::VisitForStmt(const ForStmt *FS) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2487 | AddStmt(FS->getBody()); |
| 2488 | AddStmt(FS->getInc()); |
| 2489 | AddStmt(FS->getCond()); |
| 2490 | AddDecl(FS->getConditionVariable()); |
| 2491 | AddStmt(FS->getInit()); |
| 2492 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2493 | void EnqueueVisitor::VisitGotoStmt(const GotoStmt *GS) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2494 | WL.push_back(LabelRefVisit(GS->getLabel(), GS->getLabelLoc(), Parent)); |
| 2495 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2496 | void EnqueueVisitor::VisitIfStmt(const IfStmt *If) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2497 | AddStmt(If->getElse()); |
| 2498 | AddStmt(If->getThen()); |
| 2499 | AddStmt(If->getCond()); |
| 2500 | AddDecl(If->getConditionVariable()); |
| 2501 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2502 | void EnqueueVisitor::VisitInitListExpr(const InitListExpr *IE) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2503 | // We care about the syntactic form of the initializer list, only. |
| 2504 | if (InitListExpr *Syntactic = IE->getSyntacticForm()) |
| 2505 | IE = Syntactic; |
| 2506 | EnqueueChildren(IE); |
| 2507 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2508 | void EnqueueVisitor::VisitMemberExpr(const MemberExpr *M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2509 | WL.push_back(MemberExprParts(M, Parent)); |
| 2510 | |
| 2511 | // If the base of the member access expression is an implicit 'this', don't |
| 2512 | // visit it. |
| 2513 | // FIXME: If we ever want to show these implicit accesses, this will be |
| 2514 | // unfortunate. However, clang_getCursor() relies on this behavior. |
Argyrios Kyrtzidis | 58d0e7a | 2015-03-13 04:40:07 +0000 | [diff] [blame] | 2515 | if (M->isImplicitAccess()) |
| 2516 | return; |
| 2517 | |
| 2518 | // Ignore base anonymous struct/union fields, otherwise they will shadow the |
| 2519 | // real field that that we are interested in. |
| 2520 | if (auto *SubME = dyn_cast<MemberExpr>(M->getBase())) { |
| 2521 | if (auto *FD = dyn_cast_or_null<FieldDecl>(SubME->getMemberDecl())) { |
| 2522 | if (FD->isAnonymousStructOrUnion()) { |
| 2523 | AddStmt(SubME->getBase()); |
| 2524 | return; |
| 2525 | } |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | AddStmt(M->getBase()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2530 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2531 | void EnqueueVisitor::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2532 | AddTypeLoc(E->getEncodedTypeSourceInfo()); |
| 2533 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2534 | void EnqueueVisitor::VisitObjCMessageExpr(const ObjCMessageExpr *M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2535 | EnqueueChildren(M); |
| 2536 | AddTypeLoc(M->getClassReceiverTypeInfo()); |
| 2537 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2538 | void EnqueueVisitor::VisitOffsetOfExpr(const OffsetOfExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2539 | // Visit the components of the offsetof expression. |
| 2540 | for (unsigned N = E->getNumComponents(), I = N; I > 0; --I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2541 | const OffsetOfNode &Node = E->getComponent(I-1); |
| 2542 | switch (Node.getKind()) { |
| 2543 | case OffsetOfNode::Array: |
| 2544 | AddStmt(E->getIndexExpr(Node.getArrayExprIndex())); |
| 2545 | break; |
| 2546 | case OffsetOfNode::Field: |
| 2547 | AddMemberRef(Node.getField(), Node.getSourceRange().getEnd()); |
| 2548 | break; |
| 2549 | case OffsetOfNode::Identifier: |
| 2550 | case OffsetOfNode::Base: |
| 2551 | continue; |
| 2552 | } |
| 2553 | } |
| 2554 | // Visit the type into which we're computing the offset. |
| 2555 | AddTypeLoc(E->getTypeSourceInfo()); |
| 2556 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2557 | void EnqueueVisitor::VisitOverloadExpr(const OverloadExpr *E) { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 2558 | if (E->hasExplicitTemplateArgs()) |
| 2559 | AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2560 | WL.push_back(OverloadExprParts(E, Parent)); |
| 2561 | } |
| 2562 | void EnqueueVisitor::VisitUnaryExprOrTypeTraitExpr( |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2563 | const UnaryExprOrTypeTraitExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2564 | EnqueueChildren(E); |
| 2565 | if (E->isArgumentType()) |
| 2566 | AddTypeLoc(E->getArgumentTypeInfo()); |
| 2567 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2568 | void EnqueueVisitor::VisitStmt(const Stmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2569 | EnqueueChildren(S); |
| 2570 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2571 | void EnqueueVisitor::VisitSwitchStmt(const SwitchStmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2572 | AddStmt(S->getBody()); |
| 2573 | AddStmt(S->getCond()); |
| 2574 | AddDecl(S->getConditionVariable()); |
| 2575 | } |
| 2576 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2577 | void EnqueueVisitor::VisitWhileStmt(const WhileStmt *W) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2578 | AddStmt(W->getBody()); |
| 2579 | AddStmt(W->getCond()); |
| 2580 | AddDecl(W->getConditionVariable()); |
| 2581 | } |
| 2582 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2583 | void EnqueueVisitor::VisitTypeTraitExpr(const TypeTraitExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2584 | for (unsigned I = E->getNumArgs(); I > 0; --I) |
| 2585 | AddTypeLoc(E->getArg(I-1)); |
| 2586 | } |
| 2587 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2588 | void EnqueueVisitor::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2589 | AddTypeLoc(E->getQueriedTypeSourceInfo()); |
| 2590 | } |
| 2591 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2592 | void EnqueueVisitor::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2593 | EnqueueChildren(E); |
| 2594 | } |
| 2595 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2596 | void EnqueueVisitor::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2597 | VisitOverloadExpr(U); |
| 2598 | if (!U->isImplicitAccess()) |
| 2599 | AddStmt(U->getBase()); |
| 2600 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2601 | void EnqueueVisitor::VisitVAArgExpr(const VAArgExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2602 | AddStmt(E->getSubExpr()); |
| 2603 | AddTypeLoc(E->getWrittenTypeInfo()); |
| 2604 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2605 | void EnqueueVisitor::VisitSizeOfPackExpr(const SizeOfPackExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2606 | WL.push_back(SizeOfPackExprParts(E, Parent)); |
| 2607 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2608 | void EnqueueVisitor::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2609 | // If the opaque value has a source expression, just transparently |
| 2610 | // visit that. This is useful for (e.g.) pseudo-object expressions. |
| 2611 | if (Expr *SourceExpr = E->getSourceExpr()) |
| 2612 | return Visit(SourceExpr); |
| 2613 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2614 | void EnqueueVisitor::VisitLambdaExpr(const LambdaExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2615 | AddStmt(E->getBody()); |
| 2616 | WL.push_back(LambdaExprParts(E, Parent)); |
| 2617 | } |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2618 | void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2619 | // Treat the expression like its syntactic form. |
| 2620 | Visit(E->getSyntacticForm()); |
| 2621 | } |
| 2622 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2623 | void EnqueueVisitor::VisitOMPExecutableDirective( |
| 2624 | const OMPExecutableDirective *D) { |
| 2625 | EnqueueChildren(D); |
| 2626 | for (ArrayRef<OMPClause *>::iterator I = D->clauses().begin(), |
| 2627 | E = D->clauses().end(); |
| 2628 | I != E; ++I) |
| 2629 | EnqueueChildren(*I); |
| 2630 | } |
| 2631 | |
Alexander Musman | 3aaab66 | 2014-08-19 11:27:13 +0000 | [diff] [blame] | 2632 | void EnqueueVisitor::VisitOMPLoopDirective(const OMPLoopDirective *D) { |
| 2633 | VisitOMPExecutableDirective(D); |
| 2634 | } |
| 2635 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2636 | void EnqueueVisitor::VisitOMPParallelDirective(const OMPParallelDirective *D) { |
| 2637 | VisitOMPExecutableDirective(D); |
| 2638 | } |
| 2639 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2640 | void EnqueueVisitor::VisitOMPSimdDirective(const OMPSimdDirective *D) { |
Alexander Musman | 3aaab66 | 2014-08-19 11:27:13 +0000 | [diff] [blame] | 2641 | VisitOMPLoopDirective(D); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2644 | void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) { |
Alexander Musman | 3aaab66 | 2014-08-19 11:27:13 +0000 | [diff] [blame] | 2645 | VisitOMPLoopDirective(D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2648 | void EnqueueVisitor::VisitOMPForSimdDirective(const OMPForSimdDirective *D) { |
| 2649 | VisitOMPLoopDirective(D); |
| 2650 | } |
| 2651 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2652 | void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) { |
| 2653 | VisitOMPExecutableDirective(D); |
| 2654 | } |
| 2655 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2656 | void EnqueueVisitor::VisitOMPSectionDirective(const OMPSectionDirective *D) { |
| 2657 | VisitOMPExecutableDirective(D); |
| 2658 | } |
| 2659 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2660 | void EnqueueVisitor::VisitOMPSingleDirective(const OMPSingleDirective *D) { |
| 2661 | VisitOMPExecutableDirective(D); |
| 2662 | } |
| 2663 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2664 | void EnqueueVisitor::VisitOMPMasterDirective(const OMPMasterDirective *D) { |
| 2665 | VisitOMPExecutableDirective(D); |
| 2666 | } |
| 2667 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2668 | void EnqueueVisitor::VisitOMPCriticalDirective(const OMPCriticalDirective *D) { |
| 2669 | VisitOMPExecutableDirective(D); |
| 2670 | AddDeclarationNameInfo(D); |
| 2671 | } |
| 2672 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2673 | void |
| 2674 | EnqueueVisitor::VisitOMPParallelForDirective(const OMPParallelForDirective *D) { |
Alexander Musman | 3aaab66 | 2014-08-19 11:27:13 +0000 | [diff] [blame] | 2675 | VisitOMPLoopDirective(D); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2678 | void EnqueueVisitor::VisitOMPParallelForSimdDirective( |
| 2679 | const OMPParallelForSimdDirective *D) { |
| 2680 | VisitOMPLoopDirective(D); |
| 2681 | } |
| 2682 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2683 | void EnqueueVisitor::VisitOMPParallelSectionsDirective( |
| 2684 | const OMPParallelSectionsDirective *D) { |
| 2685 | VisitOMPExecutableDirective(D); |
| 2686 | } |
| 2687 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2688 | void EnqueueVisitor::VisitOMPTaskDirective(const OMPTaskDirective *D) { |
| 2689 | VisitOMPExecutableDirective(D); |
| 2690 | } |
| 2691 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2692 | void |
| 2693 | EnqueueVisitor::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D) { |
| 2694 | VisitOMPExecutableDirective(D); |
| 2695 | } |
| 2696 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2697 | void EnqueueVisitor::VisitOMPBarrierDirective(const OMPBarrierDirective *D) { |
| 2698 | VisitOMPExecutableDirective(D); |
| 2699 | } |
| 2700 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2701 | void EnqueueVisitor::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D) { |
| 2702 | VisitOMPExecutableDirective(D); |
| 2703 | } |
| 2704 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2705 | void EnqueueVisitor::VisitOMPTaskgroupDirective( |
| 2706 | const OMPTaskgroupDirective *D) { |
| 2707 | VisitOMPExecutableDirective(D); |
| 2708 | } |
| 2709 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2710 | void EnqueueVisitor::VisitOMPFlushDirective(const OMPFlushDirective *D) { |
| 2711 | VisitOMPExecutableDirective(D); |
| 2712 | } |
| 2713 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2714 | void EnqueueVisitor::VisitOMPOrderedDirective(const OMPOrderedDirective *D) { |
| 2715 | VisitOMPExecutableDirective(D); |
| 2716 | } |
| 2717 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2718 | void EnqueueVisitor::VisitOMPAtomicDirective(const OMPAtomicDirective *D) { |
| 2719 | VisitOMPExecutableDirective(D); |
| 2720 | } |
| 2721 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2722 | void EnqueueVisitor::VisitOMPTargetDirective(const OMPTargetDirective *D) { |
| 2723 | VisitOMPExecutableDirective(D); |
| 2724 | } |
| 2725 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2726 | void EnqueueVisitor::VisitOMPTargetDataDirective(const |
| 2727 | OMPTargetDataDirective *D) { |
| 2728 | VisitOMPExecutableDirective(D); |
| 2729 | } |
| 2730 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2731 | void EnqueueVisitor::VisitOMPTargetEnterDataDirective( |
| 2732 | const OMPTargetEnterDataDirective *D) { |
| 2733 | VisitOMPExecutableDirective(D); |
| 2734 | } |
| 2735 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2736 | void EnqueueVisitor::VisitOMPTargetExitDataDirective( |
| 2737 | const OMPTargetExitDataDirective *D) { |
| 2738 | VisitOMPExecutableDirective(D); |
| 2739 | } |
| 2740 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2741 | void EnqueueVisitor::VisitOMPTargetParallelDirective( |
| 2742 | const OMPTargetParallelDirective *D) { |
| 2743 | VisitOMPExecutableDirective(D); |
| 2744 | } |
| 2745 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2746 | void EnqueueVisitor::VisitOMPTargetParallelForDirective( |
| 2747 | const OMPTargetParallelForDirective *D) { |
| 2748 | VisitOMPLoopDirective(D); |
| 2749 | } |
| 2750 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2751 | void EnqueueVisitor::VisitOMPTeamsDirective(const OMPTeamsDirective *D) { |
| 2752 | VisitOMPExecutableDirective(D); |
| 2753 | } |
| 2754 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2755 | void EnqueueVisitor::VisitOMPCancellationPointDirective( |
| 2756 | const OMPCancellationPointDirective *D) { |
| 2757 | VisitOMPExecutableDirective(D); |
| 2758 | } |
| 2759 | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2760 | void EnqueueVisitor::VisitOMPCancelDirective(const OMPCancelDirective *D) { |
| 2761 | VisitOMPExecutableDirective(D); |
| 2762 | } |
| 2763 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2764 | void EnqueueVisitor::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D) { |
| 2765 | VisitOMPLoopDirective(D); |
| 2766 | } |
| 2767 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2768 | void EnqueueVisitor::VisitOMPTaskLoopSimdDirective( |
| 2769 | const OMPTaskLoopSimdDirective *D) { |
| 2770 | VisitOMPLoopDirective(D); |
| 2771 | } |
| 2772 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2773 | void EnqueueVisitor::VisitOMPDistributeDirective( |
| 2774 | const OMPDistributeDirective *D) { |
| 2775 | VisitOMPLoopDirective(D); |
| 2776 | } |
| 2777 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2778 | void EnqueueVisitor::VisitOMPDistributeParallelForDirective( |
| 2779 | const OMPDistributeParallelForDirective *D) { |
| 2780 | VisitOMPLoopDirective(D); |
| 2781 | } |
| 2782 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2783 | void EnqueueVisitor::VisitOMPDistributeParallelForSimdDirective( |
| 2784 | const OMPDistributeParallelForSimdDirective *D) { |
| 2785 | VisitOMPLoopDirective(D); |
| 2786 | } |
| 2787 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2788 | void EnqueueVisitor::VisitOMPDistributeSimdDirective( |
| 2789 | const OMPDistributeSimdDirective *D) { |
| 2790 | VisitOMPLoopDirective(D); |
| 2791 | } |
| 2792 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2793 | void EnqueueVisitor::VisitOMPTargetParallelForSimdDirective( |
| 2794 | const OMPTargetParallelForSimdDirective *D) { |
| 2795 | VisitOMPLoopDirective(D); |
| 2796 | } |
| 2797 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2798 | void EnqueueVisitor::VisitOMPTargetSimdDirective( |
| 2799 | const OMPTargetSimdDirective *D) { |
| 2800 | VisitOMPLoopDirective(D); |
| 2801 | } |
| 2802 | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2803 | void EnqueueVisitor::VisitOMPTeamsDistributeDirective( |
| 2804 | const OMPTeamsDistributeDirective *D) { |
| 2805 | VisitOMPLoopDirective(D); |
| 2806 | } |
| 2807 | |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 2808 | void EnqueueVisitor::VisitOMPTeamsDistributeSimdDirective( |
| 2809 | const OMPTeamsDistributeSimdDirective *D) { |
| 2810 | VisitOMPLoopDirective(D); |
| 2811 | } |
| 2812 | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2813 | void EnqueueVisitor::VisitOMPTeamsDistributeParallelForSimdDirective( |
| 2814 | const OMPTeamsDistributeParallelForSimdDirective *D) { |
| 2815 | VisitOMPLoopDirective(D); |
| 2816 | } |
| 2817 | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 2818 | void EnqueueVisitor::VisitOMPTeamsDistributeParallelForDirective( |
| 2819 | const OMPTeamsDistributeParallelForDirective *D) { |
| 2820 | VisitOMPLoopDirective(D); |
| 2821 | } |
| 2822 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2823 | void EnqueueVisitor::VisitOMPTargetTeamsDirective( |
| 2824 | const OMPTargetTeamsDirective *D) { |
| 2825 | VisitOMPExecutableDirective(D); |
| 2826 | } |
| 2827 | |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 2828 | void EnqueueVisitor::VisitOMPTargetTeamsDistributeDirective( |
| 2829 | const OMPTargetTeamsDistributeDirective *D) { |
| 2830 | VisitOMPLoopDirective(D); |
| 2831 | } |
| 2832 | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 2833 | void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForDirective( |
| 2834 | const OMPTargetTeamsDistributeParallelForDirective *D) { |
| 2835 | VisitOMPLoopDirective(D); |
| 2836 | } |
| 2837 | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 2838 | void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForSimdDirective( |
| 2839 | const OMPTargetTeamsDistributeParallelForSimdDirective *D) { |
| 2840 | VisitOMPLoopDirective(D); |
| 2841 | } |
| 2842 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2843 | void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2844 | EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S); |
| 2845 | } |
| 2846 | |
| 2847 | bool CursorVisitor::IsInRegionOfInterest(CXCursor C) { |
| 2848 | if (RegionOfInterest.isValid()) { |
| 2849 | SourceRange Range = getRawCursorExtent(C); |
| 2850 | if (Range.isInvalid() || CompareRegionOfInterest(Range)) |
| 2851 | return false; |
| 2852 | } |
| 2853 | return true; |
| 2854 | } |
| 2855 | |
| 2856 | bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) { |
| 2857 | while (!WL.empty()) { |
| 2858 | // Dequeue the worklist item. |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 2859 | VisitorJob LI = WL.pop_back_val(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2860 | |
| 2861 | // Set the Parent field, then back to its old value once we're done. |
| 2862 | SetParentRAII SetParent(Parent, StmtParent, LI.getParent()); |
| 2863 | |
| 2864 | switch (LI.getKind()) { |
| 2865 | case VisitorJob::DeclVisitKind: { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2866 | const Decl *D = cast<DeclVisit>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2867 | if (!D) |
| 2868 | continue; |
| 2869 | |
| 2870 | // For now, perform default visitation for Decls. |
| 2871 | if (Visit(MakeCXCursor(D, TU, RegionOfInterest, |
| 2872 | cast<DeclVisit>(&LI)->isFirst()))) |
| 2873 | return true; |
| 2874 | |
| 2875 | continue; |
| 2876 | } |
| 2877 | case VisitorJob::ExplicitTemplateArgsVisitKind: { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 2878 | for (const TemplateArgumentLoc &Arg : |
| 2879 | *cast<ExplicitTemplateArgsVisit>(&LI)) { |
| 2880 | if (VisitTemplateArgumentLoc(Arg)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2881 | return true; |
| 2882 | } |
| 2883 | continue; |
| 2884 | } |
| 2885 | case VisitorJob::TypeLocVisitKind: { |
| 2886 | // Perform default visitation for TypeLocs. |
| 2887 | if (Visit(cast<TypeLocVisit>(&LI)->get())) |
| 2888 | return true; |
| 2889 | continue; |
| 2890 | } |
| 2891 | case VisitorJob::LabelRefVisitKind: { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2892 | const LabelDecl *LS = cast<LabelRefVisit>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2893 | if (LabelStmt *stmt = LS->getStmt()) { |
| 2894 | if (Visit(MakeCursorLabelRef(stmt, cast<LabelRefVisit>(&LI)->getLoc(), |
| 2895 | TU))) { |
| 2896 | return true; |
| 2897 | } |
| 2898 | } |
| 2899 | continue; |
| 2900 | } |
| 2901 | |
| 2902 | case VisitorJob::NestedNameSpecifierLocVisitKind: { |
| 2903 | NestedNameSpecifierLocVisit *V = cast<NestedNameSpecifierLocVisit>(&LI); |
| 2904 | if (VisitNestedNameSpecifierLoc(V->get())) |
| 2905 | return true; |
| 2906 | continue; |
| 2907 | } |
| 2908 | |
| 2909 | case VisitorJob::DeclarationNameInfoVisitKind: { |
| 2910 | if (VisitDeclarationNameInfo(cast<DeclarationNameInfoVisit>(&LI) |
| 2911 | ->get())) |
| 2912 | return true; |
| 2913 | continue; |
| 2914 | } |
| 2915 | case VisitorJob::MemberRefVisitKind: { |
| 2916 | MemberRefVisit *V = cast<MemberRefVisit>(&LI); |
| 2917 | if (Visit(MakeCursorMemberRef(V->get(), V->getLoc(), TU))) |
| 2918 | return true; |
| 2919 | continue; |
| 2920 | } |
| 2921 | case VisitorJob::StmtVisitKind: { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2922 | const Stmt *S = cast<StmtVisit>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2923 | if (!S) |
| 2924 | continue; |
| 2925 | |
| 2926 | // Update the current cursor. |
| 2927 | CXCursor Cursor = MakeCXCursor(S, StmtParent, TU, RegionOfInterest); |
| 2928 | if (!IsInRegionOfInterest(Cursor)) |
| 2929 | continue; |
| 2930 | switch (Visitor(Cursor, Parent, ClientData)) { |
| 2931 | case CXChildVisit_Break: return true; |
| 2932 | case CXChildVisit_Continue: break; |
| 2933 | case CXChildVisit_Recurse: |
| 2934 | if (PostChildrenVisitor) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 2935 | WL.push_back(PostChildrenVisit(nullptr, Cursor)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2936 | EnqueueWorkList(WL, S); |
| 2937 | break; |
| 2938 | } |
| 2939 | continue; |
| 2940 | } |
| 2941 | case VisitorJob::MemberExprPartsKind: { |
| 2942 | // Handle the other pieces in the MemberExpr besides the base. |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2943 | const MemberExpr *M = cast<MemberExprParts>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2944 | |
| 2945 | // Visit the nested-name-specifier |
| 2946 | if (NestedNameSpecifierLoc QualifierLoc = M->getQualifierLoc()) |
| 2947 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 2948 | return true; |
| 2949 | |
| 2950 | // Visit the declaration name. |
| 2951 | if (VisitDeclarationNameInfo(M->getMemberNameInfo())) |
| 2952 | return true; |
| 2953 | |
| 2954 | // Visit the explicitly-specified template arguments, if any. |
| 2955 | if (M->hasExplicitTemplateArgs()) { |
| 2956 | for (const TemplateArgumentLoc *Arg = M->getTemplateArgs(), |
| 2957 | *ArgEnd = Arg + M->getNumTemplateArgs(); |
| 2958 | Arg != ArgEnd; ++Arg) { |
| 2959 | if (VisitTemplateArgumentLoc(*Arg)) |
| 2960 | return true; |
| 2961 | } |
| 2962 | } |
| 2963 | continue; |
| 2964 | } |
| 2965 | case VisitorJob::DeclRefExprPartsKind: { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2966 | const DeclRefExpr *DR = cast<DeclRefExprParts>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2967 | // Visit nested-name-specifier, if present. |
| 2968 | if (NestedNameSpecifierLoc QualifierLoc = DR->getQualifierLoc()) |
| 2969 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 2970 | return true; |
| 2971 | // Visit declaration name. |
| 2972 | if (VisitDeclarationNameInfo(DR->getNameInfo())) |
| 2973 | return true; |
| 2974 | continue; |
| 2975 | } |
| 2976 | case VisitorJob::OverloadExprPartsKind: { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2977 | const OverloadExpr *O = cast<OverloadExprParts>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2978 | // Visit the nested-name-specifier. |
| 2979 | if (NestedNameSpecifierLoc QualifierLoc = O->getQualifierLoc()) |
| 2980 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
| 2981 | return true; |
| 2982 | // Visit the declaration name. |
| 2983 | if (VisitDeclarationNameInfo(O->getNameInfo())) |
| 2984 | return true; |
| 2985 | // Visit the overloaded declaration reference. |
| 2986 | if (Visit(MakeCursorOverloadedDeclRef(O, TU))) |
| 2987 | return true; |
| 2988 | continue; |
| 2989 | } |
| 2990 | case VisitorJob::SizeOfPackExprPartsKind: { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 2991 | const SizeOfPackExpr *E = cast<SizeOfPackExprParts>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2992 | NamedDecl *Pack = E->getPack(); |
| 2993 | if (isa<TemplateTypeParmDecl>(Pack)) { |
| 2994 | if (Visit(MakeCursorTypeRef(cast<TemplateTypeParmDecl>(Pack), |
| 2995 | E->getPackLoc(), TU))) |
| 2996 | return true; |
| 2997 | |
| 2998 | continue; |
| 2999 | } |
| 3000 | |
| 3001 | if (isa<TemplateTemplateParmDecl>(Pack)) { |
| 3002 | if (Visit(MakeCursorTemplateRef(cast<TemplateTemplateParmDecl>(Pack), |
| 3003 | E->getPackLoc(), TU))) |
| 3004 | return true; |
| 3005 | |
| 3006 | continue; |
| 3007 | } |
| 3008 | |
| 3009 | // Non-type template parameter packs and function parameter packs are |
| 3010 | // treated like DeclRefExpr cursors. |
| 3011 | continue; |
| 3012 | } |
| 3013 | |
| 3014 | case VisitorJob::LambdaExprPartsKind: { |
| 3015 | // Visit captures. |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 3016 | const LambdaExpr *E = cast<LambdaExprParts>(&LI)->get(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3017 | for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(), |
| 3018 | CEnd = E->explicit_capture_end(); |
| 3019 | C != CEnd; ++C) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 3020 | // FIXME: Lambda init-captures. |
| 3021 | if (!C->capturesVariable()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3022 | continue; |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 3023 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3024 | if (Visit(MakeCursorVariableRef(C->getCapturedVar(), |
| 3025 | C->getLocation(), |
| 3026 | TU))) |
| 3027 | return true; |
| 3028 | } |
| 3029 | |
| 3030 | // Visit parameters and return type, if present. |
| 3031 | if (E->hasExplicitParameters() || E->hasExplicitResultType()) { |
| 3032 | TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); |
| 3033 | if (E->hasExplicitParameters() && E->hasExplicitResultType()) { |
| 3034 | // Visit the whole type. |
| 3035 | if (Visit(TL)) |
| 3036 | return true; |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3037 | } else if (FunctionProtoTypeLoc Proto = |
| 3038 | TL.getAs<FunctionProtoTypeLoc>()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3039 | if (E->hasExplicitParameters()) { |
| 3040 | // Visit parameters. |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 3041 | for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) |
| 3042 | if (Visit(MakeCXCursor(Proto.getParam(I), TU))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3043 | return true; |
| 3044 | } else { |
| 3045 | // Visit result type. |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 3046 | if (Visit(Proto.getReturnLoc())) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3047 | return true; |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | break; |
| 3052 | } |
| 3053 | |
| 3054 | case VisitorJob::PostChildrenVisitKind: |
| 3055 | if (PostChildrenVisitor(Parent, ClientData)) |
| 3056 | return true; |
| 3057 | break; |
| 3058 | } |
| 3059 | } |
| 3060 | return false; |
| 3061 | } |
| 3062 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 3063 | bool CursorVisitor::Visit(const Stmt *S) { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 3064 | VisitorWorkList *WL = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3065 | if (!WorkListFreeList.empty()) { |
| 3066 | WL = WorkListFreeList.back(); |
| 3067 | WL->clear(); |
| 3068 | WorkListFreeList.pop_back(); |
| 3069 | } |
| 3070 | else { |
| 3071 | WL = new VisitorWorkList(); |
| 3072 | WorkListCache.push_back(WL); |
| 3073 | } |
| 3074 | EnqueueWorkList(*WL, S); |
| 3075 | bool result = RunVisitorWorkList(*WL); |
| 3076 | WorkListFreeList.push_back(WL); |
| 3077 | return result; |
| 3078 | } |
| 3079 | |
| 3080 | namespace { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3081 | typedef SmallVector<SourceRange, 4> RefNamePieces; |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 3082 | RefNamePieces buildPieces(unsigned NameFlags, bool IsMemberRefExpr, |
| 3083 | const DeclarationNameInfo &NI, SourceRange QLoc, |
| 3084 | const SourceRange *TemplateArgsLoc = nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3085 | const bool WantQualifier = NameFlags & CXNameRange_WantQualifier; |
| 3086 | const bool WantTemplateArgs = NameFlags & CXNameRange_WantTemplateArgs; |
| 3087 | const bool WantSinglePiece = NameFlags & CXNameRange_WantSinglePiece; |
| 3088 | |
| 3089 | const DeclarationName::NameKind Kind = NI.getName().getNameKind(); |
| 3090 | |
| 3091 | RefNamePieces Pieces; |
| 3092 | |
| 3093 | if (WantQualifier && QLoc.isValid()) |
| 3094 | Pieces.push_back(QLoc); |
| 3095 | |
| 3096 | if (Kind != DeclarationName::CXXOperatorName || IsMemberRefExpr) |
| 3097 | Pieces.push_back(NI.getLoc()); |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 3098 | |
| 3099 | if (WantTemplateArgs && TemplateArgsLoc && TemplateArgsLoc->isValid()) |
| 3100 | Pieces.push_back(*TemplateArgsLoc); |
| 3101 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3102 | if (Kind == DeclarationName::CXXOperatorName) { |
| 3103 | Pieces.push_back(SourceLocation::getFromRawEncoding( |
| 3104 | NI.getInfo().CXXOperatorName.BeginOpNameLoc)); |
| 3105 | Pieces.push_back(SourceLocation::getFromRawEncoding( |
| 3106 | NI.getInfo().CXXOperatorName.EndOpNameLoc)); |
| 3107 | } |
| 3108 | |
| 3109 | if (WantSinglePiece) { |
| 3110 | SourceRange R(Pieces.front().getBegin(), Pieces.back().getEnd()); |
| 3111 | Pieces.clear(); |
| 3112 | Pieces.push_back(R); |
| 3113 | } |
| 3114 | |
| 3115 | return Pieces; |
| 3116 | } |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 3117 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3118 | |
| 3119 | //===----------------------------------------------------------------------===// |
| 3120 | // Misc. API hooks. |
| 3121 | //===----------------------------------------------------------------------===// |
| 3122 | |
Chad Rosier | 05c71aa | 2013-03-27 18:28:23 +0000 | [diff] [blame] | 3123 | static void fatal_error_handler(void *user_data, const std::string& reason, |
| 3124 | bool gen_crash_diag) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3125 | // Write the result out to stderr avoiding errs() because raw_ostreams can |
| 3126 | // call report_fatal_error. |
| 3127 | fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str()); |
| 3128 | ::abort(); |
| 3129 | } |
| 3130 | |
Chandler Carruth | 6666074 | 2014-06-27 16:37:27 +0000 | [diff] [blame] | 3131 | namespace { |
| 3132 | struct RegisterFatalErrorHandler { |
| 3133 | RegisterFatalErrorHandler() { |
| 3134 | llvm::install_fatal_error_handler(fatal_error_handler, nullptr); |
| 3135 | } |
| 3136 | }; |
| 3137 | } |
| 3138 | |
| 3139 | static llvm::ManagedStatic<RegisterFatalErrorHandler> RegisterFatalErrorHandlerOnce; |
| 3140 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3141 | CXIndex clang_createIndex(int excludeDeclarationsFromPCH, |
| 3142 | int displayDiagnostics) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3143 | // We use crash recovery to make some of our APIs more reliable, implicitly |
| 3144 | // enable it. |
Argyrios Kyrtzidis | 3701f54 | 2013-11-27 08:58:09 +0000 | [diff] [blame] | 3145 | if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY")) |
| 3146 | llvm::CrashRecoveryContext::Enable(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3147 | |
Chandler Carruth | 6666074 | 2014-06-27 16:37:27 +0000 | [diff] [blame] | 3148 | // Look through the managed static to trigger construction of the managed |
| 3149 | // static which registers our fatal error handler. This ensures it is only |
| 3150 | // registered once. |
| 3151 | (void)*RegisterFatalErrorHandlerOnce; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3152 | |
Adrian Prantl | bc06858 | 2015-07-08 01:00:30 +0000 | [diff] [blame] | 3153 | // Initialize targets for clang module support. |
| 3154 | llvm::InitializeAllTargets(); |
| 3155 | llvm::InitializeAllTargetMCs(); |
| 3156 | llvm::InitializeAllAsmPrinters(); |
| 3157 | llvm::InitializeAllAsmParsers(); |
| 3158 | |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 3159 | CIndexer *CIdxr = new CIndexer(); |
| 3160 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3161 | if (excludeDeclarationsFromPCH) |
| 3162 | CIdxr->setOnlyLocalDecls(); |
| 3163 | if (displayDiagnostics) |
| 3164 | CIdxr->setDisplayDiagnostics(); |
| 3165 | |
| 3166 | if (getenv("LIBCLANG_BGPRIO_INDEX")) |
| 3167 | CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() | |
| 3168 | CXGlobalOpt_ThreadBackgroundPriorityForIndexing); |
| 3169 | if (getenv("LIBCLANG_BGPRIO_EDIT")) |
| 3170 | CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() | |
| 3171 | CXGlobalOpt_ThreadBackgroundPriorityForEditing); |
| 3172 | |
| 3173 | return CIdxr; |
| 3174 | } |
| 3175 | |
| 3176 | void clang_disposeIndex(CXIndex CIdx) { |
| 3177 | if (CIdx) |
| 3178 | delete static_cast<CIndexer *>(CIdx); |
| 3179 | } |
| 3180 | |
| 3181 | void clang_CXIndex_setGlobalOptions(CXIndex CIdx, unsigned options) { |
| 3182 | if (CIdx) |
| 3183 | static_cast<CIndexer *>(CIdx)->setCXGlobalOptFlags(options); |
| 3184 | } |
| 3185 | |
| 3186 | unsigned clang_CXIndex_getGlobalOptions(CXIndex CIdx) { |
| 3187 | if (CIdx) |
| 3188 | return static_cast<CIndexer *>(CIdx)->getCXGlobalOptFlags(); |
| 3189 | return 0; |
| 3190 | } |
| 3191 | |
| 3192 | void clang_toggleCrashRecovery(unsigned isEnabled) { |
| 3193 | if (isEnabled) |
| 3194 | llvm::CrashRecoveryContext::Enable(); |
| 3195 | else |
| 3196 | llvm::CrashRecoveryContext::Disable(); |
| 3197 | } |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3198 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3199 | CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, |
| 3200 | const char *ast_filename) { |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 3201 | CXTranslationUnit TU; |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3202 | enum CXErrorCode Result = |
| 3203 | clang_createTranslationUnit2(CIdx, ast_filename, &TU); |
Reid Kleckner | fd48fc6 | 2014-02-12 23:56:20 +0000 | [diff] [blame] | 3204 | (void)Result; |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3205 | assert((TU && Result == CXError_Success) || |
| 3206 | (!TU && Result != CXError_Success)); |
| 3207 | return TU; |
| 3208 | } |
| 3209 | |
| 3210 | enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx, |
| 3211 | const char *ast_filename, |
| 3212 | CXTranslationUnit *out_TU) { |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 3213 | if (out_TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 3214 | *out_TU = nullptr; |
Dmitri Gribenko | 8850cda | 2014-02-19 10:24:00 +0000 | [diff] [blame] | 3215 | |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3216 | if (!CIdx || !ast_filename || !out_TU) |
| 3217 | return CXError_InvalidArguments; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3218 | |
Argyrios Kyrtzidis | 2702101 | 2013-05-24 22:24:07 +0000 | [diff] [blame] | 3219 | LOG_FUNC_SECTION { |
| 3220 | *Log << ast_filename; |
| 3221 | } |
| 3222 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3223 | CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); |
| 3224 | FileSystemOptions FileSystemOpts; |
| 3225 | |
Justin Bogner | d512c1e | 2014-10-15 00:33:06 +0000 | [diff] [blame] | 3226 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags = |
| 3227 | CompilerInstance::createDiagnostics(new DiagnosticOptions()); |
David Blaikie | 6f7382d | 2014-08-10 19:08:04 +0000 | [diff] [blame] | 3228 | std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile( |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 3229 | ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), Diags, |
Adrian Prantl | 6b21ab2 | 2015-08-27 19:46:20 +0000 | [diff] [blame] | 3230 | FileSystemOpts, /*UseDebugInfo=*/false, |
| 3231 | CXXIdx->getOnlyLocalDecls(), None, |
David Blaikie | 6f7382d | 2014-08-10 19:08:04 +0000 | [diff] [blame] | 3232 | /*CaptureDiagnostics=*/true, |
| 3233 | /*AllowPCHWithCompilerErrors=*/true, |
| 3234 | /*UserFilesAreVolatile=*/true); |
David Blaikie | ea4395e | 2017-01-06 19:49:01 +0000 | [diff] [blame^] | 3235 | *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU)); |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3236 | return *out_TU ? CXError_Success : CXError_Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | unsigned clang_defaultEditingTranslationUnitOptions() { |
| 3240 | return CXTranslationUnit_PrecompiledPreamble | |
| 3241 | CXTranslationUnit_CacheCompletionResults; |
| 3242 | } |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3243 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3244 | CXTranslationUnit |
| 3245 | clang_createTranslationUnitFromSourceFile(CXIndex CIdx, |
| 3246 | const char *source_filename, |
| 3247 | int num_command_line_args, |
| 3248 | const char * const *command_line_args, |
| 3249 | unsigned num_unsaved_files, |
| 3250 | struct CXUnsavedFile *unsaved_files) { |
| 3251 | unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord; |
| 3252 | return clang_parseTranslationUnit(CIdx, source_filename, |
| 3253 | command_line_args, num_command_line_args, |
| 3254 | unsaved_files, num_unsaved_files, |
| 3255 | Options); |
| 3256 | } |
| 3257 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3258 | static CXErrorCode |
| 3259 | clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename, |
| 3260 | const char *const *command_line_args, |
| 3261 | int num_command_line_args, |
| 3262 | ArrayRef<CXUnsavedFile> unsaved_files, |
| 3263 | unsigned options, CXTranslationUnit *out_TU) { |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 3264 | // Set up the initial return values. |
| 3265 | if (out_TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 3266 | *out_TU = nullptr; |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 3267 | |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3268 | // Check arguments. |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3269 | if (!CIdx || !out_TU) |
| 3270 | return CXError_InvalidArguments; |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3271 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3272 | CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); |
| 3273 | |
| 3274 | if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing)) |
| 3275 | setThreadBackgroundPriority(); |
| 3276 | |
| 3277 | bool PrecompilePreamble = options & CXTranslationUnit_PrecompiledPreamble; |
Benjamin Kramer | 5c248d8 | 2015-12-15 09:30:31 +0000 | [diff] [blame] | 3278 | bool CreatePreambleOnFirstParse = |
| 3279 | options & CXTranslationUnit_CreatePreambleOnFirstParse; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3280 | // FIXME: Add a flag for modules. |
| 3281 | TranslationUnitKind TUKind |
| 3282 | = (options & CXTranslationUnit_Incomplete)? TU_Prefix : TU_Complete; |
Alp Toker | 8c8a875 | 2013-12-03 06:53:35 +0000 | [diff] [blame] | 3283 | bool CacheCodeCompletionResults |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3284 | = options & CXTranslationUnit_CacheCompletionResults; |
| 3285 | bool IncludeBriefCommentsInCodeCompletion |
| 3286 | = options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; |
| 3287 | bool SkipFunctionBodies = options & CXTranslationUnit_SkipFunctionBodies; |
| 3288 | bool ForSerialization = options & CXTranslationUnit_ForSerialization; |
| 3289 | |
| 3290 | // Configure the diagnostics. |
| 3291 | IntrusiveRefCntPtr<DiagnosticsEngine> |
Sean Silva | f1b49e2 | 2013-01-20 01:58:28 +0000 | [diff] [blame] | 3292 | Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3293 | |
Manuel Klimek | 016c024 | 2016-03-01 10:56:19 +0000 | [diff] [blame] | 3294 | if (options & CXTranslationUnit_KeepGoing) |
| 3295 | Diags->setFatalsAsError(true); |
| 3296 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3297 | // Recover resources if we crash before exiting this function. |
| 3298 | llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine, |
| 3299 | llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> > |
Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 3300 | DiagCleanup(Diags.get()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3301 | |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 3302 | std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles( |
| 3303 | new std::vector<ASTUnit::RemappedFile>()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3304 | |
| 3305 | // Recover resources if we crash before exiting this function. |
| 3306 | llvm::CrashRecoveryContextCleanupRegistrar< |
| 3307 | std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get()); |
| 3308 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3309 | for (auto &UF : unsaved_files) { |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 3310 | std::unique_ptr<llvm::MemoryBuffer> MB = |
Alp Toker | 9d85b18 | 2014-07-07 01:23:14 +0000 | [diff] [blame] | 3311 | llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 3312 | RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release())); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3313 | } |
| 3314 | |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 3315 | std::unique_ptr<std::vector<const char *>> Args( |
| 3316 | new std::vector<const char *>()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3317 | |
| 3318 | // Recover resources if we crash before exiting this method. |
| 3319 | llvm::CrashRecoveryContextCleanupRegistrar<std::vector<const char*> > |
| 3320 | ArgsCleanup(Args.get()); |
| 3321 | |
| 3322 | // Since the Clang C library is primarily used by batch tools dealing with |
| 3323 | // (often very broken) source code, where spell-checking can have a |
| 3324 | // significant negative impact on performance (particularly when |
| 3325 | // precompiled headers are involved), we disable it by default. |
| 3326 | // Only do this if we haven't found a spell-checking-related argument. |
| 3327 | bool FoundSpellCheckingArgument = false; |
| 3328 | for (int I = 0; I != num_command_line_args; ++I) { |
| 3329 | if (strcmp(command_line_args[I], "-fno-spell-checking") == 0 || |
| 3330 | strcmp(command_line_args[I], "-fspell-checking") == 0) { |
| 3331 | FoundSpellCheckingArgument = true; |
| 3332 | break; |
| 3333 | } |
| 3334 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3335 | Args->insert(Args->end(), command_line_args, |
| 3336 | command_line_args + num_command_line_args); |
| 3337 | |
Benjamin Kramer | c02670e | 2015-11-18 16:14:27 +0000 | [diff] [blame] | 3338 | if (!FoundSpellCheckingArgument) |
| 3339 | Args->insert(Args->begin() + 1, "-fno-spell-checking"); |
| 3340 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3341 | // The 'source_filename' argument is optional. If the caller does not |
| 3342 | // specify it then it is assumed that the source file is specified |
| 3343 | // in the actual argument list. |
| 3344 | // Put the source file after command_line_args otherwise if '-x' flag is |
| 3345 | // present it will be unused. |
| 3346 | if (source_filename) |
| 3347 | Args->push_back(source_filename); |
| 3348 | |
| 3349 | // Do we need the detailed preprocessing record? |
| 3350 | if (options & CXTranslationUnit_DetailedPreprocessingRecord) { |
| 3351 | Args->push_back("-Xclang"); |
| 3352 | Args->push_back("-detailed-preprocessing-record"); |
| 3353 | } |
| 3354 | |
| 3355 | unsigned NumErrors = Diags->getClient()->getNumErrors(); |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 3356 | std::unique_ptr<ASTUnit> ErrUnit; |
Benjamin Kramer | 5c248d8 | 2015-12-15 09:30:31 +0000 | [diff] [blame] | 3357 | // Unless the user specified that they want the preamble on the first parse |
| 3358 | // set it up to be created on the first reparse. This makes the first parse |
| 3359 | // faster, trading for a slower (first) reparse. |
| 3360 | unsigned PrecompilePreambleAfterNParses = |
| 3361 | !PrecompilePreamble ? 0 : 2 - CreatePreambleOnFirstParse; |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 3362 | std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCommandLine( |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 3363 | Args->data(), Args->data() + Args->size(), |
| 3364 | CXXIdx->getPCHContainerOperations(), Diags, |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 3365 | CXXIdx->getClangResourcesPath(), CXXIdx->getOnlyLocalDecls(), |
| 3366 | /*CaptureDiagnostics=*/true, *RemappedFiles.get(), |
Benjamin Kramer | 5c248d8 | 2015-12-15 09:30:31 +0000 | [diff] [blame] | 3367 | /*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses, |
| 3368 | TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion, |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 3369 | /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, |
Argyrios Kyrtzidis | a3e2ff1 | 2015-11-20 03:36:21 +0000 | [diff] [blame] | 3370 | /*UserFilesAreVolatile=*/true, ForSerialization, |
| 3371 | CXXIdx->getPCHContainerOperations()->getRawReader().getFormat(), |
| 3372 | &ErrUnit)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3373 | |
Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 3374 | // Early failures in LoadFromCommandLine may return with ErrUnit unset. |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3375 | if (!Unit && !ErrUnit) |
| 3376 | return CXError_ASTReadError; |
Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 3377 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3378 | if (NumErrors != Diags->getClient()->getNumErrors()) { |
| 3379 | // Make sure to check that 'Unit' is non-NULL. |
| 3380 | if (CXXIdx->getDisplayDiagnostics()) |
| 3381 | printDiagsToStderr(Unit ? Unit.get() : ErrUnit.get()); |
| 3382 | } |
| 3383 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3384 | if (isASTReadError(Unit ? Unit.get() : ErrUnit.get())) |
| 3385 | return CXError_ASTReadError; |
| 3386 | |
David Blaikie | ea4395e | 2017-01-06 19:49:01 +0000 | [diff] [blame^] | 3387 | *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(Unit)); |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3388 | return *out_TU ? CXError_Success : CXError_Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3389 | } |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3390 | |
| 3391 | CXTranslationUnit |
| 3392 | clang_parseTranslationUnit(CXIndex CIdx, |
| 3393 | const char *source_filename, |
| 3394 | const char *const *command_line_args, |
| 3395 | int num_command_line_args, |
| 3396 | struct CXUnsavedFile *unsaved_files, |
| 3397 | unsigned num_unsaved_files, |
| 3398 | unsigned options) { |
| 3399 | CXTranslationUnit TU; |
| 3400 | enum CXErrorCode Result = clang_parseTranslationUnit2( |
| 3401 | CIdx, source_filename, command_line_args, num_command_line_args, |
| 3402 | unsaved_files, num_unsaved_files, options, &TU); |
Reid Kleckner | 6eaf05a | 2014-02-13 01:19:59 +0000 | [diff] [blame] | 3403 | (void)Result; |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 3404 | assert((TU && Result == CXError_Success) || |
| 3405 | (!TU && Result != CXError_Success)); |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3406 | return TU; |
| 3407 | } |
| 3408 | |
| 3409 | enum CXErrorCode clang_parseTranslationUnit2( |
Benjamin Kramer | c02670e | 2015-11-18 16:14:27 +0000 | [diff] [blame] | 3410 | CXIndex CIdx, const char *source_filename, |
| 3411 | const char *const *command_line_args, int num_command_line_args, |
| 3412 | struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files, |
| 3413 | unsigned options, CXTranslationUnit *out_TU) { |
| 3414 | SmallVector<const char *, 4> Args; |
| 3415 | Args.push_back("clang"); |
| 3416 | Args.append(command_line_args, command_line_args + num_command_line_args); |
| 3417 | return clang_parseTranslationUnit2FullArgv( |
| 3418 | CIdx, source_filename, Args.data(), Args.size(), unsaved_files, |
| 3419 | num_unsaved_files, options, out_TU); |
| 3420 | } |
| 3421 | |
| 3422 | enum CXErrorCode clang_parseTranslationUnit2FullArgv( |
| 3423 | CXIndex CIdx, const char *source_filename, |
| 3424 | const char *const *command_line_args, int num_command_line_args, |
| 3425 | struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files, |
| 3426 | unsigned options, CXTranslationUnit *out_TU) { |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 3427 | LOG_FUNC_SECTION { |
| 3428 | *Log << source_filename << ": "; |
| 3429 | for (int i = 0; i != num_command_line_args; ++i) |
| 3430 | *Log << command_line_args[i] << " "; |
| 3431 | } |
| 3432 | |
Alp Toker | 9d85b18 | 2014-07-07 01:23:14 +0000 | [diff] [blame] | 3433 | if (num_unsaved_files && !unsaved_files) |
| 3434 | return CXError_InvalidArguments; |
| 3435 | |
Alp Toker | 5c53298 | 2014-07-07 22:42:03 +0000 | [diff] [blame] | 3436 | CXErrorCode result = CXError_Failure; |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3437 | auto ParseTranslationUnitImpl = [=, &result] { |
| 3438 | result = clang_parseTranslationUnit_Impl( |
| 3439 | CIdx, source_filename, command_line_args, num_command_line_args, |
| 3440 | llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU); |
| 3441 | }; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3442 | llvm::CrashRecoveryContext CRC; |
| 3443 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3444 | if (!RunSafely(CRC, ParseTranslationUnitImpl)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3445 | fprintf(stderr, "libclang: crash detected during parsing: {\n"); |
| 3446 | fprintf(stderr, " 'source_filename' : '%s'\n", source_filename); |
| 3447 | fprintf(stderr, " 'command_line_args' : ["); |
| 3448 | for (int i = 0; i != num_command_line_args; ++i) { |
| 3449 | if (i) |
| 3450 | fprintf(stderr, ", "); |
| 3451 | fprintf(stderr, "'%s'", command_line_args[i]); |
| 3452 | } |
| 3453 | fprintf(stderr, "],\n"); |
| 3454 | fprintf(stderr, " 'unsaved_files' : ["); |
| 3455 | for (unsigned i = 0; i != num_unsaved_files; ++i) { |
| 3456 | if (i) |
| 3457 | fprintf(stderr, ", "); |
| 3458 | fprintf(stderr, "('%s', '...', %ld)", unsaved_files[i].Filename, |
| 3459 | unsaved_files[i].Length); |
| 3460 | } |
| 3461 | fprintf(stderr, "],\n"); |
| 3462 | fprintf(stderr, " 'options' : %d,\n", options); |
| 3463 | fprintf(stderr, "}\n"); |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3464 | |
| 3465 | return CXError_Crashed; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3466 | } else if (getenv("LIBCLANG_RESOURCE_USAGE")) { |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3467 | if (CXTranslationUnit *TU = out_TU) |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3468 | PrintLibclangResourceUsage(*TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3469 | } |
Alp Toker | 5c53298 | 2014-07-07 22:42:03 +0000 | [diff] [blame] | 3470 | |
| 3471 | return result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3474 | CXString clang_Type_getObjCEncoding(CXType CT) { |
| 3475 | CXTranslationUnit tu = static_cast<CXTranslationUnit>(CT.data[1]); |
| 3476 | ASTContext &Ctx = getASTUnit(tu)->getASTContext(); |
| 3477 | std::string encoding; |
| 3478 | Ctx.getObjCEncodingForType(QualType::getFromOpaquePtr(CT.data[0]), |
| 3479 | encoding); |
| 3480 | |
| 3481 | return cxstring::createDup(encoding); |
| 3482 | } |
| 3483 | |
| 3484 | static const IdentifierInfo *getMacroIdentifier(CXCursor C) { |
| 3485 | if (C.kind == CXCursor_MacroDefinition) { |
| 3486 | if (const MacroDefinitionRecord *MDR = getCursorMacroDefinition(C)) |
| 3487 | return MDR->getName(); |
| 3488 | } else if (C.kind == CXCursor_MacroExpansion) { |
| 3489 | MacroExpansionCursor ME = getCursorMacroExpansion(C); |
| 3490 | return ME.getName(); |
| 3491 | } |
| 3492 | return nullptr; |
| 3493 | } |
| 3494 | |
| 3495 | unsigned clang_Cursor_isMacroFunctionLike(CXCursor C) { |
| 3496 | const IdentifierInfo *II = getMacroIdentifier(C); |
| 3497 | if (!II) { |
| 3498 | return false; |
| 3499 | } |
| 3500 | ASTUnit *ASTU = getCursorASTUnit(C); |
| 3501 | Preprocessor &PP = ASTU->getPreprocessor(); |
| 3502 | if (const MacroInfo *MI = PP.getMacroInfo(II)) |
| 3503 | return MI->isFunctionLike(); |
| 3504 | return false; |
| 3505 | } |
| 3506 | |
| 3507 | unsigned clang_Cursor_isMacroBuiltin(CXCursor C) { |
| 3508 | const IdentifierInfo *II = getMacroIdentifier(C); |
| 3509 | if (!II) { |
| 3510 | return false; |
| 3511 | } |
| 3512 | ASTUnit *ASTU = getCursorASTUnit(C); |
| 3513 | Preprocessor &PP = ASTU->getPreprocessor(); |
| 3514 | if (const MacroInfo *MI = PP.getMacroInfo(II)) |
| 3515 | return MI->isBuiltinMacro(); |
| 3516 | return false; |
| 3517 | } |
| 3518 | |
| 3519 | unsigned clang_Cursor_isFunctionInlined(CXCursor C) { |
| 3520 | const Decl *D = getCursorDecl(C); |
| 3521 | const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D); |
| 3522 | if (!FD) { |
| 3523 | return false; |
| 3524 | } |
| 3525 | return FD->isInlined(); |
| 3526 | } |
| 3527 | |
| 3528 | static StringLiteral* getCFSTR_value(CallExpr *callExpr) { |
| 3529 | if (callExpr->getNumArgs() != 1) { |
| 3530 | return nullptr; |
| 3531 | } |
| 3532 | |
| 3533 | StringLiteral *S = nullptr; |
| 3534 | auto *arg = callExpr->getArg(0); |
| 3535 | if (arg->getStmtClass() == Stmt::ImplicitCastExprClass) { |
| 3536 | ImplicitCastExpr *I = static_cast<ImplicitCastExpr *>(arg); |
| 3537 | auto *subExpr = I->getSubExprAsWritten(); |
| 3538 | |
| 3539 | if(subExpr->getStmtClass() != Stmt::StringLiteralClass){ |
| 3540 | return nullptr; |
| 3541 | } |
| 3542 | |
| 3543 | S = static_cast<StringLiteral *>(I->getSubExprAsWritten()); |
| 3544 | } else if (arg->getStmtClass() == Stmt::StringLiteralClass) { |
| 3545 | S = static_cast<StringLiteral *>(callExpr->getArg(0)); |
| 3546 | } else { |
| 3547 | return nullptr; |
| 3548 | } |
| 3549 | return S; |
| 3550 | } |
| 3551 | |
David Blaikie | 5927257 | 2016-04-13 18:23:33 +0000 | [diff] [blame] | 3552 | struct ExprEvalResult { |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3553 | CXEvalResultKind EvalType; |
| 3554 | union { |
Argyrios Kyrtzidis | 5dda112 | 2016-12-01 23:41:27 +0000 | [diff] [blame] | 3555 | unsigned long long unsignedVal; |
| 3556 | long long intVal; |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3557 | double floatVal; |
| 3558 | char *stringVal; |
| 3559 | } EvalData; |
Argyrios Kyrtzidis | 5dda112 | 2016-12-01 23:41:27 +0000 | [diff] [blame] | 3560 | bool IsUnsignedInt; |
David Blaikie | 5927257 | 2016-04-13 18:23:33 +0000 | [diff] [blame] | 3561 | ~ExprEvalResult() { |
| 3562 | if (EvalType != CXEval_UnExposed && EvalType != CXEval_Float && |
| 3563 | EvalType != CXEval_Int) { |
| 3564 | delete EvalData.stringVal; |
| 3565 | } |
| 3566 | } |
| 3567 | }; |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3568 | |
| 3569 | void clang_EvalResult_dispose(CXEvalResult E) { |
David Blaikie | 5927257 | 2016-04-13 18:23:33 +0000 | [diff] [blame] | 3570 | delete static_cast<ExprEvalResult *>(E); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E) { |
| 3574 | if (!E) { |
| 3575 | return CXEval_UnExposed; |
| 3576 | } |
| 3577 | return ((ExprEvalResult *)E)->EvalType; |
| 3578 | } |
| 3579 | |
| 3580 | int clang_EvalResult_getAsInt(CXEvalResult E) { |
Argyrios Kyrtzidis | 5dda112 | 2016-12-01 23:41:27 +0000 | [diff] [blame] | 3581 | return clang_EvalResult_getAsLongLong(E); |
| 3582 | } |
| 3583 | |
| 3584 | long long clang_EvalResult_getAsLongLong(CXEvalResult E) { |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3585 | if (!E) { |
| 3586 | return 0; |
| 3587 | } |
Argyrios Kyrtzidis | 5dda112 | 2016-12-01 23:41:27 +0000 | [diff] [blame] | 3588 | ExprEvalResult *Result = (ExprEvalResult*)E; |
| 3589 | if (Result->IsUnsignedInt) |
| 3590 | return Result->EvalData.unsignedVal; |
| 3591 | return Result->EvalData.intVal; |
| 3592 | } |
| 3593 | |
| 3594 | unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E) { |
| 3595 | return ((ExprEvalResult *)E)->IsUnsignedInt; |
| 3596 | } |
| 3597 | |
| 3598 | unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E) { |
| 3599 | if (!E) { |
| 3600 | return 0; |
| 3601 | } |
| 3602 | |
| 3603 | ExprEvalResult *Result = (ExprEvalResult*)E; |
| 3604 | if (Result->IsUnsignedInt) |
| 3605 | return Result->EvalData.unsignedVal; |
| 3606 | return Result->EvalData.intVal; |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | double clang_EvalResult_getAsDouble(CXEvalResult E) { |
| 3610 | if (!E) { |
| 3611 | return 0; |
| 3612 | } |
| 3613 | return ((ExprEvalResult *)E)->EvalData.floatVal; |
| 3614 | } |
| 3615 | |
| 3616 | const char* clang_EvalResult_getAsStr(CXEvalResult E) { |
| 3617 | if (!E) { |
| 3618 | return nullptr; |
| 3619 | } |
| 3620 | return ((ExprEvalResult *)E)->EvalData.stringVal; |
| 3621 | } |
| 3622 | |
| 3623 | static const ExprEvalResult* evaluateExpr(Expr *expr, CXCursor C) { |
| 3624 | Expr::EvalResult ER; |
| 3625 | ASTContext &ctx = getCursorContext(C); |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3626 | if (!expr) |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3627 | return nullptr; |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3628 | |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3629 | expr = expr->IgnoreParens(); |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3630 | if (!expr->EvaluateAsRValue(ER, ctx)) |
| 3631 | return nullptr; |
| 3632 | |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3633 | QualType rettype; |
| 3634 | CallExpr *callExpr; |
David Blaikie | 5927257 | 2016-04-13 18:23:33 +0000 | [diff] [blame] | 3635 | auto result = llvm::make_unique<ExprEvalResult>(); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3636 | result->EvalType = CXEval_UnExposed; |
Argyrios Kyrtzidis | 5dda112 | 2016-12-01 23:41:27 +0000 | [diff] [blame] | 3637 | result->IsUnsignedInt = false; |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3638 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3639 | if (ER.Val.isInt()) { |
| 3640 | result->EvalType = CXEval_Int; |
Argyrios Kyrtzidis | 5dda112 | 2016-12-01 23:41:27 +0000 | [diff] [blame] | 3641 | |
| 3642 | auto& val = ER.Val.getInt(); |
| 3643 | if (val.isUnsigned()) { |
| 3644 | result->IsUnsignedInt = true; |
| 3645 | result->EvalData.unsignedVal = val.getZExtValue(); |
| 3646 | } else { |
| 3647 | result->EvalData.intVal = val.getExtValue(); |
| 3648 | } |
| 3649 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3650 | return result.release(); |
| 3651 | } |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3652 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3653 | if (ER.Val.isFloat()) { |
| 3654 | llvm::SmallVector<char, 100> Buffer; |
| 3655 | ER.Val.getFloat().toString(Buffer); |
| 3656 | std::string floatStr(Buffer.data(), Buffer.size()); |
| 3657 | result->EvalType = CXEval_Float; |
| 3658 | bool ignored; |
| 3659 | llvm::APFloat apFloat = ER.Val.getFloat(); |
Stephan Bergmann | 17c7f70 | 2016-12-14 11:57:17 +0000 | [diff] [blame] | 3660 | apFloat.convert(llvm::APFloat::IEEEdouble(), |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3661 | llvm::APFloat::rmNearestTiesToEven, &ignored); |
| 3662 | result->EvalData.floatVal = apFloat.convertToDouble(); |
| 3663 | return result.release(); |
| 3664 | } |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3665 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3666 | if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) { |
| 3667 | const ImplicitCastExpr *I = dyn_cast<ImplicitCastExpr>(expr); |
| 3668 | auto *subExpr = I->getSubExprAsWritten(); |
| 3669 | if (subExpr->getStmtClass() == Stmt::StringLiteralClass || |
| 3670 | subExpr->getStmtClass() == Stmt::ObjCStringLiteralClass) { |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3671 | const StringLiteral *StrE = nullptr; |
| 3672 | const ObjCStringLiteral *ObjCExpr; |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3673 | ObjCExpr = dyn_cast<ObjCStringLiteral>(subExpr); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3674 | |
| 3675 | if (ObjCExpr) { |
| 3676 | StrE = ObjCExpr->getString(); |
| 3677 | result->EvalType = CXEval_ObjCStrLiteral; |
| 3678 | } else { |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3679 | StrE = cast<StringLiteral>(I->getSubExprAsWritten()); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3680 | result->EvalType = CXEval_StrLiteral; |
| 3681 | } |
| 3682 | |
| 3683 | std::string strRef(StrE->getString().str()); |
David Blaikie | 5927257 | 2016-04-13 18:23:33 +0000 | [diff] [blame] | 3684 | result->EvalData.stringVal = new char[strRef.size() + 1]; |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3685 | strncpy((char *)result->EvalData.stringVal, strRef.c_str(), |
| 3686 | strRef.size()); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3687 | result->EvalData.stringVal[strRef.size()] = '\0'; |
David Blaikie | 5927257 | 2016-04-13 18:23:33 +0000 | [diff] [blame] | 3688 | return result.release(); |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3689 | } |
| 3690 | } else if (expr->getStmtClass() == Stmt::ObjCStringLiteralClass || |
| 3691 | expr->getStmtClass() == Stmt::StringLiteralClass) { |
| 3692 | const StringLiteral *StrE = nullptr; |
| 3693 | const ObjCStringLiteral *ObjCExpr; |
| 3694 | ObjCExpr = dyn_cast<ObjCStringLiteral>(expr); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3695 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3696 | if (ObjCExpr) { |
| 3697 | StrE = ObjCExpr->getString(); |
| 3698 | result->EvalType = CXEval_ObjCStrLiteral; |
| 3699 | } else { |
| 3700 | StrE = cast<StringLiteral>(expr); |
| 3701 | result->EvalType = CXEval_StrLiteral; |
| 3702 | } |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3703 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3704 | std::string strRef(StrE->getString().str()); |
| 3705 | result->EvalData.stringVal = new char[strRef.size() + 1]; |
| 3706 | strncpy((char *)result->EvalData.stringVal, strRef.c_str(), strRef.size()); |
| 3707 | result->EvalData.stringVal[strRef.size()] = '\0'; |
| 3708 | return result.release(); |
| 3709 | } |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3710 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3711 | if (expr->getStmtClass() == Stmt::CStyleCastExprClass) { |
| 3712 | CStyleCastExpr *CC = static_cast<CStyleCastExpr *>(expr); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3713 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3714 | rettype = CC->getType(); |
| 3715 | if (rettype.getAsString() == "CFStringRef" && |
| 3716 | CC->getSubExpr()->getStmtClass() == Stmt::CallExprClass) { |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3717 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3718 | callExpr = static_cast<CallExpr *>(CC->getSubExpr()); |
| 3719 | StringLiteral *S = getCFSTR_value(callExpr); |
| 3720 | if (S) { |
| 3721 | std::string strLiteral(S->getString().str()); |
| 3722 | result->EvalType = CXEval_CFStr; |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3723 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3724 | result->EvalData.stringVal = new char[strLiteral.size() + 1]; |
| 3725 | strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(), |
| 3726 | strLiteral.size()); |
| 3727 | result->EvalData.stringVal[strLiteral.size()] = '\0'; |
David Blaikie | 5927257 | 2016-04-13 18:23:33 +0000 | [diff] [blame] | 3728 | return result.release(); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | |
David Blaikie | bbc0088 | 2016-04-13 18:36:19 +0000 | [diff] [blame] | 3732 | } else if (expr->getStmtClass() == Stmt::CallExprClass) { |
| 3733 | callExpr = static_cast<CallExpr *>(expr); |
| 3734 | rettype = callExpr->getCallReturnType(ctx); |
| 3735 | |
| 3736 | if (rettype->isVectorType() || callExpr->getNumArgs() > 1) |
| 3737 | return nullptr; |
| 3738 | |
| 3739 | if (rettype->isIntegralType(ctx) || rettype->isRealFloatingType()) { |
| 3740 | if (callExpr->getNumArgs() == 1 && |
| 3741 | !callExpr->getArg(0)->getType()->isIntegralType(ctx)) |
| 3742 | return nullptr; |
| 3743 | } else if (rettype.getAsString() == "CFStringRef") { |
| 3744 | |
| 3745 | StringLiteral *S = getCFSTR_value(callExpr); |
| 3746 | if (S) { |
| 3747 | std::string strLiteral(S->getString().str()); |
| 3748 | result->EvalType = CXEval_CFStr; |
| 3749 | result->EvalData.stringVal = new char[strLiteral.size() + 1]; |
| 3750 | strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(), |
| 3751 | strLiteral.size()); |
| 3752 | result->EvalData.stringVal[strLiteral.size()] = '\0'; |
| 3753 | return result.release(); |
| 3754 | } |
| 3755 | } |
| 3756 | } else if (expr->getStmtClass() == Stmt::DeclRefExprClass) { |
| 3757 | DeclRefExpr *D = static_cast<DeclRefExpr *>(expr); |
| 3758 | ValueDecl *V = D->getDecl(); |
| 3759 | if (V->getKind() == Decl::Function) { |
| 3760 | std::string strName = V->getNameAsString(); |
| 3761 | result->EvalType = CXEval_Other; |
| 3762 | result->EvalData.stringVal = new char[strName.size() + 1]; |
| 3763 | strncpy(result->EvalData.stringVal, strName.c_str(), strName.size()); |
| 3764 | result->EvalData.stringVal[strName.size()] = '\0'; |
| 3765 | return result.release(); |
| 3766 | } |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3767 | } |
| 3768 | |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3769 | return nullptr; |
| 3770 | } |
| 3771 | |
| 3772 | CXEvalResult clang_Cursor_Evaluate(CXCursor C) { |
| 3773 | const Decl *D = getCursorDecl(C); |
| 3774 | if (D) { |
| 3775 | const Expr *expr = nullptr; |
| 3776 | if (auto *Var = dyn_cast<VarDecl>(D)) { |
| 3777 | expr = Var->getInit(); |
| 3778 | } else if (auto *Field = dyn_cast<FieldDecl>(D)) { |
| 3779 | expr = Field->getInClassInitializer(); |
| 3780 | } |
| 3781 | if (expr) |
Aaron Ballman | 01dc157 | 2016-01-20 15:25:30 +0000 | [diff] [blame] | 3782 | return const_cast<CXEvalResult>(reinterpret_cast<const void *>( |
| 3783 | evaluateExpr(const_cast<Expr *>(expr), C))); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3784 | return nullptr; |
| 3785 | } |
| 3786 | |
| 3787 | const CompoundStmt *compoundStmt = dyn_cast_or_null<CompoundStmt>(getCursorStmt(C)); |
| 3788 | if (compoundStmt) { |
| 3789 | Expr *expr = nullptr; |
| 3790 | for (auto *bodyIterator : compoundStmt->body()) { |
| 3791 | if ((expr = dyn_cast<Expr>(bodyIterator))) { |
| 3792 | break; |
| 3793 | } |
| 3794 | } |
| 3795 | if (expr) |
Aaron Ballman | 01dc157 | 2016-01-20 15:25:30 +0000 | [diff] [blame] | 3796 | return const_cast<CXEvalResult>( |
| 3797 | reinterpret_cast<const void *>(evaluateExpr(expr, C))); |
Argyrios Kyrtzidis | 785705b | 2016-01-16 00:20:02 +0000 | [diff] [blame] | 3798 | } |
| 3799 | return nullptr; |
| 3800 | } |
| 3801 | |
| 3802 | unsigned clang_Cursor_hasAttrs(CXCursor C) { |
| 3803 | const Decl *D = getCursorDecl(C); |
| 3804 | if (!D) { |
| 3805 | return 0; |
| 3806 | } |
| 3807 | |
| 3808 | if (D->hasAttrs()) { |
| 3809 | return 1; |
| 3810 | } |
| 3811 | |
| 3812 | return 0; |
| 3813 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3814 | unsigned clang_defaultSaveOptions(CXTranslationUnit TU) { |
| 3815 | return CXSaveTranslationUnit_None; |
| 3816 | } |
| 3817 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3818 | static CXSaveError clang_saveTranslationUnit_Impl(CXTranslationUnit TU, |
| 3819 | const char *FileName, |
| 3820 | unsigned options) { |
| 3821 | CIndexer *CXXIdx = TU->CIdx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3822 | if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing)) |
| 3823 | setThreadBackgroundPriority(); |
| 3824 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3825 | bool hadError = cxtu::getASTUnit(TU)->Save(FileName); |
| 3826 | return hadError ? CXSaveError_Unknown : CXSaveError_None; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName, |
| 3830 | unsigned options) { |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 3831 | LOG_FUNC_SECTION { |
| 3832 | *Log << TU << ' ' << FileName; |
| 3833 | } |
| 3834 | |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 3835 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 3836 | LOG_BAD_TU(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3837 | return CXSaveError_InvalidTU; |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 3838 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3839 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 3840 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3841 | ASTUnit::ConcurrencyCheck Check(*CXXUnit); |
| 3842 | if (!CXXUnit->hasSema()) |
| 3843 | return CXSaveError_InvalidTU; |
| 3844 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3845 | CXSaveError result; |
| 3846 | auto SaveTranslationUnitImpl = [=, &result]() { |
| 3847 | result = clang_saveTranslationUnit_Impl(TU, FileName, options); |
| 3848 | }; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3849 | |
| 3850 | if (!CXXUnit->getDiagnostics().hasUnrecoverableErrorOccurred() || |
| 3851 | getenv("LIBCLANG_NOTHREADS")) { |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3852 | SaveTranslationUnitImpl(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3853 | |
| 3854 | if (getenv("LIBCLANG_RESOURCE_USAGE")) |
| 3855 | PrintLibclangResourceUsage(TU); |
| 3856 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3857 | return result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | // We have an AST that has invalid nodes due to compiler errors. |
| 3861 | // Use a crash recovery thread for protection. |
| 3862 | |
| 3863 | llvm::CrashRecoveryContext CRC; |
| 3864 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3865 | if (!RunSafely(CRC, SaveTranslationUnitImpl)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3866 | fprintf(stderr, "libclang: crash detected during AST saving: {\n"); |
| 3867 | fprintf(stderr, " 'filename' : '%s'\n", FileName); |
| 3868 | fprintf(stderr, " 'options' : %d,\n", options); |
| 3869 | fprintf(stderr, "}\n"); |
| 3870 | |
| 3871 | return CXSaveError_Unknown; |
| 3872 | |
| 3873 | } else if (getenv("LIBCLANG_RESOURCE_USAGE")) { |
| 3874 | PrintLibclangResourceUsage(TU); |
| 3875 | } |
| 3876 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3877 | return result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) { |
| 3881 | if (CTUnit) { |
| 3882 | // If the translation unit has been marked as unsafe to free, just discard |
| 3883 | // it. |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3884 | ASTUnit *Unit = cxtu::getASTUnit(CTUnit); |
| 3885 | if (Unit && Unit->isUnsafeToFree()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3886 | return; |
| 3887 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 3888 | delete cxtu::getASTUnit(CTUnit); |
Dmitri Gribenko | b95b3f1 | 2013-01-26 22:44:19 +0000 | [diff] [blame] | 3889 | delete CTUnit->StringPool; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3890 | delete static_cast<CXDiagnosticSetImpl *>(CTUnit->Diagnostics); |
| 3891 | disposeOverridenCXCursorsPool(CTUnit->OverridenCursorsPool); |
Dmitri Gribenko | 9e60511 | 2013-11-13 22:16:51 +0000 | [diff] [blame] | 3892 | delete CTUnit->CommentToXML; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3893 | delete CTUnit; |
| 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | unsigned clang_defaultReparseOptions(CXTranslationUnit TU) { |
| 3898 | return CXReparse_None; |
| 3899 | } |
| 3900 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3901 | static CXErrorCode |
| 3902 | clang_reparseTranslationUnit_Impl(CXTranslationUnit TU, |
| 3903 | ArrayRef<CXUnsavedFile> unsaved_files, |
| 3904 | unsigned options) { |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3905 | // Check arguments. |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 3906 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 3907 | LOG_BAD_TU(TU); |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3908 | return CXError_InvalidArguments; |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3909 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3910 | |
| 3911 | // Reset the associated diagnostics. |
| 3912 | delete static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 3913 | TU->Diagnostics = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3914 | |
Dmitri Gribenko | 183436e | 2013-01-26 21:49:50 +0000 | [diff] [blame] | 3915 | CIndexer *CXXIdx = TU->CIdx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3916 | if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing)) |
| 3917 | setThreadBackgroundPriority(); |
| 3918 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 3919 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3920 | ASTUnit::ConcurrencyCheck Check(*CXXUnit); |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 3921 | |
| 3922 | std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles( |
| 3923 | new std::vector<ASTUnit::RemappedFile>()); |
| 3924 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3925 | // Recover resources if we crash before exiting this function. |
| 3926 | llvm::CrashRecoveryContextCleanupRegistrar< |
| 3927 | std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get()); |
Alp Toker | 9d85b18 | 2014-07-07 01:23:14 +0000 | [diff] [blame] | 3928 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3929 | for (auto &UF : unsaved_files) { |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 3930 | std::unique_ptr<llvm::MemoryBuffer> MB = |
Alp Toker | 9d85b18 | 2014-07-07 01:23:14 +0000 | [diff] [blame] | 3931 | llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 3932 | RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release())); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3933 | } |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3934 | |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 3935 | if (!CXXUnit->Reparse(CXXIdx->getPCHContainerOperations(), |
| 3936 | *RemappedFiles.get())) |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3937 | return CXError_Success; |
| 3938 | if (isASTReadError(CXXUnit)) |
| 3939 | return CXError_ASTReadError; |
| 3940 | return CXError_Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | int clang_reparseTranslationUnit(CXTranslationUnit TU, |
| 3944 | unsigned num_unsaved_files, |
| 3945 | struct CXUnsavedFile *unsaved_files, |
| 3946 | unsigned options) { |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 3947 | LOG_FUNC_SECTION { |
| 3948 | *Log << TU; |
| 3949 | } |
| 3950 | |
Alp Toker | 9d85b18 | 2014-07-07 01:23:14 +0000 | [diff] [blame] | 3951 | if (num_unsaved_files && !unsaved_files) |
| 3952 | return CXError_InvalidArguments; |
| 3953 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3954 | CXErrorCode result; |
| 3955 | auto ReparseTranslationUnitImpl = [=, &result]() { |
| 3956 | result = clang_reparseTranslationUnit_Impl( |
| 3957 | TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options); |
| 3958 | }; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3959 | |
| 3960 | if (getenv("LIBCLANG_NOTHREADS")) { |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3961 | ReparseTranslationUnitImpl(); |
Alp Toker | 5c53298 | 2014-07-07 22:42:03 +0000 | [diff] [blame] | 3962 | return result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | llvm::CrashRecoveryContext CRC; |
| 3966 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 3967 | if (!RunSafely(CRC, ReparseTranslationUnitImpl)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3968 | fprintf(stderr, "libclang: crash detected during reparsing\n"); |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 3969 | cxtu::getASTUnit(TU)->setUnsafeToFree(true); |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 3970 | return CXError_Crashed; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3971 | } else if (getenv("LIBCLANG_RESOURCE_USAGE")) |
| 3972 | PrintLibclangResourceUsage(TU); |
| 3973 | |
Alp Toker | 5c53298 | 2014-07-07 22:42:03 +0000 | [diff] [blame] | 3974 | return result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | |
| 3978 | CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 3979 | if (isNotUsableTU(CTUnit)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 3980 | LOG_BAD_TU(CTUnit); |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 3981 | return cxstring::createEmpty(); |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 3982 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3983 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 3984 | ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 3985 | return cxstring::createDup(CXXUnit->getOriginalSourceFileName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 3989 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 3990 | LOG_BAD_TU(TU); |
Argyrios Kyrtzidis | 0e95fca | 2013-04-04 22:40:59 +0000 | [diff] [blame] | 3991 | return clang_getNullCursor(); |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 3992 | } |
Argyrios Kyrtzidis | 0e95fca | 2013-04-04 22:40:59 +0000 | [diff] [blame] | 3993 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 3994 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3995 | return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU); |
| 3996 | } |
| 3997 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3998 | //===----------------------------------------------------------------------===// |
| 3999 | // CXFile Operations. |
| 4000 | //===----------------------------------------------------------------------===// |
| 4001 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4002 | CXString clang_getFileName(CXFile SFile) { |
| 4003 | if (!SFile) |
Dmitri Gribenko | f98dfba | 2013-02-01 14:13:32 +0000 | [diff] [blame] | 4004 | return cxstring::createNull(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4005 | |
| 4006 | FileEntry *FEnt = static_cast<FileEntry *>(SFile); |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4007 | return cxstring::createRef(FEnt->getName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | time_t clang_getFileTime(CXFile SFile) { |
| 4011 | if (!SFile) |
| 4012 | return 0; |
| 4013 | |
| 4014 | FileEntry *FEnt = static_cast<FileEntry *>(SFile); |
| 4015 | return FEnt->getModificationTime(); |
| 4016 | } |
| 4017 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 4018 | CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 4019 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 4020 | LOG_BAD_TU(TU); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 4021 | return nullptr; |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 4022 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4023 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 4024 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4025 | |
| 4026 | FileManager &FMgr = CXXUnit->getFileManager(); |
| 4027 | return const_cast<FileEntry *>(FMgr.getFile(file_name)); |
| 4028 | } |
| 4029 | |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 4030 | unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU, |
| 4031 | CXFile file) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 4032 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 4033 | LOG_BAD_TU(TU); |
| 4034 | return 0; |
| 4035 | } |
| 4036 | |
| 4037 | if (!file) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4038 | return 0; |
| 4039 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 4040 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4041 | FileEntry *FEnt = static_cast<FileEntry *>(file); |
| 4042 | return CXXUnit->getPreprocessor().getHeaderSearchInfo() |
| 4043 | .isFileMultipleIncludeGuarded(FEnt); |
| 4044 | } |
| 4045 | |
Argyrios Kyrtzidis | ac08b26 | 2013-01-26 04:52:52 +0000 | [diff] [blame] | 4046 | int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) { |
| 4047 | if (!file || !outID) |
| 4048 | return 1; |
| 4049 | |
Argyrios Kyrtzidis | ac08b26 | 2013-01-26 04:52:52 +0000 | [diff] [blame] | 4050 | FileEntry *FEnt = static_cast<FileEntry *>(file); |
Rafael Espindola | f8f91b8 | 2013-08-01 21:42:11 +0000 | [diff] [blame] | 4051 | const llvm::sys::fs::UniqueID &ID = FEnt->getUniqueID(); |
| 4052 | outID->data[0] = ID.getDevice(); |
| 4053 | outID->data[1] = ID.getFile(); |
Argyrios Kyrtzidis | ac08b26 | 2013-01-26 04:52:52 +0000 | [diff] [blame] | 4054 | outID->data[2] = FEnt->getModificationTime(); |
| 4055 | return 0; |
Argyrios Kyrtzidis | ac08b26 | 2013-01-26 04:52:52 +0000 | [diff] [blame] | 4056 | } |
| 4057 | |
Argyrios Kyrtzidis | ac3997e | 2014-08-16 00:26:19 +0000 | [diff] [blame] | 4058 | int clang_File_isEqual(CXFile file1, CXFile file2) { |
| 4059 | if (file1 == file2) |
| 4060 | return true; |
| 4061 | |
| 4062 | if (!file1 || !file2) |
| 4063 | return false; |
| 4064 | |
| 4065 | FileEntry *FEnt1 = static_cast<FileEntry *>(file1); |
| 4066 | FileEntry *FEnt2 = static_cast<FileEntry *>(file2); |
| 4067 | return FEnt1->getUniqueID() == FEnt2->getUniqueID(); |
| 4068 | } |
| 4069 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4070 | //===----------------------------------------------------------------------===// |
| 4071 | // CXCursor Operations. |
| 4072 | //===----------------------------------------------------------------------===// |
| 4073 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4074 | static const Decl *getDeclFromExpr(const Stmt *E) { |
| 4075 | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4076 | return getDeclFromExpr(CE->getSubExpr()); |
| 4077 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4078 | if (const DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4079 | return RefExpr->getDecl(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4080 | if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4081 | return ME->getMemberDecl(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4082 | if (const ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4083 | return RE->getDecl(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4084 | if (const ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(E)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4085 | if (PRE->isExplicitProperty()) |
| 4086 | return PRE->getExplicitProperty(); |
| 4087 | // It could be messaging both getter and setter as in: |
| 4088 | // ++myobj.myprop; |
| 4089 | // in which case prefer to associate the setter since it is less obvious |
| 4090 | // from inspecting the source that the setter is going to get called. |
| 4091 | if (PRE->isMessagingSetter()) |
| 4092 | return PRE->getImplicitPropertySetter(); |
| 4093 | return PRE->getImplicitPropertyGetter(); |
| 4094 | } |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4095 | if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4096 | return getDeclFromExpr(POE->getSyntacticForm()); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4097 | if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4098 | if (Expr *Src = OVE->getSourceExpr()) |
| 4099 | return getDeclFromExpr(Src); |
| 4100 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4101 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4102 | return getDeclFromExpr(CE->getCallee()); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4103 | if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4104 | if (!CE->isElidable()) |
| 4105 | return CE->getConstructor(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 4106 | if (const CXXInheritedCtorInitExpr *CE = |
| 4107 | dyn_cast<CXXInheritedCtorInitExpr>(E)) |
| 4108 | return CE->getConstructor(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4109 | if (const ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4110 | return OME->getMethodDecl(); |
| 4111 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4112 | if (const ObjCProtocolExpr *PE = dyn_cast<ObjCProtocolExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4113 | return PE->getProtocol(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4114 | if (const SubstNonTypeTemplateParmPackExpr *NTTP |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4115 | = dyn_cast<SubstNonTypeTemplateParmPackExpr>(E)) |
| 4116 | return NTTP->getParameterPack(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4117 | if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4118 | if (isa<NonTypeTemplateParmDecl>(SizeOfPack->getPack()) || |
| 4119 | isa<ParmVarDecl>(SizeOfPack->getPack())) |
| 4120 | return SizeOfPack->getPack(); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 4121 | |
| 4122 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4123 | } |
| 4124 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4125 | static SourceLocation getLocationFromExpr(const Expr *E) { |
| 4126 | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4127 | return getLocationFromExpr(CE->getSubExpr()); |
| 4128 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4129 | if (const ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4130 | return /*FIXME:*/Msg->getLeftLoc(); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4131 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4132 | return DRE->getLocation(); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4133 | if (const MemberExpr *Member = dyn_cast<MemberExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4134 | return Member->getMemberLoc(); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4135 | if (const ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4136 | return Ivar->getLocation(); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4137 | if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4138 | return SizeOfPack->getPackLoc(); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4139 | if (const ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4140 | return PropRef->getLocation(); |
| 4141 | |
| 4142 | return E->getLocStart(); |
| 4143 | } |
| 4144 | |
NAKAMURA Takumi | a01f4c3 | 2016-12-19 16:50:43 +0000 | [diff] [blame] | 4145 | extern "C" { |
| 4146 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4147 | unsigned clang_visitChildren(CXCursor parent, |
| 4148 | CXCursorVisitor visitor, |
| 4149 | CXClientData client_data) { |
| 4150 | CursorVisitor CursorVis(getCursorTU(parent), visitor, client_data, |
| 4151 | /*VisitPreprocessorLast=*/false); |
| 4152 | return CursorVis.VisitChildren(parent); |
| 4153 | } |
| 4154 | |
| 4155 | #ifndef __has_feature |
| 4156 | #define __has_feature(x) 0 |
| 4157 | #endif |
| 4158 | #if __has_feature(blocks) |
| 4159 | typedef enum CXChildVisitResult |
| 4160 | (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent); |
| 4161 | |
| 4162 | static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent, |
| 4163 | CXClientData client_data) { |
| 4164 | CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data; |
| 4165 | return block(cursor, parent); |
| 4166 | } |
| 4167 | #else |
| 4168 | // If we are compiled with a compiler that doesn't have native blocks support, |
| 4169 | // define and call the block manually, so the |
| 4170 | typedef struct _CXChildVisitResult |
| 4171 | { |
| 4172 | void *isa; |
| 4173 | int flags; |
| 4174 | int reserved; |
| 4175 | enum CXChildVisitResult(*invoke)(struct _CXChildVisitResult*, CXCursor, |
| 4176 | CXCursor); |
| 4177 | } *CXCursorVisitorBlock; |
| 4178 | |
| 4179 | static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent, |
| 4180 | CXClientData client_data) { |
| 4181 | CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data; |
| 4182 | return block->invoke(block, cursor, parent); |
| 4183 | } |
| 4184 | #endif |
| 4185 | |
| 4186 | |
| 4187 | unsigned clang_visitChildrenWithBlock(CXCursor parent, |
| 4188 | CXCursorVisitorBlock block) { |
| 4189 | return clang_visitChildren(parent, visitWithBlock, block); |
| 4190 | } |
| 4191 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4192 | static CXString getDeclSpelling(const Decl *D) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4193 | if (!D) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4194 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4195 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4196 | const NamedDecl *ND = dyn_cast<NamedDecl>(D); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4197 | if (!ND) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4198 | if (const ObjCPropertyImplDecl *PropImpl = |
| 4199 | dyn_cast<ObjCPropertyImplDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4200 | if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl()) |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4201 | return cxstring::createDup(Property->getIdentifier()->getName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4202 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4203 | if (const ImportDecl *ImportD = dyn_cast<ImportDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4204 | if (Module *Mod = ImportD->getImportedModule()) |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4205 | return cxstring::createDup(Mod->getFullModuleName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4206 | |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4207 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4208 | } |
| 4209 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4210 | if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4211 | return cxstring::createDup(OMD->getSelector().getAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4212 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4213 | if (const ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4214 | // No, this isn't the same as the code below. getIdentifier() is non-virtual |
| 4215 | // and returns different names. NamedDecl returns the class name and |
| 4216 | // ObjCCategoryImplDecl returns the category name. |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4217 | return cxstring::createRef(CIMP->getIdentifier()->getNameStart()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4218 | |
| 4219 | if (isa<UsingDirectiveDecl>(D)) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4220 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4221 | |
| 4222 | SmallString<1024> S; |
| 4223 | llvm::raw_svector_ostream os(S); |
| 4224 | ND->printName(os); |
| 4225 | |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4226 | return cxstring::createDup(os.str()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | CXString clang_getCursorSpelling(CXCursor C) { |
| 4230 | if (clang_isTranslationUnit(C.kind)) |
Dmitri Gribenko | 2c173b4 | 2013-01-11 19:28:44 +0000 | [diff] [blame] | 4231 | return clang_getTranslationUnitSpelling(getCursorTU(C)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4232 | |
| 4233 | if (clang_isReference(C.kind)) { |
| 4234 | switch (C.kind) { |
| 4235 | case CXCursor_ObjCSuperClassRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4236 | const ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first; |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4237 | return cxstring::createRef(Super->getIdentifier()->getNameStart()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4238 | } |
| 4239 | case CXCursor_ObjCClassRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4240 | const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first; |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4241 | return cxstring::createRef(Class->getIdentifier()->getNameStart()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4242 | } |
| 4243 | case CXCursor_ObjCProtocolRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4244 | const ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4245 | assert(OID && "getCursorSpelling(): Missing protocol decl"); |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4246 | return cxstring::createRef(OID->getIdentifier()->getNameStart()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4247 | } |
| 4248 | case CXCursor_CXXBaseSpecifier: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4249 | const CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4250 | return cxstring::createDup(B->getType().getAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4251 | } |
| 4252 | case CXCursor_TypeRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4253 | const TypeDecl *Type = getCursorTypeRef(C).first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4254 | assert(Type && "Missing type decl"); |
| 4255 | |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4256 | return cxstring::createDup(getCursorContext(C).getTypeDeclType(Type). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4257 | getAsString()); |
| 4258 | } |
| 4259 | case CXCursor_TemplateRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4260 | const TemplateDecl *Template = getCursorTemplateRef(C).first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4261 | assert(Template && "Missing template decl"); |
| 4262 | |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4263 | return cxstring::createDup(Template->getNameAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | case CXCursor_NamespaceRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4267 | const NamedDecl *NS = getCursorNamespaceRef(C).first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4268 | assert(NS && "Missing namespace decl"); |
| 4269 | |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4270 | return cxstring::createDup(NS->getNameAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | case CXCursor_MemberRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4274 | const FieldDecl *Field = getCursorMemberRef(C).first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4275 | assert(Field && "Missing member decl"); |
| 4276 | |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4277 | return cxstring::createDup(Field->getNameAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | case CXCursor_LabelRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4281 | const LabelStmt *Label = getCursorLabelRef(C).first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4282 | assert(Label && "Missing label"); |
| 4283 | |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4284 | return cxstring::createRef(Label->getName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | case CXCursor_OverloadedDeclRef: { |
| 4288 | OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first; |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4289 | if (const Decl *D = Storage.dyn_cast<const Decl *>()) { |
| 4290 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4291 | return cxstring::createDup(ND->getNameAsString()); |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4292 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4293 | } |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4294 | if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>()) |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4295 | return cxstring::createDup(E->getName().getAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4296 | OverloadedTemplateStorage *Ovl |
| 4297 | = Storage.get<OverloadedTemplateStorage*>(); |
| 4298 | if (Ovl->size() == 0) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4299 | return cxstring::createEmpty(); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4300 | return cxstring::createDup((*Ovl->begin())->getNameAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | case CXCursor_VariableRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 4304 | const VarDecl *Var = getCursorVariableRef(C).first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4305 | assert(Var && "Missing variable decl"); |
| 4306 | |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4307 | return cxstring::createDup(Var->getNameAsString()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | default: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4311 | return cxstring::createRef("<not implemented>"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | if (clang_isExpression(C.kind)) { |
Argyrios Kyrtzidis | 3227d86 | 2014-03-03 19:40:52 +0000 | [diff] [blame] | 4316 | const Expr *E = getCursorExpr(C); |
| 4317 | |
| 4318 | if (C.kind == CXCursor_ObjCStringLiteral || |
| 4319 | C.kind == CXCursor_StringLiteral) { |
| 4320 | const StringLiteral *SLit; |
| 4321 | if (const ObjCStringLiteral *OSL = dyn_cast<ObjCStringLiteral>(E)) { |
| 4322 | SLit = OSL->getString(); |
| 4323 | } else { |
| 4324 | SLit = cast<StringLiteral>(E); |
| 4325 | } |
| 4326 | SmallString<256> Buf; |
| 4327 | llvm::raw_svector_ostream OS(Buf); |
| 4328 | SLit->outputString(OS); |
| 4329 | return cxstring::createDup(OS.str()); |
| 4330 | } |
| 4331 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4332 | const Decl *D = getDeclFromExpr(getCursorExpr(C)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4333 | if (D) |
| 4334 | return getDeclSpelling(D); |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4335 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | if (clang_isStatement(C.kind)) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4339 | const Stmt *S = getCursorStmt(C); |
| 4340 | if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4341 | return cxstring::createRef(Label->getName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4342 | |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4343 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | if (C.kind == CXCursor_MacroExpansion) |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4347 | return cxstring::createRef(getCursorMacroExpansion(C).getName() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4348 | ->getNameStart()); |
| 4349 | |
| 4350 | if (C.kind == CXCursor_MacroDefinition) |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4351 | return cxstring::createRef(getCursorMacroDefinition(C)->getName() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4352 | ->getNameStart()); |
| 4353 | |
| 4354 | if (C.kind == CXCursor_InclusionDirective) |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4355 | return cxstring::createDup(getCursorInclusionDirective(C)->getFileName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4356 | |
| 4357 | if (clang_isDeclaration(C.kind)) |
| 4358 | return getDeclSpelling(getCursorDecl(C)); |
| 4359 | |
| 4360 | if (C.kind == CXCursor_AnnotateAttr) { |
Dmitri Gribenko | e4baea6 | 2013-01-26 18:08:08 +0000 | [diff] [blame] | 4361 | const AnnotateAttr *AA = cast<AnnotateAttr>(cxcursor::getCursorAttr(C)); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4362 | return cxstring::createDup(AA->getAnnotation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | if (C.kind == CXCursor_AsmLabelAttr) { |
Dmitri Gribenko | e4baea6 | 2013-01-26 18:08:08 +0000 | [diff] [blame] | 4366 | const AsmLabelAttr *AA = cast<AsmLabelAttr>(cxcursor::getCursorAttr(C)); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4367 | return cxstring::createDup(AA->getLabel()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
Argyrios Kyrtzidis | 16834f1 | 2013-09-25 00:14:38 +0000 | [diff] [blame] | 4370 | if (C.kind == CXCursor_PackedAttr) { |
| 4371 | return cxstring::createRef("packed"); |
| 4372 | } |
| 4373 | |
Saleem Abdulrasool | 79c6971 | 2015-09-05 18:53:43 +0000 | [diff] [blame] | 4374 | if (C.kind == CXCursor_VisibilityAttr) { |
| 4375 | const VisibilityAttr *AA = cast<VisibilityAttr>(cxcursor::getCursorAttr(C)); |
| 4376 | switch (AA->getVisibility()) { |
| 4377 | case VisibilityAttr::VisibilityType::Default: |
| 4378 | return cxstring::createRef("default"); |
| 4379 | case VisibilityAttr::VisibilityType::Hidden: |
| 4380 | return cxstring::createRef("hidden"); |
| 4381 | case VisibilityAttr::VisibilityType::Protected: |
| 4382 | return cxstring::createRef("protected"); |
| 4383 | } |
| 4384 | llvm_unreachable("unknown visibility type"); |
| 4385 | } |
| 4386 | |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4387 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C, |
| 4391 | unsigned pieceIndex, |
| 4392 | unsigned options) { |
| 4393 | if (clang_Cursor_isNull(C)) |
| 4394 | return clang_getNullRange(); |
| 4395 | |
| 4396 | ASTContext &Ctx = getCursorContext(C); |
| 4397 | |
| 4398 | if (clang_isStatement(C.kind)) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4399 | const Stmt *S = getCursorStmt(C); |
| 4400 | if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4401 | if (pieceIndex > 0) |
| 4402 | return clang_getNullRange(); |
| 4403 | return cxloc::translateSourceRange(Ctx, Label->getIdentLoc()); |
| 4404 | } |
| 4405 | |
| 4406 | return clang_getNullRange(); |
| 4407 | } |
| 4408 | |
| 4409 | if (C.kind == CXCursor_ObjCMessageExpr) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 4410 | if (const ObjCMessageExpr * |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4411 | ME = dyn_cast_or_null<ObjCMessageExpr>(getCursorExpr(C))) { |
| 4412 | if (pieceIndex >= ME->getNumSelectorLocs()) |
| 4413 | return clang_getNullRange(); |
| 4414 | return cxloc::translateSourceRange(Ctx, ME->getSelectorLoc(pieceIndex)); |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | if (C.kind == CXCursor_ObjCInstanceMethodDecl || |
| 4419 | C.kind == CXCursor_ObjCClassMethodDecl) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4420 | if (const ObjCMethodDecl * |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4421 | MD = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(C))) { |
| 4422 | if (pieceIndex >= MD->getNumSelectorLocs()) |
| 4423 | return clang_getNullRange(); |
| 4424 | return cxloc::translateSourceRange(Ctx, MD->getSelectorLoc(pieceIndex)); |
| 4425 | } |
| 4426 | } |
| 4427 | |
| 4428 | if (C.kind == CXCursor_ObjCCategoryDecl || |
| 4429 | C.kind == CXCursor_ObjCCategoryImplDecl) { |
| 4430 | if (pieceIndex > 0) |
| 4431 | return clang_getNullRange(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4432 | if (const ObjCCategoryDecl * |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4433 | CD = dyn_cast_or_null<ObjCCategoryDecl>(getCursorDecl(C))) |
| 4434 | return cxloc::translateSourceRange(Ctx, CD->getCategoryNameLoc()); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4435 | if (const ObjCCategoryImplDecl * |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4436 | CID = dyn_cast_or_null<ObjCCategoryImplDecl>(getCursorDecl(C))) |
| 4437 | return cxloc::translateSourceRange(Ctx, CID->getCategoryNameLoc()); |
| 4438 | } |
| 4439 | |
| 4440 | if (C.kind == CXCursor_ModuleImportDecl) { |
| 4441 | if (pieceIndex > 0) |
| 4442 | return clang_getNullRange(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4443 | if (const ImportDecl *ImportD = |
| 4444 | dyn_cast_or_null<ImportDecl>(getCursorDecl(C))) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4445 | ArrayRef<SourceLocation> Locs = ImportD->getIdentifierLocs(); |
| 4446 | if (!Locs.empty()) |
| 4447 | return cxloc::translateSourceRange(Ctx, |
| 4448 | SourceRange(Locs.front(), Locs.back())); |
| 4449 | } |
| 4450 | return clang_getNullRange(); |
| 4451 | } |
| 4452 | |
Argyrios Kyrtzidis | a2a1e53 | 2014-08-26 20:23:26 +0000 | [diff] [blame] | 4453 | if (C.kind == CXCursor_CXXMethod || C.kind == CXCursor_Destructor || |
Kevin Funk | 4be5d67 | 2016-12-20 09:56:56 +0000 | [diff] [blame] | 4454 | C.kind == CXCursor_ConversionFunction || |
| 4455 | C.kind == CXCursor_FunctionDecl) { |
Argyrios Kyrtzidis | a2a1e53 | 2014-08-26 20:23:26 +0000 | [diff] [blame] | 4456 | if (pieceIndex > 0) |
| 4457 | return clang_getNullRange(); |
| 4458 | if (const FunctionDecl *FD = |
| 4459 | dyn_cast_or_null<FunctionDecl>(getCursorDecl(C))) { |
| 4460 | DeclarationNameInfo FunctionName = FD->getNameInfo(); |
| 4461 | return cxloc::translateSourceRange(Ctx, FunctionName.getSourceRange()); |
| 4462 | } |
| 4463 | return clang_getNullRange(); |
| 4464 | } |
| 4465 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4466 | // FIXME: A CXCursor_InclusionDirective should give the location of the |
| 4467 | // filename, but we don't keep track of this. |
| 4468 | |
| 4469 | // FIXME: A CXCursor_AnnotateAttr should give the location of the annotation |
| 4470 | // but we don't keep track of this. |
| 4471 | |
| 4472 | // FIXME: A CXCursor_AsmLabelAttr should give the location of the label |
| 4473 | // but we don't keep track of this. |
| 4474 | |
| 4475 | // Default handling, give the location of the cursor. |
| 4476 | |
| 4477 | if (pieceIndex > 0) |
| 4478 | return clang_getNullRange(); |
| 4479 | |
| 4480 | CXSourceLocation CXLoc = clang_getCursorLocation(C); |
| 4481 | SourceLocation Loc = cxloc::translateSourceLocation(CXLoc); |
| 4482 | return cxloc::translateSourceRange(Ctx, Loc); |
| 4483 | } |
| 4484 | |
Eli Bendersky | 44a206f | 2014-07-31 18:04:56 +0000 | [diff] [blame] | 4485 | CXString clang_Cursor_getMangling(CXCursor C) { |
| 4486 | if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind)) |
| 4487 | return cxstring::createEmpty(); |
| 4488 | |
Eli Bendersky | 44a206f | 2014-07-31 18:04:56 +0000 | [diff] [blame] | 4489 | // Mangling only works for functions and variables. |
Eli Bendersky | 7975959 | 2014-08-01 15:01:10 +0000 | [diff] [blame] | 4490 | const Decl *D = getCursorDecl(C); |
Eli Bendersky | 44a206f | 2014-07-31 18:04:56 +0000 | [diff] [blame] | 4491 | if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D))) |
| 4492 | return cxstring::createEmpty(); |
| 4493 | |
Argyrios Kyrtzidis | ca741ce | 2016-02-14 22:30:14 +0000 | [diff] [blame] | 4494 | ASTContext &Ctx = D->getASTContext(); |
| 4495 | index::CodegenNameGenerator CGNameGen(Ctx); |
| 4496 | return cxstring::createDup(CGNameGen.getName(D)); |
Eli Bendersky | 44a206f | 2014-07-31 18:04:56 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
Saleem Abdulrasool | 6003443 | 2015-11-12 03:57:22 +0000 | [diff] [blame] | 4499 | CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) { |
| 4500 | if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind)) |
| 4501 | return nullptr; |
| 4502 | |
| 4503 | const Decl *D = getCursorDecl(C); |
| 4504 | if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D))) |
| 4505 | return nullptr; |
| 4506 | |
Argyrios Kyrtzidis | ca741ce | 2016-02-14 22:30:14 +0000 | [diff] [blame] | 4507 | ASTContext &Ctx = D->getASTContext(); |
| 4508 | index::CodegenNameGenerator CGNameGen(Ctx); |
| 4509 | std::vector<std::string> Manglings = CGNameGen.getAllManglings(D); |
Saleem Abdulrasool | 6003443 | 2015-11-12 03:57:22 +0000 | [diff] [blame] | 4510 | return cxstring::createSet(Manglings); |
| 4511 | } |
| 4512 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4513 | CXString clang_getCursorDisplayName(CXCursor C) { |
| 4514 | if (!clang_isDeclaration(C.kind)) |
| 4515 | return clang_getCursorSpelling(C); |
| 4516 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4517 | const Decl *D = getCursorDecl(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4518 | if (!D) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 4519 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4520 | |
| 4521 | PrintingPolicy Policy = getCursorContext(C).getPrintingPolicy(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4522 | if (const FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4523 | D = FunTmpl->getTemplatedDecl(); |
| 4524 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4525 | if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4526 | SmallString<64> Str; |
| 4527 | llvm::raw_svector_ostream OS(Str); |
| 4528 | OS << *Function; |
| 4529 | if (Function->getPrimaryTemplate()) |
| 4530 | OS << "<>"; |
| 4531 | OS << "("; |
| 4532 | for (unsigned I = 0, N = Function->getNumParams(); I != N; ++I) { |
| 4533 | if (I) |
| 4534 | OS << ", "; |
| 4535 | OS << Function->getParamDecl(I)->getType().getAsString(Policy); |
| 4536 | } |
| 4537 | |
| 4538 | if (Function->isVariadic()) { |
| 4539 | if (Function->getNumParams()) |
| 4540 | OS << ", "; |
| 4541 | OS << "..."; |
| 4542 | } |
| 4543 | OS << ")"; |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4544 | return cxstring::createDup(OS.str()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4545 | } |
| 4546 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4547 | if (const ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4548 | SmallString<64> Str; |
| 4549 | llvm::raw_svector_ostream OS(Str); |
| 4550 | OS << *ClassTemplate; |
| 4551 | OS << "<"; |
| 4552 | TemplateParameterList *Params = ClassTemplate->getTemplateParameters(); |
| 4553 | for (unsigned I = 0, N = Params->size(); I != N; ++I) { |
| 4554 | if (I) |
| 4555 | OS << ", "; |
| 4556 | |
| 4557 | NamedDecl *Param = Params->getParam(I); |
| 4558 | if (Param->getIdentifier()) { |
| 4559 | OS << Param->getIdentifier()->getName(); |
| 4560 | continue; |
| 4561 | } |
| 4562 | |
| 4563 | // There is no parameter name, which makes this tricky. Try to come up |
| 4564 | // with something useful that isn't too long. |
| 4565 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) |
| 4566 | OS << (TTP->wasDeclaredWithTypename()? "typename" : "class"); |
| 4567 | else if (NonTypeTemplateParmDecl *NTTP |
| 4568 | = dyn_cast<NonTypeTemplateParmDecl>(Param)) |
| 4569 | OS << NTTP->getType().getAsString(Policy); |
| 4570 | else |
| 4571 | OS << "template<...> class"; |
| 4572 | } |
| 4573 | |
| 4574 | OS << ">"; |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4575 | return cxstring::createDup(OS.str()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4576 | } |
| 4577 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 4578 | if (const ClassTemplateSpecializationDecl *ClassSpec |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4579 | = dyn_cast<ClassTemplateSpecializationDecl>(D)) { |
| 4580 | // If the type was explicitly written, use that. |
| 4581 | if (TypeSourceInfo *TSInfo = ClassSpec->getTypeAsWritten()) |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4582 | return cxstring::createDup(TSInfo->getType().getAsString(Policy)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4583 | |
Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 4584 | SmallString<128> Str; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4585 | llvm::raw_svector_ostream OS(Str); |
| 4586 | OS << *ClassSpec; |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 4587 | TemplateSpecializationType::PrintTemplateArgumentList( |
| 4588 | OS, ClassSpec->getTemplateArgs().asArray(), Policy); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 4589 | return cxstring::createDup(OS.str()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | return clang_getCursorSpelling(C); |
| 4593 | } |
| 4594 | |
| 4595 | CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { |
| 4596 | switch (Kind) { |
| 4597 | case CXCursor_FunctionDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4598 | return cxstring::createRef("FunctionDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4599 | case CXCursor_TypedefDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4600 | return cxstring::createRef("TypedefDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4601 | case CXCursor_EnumDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4602 | return cxstring::createRef("EnumDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4603 | case CXCursor_EnumConstantDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4604 | return cxstring::createRef("EnumConstantDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4605 | case CXCursor_StructDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4606 | return cxstring::createRef("StructDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4607 | case CXCursor_UnionDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4608 | return cxstring::createRef("UnionDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4609 | case CXCursor_ClassDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4610 | return cxstring::createRef("ClassDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4611 | case CXCursor_FieldDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4612 | return cxstring::createRef("FieldDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4613 | case CXCursor_VarDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4614 | return cxstring::createRef("VarDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4615 | case CXCursor_ParmDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4616 | return cxstring::createRef("ParmDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4617 | case CXCursor_ObjCInterfaceDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4618 | return cxstring::createRef("ObjCInterfaceDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4619 | case CXCursor_ObjCCategoryDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4620 | return cxstring::createRef("ObjCCategoryDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4621 | case CXCursor_ObjCProtocolDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4622 | return cxstring::createRef("ObjCProtocolDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4623 | case CXCursor_ObjCPropertyDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4624 | return cxstring::createRef("ObjCPropertyDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4625 | case CXCursor_ObjCIvarDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4626 | return cxstring::createRef("ObjCIvarDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4627 | case CXCursor_ObjCInstanceMethodDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4628 | return cxstring::createRef("ObjCInstanceMethodDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4629 | case CXCursor_ObjCClassMethodDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4630 | return cxstring::createRef("ObjCClassMethodDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4631 | case CXCursor_ObjCImplementationDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4632 | return cxstring::createRef("ObjCImplementationDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4633 | case CXCursor_ObjCCategoryImplDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4634 | return cxstring::createRef("ObjCCategoryImplDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4635 | case CXCursor_CXXMethod: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4636 | return cxstring::createRef("CXXMethod"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4637 | case CXCursor_UnexposedDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4638 | return cxstring::createRef("UnexposedDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4639 | case CXCursor_ObjCSuperClassRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4640 | return cxstring::createRef("ObjCSuperClassRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4641 | case CXCursor_ObjCProtocolRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4642 | return cxstring::createRef("ObjCProtocolRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4643 | case CXCursor_ObjCClassRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4644 | return cxstring::createRef("ObjCClassRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4645 | case CXCursor_TypeRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4646 | return cxstring::createRef("TypeRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4647 | case CXCursor_TemplateRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4648 | return cxstring::createRef("TemplateRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4649 | case CXCursor_NamespaceRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4650 | return cxstring::createRef("NamespaceRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4651 | case CXCursor_MemberRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4652 | return cxstring::createRef("MemberRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4653 | case CXCursor_LabelRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4654 | return cxstring::createRef("LabelRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4655 | case CXCursor_OverloadedDeclRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4656 | return cxstring::createRef("OverloadedDeclRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4657 | case CXCursor_VariableRef: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4658 | return cxstring::createRef("VariableRef"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4659 | case CXCursor_IntegerLiteral: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4660 | return cxstring::createRef("IntegerLiteral"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4661 | case CXCursor_FloatingLiteral: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4662 | return cxstring::createRef("FloatingLiteral"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4663 | case CXCursor_ImaginaryLiteral: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4664 | return cxstring::createRef("ImaginaryLiteral"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4665 | case CXCursor_StringLiteral: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4666 | return cxstring::createRef("StringLiteral"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4667 | case CXCursor_CharacterLiteral: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4668 | return cxstring::createRef("CharacterLiteral"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4669 | case CXCursor_ParenExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4670 | return cxstring::createRef("ParenExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4671 | case CXCursor_UnaryOperator: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4672 | return cxstring::createRef("UnaryOperator"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4673 | case CXCursor_ArraySubscriptExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4674 | return cxstring::createRef("ArraySubscriptExpr"); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 4675 | case CXCursor_OMPArraySectionExpr: |
| 4676 | return cxstring::createRef("OMPArraySectionExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4677 | case CXCursor_BinaryOperator: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4678 | return cxstring::createRef("BinaryOperator"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4679 | case CXCursor_CompoundAssignOperator: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4680 | return cxstring::createRef("CompoundAssignOperator"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4681 | case CXCursor_ConditionalOperator: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4682 | return cxstring::createRef("ConditionalOperator"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4683 | case CXCursor_CStyleCastExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4684 | return cxstring::createRef("CStyleCastExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4685 | case CXCursor_CompoundLiteralExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4686 | return cxstring::createRef("CompoundLiteralExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4687 | case CXCursor_InitListExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4688 | return cxstring::createRef("InitListExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4689 | case CXCursor_AddrLabelExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4690 | return cxstring::createRef("AddrLabelExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4691 | case CXCursor_StmtExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4692 | return cxstring::createRef("StmtExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4693 | case CXCursor_GenericSelectionExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4694 | return cxstring::createRef("GenericSelectionExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4695 | case CXCursor_GNUNullExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4696 | return cxstring::createRef("GNUNullExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4697 | case CXCursor_CXXStaticCastExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4698 | return cxstring::createRef("CXXStaticCastExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4699 | case CXCursor_CXXDynamicCastExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4700 | return cxstring::createRef("CXXDynamicCastExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4701 | case CXCursor_CXXReinterpretCastExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4702 | return cxstring::createRef("CXXReinterpretCastExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4703 | case CXCursor_CXXConstCastExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4704 | return cxstring::createRef("CXXConstCastExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4705 | case CXCursor_CXXFunctionalCastExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4706 | return cxstring::createRef("CXXFunctionalCastExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4707 | case CXCursor_CXXTypeidExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4708 | return cxstring::createRef("CXXTypeidExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4709 | case CXCursor_CXXBoolLiteralExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4710 | return cxstring::createRef("CXXBoolLiteralExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4711 | case CXCursor_CXXNullPtrLiteralExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4712 | return cxstring::createRef("CXXNullPtrLiteralExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4713 | case CXCursor_CXXThisExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4714 | return cxstring::createRef("CXXThisExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4715 | case CXCursor_CXXThrowExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4716 | return cxstring::createRef("CXXThrowExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4717 | case CXCursor_CXXNewExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4718 | return cxstring::createRef("CXXNewExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4719 | case CXCursor_CXXDeleteExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4720 | return cxstring::createRef("CXXDeleteExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4721 | case CXCursor_UnaryExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4722 | return cxstring::createRef("UnaryExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4723 | case CXCursor_ObjCStringLiteral: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4724 | return cxstring::createRef("ObjCStringLiteral"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4725 | case CXCursor_ObjCBoolLiteralExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4726 | return cxstring::createRef("ObjCBoolLiteralExpr"); |
Erik Pilkington | 29099de | 2016-07-16 00:35:23 +0000 | [diff] [blame] | 4727 | case CXCursor_ObjCAvailabilityCheckExpr: |
| 4728 | return cxstring::createRef("ObjCAvailabilityCheckExpr"); |
Argyrios Kyrtzidis | c2233be | 2013-04-23 17:57:17 +0000 | [diff] [blame] | 4729 | case CXCursor_ObjCSelfExpr: |
| 4730 | return cxstring::createRef("ObjCSelfExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4731 | case CXCursor_ObjCEncodeExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4732 | return cxstring::createRef("ObjCEncodeExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4733 | case CXCursor_ObjCSelectorExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4734 | return cxstring::createRef("ObjCSelectorExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4735 | case CXCursor_ObjCProtocolExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4736 | return cxstring::createRef("ObjCProtocolExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4737 | case CXCursor_ObjCBridgedCastExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4738 | return cxstring::createRef("ObjCBridgedCastExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4739 | case CXCursor_BlockExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4740 | return cxstring::createRef("BlockExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4741 | case CXCursor_PackExpansionExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4742 | return cxstring::createRef("PackExpansionExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4743 | case CXCursor_SizeOfPackExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4744 | return cxstring::createRef("SizeOfPackExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4745 | case CXCursor_LambdaExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4746 | return cxstring::createRef("LambdaExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4747 | case CXCursor_UnexposedExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4748 | return cxstring::createRef("UnexposedExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4749 | case CXCursor_DeclRefExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4750 | return cxstring::createRef("DeclRefExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4751 | case CXCursor_MemberRefExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4752 | return cxstring::createRef("MemberRefExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4753 | case CXCursor_CallExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4754 | return cxstring::createRef("CallExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4755 | case CXCursor_ObjCMessageExpr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4756 | return cxstring::createRef("ObjCMessageExpr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4757 | case CXCursor_UnexposedStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4758 | return cxstring::createRef("UnexposedStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4759 | case CXCursor_DeclStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4760 | return cxstring::createRef("DeclStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4761 | case CXCursor_LabelStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4762 | return cxstring::createRef("LabelStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4763 | case CXCursor_CompoundStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4764 | return cxstring::createRef("CompoundStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4765 | case CXCursor_CaseStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4766 | return cxstring::createRef("CaseStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4767 | case CXCursor_DefaultStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4768 | return cxstring::createRef("DefaultStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4769 | case CXCursor_IfStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4770 | return cxstring::createRef("IfStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4771 | case CXCursor_SwitchStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4772 | return cxstring::createRef("SwitchStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4773 | case CXCursor_WhileStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4774 | return cxstring::createRef("WhileStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4775 | case CXCursor_DoStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4776 | return cxstring::createRef("DoStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4777 | case CXCursor_ForStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4778 | return cxstring::createRef("ForStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4779 | case CXCursor_GotoStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4780 | return cxstring::createRef("GotoStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4781 | case CXCursor_IndirectGotoStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4782 | return cxstring::createRef("IndirectGotoStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4783 | case CXCursor_ContinueStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4784 | return cxstring::createRef("ContinueStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4785 | case CXCursor_BreakStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4786 | return cxstring::createRef("BreakStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4787 | case CXCursor_ReturnStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4788 | return cxstring::createRef("ReturnStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4789 | case CXCursor_GCCAsmStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4790 | return cxstring::createRef("GCCAsmStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4791 | case CXCursor_MSAsmStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4792 | return cxstring::createRef("MSAsmStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4793 | case CXCursor_ObjCAtTryStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4794 | return cxstring::createRef("ObjCAtTryStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4795 | case CXCursor_ObjCAtCatchStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4796 | return cxstring::createRef("ObjCAtCatchStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4797 | case CXCursor_ObjCAtFinallyStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4798 | return cxstring::createRef("ObjCAtFinallyStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4799 | case CXCursor_ObjCAtThrowStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4800 | return cxstring::createRef("ObjCAtThrowStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4801 | case CXCursor_ObjCAtSynchronizedStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4802 | return cxstring::createRef("ObjCAtSynchronizedStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4803 | case CXCursor_ObjCAutoreleasePoolStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4804 | return cxstring::createRef("ObjCAutoreleasePoolStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4805 | case CXCursor_ObjCForCollectionStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4806 | return cxstring::createRef("ObjCForCollectionStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4807 | case CXCursor_CXXCatchStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4808 | return cxstring::createRef("CXXCatchStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4809 | case CXCursor_CXXTryStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4810 | return cxstring::createRef("CXXTryStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4811 | case CXCursor_CXXForRangeStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4812 | return cxstring::createRef("CXXForRangeStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4813 | case CXCursor_SEHTryStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4814 | return cxstring::createRef("SEHTryStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4815 | case CXCursor_SEHExceptStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4816 | return cxstring::createRef("SEHExceptStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4817 | case CXCursor_SEHFinallyStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4818 | return cxstring::createRef("SEHFinallyStmt"); |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 4819 | case CXCursor_SEHLeaveStmt: |
| 4820 | return cxstring::createRef("SEHLeaveStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4821 | case CXCursor_NullStmt: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4822 | return cxstring::createRef("NullStmt"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4823 | case CXCursor_InvalidFile: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4824 | return cxstring::createRef("InvalidFile"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4825 | case CXCursor_InvalidCode: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4826 | return cxstring::createRef("InvalidCode"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4827 | case CXCursor_NoDeclFound: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4828 | return cxstring::createRef("NoDeclFound"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4829 | case CXCursor_NotImplemented: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4830 | return cxstring::createRef("NotImplemented"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4831 | case CXCursor_TranslationUnit: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4832 | return cxstring::createRef("TranslationUnit"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4833 | case CXCursor_UnexposedAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4834 | return cxstring::createRef("UnexposedAttr"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4835 | case CXCursor_IBActionAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4836 | return cxstring::createRef("attribute(ibaction)"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4837 | case CXCursor_IBOutletAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4838 | return cxstring::createRef("attribute(iboutlet)"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4839 | case CXCursor_IBOutletCollectionAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4840 | return cxstring::createRef("attribute(iboutletcollection)"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4841 | case CXCursor_CXXFinalAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4842 | return cxstring::createRef("attribute(final)"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4843 | case CXCursor_CXXOverrideAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4844 | return cxstring::createRef("attribute(override)"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4845 | case CXCursor_AnnotateAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4846 | return cxstring::createRef("attribute(annotate)"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4847 | case CXCursor_AsmLabelAttr: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4848 | return cxstring::createRef("asm label"); |
Argyrios Kyrtzidis | 16834f1 | 2013-09-25 00:14:38 +0000 | [diff] [blame] | 4849 | case CXCursor_PackedAttr: |
| 4850 | return cxstring::createRef("attribute(packed)"); |
Joey Gouly | 8122838 | 2014-05-01 15:41:58 +0000 | [diff] [blame] | 4851 | case CXCursor_PureAttr: |
| 4852 | return cxstring::createRef("attribute(pure)"); |
| 4853 | case CXCursor_ConstAttr: |
| 4854 | return cxstring::createRef("attribute(const)"); |
| 4855 | case CXCursor_NoDuplicateAttr: |
| 4856 | return cxstring::createRef("attribute(noduplicate)"); |
Eli Bendersky | 2581e66 | 2014-05-28 19:29:58 +0000 | [diff] [blame] | 4857 | case CXCursor_CUDAConstantAttr: |
| 4858 | return cxstring::createRef("attribute(constant)"); |
| 4859 | case CXCursor_CUDADeviceAttr: |
| 4860 | return cxstring::createRef("attribute(device)"); |
| 4861 | case CXCursor_CUDAGlobalAttr: |
| 4862 | return cxstring::createRef("attribute(global)"); |
| 4863 | case CXCursor_CUDAHostAttr: |
| 4864 | return cxstring::createRef("attribute(host)"); |
Eli Bendersky | 9b07147 | 2014-08-08 14:59:00 +0000 | [diff] [blame] | 4865 | case CXCursor_CUDASharedAttr: |
| 4866 | return cxstring::createRef("attribute(shared)"); |
Saleem Abdulrasool | 79c6971 | 2015-09-05 18:53:43 +0000 | [diff] [blame] | 4867 | case CXCursor_VisibilityAttr: |
| 4868 | return cxstring::createRef("attribute(visibility)"); |
Saleem Abdulrasool | 8aa0b80 | 2015-12-10 18:45:18 +0000 | [diff] [blame] | 4869 | case CXCursor_DLLExport: |
| 4870 | return cxstring::createRef("attribute(dllexport)"); |
| 4871 | case CXCursor_DLLImport: |
| 4872 | return cxstring::createRef("attribute(dllimport)"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4873 | case CXCursor_PreprocessingDirective: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4874 | return cxstring::createRef("preprocessing directive"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4875 | case CXCursor_MacroDefinition: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4876 | return cxstring::createRef("macro definition"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4877 | case CXCursor_MacroExpansion: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4878 | return cxstring::createRef("macro expansion"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4879 | case CXCursor_InclusionDirective: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4880 | return cxstring::createRef("inclusion directive"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4881 | case CXCursor_Namespace: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4882 | return cxstring::createRef("Namespace"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4883 | case CXCursor_LinkageSpec: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4884 | return cxstring::createRef("LinkageSpec"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4885 | case CXCursor_CXXBaseSpecifier: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4886 | return cxstring::createRef("C++ base class specifier"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4887 | case CXCursor_Constructor: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4888 | return cxstring::createRef("CXXConstructor"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4889 | case CXCursor_Destructor: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4890 | return cxstring::createRef("CXXDestructor"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4891 | case CXCursor_ConversionFunction: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4892 | return cxstring::createRef("CXXConversion"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4893 | case CXCursor_TemplateTypeParameter: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4894 | return cxstring::createRef("TemplateTypeParameter"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4895 | case CXCursor_NonTypeTemplateParameter: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4896 | return cxstring::createRef("NonTypeTemplateParameter"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4897 | case CXCursor_TemplateTemplateParameter: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4898 | return cxstring::createRef("TemplateTemplateParameter"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4899 | case CXCursor_FunctionTemplate: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4900 | return cxstring::createRef("FunctionTemplate"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4901 | case CXCursor_ClassTemplate: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4902 | return cxstring::createRef("ClassTemplate"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4903 | case CXCursor_ClassTemplatePartialSpecialization: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4904 | return cxstring::createRef("ClassTemplatePartialSpecialization"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4905 | case CXCursor_NamespaceAlias: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4906 | return cxstring::createRef("NamespaceAlias"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4907 | case CXCursor_UsingDirective: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4908 | return cxstring::createRef("UsingDirective"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4909 | case CXCursor_UsingDeclaration: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4910 | return cxstring::createRef("UsingDeclaration"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4911 | case CXCursor_TypeAliasDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4912 | return cxstring::createRef("TypeAliasDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4913 | case CXCursor_ObjCSynthesizeDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4914 | return cxstring::createRef("ObjCSynthesizeDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4915 | case CXCursor_ObjCDynamicDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4916 | return cxstring::createRef("ObjCDynamicDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4917 | case CXCursor_CXXAccessSpecifier: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4918 | return cxstring::createRef("CXXAccessSpecifier"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4919 | case CXCursor_ModuleImportDecl: |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 4920 | return cxstring::createRef("ModuleImport"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4921 | case CXCursor_OMPParallelDirective: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4922 | return cxstring::createRef("OMPParallelDirective"); |
| 4923 | case CXCursor_OMPSimdDirective: |
| 4924 | return cxstring::createRef("OMPSimdDirective"); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4925 | case CXCursor_OMPForDirective: |
| 4926 | return cxstring::createRef("OMPForDirective"); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4927 | case CXCursor_OMPForSimdDirective: |
| 4928 | return cxstring::createRef("OMPForSimdDirective"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4929 | case CXCursor_OMPSectionsDirective: |
| 4930 | return cxstring::createRef("OMPSectionsDirective"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4931 | case CXCursor_OMPSectionDirective: |
| 4932 | return cxstring::createRef("OMPSectionDirective"); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4933 | case CXCursor_OMPSingleDirective: |
| 4934 | return cxstring::createRef("OMPSingleDirective"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4935 | case CXCursor_OMPMasterDirective: |
| 4936 | return cxstring::createRef("OMPMasterDirective"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4937 | case CXCursor_OMPCriticalDirective: |
| 4938 | return cxstring::createRef("OMPCriticalDirective"); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4939 | case CXCursor_OMPParallelForDirective: |
| 4940 | return cxstring::createRef("OMPParallelForDirective"); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4941 | case CXCursor_OMPParallelForSimdDirective: |
| 4942 | return cxstring::createRef("OMPParallelForSimdDirective"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4943 | case CXCursor_OMPParallelSectionsDirective: |
| 4944 | return cxstring::createRef("OMPParallelSectionsDirective"); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4945 | case CXCursor_OMPTaskDirective: |
| 4946 | return cxstring::createRef("OMPTaskDirective"); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4947 | case CXCursor_OMPTaskyieldDirective: |
| 4948 | return cxstring::createRef("OMPTaskyieldDirective"); |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4949 | case CXCursor_OMPBarrierDirective: |
| 4950 | return cxstring::createRef("OMPBarrierDirective"); |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4951 | case CXCursor_OMPTaskwaitDirective: |
| 4952 | return cxstring::createRef("OMPTaskwaitDirective"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4953 | case CXCursor_OMPTaskgroupDirective: |
| 4954 | return cxstring::createRef("OMPTaskgroupDirective"); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4955 | case CXCursor_OMPFlushDirective: |
| 4956 | return cxstring::createRef("OMPFlushDirective"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4957 | case CXCursor_OMPOrderedDirective: |
| 4958 | return cxstring::createRef("OMPOrderedDirective"); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4959 | case CXCursor_OMPAtomicDirective: |
| 4960 | return cxstring::createRef("OMPAtomicDirective"); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4961 | case CXCursor_OMPTargetDirective: |
| 4962 | return cxstring::createRef("OMPTargetDirective"); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4963 | case CXCursor_OMPTargetDataDirective: |
| 4964 | return cxstring::createRef("OMPTargetDataDirective"); |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 4965 | case CXCursor_OMPTargetEnterDataDirective: |
| 4966 | return cxstring::createRef("OMPTargetEnterDataDirective"); |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 4967 | case CXCursor_OMPTargetExitDataDirective: |
| 4968 | return cxstring::createRef("OMPTargetExitDataDirective"); |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 4969 | case CXCursor_OMPTargetParallelDirective: |
| 4970 | return cxstring::createRef("OMPTargetParallelDirective"); |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 4971 | case CXCursor_OMPTargetParallelForDirective: |
| 4972 | return cxstring::createRef("OMPTargetParallelForDirective"); |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 4973 | case CXCursor_OMPTargetUpdateDirective: |
| 4974 | return cxstring::createRef("OMPTargetUpdateDirective"); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4975 | case CXCursor_OMPTeamsDirective: |
| 4976 | return cxstring::createRef("OMPTeamsDirective"); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4977 | case CXCursor_OMPCancellationPointDirective: |
| 4978 | return cxstring::createRef("OMPCancellationPointDirective"); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4979 | case CXCursor_OMPCancelDirective: |
| 4980 | return cxstring::createRef("OMPCancelDirective"); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 4981 | case CXCursor_OMPTaskLoopDirective: |
| 4982 | return cxstring::createRef("OMPTaskLoopDirective"); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 4983 | case CXCursor_OMPTaskLoopSimdDirective: |
| 4984 | return cxstring::createRef("OMPTaskLoopSimdDirective"); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4985 | case CXCursor_OMPDistributeDirective: |
| 4986 | return cxstring::createRef("OMPDistributeDirective"); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4987 | case CXCursor_OMPDistributeParallelForDirective: |
| 4988 | return cxstring::createRef("OMPDistributeParallelForDirective"); |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 4989 | case CXCursor_OMPDistributeParallelForSimdDirective: |
| 4990 | return cxstring::createRef("OMPDistributeParallelForSimdDirective"); |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 4991 | case CXCursor_OMPDistributeSimdDirective: |
| 4992 | return cxstring::createRef("OMPDistributeSimdDirective"); |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 4993 | case CXCursor_OMPTargetParallelForSimdDirective: |
| 4994 | return cxstring::createRef("OMPTargetParallelForSimdDirective"); |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 4995 | case CXCursor_OMPTargetSimdDirective: |
| 4996 | return cxstring::createRef("OMPTargetSimdDirective"); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 4997 | case CXCursor_OMPTeamsDistributeDirective: |
| 4998 | return cxstring::createRef("OMPTeamsDistributeDirective"); |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 4999 | case CXCursor_OMPTeamsDistributeSimdDirective: |
| 5000 | return cxstring::createRef("OMPTeamsDistributeSimdDirective"); |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 5001 | case CXCursor_OMPTeamsDistributeParallelForSimdDirective: |
| 5002 | return cxstring::createRef("OMPTeamsDistributeParallelForSimdDirective"); |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 5003 | case CXCursor_OMPTeamsDistributeParallelForDirective: |
| 5004 | return cxstring::createRef("OMPTeamsDistributeParallelForDirective"); |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 5005 | case CXCursor_OMPTargetTeamsDirective: |
| 5006 | return cxstring::createRef("OMPTargetTeamsDirective"); |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 5007 | case CXCursor_OMPTargetTeamsDistributeDirective: |
| 5008 | return cxstring::createRef("OMPTargetTeamsDistributeDirective"); |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 5009 | case CXCursor_OMPTargetTeamsDistributeParallelForDirective: |
| 5010 | return cxstring::createRef("OMPTargetTeamsDistributeParallelForDirective"); |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 5011 | case CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective: |
| 5012 | return cxstring::createRef( |
| 5013 | "OMPTargetTeamsDistributeParallelForSimdDirective"); |
Francisco Lopes da Silva | 975a9f6 | 2015-01-21 16:24:11 +0000 | [diff] [blame] | 5014 | case CXCursor_OverloadCandidate: |
| 5015 | return cxstring::createRef("OverloadCandidate"); |
Sergey Kalinichev | 8f3b187 | 2015-11-15 13:48:32 +0000 | [diff] [blame] | 5016 | case CXCursor_TypeAliasTemplateDecl: |
| 5017 | return cxstring::createRef("TypeAliasTemplateDecl"); |
Olivier Goffart | 8197801 | 2016-06-09 16:15:55 +0000 | [diff] [blame] | 5018 | case CXCursor_StaticAssert: |
| 5019 | return cxstring::createRef("StaticAssert"); |
Olivier Goffart | d211c64 | 2016-11-04 06:29:27 +0000 | [diff] [blame] | 5020 | case CXCursor_FriendDecl: |
| 5021 | return cxstring::createRef("FriendDecl"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | llvm_unreachable("Unhandled CXCursorKind"); |
| 5025 | } |
| 5026 | |
| 5027 | struct GetCursorData { |
| 5028 | SourceLocation TokenBeginLoc; |
| 5029 | bool PointsAtMacroArgExpansion; |
| 5030 | bool VisitedObjCPropertyImplDecl; |
| 5031 | SourceLocation VisitedDeclaratorDeclStartLoc; |
| 5032 | CXCursor &BestCursor; |
| 5033 | |
| 5034 | GetCursorData(SourceManager &SM, |
| 5035 | SourceLocation tokenBegin, CXCursor &outputCursor) |
| 5036 | : TokenBeginLoc(tokenBegin), BestCursor(outputCursor) { |
| 5037 | PointsAtMacroArgExpansion = SM.isMacroArgExpansion(tokenBegin); |
| 5038 | VisitedObjCPropertyImplDecl = false; |
| 5039 | } |
| 5040 | }; |
| 5041 | |
| 5042 | static enum CXChildVisitResult GetCursorVisitor(CXCursor cursor, |
| 5043 | CXCursor parent, |
| 5044 | CXClientData client_data) { |
| 5045 | GetCursorData *Data = static_cast<GetCursorData *>(client_data); |
| 5046 | CXCursor *BestCursor = &Data->BestCursor; |
| 5047 | |
| 5048 | // If we point inside a macro argument we should provide info of what the |
| 5049 | // token is so use the actual cursor, don't replace it with a macro expansion |
| 5050 | // cursor. |
| 5051 | if (cursor.kind == CXCursor_MacroExpansion && Data->PointsAtMacroArgExpansion) |
| 5052 | return CXChildVisit_Recurse; |
| 5053 | |
| 5054 | if (clang_isDeclaration(cursor.kind)) { |
| 5055 | // Avoid having the implicit methods override the property decls. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5056 | if (const ObjCMethodDecl *MD |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5057 | = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor))) { |
| 5058 | if (MD->isImplicit()) |
| 5059 | return CXChildVisit_Break; |
| 5060 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5061 | } else if (const ObjCInterfaceDecl *ID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5062 | = dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(cursor))) { |
| 5063 | // Check that when we have multiple @class references in the same line, |
| 5064 | // that later ones do not override the previous ones. |
| 5065 | // If we have: |
| 5066 | // @class Foo, Bar; |
| 5067 | // source ranges for both start at '@', so 'Bar' will end up overriding |
| 5068 | // 'Foo' even though the cursor location was at 'Foo'. |
| 5069 | if (BestCursor->kind == CXCursor_ObjCInterfaceDecl || |
| 5070 | BestCursor->kind == CXCursor_ObjCClassRef) |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5071 | if (const ObjCInterfaceDecl *PrevID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5072 | = dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(*BestCursor))){ |
| 5073 | if (PrevID != ID && |
| 5074 | !PrevID->isThisDeclarationADefinition() && |
| 5075 | !ID->isThisDeclarationADefinition()) |
| 5076 | return CXChildVisit_Break; |
| 5077 | } |
| 5078 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5079 | } else if (const DeclaratorDecl *DD |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5080 | = dyn_cast_or_null<DeclaratorDecl>(getCursorDecl(cursor))) { |
| 5081 | SourceLocation StartLoc = DD->getSourceRange().getBegin(); |
| 5082 | // Check that when we have multiple declarators in the same line, |
| 5083 | // that later ones do not override the previous ones. |
| 5084 | // If we have: |
| 5085 | // int Foo, Bar; |
| 5086 | // source ranges for both start at 'int', so 'Bar' will end up overriding |
| 5087 | // 'Foo' even though the cursor location was at 'Foo'. |
| 5088 | if (Data->VisitedDeclaratorDeclStartLoc == StartLoc) |
| 5089 | return CXChildVisit_Break; |
| 5090 | Data->VisitedDeclaratorDeclStartLoc = StartLoc; |
| 5091 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5092 | } else if (const ObjCPropertyImplDecl *PropImp |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5093 | = dyn_cast_or_null<ObjCPropertyImplDecl>(getCursorDecl(cursor))) { |
| 5094 | (void)PropImp; |
| 5095 | // Check that when we have multiple @synthesize in the same line, |
| 5096 | // that later ones do not override the previous ones. |
| 5097 | // If we have: |
| 5098 | // @synthesize Foo, Bar; |
| 5099 | // source ranges for both start at '@', so 'Bar' will end up overriding |
| 5100 | // 'Foo' even though the cursor location was at 'Foo'. |
| 5101 | if (Data->VisitedObjCPropertyImplDecl) |
| 5102 | return CXChildVisit_Break; |
| 5103 | Data->VisitedObjCPropertyImplDecl = true; |
| 5104 | } |
| 5105 | } |
| 5106 | |
| 5107 | if (clang_isExpression(cursor.kind) && |
| 5108 | clang_isDeclaration(BestCursor->kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5109 | if (const Decl *D = getCursorDecl(*BestCursor)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5110 | // Avoid having the cursor of an expression replace the declaration cursor |
| 5111 | // when the expression source range overlaps the declaration range. |
| 5112 | // This can happen for C++ constructor expressions whose range generally |
| 5113 | // include the variable declaration, e.g.: |
| 5114 | // MyCXXClass foo; // Make sure pointing at 'foo' returns a VarDecl cursor. |
| 5115 | if (D->getLocation().isValid() && Data->TokenBeginLoc.isValid() && |
| 5116 | D->getLocation() == Data->TokenBeginLoc) |
| 5117 | return CXChildVisit_Break; |
| 5118 | } |
| 5119 | } |
| 5120 | |
| 5121 | // If our current best cursor is the construction of a temporary object, |
| 5122 | // don't replace that cursor with a type reference, because we want |
| 5123 | // clang_getCursor() to point at the constructor. |
| 5124 | if (clang_isExpression(BestCursor->kind) && |
| 5125 | isa<CXXTemporaryObjectExpr>(getCursorExpr(*BestCursor)) && |
| 5126 | cursor.kind == CXCursor_TypeRef) { |
| 5127 | // Keep the cursor pointing at CXXTemporaryObjectExpr but also mark it |
| 5128 | // as having the actual point on the type reference. |
| 5129 | *BestCursor = getTypeRefedCallExprCursor(*BestCursor); |
| 5130 | return CXChildVisit_Recurse; |
| 5131 | } |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 5132 | |
| 5133 | // If we already have an Objective-C superclass reference, don't |
| 5134 | // update it further. |
| 5135 | if (BestCursor->kind == CXCursor_ObjCSuperClassRef) |
| 5136 | return CXChildVisit_Break; |
| 5137 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5138 | *BestCursor = cursor; |
| 5139 | return CXChildVisit_Recurse; |
| 5140 | } |
| 5141 | |
| 5142 | CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 5143 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 5144 | LOG_BAD_TU(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5145 | return clang_getNullCursor(); |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 5146 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5147 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 5148 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5149 | ASTUnit::ConcurrencyCheck Check(*CXXUnit); |
| 5150 | |
| 5151 | SourceLocation SLoc = cxloc::translateSourceLocation(Loc); |
| 5152 | CXCursor Result = cxcursor::getCursor(TU, SLoc); |
| 5153 | |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 5154 | LOG_FUNC_SECTION { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5155 | CXFile SearchFile; |
| 5156 | unsigned SearchLine, SearchColumn; |
| 5157 | CXFile ResultFile; |
| 5158 | unsigned ResultLine, ResultColumn; |
| 5159 | CXString SearchFileName, ResultFileName, KindSpelling, USR; |
| 5160 | const char *IsDef = clang_isCursorDefinition(Result)? " (Definition)" : ""; |
| 5161 | CXSourceLocation ResultLoc = clang_getCursorLocation(Result); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 5162 | |
| 5163 | clang_getFileLocation(Loc, &SearchFile, &SearchLine, &SearchColumn, |
| 5164 | nullptr); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 5165 | clang_getFileLocation(ResultLoc, &ResultFile, &ResultLine, |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 5166 | &ResultColumn, nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5167 | SearchFileName = clang_getFileName(SearchFile); |
| 5168 | ResultFileName = clang_getFileName(ResultFile); |
| 5169 | KindSpelling = clang_getCursorKindSpelling(Result.kind); |
| 5170 | USR = clang_getCursorUSR(Result); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 5171 | *Log << llvm::format("(%s:%d:%d) = %s", |
| 5172 | clang_getCString(SearchFileName), SearchLine, SearchColumn, |
| 5173 | clang_getCString(KindSpelling)) |
| 5174 | << llvm::format("(%s:%d:%d):%s%s", |
| 5175 | clang_getCString(ResultFileName), ResultLine, ResultColumn, |
| 5176 | clang_getCString(USR), IsDef); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5177 | clang_disposeString(SearchFileName); |
| 5178 | clang_disposeString(ResultFileName); |
| 5179 | clang_disposeString(KindSpelling); |
| 5180 | clang_disposeString(USR); |
| 5181 | |
| 5182 | CXCursor Definition = clang_getCursorDefinition(Result); |
| 5183 | if (!clang_equalCursors(Definition, clang_getNullCursor())) { |
| 5184 | CXSourceLocation DefinitionLoc = clang_getCursorLocation(Definition); |
| 5185 | CXString DefinitionKindSpelling |
| 5186 | = clang_getCursorKindSpelling(Definition.kind); |
| 5187 | CXFile DefinitionFile; |
| 5188 | unsigned DefinitionLine, DefinitionColumn; |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 5189 | clang_getFileLocation(DefinitionLoc, &DefinitionFile, |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 5190 | &DefinitionLine, &DefinitionColumn, nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5191 | CXString DefinitionFileName = clang_getFileName(DefinitionFile); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 5192 | *Log << llvm::format(" -> %s(%s:%d:%d)", |
| 5193 | clang_getCString(DefinitionKindSpelling), |
| 5194 | clang_getCString(DefinitionFileName), |
| 5195 | DefinitionLine, DefinitionColumn); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5196 | clang_disposeString(DefinitionFileName); |
| 5197 | clang_disposeString(DefinitionKindSpelling); |
| 5198 | } |
| 5199 | } |
| 5200 | |
| 5201 | return Result; |
| 5202 | } |
| 5203 | |
| 5204 | CXCursor clang_getNullCursor(void) { |
| 5205 | return MakeCXCursorInvalid(CXCursor_InvalidFile); |
| 5206 | } |
| 5207 | |
| 5208 | unsigned clang_equalCursors(CXCursor X, CXCursor Y) { |
Argyrios Kyrtzidis | bf1be59 | 2013-01-08 18:23:28 +0000 | [diff] [blame] | 5209 | // Clear out the "FirstInDeclGroup" part in a declaration cursor, since we |
| 5210 | // can't set consistently. For example, when visiting a DeclStmt we will set |
| 5211 | // it but we don't set it on the result of clang_getCursorDefinition for |
| 5212 | // a reference of the same declaration. |
| 5213 | // FIXME: Setting "FirstInDeclGroup" in CXCursors is a hack that only works |
| 5214 | // when visiting a DeclStmt currently, the AST should be enhanced to be able |
| 5215 | // to provide that kind of info. |
| 5216 | if (clang_isDeclaration(X.kind)) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 5217 | X.data[1] = nullptr; |
Argyrios Kyrtzidis | bf1be59 | 2013-01-08 18:23:28 +0000 | [diff] [blame] | 5218 | if (clang_isDeclaration(Y.kind)) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 5219 | Y.data[1] = nullptr; |
Argyrios Kyrtzidis | bf1be59 | 2013-01-08 18:23:28 +0000 | [diff] [blame] | 5220 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5221 | return X == Y; |
| 5222 | } |
| 5223 | |
| 5224 | unsigned clang_hashCursor(CXCursor C) { |
| 5225 | unsigned Index = 0; |
| 5226 | if (clang_isExpression(C.kind) || clang_isStatement(C.kind)) |
| 5227 | Index = 1; |
| 5228 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5229 | return llvm::DenseMapInfo<std::pair<unsigned, const void*> >::getHashValue( |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5230 | std::make_pair(C.kind, C.data[Index])); |
| 5231 | } |
| 5232 | |
| 5233 | unsigned clang_isInvalid(enum CXCursorKind K) { |
| 5234 | return K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid; |
| 5235 | } |
| 5236 | |
| 5237 | unsigned clang_isDeclaration(enum CXCursorKind K) { |
| 5238 | return (K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl) || |
| 5239 | (K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl); |
| 5240 | } |
| 5241 | |
| 5242 | unsigned clang_isReference(enum CXCursorKind K) { |
| 5243 | return K >= CXCursor_FirstRef && K <= CXCursor_LastRef; |
| 5244 | } |
| 5245 | |
| 5246 | unsigned clang_isExpression(enum CXCursorKind K) { |
| 5247 | return K >= CXCursor_FirstExpr && K <= CXCursor_LastExpr; |
| 5248 | } |
| 5249 | |
| 5250 | unsigned clang_isStatement(enum CXCursorKind K) { |
| 5251 | return K >= CXCursor_FirstStmt && K <= CXCursor_LastStmt; |
| 5252 | } |
| 5253 | |
| 5254 | unsigned clang_isAttribute(enum CXCursorKind K) { |
| 5255 | return K >= CXCursor_FirstAttr && K <= CXCursor_LastAttr; |
| 5256 | } |
| 5257 | |
| 5258 | unsigned clang_isTranslationUnit(enum CXCursorKind K) { |
| 5259 | return K == CXCursor_TranslationUnit; |
| 5260 | } |
| 5261 | |
| 5262 | unsigned clang_isPreprocessing(enum CXCursorKind K) { |
| 5263 | return K >= CXCursor_FirstPreprocessing && K <= CXCursor_LastPreprocessing; |
| 5264 | } |
| 5265 | |
| 5266 | unsigned clang_isUnexposed(enum CXCursorKind K) { |
| 5267 | switch (K) { |
| 5268 | case CXCursor_UnexposedDecl: |
| 5269 | case CXCursor_UnexposedExpr: |
| 5270 | case CXCursor_UnexposedStmt: |
| 5271 | case CXCursor_UnexposedAttr: |
| 5272 | return true; |
| 5273 | default: |
| 5274 | return false; |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | CXCursorKind clang_getCursorKind(CXCursor C) { |
| 5279 | return C.kind; |
| 5280 | } |
| 5281 | |
| 5282 | CXSourceLocation clang_getCursorLocation(CXCursor C) { |
| 5283 | if (clang_isReference(C.kind)) { |
| 5284 | switch (C.kind) { |
| 5285 | case CXCursor_ObjCSuperClassRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5286 | std::pair<const ObjCInterfaceDecl *, SourceLocation> P |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5287 | = getCursorObjCSuperClassRef(C); |
| 5288 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5289 | } |
| 5290 | |
| 5291 | case CXCursor_ObjCProtocolRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5292 | std::pair<const ObjCProtocolDecl *, SourceLocation> P |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5293 | = getCursorObjCProtocolRef(C); |
| 5294 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5295 | } |
| 5296 | |
| 5297 | case CXCursor_ObjCClassRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5298 | std::pair<const ObjCInterfaceDecl *, SourceLocation> P |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5299 | = getCursorObjCClassRef(C); |
| 5300 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5301 | } |
| 5302 | |
| 5303 | case CXCursor_TypeRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5304 | std::pair<const TypeDecl *, SourceLocation> P = getCursorTypeRef(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5305 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5306 | } |
| 5307 | |
| 5308 | case CXCursor_TemplateRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5309 | std::pair<const TemplateDecl *, SourceLocation> P = |
| 5310 | getCursorTemplateRef(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5311 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5312 | } |
| 5313 | |
| 5314 | case CXCursor_NamespaceRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5315 | std::pair<const NamedDecl *, SourceLocation> P = getCursorNamespaceRef(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5316 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5317 | } |
| 5318 | |
| 5319 | case CXCursor_MemberRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5320 | std::pair<const FieldDecl *, SourceLocation> P = getCursorMemberRef(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5321 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5322 | } |
| 5323 | |
| 5324 | case CXCursor_VariableRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5325 | std::pair<const VarDecl *, SourceLocation> P = getCursorVariableRef(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5326 | return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); |
| 5327 | } |
| 5328 | |
| 5329 | case CXCursor_CXXBaseSpecifier: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5330 | const CXXBaseSpecifier *BaseSpec = getCursorCXXBaseSpecifier(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5331 | if (!BaseSpec) |
| 5332 | return clang_getNullLocation(); |
| 5333 | |
| 5334 | if (TypeSourceInfo *TSInfo = BaseSpec->getTypeSourceInfo()) |
| 5335 | return cxloc::translateSourceLocation(getCursorContext(C), |
| 5336 | TSInfo->getTypeLoc().getBeginLoc()); |
| 5337 | |
| 5338 | return cxloc::translateSourceLocation(getCursorContext(C), |
| 5339 | BaseSpec->getLocStart()); |
| 5340 | } |
| 5341 | |
| 5342 | case CXCursor_LabelRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5343 | std::pair<const LabelStmt *, SourceLocation> P = getCursorLabelRef(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5344 | return cxloc::translateSourceLocation(getCursorContext(C), P.second); |
| 5345 | } |
| 5346 | |
| 5347 | case CXCursor_OverloadedDeclRef: |
| 5348 | return cxloc::translateSourceLocation(getCursorContext(C), |
| 5349 | getCursorOverloadedDeclRef(C).second); |
| 5350 | |
| 5351 | default: |
| 5352 | // FIXME: Need a way to enumerate all non-reference cases. |
| 5353 | llvm_unreachable("Missed a reference kind"); |
| 5354 | } |
| 5355 | } |
| 5356 | |
| 5357 | if (clang_isExpression(C.kind)) |
| 5358 | return cxloc::translateSourceLocation(getCursorContext(C), |
| 5359 | getLocationFromExpr(getCursorExpr(C))); |
| 5360 | |
| 5361 | if (clang_isStatement(C.kind)) |
| 5362 | return cxloc::translateSourceLocation(getCursorContext(C), |
| 5363 | getCursorStmt(C)->getLocStart()); |
| 5364 | |
| 5365 | if (C.kind == CXCursor_PreprocessingDirective) { |
| 5366 | SourceLocation L = cxcursor::getCursorPreprocessingDirective(C).getBegin(); |
| 5367 | return cxloc::translateSourceLocation(getCursorContext(C), L); |
| 5368 | } |
| 5369 | |
| 5370 | if (C.kind == CXCursor_MacroExpansion) { |
| 5371 | SourceLocation L |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 5372 | = cxcursor::getCursorMacroExpansion(C).getSourceRange().getBegin(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5373 | return cxloc::translateSourceLocation(getCursorContext(C), L); |
| 5374 | } |
| 5375 | |
| 5376 | if (C.kind == CXCursor_MacroDefinition) { |
| 5377 | SourceLocation L = cxcursor::getCursorMacroDefinition(C)->getLocation(); |
| 5378 | return cxloc::translateSourceLocation(getCursorContext(C), L); |
| 5379 | } |
| 5380 | |
| 5381 | if (C.kind == CXCursor_InclusionDirective) { |
| 5382 | SourceLocation L |
| 5383 | = cxcursor::getCursorInclusionDirective(C)->getSourceRange().getBegin(); |
| 5384 | return cxloc::translateSourceLocation(getCursorContext(C), L); |
| 5385 | } |
| 5386 | |
Argyrios Kyrtzidis | 16834f1 | 2013-09-25 00:14:38 +0000 | [diff] [blame] | 5387 | if (clang_isAttribute(C.kind)) { |
| 5388 | SourceLocation L |
| 5389 | = cxcursor::getCursorAttr(C)->getLocation(); |
| 5390 | return cxloc::translateSourceLocation(getCursorContext(C), L); |
| 5391 | } |
| 5392 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5393 | if (!clang_isDeclaration(C.kind)) |
| 5394 | return clang_getNullLocation(); |
| 5395 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5396 | const Decl *D = getCursorDecl(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5397 | if (!D) |
| 5398 | return clang_getNullLocation(); |
| 5399 | |
| 5400 | SourceLocation Loc = D->getLocation(); |
| 5401 | // FIXME: Multiple variables declared in a single declaration |
| 5402 | // currently lack the information needed to correctly determine their |
| 5403 | // ranges when accounting for the type-specifier. We use context |
| 5404 | // stored in the CXCursor to determine if the VarDecl is in a DeclGroup, |
| 5405 | // and if so, whether it is the first decl. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5406 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5407 | if (!cxcursor::isFirstInDeclGroup(C)) |
| 5408 | Loc = VD->getLocation(); |
| 5409 | } |
| 5410 | |
| 5411 | // For ObjC methods, give the start location of the method name. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5412 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5413 | Loc = MD->getSelectorStartLoc(); |
| 5414 | |
| 5415 | return cxloc::translateSourceLocation(getCursorContext(C), Loc); |
| 5416 | } |
| 5417 | |
NAKAMURA Takumi | a01f4c3 | 2016-12-19 16:50:43 +0000 | [diff] [blame] | 5418 | } // end extern "C" |
| 5419 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5420 | CXCursor cxcursor::getCursor(CXTranslationUnit TU, SourceLocation SLoc) { |
| 5421 | assert(TU); |
| 5422 | |
| 5423 | // Guard against an invalid SourceLocation, or we may assert in one |
| 5424 | // of the following calls. |
| 5425 | if (SLoc.isInvalid()) |
| 5426 | return clang_getNullCursor(); |
| 5427 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 5428 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5429 | |
| 5430 | // Translate the given source location to make it point at the beginning of |
| 5431 | // the token under the cursor. |
| 5432 | SLoc = Lexer::GetBeginningOfToken(SLoc, CXXUnit->getSourceManager(), |
| 5433 | CXXUnit->getASTContext().getLangOpts()); |
| 5434 | |
| 5435 | CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound); |
| 5436 | if (SLoc.isValid()) { |
| 5437 | GetCursorData ResultData(CXXUnit->getSourceManager(), SLoc, Result); |
| 5438 | CursorVisitor CursorVis(TU, GetCursorVisitor, &ResultData, |
| 5439 | /*VisitPreprocessorLast=*/true, |
| 5440 | /*VisitIncludedEntities=*/false, |
| 5441 | SourceLocation(SLoc)); |
| 5442 | CursorVis.visitFileRegion(); |
| 5443 | } |
| 5444 | |
| 5445 | return Result; |
| 5446 | } |
| 5447 | |
| 5448 | static SourceRange getRawCursorExtent(CXCursor C) { |
| 5449 | if (clang_isReference(C.kind)) { |
| 5450 | switch (C.kind) { |
| 5451 | case CXCursor_ObjCSuperClassRef: |
| 5452 | return getCursorObjCSuperClassRef(C).second; |
| 5453 | |
| 5454 | case CXCursor_ObjCProtocolRef: |
| 5455 | return getCursorObjCProtocolRef(C).second; |
| 5456 | |
| 5457 | case CXCursor_ObjCClassRef: |
| 5458 | return getCursorObjCClassRef(C).second; |
| 5459 | |
| 5460 | case CXCursor_TypeRef: |
| 5461 | return getCursorTypeRef(C).second; |
| 5462 | |
| 5463 | case CXCursor_TemplateRef: |
| 5464 | return getCursorTemplateRef(C).second; |
| 5465 | |
| 5466 | case CXCursor_NamespaceRef: |
| 5467 | return getCursorNamespaceRef(C).second; |
| 5468 | |
| 5469 | case CXCursor_MemberRef: |
| 5470 | return getCursorMemberRef(C).second; |
| 5471 | |
| 5472 | case CXCursor_CXXBaseSpecifier: |
| 5473 | return getCursorCXXBaseSpecifier(C)->getSourceRange(); |
| 5474 | |
| 5475 | case CXCursor_LabelRef: |
| 5476 | return getCursorLabelRef(C).second; |
| 5477 | |
| 5478 | case CXCursor_OverloadedDeclRef: |
| 5479 | return getCursorOverloadedDeclRef(C).second; |
| 5480 | |
| 5481 | case CXCursor_VariableRef: |
| 5482 | return getCursorVariableRef(C).second; |
| 5483 | |
| 5484 | default: |
| 5485 | // FIXME: Need a way to enumerate all non-reference cases. |
| 5486 | llvm_unreachable("Missed a reference kind"); |
| 5487 | } |
| 5488 | } |
| 5489 | |
| 5490 | if (clang_isExpression(C.kind)) |
| 5491 | return getCursorExpr(C)->getSourceRange(); |
| 5492 | |
| 5493 | if (clang_isStatement(C.kind)) |
| 5494 | return getCursorStmt(C)->getSourceRange(); |
| 5495 | |
| 5496 | if (clang_isAttribute(C.kind)) |
| 5497 | return getCursorAttr(C)->getRange(); |
| 5498 | |
| 5499 | if (C.kind == CXCursor_PreprocessingDirective) |
| 5500 | return cxcursor::getCursorPreprocessingDirective(C); |
| 5501 | |
| 5502 | if (C.kind == CXCursor_MacroExpansion) { |
| 5503 | ASTUnit *TU = getCursorASTUnit(C); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 5504 | SourceRange Range = cxcursor::getCursorMacroExpansion(C).getSourceRange(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5505 | return TU->mapRangeFromPreamble(Range); |
| 5506 | } |
| 5507 | |
| 5508 | if (C.kind == CXCursor_MacroDefinition) { |
| 5509 | ASTUnit *TU = getCursorASTUnit(C); |
| 5510 | SourceRange Range = cxcursor::getCursorMacroDefinition(C)->getSourceRange(); |
| 5511 | return TU->mapRangeFromPreamble(Range); |
| 5512 | } |
| 5513 | |
| 5514 | if (C.kind == CXCursor_InclusionDirective) { |
| 5515 | ASTUnit *TU = getCursorASTUnit(C); |
| 5516 | SourceRange Range = cxcursor::getCursorInclusionDirective(C)->getSourceRange(); |
| 5517 | return TU->mapRangeFromPreamble(Range); |
| 5518 | } |
| 5519 | |
| 5520 | if (C.kind == CXCursor_TranslationUnit) { |
| 5521 | ASTUnit *TU = getCursorASTUnit(C); |
| 5522 | FileID MainID = TU->getSourceManager().getMainFileID(); |
| 5523 | SourceLocation Start = TU->getSourceManager().getLocForStartOfFile(MainID); |
| 5524 | SourceLocation End = TU->getSourceManager().getLocForEndOfFile(MainID); |
| 5525 | return SourceRange(Start, End); |
| 5526 | } |
| 5527 | |
| 5528 | if (clang_isDeclaration(C.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5529 | const Decl *D = cxcursor::getCursorDecl(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5530 | if (!D) |
| 5531 | return SourceRange(); |
| 5532 | |
| 5533 | SourceRange R = D->getSourceRange(); |
| 5534 | // FIXME: Multiple variables declared in a single declaration |
| 5535 | // currently lack the information needed to correctly determine their |
| 5536 | // ranges when accounting for the type-specifier. We use context |
| 5537 | // stored in the CXCursor to determine if the VarDecl is in a DeclGroup, |
| 5538 | // and if so, whether it is the first decl. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5539 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5540 | if (!cxcursor::isFirstInDeclGroup(C)) |
| 5541 | R.setBegin(VD->getLocation()); |
| 5542 | } |
| 5543 | return R; |
| 5544 | } |
| 5545 | return SourceRange(); |
| 5546 | } |
| 5547 | |
| 5548 | /// \brief Retrieves the "raw" cursor extent, which is then extended to include |
| 5549 | /// the decl-specifier-seq for declarations. |
| 5550 | static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr) { |
| 5551 | if (clang_isDeclaration(C.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5552 | const Decl *D = cxcursor::getCursorDecl(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5553 | if (!D) |
| 5554 | return SourceRange(); |
| 5555 | |
| 5556 | SourceRange R = D->getSourceRange(); |
| 5557 | |
| 5558 | // Adjust the start of the location for declarations preceded by |
| 5559 | // declaration specifiers. |
| 5560 | SourceLocation StartLoc; |
| 5561 | if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) { |
| 5562 | if (TypeSourceInfo *TI = DD->getTypeSourceInfo()) |
| 5563 | StartLoc = TI->getTypeLoc().getLocStart(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5564 | } else if (const TypedefDecl *Typedef = dyn_cast<TypedefDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5565 | if (TypeSourceInfo *TI = Typedef->getTypeSourceInfo()) |
| 5566 | StartLoc = TI->getTypeLoc().getLocStart(); |
| 5567 | } |
| 5568 | |
| 5569 | if (StartLoc.isValid() && R.getBegin().isValid() && |
| 5570 | SrcMgr.isBeforeInTranslationUnit(StartLoc, R.getBegin())) |
| 5571 | R.setBegin(StartLoc); |
| 5572 | |
| 5573 | // FIXME: Multiple variables declared in a single declaration |
| 5574 | // currently lack the information needed to correctly determine their |
| 5575 | // ranges when accounting for the type-specifier. We use context |
| 5576 | // stored in the CXCursor to determine if the VarDecl is in a DeclGroup, |
| 5577 | // and if so, whether it is the first decl. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5578 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5579 | if (!cxcursor::isFirstInDeclGroup(C)) |
| 5580 | R.setBegin(VD->getLocation()); |
| 5581 | } |
| 5582 | |
| 5583 | return R; |
| 5584 | } |
| 5585 | |
| 5586 | return getRawCursorExtent(C); |
| 5587 | } |
| 5588 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5589 | CXSourceRange clang_getCursorExtent(CXCursor C) { |
| 5590 | SourceRange R = getRawCursorExtent(C); |
| 5591 | if (R.isInvalid()) |
| 5592 | return clang_getNullRange(); |
| 5593 | |
| 5594 | return cxloc::translateSourceRange(getCursorContext(C), R); |
| 5595 | } |
| 5596 | |
| 5597 | CXCursor clang_getCursorReferenced(CXCursor C) { |
| 5598 | if (clang_isInvalid(C.kind)) |
| 5599 | return clang_getNullCursor(); |
| 5600 | |
| 5601 | CXTranslationUnit tu = getCursorTU(C); |
| 5602 | if (clang_isDeclaration(C.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5603 | const Decl *D = getCursorDecl(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5604 | if (!D) |
| 5605 | return clang_getNullCursor(); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5606 | if (const UsingDecl *Using = dyn_cast<UsingDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5607 | return MakeCursorOverloadedDeclRef(Using, D->getLocation(), tu); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5608 | if (const ObjCPropertyImplDecl *PropImpl = |
| 5609 | dyn_cast<ObjCPropertyImplDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5610 | if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl()) |
| 5611 | return MakeCXCursor(Property, tu); |
| 5612 | |
| 5613 | return C; |
| 5614 | } |
| 5615 | |
| 5616 | if (clang_isExpression(C.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5617 | const Expr *E = getCursorExpr(C); |
| 5618 | const Decl *D = getDeclFromExpr(E); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5619 | if (D) { |
| 5620 | CXCursor declCursor = MakeCXCursor(D, tu); |
| 5621 | declCursor = getSelectorIdentifierCursor(getSelectorIdentifierIndex(C), |
| 5622 | declCursor); |
| 5623 | return declCursor; |
| 5624 | } |
| 5625 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5626 | if (const OverloadExpr *Ovl = dyn_cast_or_null<OverloadExpr>(E)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5627 | return MakeCursorOverloadedDeclRef(Ovl, tu); |
| 5628 | |
| 5629 | return clang_getNullCursor(); |
| 5630 | } |
| 5631 | |
| 5632 | if (clang_isStatement(C.kind)) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 5633 | const Stmt *S = getCursorStmt(C); |
| 5634 | if (const GotoStmt *Goto = dyn_cast_or_null<GotoStmt>(S)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5635 | if (LabelDecl *label = Goto->getLabel()) |
| 5636 | if (LabelStmt *labelS = label->getStmt()) |
| 5637 | return MakeCXCursor(labelS, getCursorDecl(C), tu); |
| 5638 | |
| 5639 | return clang_getNullCursor(); |
| 5640 | } |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5641 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5642 | if (C.kind == CXCursor_MacroExpansion) { |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5643 | if (const MacroDefinitionRecord *Def = |
| 5644 | getCursorMacroExpansion(C).getDefinition()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5645 | return MakeMacroDefinitionCursor(Def, tu); |
| 5646 | } |
| 5647 | |
| 5648 | if (!clang_isReference(C.kind)) |
| 5649 | return clang_getNullCursor(); |
| 5650 | |
| 5651 | switch (C.kind) { |
| 5652 | case CXCursor_ObjCSuperClassRef: |
| 5653 | return MakeCXCursor(getCursorObjCSuperClassRef(C).first, tu); |
| 5654 | |
| 5655 | case CXCursor_ObjCProtocolRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5656 | const ObjCProtocolDecl *Prot = getCursorObjCProtocolRef(C).first; |
| 5657 | if (const ObjCProtocolDecl *Def = Prot->getDefinition()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5658 | return MakeCXCursor(Def, tu); |
| 5659 | |
| 5660 | return MakeCXCursor(Prot, tu); |
| 5661 | } |
| 5662 | |
| 5663 | case CXCursor_ObjCClassRef: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5664 | const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first; |
| 5665 | if (const ObjCInterfaceDecl *Def = Class->getDefinition()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5666 | return MakeCXCursor(Def, tu); |
| 5667 | |
| 5668 | return MakeCXCursor(Class, tu); |
| 5669 | } |
| 5670 | |
| 5671 | case CXCursor_TypeRef: |
| 5672 | return MakeCXCursor(getCursorTypeRef(C).first, tu ); |
| 5673 | |
| 5674 | case CXCursor_TemplateRef: |
| 5675 | return MakeCXCursor(getCursorTemplateRef(C).first, tu ); |
| 5676 | |
| 5677 | case CXCursor_NamespaceRef: |
| 5678 | return MakeCXCursor(getCursorNamespaceRef(C).first, tu ); |
| 5679 | |
| 5680 | case CXCursor_MemberRef: |
| 5681 | return MakeCXCursor(getCursorMemberRef(C).first, tu ); |
| 5682 | |
| 5683 | case CXCursor_CXXBaseSpecifier: { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 5684 | const CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5685 | return clang_getTypeDeclaration(cxtype::MakeCXType(B->getType(), |
| 5686 | tu )); |
| 5687 | } |
| 5688 | |
| 5689 | case CXCursor_LabelRef: |
| 5690 | // FIXME: We end up faking the "parent" declaration here because we |
| 5691 | // don't want to make CXCursor larger. |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 5692 | return MakeCXCursor(getCursorLabelRef(C).first, |
| 5693 | cxtu::getASTUnit(tu)->getASTContext() |
| 5694 | .getTranslationUnitDecl(), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5695 | tu); |
| 5696 | |
| 5697 | case CXCursor_OverloadedDeclRef: |
| 5698 | return C; |
| 5699 | |
| 5700 | case CXCursor_VariableRef: |
| 5701 | return MakeCXCursor(getCursorVariableRef(C).first, tu); |
| 5702 | |
| 5703 | default: |
| 5704 | // We would prefer to enumerate all non-reference cursor kinds here. |
| 5705 | llvm_unreachable("Unhandled reference cursor kind"); |
| 5706 | } |
| 5707 | } |
| 5708 | |
| 5709 | CXCursor clang_getCursorDefinition(CXCursor C) { |
| 5710 | if (clang_isInvalid(C.kind)) |
| 5711 | return clang_getNullCursor(); |
| 5712 | |
| 5713 | CXTranslationUnit TU = getCursorTU(C); |
| 5714 | |
| 5715 | bool WasReference = false; |
| 5716 | if (clang_isReference(C.kind) || clang_isExpression(C.kind)) { |
| 5717 | C = clang_getCursorReferenced(C); |
| 5718 | WasReference = true; |
| 5719 | } |
| 5720 | |
| 5721 | if (C.kind == CXCursor_MacroExpansion) |
| 5722 | return clang_getCursorReferenced(C); |
| 5723 | |
| 5724 | if (!clang_isDeclaration(C.kind)) |
| 5725 | return clang_getNullCursor(); |
| 5726 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5727 | const Decl *D = getCursorDecl(C); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5728 | if (!D) |
| 5729 | return clang_getNullCursor(); |
| 5730 | |
| 5731 | switch (D->getKind()) { |
| 5732 | // Declaration kinds that don't really separate the notions of |
| 5733 | // declaration and definition. |
| 5734 | case Decl::Namespace: |
| 5735 | case Decl::Typedef: |
| 5736 | case Decl::TypeAlias: |
| 5737 | case Decl::TypeAliasTemplate: |
| 5738 | case Decl::TemplateTypeParm: |
| 5739 | case Decl::EnumConstant: |
| 5740 | case Decl::Field: |
Richard Smith | bdb84f3 | 2016-07-22 23:36:59 +0000 | [diff] [blame] | 5741 | case Decl::Binding: |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 5742 | case Decl::MSProperty: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5743 | case Decl::IndirectField: |
| 5744 | case Decl::ObjCIvar: |
| 5745 | case Decl::ObjCAtDefsField: |
| 5746 | case Decl::ImplicitParam: |
| 5747 | case Decl::ParmVar: |
| 5748 | case Decl::NonTypeTemplateParm: |
| 5749 | case Decl::TemplateTemplateParm: |
| 5750 | case Decl::ObjCCategoryImpl: |
| 5751 | case Decl::ObjCImplementation: |
| 5752 | case Decl::AccessSpec: |
| 5753 | case Decl::LinkageSpec: |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 5754 | case Decl::Export: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5755 | case Decl::ObjCPropertyImpl: |
| 5756 | case Decl::FileScopeAsm: |
| 5757 | case Decl::StaticAssert: |
| 5758 | case Decl::Block: |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 5759 | case Decl::Captured: |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 5760 | case Decl::OMPCapturedExpr: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5761 | case Decl::Label: // FIXME: Is this right?? |
| 5762 | case Decl::ClassScopeFunctionSpecialization: |
| 5763 | case Decl::Import: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 5764 | case Decl::OMPThreadPrivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 5765 | case Decl::OMPDeclareReduction: |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 5766 | case Decl::ObjCTypeParam: |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 5767 | case Decl::BuiltinTemplate: |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 5768 | case Decl::PragmaComment: |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 5769 | case Decl::PragmaDetectMismatch: |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 5770 | case Decl::UsingPack: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5771 | return C; |
| 5772 | |
| 5773 | // Declaration kinds that don't make any sense here, but are |
| 5774 | // nonetheless harmless. |
David Blaikie | f005d3c | 2013-02-22 17:44:58 +0000 | [diff] [blame] | 5775 | case Decl::Empty: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5776 | case Decl::TranslationUnit: |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 5777 | case Decl::ExternCContext: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5778 | break; |
| 5779 | |
| 5780 | // Declaration kinds for which the definition is not resolvable. |
| 5781 | case Decl::UnresolvedUsingTypename: |
| 5782 | case Decl::UnresolvedUsingValue: |
| 5783 | break; |
| 5784 | |
| 5785 | case Decl::UsingDirective: |
| 5786 | return MakeCXCursor(cast<UsingDirectiveDecl>(D)->getNominatedNamespace(), |
| 5787 | TU); |
| 5788 | |
| 5789 | case Decl::NamespaceAlias: |
| 5790 | return MakeCXCursor(cast<NamespaceAliasDecl>(D)->getNamespace(), TU); |
| 5791 | |
| 5792 | case Decl::Enum: |
| 5793 | case Decl::Record: |
| 5794 | case Decl::CXXRecord: |
| 5795 | case Decl::ClassTemplateSpecialization: |
| 5796 | case Decl::ClassTemplatePartialSpecialization: |
| 5797 | if (TagDecl *Def = cast<TagDecl>(D)->getDefinition()) |
| 5798 | return MakeCXCursor(Def, TU); |
| 5799 | return clang_getNullCursor(); |
| 5800 | |
| 5801 | case Decl::Function: |
| 5802 | case Decl::CXXMethod: |
| 5803 | case Decl::CXXConstructor: |
| 5804 | case Decl::CXXDestructor: |
| 5805 | case Decl::CXXConversion: { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 5806 | const FunctionDecl *Def = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5807 | if (cast<FunctionDecl>(D)->getBody(Def)) |
Dmitri Gribenko | 9c256e3 | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 5808 | return MakeCXCursor(Def, TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5809 | return clang_getNullCursor(); |
| 5810 | } |
| 5811 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5812 | case Decl::Var: |
| 5813 | case Decl::VarTemplateSpecialization: |
Richard Smith | bdb84f3 | 2016-07-22 23:36:59 +0000 | [diff] [blame] | 5814 | case Decl::VarTemplatePartialSpecialization: |
| 5815 | case Decl::Decomposition: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5816 | // Ask the variable if it has a definition. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5817 | if (const VarDecl *Def = cast<VarDecl>(D)->getDefinition()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5818 | return MakeCXCursor(Def, TU); |
| 5819 | return clang_getNullCursor(); |
| 5820 | } |
| 5821 | |
| 5822 | case Decl::FunctionTemplate: { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 5823 | const FunctionDecl *Def = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5824 | if (cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->getBody(Def)) |
| 5825 | return MakeCXCursor(Def->getDescribedFunctionTemplate(), TU); |
| 5826 | return clang_getNullCursor(); |
| 5827 | } |
| 5828 | |
| 5829 | case Decl::ClassTemplate: { |
| 5830 | if (RecordDecl *Def = cast<ClassTemplateDecl>(D)->getTemplatedDecl() |
| 5831 | ->getDefinition()) |
| 5832 | return MakeCXCursor(cast<CXXRecordDecl>(Def)->getDescribedClassTemplate(), |
| 5833 | TU); |
| 5834 | return clang_getNullCursor(); |
| 5835 | } |
| 5836 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5837 | case Decl::VarTemplate: { |
| 5838 | if (VarDecl *Def = |
| 5839 | cast<VarTemplateDecl>(D)->getTemplatedDecl()->getDefinition()) |
| 5840 | return MakeCXCursor(cast<VarDecl>(Def)->getDescribedVarTemplate(), TU); |
| 5841 | return clang_getNullCursor(); |
| 5842 | } |
| 5843 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5844 | case Decl::Using: |
| 5845 | return MakeCursorOverloadedDeclRef(cast<UsingDecl>(D), |
| 5846 | D->getLocation(), TU); |
| 5847 | |
| 5848 | case Decl::UsingShadow: |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 5849 | case Decl::ConstructorUsingShadow: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5850 | return clang_getCursorDefinition( |
| 5851 | MakeCXCursor(cast<UsingShadowDecl>(D)->getTargetDecl(), |
| 5852 | TU)); |
| 5853 | |
| 5854 | case Decl::ObjCMethod: { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5855 | const ObjCMethodDecl *Method = cast<ObjCMethodDecl>(D); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5856 | if (Method->isThisDeclarationADefinition()) |
| 5857 | return C; |
| 5858 | |
| 5859 | // Dig out the method definition in the associated |
| 5860 | // @implementation, if we have it. |
| 5861 | // FIXME: The ASTs should make finding the definition easier. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5862 | if (const ObjCInterfaceDecl *Class |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5863 | = dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext())) |
| 5864 | if (ObjCImplementationDecl *ClassImpl = Class->getImplementation()) |
| 5865 | if (ObjCMethodDecl *Def = ClassImpl->getMethod(Method->getSelector(), |
| 5866 | Method->isInstanceMethod())) |
| 5867 | if (Def->isThisDeclarationADefinition()) |
| 5868 | return MakeCXCursor(Def, TU); |
| 5869 | |
| 5870 | return clang_getNullCursor(); |
| 5871 | } |
| 5872 | |
| 5873 | case Decl::ObjCCategory: |
| 5874 | if (ObjCCategoryImplDecl *Impl |
| 5875 | = cast<ObjCCategoryDecl>(D)->getImplementation()) |
| 5876 | return MakeCXCursor(Impl, TU); |
| 5877 | return clang_getNullCursor(); |
| 5878 | |
| 5879 | case Decl::ObjCProtocol: |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5880 | if (const ObjCProtocolDecl *Def = cast<ObjCProtocolDecl>(D)->getDefinition()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5881 | return MakeCXCursor(Def, TU); |
| 5882 | return clang_getNullCursor(); |
| 5883 | |
| 5884 | case Decl::ObjCInterface: { |
| 5885 | // There are two notions of a "definition" for an Objective-C |
| 5886 | // class: the interface and its implementation. When we resolved a |
| 5887 | // reference to an Objective-C class, produce the @interface as |
| 5888 | // the definition; when we were provided with the interface, |
| 5889 | // produce the @implementation as the definition. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5890 | const ObjCInterfaceDecl *IFace = cast<ObjCInterfaceDecl>(D); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5891 | if (WasReference) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5892 | if (const ObjCInterfaceDecl *Def = IFace->getDefinition()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5893 | return MakeCXCursor(Def, TU); |
| 5894 | } else if (ObjCImplementationDecl *Impl = IFace->getImplementation()) |
| 5895 | return MakeCXCursor(Impl, TU); |
| 5896 | return clang_getNullCursor(); |
| 5897 | } |
| 5898 | |
| 5899 | case Decl::ObjCProperty: |
| 5900 | // FIXME: We don't really know where to find the |
| 5901 | // ObjCPropertyImplDecls that implement this property. |
| 5902 | return clang_getNullCursor(); |
| 5903 | |
| 5904 | case Decl::ObjCCompatibleAlias: |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5905 | if (const ObjCInterfaceDecl *Class |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5906 | = cast<ObjCCompatibleAliasDecl>(D)->getClassInterface()) |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5907 | if (const ObjCInterfaceDecl *Def = Class->getDefinition()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5908 | return MakeCXCursor(Def, TU); |
| 5909 | |
| 5910 | return clang_getNullCursor(); |
| 5911 | |
| 5912 | case Decl::Friend: |
| 5913 | if (NamedDecl *Friend = cast<FriendDecl>(D)->getFriendDecl()) |
| 5914 | return clang_getCursorDefinition(MakeCXCursor(Friend, TU)); |
| 5915 | return clang_getNullCursor(); |
| 5916 | |
| 5917 | case Decl::FriendTemplate: |
| 5918 | if (NamedDecl *Friend = cast<FriendTemplateDecl>(D)->getFriendDecl()) |
| 5919 | return clang_getCursorDefinition(MakeCXCursor(Friend, TU)); |
| 5920 | return clang_getNullCursor(); |
| 5921 | } |
| 5922 | |
| 5923 | return clang_getNullCursor(); |
| 5924 | } |
| 5925 | |
| 5926 | unsigned clang_isCursorDefinition(CXCursor C) { |
| 5927 | if (!clang_isDeclaration(C.kind)) |
| 5928 | return 0; |
| 5929 | |
| 5930 | return clang_getCursorDefinition(C) == C; |
| 5931 | } |
| 5932 | |
| 5933 | CXCursor clang_getCanonicalCursor(CXCursor C) { |
| 5934 | if (!clang_isDeclaration(C.kind)) |
| 5935 | return C; |
| 5936 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5937 | if (const Decl *D = getCursorDecl(C)) { |
| 5938 | if (const ObjCCategoryImplDecl *CatImplD = dyn_cast<ObjCCategoryImplDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5939 | if (ObjCCategoryDecl *CatD = CatImplD->getCategoryDecl()) |
| 5940 | return MakeCXCursor(CatD, getCursorTU(C)); |
| 5941 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5942 | if (const ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 5943 | if (const ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5944 | return MakeCXCursor(IFD, getCursorTU(C)); |
| 5945 | |
| 5946 | return MakeCXCursor(D->getCanonicalDecl(), getCursorTU(C)); |
| 5947 | } |
| 5948 | |
| 5949 | return C; |
| 5950 | } |
| 5951 | |
| 5952 | int clang_Cursor_getObjCSelectorIndex(CXCursor cursor) { |
| 5953 | return cxcursor::getSelectorIdentifierIndexAndLoc(cursor).first; |
| 5954 | } |
| 5955 | |
| 5956 | unsigned clang_getNumOverloadedDecls(CXCursor C) { |
| 5957 | if (C.kind != CXCursor_OverloadedDeclRef) |
| 5958 | return 0; |
| 5959 | |
| 5960 | OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first; |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5961 | if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5962 | return E->getNumDecls(); |
| 5963 | |
| 5964 | if (OverloadedTemplateStorage *S |
| 5965 | = Storage.dyn_cast<OverloadedTemplateStorage*>()) |
| 5966 | return S->size(); |
| 5967 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5968 | const Decl *D = Storage.get<const Decl *>(); |
| 5969 | if (const UsingDecl *Using = dyn_cast<UsingDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5970 | return Using->shadow_size(); |
| 5971 | |
| 5972 | return 0; |
| 5973 | } |
| 5974 | |
| 5975 | CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) { |
| 5976 | if (cursor.kind != CXCursor_OverloadedDeclRef) |
| 5977 | return clang_getNullCursor(); |
| 5978 | |
| 5979 | if (index >= clang_getNumOverloadedDecls(cursor)) |
| 5980 | return clang_getNullCursor(); |
| 5981 | |
| 5982 | CXTranslationUnit TU = getCursorTU(cursor); |
| 5983 | OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(cursor).first; |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5984 | if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5985 | return MakeCXCursor(E->decls_begin()[index], TU); |
| 5986 | |
| 5987 | if (OverloadedTemplateStorage *S |
| 5988 | = Storage.dyn_cast<OverloadedTemplateStorage*>()) |
| 5989 | return MakeCXCursor(S->begin()[index], TU); |
| 5990 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 5991 | const Decl *D = Storage.get<const Decl *>(); |
| 5992 | if (const UsingDecl *Using = dyn_cast<UsingDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5993 | // FIXME: This is, unfortunately, linear time. |
| 5994 | UsingDecl::shadow_iterator Pos = Using->shadow_begin(); |
| 5995 | std::advance(Pos, index); |
| 5996 | return MakeCXCursor(cast<UsingShadowDecl>(*Pos)->getTargetDecl(), TU); |
| 5997 | } |
| 5998 | |
| 5999 | return clang_getNullCursor(); |
| 6000 | } |
| 6001 | |
| 6002 | void clang_getDefinitionSpellingAndExtent(CXCursor C, |
| 6003 | const char **startBuf, |
| 6004 | const char **endBuf, |
| 6005 | unsigned *startLine, |
| 6006 | unsigned *startColumn, |
| 6007 | unsigned *endLine, |
| 6008 | unsigned *endColumn) { |
| 6009 | assert(getCursorDecl(C) && "CXCursor has null decl"); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 6010 | const FunctionDecl *FD = dyn_cast<FunctionDecl>(getCursorDecl(C)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6011 | CompoundStmt *Body = dyn_cast<CompoundStmt>(FD->getBody()); |
| 6012 | |
| 6013 | SourceManager &SM = FD->getASTContext().getSourceManager(); |
| 6014 | *startBuf = SM.getCharacterData(Body->getLBracLoc()); |
| 6015 | *endBuf = SM.getCharacterData(Body->getRBracLoc()); |
| 6016 | *startLine = SM.getSpellingLineNumber(Body->getLBracLoc()); |
| 6017 | *startColumn = SM.getSpellingColumnNumber(Body->getLBracLoc()); |
| 6018 | *endLine = SM.getSpellingLineNumber(Body->getRBracLoc()); |
| 6019 | *endColumn = SM.getSpellingColumnNumber(Body->getRBracLoc()); |
| 6020 | } |
| 6021 | |
| 6022 | |
| 6023 | CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, unsigned NameFlags, |
| 6024 | unsigned PieceIndex) { |
| 6025 | RefNamePieces Pieces; |
| 6026 | |
| 6027 | switch (C.kind) { |
| 6028 | case CXCursor_MemberRefExpr: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 6029 | if (const MemberExpr *E = dyn_cast<MemberExpr>(getCursorExpr(C))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6030 | Pieces = buildPieces(NameFlags, true, E->getMemberNameInfo(), |
| 6031 | E->getQualifierLoc().getSourceRange()); |
| 6032 | break; |
| 6033 | |
| 6034 | case CXCursor_DeclRefExpr: |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 6035 | if (const DeclRefExpr *E = dyn_cast<DeclRefExpr>(getCursorExpr(C))) { |
| 6036 | SourceRange TemplateArgLoc(E->getLAngleLoc(), E->getRAngleLoc()); |
| 6037 | Pieces = |
| 6038 | buildPieces(NameFlags, false, E->getNameInfo(), |
| 6039 | E->getQualifierLoc().getSourceRange(), &TemplateArgLoc); |
| 6040 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6041 | break; |
| 6042 | |
| 6043 | case CXCursor_CallExpr: |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 6044 | if (const CXXOperatorCallExpr *OCE = |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6045 | dyn_cast<CXXOperatorCallExpr>(getCursorExpr(C))) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 6046 | const Expr *Callee = OCE->getCallee(); |
| 6047 | if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6048 | Callee = ICE->getSubExpr(); |
| 6049 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 6050 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6051 | Pieces = buildPieces(NameFlags, false, DRE->getNameInfo(), |
| 6052 | DRE->getQualifierLoc().getSourceRange()); |
| 6053 | } |
| 6054 | break; |
| 6055 | |
| 6056 | default: |
| 6057 | break; |
| 6058 | } |
| 6059 | |
| 6060 | if (Pieces.empty()) { |
| 6061 | if (PieceIndex == 0) |
| 6062 | return clang_getCursorExtent(C); |
| 6063 | } else if (PieceIndex < Pieces.size()) { |
| 6064 | SourceRange R = Pieces[PieceIndex]; |
| 6065 | if (R.isValid()) |
| 6066 | return cxloc::translateSourceRange(getCursorContext(C), R); |
| 6067 | } |
| 6068 | |
| 6069 | return clang_getNullRange(); |
| 6070 | } |
| 6071 | |
| 6072 | void clang_enableStackTraces(void) { |
Richard Smith | dfed58a | 2016-06-09 00:53:41 +0000 | [diff] [blame] | 6073 | // FIXME: Provide an argv0 here so we can find llvm-symbolizer. |
| 6074 | llvm::sys::PrintStackTraceOnErrorSignal(StringRef()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | void clang_executeOnThread(void (*fn)(void*), void *user_data, |
| 6078 | unsigned stack_size) { |
| 6079 | llvm::llvm_execute_on_thread(fn, user_data, stack_size); |
| 6080 | } |
| 6081 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6082 | //===----------------------------------------------------------------------===// |
| 6083 | // Token-based Operations. |
| 6084 | //===----------------------------------------------------------------------===// |
| 6085 | |
| 6086 | /* CXToken layout: |
| 6087 | * int_data[0]: a CXTokenKind |
| 6088 | * int_data[1]: starting token location |
| 6089 | * int_data[2]: token length |
| 6090 | * int_data[3]: reserved |
| 6091 | * ptr_data: for identifiers and keywords, an IdentifierInfo*. |
| 6092 | * otherwise unused. |
| 6093 | */ |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6094 | CXTokenKind clang_getTokenKind(CXToken CXTok) { |
| 6095 | return static_cast<CXTokenKind>(CXTok.int_data[0]); |
| 6096 | } |
| 6097 | |
| 6098 | CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) { |
| 6099 | switch (clang_getTokenKind(CXTok)) { |
| 6100 | case CXToken_Identifier: |
| 6101 | case CXToken_Keyword: |
| 6102 | // We know we have an IdentifierInfo*, so use that. |
Dmitri Gribenko | 3c66b0b | 2013-02-02 00:02:12 +0000 | [diff] [blame] | 6103 | return cxstring::createRef(static_cast<IdentifierInfo *>(CXTok.ptr_data) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6104 | ->getNameStart()); |
| 6105 | |
| 6106 | case CXToken_Literal: { |
| 6107 | // We have stashed the starting pointer in the ptr_data field. Use it. |
| 6108 | const char *Text = static_cast<const char *>(CXTok.ptr_data); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 6109 | return cxstring::createDup(StringRef(Text, CXTok.int_data[2])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6110 | } |
| 6111 | |
| 6112 | case CXToken_Punctuation: |
| 6113 | case CXToken_Comment: |
| 6114 | break; |
| 6115 | } |
| 6116 | |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 6117 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 6118 | LOG_BAD_TU(TU); |
| 6119 | return cxstring::createEmpty(); |
| 6120 | } |
| 6121 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6122 | // We have to find the starting buffer pointer the hard way, by |
| 6123 | // deconstructing the source location. |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6124 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6125 | if (!CXXUnit) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 6126 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6127 | |
| 6128 | SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]); |
| 6129 | std::pair<FileID, unsigned> LocInfo |
| 6130 | = CXXUnit->getSourceManager().getDecomposedSpellingLoc(Loc); |
| 6131 | bool Invalid = false; |
| 6132 | StringRef Buffer |
| 6133 | = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid); |
| 6134 | if (Invalid) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 6135 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6136 | |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 6137 | return cxstring::createDup(Buffer.substr(LocInfo.second, CXTok.int_data[2])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6138 | } |
| 6139 | |
| 6140 | CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 6141 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 6142 | LOG_BAD_TU(TU); |
| 6143 | return clang_getNullLocation(); |
| 6144 | } |
| 6145 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6146 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6147 | if (!CXXUnit) |
| 6148 | return clang_getNullLocation(); |
| 6149 | |
| 6150 | return cxloc::translateSourceLocation(CXXUnit->getASTContext(), |
| 6151 | SourceLocation::getFromRawEncoding(CXTok.int_data[1])); |
| 6152 | } |
| 6153 | |
| 6154 | CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 6155 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 6156 | LOG_BAD_TU(TU); |
| 6157 | return clang_getNullRange(); |
| 6158 | } |
| 6159 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6160 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6161 | if (!CXXUnit) |
| 6162 | return clang_getNullRange(); |
| 6163 | |
| 6164 | return cxloc::translateSourceRange(CXXUnit->getASTContext(), |
| 6165 | SourceLocation::getFromRawEncoding(CXTok.int_data[1])); |
| 6166 | } |
| 6167 | |
| 6168 | static void getTokens(ASTUnit *CXXUnit, SourceRange Range, |
| 6169 | SmallVectorImpl<CXToken> &CXTokens) { |
| 6170 | SourceManager &SourceMgr = CXXUnit->getSourceManager(); |
| 6171 | std::pair<FileID, unsigned> BeginLocInfo |
Argyrios Kyrtzidis | 5d47a9b | 2013-02-13 18:33:28 +0000 | [diff] [blame] | 6172 | = SourceMgr.getDecomposedSpellingLoc(Range.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6173 | std::pair<FileID, unsigned> EndLocInfo |
Argyrios Kyrtzidis | 5d47a9b | 2013-02-13 18:33:28 +0000 | [diff] [blame] | 6174 | = SourceMgr.getDecomposedSpellingLoc(Range.getEnd()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6175 | |
| 6176 | // Cannot tokenize across files. |
| 6177 | if (BeginLocInfo.first != EndLocInfo.first) |
| 6178 | return; |
| 6179 | |
| 6180 | // Create a lexer |
| 6181 | bool Invalid = false; |
| 6182 | StringRef Buffer |
| 6183 | = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid); |
| 6184 | if (Invalid) |
| 6185 | return; |
| 6186 | |
| 6187 | Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first), |
| 6188 | CXXUnit->getASTContext().getLangOpts(), |
| 6189 | Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end()); |
| 6190 | Lex.SetCommentRetentionState(true); |
| 6191 | |
| 6192 | // Lex tokens until we hit the end of the range. |
| 6193 | const char *EffectiveBufferEnd = Buffer.data() + EndLocInfo.second; |
| 6194 | Token Tok; |
| 6195 | bool previousWasAt = false; |
| 6196 | do { |
| 6197 | // Lex the next token |
| 6198 | Lex.LexFromRawLexer(Tok); |
| 6199 | if (Tok.is(tok::eof)) |
| 6200 | break; |
| 6201 | |
| 6202 | // Initialize the CXToken. |
| 6203 | CXToken CXTok; |
| 6204 | |
| 6205 | // - Common fields |
| 6206 | CXTok.int_data[1] = Tok.getLocation().getRawEncoding(); |
| 6207 | CXTok.int_data[2] = Tok.getLength(); |
| 6208 | CXTok.int_data[3] = 0; |
| 6209 | |
| 6210 | // - Kind-specific fields |
| 6211 | if (Tok.isLiteral()) { |
| 6212 | CXTok.int_data[0] = CXToken_Literal; |
Dmitri Gribenko | f930448 | 2013-01-23 15:56:07 +0000 | [diff] [blame] | 6213 | CXTok.ptr_data = const_cast<char *>(Tok.getLiteralData()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6214 | } else if (Tok.is(tok::raw_identifier)) { |
| 6215 | // Lookup the identifier to determine whether we have a keyword. |
| 6216 | IdentifierInfo *II |
| 6217 | = CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok); |
| 6218 | |
| 6219 | if ((II->getObjCKeywordID() != tok::objc_not_keyword) && previousWasAt) { |
| 6220 | CXTok.int_data[0] = CXToken_Keyword; |
| 6221 | } |
| 6222 | else { |
| 6223 | CXTok.int_data[0] = Tok.is(tok::identifier) |
| 6224 | ? CXToken_Identifier |
| 6225 | : CXToken_Keyword; |
| 6226 | } |
| 6227 | CXTok.ptr_data = II; |
| 6228 | } else if (Tok.is(tok::comment)) { |
| 6229 | CXTok.int_data[0] = CXToken_Comment; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 6230 | CXTok.ptr_data = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6231 | } else { |
| 6232 | CXTok.int_data[0] = CXToken_Punctuation; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 6233 | CXTok.ptr_data = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6234 | } |
| 6235 | CXTokens.push_back(CXTok); |
| 6236 | previousWasAt = Tok.is(tok::at); |
Argyrios Kyrtzidis | c7c6a07 | 2016-11-09 23:58:39 +0000 | [diff] [blame] | 6237 | } while (Lex.getBufferLocation() < EffectiveBufferEnd); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, |
| 6241 | CXToken **Tokens, unsigned *NumTokens) { |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 6242 | LOG_FUNC_SECTION { |
| 6243 | *Log << TU << ' ' << Range; |
| 6244 | } |
| 6245 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6246 | if (Tokens) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 6247 | *Tokens = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6248 | if (NumTokens) |
| 6249 | *NumTokens = 0; |
| 6250 | |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 6251 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 6252 | LOG_BAD_TU(TU); |
Argyrios Kyrtzidis | 0e95fca | 2013-04-04 22:40:59 +0000 | [diff] [blame] | 6253 | return; |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 6254 | } |
Argyrios Kyrtzidis | 0e95fca | 2013-04-04 22:40:59 +0000 | [diff] [blame] | 6255 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6256 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6257 | if (!CXXUnit || !Tokens || !NumTokens) |
| 6258 | return; |
| 6259 | |
| 6260 | ASTUnit::ConcurrencyCheck Check(*CXXUnit); |
| 6261 | |
| 6262 | SourceRange R = cxloc::translateCXSourceRange(Range); |
| 6263 | if (R.isInvalid()) |
| 6264 | return; |
| 6265 | |
| 6266 | SmallVector<CXToken, 32> CXTokens; |
| 6267 | getTokens(CXXUnit, R, CXTokens); |
| 6268 | |
| 6269 | if (CXTokens.empty()) |
| 6270 | return; |
| 6271 | |
| 6272 | *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size()); |
| 6273 | memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size()); |
| 6274 | *NumTokens = CXTokens.size(); |
| 6275 | } |
| 6276 | |
| 6277 | void clang_disposeTokens(CXTranslationUnit TU, |
| 6278 | CXToken *Tokens, unsigned NumTokens) { |
| 6279 | free(Tokens); |
| 6280 | } |
| 6281 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6282 | //===----------------------------------------------------------------------===// |
| 6283 | // Token annotation APIs. |
| 6284 | //===----------------------------------------------------------------------===// |
| 6285 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6286 | static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor, |
| 6287 | CXCursor parent, |
| 6288 | CXClientData client_data); |
| 6289 | static bool AnnotateTokensPostChildrenVisitor(CXCursor cursor, |
| 6290 | CXClientData client_data); |
| 6291 | |
| 6292 | namespace { |
| 6293 | class AnnotateTokensWorker { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6294 | CXToken *Tokens; |
| 6295 | CXCursor *Cursors; |
| 6296 | unsigned NumTokens; |
| 6297 | unsigned TokIdx; |
| 6298 | unsigned PreprocessingTokIdx; |
| 6299 | CursorVisitor AnnotateVis; |
| 6300 | SourceManager &SrcMgr; |
| 6301 | bool HasContextSensitiveKeywords; |
| 6302 | |
| 6303 | struct PostChildrenInfo { |
| 6304 | CXCursor Cursor; |
| 6305 | SourceRange CursorRange; |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6306 | unsigned BeforeReachingCursorIdx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6307 | unsigned BeforeChildrenTokenIdx; |
| 6308 | }; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 6309 | SmallVector<PostChildrenInfo, 8> PostChildrenInfos; |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6310 | |
| 6311 | CXToken &getTok(unsigned Idx) { |
| 6312 | assert(Idx < NumTokens); |
| 6313 | return Tokens[Idx]; |
| 6314 | } |
| 6315 | const CXToken &getTok(unsigned Idx) const { |
| 6316 | assert(Idx < NumTokens); |
| 6317 | return Tokens[Idx]; |
| 6318 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6319 | bool MoreTokens() const { return TokIdx < NumTokens; } |
| 6320 | unsigned NextToken() const { return TokIdx; } |
| 6321 | void AdvanceToken() { ++TokIdx; } |
| 6322 | SourceLocation GetTokenLoc(unsigned tokI) { |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6323 | return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6324 | } |
| 6325 | bool isFunctionMacroToken(unsigned tokI) const { |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6326 | return getTok(tokI).int_data[3] != 0; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6327 | } |
| 6328 | SourceLocation getFunctionMacroTokenLoc(unsigned tokI) const { |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6329 | return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[3]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | void annotateAndAdvanceTokens(CXCursor, RangeComparisonResult, SourceRange); |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6333 | bool annotateAndAdvanceFunctionMacroTokens(CXCursor, RangeComparisonResult, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6334 | SourceRange); |
| 6335 | |
| 6336 | public: |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6337 | AnnotateTokensWorker(CXToken *tokens, CXCursor *cursors, unsigned numTokens, |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6338 | CXTranslationUnit TU, SourceRange RegionOfInterest) |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6339 | : Tokens(tokens), Cursors(cursors), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6340 | NumTokens(numTokens), TokIdx(0), PreprocessingTokIdx(0), |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6341 | AnnotateVis(TU, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6342 | AnnotateTokensVisitor, this, |
| 6343 | /*VisitPreprocessorLast=*/true, |
| 6344 | /*VisitIncludedEntities=*/false, |
| 6345 | RegionOfInterest, |
| 6346 | /*VisitDeclsOnly=*/false, |
| 6347 | AnnotateTokensPostChildrenVisitor), |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6348 | SrcMgr(cxtu::getASTUnit(TU)->getSourceManager()), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6349 | HasContextSensitiveKeywords(false) { } |
| 6350 | |
| 6351 | void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); } |
| 6352 | enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent); |
| 6353 | bool postVisitChildren(CXCursor cursor); |
| 6354 | void AnnotateTokens(); |
| 6355 | |
| 6356 | /// \brief Determine whether the annotator saw any cursors that have |
| 6357 | /// context-sensitive keywords. |
| 6358 | bool hasContextSensitiveKeywords() const { |
| 6359 | return HasContextSensitiveKeywords; |
| 6360 | } |
| 6361 | |
| 6362 | ~AnnotateTokensWorker() { |
| 6363 | assert(PostChildrenInfos.empty()); |
| 6364 | } |
| 6365 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6366 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6367 | |
| 6368 | void AnnotateTokensWorker::AnnotateTokens() { |
| 6369 | // Walk the AST within the region of interest, annotating tokens |
| 6370 | // along the way. |
| 6371 | AnnotateVis.visitFileRegion(); |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6372 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6373 | |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6374 | static inline void updateCursorAnnotation(CXCursor &Cursor, |
| 6375 | const CXCursor &updateC) { |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6376 | if (clang_isInvalid(updateC.kind) || !clang_isInvalid(Cursor.kind)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6377 | return; |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6378 | Cursor = updateC; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6379 | } |
| 6380 | |
| 6381 | /// \brief It annotates and advances tokens with a cursor until the comparison |
| 6382 | //// between the cursor location and the source range is the same as |
| 6383 | /// \arg compResult. |
| 6384 | /// |
| 6385 | /// Pass RangeBefore to annotate tokens with a cursor until a range is reached. |
| 6386 | /// Pass RangeOverlap to annotate tokens inside a range. |
| 6387 | void AnnotateTokensWorker::annotateAndAdvanceTokens(CXCursor updateC, |
| 6388 | RangeComparisonResult compResult, |
| 6389 | SourceRange range) { |
| 6390 | while (MoreTokens()) { |
| 6391 | const unsigned I = NextToken(); |
| 6392 | if (isFunctionMacroToken(I)) |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6393 | if (!annotateAndAdvanceFunctionMacroTokens(updateC, compResult, range)) |
| 6394 | return; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6395 | |
| 6396 | SourceLocation TokLoc = GetTokenLoc(I); |
| 6397 | if (LocationCompare(SrcMgr, TokLoc, range) == compResult) { |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6398 | updateCursorAnnotation(Cursors[I], updateC); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6399 | AdvanceToken(); |
| 6400 | continue; |
| 6401 | } |
| 6402 | break; |
| 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | /// \brief Special annotation handling for macro argument tokens. |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6407 | /// \returns true if it advanced beyond all macro tokens, false otherwise. |
| 6408 | bool AnnotateTokensWorker::annotateAndAdvanceFunctionMacroTokens( |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6409 | CXCursor updateC, |
| 6410 | RangeComparisonResult compResult, |
| 6411 | SourceRange range) { |
| 6412 | assert(MoreTokens()); |
| 6413 | assert(isFunctionMacroToken(NextToken()) && |
| 6414 | "Should be called only for macro arg tokens"); |
| 6415 | |
| 6416 | // This works differently than annotateAndAdvanceTokens; because expanded |
| 6417 | // macro arguments can have arbitrary translation-unit source order, we do not |
| 6418 | // advance the token index one by one until a token fails the range test. |
| 6419 | // We only advance once past all of the macro arg tokens if all of them |
| 6420 | // pass the range test. If one of them fails we keep the token index pointing |
| 6421 | // at the start of the macro arg tokens so that the failing token will be |
| 6422 | // annotated by a subsequent annotation try. |
| 6423 | |
| 6424 | bool atLeastOneCompFail = false; |
| 6425 | |
| 6426 | unsigned I = NextToken(); |
| 6427 | for (; I < NumTokens && isFunctionMacroToken(I); ++I) { |
| 6428 | SourceLocation TokLoc = getFunctionMacroTokenLoc(I); |
| 6429 | if (TokLoc.isFileID()) |
| 6430 | continue; // not macro arg token, it's parens or comma. |
| 6431 | if (LocationCompare(SrcMgr, TokLoc, range) == compResult) { |
| 6432 | if (clang_isInvalid(clang_getCursorKind(Cursors[I]))) |
| 6433 | Cursors[I] = updateC; |
| 6434 | } else |
| 6435 | atLeastOneCompFail = true; |
| 6436 | } |
| 6437 | |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6438 | if (atLeastOneCompFail) |
| 6439 | return false; |
| 6440 | |
| 6441 | TokIdx = I; // All of the tokens were handled, advance beyond all of them. |
| 6442 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | enum CXChildVisitResult |
| 6446 | AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6447 | SourceRange cursorRange = getRawCursorExtent(cursor); |
| 6448 | if (cursorRange.isInvalid()) |
| 6449 | return CXChildVisit_Recurse; |
| 6450 | |
| 6451 | if (!HasContextSensitiveKeywords) { |
| 6452 | // Objective-C properties can have context-sensitive keywords. |
| 6453 | if (cursor.kind == CXCursor_ObjCPropertyDecl) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 6454 | if (const ObjCPropertyDecl *Property |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6455 | = dyn_cast_or_null<ObjCPropertyDecl>(getCursorDecl(cursor))) |
| 6456 | HasContextSensitiveKeywords = Property->getPropertyAttributesAsWritten() != 0; |
| 6457 | } |
| 6458 | // Objective-C methods can have context-sensitive keywords. |
| 6459 | else if (cursor.kind == CXCursor_ObjCInstanceMethodDecl || |
| 6460 | cursor.kind == CXCursor_ObjCClassMethodDecl) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 6461 | if (const ObjCMethodDecl *Method |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6462 | = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor))) { |
| 6463 | if (Method->getObjCDeclQualifier()) |
| 6464 | HasContextSensitiveKeywords = true; |
| 6465 | else { |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 6466 | for (const auto *P : Method->parameters()) { |
Aaron Ballman | 43b68be | 2014-03-07 17:50:17 +0000 | [diff] [blame] | 6467 | if (P->getObjCDeclQualifier()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6468 | HasContextSensitiveKeywords = true; |
| 6469 | break; |
| 6470 | } |
| 6471 | } |
| 6472 | } |
| 6473 | } |
| 6474 | } |
| 6475 | // C++ methods can have context-sensitive keywords. |
| 6476 | else if (cursor.kind == CXCursor_CXXMethod) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 6477 | if (const CXXMethodDecl *Method |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6478 | = dyn_cast_or_null<CXXMethodDecl>(getCursorDecl(cursor))) { |
| 6479 | if (Method->hasAttr<FinalAttr>() || Method->hasAttr<OverrideAttr>()) |
| 6480 | HasContextSensitiveKeywords = true; |
| 6481 | } |
| 6482 | } |
| 6483 | // C++ classes can have context-sensitive keywords. |
| 6484 | else if (cursor.kind == CXCursor_StructDecl || |
| 6485 | cursor.kind == CXCursor_ClassDecl || |
| 6486 | cursor.kind == CXCursor_ClassTemplate || |
| 6487 | cursor.kind == CXCursor_ClassTemplatePartialSpecialization) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 6488 | if (const Decl *D = getCursorDecl(cursor)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6489 | if (D->hasAttr<FinalAttr>()) |
| 6490 | HasContextSensitiveKeywords = true; |
| 6491 | } |
| 6492 | } |
Argyrios Kyrtzidis | 990b386 | 2013-06-04 18:24:30 +0000 | [diff] [blame] | 6493 | |
| 6494 | // Don't override a property annotation with its getter/setter method. |
| 6495 | if (cursor.kind == CXCursor_ObjCInstanceMethodDecl && |
| 6496 | parent.kind == CXCursor_ObjCPropertyDecl) |
| 6497 | return CXChildVisit_Continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6498 | |
| 6499 | if (clang_isPreprocessing(cursor.kind)) { |
| 6500 | // Items in the preprocessing record are kept separate from items in |
| 6501 | // declarations, so we keep a separate token index. |
| 6502 | unsigned SavedTokIdx = TokIdx; |
| 6503 | TokIdx = PreprocessingTokIdx; |
| 6504 | |
| 6505 | // Skip tokens up until we catch up to the beginning of the preprocessing |
| 6506 | // entry. |
| 6507 | while (MoreTokens()) { |
| 6508 | const unsigned I = NextToken(); |
| 6509 | SourceLocation TokLoc = GetTokenLoc(I); |
| 6510 | switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) { |
| 6511 | case RangeBefore: |
| 6512 | AdvanceToken(); |
| 6513 | continue; |
| 6514 | case RangeAfter: |
| 6515 | case RangeOverlap: |
| 6516 | break; |
| 6517 | } |
| 6518 | break; |
| 6519 | } |
| 6520 | |
| 6521 | // Look at all of the tokens within this range. |
| 6522 | while (MoreTokens()) { |
| 6523 | const unsigned I = NextToken(); |
| 6524 | SourceLocation TokLoc = GetTokenLoc(I); |
| 6525 | switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) { |
| 6526 | case RangeBefore: |
| 6527 | llvm_unreachable("Infeasible"); |
| 6528 | case RangeAfter: |
| 6529 | break; |
| 6530 | case RangeOverlap: |
Argyrios Kyrtzidis | 5d47a9b | 2013-02-13 18:33:28 +0000 | [diff] [blame] | 6531 | // For macro expansions, just note where the beginning of the macro |
| 6532 | // expansion occurs. |
| 6533 | if (cursor.kind == CXCursor_MacroExpansion) { |
| 6534 | if (TokLoc == cursorRange.getBegin()) |
| 6535 | Cursors[I] = cursor; |
| 6536 | AdvanceToken(); |
| 6537 | break; |
| 6538 | } |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6539 | // We may have already annotated macro names inside macro definitions. |
| 6540 | if (Cursors[I].kind != CXCursor_MacroExpansion) |
| 6541 | Cursors[I] = cursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6542 | AdvanceToken(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6543 | continue; |
| 6544 | } |
| 6545 | break; |
| 6546 | } |
| 6547 | |
| 6548 | // Save the preprocessing token index; restore the non-preprocessing |
| 6549 | // token index. |
| 6550 | PreprocessingTokIdx = TokIdx; |
| 6551 | TokIdx = SavedTokIdx; |
| 6552 | return CXChildVisit_Recurse; |
| 6553 | } |
| 6554 | |
| 6555 | if (cursorRange.isInvalid()) |
| 6556 | return CXChildVisit_Continue; |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6557 | |
| 6558 | unsigned BeforeReachingCursorIdx = NextToken(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6559 | const enum CXCursorKind cursorK = clang_getCursorKind(cursor); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6560 | const enum CXCursorKind K = clang_getCursorKind(parent); |
| 6561 | const CXCursor updateC = |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6562 | (clang_isInvalid(K) || K == CXCursor_TranslationUnit || |
| 6563 | // Attributes are annotated out-of-order, skip tokens until we reach it. |
| 6564 | clang_isAttribute(cursor.kind)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6565 | ? clang_getNullCursor() : parent; |
| 6566 | |
| 6567 | annotateAndAdvanceTokens(updateC, RangeBefore, cursorRange); |
| 6568 | |
| 6569 | // Avoid having the cursor of an expression "overwrite" the annotation of the |
| 6570 | // variable declaration that it belongs to. |
| 6571 | // This can happen for C++ constructor expressions whose range generally |
| 6572 | // include the variable declaration, e.g.: |
| 6573 | // MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor. |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6574 | if (clang_isExpression(cursorK) && MoreTokens()) { |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 6575 | const Expr *E = getCursorExpr(cursor); |
Dmitri Gribenko | a169118 | 2013-01-26 18:12:08 +0000 | [diff] [blame] | 6576 | if (const Decl *D = getCursorParentDecl(cursor)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6577 | const unsigned I = NextToken(); |
| 6578 | if (E->getLocStart().isValid() && D->getLocation().isValid() && |
| 6579 | E->getLocStart() == D->getLocation() && |
| 6580 | E->getLocStart() == GetTokenLoc(I)) { |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6581 | updateCursorAnnotation(Cursors[I], updateC); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6582 | AdvanceToken(); |
| 6583 | } |
| 6584 | } |
| 6585 | } |
| 6586 | |
| 6587 | // Before recursing into the children keep some state that we are going |
| 6588 | // to use in the AnnotateTokensWorker::postVisitChildren callback to do some |
| 6589 | // extra work after the child nodes are visited. |
| 6590 | // Note that we don't call VisitChildren here to avoid traversing statements |
| 6591 | // code-recursively which can blow the stack. |
| 6592 | |
| 6593 | PostChildrenInfo Info; |
| 6594 | Info.Cursor = cursor; |
| 6595 | Info.CursorRange = cursorRange; |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6596 | Info.BeforeReachingCursorIdx = BeforeReachingCursorIdx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6597 | Info.BeforeChildrenTokenIdx = NextToken(); |
| 6598 | PostChildrenInfos.push_back(Info); |
| 6599 | |
| 6600 | return CXChildVisit_Recurse; |
| 6601 | } |
| 6602 | |
| 6603 | bool AnnotateTokensWorker::postVisitChildren(CXCursor cursor) { |
| 6604 | if (PostChildrenInfos.empty()) |
| 6605 | return false; |
| 6606 | const PostChildrenInfo &Info = PostChildrenInfos.back(); |
| 6607 | if (!clang_equalCursors(Info.Cursor, cursor)) |
| 6608 | return false; |
| 6609 | |
| 6610 | const unsigned BeforeChildren = Info.BeforeChildrenTokenIdx; |
| 6611 | const unsigned AfterChildren = NextToken(); |
| 6612 | SourceRange cursorRange = Info.CursorRange; |
| 6613 | |
| 6614 | // Scan the tokens that are at the end of the cursor, but are not captured |
| 6615 | // but the child cursors. |
| 6616 | annotateAndAdvanceTokens(cursor, RangeOverlap, cursorRange); |
| 6617 | |
| 6618 | // Scan the tokens that are at the beginning of the cursor, but are not |
| 6619 | // capture by the child cursors. |
| 6620 | for (unsigned I = BeforeChildren; I != AfterChildren; ++I) { |
| 6621 | if (!clang_isInvalid(clang_getCursorKind(Cursors[I]))) |
| 6622 | break; |
| 6623 | |
| 6624 | Cursors[I] = cursor; |
| 6625 | } |
| 6626 | |
Argyrios Kyrtzidis | a2ed813 | 2013-02-08 01:12:25 +0000 | [diff] [blame] | 6627 | // Attributes are annotated out-of-order, rewind TokIdx to when we first |
| 6628 | // encountered the attribute cursor. |
| 6629 | if (clang_isAttribute(cursor.kind)) |
| 6630 | TokIdx = Info.BeforeReachingCursorIdx; |
| 6631 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6632 | PostChildrenInfos.pop_back(); |
| 6633 | return false; |
| 6634 | } |
| 6635 | |
| 6636 | static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor, |
| 6637 | CXCursor parent, |
| 6638 | CXClientData client_data) { |
| 6639 | return static_cast<AnnotateTokensWorker*>(client_data)->Visit(cursor, parent); |
| 6640 | } |
| 6641 | |
| 6642 | static bool AnnotateTokensPostChildrenVisitor(CXCursor cursor, |
| 6643 | CXClientData client_data) { |
| 6644 | return static_cast<AnnotateTokensWorker*>(client_data)-> |
| 6645 | postVisitChildren(cursor); |
| 6646 | } |
| 6647 | |
| 6648 | namespace { |
| 6649 | |
| 6650 | /// \brief Uses the macro expansions in the preprocessing record to find |
| 6651 | /// and mark tokens that are macro arguments. This info is used by the |
| 6652 | /// AnnotateTokensWorker. |
| 6653 | class MarkMacroArgTokensVisitor { |
| 6654 | SourceManager &SM; |
| 6655 | CXToken *Tokens; |
| 6656 | unsigned NumTokens; |
| 6657 | unsigned CurIdx; |
| 6658 | |
| 6659 | public: |
| 6660 | MarkMacroArgTokensVisitor(SourceManager &SM, |
| 6661 | CXToken *tokens, unsigned numTokens) |
| 6662 | : SM(SM), Tokens(tokens), NumTokens(numTokens), CurIdx(0) { } |
| 6663 | |
| 6664 | CXChildVisitResult visit(CXCursor cursor, CXCursor parent) { |
| 6665 | if (cursor.kind != CXCursor_MacroExpansion) |
| 6666 | return CXChildVisit_Continue; |
| 6667 | |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 6668 | SourceRange macroRange = getCursorMacroExpansion(cursor).getSourceRange(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6669 | if (macroRange.getBegin() == macroRange.getEnd()) |
| 6670 | return CXChildVisit_Continue; // it's not a function macro. |
| 6671 | |
| 6672 | for (; CurIdx < NumTokens; ++CurIdx) { |
| 6673 | if (!SM.isBeforeInTranslationUnit(getTokenLoc(CurIdx), |
| 6674 | macroRange.getBegin())) |
| 6675 | break; |
| 6676 | } |
| 6677 | |
| 6678 | if (CurIdx == NumTokens) |
| 6679 | return CXChildVisit_Break; |
| 6680 | |
| 6681 | for (; CurIdx < NumTokens; ++CurIdx) { |
| 6682 | SourceLocation tokLoc = getTokenLoc(CurIdx); |
| 6683 | if (!SM.isBeforeInTranslationUnit(tokLoc, macroRange.getEnd())) |
| 6684 | break; |
| 6685 | |
| 6686 | setFunctionMacroTokenLoc(CurIdx, SM.getMacroArgExpandedLocation(tokLoc)); |
| 6687 | } |
| 6688 | |
| 6689 | if (CurIdx == NumTokens) |
| 6690 | return CXChildVisit_Break; |
| 6691 | |
| 6692 | return CXChildVisit_Continue; |
| 6693 | } |
| 6694 | |
| 6695 | private: |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6696 | CXToken &getTok(unsigned Idx) { |
| 6697 | assert(Idx < NumTokens); |
| 6698 | return Tokens[Idx]; |
| 6699 | } |
| 6700 | const CXToken &getTok(unsigned Idx) const { |
| 6701 | assert(Idx < NumTokens); |
| 6702 | return Tokens[Idx]; |
| 6703 | } |
| 6704 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6705 | SourceLocation getTokenLoc(unsigned tokI) { |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6706 | return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | void setFunctionMacroTokenLoc(unsigned tokI, SourceLocation loc) { |
| 6710 | // The third field is reserved and currently not used. Use it here |
| 6711 | // to mark macro arg expanded tokens with their expanded locations. |
Argyrios Kyrtzidis | 50126f1 | 2013-11-27 05:50:55 +0000 | [diff] [blame] | 6712 | getTok(tokI).int_data[3] = loc.getRawEncoding(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6713 | } |
| 6714 | }; |
| 6715 | |
| 6716 | } // end anonymous namespace |
| 6717 | |
| 6718 | static CXChildVisitResult |
| 6719 | MarkMacroArgTokensVisitorDelegate(CXCursor cursor, CXCursor parent, |
| 6720 | CXClientData client_data) { |
| 6721 | return static_cast<MarkMacroArgTokensVisitor*>(client_data)->visit(cursor, |
| 6722 | parent); |
| 6723 | } |
| 6724 | |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6725 | /// \brief Used by \c annotatePreprocessorTokens. |
| 6726 | /// \returns true if lexing was finished, false otherwise. |
| 6727 | static bool lexNext(Lexer &Lex, Token &Tok, |
| 6728 | unsigned &NextIdx, unsigned NumTokens) { |
| 6729 | if (NextIdx >= NumTokens) |
| 6730 | return true; |
| 6731 | |
| 6732 | ++NextIdx; |
| 6733 | Lex.LexFromRawLexer(Tok); |
Alexander Kornienko | 1a9f184 | 2015-12-28 15:24:08 +0000 | [diff] [blame] | 6734 | return Tok.is(tok::eof); |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6735 | } |
| 6736 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6737 | static void annotatePreprocessorTokens(CXTranslationUnit TU, |
| 6738 | SourceRange RegionOfInterest, |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6739 | CXCursor *Cursors, |
| 6740 | CXToken *Tokens, |
| 6741 | unsigned NumTokens) { |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6742 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6743 | |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6744 | Preprocessor &PP = CXXUnit->getPreprocessor(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6745 | SourceManager &SourceMgr = CXXUnit->getSourceManager(); |
| 6746 | std::pair<FileID, unsigned> BeginLocInfo |
Argyrios Kyrtzidis | 5d47a9b | 2013-02-13 18:33:28 +0000 | [diff] [blame] | 6747 | = SourceMgr.getDecomposedSpellingLoc(RegionOfInterest.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6748 | std::pair<FileID, unsigned> EndLocInfo |
Argyrios Kyrtzidis | 5d47a9b | 2013-02-13 18:33:28 +0000 | [diff] [blame] | 6749 | = SourceMgr.getDecomposedSpellingLoc(RegionOfInterest.getEnd()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6750 | |
| 6751 | if (BeginLocInfo.first != EndLocInfo.first) |
| 6752 | return; |
| 6753 | |
| 6754 | StringRef Buffer; |
| 6755 | bool Invalid = false; |
| 6756 | Buffer = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid); |
| 6757 | if (Buffer.empty() || Invalid) |
| 6758 | return; |
| 6759 | |
| 6760 | Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first), |
| 6761 | CXXUnit->getASTContext().getLangOpts(), |
| 6762 | Buffer.begin(), Buffer.data() + BeginLocInfo.second, |
| 6763 | Buffer.end()); |
| 6764 | Lex.SetCommentRetentionState(true); |
| 6765 | |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6766 | unsigned NextIdx = 0; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6767 | // Lex tokens in raw mode until we hit the end of the range, to avoid |
| 6768 | // entering #includes or expanding macros. |
| 6769 | while (true) { |
| 6770 | Token Tok; |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6771 | if (lexNext(Lex, Tok, NextIdx, NumTokens)) |
| 6772 | break; |
| 6773 | unsigned TokIdx = NextIdx-1; |
| 6774 | assert(Tok.getLocation() == |
| 6775 | SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6776 | |
| 6777 | reprocess: |
| 6778 | if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) { |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6779 | // We have found a preprocessing directive. Annotate the tokens |
| 6780 | // appropriately. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6781 | // |
| 6782 | // FIXME: Some simple tests here could identify macro definitions and |
| 6783 | // #undefs, to provide specific cursor kinds for those. |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6784 | |
| 6785 | SourceLocation BeginLoc = Tok.getLocation(); |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6786 | if (lexNext(Lex, Tok, NextIdx, NumTokens)) |
| 6787 | break; |
| 6788 | |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 6789 | MacroInfo *MI = nullptr; |
Alp Toker | 2d57cea | 2014-05-17 04:53:25 +0000 | [diff] [blame] | 6790 | if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "define") { |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6791 | if (lexNext(Lex, Tok, NextIdx, NumTokens)) |
| 6792 | break; |
| 6793 | |
| 6794 | if (Tok.is(tok::raw_identifier)) { |
Alp Toker | 2d57cea | 2014-05-17 04:53:25 +0000 | [diff] [blame] | 6795 | IdentifierInfo &II = |
| 6796 | PP.getIdentifierTable().get(Tok.getRawIdentifier()); |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6797 | SourceLocation MappedTokLoc = |
| 6798 | CXXUnit->mapLocationToPreamble(Tok.getLocation()); |
| 6799 | MI = getMacroInfo(II, MappedTokLoc, TU); |
| 6800 | } |
| 6801 | } |
| 6802 | |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6803 | bool finished = false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6804 | do { |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6805 | if (lexNext(Lex, Tok, NextIdx, NumTokens)) { |
| 6806 | finished = true; |
| 6807 | break; |
| 6808 | } |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6809 | // If we are in a macro definition, check if the token was ever a |
| 6810 | // macro name and annotate it if that's the case. |
| 6811 | if (MI) { |
| 6812 | SourceLocation SaveLoc = Tok.getLocation(); |
| 6813 | Tok.setLocation(CXXUnit->mapLocationToPreamble(SaveLoc)); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 6814 | MacroDefinitionRecord *MacroDef = |
| 6815 | checkForMacroInMacroDefinition(MI, Tok, TU); |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6816 | Tok.setLocation(SaveLoc); |
| 6817 | if (MacroDef) |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 6818 | Cursors[NextIdx - 1] = |
| 6819 | MakeMacroExpansionCursor(MacroDef, Tok.getLocation(), TU); |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6820 | } |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6821 | } while (!Tok.isAtStartOfLine()); |
| 6822 | |
| 6823 | unsigned LastIdx = finished ? NextIdx-1 : NextIdx-2; |
| 6824 | assert(TokIdx <= LastIdx); |
| 6825 | SourceLocation EndLoc = |
| 6826 | SourceLocation::getFromRawEncoding(Tokens[LastIdx].int_data[1]); |
| 6827 | CXCursor Cursor = |
| 6828 | MakePreprocessingDirectiveCursor(SourceRange(BeginLoc, EndLoc), TU); |
| 6829 | |
| 6830 | for (; TokIdx <= LastIdx; ++TokIdx) |
Argyrios Kyrtzidis | 68d31ce | 2013-01-07 19:16:32 +0000 | [diff] [blame] | 6831 | updateCursorAnnotation(Cursors[TokIdx], Cursor); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6832 | |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6833 | if (finished) |
| 6834 | break; |
| 6835 | goto reprocess; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6836 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | // This gets run a separate thread to avoid stack blowout. |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 6841 | static void clang_annotateTokensImpl(CXTranslationUnit TU, ASTUnit *CXXUnit, |
| 6842 | CXToken *Tokens, unsigned NumTokens, |
| 6843 | CXCursor *Cursors) { |
Dmitri Gribenko | 183436e | 2013-01-26 21:49:50 +0000 | [diff] [blame] | 6844 | CIndexer *CXXIdx = TU->CIdx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6845 | if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing)) |
| 6846 | setThreadBackgroundPriority(); |
| 6847 | |
| 6848 | // Determine the region of interest, which contains all of the tokens. |
| 6849 | SourceRange RegionOfInterest; |
| 6850 | RegionOfInterest.setBegin( |
| 6851 | cxloc::translateSourceLocation(clang_getTokenLocation(TU, Tokens[0]))); |
| 6852 | RegionOfInterest.setEnd( |
| 6853 | cxloc::translateSourceLocation(clang_getTokenLocation(TU, |
| 6854 | Tokens[NumTokens-1]))); |
| 6855 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6856 | // Relex the tokens within the source range to look for preprocessing |
| 6857 | // directives. |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6858 | annotatePreprocessorTokens(TU, RegionOfInterest, Cursors, Tokens, NumTokens); |
Argyrios Kyrtzidis | 5d47a9b | 2013-02-13 18:33:28 +0000 | [diff] [blame] | 6859 | |
| 6860 | // If begin location points inside a macro argument, set it to the expansion |
| 6861 | // location so we can have the full context when annotating semantically. |
| 6862 | { |
| 6863 | SourceManager &SM = CXXUnit->getSourceManager(); |
| 6864 | SourceLocation Loc = |
| 6865 | SM.getMacroArgExpandedLocation(RegionOfInterest.getBegin()); |
| 6866 | if (Loc.isMacroID()) |
| 6867 | RegionOfInterest.setBegin(SM.getExpansionLoc(Loc)); |
| 6868 | } |
| 6869 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6870 | if (CXXUnit->getPreprocessor().getPreprocessingRecord()) { |
| 6871 | // Search and mark tokens that are macro argument expansions. |
| 6872 | MarkMacroArgTokensVisitor Visitor(CXXUnit->getSourceManager(), |
| 6873 | Tokens, NumTokens); |
| 6874 | CursorVisitor MacroArgMarker(TU, |
| 6875 | MarkMacroArgTokensVisitorDelegate, &Visitor, |
| 6876 | /*VisitPreprocessorLast=*/true, |
| 6877 | /*VisitIncludedEntities=*/false, |
| 6878 | RegionOfInterest); |
| 6879 | MacroArgMarker.visitPreprocessedEntitiesInRegion(); |
| 6880 | } |
| 6881 | |
| 6882 | // Annotate all of the source locations in the region of interest that map to |
| 6883 | // a specific cursor. |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 6884 | AnnotateTokensWorker W(Tokens, Cursors, NumTokens, TU, RegionOfInterest); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6885 | |
| 6886 | // FIXME: We use a ridiculous stack size here because the data-recursion |
| 6887 | // algorithm uses a large stack frame than the non-data recursive version, |
| 6888 | // and AnnotationTokensWorker currently transforms the data-recursion |
| 6889 | // algorithm back into a traditional recursion by explicitly calling |
| 6890 | // VisitChildren(). We will need to remove this explicit recursive call. |
| 6891 | W.AnnotateTokens(); |
| 6892 | |
| 6893 | // If we ran into any entities that involve context-sensitive keywords, |
| 6894 | // take another pass through the tokens to mark them as such. |
| 6895 | if (W.hasContextSensitiveKeywords()) { |
| 6896 | for (unsigned I = 0; I != NumTokens; ++I) { |
| 6897 | if (clang_getTokenKind(Tokens[I]) != CXToken_Identifier) |
| 6898 | continue; |
| 6899 | |
| 6900 | if (Cursors[I].kind == CXCursor_ObjCPropertyDecl) { |
| 6901 | IdentifierInfo *II = static_cast<IdentifierInfo *>(Tokens[I].ptr_data); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 6902 | if (const ObjCPropertyDecl *Property |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6903 | = dyn_cast_or_null<ObjCPropertyDecl>(getCursorDecl(Cursors[I]))) { |
| 6904 | if (Property->getPropertyAttributesAsWritten() != 0 && |
| 6905 | llvm::StringSwitch<bool>(II->getName()) |
| 6906 | .Case("readonly", true) |
| 6907 | .Case("assign", true) |
| 6908 | .Case("unsafe_unretained", true) |
| 6909 | .Case("readwrite", true) |
| 6910 | .Case("retain", true) |
| 6911 | .Case("copy", true) |
| 6912 | .Case("nonatomic", true) |
| 6913 | .Case("atomic", true) |
| 6914 | .Case("getter", true) |
| 6915 | .Case("setter", true) |
| 6916 | .Case("strong", true) |
| 6917 | .Case("weak", true) |
Manman Ren | 04fd4d8 | 2016-05-31 23:22:04 +0000 | [diff] [blame] | 6918 | .Case("class", true) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6919 | .Default(false)) |
| 6920 | Tokens[I].int_data[0] = CXToken_Keyword; |
| 6921 | } |
| 6922 | continue; |
| 6923 | } |
| 6924 | |
| 6925 | if (Cursors[I].kind == CXCursor_ObjCInstanceMethodDecl || |
| 6926 | Cursors[I].kind == CXCursor_ObjCClassMethodDecl) { |
| 6927 | IdentifierInfo *II = static_cast<IdentifierInfo *>(Tokens[I].ptr_data); |
| 6928 | if (llvm::StringSwitch<bool>(II->getName()) |
| 6929 | .Case("in", true) |
| 6930 | .Case("out", true) |
| 6931 | .Case("inout", true) |
| 6932 | .Case("oneway", true) |
| 6933 | .Case("bycopy", true) |
| 6934 | .Case("byref", true) |
| 6935 | .Default(false)) |
| 6936 | Tokens[I].int_data[0] = CXToken_Keyword; |
| 6937 | continue; |
| 6938 | } |
| 6939 | |
| 6940 | if (Cursors[I].kind == CXCursor_CXXFinalAttr || |
| 6941 | Cursors[I].kind == CXCursor_CXXOverrideAttr) { |
| 6942 | Tokens[I].int_data[0] = CXToken_Keyword; |
| 6943 | continue; |
| 6944 | } |
| 6945 | } |
| 6946 | } |
| 6947 | } |
| 6948 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6949 | void clang_annotateTokens(CXTranslationUnit TU, |
| 6950 | CXToken *Tokens, unsigned NumTokens, |
| 6951 | CXCursor *Cursors) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 6952 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 6953 | LOG_BAD_TU(TU); |
| 6954 | return; |
| 6955 | } |
| 6956 | if (NumTokens == 0 || !Tokens || !Cursors) { |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 6957 | LOG_FUNC_SECTION { *Log << "<null input>"; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6958 | return; |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | LOG_FUNC_SECTION { |
| 6962 | *Log << TU << ' '; |
| 6963 | CXSourceLocation bloc = clang_getTokenLocation(TU, Tokens[0]); |
| 6964 | CXSourceLocation eloc = clang_getTokenLocation(TU, Tokens[NumTokens-1]); |
| 6965 | *Log << clang_getRange(bloc, eloc); |
| 6966 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6967 | |
| 6968 | // Any token we don't specifically annotate will have a NULL cursor. |
| 6969 | CXCursor C = clang_getNullCursor(); |
| 6970 | for (unsigned I = 0; I != NumTokens; ++I) |
| 6971 | Cursors[I] = C; |
| 6972 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 6973 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6974 | if (!CXXUnit) |
| 6975 | return; |
| 6976 | |
| 6977 | ASTUnit::ConcurrencyCheck Check(*CXXUnit); |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 6978 | |
| 6979 | auto AnnotateTokensImpl = [=]() { |
| 6980 | clang_annotateTokensImpl(TU, CXXUnit, Tokens, NumTokens, Cursors); |
| 6981 | }; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6982 | llvm::CrashRecoveryContext CRC; |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 6983 | if (!RunSafely(CRC, AnnotateTokensImpl, GetSafetyThreadStackSize() * 2)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6984 | fprintf(stderr, "libclang: crash detected while annotating tokens\n"); |
| 6985 | } |
| 6986 | } |
| 6987 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6988 | //===----------------------------------------------------------------------===// |
| 6989 | // Operations for querying linkage of a cursor. |
| 6990 | //===----------------------------------------------------------------------===// |
| 6991 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6992 | CXLinkageKind clang_getCursorLinkage(CXCursor cursor) { |
| 6993 | if (!clang_isDeclaration(cursor.kind)) |
| 6994 | return CXLinkage_Invalid; |
| 6995 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 6996 | const Decl *D = cxcursor::getCursorDecl(cursor); |
| 6997 | if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D)) |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 6998 | switch (ND->getLinkageInternal()) { |
Rafael Espindola | 50df3a0 | 2013-05-25 17:16:20 +0000 | [diff] [blame] | 6999 | case NoLinkage: |
| 7000 | case VisibleNoLinkage: return CXLinkage_NoLinkage; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7001 | case InternalLinkage: return CXLinkage_Internal; |
| 7002 | case UniqueExternalLinkage: return CXLinkage_UniqueExternal; |
| 7003 | case ExternalLinkage: return CXLinkage_External; |
| 7004 | }; |
| 7005 | |
| 7006 | return CXLinkage_Invalid; |
| 7007 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7008 | |
| 7009 | //===----------------------------------------------------------------------===// |
Ehsan Akhgari | b743de7 | 2016-05-31 15:55:51 +0000 | [diff] [blame] | 7010 | // Operations for querying visibility of a cursor. |
| 7011 | //===----------------------------------------------------------------------===// |
| 7012 | |
Ehsan Akhgari | b743de7 | 2016-05-31 15:55:51 +0000 | [diff] [blame] | 7013 | CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) { |
| 7014 | if (!clang_isDeclaration(cursor.kind)) |
| 7015 | return CXVisibility_Invalid; |
| 7016 | |
| 7017 | const Decl *D = cxcursor::getCursorDecl(cursor); |
| 7018 | if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D)) |
| 7019 | switch (ND->getVisibility()) { |
| 7020 | case HiddenVisibility: return CXVisibility_Hidden; |
| 7021 | case ProtectedVisibility: return CXVisibility_Protected; |
| 7022 | case DefaultVisibility: return CXVisibility_Default; |
| 7023 | }; |
| 7024 | |
| 7025 | return CXVisibility_Invalid; |
| 7026 | } |
Ehsan Akhgari | b743de7 | 2016-05-31 15:55:51 +0000 | [diff] [blame] | 7027 | |
| 7028 | //===----------------------------------------------------------------------===// |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7029 | // Operations for querying language of a cursor. |
| 7030 | //===----------------------------------------------------------------------===// |
| 7031 | |
| 7032 | static CXLanguageKind getDeclLanguage(const Decl *D) { |
| 7033 | if (!D) |
| 7034 | return CXLanguage_C; |
| 7035 | |
| 7036 | switch (D->getKind()) { |
| 7037 | default: |
| 7038 | break; |
| 7039 | case Decl::ImplicitParam: |
| 7040 | case Decl::ObjCAtDefsField: |
| 7041 | case Decl::ObjCCategory: |
| 7042 | case Decl::ObjCCategoryImpl: |
| 7043 | case Decl::ObjCCompatibleAlias: |
| 7044 | case Decl::ObjCImplementation: |
| 7045 | case Decl::ObjCInterface: |
| 7046 | case Decl::ObjCIvar: |
| 7047 | case Decl::ObjCMethod: |
| 7048 | case Decl::ObjCProperty: |
| 7049 | case Decl::ObjCPropertyImpl: |
| 7050 | case Decl::ObjCProtocol: |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 7051 | case Decl::ObjCTypeParam: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7052 | return CXLanguage_ObjC; |
| 7053 | case Decl::CXXConstructor: |
| 7054 | case Decl::CXXConversion: |
| 7055 | case Decl::CXXDestructor: |
| 7056 | case Decl::CXXMethod: |
| 7057 | case Decl::CXXRecord: |
| 7058 | case Decl::ClassTemplate: |
| 7059 | case Decl::ClassTemplatePartialSpecialization: |
| 7060 | case Decl::ClassTemplateSpecialization: |
| 7061 | case Decl::Friend: |
| 7062 | case Decl::FriendTemplate: |
| 7063 | case Decl::FunctionTemplate: |
| 7064 | case Decl::LinkageSpec: |
| 7065 | case Decl::Namespace: |
| 7066 | case Decl::NamespaceAlias: |
| 7067 | case Decl::NonTypeTemplateParm: |
| 7068 | case Decl::StaticAssert: |
| 7069 | case Decl::TemplateTemplateParm: |
| 7070 | case Decl::TemplateTypeParm: |
| 7071 | case Decl::UnresolvedUsingTypename: |
| 7072 | case Decl::UnresolvedUsingValue: |
| 7073 | case Decl::Using: |
| 7074 | case Decl::UsingDirective: |
| 7075 | case Decl::UsingShadow: |
| 7076 | return CXLanguage_CPlusPlus; |
| 7077 | } |
| 7078 | |
| 7079 | return CXLanguage_C; |
| 7080 | } |
| 7081 | |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7082 | static CXAvailabilityKind getCursorAvailabilityForDecl(const Decl *D) { |
| 7083 | if (isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isDeleted()) |
Manuel Klimek | 8e3a7ed | 2015-09-25 17:53:16 +0000 | [diff] [blame] | 7084 | return CXAvailability_NotAvailable; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7085 | |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7086 | switch (D->getAvailability()) { |
| 7087 | case AR_Available: |
| 7088 | case AR_NotYetIntroduced: |
| 7089 | if (const EnumConstantDecl *EnumConst = dyn_cast<EnumConstantDecl>(D)) |
Benjamin Kramer | 656363d | 2013-10-15 18:53:18 +0000 | [diff] [blame] | 7090 | return getCursorAvailabilityForDecl( |
| 7091 | cast<Decl>(EnumConst->getDeclContext())); |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7092 | return CXAvailability_Available; |
| 7093 | |
| 7094 | case AR_Deprecated: |
| 7095 | return CXAvailability_Deprecated; |
| 7096 | |
| 7097 | case AR_Unavailable: |
| 7098 | return CXAvailability_NotAvailable; |
| 7099 | } |
Benjamin Kramer | 656363d | 2013-10-15 18:53:18 +0000 | [diff] [blame] | 7100 | |
| 7101 | llvm_unreachable("Unknown availability kind!"); |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7102 | } |
| 7103 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7104 | enum CXAvailabilityKind clang_getCursorAvailability(CXCursor cursor) { |
| 7105 | if (clang_isDeclaration(cursor.kind)) |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7106 | if (const Decl *D = cxcursor::getCursorDecl(cursor)) |
| 7107 | return getCursorAvailabilityForDecl(D); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7108 | |
| 7109 | return CXAvailability_Available; |
| 7110 | } |
| 7111 | |
| 7112 | static CXVersion convertVersion(VersionTuple In) { |
| 7113 | CXVersion Out = { -1, -1, -1 }; |
| 7114 | if (In.empty()) |
| 7115 | return Out; |
| 7116 | |
| 7117 | Out.Major = In.getMajor(); |
| 7118 | |
NAKAMURA Takumi | c2b5d1f | 2013-02-21 02:32:34 +0000 | [diff] [blame] | 7119 | Optional<unsigned> Minor = In.getMinor(); |
| 7120 | if (Minor.hasValue()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7121 | Out.Minor = *Minor; |
| 7122 | else |
| 7123 | return Out; |
| 7124 | |
NAKAMURA Takumi | c2b5d1f | 2013-02-21 02:32:34 +0000 | [diff] [blame] | 7125 | Optional<unsigned> Subminor = In.getSubminor(); |
| 7126 | if (Subminor.hasValue()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7127 | Out.Subminor = *Subminor; |
| 7128 | |
| 7129 | return Out; |
| 7130 | } |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7131 | |
| 7132 | static int getCursorPlatformAvailabilityForDecl(const Decl *D, |
| 7133 | int *always_deprecated, |
| 7134 | CXString *deprecated_message, |
| 7135 | int *always_unavailable, |
| 7136 | CXString *unavailable_message, |
| 7137 | CXPlatformAvailability *availability, |
| 7138 | int availability_size) { |
| 7139 | bool HadAvailAttr = false; |
| 7140 | int N = 0; |
Aaron Ballman | b97112e | 2014-03-08 22:19:01 +0000 | [diff] [blame] | 7141 | for (auto A : D->attrs()) { |
| 7142 | if (DeprecatedAttr *Deprecated = dyn_cast<DeprecatedAttr>(A)) { |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7143 | HadAvailAttr = true; |
| 7144 | if (always_deprecated) |
| 7145 | *always_deprecated = 1; |
Nico Weber | aacf031 | 2014-04-24 05:16:45 +0000 | [diff] [blame] | 7146 | if (deprecated_message) { |
Argyrios Kyrtzidis | edfe07f | 2014-04-24 06:05:40 +0000 | [diff] [blame] | 7147 | clang_disposeString(*deprecated_message); |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7148 | *deprecated_message = cxstring::createDup(Deprecated->getMessage()); |
Nico Weber | aacf031 | 2014-04-24 05:16:45 +0000 | [diff] [blame] | 7149 | } |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7150 | continue; |
| 7151 | } |
| 7152 | |
Aaron Ballman | b97112e | 2014-03-08 22:19:01 +0000 | [diff] [blame] | 7153 | if (UnavailableAttr *Unavailable = dyn_cast<UnavailableAttr>(A)) { |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7154 | HadAvailAttr = true; |
| 7155 | if (always_unavailable) |
| 7156 | *always_unavailable = 1; |
| 7157 | if (unavailable_message) { |
Argyrios Kyrtzidis | edfe07f | 2014-04-24 06:05:40 +0000 | [diff] [blame] | 7158 | clang_disposeString(*unavailable_message); |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7159 | *unavailable_message = cxstring::createDup(Unavailable->getMessage()); |
| 7160 | } |
| 7161 | continue; |
| 7162 | } |
| 7163 | |
Aaron Ballman | b97112e | 2014-03-08 22:19:01 +0000 | [diff] [blame] | 7164 | if (AvailabilityAttr *Avail = dyn_cast<AvailabilityAttr>(A)) { |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7165 | HadAvailAttr = true; |
| 7166 | if (N < availability_size) { |
| 7167 | availability[N].Platform |
| 7168 | = cxstring::createDup(Avail->getPlatform()->getName()); |
| 7169 | availability[N].Introduced = convertVersion(Avail->getIntroduced()); |
| 7170 | availability[N].Deprecated = convertVersion(Avail->getDeprecated()); |
| 7171 | availability[N].Obsoleted = convertVersion(Avail->getObsoleted()); |
| 7172 | availability[N].Unavailable = Avail->getUnavailable(); |
| 7173 | availability[N].Message = cxstring::createDup(Avail->getMessage()); |
| 7174 | } |
| 7175 | ++N; |
| 7176 | } |
| 7177 | } |
| 7178 | |
| 7179 | if (!HadAvailAttr) |
| 7180 | if (const EnumConstantDecl *EnumConst = dyn_cast<EnumConstantDecl>(D)) |
| 7181 | return getCursorPlatformAvailabilityForDecl( |
| 7182 | cast<Decl>(EnumConst->getDeclContext()), |
| 7183 | always_deprecated, |
| 7184 | deprecated_message, |
| 7185 | always_unavailable, |
| 7186 | unavailable_message, |
| 7187 | availability, |
| 7188 | availability_size); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7189 | |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7190 | return N; |
| 7191 | } |
| 7192 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7193 | int clang_getCursorPlatformAvailability(CXCursor cursor, |
| 7194 | int *always_deprecated, |
| 7195 | CXString *deprecated_message, |
| 7196 | int *always_unavailable, |
| 7197 | CXString *unavailable_message, |
| 7198 | CXPlatformAvailability *availability, |
| 7199 | int availability_size) { |
| 7200 | if (always_deprecated) |
| 7201 | *always_deprecated = 0; |
| 7202 | if (deprecated_message) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 7203 | *deprecated_message = cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7204 | if (always_unavailable) |
| 7205 | *always_unavailable = 0; |
| 7206 | if (unavailable_message) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 7207 | *unavailable_message = cxstring::createEmpty(); |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7208 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7209 | if (!clang_isDeclaration(cursor.kind)) |
| 7210 | return 0; |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7211 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7212 | const Decl *D = cxcursor::getCursorDecl(cursor); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7213 | if (!D) |
| 7214 | return 0; |
Argyrios Kyrtzidis | dc2973f | 2013-10-15 17:00:53 +0000 | [diff] [blame] | 7215 | |
| 7216 | return getCursorPlatformAvailabilityForDecl(D, always_deprecated, |
| 7217 | deprecated_message, |
| 7218 | always_unavailable, |
| 7219 | unavailable_message, |
| 7220 | availability, |
| 7221 | availability_size); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | void clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability) { |
| 7225 | clang_disposeString(availability->Platform); |
| 7226 | clang_disposeString(availability->Message); |
| 7227 | } |
| 7228 | |
| 7229 | CXLanguageKind clang_getCursorLanguage(CXCursor cursor) { |
| 7230 | if (clang_isDeclaration(cursor.kind)) |
| 7231 | return getDeclLanguage(cxcursor::getCursorDecl(cursor)); |
| 7232 | |
| 7233 | return CXLanguage_Invalid; |
| 7234 | } |
| 7235 | |
| 7236 | /// \brief If the given cursor is the "templated" declaration |
| 7237 | /// descibing a class or function template, return the class or |
| 7238 | /// function template. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7239 | static const Decl *maybeGetTemplateCursor(const Decl *D) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7240 | if (!D) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7241 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7242 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7243 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7244 | if (FunctionTemplateDecl *FunTmpl = FD->getDescribedFunctionTemplate()) |
| 7245 | return FunTmpl; |
| 7246 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7247 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7248 | if (ClassTemplateDecl *ClassTmpl = RD->getDescribedClassTemplate()) |
| 7249 | return ClassTmpl; |
| 7250 | |
| 7251 | return D; |
| 7252 | } |
| 7253 | |
Argyrios Kyrtzidis | 4e0854f | 2014-10-15 17:05:31 +0000 | [diff] [blame] | 7254 | |
| 7255 | enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor C) { |
| 7256 | StorageClass sc = SC_None; |
| 7257 | const Decl *D = getCursorDecl(C); |
| 7258 | if (D) { |
| 7259 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 7260 | sc = FD->getStorageClass(); |
| 7261 | } else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 7262 | sc = VD->getStorageClass(); |
| 7263 | } else { |
| 7264 | return CX_SC_Invalid; |
| 7265 | } |
| 7266 | } else { |
| 7267 | return CX_SC_Invalid; |
| 7268 | } |
| 7269 | switch (sc) { |
| 7270 | case SC_None: |
| 7271 | return CX_SC_None; |
| 7272 | case SC_Extern: |
| 7273 | return CX_SC_Extern; |
| 7274 | case SC_Static: |
| 7275 | return CX_SC_Static; |
| 7276 | case SC_PrivateExtern: |
| 7277 | return CX_SC_PrivateExtern; |
Argyrios Kyrtzidis | 4e0854f | 2014-10-15 17:05:31 +0000 | [diff] [blame] | 7278 | case SC_Auto: |
| 7279 | return CX_SC_Auto; |
| 7280 | case SC_Register: |
| 7281 | return CX_SC_Register; |
Argyrios Kyrtzidis | 4e0854f | 2014-10-15 17:05:31 +0000 | [diff] [blame] | 7282 | } |
Kaelyn Takata | ab61e70 | 2014-10-15 18:03:26 +0000 | [diff] [blame] | 7283 | llvm_unreachable("Unhandled storage class!"); |
Argyrios Kyrtzidis | 4e0854f | 2014-10-15 17:05:31 +0000 | [diff] [blame] | 7284 | } |
| 7285 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7286 | CXCursor clang_getCursorSemanticParent(CXCursor cursor) { |
| 7287 | if (clang_isDeclaration(cursor.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7288 | if (const Decl *D = getCursorDecl(cursor)) { |
| 7289 | const DeclContext *DC = D->getDeclContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7290 | if (!DC) |
| 7291 | return clang_getNullCursor(); |
| 7292 | |
| 7293 | return MakeCXCursor(maybeGetTemplateCursor(cast<Decl>(DC)), |
| 7294 | getCursorTU(cursor)); |
| 7295 | } |
| 7296 | } |
| 7297 | |
| 7298 | if (clang_isStatement(cursor.kind) || clang_isExpression(cursor.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7299 | if (const Decl *D = getCursorDecl(cursor)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7300 | return MakeCXCursor(D, getCursorTU(cursor)); |
| 7301 | } |
| 7302 | |
| 7303 | return clang_getNullCursor(); |
| 7304 | } |
| 7305 | |
| 7306 | CXCursor clang_getCursorLexicalParent(CXCursor cursor) { |
| 7307 | if (clang_isDeclaration(cursor.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7308 | if (const Decl *D = getCursorDecl(cursor)) { |
| 7309 | const DeclContext *DC = D->getLexicalDeclContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7310 | if (!DC) |
| 7311 | return clang_getNullCursor(); |
| 7312 | |
| 7313 | return MakeCXCursor(maybeGetTemplateCursor(cast<Decl>(DC)), |
| 7314 | getCursorTU(cursor)); |
| 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | // FIXME: Note that we can't easily compute the lexical context of a |
| 7319 | // statement or expression, so we return nothing. |
| 7320 | return clang_getNullCursor(); |
| 7321 | } |
| 7322 | |
| 7323 | CXFile clang_getIncludedFile(CXCursor cursor) { |
| 7324 | if (cursor.kind != CXCursor_InclusionDirective) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7325 | return nullptr; |
| 7326 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 7327 | const InclusionDirective *ID = getCursorInclusionDirective(cursor); |
Dmitri Gribenko | f930448 | 2013-01-23 15:56:07 +0000 | [diff] [blame] | 7328 | return const_cast<FileEntry *>(ID->getFile()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7329 | } |
| 7330 | |
Argyrios Kyrtzidis | 9adfd8a | 2013-04-18 22:15:49 +0000 | [diff] [blame] | 7331 | unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, unsigned reserved) { |
| 7332 | if (C.kind != CXCursor_ObjCPropertyDecl) |
| 7333 | return CXObjCPropertyAttr_noattr; |
| 7334 | |
| 7335 | unsigned Result = CXObjCPropertyAttr_noattr; |
| 7336 | const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(getCursorDecl(C)); |
| 7337 | ObjCPropertyDecl::PropertyAttributeKind Attr = |
| 7338 | PD->getPropertyAttributesAsWritten(); |
| 7339 | |
| 7340 | #define SET_CXOBJCPROP_ATTR(A) \ |
| 7341 | if (Attr & ObjCPropertyDecl::OBJC_PR_##A) \ |
| 7342 | Result |= CXObjCPropertyAttr_##A |
| 7343 | SET_CXOBJCPROP_ATTR(readonly); |
| 7344 | SET_CXOBJCPROP_ATTR(getter); |
| 7345 | SET_CXOBJCPROP_ATTR(assign); |
| 7346 | SET_CXOBJCPROP_ATTR(readwrite); |
| 7347 | SET_CXOBJCPROP_ATTR(retain); |
| 7348 | SET_CXOBJCPROP_ATTR(copy); |
| 7349 | SET_CXOBJCPROP_ATTR(nonatomic); |
| 7350 | SET_CXOBJCPROP_ATTR(setter); |
| 7351 | SET_CXOBJCPROP_ATTR(atomic); |
| 7352 | SET_CXOBJCPROP_ATTR(weak); |
| 7353 | SET_CXOBJCPROP_ATTR(strong); |
| 7354 | SET_CXOBJCPROP_ATTR(unsafe_unretained); |
Manman Ren | 04fd4d8 | 2016-05-31 23:22:04 +0000 | [diff] [blame] | 7355 | SET_CXOBJCPROP_ATTR(class); |
Argyrios Kyrtzidis | 9adfd8a | 2013-04-18 22:15:49 +0000 | [diff] [blame] | 7356 | #undef SET_CXOBJCPROP_ATTR |
| 7357 | |
| 7358 | return Result; |
| 7359 | } |
| 7360 | |
Argyrios Kyrtzidis | 9d9bc01 | 2013-04-18 23:29:12 +0000 | [diff] [blame] | 7361 | unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C) { |
| 7362 | if (!clang_isDeclaration(C.kind)) |
| 7363 | return CXObjCDeclQualifier_None; |
| 7364 | |
| 7365 | Decl::ObjCDeclQualifier QT = Decl::OBJC_TQ_None; |
| 7366 | const Decl *D = getCursorDecl(C); |
| 7367 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 7368 | QT = MD->getObjCDeclQualifier(); |
| 7369 | else if (const ParmVarDecl *PD = dyn_cast<ParmVarDecl>(D)) |
| 7370 | QT = PD->getObjCDeclQualifier(); |
| 7371 | if (QT == Decl::OBJC_TQ_None) |
| 7372 | return CXObjCDeclQualifier_None; |
| 7373 | |
| 7374 | unsigned Result = CXObjCDeclQualifier_None; |
| 7375 | if (QT & Decl::OBJC_TQ_In) Result |= CXObjCDeclQualifier_In; |
| 7376 | if (QT & Decl::OBJC_TQ_Inout) Result |= CXObjCDeclQualifier_Inout; |
| 7377 | if (QT & Decl::OBJC_TQ_Out) Result |= CXObjCDeclQualifier_Out; |
| 7378 | if (QT & Decl::OBJC_TQ_Bycopy) Result |= CXObjCDeclQualifier_Bycopy; |
| 7379 | if (QT & Decl::OBJC_TQ_Byref) Result |= CXObjCDeclQualifier_Byref; |
| 7380 | if (QT & Decl::OBJC_TQ_Oneway) Result |= CXObjCDeclQualifier_Oneway; |
| 7381 | |
| 7382 | return Result; |
| 7383 | } |
| 7384 | |
Argyrios Kyrtzidis | 7b50fc5 | 2013-07-05 20:44:37 +0000 | [diff] [blame] | 7385 | unsigned clang_Cursor_isObjCOptional(CXCursor C) { |
| 7386 | if (!clang_isDeclaration(C.kind)) |
| 7387 | return 0; |
| 7388 | |
| 7389 | const Decl *D = getCursorDecl(C); |
| 7390 | if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D)) |
| 7391 | return PD->getPropertyImplementation() == ObjCPropertyDecl::Optional; |
| 7392 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 7393 | return MD->getImplementationControl() == ObjCMethodDecl::Optional; |
| 7394 | |
| 7395 | return 0; |
| 7396 | } |
| 7397 | |
Argyrios Kyrtzidis | 23814e4 | 2013-04-18 23:53:05 +0000 | [diff] [blame] | 7398 | unsigned clang_Cursor_isVariadic(CXCursor C) { |
| 7399 | if (!clang_isDeclaration(C.kind)) |
| 7400 | return 0; |
| 7401 | |
| 7402 | const Decl *D = getCursorDecl(C); |
| 7403 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 7404 | return FD->isVariadic(); |
| 7405 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 7406 | return MD->isVariadic(); |
| 7407 | |
| 7408 | return 0; |
| 7409 | } |
| 7410 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7411 | CXSourceRange clang_Cursor_getCommentRange(CXCursor C) { |
| 7412 | if (!clang_isDeclaration(C.kind)) |
| 7413 | return clang_getNullRange(); |
| 7414 | |
| 7415 | const Decl *D = getCursorDecl(C); |
| 7416 | ASTContext &Context = getCursorContext(C); |
| 7417 | const RawComment *RC = Context.getRawCommentForAnyRedecl(D); |
| 7418 | if (!RC) |
| 7419 | return clang_getNullRange(); |
| 7420 | |
| 7421 | return cxloc::translateSourceRange(Context, RC->getSourceRange()); |
| 7422 | } |
| 7423 | |
| 7424 | CXString clang_Cursor_getRawCommentText(CXCursor C) { |
| 7425 | if (!clang_isDeclaration(C.kind)) |
Dmitri Gribenko | f98dfba | 2013-02-01 14:13:32 +0000 | [diff] [blame] | 7426 | return cxstring::createNull(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7427 | |
| 7428 | const Decl *D = getCursorDecl(C); |
| 7429 | ASTContext &Context = getCursorContext(C); |
| 7430 | const RawComment *RC = Context.getRawCommentForAnyRedecl(D); |
| 7431 | StringRef RawText = RC ? RC->getRawText(Context.getSourceManager()) : |
| 7432 | StringRef(); |
| 7433 | |
| 7434 | // Don't duplicate the string because RawText points directly into source |
| 7435 | // code. |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 7436 | return cxstring::createRef(RawText); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7437 | } |
| 7438 | |
| 7439 | CXString clang_Cursor_getBriefCommentText(CXCursor C) { |
| 7440 | if (!clang_isDeclaration(C.kind)) |
Dmitri Gribenko | f98dfba | 2013-02-01 14:13:32 +0000 | [diff] [blame] | 7441 | return cxstring::createNull(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7442 | |
| 7443 | const Decl *D = getCursorDecl(C); |
| 7444 | const ASTContext &Context = getCursorContext(C); |
| 7445 | const RawComment *RC = Context.getRawCommentForAnyRedecl(D); |
| 7446 | |
| 7447 | if (RC) { |
| 7448 | StringRef BriefText = RC->getBriefText(Context); |
| 7449 | |
| 7450 | // Don't duplicate the string because RawComment ensures that this memory |
| 7451 | // will not go away. |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 7452 | return cxstring::createRef(BriefText); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7453 | } |
| 7454 | |
Dmitri Gribenko | f98dfba | 2013-02-01 14:13:32 +0000 | [diff] [blame] | 7455 | return cxstring::createNull(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7456 | } |
| 7457 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7458 | CXModule clang_Cursor_getModule(CXCursor C) { |
| 7459 | if (C.kind == CXCursor_ModuleImportDecl) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7460 | if (const ImportDecl *ImportD = |
| 7461 | dyn_cast_or_null<ImportDecl>(getCursorDecl(C))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7462 | return ImportD->getImportedModule(); |
| 7463 | } |
| 7464 | |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7465 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7466 | } |
| 7467 | |
Argyrios Kyrtzidis | f6d49c3 | 2014-05-14 23:14:37 +0000 | [diff] [blame] | 7468 | CXModule clang_getModuleForFile(CXTranslationUnit TU, CXFile File) { |
| 7469 | if (isNotUsableTU(TU)) { |
| 7470 | LOG_BAD_TU(TU); |
| 7471 | return nullptr; |
| 7472 | } |
| 7473 | if (!File) |
| 7474 | return nullptr; |
| 7475 | FileEntry *FE = static_cast<FileEntry *>(File); |
| 7476 | |
| 7477 | ASTUnit &Unit = *cxtu::getASTUnit(TU); |
| 7478 | HeaderSearch &HS = Unit.getPreprocessor().getHeaderSearchInfo(); |
| 7479 | ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE); |
| 7480 | |
Richard Smith | feb54b6 | 2014-10-23 02:01:19 +0000 | [diff] [blame] | 7481 | return Header.getModule(); |
Argyrios Kyrtzidis | f6d49c3 | 2014-05-14 23:14:37 +0000 | [diff] [blame] | 7482 | } |
| 7483 | |
Argyrios Kyrtzidis | 12fdb9e | 2013-04-26 22:47:49 +0000 | [diff] [blame] | 7484 | CXFile clang_Module_getASTFile(CXModule CXMod) { |
| 7485 | if (!CXMod) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7486 | return nullptr; |
Argyrios Kyrtzidis | 12fdb9e | 2013-04-26 22:47:49 +0000 | [diff] [blame] | 7487 | Module *Mod = static_cast<Module*>(CXMod); |
| 7488 | return const_cast<FileEntry *>(Mod->getASTFile()); |
| 7489 | } |
| 7490 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7491 | CXModule clang_Module_getParent(CXModule CXMod) { |
| 7492 | if (!CXMod) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7493 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7494 | Module *Mod = static_cast<Module*>(CXMod); |
| 7495 | return Mod->Parent; |
| 7496 | } |
| 7497 | |
| 7498 | CXString clang_Module_getName(CXModule CXMod) { |
| 7499 | if (!CXMod) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 7500 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7501 | Module *Mod = static_cast<Module*>(CXMod); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 7502 | return cxstring::createDup(Mod->Name); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7503 | } |
| 7504 | |
| 7505 | CXString clang_Module_getFullName(CXModule CXMod) { |
| 7506 | if (!CXMod) |
Dmitri Gribenko | 36a6dd0 | 2013-02-01 14:21:22 +0000 | [diff] [blame] | 7507 | return cxstring::createEmpty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7508 | Module *Mod = static_cast<Module*>(CXMod); |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 7509 | return cxstring::createDup(Mod->getFullModuleName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7510 | } |
| 7511 | |
Argyrios Kyrtzidis | 884337f | 2014-05-15 04:44:25 +0000 | [diff] [blame] | 7512 | int clang_Module_isSystem(CXModule CXMod) { |
| 7513 | if (!CXMod) |
| 7514 | return 0; |
| 7515 | Module *Mod = static_cast<Module*>(CXMod); |
| 7516 | return Mod->IsSystem; |
| 7517 | } |
| 7518 | |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 7519 | unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit TU, |
| 7520 | CXModule CXMod) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 7521 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 7522 | LOG_BAD_TU(TU); |
| 7523 | return 0; |
| 7524 | } |
| 7525 | if (!CXMod) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7526 | return 0; |
| 7527 | Module *Mod = static_cast<Module*>(CXMod); |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 7528 | FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager(); |
| 7529 | ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr); |
| 7530 | return TopHeaders.size(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7531 | } |
| 7532 | |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 7533 | CXFile clang_Module_getTopLevelHeader(CXTranslationUnit TU, |
| 7534 | CXModule CXMod, unsigned Index) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 7535 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 7536 | LOG_BAD_TU(TU); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7537 | return nullptr; |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 7538 | } |
| 7539 | if (!CXMod) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7540 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7541 | Module *Mod = static_cast<Module*>(CXMod); |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 7542 | FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7543 | |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 7544 | ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr); |
| 7545 | if (Index < TopHeaders.size()) |
| 7546 | return const_cast<FileEntry *>(TopHeaders[Index]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7547 | |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7548 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7549 | } |
| 7550 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7551 | //===----------------------------------------------------------------------===// |
| 7552 | // C++ AST instrospection. |
| 7553 | //===----------------------------------------------------------------------===// |
| 7554 | |
Jonathan Coe | 2956535 | 2016-04-27 12:48:25 +0000 | [diff] [blame] | 7555 | unsigned clang_CXXConstructor_isDefaultConstructor(CXCursor C) { |
| 7556 | if (!clang_isDeclaration(C.kind)) |
| 7557 | return 0; |
| 7558 | |
| 7559 | const Decl *D = cxcursor::getCursorDecl(C); |
| 7560 | const CXXConstructorDecl *Constructor = |
| 7561 | D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr; |
| 7562 | return (Constructor && Constructor->isDefaultConstructor()) ? 1 : 0; |
| 7563 | } |
| 7564 | |
| 7565 | unsigned clang_CXXConstructor_isCopyConstructor(CXCursor C) { |
| 7566 | if (!clang_isDeclaration(C.kind)) |
| 7567 | return 0; |
| 7568 | |
| 7569 | const Decl *D = cxcursor::getCursorDecl(C); |
| 7570 | const CXXConstructorDecl *Constructor = |
| 7571 | D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr; |
| 7572 | return (Constructor && Constructor->isCopyConstructor()) ? 1 : 0; |
| 7573 | } |
| 7574 | |
| 7575 | unsigned clang_CXXConstructor_isMoveConstructor(CXCursor C) { |
| 7576 | if (!clang_isDeclaration(C.kind)) |
| 7577 | return 0; |
| 7578 | |
| 7579 | const Decl *D = cxcursor::getCursorDecl(C); |
| 7580 | const CXXConstructorDecl *Constructor = |
| 7581 | D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr; |
| 7582 | return (Constructor && Constructor->isMoveConstructor()) ? 1 : 0; |
| 7583 | } |
| 7584 | |
| 7585 | unsigned clang_CXXConstructor_isConvertingConstructor(CXCursor C) { |
| 7586 | if (!clang_isDeclaration(C.kind)) |
| 7587 | return 0; |
| 7588 | |
| 7589 | const Decl *D = cxcursor::getCursorDecl(C); |
| 7590 | const CXXConstructorDecl *Constructor = |
| 7591 | D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr; |
| 7592 | // Passing 'false' excludes constructors marked 'explicit'. |
| 7593 | return (Constructor && Constructor->isConvertingConstructor(false)) ? 1 : 0; |
| 7594 | } |
| 7595 | |
Saleem Abdulrasool | 6ea75db | 2015-10-27 15:50:22 +0000 | [diff] [blame] | 7596 | unsigned clang_CXXField_isMutable(CXCursor C) { |
| 7597 | if (!clang_isDeclaration(C.kind)) |
| 7598 | return 0; |
| 7599 | |
| 7600 | if (const auto D = cxcursor::getCursorDecl(C)) |
| 7601 | if (const auto FD = dyn_cast_or_null<FieldDecl>(D)) |
| 7602 | return FD->isMutable() ? 1 : 0; |
| 7603 | return 0; |
| 7604 | } |
| 7605 | |
Dmitri Gribenko | 62770be | 2013-05-17 18:38:35 +0000 | [diff] [blame] | 7606 | unsigned clang_CXXMethod_isPureVirtual(CXCursor C) { |
| 7607 | if (!clang_isDeclaration(C.kind)) |
| 7608 | return 0; |
| 7609 | |
Dmitri Gribenko | 62770be | 2013-05-17 18:38:35 +0000 | [diff] [blame] | 7610 | const Decl *D = cxcursor::getCursorDecl(C); |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 7611 | const CXXMethodDecl *Method = |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7612 | D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr; |
Dmitri Gribenko | 62770be | 2013-05-17 18:38:35 +0000 | [diff] [blame] | 7613 | return (Method && Method->isVirtual() && Method->isPure()) ? 1 : 0; |
| 7614 | } |
| 7615 | |
Dmitri Gribenko | e570ede | 2014-04-07 14:59:13 +0000 | [diff] [blame] | 7616 | unsigned clang_CXXMethod_isConst(CXCursor C) { |
| 7617 | if (!clang_isDeclaration(C.kind)) |
| 7618 | return 0; |
| 7619 | |
| 7620 | const Decl *D = cxcursor::getCursorDecl(C); |
| 7621 | const CXXMethodDecl *Method = |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7622 | D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr; |
Dmitri Gribenko | e570ede | 2014-04-07 14:59:13 +0000 | [diff] [blame] | 7623 | return (Method && (Method->getTypeQualifiers() & Qualifiers::Const)) ? 1 : 0; |
| 7624 | } |
| 7625 | |
Jonathan Coe | 2956535 | 2016-04-27 12:48:25 +0000 | [diff] [blame] | 7626 | unsigned clang_CXXMethod_isDefaulted(CXCursor C) { |
| 7627 | if (!clang_isDeclaration(C.kind)) |
| 7628 | return 0; |
| 7629 | |
| 7630 | const Decl *D = cxcursor::getCursorDecl(C); |
| 7631 | const CXXMethodDecl *Method = |
| 7632 | D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr; |
| 7633 | return (Method && Method->isDefaulted()) ? 1 : 0; |
| 7634 | } |
| 7635 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7636 | unsigned clang_CXXMethod_isStatic(CXCursor C) { |
| 7637 | if (!clang_isDeclaration(C.kind)) |
| 7638 | return 0; |
| 7639 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7640 | const Decl *D = cxcursor::getCursorDecl(C); |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 7641 | const CXXMethodDecl *Method = |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7642 | D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7643 | return (Method && Method->isStatic()) ? 1 : 0; |
| 7644 | } |
| 7645 | |
| 7646 | unsigned clang_CXXMethod_isVirtual(CXCursor C) { |
| 7647 | if (!clang_isDeclaration(C.kind)) |
| 7648 | return 0; |
| 7649 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 7650 | const Decl *D = cxcursor::getCursorDecl(C); |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 7651 | const CXXMethodDecl *Method = |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7652 | D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7653 | return (Method && Method->isVirtual()) ? 1 : 0; |
| 7654 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7655 | |
| 7656 | //===----------------------------------------------------------------------===// |
| 7657 | // Attribute introspection. |
| 7658 | //===----------------------------------------------------------------------===// |
| 7659 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7660 | CXType clang_getIBOutletCollectionType(CXCursor C) { |
| 7661 | if (C.kind != CXCursor_IBOutletCollectionAttr) |
| 7662 | return cxtype::MakeCXType(QualType(), cxcursor::getCursorTU(C)); |
| 7663 | |
Dmitri Gribenko | e4baea6 | 2013-01-26 18:08:08 +0000 | [diff] [blame] | 7664 | const IBOutletCollectionAttr *A = |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7665 | cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(C)); |
| 7666 | |
| 7667 | return cxtype::MakeCXType(A->getInterface(), cxcursor::getCursorTU(C)); |
| 7668 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7669 | |
| 7670 | //===----------------------------------------------------------------------===// |
| 7671 | // Inspecting memory usage. |
| 7672 | //===----------------------------------------------------------------------===// |
| 7673 | |
| 7674 | typedef std::vector<CXTUResourceUsageEntry> MemUsageEntries; |
| 7675 | |
| 7676 | static inline void createCXTUResourceUsageEntry(MemUsageEntries &entries, |
| 7677 | enum CXTUResourceUsageKind k, |
| 7678 | unsigned long amount) { |
| 7679 | CXTUResourceUsageEntry entry = { k, amount }; |
| 7680 | entries.push_back(entry); |
| 7681 | } |
| 7682 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7683 | const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) { |
| 7684 | const char *str = ""; |
| 7685 | switch (kind) { |
| 7686 | case CXTUResourceUsage_AST: |
| 7687 | str = "ASTContext: expressions, declarations, and types"; |
| 7688 | break; |
| 7689 | case CXTUResourceUsage_Identifiers: |
| 7690 | str = "ASTContext: identifiers"; |
| 7691 | break; |
| 7692 | case CXTUResourceUsage_Selectors: |
| 7693 | str = "ASTContext: selectors"; |
| 7694 | break; |
| 7695 | case CXTUResourceUsage_GlobalCompletionResults: |
| 7696 | str = "Code completion: cached global results"; |
| 7697 | break; |
| 7698 | case CXTUResourceUsage_SourceManagerContentCache: |
| 7699 | str = "SourceManager: content cache allocator"; |
| 7700 | break; |
| 7701 | case CXTUResourceUsage_AST_SideTables: |
| 7702 | str = "ASTContext: side tables"; |
| 7703 | break; |
| 7704 | case CXTUResourceUsage_SourceManager_Membuffer_Malloc: |
| 7705 | str = "SourceManager: malloc'ed memory buffers"; |
| 7706 | break; |
| 7707 | case CXTUResourceUsage_SourceManager_Membuffer_MMap: |
| 7708 | str = "SourceManager: mmap'ed memory buffers"; |
| 7709 | break; |
| 7710 | case CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc: |
| 7711 | str = "ExternalASTSource: malloc'ed memory buffers"; |
| 7712 | break; |
| 7713 | case CXTUResourceUsage_ExternalASTSource_Membuffer_MMap: |
| 7714 | str = "ExternalASTSource: mmap'ed memory buffers"; |
| 7715 | break; |
| 7716 | case CXTUResourceUsage_Preprocessor: |
| 7717 | str = "Preprocessor: malloc'ed memory"; |
| 7718 | break; |
| 7719 | case CXTUResourceUsage_PreprocessingRecord: |
| 7720 | str = "Preprocessor: PreprocessingRecord"; |
| 7721 | break; |
| 7722 | case CXTUResourceUsage_SourceManager_DataStructures: |
| 7723 | str = "SourceManager: data structures and tables"; |
| 7724 | break; |
| 7725 | case CXTUResourceUsage_Preprocessor_HeaderSearch: |
| 7726 | str = "Preprocessor: header search tables"; |
| 7727 | break; |
| 7728 | } |
| 7729 | return str; |
| 7730 | } |
| 7731 | |
| 7732 | CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) { |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 7733 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 7734 | LOG_BAD_TU(TU); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7735 | CXTUResourceUsage usage = { (void*) nullptr, 0, nullptr }; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7736 | return usage; |
| 7737 | } |
| 7738 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 7739 | ASTUnit *astUnit = cxtu::getASTUnit(TU); |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 7740 | std::unique_ptr<MemUsageEntries> entries(new MemUsageEntries()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7741 | ASTContext &astContext = astUnit->getASTContext(); |
| 7742 | |
| 7743 | // How much memory is used by AST nodes and types? |
| 7744 | createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST, |
| 7745 | (unsigned long) astContext.getASTAllocatedMemory()); |
| 7746 | |
| 7747 | // How much memory is used by identifiers? |
| 7748 | createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Identifiers, |
| 7749 | (unsigned long) astContext.Idents.getAllocator().getTotalMemory()); |
| 7750 | |
| 7751 | // How much memory is used for selectors? |
| 7752 | createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Selectors, |
| 7753 | (unsigned long) astContext.Selectors.getTotalMemory()); |
| 7754 | |
| 7755 | // How much memory is used by ASTContext's side tables? |
| 7756 | createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST_SideTables, |
| 7757 | (unsigned long) astContext.getSideTableAllocatedMemory()); |
| 7758 | |
| 7759 | // How much memory is used for caching global code completion results? |
| 7760 | unsigned long completionBytes = 0; |
| 7761 | if (GlobalCodeCompletionAllocator *completionAllocator = |
Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 7762 | astUnit->getCachedCompletionAllocator().get()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7763 | completionBytes = completionAllocator->getTotalMemory(); |
| 7764 | } |
| 7765 | createCXTUResourceUsageEntry(*entries, |
| 7766 | CXTUResourceUsage_GlobalCompletionResults, |
| 7767 | completionBytes); |
| 7768 | |
| 7769 | // How much memory is being used by SourceManager's content cache? |
| 7770 | createCXTUResourceUsageEntry(*entries, |
| 7771 | CXTUResourceUsage_SourceManagerContentCache, |
| 7772 | (unsigned long) astContext.getSourceManager().getContentCacheSize()); |
| 7773 | |
| 7774 | // How much memory is being used by the MemoryBuffer's in SourceManager? |
| 7775 | const SourceManager::MemoryBufferSizes &srcBufs = |
| 7776 | astUnit->getSourceManager().getMemoryBufferSizes(); |
| 7777 | |
| 7778 | createCXTUResourceUsageEntry(*entries, |
| 7779 | CXTUResourceUsage_SourceManager_Membuffer_Malloc, |
| 7780 | (unsigned long) srcBufs.malloc_bytes); |
| 7781 | createCXTUResourceUsageEntry(*entries, |
| 7782 | CXTUResourceUsage_SourceManager_Membuffer_MMap, |
| 7783 | (unsigned long) srcBufs.mmap_bytes); |
| 7784 | createCXTUResourceUsageEntry(*entries, |
| 7785 | CXTUResourceUsage_SourceManager_DataStructures, |
| 7786 | (unsigned long) astContext.getSourceManager() |
| 7787 | .getDataStructureSizes()); |
| 7788 | |
| 7789 | // How much memory is being used by the ExternalASTSource? |
| 7790 | if (ExternalASTSource *esrc = astContext.getExternalSource()) { |
| 7791 | const ExternalASTSource::MemoryBufferSizes &sizes = |
| 7792 | esrc->getMemoryBufferSizes(); |
| 7793 | |
| 7794 | createCXTUResourceUsageEntry(*entries, |
| 7795 | CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc, |
| 7796 | (unsigned long) sizes.malloc_bytes); |
| 7797 | createCXTUResourceUsageEntry(*entries, |
| 7798 | CXTUResourceUsage_ExternalASTSource_Membuffer_MMap, |
| 7799 | (unsigned long) sizes.mmap_bytes); |
| 7800 | } |
| 7801 | |
| 7802 | // How much memory is being used by the Preprocessor? |
| 7803 | Preprocessor &pp = astUnit->getPreprocessor(); |
| 7804 | createCXTUResourceUsageEntry(*entries, |
| 7805 | CXTUResourceUsage_Preprocessor, |
| 7806 | pp.getTotalMemory()); |
| 7807 | |
| 7808 | if (PreprocessingRecord *pRec = pp.getPreprocessingRecord()) { |
| 7809 | createCXTUResourceUsageEntry(*entries, |
| 7810 | CXTUResourceUsage_PreprocessingRecord, |
| 7811 | pRec->getTotalMemory()); |
| 7812 | } |
| 7813 | |
| 7814 | createCXTUResourceUsageEntry(*entries, |
| 7815 | CXTUResourceUsage_Preprocessor_HeaderSearch, |
| 7816 | pp.getHeaderSearchInfo().getTotalMemory()); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7817 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7818 | CXTUResourceUsage usage = { (void*) entries.get(), |
| 7819 | (unsigned) entries->size(), |
Alexander Kornienko | 6ee521c | 2015-01-23 15:36:10 +0000 | [diff] [blame] | 7820 | !entries->empty() ? &(*entries)[0] : nullptr }; |
Eric Fiselier | e95fc44 | 2016-11-14 07:03:50 +0000 | [diff] [blame] | 7821 | (void)entries.release(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7822 | return usage; |
| 7823 | } |
| 7824 | |
| 7825 | void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage) { |
| 7826 | if (usage.data) |
| 7827 | delete (MemUsageEntries*) usage.data; |
| 7828 | } |
| 7829 | |
Argyrios Kyrtzidis | 0e282ef | 2013-12-06 18:55:45 +0000 | [diff] [blame] | 7830 | CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit TU, CXFile file) { |
| 7831 | CXSourceRangeList *skipped = new CXSourceRangeList; |
Argyrios Kyrtzidis | 9ef5775 | 2013-12-05 08:19:32 +0000 | [diff] [blame] | 7832 | skipped->count = 0; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7833 | skipped->ranges = nullptr; |
Argyrios Kyrtzidis | 9ef5775 | 2013-12-05 08:19:32 +0000 | [diff] [blame] | 7834 | |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 7835 | if (isNotUsableTU(TU)) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 7836 | LOG_BAD_TU(TU); |
| 7837 | return skipped; |
| 7838 | } |
| 7839 | |
Argyrios Kyrtzidis | 9ef5775 | 2013-12-05 08:19:32 +0000 | [diff] [blame] | 7840 | if (!file) |
| 7841 | return skipped; |
| 7842 | |
| 7843 | ASTUnit *astUnit = cxtu::getASTUnit(TU); |
| 7844 | PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord(); |
| 7845 | if (!ppRec) |
| 7846 | return skipped; |
| 7847 | |
| 7848 | ASTContext &Ctx = astUnit->getASTContext(); |
| 7849 | SourceManager &sm = Ctx.getSourceManager(); |
| 7850 | FileEntry *fileEntry = static_cast<FileEntry *>(file); |
| 7851 | FileID wantedFileID = sm.translateFile(fileEntry); |
| 7852 | |
| 7853 | const std::vector<SourceRange> &SkippedRanges = ppRec->getSkippedRanges(); |
| 7854 | std::vector<SourceRange> wantedRanges; |
| 7855 | for (std::vector<SourceRange>::const_iterator i = SkippedRanges.begin(), ei = SkippedRanges.end(); |
| 7856 | i != ei; ++i) { |
| 7857 | if (sm.getFileID(i->getBegin()) == wantedFileID || sm.getFileID(i->getEnd()) == wantedFileID) |
| 7858 | wantedRanges.push_back(*i); |
| 7859 | } |
| 7860 | |
| 7861 | skipped->count = wantedRanges.size(); |
| 7862 | skipped->ranges = new CXSourceRange[skipped->count]; |
| 7863 | for (unsigned i = 0, ei = skipped->count; i != ei; ++i) |
| 7864 | skipped->ranges[i] = cxloc::translateSourceRange(Ctx, wantedRanges[i]); |
| 7865 | |
| 7866 | return skipped; |
| 7867 | } |
| 7868 | |
Cameron Desrochers | d809128 | 2016-08-18 15:43:55 +0000 | [diff] [blame] | 7869 | CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) { |
| 7870 | CXSourceRangeList *skipped = new CXSourceRangeList; |
| 7871 | skipped->count = 0; |
| 7872 | skipped->ranges = nullptr; |
| 7873 | |
| 7874 | if (isNotUsableTU(TU)) { |
| 7875 | LOG_BAD_TU(TU); |
| 7876 | return skipped; |
| 7877 | } |
| 7878 | |
| 7879 | ASTUnit *astUnit = cxtu::getASTUnit(TU); |
| 7880 | PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord(); |
| 7881 | if (!ppRec) |
| 7882 | return skipped; |
| 7883 | |
| 7884 | ASTContext &Ctx = astUnit->getASTContext(); |
| 7885 | |
| 7886 | const std::vector<SourceRange> &SkippedRanges = ppRec->getSkippedRanges(); |
| 7887 | |
| 7888 | skipped->count = SkippedRanges.size(); |
| 7889 | skipped->ranges = new CXSourceRange[skipped->count]; |
| 7890 | for (unsigned i = 0, ei = skipped->count; i != ei; ++i) |
| 7891 | skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]); |
| 7892 | |
| 7893 | return skipped; |
| 7894 | } |
| 7895 | |
Argyrios Kyrtzidis | 0e282ef | 2013-12-06 18:55:45 +0000 | [diff] [blame] | 7896 | void clang_disposeSourceRangeList(CXSourceRangeList *ranges) { |
| 7897 | if (ranges) { |
| 7898 | delete[] ranges->ranges; |
| 7899 | delete ranges; |
Argyrios Kyrtzidis | 9ef5775 | 2013-12-05 08:19:32 +0000 | [diff] [blame] | 7900 | } |
| 7901 | } |
| 7902 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7903 | void clang::PrintLibclangResourceUsage(CXTranslationUnit TU) { |
| 7904 | CXTUResourceUsage Usage = clang_getCXTUResourceUsage(TU); |
| 7905 | for (unsigned I = 0; I != Usage.numEntries; ++I) |
| 7906 | fprintf(stderr, " %s: %lu\n", |
| 7907 | clang_getTUResourceUsageName(Usage.entries[I].kind), |
| 7908 | Usage.entries[I].amount); |
| 7909 | |
| 7910 | clang_disposeCXTUResourceUsage(Usage); |
| 7911 | } |
| 7912 | |
| 7913 | //===----------------------------------------------------------------------===// |
| 7914 | // Misc. utility functions. |
| 7915 | //===----------------------------------------------------------------------===// |
| 7916 | |
| 7917 | /// Default to using an 8 MB stack size on "safety" threads. |
| 7918 | static unsigned SafetyStackThreadSize = 8 << 20; |
| 7919 | |
| 7920 | namespace clang { |
| 7921 | |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 7922 | bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref<void()> Fn, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7923 | unsigned Size) { |
| 7924 | if (!Size) |
| 7925 | Size = GetSafetyThreadStackSize(); |
| 7926 | if (Size) |
Benjamin Kramer | 11a9cd9 | 2015-07-25 20:55:44 +0000 | [diff] [blame] | 7927 | return CRC.RunSafelyOnThread(Fn, Size); |
| 7928 | return CRC.RunSafely(Fn); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7929 | } |
| 7930 | |
| 7931 | unsigned GetSafetyThreadStackSize() { |
| 7932 | return SafetyStackThreadSize; |
| 7933 | } |
| 7934 | |
| 7935 | void SetSafetyThreadStackSize(unsigned Value) { |
| 7936 | SafetyStackThreadSize = Value; |
| 7937 | } |
| 7938 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7939 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7940 | |
| 7941 | void clang::setThreadBackgroundPriority() { |
| 7942 | if (getenv("LIBCLANG_BGPRIO_DISABLE")) |
| 7943 | return; |
| 7944 | |
Alp Toker | 1a86ad2 | 2014-07-06 06:24:00 +0000 | [diff] [blame] | 7945 | #ifdef USE_DARWIN_THREADS |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7946 | setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG); |
| 7947 | #endif |
| 7948 | } |
| 7949 | |
| 7950 | void cxindex::printDiagsToStderr(ASTUnit *Unit) { |
| 7951 | if (!Unit) |
| 7952 | return; |
| 7953 | |
| 7954 | for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(), |
| 7955 | DEnd = Unit->stored_diag_end(); |
| 7956 | D != DEnd; ++D) { |
Ben Langmuir | 749323f | 2014-04-22 17:40:12 +0000 | [diff] [blame] | 7957 | CXStoredDiagnostic Diag(*D, Unit->getLangOpts()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7958 | CXString Msg = clang_formatDiagnostic(&Diag, |
| 7959 | clang_defaultDiagnosticDisplayOptions()); |
| 7960 | fprintf(stderr, "%s\n", clang_getCString(Msg)); |
| 7961 | clang_disposeString(Msg); |
| 7962 | } |
| 7963 | #ifdef LLVM_ON_WIN32 |
| 7964 | // On Windows, force a flush, since there may be multiple copies of |
| 7965 | // stderr and stdout in the file system, all with different buffers |
| 7966 | // but writing to the same device. |
| 7967 | fflush(stderr); |
| 7968 | #endif |
| 7969 | } |
| 7970 | |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 7971 | MacroInfo *cxindex::getMacroInfo(const IdentifierInfo &II, |
| 7972 | SourceLocation MacroDefLoc, |
| 7973 | CXTranslationUnit TU){ |
| 7974 | if (MacroDefLoc.isInvalid() || !TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7975 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 7976 | if (!II.hadMacroDefinition()) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7977 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 7978 | |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 7979 | ASTUnit *Unit = cxtu::getASTUnit(TU); |
Argyrios Kyrtzidis | 2d77aeb | 2013-01-07 19:16:30 +0000 | [diff] [blame] | 7980 | Preprocessor &PP = Unit->getPreprocessor(); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 7981 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(&II); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 7982 | if (MD) { |
| 7983 | for (MacroDirective::DefInfo |
| 7984 | Def = MD->getDefinition(); Def; Def = Def.getPreviousDefinition()) { |
| 7985 | if (MacroDefLoc == Def.getMacroInfo()->getDefinitionLoc()) |
| 7986 | return Def.getMacroInfo(); |
| 7987 | } |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 7988 | } |
| 7989 | |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7990 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 7991 | } |
| 7992 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 7993 | const MacroInfo *cxindex::getMacroInfo(const MacroDefinitionRecord *MacroDef, |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 7994 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 7995 | if (!MacroDef || !TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7996 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 7997 | const IdentifierInfo *II = MacroDef->getName(); |
| 7998 | if (!II) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 7999 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8000 | |
| 8001 | return getMacroInfo(*II, MacroDef->getLocation(), TU); |
| 8002 | } |
| 8003 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 8004 | MacroDefinitionRecord * |
| 8005 | cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, const Token &Tok, |
| 8006 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8007 | if (!MI || !TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8008 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8009 | if (Tok.isNot(tok::raw_identifier)) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8010 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8011 | |
| 8012 | if (MI->getNumTokens() == 0) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8013 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8014 | SourceRange DefRange(MI->getReplacementToken(0).getLocation(), |
| 8015 | MI->getDefinitionEndLoc()); |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 8016 | ASTUnit *Unit = cxtu::getASTUnit(TU); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8017 | |
| 8018 | // Check that the token is inside the definition and not its argument list. |
| 8019 | SourceManager &SM = Unit->getSourceManager(); |
| 8020 | if (SM.isBeforeInTranslationUnit(Tok.getLocation(), DefRange.getBegin())) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8021 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8022 | if (SM.isBeforeInTranslationUnit(DefRange.getEnd(), Tok.getLocation())) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8023 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8024 | |
| 8025 | Preprocessor &PP = Unit->getPreprocessor(); |
| 8026 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
| 8027 | if (!PPRec) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8028 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8029 | |
Alp Toker | 2d57cea | 2014-05-17 04:53:25 +0000 | [diff] [blame] | 8030 | IdentifierInfo &II = PP.getIdentifierTable().get(Tok.getRawIdentifier()); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8031 | if (!II.hadMacroDefinition()) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8032 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8033 | |
| 8034 | // Check that the identifier is not one of the macro arguments. |
| 8035 | if (std::find(MI->arg_begin(), MI->arg_end(), &II) != MI->arg_end()) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8036 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8037 | |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 8038 | MacroDirective *InnerMD = PP.getLocalMacroDirectiveHistory(&II); |
Argyrios Kyrtzidis | 09c9e81 | 2013-02-20 00:54:57 +0000 | [diff] [blame] | 8039 | if (!InnerMD) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8040 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8041 | |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 8042 | return PPRec->findMacroDefinition(InnerMD->getMacroInfo()); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8043 | } |
| 8044 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 8045 | MacroDefinitionRecord * |
| 8046 | cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, SourceLocation Loc, |
| 8047 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8048 | if (Loc.isInvalid() || !MI || !TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8049 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8050 | |
| 8051 | if (MI->getNumTokens() == 0) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8052 | return nullptr; |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 8053 | ASTUnit *Unit = cxtu::getASTUnit(TU); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8054 | Preprocessor &PP = Unit->getPreprocessor(); |
| 8055 | if (!PP.getPreprocessingRecord()) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8056 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8057 | Loc = Unit->getSourceManager().getSpellingLoc(Loc); |
| 8058 | Token Tok; |
| 8059 | if (PP.getRawToken(Loc, Tok)) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8060 | return nullptr; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 8061 | |
| 8062 | return checkForMacroInMacroDefinition(MI, Tok, TU); |
| 8063 | } |
| 8064 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8065 | CXString clang_getClangVersion() { |
Dmitri Gribenko | 2f23e9c | 2013-02-02 02:19:29 +0000 | [diff] [blame] | 8066 | return cxstring::createDup(getClangFullVersion()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8067 | } |
| 8068 | |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8069 | Logger &cxindex::Logger::operator<<(CXTranslationUnit TU) { |
| 8070 | if (TU) { |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 8071 | if (ASTUnit *Unit = cxtu::getASTUnit(TU)) { |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8072 | LogOS << '<' << Unit->getMainFileName() << '>'; |
Argyrios Kyrtzidis | 37f2ab4 | 2013-03-05 20:21:14 +0000 | [diff] [blame] | 8073 | if (Unit->isMainFileAST()) |
| 8074 | LogOS << " (" << Unit->getASTFileName() << ')'; |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8075 | return *this; |
| 8076 | } |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 8077 | } else { |
| 8078 | LogOS << "<NULL TU>"; |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8079 | } |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8080 | return *this; |
| 8081 | } |
| 8082 | |
Argyrios Kyrtzidis | ba4b5f8 | 2013-03-08 02:32:26 +0000 | [diff] [blame] | 8083 | Logger &cxindex::Logger::operator<<(const FileEntry *FE) { |
| 8084 | *this << FE->getName(); |
| 8085 | return *this; |
| 8086 | } |
| 8087 | |
| 8088 | Logger &cxindex::Logger::operator<<(CXCursor cursor) { |
| 8089 | CXString cursorName = clang_getCursorDisplayName(cursor); |
| 8090 | *this << cursorName << "@" << clang_getCursorLocation(cursor); |
| 8091 | clang_disposeString(cursorName); |
| 8092 | return *this; |
| 8093 | } |
| 8094 | |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8095 | Logger &cxindex::Logger::operator<<(CXSourceLocation Loc) { |
| 8096 | CXFile File; |
| 8097 | unsigned Line, Column; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8098 | clang_getFileLocation(Loc, &File, &Line, &Column, nullptr); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8099 | CXString FileName = clang_getFileName(File); |
| 8100 | *this << llvm::format("(%s:%d:%d)", clang_getCString(FileName), Line, Column); |
| 8101 | clang_disposeString(FileName); |
| 8102 | return *this; |
| 8103 | } |
| 8104 | |
| 8105 | Logger &cxindex::Logger::operator<<(CXSourceRange range) { |
| 8106 | CXSourceLocation BLoc = clang_getRangeStart(range); |
| 8107 | CXSourceLocation ELoc = clang_getRangeEnd(range); |
| 8108 | |
| 8109 | CXFile BFile; |
| 8110 | unsigned BLine, BColumn; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8111 | clang_getFileLocation(BLoc, &BFile, &BLine, &BColumn, nullptr); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8112 | |
| 8113 | CXFile EFile; |
| 8114 | unsigned ELine, EColumn; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 8115 | clang_getFileLocation(ELoc, &EFile, &ELine, &EColumn, nullptr); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8116 | |
| 8117 | CXString BFileName = clang_getFileName(BFile); |
| 8118 | if (BFile == EFile) { |
| 8119 | *this << llvm::format("[%s %d:%d-%d:%d]", clang_getCString(BFileName), |
| 8120 | BLine, BColumn, ELine, EColumn); |
| 8121 | } else { |
| 8122 | CXString EFileName = clang_getFileName(EFile); |
| 8123 | *this << llvm::format("[%s:%d:%d - ", clang_getCString(BFileName), |
| 8124 | BLine, BColumn) |
| 8125 | << llvm::format("%s:%d:%d]", clang_getCString(EFileName), |
| 8126 | ELine, EColumn); |
| 8127 | clang_disposeString(EFileName); |
| 8128 | } |
| 8129 | clang_disposeString(BFileName); |
| 8130 | return *this; |
| 8131 | } |
| 8132 | |
| 8133 | Logger &cxindex::Logger::operator<<(CXString Str) { |
| 8134 | *this << clang_getCString(Str); |
| 8135 | return *this; |
| 8136 | } |
| 8137 | |
| 8138 | Logger &cxindex::Logger::operator<<(const llvm::format_object_base &Fmt) { |
| 8139 | LogOS << Fmt; |
| 8140 | return *this; |
| 8141 | } |
| 8142 | |
Chandler Carruth | 37ad258 | 2014-06-27 15:14:39 +0000 | [diff] [blame] | 8143 | static llvm::ManagedStatic<llvm::sys::Mutex> LoggingMutex; |
| 8144 | |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8145 | cxindex::Logger::~Logger() { |
Chandler Carruth | 37ad258 | 2014-06-27 15:14:39 +0000 | [diff] [blame] | 8146 | llvm::sys::ScopedLock L(*LoggingMutex); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8147 | |
| 8148 | static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime(); |
| 8149 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8150 | raw_ostream &OS = llvm::errs(); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8151 | OS << "[libclang:" << Name << ':'; |
| 8152 | |
Alp Toker | 1a86ad2 | 2014-07-06 06:24:00 +0000 | [diff] [blame] | 8153 | #ifdef USE_DARWIN_THREADS |
| 8154 | // TODO: Portability. |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8155 | mach_port_t tid = pthread_mach_thread_np(pthread_self()); |
| 8156 | OS << tid << ':'; |
| 8157 | #endif |
| 8158 | |
| 8159 | llvm::TimeRecord TR = llvm::TimeRecord::getCurrentTime(); |
| 8160 | OS << llvm::format("%7.4f] ", TR.getWallTime() - sBeginTR.getWallTime()); |
Yaron Keren | 09fb7c6 | 2015-03-10 07:33:23 +0000 | [diff] [blame] | 8161 | OS << Msg << '\n'; |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8162 | |
| 8163 | if (Trace) { |
Zachary Turner | 1fe2a8d | 2015-03-05 19:15:09 +0000 | [diff] [blame] | 8164 | llvm::sys::PrintStackTrace(OS); |
Argyrios Kyrtzidis | ea47435 | 2013-01-10 18:54:52 +0000 | [diff] [blame] | 8165 | OS << "--------------------------------------------------\n"; |
| 8166 | } |
| 8167 | } |
Benjamin Kramer | c1ffdab | 2016-03-03 08:58:18 +0000 | [diff] [blame] | 8168 | |
| 8169 | #ifdef CLANG_TOOL_EXTRA_BUILD |
| 8170 | // This anchor is used to force the linker to link the clang-tidy plugin. |
| 8171 | extern volatile int ClangTidyPluginAnchorSource; |
| 8172 | static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination = |
| 8173 | ClangTidyPluginAnchorSource; |
Benjamin Kramer | 9eba735 | 2016-11-17 15:22:36 +0000 | [diff] [blame] | 8174 | |
| 8175 | // This anchor is used to force the linker to link the clang-include-fixer |
| 8176 | // plugin. |
| 8177 | extern volatile int ClangIncludeFixerPluginAnchorSource; |
| 8178 | static int LLVM_ATTRIBUTE_UNUSED ClangIncludeFixerPluginAnchorDestination = |
| 8179 | ClangIncludeFixerPluginAnchorSource; |
Benjamin Kramer | c1ffdab | 2016-03-03 08:58:18 +0000 | [diff] [blame] | 8180 | #endif |