GCC Middle and Back End API Reference
gengtype.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  input_file_st
struct  fileloc
struct  options
struct  nested_ptr_data
struct  pair
struct  type
struct  outf

Macros

#define obstack_chunk_alloc   ((void *(*) (long)) xmalloc)
#define obstack_chunk_free   ((void (*) (void *)) free)
#define OBSTACK_CHUNK_SIZE   0
#define NUM_PARAM   10
#define UNION_P(x)
#define DBGPRINTF(Fmt,...)   do {/*nodbgrintf*/} while (0)
#define DBGPRINT_COUNT_TYPE(Msg, Ty)   do{/*nodbgprint_count_type*/}while (0)
#define FOR_ALL_INHERITED_FIELDS(TYPE, FIELD_VAR)

Typedefs

typedef unsigned lang_bitmap
typedef struct input_file_st input_file
typedef struct pairpair_p
typedef struct typetype_p
typedef struct typeconst_type_p
typedef struct optionsoptions_p
typedef struct outfoutf_p

Enumerations

enum  typekind {
  TYPE_NONE = 0, TYPE_UNDEFINED, TYPE_SCALAR, TYPE_STRING,
  TYPE_STRUCT, TYPE_UNION, TYPE_POINTER, TYPE_ARRAY,
  TYPE_LANG_STRUCT, TYPE_PARAM_STRUCT, TYPE_USER_STRUCT
}
enum  option_kind { OPTION_NONE = 0, OPTION_STRING, OPTION_TYPE, OPTION_NESTED }
enum  gc_used_enum { GC_UNUSED = 0, GC_USED, GC_MAYBE_POINTED_TO, GC_POINTED_TO }

Functions

input_fileinput_file_by_name (const char *name)
const char * get_file_srcdir_relative_path (const input_file *inpf)
static const char * get_input_file_name ()
static lang_bitmap get_lang_bitmap ()
static void set_lang_bitmap ()
options_p create_string_option (options_p next, const char *name, const char *info)
options_p create_type_option (options_p next, const char *name, type_p info)
options_p create_nested_option (options_p next, const char *name, struct nested_ptr_data *info)
options_p create_nested_ptr_option (options_p, type_p t, const char *from, const char *to)
static bool union_or_struct_p ()
static struct fileloctype_fileloc ()
void oprintf (ATTRIBUTE_PRINTF_2, outf_p get_output_file_with_visibility(input_file *inpf), const char *get_output_file_name(input_file *inpf), extern const char *srcdir, extern size_t srcdir_len, extern const char *read_state_filename, extern const char *write_state_filename, void read_state(const char *path), void write_state(const char *path), extern void error_at_line(const struct fileloc *pos, const char *msg,...) ATTRIBUTE_PRINTF_2, extern char *xasprintf(const char *,...) ATTRIBUTE_PRINTF_1, extern void do_typedef(const char *s, type_p t, struct fileloc *pos), extern void do_scalar_typedef(const char *s, struct fileloc *pos), extern type_p resolve_typedef(const char *s, struct fileloc *pos), extern void add_subclass(type_p base, type_p subclass), extern type_p new_structure(const char *name, enum typekind kind, struct fileloc *pos, pair_p fields, options_p o, type_p base), type_p create_user_defined_type(const char *, struct fileloc *), extern type_p find_structure(const char *s, enum typekind kind), extern type_p create_scalar_type(const char *name), extern type_p create_pointer(type_p t), extern type_p create_array(type_p t, const char *len), extern pair_p create_field_at(pair_p next, type_p type, const char *name, options_p opt, struct fileloc *pos), extern pair_p nreverse_pairs(pair_p list), extern type_p adjust_field_type(type_p, options_p), extern void note_variable(const char *s, type_p t, options_p o, struct fileloc *pos), extern int yylex(const char **yylval), extern void yybegin(const char *fname), extern void yyend(void), extern void parse_file(const char *name), extern bool hit_error, enum gty_token)
bool opts_have (options_p opts, const char *str)

Variables

const input_file ** gt_files
size_t num_gt_files
input_filethis_file
input_filesystem_h_file
const char ** lang_dir_names
size_t num_lang_dirs
int lexer_toplevel_done
struct fileloc lexer_line
pair_p typedefs
type_p structures
type_p param_structs
pair_p variables
struct type string_type
struct type scalar_nonchar
struct type scalar_char
outf_p output_files
outf_p header_file
int verbosity_level
int do_dump
int do_debug

Macro Definition Documentation

