Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix type annotations
  • Loading branch information
markshannon committed Mar 31, 2025
commit 3d3cc0edcca7087b65822b15c9be3aae8865f1e2
21 changes: 13 additions & 8 deletions Tools/cases_generator/generators_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def _emit_stmt(
uop: CodeSection,
storage: Storage,
inst: Instruction | None,
) -> tuple[bool, Token, Storage]:
) -> tuple[bool, Token | None, Storage]:
if isinstance(stmt, SimpleStmt):
return self._emit_simple(stmt, uop, storage, inst)
elif isinstance(stmt, BlockStmt):
Expand All @@ -488,17 +488,16 @@ def _emit_simple(
uop: CodeSection,
storage: Storage,
inst: Instruction | None,
) -> tuple[bool, Token, Storage]:
) -> tuple[bool, Token | None, Storage]:
local_stores = set(uop.local_stores)
reachable = True
tkn_iter = TokenIterator(stmt.contents)
tkn = tkn_iter.peek()
try:
if stmt in uop.properties.escaping_calls:
escape = uop.properties.escaping_calls[stmt]
if escape.kills is not None:
self.stackref_kill(escape.kills, storage, True)
self.emit_save(storage)
tkn_iter = TokenIterator(stmt.contents)
for tkn in tkn_iter:
if tkn.kind == "GOTO":
label_tkn = next(tkn_iter)
Expand Down Expand Up @@ -538,11 +537,11 @@ def _emit_simple(

def _emit_macro_if(
self,
stmt: IfStmt,
stmt: MacroIfStmt,
uop: CodeSection,
storage: Storage,
inst: Instruction | None,
) -> tuple[bool, Token, Storage]:
) -> tuple[bool, Token | None, Storage]:
self.out.emit(stmt.condition)
branch = stmt.else_ is not None
reachable = True
Expand All @@ -554,7 +553,9 @@ def _emit_macro_if(
reachable = False
if branch:
else_storage = storage.copy()
assert stmt.else_ is not None
self.out.emit(stmt.else_)
assert stmt.else_body is not None
for s in stmt.else_body:
r, tkn, else_storage = self._emit_stmt(s, uop, else_storage, inst)
if tkn is not None:
Expand All @@ -572,7 +573,7 @@ def _emit_if(
uop: CodeSection,
storage: Storage,
inst: Instruction | None,
) -> tuple[bool, Token, Storage]:
) -> tuple[bool, Token | None, Storage]:
self.out.emit(stmt.if_)
for tkn in stmt.condition:
self.out.emit(tkn)
Expand Down Expand Up @@ -604,6 +605,7 @@ def _emit_if(
return reachable, rbrace, storage
except StackError as ex:
self._print_storage(if_storage)
assert rbrace is not None
raise analysis_error(ex.args[0], rbrace) from None

def _emit_block(
Expand All @@ -627,7 +629,9 @@ def _emit_block(
break
return reachable, stmt.close, storage
except StackError as ex:
raise analysis_error(ex.args[0], rbrace) from None
if tkn is None:
tkn = stmt.close
raise analysis_error(ex.args[0], tkn) from None

def _emit_for(
self,
Expand Down Expand Up @@ -665,6 +669,7 @@ def emit_tokens(
) -> Storage:
self.out.start_line()
reachable, tkn, storage = self._emit_block(code.body, code, storage, inst, emit_braces)
assert tkn is not None
try:
if reachable:
self._print_storage(storage)
Expand Down
2 changes: 1 addition & 1 deletion Tools/cases_generator/optimizer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def write_uop(
out.start_line()
stack.flush(out)
except StackError as ex:
raise analysis_error(ex.args[0], prototype.body[0]) # from None
raise analysis_error(ex.args[0], prototype.body.open) # from None


SKIPS = ("_EXTENDED_ARG",)
Expand Down
6 changes: 4 additions & 2 deletions Tools/cases_generator/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ def print(self, out:CWriter) -> None:
for tkn in self.condition:
out.emit(tkn)
self.body.print(out)
if self.else_body is not None:
if self.else_ is not None:
out.emit(self.else_)
self.body.print(out)
if self.else_body is not None:
self.else_body.print(out)

def accept(self, visitor: Visitor) -> None:
Expand Down Expand Up @@ -689,7 +691,7 @@ def if_stmt(self, if_: lx.Token) -> IfStmt:
return IfStmt(if_, condition, body, else_, else_body)

Comment thread
markshannon marked this conversation as resolved.

def macro_if(self, cond: lx.Token) -> IfStmt:
def macro_if(self, cond: lx.Token) -> MacroIfStmt:
else_ = None
body: list[Stmt] = []
else_body: list[Stmt] | None = None
Expand Down
2 changes: 1 addition & 1 deletion Tools/cases_generator/tier2_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def write_uop(uop: Uop, emitter: Emitter, stack: Stack) -> Stack:
storage = emitter.emit_tokens(uop, storage, None, False)
storage.flush(emitter.out)
except StackError as ex:
raise analysis_error(ex.args[0], uop.body[0]) from None
raise analysis_error(ex.args[0], uop.body.open) from None
return storage.stack

SKIPS = ("_EXTENDED_ARG",)
Expand Down