token_list_t *replacements);
static string_list_t *
-_string_list_create(void *ctx);
+_string_list_create(glcpp_parser_t *parser);
static void
-_string_list_append_item(string_list_t *list, const char *str);
+_string_list_append_item(glcpp_parser_t *parser, string_list_t *list,
+ const char *str);
static int
_string_list_contains(string_list_t *list, const char *member, int *index);
_string_list_equal(string_list_t *a, string_list_t *b);
static argument_list_t *
-_argument_list_create(void *ctx);
+_argument_list_create(glcpp_parser_t *parser);
static void
-_argument_list_append(argument_list_t *list, token_list_t *argument);
+_argument_list_append(glcpp_parser_t *parser, argument_list_t *list,
+ token_list_t *argument);
static int
_argument_list_length(argument_list_t *list);
static token_list_t *
_argument_list_member_at(argument_list_t *list, int index);
-/* Note: This function ralloc_steal()s the str pointer. */
static token_t *
-_token_create_str(void *ctx, int type, char *str);
+_token_create_str(glcpp_parser_t *parser, int type, char *str);
static token_t *
-_token_create_ival(void *ctx, int type, int ival);
+_token_create_ival(glcpp_parser_t *parser, int type, int ival);
static token_list_t *
-_token_list_create(void *ctx);
+_token_list_create(glcpp_parser_t *parser);
static void
-_token_list_append(token_list_t *list, token_t *token);
+_token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token);
static void
_token_list_append_list(token_list_t *list, token_list_t *tail);
| text_line {
_glcpp_parser_print_expanded_token_list (parser, $1);
ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
- ralloc_free ($1);
}
| expanded_line
;
control_line_success:
HASH_TOKEN DEFINE_TOKEN define
| HASH_TOKEN UNDEF IDENTIFIER NEWLINE {
- macro_t *macro;
struct hash_entry *entry;
/* Section 3.4 (Preprocessor) of the GLSL ES 3.00 spec says:
entry = _mesa_hash_table_search (parser->defines, $3);
if (entry) {
- macro = entry->data;
_mesa_hash_table_remove (parser->defines, entry);
- ralloc_free (macro);
}
- ralloc_free ($3);
}
| HASH_TOKEN IF pp_tokens NEWLINE {
/* Be careful to only evaluate the 'if' expression if
struct hash_entry *entry =
_mesa_hash_table_search(parser->defines, $3);
macro_t *macro = entry ? entry->data : NULL;
- ralloc_free ($3);
_glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
}
| HASH_TOKEN IFNDEF IDENTIFIER junk NEWLINE {
| IDENTIFIER {
$$.value = 0;
if (parser->is_gles)
- $$.undefined_macro = ralloc_strdup (parser, $1);
+ $$.undefined_macro = linear_strdup(parser->linalloc, $1);
else
$$.undefined_macro = NULL;
}
identifier_list:
IDENTIFIER {
$$ = _string_list_create (parser);
- _string_list_append_item ($$, $1);
- ralloc_steal ($$, $1);
+ _string_list_append_item (parser, $$, $1);
}
| identifier_list ',' IDENTIFIER {
$$ = $1;
- _string_list_append_item ($$, $3);
- ralloc_steal ($$, $3);
+ _string_list_append_item (parser, $$, $3);
}
;
preprocessing_token {
parser->space_tokens = 1;
$$ = _token_list_create (parser);
- _token_list_append ($$, $1);
+ _token_list_append (parser, $$, $1);
}
| pp_tokens preprocessing_token {
$$ = $1;
- _token_list_append ($$, $2);
+ _token_list_append (parser, $$, $2);
}
;
%%
string_list_t *
-_string_list_create(void *ctx)
+_string_list_create(glcpp_parser_t *parser)
{
string_list_t *list;
- list = ralloc (ctx, string_list_t);
+ list = linear_alloc_child(parser->linalloc, sizeof(string_list_t));
list->head = NULL;
list->tail = NULL;
}
void
-_string_list_append_item(string_list_t *list, const char *str)
+_string_list_append_item(glcpp_parser_t *parser, string_list_t *list,
+ const char *str)
{
string_node_t *node;
- node = ralloc (list, string_node_t);
- node->str = ralloc_strdup (node, str);
+ node = linear_alloc_child(parser->linalloc, sizeof(string_node_t));
+ node->str = linear_strdup(parser->linalloc, str);
node->next = NULL;
}
argument_list_t *
-_argument_list_create(void *ctx)
+_argument_list_create(glcpp_parser_t *parser)
{
argument_list_t *list;
- list = ralloc (ctx, argument_list_t);
+ list = linear_alloc_child(parser->linalloc, sizeof(argument_list_t));
list->head = NULL;
list->tail = NULL;
}
void
-_argument_list_append(argument_list_t *list, token_list_t *argument)
+_argument_list_append(glcpp_parser_t *parser,
+ argument_list_t *list, token_list_t *argument)
{
argument_node_t *node;
- node = ralloc (list, argument_node_t);
+ node = linear_alloc_child(parser->linalloc, sizeof(argument_node_t));
node->argument = argument;
node->next = NULL;
return NULL;
}
-/* Note: This function ralloc_steal()s the str pointer. */
token_t *
-_token_create_str(void *ctx, int type, char *str)
+_token_create_str(glcpp_parser_t *parser, int type, char *str)
{
token_t *token;
- token = ralloc (ctx, token_t);
+ token = linear_alloc_child(parser->linalloc, sizeof(token_t));
token->type = type;
token->value.str = str;
- ralloc_steal (token, str);
-
return token;
}
token_t *
-_token_create_ival(void *ctx, int type, int ival)
+_token_create_ival(glcpp_parser_t *parser, int type, int ival)
{
token_t *token;
- token = ralloc (ctx, token_t);
+ token = linear_alloc_child(parser->linalloc, sizeof(token_t));
token->type = type;
token->value.ival = ival;
}
token_list_t *
-_token_list_create(void *ctx)
+_token_list_create(glcpp_parser_t *parser)
{
token_list_t *list;
- list = ralloc (ctx, token_list_t);
+ list = linear_alloc_child(parser->linalloc, sizeof(token_list_t));
list->head = NULL;
list->tail = NULL;
list->non_space_tail = NULL;
}
void
-_token_list_append(token_list_t *list, token_t *token)
+_token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token)
{
token_node_t *node;
- node = ralloc (list, token_node_t);
+ node = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
node->token = token;
node->next = NULL;
}
static token_list_t *
-_token_list_copy(void *ctx, token_list_t *other)
+_token_list_copy(glcpp_parser_t *parser, token_list_t *other)
{
token_list_t *copy;
token_node_t *node;
if (other == NULL)
return NULL;
- copy = _token_list_create (ctx);
+ copy = _token_list_create (parser);
for (node = other->head; node; node = node->next) {
- token_t *new_token = ralloc (copy, token_t);
+ token_t *new_token = linear_alloc_child(parser->linalloc, sizeof(token_t));
*new_token = *node->token;
- _token_list_append (copy, new_token);
+ _token_list_append (parser, copy, new_token);
}
return copy;
static void
_token_list_trim_trailing_space(token_list_t *list)
{
- token_node_t *tail, *next;
-
if (list->non_space_tail) {
- tail = list->non_space_tail->next;
list->non_space_tail->next = NULL;
list->tail = list->non_space_tail;
-
- while (tail) {
- next = tail->next;
- ralloc_free (tail);
- tail = next;
- }
}
}
}
}
-/* 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.
+/* Return a new token formed by pasting 'token' and 'other'. Note that this
+ * function may return 'token' or 'other' directly rather than allocating
+ * anything new.
*
* Caution: Only very cursory error-checking is performed to see if
* the final result is a valid single token. */
switch (token->type) {
case '<':
if (other->type == '<')
- combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
+ combined = _token_create_ival (parser, LEFT_SHIFT, LEFT_SHIFT);
else if (other->type == '=')
- combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
+ combined = _token_create_ival (parser, LESS_OR_EQUAL, LESS_OR_EQUAL);
break;
case '>':
if (other->type == '>')
- combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
+ combined = _token_create_ival (parser, RIGHT_SHIFT, RIGHT_SHIFT);
else if (other->type == '=')
- combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
+ combined = _token_create_ival (parser, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
break;
case '=':
if (other->type == '=')
- combined = _token_create_ival (token, EQUAL, EQUAL);
+ combined = _token_create_ival (parser, EQUAL, EQUAL);
break;
case '!':
if (other->type == '=')
- combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
+ combined = _token_create_ival (parser, NOT_EQUAL, NOT_EQUAL);
break;
case '&':
if (other->type == '&')
- combined = _token_create_ival (token, AND, AND);
+ combined = _token_create_ival (parser, AND, AND);
break;
case '|':
if (other->type == '|')
- combined = _token_create_ival (token, OR, OR);
+ combined = _token_create_ival (parser, OR, OR);
break;
}
}
if (token->type == INTEGER)
- str = ralloc_asprintf (token, "%" PRIiMAX, token->value.ival);
+ str = linear_asprintf(parser->linalloc, "%" PRIiMAX, token->value.ival);
else
- str = ralloc_strdup (token, token->value.str);
+ str = linear_strdup(parser->linalloc, token->value.str);
if (other->type == INTEGER)
- ralloc_asprintf_append (&str, "%" PRIiMAX, other->value.ival);
+ linear_asprintf_append(parser->linalloc, &str, "%" PRIiMAX, other->value.ival);
else
- ralloc_strcat (&str, other->value.str);
+ linear_strcat(parser->linalloc, &str, other->value.str);
/* New token is same type as original token, unless we
* started with an integer, in which case we will be
if (combined_type == INTEGER)
combined_type = INTEGER_STRING;
- combined = _token_create_str (token, combined_type, str);
+ combined = _token_create_str (parser, combined_type, str);
combined->location = token->location;
return combined;
}
tok = _token_create_ival (parser, INTEGER, value);
list = _token_list_create(parser);
- _token_list_append(list, tok);
+ _token_list_append(parser, list, tok);
_define_object_macro(parser, NULL, name, list);
}
glcpp_lex_init_extra (parser, &parser->scanner);
parser->defines = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
_mesa_key_string_equal);
+ parser->linalloc = linear_alloc_parent(parser, 0);
parser->active = NULL;
parser->lexing_directive = 0;
parser->lexing_version_directive = 0;
* Macro name is not followed by a balanced set of parentheses.
*/
static function_status_t
-_arguments_parse(argument_list_t *arguments, token_node_t *node,
+_arguments_parse(glcpp_parser_t *parser,
+ argument_list_t *arguments, token_node_t *node,
token_node_t **last)
{
token_list_t *argument;
node = node->next;
- argument = _token_list_create (arguments);
- _argument_list_append (arguments, argument);
+ argument = _token_list_create (parser);
+ _argument_list_append (parser, arguments, argument);
for (paren_count = 1; node; node = node->next) {
if (node->token->type == '(') {
if (node->token->type == ',' && paren_count == 1) {
_token_list_trim_trailing_space (argument);
- argument = _token_list_create (arguments);
- _argument_list_append (arguments, argument);
+ argument = _token_list_create (parser);
+ _argument_list_append (parser, arguments, argument);
} else {
if (argument->head == NULL) {
/* Don't treat initial whitespace as part of the argument. */
if (node->token->type == SPACE)
continue;
}
- _token_list_append (argument, node->token);
+ _token_list_append(parser, argument, node->token);
}
}
}
static token_list_t *
-_token_list_create_with_one_ival(void *ctx, int type, int ival)
+_token_list_create_with_one_ival(glcpp_parser_t *parser, int type, int ival)
{
token_list_t *list;
token_t *node;
- list = _token_list_create(ctx);
- node = _token_create_ival(list, type, ival);
- _token_list_append(list, node);
+ list = _token_list_create(parser);
+ node = _token_create_ival(parser, type, ival);
+ _token_list_append(parser, list, node);
return list;
}
static token_list_t *
-_token_list_create_with_one_space(void *ctx)
+_token_list_create_with_one_space(glcpp_parser_t *parser)
{
- return _token_list_create_with_one_ival(ctx, SPACE, SPACE);
+ return _token_list_create_with_one_ival(parser, SPACE, SPACE);
}
static token_list_t *
-_token_list_create_with_one_integer(void *ctx, int ival)
+_token_list_create_with_one_integer(glcpp_parser_t *parser, int ival)
{
- return _token_list_create_with_one_ival(ctx, INTEGER, ival);
+ return _token_list_create_with_one_ival(parser, INTEGER, ival);
}
/* Evaluate a DEFINED token node (based on subsequent tokens in the list).
if (value == -1)
goto NEXT;
- replacement = ralloc (list, token_node_t);
- replacement->token = _token_create_ival (list, INTEGER, value);
+ replacement = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
+ replacement->token = _token_create_ival (parser, INTEGER, value);
/* Splice replacement node into list, replacing from "node"
* through "last". */
expanded = _token_list_create (parser);
token = _token_create_ival (parser, head_token_type, head_token_type);
- _token_list_append (expanded, token);
+ _token_list_append (parser, expanded, token);
_glcpp_parser_expand_token_list (parser, list, mode);
_token_list_append_list (expanded, list);
glcpp_parser_lex_from (parser, expanded);
assert(macro->is_function);
arguments = _argument_list_create(parser);
- status = _arguments_parse(arguments, node, last);
+ status = _arguments_parse(parser, arguments, node, last);
switch (status) {
case FUNCTION_STATUS_SUCCESS:
/* Replace a macro defined as empty with a SPACE token. */
if (macro->replacements == NULL) {
- ralloc_free(arguments);
return _token_list_create_with_one_space(parser);
}
}
/* Perform argument substitution on the replacement list. */
- substituted = _token_list_create(arguments);
+ substituted = _token_list_create(parser);
for (node = macro->replacements->head; node; node = node->next) {
if (node->token->type == IDENTIFIER &&
} else {
token_t *new_token;
- new_token = _token_create_ival(substituted, PLACEHOLDER,
+ new_token = _token_create_ival(parser, PLACEHOLDER,
PLACEHOLDER);
- _token_list_append(substituted, new_token);
+ _token_list_append(parser, substituted, new_token);
}
} else {
- _token_list_append(substituted, node->token);
+ _token_list_append(parser, substituted, node->token);
}
}
token_list_t *expansion;
token_t *final;
- str = ralloc_strdup(parser, token->value.str);
+ str = linear_strdup(parser->linalloc, token->value.str);
final = _token_create_str(parser, OTHER, str);
expansion = _token_list_create(parser);
- _token_list_append(expansion, final);
+ _token_list_append(parser, expansion, final);
return expansion;
}
{
active_list_t *node;
- node = ralloc(parser->active, active_list_t);
- node->identifier = ralloc_strdup(node, identifier);
+ node = linear_alloc_child(parser->linalloc, sizeof(active_list_t));
+ node->identifier = linear_strdup(parser->linalloc, identifier);
node->marker = marker;
node->next = parser->active;
}
node = parser->active->next;
- ralloc_free (parser->active);
-
parser->active = node;
}
if (loc != NULL)
_check_for_reserved_macro_name(parser, loc, identifier);
- macro = ralloc (parser, macro_t);
+ macro = linear_alloc_child(parser->linalloc, sizeof(macro_t));
macro->is_function = 0;
macro->parameters = NULL;
- macro->identifier = ralloc_strdup (macro, identifier);
+ macro->identifier = linear_strdup(parser->linalloc, identifier);
macro->replacements = replacements;
- ralloc_steal (macro, replacements);
entry = _mesa_hash_table_search(parser->defines, identifier);
previous = entry ? entry->data : NULL;
if (previous) {
if (_macro_equal (macro, previous)) {
- ralloc_free (macro);
return;
}
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"", dup);
}
- macro = ralloc (parser, macro_t);
- ralloc_steal (macro, parameters);
- ralloc_steal (macro, replacements);
+ macro = linear_alloc_child(parser->linalloc, sizeof(macro_t));
macro->is_function = 1;
macro->parameters = parameters;
- macro->identifier = ralloc_strdup (macro, identifier);
+ macro->identifier = linear_strdup(parser->linalloc, identifier);
macro->replacements = replacements;
entry = _mesa_hash_table_search(parser->defines, identifier);
previous = entry ? entry->data : NULL;
if (previous) {
if (_macro_equal (macro, previous)) {
- ralloc_free (macro);
return;
}
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
node = parser->lex_from_node;
if (node == NULL) {
- ralloc_free (parser->lex_from_list);
parser->lex_from_list = NULL;
return NEWLINE;
}
for (node = list->head; node; node = node->next) {
if (node->token->type == SPACE)
continue;
- _token_list_append (parser->lex_from_list, node->token);
+ _token_list_append (parser, parser->lex_from_list, node->token);
}
- 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) {
- ralloc_free (parser->lex_from_list);
parser->lex_from_list = NULL;
}
}
if (parser->skip_stack)
current = parser->skip_stack->type;
- node = ralloc (parser, skip_node_t);
+ node = linear_alloc_child(parser->linalloc, sizeof(skip_node_t));
node->loc = *loc;
if (current == SKIP_NO_SKIP) {
node = parser->skip_stack;
parser->skip_stack = node->next;
- ralloc_free (node);
}
static void