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

Function generateIfStatementFromElif

python/executor.py:324–370  ·  view source on GitHub ↗
(elif_node, else_nodes, traced)

Source from the content-addressed store, hash-verified

322
323
324def generateIfStatementFromElif(elif_node, else_nodes, traced):
325 condition = generateAstExpression(elif_node["childSets"]["condition"][0])
326 lineno = 1
327 if 'meta' in elif_node and 'lineno' in elif_node['meta']:
328 lineno = elif_node['meta']['lineno']
329
330 if traced:
331 key = ast.Name(id=SPLOOT_KEY, ctx=ast.Load())
332 func = ast.Attribute(
333 value=key, attr="logExpressionResultAndStartFrame", ctx=ast.Load()
334 )
335 args = [
336 ast.Constant("PYTHON_ELIF_STATEMENT"),
337 ast.Constant("condition"),
338 condition,
339 ]
340 condition = ast.Call(func, args=args, keywords=[])
341
342 statements = getStatementsFromBlock(elif_node["childSets"]["block"], traced)
343
344 else_statements = []
345 if len(else_nodes) != 0:
346 else_statements = generateElifNestedChain(else_nodes, traced)
347
348 if traced:
349 key = ast.Name(id=SPLOOT_KEY, ctx=ast.Load())
350 func = ast.Attribute(value=key, attr="endFrame", ctx=ast.Load())
351 call_end_frame = ast.Call(func, args=[], keywords=[])
352
353 # End the elif frame before starting the next else/elif block
354 else_statements.insert(0, ast.Expr(call_end_frame, lineno=1, col_offset=0))
355
356 key = ast.Name(id=SPLOOT_KEY, ctx=ast.Load())
357 func = ast.Attribute(value=key, attr="startChildSet", ctx=ast.Load())
358 args = [ast.Constant("block")]
359 call_start_childset = ast.Call(func, args=args, keywords=[])
360
361 key = ast.Name(id=SPLOOT_KEY, ctx=ast.Load())
362 func = ast.Attribute(value=key, attr="endFrame", ctx=ast.Load())
363 call_end_frame = ast.Call(func, args=[], keywords=[])
364
365 statements.insert(0, ast.Expr(call_start_childset, lineno=1, col_offset=0))
366 statements.append(ast.Expr(call_end_frame, lineno=1, col_offset=0))
367
368 return [
369 ast.If(condition, statements, else_statements, lineno=lineno),
370 ]
371
372
373def generateElifNestedChain(else_nodes, traced):

Callers 1

generateElifNestedChainFunction · 0.70

Calls 3

generateAstExpressionFunction · 0.70
getStatementsFromBlockFunction · 0.70
generateElifNestedChainFunction · 0.70

Tested by

no test coverage detected