2015-10-20 18:07:28 +02:00
|
|
|
/*
|
2019-01-10 15:13:51 -05:00
|
|
|
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
2015-10-20 18:07:28 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_COMPILER_DIRECTIVESPARSER_HPP
|
|
|
|
#define SHARE_COMPILER_DIRECTIVESPARSER_HPP
|
2015-10-20 18:07:28 +02:00
|
|
|
|
|
|
|
#include "utilities/json.hpp"
|
|
|
|
#include "compiler/compilerDirectives.hpp"
|
|
|
|
|
|
|
|
enum FlagType {
|
|
|
|
boolFlag,
|
|
|
|
intxFlag,
|
2016-11-29 12:40:46 -08:00
|
|
|
uintxFlag,
|
2015-10-20 18:07:28 +02:00
|
|
|
doubleFlag,
|
|
|
|
ccstrFlag,
|
2015-10-29 09:24:00 +01:00
|
|
|
ccstrlistFlag,
|
2015-10-20 18:07:28 +02:00
|
|
|
UnknownFlagType
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* flag_type_names[] = {
|
|
|
|
"bool",
|
|
|
|
"int",
|
2016-11-29 12:40:46 -08:00
|
|
|
"uint",
|
2015-10-20 18:07:28 +02:00
|
|
|
"double",
|
|
|
|
"string",
|
2015-10-29 09:24:00 +01:00
|
|
|
"string list",
|
2015-10-20 18:07:28 +02:00
|
|
|
"unknown"
|
|
|
|
};
|
|
|
|
|
2018-10-25 11:18:24 -07:00
|
|
|
class DirectivesParserTest;
|
|
|
|
|
2015-10-20 18:07:28 +02:00
|
|
|
class DirectivesParser : public JSON {
|
2018-10-25 11:18:24 -07:00
|
|
|
friend class DirectivesParserTest;
|
|
|
|
public:
|
2015-10-20 18:07:28 +02:00
|
|
|
static bool has_file();
|
|
|
|
static bool parse_from_flag();
|
|
|
|
static bool parse_from_file(const char* filename, outputStream* st);
|
2016-03-03 16:21:16 +01:00
|
|
|
static int parse_string(const char* string, outputStream* st);
|
|
|
|
int install_directives();
|
2015-10-20 18:07:28 +02:00
|
|
|
|
2018-10-25 11:18:24 -07:00
|
|
|
private:
|
2016-04-28 15:52:08 +02:00
|
|
|
DirectivesParser(const char* text, outputStream* st, bool silent);
|
2015-10-20 18:07:28 +02:00
|
|
|
~DirectivesParser();
|
|
|
|
|
|
|
|
bool callback(JSON_TYPE t, JSON_VAL* v, uint level);
|
|
|
|
static bool parse_from_file_inner(const char* filename, outputStream* st);
|
|
|
|
|
|
|
|
// types of "keys". i.e recognized <key>:<value> pairs in our JSON syntax
|
|
|
|
typedef enum {
|
|
|
|
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
|
|
|
|
typedef struct {
|
|
|
|
const char *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
|
|
|
|
static const key keys[];
|
|
|
|
// Marker for outermost moosewings/array
|
|
|
|
static const key dir_array_key;
|
|
|
|
// Marker for a directives set (these are "implicit" objects, as in not named)
|
|
|
|
static const key dir_key;
|
|
|
|
// Marker for a multi value
|
|
|
|
static const 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 [ ...
|
|
|
|
static const uint MAX_DEPTH = 5;
|
|
|
|
const key* stack[MAX_DEPTH];
|
|
|
|
uint depth;
|
|
|
|
|
|
|
|
bool push_key(const char* str, size_t len);
|
|
|
|
bool push_key(const key* k);
|
|
|
|
const key* current_key();
|
|
|
|
const key* pop_key();
|
|
|
|
static const key* lookup_key(const char* s, size_t len);
|
|
|
|
|
|
|
|
bool set_option(JSON_TYPE t, JSON_VAL* v);
|
|
|
|
bool set_option_flag(JSON_TYPE t, JSON_VAL* v, const key* option_key, DirectiveSet* set);
|
|
|
|
|
|
|
|
CompilerDirectives* current_directive;
|
|
|
|
DirectiveSet* current_directiveset;
|
|
|
|
|
|
|
|
void push_tmp(CompilerDirectives* dir);
|
2015-12-16 15:38:28 +01:00
|
|
|
void clean_tmp();
|
2015-10-20 18:07:28 +02:00
|
|
|
CompilerDirectives* pop_tmp();
|
|
|
|
CompilerDirectives* _tmp_top; // temporary storage for dirs while parsing
|
2015-12-16 15:38:28 +01:00
|
|
|
int _tmp_depth; // Number of directives that has been parsed but not installed.
|
2015-10-20 18:07:28 +02:00
|
|
|
|
|
|
|
static uint mask(keytype kt);
|
|
|
|
};
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_COMPILER_DIRECTIVESPARSER_HPP
|