fcml  1.2.2
Classes | Typedefs | Functions
fcml_symbols.h File Reference

API for symbols handling. More...

#include "fcml_lib_export.h"
#include "fcml_common.h"
#include "fcml_errors.h"
Include dependency graph for fcml_symbols.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fcml_st_symbol
 Represents one named symbol with associated value. More...
 

Typedefs

typedef fcml_ptr fcml_st_symbol_table
 Type for symbol tables. More...
 
typedef struct fcml_st_symbol fcml_st_symbol
 Represents one named symbol with associated value. More...
 

Functions

LIB_EXPORT fcml_st_symbol *LIB_CALL fcml_fn_symbol_alloc (const fcml_string symbol, fcml_int64_t value)
 Allocates new symbol on FCML library heap. More...
 
LIB_EXPORT void LIB_CALL fcml_fn_symbol_free (fcml_st_symbol *symbol)
 Frees symbol allocated by FCML library. More...
 
LIB_EXPORT fcml_st_symbol_table LIB_CALL fcml_fn_symbol_table_alloc ()
 Allocates new symbol table. More...
 
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_symbol_add_raw (fcml_st_symbol_table symbol_table, const fcml_string symbol, fcml_int64_t value)
 Adds new symbol to the symbol table. More...
 
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_symbol_add (fcml_st_symbol_table symbol_table, const fcml_st_symbol *symbol)
 Adds existing symbol to the symbol table. More...
 
LIB_EXPORT void LIB_CALL fcml_fn_symbol_remove (fcml_st_symbol_table symbol_table, const fcml_string symbol)
 Removes the symbol from the symbol table. More...
 
LIB_EXPORT fcml_st_symbol *LIB_CALL fcml_fn_symbol_get (fcml_st_symbol_table symbol_table, const fcml_string symbol)
 Gets the symbol with the given name from the symbol table. More...
 
LIB_EXPORT void LIB_CALL fcml_fn_symbol_remove_all (fcml_st_symbol_table symbol_table)
 Removes all symbols from the symbol table. More...
 
LIB_EXPORT void LIB_CALL fcml_fn_symbol_table_free (fcml_st_symbol_table symbol_table)
 Frees a symbol table. More...
 

Detailed Description

API for symbols handling.

Currently used only by parsers.

Typedef Documentation

◆ fcml_st_symbol

Represents one named symbol with associated value.

◆ fcml_st_symbol_table

typedef fcml_ptr fcml_st_symbol_table

Type for symbol tables.

Function Documentation

◆ fcml_fn_symbol_add()

LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_symbol_add ( fcml_st_symbol_table  symbol_table,
const fcml_st_symbol symbol 
)

Adds existing symbol to the symbol table.

Remember that only symbols allocated on FCML heap should be added there. Of course in some cases heaps are shared so it will works without any problems but even if they are you should use fcml_fn_symbol_table_alloc() function to allocate every symbol.

Parameters
symbol_tableThe symbol table where new symbol should be placed.
symbolThe symbol to be added.
Returns
Error code or FCML_CEH_GEC_NO_ERROR.

◆ fcml_fn_symbol_add_raw()

LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_symbol_add_raw ( fcml_st_symbol_table  symbol_table,
const fcml_string  symbol,
fcml_int64_t  value 
)

Adds new symbol to the symbol table.

This function is more secure than fcml_fn_symbol_add() because it always allocates new symbol instance internally, so you do not have to pay attention not to pass the symbol allocated on the different heap to the symbol table. After the symbol has been properly added you can safely free the name because this function duplicates the name to the symbol needs. Of course the symbol as well as the duplicated name are freed by fcml_fn_symbol_table_free() function. You can also free it on your own if the symbol is not managed by symbol table using fcml_fn_symbol_free() function.

Parameters
symbol_tableThe symbol table.
symbolThe symbol name.
valueThe symbol value.
See also
fcml_fn_symbol_table_free

◆ fcml_fn_symbol_alloc()

LIB_EXPORT fcml_st_symbol* LIB_CALL fcml_fn_symbol_alloc ( const fcml_string  symbol,
fcml_int64_t  value 
)

Allocates new symbol on FCML library heap.

This function should be always used when symbols are added using fcml_fn_symbol_add() function.

Returns
Allocated symbol or NULL if allocation failed.

◆ fcml_fn_symbol_free()

LIB_EXPORT void LIB_CALL fcml_fn_symbol_free ( fcml_st_symbol symbol)

Frees symbol allocated by FCML library.

Parameters
symbolThe symbol to be freed.

◆ fcml_fn_symbol_get()

LIB_EXPORT fcml_st_symbol* LIB_CALL fcml_fn_symbol_get ( fcml_st_symbol_table  symbol_table,
const fcml_string  symbol 
)

Gets the symbol with the given name from the symbol table.

Parameters
symbol_tableThe symbol table.
symbolThe name of the symbol to get from the table.
Returns
The pointer to the symbol or NULL if there is no such symbol in the symbol table.

◆ fcml_fn_symbol_remove()

LIB_EXPORT void LIB_CALL fcml_fn_symbol_remove ( fcml_st_symbol_table  symbol_table,
const fcml_string  symbol 
)

Removes the symbol from the symbol table.

The removed symbol is automatically freed.

Parameters
symbol_tableThe symbol table.
symbolThe name of the symbol to remove.

◆ fcml_fn_symbol_remove_all()

LIB_EXPORT void LIB_CALL fcml_fn_symbol_remove_all ( fcml_st_symbol_table  symbol_table)

Removes all symbols from the symbol table.

Removes and frees all symbols from the given symbol table but does not free the symbol table itself.

Parameters
symbol_tableThe symbol table to be cleared.

◆ fcml_fn_symbol_table_alloc()

LIB_EXPORT fcml_st_symbol_table LIB_CALL fcml_fn_symbol_table_alloc ( )

Allocates new symbol table.

Returns
The allocated symbol table or NULL if something failed.

◆ fcml_fn_symbol_table_free()

LIB_EXPORT void LIB_CALL fcml_fn_symbol_table_free ( fcml_st_symbol_table  symbol_table)

Frees a symbol table.

Frees all symbols as well as the symbol table itself.

Parameters
symbol_tableA symbol table to be freed.