#define DBGPRINT_COUNT_TYPE (   Msg,
  Ty 
)    do{/*nodbgprint_count_type*/}while (0)
#define DBGPRINTF (   Fmt,
  ... 
)    do {/*nodbgrintf*/} while (0)
#define FOR_ALL_INHERITED_FIELDS (   TYPE,
  FIELD_VAR 
)
Value:
for (type_p sub = (TYPE); sub; sub = sub->u.s.base_class) \
for (FIELD_VAR = sub->u.s.fields; FIELD_VAR; FIELD_VAR = FIELD_VAR->next)
#define NUM_PARAM   10

We can have at most ten type parameters in parameterized structures.

#define obstack_chunk_alloc   ((void *(*) (long)) xmalloc)

Process source files and output type information. Copyright (C) 2002-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/.

#define obstack_chunk_free   ((void (*) (void *)) free)
#define OBSTACK_CHUNK_SIZE   0
#define UNION_P (   x)
Value:
((x)->kind == TYPE_UNION \
|| ((x)->kind == TYPE_LANG_STRUCT \
&& (x)->u.s.lang_struct->kind == TYPE_UNION))

Test if a type is a union, either a plain one or a language specific one.


Typedef Documentation

typedef struct type* const_type_p
typedef struct input_file_st input_file
typedef unsigned lang_bitmap

Sets of accepted source languages like C, C++, Ada... are represented by a bitmap.

typedef struct options* options_p
typedef struct outf* outf_p
typedef struct pair* pair_p

Data types handed around within, but opaque to, the lexer and parser.

typedef struct type* type_p

Enumeration Type Documentation

Usage information for GTY-ed types. Gengtype has to care only of used GTY-ed types. Types are initially unused, and their usage is computed by set_gc_used_type and set_gc_used functions.

Enumerator:
GC_UNUSED 

We need that zeroed types are initially unused.

GC_USED 

The GTY-ed type is used, e.g by a GTY-ed variable or a field inside a GTY-ed used type.

GC_MAYBE_POINTED_TO 

For GTY-ed structures whose definitions we haven't seen so far when we encounter a pointer to it that is annotated with ``maybe_undef''. If after reading in everything we don't have source file information for it, we assume that it never has been defined.

GC_POINTED_TO 

For known GTY-ed structures which are pointed to by GTY-ed variables or fields.

Discriminating kind for options.

Enumerator:
OPTION_NONE 
OPTION_STRING 
OPTION_TYPE 
OPTION_NESTED 
enum typekind

Discrimating kind of types we can understand.

Enumerator:
TYPE_NONE 
TYPE_UNDEFINED 
TYPE_SCALAR 
TYPE_STRING 
TYPE_STRUCT 
TYPE_UNION 
TYPE_POINTER 
TYPE_ARRAY 
TYPE_LANG_STRUCT 
TYPE_PARAM_STRUCT 
TYPE_USER_STRUCT 

Function Documentation

options_p create_nested_option ( options_p  next,
const char *  name,
struct nested_ptr_data info 
)

Create a nested option.

options_p create_nested_ptr_option ( options_p  ,
type_p  t,
const char *  from,
const char *  to 
)

Create a nested pointer option.

options_p create_string_option ( options_p  next,
const char *  name,
const char *  info 
)

Some functions to create various options structures with name NAME and info INFO. NEXT is the next option in the chain. Create a string option.

options_p create_type_option ( options_p  next,
const char *  name,
type_p  info 
)

Create a type option.

const char* get_file_srcdir_relative_path ( const input_file inpf)

For F an input_file, return the relative path to F from if the latter is a prefix in F, NULL otherwise.

static const char* get_input_file_name ( )
inlinestatic

Get the name of an input file.

References input_file_st::inpbitmap, and NULL.

Referenced by print_cur_token().

static lang_bitmap get_lang_bitmap ( )
inlinestatic

Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff INPUT_FILE is used by <lang>.

This function should be written to assume that a file is used if the situation is unclear. If it wrongly assumes a file is used, a linker error will result. If it wrongly assumes a file is not used, some GC roots may be missed, which is a much harder-to-debug problem.

References gcc_assert, and input_file_st::inpbitmap.

Referenced by do_typedef().

input_file* input_file_by_name ( const char *  name)

Retrieve or create the input_file for a given name, which is a file path. This is the only function allocating input_file-s and it is hash-consing them.

Referenced by read_state_type(), and read_state_variables().

