summaryrefslogtreecommitdiff
path: root/src/glsl/glcpp/glcpp-parse.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl/glcpp/glcpp-parse.y')
-rw-r--r--src/glsl/glcpp/glcpp-parse.y151
1 files changed, 76 insertions, 75 deletions
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index b449eb288b..65112c94d9 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -32,10 +32,6 @@
#include "main/core.h" /* for struct gl_extensions */
#include "main/mtypes.h" /* for gl_api enum */
-#define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
-#define glcpp_printf(stream, fmt, args, ...) \
- stream = talloc_asprintf_append(stream, fmt, args)
-
static void
yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
@@ -79,7 +75,7 @@ _argument_list_length (argument_list_t *list);
static token_list_t *
_argument_list_member_at (argument_list_t *list, int index);
-/* Note: This function talloc_steal()s the str pointer. */
+/* Note: This function ralloc_steal()s the str pointer. */
static token_t *
_token_create_str (void *ctx, int type, char *str);
@@ -89,7 +85,7 @@ _token_create_ival (void *ctx, int type, int ival);
static token_list_t *
_token_list_create (void *ctx);
-/* Note: This function calls talloc_steal on token. */
+/* Note: This function calls ralloc_steal on token. */
static void
_token_list_append (token_list_t *list, token_t *token);
@@ -189,12 +185,12 @@ input:
line:
control_line {
- glcpp_print(parser->output, "\n");
+ ralloc_strcat (&parser->output, "\n");
}
| text_line {
_glcpp_parser_print_expanded_token_list (parser, $1);
- glcpp_print(parser->output, "\n");
- talloc_free ($1);
+ ralloc_strcat (&parser->output, "\n");
+ ralloc_free ($1);
}
| expanded_line
| HASH non_directive
@@ -223,9 +219,9 @@ control_line:
macro_t *macro = hash_table_find (parser->defines, $2);
if (macro) {
hash_table_remove (parser->defines, $2);
- talloc_free (macro);
+ ralloc_free (macro);
}
- talloc_free ($2);
+ ralloc_free ($2);
}
| HASH_IF conditional_tokens NEWLINE {
/* Be careful to only evaluate the 'if' expression if
@@ -258,12 +254,12 @@ control_line:
}
| HASH_IFDEF IDENTIFIER junk NEWLINE {
macro_t *macro = hash_table_find (parser->defines, $2);
- talloc_free ($2);
+ ralloc_free ($2);
_glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
}
| HASH_IFNDEF IDENTIFIER junk NEWLINE {
macro_t *macro = hash_table_find (parser->defines, $2);
- talloc_free ($2);
+ ralloc_free ($2);
_glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL);
}
| HASH_ELIF conditional_tokens NEWLINE {
@@ -310,7 +306,7 @@ control_line:
macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
if (macro) {
hash_table_remove (parser->defines, "__VERSION__");
- talloc_free (macro);
+ ralloc_free (macro);
}
add_builtin_define (parser, "__VERSION__", $2);
@@ -325,7 +321,7 @@ control_line:
if ($2 >= 130 || $2 == 100)
add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
- glcpp_printf(parser->output, "#version %" PRIiMAX, $2);
+ ralloc_asprintf_append (&parser->output, "#version %" PRIiMAX, $2);
}
| HASH NEWLINE
;
@@ -426,12 +422,12 @@ identifier_list:
IDENTIFIER {
$$ = _string_list_create (parser);
_string_list_append_item ($$, $1);
- talloc_steal ($$, $1);
+ ralloc_steal ($$, $1);
}
| identifier_list ',' IDENTIFIER {
$$ = $1;
_string_list_append_item ($$, $3);
- talloc_steal ($$, $3);
+ ralloc_steal ($$, $3);
}
;
@@ -559,7 +555,7 @@ _string_list_create (void *ctx)
{
string_list_t *list;
- list = talloc (ctx, string_list_t);
+ list = ralloc (ctx, string_list_t);
list->head = NULL;
list->tail = NULL;
@@ -571,8 +567,8 @@ _string_list_append_item (string_list_t *list, const char *str)
{
string_node_t *node;
- node = talloc (list, string_node_t);
- node->str = talloc_strdup (node, str);
+ node = ralloc (list, string_node_t);
+ node->str = ralloc_strdup (node, str);
node->next = NULL;
@@ -650,7 +646,7 @@ _argument_list_create (void *ctx)
{
argument_list_t *list;
- list = talloc (ctx, argument_list_t);
+ list = ralloc (ctx, argument_list_t);
list->head = NULL;
list->tail = NULL;
@@ -662,7 +658,7 @@ _argument_list_append (argument_list_t *list, token_list_t *argument)
{
argument_node_t *node;
- node = talloc (list, argument_node_t);
+ node = ralloc (list, argument_node_t);
node->argument = argument;
node->next = NULL;
@@ -713,15 +709,17 @@ _argument_list_member_at (argument_list_t *list, int index)
return NULL;
}
-/* Note: This function talloc_steal()s the str pointer. */
+/* Note: This function ralloc_steal()s the str pointer. */
token_t *
_token_create_str (void *ctx, int type, char *str)
{
token_t *token;
- token = talloc (ctx, token_t);
+ token = ralloc (ctx, token_t);
token->type = type;
- token->value.str = talloc_steal (token, str);
+ token->value.str = str;
+
+ ralloc_steal (token, str);
return token;
}
@@ -731,7 +729,7 @@ _token_create_ival (void *ctx, int type, int ival)
{
token_t *token;
- token = talloc (ctx, token_t);
+ token = ralloc (ctx, token_t);
token->type = type;
token->value.ival = ival;
@@ -743,7 +741,7 @@ _token_list_create (void *ctx)
{
token_list_t *list;
- list = talloc (ctx, token_list_t);
+ list = ralloc (ctx, token_list_t);
list->head = NULL;
list->tail = NULL;
list->non_space_tail = NULL;
@@ -756,11 +754,12 @@ _token_list_append (token_list_t *list, token_t *token)
{
token_node_t *node;
- node = talloc (list, token_node_t);
- node->token = talloc_steal (list, token);
-
+ node = ralloc (list, token_node_t);
+ node->token = token;
node->next = NULL;
+ ralloc_steal (list, token);
+
if (list->head == NULL) {
list->head = node;
} else {
@@ -799,7 +798,7 @@ _token_list_copy (void *ctx, token_list_t *other)
copy = _token_list_create (ctx);
for (node = other->head; node; node = node->next) {
- token_t *new_token = talloc (copy, token_t);
+ token_t *new_token = ralloc (copy, token_t);
*new_token = *node->token;
_token_list_append (copy, new_token);
}
@@ -819,7 +818,7 @@ _token_list_trim_trailing_space (token_list_t *list)
while (tail) {
next = tail->next;
- talloc_free (tail);
+ ralloc_free (tail);
tail = next;
}
}
@@ -905,51 +904,51 @@ static void
_token_print (char **out, token_t *token)
{
if (token->type < 256) {
- glcpp_printf (*out, "%c", token->type);
+ ralloc_asprintf_append (out, "%c", token->type);
return;
}
switch (token->type) {
case INTEGER:
- glcpp_printf (*out, "%" PRIiMAX, token->value.ival);
+ ralloc_asprintf_append (out, "%" PRIiMAX, token->value.ival);
break;
case IDENTIFIER:
case INTEGER_STRING:
case OTHER:
- glcpp_print (*out, token->value.str);
+ ralloc_strcat (out, token->value.str);
break;
case SPACE:
- glcpp_print (*out, " ");
+ ralloc_strcat (out, " ");
break;
case LEFT_SHIFT:
- glcpp_print (*out, "<<");
+ ralloc_strcat (out, "<<");
break;
case RIGHT_SHIFT:
- glcpp_print (*out, ">>");
+ ralloc_strcat (out, ">>");
break;
case LESS_OR_EQUAL:
- glcpp_print (*out, "<=");
+ ralloc_strcat (out, "<=");
break;
case GREATER_OR_EQUAL:
- glcpp_print (*out, ">=");
+ ralloc_strcat (out, ">=");
break;
case EQUAL:
- glcpp_print (*out, "==");
+ ralloc_strcat (out, "==");
break;
case NOT_EQUAL:
- glcpp_print (*out, "!=");
+ ralloc_strcat (out, "!=");
break;
case AND:
- glcpp_print (*out, "&&");
+ ralloc_strcat (out, "&&");
break;
case OR:
- glcpp_print (*out, "||");
+ ralloc_strcat (out, "||");
break;
case PASTE:
- glcpp_print (*out, "##");
+ ralloc_strcat (out, "##");
break;
case COMMA_FINAL:
- glcpp_print (*out, ",");
+ ralloc_strcat (out, ",");
break;
case PLACEHOLDER:
/* Nothing to print. */
@@ -960,7 +959,7 @@ _token_print (char **out, token_t *token)
}
}
-/* Return a new token (talloc()ed off of 'token') formed by pasting
+/* Return a new token (ralloc()ed off of 'token') formed by pasting
* 'token' and 'other'. Note that this function may return 'token' or
* 'other' directly rather than allocating anything new.
*
@@ -1031,7 +1030,7 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
{
char *str;
- str = talloc_asprintf (token, "%s%s", token->value.str,
+ str = ralloc_asprintf (token, "%s%s", token->value.str,
other->value.str);
combined = _token_create_str (token, token->type, str);
combined->location = token->location;
@@ -1039,11 +1038,11 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
}
glcpp_error (&token->location, parser, "");
- glcpp_print (parser->info_log, "Pasting \"");
+ ralloc_strcat (&parser->info_log, "Pasting \"");
_token_print (&parser->info_log, token);
- glcpp_print (parser->info_log, "\" and \"");
+ ralloc_strcat (&parser->info_log, "\" and \"");
_token_print (&parser->info_log, other);
- glcpp_print (parser->info_log, "\" does not give a valid preprocessing token.\n");
+ ralloc_strcat (&parser->info_log, "\" does not give a valid preprocessing token.\n");
return token;
}
@@ -1085,7 +1084,7 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
glcpp_parser_t *parser;
int language_version;
- parser = talloc (NULL, glcpp_parser_t);
+ parser = ralloc (NULL, glcpp_parser_t);
glcpp_lex_init_extra (parser, &parser->scanner);
parser->defines = hash_table_ctor (32, hash_table_string_hash,
@@ -1102,8 +1101,8 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
parser->lex_from_list = NULL;
parser->lex_from_node = NULL;
- parser->output = talloc_strdup(parser, "");
- parser->info_log = talloc_strdup(parser, "");
+ parser->output = ralloc_strdup(parser, "");
+ parser->info_log = ralloc_strdup(parser, "");
parser->error = 0;
/* Add pre-defined macros. */
@@ -1145,7 +1144,7 @@ glcpp_parser_destroy (glcpp_parser_t *parser)
{
glcpp_lex_destroy (parser->scanner);
hash_table_dtor (parser->defines);
- talloc_free (parser);
+ ralloc_free (parser);
}
typedef enum function_status
@@ -1316,7 +1315,7 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
/* Replace a macro defined as empty with a SPACE token. */
if (macro->replacements == NULL) {
- talloc_free (arguments);
+ ralloc_free (arguments);
return _token_list_create_with_one_space (parser);
}
@@ -1472,7 +1471,7 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
token_list_t *expansion;
token_t *final;
- str = talloc_strdup (parser, token->value.str);
+ str = ralloc_strdup (parser, token->value.str);
final = _token_create_str (parser, OTHER, str);
expansion = _token_list_create (parser);
_token_list_append (expansion, final);
@@ -1508,8 +1507,8 @@ _active_list_push (active_list_t *list,
{
active_list_t *node;
- node = talloc (list, active_list_t);
- node->identifier = talloc_strdup (node, identifier);
+ node = ralloc (list, active_list_t);
+ node->identifier = ralloc_strdup (node, identifier);
node->marker = marker;
node->next = list;
@@ -1525,7 +1524,7 @@ _active_list_pop (active_list_t *list)
return NULL;
node = list->next;
- talloc_free (list);
+ ralloc_free (list);
return node;
}
@@ -1674,17 +1673,18 @@ _define_object_macro (glcpp_parser_t *parser,
if (loc != NULL)
_check_for_reserved_macro_name(parser, loc, identifier);
- macro = talloc (parser, macro_t);
+ macro = ralloc (parser, macro_t);
macro->is_function = 0;
macro->parameters = NULL;
- macro->identifier = talloc_strdup (macro, identifier);
- macro->replacements = talloc_steal (macro, replacements);
+ macro->identifier = ralloc_strdup (macro, identifier);
+ macro->replacements = replacements;
+ ralloc_steal (macro, replacements);
previous = hash_table_find (parser->defines, identifier);
if (previous) {
if (_macro_equal (macro, previous)) {
- talloc_free (macro);
+ ralloc_free (macro);
return;
}
glcpp_error (loc, parser, "Redefinition of macro %s\n",
@@ -1705,17 +1705,18 @@ _define_function_macro (glcpp_parser_t *parser,
_check_for_reserved_macro_name(parser, loc, identifier);
- macro = talloc (parser, macro_t);
+ macro = ralloc (parser, macro_t);
+ ralloc_steal (macro, parameters);
+ ralloc_steal (macro, replacements);
macro->is_function = 1;
- macro->parameters = talloc_steal (macro, parameters);
- macro->identifier = talloc_strdup (macro, identifier);
- macro->replacements = talloc_steal (macro, replacements);
-
+ macro->parameters = parameters;
+ macro->identifier = ralloc_strdup (macro, identifier);
+ macro->replacements = replacements;
previous = hash_table_find (parser->defines, identifier);
if (previous) {
if (_macro_equal (macro, previous)) {
- talloc_free (macro);
+ ralloc_free (macro);
return;
}
glcpp_error (loc, parser, "Redefinition of macro %s\n",
@@ -1791,7 +1792,7 @@ glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
node = parser->lex_from_node;
if (node == NULL) {
- talloc_free (parser->lex_from_list);
+ ralloc_free (parser->lex_from_list);
parser->lex_from_list = NULL;
return NEWLINE;
}
@@ -1820,13 +1821,13 @@ glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
_token_list_append (parser->lex_from_list, node->token);
}
- talloc_free (list);
+ ralloc_free (list);
parser->lex_from_node = parser->lex_from_list->head;
/* It's possible the list consisted of nothing but whitespace. */
if (parser->lex_from_node == NULL) {
- talloc_free (parser->lex_from_list);
+ ralloc_free (parser->lex_from_list);
parser->lex_from_list = NULL;
}
}
@@ -1841,7 +1842,7 @@ _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
if (parser->skip_stack)
current = parser->skip_stack->type;
- node = talloc (parser, skip_node_t);
+ node = ralloc (parser, skip_node_t);
node->loc = *loc;
if (current == SKIP_NO_SKIP) {
@@ -1886,5 +1887,5 @@ _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
node = parser->skip_stack;
parser->skip_stack = node->next;
- talloc_free (node);
+ ralloc_free (node);
}