Clan  0.8.0
Functions
symbol.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <osl/macros.h>
#include <osl/strings.h>
#include <osl/generic.h>
#include <osl/relation.h>
#include <osl/relation_list.h>
#include <osl/extensions/arrays.h>
#include <clan/macros.h>
#include <clan/symbol.h>
Include dependency graph for symbol.c:

Go to the source code of this file.

Functions

void yyerror (char *)
void clan_symbol_print_structure (FILE *file, clan_symbol_p symbol, int level)
void clan_symbol_print (FILE *file, clan_symbol_p symbol)
clan_symbol_p clan_symbol_malloc ()
void clan_symbol_free (clan_symbol_p symbol)
clan_symbol_p clan_symbol_lookup (clan_symbol_p symbol, char *identifier)
clan_symbol_p clan_symbol_lookup_by_key (clan_symbol_p symbol, int key)
static int clan_symbol_generate_new_key (clan_symbol_p table)
clan_symbol_p clan_symbol_add (clan_symbol_p *table, char *identifier, int type)
int clan_symbol_get_key (clan_symbol_p symbol, char *identifier)
int clan_symbol_get_rank (clan_symbol_p symbol, char *identifier)
int clan_symbol_get_type (clan_symbol_p symbol, char *identifier)
osl_strings_p clan_symbol_array_to_strings (clan_symbol_p *sarray, int size)
int clan_symbol_nb_of_type (clan_symbol_p symbol, int type)
osl_generic_p clan_symbol_to_strings (clan_symbol_p symbol, int type)
clan_symbol_p clan_symbol_clone_one (clan_symbol_p symbol)
osl_generic_p clan_symbol_to_arrays (clan_symbol_p symbol)
int clan_symbol_new_iterator (clan_symbol_p *table, clan_symbol_p *array, char *id, int depth)
int clan_symbol_update_type (clan_symbol_p table, osl_relation_list_p access, int type)

Function Documentation

clan_symbol_p clan_symbol_add ( clan_symbol_p table,
char *  identifier,
int  type 
)

clan_symbol_add function: This function adds a new clan_symbol_t in the symbol table whose address is provided as a parameter. If the symbol table is empty (NULL), the new node will become its first element. A new node is added only if an existing node with the same identifier does not already exist. It returns the pointer to the symbol table node corresponding to the identifier.

Parameters:
[in,out]tableThe address of the symbol table.
[in]identifierThe identifier of the symbol we want to add.
[in]typeThe new symbol type.

Definition at line 301 of file symbol.c.

References clan_symbol_generate_new_key(), clan_symbol_lookup(), clan_symbol_malloc(), clan_symbol::identifier, clan_symbol::key, clan_symbol::next, and clan_symbol::type.

Referenced by clan_symbol_new_iterator(), and yyparse().

osl_strings_p clan_symbol_array_to_strings ( clan_symbol_p sarray,
int  size 
) [read]

clan_symbol_array_to_strings function: this functions builds (and returns a pointer to) an osl_strings_t structure containing the symbol strings contained in an array of symbols of length nb. The symbol string order is the same as the one in the symbol array.

Parameters:
[in]sarrayThe symbol array.
[in]sizeThe size of the symbol array.
Returns:
An osl_strings_t containing all the symbol strings.

Definition at line 399 of file symbol.c.

References CLAN_malloc.

Referenced by yyparse().

clan_symbol_clone_one function: this function clones one symbol, i.e., it returns the clone of the symbol provided as an argument only, with a next field set to NULL.

Parameters:
symbolThe symbol to clone.
Returns:
The clone of the symbol (and this symbol only).

Definition at line 502 of file symbol.c.

References clan_symbol_malloc(), clan_symbol::identifier, clan_symbol::rank, and clan_symbol::type.

Referenced by clan_symbol_new_iterator().

void clan_symbol_free ( clan_symbol_p  symbol)

clan_symbol_free function: This function frees the allocated memory for a clan_symbol_t structure.

Parameters:
[in,out]symbolThe pointer to the symbol we want to free.

Definition at line 214 of file symbol.c.

References clan_symbol::identifier, and clan_symbol::next.

Referenced by clan_parser_reinitialize(), clan_parser_state_free(), and yyparse().

static int clan_symbol_generate_new_key ( clan_symbol_p  table) [static]

clan_symbol_generate_new_key function: this function generates a key which is not yet present in the table.

