GCC Middle and Back End API Reference
gengtype-parse.c File Reference

Data Structures

struct  token

Functions

static int token ()
static const char * advance ()
static const char * print_token ()
static const char * print_cur_token ()
static void ATTRIBUTE_PRINTF_1 parse_error ()
static const char * require ()
static const char * require2 ()
static const char * string_seq ()
static const char * require_template_declaration ()
static const char * typedef_name ()
static void consume_balanced ()
static void consume_until_eos ()
static bool consume_until_comma_or_eos ()
static type_p type (options_p *optsp, bool nested)
static options_p str_optvalue_opt ()
static type_p absdecl ()
static options_p type_optvalue ()
static options_p nestedptr_optvalue ()
static options_p option ()
static options_p option_seq ()
static options_p gtymarker ()
static options_p gtymarker_opt ()
static type_p array_and_function_declarators_opt ()
static type_p inner_declarator (type_p, const char **, options_p *, bool)
static type_p direct_declarator (type_p ty, const char **namep, options_p *optsp, bool in_struct)
static type_p declarator (type_p ty, const char **namep, options_p *optsp, bool in_struct=false)
static pair_p struct_field_seq ()
static bool opts_have ()
static type_p type ()
static void typedef_decl ()
static void struct_or_union ()
static void extern_or_static ()
void parse_file ()

Variables

static struct token T
static const char *const token_names []
static const char *const token_value_format []

Function Documentation

static type_p absdecl ( )
static
absdecl: type '*'*
   -- a vague approximation to what the C standard calls an abstract
   declarator.  The only kinds that are actually used are those that
   are just a bare type and those that have trailing pointer-stars.
   Further kinds should be implemented if and when they become
   necessary.  Used only within  option values, therefore
   further  tags within the type are invalid.  Note that the
   return value has already been run through adjust_field_type.   

References adjust_field_type(), advance(), create_pointer(), parse_error(), and type().

Referenced by nestedptr_optvalue(), and type_optvalue().

static const char* advance ( )
inlinestatic
static type_p array_and_function_declarators_opt ( )
static
Declarators. The logic here is largely lifted from c-parser.c.
   Note that we do not have to process abstract declarators, which can
   appear only in parameter type lists or casts (but see absdecl,
   above).  Also, type qualifiers are thrown out in gengtype-lex.l so
   we don't have to do it.   
array_and_function_declarators_opt:
   \epsilon
   array_and_function_declarators_opt ARRAY
   array_and_function_declarators_opt '(' ... ')'

   where '...' indicates stuff we ignore except insofar as grouping
   symbols ()[]{} must balance.

   Subroutine of direct_declarator - do not use elsewhere.  

References advance(), consume_balanced(), create_array(), and create_scalar_type().

Referenced by direct_declarator().

static void consume_balanced ( )
static
Absorb a sequence of tokens delimited by balanced ()[]{}.   

References advance(), parse_error(), and require().

Referenced by array_and_function_declarators_opt(), consume_until_comma_or_eos(), consume_until_eos(), and type().

static bool consume_until_comma_or_eos ( )
static
Absorb a sequence of tokens, possibly including ()[]{}-delimited
   expressions, until we encounter a comma or semicolon outside any
   such delimiters; absorb that too.  Returns true if the loop ended
   with a comma.   

References advance(), consume_balanced(), parse_error(), and print_cur_token().

Referenced by struct_field_seq(), and typedef_decl().

static void consume_until_eos ( )
static
Absorb a sequence of tokens, possibly including ()[]{}-delimited
   expressions, until we encounter an end-of-statement marker (a ';' or
   a '}') outside any such delimiters; absorb that too.   

References advance(), consume_balanced(), and parse_error().

Referenced by struct_field_seq().

static type_p declarator ( type_p  ty,
const char **  namep,
options_p optsp,
bool  in_struct = false 
)
static
declarator: '*'+ direct_declarator

   This is the sole public interface to this part of the grammar.
   Arguments are the type known so far, a pointer to where the name
   may be stored, and a pointer to where GTY options may be stored.

   IN_STRUCT is true when we are called to parse declarators inside
   a structure or class.

   Returns the final type.   

