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 { |
| 22 | assert ("FIXME: not implemented."); |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 25 | Decl* Decl::Materialize(llvm::Deserializer& D) { |
| 26 | assert ("FIXME: not implemented."); |
| 27 | return NULL; |
Ted Kremenek | 2f1f8cb | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 28 | } |
Ted Kremenek | 0497331 | 2007-11-02 18:05:11 +0000 | [diff] [blame^] | 29 | |
| 30 | void NamedDecl::InternalEmit(llvm::Serializer& S) const { |
| 31 | S.EmitPtr(Identifier); |
| 32 | } |
| 33 | |
| 34 | void NamedDecl::InternalRead(llvm::Deserializer& D) { |
| 35 | D.ReadPtr(Identifier); |
| 36 | } |
| 37 | |
| 38 | void ScopedDecl::InternalEmit(llvm::Serializer& S) const { |
| 39 | NamedDecl::InternalEmit(S); |
| 40 | S.EmitPtr(Next); |
| 41 | S.EmitOwnedPtr<Decl>(NextDeclarator); |
| 42 | } |
| 43 | |
| 44 | void ScopedDecl::InternalRead(llvm::Deserializer& D) { |
| 45 | NamedDecl::InternalRead(D); |
| 46 | D.ReadPtr(Next); |
| 47 | NextDeclarator = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>()); |
| 48 | } |
| 49 | |
| 50 | void ValueDecl::InternalEmit(llvm::Serializer& S) const { |
| 51 | S.Emit(DeclType); |
| 52 | ScopedDecl::InternalEmit(S); |
| 53 | } |
| 54 | |
| 55 | void ValueDecl::InternalRead(llvm::Deserializer& D) { |
| 56 | D.Read(DeclType); |
| 57 | ScopedDecl::InternalRead(D); |
| 58 | } |
| 59 | |
| 60 | void VarDecl::InternalEmit(llvm::Serializer& S) const { |
| 61 | S.EmitInt(SClass); |
| 62 | S.EmitInt(objcDeclQualifier); |
| 63 | VarDecl::InternalEmit(S); |
| 64 | S.EmitOwnedPtr(Init); |
| 65 | } |
| 66 | |
| 67 | void 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 | |
| 75 | void BlockVarDecl::Emit(llvm::Serializer& S) const { |
| 76 | S.Emit(getLocation()); |
| 77 | VarDecl::InternalEmit(S); |
| 78 | } |
| 79 | |
| 80 | BlockVarDecl* 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 | |
| 87 | void FileVarDecl::Emit(llvm::Serializer& S) const { |
| 88 | S.Emit(getLocation()); |
| 89 | VarDecl::InternalEmit(S); |
| 90 | } |
| 91 | |
| 92 | FileVarDecl* 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 | |
| 99 | void ParmVarDecl::Emit(llvm::Serializer& S) const { |
| 100 | S.Emit(getLocation()); |
| 101 | VarDecl::InternalEmit(S); |
| 102 | } |
| 103 | |
| 104 | ParmVarDecl* 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 | |
| 111 | void 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 | |
| 127 | FunctionDecl* 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 | } |