summaryrefslogtreecommitdiff
path: root/test/grammar.y
diff options
context:
space:
mode:
Diffstat (limited to 'test/grammar.y')
-rw-r--r--test/grammar.y37
1 files changed, 19 insertions, 18 deletions
diff --git a/test/grammar.y b/test/grammar.y
index 6755522683701..c4c8fd5809309 100644
--- a/test/grammar.y
+++ b/test/grammar.y
@@ -1,4 +1,4 @@
-/* $Id: grammar.y,v 1.5 2012/01/15 20:00:59 tom Exp $
+/* $Id: grammar.y,v 1.7 2020/03/30 23:55:49 tom Exp $
*
* yacc grammar for C function prototype generator
* This was derived from the grammar in Appendix A of
@@ -94,6 +94,7 @@ static void yyerror(const char *s);
/* #include "cproto.h" */
#define MAX_TEXT_SIZE 1024
+#define TEXT_LEN (MAX_TEXT_SIZE / 2 - 3)
/* Prototype styles */
#if OPT_LINTLIBRARY
@@ -679,19 +680,19 @@ struct_or_union_specifier
{
char *s;
if ((s = implied_typedef()) == 0)
- (void)sprintf(s = buf, "%s %s", $1.text, $2.text);
+ (void)sprintf(s = buf, "%.*s %.*s", TEXT_LEN, $1.text, TEXT_LEN, $2.text);
new_decl_spec(&$$, s, $1.begin, DS_NONE);
}
| struct_or_union braces
{
char *s;
if ((s = implied_typedef()) == 0)
- (void)sprintf(s = buf, "%s {}", $1.text);
+ (void)sprintf(s = buf, "%.*s {}", TEXT_LEN, $1.text);
new_decl_spec(&$$, s, $1.begin, DS_NONE);
}
| struct_or_union any_id
{
- (void)sprintf(buf, "%s %s", $1.text, $2.text);
+ (void)sprintf(buf, "%.*s %.*s", TEXT_LEN, $1.text, TEXT_LEN, $2.text);
new_decl_spec(&$$, buf, $1.begin, DS_NONE);
}
;
@@ -744,19 +745,19 @@ enum_specifier
{
char *s;
if ((s = implied_typedef()) == 0)
- (void)sprintf(s = buf, "enum %s", $2.text);
+ (void)sprintf(s = buf, "enum %.*s", TEXT_LEN, $2.text);
new_decl_spec(&$$, s, $1.begin, DS_NONE);
}
| enumeration braces
{
char *s;
if ((s = implied_typedef()) == 0)
- (void)sprintf(s = buf, "%s {}", $1.text);
+ (void)sprintf(s = buf, "%.*s {}", TEXT_LEN, $1.text);
new_decl_spec(&$$, s, $1.begin, DS_NONE);
}
| enumeration any_id
{
- (void)sprintf(buf, "enum %s", $2.text);
+ (void)sprintf(buf, "enum %.*s", TEXT_LEN, $2.text);
new_decl_spec(&$$, buf, $1.begin, DS_NONE);
}
;
@@ -778,7 +779,7 @@ declarator
: pointer direct_declarator
{
$$ = $2;
- (void)sprintf(buf, "%s%s", $1.text, $$->text);
+ (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $1.text, TEXT_LEN, $$->text);
free($$->text);
$$->text = xstrdup(buf);
$$->begin = $1.begin;
@@ -795,7 +796,7 @@ direct_declarator
| '(' declarator ')'
{
$$ = $2;
- (void)sprintf(buf, "(%s)", $$->text);
+ (void)sprintf(buf, "(%.*s)", TEXT_LEN, $$->text);
free($$->text);
$$->text = xstrdup(buf);
$$->begin = $1.begin;
@@ -803,7 +804,7 @@ direct_declarator
| direct_declarator T_BRACKETS
{
$$ = $1;
- (void)sprintf(buf, "%s%s", $$->text, $2.text);
+ (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $$->text, TEXT_LEN, $2.text);
free($$->text);
$$->text = xstrdup(buf);
}
@@ -828,12 +829,12 @@ direct_declarator
pointer
: '*' opt_type_qualifiers
{
- (void)sprintf($$.text, "*%s", $2.text);
+ (void)sprintf($$.text, "*%.*s", TEXT_LEN, $2.text);
$$.begin = $1.begin;
}
| '*' opt_type_qualifiers pointer
{
- (void)sprintf($$.text, "*%s%s", $2.text, $3.text);
+ (void)sprintf($$.text, "*%.*s%.*s", TEXT_LEN, $2.text, TEXT_LEN, $3.text);
$$.begin = $1.begin;
}
;
@@ -856,7 +857,7 @@ type_qualifier_list
}
| type_qualifier_list type_qualifier
{
- (void)sprintf($$.text, "%s%s ", $1.text, $2.text);
+ (void)sprintf($$.text, "%.*s%.*s ", TEXT_LEN, $1.text, TEXT_LEN, $2.text);
$$.begin = $1.begin;
free($2.text);
}
@@ -931,7 +932,7 @@ identifier_or_ref
$$ = $2;
} else
#endif
- (void)sprintf($$.text, "&%s", $2.text);
+ (void)sprintf($$.text, "&%.*s", TEXT_LEN, $2.text);
$$.begin = $1.begin;
}
;
@@ -944,7 +945,7 @@ abs_declarator
| pointer direct_abs_declarator
{
$$ = $2;
- (void)sprintf(buf, "%s%s", $1.text, $$->text);
+ (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $1.text, TEXT_LEN, $$->text);
free($$->text);
$$->text = xstrdup(buf);
$$->begin = $1.begin;
@@ -956,7 +957,7 @@ direct_abs_declarator
: '(' abs_declarator ')'
{
$$ = $2;
- (void)sprintf(buf, "(%s)", $$->text);
+ (void)sprintf(buf, "(%.*s)", TEXT_LEN, $$->text);
free($$->text);
$$->text = xstrdup(buf);
$$->begin = $1.begin;
@@ -964,7 +965,7 @@ direct_abs_declarator
| direct_abs_declarator T_BRACKETS
{
$$ = $1;
- (void)sprintf(buf, "%s%s", $$->text, $2.text);
+ (void)sprintf(buf, "%.*s%.*s", TEXT_LEN, $$->text, TEXT_LEN, $2.text);
free($$->text);
$$->text = xstrdup(buf);
}
@@ -1027,7 +1028,7 @@ extern char *yytext;
extern FILE *yyin, *yyout;
static int curly; /* number of curly brace nesting levels */
-static int ly_count; /* number of occurances of %% */
+static int ly_count; /* number of occurrences of %% */
static int inc_depth; /* include nesting level */
static SymbolTable *included_files; /* files already included */
static int yy_start = 0; /* start state number */