Parameters:
[in]tableThe first element of the symbol table.
Returns:
A key which would be convenient for a new symbol.

Definition at line 278 of file symbol.c.

References CLAN_KEY_START, clan_symbol::key, and clan_symbol::next.

Referenced by clan_symbol_add().

int clan_symbol_get_key ( clan_symbol_p  symbol,
char *  identifier 
)

clan_symbol_get_key function: This function returns the key of the symbol with identifier "identifier" in the symbol table whose first element is "symbol". If the symbol with the specified identifier is not found, it returns CLAN_UNDEFINED.

Parameters:
[in]symbolThe first node of the list of symbols.
[in]identifierThe identifier we want to know the key.
Returns:
The key corresponding to the identifier or CLAN_UNDEFINED.

Definition at line 338 of file symbol.c.

References CLAN_UNDEFINED, clan_symbol::identifier, clan_symbol::key, and clan_symbol::next.

int clan_symbol_get_rank ( clan_symbol_p  symbol,
char *  identifier 
)

clan_symbol_get_rank function: This function returns the rank of the symbol with identifier "identifier" in the symbol table whose first element is "symbol". If the symbol with the specified identifier is not found, it returns -1.

Parameters:
[in]symbolThe first node of the list of symbols.
[in]identifierThe identifier we want to know the key.
Returns:
The rank corresponding to the identifier or CLAN_UNDEFINED.

Definition at line 358 of file symbol.c.

References CLAN_UNDEFINED, clan_symbol::identifier, clan_symbol::next, and clan_symbol::rank.

Referenced by clan_vector_term().

int clan_symbol_get_type ( clan_symbol_p  symbol,
char *  identifier 
)

clan_symbol_get_type function: This function returns the type of the symbol with identifier "identifier" in the symbol table whose first element is "symbol". If the symbol with the specified identifier is not found, it returns -1.

Parameters:
[in]symbolThe first node of the list of symbols.
[in]identifierThe identifier we want to know the type.
Returns:
The type of the symbol corresponding to the identifier.

Definition at line 378 of file symbol.c.

References CLAN_UNDEFINED, clan_symbol::identifier, clan_symbol::next, and clan_symbol::type.

Referenced by clan_vector_term().

clan_symbol_p clan_symbol_lookup ( clan_symbol_p  symbol,
char *  identifier 
)

clan_symbol_lookup function: This function searches the symbol table for a symbol with the identifier provided as parameter. It returns the pointer to the symbol if it already exists inside the table, NULL otherwise.

Parameters:
[in]symbolThe first node of the list of symbols.
[in]identifierThe identifier we are looking for.
Returns:
The symbol corresponding to identifier, NULL if it doesn't exist.

Definition at line 240 of file symbol.c.

References clan_symbol::identifier, and clan_symbol::next.

Referenced by clan_symbol_add().

clan_symbol_lookup_by_key function: This function searches the symbol table for a symbol with the key provided as parameter. It returns the pointer to the symbol if it already exists inside the table, NULL otherwise.

Parameters:
[in]symbolThe first node of the list of symbols.
[in]keyThe key of the searched symbol.
Returns:
The symbol corresponding to the key, or NULL if it doesn't exist.

Definition at line 260 of file symbol.c.

References clan_symbol::key, and clan_symbol::next.

Referenced by clan_symbol_update_type().

clan_symbol_malloc function: This function allocates the memory space for a clan_symbol_t structure and sets its fields with default values. Then it returns a pointer to the allocated space.

Returns:
A newly allocated symbol set with default values.

Definition at line 195 of file symbol.c.

References CLAN_malloc, CLAN_UNDEFINED, clan_symbol::identifier, clan_symbol::key, clan_symbol::next, clan_symbol::rank, and clan_symbol::type.

Referenced by clan_symbol_add(), and clan_symbol_clone_one().

int clan_symbol_nb_of_type ( clan_symbol_p  symbol,
int  type 
)

clan_symbol_nb_of_type function: this function returns the number of symbols of a given type in the symbol table.

Parameters:
[in]symbolThe top of the symbol table.
[in]typeThe type of the elements.
Returns:
The number of symbols of the provoded type in the symbol table.

Definition at line 432 of file symbol.c.

References clan_symbol::next, and clan_symbol::type.

Referenced by clan_symbol_to_strings(), and yyparse().

