if (Decl::CollectingStats()) add(DK);
}
+ Decl(Kind DK, EmptyShell Empty)
+ : NextDeclInContext(0), DeclKind(DK), InvalidDecl(0),
+ HasAttrs(false), Implicit(false), Used(false),
+ Access(AS_none), PCHLevel(0),
+ IdentifierNamespace(getIdentifierNamespaceForKind(DK)) {
+ if (Decl::CollectingStats()) add(DK);
+ }
+
virtual ~Decl();
public:
static bool classof(const ClassTemplateSpecializationDecl *D) {
return true;
}
+
+ friend class PCHDeclReader;
+ friend class PCHDeclWriter;
};
/// CXXMethodDecl - Represents a static or instance method of a
FriendLoc(FriendL) {
}
+ FriendDecl(EmptyShell Empty) : Decl(Decl::Friend, Empty), NextFriend(0) { }
+
public:
static FriendDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, FriendUnion Friend_,
SourceLocation FriendL);
+ static FriendDecl *Create(ASTContext &C, EmptyShell Empty);
/// If this friend declaration names an (untemplated but
/// possibly dependent) type, return the type; otherwise
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classof(const FriendDecl *D) { return true; }
static bool classofKind(Kind K) { return K == Decl::Friend; }
+
+ friend class PCHDeclReader;
+ friend class PCHDeclWriter;
};
/// An iterator over the friend declarations of a class.
cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
return FD;
}
+
+FriendDecl *FriendDecl::Create(ASTContext &C, EmptyShell Empty) {
+ return new (C) FriendDecl(Empty);
+}
// Declaration deserialization
//===----------------------------------------------------------------------===//
-namespace {
+namespace clang {
class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
PCHReader &Reader;
const PCHReader::RecordData &Record;
void VisitLinkageSpecDecl(LinkageSpecDecl *D);
void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
void VisitAccessSpecDecl(AccessSpecDecl *D);
+ void VisitFriendDecl(FriendDecl *D);
void VisitFriendTemplateDecl(FriendTemplateDecl *D);
void VisitStaticAssertDecl(StaticAssertDecl *D);
void VisitBlockDecl(BlockDecl *BD);
Bases.push_back(ReadCXXBaseSpecifier());
D->setBases(Bases.begin(), NumBases);
+ D->data().FirstFriend
+ = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
+
// FIXME: there's a lot of stuff we do here that's kindof sketchy
// if we're leaving the context incomplete.
D->completeDefinition();
D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
}
+void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
+ if (Record[Idx++])
+ D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
+ else
+ D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
+ D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
+ D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
+}
+
void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
assert(false && "cannot read FriendTemplateDecl");
}
SourceLocation());
break;
case pch::DECL_FRIEND:
- assert(false && "cannot read FriendDecl");
+ D = FriendDecl::Create(*Context, Decl::EmptyShell());
break;
case pch::DECL_FRIEND_TEMPLATE:
assert(false && "cannot read FriendTemplateDecl");
if (DC->getPrimaryContext() != DC)
return 0;
- // Since there is no name lookup into functions or methods, and we
- // perform name lookup for the translation unit via the
- // IdentifierInfo chains, don't bother to build a
- // visible-declarations table for these entities.
- if (DC->isFunctionOrMethod() || DC->isTranslationUnit())
+ // Since there is no name lookup into functions or methods, don't bother to
+ // build a visible-declarations table for these entities.
+ if (DC->isFunctionOrMethod())
+ return 0;
+
+ // If not in C++, we perform name lookup for the translation unit via the
+ // IdentifierInfo chains, don't bother to build a visible-declarations table.
+ // FIXME: In C++ we need the visible declarations in order to "see" the
+ // friend declarations, is there a way to do this without writing the table ?
+ if (DC->isTranslationUnit() && !Context.getLangOptions().CPlusPlus)
return 0;
// Force the DeclContext to build a its name-lookup table.
// Declaration serialization
//===----------------------------------------------------------------------===//
-namespace {
+namespace clang {
class PCHDeclWriter : public DeclVisitor<PCHDeclWriter, void> {
PCHWriter &Writer;
void VisitLinkageSpecDecl(LinkageSpecDecl *D);
void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
void VisitAccessSpecDecl(AccessSpecDecl *D);
+ void VisitFriendDecl(FriendDecl *D);
void VisitFriendTemplateDecl(FriendTemplateDecl *D);
void VisitStaticAssertDecl(StaticAssertDecl *D);
void VisitBlockDecl(BlockDecl *D);
}
void PCHDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
- // assert(false && "cannot write CXXRecordDecl");
VisitRecordDecl(D);
enum {
for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
E = D->bases_end(); I != E; ++I)
WriteCXXBaseSpecifier(&*I);
+
+ Writer.AddDeclRef(D->data().FirstFriend, Record);
}
Code = pch::DECL_CXX_RECORD;
}
Code = pch::DECL_ACCESS_SPEC;
}
+void PCHDeclWriter::VisitFriendDecl(FriendDecl *D) {
+ Record.push_back(D->Friend.is<TypeSourceInfo*>());
+ if (D->Friend.is<TypeSourceInfo*>())
+ Writer.AddTypeSourceInfo(D->Friend.get<TypeSourceInfo*>(), Record);
+ else
+ Writer.AddDeclRef(D->Friend.get<NamedDecl*>(), Record);
+ Writer.AddDeclRef(D->NextFriend, Record);
+ Writer.AddSourceLocation(D->FriendLoc, Record);
+ Code = pch::DECL_FRIEND;
+}
+
void PCHDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
assert(false && "cannot write FriendTemplateDecl");
}
--- /dev/null
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/cxx-friends.h -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-friends.h
+// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s
+
+class F {
+ void m() {
+ A* a;
+ a->x = 0;
+ }
+};
--- /dev/null
+// Header for PCH test cxx-friends.cpp
+
+class A {
+ int x;
+ friend class F;
+};