-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymbol_table.c
More file actions
71 lines (56 loc) · 1.84 KB
/
symbol_table.c
File metadata and controls
71 lines (56 loc) · 1.84 KB
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
/*Created by Omri Kaisari on 08/08/2020.*/
#include <stdlib.h>
#include <string.h>
#include "symbol_table.h"
/**
* @brief the symbol_entry_type struct contains a symbol entry. it has the label of a sybol, its location and
* its properties
*/
struct symbol_entry_type {
char *label; /*the label of the symbol*/
int location; /*the location of the symbol*/
Property property; /*the first property*/
Property property2; /*the second property*/
};
/************************************************** Functions implementations *****************************************/
SymbolEntry symbol_entry_create(const char *label, int location, Property property) {
SymbolEntry entry = malloc(sizeof(struct symbol_entry_type));
entry->property = property;
entry->location = location;
entry->label = malloc(sizeof(char) * (strlen(label) + 1));
strcpy(entry->label, label);
entry->property2 = NA;
return entry;
}
int symbol_entry_compare(char *label, SymbolEntry entry) {
return strcmp(label, entry->label);
}
void symbol_entry_destroy(SymbolEntry entry) {
free(entry->label);
free(entry);
}
Property symbol_get_second_property(SymbolEntry entry) {
return entry->property2;
}
void symbol_entry_tmp_destroy(SymbolEntry entry) {
if (entry != NULL)
free(entry);
}
void symbol_update_second_property(SymbolEntry entry) {
entry->property2 = EntryP;
}
int symbol_get_location(SymbolEntry entry) {
return entry->location;
}
void symbol_update_location(SymbolEntry entry, int diff) {
entry->location += diff;
}
Property symbol_get_property(SymbolEntry entry) {
return entry->property;
}
size_t symbol_size_of() {
return sizeof(struct symbol_entry_type);
}
const char *symbol_entry_get_label(SymbolEntry entry) {
return entry->label;
}