Close all memory leaks.
This commit is contained in:
parent
67e5d3a4be
commit
84199887a7
14
Monicelli.y
14
Monicelli.y
|
@ -6,6 +6,9 @@ extern int yylex();
|
|||
|
||||
#include "Nodes.hpp"
|
||||
|
||||
// For free()
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace monicelli;
|
||||
|
||||
extern Program *program;
|
||||
|
@ -128,6 +131,7 @@ fun_decl:
|
|||
$$ = new Function(new Id($2), paramsStack.top(), stmtStack.top());
|
||||
paramsStack.pop();
|
||||
stmtStack.pop();
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
args:
|
||||
|
@ -189,7 +193,14 @@ numeric:
|
|||
NUMBER { $$ = new Integer($1); } | FLOAT { $$ = new Float($1); }
|
||||
;
|
||||
variable:
|
||||
ID { $$ = new Id($1); } | ARTICLE ID { $$ = new Id($2); }
|
||||
ID {
|
||||
$$ = new Id($1);
|
||||
free($1);
|
||||
}
|
||||
| ARTICLE ID {
|
||||
$$ = new Id($2);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
assign_stmt:
|
||||
variable ASSIGN expression {
|
||||
|
@ -262,6 +273,7 @@ fun_call:
|
|||
ID call_args FUN_END {
|
||||
$$ = new FunctionCall(new Id($3), argsStack.top());
|
||||
argsStack.pop();
|
||||
free($3);
|
||||
}
|
||||
;
|
||||
call_args:
|
||||
|
|
20
Nodes.hpp
20
Nodes.hpp
|
@ -23,19 +23,31 @@ public:
|
|||
|
||||
|
||||
class Statement: public Emittable {
|
||||
public:
|
||||
virtual ~Statement() {}
|
||||
};
|
||||
|
||||
|
||||
class SemiExpression: public Emittable {
|
||||
public:
|
||||
virtual ~SemiExpression() {}
|
||||
};
|
||||
|
||||
|
||||
class Expression: public Emittable {
|
||||
public:
|
||||
virtual ~Expression() {}
|
||||
};
|
||||
|
||||
|
||||
class StatementList: public std::vector<Statement*>, public Emittable {
|
||||
public:
|
||||
virtual ~StatementList() {
|
||||
for (Statement *s: *this) {
|
||||
delete s;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void emit(std::ostream &stream, int indent = 0);
|
||||
};
|
||||
|
||||
|
@ -55,6 +67,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual ~ListEmittable() {
|
||||
for (T e: *this) {
|
||||
delete e;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual std::string getSeparator() const {
|
||||
return ", ";
|
||||
|
@ -73,6 +91,8 @@ class SimpleExpression: public Expression {
|
|||
class Id: public SimpleExpression {
|
||||
public:
|
||||
explicit Id(const char *c): value(c) {}
|
||||
virtual ~Id() {}
|
||||
|
||||
virtual void emit(std::ostream &stream, int indent = 0);
|
||||
|
||||
private:
|
||||
|
|
Reference in New Issue
Block a user