gcc/gcc/gengtype-lex.l

362 lines
8.7 KiB
Plaintext
Raw Normal View History

/* -*- indented-text -*- */
/* Process source files and output type information.
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
2005-06-25 04:02:01 +02:00
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA. */
%{
#include "bconfig.h"
#include "system.h"
#define malloc xmalloc
#define realloc xrealloc
#include "gengtype.h"
#include "gengtype-yacc.h"
struct fileloc lexer_line;
int lexer_toplevel_done;
static void
update_lineno (const char *l, size_t len)
{
while (len-- > 0)
if (*l++ == '\n')
lexer_line.line++;
}
%}
ID [[:alpha:]_][[:alnum:]_]*
WS [[:space:]]+
IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD
ITYPE {IWORD}({WS}{IWORD})*
%x in_struct in_struct_comment in_comment
%option warn noyywrap nounput nodefault perf-report
%option 8bit never-interactive
%%
[^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
char *tagstart;
size_t taglen;
char *namestart;
size_t namelen;
int is_pointer = 0;
struct type *t;
int union_p;
tagstart = yytext + strlen (" typedef ");
while (ISSPACE (*tagstart))
tagstart++;
union_p = tagstart[0] == 'u';
tagstart += strlen ("union ");
while (ISSPACE (*tagstart))
tagstart++;
for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
;
for (namestart = tagstart + taglen;
! ISIDNUM (*namestart);
namestart++)
if (*namestart == '*')
is_pointer = 1;
for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
;
t = find_structure ((const char *) xmemdup (tagstart, taglen, taglen+1),
union_p);
if (is_pointer)
t = create_pointer (t);
namestart = (char *) xmemdup (namestart, namelen, namelen+1);
#ifdef USE_MAPPED_LOCATION
/* temporary kludge - gentype doesn't handle cpp conditionals */
if (strcmp (namestart, "location_t") != 0
&& strcmp (namestart, "expanded_location") != 0)
#endif
do_typedef (namestart, t, &lexer_line);
update_lineno (yytext, yyleng);
}
[^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
char *namestart;
size_t namelen;
char *typestart;
size_t typelen;
for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
;
for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
;
namestart -= namelen - 1;
for (typestart = yytext + strlen (" typedef ");
ISSPACE(*typestart);
typestart++)
;
for (typelen = namestart - typestart;
ISSPACE (typestart[typelen-1]);
typelen--)
;
typestart[typelen] = '\0';
do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1),
create_scalar_type (typestart),
&lexer_line);
update_lineno (yytext, yyleng);
}
[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}"(" {
char *namestart;
size_t namelen;
for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
;
for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
;
namestart -= namelen - 1;
do_scalar_typedef ((const char *) xmemdup (namestart, namelen, namelen+1),
&lexer_line);
update_lineno (yytext, yyleng);
}
[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?"(" {
char *namestart;
size_t namelen;
for (namestart = yytext + yyleng - 2; !ISIDNUM (*namestart); namestart--)
;
for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
;
namestart -= namelen - 1;
do_scalar_typedef ((const char *) xmemdup (namestart, namelen, namelen+1),
&lexer_line);
update_lineno (yytext, yyleng);
}
[^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
char *tagstart;
size_t taglen;
int typedef_p;
int union_p;
typedef_p = yytext[1] == 't';
if (typedef_p)
for (tagstart = yytext + strlen (" typedef ");
ISSPACE(*tagstart);
tagstart++)
;
else
tagstart = yytext + 1;
union_p = tagstart[0] == 'u';
tagstart += strlen ("union ");
while (ISSPACE (*tagstart))
tagstart++;
for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
;
yylval.s = (const char *) xmemdup (tagstart, taglen, taglen + 1);
BEGIN(in_struct);
update_lineno (yytext, yyleng);
return union_p ? (typedef_p ? ENT_TYPEDEF_UNION : ENT_UNION)
: (typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT);
}
[^[:alnum:]_](extern|static){WS}/"GTY" {
BEGIN(in_struct);
update_lineno (yytext, yyleng);
return ENT_EXTERNSTATIC;
}
^"DEF_VEC_"[IPO]{WS}?"("{WS}?{ID}{WS}?")" {
/* Definition of a generic VEC structure. If the letter after
DEF_VEC_ is "I", the structure definition is slightly different
than if it is "P" or "O". */
char *p = yytext + sizeof("DEF_VEC_") - 1;
char *q;
const char *type;
bool is_I = (*p == 'I');
/* Extract the argument to the macro. */
p++;
while (!ISALNUM(*p) && *p != '_')
p++;
q = p;
while (ISALNUM(*q) || *q == '_')
++;
type = xmemdup (p, q - p, q - p + 1);
note_def_vec (type, is_I, &lexer_line);
note_def_vec_alloc (type, "none", &lexer_line);
}
vec.h: Update API to separate allocation mechanism from type. * vec.h: Update API to separate allocation mechanism from type. (VEC_safe_grow): New. * vec.c (calculate_allocation): New. (vec_gc_o_reserve, vec_heap_o_reserve): Adjust. (vec_gc_free, vec_heap_free): Remove. * gengtype-lex.l (DEF_VEC_): Process mult-argument macros. Adjust. (VEC): Likewise. (mangle_macro_name): New. (struct macro_def): New. (struct macro): Add multiple argument values. (macro_expans_end): New. (push_macro_expansion): Chain on new macro. Process multiple args, create follow on expansion. Return follow on argument. (macro_input): Deal with multiple arguments. * tree.h: Define VEC(tree,heap) and VEC(tree,gc). (struct tree_binfo): Adjust. * basic-block.h: Define VEC(edge,gc). (struct edge_def): Adjust. (struct basic_block_def, struct edge_iterator): Likewise. (ei_container, ei_start_1, ei_last_1): Likewise. * cfg.c (connect_src, connect_dest): Likewise. * cfgrtl.c (force_nonfallthru_and_redirect) * dbxout.c (dbxout_type) * dwarf2out.c (gen_member_die) * lambda-code.c: Define VEC(int,gc), VEC(lambda_loop,gc). (gcc_tree_to_linear_expression): Adjust. (gcc_loop_to_lambda_loop, gcc_loopnest_to_lambda_loopnest, lbv_to_gcc_expression, lle_to_gcc_expression, lambda_loopnest_to_gcc_loopnest, can_convert_to_perfect_nest, perfect_nestify): Likewise. * lambda.h (gcc_loopnest_to_lambda_loopnest, lambda_loopnest_to_gcc_loopnest): Adjust prototypes. * profile.c (instrument_values): Adjust. * tree-cfg.c (modified_noreturn_calls): Adjust. (remove_fallthru_edge): Likewise. * tree-dump.c (dequeue_and_dump): Adjust. * tree-flow-inline.h (mark_stmt_modified): Adjust. * tree-flow.h (modified_noreturn_calls): Adjust. (tree_on_heap): Remove. (yay!) (register_new_def): Adjust. * tree-into-ssa.c: Define VEC(int,heap). (block_defs_stack): Adjust. (find_idf, insert_phi_nodes, register_new_def, rewrite_initialize_block, rewrite_finalize_block, register_new_update_single, rewrite_update_init_block, rewrite_update_fini_block, rewrite_blocks, ssa_rewrite_finalize_block, ssa_register_new_def, ssa_rewrite_initialize_block, rewrite_ssa_into_ssa): Likewise. * tree-loop-linear.c (linear_transform_loops): Adjust. * tree-ssa-alias.c: Define VEC(fieldoff_t,heap). (push_fields_onto_fieldstack, create_overlap_variables_for): Adjust. * tree-ssa-dom.c (avail_exprs_stack, block_defs_stack, stmts_to_rescan, const_and_copies_stack, nonzero_vars_stack, vrp_variables_stack): Adjust declarations. (tree_ssa_dominator_optimize): Adjust. (dom_opt_initialize_block, remove_local_expressions_from_table, restore_nonzero_vars_to_original_value, restore_vars_to_original_value, restore_currdefs_to_original_value, dom_opt_finalize_block, record_var_is_nonzero, record_cond, record_const_or_copy_1, optimize_stmt, update_rhs_and_lookup_avail_expr, lookup_avail_expr, record_range): Likewise. * tree-ssa-pre.c: Define VEC(basic_block,heap). (compute_antic_aux): Adjust. (inserted_exprs, create_expression_by_pieces, insert_into_preds_of_block, eliminate, mark_operand_necessary, remove_dead_inserted_code, fini_pre): Likewise. * tree-ssa-propagate.c (interesting_ssa_edges): Adjust. (varying_ssa_edges, add_ssa_edge, process_ssa_edge_worklist. ssa_prop_init): Likewise. * tree-ssa.c: Define VEC(bitmap,heap). (verify_name_tags): Adjust. * value-prof.c (rtl_divmod_values_to_profile): Adjust. (insn_prefetch_values_to_profile, rtl_find_values_to_profile, tree_divmod_values_to_profile, tree_find_values_to_profile, value_profile_transformations): Likewise. * value-prof.h: Define VEC(histogram_value,heap). * varasm.c: Remove alias_pair pointer typedef, define VEC(alias_pair,gc). (finish_aliases_1, finish_aliases_2, assemble_alias): Adjust. * config/pa/pa.c (typedef extern_symbol): Typedef the structure, not a pointer to it. Create an object vector. (extern_symbols): Turn into an object vector. (pa_hpux_asm_output_external, pa_hpux_file_end): Adjust. * cp/cp-tree.h: Adjust for new VEC API. Define VEC(tree_pair_s,gc). (struct save_scope): Adjust. (struct lang_type_class): Adjust. (unemitted_tinfo_decls): Adjust. * cp/class.c (add_method, resort_type_method_vec, finish_struct_methods, struct find_final_overrider_data, dfs_find_final_overrider_pre, find_final_overrider, get_vcall_index, warn_hidden, walk_subobject_offsets, check_methods, fixup_inline_methods, end_of_class, warn_about_ambiguous_bases, finish_struct, build_vtbl_initializer, add_vcall_offset): Adjust. * cp/decl.c (xref_basetypes, finish_method): Adjust. * cp/decl2.c (check_classfn): Adjust. * cp/init.c (sort_mem_initializers, push_base_cleanups): Adjust. * cp/method.c (do_build_copy_constructor): Adjust. * cp/name-lookup.c (new_class_binding, store_binding, store_bindings, store_class_bindings): Adjust. * cp/name-lookup.h: Define VEC(cxx_saved_binding,gc), VEC(cp_class_binding,gc). (struct cp_binding_level): Adjust. * cp/parser.c: Define VEC(cp_token_position,heap). (struct cp_lexer): Adjust. (cp_lexer_new_main, cp_lexer_new_from_tokens, cp_lexer_destroy, cp_lexer_save_tokens): Adjust. * cp/pt.c (retrieve_specialization, check_explicit_specialization): Adjust. * cp/rtti.c (unemitted_tinfo_decls): Adjust. (init_rtti_processing, get_tinfo_decl, get_pseudo_ti_init, get_pseudo_ti_desc): Adjust. * cp/search.c (dfs_access_in_type, lookup_conversion_operator, lookup_fnfields_1, dfs_walk_once, dfs_walk_once_accessible, dfs_get_pure_virtuals, lookup_conversions_r, binfo_for_vbase): Adjust. * cp/semantics.c: Define VEC(deferred_access,gc). (push_deferring_access_checks): Adjust. * cp/typeck2.c (abstract_virtuals_error): Adjust. From-SVN: r98498
2005-04-21 11:18:28 +02:00
^"DEF_VEC_ALLOC_"[IPO]{WS}?"("{WS}?{ID}{WS}?","{WS}?{ID}{WS}?")" {
/* Definition of an allocation strategy for a VEC structure. For
purposes of gengtype, this just declares a wrapper structure. */
char *p = yytext + sizeof("DEF_VEC_ALLOC_I") - 1;
char *q;
char *type, *astrat;
/* Extract the two arguments to the macro. */
while (!ISALNUM(*p) && *p != '_')
p++;
q = p;
while (ISALNUM(*q) || *q == '_')
q++;
type = alloca (q - p + 1);
memcpy (type, p, q - p);
type[q - p] = '\0';
p = q;
while (!ISALNUM(*p) && *p != '_')
p++;
q = p;
while (ISALNUM(*q) || *q == '_')
q++;
astrat = alloca (q - p + 1);
memcpy (astrat, p, q - p);
astrat[q - p] = '\0';
note_def_vec_alloc (type, astrat, &lexer_line);
}
<in_struct>{
"/*" { BEGIN(in_struct_comment); }
{WS} { update_lineno (yytext, yyleng); }
"const"/[^[:alnum:]_] /* don't care */
"GTY"/[^[:alnum:]_] { return GTY_TOKEN; }
"VEC"/[^[:alnum:]_] { return VEC_TOKEN; }
"union"/[^[:alnum:]_] { return UNION; }
"struct"/[^[:alnum:]_] { return STRUCT; }
"enum"/[^[:alnum:]_] { return ENUM; }
"ptr_alias"/[^[:alnum:]_] { return ALIAS; }
"nested_ptr"/[^[:alnum:]_] { return NESTED_PTR; }
[0-9]+ { return NUM; }
"param"[0-9]*"_is"/[^[:alnum:]_] {
yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
Index: gcc/ChangeLog 2002-09-12 Geoffrey Keating <geoffk@apple.com> * ggc-common.c (ggc_mark_rtx_children_1): Update for changed name mangling. The following changes are merged from pch-branch: * doc/gty.texi (GTY Options): Document %a. * gengtype.c (do_scalar_typedef): New function. (process_gc_options): Handle `length' option. (set_gc_used_type): A pointer to an array of structures doesn't qualify as a pointer to a structure. (output_escaped_param): Add `%a' escape. (write_gc_structure_fields): Allow 'desc' on array of unions. (main): Define `uint8', `jword' and `JCF_u2' as scalars; use do_scalar_typedef. * gengtype.c (enum rtx_code): Make global. (rtx_format): Make global. (rtx_next): New. (gen_rtx_next): New. (write_rtx_next): New. (adjust_field_rtx_def): Skip fields marked by chain_next. (open_base_files): Delete redundant prototype. (write_enum_defn): New. (output_mangled_typename): Correct abort call. (write_gc_marker_routine_for_structure): Handle chain_next and chain_prev options. (finish_root_table): Don't output redundant \n. (main): Call gen_rtx_next, write_rtx_next, write_enum_defn. * c-tree.h (union lang_tree_node): Add chain_next option. * gengtype.h (NUM_PARAM): New definition. (struct type): For TYPE_PARAM_STRUCT, allow multiple parameters. * gengtype.c (find_param_structure): New. (adjust_field_type): Handle param<n>_is option. (process_gc_options): Detect use_params option. Update callers. (set_gc_used_type): Add 'param' parameter, update callers. Handle 'use_params' option. (open_base_files): Add splay-tree.h to list of files included. (output_mangled_typename): New. (write_gc_structure_fields): Update 'param' parameter to support multiple parameters. Change name mangling. Allow parameterized fields to have an apparent scalar type. Handle param<n>_is options, use_param option. (write_gc_marker_routine_for_structure): Update for change to name mangling. Better guess the output file for parameterized types. (write_gc_types): Update for change to name mangling. (write_gc_root): Update for change to name mangling. Handle (ignore) param<n>_is options. * doc/gty.texi (GTY Options): Add description of param<n>_is options, use_params option. * ggc.h (ggc_mark_rtx): Update for changed name mangling. * gengtype-lex.l: Produce token for param<n>_is. * gengtype-yacc.y: Parse param<n>_is. * gengtype.c (adjust_field_tree_exp): Don't name a variable 'rindex'. * rtl.c: Update comment describing rtx_format. * rtl.h (union rtunion): Separate definition and typedef. (struct rtx_def): Use gengtype to mark. * Makefile.in (gengtype.o): Also depend on rtl.def. * ggc.h (ggc_mark_rtx_children): Delete prototype. (ggc_mark_rtx): Change to alias of gengtype-generated routine. * ggc-common.c (ggc_mark_rtx_children): Delete. (ggc_mark_rtx_children_1): Delete. (gt_ggc_m_rtx_def): Delete. * gengtype.c (adjust_field_rtx_def): New. (adjust_field_type): Call adjust_field_rtx_def. (write_gc_structure_fields): Add 'default' case to switch if none is specified; remove unused code. * tree.h (struct tree_exp): Update for change to meaning of special. * gengtype.c (adjust_field_tree_exp): New function. (adjust_field_type): Handle `tree_exp' special here. (write_gc_structure_fields): Don't handle `tree_exp' special here. Handle new `dot' option. * gengtype.h: Make `info' a pointer-to-const. * gengtype-yacc.y (yacc_ids): Use xasprintf. * gengtype.c (write_gc_structure_fields): Remove implementation of `always' option, add `default' option. * doc/gty.texi (GTY Options): Remove documentation of `always', add `default'. Index: gcc/cp/ChangeLog 2002-09-12 Geoffrey Keating <geoffk@apple.com> * cp-tree.h (union lang_tree_node): Add chain_next option. Index: gcc/f/ChangeLog 2002-09-12 Geoffrey Keating <geoffk@apple.com> * com.c (union lang_tree_node): Add chain_next option. Index: gcc/java/ChangeLog 2002-09-12 Geoffrey Keating <geoffk@apple.com> * java-tree.h (union lang_tree_node): Add chain_next option. From-SVN: r57206
2002-09-16 20:33:23 +02:00
return PARAM_IS;
}
{IWORD}({WS}{IWORD})*/[^[:alnum:]_] |
"ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
size_t len;
for (len = yyleng; ISSPACE (yytext[len-1]); len--)
;
yylval.s = (const char *) xmemdup (yytext, len, len+1);
update_lineno (yytext, yyleng);
return SCALAR;
}
{ID}/[^[:alnum:]_] {
yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
return ID;
}
\"([^"\\]|\\.)*\" {
yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
return STRING;
}
"["[^\[\]]*"]" {
yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
return ARRAY;
}
"'"("\\".|[^\\])"'" {
yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng);
return CHAR;
}
[(){},*:<>] { return yytext[0]; }
[;=] {
if (lexer_toplevel_done)
{
BEGIN(INITIAL);
lexer_toplevel_done = 0;
}
return yytext[0];
}
"#define"[^\n]*\n {lexer_line.line++;}
. {
error_at_line (&lexer_line, "unexpected character `%s'", yytext);
}
}
"/*" { BEGIN(in_comment); }
\n { lexer_line.line++; }
{ID} |
"'"("\\".|[^\\])"'" |
[^"/\n] /* do nothing */
\"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
"/"/[^*] /* do nothing */
<in_comment,in_struct_comment>{
\n { lexer_line.line++; }
[^*\n]{16} |
[^*\n] /* do nothing */
"*"/[^/] /* do nothing */
}
<in_comment>"*/" { BEGIN(INITIAL); }
<in_struct_comment>"*/" { BEGIN(in_struct); }
["/] |
<in_struct_comment,in_comment>"*" {
error_at_line (&lexer_line,
"unterminated comment or string; unexpected EOF");
}
^"#define"{WS}"GTY(" /* do nothing */
{WS}"GTY"{WS}?"(" {
error_at_line (&lexer_line, "stray GTY marker");
}
%%
void
yyerror (const char *s)
{
error_at_line (&lexer_line, s);
}
void
parse_file (const char *fname)
{
yyin = fopen (fname, "r");
lexer_line.file = fname;
lexer_line.line = 1;
if (yyin == NULL)
{
perror (fname);
exit (1);
}
if (yyparse() != 0)
exit (1);
fclose (yyin);
}