Home | History | Annotate | Download | only in glcpp

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)
1077 glcpp_error (&token->location, parser, "");
1078 ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \"");
1079 _token_print (&parser->info_log, &parser->info_log_length, token);
1080 ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" and \"");
1081 _token_print (&parser->info_log, &parser->info_log_length, other);
1082 ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" does not give a valid preprocessing token.\n");
1088 _token_list_print (glcpp_parser_t *parser, token_list_t *list)
1096 _token_print (&parser->output, &parser->output_length, node->token);
1100 yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
1102 glcpp_error(locp, parser, "%s", error);
1105 static void add_builtin_define(glcpp_parser_t *parser,
1111 tok = _token_create_ival (parser, INTEGER, value);
1113 list = _token_list_create(parser);
1115 _define_object_macro(parser, NULL, name, list);
1121 glcpp_parser_t *parser;
1124 parser = ralloc (NULL, glcpp_parser_t);
1126 glcpp_lex_init_extra (parser, &parser->scanner);
1127 parser->defines = hash_table_ctor (32, hash_table_string_hash,
1129 parser->active = NULL;
1130 parser->lexing_if = 0;
1131 parser->space_tokens = 1;
1132 parser->newline_as_space = 0;
1133 parser->in_control_line = 0;
1134 parser->paren_count = 0;
1136 parser->skip_stack = NULL;
1138 parser->lex_from_list = NULL;
1139 parser->lex_from_node = NULL;
1141 parser->output = ralloc_strdup(parser, "");
1142 parser->output_length = 0;
1143 parser->info_log = ralloc_strdup(parser, "");
1144 parser->info_log_length = 0;
1145 parser->error = 0;
1147 parser->has_new_line_number = 0;
1148 parser->new_line_number = 1;
1149 parser->has_new_source_number = 0;
1150 parser->new_source_number = 0;
1153 add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
1154 add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
1157 add_builtin_define(parser, "GL_ES", 1);
1161 add_builtin_define(parser, "GL_EXT_texture_array", 1);
1165 add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
1169 add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
1172 add_builtin_define(parser, "GL_ARB_shader_texture_lod", 1);
1175 add_builtin_define(parser, "GL_ARB_draw_instanced", 1);
1178 add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
1179 add_builtin_define(parser, "GL_ARB_conservative_depth", 1);
1183 add_builtin_define(parser, "GL_OES_EGL_image_external", 1);
1186 add_builtin_define(parser, "GL_ARB_shader_bit_encoding", 1);
1189 add_builtin_define(parser, "GL_ARB_uniform_buffer_object", 1);
1193 add_builtin_define(parser, "__VERSION__", language_version);
1195 return parser;
1199 glcpp_parser_destroy (glcpp_parser_t *parser)
1201 glcpp_lex_destroy (parser->scanner);
1202 hash_table_dtor (parser->defines);
1203 ralloc_free (parser);
1315 _glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
1322 expanded = _token_list_create (parser);
1323 token = _token_create_ival (parser, head_token_type, head_token_type);
1325 _glcpp_parser_expand_token_list (parser, list);
1327 glcpp_parser_lex_from (parser, expanded);
1331 _glcpp_parser_apply_pastes (glcpp_parser_t *parser, token_list_t *list)
1359 yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
1363 node->token = _token_paste (parser, node->token, next_non_space->token);
1390 _glcpp_parser_expand_function (glcpp_parser_t *parser,
1404 macro = hash_table_find (parser->defines, identifier);
1408 arguments = _argument_list_create (parser);
1417 glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
1424 return _token_list_create_with_one_space (parser);
1433 glcpp_error (&node->token->location, parser,
1459 expanded_argument = _token_list_copy (parser,
1461 _glcpp_parser_expand_token_list (parser,
1483 _glcpp_parser_apply_pastes (parser, substituted);
1504 _glcpp_parser_expand_node (glcpp_parser_t *parser,
1527 macro = hash_table_find (parser->defines, identifier);
1535 if (_parser_active_list_contains (parser, identifier)) {
1543 str = ralloc_strdup (parser, token->value.str);
1544 final = _token_create_str (parser, OTHER, str);
1545 expansion = _token_list_create (parser);
1558 return _token_list_create_with_one_space (parser);
1560 replacement = _token_list_copy (parser, macro->replacements);
1561 _glcpp_parser_apply_pastes (parser, replacement);
1565 return _glcpp_parser_expand_function (parser, node, last);
1568 /* Push a new identifier onto the parser's active list.
1576 _parser_active_list_push (glcpp_parser_t *parser,
1582 node = ralloc (parser->active, active_list_t);
1585 node->next = parser->active;
1587 parser->active = node;
1591 _parser_active_list_pop (glcpp_parser_t *parser)
1593 active_list_t *node = parser->active;
1596 parser->active = NULL;
1600 node = parser->active->next;
1601 ralloc_free (parser->active);
1603 parser->active = node;
1607 _parser_active_list_contains (glcpp_parser_t *parser, const char *identifier)
1611 if (parser->active == NULL)
1614 for (node = parser->active; node; node = node->next)
1627 _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
1633 active_list_t *active_initial = parser->active;
1645 while (parser->active && parser->active->marker == node)
1646 _parser_active_list_pop (parser);
1648 expansion = _glcpp_parser_expand_node (parser, node, &last);
1653 while (parser->active &&
1654 parser->active->marker == n)
1656 _parser_active_list_pop (parser);
1659 _parser_active_list_push (parser,
1691 while (parser->active && parser->active != active_initial)
1692 _parser_active_list_pop (parser);
1698 _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
1704 _glcpp_parser_expand_token_list (parser, list);
1708 _token_list_print (parser, list);
1712 _check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
1719 glcpp_error (loc, parser, "Macro names containing \"__\" are reserved.\n");
1722 glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
1742 _define_object_macro (glcpp_parser_t *parser,
1750 _check_for_reserved_macro_name(parser, loc, identifier);
1752 macro = ralloc (parser, macro_t);
1760 previous = hash_table_find (parser->defines, identifier);
1766 glcpp_error (loc, parser, "Redefinition of macro %s\n",
1770 hash_table_insert (parser->defines, macro, identifier);
1774 _define_function_macro (glcpp_parser_t *parser,
1782 _check_for_reserved_macro_name(parser, loc, identifier);
1784 macro = ralloc (parser, macro_t);
1792 previous = hash_table_find (parser->defines, identifier);
1798 glcpp_error (loc, parser, "Redefinition of macro %s\n",
1802 hash_table_insert (parser->defines, macro, identifier);
1806 glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
1811 if (parser->lex_from_list == NULL) {
1812 ret = glcpp_lex (yylval, yylloc, parser->scanner);
1826 if (parser->newline_as_space)
1829 parser->paren_count++;
1831 parser->paren_count--;
1832 if (parser->paren_count == 0)
1833 parser->newline_as_space = 0;
1837 if (parser->paren_count == 0)
1838 parser->newline_as_space = 0;
1841 else if (parser->in_control_line)
1844 parser->in_control_line = 0;
1852 parser->in_control_line = 1;
1857 macro = hash_table_find (parser->defines,
1860 parser->newline_as_space = 1;
1861 parser->paren_count = 0;
1868 node = parser->lex_from_node;
1871 ralloc_free (parser->lex_from_list);
1872 parser->lex_from_list = NULL;
1879 parser->lex_from_node = node->next;
1885 glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
1889 assert (parser->lex_from_list == NULL);
1892 parser->lex_from_list = _token_list_create (parser);
1897 _token_list_append (parser->lex_from_list, node->token);
1902 parser->lex_from_node = parser->lex_from_list->head;
1905 if (parser->lex_from_node == NULL) {
1906 ralloc_free (parser->lex_from_list);
1907 parser->lex_from_list = NULL;
1912 _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
1918 if (parser->skip_stack)
1919 current = parser->skip_stack->type;
1921 node = ralloc (parser, skip_node_t);
1933 node->next = parser->skip_stack;
1934 parser->skip_stack = node;
1938 _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
1941 if (parser->skip_stack == NULL) {
1942 glcpp_error (loc, parser, "%s without #if\n", type);
1946 if (parser->skip_stack->type == SKIP_TO_ELSE) {
1948 parser->skip_stack->type = SKIP_NO_SKIP;
1950 parser->skip_stack->type = SKIP_TO_ENDIF;
1955 _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
1959 if (parser->skip_stack == NULL) {
1960 glcpp_error (loc, parser, "#endif without #if\n");
1964 node = parser->skip_stack;
1965 parser->skip_stack = node->next;