3 #include <utils/Assert.h>
8 #include "diagnostics/SourceManager.h"
20 SourceLocation() : file_
{}, line_{-1}, column_{-1} {}
23 SourceLocation(
SourceFile file,
int line,
int column)
24 : file_{file}, line_{line}, column_{column} {}
25 std::ostream& print(std::ostream& os)
const {
27 os <<
":" << line_ <<
":" << column_;
30 std::string toString()
const {
31 std::ostringstream os;
37 bool isValid()
const {
return line_ != -1; }
40 int line()
const {
return line_; }
41 int column()
const {
return column_; }
58 SourceRange(
SourceFile file) : begin_{file, 0, 0}, end_{file, 0, 0} {}
63 : begin_{begin}, end_{end} {
64 assert(begin.file_ == end.file_ &&
"SourceRange spans multiple files");
71 std::ostream& print(std::ostream& os)
const {
73 os <<
" - " << end_.line_ <<
":" << end_.column_;
77 std::string toString()
const {
78 std::ostringstream os;
87 assert(a.begin_.file_ == b.begin_.file_ &&
88 "Tried to merge SourceRanges from different files");
89 auto file = a.begin_.file_;
95 std::min(a.begin_.line_, b.begin_.line_),
96 std::min(a.begin_.column_, b.begin_.column_)}
,
99 std::max(a.end_.line_, b.end_.line_),
100 std::max(a.end_.column_, b.end_.column_)}
};