References advance(), create_pointer(), and direct_declarator().

Referenced by extern_or_static(), struct_field_seq(), and typedef_decl().

static type_p direct_declarator ( type_p  ty,
const char **  namep,
options_p optsp,
bool  in_struct 
)
static
direct_declarator:
   '(' inner_declarator ')'
   '(' \epsilon ')'     <-- C++ ctors/dtors
   gtymarker_opt ID array_and_function_declarators_opt

   Subroutine of declarator, mutually recursive with inner_declarator;
   do not use elsewhere.

   IN_STRUCT is true if we are called while parsing structures or classes.   

References advance(), array_and_function_declarators_opt(), gtymarker(), inner_declarator(), parse_error(), print_cur_token(), and require().

Referenced by declarator(), and inner_declarator().

static void extern_or_static ( )
static
GC root declaration:
   (extern|static) gtymarker? type ID array_declarators_opt (';'|'=')
   If the gtymarker is not present, we ignore the rest of the declaration.   

References adjust_field_type(), advance(), declarator(), gtymarker(), lexer_line, note_variable(), parse_error(), require2(), and type().

Referenced by parse_file().

static options_p gtymarker ( )
static
GTY marker: 'GTY' '(' '(' option_seq? ')' ')'  

References option_seq(), and require().

Referenced by direct_declarator(), extern_or_static(), and gtymarker_opt().

static options_p gtymarker_opt ( )
static
Optional GTY marker.   

References gtymarker().

Referenced by type().

static type_p inner_declarator ( type_p  ty,
const char **  namep,
options_p optsp,
bool  in_struct 
)
static
The difference between inner_declarator and declarator is in the
   handling of stars.  Consider this declaration:

   char * (*pfc) (void)

   It declares a pointer to a function that takes no arguments and
   returns a char*.  To construct the correct type for this
   declaration, the star outside the parentheses must be processed
   _before_ the function type, the star inside the parentheses must
   be processed _after_ the function type.  To accomplish this,
   declarator() creates pointers before recursing (it is actually
   coded as a while loop), whereas inner_declarator() recurses before
   creating pointers.   
inner_declarator:
   '*' inner_declarator
   direct_declarator

   Mutually recursive subroutine of direct_declarator; do not use
   elsewhere.

   IN_STRUCT is true if we are called while parsing structures or classes.   

References advance(), create_pointer(), and direct_declarator().

Referenced by direct_declarator().

static options_p nestedptr_optvalue ( )
static
Nested pointer data: '(' type '*'* ',' string_seq ',' string_seq ')'  

References absdecl(), create_nested_ptr_option(), require(), and string_seq().

Referenced by option().

static options_p option_seq ( )
static
One comma-separated list of options.   

References advance(), and option().

Referenced by gtymarker().

static bool opts_have ( )
static
Return true if OPTS contain the option named STR.   

References options::next.

Referenced by type().

static void ATTRIBUTE_PRINTF_1 parse_error ( )
static
Report a parse error on the current line, with diagnostic MSG.
   Behaves as standard printf with respect to additional arguments and
   format escapes.   

References fileloc::file, get_input_file_name(), hit_error, lexer_line, and fileloc::line.

Referenced by absdecl(), consume_balanced(), consume_until_comma_or_eos(), consume_until_eos(), direct_declarator(), extern_or_static(), option(), parse_file(), require(), require2(), struct_field_seq(), type(), and typedef_decl().

void parse_file ( )
Parse the file FNAME for GC-relevant declarations and definitions.
   This is the only entry point to this file.   

References advance(), extern_or_static(), lexer_toplevel_done, parse_error(), print_cur_token(), struct_or_union(), and typedef_decl().

Referenced by main().

static const char* print_cur_token ( )
inlinestatic
Convenience wrapper around print_token which produces the printable
   representation of the current token.   

References token::code, print_token(), T, and token::value.

Referenced by consume_until_comma_or_eos(), direct_declarator(), option(), parse_file(), and type().

