Ted Kremenek | 19a95bc | 2007-10-25 16:02:43 +0000 | [diff] [blame] | 1 | //==--- SourceLocation.cpp - Compact identifier for Source Files -*- C++ -*-==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Ted Kremenek | 19a95bc | 2007-10-25 16:02:43 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines serialization methods for the SourceLocation class. |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 11 | // This file defines accessor methods for the FullSourceLoc class. |
Ted Kremenek | 19a95bc | 2007-10-25 16:02:43 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Basic/SourceLocation.h" |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 16 | #include "clang/Basic/SourceManager.h" |
Ted Kremenek | 19a95bc | 2007-10-25 16:02:43 +0000 | [diff] [blame] | 17 | #include "llvm/Bitcode/Serialize.h" |
| 18 | #include "llvm/Bitcode/Deserialize.h" |
| 19 | |
Ted Kremenek | 19a95bc | 2007-10-25 16:02:43 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 22 | void SourceLocation::Emit(llvm::Serializer& S) const { |
| 23 | S.EmitInt(getRawEncoding()); |
Ted Kremenek | 19a95bc | 2007-10-25 16:02:43 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 26 | SourceLocation SourceLocation::ReadVal(llvm::Deserializer& D) { |
Ted Kremenek | 19a95bc | 2007-10-25 16:02:43 +0000 | [diff] [blame] | 27 | return SourceLocation::getFromRawEncoding(D.ReadInt()); |
| 28 | } |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 29 | |
| 30 | void SourceRange::Emit(llvm::Serializer& S) const { |
| 31 | B.Emit(S); |
| 32 | E.Emit(S); |
| 33 | } |
| 34 | |
| 35 | SourceRange SourceRange::ReadVal(llvm::Deserializer& D) { |
| 36 | SourceLocation A = SourceLocation::ReadVal(D); |
| 37 | SourceLocation B = SourceLocation::ReadVal(D); |
| 38 | return SourceRange(A,B); |
| 39 | } |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 40 | |
| 41 | FullSourceLoc FullSourceLoc::getLogicalLoc() { |
| 42 | assert (isValid()); |
| 43 | return FullSourceLoc(SrcMgr->getLogicalLoc(Loc),*SrcMgr); |
| 44 | } |
| 45 | |
| 46 | FullSourceLoc FullSourceLoc::getIncludeLoc() { |
| 47 | assert (isValid()); |
| 48 | return FullSourceLoc(SrcMgr->getIncludeLoc(Loc),*SrcMgr); |
| 49 | } |
| 50 | |
Ted Kremenek | 1758b07 | 2008-04-03 17:55:15 +0000 | [diff] [blame] | 51 | unsigned FullSourceLoc::getLineNumber() const { |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 52 | assert (isValid()); |
| 53 | return SrcMgr->getLineNumber(Loc); |
| 54 | } |
| 55 | |
Ted Kremenek | 1758b07 | 2008-04-03 17:55:15 +0000 | [diff] [blame] | 56 | unsigned FullSourceLoc::getColumnNumber() const { |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 57 | assert (isValid()); |
| 58 | return SrcMgr->getColumnNumber(Loc); |
| 59 | } |
| 60 | |
Ted Kremenek | 1758b07 | 2008-04-03 17:55:15 +0000 | [diff] [blame] | 61 | |
| 62 | unsigned FullSourceLoc::getLogicalLineNumber() const { |
| 63 | assert (isValid()); |
| 64 | return SrcMgr->getLogicalLineNumber(Loc); |
| 65 | } |
| 66 | |
| 67 | unsigned FullSourceLoc::getLogicalColumnNumber() const { |
| 68 | assert (isValid()); |
| 69 | return SrcMgr->getLogicalColumnNumber(Loc); |
| 70 | } |
| 71 | |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 72 | const char* FullSourceLoc::getSourceName() const { |
| 73 | assert (isValid()); |
| 74 | return SrcMgr->getSourceName(Loc); |
| 75 | } |
| 76 | |
| 77 | const FileEntry* FullSourceLoc::getFileEntryForLoc() const { |
| 78 | assert (isValid()); |
| 79 | return SrcMgr->getFileEntryForLoc(Loc); |
| 80 | } |
| 81 | |
| 82 | const char * FullSourceLoc::getCharacterData() const { |
| 83 | assert (isValid()); |
| 84 | return SrcMgr->getCharacterData(Loc); |
| 85 | } |
| 86 | |
| 87 | const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const { |
| 88 | assert (isValid()); |
| 89 | return SrcMgr->getBuffer(Loc.getFileID()); |
| 90 | } |
Ted Kremenek | 9fd87b1 | 2008-04-14 21:04:18 +0000 | [diff] [blame] | 91 | |
| 92 | unsigned FullSourceLoc::getCanonicalFileID() const { |
| 93 | return SrcMgr->getCanonicalFileID(Loc); |
| 94 | } |