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 | |
| 19 | using llvm::SerializeTrait; |
| 20 | using llvm::Deserializer; |
| 21 | using llvm::Serializer; |
| 22 | using namespace clang; |
| 23 | |
| 24 | |
| 25 | static void EmitEnumConstantDecl(Serializer& S, EnumConstantDecl& decl) { |
| 26 | S.Emit(decl.getLocation()); |
| 27 | S.EmitPtr(decl.getIdentifier()); |
| 28 | // S.Emit(decl.getType()); FIXME |
| 29 | S.EmitOwnedPtr<Stmt>(decl.getInitExpr()); |
| 30 | // S.Emit(decl.getInitVal()); FIXME |
| 31 | S.EmitOwnedPtr<Decl>(decl.getNextDeclarator()); |
| 32 | } |
| 33 | |
| 34 | static void EmitFunctionDecl(Serializer& S, FunctionDecl& decl) { |
| 35 | S.Emit(decl.getLocation()); |
| 36 | S.EmitPtr(decl.getIdentifier()); |
| 37 | // S.Emit(decl.getType()); FIXME |
| 38 | // S.Emit(decl.getStorageClass()); FIXME |
| 39 | S.EmitBool(decl.isInline()); |
| 40 | S.EmitOwnedPtr<Decl>(decl.getNextDeclarator()); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | void SerializeTrait<Decl>::Emit(Serializer& S, Decl& decl) { |
| 45 | assert (!decl.isInvalidDecl() && "Can only serialize valid decls."); |
| 46 | |
| 47 | S.EmitInt((unsigned) decl.getKind()); |
| 48 | |
| 49 | switch (decl.getKind()) { |
| 50 | default: |
| 51 | assert (false && "Serialization not implemented for decl type."); |
| 52 | return; |
| 53 | |
| 54 | case Decl::EnumConstant: |
| 55 | EmitEnumConstantDecl(S,cast<EnumConstantDecl>(decl)); |
| 56 | return; |
| 57 | |
| 58 | case Decl::Function: |
| 59 | EmitFunctionDecl(S,cast<FunctionDecl>(decl)); |
| 60 | return; |
| 61 | } |
| 62 | } |