Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 1 | //===--- 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 Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 21 | void Decl::Emit(llvm::Serializer& S) const { |
Ted Kremenek | 8af8fe3 | 2007-11-05 21:38:00 +0000 | [diff] [blame] | 22 | 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 Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 44 | |
| 45 | case Typedef: |
| 46 | cast<TypedefDecl>(this)->Emit(S); |
| 47 | break; |
Ted Kremenek | 8af8fe3 | 2007-11-05 21:38:00 +0000 | [diff] [blame] | 48 | } |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 51 | Decl* Decl::Materialize(llvm::Deserializer& D) { |
Ted Kremenek | 8af8fe3 | 2007-11-05 21:38:00 +0000 | [diff] [blame] | 52 | assert (false && "FIXME: not implemented."); |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 53 | return NULL; |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 54 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 55 | |
| 56 | void NamedDecl::InternalEmit(llvm::Serializer& S) const { |
| 57 | S.EmitPtr(Identifier); |
| 58 | } |
| 59 | |
| 60 | void NamedDecl::InternalRead(llvm::Deserializer& D) { |
| 61 | D.ReadPtr(Identifier); |
| 62 | } |
| 63 | |
| 64 | void ScopedDecl::InternalEmit(llvm::Serializer& S) const { |
| 65 | NamedDecl::InternalEmit(S); |
| 66 | S.EmitPtr(Next); |
| 67 | S.EmitOwnedPtr<Decl>(NextDeclarator); |
| 68 | } |
| 69 | |
| 70 | void ScopedDecl::InternalRead(llvm::Deserializer& D) { |
| 71 | NamedDecl::InternalRead(D); |
| 72 | D.ReadPtr(Next); |
| 73 | NextDeclarator = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>()); |
| 74 | } |
| 75 | |
| 76 | void ValueDecl::InternalEmit(llvm::Serializer& S) const { |
| 77 | S.Emit(DeclType); |
| 78 | ScopedDecl::InternalEmit(S); |
| 79 | } |
| 80 | |
| 81 | void ValueDecl::InternalRead(llvm::Deserializer& D) { |
| 82 | D.Read(DeclType); |
| 83 | ScopedDecl::InternalRead(D); |
| 84 | } |
| 85 | |
| 86 | void VarDecl::InternalEmit(llvm::Serializer& S) const { |
| 87 | S.EmitInt(SClass); |
| 88 | S.EmitInt(objcDeclQualifier); |
Ted Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 89 | ValueDecl::InternalEmit(S); |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 90 | S.EmitOwnedPtr(Init); |
| 91 | } |
| 92 | |
| 93 | void 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 | |
| 101 | void BlockVarDecl::Emit(llvm::Serializer& S) const { |
| 102 | S.Emit(getLocation()); |
| 103 | VarDecl::InternalEmit(S); |
| 104 | } |
| 105 | |
| 106 | BlockVarDecl* 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 | |
| 113 | void FileVarDecl::Emit(llvm::Serializer& S) const { |
| 114 | S.Emit(getLocation()); |
| 115 | VarDecl::InternalEmit(S); |
| 116 | } |
| 117 | |
| 118 | FileVarDecl* 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 | |
| 125 | void ParmVarDecl::Emit(llvm::Serializer& S) const { |
| 126 | S.Emit(getLocation()); |
| 127 | VarDecl::InternalEmit(S); |
| 128 | } |
| 129 | |
| 130 | ParmVarDecl* 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 | |
| 137 | void 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 | |
| 153 | FunctionDecl* 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 Kremenek | f7bf411 | 2007-11-05 21:49:34 +0000 | [diff] [blame] | 172 | |
| 173 | void TypedefDecl::Emit(llvm::Serializer& S) const { |
| 174 | S.Emit(getLocation()); |
| 175 | InternalEmit(S); |
| 176 | S.Emit(UnderlyingType); |
| 177 | } |
| 178 | |
| 179 | TypedefDecl* 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 | } |