-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsymbol.h
201 lines (186 loc) · 8.01 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Description: Symbol module of the Chaos Programming Language's source
*
* Copyright (c) 2019-2021 Chaos Language Development Authority <[email protected]>
*
* License: GNU General Public License v3.0
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
* Authors: M. Mert Yildiran <[email protected]>
* Melih Sahin <[email protected]>
*/
#ifndef KAOS_SYMBOL_H
#define KAOS_SYMBOL_H
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
typedef struct Symbol Symbol;
#include "../enums.h"
#include "errors.h"
#include "../utilities/helpers.h"
#if !defined(_WIN32) && !defined(_WIN64) && !defined(__CYGWIN__)
# include "../utilities/shell.h"
#endif
#include "function.h"
typedef struct Symbol {
unsigned long long id;
char *name;
char *secondary_name;
enum Type type;
enum Type secondary_type;
union Value {
bool b;
long long i;
char *s;
double f;
} value;
size_t len;
short sign;
enum ValueType value_type;
struct Symbol* previous;
struct Symbol* next;
struct Symbol** children;
unsigned long children_count;
char *key;
struct FunctionCall* scope;
enum Role role;
struct _Function* param_of;
long long addr;
bool is_dynamic;
} Symbol;
Symbol* symbol_cursor;
typedef struct symbol_array {
Symbol** arr;
unsigned long* child_counter;
unsigned capacity, size;
} symbol_array;
symbol_array complex_mode_stack;
symbol_array nested_complex_mode_stack;
typedef struct symbol_id_array {
unsigned long long* arr;
unsigned capacity, size;
} symbol_id_array;
symbol_id_array left_right_bracket_stack;
Symbol* variable_complex_element;
unsigned long long variable_complex_element_symbol_id;
Symbol* addSymbol(char *name, enum Type type, union Value value, enum ValueType value_type);
void updateSymbolScope(Symbol* symbol);
Symbol* updateSymbol(char *name, enum Type type, union Value value, enum ValueType value_type);
void removeSymbolByName(char *name);
void removeSymbol(Symbol* symbol);
void freeSymbol(Symbol* symbol);
Symbol* findSymbol(char *name);
Symbol* getSymbol(char *name);
Symbol* getSymbolById(unsigned long long id);
Symbol* deepCopySymbol(Symbol* symbol, enum Type type, char *key);
Symbol* deepCopyComplex(char *name, Symbol* symbol);
char* getSymbolValueString(char *name);
char* _getSymbolValueString(Symbol* symbol);
double getSymbolValueFloat(char *name);
double _getSymbolValueFloat(Symbol* symbol);
bool getSymbolValueBool(char *name);
bool _getSymbolValueBool(Symbol* symbol);
long long getSymbolValueInt(char *name);
long long _getSymbolValueInt(Symbol* symbol);
char* getSymbolValueString_NullIfNotString(Symbol* symbol);
long long getSymbolValueInt_ZeroIfNotInt(Symbol* symbol);
void printSymbolValue(Symbol* symbol, bool is_complex, bool pretty, bool escaped, unsigned long iter);
void printSymbolValueEndWith(Symbol* symbol, char *end, bool pretty, bool escaped);
void printSymbolValueEndWithNewLine(Symbol* symbol, bool pretty, bool escaped);
char* encodeSymbolValueToString(Symbol* symbol, bool is_complex, bool pretty, bool escaped, unsigned long iter, char *encoded, bool double_quotes);
bool isDefined(char *name);
void addSymbolToComplex(Symbol* symbol);
void printSymbolTable();
Symbol* addSymbolBool(char *name, bool b);
void updateSymbolBool(char *name, bool b);
Symbol* addSymbolInt(char *name, long long i);
void updateSymbolInt(char *name, long long i);
Symbol* addSymbolFloat(char *name, double f);
void updateSymbolFloat(char *name, double f);
Symbol* addSymbolString(char *name, char *s);
void updateSymbolString(char *name, char *s);
void addSymbolList(char *name);
Symbol* createCloneFromSymbolByName(char *clone_name, enum Type type, char *name, enum Type extra_type);
Symbol* createCloneFromComplexElement(char *clone_name, enum Type type, char *name, enum Type extra_type);
Symbol* createCloneFromSymbol(char *clone_name, enum Type type, Symbol* symbol, enum Type extra_type);
Symbol* updateSymbolByClonning(char *clone_name, Symbol* symbol);
Symbol* updateSymbolByClonningName(char *clone_name, char *name);
Symbol* updateSymbolByClonningComplexElement(char *clone_name, char *name);
enum Type isComplexIllegal(enum Type type);
Symbol* finishComplexMode(char *name, enum Type type);
void finishComplexModeWithUpdate(char *name);
void _finishComplexModeWithUpdate(Symbol* symbol);
Symbol* getListElement(Symbol* symbol, long long i);
void cloneSymbolToComplex(char *name, char *key);
Symbol* getComplexElement(Symbol* complex, long long i, char *key);
Symbol* getComplexElementBySymbolId(Symbol* complex, unsigned long long symbol_id);
void updateComplexElementComplex();
void updateComplexElementWrapper(enum Type type, union Value value, enum ValueType value_type);
void updateComplexElement(Symbol* complex, unsigned long long symbol_id, enum Type type, union Value value, enum ValueType value_type);
void updateComplexElementBool(bool b);
void updateComplexElementInt(long long i);
void updateComplexElementFloat(double f);
void updateComplexElementString(char *s);
void updateComplexElementSymbol(Symbol* source);
void _updateComplexElementSymbol(Symbol* complex, unsigned long long symbol_id, Symbol* source);
void removeComplexElementByLeftRightBracketStack(char *name);
void removeComplexElement(Symbol* complex, unsigned long long symbol_id);
void addSymbolDict(char *name);
Symbol* addSymbolAnyStringNew(char *name, char *s, size_t len);
Symbol* addSymbolAnyString(char *name, char *s);
Symbol* addSymbolAnyInt(char *name, long long i);
Symbol* addSymbolAnyFloat(char *name, double f);
Symbol* addSymbolAnyBool(char *name, bool b);
Symbol* getDictElement(Symbol* symbol, char *key);
FunctionCall* getCurrentScope();
Symbol* getSymbolFunctionParameter(char *name);
void freeAllSymbols();
Symbol* assignByTypeCasting(Symbol* clone_symbol, Symbol* symbol);
bool symbolValueByTypeCastingToBool(Symbol* symbol);
long long symbolValueByTypeCastingToInt(Symbol* symbol);
double symbolValueByTypeCastingToFloat(Symbol* symbol);
char* symbolValueByTypeCastingToString(Symbol* symbol);
Symbol* createSymbolWithoutValueType(char *name, enum Type type);
void removeSymbolsByScope(FunctionCall* scope);
long long incrementThenAssign(char *name, long long i);
long long assignThenIncrement(char *name, long long i);
char* getTypeName(unsigned i);
char* getValueTypeName(unsigned i);
void pushComplexModeStack(Symbol* complex_mode);
void popComplexModeStack();
void freeComplexModeStack();
bool isComplexMode();
bool isNestedComplexMode();
Symbol* getComplexMode();
void pushLeftRightBracketStack(unsigned long long symbol_id);
unsigned long long popLeftRightBracketStack();
void freeLeftRightBracketStack();
void freeLeftRightBracketStackSymbols();
Symbol* getComplexElementThroughLeftRightBracketStack(char *name, unsigned long inverse_nested);
void removeChildrenOfComplex(Symbol* symbol);
bool isComplex(Symbol* symbol);
void buildVariableComplexElement(char *name, char *key);
void pushNestedComplexModeStack(Symbol* complex_mode);
void popNestedComplexModeStack(char *key);
void freeNestedComplexModeStack();
void reverseComplexMode();
bool resolveRelEqualUnknown(char* name_l, char* name_r);
bool resolveRelNotEqualUnknown(char* name_l, char* name_r);
bool resolveRelGreatUnknown(char* name_l, char* name_r);
bool resolveRelSmallUnknown(char* name_l, char* name_r);
bool resolveRelGreatEqualUnknown(char* name_l, char* name_r);
bool resolveRelSmallEqualUnknown(char* name_l, char* name_r);
void changeSymbolScope(Symbol* symbol, FunctionCall* scope);
#include "../ast/ast.h"
#endif