Files
Pyarmor-Static-Unpack-1shot/ASTNode.h

736 lines
19 KiB
C
Raw Normal View History

2009-07-26 10:07:13 +00:00
#ifndef _PYC_ASTNODE_H
#define _PYC_ASTNODE_H
2011-10-23 17:48:10 -07:00
#include "pyc_module.h"
2009-07-26 10:07:13 +00:00
#include <list>
2023-02-13 19:25:45 -08:00
#include <deque>
2009-07-26 10:07:13 +00:00
/* Similar interface to PycObject, so PycRef can work on it... *
* However, this does *NOT* mean the two are interchangeable! */
class ASTNode {
public:
enum Type {
NODE_INVALID, NODE_NODELIST, NODE_OBJECT, NODE_UNARY, NODE_BINARY,
NODE_COMPARE, NODE_SLICE, NODE_STORE, NODE_RETURN, NODE_NAME,
NODE_DELETE, NODE_FUNCTION, NODE_CLASS, NODE_CALL, NODE_IMPORT,
2023-02-12 15:56:18 -08:00
NODE_TUPLE, NODE_LIST, NODE_SET, NODE_MAP, NODE_SUBSCR, NODE_PRINT,
2011-01-10 13:15:56 -08:00
NODE_CONVERT, NODE_KEYWORD, NODE_RAISE, NODE_EXEC, NODE_BLOCK,
NODE_COMPREHENSION, NODE_LOADBUILDCLASS, NODE_AWAITABLE,
NODE_FORMATTEDVALUE, NODE_JOINEDSTR, NODE_CONST_MAP,
NODE_ANNOTATED_VAR, NODE_CHAINSTORE, NODE_TERNARY,
2009-07-27 03:00:55 +00:00
// Empty node types
NODE_LOCALS,
2009-07-26 10:07:13 +00:00
};
ASTNode(int type = NODE_INVALID) : m_refs(), m_type(type), m_processed() { }
2009-07-26 10:07:13 +00:00
virtual ~ASTNode() { }
int type() const { return internalGetType(this); }
2009-07-26 10:07:13 +00:00
bool processed() const { return m_processed; }
void setProcessed() { m_processed = true; }
2009-07-26 10:07:13 +00:00
private:
int m_refs;
int m_type;
bool m_processed;
2009-07-26 10:07:13 +00:00
// Hack to make clang happy :(
static int internalGetType(const ASTNode *node)
{
return node ? node->m_type : NODE_INVALID;
}
static void internalAddRef(ASTNode *node)
{
if (node)
++node->m_refs;
}
static void internalDelRef(ASTNode *node)
{
if (node && --node->m_refs == 0)
delete node;
}
2009-07-26 10:07:13 +00:00
public:
void addRef() { internalAddRef(this); }
void delRef() { internalDelRef(this); }
2009-07-26 10:07:13 +00:00
};
class ASTNodeList : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<PycRef<ASTNode>> list_t;
2009-07-26 10:07:13 +00:00
ASTNodeList(list_t nodes)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_NODELIST), m_nodes(std::move(nodes)) { }
2009-07-26 10:07:13 +00:00
const list_t& nodes() const { return m_nodes; }
void removeFirst();
void removeLast();
2019-10-08 13:34:15 -07:00
void append(PycRef<ASTNode> node) { m_nodes.emplace_back(std::move(node)); }
2009-07-26 10:07:13 +00:00
protected:
ASTNodeList(list_t nodes, ASTNode::Type type)
: ASTNode(type), m_nodes(std::move(nodes)) { }
2009-07-26 10:07:13 +00:00
private:
list_t m_nodes;
};
class ASTChainStore : public ASTNodeList {
public:
ASTChainStore(list_t nodes, PycRef<ASTNode> src)
: ASTNodeList(nodes, NODE_CHAINSTORE), m_src(std::move(src)) { }
PycRef<ASTNode> src() const { return m_src; }
private:
PycRef<ASTNode> m_src;
};
2009-07-26 10:07:13 +00:00
class ASTObject : public ASTNode {
public:
ASTObject(PycRef<PycObject> obj)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_OBJECT), m_obj(std::move(obj)) { }
2009-07-26 10:07:13 +00:00
PycRef<PycObject> object() const { return m_obj; }
private:
PycRef<PycObject> m_obj;
};
class ASTUnary : public ASTNode {
public:
enum UnOp {
UN_POSITIVE, UN_NEGATIVE, UN_INVERT, UN_NOT
};
ASTUnary(PycRef<ASTNode> operand, int op)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_UNARY), m_op(op), m_operand(std::move(operand)) { }
2009-07-26 10:07:13 +00:00
PycRef<ASTNode> operand() const { return m_operand; }
int op() const { return m_op; }
virtual const char* op_str() const;
protected:
int m_op;
2009-07-26 10:07:13 +00:00
private:
PycRef<ASTNode> m_operand;
};
class ASTBinary : public ASTNode {
public:
enum BinOp {
BIN_ATTR, BIN_POWER, BIN_MULTIPLY, BIN_DIVIDE, BIN_FLOOR, BIN_MODULO,
BIN_ADD, BIN_SUBTRACT, BIN_LSHIFT, BIN_RSHIFT, BIN_AND, BIN_XOR,
BIN_OR, BIN_LOG_AND, BIN_LOG_OR, BIN_MAT_MULTIPLY,
/* Inplace operations */
BIN_IP_ADD, BIN_IP_SUBTRACT, BIN_IP_MULTIPLY, BIN_IP_DIVIDE,
BIN_IP_MODULO, BIN_IP_POWER, BIN_IP_LSHIFT, BIN_IP_RSHIFT, BIN_IP_AND,
BIN_IP_XOR, BIN_IP_OR, BIN_IP_FLOOR, BIN_IP_MAT_MULTIPLY,
};
ASTBinary(PycRef<ASTNode> left, PycRef<ASTNode> right, int op,
int type = NODE_BINARY)
2019-10-08 13:34:15 -07:00
: ASTNode(type), m_op(op), m_left(std::move(left)), m_right(std::move(right)) { }
2009-07-26 10:07:13 +00:00
PycRef<ASTNode> left() const { return m_left; }
PycRef<ASTNode> right() const { return m_right; }
int op() const { return m_op; }
2011-09-18 11:59:02 -07:00
bool is_inplace() const { return m_op >= BIN_IP_ADD; }
virtual const char* op_str() const;
protected:
int m_op;
2009-07-26 10:07:13 +00:00
private:
PycRef<ASTNode> m_left;
PycRef<ASTNode> m_right;
};
class ASTCompare : public ASTBinary {
public:
enum CompareOp {
CMP_LESS, CMP_LESS_EQUAL, CMP_EQUAL, CMP_NOT_EQUAL, CMP_GREATER,
CMP_GREATER_EQUAL, CMP_IN, CMP_NOT_IN, CMP_IS, CMP_IS_NOT,
CMP_EXCEPTION, CMP_BAD
};
ASTCompare(PycRef<ASTNode> left, PycRef<ASTNode> right, int op)
2019-10-08 13:34:15 -07:00
: ASTBinary(std::move(left), std::move(right), op, NODE_COMPARE) { }
2009-07-26 10:07:13 +00:00
const char* op_str() const override;
2009-07-26 10:07:13 +00:00
};
class ASTSlice : public ASTBinary {
public:
enum SliceOp {
SLICE0, SLICE1, SLICE2, SLICE3
};
2019-10-08 13:34:15 -07:00
ASTSlice(int op, PycRef<ASTNode> left = {}, PycRef<ASTNode> right = {})
: ASTBinary(std::move(left), std::move(right), op, NODE_SLICE) { }
};
2009-07-26 10:07:13 +00:00
class ASTStore : public ASTNode {
public:
ASTStore(PycRef<ASTNode> src, PycRef<ASTNode> dest)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_STORE), m_src(std::move(src)), m_dest(std::move(dest)) { }
2009-07-26 10:07:13 +00:00
PycRef<ASTNode> src() const { return m_src; }
PycRef<ASTNode> dest() const { return m_dest; }
private:
PycRef<ASTNode> m_src;
PycRef<ASTNode> m_dest;
};
class ASTReturn : public ASTNode {
public:
2011-09-18 22:31:09 -07:00
enum RetType {
RETURN, YIELD, YIELD_FROM
2011-09-18 22:31:09 -07:00
};
ASTReturn(PycRef<ASTNode> value, RetType rettype = RETURN)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_RETURN), m_value(std::move(value)), m_rettype(rettype) { }
2009-07-26 10:07:13 +00:00
PycRef<ASTNode> value() const { return m_value; }
2011-09-18 22:31:09 -07:00
RetType rettype() const { return m_rettype; }
2009-07-26 10:07:13 +00:00
private:
PycRef<ASTNode> m_value;
2011-09-18 22:31:09 -07:00
RetType m_rettype;
2009-07-26 10:07:13 +00:00
};
class ASTName : public ASTNode {
public:
ASTName(PycRef<PycString> name)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_NAME), m_name(std::move(name)) { }
2009-07-26 10:07:13 +00:00
2009-07-27 03:00:55 +00:00
PycRef<PycString> name() const { return m_name; }
2009-07-26 10:07:13 +00:00
private:
2009-07-27 03:00:55 +00:00
PycRef<PycString> m_name;
2009-07-26 10:07:13 +00:00
};
class ASTDelete : public ASTNode {
public:
ASTDelete(PycRef<ASTNode> value)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_DELETE), m_value(std::move(value)) { }
2009-07-26 10:07:13 +00:00
PycRef<ASTNode> value() const { return m_value; }
private:
PycRef<ASTNode> m_value;
};
class ASTFunction : public ASTNode {
public:
2019-10-08 11:36:12 -07:00
typedef std::list<PycRef<ASTNode>> defarg_t;
2019-10-08 11:36:12 -07:00
ASTFunction(PycRef<ASTNode> code, defarg_t defArgs, defarg_t kwDefArgs)
: ASTNode(NODE_FUNCTION), m_code(std::move(code)),
m_defargs(std::move(defArgs)), m_kwdefargs(std::move(kwDefArgs)) { }
PycRef<ASTNode> code() const { return m_code; }
const defarg_t& defargs() const { return m_defargs; }
2019-10-08 11:36:12 -07:00
const defarg_t& kwdefargs() const { return m_kwdefargs; }
private:
PycRef<ASTNode> m_code;
defarg_t m_defargs;
2019-10-08 11:36:12 -07:00
defarg_t m_kwdefargs;
};
class ASTClass : public ASTNode {
public:
2009-07-27 03:00:55 +00:00
ASTClass(PycRef<ASTNode> code, PycRef<ASTNode> bases, PycRef<ASTNode> name)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_CLASS), m_code(std::move(code)), m_bases(std::move(bases)),
m_name(std::move(name)) { }
PycRef<ASTNode> code() const { return m_code; }
2009-07-27 03:00:55 +00:00
PycRef<ASTNode> bases() const { return m_bases; }
PycRef<ASTNode> name() const { return m_name; }
private:
PycRef<ASTNode> m_code;
2009-07-27 03:00:55 +00:00
PycRef<ASTNode> m_bases;
PycRef<ASTNode> m_name;
};
class ASTCall : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<PycRef<ASTNode>> pparam_t;
typedef std::list<std::pair<PycRef<ASTNode>, PycRef<ASTNode>>> kwparam_t;
ASTCall(PycRef<ASTNode> func, pparam_t pparams, kwparam_t kwparams)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_CALL), m_func(std::move(func)), m_pparams(std::move(pparams)),
m_kwparams(std::move(kwparams)) { }
PycRef<ASTNode> func() const { return m_func; }
const pparam_t& pparams() const { return m_pparams; }
const kwparam_t& kwparams() const { return m_kwparams; }
2011-10-09 22:38:18 -07:00
PycRef<ASTNode> var() const { return m_var; }
PycRef<ASTNode> kw() const { return m_kw; }
2019-10-08 13:34:15 -07:00
bool hasVar() const { return m_var != nullptr; }
bool hasKW() const { return m_kw != nullptr; }
2011-10-09 22:38:18 -07:00
2019-10-08 13:34:15 -07:00
void setVar(PycRef<ASTNode> var) { m_var = std::move(var); }
void setKW(PycRef<ASTNode> kw) { m_kw = std::move(kw); }
private:
PycRef<ASTNode> m_func;
pparam_t m_pparams;
kwparam_t m_kwparams;
2011-10-09 22:38:18 -07:00
PycRef<ASTNode> m_var;
PycRef<ASTNode> m_kw;
};
2009-07-27 03:00:55 +00:00
class ASTImport : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<PycRef<ASTStore>> list_t;
2009-07-27 03:00:55 +00:00
ASTImport(PycRef<ASTNode> name, PycRef<ASTNode> fromlist)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_IMPORT), m_name(std::move(name)), m_fromlist(std::move(fromlist)) { }
2009-07-27 03:00:55 +00:00
PycRef<ASTNode> name() const { return m_name; }
list_t stores() const { return m_stores; }
2019-10-08 13:34:15 -07:00
void add_store(PycRef<ASTStore> store) { m_stores.emplace_back(std::move(store)); }
2009-07-27 03:00:55 +00:00
PycRef<ASTNode> fromlist() const { return m_fromlist; }
private:
PycRef<ASTNode> m_name;
list_t m_stores;
2009-07-27 03:00:55 +00:00
PycRef<ASTNode> m_fromlist;
};
class ASTTuple : public ASTNode {
public:
typedef std::vector<PycRef<ASTNode>> value_t;
2009-07-27 03:00:55 +00:00
ASTTuple(value_t values)
: ASTNode(NODE_TUPLE), m_values(std::move(values)),
m_requireParens(true) { }
2009-07-27 03:00:55 +00:00
const value_t& values() const { return m_values; }
2019-10-08 13:34:15 -07:00
void add(PycRef<ASTNode> name) { m_values.emplace_back(std::move(name)); }
2009-07-27 03:00:55 +00:00
void setRequireParens(bool require) { m_requireParens = require; }
bool requireParens() const { return m_requireParens; }
2009-07-27 03:00:55 +00:00
private:
value_t m_values;
bool m_requireParens;
2009-07-27 03:00:55 +00:00
};
class ASTList : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<PycRef<ASTNode>> value_t;
ASTList(value_t values)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_LIST), m_values(std::move(values)) { }
const value_t& values() const { return m_values; }
private:
value_t m_values;
};
2023-02-12 15:56:18 -08:00
class ASTSet : public ASTNode {
public:
2023-02-13 19:25:45 -08:00
typedef std::deque<PycRef<ASTNode>> value_t;
2023-02-12 15:56:18 -08:00
ASTSet(value_t values)
: ASTNode(NODE_SET), m_values(std::move(values)) { }
const value_t& values() const { return m_values; }
private:
value_t m_values;
};
class ASTMap : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<std::pair<PycRef<ASTNode>, PycRef<ASTNode>>> map_t;
ASTMap() : ASTNode(NODE_MAP) { }
void add(PycRef<ASTNode> key, PycRef<ASTNode> value)
2019-10-08 13:34:15 -07:00
{
m_values.emplace_back(std::move(key), std::move(value));
}
const map_t& values() const { return m_values; }
private:
map_t m_values;
};
class ASTConstMap : public ASTNode {
public:
typedef std::vector<PycRef<ASTNode>> values_t;
ASTConstMap(PycRef<ASTNode> keys, const values_t& values)
: ASTNode(NODE_CONST_MAP), m_keys(std::move(keys)), m_values(std::move(values)) { }
const PycRef<ASTNode>& keys() const { return m_keys; }
const values_t& values() const { return m_values; }
private:
PycRef<ASTNode> m_keys;
values_t m_values;
};
class ASTSubscr : public ASTNode {
public:
ASTSubscr(PycRef<ASTNode> name, PycRef<ASTNode> key)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_SUBSCR), m_name(std::move(name)), m_key(std::move(key)) { }
PycRef<ASTNode> name() const { return m_name; }
PycRef<ASTNode> key() const { return m_key; }
private:
PycRef<ASTNode> m_name;
PycRef<ASTNode> m_key;
};
class ASTPrint : public ASTNode {
public:
typedef std::list<PycRef<ASTNode>> values_t;
2019-10-08 13:34:15 -07:00
ASTPrint(PycRef<ASTNode> value, PycRef<ASTNode> stream = {})
: ASTNode(NODE_PRINT), m_stream(std::move(stream)), m_eol()
{
if (value != nullptr)
m_values.emplace_back(std::move(value));
else
m_eol = true;
}
values_t values() const { return m_values; }
PycRef<ASTNode> stream() const { return m_stream; }
bool eol() const { return m_eol; }
void add(PycRef<ASTNode> value) { m_values.emplace_back(std::move(value)); }
void setEol(bool eol) { m_eol = eol; }
private:
values_t m_values;
PycRef<ASTNode> m_stream;
bool m_eol;
};
class ASTConvert : public ASTNode {
public:
ASTConvert(PycRef<ASTNode> name)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_CONVERT), m_name(std::move(name)) { }
PycRef<ASTNode> name() const { return m_name; }
private:
PycRef<ASTNode> m_name;
};
class ASTKeyword : public ASTNode {
public:
enum Word {
KW_PASS, KW_BREAK, KW_CONTINUE
};
ASTKeyword(Word key) : ASTNode(NODE_KEYWORD), m_key(key) { }
Word key() const { return m_key; }
const char* word_str() const;
private:
Word m_key;
};
class ASTRaise : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<PycRef<ASTNode>> param_t;
2019-10-08 13:34:15 -07:00
ASTRaise(param_t params) : ASTNode(NODE_RAISE), m_params(std::move(params)) { }
const param_t& params() const { return m_params; }
private:
param_t m_params;
};
2011-01-10 13:15:56 -08:00
class ASTExec : public ASTNode {
public:
ASTExec(PycRef<ASTNode> stmt, PycRef<ASTNode> glob, PycRef<ASTNode> loc)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_EXEC), m_stmt(std::move(stmt)), m_glob(std::move(glob)),
m_loc(std::move(loc)) { }
2011-01-10 13:15:56 -08:00
PycRef<ASTNode> statement() const { return m_stmt; }
PycRef<ASTNode> globals() const { return m_glob; }
PycRef<ASTNode> locals() const { return m_loc; }
private:
PycRef<ASTNode> m_stmt;
PycRef<ASTNode> m_glob;
PycRef<ASTNode> m_loc;
};
2010-12-20 22:58:44 -08:00
class ASTBlock : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<PycRef<ASTNode>> list_t;
2010-12-20 22:58:44 -08:00
enum BlkType {
2012-06-03 20:39:45 -07:00
BLK_MAIN, BLK_IF, BLK_ELSE, BLK_ELIF, BLK_TRY,
BLK_CONTAINER, BLK_EXCEPT, BLK_FINALLY,
BLK_WHILE, BLK_FOR, BLK_WITH, BLK_ASYNCFOR
2010-12-20 22:58:44 -08:00
};
2011-01-02 02:51:23 -08:00
ASTBlock(BlkType blktype, int end = 0, int inited = 0)
: ASTNode(NODE_BLOCK), m_blktype(blktype), m_end(end), m_inited(inited) { }
2010-12-20 22:58:44 -08:00
BlkType blktype() const { return m_blktype; }
2010-12-24 23:34:05 -08:00
int end() const { return m_end; }
2010-12-20 22:58:44 -08:00
const list_t& nodes() const { return m_nodes; }
list_t::size_type size() const { return m_nodes.size(); }
2010-12-20 22:58:44 -08:00
void removeFirst();
void removeLast();
2019-10-08 13:34:15 -07:00
void append(PycRef<ASTNode> node) { m_nodes.emplace_back(std::move(node)); }
2010-12-20 22:58:44 -08:00
const char* type_str() const;
2011-01-02 02:51:23 -08:00
virtual int inited() const { return m_inited; }
virtual void init() { m_inited = 1; }
virtual void init(int init) { m_inited = init; }
void setEnd(int end) { m_end = end; }
2010-12-20 22:58:44 -08:00
private:
BlkType m_blktype;
2010-12-24 23:34:05 -08:00
int m_end;
2010-12-20 22:58:44 -08:00
list_t m_nodes;
2011-01-02 02:51:23 -08:00
protected:
int m_inited; /* Is the block's definition "complete" */
2010-12-20 22:58:44 -08:00
};
class ASTCondBlock : public ASTBlock {
public:
2011-01-02 02:51:23 -08:00
enum InitCond {
UNINITED, POPPED, PRE_POPPED
};
2019-10-08 13:34:15 -07:00
ASTCondBlock(ASTBlock::BlkType blktype, int end, PycRef<ASTNode> cond,
bool negative = false)
: ASTBlock(blktype, end), m_cond(std::move(cond)), m_negative(negative) { }
PycRef<ASTNode> cond() const { return m_cond; }
bool negative() const { return m_negative; }
private:
PycRef<ASTNode> m_cond;
bool m_negative;
};
class ASTIterBlock : public ASTBlock {
public:
2022-07-08 17:53:39 -05:00
ASTIterBlock(ASTBlock::BlkType blktype, int start, int end, PycRef<ASTNode> iter)
: ASTBlock(blktype, end), m_iter(std::move(iter)), m_idx(), m_comp(), m_start(start) { }
PycRef<ASTNode> iter() const { return m_iter; }
PycRef<ASTNode> index() const { return m_idx; }
PycRef<ASTNode> condition() const { return m_cond; }
2011-10-10 15:57:20 -07:00
bool isComprehension() const { return m_comp; }
2022-07-08 17:53:39 -05:00
int start() const { return m_start; }
2019-10-08 13:34:15 -07:00
void setIndex(PycRef<ASTNode> idx) { m_idx = std::move(idx); init(); }
void setCondition(PycRef<ASTNode> cond) { m_cond = std::move(cond); }
2011-10-10 15:57:20 -07:00
void setComprehension(bool comp) { m_comp = comp; }
private:
PycRef<ASTNode> m_iter;
PycRef<ASTNode> m_idx;
PycRef<ASTNode> m_cond;
2011-10-10 15:57:20 -07:00
bool m_comp;
2022-07-08 17:53:39 -05:00
int m_start;
};
class ASTContainerBlock : public ASTBlock {
public:
2011-10-09 01:47:20 -07:00
ASTContainerBlock(int finally, int except = 0)
: ASTBlock(ASTBlock::BLK_CONTAINER, 0), m_finally(finally), m_except(except) { }
bool hasFinally() const { return m_finally != 0; }
bool hasExcept() const { return m_except != 0; }
2011-10-09 01:47:20 -07:00
int finally() const { return m_finally; }
int except() const { return m_except; }
2011-10-09 01:47:20 -07:00
void setExcept(int except) { m_except = except; }
private:
2011-10-09 01:47:20 -07:00
int m_finally;
int m_except;
};
2012-06-03 20:39:45 -07:00
class ASTWithBlock : public ASTBlock {
public:
ASTWithBlock(int end)
: ASTBlock(ASTBlock::BLK_WITH, end) { }
PycRef<ASTNode> expr() const { return m_expr; }
PycRef<ASTNode> var() const { return m_var; }
2019-10-08 13:34:15 -07:00
void setExpr(PycRef<ASTNode> expr) { m_expr = std::move(expr); init(); }
void setVar(PycRef<ASTNode> var) { m_var = std::move(var); }
2012-06-03 20:39:45 -07:00
private:
PycRef<ASTNode> m_expr;
PycRef<ASTNode> m_var; // optional value
};
2011-10-10 15:57:20 -07:00
class ASTComprehension : public ASTNode {
public:
2019-10-08 13:34:15 -07:00
typedef std::list<PycRef<ASTIterBlock>> generator_t;
2011-10-10 15:57:20 -07:00
ASTComprehension(PycRef<ASTNode> result)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_COMPREHENSION), m_result(std::move(result)) { }
2011-10-10 15:57:20 -07:00
PycRef<ASTNode> result() const { return m_result; }
generator_t generators() const { return m_generators; }
void addGenerator(PycRef<ASTIterBlock> gen) {
2019-10-08 13:34:15 -07:00
m_generators.emplace_front(std::move(gen));
2011-10-10 15:57:20 -07:00
}
private:
PycRef<ASTNode> m_result;
generator_t m_generators;
};
class ASTLoadBuildClass : public ASTNode {
public:
ASTLoadBuildClass(PycRef<PycObject> obj)
2019-10-08 13:34:15 -07:00
: ASTNode(NODE_LOADBUILDCLASS), m_obj(std::move(obj)) { }
PycRef<PycObject> object() const { return m_obj; }
private:
PycRef<PycObject> m_obj;
};
class ASTAwaitable : public ASTNode {
public:
ASTAwaitable(PycRef<ASTNode> expr)
: ASTNode(NODE_AWAITABLE), m_expr(std::move(expr)) { }
PycRef<ASTNode> expression() const { return m_expr; }
private:
PycRef<ASTNode> m_expr;
};
class ASTFormattedValue : public ASTNode {
public:
enum ConversionFlag {
2020-10-20 21:08:02 -07:00
NONE = 0,
STR = 1,
REPR = 2,
ASCII = 3,
FMTSPEC = 4
};
2020-10-17 21:04:39 +11:00
2020-10-20 21:08:02 -07:00
ASTFormattedValue(PycRef<ASTNode> val, ConversionFlag conversion,
PycRef<ASTNode> format_spec)
: ASTNode(NODE_FORMATTEDVALUE),
2020-10-20 21:08:02 -07:00
m_val(std::move(val)),
m_conversion(conversion),
m_format_spec(std::move(format_spec))
{ }
PycRef<ASTNode> val() const { return m_val; }
ConversionFlag conversion() const { return m_conversion; }
PycRef<ASTNode> format_spec() const { return m_format_spec; }
private:
PycRef<ASTNode> m_val;
ConversionFlag m_conversion;
PycRef<ASTNode> m_format_spec;
};
// Same as ASTList
class ASTJoinedStr : public ASTNode {
public:
typedef std::list<PycRef<ASTNode>> value_t;
ASTJoinedStr(value_t values)
: ASTNode(NODE_JOINEDSTR), m_values(std::move(values)) { }
const value_t& values() const { return m_values; }
private:
value_t m_values;
};
class ASTAnnotatedVar : public ASTNode {
public:
ASTAnnotatedVar(PycRef<ASTNode> name, PycRef<ASTNode> type)
: ASTNode(NODE_ANNOTATED_VAR), m_name(std::move(name)), m_type(std::move(type)) { }
PycRef<ASTNode> name() const noexcept { return m_name; }
PycRef<ASTNode> annotation() const noexcept { return m_type; }
private:
PycRef<ASTNode> m_name;
PycRef<ASTNode> m_type;
};
class ASTTernary : public ASTNode
{
public:
ASTTernary(PycRef<ASTNode> if_block, PycRef<ASTNode> if_expr,
PycRef<ASTNode> else_expr)
: ASTNode(NODE_TERNARY), m_if_block(std::move(if_block)),
m_if_expr(std::move(if_expr)), m_else_expr(std::move(else_expr)) { }
PycRef<ASTNode> if_block() const noexcept { return m_if_block; }
PycRef<ASTNode> if_expr() const noexcept { return m_if_expr; }
PycRef<ASTNode> else_expr() const noexcept { return m_else_expr; }
private:
PycRef<ASTNode> m_if_block; // contains "condition" and "negative"
PycRef<ASTNode> m_if_expr;
PycRef<ASTNode> m_else_expr;
};
2009-07-26 10:07:13 +00:00
#endif