/// isMutable - Determines whether this field is mutable (C++ only).
bool isMutable() const { return Mutable; }
+ /// \brief Set whether this field is mutable (C++ only).
+ void setMutable(bool M) { Mutable = M; }
+
/// isBitfield - Determines whether this field is a bitfield.
bool isBitField() const { return BitWidth != NULL; }
DECL_TYPEDEF,
/// \brief An EnumDecl record.
DECL_ENUM,
+ /// \brief A RecordDecl record.
+ DECL_RECORD,
/// \brief An EnumConstantDecl record.
DECL_ENUM_CONSTANT,
+ /// \brief A FieldDecl record.
+ DECL_FIELD,
/// \brief A VarDecl record.
DECL_VAR,
/// \brief A record that stores the set of declarations that are
void VisitTypedefDecl(TypedefDecl *TD);
void VisitTagDecl(TagDecl *TD);
void VisitEnumDecl(EnumDecl *ED);
+ void VisitRecordDecl(RecordDecl *RD);
void VisitValueDecl(ValueDecl *VD);
void VisitEnumConstantDecl(EnumConstantDecl *ECD);
+ void VisitFieldDecl(FieldDecl *FD);
void VisitVarDecl(VarDecl *VD);
std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
ED->setIntegerType(Reader.GetType(Record[Idx++]));
}
+void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
+ VisitTagDecl(RD);
+ RD->setHasFlexibleArrayMember(Record[Idx++]);
+ RD->setAnonymousStructOrUnion(Record[Idx++]);
+}
+
void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
VisitNamedDecl(VD);
VD->setType(Reader.GetType(Record[Idx++]));
void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
VisitValueDecl(ECD);
- // FIXME: initialization expression
+ // FIXME: read the initialization expression
ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
}
+void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
+ VisitValueDecl(FD);
+ FD->setMutable(Record[Idx++]);
+ // FIXME: Read the bit width.
+}
+
void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
VisitValueDecl(VD);
VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
}
case pch::TYPE_RECORD:
- // FIXME: Deserialize RecordType
- assert(false && "Cannot de-serialize record types yet");
- return QualType();
+ assert(Record.size() == 1 && "Incorrect encoding of record type");
+ return Context.getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0])));
case pch::TYPE_ENUM:
assert(Record.size() == 1 && "Incorrect encoding of enum type");
break;
}
+ case pch::DECL_RECORD: {
+ RecordDecl *Record = RecordDecl::Create(Context, TagDecl::TK_struct,
+ 0, SourceLocation(), 0, 0);
+ LoadedDecl(Index, Record);
+ Reader.VisitRecordDecl(Record);
+ D = Record;
+ break;
+ }
+
case pch::DECL_ENUM_CONSTANT: {
EnumConstantDecl *ECD = EnumConstantDecl::Create(Context, 0,
SourceLocation(), 0,
break;
}
+ case pch::DECL_FIELD: {
+ FieldDecl *Field = FieldDecl::Create(Context, 0, SourceLocation(), 0,
+ QualType(), 0, false);
+ LoadedDecl(Index, Field);
+ Reader.VisitFieldDecl(Field);
+ D = Field;
+ break;
+ }
+
case pch::DECL_VAR: {
VarDecl *Var = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
VarDecl::None, SourceLocation());
Decls.clear();
unsigned Idx = 0;
- // llvm::SmallVector<uintptr_t, 16> DeclIDs;
while (Idx < Record.size()) {
Decls.push_back(VisibleDeclaration());
Decls.back().Name = ReadDeclarationName(Record, Idx);
- // FIXME: Don't actually read anything here!
unsigned Size = Record[Idx++];
llvm::SmallVector<unsigned, 4> & LoadedDecls
= Decls.back().Declarations;
void VisitTypedefDecl(TypedefDecl *D);
void VisitTagDecl(TagDecl *D);
void VisitEnumDecl(EnumDecl *D);
+ void VisitRecordDecl(RecordDecl *D);
void VisitValueDecl(ValueDecl *D);
void VisitEnumConstantDecl(EnumConstantDecl *D);
+ void VisitFieldDecl(FieldDecl *D);
void VisitVarDecl(VarDecl *D);
void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
uint64_t VisibleOffset);
Code = pch::DECL_ENUM;
}
+void PCHDeclWriter::VisitRecordDecl(RecordDecl *D) {
+ VisitTagDecl(D);
+ Record.push_back(D->hasFlexibleArrayMember());
+ Record.push_back(D->isAnonymousStructOrUnion());
+ Code = pch::DECL_RECORD;
+}
+
void PCHDeclWriter::VisitValueDecl(ValueDecl *D) {
VisitNamedDecl(D);
Writer.AddTypeRef(D->getType(), Record);
Code = pch::DECL_ENUM_CONSTANT;
}
+void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) {
+ VisitValueDecl(D);
+ Record.push_back(D->isMutable());
+ // FIXME: Writer.AddExprRef(D->getBitWidth());
+ Code = pch::DECL_FIELD;
+}
+
void PCHDeclWriter::VisitVarDecl(VarDecl *D) {
VisitValueDecl(D);
Record.push_back(D->getStorageClass());
uint64_t Offset = S.GetCurrentBitNo();
RecordData Record;
StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr());
+ if (!Map)
+ return 0;
+
for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end();
D != DEnd; ++D) {
AddDeclarationName(D->first, Record);
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -include %S/enum.h -fsyntax-only -verify %s
+// RUN: clang-cc -include %S/enum.h -fsyntax-only -verify %s
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -o %t %S/enum.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -include-pch %t -fsyntax-only -verify %s
+// RUN: clang-cc -emit-pch -o %t %S/enum.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
int i = Red;
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -include %S/line-directive.h -fsyntax-only %s 2>&1|grep "25:5"
+// RUN: clang-cc -include %S/line-directive.h -fsyntax-only %s 2>&1|grep "25:5"
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -o %t %S/line-directive.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -include-pch %t -fsyntax-only %s 2>&1|grep "25:5"
+// RUN: clang-cc -emit-pch -o %t %S/line-directive.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only %s 2>&1|grep "25:5"
double x; // expected-error{{redefinition of 'x' with a different type}}
--- /dev/null
+// Test this without pch.
+// RUN: clang-cc -include %S/struct.h -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/struct.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+struct Point *p1;
+
+float getX(struct Point *p1) {
+ return p1->x;
+}
+
+void *get_fun_ptr() {
+ return fun->is_ptr? fun->ptr : 0;
+}
+
+struct Fun2 {
+ int very_fun;
+};
+
+int get_very_fun() {
+ return fun2->very_fun;
+}
--- /dev/null
+// Used with the struct.c test
+
+struct Point {
+ float x, y, z;
+};
+
+struct Point2 {
+ float xValue, yValue, zValue;
+};
+
+struct Fun;
+
+struct Fun *fun;
+
+struct Fun {
+ int is_ptr;
+
+ union {
+ void *ptr;
+ int *integer;
+ };
+};
+
+struct Fun2;
+struct Fun2 *fun2;
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -fblocks -include %S/types.h -fsyntax-only -verify %s
+// RUN: clang-cc -fblocks -include %S/types.h -fsyntax-only -verify %s
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -fblocks -o %t %S/types.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -fblocks -include-pch %t -fsyntax-only -verify %s
+// RUN: clang-cc -emit-pch -fblocks -o %t %S/types.h &&
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -verify %s
// FIXME: TYPE_EXT_QUAL
// FIXME: TYPE_FIXED_WIDTH_INT
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -include %S/variables.h -fsyntax-only -verify %s
+// RUN: clang-cc -include %S/variables.h -fsyntax-only -verify %s
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -o %t %S/variables.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -include-pch %t -fsyntax-only -verify %s
+// RUN: clang-cc -emit-pch -o %t %S/variables.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
int *ip2 = &x;
float *fp = &ip; // expected-warning{{incompatible pointer types}}