blob: 12a49623c6c4c1802b0b2254198a9c30495402e8 [file] [log] [blame]
Ted Kremenek19a95bc2007-10-25 16:02:43 +00001//==--- SourceLocation.cpp - Compact identifier for Source Files -*- C++ -*-==//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremenek19a95bc2007-10-25 16:02:43 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines serialization methods for the SourceLocation class.
Ted Kremenek9c728dc2007-12-12 22:39:36 +000011// This file defines accessor methods for the FullSourceLoc class.
Ted Kremenek19a95bc2007-10-25 16:02:43 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Basic/SourceLocation.h"
Ted Kremenek9c728dc2007-12-12 22:39:36 +000016#include "clang/Basic/SourceManager.h"
Ted Kremenek19a95bc2007-10-25 16:02:43 +000017#include "llvm/Bitcode/Serialize.h"
18#include "llvm/Bitcode/Deserialize.h"
19
Ted Kremenek19a95bc2007-10-25 16:02:43 +000020using namespace clang;
21
Ted Kremenekbeb77132007-11-01 22:25:41 +000022void SourceLocation::Emit(llvm::Serializer& S) const {
23 S.EmitInt(getRawEncoding());
Ted Kremenek19a95bc2007-10-25 16:02:43 +000024}
25
Ted Kremenekbeb77132007-11-01 22:25:41 +000026SourceLocation SourceLocation::ReadVal(llvm::Deserializer& D) {
Ted Kremenek19a95bc2007-10-25 16:02:43 +000027 return SourceLocation::getFromRawEncoding(D.ReadInt());
28}
Ted Kremenekbeb77132007-11-01 22:25:41 +000029
30void SourceRange::Emit(llvm::Serializer& S) const {
31 B.Emit(S);
32 E.Emit(S);
33}
34
35SourceRange SourceRange::ReadVal(llvm::Deserializer& D) {
36 SourceLocation A = SourceLocation::ReadVal(D);
37 SourceLocation B = SourceLocation::ReadVal(D);
38 return SourceRange(A,B);
39}
Ted Kremenek9c728dc2007-12-12 22:39:36 +000040
41FullSourceLoc FullSourceLoc::getLogicalLoc() {
42 assert (isValid());
43 return FullSourceLoc(SrcMgr->getLogicalLoc(Loc),*SrcMgr);
44}
45
46FullSourceLoc FullSourceLoc::getIncludeLoc() {
47 assert (isValid());
48 return FullSourceLoc(SrcMgr->getIncludeLoc(Loc),*SrcMgr);
49}
50
Ted Kremenek1758b072008-04-03 17:55:15 +000051unsigned FullSourceLoc::getLineNumber() const {
Ted Kremenek9c728dc2007-12-12 22:39:36 +000052 assert (isValid());
53 return SrcMgr->getLineNumber(Loc);
54}
55
Ted Kremenek1758b072008-04-03 17:55:15 +000056unsigned FullSourceLoc::getColumnNumber() const {
Ted Kremenek9c728dc2007-12-12 22:39:36 +000057 assert (isValid());
58 return SrcMgr->getColumnNumber(Loc);
59}
60
Ted Kremenek1758b072008-04-03 17:55:15 +000061
62unsigned FullSourceLoc::getLogicalLineNumber() const {
63 assert (isValid());
64 return SrcMgr->getLogicalLineNumber(Loc);
65}
66
67unsigned FullSourceLoc::getLogicalColumnNumber() const {
68 assert (isValid());
69 return SrcMgr->getLogicalColumnNumber(Loc);
70}
71
Ted Kremenek9c728dc2007-12-12 22:39:36 +000072const char* FullSourceLoc::getSourceName() const {
73 assert (isValid());
74 return SrcMgr->getSourceName(Loc);
75}
76
77const FileEntry* FullSourceLoc::getFileEntryForLoc() const {
78 assert (isValid());
79 return SrcMgr->getFileEntryForLoc(Loc);
80}
81
Nico Weber7bfaaae2008-08-10 19:59:06 +000082bool FullSourceLoc::isInSystemHeader() const {
83 assert (isValid());
84 return SrcMgr->isInSystemHeader(Loc);
85}
86
87
Ted Kremenek9c728dc2007-12-12 22:39:36 +000088const char * FullSourceLoc::getCharacterData() const {
89 assert (isValid());
90 return SrcMgr->getCharacterData(Loc);
91}
92
93const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const {
94 assert (isValid());
95 return SrcMgr->getBuffer(Loc.getFileID());
96}
Ted Kremenek9fd87b12008-04-14 21:04:18 +000097
98unsigned FullSourceLoc::getCanonicalFileID() const {
99 return SrcMgr->getCanonicalFileID(Loc);
100}