summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/lib/Serialization
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Serialization')
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/ASTReader.cpp144
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp9
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/ASTReaderInternals.h10
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/ASTReaderStmt.cpp15
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/ASTWriter.cpp1
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/ASTWriterDecl.cpp3
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/ASTWriterStmt.cpp8
-rw-r--r--contrib/llvm/tools/clang/lib/Serialization/Module.cpp3
8 files changed, 113 insertions, 80 deletions
diff --git a/contrib/llvm/tools/clang/lib/Serialization/ASTReader.cpp b/contrib/llvm/tools/clang/lib/Serialization/ASTReader.cpp
index f91b66c..06b42f3 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/ASTReader.cpp
+++ b/contrib/llvm/tools/clang/lib/Serialization/ASTReader.cpp
@@ -27,7 +27,6 @@
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLocVisitor.h"
-#include "llvm/Support/SaveAndRestore.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Lex/Preprocessor.h"
@@ -46,6 +45,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/system_error.h"
#include <algorithm>
#include <iterator>
@@ -664,46 +664,6 @@ ASTDeclContextNameLookupTrait::GetInternalKey(
return Key;
}
-ASTDeclContextNameLookupTrait::external_key_type
-ASTDeclContextNameLookupTrait::GetExternalKey(
- const internal_key_type& Key) const {
- ASTContext &Context = Reader.getContext();
- switch (Key.Kind) {
- case DeclarationName::Identifier:
- return DeclarationName((IdentifierInfo*)Key.Data);
-
- case DeclarationName::ObjCZeroArgSelector:
- case DeclarationName::ObjCOneArgSelector:
- case DeclarationName::ObjCMultiArgSelector:
- return DeclarationName(Selector(Key.Data));
-
- case DeclarationName::CXXConstructorName:
- return Context.DeclarationNames.getCXXConstructorName(
- Context.getCanonicalType(Reader.getLocalType(F, Key.Data)));
-
- case DeclarationName::CXXDestructorName:
- return Context.DeclarationNames.getCXXDestructorName(
- Context.getCanonicalType(Reader.getLocalType(F, Key.Data)));
-
- case DeclarationName::CXXConversionFunctionName:
- return Context.DeclarationNames.getCXXConversionFunctionName(
- Context.getCanonicalType(Reader.getLocalType(F, Key.Data)));
-
- case DeclarationName::CXXOperatorName:
- return Context.DeclarationNames.getCXXOperatorName(
- (OverloadedOperatorKind)Key.Data);
-
- case DeclarationName::CXXLiteralOperatorName:
- return Context.DeclarationNames.getCXXLiteralOperatorName(
- (IdentifierInfo*)Key.Data);
-
- case DeclarationName::CXXUsingDirective:
- return DeclarationName::getUsingDirectiveName();
- }
-
- llvm_unreachable("Invalid Name Kind ?");
-}
-
std::pair<unsigned, unsigned>
ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) {
using namespace clang::io;
@@ -749,7 +709,7 @@ ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) {
ASTDeclContextNameLookupTrait::data_type
ASTDeclContextNameLookupTrait::ReadData(internal_key_type,
const unsigned char* d,
- unsigned DataLen) {
+ unsigned DataLen) {
using namespace clang::io;
unsigned NumDecls = ReadUnalignedLE16(d);
LE32DeclID *Start = (LE32DeclID *)d;
@@ -1911,7 +1871,8 @@ ASTReader::ReadASTBlock(ModuleFile &F) {
case UPDATE_VISIBLE: {
unsigned Idx = 0;
serialization::DeclID ID = ReadDeclID(F, Record, Idx);
- void *Table = ASTDeclContextNameLookupTable::Create(
+ ASTDeclContextNameLookupTable *Table =
+ ASTDeclContextNameLookupTable::Create(
(const unsigned char *)BlobStart + Record[Idx++],
(const unsigned char *)BlobStart,
ASTDeclContextNameLookupTrait(*this, F));
@@ -4908,7 +4869,7 @@ namespace {
// Look for this name within this module.
ASTDeclContextNameLookupTable *LookupTable =
- (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData;
+ Info->second.NameLookupTableData;
ASTDeclContextNameLookupTable::iterator Pos
= LookupTable->find(This->Name);
if (Pos == LookupTable->end())
@@ -4972,48 +4933,95 @@ ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC,
}
namespace {
- /// \brief ModuleFile visitor used to complete the visible decls map of a
+ /// \brief ModuleFile visitor used to retrieve all visible names in a
/// declaration context.
- class DeclContextVisibleDeclMapVisitor {
+ class DeclContextAllNamesVisitor {
ASTReader &Reader;
- DeclContext *DC;
+ llvm::SmallVectorImpl<const DeclContext *> &Contexts;
+ const DeclContext *DC;
+ llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > &Decls;
public:
- DeclContextVisibleDeclMapVisitor(ASTReader &Reader, DeclContext *DC)
- : Reader(Reader), DC(DC) { }
+ DeclContextAllNamesVisitor(ASTReader &Reader,
+ SmallVectorImpl<const DeclContext *> &Contexts,
+ llvm::DenseMap<DeclarationName,
+ SmallVector<NamedDecl *, 8> > &Decls)
+ : Reader(Reader), Contexts(Contexts), Decls(Decls) { }
static bool visit(ModuleFile &M, void *UserData) {
- return static_cast<DeclContextVisibleDeclMapVisitor*>(UserData)->visit(M);
- }
+ DeclContextAllNamesVisitor *This
+ = static_cast<DeclContextAllNamesVisitor *>(UserData);
- bool visit(ModuleFile &M) {
// Check whether we have any visible declaration information for
// this context in this module.
- ModuleFile::DeclContextInfosMap::iterator
- Info = M.DeclContextInfos.find(DC);
- if (Info == M.DeclContextInfos.end() ||
- !Info->second.NameLookupTableData)
+ ModuleFile::DeclContextInfosMap::iterator Info;
+ bool FoundInfo = false;
+ for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) {
+ Info = M.DeclContextInfos.find(This->Contexts[I]);
+ if (Info != M.DeclContextInfos.end() &&
+ Info->second.NameLookupTableData) {
+ FoundInfo = true;
+ break;
+ }
+ }
+
+ if (!FoundInfo)
return false;
-
- // Look for this name within this module.
+
ASTDeclContextNameLookupTable *LookupTable =
- (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData;
- for (ASTDeclContextNameLookupTable::key_iterator
- I = LookupTable->key_begin(),
- E = LookupTable->key_end(); I != E; ++I) {
- DC->lookup(*I); // Force loading of the visible decls for the decl name.
+ Info->second.NameLookupTableData;
+ bool FoundAnything = false;
+ for (ASTDeclContextNameLookupTable::data_iterator
+ I = LookupTable->data_begin(), E = LookupTable->data_end();
+ I != E; ++I) {
+ ASTDeclContextNameLookupTrait::data_type Data = *I;
+ for (; Data.first != Data.second; ++Data.first) {
+ NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M,
+ *Data.first);
+ if (!ND)
+ continue;
+
+ // Record this declaration.
+ FoundAnything = true;
+ This->Decls[ND->getDeclName()].push_back(ND);
+ }
}
- return false;
+ return FoundAnything;
}
};
}
-void ASTReader::completeVisibleDeclsMap(DeclContext *DC) {
+void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) {
if (!DC->hasExternalVisibleStorage())
return;
- DeclContextVisibleDeclMapVisitor Visitor(*this, DC);
- ModuleMgr.visit(&DeclContextVisibleDeclMapVisitor::visit, &Visitor);
+ llvm::DenseMap<DeclarationName, llvm::SmallVector<NamedDecl*, 8> > Decls;
+
+ // Compute the declaration contexts we need to look into. Multiple such
+ // declaration contexts occur when two declaration contexts from disjoint
+ // modules get merged, e.g., when two namespaces with the same name are
+ // independently defined in separate modules.
+ SmallVector<const DeclContext *, 2> Contexts;
+ Contexts.push_back(DC);
+
+ if (DC->isNamespace()) {
+ MergedDeclsMap::iterator Merged
+ = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC)));
+ if (Merged != MergedDecls.end()) {
+ for (unsigned I = 0, N = Merged->second.size(); I != N; ++I)
+ Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I])));
+ }
+ }
+
+ DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls);
+ ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor);
+ ++NumVisibleDeclContextsRead;
+
+ for (llvm::DenseMap<DeclarationName,
+ llvm::SmallVector<NamedDecl*, 8> >::iterator
+ I = Decls.begin(), E = Decls.end(); I != E; ++I) {
+ SetExternalVisibleDeclsForName(DC, I->first, I->second);
+ }
}
/// \brief Under non-PCH compilation the consumer receives the objc methods
@@ -6364,6 +6372,6 @@ ASTReader::~ASTReader() {
for (DeclContextVisibleUpdates::iterator J = I->second.begin(),
F = I->second.end();
J != F; ++J)
- delete static_cast<ASTDeclContextNameLookupTable*>(J->first);
+ delete J->first;
}
}
diff --git a/contrib/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp b/contrib/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp
index 5db5f92..8dd53ee 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/contrib/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "ASTCommon.h"
+#include "ASTReaderInternals.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Sema/IdentifierResolver.h"
#include "clang/Sema/Sema.h"
@@ -955,6 +956,10 @@ void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx));
BD->setParams(Params);
+ BD->setIsVariadic(Record[Idx++]);
+ BD->setBlockMissingReturnType(Record[Idx++]);
+ BD->setIsConversionFromLambda(Record[Idx++]);
+
bool capturesCXXThis = Record[Idx++];
unsigned numCaptures = Record[Idx++];
SmallVector<BlockDecl::Capture, 16> captures;
@@ -2100,7 +2105,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
DeclContextVisibleUpdates &U = I->second;
for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
UI != UE; ++UI) {
- UI->second->DeclContextInfos[DC].NameLookupTableData = UI->first;
+ DeclContextInfo &Info = UI->second->DeclContextInfos[DC];
+ delete Info.NameLookupTableData;
+ Info.NameLookupTableData = UI->first;
}
PendingVisibleUpdates.erase(I);
}
diff --git a/contrib/llvm/tools/clang/lib/Serialization/ASTReaderInternals.h b/contrib/llvm/tools/clang/lib/Serialization/ASTReaderInternals.h
index 3a1dfcf..e5159e9 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/ASTReaderInternals.h
+++ b/contrib/llvm/tools/clang/lib/Serialization/ASTReaderInternals.h
@@ -57,8 +57,7 @@ public:
typedef DeclarationName external_key_type;
typedef DeclNameKey internal_key_type;
- explicit ASTDeclContextNameLookupTrait(ASTReader &Reader,
- ModuleFile &F)
+ explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
: Reader(Reader), F(F) { }
static bool EqualKey(const internal_key_type& a,
@@ -68,9 +67,8 @@ public:
unsigned ComputeHash(const DeclNameKey &Key) const;
internal_key_type GetInternalKey(const external_key_type& Name) const;
- external_key_type GetExternalKey(const internal_key_type& Key) const;
- static std::pair<unsigned, unsigned>
+ static std::pair<unsigned, unsigned>
ReadKeyDataLength(const unsigned char*& d);
internal_key_type ReadKey(const unsigned char* d, unsigned);
@@ -79,10 +77,6 @@ public:
unsigned DataLen);
};
-/// \brief The on-disk hash table used for the DeclContext's Name lookup table.
-typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait>
- ASTDeclContextNameLookupTable;
-
/// \brief Class that performs lookup for an identifier stored in an AST file.
class ASTIdentifierLookupTrait {
ASTReader &Reader;
diff --git a/contrib/llvm/tools/clang/lib/Serialization/ASTReaderStmt.cpp b/contrib/llvm/tools/clang/lib/Serialization/ASTReaderStmt.cpp
index 2eeb090..007ecee 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/contrib/llvm/tools/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -159,9 +159,18 @@ void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
S->setIdentLoc(ReadSourceLocation(Record, Idx));
}
+void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) {
+ VisitStmt(S);
+ AttrVec Attrs;
+ Reader.ReadAttributes(F, Attrs, Record, Idx);
+ S->Attrs = Attrs;
+ S->SubStmt = Reader.ReadSubStmt();
+ S->AttrLoc = ReadSourceLocation(Record, Idx);
+}
+
void ASTStmtReader::VisitIfStmt(IfStmt *S) {
VisitStmt(S);
- S->setConditionVariable(Reader.getContext(),
+ S->setConditionVariable(Reader.getContext(),
ReadDeclAs<VarDecl>(Record, Idx));
S->setCond(Reader.ReadSubExpr());
S->setThen(Reader.ReadSubStmt());
@@ -1630,6 +1639,10 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
S = new (Context) LabelStmt(Empty);
break;
+ case STMT_ATTRIBUTED:
+ S = new (Context) AttributedStmt(Empty);
+ break;
+
case STMT_IF:
S = new (Context) IfStmt(Empty);
break;
diff --git a/contrib/llvm/tools/clang/lib/Serialization/ASTWriter.cpp b/contrib/llvm/tools/clang/lib/Serialization/ASTWriter.cpp
index a4301b5..81c0a9d 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/ASTWriter.cpp
+++ b/contrib/llvm/tools/clang/lib/Serialization/ASTWriter.cpp
@@ -651,6 +651,7 @@ static void AddStmtsExprs(llvm::BitstreamWriter &Stream,
RECORD(STMT_CASE);
RECORD(STMT_DEFAULT);
RECORD(STMT_LABEL);
+ RECORD(STMT_ATTRIBUTED);
RECORD(STMT_IF);
RECORD(STMT_SWITCH);
RECORD(STMT_WHILE);
diff --git a/contrib/llvm/tools/clang/lib/Serialization/ASTWriterDecl.cpp b/contrib/llvm/tools/clang/lib/Serialization/ASTWriterDecl.cpp
index 7a4ef63..1ee3ac4 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/contrib/llvm/tools/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -775,6 +775,9 @@ void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
P != PEnd; ++P)
Writer.AddDeclRef(*P, Record);
+ Record.push_back(D->isVariadic());
+ Record.push_back(D->blockMissingReturnType());
+ Record.push_back(D->isConversionFromLambda());
Record.push_back(D->capturesCXXThis());
Record.push_back(D->getNumCaptures());
for (BlockDecl::capture_iterator
diff --git a/contrib/llvm/tools/clang/lib/Serialization/ASTWriterStmt.cpp b/contrib/llvm/tools/clang/lib/Serialization/ASTWriterStmt.cpp
index 827caa0..1e31211 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/contrib/llvm/tools/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -106,6 +106,14 @@ void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) {
Code = serialization::STMT_LABEL;
}
+void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) {
+ VisitStmt(S);
+ Writer.WriteAttributes(S->getAttrs(), Record);
+ Writer.AddStmt(S->getSubStmt());
+ Writer.AddSourceLocation(S->getAttrLoc(), Record);
+ Code = serialization::STMT_ATTRIBUTED;
+}
+
void ASTStmtWriter::VisitIfStmt(IfStmt *S) {
VisitStmt(S);
Writer.AddDeclRef(S->getConditionVariable(), Record);
diff --git a/contrib/llvm/tools/clang/lib/Serialization/Module.cpp b/contrib/llvm/tools/clang/lib/Serialization/Module.cpp
index 16b95e2..ff241d3 100644
--- a/contrib/llvm/tools/clang/lib/Serialization/Module.cpp
+++ b/contrib/llvm/tools/clang/lib/Serialization/Module.cpp
@@ -45,8 +45,7 @@ ModuleFile::~ModuleFile() {
E = DeclContextInfos.end();
I != E; ++I) {
if (I->second.NameLookupTableData)
- delete static_cast<ASTDeclContextNameLookupTable*>(
- I->second.NameLookupTableData);
+ delete I->second.NameLookupTableData;
}
delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
OpenPOWER on IntegriCloud