static const char* print_token ( )
static
Produce a printable representation for a token defined by CODE and
   VALUE.  This sometimes returns pointers into malloc memory and
   sometimes not, therefore it is unsafe to free the pointer it
   returns, so that memory is leaked.  This does not matter, as this
   function is only used for diagnostics, and in a successful run of
   the program there will be none.   

References token_names, token_value_format, and xasprintf().

Referenced by print_cur_token(), require(), and require2().

static const char* require ( )
static
If the next token does not have code T, report a parse error; otherwise
   return the token's value.   

References advance(), parse_error(), print_token(), and token().

Referenced by consume_balanced(), direct_declarator(), gtymarker(), nestedptr_optvalue(), require_template_declaration(), str_optvalue_opt(), string_seq(), type(), type_optvalue(), and typedef_name().

static const char* require2 ( )
static
If the next token does not have one of the codes T1 or T2, report a
   parse error; otherwise return the token's value.   

References advance(), parse_error(), print_token(), and token().

Referenced by extern_or_static(), and require_template_declaration().

static const char* require_template_declaration ( )
static
The caller has detected a template declaration that starts
   with TMPL_NAME.  Parse up to the closing '>'.  This recognizes
   simple template declarations of the form ID<ID1,ID2,...,IDn>.
   It does not try to parse anything more sophisticated than that.

   Returns the template declaration string "ID<ID1,ID2,...,IDn>".   

References require(), and require2().

Referenced by typedef_name().

static options_p str_optvalue_opt ( )
static
Optional parenthesized string: ('(' string_seq ')')?  

References advance(), create_string_option(), require(), string_seq(), and token::value.

Referenced by option().

static const char* string_seq ( )
static
Near-terminals.   
C-style string constant concatenation: STRING+
   Bare STRING should appear nowhere else in this file.   

References advance(), memcpy(), require(), and strlen().

Referenced by nestedptr_optvalue(), and str_optvalue_opt().

static pair_p struct_field_seq ( )
static
Types and declarations.   
Structure field(s) declaration:
   (
   type bitfield ';'
   | type declarator bitfield? ( ',' declarator bitfield? )+ ';'
   )+

   Knows that such declarations must end with a close brace (or,
   erroneously, at EOF).

References consume_until_comma_or_eos(), consume_until_eos(), create_field_at(), declarator(), lexer_line, nreverse_pairs(), parse_error(), and type().

Referenced by type().

static void struct_or_union ( )
static
Structure definition: type() does all the work.   

References advance(), and type().

Referenced by parse_file().

static int token ( )
inlinestatic
Retrieve the code of the current token; if there is no current token,
   get the next one from the lexer.   

References token::code, T, token::valid, and token::value.

Referenced by ipa_get_indirect_edge_target_1(), ipa_intraprocedural_devirtualization(), require(), require2(), and type().

static type_p type ( options_p optsp,
bool  nested 
)
static
option handling.   

