clang: lib/Basic/SourceLocation.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

17#include "llvm/ADT/DenseMapInfo.h"

18#include "llvm/ADT/FoldingSet.h"

19#include "llvm/ADT/StringRef.h"

20#include "llvm/Support/Compiler.h"

21#include "llvm/Support/MemoryBuffer.h"

22#include "llvm/Support/raw_ostream.h"

23#include

24#include

25#include

26

27using namespace clang;

28

29

30

31

32

35 Loc.print(OS, SM);

36 OS << ": ";

37 }

38 OS << Message << '\n';

39}

40

41

42

43

44

45static_assert(std::is_trivially_destructible_v,

46 "SourceLocation must be trivially destructible because it is "

47 "used in unions");

48

49static_assert(std::is_trivially_destructible_v,

50 "SourceRange must be trivially destructible because it is "

51 "used in unions");

52

54 return llvm::DenseMapInfo::getHashValue(ID);

55}

56

59 ID.AddInteger(X.ID);

60}

61

64 OS << "";

65 return;

66 }

67

70

72 OS << "";

73 return;

74 }

75

78 return;

79 }

80

81 SM.getExpansionLoc(*this).print(OS, SM);

82

83 OS << " <Spelling=";

84 SM.getSpellingLoc(*this).print(OS, SM);

85 OS << '>';

86}

87

88LLVM_DUMP_METHOD std::string

90 std::string S;

91 llvm::raw_string_ostream OS(S);

93 return S;

94}

95

98 llvm::errs() << '\n';

99}

100

103 llvm::errs() << '\n';

104}

105

109

111

113 OS << "";

115 }

116

122 OS << "line" << ':' << PLoc.getLine() << ':' << PLoc.getColumn();

123 } else {

124 OS << "col" << ':' << PLoc.getColumn();

125 }

126 return PLoc;

127 }

129

130 OS << " <Spelling=";

132 OS << '>';

133 return PrintedLoc;

134}

135

137

138 OS << '<';

140 if (B != E) {

141 OS << ", ";

143 }

144 OS << '>';

145}

146

147LLVM_DUMP_METHOD std::string

149 std::string S;

150 llvm::raw_string_ostream OS(S);

152 return S;

153}

154

155

156

157

158

162}

163

167}

168

171}

172

176}

177

181}

182

186

187 return SrcMgr->getPresumedLoc(*this, UseLineDirectives);

188}

189

193}

194

198}

199

202 return std::make_pair(FullSourceLoc(), StringRef());

203

204 std::pair<SourceLocation, StringRef> ImportLoc =

206 return std::make_pair(FullSourceLoc(ImportLoc.first, *SrcMgr),

207 ImportLoc.second);

208}

209

213}

214

218}

219

223}

224

228}

229

233}

234

238}

239

243}

244

248}

249

253}

254

258}

259

263}

264

267}

268

272}

273

277}

278

281}

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...

static PresumedLoc PrintDifference(raw_ostream &OS, const SourceManager &SM, SourceLocation Loc, PresumedLoc Previous)

Defines the clang::SourceLocation class and associated facilities.

Defines the SourceManager interface.

Cached information about one file (either on disk or in the virtual file system).

An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...

A SourceLocation and its associated SourceManager.

FullSourceLoc getFileLoc() const

unsigned getColumnNumber(bool *Invalid=nullptr) const

std::pair< FileID, unsigned > getDecomposedExpansionLoc() const

Decompose the underlying SourceLocation into a raw (FileID + Offset) pair, after walking through all ...

FullSourceLoc getExpansionLoc() const

unsigned getLineNumber(bool *Invalid=nullptr) const

FullSourceLoc getSpellingLoc() const

std::pair< FullSourceLoc, StringRef > getModuleImportLoc() const

OptionalFileEntryRef getFileEntryRef() const

unsigned getSpellingLineNumber(bool *Invalid=nullptr) const

