1c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann//===- ExternalASTSource.cpp - Abstract External AST Interface --*- C++ -*-===// 2c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// 3c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// The LLVM Compiler Infrastructure 4c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// 5c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// This file is distributed under the University of Illinois Open Source 6c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// License. See LICENSE.TXT for details. 7c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// 8c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann//===----------------------------------------------------------------------===// 9c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// 10c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// This file provides the default implementation of the ExternalASTSource 11c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// interface, which enables construction of AST nodes from some external 12c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// source. 13c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann// 14c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann//===----------------------------------------------------------------------===// 15c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 16c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann#include "clang/AST/ExternalASTSource.h" 176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "clang/AST/ASTContext.h" 18c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann#include "clang/AST/DeclarationName.h" 19a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar#include "clang/Basic/Module.h" 206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "llvm/Support/ErrorHandling.h" 21c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 22c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumannusing namespace clang; 23c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 24c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel NaumannExternalASTSource::~ExternalASTSource() { } 25c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 26a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarllvm::Optional<ExternalASTSource::ASTSourceDescriptor> 27a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga NainarExternalASTSource::getSourceDescriptor(unsigned ID) { 28a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar return None; 29a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar} 30a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar 31a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga NainarExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M) 32a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar : Signature(M.Signature), ClangModule(&M) { 33a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar if (M.Directory) 34a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Path = M.Directory->getName(); 35a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar if (auto *File = M.getASTFile()) 36a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar ASTFile = File->getName(); 37a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar} 38a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar 39a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarstd::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const { 40a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar if (ClangModule) 41a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar return ClangModule->Name; 42a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar else 43a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar return PCHModuleName; 44a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar} 45a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar 466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset, 476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines unsigned Length, 486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SmallVectorImpl<Decl *> &Decls) {} 496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::CompleteRedeclChain(const Decl *D) {} 516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::CompleteType(TagDecl *Tag) {} 536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {} 556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::ReadComments() {} 576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::StartedDeserializing() {} 596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::FinishedDeserializing() {} 616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {} 636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 64c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumannvoid ExternalASTSource::PrintStats() { } 65c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesbool ExternalASTSource::layoutRecordType( 676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, 686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, 696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, 706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) { 716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return false; 726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines} 736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 74c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel NaumannDecl *ExternalASTSource::GetExternalDecl(uint32_t ID) { 756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 76c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann} 77c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 78c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel NaumannSelector ExternalASTSource::GetExternalSelector(uint32_t ID) { 79c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann return Selector(); 80c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann} 81c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 82c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumannuint32_t ExternalASTSource::GetNumExternalSelectors() { 83c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann return 0; 84c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann} 85c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 86c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel NaumannStmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) { 876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 88c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann} 89c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 903ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga NainarCXXCtorInitializer ** 913ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga NainarExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) { 923ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar return nullptr; 933ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar} 943ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 95c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel NaumannCXXBaseSpecifier * 96c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel NaumannExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) { 976bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 98c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann} 99c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 1003646c68676c3c46a026b23d52188ef6e0d856178Richard Smithbool 101c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel NaumannExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC, 102c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann DeclarationName Name) { 1033646c68676c3c46a026b23d52188ef6e0d856178Richard Smith return false; 104c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann} 105c304d9058ad69ff1fcbc6d19ca0be91acfa243a2Axel Naumann 106a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {} 107b346d2f419ec7d7ce6b20780d518490338efa7deNick Lewycky 108a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid ExternalASTSource::FindExternalLexicalDecls( 109a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, 110a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar SmallVectorImpl<Decl *> &Result) {} 11169d891d45a29fdd0074ff3eb158694e95fef57e1Axel Naumann 112a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {} 1136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesuint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { 1156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines uint32_t OldGeneration = CurrentGeneration; 1166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // Make sure the generation of the topmost external source for the context is 1186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // incremented. That might not be us. 1196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines auto *P = C.getExternalSource(); 1206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines if (P && P != this) 1216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines CurrentGeneration = P->incrementGeneration(C); 1226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines else { 1236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // FIXME: Only bump the generation counter if the current generation number 1246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // has been observed? 1256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines if (!++CurrentGeneration) 1266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::report_fatal_error("generation counter overflowed", false); 1276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines } 1286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return OldGeneration; 1306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines} 131