blob: c07edb4a589fc5c015097ecb202ba9c3bb46ef5c [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 {
22 assert ("FIXME: not implemented.");
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000023}
24
Ted Kremenekbeb77132007-11-01 22:25:41 +000025Decl* Decl::Materialize(llvm::Deserializer& D) {
26 assert ("FIXME: not implemented.");
27 return NULL;
Ted Kremenek2f1f8cb2007-10-25 21:37:16 +000028}
Ted Kremenek04973312007-11-02 18:05:11 +000029
30void NamedDecl::InternalEmit(llvm::Serializer& S) const {
31 S.EmitPtr(Identifier);
32}
33
34void NamedDecl::InternalRead(llvm::Deserializer& D) {
35 D.ReadPtr(Identifier);
36}
37
38void ScopedDecl::InternalEmit(llvm::Serializer& S) const {
39 NamedDecl::InternalEmit(S);
40 S.EmitPtr(Next);
41 S.EmitOwnedPtr<Decl>(NextDeclarator);
42}
43
44void ScopedDecl::InternalRead(llvm::Deserializer& D) {
45 NamedDecl::InternalRead(D);
46 D.ReadPtr(Next);
47 NextDeclarator = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>());
48}
49
50void ValueDecl::InternalEmit(llvm::Serializer& S) const {
51 S.Emit(DeclType);
52 ScopedDecl::InternalEmit(S);
53}
54
55void ValueDecl::InternalRead(llvm::Deserializer& D) {
56 D.Read(DeclType);
57 ScopedDecl::InternalRead(D);
58}
59
60void VarDecl::InternalEmit(llvm::Serializer& S) const {
61 S.EmitInt(SClass);
62 S.EmitInt(objcDeclQualifier);
63 VarDecl::InternalEmit(S);
64 S.EmitOwnedPtr(Init);
65}
66
67void VarDecl::InternalRead(llvm::Deserializer& D) {
68 SClass = D.ReadInt();
69 objcDeclQualifier = static_cast<ObjcDeclQualifier>(D.ReadInt());
70 VarDecl::InternalRead(D);
71 D.ReadOwnedPtr(Init);
72}
73
74
75void BlockVarDecl::Emit(llvm::Serializer& S) const {
76 S.Emit(getLocation());
77 VarDecl::InternalEmit(S);
78}
79
80BlockVarDecl* BlockVarDecl::Materialize(llvm::Deserializer& D) {
81 SourceLocation L = SourceLocation::ReadVal(D);
82 BlockVarDecl* decl = new BlockVarDecl(L,NULL,QualType(),None,NULL);
83 decl->VarDecl::InternalRead(D);
84 return decl;
85}
86
87void FileVarDecl::Emit(llvm::Serializer& S) const {
88 S.Emit(getLocation());
89 VarDecl::InternalEmit(S);
90}
91
92FileVarDecl* FileVarDecl::Materialize(llvm::Deserializer& D) {
93 SourceLocation L = SourceLocation::ReadVal(D);
94 FileVarDecl* decl = new FileVarDecl(L,NULL,QualType(),None,NULL);
95 decl->VarDecl::InternalRead(D);
96 return decl;
97}
98
99void ParmVarDecl::Emit(llvm::Serializer& S) const {
100 S.Emit(getLocation());
101 VarDecl::InternalEmit(S);
102}
103
104ParmVarDecl* ParmVarDecl::Materialize(llvm::Deserializer& D) {
105 SourceLocation L = SourceLocation::ReadVal(D);
106 ParmVarDecl* decl = new ParmVarDecl(L,NULL,QualType(),None,NULL);
107 decl->VarDecl::InternalRead(D);
108 return decl;
109}
110
111void FunctionDecl::Emit(llvm::Serializer& S) const {
112 S.Emit(getLocation());
113 S.EmitInt(SClass);
114 S.EmitBool(IsInline);
115
116 ValueDecl::InternalEmit(S);
117
118 unsigned NumParams = getNumParams();
119 S.EmitInt(NumParams);
120
121 for (unsigned i = 0 ; i < NumParams; ++i)
122 S.EmitOwnedPtr(ParamInfo[i]);
123
124 S.EmitOwnedPtr(Body);
125}
126
127FunctionDecl* FunctionDecl::Materialize(llvm::Deserializer& D) {
128 SourceLocation L = SourceLocation::ReadVal(D);
129 StorageClass SClass = static_cast<StorageClass>(D.ReadInt());
130 bool IsInline = D.ReadBool();
131
132 FunctionDecl* decl = new FunctionDecl(L,NULL,QualType(),SClass,IsInline);
133
134 decl->ValueDecl::InternalRead(D);
135
136 unsigned NumParams = D.ReadInt();
137 decl->ParamInfo = NumParams ? new ParmVarDecl*[NumParams] : NULL;
138
139 for (unsigned i = 0 ; i < NumParams; ++i)
140 D.ReadOwnedPtr(decl->ParamInfo[i]);
141
142 D.ReadOwnedPtr(decl->Body);
143
144 return decl;
145}