-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnamespace.h
185 lines (155 loc) · 7.67 KB
/
namespace.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
#pragma once
#include <string>
#include <list>
#include <map>
#include <stdio.h>
#include <stdarg.h>
#include "../include/lexem.h"
#include "lexem_tree_root.h"
#include "../include/type_t.h"
#include "../include/statement_t.h"
#include "../include/space_t.h"
#include "function.h"
#include <string>
#include "errors.h"
#include "primula.h"
#if ! COMPILER
typedef union {
int i32;
const char * p8;
float f32;
} common_value_t;
#endif
class namespace_t : public space_t
{
protected:
static bool config_translate_ternary;
public:
static Errors errors;
function_overload_t * owner_function;
visibility_t current_visibility;
std::map<std::string, type_t*> space_types_map;
std::map<std::string, variable_base_t*> space_variables_map;
std::map<std::string, class function_parser*> function_map;
std::map<std::string, int> enum_map;
std::map<std::string, namespace_t *> embedded_space_map;
std::list<namespace_t *> using_space_list;
std::map<std::string, function_parser*> template_function_map;
std::map<std::string, type_t*> template_types_map;
static type_t builtin_types[18];
bool no_parse_methods_body; // = false; // An old g++ does not allow such initialization
std::map<std::string, type_t*> instance_types;
#if ! COMPILER
int non_static_variable_pool_size;
#endif
public:
namespace_t()
{
this->parent = nullptr;
this->type = global_space;
this->no_parse_methods_body = false;
}
void CreateError(int linenum, int error, std::string description, ...);
namespace_t * CreateSpace(spacetype_t type, std::string name)
{
namespace_t * space = new namespace_t(this, type, name);
space->parent = this;
return space;
}
void RegisterFunction(std::string name, function_parser * function, bool back);
namespace_t * Parent() { return parent; }
static type_t * GetBuiltinType(lexem_type_t type);
void RegisterBuiltinTypes();
type_t * TryLexenForType(SourcePtr & source);
void ParseUsing(SourcePtr &source);
int ParseStatement(Code::lexem_list_t statement);
int ParseStatement(SourcePtr &source);
function_overload_t * CheckCostructorDestructor(linkage_t * linkage, type_t * type, std::string name, SourcePtr &source);
void CheckOverloadOperator(linkage_t * linkage, type_t * type, SourcePtr &overload);
variable_base_t * TryEnumeration(std::string name, bool self_space);
expression_node_t * TryEnumeration(std::string name);
variable_base_t * FindVariable(std::string name);
variable_base_t * FindVariableInspace(std::string name);
function_parser * FindFunctionInSpace(std::string name);
function_parser * FindFunction(std::string name);
function_parser * FindTemplateFunction(std::string name);
type_t * FindType(std::string name);
variable_base_t * CreateVariable(type_t * type, std::string name, variable_segment_t segment);
function_overload_t * CreateFunction(type_t *type, std::string name, Code::lexem_list_t * sequence, linkage_t * linkage);
type_t * CreateType(type_t * type, std::string name);
function_overload_t * CreateOperator(type_t *type, std::string name, Code::lexem_list_t * sequence, linkage_t * linkage);
type_t * ParseTypeDefinition(SourcePtr &source);
type_t * ParseCompoundDefinition(std::string parent_name, lexem_type_t kind, Code::statement_list_t * statements);
type_t * ParseEnumeration(std::string parent_name, Code::statement_list_t * statements);
static_data_t * BraceEncodedInitialization(type_t * type, SourcePtr & source);
static_data_t * BraceEncodedStructureInitialization(structure_t * structure, Code::statement_list_t * encoded_data);
static_data_t * CheckLexemeData(type_t * type, Code::lexem_node_t * node);
static_data_t * TryEnumsAndConstants(type_t * type, Code::lexem_node_t * node);
// Copy structure data to raw memory
unsigned int * PackDefinitionToMemory(type_t * type, SourcePtr & source, unsigned int * data_ptr);
unsigned int * PackStructureInMemory(structure_t * structure, Code::statement_list_t * encoded_data, unsigned int * data_ptr);
unsigned int * PackLexemeData(type_t * type, Code::lexem_node_t * node, unsigned int * data_ptr);
unsigned int * PackEnumsAndConstants(type_t * type, Code::lexem_node_t * node, unsigned int * data_ptr);
namespace_t * findBreakableSpace(bool continues);
namespace_t * findContinuableSpace();
namespace_t * FindNamespaceInSpace(std::string name);
namespace_t * FindNamespace(std::string name);
// An old g++ does not like namaspace qualification in compound defintion.
// TODO: Move some qualification in test - we must support these qualifications
// keep following line until new test will created
//
// int namespace_t::CheckNamespace(SourcePtr &source);
//
int CheckNamespace(SourcePtr &source);
expression_t * ParseExpression(SourcePtr &source);
expression_t * ParseExpressionExtended(SourcePtr &lexem, type_t ** ptype, bool hide);
statement_t * CheckOperator_IF(SourcePtr &source);
statement_t * CheckOperator_RETURN(SourcePtr &source);
statement_t * CheckOperator_DO(SourcePtr &source);
statement_t * CheckOperator_WHILE(SourcePtr &source);
statement_t * CheckOperator_SWITCH(SourcePtr &source);
statement_t * CheckOperator_FOR(SourcePtr &source);
statement_t * CheckOperator_BREAK(SourcePtr &source);
statement_t * CheckOperator_CASE(SourcePtr &source);
statement_t * CheckOperator_CONTINUE(SourcePtr &source);
statement_t * CheckOperator_DEFAULT(SourcePtr &source);
statement_t * CheckOperator_OPERATOR(SourcePtr &source);
statement_t * CheckOperator_GOTO(SourcePtr & source);
statement_t * CheckOperator_DELETE(SourcePtr & source);
statement_t * CheckOperator_TRY(SourcePtr &source);
statement_t * CheckOperator_THROW(SourcePtr &source);
statement_t * CheckOperators(SourcePtr &source);
statement_t * CreateStatement(SourcePtr &source, spacetype_t soace_type);
int Parse(Code::statement_list_t source);
void ParseTemplate(SourcePtr & source);
type_t * TryTranslateType(type_t * type);
function_parser * CreateFunctionFromTemplate(function_parser * func, SourcePtr & source);
function_parser * CreateFunctionInstance(function_parser * func, int line_number);
variable_base_t * CreateObjectFromTemplate(type_t * type, linkage_t * linkage, SourcePtr & source);
void TranslateNamespace(namespace_t * space, int line_num);
variable_base_t * TranslateVariable(namespace_t * space, variable_base_t * var);
expression_t * TranslateExpression(namespace_t * space, expression_t * exp);
char TranslateCharacter(SourcePtr source);
private:
void CheckStorageClass(SourcePtr & source, linkage_t * linkage);
void SelectStatement(type_t * type, linkage_t * linkage, std::string name, SourcePtr & source);
type_t * TypeDefOpenBraket(SourcePtr & source, std::string & name, type_t * type);
type_t * ParseIndex(SourcePtr & source, type_t * type);
//inline template_t * namespace_t::CreateTemplateType(std::string type_name);
void TranslateTernaryOperation(expression_t * code);
variable_segment_t FindSegmentType(linkage_t * linkage);
// friend class function_overload_parser;
friend struct function_overload_t;
namespace_t(namespace_t * parent, spacetype_t type, std::string name)
{
this->parent = parent;
this->type = type;
this->name = name;
owner_function = parent->owner_function;
no_parse_methods_body = false;
#if ! COMPILER
non_static_variable_pool_size = 0;
#endif
}
public:
};