Getting rid of last C leftovers.

This commit is contained in:
Stefano Sanfilippo 2014-11-28 00:01:24 +01:00
parent 84199887a7
commit 3facc1c9d4
4 changed files with 8 additions and 14 deletions

View File

@ -1,7 +1,8 @@
%{ %{
#include "Monicelli.tab.h" #include "Monicelli.tab.h"
#include <stdlib.h>
#include <stdio.h> #include <string>
#include <cstdlib>
extern int lineNumber; extern int lineNumber;
@ -163,7 +164,7 @@ CHAR [a-zA-Z_]
<INITIAL,shift>[ \t\f\v] {} <INITIAL,shift>[ \t\f\v] {}
{CHAR}({DIGIT}|{CHAR})* { {CHAR}({DIGIT}|{CHAR})* {
mclval.strval = strdup(yytext); mclval.strval = new std::string(yytext);
return ID; return ID;
} }

View File

@ -6,9 +6,6 @@ extern int yylex();
#include "Nodes.hpp" #include "Nodes.hpp"
// For free()
#include <cstdlib>
using namespace monicelli; using namespace monicelli;
extern Program *program; extern Program *program;
@ -53,7 +50,7 @@ static std::stack<BranchCaseList*> branchCaseStack;
%union { %union {
int intval; int intval;
double floatval; double floatval;
char *strval; std::string* strval;
bool boolval; bool boolval;
monicelli::Type typeval; monicelli::Type typeval;
monicelli::Statement* statementval; monicelli::Statement* statementval;
@ -131,7 +128,6 @@ fun_decl:
$$ = new Function(new Id($2), paramsStack.top(), stmtStack.top()); $$ = new Function(new Id($2), paramsStack.top(), stmtStack.top());
paramsStack.pop(); paramsStack.pop();
stmtStack.pop(); stmtStack.pop();
free($2);
} }
; ;
args: args:
@ -195,11 +191,9 @@ numeric:
variable: variable:
ID { ID {
$$ = new Id($1); $$ = new Id($1);
free($1);
} }
| ARTICLE ID { | ARTICLE ID {
$$ = new Id($2); $$ = new Id($2);
free($2);
} }
; ;
assign_stmt: assign_stmt:
@ -273,7 +267,6 @@ fun_call:
ID call_args FUN_END { ID call_args FUN_END {
$$ = new FunctionCall(new Id($3), argsStack.top()); $$ = new FunctionCall(new Id($3), argsStack.top());
argsStack.pop(); argsStack.pop();
free($3);
} }
; ;
call_args: call_args:

View File

@ -11,7 +11,7 @@ void emitIndent(std::ostream &stream, int indent) {
} }
void Id::emit(std::ostream &stream, int indent) { void Id::emit(std::ostream &stream, int indent) {
stream << value; stream << *value;
} }
void Integer::emit(std::ostream &stream, int indent) { void Integer::emit(std::ostream &stream, int indent) {

View File

@ -90,13 +90,13 @@ class SimpleExpression: public Expression {
class Id: public SimpleExpression { class Id: public SimpleExpression {
public: public:
explicit Id(const char *c): value(c) {} explicit Id(std::string *c): value(c) {}
virtual ~Id() {} virtual ~Id() {}
virtual void emit(std::ostream &stream, int indent = 0); virtual void emit(std::ostream &stream, int indent = 0);
private: private:
std::string value; std::unique_ptr<std::string> value;
}; };