Fix for old python versions
This commit is contained in:
30
code.h
30
code.h
@@ -21,39 +21,39 @@ public:
|
||||
int stackSize() const { return m_stackSize; }
|
||||
int flags() const { return m_flags; }
|
||||
PycRef<PycString> code() const { return m_code; }
|
||||
PycRef<PycTuple> consts() const { return m_consts; }
|
||||
PycRef<PycTuple> names() const { return m_names; }
|
||||
PycRef<PycTuple> varNames() const { return m_varNames; }
|
||||
PycRef<PycTuple> freeVars() const { return m_freeVars; }
|
||||
PycRef<PycTuple> cellVars() const { return m_cellVars; }
|
||||
PycRef<PycSequence> consts() const { return m_consts; }
|
||||
PycRef<PycSequence> names() const { return m_names; }
|
||||
PycRef<PycSequence> varNames() const { return m_varNames; }
|
||||
PycRef<PycSequence> freeVars() const { return m_freeVars; }
|
||||
PycRef<PycSequence> cellVars() const { return m_cellVars; }
|
||||
PycRef<PycString> fileName() const { return m_fileName; }
|
||||
PycRef<PycString> name() const { return m_name; }
|
||||
int firstLine() const { return m_firstLine; }
|
||||
PycRef<PycString> lnTable() const { return m_lnTable; }
|
||||
|
||||
PycRef<PycObject> getConst(int idx) const
|
||||
{ return m_consts->values()[idx]; }
|
||||
{ return m_consts->get(idx); }
|
||||
|
||||
PycRef<PycString> getName(int idx) const
|
||||
{ return m_names->values()[idx].cast<PycString>(); }
|
||||
{ return m_names->get(idx).cast<PycString>(); }
|
||||
|
||||
PycRef<PycString> getVarName(int idx) const
|
||||
{ return m_varNames->values()[idx].cast<PycString>(); }
|
||||
{ return m_varNames->get(idx).cast<PycString>(); }
|
||||
|
||||
PycRef<PycObject> getCellVar(int idx) const
|
||||
{
|
||||
return (idx > m_cellVars->size()) ? m_freeVars->values()[idx - m_cellVars->size()]
|
||||
: m_cellVars->values()[idx];
|
||||
return (idx > m_cellVars->size()) ? m_freeVars->get(idx - m_cellVars->size())
|
||||
: m_cellVars->get(idx);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_argCount, m_kwOnlyArgCount, m_numLocals, m_stackSize, m_flags;
|
||||
PycRef<PycString> m_code;
|
||||
PycRef<PycTuple> m_consts;
|
||||
PycRef<PycTuple> m_names;
|
||||
PycRef<PycTuple> m_varNames;
|
||||
PycRef<PycTuple> m_freeVars;
|
||||
PycRef<PycTuple> m_cellVars;
|
||||
PycRef<PycSequence> m_consts;
|
||||
PycRef<PycSequence> m_names;
|
||||
PycRef<PycSequence> m_varNames;
|
||||
PycRef<PycSequence> m_freeVars;
|
||||
PycRef<PycSequence> m_cellVars;
|
||||
PycRef<PycString> m_fileName;
|
||||
PycRef<PycString> m_name;
|
||||
int m_firstLine;
|
||||
|
25
pycdas.cpp
25
pycdas.cpp
@@ -34,29 +34,24 @@ void output_object(PycRef<PycObject> obj, PycModule* mod, int indent)
|
||||
iprintf(indent + 1, "Flags: 0x%08X\n", codeObj->flags());
|
||||
|
||||
iprintf(indent + 1, "[Names]\n");
|
||||
PycTuple::value_t names = codeObj->names()->values();
|
||||
for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++)
|
||||
output_object(*i, mod, indent + 2);
|
||||
for (int i=0; i<codeObj->names()->size(); i++)
|
||||
output_object(codeObj->names()->get(i), mod, indent + 2);
|
||||
|
||||
iprintf(indent + 1, "[Var Names]\n");
|
||||
names = codeObj->varNames()->values();
|
||||
for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++)
|
||||
output_object(*i, mod, indent + 2);
|
||||
for (int i=0; i<codeObj->varNames()->size(); i++)
|
||||
output_object(codeObj->varNames()->get(i), mod, indent + 2);
|
||||
|
||||
iprintf(indent + 1, "[Free Vars]\n");
|
||||
names = codeObj->freeVars()->values();
|
||||
for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++)
|
||||
output_object(*i, mod, indent + 2);
|
||||
for (int i=0; i<codeObj->freeVars()->size(); i++)
|
||||
output_object(codeObj->freeVars()->get(i), mod, indent + 2);
|
||||
|
||||
iprintf(indent + 1, "[Cell Vars]\n");
|
||||
names = codeObj->cellVars()->values();
|
||||
for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++)
|
||||
output_object(*i, mod, indent + 2);
|
||||
for (int i=0; i<codeObj->cellVars()->size(); i++)
|
||||
output_object(codeObj->cellVars()->get(i), mod, indent + 2);
|
||||
|
||||
iprintf(indent + 1, "[Constants]\n");
|
||||
PycTuple::value_t consts = codeObj->consts()->values();
|
||||
for (PycTuple::value_t::iterator i = consts.begin(); i != consts.end(); i++)
|
||||
output_object(*i, mod, indent + 2);
|
||||
for (int i=0; i<codeObj->consts()->size(); i++)
|
||||
output_object(codeObj->consts()->get(i), mod, indent + 2);
|
||||
|
||||
iprintf(indent + 1, "[Disassembly]\n");
|
||||
bc_disasm(codeObj, mod, indent + 2);
|
||||
|
46
sequence.h
46
sequence.h
@@ -5,12 +5,22 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
class PycTuple : public PycObject {
|
||||
class PycSequence : public PycObject {
|
||||
public:
|
||||
PycSequence(int type) : PycObject(type), m_size(0) { }
|
||||
|
||||
int size() const { return m_size; }
|
||||
virtual PycRef<PycObject> get(int idx) const = 0;
|
||||
|
||||
protected:
|
||||
int m_size;
|
||||
};
|
||||
|
||||
class PycTuple : public PycSequence {
|
||||
public:
|
||||
typedef std::vector<PycRef<PycObject> > value_t;
|
||||
|
||||
PycTuple(int type = TYPE_TUPLE)
|
||||
: PycObject(type), m_size(0) { }
|
||||
PycTuple(int type = TYPE_TUPLE) : PycSequence(type) { }
|
||||
|
||||
bool isType(int type) const
|
||||
{ return (type == TYPE_TUPLE) || PycObject::isType(type); }
|
||||
@@ -19,20 +29,18 @@ public:
|
||||
|
||||
void load(class PycData* stream, class PycModule* mod);
|
||||
|
||||
int size() const { return m_size; }
|
||||
value_t values() const { return m_values; }
|
||||
PycRef<PycObject> get(int idx) const { return m_values[idx]; }
|
||||
|
||||
private:
|
||||
int m_size;
|
||||
value_t m_values;
|
||||
};
|
||||
|
||||
class PycList : public PycObject {
|
||||
class PycList : public PycSequence {
|
||||
public:
|
||||
typedef std::list<PycRef<PycObject> > value_t;
|
||||
|
||||
PycList(int type = TYPE_LIST)
|
||||
: PycObject(type), m_size(0) { }
|
||||
PycList(int type = TYPE_LIST) : PycSequence(type) { }
|
||||
|
||||
bool isType(int type) const
|
||||
{ return (type == TYPE_LIST) || PycObject::isType(type); }
|
||||
@@ -41,21 +49,24 @@ public:
|
||||
|
||||
void load(class PycData* stream, class PycModule* mod);
|
||||
|
||||
int size() const { return m_size; }
|
||||
value_t values() const { return m_values; }
|
||||
PycRef<PycObject> get(int idx) const
|
||||
{
|
||||
value_t::const_iterator it = m_values.begin();
|
||||
for (int i=0; i<idx; i++) ++it;
|
||||
return *it;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_size;
|
||||
value_t m_values;
|
||||
};
|
||||
|
||||
class PycDict : public PycObject {
|
||||
class PycDict : public PycSequence {
|
||||
public:
|
||||
typedef std::list<PycRef<PycObject> > key_t;
|
||||
typedef std::list<PycRef<PycObject> > value_t;
|
||||
|
||||
PycDict(int type = TYPE_DICT)
|
||||
: PycObject(type), m_size(0) { }
|
||||
PycDict(int type = TYPE_DICT) : PycSequence(type) { }
|
||||
|
||||
bool isType(int type) const
|
||||
{ return (type == TYPE_DICT) || PycObject::isType(type); }
|
||||
@@ -64,13 +75,18 @@ public:
|
||||
|
||||
void load(class PycData* stream, class PycModule* mod);
|
||||
|
||||
int size() const { return m_size; }
|
||||
PycRef<PycObject> get(PycRef<PycObject> key) const;
|
||||
key_t keys() const { return m_keys; }
|
||||
value_t values() const { return m_values; }
|
||||
|
||||
PycRef<PycObject> get(int idx) const
|
||||
{
|
||||
value_t::const_iterator it = m_values.begin();
|
||||
for (int i=0; i<idx; i++) ++it;
|
||||
return *it;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_size;
|
||||
key_t m_keys;
|
||||
value_t m_values;
|
||||
};
|
||||
|
Reference in New Issue
Block a user