Referenced by absdecl(), add_candidate_1(), add_elt_to_tree(), add_fixup_edge(), add_to_evolution_1(), add_to_parts(), add_ttypes_entry(), add_uses(), adjust_range_with_scev(), aff_combination_add_elt(), aff_combination_add_product(), aff_combination_convert(), aff_combination_expand(), aff_combination_to_tree(), aff_combination_zero(), analyze_miv_subscript(), analyze_siv_subscript_cst_affine(), analyze_ziv_subscript(), array_value_type(), assert_loop_rolls_lt(), assign_parms_augmented_arg_list(), assign_stack_temp_for_type(), assign_temp(), build1_stat(), build_aligned_type(), build_common_builtin_nodes(), build_constructor(), build_decl_stat(), build_duplicate_type(), build_fake_var_decl(), build_fixed(), build_int_cst_wide(), build_offset_type(), build_personality_function(), build_range_type_1(), build_real(), build_string_literal(), build_vector_stat(), can_use_analyze_subscript_affine_affine(), cand_value_at(), canonicalize_component_ref(), canonicalize_float_value(), canonicalize_loop_ivs(), cgraph_create_indirect_edge(), check_pow(), check_stmt_for_type_change(), check_target_format(), chrec_convert_aggressive(), chrec_fold_plus_poly_poly(), const_binop(), convert_affine_scev(), convert_mult_to_widen(), convert_plusminus_to_widen(), convert_to_integer(), convert_to_real(), copy_decl_to_var(), copy_result_decl_to_var(), create_canonical_iv(), create_expand_operand(), create_field_all(), create_loop_fn(), create_omp_child_function(), create_parallel_loop(), dbxout_symbol(), default_assemble_visibility(), default_elf_asm_named_section(), default_emutls_var_fields(), difference_cost(), do_compare_and_jump(), do_jump(), do_store_flag(), dump_generic_node(), dump_gimple_try(), eliminate_local_variables_1(), estimate_numbers_of_iterations_loop(), execute_cse_sincos_1(), expand_asm_operands(), expand_builtin_cexpi(), expand_complex_comparison(), expand_complex_libcall(), expand_complex_operations_1(), expand_expr_real_1(), expand_expr_real_2(), expand_LOAD_LANES(), expand_omp_atomic_load(), expand_omp_atomic_pipeline(), expand_omp_atomic_store(), expand_omp_for_generic(), expand_omp_for_static_chunk(), expand_omp_for_static_nochunk(), expand_omp_simd(), expand_STORE_LANES(), expand_vector_operations_1(), extern_or_static(), extract_affine(), extract_range_from_assert(), extract_range_from_binary_expr_1(), extract_range_from_multiplicative_op_1(), extract_range_from_unary_expr_1(), factor_tests(), field_byte_offset(), field_type(), finalize_nesting_tree_1(), find_bivs(), find_reloads(), finish_builtin_struct(), fixup_child_record_type(), fold_binary_loc(), fold_builtin_bitop(), fold_builtin_fpclassify(), fold_builtin_sincos(), fold_builtin_stpcpy(), fold_cond_expr_with_comparison(), fold_truth_andor(), fold_truth_andor_1(), fold_unary_loc(), force_fit_type_double(), gen_eh_region(), gen_parallel_loop(), gen_typedef_die(), generic_type_for(), get_chain_decl(), get_chain_field(), get_dep_weak_1(), get_emutls_object_type(), get_frame_type(), get_nl_goto_field(), get_odr_type(), get_qualified_type(), get_use_type(), gimple_alloc_histogram_value(), gimple_call_fnspec(), gimple_divmod_values_to_profile(), gimple_expand_builtin_pow(), gimple_extract_devirt_binfo_from_cst(), gimple_fold_builtin(), gimple_signed_or_unsigned_type(), gimplify_init_constructor(), gimplify_init_ctor_preeval_1(), go_output_typedef(), graphite_translate_clast_equation(), handle_builtin_strcat(), handle_builtin_strcpy(), idx_infer_loop_bounds(), infer_loop_bounds_from_pointer_arith(), infer_loop_bounds_from_signedness(), init_dep_1(), init_vn_nary_op_from_pieces(), initialize_reductions(), input_gimple_stmt(), insert_field_into_struct(), insert_reciprocals(), install_var_field(), instrument_derefs(), ipa_print_node_jump_functions_for_edge(), ipa_set_ancestor_jf(), iterative_hash_canonical_type(), iv_period(), layout_decl(), lookup_key(), lookup_type_for_runtime(), lto_symtab_merge(), make_accum_type(), make_bit_field_ref(), make_debug_expr_from_rtl(), make_fract_type(), make_signed_type(), make_tree(), make_unsigned_type(), max_precision_type(), may_negate_without_overflow_p(), mf_xform_derefs_1(), minmax_replacement(), native_encode_initializer(), negate_expr(), negate_expr_p(), new_decision_test(), new_insn_reg(), new_omp_region(), new_poly_dr(), next_position(), number_of_iterations_cond(), number_of_iterations_exit(), number_of_iterations_le(), number_of_iterations_lt_to_ne(), optimize_range_tests(), output_one_function_exception_table(), output_used_types(), phi_translate_1(), possible_polymorphic_call_targets(), precompute_arguments(), premark_used_types_helper(), ptr_difference_const(), ptr_difference_cost(), push_reload(), push_secondary_reload(), record_type(), ref_at_iteration(), register_edge_assert_for_2(), remap_type(), remap_vla_decls(), restructure_reference(), rewrite_reciprocal(), scev_const_prop(), sdbout_parms(), separate_decls_in_region(), set_debug_level(), set_mem_attributes_minus_bitpos(), signed_or_unsigned_type_for(), simple_iv(), simplify_vector_constructor(), slsr_process_ref(), sra_modify_expr(), std_canonical_va_list_type(), stream_in_histogram_value(), strip_array_types(), strip_offset_1(), struct_field_seq(), struct_or_union(), task_copyfn_remap_type(), translate_clast_assignment(), translate_clast_for(), tree_predict_by_opcode(), tree_unary_nonnegative_warnv_p(), tree_unary_nonzero_warnv_p(), type_for_clast_red(), type_for_clast_term(), type_for_interval(), type_hash_add(), type_hash_canon(), type_hash_lookup(), type_main_variant(), typedef_decl(), types_used_by_var_decl_insert(), used_types_insert_helper(), vect_create_destination_var(), vect_is_simple_reduction_1(), vect_operation_fits_smaller_type(), vect_recog_dot_prod_pattern(), vect_recog_mixed_size_cond_pattern(), vect_recog_rotate_pattern(), vect_recog_widen_mult_pattern(), vect_recog_widen_shift_pattern(), vect_recog_widen_sum_pattern(), vect_update_ivs_after_vectorizer(), vectorizable_call(), vn_nary_may_trap(), vn_phi_compute_hash(), vn_reference_insert_pieces(), vn_reference_lookup_or_insert_for_pieces(), and vn_reference_lookup_pieces().

