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