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

56 lines
1.0 KiB
C
Raw Normal View History

2009-07-26 10:07:13 +00:00
#ifndef _PYC_FASTSTACK_H
#define _PYC_FASTSTACK_H
#include "ASTNode.h"
#include <stack>
class FastStack {
public:
FastStack(int size) : m_ptr(-1) { m_stack.resize(size); }
2010-12-30 16:48:59 -08:00
FastStack(const FastStack& copy)
: m_stack(copy.m_stack), m_ptr(copy.m_ptr) { }
2009-07-26 10:07:13 +00:00
FastStack& operator=(const FastStack& copy)
{
m_stack = copy.m_stack;
m_ptr = copy.m_ptr;
return *this;
}
void push(PycRef<ASTNode> node)
{
if (static_cast<int>(m_stack.size()) == m_ptr + 1)
m_stack.emplace_back(nullptr);
2011-09-18 23:55:27 -07:00
m_stack[++m_ptr] = std::move(node);
2010-12-30 16:48:59 -08:00
}
2009-07-26 10:07:13 +00:00
void pop()
{
2010-12-30 16:48:59 -08:00
if (m_ptr > -1)
m_stack[m_ptr--] = nullptr;
2010-12-30 16:48:59 -08:00
}
2009-07-26 10:07:13 +00:00
PycRef<ASTNode> top() const
2010-12-18 22:18:32 -08:00
{
if (m_ptr > -1)
return m_stack[m_ptr];
else
return nullptr;
}
bool empty() const
{
return m_ptr == -1;
}
2009-07-26 10:07:13 +00:00
private:
std::vector<PycRef<ASTNode>> m_stack;
int m_ptr;
2009-07-26 10:07:13 +00:00
};
typedef std::stack<FastStack> stackhist_t;
#endif