From 9ffbdd3738b02a0220c8d9156babf20e0c5ff7d4 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 8 Jan 2023 21:23:16 +0000 Subject: Revert "scanner: don't accept invalid symbols in binary expressions" This reverts commit b37f24b7e27a77c398f41cc331608aff806f0d42. --- giscanner/scannerparser.y | 58 ++++++++++++++-------- giscanner/sourcescanner.c | 15 ------ giscanner/sourcescanner.h | 4 -- .../Regress.BAD_EXPR_CONSTANT.page | 14 ++++++ .../Regress.BAD_EXPR_CONSTANT.page | 14 ++++++ .../Regress.BAD_EXPR_CONSTANT.page | 14 ++++++ tests/scanner/Regress-1.0-expected.gir | 6 +++ 7 files changed, 84 insertions(+), 41 deletions(-) create mode 100644 tests/scanner/Regress-1.0-C-expected/Regress.BAD_EXPR_CONSTANT.page create mode 100644 tests/scanner/Regress-1.0-Gjs-expected/Regress.BAD_EXPR_CONSTANT.page create mode 100644 tests/scanner/Regress-1.0-Python-expected/Regress.BAD_EXPR_CONSTANT.page diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y index 26c9eba7..52fc1996 100644 --- a/giscanner/scannerparser.y +++ b/giscanner/scannerparser.y @@ -582,25 +582,24 @@ multiplicative_expression : cast_expression | multiplicative_expression '*' cast_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int * $3->const_int; } | multiplicative_expression '/' cast_expression { + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; if ($3->const_int != 0) { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); $$->const_int = $1->const_int / $3->const_int; - } else { - $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, scanner->current_file, lineno); } } | multiplicative_expression '%' cast_expression { + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; if ($3->const_int != 0) { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); $$->const_int = $1->const_int % $3->const_int; - } else { - $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, scanner->current_file, lineno); } } ; @@ -609,12 +608,14 @@ additive_expression : multiplicative_expression | additive_expression '+' multiplicative_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int + $3->const_int; } | additive_expression '-' multiplicative_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int - $3->const_int; } ; @@ -623,7 +624,8 @@ shift_expression : additive_expression | shift_expression SL additive_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int << $3->const_int; /* assume this is a bitfield/flags declaration @@ -634,7 +636,8 @@ shift_expression } | shift_expression SR additive_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int >> $3->const_int; } ; @@ -643,22 +646,26 @@ relational_expression : shift_expression | relational_expression '<' shift_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int < $3->const_int; } | relational_expression '>' shift_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int > $3->const_int; } | relational_expression LTEQ shift_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int <= $3->const_int; } | relational_expression GTEQ shift_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int >= $3->const_int; } ; @@ -667,12 +674,14 @@ equality_expression : relational_expression | equality_expression EQ relational_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int == $3->const_int; } | equality_expression NOTEQ relational_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int != $3->const_int; } ; @@ -681,7 +690,8 @@ and_expression : equality_expression | and_expression '&' equality_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int & $3->const_int; } ; @@ -690,7 +700,8 @@ exclusive_or_expression : and_expression | exclusive_or_expression '^' and_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int ^ $3->const_int; } ; @@ -699,7 +710,8 @@ inclusive_or_expression : exclusive_or_expression | inclusive_or_expression '|' exclusive_or_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = $1->const_int | $3->const_int; } ; @@ -708,7 +720,8 @@ logical_and_expression : inclusive_or_expression | logical_and_expression ANDAND inclusive_or_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = gi_source_symbol_get_const_boolean ($1) && gi_source_symbol_get_const_boolean ($3); @@ -719,7 +732,8 @@ logical_or_expression : logical_and_expression | logical_or_expression OROR logical_and_expression { - $$ = gi_source_symbol_const_binary ($1, $3, scanner->current_file, lineno); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_int_set = TRUE; $$->const_int = gi_source_symbol_get_const_boolean ($1) || gi_source_symbol_get_const_boolean ($3); diff --git a/giscanner/sourcescanner.c b/giscanner/sourcescanner.c index 80c61a27..27f82f77 100644 --- a/giscanner/sourcescanner.c +++ b/giscanner/sourcescanner.c @@ -73,21 +73,6 @@ gi_source_symbol_copy (GISourceSymbol * symbol) return new_symbol; } -GISourceSymbol * -gi_source_symbol_const_binary (GISourceSymbol * s1, GISourceSymbol * s2, GFile *file, int line) -{ - GISourceSymbol *new_symbol; - - if (s1->const_int_set && s2->const_int_set) { - new_symbol = gi_source_symbol_new (CSYMBOL_TYPE_CONST, file, line); - new_symbol->const_int_set = TRUE; - } else { - new_symbol = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, file, line); - } - - return new_symbol; -} - GISourceSymbol * gi_source_symbol_ref (GISourceSymbol * symbol) { diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h index eb2d312f..40c5fc96 100644 --- a/giscanner/sourcescanner.h +++ b/giscanner/sourcescanner.h @@ -172,10 +172,6 @@ gboolean gi_source_symbol_get_const_boolean (GISourceSymbol *symb GISourceSymbol * gi_source_symbol_ref (GISourceSymbol *symbol); void gi_source_symbol_unref (GISourceSymbol *symbol); GISourceSymbol * gi_source_symbol_copy (GISourceSymbol *symbol); -GISourceSymbol * gi_source_symbol_const_binary (GISourceSymbol *s1, - GISourceSymbol *s2, - GFile *file, - int line); /* Private */ void gi_source_scanner_add_symbol (GISourceScanner *scanner, diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.BAD_EXPR_CONSTANT.page b/tests/scanner/Regress-1.0-C-expected/Regress.BAD_EXPR_CONSTANT.page new file mode 100644 index 00000000..bc8190a8 --- /dev/null +++ b/tests/scanner/Regress-1.0-C-expected/Regress.BAD_EXPR_CONSTANT.page @@ -0,0 +1,14 @@ + + + + + + Regress.BAD_EXPR_CONSTANT + + + diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.BAD_EXPR_CONSTANT.page b/tests/scanner/Regress-1.0-Gjs-expected/Regress.BAD_EXPR_CONSTANT.page new file mode 100644 index 00000000..bc8190a8 --- /dev/null +++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.BAD_EXPR_CONSTANT.page @@ -0,0 +1,14 @@ + + + + + + Regress.BAD_EXPR_CONSTANT + + + diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.BAD_EXPR_CONSTANT.page b/tests/scanner/Regress-1.0-Python-expected/Regress.BAD_EXPR_CONSTANT.page new file mode 100644 index 00000000..bc8190a8 --- /dev/null +++ b/tests/scanner/Regress-1.0-Python-expected/Regress.BAD_EXPR_CONSTANT.page @@ -0,0 +1,14 @@ + + + + + + Regress.BAD_EXPR_CONSTANT + + + diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 1d7aeb73..ecfc5cb6 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -1250,6 +1250,12 @@ it says it's pointer but it's actually a string. + + + + -- cgit v1.2.1