got rid of double-free conditions and segfault
This commit is contained in:
15
yab2cpp.h
15
yab2cpp.h
@@ -312,8 +312,7 @@ public:
|
||||
virtual void close();
|
||||
|
||||
explicit ifStatement(expression *e);
|
||||
virtual ~ifStatement()
|
||||
{}
|
||||
virtual ~ifStatement();
|
||||
};
|
||||
|
||||
/* looping constructs */
|
||||
@@ -326,8 +325,7 @@ public:
|
||||
virtual void close(expression *e);
|
||||
|
||||
explicit repeatLoop();
|
||||
virtual ~repeatLoop()
|
||||
{}
|
||||
virtual ~repeatLoop();
|
||||
};
|
||||
|
||||
class doLoop:public codeType
|
||||
@@ -339,8 +337,7 @@ public:
|
||||
virtual void close();
|
||||
|
||||
explicit doLoop();
|
||||
virtual ~doLoop()
|
||||
{}
|
||||
virtual ~doLoop();
|
||||
};
|
||||
|
||||
class whileLoop:public codeType
|
||||
@@ -354,8 +351,7 @@ public:
|
||||
virtual void close();
|
||||
|
||||
explicit whileLoop(expression *e);
|
||||
virtual ~whileLoop()
|
||||
{}
|
||||
virtual ~whileLoop();
|
||||
};
|
||||
|
||||
class variableType:public operands
|
||||
@@ -401,8 +397,7 @@ public:
|
||||
|
||||
explicit forLoop(variableType *v, expression *start, expression *stop,
|
||||
expression *stepVal=nullptr);
|
||||
virtual ~forLoop()
|
||||
{}
|
||||
virtual ~forLoop();
|
||||
};
|
||||
|
||||
class fn:codeType
|
||||
|
||||
@@ -140,6 +140,7 @@ void ifStatement::alternative(expression *e)
|
||||
{
|
||||
done->generateJumpTo();
|
||||
this->chain->generate();
|
||||
delete this->chain;
|
||||
this->chain=nullptr;
|
||||
if(e!=nullptr)
|
||||
{
|
||||
@@ -156,6 +157,12 @@ void ifStatement::close()
|
||||
this->done->generate();
|
||||
}
|
||||
|
||||
ifStatement::~ifStatement()
|
||||
{
|
||||
delete this->redo;
|
||||
delete this->done;
|
||||
}
|
||||
|
||||
/* Loop definitions */
|
||||
repeatLoop::repeatLoop():codeType(T_REPEATLOOP)
|
||||
{
|
||||
@@ -176,6 +183,12 @@ void repeatLoop::close(expression *e)
|
||||
loopEnd->generate();
|
||||
}
|
||||
|
||||
repeatLoop::~repeatLoop()
|
||||
{
|
||||
delete loopStart;
|
||||
delete loopEnd;
|
||||
}
|
||||
|
||||
doLoop::doLoop():codeType(T_DOLOOP)
|
||||
{
|
||||
this->loopStart=new label();
|
||||
@@ -194,6 +207,12 @@ void doLoop::close()
|
||||
this->loopEnd->generate();
|
||||
}
|
||||
|
||||
doLoop::~doLoop()
|
||||
{
|
||||
delete loopStart;
|
||||
delete loopEnd;
|
||||
}
|
||||
|
||||
whileLoop::whileLoop(expression *e):codeType(T_WHILELOOP)
|
||||
{
|
||||
loopContinue=new label();
|
||||
@@ -216,6 +235,14 @@ void whileLoop::close()
|
||||
loopEnd->generate();
|
||||
}
|
||||
|
||||
whileLoop::~whileLoop()
|
||||
{
|
||||
delete loopContinue;
|
||||
delete loopStart;
|
||||
delete loopEnd;
|
||||
}
|
||||
|
||||
|
||||
forLoop::forLoop(variableType *v, expression *start, expression *stop,
|
||||
expression *stepVal):codeType(T_FORLOOP)
|
||||
{
|
||||
@@ -267,3 +294,10 @@ void forLoop::close()
|
||||
var->assignment(stepper);
|
||||
infrastructure->close();
|
||||
}
|
||||
|
||||
forLoop::~forLoop()
|
||||
{
|
||||
delete startTemp;
|
||||
delete stopTemp;
|
||||
delete infrastructure;
|
||||
}
|
||||
|
||||
@@ -448,8 +448,11 @@ operands *expression::evaluate()
|
||||
this->oper=O_TERM;
|
||||
l->dispose();
|
||||
delete left;
|
||||
r->dispose();
|
||||
delete right;
|
||||
if (getRight()!=nullptr)
|
||||
{
|
||||
r->dispose();
|
||||
delete right;
|
||||
}
|
||||
return this->op;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user