
Instead of ignoring boilerplate when decompiling `async for`, build the loop semantically by deconstructing the BLK_WHILE -> BLK_CONTAINER -> BLK_TRY that python generates when compiling an `async for` (see https://www.python.org/dev/peps/pep-0492/#asynchronous-iterators-and-async-for). When reading GET_AITER, convert the BLK_WHILE into a BLK_ASYNCFOR in the same way as a `for` loop. Ignore GET_ANEXT. Use END_FINALLY as the trigger to finish building the BLK_ASYNCFOR: -> Extract the loop variable from the contents of the BLK_TRY. -> Throw away the BLK_TRY and BLK_CONTAINER, leave the BLK_ASYNCFOR on top of the stack.
82 lines
1.7 KiB
C++
82 lines
1.7 KiB
C++
#include "ASTNode.h"
|
|
|
|
/* ASTNodeList */
|
|
void ASTNodeList::removeLast()
|
|
{
|
|
list_t::iterator it = m_nodes.end();
|
|
--it;
|
|
m_nodes.erase(it);
|
|
}
|
|
|
|
void ASTNodeList::removeFirst()
|
|
{
|
|
m_nodes.erase(m_nodes.cbegin());
|
|
}
|
|
|
|
|
|
/* ASTUnary */
|
|
const char* ASTUnary::op_str() const
|
|
{
|
|
static const char* s_op_strings[] = {
|
|
"+", "-", "~", "not "
|
|
};
|
|
return s_op_strings[op()];
|
|
}
|
|
|
|
|
|
/* ASTBinary */
|
|
const char* ASTBinary::op_str() const
|
|
{
|
|
static const char* s_op_strings[] = {
|
|
".", " ** ", " * ", " / ", " // ", " % ", " + ", " - ",
|
|
" << ", " >> ", " & ", " ^ ", " | ", " and ", " or ", " @ ",
|
|
" += ", " -= ", " *= ", " /= ", " %= ", " **= ", " <<= ",
|
|
" >>= ", " &= ", " ^= ", " |= ", " //= ", " @= ",
|
|
};
|
|
return s_op_strings[op()];
|
|
}
|
|
|
|
|
|
/* ASTCompare */
|
|
const char* ASTCompare::op_str() const
|
|
{
|
|
static const char* s_cmp_strings[] = {
|
|
" < ", " <= ", " == ", " != ", " > ", " >= ", " in ", " not in ", " is ", " is not ",
|
|
"<EXCEPTION MATCH>", "<BAD>"
|
|
};
|
|
return s_cmp_strings[op()];
|
|
}
|
|
|
|
|
|
/* ASTKeyword */
|
|
const char* ASTKeyword::word_str() const
|
|
{
|
|
static const char* s_word_strings[] = {
|
|
"pass", "break", "continue"
|
|
};
|
|
return s_word_strings[key()];
|
|
}
|
|
|
|
|
|
/* ASTBlock */
|
|
void ASTBlock::removeLast()
|
|
{
|
|
list_t::iterator it = m_nodes.end();
|
|
--it;
|
|
m_nodes.erase(it);
|
|
}
|
|
|
|
void ASTBlock::removeFirst()
|
|
{
|
|
m_nodes.erase(m_nodes.begin());
|
|
}
|
|
|
|
const char* ASTBlock::type_str() const
|
|
{
|
|
static const char* s_type_strings[] = {
|
|
"", "if", "else", "elif", "try", "CONTAINER", "except",
|
|
"finally", "while", "for", "with", "async for"
|
|
};
|
|
return s_type_strings[blktype()];
|
|
}
|