ASTUnit.h revision 9b7db6200d366e4964d63ae1f33c7b9d7b9831cb
14b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis//===--- ASTUnit.h - ASTUnit utility ----------------------------*- C++ -*-===// 24b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 34b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// The LLVM Compiler Infrastructure 44b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 54b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// This file is distributed under the University of Illinois Open Source 64b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// License. See LICENSE.TXT for details. 74b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 84b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 94b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 104b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// ASTUnit utility class. 114b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 124b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 134b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis 140853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H 150853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis#define LLVM_CLANG_FRONTEND_ASTUNIT_H 160853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 17eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor#include "clang/Index/ASTLocation.h" 1805a07605322dfef2b017781042043a261c5a89cdSebastian Redl#include "clang/Serialization/ASTBitCodes.h" 19914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor#include "clang/Sema/Sema.h" 200a2c5e256abb4dc031c21fe4dc92c4f3afe9947cJohn McCall#include "clang/Sema/CodeCompleteConsumer.h" 214ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor#include "clang/Lex/PreprocessingRecord.h" 2231b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbar#include "clang/Basic/SourceManager.h" 23eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor#include "clang/Basic/FileManager.h" 24389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis#include "clang/Basic/FileSystemOptions.h" 2587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor#include "clang-c/Index.h" 2628019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 270853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis#include "llvm/ADT/OwningPtr.h" 28a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor#include "llvm/ADT/SmallVector.h" 29cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor#include "llvm/ADT/StringMap.h" 3003013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" 31788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor#include <map> 320853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis#include <string> 33f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar#include <vector> 34f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar#include <cassert> 354db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor#include <utility> 36cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor#include <sys/types.h> 374db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor 384db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregornamespace llvm { 394db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor class MemoryBuffer; 404db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor} 410853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 420853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidisnamespace clang { 43521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass ASTContext; 441abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregorclass CodeCompleteConsumer; 45521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass CompilerInvocation; 46521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass Decl; 47521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass Diagnostic; 48521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass FileEntry; 49521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass FileManager; 50521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass HeaderSearch; 51521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass Preprocessor; 52521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass SourceManager; 53521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass TargetInfo; 540853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 55f96b524306ccfa623235d375deee79637bd38f29Steve Naroffusing namespace idx; 5644c181aec37789f25f6c15543c164416f72e562aDouglas Gregor 573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl/// \brief Utility class for loading a ASTContext from an AST file. 580853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis/// 590853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidisclass ASTUnit { 60788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregorpublic: 61788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor typedef std::map<FileID, std::vector<PreprocessedEntity *> > 62788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor PreprocessedEntitiesByFileMap; 63bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor 64788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregorprivate: 6528019772db70d4547be05a042eb950bc910f134fDouglas Gregor llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics; 66405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor llvm::OwningPtr<FileManager> FileMgr; 67405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor llvm::OwningPtr<SourceManager> SourceMgr; 680853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis llvm::OwningPtr<HeaderSearch> HeaderInfo; 690853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis llvm::OwningPtr<TargetInfo> Target; 700853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis llvm::OwningPtr<Preprocessor> PP; 710853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis llvm::OwningPtr<ASTContext> Ctx; 72389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 73389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis FileSystemOptions FileSystemOpts; 74389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 75914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor /// \brief The AST consumer that received information about the translation 76914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor /// unit as it was parsed or loaded. 77914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor llvm::OwningPtr<ASTConsumer> Consumer; 78914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor 79914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor /// \brief The semantic analysis object used to type-check the translation 80914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor /// unit. 81914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor llvm::OwningPtr<Sema> TheSema; 82914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor 83807b06157a1a5c050520fc194d32f16d22d423a8Daniel Dunbar /// Optional owned invocation, just used to make the invocation used in 84807b06157a1a5c050520fc194d32f16d22d423a8Daniel Dunbar /// LoadFromCommandLine available. 85807b06157a1a5c050520fc194d32f16d22d423a8Daniel Dunbar llvm::OwningPtr<CompilerInvocation> Invocation; 86914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor 871aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor /// \brief The set of target features. 881aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor /// 891aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor /// FIXME: each time we reparse, we need to restore the set of target 901aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor /// features from this vector, because TargetInfo::CreateTargetInfo() 911aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor /// mangles the target options in place. Yuck! 921aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor std::vector<std::string> TargetFeatures; 931aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor 947d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // OnlyLocalDecls - when true, walking this AST should only visit declarations 957d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // that come from the AST itself, not from included precompiled headers. 967d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // FIXME: This is temporary; eventually, CIndex will always do this. 977d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor bool OnlyLocalDecls; 98c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar 99abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// \brief Whether to capture any diagnostics produced. 100abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor bool CaptureDiagnostics; 101e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor 102df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// \brief Track whether the main file was loaded from an AST or not. 103c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar bool MainFileIsAST; 104c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar 105df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// \brief Whether this AST represents a complete translation unit. 106df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor bool CompleteTranslationUnit; 107df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor 108213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor /// \brief Whether we should time each operation. 109213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor bool WantTiming; 110213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor 111f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar /// Track the top-level decls which appeared in an ASTUnit which was loaded 112f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar /// from a source file. 113f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar // 114f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar // FIXME: This is just an optimization hack to avoid deserializing large parts 115f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar // of a PCH file when using the Index library on an ASTUnit loaded from 116f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar // source. In the long term we should make the Index library use efficient and 117f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar // more scalable search mechanisms. 118f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar std::vector<Decl*> TopLevelDecls; 119f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 12089d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// \brief The list of preprocessed entities which appeared when the ASTUnit 12189d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// was loaded. 12289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// 12389d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// FIXME: This is just an optimization hack to avoid deserializing large 12489d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// parts of a PCH file while performing a walk or search. In the long term, 12589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// we should provide more scalable search mechanisms. 12689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor std::vector<PreprocessedEntity *> PreprocessedEntities; 12789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 12868d40e2d16b9fadba386853d6bbb60089291fdc5Daniel Dunbar /// The name of the original source file used to generate this ASTUnit. 12968d40e2d16b9fadba386853d6bbb60089291fdc5Daniel Dunbar std::string OriginalSourceFile; 13068d40e2d16b9fadba386853d6bbb60089291fdc5Daniel Dunbar 131f96b524306ccfa623235d375deee79637bd38f29Steve Naroff // Critical optimization when using clang_getCursor(). 132f96b524306ccfa623235d375deee79637bd38f29Steve Naroff ASTLocation LastLoc; 133f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 134a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor /// \brief The set of diagnostics produced when creating this 135a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor /// translation unit. 136405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor llvm::SmallVector<StoredDiagnostic, 4> StoredDiagnostics; 137a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 1384cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// \brief The number of stored diagnostics that come from the driver 1394cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// itself. 1404cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// 1414cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// Diagnostics that come from the driver are retained from one parse to 1424cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// the next. 1434cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor unsigned NumStoredDiagnosticsFromDriver; 1444cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 145313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor /// \brief Temporary files that should be removed when the ASTUnit is 146313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor /// destroyed. 147313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor llvm::SmallVector<llvm::sys::Path, 4> TemporaryFiles; 148bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 149788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// \brief A mapping from file IDs to the set of preprocessed entities 150788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// stored in that file. 151788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// 152788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// FIXME: This is just an optimization hack to avoid searching through 153788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// many preprocessed entities during cursor traversal in the CIndex library. 154788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// Ideally, we would just be able to perform a binary search within the 155788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// list of preprocessed entities. 156788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor PreprocessedEntitiesByFileMap PreprocessedEntitiesByFile; 157788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor 158bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor /// \brief Simple hack to allow us to assert that ASTUnit is not being 159bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor /// used concurrently, which is not supported. 160bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor /// 161bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor /// Clients should create instances of the ConcurrencyCheck class whenever 162bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor /// using the ASTUnit in a way that isn't intended to be concurrent, which is 163bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor /// just about any usage. 164bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor unsigned int ConcurrencyCheckValue; 165bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor static const unsigned int CheckLocked = 28573289; 166bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor static const unsigned int CheckUnlocked = 9803453; 167175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor 168eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// \brief Counter that determines when we want to try building a 169eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// precompiled preamble. 170eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// 171eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// If zero, we will never build a precompiled preamble. Otherwise, 172eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// it's treated as a counter that decrements each time we reparse 173eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// without the benefit of a precompiled preamble. When it hits 1, 174eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// we'll attempt to rebuild the precompiled header. This way, if 175eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// building the precompiled preamble fails, we won't try again for 176eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// some number of calls. 177eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor unsigned PreambleRebuildCounter; 178eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor 179175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor /// \brief The file in which the precompiled preamble is stored. 180385103b79c5338a2be5da0ca70652400bc267371Douglas Gregor std::string PreambleFile; 181175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor 182175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor /// \brief The contents of the preamble that has been precompiled to 183175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor /// \c PreambleFile. 184175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor std::vector<char> Preamble; 185175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor 186f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// \brief Whether the preamble ends at the start of a new line. 187f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// 188f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// Used to inform the lexer as to whether it's starting at the beginning of 189f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// a line after skipping the preamble. 190f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor bool PreambleEndsAtStartOfLine; 191f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor 192175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor /// \brief The size of the source buffer that we've reserved for the main 193175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor /// file within the precompiled preamble. 194175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor unsigned PreambleReservedSize; 195cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor 196cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// \brief Keeps track of the files that were used when computing the 197cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// preamble, with both their buffer size and their modification time. 198cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// 199cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// If any of the files have changed from one compile to the next, 200cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor /// the preamble must be thrown away. 201cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor llvm::StringMap<std::pair<off_t, time_t> > FilesInPreamble; 202cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor 20328233428da1ebec20c893d6297ae3191318940ddDouglas Gregor /// \brief When non-NULL, this is the buffer used to store the contents of 20428233428da1ebec20c893d6297ae3191318940ddDouglas Gregor /// the main file when it has been padded for use with the precompiled 20528233428da1ebec20c893d6297ae3191318940ddDouglas Gregor /// preamble. 20628233428da1ebec20c893d6297ae3191318940ddDouglas Gregor llvm::MemoryBuffer *SavedMainFileBuffer; 207c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 208671947b18dba342f9aba022ee992babef325a833Douglas Gregor /// \brief When non-NULL, this is the buffer used to store the 209671947b18dba342f9aba022ee992babef325a833Douglas Gregor /// contents of the preamble when it has been padded to build the 210671947b18dba342f9aba022ee992babef325a833Douglas Gregor /// precompiled preamble. 211671947b18dba342f9aba022ee992babef325a833Douglas Gregor llvm::MemoryBuffer *PreambleBuffer; 212671947b18dba342f9aba022ee992babef325a833Douglas Gregor 213c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// \brief The number of warnings that occurred while parsing the preamble. 214c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// 215c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// This value will be used to restore the state of the \c Diagnostic object 216c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// when re-using the precompiled preamble. Note that only the 217c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// number of warnings matters, since we will not save the preamble 218c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// when any errors are present. 219c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor unsigned NumWarningsInPreamble; 220c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 221c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// \brief The number of diagnostics that were stored when parsing 222c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// the precompiled preamble. 223c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// 224c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// This value is used to determine how many of the stored 225c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// diagnostics should be retained when reparsing in the presence of 226c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor /// a precompiled preamble. 227c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor unsigned NumStoredDiagnosticsInPreamble; 228c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 2293c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief A list of the serialization ID numbers for each of the top-level 230eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor /// declarations parsed within the precompiled preamble. 2318538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl std::vector<serialization::DeclID> TopLevelDeclsInPreamble; 232eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 23389d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// \brief A list of the offsets into the precompiled preamble which 23489d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// correspond to preprocessed entities. 23589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor std::vector<uint64_t> PreprocessedEntitiesInPreamble; 23689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 23787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief Whether we should be caching code-completion results. 23887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor bool ShouldCacheCodeCompletionResults; 23987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 240e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor static void ConfigureDiags(llvm::IntrusiveRefCntPtr<Diagnostic> &Diags, 2410b53cf834346d78985aaa9e7300445a39c245614Douglas Gregor const char **ArgBegin, const char **ArgEnd, 242e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor ASTUnit &AST, bool CaptureDiagnostics); 243e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor 24487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregorpublic: 24587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief A cached code-completion result, which may be introduced in one of 24687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// many different contexts. 24787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor struct CachedCodeCompletionResult { 24887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief The code-completion string corresponding to this completion 24987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// result. 25087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor CodeCompletionString *Completion; 25187c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 25287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief A bitmask that indicates which code-completion contexts should 25387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// contain this completion result. 25487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// 25587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// The bits in the bitmask correspond to the values of 25687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// CodeCompleteContext::Kind. To map from a completion context kind to a 25787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// bit, subtract one from the completion context kind and shift 1 by that 25887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// number of bits. Many completions can occur in several different 25987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// contexts. 26087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor unsigned ShowInContexts; 26187c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 26287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief The priority given to this code-completion result. 26387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor unsigned Priority; 26487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 26587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief The libclang cursor kind corresponding to this code-completion 26687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// result. 26787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor CXCursorKind Kind; 2681827e10051638770ad9ccf3e285caf95f995afd1Douglas Gregor 26958ddb60f409125eda5436c4a1f070f7fa4744295Douglas Gregor /// \brief The availability of this code-completion result. 27058ddb60f409125eda5436c4a1f070f7fa4744295Douglas Gregor CXAvailabilityKind Availability; 27158ddb60f409125eda5436c4a1f070f7fa4744295Douglas Gregor 2721827e10051638770ad9ccf3e285caf95f995afd1Douglas Gregor /// \brief The simplified type class for a non-macro completion result. 2731827e10051638770ad9ccf3e285caf95f995afd1Douglas Gregor SimplifiedTypeClass TypeClass; 274f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 275f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// \brief The type of a non-macro completion result, stored as a unique 276f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// integer used by the string map of cached completion types. 277f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// 278f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// This value will be zero if the type is not known, or a unique value 279f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// determined by the formatted type string. Se \c CachedCompletionTypes 280f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// for more information. 281f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor unsigned Type; 28287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor }; 28387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 284f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// \brief Retrieve the mapping from formatted type names to unique type 285f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// identifiers. 286f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor llvm::StringMap<unsigned> &getCachedCompletionTypes() { 287f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor return CachedCompletionTypes; 288f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor } 289f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 29087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregorprivate: 291218937c13ef5b0625a70aad41ca7a92da9278bd2Douglas Gregor /// \brief Allocator used to store cached code completions. 292dae687575010c9c49a4b552f5eef82cd6279d9acDouglas Gregor CodeCompletionAllocator CachedCompletionAllocator; 293218937c13ef5b0625a70aad41ca7a92da9278bd2Douglas Gregor 29487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief The set of cached code-completion results. 29587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor std::vector<CachedCodeCompletionResult> CachedCompletionResults; 29687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 297f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// \brief A mapping from the formatted type name to a unique number for that 298f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor /// type, which is used for type equality comparisons. 299f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor llvm::StringMap<unsigned> CachedCompletionTypes; 300f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 3019b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// \brief A string hash of the top-level declaration and macro definition 3029b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// names processed the last time that we reparsed the file. 303727d93ef49e18147149354fadd10e86b13bc4ab0Douglas Gregor /// 3049b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// This hash value is used to determine when we need to refresh the 3059b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// global code-completion cache. 3069b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor unsigned CompletionCacheTopLevelHashValue; 307727d93ef49e18147149354fadd10e86b13bc4ab0Douglas Gregor 3089b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// \brief A string hash of the top-level declaration and macro definition 3099b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// names processed the last time that we reparsed the precompiled preamble. 310727d93ef49e18147149354fadd10e86b13bc4ab0Douglas Gregor /// 3119b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// This hash value is used to determine when we need to refresh the 3129b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// global code-completion cache after a rebuild of the precompiled preamble. 3139b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor unsigned PreambleTopLevelHashValue; 314ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar 3159b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// \brief The current hash value for the top-level declaration and macro 3169b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// definition names 3179b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor unsigned CurrentTopLevelHashValue; 3189b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor 319ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar /// \brief Bit used by CIndex to mark when a translation unit may be in an 320ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar /// inconsistent state, and is not safe to free. 321ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar unsigned UnsafeToFree : 1; 322ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar 323c4421e966d77a18f815284175b3fcbb46f36fa39Douglas Gregor /// \brief Cache any "global" code-completion results, so that we can avoid 324c4421e966d77a18f815284175b3fcbb46f36fa39Douglas Gregor /// recomputing them with each completion. 32587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor void CacheCodeCompletionResults(); 32687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 32787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor /// \brief Clear out and deallocate 32887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor void ClearCachedCompletionResults(); 32987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 33031b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbar ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT 33131b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbar ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT 332bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 3333687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor explicit ASTUnit(bool MainFileIsAST); 3348b96253907c47141af0b7b2a44a368748d006a87Douglas Gregor 335abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor void CleanTemporaryFiles(); 336754f3490c5b0f5d83361f001bc87944f23644abbDouglas Gregor bool Parse(llvm::MemoryBuffer *OverrideMainBuffer); 337175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor 338f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor std::pair<llvm::MemoryBuffer *, std::pair<unsigned, bool> > 339df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor ComputePreamble(CompilerInvocation &Invocation, 340df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor unsigned MaxLines, bool &CreatedBuffer); 341175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor 342df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor llvm::MemoryBuffer *getMainBufferWithPrecompiledPreamble( 3432283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor CompilerInvocation PreambleInvocation, 344df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor bool AllowRebuild = true, 345df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor unsigned MaxLines = 0); 346eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor void RealizeTopLevelDeclsFromPreamble(); 34789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor void RealizePreprocessedEntitiesFromPreamble(); 34889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 3490853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidispublic: 350bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor class ConcurrencyCheck { 351bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor volatile ASTUnit &Self; 352bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 353bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor public: 354bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor explicit ConcurrencyCheck(ASTUnit &Self) 355bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor : Self(Self) 356bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor { 357bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor assert(Self.ConcurrencyCheckValue == CheckUnlocked && 358bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor "Concurrent access to ASTUnit!"); 359bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor Self.ConcurrencyCheckValue = CheckLocked; 360bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor } 361bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 362bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor ~ConcurrencyCheck() { 363bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor Self.ConcurrencyCheckValue = CheckUnlocked; 364bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor } 365bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor }; 366bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor friend class ConcurrencyCheck; 367bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 3680853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis ~ASTUnit(); 3690853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 370c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar bool isMainFileAST() const { return MainFileIsAST; } 371c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar 372ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar bool isUnsafeToFree() const { return UnsafeToFree; } 373ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar void setUnsafeToFree(bool Value) { UnsafeToFree = Value; } 374ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar 3753687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor const Diagnostic &getDiagnostics() const { return *Diagnostics; } 3763687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor Diagnostic &getDiagnostics() { return *Diagnostics; } 3773687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor 378405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor const SourceManager &getSourceManager() const { return *SourceMgr; } 379405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor SourceManager &getSourceManager() { return *SourceMgr; } 3800853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 3810853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis const Preprocessor &getPreprocessor() const { return *PP.get(); } 3820853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis Preprocessor &getPreprocessor() { return *PP.get(); } 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3840853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis const ASTContext &getASTContext() const { return *Ctx.get(); } 3850853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis ASTContext &getASTContext() { return *Ctx.get(); } 3860853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 387914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor bool hasSema() const { return TheSema; } 388914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor Sema &getSema() const { 389914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor assert(TheSema && "ASTUnit does not have a Sema object!"); 390914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor return *TheSema; 391914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor } 392914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor 393405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor const FileManager &getFileManager() const { return *FileMgr; } 394405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor FileManager &getFileManager() { return *FileMgr; } 395f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 396389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; } 397389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 39877accc11f04ed4ff9afd4e27d430144d4714be56Steve Naroff const std::string &getOriginalSourceFileName(); 3993c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl const std::string &getASTFileName(); 400b85bca2676b433ae555db09de4dd2823ff13b856Zhongxing Xu 401313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor /// \brief Add a temporary file that the ASTUnit depends on. 402313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor /// 403313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor /// This file will be erased when the ASTUnit is destroyed. 404313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor void addTemporaryFile(const llvm::sys::Path &TempFile) { 405313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor TemporaryFiles.push_back(TempFile); 406313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor } 407313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor 4087d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor bool getOnlyLocalDecls() const { return OnlyLocalDecls; } 409f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 410eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor /// \brief Retrieve the maximum PCH level of declarations that a 411eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor /// traversal of the translation unit should consider. 412eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor unsigned getMaxPCHLevel() const; 413eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 414f96b524306ccfa623235d375deee79637bd38f29Steve Naroff void setLastASTLocation(ASTLocation ALoc) { LastLoc = ALoc; } 415f96b524306ccfa623235d375deee79637bd38f29Steve Naroff ASTLocation getLastASTLocation() const { return LastLoc; } 416f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 417213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor 418213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor llvm::StringRef getMainFileName() const; 419213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor 420eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor typedef std::vector<Decl *>::iterator top_level_iterator; 421eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 422eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor top_level_iterator top_level_begin() { 423f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); 424eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor if (!TopLevelDeclsInPreamble.empty()) 425eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor RealizeTopLevelDeclsFromPreamble(); 426eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor return TopLevelDecls.begin(); 427f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar } 428eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 429eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor top_level_iterator top_level_end() { 430f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); 431eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor if (!TopLevelDeclsInPreamble.empty()) 432eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor RealizeTopLevelDeclsFromPreamble(); 433eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor return TopLevelDecls.end(); 434eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 435eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 436eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor std::size_t top_level_size() const { 437eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); 438eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor return TopLevelDeclsInPreamble.size() + TopLevelDecls.size(); 439eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 440eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 441eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor bool top_level_empty() const { 442eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!"); 443eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor return TopLevelDeclsInPreamble.empty() && TopLevelDecls.empty(); 444eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 445eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 446eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor /// \brief Add a new top-level declaration. 447eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor void addTopLevelDecl(Decl *D) { 448eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor TopLevelDecls.push_back(D); 449eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 450eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 451eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor /// \brief Add a new top-level declaration, identified by its ID in 452eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor /// the precompiled preamble. 4538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl void addTopLevelDeclFromPreamble(serialization::DeclID D) { 454eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor TopLevelDeclsInPreamble.push_back(D); 455f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar } 456f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 4579b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// \brief Retrieve a reference to the current top-level name hash value. 4589b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// 4599b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor /// Note: This is used internally by the top-level tracking action 4609b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor unsigned &getCurrentTopLevelHashValue() { return CurrentTopLevelHashValue; } 4619b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor 46289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor typedef std::vector<PreprocessedEntity *>::iterator pp_entity_iterator; 46389d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 46489d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor pp_entity_iterator pp_entity_begin(); 46589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor pp_entity_iterator pp_entity_end(); 46689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 46789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// \brief Add a new preprocessed entity that's stored at the given offset 46889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor /// in the precompiled preamble. 46989d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor void addPreprocessedEntityFromPreamble(uint64_t Offset) { 47089d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor PreprocessedEntitiesInPreamble.push_back(Offset); 47189d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor } 47289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 473788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// \brief Retrieve the mapping from File IDs to the preprocessed entities 474788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// within that file. 475788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor PreprocessedEntitiesByFileMap &getPreprocessedEntitiesByFile() { 476788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor return PreprocessedEntitiesByFile; 477788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor } 478788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor 479a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor // Retrieve the diagnostics associated with this AST 480405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor typedef const StoredDiagnostic *stored_diag_iterator; 481405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor stored_diag_iterator stored_diag_begin() const { 482405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor return StoredDiagnostics.begin(); 483405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor } 484405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor stored_diag_iterator stored_diag_end() const { 485405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor return StoredDiagnostics.end(); 486405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor } 487405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor unsigned stored_diag_size() const { return StoredDiagnostics.size(); } 488405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor 489405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor llvm::SmallVector<StoredDiagnostic, 4> &getStoredDiagnostics() { 490405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor return StoredDiagnostics; 491a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor } 492a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 49387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor typedef std::vector<CachedCodeCompletionResult>::iterator 49487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor cached_completion_iterator; 49587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 49687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor cached_completion_iterator cached_completion_begin() { 49787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor return CachedCompletionResults.begin(); 49887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor } 49987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 50087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor cached_completion_iterator cached_completion_end() { 50187c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor return CachedCompletionResults.end(); 50287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor } 50387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 50487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor unsigned cached_completion_size() const { 50587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor return CachedCompletionResults.size(); 50687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor } 507389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 508389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis llvm::MemoryBuffer *getBufferForFile(llvm::StringRef Filename, 50975dfb65c38d51772df9a00ce2d2feeefd55667adChris Lattner std::string *ErrorStr = 0); 510389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 511df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// \brief Whether this AST represents a complete translation unit. 512df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// 513df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// If false, this AST is only a partial translation unit, e.g., one 514df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// that might still be used as a precompiled header or preamble. 515df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor bool isCompleteTranslationUnit() const { return CompleteTranslationUnit; } 516df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor 5174db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor /// \brief A mapping from a file name to the memory buffer that stores the 5184db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor /// remapped contents of that file. 5194db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor typedef std::pair<std::string, const llvm::MemoryBuffer *> RemappedFile; 5204db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor 5213c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \brief Create a ASTUnit from an AST file. 5220853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis /// 5233c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \param Filename - The AST file to load. 5240853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis /// 5255262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar /// \param Diags - The diagnostics engine to use for reporting errors; its 5265262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar /// lifetime is expected to extend past that of the returned ASTUnit. 52731b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbar /// 5283c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// \returns - The initialized ASTUnit or null if the AST failed to load. 5293c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl static ASTUnit *LoadFromASTFile(const std::string &Filename, 53028019772db70d4547be05a042eb950bc910f134fDouglas Gregor llvm::IntrusiveRefCntPtr<Diagnostic> Diags, 531389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis const FileSystemOptions &FileSystemOpts, 5325cf48766d626ff6b223acc9d4b7e415ca8480836Ted Kremenek bool OnlyLocalDecls = false, 5334db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor RemappedFile *RemappedFiles = 0, 534a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor unsigned NumRemappedFiles = 0, 535a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor bool CaptureDiagnostics = false); 536521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar 5374cd912aa94656697a44c3ebb159f05060300524eDouglas Gregorprivate: 5384cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// \brief Helper function for \c LoadFromCompilerInvocation() and 5394cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation. 5404cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// 5414cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// \param PrecompilePreamble Whether to precompile the preamble of this 5424cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// translation unit, to improve the performance of reparsing. 5434cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// 5444cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// \returns \c true if a catastrophic failure occurred (which means that the 5454cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor /// \c ASTUnit itself is invalid), or \c false otherwise. 5464cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor bool LoadFromCompilerInvocation(bool PrecompilePreamble); 5474cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 5484cd912aa94656697a44c3ebb159f05060300524eDouglas Gregorpublic: 5494cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 550521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar /// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a 551521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar /// CompilerInvocation object. 552521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar /// 553521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar /// \param CI - The compiler invocation to use; it must have exactly one input 554f7acc37450d59ef751df73acb91de73850cc6517Daniel Dunbar /// source file. The ASTUnit takes ownership of the CompilerInvocation object. 555521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar /// 5565262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar /// \param Diags - The diagnostics engine to use for reporting errors; its 5575262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar /// lifetime is expected to extend past that of the returned ASTUnit. 558521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar // 559521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we 560521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar // shouldn't need to specify them at construction time. 561f7acc37450d59ef751df73acb91de73850cc6517Daniel Dunbar static ASTUnit *LoadFromCompilerInvocation(CompilerInvocation *CI, 56228019772db70d4547be05a042eb950bc910f134fDouglas Gregor llvm::IntrusiveRefCntPtr<Diagnostic> Diags, 563a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor bool OnlyLocalDecls = false, 56444c181aec37789f25f6c15543c164416f72e562aDouglas Gregor bool CaptureDiagnostics = false, 565df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor bool PrecompilePreamble = false, 56687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor bool CompleteTranslationUnit = true, 56787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor bool CacheCodeCompletionResults = false); 568521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar 5697b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// LoadFromCommandLine - Create an ASTUnit from a vector of command line 5707b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// arguments, which must specify exactly one source file. 5717b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// 5727b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// \param ArgBegin - The beginning of the argument vector. 5737b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// 5747b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// \param ArgEnd - The end of the argument vector. 5757b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// 5765262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar /// \param Diags - The diagnostics engine to use for reporting errors; its 5775262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar /// lifetime is expected to extend past that of the returned ASTUnit. 5787b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// 579869824e87940f97b87064db2df2861e82e08a8c6Daniel Dunbar /// \param ResourceFilesPath - The path to the compiler resource files. 5807b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar // 5817b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we 5827b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar // shouldn't need to specify them at construction time. 5837b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar static ASTUnit *LoadFromCommandLine(const char **ArgBegin, 5847b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar const char **ArgEnd, 58528019772db70d4547be05a042eb950bc910f134fDouglas Gregor llvm::IntrusiveRefCntPtr<Diagnostic> Diags, 586869824e87940f97b87064db2df2861e82e08a8c6Daniel Dunbar llvm::StringRef ResourceFilesPath, 5877b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar bool OnlyLocalDecls = false, 588e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor bool CaptureDiagnostics = false, 5894db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor RemappedFile *RemappedFiles = 0, 590a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor unsigned NumRemappedFiles = 0, 591df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor bool PrecompilePreamble = false, 59287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor bool CompleteTranslationUnit = true, 59399ba202f659e1885fa5ee114f97c97cf6a857491Douglas Gregor bool CacheCodeCompletionResults = false, 59499ba202f659e1885fa5ee114f97c97cf6a857491Douglas Gregor bool CXXPrecompilePreamble = false, 59599ba202f659e1885fa5ee114f97c97cf6a857491Douglas Gregor bool CXXChainedPCH = false); 596abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 597abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// \brief Reparse the source files using the same command-line options that 598abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// were originally used to produce this translation unit. 599abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// 600abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// \returns True if a failure occurred that causes the ASTUnit not to 601abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// contain any translation-unit information, false otherwise. 602abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor bool Reparse(RemappedFile *RemappedFiles = 0, 603abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor unsigned NumRemappedFiles = 0); 6041abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor 6051abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor /// \brief Perform code completion at the given file, line, and 6061abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor /// column within this translation unit. 6071abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor /// 608cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// \param File The file in which code completion will occur. 609cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// 610cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// \param Line The line at which code completion will occur. 611cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// 612cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// \param Column The column at which code completion will occur. 613cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// 614cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// \param IncludeMacros Whether to include macros in the code-completion 615cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// results. 616cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// 617cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// \param IncludeCodePatterns Whether to include code patterns (such as a 618cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor /// for loop) in the code-completion results. 6191abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor /// 6202283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and 6212283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor /// OwnedBuffers parameters are all disgusting hacks. They will go away. 6221abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor void CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column, 6231abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor RemappedFile *RemappedFiles, unsigned NumRemappedFiles, 624cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor bool IncludeMacros, bool IncludeCodePatterns, 6251abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor CodeCompleteConsumer &Consumer, 6261abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor Diagnostic &Diag, LangOptions &LangOpts, 6271abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor SourceManager &SourceMgr, FileManager &FileMgr, 6282283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor llvm::SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics, 6292283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor llvm::SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers); 6307ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor 6317ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor /// \brief Save this translation unit to a file with the given name. 6327ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor /// 6337ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor /// \returns True if an error occurred, false otherwise. 6347ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor bool Save(llvm::StringRef File); 6350853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis}; 6360853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 6370853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis} // namespace clang 6380853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 6390853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis#endif 640