-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbol.h
105 lines (89 loc) · 2.48 KB
/
symbol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Project name:
* Implementace interpretu imperativního jazyka IFJ14
*
* Repository:
* https://github.com/Dasio/IFJ
*
* Team:
* Dávid Mikuš (xmikus15)
* Peter Hostačný (xhosta03)
* Tomáš Kello (xkello00)
* Adam Lučanský (xlucan01)
* Michaela Lukášová (xlukas09)
*/
#include "error.h"
#include "string.h"
#include "vector.h"
#ifndef SYMBOL_H
#define SYMBOL_H
#define DEFAULT_HASH_SIZE 16
#define DEFAULT_ARG_NUM 4
// Types of symbols
typedef enum {
T_String,
T_double,
T_int,
T_bool,
T_FunPointer,
T_Undefined
} SymbolType;
typedef enum
{
FS_Undefined = 0, /**< Function is just added to GST */
FS_Declared, /**< Function is declared */
FS_Defined /**< Function is defined */
} FuncState;
struct SymbolListStruct;
typedef struct SymbolListStruct SymbolList;
struct SymbolStruct;
typedef struct SymbolStruct Symbol;
typedef struct
{
Symbol **arg; /**< array of arguments, points to symbol in Hash */
//Symbol *ret_value; /**< pointer to symbol with return value of function */
int32_t argCount;
int32_t argMax;
SymbolList **locTable; /**< Hash of all symbols in this Context */
int32_t locSize; /**< size of HashTable */
int32_t locCount; /**< number of LOCAL/GLOBAL variables */
int32_t instrucIndex; /**< index of start in Instruction Tape */
SymbolType returnType; /**< Type of return value */
}Context;
struct SymbolStruct
{
SymbolType type; /**< Enum what kind of data are stored */
int64_t index; /**< for variable index/offset(global/local) to stack
for function index to instruction tape */
char *name; /**< Name of variable/function */
FuncState stateFunc; /**< 0- initial state 1-declared 2-defined */
Context *funCont; /**< Pointer to Context of function */
int64_tVector *adressVector; /**< for adding addresses to instruction tape
if function was called before definition */
}; // Symbol
// struct in Hash table with data and pointer to next value
struct SymbolListStruct
{
SymbolList *next;
Symbol data;
}; // SymbolList
#include "ial.h"
#include "stack.h"
/**
* Init content for funciton
* @return pointer to context
*
*/
Context *InitContext();
/**
* Init content for funciton
* @param Context* pointer to context
* @param SymbolType type of new symbol
* @param char* name of new symbol
* @param Context* pointer to context if SymbolType == T_FunPointer
* @return SymbolList* pointer to new symbol
*
*/
Symbol *AddArgToContext(Context*, SymbolType, char*, Context*);
void FreeContext(Context*);
#endif