summaryrefslogtreecommitdiffhomepage
path: root/minicc.h
blob: 59cc23aa634e1bcc2d4d747a468bc4c16658a811 (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
48
49
50
51
52
53
// Common definitions

#pragma once

#include <boost/core/demangle.hpp>

#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <string>
#include <vector>

using namespace std::string_literals;

using index_t = size_t;

namespace fs = std::filesystem;

std::vector<std::string> split(std::string s);

struct Location {
 size_t line{1};
 size_t column{1};
 size_t pos{0};

 void advance(bool newline = false); ///< advance 1 char
 std::string toString() const;
};

bool operator==(const Location &a, const Location &b);

struct Token {
 std::string type;
 std::string value;
 Location location;

 std::string toString() const;
};

// For printing via Google Test
bool operator==(const Token &a, const Token &b);
std::ostream& operator<<(std::ostream& os, const Token& token);

struct PairHashSS {
 size_t operator()(const std::pair<std::string,std::string>& p) const noexcept
 {
  size_t h0 {std::hash<std::string>{}(p.first)};
  size_t h1 {std::hash<std::string>{}(p.second)};
  return h0 ^ (h1 << 1);
 }
};

std::string demangle(const std::type_info& type);