GCC Middle and Back End API Reference
state_writer Class Reference
Inheritance diagram for state_writer:
Collaboration diagram for state_writer:

Public Member Functions

 state_writer ()
void write_new_line ()
void write_any_indent (int leading_spaces)
void begin_s_expr (const char *tag)
void end_s_expr ()

Private Member Functions

void write_state_fileloc (struct fileloc *floc)
void write_state_fields (pair_p fields)
void write_state_a_string (const char *s)
void write_state_string_option (options_p current)
void write_state_type_option (options_p current)
void write_state_nested_option (options_p current)
void write_state_option (options_p current)
void write_state_options (options_p opt)
void write_state_lang_bitmap (lang_bitmap bitmap)
void write_state_version (const char *version)
void write_state_scalar_type (type_p current)
void write_state_string_type (type_p current)
void write_state_callback_type (type_p current)
void write_state_undefined_type (type_p current)
void write_state_struct_union_type (type_p current, const char *kindstr)
void write_state_struct_type (type_p current)
void write_state_user_struct_type (type_p current)
void write_state_union_type (type_p current)
void write_state_lang_struct_type (type_p current)
void write_state_pointer_type (type_p current)
void write_state_array_type (type_p current)
void write_state_gc_used (enum gc_used_enum gus)
void write_state_common_type_content (type_p current)
void write_state_type (type_p current)
void write_state_pair (pair_p current)
int write_state_pair_list (pair_p list)
void write_state_typedefs (void)
void write_state_structures (void)
void write_state_variables (void)
void write_state_srcdir (void)
void write_state_files_list (void)
void write_state_languages (void)

Private Attributes

int m_state_written_type_count
int m_indent_amount
int m_had_recent_newline


void write_state (const char *state_path)

Detailed Description

A class for writing out "gtype.state".   

Constructor & Destructor Documentation

◆ state_writer()

state_writer::state_writer ( )
class state_writer's trivial constructor.   

Member Function Documentation

◆ begin_s_expr()

void s_expr_writer::begin_s_expr ( const char * tag)
Write the beginning of a new s-expresion e.g. "(!foo "
The writer automatically adds whitespace to show the hierarchical
structure of the expressions, so each one starts on a new line,
and any within it will be at an increased indentation level.   

References ggc_alloc(), s_expr_writer::m_indent_amount, state_file, s_expr_writer::write_any_indent(), and s_expr_writer::write_new_line().

Referenced by write_state_fields(), write_state_fileloc(), write_state_files_list(), write_state_lang_struct_type(), write_state_languages(), write_state_option(), write_state_options(), write_state_pair(), write_state_srcdir(), write_state_structures(), write_state_type(), write_state_typedefs(), write_state_variables(), and write_state_version().

◆ end_s_expr()

◆ write_any_indent()

void s_expr_writer::write_any_indent ( int leading_spaces)
If we've just had a newline, write the indentation amount, potentially
omitting some spaces.

LEADING_SPACES exists to support code that writes strings with leading
spaces (e.g " foo") which might occur within a line, or could be the first
thing on a line.  By passing leading_spaces == 1, when such a string is the
first thing on a line, write_any_indent () swallows the successive
leading spaces into the indentation so that the "foo" begins at the expected

References ggc_alloc(), i, s_expr_writer::m_had_recent_newline, s_expr_writer::m_indent_amount, and state_file.

Referenced by s_expr_writer::begin_s_expr(), s_expr_writer::end_s_expr(), write_state_a_string(), write_state_array_type(), write_state_callback_type(), write_state_common_type_content(), write_state_gc_used(), write_state_lang_bitmap(), write_state_nested_option(), write_state_option(), write_state_options(), write_state_pair(), write_state_pointer_type(), write_state_scalar_type(), write_state_string_option(), write_state_string_type(), write_state_struct_union_type(), write_state_type(), write_state_type_option(), write_state_undefined_type(), and write_state_user_struct_type().

◆ write_new_line()

void s_expr_writer::write_new_line ( void )
Write a newline to the output file, merging adjacent newlines.   

References ggc_alloc(), s_expr_writer::m_had_recent_newline, and state_file.

Referenced by s_expr_writer::begin_s_expr(), s_expr_writer::end_s_expr(), and write_state_structures().

◆ write_state_a_string()

◆ write_state_array_type()

void state_writer::write_state_array_type ( type_p current)

◆ write_state_callback_type()

void state_writer::write_state_callback_type ( type_p current)
Write the callback type.  There is only one such thing!  

References callback_type, fatal(), ggc_alloc(), state_file, s_expr_writer::write_any_indent(), and write_state_common_type_content().

Referenced by write_state_type().

◆ write_state_common_type_content()

void state_writer::write_state_common_type_content ( type_p current)

◆ write_state_fields()

◆ write_state_fileloc()

void state_writer::write_state_fileloc ( struct fileloc * floc)
Write a file location.  Files relative to $(srcdir) are quite
frequent and are handled specially.  This ensures that two gengtype
state file-s produced by gengtype on the same GCC source tree are
very similar and can be reasonably compared with diff, even if the
two GCC source trees have different absolute paths.   

