GCC Middle and Back End API Reference
gengtype-parse.cc File Reference
#include "bconfig.h"
#include "system.h"
#include "gengtype.h"
Include dependency graph for gengtype-parse.cc:

Data Structures

struct  token
 

Functions

static int token (void)
 
static const charadvance (void)
 
static const charprint_token (int code, const char *value)
 
static const charprint_cur_token (void)
 
static void ATTRIBUTE_PRINTF_1 parse_error (const char *msg,...)
 
static const charrequire (int t)
 
static const charrequire_without_advance (int t)
 
static const charrequire2 (int t1, int t2)
 
static const charrequire4 (int t1, int t2, int t3, int t4)
 
static const charstring_seq (void)
 
static const charrequire_template_declaration (const char *tmpl_name)
 
static const chartypedef_name (void)
 
static void consume_balanced (int opener, int closer)
 
static void consume_until_eos (void)
 
static bool consume_until_comma_or_eos ()
 
static type_p type (options_p *optsp, bool nested)
 
static options_p str_optvalue_opt (options_p prev)
 
static type_p absdecl (void)
 
static options_p type_optvalue (options_p prev, const char *name)
 
static options_p nestedptr_optvalue (options_p prev)
 
static options_p option (options_p prev)
 
static options_p option_seq (void)
 
static options_p gtymarker (void)
 
static options_p gtymarker_opt (void)
 
static type_p array_and_function_declarators_opt (type_p ty)
 
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 (void)
 
bool opts_have (options_p opts, const char *str)
 
static void typedef_decl (void)
 
static void struct_or_union (void)
 
static void extern_or_static (void)
 
void parse_file (const char *fname)
 

Variables

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

Function Documentation

◆ absdecl()

static type_p absdecl ( void )
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(), ggc_alloc(), parse_error(), ty, and type().

Referenced by nestedptr_optvalue(), and type_optvalue().

◆ advance()

◆ array_and_function_declarators_opt()

static type_p array_and_function_declarators_opt ( type_p ty)
static
Declarators. The logic here is largely lifted from c-parser.cc.
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(), ARRAY, array_and_function_declarators_opt(), consume_balanced(), create_array(), create_scalar_type(), and ty.

Referenced by array_and_function_declarators_opt(), and direct_declarator().

◆ consume_balanced()

static void consume_balanced ( int opener,
int closer )
static

◆ consume_until_comma_or_eos()

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(), EOF_TOKEN, parse_error(), and print_cur_token().

Referenced by struct_field_seq(), and typedef_decl().

◆ consume_until_eos()

static void consume_until_eos ( void )
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(), EOF_TOKEN, and parse_error().

Referenced by struct_field_seq().

◆ declarator()

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(), direct_declarator(), ggc_alloc(), and ty.

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

◆ direct_declarator()

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(), ggc_alloc(), GTY_TOKEN, gtymarker(), ID, IGNORABLE_CXX_KEYWORD, inner_declarator(), NULL, parse_error(), print_cur_token(), require(), and ty.

Referenced by declarator(), and inner_declarator().

◆ extern_or_static()

static void extern_or_static ( void )
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(), EXTERN, ggc_alloc(), GTY_TOKEN, gtymarker(), lexer_line, note_variable(), parse_error(), require2(), STATIC, ty, and type().

Referenced by parse_file().

◆ gtymarker()

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

References GTY_TOKEN, option_seq(), and require().

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

◆ gtymarker_opt()

static options_p gtymarker_opt ( void )
static
Optional GTY marker.   

References GTY_TOKEN, and gtymarker().

Referenced by type().

◆ inner_declarator()

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(), direct_declarator(), ggc_alloc(), inner_declarator(), and ty.

Referenced by direct_declarator(), and inner_declarator().

◆ nestedptr_optvalue()

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

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

Referenced by option().

◆ option()

◆ option_seq()

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

References advance(), ggc_alloc(), and option().

Referenced by gtymarker().

◆ opts_have()

bool opts_have ( options_p opts,
const char * str )
Return true if OPTS contain the option named STR.   

References ggc_alloc().

Referenced by type().

◆ parse_error()

static void ATTRIBUTE_PRINTF_1 parse_error ( const char * msg,
... )
static

◆ parse_file()

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

