| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H |
| 14 | #define LLVM_CLANG_FRONTEND_ASTUNIT_H |
| 15 | |
| 16 | #include "clang-c/Index.h" |
| 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/Basic/Diagnostic.h" |
| 19 | #include "clang/Basic/FileSystemOptions.h" |
| 20 | #include "clang/Basic/LLVM.h" |
| 21 | #include "clang/Basic/LangOptions.h" |
| 22 | #include "clang/Basic/SourceLocation.h" |
| 23 | #include "clang/Basic/SourceManager.h" |
| 24 | #include "clang/Basic/TargetOptions.h" |
| 25 | #include "clang/Lex/HeaderSearchOptions.h" |
| 26 | #include "clang/Lex/ModuleLoader.h" |
| 27 | #include "clang/Lex/PreprocessingRecord.h" |
| 28 | #include "clang/Sema/CodeCompleteConsumer.h" |
| 29 | #include "clang/Serialization/ASTBitCodes.h" |
| 30 | #include "clang/Frontend/PrecompiledPreamble.h" |
| 31 | #include "llvm/ADT/ArrayRef.h" |
| 32 | #include "llvm/ADT/DenseMap.h" |
| 33 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 34 | #include "llvm/ADT/None.h" |
| 35 | #include "llvm/ADT/Optional.h" |
| 36 | #include "llvm/ADT/STLExtras.h" |
| 37 | #include "llvm/ADT/SmallVector.h" |
| 38 | #include "llvm/ADT/StringMap.h" |
| 39 | #include "llvm/ADT/StringRef.h" |
| 40 | #include "llvm/ADT/iterator_range.h" |
| 41 | #include <cassert> |
| 42 | #include <cstddef> |
| 43 | #include <cstdint> |
| 44 | #include <memory> |
| 45 | #include <string> |
| 46 | #include <utility> |
| 47 | #include <vector> |
| 48 | |
| 49 | namespace llvm { |
| 50 | |
| 51 | class MemoryBuffer; |
| 52 | |
| 53 | namespace vfs { |
| 54 | |
| 55 | class FileSystem; |
| 56 | |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | namespace clang { |
| 61 | |
| 62 | class ASTContext; |
| 63 | class ASTDeserializationListener; |
| 64 | class ASTMutationListener; |
| 65 | class ASTReader; |
| 66 | class CompilerInstance; |
| 67 | class CompilerInvocation; |
| 68 | class Decl; |
| 69 | class FileEntry; |
| 70 | class FileManager; |
| 71 | class FrontendAction; |
| 72 | class ; |
| 73 | class InputKind; |
| 74 | class InMemoryModuleCache; |
| 75 | class PCHContainerOperations; |
| 76 | class PCHContainerReader; |
| 77 | class Preprocessor; |
| 78 | class PreprocessorOptions; |
| 79 | class Sema; |
| 80 | class TargetInfo; |
| 81 | |
| 82 | |
| 83 | enum class SkipFunctionBodiesScope { None, Preamble, PreambleAndMainFile }; |
| 84 | |
| 85 | |
| 86 | class ASTUnit { |
| 87 | public: |
| 88 | struct StandaloneFixIt { |
| 89 | std::pair<unsigned, unsigned> RemoveRange; |
| 90 | std::pair<unsigned, unsigned> InsertFromRange; |
| 91 | std::string CodeToInsert; |
| 92 | bool BeforePreviousInsertions; |
| 93 | }; |
| 94 | |
| 95 | struct StandaloneDiagnostic { |
| 96 | unsigned ID; |
| 97 | DiagnosticsEngine::Level Level; |
| 98 | std::string Message; |
| 99 | std::string Filename; |
| 100 | unsigned LocOffset; |
| 101 | std::vector<std::pair<unsigned, unsigned>> Ranges; |
| 102 | std::vector<StandaloneFixIt> FixIts; |
| 103 | }; |
| 104 | |
| 105 | private: |
| 106 | std::shared_ptr<LangOptions> LangOpts; |
| 107 | IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics; |
| 108 | IntrusiveRefCntPtr<FileManager> FileMgr; |
| 109 | IntrusiveRefCntPtr<SourceManager> SourceMgr; |
| 110 | IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache; |
| 111 | std::unique_ptr<HeaderSearch> ; |
| 112 | IntrusiveRefCntPtr<TargetInfo> Target; |
| 113 | std::shared_ptr<Preprocessor> PP; |
| 114 | IntrusiveRefCntPtr<ASTContext> Ctx; |
| 115 | std::shared_ptr<TargetOptions> TargetOpts; |
| 116 | std::shared_ptr<HeaderSearchOptions> HSOpts; |
| 117 | std::shared_ptr<PreprocessorOptions> PPOpts; |
| 118 | IntrusiveRefCntPtr<ASTReader> Reader; |
| 119 | bool HadModuleLoaderFatalFailure = false; |
| 120 | |
| 121 | struct ASTWriterData; |
| 122 | std::unique_ptr<ASTWriterData> WriterData; |
| 123 | |
| 124 | FileSystemOptions FileSystemOpts; |
| 125 | |
| 126 | |
| 127 | |
| 128 | std::unique_ptr<ASTConsumer> Consumer; |
| 129 | |
| 130 | |
| 131 | |
| 132 | std::unique_ptr<Sema> TheSema; |
| 133 | |
| 134 | |
| 135 | |
| 136 | std::shared_ptr<CompilerInvocation> Invocation; |
| 137 | |
| 138 | |
| 139 | TrivialModuleLoader ModuleLoader; |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | bool OnlyLocalDecls = false; |
| 145 | |
| 146 | |
| 147 | bool CaptureDiagnostics = false; |
| 148 | |
| 149 | |
| 150 | bool MainFileIsAST; |
| 151 | |
| 152 | |
| 153 | TranslationUnitKind TUKind = TU_Complete; |
| 154 | |
| 155 | |
| 156 | bool WantTiming; |
| 157 | |
| 158 | |
| 159 | bool OwnsRemappedFileBuffers = true; |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | std::vector<Decl*> TopLevelDecls; |
| 169 | |
| 170 | |
| 171 | using LocDeclsTy = SmallVector<std::pair<unsigned, Decl *>, 64>; |
| 172 | using FileDeclsTy = llvm::DenseMap<FileID, LocDeclsTy *>; |
| 173 | |
| 174 | |
| 175 | |
| 176 | FileDeclsTy FileDecls; |
| 177 | |
| 178 | |
| 179 | std::string OriginalSourceFile; |
| 180 | |
| 181 | |
| 182 | SmallVector<StandaloneDiagnostic, 4> PreambleDiagnostics; |
| 183 | |
| 184 | |
| 185 | |
| 186 | SmallVector<StoredDiagnostic, 4> StoredDiagnostics; |
| 187 | |
| 188 | |
| 189 | |
| 190 | SmallVector<StoredDiagnostic, 4> FailedParseDiagnostics; |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | unsigned NumStoredDiagnosticsFromDriver = 0; |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | unsigned PreambleRebuildCounter = 0; |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | llvm::StringMap<SourceLocation> PreambleSrcLocCache; |
| 217 | |
| 218 | |
| 219 | llvm::Optional<PrecompiledPreamble> Preamble; |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | std::unique_ptr<llvm::MemoryBuffer> SavedMainFileBuffer; |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | unsigned NumWarningsInPreamble = 0; |
| 233 | |
| 234 | |
| 235 | |
| 236 | std::vector<serialization::DeclID> TopLevelDeclsInPreamble; |
| 237 | |
| 238 | |
| 239 | bool ShouldCacheCodeCompletionResults : 1; |
| 240 | |
| 241 | |
| 242 | |
| 243 | bool : 1; |
| 244 | |
| 245 | |
| 246 | |
| 247 | bool UserFilesAreVolatile : 1; |
| 248 | |
| 249 | static void ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags, |
| 250 | ASTUnit &AST, bool CaptureDiagnostics); |
| 251 | |
| 252 | void TranslateStoredDiagnostics(FileManager &FileMgr, |
| 253 | SourceManager &SrcMan, |
| 254 | const SmallVectorImpl<StandaloneDiagnostic> &Diags, |
| 255 | SmallVectorImpl<StoredDiagnostic> &Out); |
| 256 | |
| 257 | void clearFileLevelDecls(); |
| 258 | |
| 259 | public: |
| 260 | |
| 261 | |
| 262 | struct CachedCodeCompletionResult { |
| 263 | |
| 264 | |
| 265 | CodeCompletionString *Completion; |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | uint64_t ShowInContexts; |
| 275 | |
| 276 | |
| 277 | unsigned Priority; |
| 278 | |
| 279 | |
| 280 | |
| 281 | CXCursorKind Kind; |
| 282 | |
| 283 | |
| 284 | CXAvailabilityKind Availability; |
| 285 | |
| 286 | |
| 287 | SimplifiedTypeClass TypeClass; |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | unsigned Type; |
| 296 | }; |
| 297 | |
| 298 | |
| 299 | |
| 300 | llvm::StringMap<unsigned> &getCachedCompletionTypes() { |
| 301 | return CachedCompletionTypes; |
| 302 | } |
| 303 | |
| 304 | |
| 305 | std::shared_ptr<GlobalCodeCompletionAllocator> |
| 306 | getCachedCompletionAllocator() { |
| 307 | return CachedCompletionAllocator; |
| 308 | } |
| 309 | |
| 310 | CodeCompletionTUInfo &getCodeCompletionTUInfo() { |
| 311 | if (!CCTUInfo) |
| 312 | CCTUInfo = llvm::make_unique<CodeCompletionTUInfo>( |
| 313 | std::make_shared<GlobalCodeCompletionAllocator>()); |
| 314 | return *CCTUInfo; |
| 315 | } |
| 316 | |
| 317 | private: |
| 318 | |
| 319 | std::shared_ptr<GlobalCodeCompletionAllocator> CachedCompletionAllocator; |
| 320 | |
| 321 | std::unique_ptr<CodeCompletionTUInfo> CCTUInfo; |
| 322 | |
| 323 | |
| 324 | std::vector<CachedCodeCompletionResult> CachedCompletionResults; |
| 325 | |
| 326 | |
| 327 | |
| 328 | llvm::StringMap<unsigned> CachedCompletionTypes; |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | unsigned CompletionCacheTopLevelHashValue = 0; |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | unsigned PreambleTopLevelHashValue = 0; |
| 343 | |
| 344 | |
| 345 | |
| 346 | unsigned CurrentTopLevelHashValue = 0; |
| 347 | |
| 348 | |
| 349 | |
| 350 | unsigned UnsafeToFree : 1; |
| 351 | |
| 352 | |
| 353 | SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None; |
| 354 | |
| 355 | |
| 356 | |
| 357 | void CacheCodeCompletionResults(); |
| 358 | |
| 359 | |
| 360 | void ClearCachedCompletionResults(); |
| 361 | |
| 362 | explicit ASTUnit(bool MainFileIsAST); |
| 363 | |
| 364 | bool Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 365 | std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer, |
| 366 | IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS); |
| 367 | |
| 368 | std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble( |
| 369 | std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 370 | CompilerInvocation &PreambleInvocationIn, |
| 371 | IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, bool AllowRebuild = true, |
| 372 | unsigned MaxLines = 0); |
| 373 | void RealizeTopLevelDeclsFromPreamble(); |
| 374 | |
| 375 | |
| 376 | |
| 377 | void transferASTDataFromCompilerInstance(CompilerInstance &CI); |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | class ConcurrencyState { |
| 387 | void *Mutex; |
| 388 | |
| 389 | public: |
| 390 | ConcurrencyState(); |
| 391 | ~ConcurrencyState(); |
| 392 | |
| 393 | void start(); |
| 394 | void finish(); |
| 395 | }; |
| 396 | ConcurrencyState ConcurrencyCheckValue; |
| 397 | |
| 398 | public: |
| 399 | friend class ConcurrencyCheck; |
| 400 | |
| 401 | class ConcurrencyCheck { |
| 402 | ASTUnit &Self; |
| 403 | |
| 404 | public: |
| 405 | explicit ConcurrencyCheck(ASTUnit &Self) : Self(Self) { |
| 406 | Self.ConcurrencyCheckValue.start(); |
| 407 | } |
| 408 | |
| 409 | ~ConcurrencyCheck() { |
| 410 | Self.ConcurrencyCheckValue.finish(); |
| 411 | } |
| 412 | }; |
| 413 | |
| 414 | ASTUnit(const ASTUnit &) = delete; |
| 415 | ASTUnit &operator=(const ASTUnit &) = delete; |
| 416 | ~ASTUnit(); |
| 417 | |
| 418 | bool isMainFileAST() const { return MainFileIsAST; } |
| 419 | |
| 420 | bool isUnsafeToFree() const { return UnsafeToFree; } |
| 421 | void setUnsafeToFree(bool Value) { UnsafeToFree = Value; } |
| 422 | |
| 423 | const DiagnosticsEngine &getDiagnostics() const { return *Diagnostics; } |
| 424 | DiagnosticsEngine &getDiagnostics() { return *Diagnostics; } |
| 425 | |
| 426 | const SourceManager &getSourceManager() const { return *SourceMgr; } |
| 427 | SourceManager &getSourceManager() { return *SourceMgr; } |
| 428 | |
| 429 | const Preprocessor &getPreprocessor() const { return *PP; } |
| 430 | Preprocessor &getPreprocessor() { return *PP; } |
| 431 | std::shared_ptr<Preprocessor> getPreprocessorPtr() const { return PP; } |
| 432 | |
| 433 | const ASTContext &getASTContext() const { return *Ctx; } |
| 434 | ASTContext &getASTContext() { return *Ctx; } |
| 435 | |
| 436 | void setASTContext(ASTContext *ctx) { Ctx = ctx; } |
| 437 | void setPreprocessor(std::shared_ptr<Preprocessor> pp); |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | void enableSourceFileDiagnostics(); |
| 447 | |
| 448 | bool hasSema() const { return (bool)TheSema; } |
| 449 | |
| 450 | Sema &getSema() const { |
| 451 | (0) . __assert_fail ("TheSema && \"ASTUnit does not have a Sema object!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 451, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TheSema && "ASTUnit does not have a Sema object!"); |
| 452 | return *TheSema; |
| 453 | } |
| 454 | |
| 455 | const LangOptions &getLangOpts() const { |
| 456 | (0) . __assert_fail ("LangOpts && \"ASTUnit does not have language options\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 456, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(LangOpts && "ASTUnit does not have language options"); |
| 457 | return *LangOpts; |
| 458 | } |
| 459 | |
| 460 | const HeaderSearchOptions &() const { |
| 461 | (0) . __assert_fail ("HSOpts && \"ASTUnit does not have header search options\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 461, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(HSOpts && "ASTUnit does not have header search options"); |
| 462 | return *HSOpts; |
| 463 | } |
| 464 | |
| 465 | const PreprocessorOptions &getPreprocessorOpts() const { |
| 466 | (0) . __assert_fail ("PPOpts && \"ASTUnit does not have preprocessor options\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 466, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(PPOpts && "ASTUnit does not have preprocessor options"); |
| 467 | return *PPOpts; |
| 468 | } |
| 469 | |
| 470 | const FileManager &getFileManager() const { return *FileMgr; } |
| 471 | FileManager &getFileManager() { return *FileMgr; } |
| 472 | |
| 473 | const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; } |
| 474 | |
| 475 | IntrusiveRefCntPtr<ASTReader> getASTReader() const; |
| 476 | |
| 477 | StringRef getOriginalSourceFileName() const { |
| 478 | return OriginalSourceFile; |
| 479 | } |
| 480 | |
| 481 | ASTMutationListener *getASTMutationListener(); |
| 482 | ASTDeserializationListener *getDeserializationListener(); |
| 483 | |
| 484 | bool getOnlyLocalDecls() const { return OnlyLocalDecls; } |
| 485 | |
| 486 | bool getOwnsRemappedFileBuffers() const { return OwnsRemappedFileBuffers; } |
| 487 | void setOwnsRemappedFileBuffers(bool val) { OwnsRemappedFileBuffers = val; } |
| 488 | |
| 489 | StringRef getMainFileName() const; |
| 490 | |
| 491 | |
| 492 | StringRef getASTFileName() const; |
| 493 | |
| 494 | using top_level_iterator = std::vector<Decl *>::iterator; |
| 495 | |
| 496 | top_level_iterator top_level_begin() { |
| 497 | (0) . __assert_fail ("!isMainFileAST() && \"Invalid call for AST based ASTUnit!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 497, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); |
| 498 | if (!TopLevelDeclsInPreamble.empty()) |
| 499 | RealizeTopLevelDeclsFromPreamble(); |
| 500 | return TopLevelDecls.begin(); |
| 501 | } |
| 502 | |
| 503 | top_level_iterator top_level_end() { |
| 504 | (0) . __assert_fail ("!isMainFileAST() && \"Invalid call for AST based ASTUnit!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 504, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); |
| 505 | if (!TopLevelDeclsInPreamble.empty()) |
| 506 | RealizeTopLevelDeclsFromPreamble(); |
| 507 | return TopLevelDecls.end(); |
| 508 | } |
| 509 | |
| 510 | std::size_t top_level_size() const { |
| 511 | (0) . __assert_fail ("!isMainFileAST() && \"Invalid call for AST based ASTUnit!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 511, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); |
| 512 | return TopLevelDeclsInPreamble.size() + TopLevelDecls.size(); |
| 513 | } |
| 514 | |
| 515 | bool top_level_empty() const { |
| 516 | (0) . __assert_fail ("!isMainFileAST() && \"Invalid call for AST based ASTUnit!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/ASTUnit.h", 516, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); |
| 517 | return TopLevelDeclsInPreamble.empty() && TopLevelDecls.empty(); |
| 518 | } |
| 519 | |
| 520 | |
| 521 | void addTopLevelDecl(Decl *D) { |
| 522 | TopLevelDecls.push_back(D); |
| 523 | } |
| 524 | |
| 525 | |
| 526 | void addFileLevelDecl(Decl *D); |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length, |
| 532 | SmallVectorImpl<Decl *> &Decls); |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | unsigned &getCurrentTopLevelHashValue() { return CurrentTopLevelHashValue; } |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | SourceLocation getLocation(const FileEntry *File, |
| 545 | unsigned Line, unsigned Col) const; |
| 546 | |
| 547 | |
| 548 | SourceLocation getLocation(const FileEntry *File, unsigned Offset) const; |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | SourceLocation mapLocationFromPreamble(SourceLocation Loc) const; |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | SourceLocation mapLocationToPreamble(SourceLocation Loc) const; |
| 559 | |
| 560 | bool isInPreambleFileID(SourceLocation Loc) const; |
| 561 | bool isInMainFileID(SourceLocation Loc) const; |
| 562 | SourceLocation getStartOfMainFileID() const; |
| 563 | SourceLocation getEndOfPreambleFileID() const; |
| 564 | |
| 565 | |
| 566 | SourceRange mapRangeFromPreamble(SourceRange R) const { |
| 567 | return SourceRange(mapLocationFromPreamble(R.getBegin()), |
| 568 | mapLocationFromPreamble(R.getEnd())); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | SourceRange mapRangeToPreamble(SourceRange R) const { |
| 573 | return SourceRange(mapLocationToPreamble(R.getBegin()), |
| 574 | mapLocationToPreamble(R.getEnd())); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | using stored_diag_iterator = StoredDiagnostic *; |
| 579 | using stored_diag_const_iterator = const StoredDiagnostic *; |
| 580 | |
| 581 | stored_diag_const_iterator stored_diag_begin() const { |
| 582 | return StoredDiagnostics.begin(); |
| 583 | } |
| 584 | |
| 585 | stored_diag_iterator stored_diag_begin() { |
| 586 | return StoredDiagnostics.begin(); |
| 587 | } |
| 588 | |
| 589 | stored_diag_const_iterator stored_diag_end() const { |
| 590 | return StoredDiagnostics.end(); |
| 591 | } |
| 592 | |
| 593 | stored_diag_iterator stored_diag_end() { |
| 594 | return StoredDiagnostics.end(); |
| 595 | } |
| 596 | |
| 597 | unsigned stored_diag_size() const { return StoredDiagnostics.size(); } |
| 598 | |
| 599 | stored_diag_iterator stored_diag_afterDriver_begin() { |
| 600 | if (NumStoredDiagnosticsFromDriver > StoredDiagnostics.size()) |
| 601 | NumStoredDiagnosticsFromDriver = 0; |
| 602 | return StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver; |
| 603 | } |
| 604 | |
| 605 | using cached_completion_iterator = |
| 606 | std::vector<CachedCodeCompletionResult>::iterator; |
| 607 | |
| 608 | cached_completion_iterator cached_completion_begin() { |
| 609 | return CachedCompletionResults.begin(); |
| 610 | } |
| 611 | |
| 612 | cached_completion_iterator cached_completion_end() { |
| 613 | return CachedCompletionResults.end(); |
| 614 | } |
| 615 | |
| 616 | unsigned cached_completion_size() const { |
| 617 | return CachedCompletionResults.size(); |
| 618 | } |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | llvm::iterator_range<PreprocessingRecord::iterator> |
| 624 | getLocalPreprocessingEntities() const; |
| 625 | |
| 626 | |
| 627 | |
| 628 | using DeclVisitorFn = bool (*)(void *context, const Decl *D); |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn); |
| 635 | |
| 636 | |
| 637 | const FileEntry *getPCHFile(); |
| 638 | |
| 639 | |
| 640 | |
| 641 | bool isModuleFile() const; |
| 642 | |
| 643 | std::unique_ptr<llvm::MemoryBuffer> |
| 644 | getBufferForFile(StringRef Filename, std::string *ErrorStr = nullptr); |
| 645 | |
| 646 | |
| 647 | TranslationUnitKind getTranslationUnitKind() const { return TUKind; } |
| 648 | |
| 649 | |
| 650 | InputKind getInputKind() const; |
| 651 | |
| 652 | |
| 653 | |
| 654 | using RemappedFile = std::pair<std::string, llvm::MemoryBuffer *>; |
| 655 | |
| 656 | |
| 657 | static std::unique_ptr<ASTUnit> |
| 658 | create(std::shared_ptr<CompilerInvocation> CI, |
| 659 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags, bool CaptureDiagnostics, |
| 660 | bool UserFilesAreVolatile); |
| 661 | |
| 662 | enum WhatToLoad { |
| 663 | |
| 664 | LoadPreprocessorOnly, |
| 665 | |
| 666 | |
| 667 | LoadASTOnly, |
| 668 | |
| 669 | |
| 670 | LoadEverything |
| 671 | }; |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | static std::unique_ptr<ASTUnit> LoadFromASTFile( |
| 684 | const std::string &Filename, const PCHContainerReader &PCHContainerRdr, |
| 685 | WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, |
| 686 | const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false, |
| 687 | bool OnlyLocalDecls = false, ArrayRef<RemappedFile> RemappedFiles = None, |
| 688 | bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false, |
| 689 | bool UserFilesAreVolatile = false); |
| 690 | |
| 691 | private: |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | bool LoadFromCompilerInvocation( |
| 707 | std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 708 | unsigned PrecompilePreambleAfterNParses, |
| 709 | IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS); |
| 710 | |
| 711 | public: |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | static ASTUnit *LoadFromCompilerInvocationAction( |
| 741 | std::shared_ptr<CompilerInvocation> CI, |
| 742 | std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 743 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags, |
| 744 | FrontendAction *Action = nullptr, ASTUnit *Unit = nullptr, |
| 745 | bool Persistent = true, StringRef ResourceFilesPath = StringRef(), |
| 746 | bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, |
| 747 | unsigned PrecompilePreambleAfterNParses = 0, |
| 748 | bool CacheCodeCompletionResults = false, |
| 749 | bool = false, |
| 750 | bool UserFilesAreVolatile = false, |
| 751 | std::unique_ptr<ASTUnit> *ErrAST = nullptr); |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation( |
| 768 | std::shared_ptr<CompilerInvocation> CI, |
| 769 | std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 770 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr, |
| 771 | bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, |
| 772 | unsigned PrecompilePreambleAfterNParses = 0, |
| 773 | TranslationUnitKind TUKind = TU_Complete, |
| 774 | bool CacheCodeCompletionResults = false, |
| 775 | bool = false, |
| 776 | bool UserFilesAreVolatile = false); |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | static ASTUnit *LoadFromCommandLine( |
| 808 | const char **ArgBegin, const char **ArgEnd, |
| 809 | std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 810 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath, |
| 811 | bool OnlyLocalDecls = false, bool CaptureDiagnostics = false, |
| 812 | ArrayRef<RemappedFile> RemappedFiles = None, |
| 813 | bool RemappedFilesKeepOriginalName = true, |
| 814 | unsigned PrecompilePreambleAfterNParses = 0, |
| 815 | TranslationUnitKind TUKind = TU_Complete, |
| 816 | bool CacheCodeCompletionResults = false, |
| 817 | bool = false, |
| 818 | bool AllowPCHWithCompilerErrors = false, |
| 819 | SkipFunctionBodiesScope SkipFunctionBodies = |
| 820 | SkipFunctionBodiesScope::None, |
| 821 | bool SingleFileParse = false, bool UserFilesAreVolatile = false, |
| 822 | bool ForSerialization = false, |
| 823 | llvm::Optional<StringRef> ModuleFormat = llvm::None, |
| 824 | std::unique_ptr<ASTUnit> *ErrAST = nullptr, |
| 825 | IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr); |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | bool Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 839 | ArrayRef<RemappedFile> RemappedFiles = None, |
| 840 | IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr); |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | void ResetForParse(); |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | void CodeComplete(StringRef File, unsigned Line, unsigned Column, |
| 868 | ArrayRef<RemappedFile> RemappedFiles, bool IncludeMacros, |
| 869 | bool IncludeCodePatterns, bool , |
| 870 | CodeCompleteConsumer &Consumer, |
| 871 | std::shared_ptr<PCHContainerOperations> PCHContainerOps, |
| 872 | DiagnosticsEngine &Diag, LangOptions &LangOpts, |
| 873 | SourceManager &SourceMgr, FileManager &FileMgr, |
| 874 | SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, |
| 875 | SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers); |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | bool Save(StringRef File); |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | bool serialize(raw_ostream &OS); |
| 887 | }; |
| 888 | |
| 889 | } |
| 890 | |
| 891 | #endif |
| 892 | |