void oprintf ( ATTRIBUTE_PRINTF_2  ,
outf_p   get_output_file_with_visibilityinput_file *inpf,
const char *  get_output_file_nameinput_file *inpf,
extern const char *  srcdir,
extern size_t  srcdir_len,
extern const char *  read_state_filename,
extern const char *  write_state_filename,
void   read_stateconst char *path,
void   write_stateconst char *path,
extern void error_at_line(const struct fileloc *pos, const char *msg,...)  ATTRIBUTE_PRINTF_2,
extern char *xasprintf(const char *,...)  ATTRIBUTE_PRINTF_1,
extern void   do_typedefconst char *s, type_p t, struct fileloc *pos,
extern void   do_scalar_typedefconst char *s, struct fileloc *pos,
extern type_p   resolve_typedefconst char *s, struct fileloc *pos,
extern void   add_subclasstype_p base, type_p subclass,
extern type_p   new_structureconst char *name, enum typekind kind,struct fileloc *pos, pair_p fields,options_p o, type_p base,
type_p   create_user_defined_typeconst char *, struct fileloc *,
extern type_p   find_structureconst char *s, enum typekind kind,
extern type_p   create_scalar_typeconst char *name,
extern type_p   create_pointertype_p t,
extern type_p   create_arraytype_p t, const char *len,
extern pair_p   create_field_atpair_p next, type_p type,const char *name, options_p opt,struct fileloc *pos,
extern pair_p   nreverse_pairspair_p list,
extern type_p   adjust_field_typetype_p, options_p,
extern void   note_variableconst char *s, type_p t, options_p o,struct fileloc *pos,
extern int   yylexconst char **yylval,
extern void   yybeginconst char *fname,
extern void   yyendvoid,
extern void   parse_fileconst char *name,
extern bool  hit_error,
enum  gty_token 
)

Print, like fprintf, to O. No-op if O is NULL.

Per standard convention, codes in the range (0, UCHAR_MAX] represent single characters with those character codes.

 print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
 a meaningful value to be printed.   
Parameters:
get_output_file_with_visibilityAn output file, suitable for definitions, that can see declarations made in INPF and is linked into every language that uses INPF. May return NULL in plugin mode. The INPF argument is almost const, but since the result is cached in its inpoutf field it cannot be declared const.
get_output_file_nameThe name of an output file, suitable for definitions, that can see declarations made in INPF and is linked into every language that uses INPF. May return NULL.
srcdirSource directory.
srcdir_lenLength of srcdir name.
read_state_filenameVariable used for reading and writing the state.
read_stateFunctions reading and writing the entire gengtype state, called from main, and implemented in file gengtype-state.c.
write_stateWrite the state, and update the state_number field in types.
ATTRIBUTE_PRINTF_2Print an error message.
ATTRIBUTE_PRINTF_1Like asprintf, but calls fatal() on out of memory.
do_typedefConstructor routines for types.
yylexLexer and parser routines.
gty_tokenToken codes.

References SCALAR, and UCHAR_MAX.

bool opts_have ( options_p  opts,
const char *  str 
)
static void set_lang_bitmap ( )
inlinestatic

Set the bitmap returned by get_lang_bitmap. The only legitimate callers of this function are read_input_list & read_state_*.

References lexer_line, and lexer_toplevel_done.

Referenced by read_state_variables().

static struct fileloc* type_fileloc ( )
staticread

Give the file location of a type, if any.

static bool union_or_struct_p ( )
inlinestatic

Test if a type is a union or a structure, perhaps a language specific one.


Variable Documentation

int do_debug

Trace the execution by many DBGPRINTF (with the position inside gengtype source code). Only useful to debug gengtype itself.

int do_dump

For debugging purposes we provide two flags. Dump everything to understand gengtype's state. Might be useful to gengtype users.

Variables to help debugging.

const input_file** gt_files

Table of all input files and its size.

Input file handling. Table of all input files.

Referenced by read_state_variables().

outf_p header_file

The output header file that is included into pretty much every source file.

const char** lang_dir_names

Vector of per-language directories.

Referenced by read_state_param_structs(), and state_writer::write_state_param_structs().

struct fileloc lexer_line

Referenced by print_cur_token(), and set_lang_bitmap().

int lexer_toplevel_done

Variables used to communicate between the lexer and the parser.

Referenced by set_lang_bitmap().

size_t num_gt_files
size_t num_lang_dirs
outf_p output_files

The list of output files.

Process source files and output type information. Copyright (C) 2002-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/. Data types, macros, etc. used only in this file. The list of output files.

type_p param_structs
struct type scalar_char
struct type scalar_nonchar

The two and only TYPE_SCALARs. Their u.scalar_is_char flags are set early in main.

struct type string_type

The one and only TYPE_STRING.

type_p structures
input_file* system_h_file

The "system.h" file is likewise specially useful.

input_file* this_file

A number of places use the name of this "gengtype.c" file for a location for things that we can't rely on the source to define. We also need to refer to the "system.h" file specifically. These two pointers are initialized early in main.

A number of places use the name of this "gengtype.c" file for a location for things that we can't rely on the source to define. Make sure we can still use pointer comparison on filenames.

pair_p typedefs

Various things, organized as linked lists, needed both in gengtype.c & in gengtype-state.c files.

Lists of various things.

pair_p variables
int verbosity_level

Level for verbose messages, e.g. output file generation...

Level for verbose messages.