GCC Middle and Back End API Reference
gengtype-state.c File Reference
#include "config.h"
#include "system.h"
#include "errors.h"
#include "double-int.h"
#include "hashtab.h"
#include "version.h"
#include "obstack.h"
#include "gengtype.h"
Include dependency graph for gengtype-state.c:

Data Structures

struct  state_ident_st
struct  state_token_st
class  s_expr_writer
class  state_writer

Macros

#define NULL_STATE_TOKEN   (struct state_token_st*)0
#define fatal_reading_state_printf(Tok, Fmt,...)

Enumerations

enum  state_token_en {
  STOK_NONE, STOK_INTEGER, STOK_STRING, STOK_LEFTPAR,
  STOK_RIGHTPAR, STOK_NAME
}

Functions

static struct fileloctype_lineloc ()
static void fatal_reading_state ()
static struct state_ident_ststate_ident_by_name ()
static struct state_token_stread_a_state_token ()
static struct state_token_stpeek_state_token ()
static void next_state_tokens ()
static enum state_token_en state_token_kind ()
static bool state_token_is_name ()
static int pair_list_length (pair_p list)
static int pair_list_length ()
static void write_state_trailer ()
void write_state ()
static void read_state_fileloc (struct fileloc *line)
static void read_state_options (options_p *opt)
static void read_state_type (type_p *current)
static void read_state_pair (pair_p *pair)
static int read_state_pair_list (pair_p *list)
static void read_state_fields (pair_p *fields)
static void read_state_common_type_content (type_p current)
static void record_type ()
static void read_state_already_seen_type ()
static void read_state_scalar_nonchar_type ()
static void read_state_scalar_char_type ()
static void read_state_string_type ()
static void read_state_lang_bitmap ()
static void read_state_undefined_type ()
static void read_state_struct_type ()
static void read_state_user_struct_type ()
static void read_state_union_type ()
static void read_state_pointer_type ()
static void read_state_array_type ()
static void read_state_lang_struct_type ()
static void read_state_param_struct_type ()
static void read_state_gc_used ()
static void read_state_common_type_content ()
void read_state_type ()
void read_state_fileloc ()
void read_state_fields ()
static void read_state_string_option ()
static void read_state_type_option ()
static void read_state_nested_option ()
static void read_state_option ()
void read_state_options ()
static void read_state_version ()
void read_state_pair ()
int read_state_pair_list ()
static void read_state_typedefs ()
static void read_state_structures ()
static void read_state_param_structs ()
static void read_state_variables ()
static void read_state_srcdir ()
static void read_state_languages ()
static void read_state_files_list ()
static void read_state_trailer ()
static unsigned hash_type_number ()
static int equals_type_number ()
static int string_eq ()
void read_state ()

Variables

static htab_t state_ident_tab
struct state_token_ststate_token = NULL_STATE_TOKEN
static FILE * state_file
static const char * state_path = NULL
static int state_line = 0
static long state_bol = 0
static htab_t state_seen_types

Macro Definition Documentation

#define fatal_reading_state_printf (   Tok,
  Fmt,
  ... 
)
Value:
do { \
struct state_token_st* badtok = Tok; \
if (badtok) \
fatal ("%s:%d:%d: Invalid state file; " Fmt, \
badtok->stok_file, \
badtok->stok_line, \
badtok->stok_col, __VA_ARGS__); \
fatal ("%s:%d: Invalid state file; " Fmt, \
state_path, state_line, __VA_ARGS__); \
} while (0)

Fatal printf-like message while reading state. This can't be a function, because there is no way to pass a va_arg to a variant of fatal.

#define NULL_STATE_TOKEN   (struct state_token_st*)0

Enumeration Type Documentation

The state file has simplistic lispy lexical tokens. Its lexer gives a linked list of struct state_token_st, through the peek_state_token function. Lexical tokens are consumed with next_state_tokens. The lexical kind of each lispy token.

Enumerator:
STOK_NONE 
STOK_INTEGER 
STOK_STRING 
STOK_LEFTPAR 
STOK_RIGHTPAR 
STOK_NAME 

Function Documentation

static int equals_type_number ( )
static
static void fatal_reading_state ( )
inlinestatic

