-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathstdinc.h
145 lines (124 loc) · 3.32 KB
/
stdinc.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS
# define _SCL_SECURE_NO_WARNINGS
#endif
#include <cstdint>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <stdexcept>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <atomic>
#include <cppformat/format.h>
#include "cpp/any.hpp"
#include "cpp/variant.hpp"
#include "cpp/optional.hpp"
#include "cpp/filesystem.hpp"
#include "cpp/scope_guard.hpp"
#include "cpp/string_view.hpp"
#include "cpp/small_vector.hpp"
#include "cpp/icompare.hpp"
#include "cpp/contracts.hpp"
#include "cpp/file.hpp"
#pragma warning(push)
#pragma warning(disable : 4814) // warning: in C++14 'constexpr' will not imply 'const'; consider explicitly specifying 'const'
#include "cpp/expected.hpp"
#pragma warning(pop)
using std::shared_ptr;
using std::weak_ptr;
using dynamic_bitset = std::vector<bool>;
template<typename Value>
using transparent_set = std::set<Value, std::less<>>;
template<typename Key, typename Value>
using transparent_map = std::map<Key, Value, std::less<>>;
template<typename Key, typename Value>
using transparent_multimap = std::multimap<Key, Value, std::less<>>;
template<typename Key, typename Value>
using insensitive_map = std::map<Key, Value, iless>;
template<typename Key>
using insensitive_set = std::set<Key, iless>;
class SyntaxTree;
class ProgramContext;
class Options;
class Commands;
class CodeGenerator;
struct Command;
struct Var;
class Script;
class Scope;
class SymTable;
struct CompiledScmHeader;
class MultiFileHeaderList;
struct Label;
#ifndef _MSC_VER
# define __debugbreak()
#endif
//////// TODO move the following to a 'common' header
/// IR for end of argument list used in variadic argument commands.
struct EOAL
{
};
/// Declared type of a variable.
enum class VarType : uint8_t
{
Int,
Float,
TextLabel,
TextLabel16,
};
// for future parallelism
template<typename IndexType, typename Functor>
inline void for_loop(IndexType begin, IndexType end, Functor functor)
{
for(auto i = begin; i != end; ++i)
functor(i);
}
inline std::string escape_string(const string_view& string, char quotes, bool push_quotes)
{
std::string result;
result.reserve(string.size() + (push_quotes? 2 : 0));
if(push_quotes) result.push_back(quotes);
for(auto& c : string)
{
switch(c)
{
case '\\': result += R"(\\)"; break;
case '\n': result += R"(\n)"; break;
case '\r': result += R"(\r)"; break;
case '\t': result += R"(\t)"; break;
default:
if(c == quotes)
result.push_back('\\');
result.push_back(c);
break;
}
}
if(push_quotes) result.push_back(quotes);
return result;
}
inline string_view remove_quotes(const string_view& string)
{
Expects(string.size() >= 2 && string.front() == '"' && string.back() == '"');
return string_view(string.data() + 1, string.size() - 2);
}
// based off std::quoted
inline std::string make_quoted(const string_view& string, char quotes = '"')
{
return escape_string(string, quotes, true);
}
inline char toupper_ascii(char c)
{
if(c >= 'a' && c <= 'z')
return c - ('a' - 'A');
return c;
}