int clan_symbol_new_iterator ( clan_symbol_p table,
clan_symbol_p array,
char *  id,
int  depth 
)

clan_symbol_new_iterator function: this function return 1 if it succeeds to register (or to update) an iterator in the symbol table and to add it to the iterator array. It returns 0 otherwise. The reason for failure can be that the symbol is already in use for something else than an iterator.

Parameters:
[in,out]tableThe symbol table.
[in,out]arrayThe iterator array.
[in]idThe textual name of the iterator.
[in]depthThe current loop depth.
Returns:
1 on success, 0 on failure.

Definition at line 570 of file symbol.c.

References clan_symbol_add(), clan_symbol_clone_one(), CLAN_TYPE_ITERATOR, clan_symbol::rank, clan_symbol::type, and yyerror().

Referenced by yyparse().

void clan_symbol_print ( FILE *  file,
clan_symbol_p  symbol 
)

clan_symbol_print function: This function prints the content of a clan_symbol_t structure (*symbol) into a file (file, possibly stdout).

Parameters:
[in]fileFile where informations are printed.
[in]symbolThe symbol whose information have to be printed.

Definition at line 178 of file symbol.c.

References clan_symbol_print_structure().

void clan_symbol_print_structure ( FILE *  file,
clan_symbol_p  symbol,
int  level 
)

clan_symbol_print_structure function: Displays a clan_symbol_t structure (*symbol) into a file (file, possibly stdout) in a way that trends to be understandable without falling in a deep depression or, for the lucky ones, getting a headache... It includes an indentation level (level) in order to work with others print_structure functions.

Parameters:
[in]fileFile where informations are printed.
[in]symbolThe symbol whose information have to be printed.
[in]levelNumber of spaces before printing, for each line.

Definition at line 73 of file symbol.c.

References CLAN_TYPE_ARRAY, CLAN_TYPE_FUNCTION, CLAN_TYPE_ITERATOR, CLAN_TYPE_PARAMETER, clan_symbol::identifier, clan_symbol::key, clan_symbol::next, clan_symbol::rank, and clan_symbol::type.

Referenced by clan_symbol_print().

osl_generic_p clan_symbol_to_arrays ( clan_symbol_p  symbol) [read]

clan_symbol_to_arrays function: this function generates an arrays extension from the symbol table passed as an argument. It embeds it in an osl_generic_t structure before returning it.

Parameters:
[in]symbolThe symbol table.
Returns:
An arrays structure with all the arrays of the symbol table.

Definition at line 522 of file symbol.c.

References CLAN_malloc, CLAN_strdup, clan_symbol::identifier, clan_symbol::key, and clan_symbol::next.

Referenced by yyparse().

osl_generic_p clan_symbol_to_strings ( clan_symbol_p  symbol,
int  type 
) [read]

clan_symbol_to_strings function: this function builds (and returns a pointer to) an osl_generic_t structure containing the symbol strings of a given type in the symbol table. The osl_generic_t is a shell for an osl_strings_t which actually stores the symbol strings. The symbol strings are sorted in the same order as they appear in the symbol table. If there is no corresponding symbol in the table, it returns NULL.

Parameters:
[in]symbolThe top of the symbol table.
[in]typeThe type of the elements.
Returns:
An osl_generic_t with the symbol strings of the given type.

Definition at line 457 of file symbol.c.

References CLAN_malloc, clan_symbol_nb_of_type(), clan_symbol::identifier, clan_symbol::next, and clan_symbol::type.

Referenced by yyparse().

int clan_symbol_update_type ( clan_symbol_p  table,
osl_relation_list_p  access,
int  type 
)

clan_symbol_update_type function: this function returns 1 if it succeeds to modify the type of a symbol in the symbol table. The modified symbol corresponds to the reference accessed in the last access relation of an access list provided as parameter. It returns 0 if it fails. The reasons for a failure can be either to try to modify an iterator type or a parameter type since they are supposed to be dead-ends.

Parameters:
[in,out]tableThe first symbol of the symbol table (one element may be modified).
[in]accessA list of access relations.
[in]typeThe new type for the symbol we want to update.
Returns:
1 on success, 0 on failure.

Definition at line 604 of file symbol.c.

References CLAN_error, clan_symbol_lookup_by_key(), CLAN_TYPE_ITERATOR, CLAN_TYPE_PARAMETER, clan_symbol::type, and yyerror().

Referenced by yyparse().

void yyerror ( char *  )