FullSourceLoc getImmediateMacroCallerLoc() const

const char * getCharacterData(bool *Invalid=nullptr) const

unsigned getExpansionColumnNumber(bool *Invalid=nullptr) const

StringRef getBufferData(bool *Invalid=nullptr) const

Return a StringRef to the source buffer data for the specified FileID.

void dump() const

Prints information about this FullSourceLoc to stderr.

bool isInSystemHeader() const

const FileEntry * getFileEntry() const

unsigned getFileOffset() const

std::pair< FileID, unsigned > getDecomposedLoc() const

Decompose the specified location into a raw FileID + Offset pair.

FullSourceLoc()=default

Creates a FullSourceLoc where isValid() returns false.

PresumedLoc getPresumedLoc(bool UseLineDirectives=true) const

bool isMacroArgExpansion(FullSourceLoc *StartLoc=nullptr) const

unsigned getExpansionLineNumber(bool *Invalid=nullptr) const

bool isBeforeInTranslationUnitThan(SourceLocation Loc) const

Determines the order of 2 source locations in the translation unit.

unsigned getSpellingColumnNumber(bool *Invalid=nullptr) const

Represents an unpacked "presumed" location which can be presented to the user.

unsigned getColumn() const

Return the presumed column number of this location.

const char * getFilename() const

Return the presumed filename of this location.

unsigned getLine() const

Return the presumed line number of this location.

bool isInvalid() const

Return true if this object is invalid or uninitialized.

void print(raw_ostream &OS) const override

Encodes a location in the source.

std::string printToString(const SourceManager &SM) const

void dump(const SourceManager &SM) const

bool isValid() const

Return true if this is a valid SourceLocation object.

void print(raw_ostream &OS, const SourceManager &SM) const

unsigned getHashValue() const

This class handles loading and caching of source files into memory.

FileID getFileID(SourceLocation SpellingLoc) const

Return the FileID for a SourceLocation.

unsigned getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const

Return the column # for the specified file position.

unsigned getFileOffset(SourceLocation SpellingLoc) const

Returns the offset from the start of the file that the specified SourceLocation represents.

PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const

Returns the "presumed" location of a SourceLocation specifies.

OptionalFileEntryRef getFileEntryRefForID(FileID FID) const

Returns the FileEntryRef for the provided FileID.

SourceLocation getFileLoc(SourceLocation Loc) const

Given Loc, if it is a macro location return the expansion location or the spelling location,...

unsigned getExpansionColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const

StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const

Return a StringRef to the source buffer data for the specified FileID.

bool isMacroArgExpansion(SourceLocation Loc, SourceLocation *StartLoc=nullptr) const

Tests whether the given source location represents a macro argument's expansion into the function-lik...

SourceLocation getSpellingLoc(SourceLocation Loc) const

Given a SourceLocation object, return the spelling location referenced by the ID.

SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const

Gets the location of the immediate macro caller, one level up the stack toward the initial macro type...

const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const

Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer.

unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const

unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const

Given a SourceLocation, return the spelling line number for the position indicated.

unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const

bool isInSystemHeader(SourceLocation Loc) const

Returns if a SourceLocation is in a system header.

std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const

Decompose the specified location into a raw FileID + Offset pair.

unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const

std::pair< SourceLocation, StringRef > getModuleImportLoc(SourceLocation Loc) const

std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const

Decompose the specified location into a raw FileID + Offset pair.

const FileEntry * getFileEntryForID(FileID FID) const

Returns the FileEntry record for the provided FileID.

SourceLocation getExpansionLoc(SourceLocation Loc) const

Given a SourceLocation object Loc, return the expansion location referenced by the ID.

bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const

Determines the order of 2 source locations in the translation unit.

std::string printToString(const SourceManager &SM) const

void dump(const SourceManager &SM) const

void print(raw_ostream &OS, const SourceManager &SM) const

The JSON file list parser is used to communicate input to InstallAPI.