-
Notifications
You must be signed in to change notification settings - Fork 2
/
gcc_cmdline_parser.hh
154 lines (129 loc) · 3.46 KB
/
gcc_cmdline_parser.hh
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
146
147
148
149
150
151
152
153
154
/*
* Copyright (C) 2019 SUSE Software Solutions Germany GmbH
*
* This file is part of klp-ccp.
*
* klp-ccp is free software: you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* klp-ccp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with klp-ccp. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GCC_CMDLINE_PARSER_HH
#define GCC_CMDLINE_PARSER_HH
#include <utility>
#include <vector>
#include <functional>
namespace klp
{
namespace ccp
{
class gcc_cmdline_parser
{
public:
struct gcc_version
{
constexpr gcc_version() noexcept
: maj(0), min(0), patchlevel(0)
{}
constexpr gcc_version(unsigned int _maj, unsigned int _min,
unsigned int _patchlevel) noexcept
: maj(_maj), min(_min), patchlevel(_patchlevel)
{}
constexpr bool operator==(const gcc_version &v) const noexcept
{
return (this->maj == v.maj &&
this->min == v.min &&
this->patchlevel == v.patchlevel);
}
constexpr bool operator<=(const gcc_version &v) const noexcept
{
return (((!this->maj && !this->min && !this->patchlevel) ||
(!v.maj && !v.min && !v.patchlevel)) ? true :
(this->maj < v.maj ? true :
(this->maj > v.maj ? false :
(this->min < v.min ? true :
this->min > v.min ? false :
this->patchlevel <= v.patchlevel))));
}
constexpr bool operator<(const gcc_version &v) const noexcept
{
return (this->maj < v.maj ? true :
(this->maj > v.maj ? false :
(this->min < v.min ? true :
this->min > v.min ? false :
this->patchlevel < v.patchlevel)));
}
unsigned int maj;
unsigned int min;
unsigned int patchlevel;
};
struct option
{
enum component
{
comp_none = 0,
comp_common = 0x1,
comp_driver = 0x2,
comp_target = 0x4,
comp_c = 0x8 ,
comp_cxx = 0x10,
comp_objc = 0x20,
comp_objcxx = 0x40,
};
enum argument
{
arg_none = 0,
arg_joined = 0x1,
arg_joined_or_missing = 0x2,
arg_separate = 0x4,
};
struct alias_type
{
const char *name;
const char *pos_arg;
const char *neg_arg;
};
const char *name;
int code;
unsigned int comp;
unsigned int arg;
bool reject_negative;
alias_type alias;
const char *negative;
gcc_version min_gcc_version;
gcc_version max_gcc_version;
};
gcc_cmdline_parser(const gcc_version version) noexcept;
void register_table(const option * const table);
struct decoded_opt
{
decoded_opt(const option *_o, const option *_t, const char *_val,
const bool _negative) noexcept
: o(_o), table(_t), val(_val), negative(_negative)
{}
const option *o;
const option *table;
const char *val;
bool negative;
};
typedef std::vector<decoded_opt> decoded_opts_type;
decoded_opts_type operator()(const int argc, const char *argv[]) const;
std::pair<const option*, const option*>
find_option(const char *s) const noexcept;
private:
typedef std::pair<const option*, std::size_t> _table_type;
const option* _find_option(const char *s, const _table_type &table)
const noexcept;
const gcc_version _version;
std::vector<_table_type> _tables;
};
}
}
#endif