Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/preproc.y | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index f9047c9f..008d01e7 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -588,6 +588,11 @@ expr $$ = preproc_parse_integer($1); vkd3d_free($1); } + | T_IDENTIFIER + { + $$ = 0; + vkd3d_free($1); + } | T_DEFINED T_IDENTIFIER { $$ = !!preproc_find_macro(ctx, $2);
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/preproc.l | 2 +- libs/vkd3d-shader/preproc.y | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 95b043ed..011f8dbb 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -157,7 +157,7 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* }
<INITIAL>{WS}+ {} -<INITIAL>[()[]{},] {return yytext[0];} +<INITIAL>[-()[]{},+!] {return yytext[0];} <INITIAL>. {return T_TEXT;}
%% diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 008d01e7..51df5d40 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -333,7 +333,8 @@ static void free_parse_arg_names(struct parse_arg_names *args) %token T_CONCAT "##" %token T_DEFINED "defined"
-%type <integer> expr +%type <integer> primary_expr +%type <integer> unary_expr %type <string> body_token %type <const_string> body_token_const %type <string_buffer> body_text @@ -426,6 +427,18 @@ body_token_const { $$ = ","; } + | '+' + { + $$ = "+"; + } + | '-' + { + $$ = "-"; + } + | '!' + { + $$ = "!"; + } | T_CONCAT { $$ = "##"; @@ -467,7 +480,7 @@ directive } vkd3d_free($2); } - | T_IF expr T_NEWLINE + | T_IF unary_expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT; @@ -482,7 +495,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); } - | T_ELIF expr T_NEWLINE + | T_ELIF unary_expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx);
@@ -582,7 +595,7 @@ directive vkd3d_free($2); }
-expr +primary_expr : T_INTEGER { $$ = preproc_parse_integer($1); @@ -603,3 +616,18 @@ expr $$ = !!preproc_find_macro(ctx, $3); vkd3d_free($3); } + +unary_expr + : primary_expr + | '+' unary_expr + { + $$ = $2; + } + | '-' unary_expr + { + $$ = -$2; + } + | '!' unary_expr + { + $$ = !$2; + }
On Mon, Jan 18, 2021 at 10:17 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/preproc.l | 2 +- libs/vkd3d-shader/preproc.y | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-)
I'm going to be a PITA and complain about patch subjects, specifically for this and the following patches. The current subject is okay for now, but will more likely than not clash with the same patch for the compiler proper. Perhaps just add a "in the preprocessor" suffix?
On 1/19/21 4:23 AM, Matteo Bruni wrote:
On Mon, Jan 18, 2021 at 10:17 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/preproc.l | 2 +- libs/vkd3d-shader/preproc.y | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-)
I'm going to be a PITA and complain about patch subjects, specifically for this and the following patches. The current subject is okay for now, but will more likely than not clash with the same patch for the compiler proper. Perhaps just add a "in the preprocessor" suffix?
Yeah, that's a fair point; I'll resend this series.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/preproc.l | 2 +- libs/vkd3d-shader/preproc.y | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 011f8dbb..a522b7c8 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -157,7 +157,7 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* }
<INITIAL>{WS}+ {} -<INITIAL>[-()[]{},+!] {return yytext[0];} +<INITIAL>[-()[]{},+!*/] {return yytext[0];} <INITIAL>. {return T_TEXT;}
%% diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 51df5d40..1060e9d7 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -335,6 +335,7 @@ static void free_parse_arg_names(struct parse_arg_names *args)
%type <integer> primary_expr %type <integer> unary_expr +%type <integer> mul_expr %type <string> body_token %type <const_string> body_token_const %type <string_buffer> body_text @@ -439,6 +440,14 @@ body_token_const { $$ = "!"; } + | '*' + { + $$ = "*"; + } + | '/' + { + $$ = "/"; + } | T_CONCAT { $$ = "##"; @@ -480,7 +489,7 @@ directive } vkd3d_free($2); } - | T_IF unary_expr T_NEWLINE + | T_IF mul_expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT; @@ -495,7 +504,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); } - | T_ELIF unary_expr T_NEWLINE + | T_ELIF mul_expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx);
@@ -631,3 +640,14 @@ unary_expr { $$ = !$2; } + +mul_expr + : unary_expr + | mul_expr '*' unary_expr + { + $$ = $1 * $3; + } + | mul_expr '/' unary_expr + { + $$ = $1 / $3; + }
On Mon, Jan 18, 2021 at 10:34 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/preproc.l | 2 +- libs/vkd3d-shader/preproc.y | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 011f8dbb..a522b7c8 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -157,7 +157,7 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* }
<INITIAL>{WS}+ {} -<INITIAL>[-()[]{},+!] {return yytext[0];} +<INITIAL>[-()[]{},+!*/] {return yytext[0];} <INITIAL>. {return T_TEXT;}
%% diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 51df5d40..1060e9d7 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -335,6 +335,7 @@ static void free_parse_arg_names(struct parse_arg_names *args)
%type <integer> primary_expr %type <integer> unary_expr +%type <integer> mul_expr %type <string> body_token %type <const_string> body_token_const %type <string_buffer> body_text @@ -439,6 +440,14 @@ body_token_const { $$ = "!"; }
- | '*'
{
$$ = "*";
}
- | '/'
{
$$ = "/";
| T_CONCAT { $$ = "##";}
@@ -480,7 +489,7 @@ directive } vkd3d_free($2); }
- | T_IF unary_expr T_NEWLINE
- | T_IF mul_expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT;
@@ -495,7 +504,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); }
- | T_ELIF unary_expr T_NEWLINE
- | T_ELIF mul_expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx);
@@ -631,3 +640,14 @@ unary_expr { $$ = !$2; }
+mul_expr
- : unary_expr
- | mul_expr '*' unary_expr
{
$$ = $1 * $3;
}
- | mul_expr '/' unary_expr
{
$$ = $1 / $3;
}
I don't know that we care but notice that e.g. "#if 1 / 0" causes a floating point exception.
On 1/19/21 4:24 AM, Matteo Bruni wrote:
On Mon, Jan 18, 2021 at 10:34 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/preproc.l | 2 +- libs/vkd3d-shader/preproc.y | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 011f8dbb..a522b7c8 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -157,7 +157,7 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* }
<INITIAL>{WS}+ {} -<INITIAL>[-()[]{},+!] {return yytext[0];} +<INITIAL>[-()[]{},+!*/] {return yytext[0];} <INITIAL>. {return T_TEXT;}
%% diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 51df5d40..1060e9d7 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -335,6 +335,7 @@ static void free_parse_arg_names(struct parse_arg_names *args)
%type <integer> primary_expr %type <integer> unary_expr +%type <integer> mul_expr %type <string> body_token %type <const_string> body_token_const %type <string_buffer> body_text @@ -439,6 +440,14 @@ body_token_const { $$ = "!"; }
- | '*'
{
$$ = "*";
}
- | '/'
{
$$ = "/";
| T_CONCAT { $$ = "##";}
@@ -480,7 +489,7 @@ directive } vkd3d_free($2); }
- | T_IF unary_expr T_NEWLINE
- | T_IF mul_expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT;
@@ -495,7 +504,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); }
- | T_ELIF unary_expr T_NEWLINE
- | T_ELIF mul_expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx);
@@ -631,3 +640,14 @@ unary_expr { $$ = !$2; }
+mul_expr
- : unary_expr
- | mul_expr '*' unary_expr
{
$$ = $1 * $3;
}
- | mul_expr '/' unary_expr
{
$$ = $1 / $3;
}
I don't know that we care but notice that e.g. "#if 1 / 0" causes a floating point exception.
Yes, that probably shouldn't be allowed to crash the preprocessor, thanks for catching that.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/preproc.y | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 1060e9d7..ccf4ab63 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -336,6 +336,7 @@ static void free_parse_arg_names(struct parse_arg_names *args) %type <integer> primary_expr %type <integer> unary_expr %type <integer> mul_expr +%type <integer> add_expr %type <string> body_token %type <const_string> body_token_const %type <string_buffer> body_text @@ -489,7 +490,7 @@ directive } vkd3d_free($2); } - | T_IF mul_expr T_NEWLINE + | T_IF add_expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT; @@ -504,7 +505,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); } - | T_ELIF mul_expr T_NEWLINE + | T_ELIF add_expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx);
@@ -651,3 +652,14 @@ mul_expr { $$ = $1 / $3; } + +add_expr + : mul_expr + | add_expr '+' mul_expr + { + $$ = $1 + $3; + } + | add_expr '-' mul_expr + { + $$ = $1 - $3; + }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/preproc.l | 7 ++++-- libs/vkd3d-shader/preproc.y | 43 +++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index a522b7c8..6779a39e 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -78,6 +78,9 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* <INITIAL>{IDENTIFIER}/( {return T_IDENTIFIER_PAREN;} <INITIAL>{IDENTIFIER} {return T_IDENTIFIER;}
+<INITIAL>"<=" {return T_LE;} +<INITIAL>">=" {return T_GE;} + /* We have no use for floats, but shouldn't parse them as integers. */
<INITIAL>[0-9]*.[0-9]+([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} @@ -96,7 +99,7 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* <INITIAL>"--" {return T_TEXT;} <INITIAL>"<<"=? {return T_TEXT;} <INITIAL>">>"=? {return T_TEXT;} -<INITIAL>[-+*/%&|^=><!]= {return T_TEXT;} +<INITIAL>[-+*/%&|^=!]= {return T_TEXT;}
<INCLUDE>"[^"]*" {return T_STRING;} <INCLUDE><[^>]*> {return T_STRING;} @@ -157,7 +160,7 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* }
<INITIAL>{WS}+ {} -<INITIAL>[-()[]{},+!*/] {return yytext[0];} +<INITIAL>[-()[]{},+!*/<>] {return yytext[0];} <INITIAL>. {return T_TEXT;}
%% diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index ccf4ab63..92c15539 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -331,12 +331,16 @@ static void free_parse_arg_names(struct parse_arg_names *args) %token T_UNDEF "#undef"
%token T_CONCAT "##" + +%token T_LE "<=" +%token T_GE ">=" %token T_DEFINED "defined"
%type <integer> primary_expr %type <integer> unary_expr %type <integer> mul_expr %type <integer> add_expr +%type <integer> ineq_expr %type <string> body_token %type <const_string> body_token_const %type <string_buffer> body_text @@ -449,10 +453,26 @@ body_token_const { $$ = "/"; } + | '<' + { + $$ = "<"; + } + | '>' + { + $$ = ">"; + } | T_CONCAT { $$ = "##"; } + | T_LE + { + $$ = "<="; + } + | T_GE + { + $$ = ">="; + } | T_DEFINED { $$ = "defined"; @@ -490,7 +510,7 @@ directive } vkd3d_free($2); } - | T_IF add_expr T_NEWLINE + | T_IF ineq_expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT; @@ -505,7 +525,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); } - | T_ELIF add_expr T_NEWLINE + | T_ELIF ineq_expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx);
@@ -663,3 +683,22 @@ add_expr { $$ = $1 - $3; } + +ineq_expr + : add_expr + | ineq_expr '<' add_expr + { + $$ = $1 < $3; + } + | ineq_expr '>' add_expr + { + $$ = $1 > $3; + } + | ineq_expr T_LE add_expr + { + $$ = $1 <= $3; + } + | ineq_expr T_GE add_expr + { + $$ = $1 >= $3; + }