8e78058564
git-svn-id: http://root.cern.ch/svn/root/trunk@46692 27541ba8-7e3a-0410-8455-c3a389f83636
828 lines
33 KiB
Diff
828 lines
33 KiB
Diff
Index: tools/clang/include/clang/Sema/Sema.h
|
|
===================================================================
|
|
--- tools/clang/include/clang/Sema/Sema.h (revision 165095)
|
|
+++ tools/clang/include/clang/Sema/Sema.h (working copy)
|
|
@@ -190,6 +190,13 @@
|
|
Sema(const Sema &) LLVM_DELETED_FUNCTION;
|
|
void operator=(const Sema &) LLVM_DELETED_FUNCTION;
|
|
mutable const TargetAttributesSema* TheTargetAttributesSema;
|
|
+
|
|
+ ///\brief Source of additional semantic information.
|
|
+ ExternalSemaSource *ExternalSource;
|
|
+
|
|
+ ///\brief Whether Sema has generated a multiplexer and has to delete it.
|
|
+ bool isMultiplexExternalSource;
|
|
+
|
|
public:
|
|
typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
|
|
typedef OpaquePtr<TemplateName> TemplateTy;
|
|
@@ -208,9 +215,6 @@
|
|
/// \brief Flag indicating whether or not to collect detailed statistics.
|
|
bool CollectStats;
|
|
|
|
- /// \brief Source of additional semantic information.
|
|
- ExternalSemaSource *ExternalSource;
|
|
-
|
|
/// \brief Code-completion consumer.
|
|
CodeCompleteConsumer *CodeCompleter;
|
|
|
|
@@ -770,7 +774,15 @@
|
|
ASTContext &getASTContext() const { return Context; }
|
|
ASTConsumer &getASTConsumer() const { return Consumer; }
|
|
ASTMutationListener *getASTMutationListener() const;
|
|
+ ExternalSemaSource* getExternalSource() const { return ExternalSource; }
|
|
|
|
+ ///\brief Registers an external source. If an external source already exists,
|
|
+ /// creates a multiplex external source and appends to it.
|
|
+ ///
|
|
+ ///\param[in] E - A non-null external sema source.
|
|
+ ///
|
|
+ void addExternalSource(ExternalSemaSource *E);
|
|
+
|
|
void PrintStats() const;
|
|
|
|
/// \brief Helper class that creates diagnostics with optional
|
|
Index: tools/clang/include/clang/Sema/MultiplexExternalSemaSource.h
|
|
===================================================================
|
|
--- tools/clang/include/clang/Sema/MultiplexExternalSemaSource.h (revision 0)
|
|
+++ tools/clang/include/clang/Sema/MultiplexExternalSemaSource.h (revision 0)
|
|
@@ -0,0 +1,367 @@
|
|
+//===--- MultiplexExternalSemaSource.h - External Sema Interface-*- C++ -*-===//
|
|
+//
|
|
+// The LLVM Compiler Infrastructure
|
|
+//
|
|
+// This file is distributed under the University of Illinois Open Source
|
|
+// License. See LICENSE.TXT for details.
|
|
+//
|
|
+//===----------------------------------------------------------------------===//
|
|
+//
|
|
+// This file defines ExternalSemaSource interface, dispatching to all clients
|
|
+//
|
|
+//===----------------------------------------------------------------------===//
|
|
+#ifndef LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H
|
|
+#define LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H
|
|
+
|
|
+#include "clang/Sema/ExternalSemaSource.h"
|
|
+#include "clang/Sema/Weak.h"
|
|
+
|
|
+#include "llvm/ADT/SmallVector.h"
|
|
+
|
|
+#include <utility>
|
|
+
|
|
+namespace clang {
|
|
+
|
|
+ class CXXConstructorDecl;
|
|
+ class CXXRecordDecl;
|
|
+ class DeclaratorDecl;
|
|
+ struct ExternalVTableUse;
|
|
+ class LookupResult;
|
|
+ class NamespaceDecl;
|
|
+ class Scope;
|
|
+ class Sema;
|
|
+ class TypedefNameDecl;
|
|
+ class ValueDecl;
|
|
+ class VarDecl;
|
|
+
|
|
+
|
|
+/// \brief An abstract interface that should be implemented by
|
|
+/// external AST sources that also provide information for semantic
|
|
+/// analysis.
|
|
+class MultiplexExternalSemaSource : public ExternalSemaSource {
|
|
+
|
|
+private:
|
|
+ llvm::SmallVector<ExternalSemaSource*, 2> Sources; // doesn't own them.
|
|
+
|
|
+public:
|
|
+
|
|
+ ///\brief Constructs a new multiplexing external sema source and appends the
|
|
+ /// given element to it.
|
|
+ ///
|
|
+ ///\param[in] s1 - A non-null (old) ExternalSemaSource.
|
|
+ ///\param[in] s2 - A non-null (new) ExternalSemaSource.
|
|
+ ///
|
|
+ MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2);
|
|
+
|
|
+ ~MultiplexExternalSemaSource();
|
|
+
|
|
+ ///\brief Appends new source to the source list.
|
|
+ ///
|
|
+ ///\param[in] source - An ExternalSemaSource.
|
|
+ ///
|
|
+ void addSource(ExternalSemaSource &source);
|
|
+
|
|
+ //===--------------------------------------------------------------------===//
|
|
+ // ExternalASTSource.
|
|
+ //===--------------------------------------------------------------------===//
|
|
+
|
|
+ /// \brief Resolve a declaration ID into a declaration, potentially
|
|
+ /// building a new declaration.
|
|
+ ///
|
|
+ /// This method only needs to be implemented if the AST source ever
|
|
+ /// passes back decl sets as VisibleDeclaration objects.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual Decl *GetExternalDecl(uint32_t ID);
|
|
+
|
|
+ /// \brief Resolve a selector ID into a selector.
|
|
+ ///
|
|
+ /// This operation only needs to be implemented if the AST source
|
|
+ /// returns non-zero for GetNumKnownSelectors().
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual Selector GetExternalSelector(uint32_t ID);
|
|
+
|
|
+ /// \brief Returns the number of selectors known to the external AST
|
|
+ /// source.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual uint32_t GetNumExternalSelectors();
|
|
+
|
|
+ /// \brief Resolve the offset of a statement in the decl stream into
|
|
+ /// a statement.
|
|
+ ///
|
|
+ /// This operation is meant to be used via a LazyOffsetPtr. It only
|
|
+ /// needs to be implemented if the AST source uses methods like
|
|
+ /// FunctionDecl::setLazyBody when building decls.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
|
|
+
|
|
+ /// \brief Resolve the offset of a set of C++ base specifiers in the decl
|
|
+ /// stream into an array of specifiers.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
|
|
+
|
|
+ /// \brief Finds all declarations with the given name in the
|
|
+ /// given context.
|
|
+ ///
|
|
+ /// Generally the final step of this method is either to call
|
|
+ /// SetExternalVisibleDeclsForName or to recursively call lookup on
|
|
+ /// the DeclContext after calling SetExternalVisibleDecls.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual DeclContextLookupResult
|
|
+ FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
|
|
+
|
|
+ /// \brief Ensures that the table of all visible declarations inside this
|
|
+ /// context is up to date.
|
|
+ ///
|
|
+ /// The default implementation of this functino is a no-op.
|
|
+ virtual void completeVisibleDeclsMap(const DeclContext *DC);
|
|
+
|
|
+ /// \brief Finds all declarations lexically contained within the given
|
|
+ /// DeclContext, after applying an optional filter predicate.
|
|
+ ///
|
|
+ /// \param isKindWeWant a predicate function that returns true if the passed
|
|
+ /// declaration kind is one we are looking for. If NULL, all declarations
|
|
+ /// are returned.
|
|
+ ///
|
|
+ /// \return an indication of whether the load succeeded or failed.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
|
|
+ bool (*isKindWeWant)(Decl::Kind),
|
|
+ SmallVectorImpl<Decl*> &Result);
|
|
+
|
|
+ /// \brief Finds all declarations lexically contained within the given
|
|
+ /// DeclContext.
|
|
+ ///
|
|
+ /// \return true if an error occurred
|
|
+ ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
|
|
+ SmallVectorImpl<Decl*> &Result) {
|
|
+ return FindExternalLexicalDecls(DC, 0, Result);
|
|
+ }
|
|
+
|
|
+ template <typename DeclTy>
|
|
+ ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC,
|
|
+ SmallVectorImpl<Decl*> &Result) {
|
|
+ return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
|
|
+ }
|
|
+
|
|
+ /// \brief Get the decls that are contained in a file in the Offset/Length
|
|
+ /// range. \p Length can be 0 to indicate a point at \p Offset instead of
|
|
+ /// a range.
|
|
+ virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
|
|
+ SmallVectorImpl<Decl *> &Decls);
|
|
+
|
|
+ /// \brief Gives the external AST source an opportunity to complete
|
|
+ /// an incomplete type.
|
|
+ virtual void CompleteType(TagDecl *Tag);
|
|
+
|
|
+ /// \brief Gives the external AST source an opportunity to complete an
|
|
+ /// incomplete Objective-C class.
|
|
+ ///
|
|
+ /// This routine will only be invoked if the "externally completed" bit is
|
|
+ /// set on the ObjCInterfaceDecl via the function
|
|
+ /// \c ObjCInterfaceDecl::setExternallyCompleted().
|
|
+ virtual void CompleteType(ObjCInterfaceDecl *Class);
|
|
+
|
|
+ /// \brief Loads comment ranges.
|
|
+ virtual void ReadComments();
|
|
+
|
|
+ /// \brief Notify ExternalASTSource that we started deserialization of
|
|
+ /// a decl or type so until FinishedDeserializing is called there may be
|
|
+ /// decls that are initializing. Must be paired with FinishedDeserializing.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual void StartedDeserializing();
|
|
+
|
|
+ /// \brief Notify ExternalASTSource that we finished the deserialization of
|
|
+ /// a decl or type. Must be paired with StartedDeserializing.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual void FinishedDeserializing();
|
|
+
|
|
+ /// \brief Function that will be invoked when we begin parsing a new
|
|
+ /// translation unit involving this external AST source.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual void StartTranslationUnit(ASTConsumer *Consumer);
|
|
+
|
|
+ /// \brief Print any statistics that have been gathered regarding
|
|
+ /// the external AST source.
|
|
+ ///
|
|
+ /// The default implementation of this method is a no-op.
|
|
+ virtual void PrintStats();
|
|
+
|
|
+
|
|
+ /// \brief Perform layout on the given record.
|
|
+ ///
|
|
+ /// This routine allows the external AST source to provide an specific
|
|
+ /// layout for a record, overriding the layout that would normally be
|
|
+ /// constructed. It is intended for clients who receive specific layout
|
|
+ /// details rather than source code (such as LLDB). The client is expected
|
|
+ /// to fill in the field offsets, base offsets, virtual base offsets, and
|
|
+ /// complete object size.
|
|
+ ///
|
|
+ /// \param Record The record whose layout is being requested.
|
|
+ ///
|
|
+ /// \param Size The final size of the record, in bits.
|
|
+ ///
|
|
+ /// \param Alignment The final alignment of the record, in bits.
|
|
+ ///
|
|
+ /// \param FieldOffsets The offset of each of the fields within the record,
|
|
+ /// expressed in bits. All of the fields must be provided with offsets.
|
|
+ ///
|
|
+ /// \param BaseOffsets The offset of each of the direct, non-virtual base
|
|
+ /// classes. If any bases are not given offsets, the bases will be laid
|
|
+ /// out according to the ABI.
|
|
+ ///
|
|
+ /// \param VirtualBaseOffsets The offset of each of the virtual base classes
|
|
+ /// (either direct or not). If any bases are not given offsets, the bases will
|
|
+ /// be laid out according to the ABI.
|
|
+ ///
|
|
+ /// \returns true if the record layout was provided, false otherwise.
|
|
+ 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);
|
|
+
|
|
+ /// Return the amount of memory used by memory buffers, breaking down
|
|
+ /// by heap-backed versus mmap'ed memory.
|
|
+ virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
|
|
+
|
|
+ //===--------------------------------------------------------------------===//
|
|
+ // ExternalSemaSource.
|
|
+ //===--------------------------------------------------------------------===//
|
|
+
|
|
+ /// \brief Initialize the semantic source with the Sema instance
|
|
+ /// being used to perform semantic analysis on the abstract syntax
|
|
+ /// tree.
|
|
+ virtual void InitializeSema(Sema &S);
|
|
+
|
|
+ /// \brief Inform the semantic consumer that Sema is no longer available.
|
|
+ virtual void ForgetSema();
|
|
+
|
|
+ /// \brief Load the contents of the global method pool for a given
|
|
+ /// selector.
|
|
+ virtual void ReadMethodPool(Selector Sel);
|
|
+
|
|
+ /// \brief Load the set of namespaces that are known to the external source,
|
|
+ /// which will be used during typo correction.
|
|
+ virtual void ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces);
|
|
+
|
|
+ /// \brief Do last resort, unqualified lookup on a LookupResult that
|
|
+ /// Sema cannot find.
|
|
+ ///
|
|
+ /// \param R a LookupResult that is being recovered.
|
|
+ ///
|
|
+ /// \param S the Scope of the identifier occurrence.
|
|
+ ///
|
|
+ /// \return true to tell Sema to recover using the LookupResult.
|
|
+ virtual bool LookupUnqualified(LookupResult &R, Scope *S);
|
|
+
|
|
+ /// \brief Read the set of tentative definitions known to the external Sema
|
|
+ /// source.
|
|
+ ///
|
|
+ /// The external source should append its own tentative definitions to the
|
|
+ /// given vector of tentative definitions. Note that this routine may be
|
|
+ /// invoked multiple times; the external source should take care not to
|
|
+ /// introduce the same declarations repeatedly.
|
|
+ virtual void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs);
|
|
+
|
|
+ /// \brief Read the set of unused file-scope declarations known to the
|
|
+ /// external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own unused, filed-scope to the
|
|
+ /// given vector of declarations. Note that this routine may be
|
|
+ /// invoked multiple times; the external source should take care not to
|
|
+ /// introduce the same declarations repeatedly.
|
|
+ virtual void ReadUnusedFileScopedDecls(
|
|
+ SmallVectorImpl<const DeclaratorDecl*> &Decls);
|
|
+
|
|
+ /// \brief Read the set of delegating constructors known to the
|
|
+ /// external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own delegating constructors to the
|
|
+ /// given vector of declarations. Note that this routine may be
|
|
+ /// invoked multiple times; the external source should take care not to
|
|
+ /// introduce the same declarations repeatedly.
|
|
+ virtual void ReadDelegatingConstructors(
|
|
+ SmallVectorImpl<CXXConstructorDecl*> &Decls);
|
|
+
|
|
+ /// \brief Read the set of ext_vector type declarations known to the
|
|
+ /// external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own ext_vector type declarations to
|
|
+ /// the given vector of declarations. Note that this routine may be
|
|
+ /// invoked multiple times; the external source should take care not to
|
|
+ /// introduce the same declarations repeatedly.
|
|
+ virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls);
|
|
+
|
|
+ /// \brief Read the set of dynamic classes known to the external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own dynamic classes to
|
|
+ /// the given vector of declarations. Note that this routine may be
|
|
+ /// invoked multiple times; the external source should take care not to
|
|
+ /// introduce the same declarations repeatedly.
|
|
+ virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl*> &Decls);
|
|
+
|
|
+ /// \brief Read the set of locally-scoped external declarations known to the
|
|
+ /// external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own locally-scoped external
|
|
+ /// declarations to the given vector of declarations. Note that this routine
|
|
+ /// may be invoked multiple times; the external source should take care not
|
|
+ /// to introduce the same declarations repeatedly.
|
|
+ virtual void ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl*>&Decls);
|
|
+
|
|
+ /// \brief Read the set of referenced selectors known to the
|
|
+ /// external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own referenced selectors to the
|
|
+ /// given vector of selectors. Note that this routine
|
|
+ /// may be invoked multiple times; the external source should take care not
|
|
+ /// to introduce the same selectors repeatedly.
|
|
+ virtual void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
|
|
+ SourceLocation> > &Sels);
|
|
+
|
|
+ /// \brief Read the set of weak, undeclared identifiers known to the
|
|
+ /// external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own weak, undeclared identifiers to
|
|
+ /// the given vector. Note that this routine may be invoked multiple times;
|
|
+ /// the external source should take care not to introduce the same identifiers
|
|
+ /// repeatedly.
|
|
+ virtual void ReadWeakUndeclaredIdentifiers(
|
|
+ SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI);
|
|
+
|
|
+ /// \brief Read the set of used vtables known to the external Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own used vtables to the given
|
|
+ /// vector. Note that this routine may be invoked multiple times; the external
|
|
+ /// source should take care not to introduce the same vtables repeatedly.
|
|
+ virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
|
|
+
|
|
+ /// \brief Read the set of pending instantiations known to the external
|
|
+ /// Sema source.
|
|
+ ///
|
|
+ /// The external source should append its own pending instantiations to the
|
|
+ /// given vector. Note that this routine may be invoked multiple times; the
|
|
+ /// external source should take care not to introduce the same instantiations
|
|
+ /// repeatedly.
|
|
+ virtual void ReadPendingInstantiations(
|
|
+ SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending);
|
|
+
|
|
+ // isa/cast/dyn_cast support
|
|
+ static bool classof(const MultiplexExternalSemaSource*) { return true; }
|
|
+ //static bool classof(const ExternalSemaSource*) { return true; }
|
|
+};
|
|
+
|
|
+} // end namespace clang
|
|
+
|
|
+#endif // LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H
|
|
Index: tools/clang/lib/Sema/SemaCodeComplete.cpp
|
|
===================================================================
|
|
--- tools/clang/lib/Sema/SemaCodeComplete.cpp (revision 165095)
|
|
+++ tools/clang/lib/Sema/SemaCodeComplete.cpp (working copy)
|
|
@@ -5339,11 +5339,11 @@
|
|
|
|
// If we have an external source, load the entire class method
|
|
// pool from the AST file.
|
|
- if (SemaRef.ExternalSource) {
|
|
+ if (SemaRef.getExternalSource()) {
|
|
for (uint32_t I = 0,
|
|
- N = SemaRef.ExternalSource->GetNumExternalSelectors();
|
|
+ N = SemaRef.getExternalSource()->GetNumExternalSelectors();
|
|
I != N; ++I) {
|
|
- Selector Sel = SemaRef.ExternalSource->GetExternalSelector(I);
|
|
+ Selector Sel = SemaRef.getExternalSource()->GetExternalSelector(I);
|
|
if (Sel.isNull() || SemaRef.MethodPool.count(Sel))
|
|
continue;
|
|
|
|
Index: tools/clang/lib/Sema/SemaDeclObjC.cpp
|
|
===================================================================
|
|
--- tools/clang/lib/Sema/SemaDeclObjC.cpp (revision 165095)
|
|
+++ tools/clang/lib/Sema/SemaDeclObjC.cpp (working copy)
|
|
@@ -2582,7 +2582,7 @@
|
|
// with this selector before.
|
|
Sema::GlobalMethodPool::iterator it = S.MethodPool.find(selector);
|
|
if (it == S.MethodPool.end()) {
|
|
- if (!S.ExternalSource) return;
|
|
+ if (!S.getExternalSource()) return;
|
|
S.ReadMethodPool(selector);
|
|
|
|
it = S.MethodPool.find(selector);
|
|
Index: tools/clang/lib/Sema/MultiplexExternalSemaSource.cpp
|
|
===================================================================
|
|
--- tools/clang/lib/Sema/MultiplexExternalSemaSource.cpp (revision 0)
|
|
+++ tools/clang/lib/Sema/MultiplexExternalSemaSource.cpp (revision 0)
|
|
@@ -0,0 +1,271 @@
|
|
+//===--- MultiplexExternalSemaSource.cpp ---------------------------------===//
|
|
+//
|
|
+// The LLVM Compiler Infrastructure
|
|
+//
|
|
+// This file is distributed under the University of Illinois Open Source
|
|
+// License. See LICENSE.TXT for details.
|
|
+//
|
|
+//===----------------------------------------------------------------------===//
|
|
+//
|
|
+// This file implements the event dispatching to the subscribed clients.
|
|
+//
|
|
+//===----------------------------------------------------------------------===//
|
|
+#include "clang/Sema/MultiplexExternalSemaSource.h"
|
|
+
|
|
+#include "clang/AST/DeclContextInternals.h"
|
|
+#include "clang/Sema/Lookup.h"
|
|
+
|
|
+using namespace clang;
|
|
+
|
|
+///\brief Constructs a new multiplexing external sema source and appends the
|
|
+/// given element to it.
|
|
+///
|
|
+///\param[in] source - An ExternalSemaSource.
|
|
+///
|
|
+MultiplexExternalSemaSource::MultiplexExternalSemaSource(ExternalSemaSource &s1,
|
|
+ ExternalSemaSource &s2){
|
|
+ Sources.push_back(&s1);
|
|
+ Sources.push_back(&s2);
|
|
+}
|
|
+
|
|
+// pin the vtable here.
|
|
+MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {}
|
|
+
|
|
+///\brief Appends new source to the source list.
|
|
+///
|
|
+///\param[in] source - An ExternalSemaSource.
|
|
+///
|
|
+void MultiplexExternalSemaSource::addSource(ExternalSemaSource &source) {
|
|
+ Sources.push_back(&source);
|
|
+}
|
|
+
|
|
+//===----------------------------------------------------------------------===//
|
|
+// ExternalASTSource.
|
|
+//===----------------------------------------------------------------------===//
|
|
+
|
|
+Decl *MultiplexExternalSemaSource::GetExternalDecl(uint32_t ID) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ if (Decl *Result = Sources[i]->GetExternalDecl(ID))
|
|
+ return Result;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) {
|
|
+ Selector Sel;
|
|
+ for(size_t i = 0; i < Sources.size(); ++i) {
|
|
+ Sel = Sources[i]->GetExternalSelector(ID);
|
|
+ if (!Sel.isNull())
|
|
+ return Sel;
|
|
+ }
|
|
+ return Sel;
|
|
+}
|
|
+
|
|
+uint32_t MultiplexExternalSemaSource::GetNumExternalSelectors() {
|
|
+ uint32_t total = 0;
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ total += Sources[i]->GetNumExternalSelectors();
|
|
+ return total;
|
|
+}
|
|
+
|
|
+Stmt *MultiplexExternalSemaSource::GetExternalDeclStmt(uint64_t Offset) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset))
|
|
+ return Result;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+CXXBaseSpecifier *MultiplexExternalSemaSource::GetExternalCXXBaseSpecifiers(
|
|
+ uint64_t Offset){
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset))
|
|
+ return R;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+DeclContextLookupResult MultiplexExternalSemaSource::
|
|
+FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
|
|
+ StoredDeclsList DeclsFound;
|
|
+ DeclContextLookupResult lookup;
|
|
+ for(size_t i = 0; i < Sources.size(); ++i) {
|
|
+ lookup = Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
|
|
+ while(lookup.first != lookup.second) {
|
|
+ if (!DeclsFound.HandleRedeclaration(*lookup.first))
|
|
+ DeclsFound.AddSubsequentDecl(*lookup.first);
|
|
+ lookup.first++;
|
|
+ }
|
|
+ }
|
|
+ return DeclsFound.getLookupResult();
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->completeVisibleDeclsMap(DC);
|
|
+}
|
|
+
|
|
+ExternalLoadResult MultiplexExternalSemaSource::
|
|
+FindExternalLexicalDecls(const DeclContext *DC,
|
|
+ bool (*isKindWeWant)(Decl::Kind),
|
|
+ SmallVectorImpl<Decl*> &Result) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ // FIXME: The semantics of the return result is unclear to me...
|
|
+ Sources[i]->FindExternalLexicalDecls(DC, isKindWeWant, Result);
|
|
+
|
|
+ return ELR_Success;
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File,
|
|
+ unsigned Offset,
|
|
+ unsigned Length,
|
|
+ SmallVectorImpl<Decl *> &Decls){
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->CompleteType(Tag);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->CompleteType(Class);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadComments() {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadComments();
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::StartedDeserializing() {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->StartedDeserializing();
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::FinishedDeserializing() {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->FinishedDeserializing();
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->StartTranslationUnit(Consumer);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::PrintStats() {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->PrintStats();
|
|
+}
|
|
+
|
|
+bool MultiplexExternalSemaSource::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){
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets,
|
|
+ BaseOffsets, VirtualBaseOffsets))
|
|
+ return true;
|
|
+ return false;
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::
|
|
+getMemoryBufferSizes(MemoryBufferSizes &sizes) const {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->getMemoryBufferSizes(sizes);
|
|
+
|
|
+}
|
|
+
|
|
+//===----------------------------------------------------------------------===//
|
|
+// ExternalSemaSource.
|
|
+//===----------------------------------------------------------------------===//
|
|
+
|
|
+
|
|
+void MultiplexExternalSemaSource::InitializeSema(Sema &S) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->InitializeSema(S);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ForgetSema() {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ForgetSema();
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadMethodPool(Sel);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadKnownNamespaces(
|
|
+ SmallVectorImpl<NamespaceDecl*> &Namespaces){
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadKnownNamespaces(Namespaces);
|
|
+}
|
|
+
|
|
+bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->LookupUnqualified(R, S);
|
|
+
|
|
+ return !R.empty();
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadTentativeDefinitions(
|
|
+ SmallVectorImpl<VarDecl*> &TentativeDefs) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadTentativeDefinitions(TentativeDefs);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls(
|
|
+ SmallVectorImpl<const DeclaratorDecl*> &Decls) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadUnusedFileScopedDecls(Decls);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadDelegatingConstructors(
|
|
+ SmallVectorImpl<CXXConstructorDecl*> &Decls) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadDelegatingConstructors(Decls);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadExtVectorDecls(
|
|
+ SmallVectorImpl<TypedefNameDecl*> &Decls) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadExtVectorDecls(Decls);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadDynamicClasses(
|
|
+ SmallVectorImpl<CXXRecordDecl*> &Decls) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadDynamicClasses(Decls);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadLocallyScopedExternalDecls(
|
|
+ SmallVectorImpl<NamedDecl*> &Decls) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadLocallyScopedExternalDecls(Decls);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadReferencedSelectors(
|
|
+ SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadReferencedSelectors(Sels);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers(
|
|
+ SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadWeakUndeclaredIdentifiers(WI);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadUsedVTables(
|
|
+ SmallVectorImpl<ExternalVTableUse> &VTables) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadUsedVTables(VTables);
|
|
+}
|
|
+
|
|
+void MultiplexExternalSemaSource::ReadPendingInstantiations(
|
|
+ SmallVectorImpl<std::pair<ValueDecl*,
|
|
+ SourceLocation> > &Pending) {
|
|
+ for(size_t i = 0; i < Sources.size(); ++i)
|
|
+ Sources[i]->ReadPendingInstantiations(Pending);
|
|
+}
|
|
Index: tools/clang/lib/Sema/CMakeLists.txt
|
|
===================================================================
|
|
--- tools/clang/lib/Sema/CMakeLists.txt (revision 165095)
|
|
+++ tools/clang/lib/Sema/CMakeLists.txt (working copy)
|
|
@@ -13,6 +13,7 @@
|
|
DelayedDiagnostic.cpp
|
|
IdentifierResolver.cpp
|
|
JumpDiagnostics.cpp
|
|
+ MultiplexExternalSemaSource.cpp
|
|
Scope.cpp
|
|
ScopeInfo.cpp
|
|
Sema.cpp
|
|
Index: tools/clang/lib/Sema/SemaExprMember.cpp
|
|
===================================================================
|
|
--- tools/clang/lib/Sema/SemaExprMember.cpp (revision 165095)
|
|
+++ tools/clang/lib/Sema/SemaExprMember.cpp (working copy)
|
|
@@ -354,7 +354,7 @@
|
|
// Now look up the TypeDefDecl from the vector type. Without this,
|
|
// diagostics look bad. We want extended vector types to appear built-in.
|
|
for (Sema::ExtVectorDeclsType::iterator
|
|
- I = S.ExtVectorDecls.begin(S.ExternalSource),
|
|
+ I = S.ExtVectorDecls.begin(S.getExternalSource()),
|
|
E = S.ExtVectorDecls.end();
|
|
I != E; ++I) {
|
|
if ((*I)->getUnderlyingType() == VT)
|
|
Index: tools/clang/lib/Sema/Sema.cpp
|
|
===================================================================
|
|
--- tools/clang/lib/Sema/Sema.cpp (revision 165095)
|
|
+++ tools/clang/lib/Sema/Sema.cpp (working copy)
|
|
@@ -22,6 +22,7 @@
|
|
#include "clang/Sema/CXXFieldCollector.h"
|
|
#include "clang/Sema/TemplateDeduction.h"
|
|
#include "clang/Sema/ExternalSemaSource.h"
|
|
+#include "clang/Sema/MultiplexExternalSemaSource.h"
|
|
#include "clang/Sema/ObjCMethodList.h"
|
|
#include "clang/Sema/PrettyDeclStackTrace.h"
|
|
#include "clang/Sema/Scope.h"
|
|
@@ -68,10 +69,11 @@
|
|
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
|
|
TranslationUnitKind TUKind,
|
|
CodeCompleteConsumer *CodeCompleter)
|
|
- : TheTargetAttributesSema(0), FPFeatures(pp.getLangOpts()),
|
|
+ : TheTargetAttributesSema(0), ExternalSource(0),
|
|
+ isMultiplexExternalSource(false), FPFeatures(pp.getLangOpts()),
|
|
LangOpts(pp.getLangOpts()), PP(pp), Context(ctxt), Consumer(consumer),
|
|
Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()),
|
|
- CollectStats(false), ExternalSource(0), CodeCompleter(CodeCompleter),
|
|
+ CollectStats(false), CodeCompleter(CodeCompleter),
|
|
CurContext(0), OriginalLexicalContext(0),
|
|
PackContext(0), MSStructPragmaOn(false), VisContext(0),
|
|
IsBuildingRecoveryCallExpr(false),
|
|
@@ -188,6 +190,10 @@
|
|
if (ExternalSemaSource *ExternalSema
|
|
= dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
|
|
ExternalSema->ForgetSema();
|
|
+
|
|
+ // If Sema's ExternalSource is the multiplexer - we own it.
|
|
+ if (isMultiplexExternalSource)
|
|
+ delete ExternalSource;
|
|
}
|
|
|
|
/// makeUnavailableInSystemHeader - There is an error in the current
|
|
@@ -219,6 +225,27 @@
|
|
return getASTConsumer().GetASTMutationListener();
|
|
}
|
|
|
|
+///\brief Registers an external source. If an external source already exists,
|
|
+/// creates a multiplex external source and appends to it.
|
|
+///
|
|
+///\param[in] E - A non-null external sema source.
|
|
+///
|
|
+void Sema::addExternalSource(ExternalSemaSource *E) {
|
|
+ assert(E && "Cannot use with NULL ptr");
|
|
+
|
|
+ if (!ExternalSource) {
|
|
+ ExternalSource = E;
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (isMultiplexExternalSource)
|
|
+ static_cast<MultiplexExternalSemaSource*>(ExternalSource)->addSource(*E);
|
|
+ else {
|
|
+ ExternalSource = new MultiplexExternalSemaSource(*ExternalSource, *E);
|
|
+ isMultiplexExternalSource = true;
|
|
+ }
|
|
+}
|
|
+
|
|
/// \brief Print out statistics about the semantic analysis.
|
|
void Sema::PrintStats() const {
|
|
llvm::errs() << "\n*** Semantic Analysis Stats:\n";
|
|
Index: tools/clang/lib/Serialization/ASTReader.cpp
|
|
===================================================================
|
|
--- tools/clang/lib/Serialization/ASTReader.cpp (revision 165095)
|
|
+++ tools/clang/lib/Serialization/ASTReader.cpp (working copy)
|
|
@@ -5289,7 +5289,7 @@
|
|
|
|
void ASTReader::InitializeSema(Sema &S) {
|
|
SemaObj = &S;
|
|
- S.ExternalSource = this;
|
|
+ S.addExternalSource(this);
|
|
|
|
// Makes sure any declarations that were deserialized "too early"
|
|
// still get added to the identifier's declaration chains.
|