Fatal error messages when reading the state. They are extremely unlikely, and only appear when this gengtype-state.c file is buggy, or when reading a gengtype state which was not generated by the same version of gengtype or GCC. Fatal message while reading state.

References NULL.

Referenced by read_state_fileloc(), read_state_param_structs(), read_state_srcdir(), read_state_type(), and read_state_variables().

static unsigned hash_type_number ( )
static

Utility functions for the state_seen_types hash table.

static int pair_list_length ( pair_p  list)
static

Return the length of a linked list made of pairs.

static int pair_list_length ( )
static

Compute the length of a list of pairs, starting from the first one.

static struct state_token_st* peek_state_token ( )
staticread

Used for lexical look-ahead. Retrieves the lexical token of rank DEPTH, starting with 0 when reading the state file. Gives null on end of file.

Referenced by read_state_fileloc(), read_state_param_structs(), read_state_srcdir(), and read_state_type().

static struct state_token_st* read_a_state_token ( )
staticread

Our token lexer is heavily inspired by MELT's lexer, and share some code with the file gcc/melt-runtime.c of the GCC MELT branch! We really want the gengtype state to be easily parsable by MELT. This is a usual lispy lexing routine, dealing with spaces and comments, numbers, parenthesis, names, strings.

 Handle spaces, count lines.   
 Skip comments starting with semi-colon.   
 Read signed numbers.   
 Read an opening left parenthesis.   
 Read an closing right parenthesis.   
 Read identifiers, using an obstack.   
 Read a string, dealing with escape sequences a la C!  
 Got an unexpected character.   

References state_file.

void read_state ( )

The function reading the state, called by main from gengtype.c.

static void read_state_already_seen_type ( )
static

Read an already seen type.

static void read_state_array_type ( )
static

Read a GTY-ed array type.

Referenced by read_state_gc_used().

static void read_state_common_type_content ( type_p  current)
static
static void read_state_common_type_content ( )
static

Utility function to read the common content of types.

We don't read the next field of the type.

References next_state_tokens(), and NULL.

static void read_state_fields ( pair_p fields)
static
void read_state_fields ( )

Read the fields of a GTY-ed type.

static void read_state_fileloc ( struct fileloc line)
static

End of writing routines! The corresponding reading routines follow. Forward declarations, since some read_state_* functions are recursive!

static void read_state_files_list ( )
static

Read the sequence of files.

Allocate & fill a gt_file entry with space for the lang_bitmap before!

static void read_state_gc_used ( )
static

Read the gc used information.

References next_state_tokens(), and read_state_array_type().

static void read_state_lang_bitmap ( )
static

Read a lang_bitmap representing a set of GCC front-end languages.

static void read_state_lang_struct_type ( )
static

Read a lang_struct type for GTY-ed struct-s which depends upon GCC front-end languages. This is a tricky function and it was painful to debug. Change it with extreme care. See also write_state_lang_struct_type.

Within lang_struct-ures, the lang_struct field is a linked list of homonymous types!

 Parse (!homotypes <number-types> <type-1> .... <type-n>)  
static void read_state_languages ( )
static

Read the sequence of GCC front-end languages.

References type::state_number.

static void read_state_nested_option ( )
static

Read a nested option.

static void read_state_option ( )
static

Read an GTY option.

Referenced by read_state_type_option().

static void read_state_options ( options_p opt)
static
void read_state_options ( )

Read a list of options.

static void read_state_pair ( pair_p pair)
static
void read_state_pair ( )

Read a pair.

static int read_state_pair_list ( pair_p list)
static

Return the number of pairs actually read.

int read_state_pair_list ( )

Return the number of pairs actually read.

don't consume the ); the caller will eat it.

static void read_state_param_struct_type ( )
static

Read a param_struct type for GTY parametrized structures.

References next_state_tokens(), and read_state_struct_type().

static void read_state_pointer_type ( )
static

Read a GTY-ed pointer type.

static void read_state_scalar_char_type ( )
static

Read the scalar_char type.

static void read_state_scalar_nonchar_type ( )
static

Read the scalar_nonchar type.

static void read_state_srcdir ( )
static
static void read_state_string_option ( )
static

Read a string option.

static void read_state_string_type ( )
static

