- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathdirectivesParser.hpp
142 lines (122 loc) · 4.21 KB
/
directivesParser.hpp
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
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_COMPILER_DIRECTIVESPARSER_HPP
#defineSHARE_COMPILER_DIRECTIVESPARSER_HPP
#include"compiler/compilerDirectives.hpp"
#include"utilities/json.hpp"
enum FlagType {
boolFlag,
intxFlag,
uintxFlag,
doubleFlag,
ccstrFlag,
ccstrlistFlag,
UnknownFlagType
};
staticconstchar* flag_type_names[] = {
"bool",
"int",
"uint",
"double",
"string",
"string list",
"unknown"
};
classDirectivesParserTest;
classDirectivesParser : publicJSON {
friendclassDirectivesParserTest;
public:
staticboolhas_file();
staticboolparse_from_flag();
staticboolparse_from_file(constchar* filename, outputStream* st, bool silent = false);
staticintparse_string(constchar* string, outputStream* st, bool silent = false);
intinstall_directives();
private:
DirectivesParser(constchar* text, outputStream* st, bool silent);
~DirectivesParser();
boolcallback(JSON_TYPE t, JSON_VAL* v, uint level);
staticboolparse_from_file_inner(constchar* filename, outputStream* st, bool silent = false);
// types of "keys". i.e recognized <key>:<value> pairs in our JSON syntax
typedefenum {
type_c1,
type_c2,
type_enable,
type_preset,
type_match,
type_inline,
// After here, there is no correlation between
// keytype and keys array
//type_strategy,
type_flag,
//type_dir,
// Synthetic.
type_dir_array,
type_directives,
type_value_array
} keytype;
// name, type, dtd info and maybe a setter
// this is how we map key-values
typedefstruct {
constchar *name;
keytype type;
uint allow_array_value : 1;
uint allowedmask;
void (DirectiveSet::*set)(void* arg);
FlagType flag_type;
} key;
// Array with valid keys for the directive file
staticconst key keys[];
// Marker for outermost moosewings/array
staticconst key dir_array_key;
// Marker for a directives set (these are "implicit" objects, as in not named)
staticconst key dir_key;
// Marker for a multi value
staticconst key value_array_key;
// A compiler directive shouldn't be able to use more than 5 stack slots.
// Example of max stack usage:
// depth 1: type_dir_array [
// depth 2: type_directives {
// depth 3: type_c1 c1: {
// depth 4: type_inline inline:
// depth 5: type_value_array [ ...
staticconstuint MAX_DEPTH = 5;
const key* stack[MAX_DEPTH];
uint depth;
boolpush_key(constchar* str, size_t len);
boolpush_key(const key* k);
const key* current_key();
const key* pop_key();
staticconst key* lookup_key(constchar* s, size_t len);
boolset_option(JSON_TYPE t, JSON_VAL* v);
boolset_option_flag(JSON_TYPE t, JSON_VAL* v, const key* option_key, DirectiveSet* set);
CompilerDirectives* current_directive;
DirectiveSet* current_directiveset;
voidpush_tmp(CompilerDirectives* dir);
voidclean_tmp();
CompilerDirectives* pop_tmp();
CompilerDirectives* _tmp_top; // temporary storage for dirs while parsing
int _tmp_depth; // Number of directives that has been parsed but not installed.
staticuintmask(keytype kt);
};
#endif// SHARE_COMPILER_DIRECTIVESPARSER_HPP