glsl: remove tabs and fix some other style issues in glcpp-parse.y

Note there are still tabs left in the parser rules.

Acked-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Timothy Arceri
2016-03-31 16:49:59 +11:00
parent 14c46954c9
commit 5ea825f556

View File

@@ -98,8 +98,7 @@ static int
_token_list_equal_ignoring_space(token_list_t *a, token_list_t *b);
static void
_parser_active_list_push (glcpp_parser_t *parser,
const char *identifier,
_parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
token_node_t *marker);
static void
@@ -117,15 +116,12 @@ typedef enum {
* prefixing a token of type 'head_token_type').
*/
static void
_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
int head_token_type,
token_list_t *list,
expansion_mode_t mode);
_glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
token_list_t *list, expansion_mode_t mode);
/* Perform macro expansion in-place on the given list. */
static void
_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
token_list_t *list,
_glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
expansion_mode_t mode);
static void
@@ -1060,8 +1056,7 @@ _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
* It need not be exactly the same amount of whitespace,
* though.
*/
if (node_a->token->type == SPACE
&& node_b->token->type == SPACE) {
if (node_a->token->type == SPACE && node_b->token->type == SPACE) {
while (node_a && node_a->token->type == SPACE)
node_a = node_a->next;
while (node_b && node_b->token->type == SPACE)
@@ -1074,18 +1069,14 @@ _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
switch (node_a->token->type) {
case INTEGER:
if (node_a->token->value.ival !=
node_b->token->value.ival)
{
if (node_a->token->value.ival != node_b->token->value.ival) {
return 0;
}
break;
case IDENTIFIER:
case INTEGER_STRING:
case OTHER:
if (strcmp (node_a->token->value.str,
node_b->token->value.str))
{
if (strcmp(node_a->token->value.str, node_b->token->value.str)) {
return 0;
}
break;
@@ -1240,12 +1231,10 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
/* Check that pasting onto an integer doesn't create a
* non-integer, (that is, only digits can be
* pasted. */
if (token->type == INTEGER_STRING || token->type == INTEGER)
{
if (token->type == INTEGER_STRING || token->type == INTEGER) {
switch (other->type) {
case INTEGER_STRING:
if (other->value.str[0] < '0' ||
other->value.str[0] > '9')
if (other->value.str[0] < '0' || other->value.str[0] > '9')
goto FAIL;
break;
case INTEGER:
@@ -1258,15 +1247,12 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
}
if (token->type == INTEGER)
str = ralloc_asprintf (token, "%" PRIiMAX,
token->value.ival);
str = ralloc_asprintf (token, "%" PRIiMAX, token->value.ival);
else
str = ralloc_strdup (token, token->value.str);
if (other->type == INTEGER)
ralloc_asprintf_append (&str, "%" PRIiMAX,
other->value.ival);
ralloc_asprintf_append (&str, "%" PRIiMAX, other->value.ival);
else
ralloc_strcat (&str, other->value.str);
@@ -1311,8 +1297,8 @@ yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
glcpp_error(locp, parser, "%s", error);
}
static void add_builtin_define(glcpp_parser_t *parser,
const char *name, int value)
static void
add_builtin_define(glcpp_parser_t *parser, const char *name, int value)
{
token_t *tok;
token_list_t *list;
@@ -1408,8 +1394,7 @@ typedef enum function_status
* 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(argument_list_t *arguments, token_node_t *node,
token_node_t **last)
{
token_list_t *argument;
@@ -1430,28 +1415,21 @@ _arguments_parse (argument_list_t *arguments,
_argument_list_append (arguments, argument);
for (paren_count = 1; node; node = node->next) {
if (node->token->type == '(')
{
if (node->token->type == '(') {
paren_count++;
}
else if (node->token->type == ')')
{
} else if (node->token->type == ')') {
paren_count--;
if (paren_count == 0)
break;
}
if (node->token->type == ',' &&
paren_count == 1)
{
if (node->token->type == ',' && paren_count == 1) {
_token_list_trim_trailing_space (argument);
argument = _token_list_create (arguments);
_argument_list_append (arguments, argument);
}
else {
} else {
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)
continue;
}
@@ -1514,8 +1492,7 @@ _token_list_create_with_one_integer (void *ctx, int ival)
* preprocessor error, returns -1 and *last will not be set.
*/
static int
_glcpp_parser_evaluate_defined (glcpp_parser_t *parser,
token_node_t *node,
_glcpp_parser_evaluate_defined(glcpp_parser_t *parser, token_node_t *node,
token_node_t **last)
{
token_node_t *argument, *defined = node;
@@ -1541,8 +1518,7 @@ _glcpp_parser_evaluate_defined (glcpp_parser_t *parser,
node = node->next;
if (node == NULL || (node->token->type != IDENTIFIER &&
node->token->type != OTHER))
{
node->token->type != OTHER)) {
goto FAIL;
}
@@ -1625,10 +1601,8 @@ _glcpp_parser_evaluate_defined_in_list (glcpp_parser_t *parser,
* of the "mode" parameter.
*/
static void
_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
int head_token_type,
token_list_t *list,
expansion_mode_t mode)
_glcpp_parser_expand_and_lex_from(glcpp_parser_t *parser, int head_token_type,
token_list_t *list, expansion_mode_t mode)
{
token_list_t *expanded;
token_t *token;
@@ -1647,8 +1621,7 @@ _glcpp_parser_apply_pastes (glcpp_parser_t *parser, token_list_t *list)
token_node_t *node;
node = list->head;
while (node)
{
while (node) {
token_node_t *next_non_space;
/* Look ahead for a PASTE token, skipping space. */
@@ -1704,10 +1677,8 @@ _glcpp_parser_apply_pastes (glcpp_parser_t *parser, token_list_t *list)
* of the "mode" parameter.
*/
static token_list_t *
_glcpp_parser_expand_function (glcpp_parser_t *parser,
token_node_t *node,
token_node_t **last,
expansion_mode_t mode)
_glcpp_parser_expand_function(glcpp_parser_t *parser, token_node_t *node,
token_node_t **last, expansion_mode_t mode)
{
macro_t *macro;
const char *identifier;
@@ -1745,12 +1716,10 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
_string_list_length (macro->parameters)) ||
(_string_list_length (macro->parameters) == 0 &&
_argument_list_length (arguments) == 1 &&
arguments->head->argument->head == NULL)))
{
arguments->head->argument->head == NULL))) {
glcpp_error(&node->token->location, parser,
"Error: macro %s invoked with %d arguments (expected %d)\n",
identifier,
_argument_list_length (arguments),
identifier, _argument_list_length (arguments),
_string_list_length(macro->parameters));
return NULL;
}
@@ -1758,33 +1727,23 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
/* Perform argument substitution on the replacement list. */
substituted = _token_list_create(arguments);
for (node = macro->replacements->head; node; node = node->next)
{
for (node = macro->replacements->head; node; node = node->next) {
if (node->token->type == IDENTIFIER &&
_string_list_contains (macro->parameters,
node->token->value.str,
&parameter_index))
{
_string_list_contains(macro->parameters, node->token->value.str,
&parameter_index)) {
token_list_t *argument;
argument = _argument_list_member_at (arguments,
parameter_index);
/* Before substituting, we expand the argument
* tokens, or append a placeholder token for
* an empty argument. */
argument = _argument_list_member_at(arguments, parameter_index);
/* Before substituting, we expand the argument tokens, or append a
* placeholder token for an empty argument. */
if (argument->head) {
token_list_t *expanded_argument;
expanded_argument = _token_list_copy (parser,
argument);
_glcpp_parser_expand_token_list (parser,
expanded_argument,
mode);
_token_list_append_list (substituted,
expanded_argument);
expanded_argument = _token_list_copy(parser, argument);
_glcpp_parser_expand_token_list(parser, expanded_argument, mode);
_token_list_append_list(substituted, expanded_argument);
} else {
token_t *new_token;
new_token = _token_create_ival (substituted,
PLACEHOLDER,
new_token = _token_create_ival(substituted, PLACEHOLDER,
PLACEHOLDER);
_token_list_append(substituted, new_token);
}
@@ -1822,10 +1781,8 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
* of the "mode" parameter.
*/
static token_list_t *
_glcpp_parser_expand_node (glcpp_parser_t *parser,
token_node_t *node,
token_node_t **last,
expansion_mode_t mode)
_glcpp_parser_expand_node(glcpp_parser_t *parser, token_node_t *node,
token_node_t **last, expansion_mode_t mode)
{
token_t *token = node->token;
const char *identifier;
@@ -1857,9 +1814,8 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
/* Finally, don't expand this macro if we're already actively
* expanding it, (to avoid infinite recursion). */
if (_parser_active_list_contains (parser, identifier)) {
/* We change the token type here from IDENTIFIER to
* OTHER to prevent any future expansion of this
* unexpanded token. */
/* We change the token type here from IDENTIFIER to OTHER to prevent any
* future expansion of this unexpanded token. */
char *str;
token_list_t *expansion;
token_t *final;
@@ -1871,8 +1827,7 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
return expansion;
}
if (! macro->is_function)
{
if (! macro->is_function) {
token_list_t *replacement;
/* Replace a macro defined as empty with a SPACE token. */
@@ -1895,8 +1850,7 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
* active stack.
*/
static void
_parser_active_list_push (glcpp_parser_t *parser,
const char *identifier,
_parser_active_list_push(glcpp_parser_t *parser, const char *identifier,
token_node_t *marker)
{
active_list_t *node;
@@ -1962,8 +1916,7 @@ _parser_active_list_contains (glcpp_parser_t *parser, const char *identifier)
* conditional, (#if or #elif).
*/
static void
_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
token_list_t *list,
_glcpp_parser_expand_token_list(glcpp_parser_t *parser, token_list_t *list,
expansion_mode_t mode)
{
token_node_t *node_prev;
@@ -1992,24 +1945,19 @@ _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
token_node_t *n;
if (mode == EXPANSION_MODE_EVALUATE_DEFINED) {
_glcpp_parser_evaluate_defined_in_list (parser,
expansion);
_glcpp_parser_evaluate_defined_in_list (parser, expansion);
}
for (n = node; n != last->next; n = n->next)
while (parser->active &&
parser->active->marker == n)
{
while (parser->active && parser->active->marker == n) {
_parser_active_list_pop (parser);
}
_parser_active_list_push (parser,
node->token->value.str,
last->next);
_parser_active_list_push(parser, node->token->value.str, last->next);
/* Splice expansion into list, supporting a
* simple deletion if the expansion is
* empty. */
/* Splice expansion into list, supporting a simple deletion if the
* expansion is empty.
*/
if (expansion->head) {
if (node_prev)
node_prev->next = expansion->head;
@@ -2077,8 +2025,7 @@ _check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
* A future version of the GLSL specification will clarify this.
*/
if (strstr(identifier, "__")) {
glcpp_warning(loc, parser,
"Macro names containing \"__\" are reserved "
glcpp_warning(loc, parser, "Macro names containing \"__\" are reserved "
"for use by the implementation.\n");
}
if (strncmp(identifier, "GL_", 3) == 0) {
@@ -2100,22 +2047,18 @@ _macro_equal (macro_t *a, macro_t *b)
return 0;
}
return _token_list_equal_ignoring_space (a->replacements,
b->replacements);
return _token_list_equal_ignoring_space(a->replacements, b->replacements);
}
void
_define_object_macro (glcpp_parser_t *parser,
YYLTYPE *loc,
const char *identifier,
token_list_t *replacements)
_define_object_macro(glcpp_parser_t *parser, YYLTYPE *loc,
const char *identifier, token_list_t *replacements)
{
macro_t *macro, *previous;
/* We define pre-defined macros before we've started parsing the
* actual file. So if there's no location defined yet, that's what
* were doing and we don't want to generate an error for using the
* reserved names. */
/* We define pre-defined macros before we've started parsing the actual
* file. So if there's no location defined yet, that's what were doing and
* we don't want to generate an error for using the reserved names. */
if (loc != NULL)
_check_for_reserved_macro_name(parser, loc, identifier);
@@ -2133,18 +2076,15 @@ _define_object_macro (glcpp_parser_t *parser,
ralloc_free (macro);
return;
}
glcpp_error (loc, parser, "Redefinition of macro %s\n",
identifier);
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
}
hash_table_insert (parser->defines, macro, identifier);
}
void
_define_function_macro (glcpp_parser_t *parser,
YYLTYPE *loc,
const char *identifier,
string_list_t *parameters,
_define_function_macro(glcpp_parser_t *parser, YYLTYPE *loc,
const char *identifier, string_list_t *parameters,
token_list_t *replacements)
{
macro_t *macro, *previous;
@@ -2154,8 +2094,7 @@ _define_function_macro (glcpp_parser_t *parser,
/* Check for any duplicate parameter names. */
if ((dup = _string_list_has_duplicate (parameters)) != NULL) {
glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"",
dup);
glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"", dup);
}
macro = ralloc (parser, macro_t);
@@ -2172,8 +2111,7 @@ _define_function_macro (glcpp_parser_t *parser,
ralloc_free (macro);
return;
}
glcpp_error (loc, parser, "Redefinition of macro %s\n",
identifier);
glcpp_error (loc, parser, "Redefinition of macro %s\n", identifier);
}
hash_table_insert(parser->defines, macro, identifier);
@@ -2200,8 +2138,7 @@ glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
* I'm definitely not pleased with the complexity of
* this code here.
*/
if (parser->newline_as_space)
{
if (parser->newline_as_space) {
if (ret == '(') {
parser->paren_count++;
} else if (ret == ')') {
@@ -2214,22 +2151,15 @@ glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
if (parser->paren_count == 0)
parser->newline_as_space = 0;
}
}
else if (parser->in_control_line)
{
} else if (parser->in_control_line) {
if (ret == NEWLINE)
parser->in_control_line = 0;
}
else if (ret == DEFINE_TOKEN ||
ret == UNDEF || ret == IF ||
ret == IFDEF || ret == IFNDEF ||
ret == ELIF || ret == ELSE ||
ret == ENDIF || ret == HASH_TOKEN)
{
else if (ret == DEFINE_TOKEN || ret == UNDEF || ret == IF ||
ret == IFDEF || ret == IFNDEF || ret == ELIF || ret == ELSE ||
ret == ENDIF || ret == HASH_TOKEN) {
parser->in_control_line = 1;
}
else if (ret == IDENTIFIER)
{
} else if (ret == IDENTIFIER) {
macro_t *macro;
macro = hash_table_find (parser->defines,
yylval->str);
@@ -2359,8 +2289,7 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
add_builtin_define (parser, "__VERSION__", version);
parser->is_gles = (version == 100) ||
(es_identifier &&
(strcmp(es_identifier, "es") == 0));
(es_identifier && (strcmp(es_identifier, "es") == 0));
/* Add pre-defined macros. */
if (parser->is_gles) {
@@ -2407,7 +2336,6 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
add_builtin_define(parser, "GL_AMD_shader_trinary_minmax", 1);
if (extensions != NULL) {
if (extensions->EXT_texture_array)
add_builtin_define(parser, "GL_EXT_texture_array", 1);
@@ -2415,9 +2343,10 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
if (extensions->ARB_arrays_of_arrays)
add_builtin_define(parser, "GL_ARB_arrays_of_arrays", 1);
if (extensions->ARB_fragment_coord_conventions)
if (extensions->ARB_fragment_coord_conventions) {
add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
1);
}
if (extensions->ARB_fragment_layer_viewport)
add_builtin_define(parser, "GL_ARB_fragment_layer_viewport", 1);
@@ -2565,8 +2494,7 @@ void
glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser)
{
int language_version = parser->api == API_OPENGLES2 ?
IMPLICIT_GLSL_ES_VERSION :
IMPLICIT_GLSL_VERSION;
IMPLICIT_GLSL_ES_VERSION : IMPLICIT_GLSL_VERSION;
_glcpp_parser_handle_version_declaration(parser, language_version,
NULL, false);