From: Ted Kremenek Date: Thu, 25 Oct 2007 16:02:43 +0000 (+0000) Subject: Implemented serialization of SourceLocation and SourceRange objects. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19a95bcf3561ed977c48d5f2a2793b60a8c8e573;p=clang Implemented serialization of SourceLocation and SourceRange objects. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43343 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Basic/SourceLocation.cpp b/Basic/SourceLocation.cpp new file mode 100644 index 0000000000..e39f6b7f64 --- /dev/null +++ b/Basic/SourceLocation.cpp @@ -0,0 +1,30 @@ +//==--- SourceLocation.cpp - Compact identifier for Source Files -*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Ted Kremenek and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines serialization methods for the SourceLocation class. +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/SourceLocation.h" +#include "llvm/Bitcode/Serialize.h" +#include "llvm/Bitcode/Deserialize.h" + +using llvm::Serializer; +using llvm::Deserializer; +using llvm::SerializeTrait; +using namespace clang; + +void SerializeTrait::Emit(Serializer& S, SourceLocation L) { + // FIXME: Add code for abbreviation. + S.EmitInt(L.getRawEncoding()); +} + +SourceLocation SerializeTrait::ReadVal(Deserializer& D) { + return SourceLocation::getFromRawEncoding(D.ReadInt()); +} diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index f5cad5cea4..20c83bf5b2 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -15,6 +15,7 @@ #define LLVM_CLANG_SOURCELOCATION_H #include +#include "llvm/Bitcode/Serialization.h" namespace clang { @@ -177,4 +178,31 @@ public: } // end namespace clang +//===----------------------------------------------------------------------===// +// Serialization of SourceLocations and SourceRanges. +//===----------------------------------------------------------------------===// + +namespace llvm { + +template<> struct SerializeTrait { + static void Emit(Serializer& S, clang::SourceLocation L); + static clang::SourceLocation ReadVal(Deserializer& D); +}; + +template<> struct SerializeTrait { + static inline void Emit(Serializer& S, clang::SourceRange R) { + SerializeTrait::Emit(S,R.getBegin()); + SerializeTrait::Emit(S,R.getEnd()); + } + + static inline clang::SourceRange ReadVal(Deserializer& D) { + using clang::SourceLocation; + SourceLocation L = SerializeTrait::ReadVal(D); + SourceLocation R = SerializeTrait::ReadVal(D); + return clang::SourceRange(L,R); + } +}; + +} // end namespace llvm + #endif