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; |
| 44 | } |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 47 | Decl* Decl::Materialize(llvm::Deserializer& D) { |
Ted Kremenek | 8af8fe3 | 2007-11-05 21:38:00 +0000 | [diff] [blame] | 48 | assert (false && "FIXME: not implemented."); |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 49 | return NULL; |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 50 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame] | 51 | |
| 52 | void NamedDecl::InternalEmit(llvm::Serializer& S) const { |
| 53 | S.EmitPtr(Identifier); |
| 54 | } |
| 55 | |
| 56 | void NamedDecl::InternalRead(llvm::Deserializer& D) { |
| 57 | D.ReadPtr(Identifier); |
| 58 | } |
| 59 | |
| 60 | void ScopedDecl::InternalEmit(llvm::Serializer& S) const { |
| 61 | NamedDecl::InternalEmit(S); |
| 62 | S.EmitPtr(Next); |
| 63 | S.EmitOwnedPtr<Decl>(NextDeclarator); |
| 64 | } |
| 65 | |
| 66 | void ScopedDecl::InternalRead(llvm::Deserializer& D) { |
| 67 | NamedDecl::InternalRead(D); |
| 68 | D.ReadPtr(Next); |
| 69 | NextDeclarator = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>()); |
| 70 | } |
| 71 | |
| 72 | void ValueDecl::InternalEmit(llvm::Serializer& S) const { |
| 73 | S.Emit(DeclType); |
| 74 | ScopedDecl::InternalEmit(S); |
| 75 | } |
| 76 | |
| 77 | void ValueDecl::InternalRead(llvm::Deserializer& D) { |
| 78 | D.Read(DeclType); |
| 79 | ScopedDecl::InternalRead(D); |
| 80 | } |
| 81 | |
| 82 | void VarDecl::InternalEmit(llvm::Serializer& S) const { |
| 83 | S.EmitInt(SClass); |
| 84 | S.EmitInt(objcDeclQualifier); |
| 85 | VarDecl::InternalEmit(S); |
| 86 | S.EmitOwnedPtr(Init); |
| 87 | } |
| 88 | |
| 89 | void 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 | |
| 97 | void BlockVarDecl::Emit(llvm::Serializer& S) const { |
| 98 | S.Emit(getLocation()); |
| 99 | VarDecl::InternalEmit(S); |
| 100 | } |
| 101 | |
| 102 | BlockVarDecl* 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 | |
| 109 | void FileVarDecl::Emit(llvm::Serializer& S) const { |
| 110 | S.Emit(getLocation()); |
| 111 | VarDecl::InternalEmit(S); |
| 112 | } |
| 113 | |
| 114 | FileVarDecl* 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 | |
| 121 | void ParmVarDecl::Emit(llvm::Serializer& S) const { |
| 122 | S.Emit(getLocation()); |
| 123 | VarDecl::InternalEmit(S); |
| 124 | } |
| 125 | |
| 126 | ParmVarDecl* 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 | |
| 133 | void 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 | |
| 149 | FunctionDecl* 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 | } |