QuakeForge  0.7.2.210-815cf
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Symbol Table Management

Data Structures

struct  symbol_s
 
struct  symtab_s
 

Typedefs

typedef struct symbol_s symbol_t
 
typedef struct symtab_s symtab_t
 
typedef enum vis_e vis_t
 

Enumerations

enum  stab_type_e {
  stab_global, stab_local, stab_struct, stab_union,
  stab_enum
}
 
enum  sy_type_e {
  sy_var, sy_const, sy_type, sy_expr,
  sy_func, sy_class
}
 
enum  vis_e { vis_public, vis_protected, vis_private }
 

Functions

symbol_tcopy_symbol (symbol_t *symbol)
 Make a copy of a symbol. More...
 
symbol_tmake_symbol (const char *name, struct type_s *type, struct defspace_s *space, enum storage_class_e storage)
 Create a global symbol and allocate space for a variable. More...
 
symbol_tnew_symbol (const char *name)
 Create a new, empty named symbol. More...
 
symbol_tnew_symbol_type (const char *name, struct type_s *type)
 Create a new, typed, named symbol. More...
 
symtab_tnew_symtab (symtab_t *parent, stab_type_e type)
 Create a new, empty symbol table. More...
 
symbol_tsymtab_addsymbol (symtab_t *symtab, symbol_t *symbol)
 Add a symbol to the symbol table. More...
 
symtab_tsymtab_flat_copy (symtab_t *symtab, symtab_t *parent)
 Create a new single symbol table from the given symbol table chain. More...
 
symbol_tsymtab_lookup (symtab_t *symtab, const char *name)
 Lookup a name in the symbol table. More...
 
symbol_tsymtab_removesymbol (symtab_t *symtab, symbol_t *symbol)
 Remove a symbol from the symbol table. More...
 
const char * symtype_str (sy_type_e type)
 

Detailed Description

Typedef Documentation

typedef struct symbol_s symbol_t
typedef struct symtab_s symtab_t
typedef enum vis_e vis_t

Enumeration Type Documentation

Enumerator
stab_global 

global (many symbols)

stab_local 

local (few symbols: func)

stab_struct 
stab_union 
stab_enum 
enum sy_type_e
Enumerator
sy_var 

symbol refers to a variable

sy_const 

symbol refers to a constant

sy_type 

symbol refers to a type

sy_expr 

symbol refers to an expression

sy_func 

symbol refers to a function

sy_class 

symbol refers to a class

enum vis_e
Enumerator
vis_public 
vis_protected 
vis_private 

Function Documentation

symbol_t* copy_symbol ( symbol_t symbol)

Make a copy of a symbol.

The new symbol will not be associated with any table.

Parameters
symbolThe symbol to be copied.
Returns
The new symbol.
symbol_t* make_symbol ( const char *  name,
struct type_s type,
struct defspace_s space,
enum storage_class_e  storage 
)

Create a global symbol and allocate space for a variable.

If the symbol already exists, it must be of the correct type. If it is external, it will be converted to the given storage class and allocatged space from the given defspace, otherwise it will be returned.

If the symbol is new, it will be allocated space from the given defspace with the given storage class.

Parameters
nameThe name of the symbol.
typeThe type of the symbol.
spaceThe defspace from which space will be allocated for the symbol. Ignored for sc_extern, must not be null for others.
storageThe storage class for the symbol. Only sc_extern, sc_global, and sc_static are valid.
symbol_t* new_symbol ( const char *  name)

Create a new, empty named symbol.

Only the symbol name field will be filled in. name will be copied using save_string().

Parameters
nameThe name of the symbol.
Returns
The new symbol.
symbol_t* new_symbol_type ( const char *  name,
struct type_s type 
)

Create a new, typed, named symbol.

Only the symbol name and type fields will be filled in. name will be copied using save_string().

Parameters
nameThe name of the symbol.
typeThe type of the symbol.
Returns
The new symbol.
symtab_t* new_symtab ( symtab_t parent,
stab_type_e  type 
)

Create a new, empty symbol table.

The symbol tables support scoping via their parent pointer. This supports both code block scoping and ivar inheritance.

Parameters
parentPointer to parent scope symbol table.
typeThe type of symbol table. Currently governs expected size.
Returns
The new, empty symbol table.
symbol_t* symtab_addsymbol ( symtab_t symtab,
symbol_t symbol 
)

Add a symbol to the symbol table.

If there is already a symbol with the same name in the symbol table, the symbol will not be added to the table, and the symbol that was found in the table witll be returned.

Parameters
symtabThe symol table to which the symbol will be added.
symbolThe symbol to be added to the symbol table.
Returns
The symbol as in the table, either symbol if no symbol with the same name is already in the symbol table, or the symbol that was found in the table.
symtab_t* symtab_flat_copy ( symtab_t symtab,
symtab_t parent 
)

Create a new single symbol table from the given symbol table chain.

Create a new symbol table and add all of the symbols from the given symbol table chain to the new symbol table. However, in order to preserve scoping rules, duplicate names in ancestor tables will not be added to the new table.

The new symbol table will be "local".

The intended use is for creating the ivar scope for methods.

Parameters
symtabThe symbol table chain to be copied.
parentThe parent symbol table of the new symbol table, or null.
Returns
The new symbol table.
symbol_t* symtab_lookup ( symtab_t symtab,
const char *  name 
)

Lookup a name in the symbol table.

The entire symbol table chain (symtab_t::parent) starting at symtab will be checked for name.

Parameters
symtabThe symbol table to search for name. If name is not in the symbol table, the tables's parent, if it exists, will be checked, and then its parent, until the end of the chain.
nameThe name to look up in the symbol table chain.
symbol_t* symtab_removesymbol ( symtab_t symtab,
symbol_t symbol 
)

Remove a symbol from the symbol table.

Parameters
symtabThe symol table from which the symbol will be removed.
symbolThe symbol to be removed from the symbol table.
Returns
The symbol as was in the table, or NULL if not found.
const char* symtype_str ( sy_type_e  type)