References s_expr_writer::begin_s_expr(), s_expr_writer::end_s_expr(), gcc_assert, get_file_srcdir_relative_path(), get_input_file_name(), ggc_alloc(), NULL, state_file, and write_state_a_string().

Referenced by write_state_pair(), write_state_struct_union_type(), write_state_undefined_type(), and write_state_user_struct_type().

◆ write_state_files_list()

◆ write_state_gc_used()

void state_writer::write_state_gc_used ( enum gc_used_enum gus)

◆ write_state_lang_bitmap()

void state_writer::write_state_lang_bitmap ( lang_bitmap bitmap)
Write a bitmap representing a set of GCC front-end languages.   

References ggc_alloc(), state_file, and s_expr_writer::write_any_indent().

Referenced by write_state_struct_union_type().

◆ write_state_lang_struct_type()

void state_writer::write_state_lang_struct_type ( type_p current)
Write a lang_struct type.  This is tricky and was painful to debug,
we deal with the next field specifically within their lang_struct
subfield, which points to a linked list of homonumous types.
Change this function with extreme care, see also

References s_expr_writer::begin_s_expr(), DBGPRINTF, s_expr_writer::end_s_expr(), gcc_assert, ggc_alloc(), type::lang_struct, NULL, type::s, state_file, type::state_number, type::u, union_or_struct_p(), write_state_struct_union_type(), and write_state_type().

Referenced by write_state_type().

◆ write_state_languages()

void state_writer::write_state_languages ( void )
Write the list of GCC front-end languages.   

References s_expr_writer::begin_s_expr(), s_expr_writer::end_s_expr(), ggc_alloc(), i, lang_dir_names, num_lang_dirs, and state_file.

◆ write_state_nested_option()

◆ write_state_option()

◆ write_state_options()

◆ write_state_pair()

◆ write_state_pair_list()

int state_writer::write_state_pair_list ( pair_p list)
Write a pair list and return the number of pairs written.   

References ggc_alloc(), pair::next, NULL, and write_state_pair().

Referenced by write_state_fields(), write_state_typedefs(), and write_state_variables().

◆ write_state_pointer_type()

void state_writer::write_state_pointer_type ( type_p current)

◆ write_state_scalar_type()

void state_writer::write_state_scalar_type ( type_p current)
Write a scalar type.  We have only two of these.   

References fatal(), ggc_alloc(), scalar_char, scalar_nonchar, state_file, s_expr_writer::write_any_indent(), and write_state_common_type_content().

Referenced by write_state_type().

◆ write_state_srcdir()

void state_writer::write_state_srcdir ( void )
Write the source directory.  File locations within the source
directory have been written specifically.   

References s_expr_writer::begin_s_expr(), s_expr_writer::end_s_expr(), srcdir, and write_state_a_string().

◆ write_state_string_option()

void state_writer::write_state_string_option ( options_p current)
Our option-s have three kinds, each with its writer.   

References ggc_alloc(), options::info, NULL, state_file, options::string, s_expr_writer::write_any_indent(), and write_state_a_string().

Referenced by write_state_option().

◆ write_state_string_type()

void state_writer::write_state_string_type ( type_p current)
Write the string type.  There is only one such thing!  

References fatal(), ggc_alloc(), state_file, string_type, s_expr_writer::write_any_indent(), and write_state_common_type_content().

Referenced by write_state_type().

◆ write_state_struct_type()

void state_writer::write_state_struct_type ( type_p current)

◆ write_state_struct_union_type()

◆ write_state_structures()

◆ write_state_type()

◆ write_state_type_option()

void state_writer::write_state_type_option ( options_p current)

◆ write_state_typedefs()

void state_writer::write_state_typedefs ( void )
When writing imported linked lists, like typedefs, structures, ... we count
their length first and write it.  This eases the reading, and enables an
extra verification on the number of actually read items.   
Write our typedefs.   

References s_expr_writer::begin_s_expr(), s_expr_writer::end_s_expr(), gcc_assert, ggc_alloc(), pair_list_length(), progname, state_file, typedefs, verbosity_level, and write_state_pair_list().

◆ write_state_undefined_type()

◆ write_state_union_type()

void state_writer::write_state_union_type ( type_p current)
write a GTY union type.   

References type::lang_struct, type::s, type::u, write_state_struct_union_type(), and write_state_type().

Referenced by write_state_type().

◆ write_state_user_struct_type()

◆ write_state_variables()

◆ write_state_version()

void state_writer::write_state_version ( const char * version)

Friends And Related Symbol Documentation

◆ write_state

void write_state ( const char * state_path)
The write_state routine is the only writing routine called by main
in gengtype.cc.  To avoid messing the state if gengtype is
interrupted or aborted, we write a temporary file and rename it
after having written it in totality.   
Write the state, and update the state_number field in types.   

Field Documentation

◆ m_had_recent_newline

int s_expr_writer::m_had_recent_newline

◆ m_indent_amount

int s_expr_writer::m_indent_amount

◆ m_state_written_type_count

int state_writer::m_state_written_type_count

Referenced by write_state_type().

The documentation for this class was generated from the following file: