diff options
author | Haru <haru@dotalux.com> | 2020-06-01 04:08:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 04:08:28 +0200 |
commit | 36aff97b92f9f42f9bc59911b7d06110a8e9aed5 (patch) | |
tree | 69d20dc9137da111ecda664a896bbf0abbead02e /3rdparty/libconfig/extra | |
parent | b9f7d1439c84b64facaf7d2875adc29110c65cf4 (diff) | |
parent | c66d467fb5816734851b7de6b20537ce7a08c861 (diff) | |
download | hercules-36aff97b92f9f42f9bc59911b7d06110a8e9aed5.tar.gz hercules-36aff97b92f9f42f9bc59911b7d06110a8e9aed5.tar.bz2 hercules-36aff97b92f9f42f9bc59911b7d06110a8e9aed5.tar.xz hercules-36aff97b92f9f42f9bc59911b7d06110a8e9aed5.zip |
Merge pull request #2671 from Helianthella/binliteral
add support for binary and octal number literals
Diffstat (limited to '3rdparty/libconfig/extra')
-rw-r--r-- | 3rdparty/libconfig/extra/.gitignore | 2 | ||||
-rw-r--r-- | 3rdparty/libconfig/extra/gen/Makefile | 4 | ||||
-rw-r--r-- | 3rdparty/libconfig/extra/gen/clangwarnings.patch | 14 | ||||
-rw-r--r-- | 3rdparty/libconfig/extra/gen/grammar.y | 72 | ||||
-rw-r--r-- | 3rdparty/libconfig/extra/gen/scanner.l | 146 |
5 files changed, 181 insertions, 57 deletions
diff --git a/3rdparty/libconfig/extra/.gitignore b/3rdparty/libconfig/extra/.gitignore index 03f1609a0..abc0e5b2d 100644 --- a/3rdparty/libconfig/extra/.gitignore +++ b/3rdparty/libconfig/extra/.gitignore @@ -2,4 +2,6 @@ /config.status /gen/*.c /gen/*.h +/gen/*.orig +/gen/*.rej /autom4te.cache diff --git a/3rdparty/libconfig/extra/gen/Makefile b/3rdparty/libconfig/extra/gen/Makefile index 0b2e0655e..2e952e221 100644 --- a/3rdparty/libconfig/extra/gen/Makefile +++ b/3rdparty/libconfig/extra/gen/Makefile @@ -19,9 +19,9 @@ LEXCOMPILE = $(LEX) $(LFLAGS) $(AM_LFLAGS) YLWRAP = ../aux-build/ylwrap YACCCOMPILE = $(YACC) $(YFLAGS) $(AM_YFLAGS) LEX = flex -LEXLIB = -ll +LEXLIB = -lfl LEX_OUTPUT_ROOT = lex.yy -SHELL = /bin/sh +SHELL = /bin/bash YACC = bison -y YFLAGS = diff --git a/3rdparty/libconfig/extra/gen/clangwarnings.patch b/3rdparty/libconfig/extra/gen/clangwarnings.patch index 0270dfc44..ecae69c0e 100644 --- a/3rdparty/libconfig/extra/gen/clangwarnings.patch +++ b/3rdparty/libconfig/extra/gen/clangwarnings.patch @@ -10,7 +10,7 @@ index 3595578..26444f8 100644 - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg != NULL ? yymsg : "Deleting", yytype, yyvaluep, yylocationp); - + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YYUSE (yytype); diff --git a/scanner.c b/scanner.c @@ -22,15 +22,15 @@ index 60882db..8b8af33 100644 #include <errno.h> #include <stdlib.h> +#include <assert.h> - + /* end standard C headers. */ - + @@ -1702,6 +1703,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner) - libconfig_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); } - + + assert(YY_CURRENT_BUFFER != NULL); // Fixes compiler warning -Wnull-dereference on gcc-6 and -O3 + - libconfig_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); - libconfig_yy_load_buffer_state(yyscanner ); + yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner); + yy_load_buffer_state( yyscanner ); } diff --git a/3rdparty/libconfig/extra/gen/grammar.y b/3rdparty/libconfig/extra/gen/grammar.y index 5d9f02c2d..b02612435 100644 --- a/3rdparty/libconfig/extra/gen/grammar.y +++ b/3rdparty/libconfig/extra/gen/grammar.y @@ -90,8 +90,8 @@ void libconfig_yyerror(void *scanner, struct parse_context *ctx, char *sval; } -%token <ival> TOK_BOOLEAN TOK_INTEGER TOK_HEX -%token <llval> TOK_INTEGER64 TOK_HEX64 +%token <ival> TOK_BOOLEAN TOK_INTEGER TOK_HEX TOK_BIN TOK_OCT +%token <llval> TOK_INTEGER64 TOK_HEX64 TOK_BIN64 TOK_OCT64 %token <fval> TOK_FLOAT %token <sval> TOK_STRING TOK_NAME %token TOK_EQUALS TOK_NEWLINE TOK_ARRAY_START TOK_ARRAY_END TOK_LIST_START TOK_LIST_END TOK_COMMA TOK_GROUP_START TOK_GROUP_END TOK_SEMICOLON TOK_GARBAGE TOK_ERROR @@ -310,6 +310,74 @@ simple_value: config_setting_set_format(ctx->setting, CONFIG_FORMAT_HEX); } } + | TOK_BIN + { + if (IN_ARRAY() || IN_LIST()) { + struct config_setting_t *e = config_setting_set_int_elem(ctx->parent, -1, $1); + + if (e == NULL) { + libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type); + YYABORT; + } else { + config_setting_set_format(e, CONFIG_FORMAT_BIN); + CAPTURE_PARSE_POS(e); + } + } else { + config_setting_set_int(ctx->setting, $1); + config_setting_set_format(ctx->setting, CONFIG_FORMAT_BIN); + } + } + | TOK_BIN64 + { + if (IN_ARRAY() || IN_LIST()) { + struct config_setting_t *e = config_setting_set_int64_elem(ctx->parent, -1, $1); + + if (e == NULL) { + libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type); + YYABORT; + } else { + config_setting_set_format(e, CONFIG_FORMAT_BIN); + CAPTURE_PARSE_POS(e); + } + } else { + config_setting_set_int64(ctx->setting, $1); + config_setting_set_format(ctx->setting, CONFIG_FORMAT_BIN); + } + } + | TOK_OCT + { + if (IN_ARRAY() || IN_LIST()) { + struct config_setting_t *e = config_setting_set_int_elem(ctx->parent, -1, $1); + + if (e == NULL) { + libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type); + YYABORT; + } else { + config_setting_set_format(e, CONFIG_FORMAT_OCT); + CAPTURE_PARSE_POS(e); + } + } else { + config_setting_set_int(ctx->setting, $1); + config_setting_set_format(ctx->setting, CONFIG_FORMAT_OCT); + } + } + | TOK_OCT64 + { + if (IN_ARRAY() || IN_LIST()) { + struct config_setting_t *e = config_setting_set_int64_elem(ctx->parent, -1, $1); + + if (e == NULL) { + libconfig_yyerror(scanner, ctx, scan_ctx, err_array_elem_type); + YYABORT; + } else { + config_setting_set_format(e, CONFIG_FORMAT_OCT); + CAPTURE_PARSE_POS(e); + } + } else { + config_setting_set_int64(ctx->setting, $1); + config_setting_set_format(ctx->setting, CONFIG_FORMAT_OCT); + } + } | TOK_FLOAT { if(IN_ARRAY() || IN_LIST()) diff --git a/3rdparty/libconfig/extra/gen/scanner.l b/3rdparty/libconfig/extra/gen/scanner.l index f57e1c275..4a7e5a06d 100644 --- a/3rdparty/libconfig/extra/gen/scanner.l +++ b/3rdparty/libconfig/extra/gen/scanner.l @@ -50,38 +50,103 @@ #define YY_NO_INPUT // Suppress generation of useless input() function -static unsigned long long fromhex(const char *s) +/** + * converts a hexadecimal number literal to an ull integer + * + * @param p - a pointer to the hexacimal expression to parse + * @returns the resulting unsigned long long integer + */ +static unsigned long long fromhex(const char *p) { -#ifdef __MINGW32__ + unsigned long long val = 0; + + if (*p != '0' || (p[1] != 'x' && p[1] != 'X')) { + return 0; + } - /* MinGW's strtoull() seems to be broken; it only returns the lower - * 32 bits... - */ + for (p += 2; isxdigit(*p) || *p == '_'; ++p) { + if (*p != '_') { + val <<= 4; + val |= ((*p < 'A') ? (*p & 0xF) : (9 + (*p & 0x7))); + } + } - const char *p = s; + return val; +} + +/** + * converts a binary number literal to an ull integer + * + * @param p - a pointer to the hexacimal expression to parse + * @returns the resulting unsigned long long integer + */ +static unsigned long long frombin (const char *p) +{ unsigned long long val = 0; - if(*p != '0') - return(0); + if (*p != '0' || (p[1] != 'b' && p[1] != 'B')) { + return 0; + } + + for (p += 2; *p == '0' || *p == '1' || *p == '_'; ++p) { + if (*p != '_') { + val <<= 1; + val |= (*p == '0') ? 0 : 1; + } + } - ++p; + return val; +} + +/** + * converts an octal number literal to an ull integer + * + * @param p - a pointer to the hexacimal expression to parse + * @returns the resulting unsigned long long integer + */ +static unsigned long long fromoct (const char *p) +{ + unsigned long long val = 0; - if(*p != 'x' && *p != 'X') - return(0); + if (*p != '0' || (p[1] != 'o' && p[1] != 'O')) { + return 0; + } - for(++p; isxdigit(*p); ++p) - { - val <<= 4; - val |= ((*p < 'A') ? (*p & 0xF) : (9 + (*p & 0x7))); + for (p += 2; (*p >= '0' && *p <= '7') || *p == '_'; ++p) { + if (*p != '_') { + val <<= 3; + val |= (*p & 0xF); + } } - return(val); + return val; +} -#else /* ! __MINGW32__ */ +/** + * converts a decimal number literal to a ll integer + * + * @param p - a pointer to the hexacimal expression to parse + * @returns the resulting signed long long integer + */ +static long long fromdec (const char *p) +{ + unsigned char is_neg = 0; - return(strtoull(s, NULL, 16)); + if (*p == '-') { + is_neg = 1; + p++; + } + + long long val = 0; + + for (; isdigit(*p) || *p == '_'; ++p) { + if (*p != '_') { + val *= 10; + val += (*p & 0xF); + } + } -#endif /* __MINGW32__ */ + return (is_neg == 1) ? -val : val; } %} @@ -89,10 +154,14 @@ static unsigned long long fromhex(const char *s) true [Tt][Rr][Uu][Ee] false [Ff][Aa][Ll][Ss][Ee] name [A-Za-z0-9\*][-A-Za-z0-9_\*.]* -integer [-+]?[0-9]+ -integer64 [-+]?[0-9]+L(L)? -hex 0[Xx][0-9A-Fa-f]+ -hex64 0[Xx][0-9A-Fa-f]+L(L)? +integer [-+]?[0-9_]+ +integer64 [-+]?[0-9_]+L(L)? +hex 0[Xx][0-9A-Fa-f_]+ +hex64 0[Xx][0-9A-Fa-f_]+L(L)? +bin 0[Bb][01_]+ +bin64 0[Bb][01_]+L(L)? +oct 0[Oo][0-7_]+ +oct64 0[Oo][0-7_]+L(L)? hexchar \\[Xx][0-9A-Fa-f]{2} float ([-+]?([0-9]*)?\.[0-9]*([eE][-+]?[0-9]+)?)|([-+]?([0-9]+)(\.[0-9]*)?[eE][-+]?[0-9]+) comment (#|\/\/).*$ @@ -173,29 +242,14 @@ include_open ^[ \t]*@include[ \t]+\" {true} { yylval->ival = 1; return(TOK_BOOLEAN); } {false} { yylval->ival = 0; return(TOK_BOOLEAN); } {float} { yylval->fval = atof(yytext); return(TOK_FLOAT); } -{integer} { - long long llval; - llval = atoll(yytext); - if((llval < INT_MIN) || (llval > INT_MAX)) - { - yylval->llval = llval; - return(TOK_INTEGER64); - } - else - { - yylval->ival = (int)llval; - return(TOK_INTEGER); - } - } -{integer64} { yylval->llval = atoll(yytext); return(TOK_INTEGER64); } -{hex} { - unsigned long ulval = strtoul(yytext, NULL, 16); - if (ulval > INT32_MAX) - ulval &= INT32_MAX; - yylval->ival = (int)ulval; - return(TOK_HEX); - } -{hex64} { yylval->llval = fromhex(yytext); return(TOK_HEX64); } +{integer} { yylval->ival = (int)fromdec(yytext); return TOK_INTEGER; } +{integer64} { yylval->llval = fromdec(yytext); return TOK_INTEGER64; } +{hex} { yylval->ival = (int)fromhex(yytext); return TOK_HEX; } +{hex64} { yylval->llval = fromhex(yytext); return TOK_HEX64; } +{bin} { yylval->ival = (int)frombin(yytext); return TOK_BIN; } +{bin64} { yylval->llval = frombin(yytext); return TOK_BIN64; } +{oct} { yylval->ival = (int)fromoct(yytext); return TOK_OCT; } +{oct64} { yylval->llval = fromoct(yytext); return TOK_OCT64; } {name} { yylval->sval = yytext; return(TOK_NAME); } \[ { return(TOK_ARRAY_START); } \] { return(TOK_ARRAY_END); } |