- Fixed the symbols.
This commit is contained in:
parent
5ca4adbd86
commit
eecab1bbda
@ -15,6 +15,14 @@
|
|||||||
* \section install Installation
|
* \section install Installation
|
||||||
*
|
*
|
||||||
* How to install Scyther.
|
* 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>
|
#include <stdlib.h>
|
||||||
|
@ -16,12 +16,16 @@ extern int yylineno;
|
|||||||
|
|
||||||
/* global declarations */
|
/* global declarations */
|
||||||
|
|
||||||
|
//! Symbol hash table.
|
||||||
Symbol symbtab[HASHSIZE];
|
Symbol symbtab[HASHSIZE];
|
||||||
|
//! List of available (freed) symbol blocks.
|
||||||
Symbol symb_list;
|
Symbol symb_list;
|
||||||
|
//! List of all allocated symbol blocks.
|
||||||
Symbol symb_alloc;
|
Symbol symb_alloc;
|
||||||
|
|
||||||
/* main code */
|
/* main code */
|
||||||
|
|
||||||
|
//! Open symbols code.
|
||||||
void
|
void
|
||||||
symbolsInit (void)
|
symbolsInit (void)
|
||||||
{
|
{
|
||||||
@ -33,6 +37,7 @@ symbolsInit (void)
|
|||||||
symb_alloc = NULL;
|
symb_alloc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Close symbols code.
|
||||||
void
|
void
|
||||||
symbolsDone (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
|
Symbol
|
||||||
get_symb (void)
|
get_symb (void)
|
||||||
{
|
{
|
||||||
@ -64,6 +74,7 @@ get_symb (void)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Declare a symbol to be freed.
|
||||||
void
|
void
|
||||||
free_symb (Symbol s)
|
free_symb (Symbol s)
|
||||||
{
|
{
|
||||||
@ -73,6 +84,7 @@ free_symb (Symbol s)
|
|||||||
symb_list = s;
|
symb_list = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Return the index in the hash table for the string.
|
||||||
int
|
int
|
||||||
hash (char *s)
|
hash (char *s)
|
||||||
{
|
{
|
||||||
@ -88,6 +100,7 @@ hash (char *s)
|
|||||||
return hv % HASHSIZE;
|
return hv % HASHSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Insert a string into the hash table.
|
||||||
void
|
void
|
||||||
insert (Symbol s)
|
insert (Symbol s)
|
||||||
{
|
{
|
||||||
@ -99,6 +112,7 @@ insert (Symbol s)
|
|||||||
symbtab[hv] = s;
|
symbtab[hv] = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Find a string in the hash table.
|
||||||
Symbol
|
Symbol
|
||||||
lookup (char *s)
|
lookup (char *s)
|
||||||
{
|
{
|
||||||
@ -118,6 +132,7 @@ lookup (char *s)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Print a symbol.
|
||||||
void
|
void
|
||||||
symbolPrint (Symbol s)
|
symbolPrint (Symbol s)
|
||||||
{
|
{
|
||||||
@ -128,6 +143,11 @@ symbolPrint (Symbol s)
|
|||||||
printf ("%s", s->text);
|
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
|
Symbol
|
||||||
symbolSysConst (char *str)
|
symbolSysConst (char *str)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#ifndef SYMBOLS
|
#ifndef SYMBOLS
|
||||||
#define SYMBOLS
|
#define SYMBOLS
|
||||||
|
|
||||||
/* Size of hashtable: optimistically large. */
|
//! Size of symbol hashtable.
|
||||||
|
/** Optimistically large. Should be a prime, says theory.
|
||||||
|
*/
|
||||||
#define HASHSIZE 997
|
#define HASHSIZE 997
|
||||||
|
|
||||||
#define T_UNDEF -1
|
#define T_UNDEF -1
|
||||||
@ -14,10 +16,18 @@
|
|||||||
|
|
||||||
struct symbol
|
struct symbol
|
||||||
{
|
{
|
||||||
|
//! Type of symbol.
|
||||||
|
/**
|
||||||
|
*\sa T_UNDEF, T_PROTOCOL, T_CONST, T_VAR, T_SYSCONST
|
||||||
|
*/
|
||||||
int type;
|
int type;
|
||||||
|
//! Line number at which it occurred.
|
||||||
int lineno;
|
int lineno;
|
||||||
|
//! Ascii string with name of the symbol.
|
||||||
char *text;
|
char *text;
|
||||||
|
//! Possible next pointer.
|
||||||
struct symbol *next;
|
struct symbol *next;
|
||||||
|
//! Used for linking all symbol blocks, freed or in use.
|
||||||
struct symbol *allocnext;
|
struct symbol *allocnext;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user