- Fixed the symbols.
This commit is contained in:
parent
5ca4adbd86
commit
eecab1bbda
@ -15,6 +15,14 @@
|
||||
* \section install Installation
|
||||
*
|
||||
* How to install Scyther.
|
||||
*
|
||||
* \section coding Coding convertions
|
||||
*
|
||||
* Usually, each source file except main.c has an myfileInit() and myfileDone() function
|
||||
* available. These allow any initialisation and destruction of required structures.
|
||||
*
|
||||
* GNU indent rules are used, but K&R derivatives are allowed as well. Conversion can
|
||||
* be done for any style using the GNU indent program.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -16,12 +16,16 @@ extern int yylineno;
|
||||
|
||||
/* global declarations */
|
||||
|
||||
//! Symbol hash table.
|
||||
Symbol symbtab[HASHSIZE];
|
||||
//! List of available (freed) symbol blocks.
|
||||
Symbol symb_list;
|
||||
//! List of all allocated symbol blocks.
|
||||
Symbol symb_alloc;
|
||||
|
||||
/* main code */
|
||||
|
||||
//! Open symbols code.
|
||||
void
|
||||
symbolsInit (void)
|
||||
{
|
||||
@ -33,6 +37,7 @@ symbolsInit (void)
|
||||
symb_alloc = NULL;
|
||||
}
|
||||
|
||||
//! Close symbols code.
|
||||
void
|
||||
symbolsDone (void)
|
||||
{
|
||||
@ -46,6 +51,11 @@ symbolsDone (void)
|
||||
}
|
||||
}
|
||||
|
||||
//! Create a memory block for a symbol.
|
||||
/**
|
||||
* Internal memory management is used.
|
||||
*@return A pointer to a memory block of size struct.
|
||||
*/
|
||||
Symbol
|
||||
get_symb (void)
|
||||
{
|
||||
@ -64,6 +74,7 @@ get_symb (void)
|
||||
return t;
|
||||
}
|
||||
|
||||
//! Declare a symbol to be freed.
|
||||
void
|
||||
free_symb (Symbol s)
|
||||
{
|
||||
@ -73,6 +84,7 @@ free_symb (Symbol s)
|
||||
symb_list = s;
|
||||
}
|
||||
|
||||
//! Return the index in the hash table for the string.
|
||||
int
|
||||
hash (char *s)
|
||||
{
|
||||
@ -88,6 +100,7 @@ hash (char *s)
|
||||
return hv % HASHSIZE;
|
||||
}
|
||||
|
||||
//! Insert a string into the hash table.
|
||||
void
|
||||
insert (Symbol s)
|
||||
{
|
||||
@ -99,6 +112,7 @@ insert (Symbol s)
|
||||
symbtab[hv] = s;
|
||||
}
|
||||
|
||||
//! Find a string in the hash table.
|
||||
Symbol
|
||||
lookup (char *s)
|
||||
{
|
||||
@ -118,6 +132,7 @@ lookup (char *s)
|
||||
return t;
|
||||
}
|
||||
|
||||
//! Print a symbol.
|
||||
void
|
||||
symbolPrint (Symbol s)
|
||||
{
|
||||
@ -128,6 +143,11 @@ symbolPrint (Symbol s)
|
||||
printf ("%s", s->text);
|
||||
}
|
||||
|
||||
//! Insert a string into the symbol table, if it wasn't there yet.
|
||||
/**
|
||||
* Also sets line numbers and type.
|
||||
*\sa T_SYSCONST
|
||||
*/
|
||||
Symbol
|
||||
symbolSysConst (char *str)
|
||||
{
|
||||
|
@ -1,7 +1,9 @@
|
||||
#ifndef SYMBOLS
|
||||
#define SYMBOLS
|
||||
|
||||
/* Size of hashtable: optimistically large. */
|
||||
//! Size of symbol hashtable.
|
||||
/** Optimistically large. Should be a prime, says theory.
|
||||
*/
|
||||
#define HASHSIZE 997
|
||||
|
||||
#define T_UNDEF -1
|
||||
@ -14,10 +16,18 @@
|
||||
|
||||
struct symbol
|
||||
{
|
||||
//! Type of symbol.
|
||||
/**
|
||||
*\sa T_UNDEF, T_PROTOCOL, T_CONST, T_VAR, T_SYSCONST
|
||||
*/
|
||||
int type;
|
||||
//! Line number at which it occurred.
|
||||
int lineno;
|
||||
//! Ascii string with name of the symbol.
|
||||
char *text;
|
||||
//! Possible next pointer.
|
||||
struct symbol *next;
|
||||
//! Used for linking all symbol blocks, freed or in use.
|
||||
struct symbol *allocnext;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user