Lines Matching refs:parser
36 yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
39 _define_object_macro (glcpp_parser_t *parser,
45 _define_function_macro (glcpp_parser_t *parser,
98 _parser_active_list_push (glcpp_parser_t *parser,
103 _parser_active_list_pop (glcpp_parser_t *parser);
106 _parser_active_list_contains (glcpp_parser_t *parser, const char *identifier);
112 _glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
118 _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
122 _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
126 _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
130 _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
134 _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
137 glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
140 glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
143 add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
147 %pure-parser
159 %parse-param {glcpp_parser_t *parser}
160 %lex-param {glcpp_parser_t *parser}
191 ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
194 _glcpp_parser_print_expanded_token_list (parser, $1);
195 ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
204 _glcpp_parser_skip_stack_push_if (parser, & @1, $2);
207 _glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2);
210 parser->has_new_line_number = 1;
211 parser->new_line_number = $2;
212 ralloc_asprintf_rewrite_tail (&parser->output,
213 &parser->output_length,
218 parser->has_new_line_number = 1;
219 parser->new_line_number = $2;
220 parser->has_new_source_number = 1;
221 parser->new_source_number = $3;
222 ralloc_asprintf_rewrite_tail (&parser->output,
223 &parser->output_length,
231 _define_object_macro (parser, & @2, $2, $3);
234 _define_function_macro (parser, & @2, $2, NULL, $5);
237 _define_function_macro (parser, & @2, $2, $4, $6);
240 macro_t *macro = hash_table_find (parser->defines, $2);
242 hash_table_remove (parser->defines, $2);
248 if (parser->skip_stack == NULL ||
249 parser->skip_stack->type == SKIP_NO_SKIP)
251 _glcpp_parser_expand_and_lex_from (parser,
263 if (parser->skip_stack == NULL ||
264 parser->skip_stack->type == SKIP_NO_SKIP)
266 _glcpp_parser_expand_and_lex_from (parser,
271 _glcpp_parser_skip_stack_push_if (parser, & @1, 0);
272 parser->skip_stack->type = SKIP_TO_ENDIF;
278 if (parser->skip_stack == NULL ||
279 parser->skip_stack->type == SKIP_NO_SKIP)
281 glcpp_error(& @1, parser, "#if with no expression");
283 _glcpp_parser_skip_stack_push_if (parser, & @1, 0);
286 macro_t *macro = hash_table_find (parser->defines, $2);
288 _glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
291 macro_t *macro = hash_table_find (parser->defines, $2);
293 _glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL);
303 if (parser->skip_stack &&
304 parser->skip_stack->type == SKIP_TO_ELSE)
306 _glcpp_parser_expand_and_lex_from (parser,
311 _glcpp_parser_skip_stack_change_if (parser, & @1,
318 if (parser->skip_stack &&
319 parser->skip_stack->type == SKIP_TO_ELSE)
321 glcpp_error(& @1, parser, "#elif with no expression");
325 _glcpp_parser_skip_stack_change_if (parser, & @1,
327 glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
331 _glcpp_parser_skip_stack_change_if (parser, & @1, "else", 1);
334 _glcpp_parser_skip_stack_pop (parser, & @1);
337 macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
339 hash_table_remove (parser->defines, "__VERSION__");
342 add_builtin_define (parser, "__VERSION__", $2);
345 add_builtin_define (parser, "GL_ES", 1);
353 add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
355 ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "#version %" PRIiMAX, $2);
426 yyerror (& @1, parser,
434 yyerror (& @1, parser,
462 $$ = _string_list_create (parser);
480 yyerror (& @1, parser, "Invalid tokens after #");
492 glcpp_warning(&@1, parser, "extra tokens at end of directive");
499 int v = hash_table_find (parser->defines, $2) ? 1 : 0;
500 $$ = _token_create_ival (parser, INTEGER, v);
503 int v = hash_table_find (parser->defines, $3) ? 1 : 0;
504 $$ = _token_create_ival (parser, INTEGER, v);
512 $$ = _token_list_create (parser);
523 parser->space_tokens = 1;
524 $$ = _token_list_create (parser);
535 $$ = _token_create_str (parser, IDENTIFIER, $1);
539 $$ = _token_create_str (parser, INTEGER_STRING, $1);
543 $$ = _token_create_ival (parser, $1, $1);
547 $$ = _token_create_str (parser, OTHER, $1);
551 $$ = _token_create_ival (parser, SPACE, SPACE);
1006 _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other) in _token_paste() argument
1077 glcpp_error (&token->location, parser, ""); in _token_paste()
1078 ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \""); in _token_paste()
1079 _token_print (&parser->info_log, &parser->info_log_length, token); in _token_paste()
1080 ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" and \""); in _token_paste()
1081 _token_print (&parser->info_log, &parser->info_log_length, other); in _token_paste()
1082 …ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" does not give a val… in _token_paste()
1088 _token_list_print (glcpp_parser_t *parser, token_list_t *list) in _token_list_print() argument
1096 _token_print (&parser->output, &parser->output_length, node->token); in _token_list_print()
1100 yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error) in yyerror() argument
1102 glcpp_error(locp, parser, "%s", error); in yyerror()
1105 static void add_builtin_define(glcpp_parser_t *parser, in add_builtin_define() argument
1111 tok = _token_create_ival (parser, INTEGER, value); in add_builtin_define()
1113 list = _token_list_create(parser); in add_builtin_define()
1115 _define_object_macro(parser, NULL, name, list); in add_builtin_define()
1121 glcpp_parser_t *parser; in glcpp_parser_create() local
1124 parser = ralloc (NULL, glcpp_parser_t); in glcpp_parser_create()
1126 glcpp_lex_init_extra (parser, &parser->scanner); in glcpp_parser_create()
1127 parser->defines = hash_table_ctor (32, hash_table_string_hash, in glcpp_parser_create()
1129 parser->active = NULL; in glcpp_parser_create()
1130 parser->lexing_if = 0; in glcpp_parser_create()
1131 parser->space_tokens = 1; in glcpp_parser_create()
1132 parser->newline_as_space = 0; in glcpp_parser_create()
1133 parser->in_control_line = 0; in glcpp_parser_create()
1134 parser->paren_count = 0; in glcpp_parser_create()
1136 parser->skip_stack = NULL; in glcpp_parser_create()
1138 parser->lex_from_list = NULL; in glcpp_parser_create()
1139 parser->lex_from_node = NULL; in glcpp_parser_create()
1141 parser->output = ralloc_strdup(parser, ""); in glcpp_parser_create()
1142 parser->output_length = 0; in glcpp_parser_create()
1143 parser->info_log = ralloc_strdup(parser, ""); in glcpp_parser_create()
1144 parser->info_log_length = 0; in glcpp_parser_create()
1145 parser->error = 0; in glcpp_parser_create()
1147 parser->has_new_line_number = 0; in glcpp_parser_create()
1148 parser->new_line_number = 1; in glcpp_parser_create()
1149 parser->has_new_source_number = 0; in glcpp_parser_create()
1150 parser->new_source_number = 0; in glcpp_parser_create()
1153 add_builtin_define(parser, "GL_ARB_draw_buffers", 1); in glcpp_parser_create()
1154 add_builtin_define(parser, "GL_ARB_texture_rectangle", 1); in glcpp_parser_create()
1157 add_builtin_define(parser, "GL_ES", 1); in glcpp_parser_create()
1161 add_builtin_define(parser, "GL_EXT_texture_array", 1); in glcpp_parser_create()
1165 add_builtin_define(parser, "GL_ARB_fragment_coord_conventions", in glcpp_parser_create()
1169 add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1); in glcpp_parser_create()
1172 add_builtin_define(parser, "GL_ARB_shader_texture_lod", 1); in glcpp_parser_create()
1175 add_builtin_define(parser, "GL_ARB_draw_instanced", 1); in glcpp_parser_create()
1178 add_builtin_define(parser, "GL_AMD_conservative_depth", 1); in glcpp_parser_create()
1179 add_builtin_define(parser, "GL_ARB_conservative_depth", 1); in glcpp_parser_create()
1183 add_builtin_define(parser, "GL_OES_EGL_image_external", 1); in glcpp_parser_create()
1186 add_builtin_define(parser, "GL_ARB_shader_bit_encoding", 1); in glcpp_parser_create()
1189 add_builtin_define(parser, "GL_ARB_uniform_buffer_object", 1); in glcpp_parser_create()
1193 add_builtin_define(parser, "__VERSION__", language_version); in glcpp_parser_create()
1195 return parser; in glcpp_parser_create()
1199 glcpp_parser_destroy (glcpp_parser_t *parser) in glcpp_parser_destroy() argument
1201 glcpp_lex_destroy (parser->scanner); in glcpp_parser_destroy()
1202 hash_table_dtor (parser->defines); in glcpp_parser_destroy()
1203 ralloc_free (parser); in glcpp_parser_destroy()
1315 _glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser, in _glcpp_parser_expand_and_lex_from() argument
1322 expanded = _token_list_create (parser); in _glcpp_parser_expand_and_lex_from()
1323 token = _token_create_ival (parser, head_token_type, head_token_type); in _glcpp_parser_expand_and_lex_from()
1325 _glcpp_parser_expand_token_list (parser, list); in _glcpp_parser_expand_and_lex_from()
1327 glcpp_parser_lex_from (parser, expanded); in _glcpp_parser_expand_and_lex_from()
1331 _glcpp_parser_apply_pastes (glcpp_parser_t *parser, token_list_t *list) in _glcpp_parser_apply_pastes() argument
1359 …yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n"… in _glcpp_parser_apply_pastes()
1363 node->token = _token_paste (parser, node->token, next_non_space->token); in _glcpp_parser_apply_pastes()
1390 _glcpp_parser_expand_function (glcpp_parser_t *parser, in _glcpp_parser_expand_function() argument
1404 macro = hash_table_find (parser->defines, identifier); in _glcpp_parser_expand_function()
1408 arguments = _argument_list_create (parser); in _glcpp_parser_expand_function()
1417 …glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identif… in _glcpp_parser_expand_function()
1424 return _token_list_create_with_one_space (parser); in _glcpp_parser_expand_function()
1433 glcpp_error (&node->token->location, parser, in _glcpp_parser_expand_function()
1459 expanded_argument = _token_list_copy (parser, in _glcpp_parser_expand_function()
1461 _glcpp_parser_expand_token_list (parser, in _glcpp_parser_expand_function()
1483 _glcpp_parser_apply_pastes (parser, substituted); in _glcpp_parser_expand_function()
1504 _glcpp_parser_expand_node (glcpp_parser_t *parser, in _glcpp_parser_expand_node() argument
1527 macro = hash_table_find (parser->defines, identifier); in _glcpp_parser_expand_node()
1535 if (_parser_active_list_contains (parser, identifier)) { in _glcpp_parser_expand_node()
1543 str = ralloc_strdup (parser, token->value.str); in _glcpp_parser_expand_node()
1544 final = _token_create_str (parser, OTHER, str); in _glcpp_parser_expand_node()
1545 expansion = _token_list_create (parser); in _glcpp_parser_expand_node()
1558 return _token_list_create_with_one_space (parser); in _glcpp_parser_expand_node()
1560 replacement = _token_list_copy (parser, macro->replacements); in _glcpp_parser_expand_node()
1561 _glcpp_parser_apply_pastes (parser, replacement); in _glcpp_parser_expand_node()
1565 return _glcpp_parser_expand_function (parser, node, last); in _glcpp_parser_expand_node()
1576 _parser_active_list_push (glcpp_parser_t *parser, in _parser_active_list_push() argument
1582 node = ralloc (parser->active, active_list_t); in _parser_active_list_push()
1585 node->next = parser->active; in _parser_active_list_push()
1587 parser->active = node; in _parser_active_list_push()
1591 _parser_active_list_pop (glcpp_parser_t *parser) in _parser_active_list_pop() argument
1593 active_list_t *node = parser->active; in _parser_active_list_pop()
1596 parser->active = NULL; in _parser_active_list_pop()
1600 node = parser->active->next; in _parser_active_list_pop()
1601 ralloc_free (parser->active); in _parser_active_list_pop()
1603 parser->active = node; in _parser_active_list_pop()
1607 _parser_active_list_contains (glcpp_parser_t *parser, const char *identifier) in _parser_active_list_contains() argument
1611 if (parser->active == NULL) in _parser_active_list_contains()
1614 for (node = parser->active; node; node = node->next) in _parser_active_list_contains()
1627 _glcpp_parser_expand_token_list (glcpp_parser_t *parser, in _glcpp_parser_expand_token_list() argument
1633 active_list_t *active_initial = parser->active; in _glcpp_parser_expand_token_list()
1645 while (parser->active && parser->active->marker == node) in _glcpp_parser_expand_token_list()
1646 _parser_active_list_pop (parser); in _glcpp_parser_expand_token_list()
1648 expansion = _glcpp_parser_expand_node (parser, node, &last); in _glcpp_parser_expand_token_list()
1653 while (parser->active && in _glcpp_parser_expand_token_list()
1654 parser->active->marker == n) in _glcpp_parser_expand_token_list()
1656 _parser_active_list_pop (parser); in _glcpp_parser_expand_token_list()
1659 _parser_active_list_push (parser, in _glcpp_parser_expand_token_list()
1691 while (parser->active && parser->active != active_initial) in _glcpp_parser_expand_token_list()
1692 _parser_active_list_pop (parser); in _glcpp_parser_expand_token_list()
1698 _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, in _glcpp_parser_print_expanded_token_list() argument
1704 _glcpp_parser_expand_token_list (parser, list); in _glcpp_parser_print_expanded_token_list()
1708 _token_list_print (parser, list); in _glcpp_parser_print_expanded_token_list()
1712 _check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc, in _check_for_reserved_macro_name() argument
1719 glcpp_error (loc, parser, "Macro names containing \"__\" are reserved.\n"); in _check_for_reserved_macro_name()
1722 glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n"); in _check_for_reserved_macro_name()
1742 _define_object_macro (glcpp_parser_t *parser, in _define_object_macro() argument
1750 _check_for_reserved_macro_name(parser, loc, identifier); in _define_object_macro()
1752 macro = ralloc (parser, macro_t); in _define_object_macro()
1760 previous = hash_table_find (parser->defines, identifier); in _define_object_macro()
1766 glcpp_error (loc, parser, "Redefinition of macro %s\n", in _define_object_macro()
1770 hash_table_insert (parser->defines, macro, identifier); in _define_object_macro()
1774 _define_function_macro (glcpp_parser_t *parser, in _define_function_macro() argument
1782 _check_for_reserved_macro_name(parser, loc, identifier); in _define_function_macro()
1784 macro = ralloc (parser, macro_t); in _define_function_macro()
1792 previous = hash_table_find (parser->defines, identifier); in _define_function_macro()
1798 glcpp_error (loc, parser, "Redefinition of macro %s\n", in _define_function_macro()
1802 hash_table_insert (parser->defines, macro, identifier); in _define_function_macro()
1806 glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser) in glcpp_parser_lex() argument
1811 if (parser->lex_from_list == NULL) { in glcpp_parser_lex()
1812 ret = glcpp_lex (yylval, yylloc, parser->scanner); in glcpp_parser_lex()
1826 if (parser->newline_as_space) in glcpp_parser_lex()
1829 parser->paren_count++; in glcpp_parser_lex()
1831 parser->paren_count--; in glcpp_parser_lex()
1832 if (parser->paren_count == 0) in glcpp_parser_lex()
1833 parser->newline_as_space = 0; in glcpp_parser_lex()
1837 if (parser->paren_count == 0) in glcpp_parser_lex()
1838 parser->newline_as_space = 0; in glcpp_parser_lex()
1841 else if (parser->in_control_line) in glcpp_parser_lex()
1844 parser->in_control_line = 0; in glcpp_parser_lex()
1852 parser->in_control_line = 1; in glcpp_parser_lex()
1857 macro = hash_table_find (parser->defines, in glcpp_parser_lex()
1860 parser->newline_as_space = 1; in glcpp_parser_lex()
1861 parser->paren_count = 0; in glcpp_parser_lex()
1868 node = parser->lex_from_node; in glcpp_parser_lex()
1871 ralloc_free (parser->lex_from_list); in glcpp_parser_lex()
1872 parser->lex_from_list = NULL; in glcpp_parser_lex()
1879 parser->lex_from_node = node->next; in glcpp_parser_lex()
1885 glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list) in glcpp_parser_lex_from() argument
1889 assert (parser->lex_from_list == NULL); in glcpp_parser_lex_from()
1892 parser->lex_from_list = _token_list_create (parser); in glcpp_parser_lex_from()
1897 _token_list_append (parser->lex_from_list, node->token); in glcpp_parser_lex_from()
1902 parser->lex_from_node = parser->lex_from_list->head; in glcpp_parser_lex_from()
1905 if (parser->lex_from_node == NULL) { in glcpp_parser_lex_from()
1906 ralloc_free (parser->lex_from_list); in glcpp_parser_lex_from()
1907 parser->lex_from_list = NULL; in glcpp_parser_lex_from()
1912 _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, in _glcpp_parser_skip_stack_push_if() argument
1918 if (parser->skip_stack) in _glcpp_parser_skip_stack_push_if()
1919 current = parser->skip_stack->type; in _glcpp_parser_skip_stack_push_if()
1921 node = ralloc (parser, skip_node_t); in _glcpp_parser_skip_stack_push_if()
1933 node->next = parser->skip_stack; in _glcpp_parser_skip_stack_push_if()
1934 parser->skip_stack = node; in _glcpp_parser_skip_stack_push_if()
1938 _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, in _glcpp_parser_skip_stack_change_if() argument
1941 if (parser->skip_stack == NULL) { in _glcpp_parser_skip_stack_change_if()
1942 glcpp_error (loc, parser, "%s without #if\n", type); in _glcpp_parser_skip_stack_change_if()
1946 if (parser->skip_stack->type == SKIP_TO_ELSE) { in _glcpp_parser_skip_stack_change_if()
1948 parser->skip_stack->type = SKIP_NO_SKIP; in _glcpp_parser_skip_stack_change_if()
1950 parser->skip_stack->type = SKIP_TO_ENDIF; in _glcpp_parser_skip_stack_change_if()
1955 _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc) in _glcpp_parser_skip_stack_pop() argument
1959 if (parser->skip_stack == NULL) { in _glcpp_parser_skip_stack_pop()
1960 glcpp_error (loc, parser, "#endif without #if\n"); in _glcpp_parser_skip_stack_pop()
1964 node = parser->skip_stack; in _glcpp_parser_skip_stack_pop()
1965 parser->skip_stack = node->next; in _glcpp_parser_skip_stack_pop()