/
SourceLocation.cpp
28 lines (25 loc) · 1 KB
/
SourceLocation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//==--- SourceLocation.cpp - Compact identifier for Source Files -*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines accessor methods for the PresumedLoc class.
//
//===----------------------------------------------------------------------===//
#include "gong/Basic/SourceLocation.h"
#include "gong/Basic/SourceManager.h"
#include "llvm/Support/MemoryBuffer.h"
using namespace gong;
// static
PresumedLoc PresumedLoc::build(const SourceManager &SM, SourceLocation Loc) {
int ID = SM.FindBufferContainingLoc(Loc);
if (ID == -1)
return PresumedLoc();
std::pair<unsigned, unsigned> LC = SM.getLineAndColumn(Loc);
return PresumedLoc(SM.getMemoryBuffer(ID)->getBufferIdentifier().data(),
LC.first, LC.second, SM.getBufferInfo(ID).IncludeLoc);
}