-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.h
146 lines (114 loc) · 5.05 KB
/
Common.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
//=============================================================================
// Объявление деклараций, используемых всеми модулями транслятора
//=============================================================================
#ifndef O2M_Common_h
#define O2M_Common_h
//#ifdef _WIN32
//сокрытие предупреждения Visual C++ 6.0 о строках больших 255 символов
//#pragma warning(disable: 4786)
//#endif
#include "LexAnl.h"
class CBase;
class CBaseName;
class CBaseVar;
class CBaseType;
class CElsifPair;
class CGuardPair;
class CFPElem;
class CSetVarElem;
typedef std::vector <char*> StringVector;
typedef std::vector <CBase*> CBaseVector;
typedef std::vector <CBaseName*> CBaseNameVector;
typedef std::vector <CBaseVar*> CBaseVarVector;
//-----------------------------------------------------------------------------
//строки комментариев для генерируемых компилятором файлов
const char* const comment_line_cpp = "/////////////////////////////////////////////\n";
const char* const comment_line_dfn = "(*******************************************)\n";
const char* const comment_title = "This file was generated by O2M compiler";
const char* const comment_format = "%s// %s //\n%s\n";
//сообщение об ошибке открытия файла для записи
const char* const textCannotOpenW = "ERROR: Cannot open file \"%s\" for writing\n";
//сообщение об ошибке закрытия файла
const char* const textCannotClose = "ERROR: Cannot close file \"%s\"\n";
//предупреждение о необходимости проверки наличия пути
const char* const textCheckFolder = "WARNING: Make sure that folder \"%s\" exists in source file folder\n";
//-----------------------------------------------------------------------------
//объявление переменной и сохранение в ней текущей позиции в буфере лексем
#define DECL_SAVE_POS CLexBufPos CurrLexBufPos = lb->GetCurrPos();
//сохранение в переменной текущей позиции в буфере лексем
#define SAVE_POS CurrLexBufPos = lb->GetCurrPos();
//восстановление текущей позиции в буфере лексем по значению переменной
#define RESTORE_POS lb->SetCurrPos(CurrLexBufPos);
//-----------------------------------------------------------------------------
//префикс для служебных переменных и функций
#define O2M_SYS_ "O2M_SYS_"
//-----------------------------------------------------------------------------
//максимально возможное значение эл-та множества
const int SET_MAX = (sizeof(int) << 3) - 1;
//-----------------------------------------------------------------------------
//типы наследников CBaseName
enum EName_id {
id_CBaseName,
id_CModule,
id_CDfnModule,
id_CDfnModuleSystem,
id_CImportModule,
id_CWithLoopLink,
id_CProcedure,
id_CHandlerProc,
id_CCommonProc,
id_CDfnProcedure,
id_CDfnCommonProc,
id_CForwardDecl,
id_CIdentDef,
id_CProcedureType,
id_CSetType,
id_CQualidentType,
id_CSpecType,
id_CArrayType,
id_CRecordType,
id_CCommonType,
id_CCommonExtensionType,
id_CPointerType,
id_CLongrealType,
id_CRealType,
id_CLongintType,
id_CIntegerType,
id_CShortintType,
id_CCharType,
id_CBooleanType,
id_CPtrType,
id_CSetVar,
id_CArrayVar,
id_CRecordVar,
id_CCommonVar,
id_CPointerVar,
id_CProcedureVar,
id_CLongrealVar,
id_CRealVar,
id_CLongintVar,
id_CIntegerVar,
id_CShortintVar,
id_CCharVar,
id_CBooleanVar,
id_CPtrVar
};
//-----------------------------------------------------------------------------
//проверка поглощения (inclusion) типом id1 типа id2
bool IsId1IncloseId2(const EName_id id1, const EName_id id2);
//-----------------------------------------------------------------------------
//получение ид. наименьшего типа, поглощающего оба операнда, или id_CBaseName
EName_id GetMaxDigitId(const EName_id id1, const EName_id id2);
//-----------------------------------------------------------------------------
//создание объекта TYPE из потока лексем
int TypeSelector(CLexBuf *lb, CBaseType* &BaseType, const CBaseName* parent);
//-----------------------------------------------------------------------------
//создание константы из потока лексем
int ConstSelector(CLexBuf *lb, CBaseVar* &BaseVar, const CBaseName* parent_element);
//-----------------------------------------------------------------------------
//копирование строки с выделением памяти
char* str_new_copy(const char* source);
//-----------------------------------------------------------------------------
//получение уникального числового идентификатора
int GetGlobalUId();
#endif //O2M_Common_h