-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeCheckPass.cpp
211 lines (204 loc) · 6.25 KB
/
TypeCheckPass.cpp
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
202
203
204
205
206
207
208
209
210
211
#include "TypeCheckPass.h"
namespace lwscript
{
Stmt *TypeCheckPass::ExecuteAstStmts(AstStmts *stmt)
{
for (auto &s : stmt->stmts)
s = ExecuteStmt(s);
return stmt;
}
Stmt *TypeCheckPass::ExecuteVarStmt(VarStmt *stmt)
{
for (auto &[k, v] : stmt->variables)
{
if (k->kind == AstKind::ARRAY)
{
}
else if (k->kind == AstKind::VAR_DESC)
{
auto leftType = ((VarDescExpr *)k)->type;
if (leftType.IsAny())
{
return stmt;
}
if (v->kind != AstKind::LITERAL)
Logger::Error(TEXT("Now Only check Literal Expr type and named variable only."));
auto rightType = ((LiteralExpr *)v)->type;
if (leftType.GetKind() == TypeKind::I64)
{
switch (rightType.GetKind())
{
case TypeKind::I8:
Logger::Info(k->tagToken, TEXT("Assignning a int8 value to a int64 value, it is a broadening conversion."));
break;
case TypeKind::I16:
Logger::Info(k->tagToken, TEXT("Assignning a int16 value to a int64 value, it is a broadening conversion."));
break;
case TypeKind::I32:
Logger::Info(k->tagToken, TEXT("Assignning a int32 value to a int64 value, it is a broadening conversion."));
break;
case TypeKind::U8:
Logger::Warn(k->tagToken, TEXT("Assignning a uint8 value to a int64 value, it is a broadening conversion and may lose data."));
break;
case TypeKind::U16:
Logger::Warn(k->tagToken, TEXT("Assignning a uint16 value to a int64 value, it is a broadening conversion and may lose data."));
break;
case TypeKind::U32:
Logger::Warn(k->tagToken, TEXT("Assignning a uint32 value to a int64 value, it is a broadening conversion and may lose data."));
break;
case TypeKind::U64:
Logger::Warn(k->tagToken, TEXT("Assignning a uint64 value to a int64 value, it may lose data."));
break;
case TypeKind::F32:
Logger::Warn(k->tagToken, TEXT("Assignning a floating32 value to a int64 value, it is a broadening conversion and may lose data."));
break;
case TypeKind::F64:
Logger::Warn(k->tagToken, TEXT("Assignning a floating64 value to a int64 value, it may lose data."));
break;
case TypeKind::I64:
default:
break;
}
}
}
}
return stmt;
}
Stmt *TypeCheckPass::ExecuteExprStmt(ExprStmt *stmt)
{
stmt->expr = ExecuteExpr(stmt->expr);
return stmt;
}
Stmt *TypeCheckPass::ExecuteReturnStmt(ReturnStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteIfStmt(IfStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteScopeStmt(ScopeStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteWhileStmt(WhileStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteEnumStmt(EnumStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteFunctionStmt(FunctionStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteClassStmt(ClassStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteBreakStmt(BreakStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteContinueStmt(ContinueStmt *stmt)
{
return nullptr;
}
Stmt *TypeCheckPass::ExecuteModuleStmt(ModuleStmt *stmt)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteLiteralExpr(LiteralExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteInfixExpr(InfixExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecutePrefixExpr(PrefixExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecutePostfixExpr(PostfixExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteConditionExpr(ConditionExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteGroupExpr(GroupExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteArrayExpr(ArrayExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteAppregateExpr(AppregateExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteDictExpr(DictExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteIndexExpr(IndexExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteNewExpr(NewExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteThisExpr(ThisExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteBaseExpr(BaseExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteIdentifierExpr(IdentifierExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteLambdaExpr(LambdaExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteCompoundExpr(CompoundExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteCallExpr(CallExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteDotExpr(DotExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteRefExpr(RefExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteStructExpr(StructExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteVarArgExpr(VarArgExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteFactorialExpr(FactorialExpr *expr)
{
return nullptr;
}
Expr *TypeCheckPass::ExecuteVarDescExpr(VarDescExpr *expr)
{
return nullptr;
}
}