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

Function generateIf

python/convert_ast.py:212–234  ·  view source on GitHub ↗
(statement)

Source from the content-addressed store, hash-verified

210
211
212def generateIf(statement):
213 test = generateExpression(statement.test)
214 body = getBlockBodyFromStatements(statement.body)
215 elseblocks = []
216
217 orelse = statement.orelse
218 while len(orelse) == 1 and type(orelse[0]) == ast.If:
219 # It's one if in an else, make it an elif.
220 ifstatement = orelse[0]
221 elifbody = getBlockBodyFromStatements(ifstatement.body)
222 elifcondition = generateExpression(ifstatement.test)
223 elseblocks.append(SplootNode('PYTHON_ELIF_STATEMENT', {'block': elifbody, 'condition': [elifcondition]}))
224 orelse = ifstatement.orelse
225
226 if len(orelse) != 0:
227 elsebody = getBlockBodyFromStatements(orelse)
228 elseblocks.append(SplootNode('PYTHON_ELSE_STATEMENT', {'block': elsebody}))
229
230 return SplootNode("PYTHON_IF_STATEMENT", {
231 'condition': [test],
232 'trueblock': body,
233 'elseblocks': elseblocks
234 })
235
236def generateWhile(whileStatement):
237 test = generateExpression(whileStatement.test)

Callers 1

generateSplootStatementFunction · 0.85

Calls 3

generateExpressionFunction · 0.85
SplootNodeFunction · 0.70

Tested by

no test coverage detected