blob: a9819be1cca5ab810d7e1983c359906f949d0798 [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;
44 }
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000045}
46
Ted Kremenekbeb77132007-11-01 22:25:41 +000047Decl* Decl::Materialize(llvm::Deserializer& D) {
Ted Kremenek8af8fe32007-11-05 21:38:00 +000048 assert (false && "FIXME: not implemented.");
Ted Kremenekbeb77132007-11-01 22:25:41 +000049 return NULL;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000050}
Ted Kremenek04973312007-11-02 18:05:11 +000051
52void NamedDecl::InternalEmit(llvm::Serializer& S) const {
53 S.EmitPtr(Identifier);
54}
55
56void NamedDecl::InternalRead(llvm::Deserializer& D) {
57 D.ReadPtr(Identifier);
58}
59
60void ScopedDecl::InternalEmit(llvm::Serializer& S) const {
61 NamedDecl::InternalEmit(S);
62 S.EmitPtr(Next);
63 S.EmitOwnedPtr<Decl>(NextDeclarator);
64}
65
66void ScopedDecl::InternalRead(llvm::Deserializer& D) {
67 NamedDecl::InternalRead(D);
68 D.ReadPtr(Next);
69 NextDeclarator = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>());
70}
71
72void ValueDecl::InternalEmit(llvm::Serializer& S) const {
73 S.Emit(DeclType);
74 ScopedDecl::InternalEmit(S);
75}
76
77void ValueDecl::InternalRead(llvm::Deserializer& D) {
78 D.Read(DeclType);
79 ScopedDecl::InternalRead(D);
80}
81
82void VarDecl::InternalEmit(llvm::Serializer& S) const {
83 S.EmitInt(SClass);
84 S.EmitInt(objcDeclQualifier);
85 VarDecl::InternalEmit(S);
86 S.EmitOwnedPtr(Init);
87}
88
89void VarDecl::InternalRead(llvm::Deserializer& D) {
90 SClass = D.ReadInt();
91 objcDeclQualifier = static_cast<ObjcDeclQualifier>(D.ReadInt());
92 VarDecl::InternalRead(D);
93 D.ReadOwnedPtr(Init);
94}
95
96
97void BlockVarDecl::Emit(llvm::Serializer& S) const {
98 S.Emit(getLocation());
99 VarDecl::InternalEmit(S);
100}
101
102BlockVarDecl* BlockVarDecl::Materialize(llvm::Deserializer& D) {
103 SourceLocation L = SourceLocation::ReadVal(D);
104 BlockVarDecl* decl = new BlockVarDecl(L,NULL,QualType(),None,NULL);
105 decl->VarDecl::InternalRead(D);
106 return decl;
107}
108
109void FileVarDecl::Emit(llvm::Serializer& S) const {
110 S.Emit(getLocation());
111 VarDecl::InternalEmit(S);
112}
113
114FileVarDecl* FileVarDecl::Materialize(llvm::Deserializer& D) {
115 SourceLocation L = SourceLocation::ReadVal(D);
116 FileVarDecl* decl = new FileVarDecl(L,NULL,QualType(),None,NULL);
117 decl->VarDecl::InternalRead(D);
118 return decl;
119}
120
121void ParmVarDecl::Emit(llvm::Serializer& S) const {
122 S.Emit(getLocation());
123 VarDecl::InternalEmit(S);
124}
125
126ParmVarDecl* ParmVarDecl::Materialize(llvm::Deserializer& D) {
127 SourceLocation L = SourceLocation::ReadVal(D);
128 ParmVarDecl* decl = new ParmVarDecl(L,NULL,QualType(),None,NULL);
129 decl->VarDecl::InternalRead(D);
130 return decl;
131}
132
133void FunctionDecl::Emit(llvm::Serializer& S) const {
134 S.Emit(getLocation());
135 S.EmitInt(SClass);
136 S.EmitBool(IsInline);
137
138 ValueDecl::InternalEmit(S);
139
140 unsigned NumParams = getNumParams();
141 S.EmitInt(NumParams);
142
143 for (unsigned i = 0 ; i < NumParams; ++i)
144 S.EmitOwnedPtr(ParamInfo[i]);
145
146 S.EmitOwnedPtr(Body);
147}
148
149FunctionDecl* FunctionDecl::Materialize(llvm::Deserializer& D) {
150 SourceLocation L = SourceLocation::ReadVal(D);
151 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
152 bool IsInline = D.ReadBool();
153
154 FunctionDecl* decl = new FunctionDecl(L,NULL,QualType(),SClass,IsInline);
155
156 decl->ValueDecl::InternalRead(D);
157
158 unsigned NumParams = D.ReadInt();
159 decl->ParamInfo = NumParams ? new ParmVarDecl*[NumParams] : NULL;
160
161 for (unsigned i = 0 ; i < NumParams; ++i)
162 D.ReadOwnedPtr(decl->ParamInfo[i]);
163
164 D.ReadOwnedPtr(decl->Body);
165
166 return decl;
167}