Read the string_type.

References type::kind, and TYPE_USER_STRUCT.

static void read_state_struct_type ( )
static

Read a GTY-ed struct type.

Referenced by read_state_param_struct_type().

static void read_state_structures ( )
static

Read the structures.

static void read_state_trailer ( )
static

Read the trailer.

static void read_state_type ( type_p current)
static

Referenced by read_state_fileloc().

static void read_state_type_option ( )
static

Read a type option.

References options::next, NULL, and read_state_option().

static void read_state_typedefs ( )
static

Read the typedefs.

static void read_state_undefined_type ( )
static

Read an undefined type.

static void read_state_union_type ( )
static

Read a GTY-ed union type.

static void read_state_user_struct_type ( )
static

Read a GTY-ed user-provided struct TYPE.

static void read_state_version ( )
static

Read a version, and check against the version of the gengtype.

Check that the read version string is the same as current version.

static void record_type ( )
static

Record into the state_seen_types hash-table a type which we are reading, to enable recursive or circular references to it.

References DBGPRINTF, NULL, type::s, type::state_number, and type::u.

static struct state_ident_st* state_ident_by_name ( )
staticread

Find or allocate an identifier in our name hash table.

References NULL, state_bol, state_file, and state_line.

static bool state_token_is_name ( )
inlinestatic

Test if a token is a given name i.e. an identifier.

References pair::next, and NULL.

Referenced by read_state_fileloc(), read_state_srcdir(), and read_state_type().

static enum state_token_en state_token_kind ( )
inlinestatic

Safely retrieve the lexical kind of a token.

Referenced by read_state_fileloc(), read_state_param_structs(), read_state_srcdir(), and read_state_type().

static int string_eq ( )
static
static struct fileloc* type_lineloc ( )
staticread

Gengtype persistent state serialization & de-serialization. Useful for gengtype in plugin mode.

Copyright (C) 2010-2013 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 3, 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 COPYING3. If not see http://www.gnu.org/licenses/.

Contributed by Jeremie Salvucci jerem.nosp@m.ie.s.nosp@m.alvuc.nosp@m.ci@f.nosp@m.ree.f.nosp@m.r and Basile Starynkevitch basil.nosp@m.e@st.nosp@m.arynk.nosp@m.evit.nosp@m.ch.ne.nosp@m.t Gives the file location of a type, if any.

References CONST_CAST, gcc_unreachable, NULL, type::param_struct, type::s, TYPE_ARRAY, TYPE_LANG_STRUCT, TYPE_NONE, TYPE_PARAM_STRUCT, TYPE_POINTER, TYPE_SCALAR, TYPE_STRING, TYPE_STRUCT, TYPE_UNDEFINED, TYPE_UNION, TYPE_USER_STRUCT, and type::u.

void write_state ( )

The write_state routine is the only writing routine called by main in gengtype.c. 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.

 We write a unique temporary file which is renamed when complete
 only.  So even if gengtype is interrupted, the written state file
 won't be partially written, since the temporary file is not yet
 renamed in that case.   
 This is the first line of the state.  Perhaps the file utility
 could know about that, so don't change it often.   
 Output a few comments for humans.  
 The first non-comment significant line gives the version string.   

References gcc_assert, and type().

static void write_state_trailer ( )
static

Write the trailer.

This test should probably catch IO errors like disk full...


Variable Documentation

long state_bol = 0
static

Referenced by state_ident_by_name().

htab_t state_ident_tab
static
int state_line = 0
static

Referenced by state_ident_by_name().

const char* state_path = NULL
static
htab_t state_seen_types
static

Following routines are useful for serializing datas.

We want to serialize :

  • typedefs list
  • structures list
  • param_structs list
  • variables list

So, we have one routine for each kind of data. The main writing routine is write_state. The main reading routine is read_state. Most writing routines write_state_FOO have a corresponding reading routine read_state_FOO. Reading is done in a recursive descending way, and any read error is fatal. When reading the state, we need to remember the previously seen types by their state_number, since GTY-ed types are usually shared.

struct state_token_st* state_token = NULL_STATE_TOKEN

the state_token pointer contains the leftmost current token. The tokens are organized in a linked queue, using stok_next, for token look-ahead.