MCPcopy Index your code
hub / github.com/apache/tvm / Diagnostics

Class Diagnostics

python/tvm/script/parser/core/diagnostics.py:261–305  ·  view source on GitHub ↗

Diagnostics class for error reporting in parser. Formats parse errors with source location context and raises directly, without going through DiagnosticContext. Parameters ---------- source : Source The source code.

Source from the content-addressed store, hash-verified

259
260
261class Diagnostics:
262 """Diagnostics class for error reporting in parser.
263
264 Formats parse errors with source location context and raises directly,
265 without going through DiagnosticContext.
266
267 Parameters
268 ----------
269 source : Source
270 The source code.
271 """
272
273 source: Source
274
275 def __init__(self, source: Source):
276 self.source = source
277
278 def error(self, node: doc.AST, message: str) -> None:
279 """Emit a diagnostic error by raising with source location context.
280
281 Parameters
282 ----------
283 node : doc.AST
284 The node with diagnostic error.
285
286 message : str
287 The diagnostic message.
288 """
289 lineno = getattr(node, "lineno", 1)
290 col_offset = getattr(node, "col_offset", self.source.start_column)
291 end_lineno = getattr(node, "end_lineno", lineno)
292 end_col_offset = getattr(node, "end_col_offset", col_offset)
293 lineno += self.source.start_line - 1
294 end_lineno += self.source.start_line - 1
295 col_offset += self.source.start_column + 1
296 end_col_offset += self.source.start_column + 1
297
298 source_lines = self.source.full_source.splitlines(keepends=True)
299 snippet = _format_source_snippet(
300 source_lines, lineno, col_offset, end_lineno, end_col_offset
301 )
302
303 location = f"{self.source.source_name}:{lineno}:{col_offset}"
304 formatted = f"error: {message}\n --> {location}\n{snippet}"
305 raise DiagnosticError(formatted)

Callers 2

__init__Method · 0.85
with_diag_sourceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…