MCPcopy Create free account
hub / github.com/SplootCode/splootcode / generateIfStatement

Function generateIfStatement

python/executor.py:466–496  ·  view source on GitHub ↗
(if_node, traced, lineno)

Source from the content-addressed store, hash-verified

464 return statements
465
466def generateIfStatement(if_node, traced, lineno):
467 condition = generateAstExpression(if_node["childSets"]["condition"][0])
468
469 if traced:
470 key = ast.Name(id=SPLOOT_KEY, ctx=ast.Load())
471 func = ast.Attribute(
472 value=key, attr="logExpressionResultAndStartFrame", ctx=ast.Load()
473 )
474 args = [
475 ast.Constant("PYTHON_IF_STATEMENT"),
476 ast.Constant("condition"),
477 condition,
478 ]
479 condition = ast.Call(func, args=args, keywords=[])
480
481 statements = getStatementsFromBlock(if_node["childSets"]["trueblock"], traced)
482
483 else_statements = []
484 if "elseblocks" in if_node["childSets"] and len(if_node["childSets"]["elseblocks"]) != 0:
485 else_statements = generateElifNestedChain(if_node["childSets"]["elseblocks"], traced)
486 if traced:
487 else_statements.insert(0, startChildSetStatement('elseblocks'))
488
489 if not traced:
490 return [ast.If(condition, statements, else_statements)]
491
492 statements.insert(0, startChildSetStatement('trueblock'))
493 return [
494 ast.If(condition, statements, else_statements, lineno=lineno),
495 endFrame(),
496 ]
497
498
499def startFrameStatement(nodeType, childSetName):

Callers 1

Calls 5

startChildSetStatementFunction · 0.85
endFrameFunction · 0.85
generateAstExpressionFunction · 0.70
getStatementsFromBlockFunction · 0.70
generateElifNestedChainFunction · 0.70

Tested by

no test coverage detected