References advance(), EOF_TOKEN, EXTERN, extern_or_static(), ggc_alloc(), lexer_toplevel_done, parse_error(), print_cur_token(), STATIC, STRUCT, struct_or_union(), TYPEDEF, typedef_decl(), UNION, yybegin(), and yyend().

◆ print_cur_token()

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

References print_token().

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

◆ print_token()

static const char * print_token ( int code,
const char * value )
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 CHAR_TOKEN_OFFSET, token::code, FIRST_TOKEN_WITH_VALUE, ggc_alloc(), token_names, token_value_format, and token::value.

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

◆ require()

◆ require2()

static const char * require2 ( int t1,
int t2 )
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().

◆ require4()

static const char * require4 ( int t1,
int t2,
int t3,
int t4 )
static
If the next token does not have one of the codes T1, T2, T3 or T4, report a
parse error; otherwise return the token's value.   

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

Referenced by require_template_declaration().

◆ require_template_declaration()

static const char * require_template_declaration ( const char * tmpl_name)
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>,
potentially with a single level of indirection e.g.
  ID<ID1 *, ID2, ID3 *, ..., IDn>.
It does not try to parse anything more sophisticated than that.

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

References advance(), ENUM, ggc_alloc(), ID, NULL, NUM, parse_error(), require(), require4(), and SCALAR.

Referenced by typedef_name().

◆ require_without_advance()

static const char * require_without_advance ( int t)
static
As per require, but do not advance.   

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

Referenced by type().

◆ str_optvalue_opt()

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

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

Referenced by option().

◆ string_seq()

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

References advance(), CONST_CAST, ggc_alloc(), require(), and STRING.

Referenced by nestedptr_optvalue(), and str_optvalue_opt().

◆ struct_field_seq()

static pair_p struct_field_seq ( void )
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 advance(), consume_until_comma_or_eos(), consume_until_eos(), create_field_at(), declarator(), EOF_TOKEN, ggc_alloc(), IGNORABLE_CXX_KEYWORD, lexer_line, nreverse_pairs(), parse_error(), ty, and type().

Referenced by type().

◆ struct_or_union()

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

References advance(), and type().

Referenced by parse_file().

◆ token()

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

References token::code, and yylex().

Referenced by parser::eat_ident(), parser::expect(), parser::next(), parser::parse_c_expr(), parser::parse_for(), parser::peek(), parser::peek_ident(), require(), require2(), require4(), require_without_advance(), and type().

◆ type()

static type_p type ( options_p * optsp,
bool nested )
static
option handling.   
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(), ENUM, fields, fileloc::file, find_structure(), gcc_assert, get_input_file_name(), ggc_alloc(), GTY_TOKEN, gtymarker_opt(), ID, IGNORABLE_CXX_KEYWORD, lexer_line, fileloc::line, new_structure(), NULL, opts_have(), parse_error(), print_cur_token(), require(), require_without_advance(), resolve_typedef(), SCALAR, STRUCT, struct_field_seq(), token(), TYPE_STRUCT, TYPE_UNION, TYPE_USER_STRUCT, TYPEDEF, typedef_name(), and UNION.

