X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/6574576cfb6e5039e8a21714e8d9bf482ae7c32f..d3ae5af6ec7dbcfa2c7dce1a175e35934b85b274:/tests/types.at diff --git a/tests/types.at b/tests/types.at index b0c3a364..6275903c 100644 --- a/tests/types.at +++ b/tests/types.at @@ -26,7 +26,7 @@ AT_SETUP([[%union vs. %define api.value.type]]) AT_DATA([[input.y]], [[%union { int ival; } -%define api.value.type "%union" +%define api.value.type union-directive %% exp: %empty; ]]) @@ -37,6 +37,26 @@ AT_BISON_CHECK([[input.y]], [[1]], [[]], AT_CLEANUP +## ---------------------------------------- ## +## %yacc vs. %define api.value.type union. ## +## ---------------------------------------- ## + +AT_SETUP([[%yacc vs. %define api.value.type union]]) + +AT_DATA([[input.y]], +[[%yacc +%define api.value.type union +%% +exp: %empty; +]]) + +AT_BISON_CHECK([[input.y]], [[1]], [[]], +[[input.y:2.9-22: error: '%yacc' and '%define api.value.type "union"' cannot be used together +]]) + +AT_CLEANUP + + ## ---------------- ## ## api.value.type. ## ## ---------------- ## @@ -53,7 +73,7 @@ m4_pushdef([AT_TEST], [ AT_SETUP([$1]) AT_KEYWORDS([api.value.type]) -AT_BISON_OPTION_PUSHDEFS([$1 $2]) +AT_BISON_OPTION_PUSHDEFS([%debug $1 $2]) AT_DATA_GRAMMAR([test.y], [[%debug @@ -88,16 +108,25 @@ AT_CLEANUP m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], [# A built-in type. AT_TEST([%skeleton "]b4_skel[" - %define api.value.type double], + %define api.value.type {double}], [], ['1' '2' { printf ("%2.1f\n", $1 + $2); }], ["12"], [AT_VAL = (res - '0') / 10.0], [0.3]) + # A typedef which looks like a Bison keyword, but it's using braces. + AT_TEST([%skeleton "]b4_skel[" + %define api.value.type {variant}], + [%code requires { typedef double variant; }], + ['1' '2' { printf ("%2.1f\n", $1 + $2); }], + ["12"], + [AT_VAL = (res - '0') / 10.0], + [0.3]) + # A user defined struct. AT_TEST([%skeleton "]b4_skel[" - %define api.value.type "struct foo"], + %define api.value.type {struct foo}], [%code requires { struct foo { float fval; int ival; }; }], ['1' '2' { printf ("%d %2.1f\n", $1.ival + $2.ival, $1.fval + $2.fval); }], @@ -106,9 +135,39 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], AT_VAL.fval = (res - '0') / 10.f], [30 0.3]) + # A user defined struct that uses pointers. + AT_TEST([%skeleton "]b4_skel[" + %define api.value.type {struct bar}], + [%code requires + { + struct u + { + int ival; + }; + struct bar + { + struct u *up; + }; + } + %token ival> '1' '2' + %printer { ]AT_SKEL_CC_IF([[yyoutput << $$]], + [[fprintf (yyo, "%d", $$)]])[; } ival> + ], + ['1' '2' + { + printf ("%d %d\n", $1, $ival>2); + free ($1); + free ($2); + }], + ["12"], + [AT_VAL.up = (struct u *) malloc (sizeof *AT_VAL.up); + assert (AT_VAL.up); + AT_VAL.up->ival = res - '0';], + [1 2]) + # A user defined union. AT_TEST([%skeleton "]b4_skel[" - %define api.value.type "union foo"], + %define api.value.type {union foo}], [%code requires { union foo { float fval; int ival; }; }], ['1' '2' { printf ("%d %2.1f\n", $1.ival, $2.fval); }], ["12"],