clang  9.0.0svn
ExternalASTSource.cpp
Go to the documentation of this file.
1 //===- ExternalASTSource.cpp - Abstract External AST Interface ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the default implementation of the ExternalASTSource
10 // interface, which enables construction of AST nodes from some external
11 // source.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "clang/AST/ASTContext.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/Module.h"
21 #include "llvm/ADT/None.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include <cstdint>
24 
25 using namespace clang;
26 
28 
31  return None;
32 }
33 
36  return EK_ReplyHazy;
37 }
38 
40  : Signature(M.Signature), ClangModule(&M) {
41  if (M.Directory)
42  Path = M.Directory->getName();
43  if (auto *File = M.getASTFile())
44  ASTFile = File->getName();
45 }
46 
48  if (ClangModule)
49  return ClangModule->Name;
50  else
51  return PCHModuleName;
52 }
53 
55  unsigned Length,
56  SmallVectorImpl<Decl *> &Decls) {}
57 
59 
61 
63 
65 
67 
69 
71 
73 
75  const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
76  llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
77  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
78  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) {
79  return false;
80 }
81 
83  return nullptr;
84 }
85 
87  return Selector();
88 }
89 
91  return 0;
92 }
93 
95  return nullptr;
96 }
97 
100  return nullptr;
101 }
102 
105  return nullptr;
106 }
107 
108 bool
110  DeclarationName Name) {
111  return false;
112 }
113 
115 
117  const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
119 
121 
123  uint32_t OldGeneration = CurrentGeneration;
124 
125  // Make sure the generation of the topmost external source for the context is
126  // incremented. That might not be us.
127  auto *P = C.getExternalSource();
128  if (P && P != this)
129  CurrentGeneration = P->incrementGeneration(C);
130  else {
131  // FIXME: Only bump the generation counter if the current generation number
132  // has been observed?
133  if (!++CurrentGeneration)
134  llvm::report_fatal_error("generation counter overflowed", false);
135  }
136 
137  return OldGeneration;
138 }
Defines the clang::ASTContext interface.
std::string Name
The name of this module.
Definition: Module.h:67
Smart pointer class that efficiently represents Objective-C method names.
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
virtual void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl *> &Result)
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:33
Stmt - This represents one statement.
Definition: Stmt.h:65
Defines the clang::Module class, which describes a module in the source code.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
StringRef P
virtual uint32_t GetNumExternalSelectors()
Returns the number of selectors known to the external AST source.
const FileEntry * getASTFile() const
The serialized AST file for this module, if one was created.
Definition: Module.h:472
virtual bool layoutRecordType(const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &BaseOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &VirtualBaseOffsets)
Perform layout on the given record.
virtual void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl *> &Decls)
Get the decls that are contained in a file in the Offset/Length range.
virtual void PrintStats()
Print any statistics that have been gathered regarding the external AST source.
virtual void CompleteRedeclChain(const Decl *D)
Gives the external AST source an opportunity to complete the redeclaration chain for a declaration...
virtual Selector GetExternalSelector(uint32_t ID)
Resolve a selector ID into a selector.
virtual void StartedDeserializing()
Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeseriali...
Represents a struct/union/class.
Definition: Decl.h:3598
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
uint32_t incrementGeneration(ASTContext &C)
Increment the current generation.
virtual CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset)
Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers...
Describes a module or submodule.
Definition: Module.h:64
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name)
Find all declarations with the given name in the given context, and add them to the context by callin...
virtual void FinishedDeserializing()
Notify ExternalASTSource that we finished the deserialization of a decl or type.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Represents an ObjC class declaration.
Definition: DeclObjC.h:1171
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
unsigned Offset
Definition: Format.cpp:1709
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
The result type of a method or function.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap&#39;ed memor...
const DirectoryEntry * Directory
The build directory of this module.
Definition: Module.h:97
virtual Stmt * GetExternalDeclStmt(uint64_t Offset)
Resolve the offset of a statement in the decl stream into a statement.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3069
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1264
virtual void StartTranslationUnit(ASTConsumer *Consumer)
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
virtual void ReadComments()
Loads comment ranges.
The name of a declaration.
virtual CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset)
Resolve the offset of a set of C++ constructor initializers in the decl stream into an array of initi...
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1078
virtual ExtKind hasExternalDefinitions(const Decl *D)
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2334
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents a base class of a C++ class.
Definition: DeclCXX.h:191
virtual llvm::Optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID)
Return a descriptor for the corresponding module, if one exists.
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:91
StringRef getName() const
Definition: FileManager.h:51