static type_p type ( )
static
This is called type(), but what it parses (sort of) is what C calls
   declaration-specifiers and specifier-qualifier-list:

   SCALAR
   | ID     // typedef
   | (STRUCT|UNION) ID? gtymarker? ( '{' gtymarker? struct_field_seq '}' )?
   | ENUM ID ( '{' ... '}' )?

   Returns a partial type; under some conditions (notably
   "struct foo  thing;") it may write an options
   structure to *OPTSP.

   NESTED is true when parsing a declaration already known to have a
   GTY marker. In these cases, typedef and enum declarations are not
   allowed because gengtype only understands types at the global
   scope.   

References advance(), consume_balanced(), create_scalar_type(), create_user_defined_type(), fileloc::file, find_structure(), get_input_file_name(), gtymarker_opt(), lexer_line, fileloc::line, new_structure(), opts_have(), parse_error(), print_cur_token(), require(), resolve_typedef(), SCALAR, struct_field_seq(), token(), TYPE_STRUCT, TYPE_UNION, TYPE_USER_STRUCT, typedef_name(), and xasprintf().

static options_p type_optvalue ( )
static
Type-option: '(' absdecl ')'  

References absdecl(), create_type_option(), and require().

Referenced by option().

static void typedef_decl ( )
static
Top level constructs.   
Dispatch declarations beginning with 'typedef'.   

References advance(), consume_until_comma_or_eos(), declarator(), do_typedef(), lexer_line, parse_error(), and type().

Referenced by parse_file().

static const char* typedef_name ( )
static
typedef_name: either an ID, or a template type
   specification of the form ID<t1,t2,...,tn>.   

References require(), and require_template_declaration().

Referenced by type().


Variable Documentation

const char* const token_names[]
static
Initial value:
{
"GTY",
"typedef",
"extern",
"static",
"union",
"struct",
"enum",
"...",
"ptr_alias",
"nested_ptr",
"a param<N>_is option",
"a number",
"a scalar type",
"an identifier",
"a string constant",
"a character constant",
"an array declarator",
"a C++ keyword to ignore"
}
Diagnostics.   
This array is indexed by the token code minus CHAR_TOKEN_OFFSET.   

Referenced by print_token().

const char* const token_value_format[]
static
Initial value:
{
"%s",
"'%s'",
"'%s'",
"'%s'",
"'\"%s\"'",
"\"'%s'\"",
"'[%s]'",
"'%s'",
}
This array is indexed by token code minus FIRST_TOKEN_WITH_VALUE.   

Referenced by print_token().