l0n0lc 0.8.4__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- l0n0lc/Py/350/275/254Cpp/350/275/254/350/257/221/345/231/250.py +579 -0
- l0n0lc/__init__.py +75 -6
- l0n0lc/aot/347/274/226/350/257/221.py +679 -0
- l0n0lc/ast/350/256/277/351/227/256/350/200/205.py +599 -0
- l0n0lc/cpp/347/261/273/345/236/213.py +330 -0
- l0n0lc/cpp/347/274/226/350/257/221/345/231/250.py +317 -0
- l0n0lc/simd/344/274/230/345/214/226.py +260 -0
- l0n0lc/std_map.py +153 -0
- l0n0lc/std_set.py +185 -0
- l0n0lc/std_vector.py +96 -0
- l0n0lc//344/273/243/347/240/201/344/274/230/345/214/226.py +302 -0
- l0n0lc//344/273/243/347/240/201/347/224/237/346/210/220.py +546 -0
- l0n0lc//344/276/235/350/265/226/346/263/250/345/205/245.py +155 -0
- l0n0lc//345/215/263/346/227/266/347/274/226/350/257/221.py +192 -0
- l0n0lc//345/217/230/351/207/217/347/256/241/347/220/206/345/231/250.py +123 -0
- l0n0lc//345/237/272/347/241/200/346/230/240/345/260/204.py +103 -0
- l0n0lc//345/237/272/347/241/200/346/267/267/345/205/245.py +147 -0
- l0n0lc//345/256/271/345/231/250/346/236/204/345/273/272/345/231/250.py +214 -0
- l0n0lc//345/267/245/345/205/267.py +285 -0
- l0n0lc//345/271/266/350/241/214/347/274/226/350/257/221/345/231/250.py +412 -0
- l0n0lc//345/274/202/345/270/270.py +474 -0
- l0n0lc//346/225/260/347/273/204/345/257/271/350/261/241/346/261/240.py +248 -0
- l0n0lc//346/226/207/344/273/266/347/256/241/347/220/206/345/231/250.py +286 -0
- l0n0lc//346/227/245/345/277/227/345/267/245/345/205/267.py +152 -0
- l0n0lc//347/261/273/345/236/213/346/216/250/346/226/255/345/267/245/345/205/267.py +352 -0
- l0n0lc//347/261/273/345/236/213/350/275/254/346/215/242.py +210 -0
- l0n0lc//347/261/273/346/224/257/346/214/201.py +372 -0
- l0n0lc//347/274/226/350/257/221/344/270/212/344/270/213/346/226/207.py +132 -0
- l0n0lc//347/274/226/350/257/221/347/256/241/347/220/206/345/231/250.py +171 -0
- l0n0lc//350/241/250/350/276/276/345/274/217/345/244/204/347/220/206.py +462 -0
- l0n0lc//350/275/254/350/257/221/345/231/250/345/267/245/345/205/267.py +49 -0
- l0n0lc//350/277/220/350/241/214/346/227/266/345/212/240/350/275/275.py +217 -0
- l0n0lc//351/200/232/347/224/250/345/267/245/345/205/267.py +149 -0
- l0n0lc-1.0.0.dist-info/METADATA +363 -0
- l0n0lc-1.0.0.dist-info/RECORD +39 -0
- {l0n0lc-0.8.4.dist-info → l0n0lc-1.0.0.dist-info}/WHEEL +1 -1
- l0n0lc-1.0.0.dist-info/entry_points.txt +2 -0
- {l0n0lc-0.8.4.dist-info → l0n0lc-1.0.0.dist-info}/licenses/LICENSE +0 -0
- l0n0lc/StdList.py +0 -24
- l0n0lc/StdMap.py +0 -21
- l0n0lc/c/345/237/272/347/241/200/345/244/204/347/220/206.py +0 -207
- l0n0lc/jit.py +0 -604
- l0n0lc//347/274/226/350/257/221.py +0 -58
- l0n0lc//351/200/232/347/224/250.py +0 -134
- l0n0lc-0.8.4.dist-info/METADATA +0 -241
- l0n0lc-0.8.4.dist-info/RECORD +0 -12
- {l0n0lc-0.8.4.dist-info → l0n0lc-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
from typing import Optional, Any, List, Dict, Union
|
|
2
|
+
import ast
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Jit错误(Exception):
|
|
6
|
+
"""JIT 基础异常类"""
|
|
7
|
+
|
|
8
|
+
def __init__(self, message: str, error_code: Optional[str] = None, context: Optional[Dict[str, Any]] = None):
|
|
9
|
+
"""
|
|
10
|
+
初始化JIT异常
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
message: 错误信息
|
|
14
|
+
error_code: 错误代码
|
|
15
|
+
context: 错误上下文信息
|
|
16
|
+
"""
|
|
17
|
+
super().__init__(message)
|
|
18
|
+
self.error_code = error_code
|
|
19
|
+
self.context = context or {}
|
|
20
|
+
|
|
21
|
+
def __str__(self):
|
|
22
|
+
"""返回格式化的错误信息"""
|
|
23
|
+
base_msg = super().__str__()
|
|
24
|
+
if self.error_code:
|
|
25
|
+
base_msg = f"[{self.error_code}] {base_msg}"
|
|
26
|
+
if self.context:
|
|
27
|
+
context_str = ", ".join(f"{k}={v}" for k, v in self.context.items())
|
|
28
|
+
base_msg += f" (Context: {context_str})"
|
|
29
|
+
return base_msg
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class 编译错误(Jit错误):
|
|
33
|
+
"""当 C++ 编译失败时抛出"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, message: str, compiler_output: Optional[str] = None, source_file: Optional[str] = None, python_source: Optional[str] = None):
|
|
36
|
+
"""
|
|
37
|
+
初始化编译错误
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
message: 错误信息
|
|
41
|
+
compiler_output: 编译器输出
|
|
42
|
+
source_file: 源文件路径
|
|
43
|
+
python_source: Python源码
|
|
44
|
+
"""
|
|
45
|
+
context = {}
|
|
46
|
+
if compiler_output:
|
|
47
|
+
context['compiler_output'] = compiler_output
|
|
48
|
+
if source_file:
|
|
49
|
+
context['source_file'] = source_file
|
|
50
|
+
if python_source:
|
|
51
|
+
context['python_source'] = python_source
|
|
52
|
+
super().__init__(message, "COMPILATION_ERROR", context)
|
|
53
|
+
|
|
54
|
+
def __str__(self):
|
|
55
|
+
"""返回格式化的编译错误信息"""
|
|
56
|
+
base_msg = super().__str__()
|
|
57
|
+
|
|
58
|
+
# 尝试解析编译器输出中的行号
|
|
59
|
+
cpp_line_info = self.提取C行号信息()
|
|
60
|
+
|
|
61
|
+
result = f"❌ C++ 编译失败:\n"
|
|
62
|
+
result += f" {base_msg}\n"
|
|
63
|
+
|
|
64
|
+
if cpp_line_info:
|
|
65
|
+
result += f" C++ 错误位置: {cpp_line_info}\n"
|
|
66
|
+
|
|
67
|
+
if self.context.get('source_file'):
|
|
68
|
+
result += f" 生成文件: {self.context['source_file']}\n"
|
|
69
|
+
|
|
70
|
+
# 显示Python源码上下文
|
|
71
|
+
python_source = self.context.get('python_source', '')
|
|
72
|
+
if python_source and cpp_line_info:
|
|
73
|
+
python_context = self.提取Python上下文(cpp_line_info)
|
|
74
|
+
if python_context:
|
|
75
|
+
result += f"\n🔍 对应的Python源码:\n"
|
|
76
|
+
result += f" {python_context}"
|
|
77
|
+
|
|
78
|
+
# 显示详细的编译器输出
|
|
79
|
+
if self.context.get('compiler_output'):
|
|
80
|
+
result += f"\n📋 编译器详细输出:\n"
|
|
81
|
+
compiler_output = self.context['compiler_output']
|
|
82
|
+
# 只显示关键错误信息,避免冗余
|
|
83
|
+
lines = compiler_output.split('\n')
|
|
84
|
+
error_lines = [line for line in lines if 'error:' in line.lower() or '错误' in line]
|
|
85
|
+
if error_lines:
|
|
86
|
+
for line in error_lines[-3:]: # 只显示最后3个错误
|
|
87
|
+
result += f" {line}\n"
|
|
88
|
+
else:
|
|
89
|
+
# 如果没有找到error行,显示最后几行
|
|
90
|
+
for line in lines[-5:]:
|
|
91
|
+
result += f" {line}\n"
|
|
92
|
+
|
|
93
|
+
return result
|
|
94
|
+
|
|
95
|
+
def 提取C行号信息(self) -> Optional[str]:
|
|
96
|
+
"""从编译器输出中提取C++行号信息"""
|
|
97
|
+
compiler_output = self.context.get('compiler_output', '')
|
|
98
|
+
if not compiler_output:
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
import re
|
|
102
|
+
# 匹配常见的编译器错误格式: file.cpp:line:column: error:
|
|
103
|
+
patterns = [
|
|
104
|
+
r'^([^:]+):(\d+):(\d+): error:',
|
|
105
|
+
r'^([^:]+):(\d+): error:',
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
for line in compiler_output.split('\n'):
|
|
109
|
+
for pattern in patterns:
|
|
110
|
+
match = re.search(pattern, line)
|
|
111
|
+
if match:
|
|
112
|
+
file_path = match.group(1)
|
|
113
|
+
line_num = match.group(2)
|
|
114
|
+
col_num = match.group(3) if len(match.groups()) >= 3 else "?"
|
|
115
|
+
# 提取文件名
|
|
116
|
+
file_name = file_path.split('/')[-1]
|
|
117
|
+
return f"{file_name}:{line_num}:{col_num}"
|
|
118
|
+
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
def 提取Python上下文(self, cpp_line_info: str) -> Optional[str]:
|
|
122
|
+
"""根据C++错误行号提取对应的Python源码上下文"""
|
|
123
|
+
try:
|
|
124
|
+
# 从cpp_line_info中提取行号
|
|
125
|
+
import re
|
|
126
|
+
match = re.search(r':(\d+):', cpp_line_info)
|
|
127
|
+
if not match:
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
cpp_line_num = int(match.group(1))
|
|
131
|
+
python_source = self.context.get('python_source', '')
|
|
132
|
+
if not python_source:
|
|
133
|
+
return None
|
|
134
|
+
|
|
135
|
+
python_lines = python_source.split('\n')
|
|
136
|
+
|
|
137
|
+
# 简单的启发式:C++中的函数体通常从Python函数体开始后几行开始
|
|
138
|
+
# 找到第一个非空、非注释的Python行作为起点
|
|
139
|
+
for i, line in enumerate(python_lines):
|
|
140
|
+
stripped = line.strip()
|
|
141
|
+
if stripped and not stripped.startswith('#') and not stripped.startswith('"""') and not stripped.startswith("'''"):
|
|
142
|
+
# 显示这一行作为可能的错误位置
|
|
143
|
+
line_display = min(i + 1, len(python_lines))
|
|
144
|
+
return f"第{line_display}行: {stripped}"
|
|
145
|
+
|
|
146
|
+
return None
|
|
147
|
+
except (ValueError, AttributeError, KeyError, IndexError, TypeError):
|
|
148
|
+
return None
|
|
149
|
+
except KeyboardInterrupt:
|
|
150
|
+
raise
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class 运行时错误(Jit错误):
|
|
154
|
+
"""当运行时发生错误时抛出"""
|
|
155
|
+
|
|
156
|
+
def __init__(self, message: str, function_name: Optional[str] = None, args: Optional[tuple] = None):
|
|
157
|
+
"""
|
|
158
|
+
初始化运行时错误
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
message: 错误信息
|
|
162
|
+
function_name: 函数名
|
|
163
|
+
args: 函数参数
|
|
164
|
+
"""
|
|
165
|
+
context = {}
|
|
166
|
+
if function_name:
|
|
167
|
+
context['function_name'] = function_name
|
|
168
|
+
if args:
|
|
169
|
+
context['args'] = args
|
|
170
|
+
super().__init__(message, "RUNTIME_ERROR", context)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class 类型不匹配错误(Jit错误):
|
|
174
|
+
"""当类型不匹配预期时抛出"""
|
|
175
|
+
|
|
176
|
+
def __init__(self, message: str, expected_type: Optional[str] = None, actual_type: Optional[str] = None, value: Any = None):
|
|
177
|
+
"""
|
|
178
|
+
初始化类型不匹配错误
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
message: 错误信息
|
|
182
|
+
expected_type: 期望的类型
|
|
183
|
+
actual_type: 实际的类型
|
|
184
|
+
value: 相关值
|
|
185
|
+
"""
|
|
186
|
+
context = {}
|
|
187
|
+
if expected_type:
|
|
188
|
+
context['expected_type'] = expected_type
|
|
189
|
+
if actual_type:
|
|
190
|
+
context['actual_type'] = actual_type
|
|
191
|
+
if value is not None:
|
|
192
|
+
context['value'] = str(value)
|
|
193
|
+
super().__init__(message, "TYPE_MISMATCH", context)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class 类型不一致错误(Jit错误):
|
|
197
|
+
"""当容器(如列表)中的元素类型不一致时抛出"""
|
|
198
|
+
|
|
199
|
+
def __init__(self, message: str, container_type: Optional[str] = None, found_types: Optional[List[type]] = None):
|
|
200
|
+
"""
|
|
201
|
+
初始化类型不一致错误
|
|
202
|
+
|
|
203
|
+
Args:
|
|
204
|
+
message: 错误信息
|
|
205
|
+
container_type: 容器类型
|
|
206
|
+
found_types: 找到的类型列表
|
|
207
|
+
"""
|
|
208
|
+
context = {}
|
|
209
|
+
if container_type:
|
|
210
|
+
context['container_type'] = container_type
|
|
211
|
+
if found_types:
|
|
212
|
+
context['found_types'] = [str(t) for t in found_types]
|
|
213
|
+
super().__init__(message, "TYPE_INCONSISTENCY", context)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class 安全错误(Jit错误):
|
|
217
|
+
"""当安全限制被触发时抛出"""
|
|
218
|
+
|
|
219
|
+
def __init__(self, message: str, limit_type: Optional[str] = None, limit_value: Any = None, actual_value: Any = None):
|
|
220
|
+
"""
|
|
221
|
+
初始化安全错误
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
message: 错误信息
|
|
225
|
+
limit_type: 限制类型
|
|
226
|
+
limit_value: 限制值
|
|
227
|
+
actual_value: 实际值
|
|
228
|
+
"""
|
|
229
|
+
context = {}
|
|
230
|
+
if limit_type:
|
|
231
|
+
context['limit_type'] = limit_type
|
|
232
|
+
if limit_value is not None:
|
|
233
|
+
context['limit_value'] = limit_value
|
|
234
|
+
if actual_value is not None:
|
|
235
|
+
context['actual_value'] = actual_value
|
|
236
|
+
super().__init__(message, "SECURITY_ERROR", context)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
class 依赖错误(Jit错误):
|
|
240
|
+
"""当依赖解析失败时抛出"""
|
|
241
|
+
|
|
242
|
+
def __init__(self, message: str, dependency_name: Optional[str] = None, dependency_type: Optional[str] = None):
|
|
243
|
+
"""
|
|
244
|
+
初始化依赖错误
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
message: 错误信息
|
|
248
|
+
dependency_name: 依赖名称
|
|
249
|
+
dependency_type: 依赖类型
|
|
250
|
+
"""
|
|
251
|
+
context = {}
|
|
252
|
+
if dependency_name:
|
|
253
|
+
context['dependency_name'] = dependency_name
|
|
254
|
+
if dependency_type:
|
|
255
|
+
context['dependency_type'] = dependency_type
|
|
256
|
+
super().__init__(message, "DEPENDENCY_ERROR", context)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class 配置错误(Jit错误):
|
|
260
|
+
"""当配置错误时抛出"""
|
|
261
|
+
|
|
262
|
+
def __init__(self, message: str, config_key: Optional[str] = None, config_value: Any = None):
|
|
263
|
+
"""
|
|
264
|
+
初始化配置错误
|
|
265
|
+
|
|
266
|
+
Args:
|
|
267
|
+
message: 错误信息
|
|
268
|
+
config_key: 配置键
|
|
269
|
+
config_value: 配置值
|
|
270
|
+
"""
|
|
271
|
+
context = {}
|
|
272
|
+
if config_key:
|
|
273
|
+
context['config_key'] = config_key
|
|
274
|
+
if config_value is not None:
|
|
275
|
+
context['config_value'] = str(config_value)
|
|
276
|
+
super().__init__(message, "CONFIG_ERROR", context)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
# 错误码映射表
|
|
280
|
+
ERROR_CODE_MAP = {
|
|
281
|
+
"COMPILATION_ERROR": "C001",
|
|
282
|
+
"RUNTIME_ERROR": "R001",
|
|
283
|
+
"TYPE_MISMATCH": "T001",
|
|
284
|
+
"TYPE_INCONSISTENCY": "T002",
|
|
285
|
+
"SECURITY_ERROR": "S001",
|
|
286
|
+
"DEPENDENCY_ERROR": "D001",
|
|
287
|
+
"CONFIG_ERROR": "CF001"
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def get_error_code_description(error_code: str) -> str:
|
|
292
|
+
"""
|
|
293
|
+
获取错误码描述
|
|
294
|
+
|
|
295
|
+
Args:
|
|
296
|
+
error_code: 错误码
|
|
297
|
+
|
|
298
|
+
Returns:
|
|
299
|
+
str: 错误码描述
|
|
300
|
+
"""
|
|
301
|
+
descriptions = {
|
|
302
|
+
"C001": "编译错误",
|
|
303
|
+
"R001": "运行时错误",
|
|
304
|
+
"T001": "类型不匹配",
|
|
305
|
+
"T002": "类型不一致",
|
|
306
|
+
"S001": "安全限制触发",
|
|
307
|
+
"D001": "依赖解析失败",
|
|
308
|
+
"CF001": "配置错误"
|
|
309
|
+
}
|
|
310
|
+
return descriptions.get(error_code, "未知错误")
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
class 错误处理器:
|
|
314
|
+
"""
|
|
315
|
+
统一的错误处理接口
|
|
316
|
+
|
|
317
|
+
提供格式化错误信息、抛出异常的统一方法。
|
|
318
|
+
确保所有错误都包含源码位置和上下文信息。
|
|
319
|
+
"""
|
|
320
|
+
|
|
321
|
+
@staticmethod
|
|
322
|
+
def 格式化错误信息(
|
|
323
|
+
消息: str,
|
|
324
|
+
节点: Optional[ast.AST] = None,
|
|
325
|
+
源代码: Optional[str] = None,
|
|
326
|
+
上下文: str = ""
|
|
327
|
+
) -> str:
|
|
328
|
+
"""
|
|
329
|
+
格式化错误信息,包含源码位置
|
|
330
|
+
|
|
331
|
+
Args:
|
|
332
|
+
消息: 错误消息
|
|
333
|
+
节点: AST节点(可选),用于获取行号和列号
|
|
334
|
+
源代码: Python源代码(可选)
|
|
335
|
+
上下文: 额外的上下文信息
|
|
336
|
+
|
|
337
|
+
Returns:
|
|
338
|
+
格式化的错误信息
|
|
339
|
+
"""
|
|
340
|
+
if 节点:
|
|
341
|
+
line_no = getattr(节点, "lineno", "?")
|
|
342
|
+
col_offset = getattr(节点, "col_offset", "?")
|
|
343
|
+
|
|
344
|
+
result = f"❌ 转译错误 (第{line_no}行,第{col_offset}列):\n"
|
|
345
|
+
result += f" {消息}\n"
|
|
346
|
+
|
|
347
|
+
# 添加源码上下文
|
|
348
|
+
if 源代码 and isinstance(line_no, int):
|
|
349
|
+
source_lines = 源代码.split('\n')
|
|
350
|
+
if 0 < line_no <= len(source_lines):
|
|
351
|
+
context_line = source_lines[line_no - 1].strip()
|
|
352
|
+
result += f" 源码: {context_line}\n"
|
|
353
|
+
|
|
354
|
+
# 尝试显示错误位置指示器
|
|
355
|
+
if isinstance(col_offset, int) and col_offset >= 0:
|
|
356
|
+
indent = len(context_line[:col_offset].lstrip())
|
|
357
|
+
pointer = " " * (4 + indent) + "↑"
|
|
358
|
+
result += f"{pointer}\n"
|
|
359
|
+
|
|
360
|
+
# 添加额外上下文
|
|
361
|
+
if 上下文:
|
|
362
|
+
result += f" 上下文: {上下文}\n"
|
|
363
|
+
|
|
364
|
+
return result
|
|
365
|
+
else:
|
|
366
|
+
# 没有节点信息,返回简单格式
|
|
367
|
+
result = f"❌ 转译错误:\n {消息}\n"
|
|
368
|
+
if 上下文:
|
|
369
|
+
result += f" 上下文: {上下文}\n"
|
|
370
|
+
return result
|
|
371
|
+
|
|
372
|
+
@staticmethod
|
|
373
|
+
def 抛出错误(
|
|
374
|
+
消息: str,
|
|
375
|
+
节点: Optional[ast.AST] = None,
|
|
376
|
+
源代码: Optional[str] = None,
|
|
377
|
+
上下文: str = "",
|
|
378
|
+
错误代码: Optional[str] = None
|
|
379
|
+
):
|
|
380
|
+
"""
|
|
381
|
+
抛出格式化的 JIT 错误
|
|
382
|
+
|
|
383
|
+
Args:
|
|
384
|
+
消息: 错误消息
|
|
385
|
+
节点: AST节点(可选)
|
|
386
|
+
源代码: Python源代码(可选)
|
|
387
|
+
上下文: 额外的上下文信息
|
|
388
|
+
错误代码: 错误代码(可选)
|
|
389
|
+
|
|
390
|
+
Raises:
|
|
391
|
+
Jit错误: 包含格式化错误信息的异常
|
|
392
|
+
"""
|
|
393
|
+
error_msg = 错误处理器.格式化错误信息(消息, 节点, 源代码, 上下文)
|
|
394
|
+
raise Jit错误(error_msg, error_code=错误代码)
|
|
395
|
+
|
|
396
|
+
@staticmethod
|
|
397
|
+
def 抛出类型错误(
|
|
398
|
+
消息: str,
|
|
399
|
+
期望类型: str,
|
|
400
|
+
实际类型: str,
|
|
401
|
+
节点: Optional[ast.AST] = None,
|
|
402
|
+
源代码: Optional[str] = None
|
|
403
|
+
):
|
|
404
|
+
"""
|
|
405
|
+
抛出类型不匹配错误
|
|
406
|
+
|
|
407
|
+
Args:
|
|
408
|
+
消息: 错误消息
|
|
409
|
+
期望类型: 期望的类型
|
|
410
|
+
实际类型: 实际的类型
|
|
411
|
+
节点: AST节点(可选)
|
|
412
|
+
源代码: Python源代码(可选)
|
|
413
|
+
|
|
414
|
+
Raises:
|
|
415
|
+
类型不匹配错误: 包含类型信息的异常
|
|
416
|
+
"""
|
|
417
|
+
# 使用格式化错误信息,然后创建类型不匹配错误
|
|
418
|
+
上下文 = f"期望类型: {期望类型}, 实际类型: {实际类型}"
|
|
419
|
+
formatted_msg = 错误处理器.格式化错误信息(消息, 节点, 源代码, 上下文)
|
|
420
|
+
raise 类型不匹配错误(formatted_msg, 期望类型, 实际类型)
|
|
421
|
+
|
|
422
|
+
@staticmethod
|
|
423
|
+
def 抛出编译错误(
|
|
424
|
+
消息: str,
|
|
425
|
+
编译器输出: Optional[str] = None,
|
|
426
|
+
源文件: Optional[str] = None,
|
|
427
|
+
Python源码: Optional[str] = None
|
|
428
|
+
):
|
|
429
|
+
"""
|
|
430
|
+
抛出编译错误
|
|
431
|
+
|
|
432
|
+
Args:
|
|
433
|
+
消息: 错误消息
|
|
434
|
+
编译器输出: 编译器输出(可选)
|
|
435
|
+
源文件: 源文件路径(可选)
|
|
436
|
+
Python源码: Python源代码(可选)
|
|
437
|
+
|
|
438
|
+
Raises:
|
|
439
|
+
编译错误: 包含编译信息的异常
|
|
440
|
+
"""
|
|
441
|
+
raise 编译错误(消息, 编译器输出, 源文件, Python源码)
|
|
442
|
+
|
|
443
|
+
@staticmethod
|
|
444
|
+
def 抛出不支持错误(
|
|
445
|
+
特性名称: str,
|
|
446
|
+
节点: Optional[ast.AST] = None,
|
|
447
|
+
源代码: Optional[str] = None
|
|
448
|
+
):
|
|
449
|
+
"""
|
|
450
|
+
抛出不支持的特性错误
|
|
451
|
+
|
|
452
|
+
Args:
|
|
453
|
+
特性名称: 不支持的特性名称
|
|
454
|
+
节点: AST节点(可选)
|
|
455
|
+
源代码: Python源代码(可选)
|
|
456
|
+
|
|
457
|
+
Raises:
|
|
458
|
+
Jit错误: 包含不支持特性信息的异常
|
|
459
|
+
"""
|
|
460
|
+
消息 = f"不支持的特性: {特性名称}"
|
|
461
|
+
raise 错误处理器.抛出错误(消息, 节点, 源代码, "NOT_SUPPORTED")
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def 抛出错误(消息: str, 节点: Optional[ast.AST] = None, 源代码: Optional[str] = None, 上下文: str = ""):
|
|
465
|
+
"""
|
|
466
|
+
便捷函数:抛出格式化的 JIT 错误
|
|
467
|
+
|
|
468
|
+
Args:
|
|
469
|
+
消息: 错误消息
|
|
470
|
+
节点: AST节点(可选)
|
|
471
|
+
源代码: Python源代码(可选)
|
|
472
|
+
上下文: 额外的上下文信息
|
|
473
|
+
"""
|
|
474
|
+
错误处理器.抛出错误(消息, 节点, 源代码, 上下文)
|