blob: 9ceb6adaef5d3ba18584e6c0ef715acb25251d49 [file] [log] [blame]
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +00001//===--- DeclSerialization.cpp - Serialization of Decls ---------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Ted Kremenek and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This files defines methods that implement bitcode serialization for Decls.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Decl.h"
15#include "clang/AST/Expr.h"
16#include "llvm/Bitcode/Serialize.h"
17#include "llvm/Bitcode/Deserialize.h"
18
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000019using namespace clang;
20
Ted Kremenekbeb77132007-11-01 22:25:41 +000021void Decl::Emit(llvm::Serializer& S) const {
Ted Kremenek8af8fe32007-11-05 21:38:00 +000022 S.EmitInt(getKind());
23
24 switch (getKind()) {
25 default:
26 assert (false && "Not implemented.");
27 break;
28
29 case BlockVar:
30 cast<BlockVarDecl>(this)->Emit(S);
31 break;
32
33 case FileVar:
34 cast<FileVarDecl>(this)->Emit(S);
35 break;
36
37 case ParmVar:
38 cast<ParmVarDecl>(this)->Emit(S);
39 break;
40
41 case Function:
42 cast<FunctionDecl>(this)->Emit(S);
43 break;
Ted Kremenekf7bf4112007-11-05 21:49:34 +000044
45 case Typedef:
46 cast<TypedefDecl>(this)->Emit(S);
47 break;
Ted Kremenek8af8fe32007-11-05 21:38:00 +000048 }
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000049}
50
Ted Kremenekbeb77132007-11-01 22:25:41 +000051Decl* Decl::Materialize(llvm::Deserializer& D) {
Ted Kremenek8af8fe32007-11-05 21:38:00 +000052 assert (false && "FIXME: not implemented.");
Ted Kremenekbeb77132007-11-01 22:25:41 +000053 return NULL;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000054}
Ted Kremenek04973312007-11-02 18:05:11 +000055
56void NamedDecl::InternalEmit(llvm::Serializer& S) const {
57 S.EmitPtr(Identifier);
58}
59
60void NamedDecl::InternalRead(llvm::Deserializer& D) {
61 D.ReadPtr(Identifier);
62}
63
64void ScopedDecl::InternalEmit(llvm::Serializer& S) const {
65 NamedDecl::InternalEmit(S);
66 S.EmitPtr(Next);
67 S.EmitOwnedPtr<Decl>(NextDeclarator);
68}
69
70void ScopedDecl::InternalRead(llvm::Deserializer& D) {
71 NamedDecl::InternalRead(D);
72 D.ReadPtr(Next);
73 NextDeclarator = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>());
74}
75
76void ValueDecl::InternalEmit(llvm::Serializer& S) const {
77 S.Emit(DeclType);
78 ScopedDecl::InternalEmit(S);
79}
80
81void ValueDecl::InternalRead(llvm::Deserializer& D) {
82 D.Read(DeclType);
83 ScopedDecl::InternalRead(D);
84}
85
86void VarDecl::InternalEmit(llvm::Serializer& S) const {
87 S.EmitInt(SClass);
88 S.EmitInt(objcDeclQualifier);
Ted Kremenekf7bf4112007-11-05 21:49:34 +000089 ValueDecl::InternalEmit(S);
Ted Kremenek04973312007-11-02 18:05:11 +000090 S.EmitOwnedPtr(Init);
91}
92
93void VarDecl::InternalRead(llvm::Deserializer& D) {
94 SClass = D.ReadInt();
95 objcDeclQualifier = static_cast<ObjcDeclQualifier>(D.ReadInt());
96 VarDecl::InternalRead(D);
97 D.ReadOwnedPtr(Init);
98}
99
100
101void BlockVarDecl::Emit(llvm::Serializer& S) const {
102 S.Emit(getLocation());
103 VarDecl::InternalEmit(S);
104}
105
106BlockVarDecl* BlockVarDecl::Materialize(llvm::Deserializer& D) {
107 SourceLocation L = SourceLocation::ReadVal(D);
108 BlockVarDecl* decl = new BlockVarDecl(L,NULL,QualType(),None,NULL);
109 decl->VarDecl::InternalRead(D);
110 return decl;
111}
112
113void FileVarDecl::Emit(llvm::Serializer& S) const {
114 S.Emit(getLocation());
115 VarDecl::InternalEmit(S);
116}
117
118FileVarDecl* FileVarDecl::Materialize(llvm::Deserializer& D) {
119 SourceLocation L = SourceLocation::ReadVal(D);
120 FileVarDecl* decl = new FileVarDecl(L,NULL,QualType(),None,NULL);
121 decl->VarDecl::InternalRead(D);
122 return decl;
123}
124
125void ParmVarDecl::Emit(llvm::Serializer& S) const {
126 S.Emit(getLocation());
127 VarDecl::InternalEmit(S);
128}
129
130ParmVarDecl* ParmVarDecl::Materialize(llvm::Deserializer& D) {
131 SourceLocation L = SourceLocation::ReadVal(D);
132 ParmVarDecl* decl = new ParmVarDecl(L,NULL,QualType(),None,NULL);
133 decl->VarDecl::InternalRead(D);
134 return decl;
135}
136
137void FunctionDecl::Emit(llvm::Serializer& S) const {
138 S.Emit(getLocation());
139 S.EmitInt(SClass);
140 S.EmitBool(IsInline);
141
142 ValueDecl::InternalEmit(S);
143
144 unsigned NumParams = getNumParams();
145 S.EmitInt(NumParams);
146
147 for (unsigned i = 0 ; i < NumParams; ++i)
148 S.EmitOwnedPtr(ParamInfo[i]);
149
150 S.EmitOwnedPtr(Body);
151}
152
153FunctionDecl* FunctionDecl::Materialize(llvm::Deserializer& D) {
154 SourceLocation L = SourceLocation::ReadVal(D);
155 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
156 bool IsInline = D.ReadBool();
157
158 FunctionDecl* decl = new FunctionDecl(L,NULL,QualType(),SClass,IsInline);
159
160 decl->ValueDecl::InternalRead(D);
161
162 unsigned NumParams = D.ReadInt();
163 decl->ParamInfo = NumParams ? new ParmVarDecl*[NumParams] : NULL;
164
165 for (unsigned i = 0 ; i < NumParams; ++i)
166 D.ReadOwnedPtr(decl->ParamInfo[i]);
167
168 D.ReadOwnedPtr(decl->Body);
169
170 return decl;
171}
Ted Kremenekf7bf4112007-11-05 21:49:34 +0000172
173void TypedefDecl::Emit(llvm::Serializer& S) const {
174 S.Emit(getLocation());
175 InternalEmit(S);
176 S.Emit(UnderlyingType);
177}
178
179TypedefDecl* TypedefDecl::Materialize(llvm::Deserializer& D) {
180 SourceLocation L = SourceLocation::ReadVal(D);
181 TypedefDecl* decl = new TypedefDecl(L,NULL,QualType(),NULL);
182 decl->InternalRead(D);
183 D.Read(decl->UnderlyingType);
184 return decl;
185}