Files
int2ssl/Node.cpp
T

124 lines
2.7 KiB
C++
Raw Normal View History

2015-02-13 16:59:11 +03:00
#include "stdafx.h"
#include "Node.h"
2015-02-15 16:16:45 +03:00
#include "Utility.h"
2015-02-13 16:59:11 +03:00
CNode::CNode(Type type) :
2015-02-14 13:39:47 +03:00
m_ulOffset(0),
m_Type(type)
2015-02-13 16:59:11 +03:00
{
}
CNode::CNode(const CNode& node) :
2015-02-14 13:39:47 +03:00
m_ulOffset(node.m_ulOffset),
m_Opcode(node.m_Opcode),
m_Type(node.m_Type)
2015-02-13 16:59:11 +03:00
{
2015-02-14 13:39:47 +03:00
m_Arguments.Copy(node.m_Arguments);
2015-02-13 16:59:11 +03:00
}
CNode::~CNode()
{
}
CNode& CNode::operator = (const CNode& node)
{
2015-02-14 14:38:14 +03:00
if (&node != this)
{
2015-02-14 13:39:47 +03:00
m_ulOffset = node.m_ulOffset;
m_Opcode = node.m_Opcode;
m_Type = node.m_Type;
m_Arguments.Copy(node.m_Arguments);
}
return (*this);
2015-02-13 16:59:11 +03:00
}
void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
{
2015-02-14 13:39:47 +03:00
// Indent
2015-02-14 14:38:14 +03:00
if (nIndex != 0)
{
2015-02-14 13:39:47 +03:00
ar.WriteString(" ");
2015-02-13 16:59:11 +03:00
2015-02-14 14:38:14 +03:00
for(int i = 0; i < nIndent; i++)
{
2015-02-14 13:39:47 +03:00
ar.WriteString(" ");
}
}
2015-02-13 16:59:11 +03:00
2015-02-14 14:38:14 +03:00
switch(m_Type)
{
2015-02-14 13:39:47 +03:00
case TYPE_BEGIN_OF_BLOCK:
ar.WriteString("========= begin of block =========\n");
return;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
case TYPE_END_OF_BLOCK:
ar.WriteString("========= end of block =========\n");
return;
}
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
// Node
2015-02-15 16:16:45 +03:00
std::string strOutLine;
2015-02-15 18:10:01 +03:00
uint16_t wOperator = m_Opcode.GetOperator();
2015-02-15 18:28:27 +03:00
uint32_t ulArgument = m_Opcode.GetArgument();
2015-02-13 16:59:11 +03:00
2015-02-14 14:38:14 +03:00
switch(wOperator)
{
2015-02-14 13:39:47 +03:00
case COpcode::O_STRINGOP:
case COpcode::O_INTOP:
2015-02-15 16:16:45 +03:00
strOutLine = format("0x%04X 0x%08x ",
2015-02-14 13:39:47 +03:00
wOperator,
ulArgument);
ar.WriteString(strOutLine);
break;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
case COpcode::O_FLOATOP:
2015-02-15 16:16:45 +03:00
strOutLine = format("0x%04X 0x%08X ",
2015-02-14 13:39:47 +03:00
wOperator,
ulArgument);
ar.WriteString(strOutLine);
break;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
default:
2015-02-15 16:16:45 +03:00
strOutLine = format("0x%04X .......... ",
2015-02-14 13:39:47 +03:00
wOperator);
ar.WriteString(strOutLine);
}
2015-02-14 14:38:14 +03:00
if (!m_Arguments.IsEmpty())
{
for(int i = 0; i < m_Arguments.GetSize(); i++)
{
2015-02-14 23:18:15 +03:00
m_Arguments[i].StoreTree(ar, nIndent + 1, i);
2015-02-14 13:39:47 +03:00
}
}
2015-02-14 14:38:14 +03:00
else
{
2015-02-14 13:39:47 +03:00
ar.WriteString("\n");
}
2015-02-13 16:59:11 +03:00
}
2015-02-15 18:28:27 +03:00
uint32_t CNode::GetTopOffset()
2015-02-13 16:59:11 +03:00
{
2015-02-14 13:39:47 +03:00
if (m_Arguments.GetSize() > 0)
2015-02-14 14:38:14 +03:00
{
2015-02-14 23:18:15 +03:00
return m_Arguments[0].GetTopOffset();
2015-02-14 14:38:14 +03:00
}
2015-02-14 13:39:47 +03:00
else
2015-02-14 14:38:14 +03:00
{
2015-02-14 13:39:47 +03:00
return m_ulOffset;
2015-02-14 14:38:14 +03:00
}
2015-02-13 16:59:11 +03:00
}
bool CNode::IsExpression() const
{
2015-02-14 13:39:47 +03:00
return (m_Opcode.GetAttributes().m_Type == COpcode::COpcodeAttributes::TYPE_EXPRESSION
|| m_Type == TYPE_CONDITIONAL_EXPRESSION);
2015-02-13 16:59:11 +03:00
}
bool CNode::IsInfix() const
{
2015-02-14 13:39:47 +03:00
return (m_Opcode.GetAttributes().m_Category == COpcode::COpcodeAttributes::CATEGORY_INFIX
|| m_Type == TYPE_CONDITIONAL_EXPRESSION);
2015-02-13 16:59:11 +03:00
}