Referenced by absdecl(), add_candidate_1(), add_fixup_edge(), scev_dfs::add_to_evolution_1(), add_to_parts(), add_ttypes_entry(), add_uses(), aff_combination_add_elt(), aff_combination_add_product(), aff_combination_convert(), aff_combination_expand(), aff_combination_zero(), analyze_miv_subscript(), analyze_siv_subscript_cst_affine(), analyze_ziv_subscript(), tree_switch_conversion::switch_conversion::array_value_type(), assert_loop_rolls_lt(), assign_parms_augmented_arg_list(), assign_stack_temp_for_type(), assign_temp(), assumption_copy_decl(), bit_value_assume_aligned(), build_aligned_type(), build_common_builtin_nodes(), build_complex(), build_constructor(), build_debug_expr_decl(), build_decl(), build_duplicate_type(), build_fake_var_decl(), build_fixed(), build_new_int_cst(), build_new_poly_int_cst(), build_nonstandard_boolean_type(), build_offset_type(), tree_switch_conversion::switch_conversion::build_one_array(), build_personality_function(), build_range_type_1(), build_real(), build_string_literal(), can_use_analyze_subscript_affine_affine(), canonicalize_component_ref(), canonicalize_loop_ivs(), check_pow(), check_stmt_for_type_change(), check_target_format(), chrec_convert_aggressive(), chrec_evaluate(), chrec_fold_plus_poly_poly(), clear_padding_flush(), const_binop(), convert_affine_scev(), convert_expand_mult_copysign(), convert_mult_to_widen(), convert_plusminus_to_widen(), convert_to_integer_1(), convert_to_real_1(), copy_decl_to_var(), copy_result_decl_to_var(), create_canonical_iv(), create_expand_operand(), create_expression_by_pieces(), create_field_for_decl(), create_loop_fn(), create_omp_child_function(), create_parallel_loop(), create_subroutine(), create_tmp_var_raw(), create_total_scalarization_access(), ctf_add_array(), ctf_add_encoded(), ctf_add_enum(), ctf_add_forward(), ctf_add_function(), ctf_add_function_arg(), ctf_add_generic(), ctf_add_member_offset(), ctf_add_reftype(), ctf_add_slice(), ctf_add_sou(), ctf_add_typedef(), ctf_dtd_lookup(), decl_for_type_insert(), decl_for_type_lookup(), decompose_param_expr(), default_assemble_visibility(), default_elf_asm_named_section(), default_emutls_var_fields(), pcom_worker::determine_roots_comp(), do_compare_and_jump(), do_jump(), do_narrow(), do_store_flag(), dump_generic_node(), dump_gimple_try(), effective_strub_mode_for_call(), eliminate_local_variables_1(), tree_switch_conversion::jump_table_cluster::emit(), estimate_numbers_of_iterations(), expand_arith_overflow(), expand_builtin_cexpi(), expand_call_mem_ref(), expand_complex_comparison(), expand_complex_operations_1(), expand_DIVMOD(), expand_expr_real_1(), expand_expr_real_2(), expand_ifn_va_arg_1(), expand_load_lanes_optab_fn(), expand_mul_overflow(), 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_omp_taskloop_for_inner(), expand_omp_taskloop_for_outer(), expand_partial_load_optab_fn(), expand_partial_store_optab_fn(), expand_store_lanes_optab_fn(), expand_thunk(), expand_vector_operations_1(), expand_vector_piecewise(), expr_to_aff_combination(), extern_or_static(), extract_muldiv_1(), field_byte_offset(), field_type(), finalize_nesting_tree_1(), find_bivs(), find_reloads(), finish_builtin_struct(), fixup_child_record_type(), fold_binary_loc(), fold_bit_and_mask(), fold_builtin_fpclassify(), fold_builtin_sincos(), fold_const_call(), fold_invert_truthvalue(), cfn_sincos::fold_range(), fold_range_test(), fold_ternary_loc(), fold_truth_andor(), fold_truth_andor_1(), fold_unary_loc(), scev_dfs::follow_ssa_edge_expr(), gen_eh_region(), gen_parallel_loop(), generic_type_for(), get_chain_decl(), get_chain_field(), get_compute_type(), get_emutls_object_type(), get_frame_type(), ipa_icf::sem_item_optimizer::get_group_by_hash(), irange_storage::get_irange(), get_nl_goto_field(), get_odr_type(), prange_storage::get_prange(), get_qualified_type(), get_references_in_stmt(), range_query::get_tree_range(), get_unwidened(), get_use_type(), vrange_storage::get_vrange(), gimple_alloc_histogram_value(), gimple_call_fnspec(), gimple_divmod_values_to_profile(), gimple_expand_builtin_pow(), gimple_fold_builtin_clear_padding(), gimple_fold_builtin_memory_op(), gimple_range_type(), gimple_signed_or_unsigned_type(), gimple_simplify(), gimplify_init_constructor(), gimplify_init_ctor_preeval_1(), go_output_typedef(), strlen_pass::handle_builtin_memcmp(), strlen_pass::handle_builtin_strcat(), strlen_pass::handle_builtin_strcpy(), idx_infer_loop_bounds(), infer_loop_bounds_from_pointer_arith(), infer_loop_bounds_from_signedness(), init_vn_nary_op_from_pieces(), initialize_argument_information(), initialize_reductions(), insert_field_into_struct(), insert_reciprocals(), install_var_field(), instrument_derefs(), instrument_object_size(), interpret_rhs_expr(), invert_truthvalue_loc(), ipa_print_node_jump_functions_for_edge(), iv_period(), layout_decl(), lhd_simulate_record_decl(), lookup_type_for_runtime(), lower_omp_for(), lower_omp_target(), lower_omp_task_reductions(), make_accum_type(), make_bit_field_ref(), make_debug_expr_from_rtl(), make_fract_type(), make_signed_type(), make_tree(), make_unsigned_type(), may_negate_without_overflow_p(), maybe_fold_comparisons_from_match_pd(), negate_expr(), negate_expr_p(), new_insn_reg(), new_omp_region(), next_position(), number_of_iterations_cond(), number_of_iterations_exit_assumptions(), number_of_iterations_le(), number_of_iterations_lt_to_ne(), number_of_iterations_ne(), operator_lshift::op1_range(), optimize_range_tests_1(), optimize_range_tests_cmp_bitwise(), optimize_range_tests_to_bit_test(), optimize_vec_cond_expr(), output_one_function_exception_table(), parloops_is_simple_reduction(), phi_translate_1(), possible_polymorphic_call_targets(), precompute_arguments(), prevailing_odr_type(), print_subroutine_group(), ptr_difference_const(), push_reload(), push_secondary_reload(), qualified_die_p(), record_biv_for_address_use(), record_group(), record_known_type(), record_type(), record_use(), remap_type(), remap_vla_decls(), ipa_polymorphic_call_context::restrict_to_inner_class(), restructure_reference(), rewrite_reciprocal(), scev_var_range_cant_overflow(), separate_decls_in_region(), set_mem_attributes_minus_bitpos(), set_type_binfo(), signed_or_unsigned_type_for(), simd_clone_compute_base_data_type(), simple_iv_with_niters(), simplify_bitfield_ref(), simplify_using_ranges::simplify_internal_call_using_ranges(), simplify_operand_subreg(), simplify_peeled_chrec(), simplify_vector_constructor(), slsr_process_ref(), split_constant_offset(), 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(), tree_predict_by_opcode(), tree_unary_nonnegative_warnv_p(), tree_unary_nonzero_warnv_p(), truth_type_for(), type_hash_canon(), type_main_variant(), typedef_decl(), types_used_by_var_decl_insert(), ubsan_type_descriptor(), vect_create_destination_var(), vect_get_and_check_slp_defs(), vect_recog_cond_expr_convert_pattern(), vect_recog_dot_prod_pattern(), vect_recog_mixed_size_cond_pattern(), vect_recog_rotate_pattern(), vect_recog_widen_op_pattern(), vect_recog_widen_sum_pattern(), vect_update_ivs_after_vectorizer(), vectorizable_simd_clone_call(), vn_nary_may_trap(), vn_phi_compute_hash(), vn_reference_insert_pieces(), vn_reference_lookup_or_insert_for_pieces(), vn_reference_lookup_pieces(), and wide_int_to_tree_1().

◆ type_optvalue()

static options_p type_optvalue ( options_p prev,
const char * name )
static
Type-option: '(' absdecl ')'  

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

Referenced by option().

◆ typedef_decl()

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

References advance(), consume_until_comma_or_eos(), declarator(), do_typedef(), gcc_assert, ggc_alloc(), lexer_line, parse_error(), ty, type(), and TYPEDEF.

Referenced by parse_file().

◆ typedef_name()

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

References ID, require(), and require_template_declaration().

Referenced by type().

Variable Documentation

◆ T

◆ token_names

const char* const token_names[]
static
Initial value:
= {
"GTY",
"typedef",
"extern",
"static",
"union",
"struct",
"enum",
"...",
"ptr_alias",
"nested_ptr",
"user",
"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.   
Keep in sync with 'gengtype.h:enum gty_token'.   

Referenced by print_token().

◆ token_value_format

const char* const token_value_format[]
static
Initial value:
= {
"'%s'",
"'%s'",
"'%s'",
"'\"%s\"'",
"\"'%s'\"",
"'[%s]'",
"'%s'",
}
This array is indexed by token code minus FIRST_TOKEN_WITH_VALUE.   
Keep in sync with 'gengtype.h:enum gty_token'.   

Referenced by print_token().