mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 09:08:10 +02:00
glcpp: use the linear allocator for most objects
v2: cosmetic changes Tested-by: Edmondo Tommasina <edmondo.tommasina@gmail.com> (v1) Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com> (v1)
This commit is contained in:
parent
6608dbf540
commit
47e1758692
3 changed files with 91 additions and 118 deletions
|
|
@ -101,7 +101,7 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner);
|
||||||
#define RETURN_STRING_TOKEN(token) \
|
#define RETURN_STRING_TOKEN(token) \
|
||||||
do { \
|
do { \
|
||||||
if (! parser->skipping) { \
|
if (! parser->skipping) { \
|
||||||
yylval->str = ralloc_strdup (yyextra, yytext); \
|
yylval->str = linear_strdup(yyextra->linalloc, yytext); \
|
||||||
RETURN_TOKEN_NEVER_SKIP (token); \
|
RETURN_TOKEN_NEVER_SKIP (token); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,11 @@ _define_function_macro(glcpp_parser_t *parser,
|
||||||
token_list_t *replacements);
|
token_list_t *replacements);
|
||||||
|
|
||||||
static string_list_t *
|
static string_list_t *
|
||||||
_string_list_create(void *ctx);
|
_string_list_create(glcpp_parser_t *parser);
|
||||||
|
|
||||||
static void
|
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
|
static int
|
||||||
_string_list_contains(string_list_t *list, const char *member, int *index);
|
_string_list_contains(string_list_t *list, const char *member, int *index);
|
||||||
|
|
@ -67,10 +68,11 @@ static int
|
||||||
_string_list_equal(string_list_t *a, string_list_t *b);
|
_string_list_equal(string_list_t *a, string_list_t *b);
|
||||||
|
|
||||||
static argument_list_t *
|
static argument_list_t *
|
||||||
_argument_list_create(void *ctx);
|
_argument_list_create(glcpp_parser_t *parser);
|
||||||
|
|
||||||
static void
|
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
|
static int
|
||||||
_argument_list_length(argument_list_t *list);
|
_argument_list_length(argument_list_t *list);
|
||||||
|
|
@ -78,18 +80,17 @@ _argument_list_length(argument_list_t *list);
|
||||||
static token_list_t *
|
static token_list_t *
|
||||||
_argument_list_member_at(argument_list_t *list, int index);
|
_argument_list_member_at(argument_list_t *list, int index);
|
||||||
|
|
||||||
/* Note: This function ralloc_steal()s the str pointer. */
|
|
||||||
static token_t *
|
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 *
|
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 *
|
static token_list_t *
|
||||||
_token_list_create(void *ctx);
|
_token_list_create(glcpp_parser_t *parser);
|
||||||
|
|
||||||
static void
|
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
|
static void
|
||||||
_token_list_append_list(token_list_t *list, token_list_t *tail);
|
_token_list_append_list(token_list_t *list, token_list_t *tail);
|
||||||
|
|
@ -209,7 +210,6 @@ line:
|
||||||
| text_line {
|
| text_line {
|
||||||
_glcpp_parser_print_expanded_token_list (parser, $1);
|
_glcpp_parser_print_expanded_token_list (parser, $1);
|
||||||
ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
|
ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
|
||||||
ralloc_free ($1);
|
|
||||||
}
|
}
|
||||||
| expanded_line
|
| expanded_line
|
||||||
;
|
;
|
||||||
|
|
@ -277,7 +277,6 @@ control_line:
|
||||||
control_line_success:
|
control_line_success:
|
||||||
HASH_TOKEN DEFINE_TOKEN define
|
HASH_TOKEN DEFINE_TOKEN define
|
||||||
| HASH_TOKEN UNDEF IDENTIFIER NEWLINE {
|
| HASH_TOKEN UNDEF IDENTIFIER NEWLINE {
|
||||||
macro_t *macro;
|
|
||||||
struct hash_entry *entry;
|
struct hash_entry *entry;
|
||||||
|
|
||||||
/* Section 3.4 (Preprocessor) of the GLSL ES 3.00 spec says:
|
/* Section 3.4 (Preprocessor) of the GLSL ES 3.00 spec says:
|
||||||
|
|
@ -312,11 +311,8 @@ control_line_success:
|
||||||
|
|
||||||
entry = _mesa_hash_table_search (parser->defines, $3);
|
entry = _mesa_hash_table_search (parser->defines, $3);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
macro = entry->data;
|
|
||||||
_mesa_hash_table_remove (parser->defines, entry);
|
_mesa_hash_table_remove (parser->defines, entry);
|
||||||
ralloc_free (macro);
|
|
||||||
}
|
}
|
||||||
ralloc_free ($3);
|
|
||||||
}
|
}
|
||||||
| HASH_TOKEN IF pp_tokens NEWLINE {
|
| HASH_TOKEN IF pp_tokens NEWLINE {
|
||||||
/* Be careful to only evaluate the 'if' expression if
|
/* Be careful to only evaluate the 'if' expression if
|
||||||
|
|
@ -353,7 +349,6 @@ control_line_success:
|
||||||
struct hash_entry *entry =
|
struct hash_entry *entry =
|
||||||
_mesa_hash_table_search(parser->defines, $3);
|
_mesa_hash_table_search(parser->defines, $3);
|
||||||
macro_t *macro = entry ? entry->data : NULL;
|
macro_t *macro = entry ? entry->data : NULL;
|
||||||
ralloc_free ($3);
|
|
||||||
_glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
|
_glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
|
||||||
}
|
}
|
||||||
| HASH_TOKEN IFNDEF IDENTIFIER junk NEWLINE {
|
| HASH_TOKEN IFNDEF IDENTIFIER junk NEWLINE {
|
||||||
|
|
@ -478,7 +473,7 @@ expression:
|
||||||
| IDENTIFIER {
|
| IDENTIFIER {
|
||||||
$$.value = 0;
|
$$.value = 0;
|
||||||
if (parser->is_gles)
|
if (parser->is_gles)
|
||||||
$$.undefined_macro = ralloc_strdup (parser, $1);
|
$$.undefined_macro = linear_strdup(parser->linalloc, $1);
|
||||||
else
|
else
|
||||||
$$.undefined_macro = NULL;
|
$$.undefined_macro = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -650,13 +645,11 @@ expression:
|
||||||
identifier_list:
|
identifier_list:
|
||||||
IDENTIFIER {
|
IDENTIFIER {
|
||||||
$$ = _string_list_create (parser);
|
$$ = _string_list_create (parser);
|
||||||
_string_list_append_item ($$, $1);
|
_string_list_append_item (parser, $$, $1);
|
||||||
ralloc_steal ($$, $1);
|
|
||||||
}
|
}
|
||||||
| identifier_list ',' IDENTIFIER {
|
| identifier_list ',' IDENTIFIER {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
_string_list_append_item ($$, $3);
|
_string_list_append_item (parser, $$, $3);
|
||||||
ralloc_steal ($$, $3);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -681,11 +674,11 @@ pp_tokens:
|
||||||
preprocessing_token {
|
preprocessing_token {
|
||||||
parser->space_tokens = 1;
|
parser->space_tokens = 1;
|
||||||
$$ = _token_list_create (parser);
|
$$ = _token_list_create (parser);
|
||||||
_token_list_append ($$, $1);
|
_token_list_append (parser, $$, $1);
|
||||||
}
|
}
|
||||||
| pp_tokens preprocessing_token {
|
| pp_tokens preprocessing_token {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
_token_list_append ($$, $2);
|
_token_list_append (parser, $$, $2);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -755,11 +748,11 @@ operator:
|
||||||
%%
|
%%
|
||||||
|
|
||||||
string_list_t *
|
string_list_t *
|
||||||
_string_list_create(void *ctx)
|
_string_list_create(glcpp_parser_t *parser)
|
||||||
{
|
{
|
||||||
string_list_t *list;
|
string_list_t *list;
|
||||||
|
|
||||||
list = ralloc (ctx, string_list_t);
|
list = linear_alloc_child(parser->linalloc, sizeof(string_list_t));
|
||||||
list->head = NULL;
|
list->head = NULL;
|
||||||
list->tail = NULL;
|
list->tail = NULL;
|
||||||
|
|
||||||
|
|
@ -767,12 +760,13 @@ _string_list_create(void *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
string_node_t *node;
|
||||||
|
|
||||||
node = ralloc (list, string_node_t);
|
node = linear_alloc_child(parser->linalloc, sizeof(string_node_t));
|
||||||
node->str = ralloc_strdup (node, str);
|
node->str = linear_strdup(parser->linalloc, str);
|
||||||
|
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
|
|
||||||
|
|
@ -865,11 +859,11 @@ _string_list_equal(string_list_t *a, string_list_t *b)
|
||||||
}
|
}
|
||||||
|
|
||||||
argument_list_t *
|
argument_list_t *
|
||||||
_argument_list_create(void *ctx)
|
_argument_list_create(glcpp_parser_t *parser)
|
||||||
{
|
{
|
||||||
argument_list_t *list;
|
argument_list_t *list;
|
||||||
|
|
||||||
list = ralloc (ctx, argument_list_t);
|
list = linear_alloc_child(parser->linalloc, sizeof(argument_list_t));
|
||||||
list->head = NULL;
|
list->head = NULL;
|
||||||
list->tail = NULL;
|
list->tail = NULL;
|
||||||
|
|
||||||
|
|
@ -877,11 +871,12 @@ _argument_list_create(void *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
argument_node_t *node;
|
||||||
|
|
||||||
node = ralloc (list, argument_node_t);
|
node = linear_alloc_child(parser->linalloc, sizeof(argument_node_t));
|
||||||
node->argument = argument;
|
node->argument = argument;
|
||||||
|
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
|
|
@ -932,27 +927,24 @@ _argument_list_member_at(argument_list_t *list, int index)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: This function ralloc_steal()s the str pointer. */
|
|
||||||
token_t *
|
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_t *token;
|
||||||
|
|
||||||
token = ralloc (ctx, token_t);
|
token = linear_alloc_child(parser->linalloc, sizeof(token_t));
|
||||||
token->type = type;
|
token->type = type;
|
||||||
token->value.str = str;
|
token->value.str = str;
|
||||||
|
|
||||||
ralloc_steal (token, str);
|
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
token_t *
|
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_t *token;
|
||||||
|
|
||||||
token = ralloc (ctx, token_t);
|
token = linear_alloc_child(parser->linalloc, sizeof(token_t));
|
||||||
token->type = type;
|
token->type = type;
|
||||||
token->value.ival = ival;
|
token->value.ival = ival;
|
||||||
|
|
||||||
|
|
@ -960,11 +952,11 @@ _token_create_ival(void *ctx, int type, int ival)
|
||||||
}
|
}
|
||||||
|
|
||||||
token_list_t *
|
token_list_t *
|
||||||
_token_list_create(void *ctx)
|
_token_list_create(glcpp_parser_t *parser)
|
||||||
{
|
{
|
||||||
token_list_t *list;
|
token_list_t *list;
|
||||||
|
|
||||||
list = ralloc (ctx, token_list_t);
|
list = linear_alloc_child(parser->linalloc, sizeof(token_list_t));
|
||||||
list->head = NULL;
|
list->head = NULL;
|
||||||
list->tail = NULL;
|
list->tail = NULL;
|
||||||
list->non_space_tail = NULL;
|
list->non_space_tail = NULL;
|
||||||
|
|
@ -973,11 +965,11 @@ _token_list_create(void *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
token_node_t *node;
|
||||||
|
|
||||||
node = ralloc (list, token_node_t);
|
node = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
|
||||||
node->token = token;
|
node->token = token;
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
|
|
||||||
|
|
@ -1009,7 +1001,7 @@ _token_list_append_list(token_list_t *list, token_list_t *tail)
|
||||||
}
|
}
|
||||||
|
|
||||||
static token_list_t *
|
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_list_t *copy;
|
||||||
token_node_t *node;
|
token_node_t *node;
|
||||||
|
|
@ -1017,11 +1009,11 @@ _token_list_copy(void *ctx, token_list_t *other)
|
||||||
if (other == NULL)
|
if (other == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
copy = _token_list_create (ctx);
|
copy = _token_list_create (parser);
|
||||||
for (node = other->head; node; node = node->next) {
|
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;
|
*new_token = *node->token;
|
||||||
_token_list_append (copy, new_token);
|
_token_list_append (parser, copy, new_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
|
|
@ -1030,18 +1022,9 @@ _token_list_copy(void *ctx, token_list_t *other)
|
||||||
static void
|
static void
|
||||||
_token_list_trim_trailing_space(token_list_t *list)
|
_token_list_trim_trailing_space(token_list_t *list)
|
||||||
{
|
{
|
||||||
token_node_t *tail, *next;
|
|
||||||
|
|
||||||
if (list->non_space_tail) {
|
if (list->non_space_tail) {
|
||||||
tail = list->non_space_tail->next;
|
|
||||||
list->non_space_tail->next = NULL;
|
list->non_space_tail->next = NULL;
|
||||||
list->tail = list->non_space_tail;
|
list->tail = list->non_space_tail;
|
||||||
|
|
||||||
while (tail) {
|
|
||||||
next = tail->next;
|
|
||||||
ralloc_free (tail);
|
|
||||||
tail = next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1184,9 +1167,9 @@ _token_print(char **out, size_t *len, token_t *token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a new token (ralloc()ed off of 'token') formed by pasting
|
/* Return a new token formed by pasting 'token' and 'other'. Note that this
|
||||||
* 'token' and 'other'. Note that this function may return 'token' or
|
* function may return 'token' or 'other' directly rather than allocating
|
||||||
* 'other' directly rather than allocating anything new.
|
* anything new.
|
||||||
*
|
*
|
||||||
* Caution: Only very cursory error-checking is performed to see if
|
* Caution: Only very cursory error-checking is performed to see if
|
||||||
* the final result is a valid single token. */
|
* the final result is a valid single token. */
|
||||||
|
|
@ -1208,31 +1191,31 @@ _token_paste(glcpp_parser_t *parser, token_t *token, token_t *other)
|
||||||
switch (token->type) {
|
switch (token->type) {
|
||||||
case '<':
|
case '<':
|
||||||
if (other->type == '<')
|
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 == '=')
|
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;
|
break;
|
||||||
case '>':
|
case '>':
|
||||||
if (other->type == '>')
|
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 == '=')
|
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;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
if (other->type == '=')
|
if (other->type == '=')
|
||||||
combined = _token_create_ival (token, EQUAL, EQUAL);
|
combined = _token_create_ival (parser, EQUAL, EQUAL);
|
||||||
break;
|
break;
|
||||||
case '!':
|
case '!':
|
||||||
if (other->type == '=')
|
if (other->type == '=')
|
||||||
combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
|
combined = _token_create_ival (parser, NOT_EQUAL, NOT_EQUAL);
|
||||||
break;
|
break;
|
||||||
case '&':
|
case '&':
|
||||||
if (other->type == '&')
|
if (other->type == '&')
|
||||||
combined = _token_create_ival (token, AND, AND);
|
combined = _token_create_ival (parser, AND, AND);
|
||||||
break;
|
break;
|
||||||
case '|':
|
case '|':
|
||||||
if (other->type == '|')
|
if (other->type == '|')
|
||||||
combined = _token_create_ival (token, OR, OR);
|
combined = _token_create_ival (parser, OR, OR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1276,14 +1259,14 @@ _token_paste(glcpp_parser_t *parser, token_t *token, token_t *other)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token->type == INTEGER)
|
if (token->type == INTEGER)
|
||||||
str = ralloc_asprintf (token, "%" PRIiMAX, token->value.ival);
|
str = linear_asprintf(parser->linalloc, "%" PRIiMAX, token->value.ival);
|
||||||
else
|
else
|
||||||
str = ralloc_strdup (token, token->value.str);
|
str = linear_strdup(parser->linalloc, token->value.str);
|
||||||
|
|
||||||
if (other->type == INTEGER)
|
if (other->type == INTEGER)
|
||||||
ralloc_asprintf_append (&str, "%" PRIiMAX, other->value.ival);
|
linear_asprintf_append(parser->linalloc, &str, "%" PRIiMAX, other->value.ival);
|
||||||
else
|
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
|
/* New token is same type as original token, unless we
|
||||||
* started with an integer, in which case we will be
|
* started with an integer, in which case we will be
|
||||||
|
|
@ -1292,7 +1275,7 @@ _token_paste(glcpp_parser_t *parser, token_t *token, token_t *other)
|
||||||
if (combined_type == INTEGER)
|
if (combined_type == INTEGER)
|
||||||
combined_type = INTEGER_STRING;
|
combined_type = INTEGER_STRING;
|
||||||
|
|
||||||
combined = _token_create_str (token, combined_type, str);
|
combined = _token_create_str (parser, combined_type, str);
|
||||||
combined->location = token->location;
|
combined->location = token->location;
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
@ -1335,7 +1318,7 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value)
|
||||||
tok = _token_create_ival (parser, INTEGER, value);
|
tok = _token_create_ival (parser, INTEGER, value);
|
||||||
|
|
||||||
list = _token_list_create(parser);
|
list = _token_list_create(parser);
|
||||||
_token_list_append(list, tok);
|
_token_list_append(parser, list, tok);
|
||||||
_define_object_macro(parser, NULL, name, list);
|
_define_object_macro(parser, NULL, name, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1349,6 +1332,7 @@ glcpp_parser_create(glcpp_extension_iterator extensions, void *state, gl_api api
|
||||||
glcpp_lex_init_extra (parser, &parser->scanner);
|
glcpp_lex_init_extra (parser, &parser->scanner);
|
||||||
parser->defines = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
|
parser->defines = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
|
||||||
_mesa_key_string_equal);
|
_mesa_key_string_equal);
|
||||||
|
parser->linalloc = linear_alloc_parent(parser, 0);
|
||||||
parser->active = NULL;
|
parser->active = NULL;
|
||||||
parser->lexing_directive = 0;
|
parser->lexing_directive = 0;
|
||||||
parser->lexing_version_directive = 0;
|
parser->lexing_version_directive = 0;
|
||||||
|
|
@ -1427,7 +1411,8 @@ typedef enum function_status
|
||||||
* Macro name is not followed by a balanced set of parentheses.
|
* Macro name is not followed by a balanced set of parentheses.
|
||||||
*/
|
*/
|
||||||
static function_status_t
|
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_node_t **last)
|
||||||
{
|
{
|
||||||
token_list_t *argument;
|
token_list_t *argument;
|
||||||
|
|
@ -1444,8 +1429,8 @@ _arguments_parse(argument_list_t *arguments, token_node_t *node,
|
||||||
|
|
||||||
node = node->next;
|
node = node->next;
|
||||||
|
|
||||||
argument = _token_list_create (arguments);
|
argument = _token_list_create (parser);
|
||||||
_argument_list_append (arguments, argument);
|
_argument_list_append (parser, arguments, argument);
|
||||||
|
|
||||||
for (paren_count = 1; node; node = node->next) {
|
for (paren_count = 1; node; node = node->next) {
|
||||||
if (node->token->type == '(') {
|
if (node->token->type == '(') {
|
||||||
|
|
@ -1458,15 +1443,15 @@ _arguments_parse(argument_list_t *arguments, token_node_t *node,
|
||||||
|
|
||||||
if (node->token->type == ',' && paren_count == 1) {
|
if (node->token->type == ',' && paren_count == 1) {
|
||||||
_token_list_trim_trailing_space (argument);
|
_token_list_trim_trailing_space (argument);
|
||||||
argument = _token_list_create (arguments);
|
argument = _token_list_create (parser);
|
||||||
_argument_list_append (arguments, argument);
|
_argument_list_append (parser, arguments, argument);
|
||||||
} else {
|
} else {
|
||||||
if (argument->head == NULL) {
|
if (argument->head == NULL) {
|
||||||
/* Don't treat initial whitespace as part of the argument. */
|
/* Don't treat initial whitespace as part of the argument. */
|
||||||
if (node->token->type == SPACE)
|
if (node->token->type == SPACE)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_token_list_append (argument, node->token);
|
_token_list_append(parser, argument, node->token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1479,28 +1464,28 @@ _arguments_parse(argument_list_t *arguments, token_node_t *node,
|
||||||
}
|
}
|
||||||
|
|
||||||
static token_list_t *
|
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_list_t *list;
|
||||||
token_t *node;
|
token_t *node;
|
||||||
|
|
||||||
list = _token_list_create(ctx);
|
list = _token_list_create(parser);
|
||||||
node = _token_create_ival(list, type, ival);
|
node = _token_create_ival(parser, type, ival);
|
||||||
_token_list_append(list, node);
|
_token_list_append(parser, list, node);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static token_list_t *
|
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 *
|
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).
|
/* Evaluate a DEFINED token node (based on subsequent tokens in the list).
|
||||||
|
|
@ -1604,8 +1589,8 @@ _glcpp_parser_evaluate_defined_in_list(glcpp_parser_t *parser,
|
||||||
if (value == -1)
|
if (value == -1)
|
||||||
goto NEXT;
|
goto NEXT;
|
||||||
|
|
||||||
replacement = ralloc (list, token_node_t);
|
replacement = linear_alloc_child(parser->linalloc, sizeof(token_node_t));
|
||||||
replacement->token = _token_create_ival (list, INTEGER, value);
|
replacement->token = _token_create_ival (parser, INTEGER, value);
|
||||||
|
|
||||||
/* Splice replacement node into list, replacing from "node"
|
/* Splice replacement node into list, replacing from "node"
|
||||||
* through "last". */
|
* through "last". */
|
||||||
|
|
@ -1642,7 +1627,7 @@ _glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
|
||||||
|
|
||||||
expanded = _token_list_create (parser);
|
expanded = _token_list_create (parser);
|
||||||
token = _token_create_ival (parser, head_token_type, head_token_type);
|
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);
|
_glcpp_parser_expand_token_list (parser, list, mode);
|
||||||
_token_list_append_list (expanded, list);
|
_token_list_append_list (expanded, list);
|
||||||
glcpp_parser_lex_from (parser, expanded);
|
glcpp_parser_lex_from (parser, expanded);
|
||||||
|
|
@ -1729,7 +1714,7 @@ _glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
|
||||||
assert(macro->is_function);
|
assert(macro->is_function);
|
||||||
|
|
||||||
arguments = _argument_list_create(parser);
|
arguments = _argument_list_create(parser);
|
||||||
status = _arguments_parse(arguments, node, last);
|
status = _arguments_parse(parser, arguments, node, last);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case FUNCTION_STATUS_SUCCESS:
|
case FUNCTION_STATUS_SUCCESS:
|
||||||
|
|
@ -1743,7 +1728,6 @@ _glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
|
||||||
|
|
||||||
/* Replace a macro defined as empty with a SPACE token. */
|
/* Replace a macro defined as empty with a SPACE token. */
|
||||||
if (macro->replacements == NULL) {
|
if (macro->replacements == NULL) {
|
||||||
ralloc_free(arguments);
|
|
||||||
return _token_list_create_with_one_space(parser);
|
return _token_list_create_with_one_space(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1760,7 +1744,7 @@ _glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform argument substitution on the replacement list. */
|
/* 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) {
|
for (node = macro->replacements->head; node; node = node->next) {
|
||||||
if (node->token->type == IDENTIFIER &&
|
if (node->token->type == IDENTIFIER &&
|
||||||
|
|
@ -1778,12 +1762,12 @@ _glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
|
||||||
} else {
|
} else {
|
||||||
token_t *new_token;
|
token_t *new_token;
|
||||||
|
|
||||||
new_token = _token_create_ival(substituted, PLACEHOLDER,
|
new_token = _token_create_ival(parser, PLACEHOLDER,
|
||||||
PLACEHOLDER);
|
PLACEHOLDER);
|
||||||
_token_list_append(substituted, new_token);
|
_token_list_append(parser, substituted, new_token);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_token_list_append(substituted, node->token);
|
_token_list_append(parser, substituted, node->token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1857,10 +1841,10 @@ _glcpp_parser_expand_node(glcpp_parser_t *parser, token_node_t *node,
|
||||||
token_list_t *expansion;
|
token_list_t *expansion;
|
||||||
token_t *final;
|
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);
|
final = _token_create_str(parser, OTHER, str);
|
||||||
expansion = _token_list_create(parser);
|
expansion = _token_list_create(parser);
|
||||||
_token_list_append(expansion, final);
|
_token_list_append(parser, expansion, final);
|
||||||
return expansion;
|
return expansion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1892,8 +1876,8 @@ _parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
|
||||||
{
|
{
|
||||||
active_list_t *node;
|
active_list_t *node;
|
||||||
|
|
||||||
node = ralloc(parser->active, active_list_t);
|
node = linear_alloc_child(parser->linalloc, sizeof(active_list_t));
|
||||||
node->identifier = ralloc_strdup(node, identifier);
|
node->identifier = linear_strdup(parser->linalloc, identifier);
|
||||||
node->marker = marker;
|
node->marker = marker;
|
||||||
node->next = parser->active;
|
node->next = parser->active;
|
||||||
|
|
||||||
|
|
@ -1911,8 +1895,6 @@ _parser_active_list_pop(glcpp_parser_t *parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
node = parser->active->next;
|
node = parser->active->next;
|
||||||
ralloc_free (parser->active);
|
|
||||||
|
|
||||||
parser->active = node;
|
parser->active = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2100,19 +2082,17 @@ _define_object_macro(glcpp_parser_t *parser, YYLTYPE *loc,
|
||||||
if (loc != NULL)
|
if (loc != NULL)
|
||||||
_check_for_reserved_macro_name(parser, loc, identifier);
|
_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->is_function = 0;
|
||||||
macro->parameters = NULL;
|
macro->parameters = NULL;
|
||||||
macro->identifier = ralloc_strdup (macro, identifier);
|
macro->identifier = linear_strdup(parser->linalloc, identifier);
|
||||||
macro->replacements = replacements;
|
macro->replacements = replacements;
|
||||||
ralloc_steal (macro, replacements);
|
|
||||||
|
|
||||||
entry = _mesa_hash_table_search(parser->defines, identifier);
|
entry = _mesa_hash_table_search(parser->defines, identifier);
|
||||||
previous = entry ? entry->data : NULL;
|
previous = entry ? entry->data : NULL;
|
||||||
if (previous) {
|
if (previous) {
|
||||||
if (_macro_equal (macro, previous)) {
|
if (_macro_equal (macro, previous)) {
|
||||||
ralloc_free (macro);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
|
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
|
||||||
|
|
@ -2137,20 +2117,17 @@ _define_function_macro(glcpp_parser_t *parser, YYLTYPE *loc,
|
||||||
glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"", dup);
|
glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"", dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
macro = ralloc (parser, macro_t);
|
macro = linear_alloc_child(parser->linalloc, sizeof(macro_t));
|
||||||
ralloc_steal (macro, parameters);
|
|
||||||
ralloc_steal (macro, replacements);
|
|
||||||
|
|
||||||
macro->is_function = 1;
|
macro->is_function = 1;
|
||||||
macro->parameters = parameters;
|
macro->parameters = parameters;
|
||||||
macro->identifier = ralloc_strdup (macro, identifier);
|
macro->identifier = linear_strdup(parser->linalloc, identifier);
|
||||||
macro->replacements = replacements;
|
macro->replacements = replacements;
|
||||||
|
|
||||||
entry = _mesa_hash_table_search(parser->defines, identifier);
|
entry = _mesa_hash_table_search(parser->defines, identifier);
|
||||||
previous = entry ? entry->data : NULL;
|
previous = entry ? entry->data : NULL;
|
||||||
if (previous) {
|
if (previous) {
|
||||||
if (_macro_equal (macro, previous)) {
|
if (_macro_equal (macro, previous)) {
|
||||||
ralloc_free (macro);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
|
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
|
||||||
|
|
@ -2217,7 +2194,6 @@ glcpp_parser_lex(YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
|
||||||
node = parser->lex_from_node;
|
node = parser->lex_from_node;
|
||||||
|
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
ralloc_free (parser->lex_from_list);
|
|
||||||
parser->lex_from_list = NULL;
|
parser->lex_from_list = NULL;
|
||||||
return NEWLINE;
|
return NEWLINE;
|
||||||
}
|
}
|
||||||
|
|
@ -2243,16 +2219,13 @@ glcpp_parser_lex_from(glcpp_parser_t *parser, token_list_t *list)
|
||||||
for (node = list->head; node; node = node->next) {
|
for (node = list->head; node; node = node->next) {
|
||||||
if (node->token->type == SPACE)
|
if (node->token->type == SPACE)
|
||||||
continue;
|
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;
|
parser->lex_from_node = parser->lex_from_list->head;
|
||||||
|
|
||||||
/* It's possible the list consisted of nothing but whitespace. */
|
/* It's possible the list consisted of nothing but whitespace. */
|
||||||
if (parser->lex_from_node == NULL) {
|
if (parser->lex_from_node == NULL) {
|
||||||
ralloc_free (parser->lex_from_list);
|
|
||||||
parser->lex_from_list = NULL;
|
parser->lex_from_list = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2267,7 +2240,7 @@ _glcpp_parser_skip_stack_push_if(glcpp_parser_t *parser, YYLTYPE *loc,
|
||||||
if (parser->skip_stack)
|
if (parser->skip_stack)
|
||||||
current = parser->skip_stack->type;
|
current = parser->skip_stack->type;
|
||||||
|
|
||||||
node = ralloc (parser, skip_node_t);
|
node = linear_alloc_child(parser->linalloc, sizeof(skip_node_t));
|
||||||
node->loc = *loc;
|
node->loc = *loc;
|
||||||
|
|
||||||
if (current == SKIP_NO_SKIP) {
|
if (current == SKIP_NO_SKIP) {
|
||||||
|
|
@ -2313,7 +2286,6 @@ _glcpp_parser_skip_stack_pop(glcpp_parser_t *parser, YYLTYPE *loc)
|
||||||
|
|
||||||
node = parser->skip_stack;
|
node = parser->skip_stack;
|
||||||
parser->skip_stack = node->next;
|
parser->skip_stack = node->next;
|
||||||
ralloc_free (node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ typedef void (*glcpp_extension_iterator)(
|
||||||
bool es);
|
bool es);
|
||||||
|
|
||||||
struct glcpp_parser {
|
struct glcpp_parser {
|
||||||
|
void *linalloc;
|
||||||
yyscan_t scanner;
|
yyscan_t scanner;
|
||||||
struct hash_table *defines;
|
struct hash_table *defines;
|
||||||
active_list_t *active;
|
active_list_t *active;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue