summaryrefslogtreecommitdiffstats
path: root/source/slang/source-loc.h
blob: dc353f402fb2a6237982fb997e363f20bce165e3 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// source-loc.h
#ifndef SLANG_SOURCE_LOC_H_INCLUDED
#define SLANG_SOURCE_LOC_H_INCLUDED

#include "../core/basic.h"

namespace Slang {
namespace Compiler {

using namespace CoreLib::Basic;

class CodePosition
{
public:
	int Line = -1, Col = -1, Pos = -1;
	String FileName;
	String ToString()
	{
		StringBuilder sb(100);
		sb << FileName;
		if (Line != -1)
			sb << "(" << Line << ")";
		return sb.ProduceString();
	}
	CodePosition() = default;
	CodePosition(int line, int col, int pos, String fileName)
	{
		Line = line;
		Col = col;
		Pos = pos;
		this->FileName = fileName;
	}
	bool operator < (const CodePosition & pos) const
	{
		return FileName < pos.FileName || (FileName == pos.FileName && Line < pos.Line) ||
			(FileName == pos.FileName && Line == pos.Line && Col < pos.Col);
	}
	bool operator == (const CodePosition & pos) const
	{
		return FileName == pos.FileName && Line == pos.Line && Col == pos.Col;
	}
};


}}

#endif