MCPcopy Index your code
hub / github.com/python/cpython / find_variable_stores

Function find_variable_stores

Tools/cases_generator/analyzer.py:439–470  ·  view source on GitHub ↗
(node: parser.InstDef)

Source from the content-addressed store, hash-verified

437
438
439def find_variable_stores(node: parser.InstDef) -> list[lexer.Token]:
440 res: list[lexer.Token] = []
441 outnames = { out.name for out in node.outputs }
442 innames = { out.name for out in node.inputs }
443
444 def find_stores_in_tokens(tokens: list[lexer.Token], callback: Callable[[lexer.Token], None]) -> None:
445 while tokens and tokens[0].kind == "COMMENT":
446 tokens = tokens[1:]
447 if len(tokens) < 4:
448 return
449 if tokens[1].kind == "EQUALS":
450 if tokens[0].kind == "IDENTIFIER":
451 name = tokens[0].text
452 if name in outnames or name in innames:
453 callback(tokens[0])
454 #Passing the address of a local is also a definition
455 for idx, tkn in enumerate(tokens):
456 if tkn.kind == "AND":
457 name_tkn = tokens[idx+1]
458 if name_tkn.text in outnames:
459 callback(name_tkn)
460
461 def visit(stmt: Stmt) -> None:
462 if isinstance(stmt, IfStmt):
463 def error(tkn: lexer.Token) -> None:
464 raise analysis_error("Cannot define variable in 'if' condition", tkn)
465 find_stores_in_tokens(stmt.condition, error)
466 elif isinstance(stmt, SimpleStmt):
467 find_stores_in_tokens(stmt.contents, res.append)
468
469 node.block.accept(visit)
470 return res
471
472
473#def analyze_deferred_refs(node: parser.InstDef) -> dict[lexer.Token, str | None]:

Callers 1

make_uopFunction · 0.85

Calls 1

acceptMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…