Uh, Updates?
This commit is contained in:
@@ -107,7 +107,7 @@ Tile *Codegen_x86::genCompare( TNode *t,string &func,bool negate ){
|
||||
}
|
||||
}
|
||||
|
||||
return d_new Tile( q,ql ? munchReg( ql ) : 0,qr ? munchReg( qr ) : 0 );
|
||||
return new Tile( q,ql ? munchReg( ql ) : 0,qr ? munchReg( qr ) : 0 );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
@@ -119,7 +119,7 @@ Tile *Codegen_x86::munchUnary( TNode *t ){
|
||||
case IR_NEG:s="\tneg\t%l\n";break;
|
||||
default:return 0;
|
||||
}
|
||||
return d_new Tile( s,munchReg( t->l ) );
|
||||
return new Tile( s,munchReg( t->l ) );
|
||||
}
|
||||
|
||||
Tile *Codegen_x86::munchLogical( TNode *t ){
|
||||
@@ -130,7 +130,7 @@ Tile *Codegen_x86::munchLogical( TNode *t ){
|
||||
case IR_XOR:s="\txor\t%l,%r\n";break;
|
||||
default:return 0;
|
||||
}
|
||||
return d_new Tile( s,munchReg( t->l ),munchReg( t->r ) );
|
||||
return new Tile( s,munchReg( t->l ),munchReg( t->r ) );
|
||||
}
|
||||
|
||||
Tile *Codegen_x86::munchArith( TNode *t ){
|
||||
@@ -139,10 +139,10 @@ Tile *Codegen_x86::munchArith( TNode *t ){
|
||||
int shift;
|
||||
if( t->r->op==IR_CONST ){
|
||||
if( getShift( t->r->iconst,shift ) ){
|
||||
return d_new Tile( "\tsar\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
|
||||
return new Tile( "\tsar\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
|
||||
}
|
||||
}
|
||||
Tile *q=d_new Tile( "\tcdq\n\tidiv\tecx\n",munchReg( t->l ),munchReg( t->r ) );
|
||||
Tile *q=new Tile( "\tcdq\n\tidiv\tecx\n",munchReg( t->l ),munchReg( t->r ) );
|
||||
q->want_l=EAX;q->want_r=ECX;q->hits=1<<EDX;
|
||||
return q;
|
||||
}
|
||||
@@ -151,11 +151,11 @@ Tile *Codegen_x86::munchArith( TNode *t ){
|
||||
int shift;
|
||||
if( t->r->op==IR_CONST ){
|
||||
if( getShift( t->r->iconst,shift ) ){
|
||||
return d_new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
|
||||
return new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
|
||||
}
|
||||
}else if( t->l->op==IR_CONST ){
|
||||
if( getShift( t->l->iconst,shift ) ){
|
||||
return d_new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->r ) );
|
||||
return new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->r ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,12 +169,12 @@ Tile *Codegen_x86::munchArith( TNode *t ){
|
||||
}
|
||||
|
||||
if( matchMEMCONST( t->r,s ) ){
|
||||
return d_new Tile( op+"%l,"+s+"\n",munchReg( t->l ) );
|
||||
return new Tile( op+"%l,"+s+"\n",munchReg( t->l ) );
|
||||
}
|
||||
if( t->op!=IR_SUB && matchMEMCONST( t->l,s ) ){
|
||||
return d_new Tile( op+"%l,"+s+"\n",munchReg( t->r ) );
|
||||
return new Tile( op+"%l,"+s+"\n",munchReg( t->r ) );
|
||||
}
|
||||
return d_new Tile( op+"%l,%r\n",munchReg( t->l ),munchReg( t->r ) );
|
||||
return new Tile( op+"%l,%r\n",munchReg( t->l ),munchReg( t->r ) );
|
||||
}
|
||||
|
||||
Tile *Codegen_x86::munchShift( TNode *t ){
|
||||
@@ -187,10 +187,10 @@ Tile *Codegen_x86::munchShift( TNode *t ){
|
||||
}
|
||||
|
||||
if( matchCONST( t->r,s ) ){
|
||||
return d_new Tile( op+"%l,byte "+s+"\n",munchReg( t->l ) );
|
||||
return new Tile( op+"%l,byte "+s+"\n",munchReg( t->l ) );
|
||||
}
|
||||
|
||||
Tile *q=d_new Tile( op+"%l,cl\n",munchReg( t->l ),munchReg( t->r ) );
|
||||
Tile *q=new Tile( op+"%l,cl\n",munchReg( t->l ),munchReg( t->r ) );
|
||||
q->want_r=ECX;return q;
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ Tile *Codegen_x86::munchRelop( TNode *t ){
|
||||
string func;
|
||||
Tile *q=genCompare( t,func,false );
|
||||
|
||||
q=d_new Tile( "\tset"+func+"\tal\n\tmovzx\teax,al\n",q );
|
||||
q=new Tile( "\tset"+func+"\tal\n\tmovzx\teax,al\n",q );
|
||||
q->want_l=EAX;
|
||||
return q;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ Tile *Codegen_x86::munchFPUnary( TNode *t ){
|
||||
case IR_FNEG:s="\tfchs\n";break;
|
||||
default:return 0;
|
||||
}
|
||||
return d_new Tile( s,munchFP( t->l ) );
|
||||
return new Tile( s,munchFP( t->l ) );
|
||||
}
|
||||
|
||||
Tile *Codegen_x86::munchFPArith( TNode *t ){
|
||||
@@ -224,7 +224,7 @@ Tile *Codegen_x86::munchFPArith( TNode *t ){
|
||||
case IR_FDIV:s="\tfdivrp\tst(1)\n";s2="\tfdivp\tst(1)\n";break;
|
||||
default:return 0;
|
||||
}
|
||||
return d_new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
|
||||
return new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
|
||||
}
|
||||
|
||||
Tile *Codegen_x86::munchFPRelop( TNode *t ){
|
||||
@@ -240,7 +240,7 @@ Tile *Codegen_x86::munchFPRelop( TNode *t ){
|
||||
}
|
||||
s="\tfucompp\n\tfnstsw\tax\n\tsahf\n\tset"+s+"\tal\n\tmovzx\t%l,al\n";
|
||||
s2="\tfucompp\n\tfnstsw\tax\n\tsahf\n\tset"+s2+"\tal\n\tmovzx\t%l,al\n";
|
||||
Tile *q=d_new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
|
||||
Tile *q=new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
|
||||
q->want_l=EAX;
|
||||
return q;
|
||||
}
|
||||
@@ -251,9 +251,9 @@ Tile *Codegen_x86::munchFPRelop( TNode *t ){
|
||||
Tile *Codegen_x86::munchCall( TNode *t ){
|
||||
Tile *q;
|
||||
if( t->l->op==IR_GLOBAL ){
|
||||
q=d_new Tile( "\tcall\t"+t->l->sconst+"\n",t->r ? munchReg( t->r ) : 0 );
|
||||
q=new Tile( "\tcall\t"+t->l->sconst+"\n",t->r ? munchReg( t->r ) : 0 );
|
||||
}else{
|
||||
q=d_new Tile( "\tcall\t%l\n",munchReg( t->l ),t->r ? munchReg( t->r ) : 0 );
|
||||
q=new Tile( "\tcall\t%l\n",munchReg( t->l ),t->r ? munchReg( t->r ) : 0 );
|
||||
}
|
||||
q->argFrame=t->iconst;
|
||||
q->want_l=EAX;
|
||||
@@ -270,26 +270,26 @@ Tile *Codegen_x86::munch( TNode *t ){
|
||||
string s;
|
||||
switch( t->op ){
|
||||
case IR_JSR:
|
||||
q=d_new Tile( "\tcall\t"+t->sconst+'\n' );
|
||||
q=new Tile( "\tcall\t"+t->sconst+'\n' );
|
||||
break;
|
||||
case IR_RET:
|
||||
q=d_new Tile( "\tret\n" );
|
||||
q=new Tile( "\tret\n" );
|
||||
break;
|
||||
case IR_RETURN:
|
||||
q=munchReg( t->l );q->want_l=EAX;
|
||||
s="\tjmp\t"+t->sconst+'\n';
|
||||
q=d_new Tile( s,q );
|
||||
q=new Tile( s,q );
|
||||
break;
|
||||
case IR_FRETURN:
|
||||
q=munchFP( t->l );
|
||||
s="\tjmp\t"+t->sconst+'\n';
|
||||
q=d_new Tile( s,q );
|
||||
q=new Tile( s,q );
|
||||
break;
|
||||
case IR_CALL:
|
||||
q=munchCall( t );
|
||||
break;
|
||||
case IR_JUMP:
|
||||
q=d_new Tile( "\tjmp\t"+t->sconst+'\n' );
|
||||
q=new Tile( "\tjmp\t"+t->sconst+'\n' );
|
||||
break;
|
||||
case IR_JUMPT:
|
||||
if( TNode *p=t->l ){
|
||||
@@ -297,7 +297,7 @@ Tile *Codegen_x86::munch( TNode *t ){
|
||||
if( isRelop( p->op ) ){
|
||||
string func;
|
||||
q=genCompare( p,func,neg );
|
||||
q=d_new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
|
||||
q=new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -307,7 +307,7 @@ Tile *Codegen_x86::munch( TNode *t ){
|
||||
if( isRelop( p->op ) ){
|
||||
string func;
|
||||
q=genCompare( p,func,neg );
|
||||
q=d_new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
|
||||
q=new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -315,7 +315,7 @@ Tile *Codegen_x86::munch( TNode *t ){
|
||||
if( matchMEM( t->r,s ) ){
|
||||
string c;
|
||||
if( matchCONST( t->l,c ) ){
|
||||
q=d_new Tile( "\tmov\t"+s+","+c+"\n" );
|
||||
q=new Tile( "\tmov\t"+s+","+c+"\n" );
|
||||
}else if( t->l->op==IR_ADD || t->l->op==IR_SUB ){
|
||||
TNode *p=0;
|
||||
if( nodesEqual( t->l->l,t->r ) ) p=t->l->r;
|
||||
@@ -327,13 +327,13 @@ Tile *Codegen_x86::munch( TNode *t ){
|
||||
case IR_SUB:op="\tsub\t";break;
|
||||
}
|
||||
if( matchCONST( p,c ) ){
|
||||
q=d_new Tile( op+s+","+c+"\n" );
|
||||
q=new Tile( op+s+","+c+"\n" );
|
||||
}else{
|
||||
q=d_new Tile( op+s+",%l\n",munchReg( p ) );
|
||||
q=new Tile( op+s+",%l\n",munchReg( p ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( !q ) q=d_new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
|
||||
if( !q ) q=new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -352,13 +352,13 @@ Tile *Codegen_x86::munchReg( TNode *t ){
|
||||
|
||||
switch( t->op ){
|
||||
case IR_JUMPT:
|
||||
q=d_new Tile( "\tand\t%l,%l\n\tjnz\t"+t->sconst+'\n',munchReg( t->l ) );
|
||||
q=new Tile( "\tand\t%l,%l\n\tjnz\t"+t->sconst+'\n',munchReg( t->l ) );
|
||||
break;
|
||||
case IR_JUMPF:
|
||||
q=d_new Tile( "\tand\t%l,%l\n\tjz\t"+t->sconst+'\n',munchReg( t->l ) );
|
||||
q=new Tile( "\tand\t%l,%l\n\tjz\t"+t->sconst+'\n',munchReg( t->l ) );
|
||||
break;
|
||||
case IR_JUMPGE:
|
||||
q=d_new Tile( "\tcmp\t%l,%r\n\tjnc\t"+t->sconst+'\n',munchReg( t->l ),munchReg( t->r ) );
|
||||
q=new Tile( "\tcmp\t%l,%r\n\tjnc\t"+t->sconst+'\n',munchReg( t->l ),munchReg( t->r ) );
|
||||
break;
|
||||
case IR_CALL:
|
||||
q=munchCall( t );
|
||||
@@ -366,37 +366,37 @@ Tile *Codegen_x86::munchReg( TNode *t ){
|
||||
case IR_MOVE:
|
||||
//MUST BE MOVE TO MEM!
|
||||
if( matchMEM( t->r,s ) ){
|
||||
q=d_new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
|
||||
q=new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
|
||||
}else if( t->r->op==IR_MEM ){
|
||||
q=d_new Tile( "\tmov\t[%r],%l\n",munchReg( t->l ),munchReg( t->r->l ) );
|
||||
q=new Tile( "\tmov\t[%r],%l\n",munchReg( t->l ),munchReg( t->r->l ) );
|
||||
}
|
||||
break;
|
||||
case IR_MEM:
|
||||
if( matchMEM( t,s ) ){
|
||||
q=d_new Tile( "\tmov\t%l,"+s+"\n" );
|
||||
q=new Tile( "\tmov\t%l,"+s+"\n" );
|
||||
}else{
|
||||
q=d_new Tile( "\tmov\t%l,[%l]\n",munchReg( t->l ) );
|
||||
q=new Tile( "\tmov\t%l,[%l]\n",munchReg( t->l ) );
|
||||
}
|
||||
break;
|
||||
case IR_SEQ:
|
||||
q=d_new Tile( "",munch(t->l),munch(t->r) );
|
||||
q=new Tile( "",munch(t->l),munch(t->r) );
|
||||
break;
|
||||
case IR_ARG:
|
||||
q=d_new Tile( "\tlea\t%l,[esp"+itoa_sgn(t->iconst)+"]\n" );
|
||||
q=new Tile( "\tlea\t%l,[esp"+itoa_sgn(t->iconst)+"]\n" );
|
||||
break;
|
||||
case IR_LOCAL:
|
||||
q=d_new Tile( "\tlea\t%l,[ebp"+itoa_sgn(t->iconst)+"]\n" );
|
||||
q=new Tile( "\tlea\t%l,[ebp"+itoa_sgn(t->iconst)+"]\n" );
|
||||
break;
|
||||
case IR_GLOBAL:
|
||||
q=d_new Tile( string( "\tmov\t%l," )+t->sconst+'\n' );
|
||||
q=new Tile( string( "\tmov\t%l," )+t->sconst+'\n' );
|
||||
break;
|
||||
case IR_CAST:
|
||||
q=munchFP( t->l );
|
||||
s="\tpush\t%l\n\tfistp\t[esp]\n\tpop\t%l\n";
|
||||
q=d_new Tile( s,q );
|
||||
q=new Tile( s,q );
|
||||
break;
|
||||
case IR_CONST:
|
||||
q=d_new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" );
|
||||
q=new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" );
|
||||
break;
|
||||
case IR_NEG:
|
||||
q=munchUnary( t );
|
||||
@@ -419,7 +419,7 @@ Tile *Codegen_x86::munchReg( TNode *t ){
|
||||
default:
|
||||
q=munchFP( t );if( !q ) return 0;
|
||||
s="\tpush\t%l\n\tfstp\t[esp]\n\tpop\t%l\n";
|
||||
q=d_new Tile( s,q );
|
||||
q=new Tile( s,q );
|
||||
}
|
||||
return q;
|
||||
}
|
||||
@@ -439,7 +439,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){
|
||||
break;
|
||||
case IR_FCAST:
|
||||
s="\tpush\t%l\n\tfild\t[esp]\n\tpop\t%l\n";
|
||||
q=d_new Tile( s,munchReg( t->l ) );
|
||||
q=new Tile( s,munchReg( t->l ) );
|
||||
break;
|
||||
case IR_FNEG:
|
||||
q=munchFPUnary( t );
|
||||
@@ -450,7 +450,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){
|
||||
default:
|
||||
q=munchReg( t );if( !q ) return 0;
|
||||
s="\tpush\t%l\n\tfld\t[esp]\n\tpop\t%l\n";
|
||||
q=d_new Tile( s,q );
|
||||
q=new Tile( s,q );
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ Decl *DeclSeq::findDecl( const string &s ){
|
||||
|
||||
Decl *DeclSeq::insertDecl( const string &s,Type *t,int kind,ConstType *d ){
|
||||
if( findDecl( s ) ) return 0;
|
||||
decls.push_back( d_new Decl( s,t,kind,d ) );
|
||||
decls.push_back( new Decl( s,t,kind,d ) );
|
||||
return decls.back();
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -69,9 +69,9 @@ void VarDeclNode::proto(DeclSeq *d, Environ *e) {
|
||||
|
||||
|
||||
if (!c) ex("Expression must be constant");
|
||||
if (ty == Type::int_type) ty = d_new ConstType(c->intValue());
|
||||
else if (ty == Type::float_type) ty = d_new ConstType(c->floatValue());
|
||||
else ty = d_new ConstType(c->stringValue());
|
||||
if (ty == Type::int_type) ty = new ConstType(c->intValue());
|
||||
else if (ty == Type::float_type) ty = new ConstType(c->floatValue());
|
||||
else ty = new ConstType(c->stringValue());
|
||||
e->types.push_back(ty);
|
||||
delete expr; expr = 0;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ void VarDeclNode::proto(DeclSeq *d, Environ *e) {
|
||||
|
||||
Decl *decl = d->insertDecl(ident, ty, kind, defType);
|
||||
if (!decl) ex("Duplicate variable name");
|
||||
if (expr) sem_var = d_new DeclVarNode(decl);
|
||||
if (expr) sem_var = new DeclVarNode(decl);
|
||||
}
|
||||
|
||||
void VarDeclNode::semant(Environ *e) {
|
||||
@@ -106,9 +106,9 @@ void VarDeclNode::translate(Codegen *g) {
|
||||
//////////////////////////
|
||||
void FuncDeclNode::proto(DeclSeq *d, Environ *e) {
|
||||
Type *t = tagType(tag, e); if (!t) t = Type::int_type;
|
||||
a_ptr<DeclSeq> decls(d_new DeclSeq());
|
||||
a_ptr<DeclSeq> decls(new DeclSeq());
|
||||
params->proto(decls, e);
|
||||
sem_type = d_new FuncType(t, decls.release(), false, false);
|
||||
sem_type = new FuncType(t, decls.release(), false, false);
|
||||
if (!d->insertDecl(ident, sem_type, DECL_FUNC)) {
|
||||
delete sem_type; ex("duplicate identifier");
|
||||
}
|
||||
@@ -117,7 +117,7 @@ void FuncDeclNode::proto(DeclSeq *d, Environ *e) {
|
||||
|
||||
void FuncDeclNode::semant(Environ *e) {
|
||||
|
||||
sem_env = d_new Environ(genLabel(), sem_type->returnType, 1, e);
|
||||
sem_env = new Environ(genLabel(), sem_type->returnType, 1, e);
|
||||
DeclSeq *decls = sem_env->decls;
|
||||
|
||||
int k;
|
||||
@@ -156,7 +156,7 @@ void FuncDeclNode::translate(Codegen *g) {
|
||||
//leave the function
|
||||
g->label(sem_env->funcLabel + "_leave");
|
||||
t = deleteVars(sem_env);
|
||||
if (g->debug) t = d_new TNode(IR_SEQ, call("__bbDebugLeave"), t);
|
||||
if (g->debug) t = new TNode(IR_SEQ, call("__bbDebugLeave"), t);
|
||||
g->leave(t, sem_type->params->size() * 4);
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ void FuncDeclNode::translate(Codegen *g) {
|
||||
// Type Declaration //
|
||||
//////////////////////
|
||||
void StructDeclNode::proto(DeclSeq *d, Environ *e) {
|
||||
sem_type = d_new StructType(ident, d_new DeclSeq());
|
||||
sem_type = new StructType(ident, new DeclSeq());
|
||||
if (!d->insertDecl(ident, sem_type, DECL_STRUCT)) {
|
||||
delete sem_type; ex("Duplicate identifier");
|
||||
}
|
||||
@@ -262,7 +262,7 @@ void VectorDeclNode::proto(DeclSeq *d, Environ *env) {
|
||||
sizes.push_back(n + 1);
|
||||
}
|
||||
string label = genLabel();
|
||||
sem_type = d_new VectorType(label, ty, sizes);
|
||||
sem_type = new VectorType(label, ty, sizes);
|
||||
if (!d->insertDecl(ident, sem_type, kind)) {
|
||||
delete sem_type; ex("Duplicate identifier");
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
Environ::Environ( const string &f,Type *r,int l,Environ *gs )
|
||||
:funcLabel(f),returnType(r),level(l),globals(gs){
|
||||
decls=d_new DeclSeq();
|
||||
typeDecls=d_new DeclSeq();
|
||||
funcDecls=d_new DeclSeq();
|
||||
decls=new DeclSeq();
|
||||
typeDecls=new DeclSeq();
|
||||
funcDecls=new DeclSeq();
|
||||
if( globals ) globals->children.push_back( this );
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ Label *Environ::findLabel( const string &s ){
|
||||
}
|
||||
|
||||
Label *Environ::insertLabel( const string &s,int def,int src,int sz ){
|
||||
Label *l=d_new Label( s,def,src,sz );
|
||||
Label *l=new Label( s,def,src,sz );
|
||||
labels.push_back( l );return l;
|
||||
}
|
||||
|
||||
|
||||
+65
-65
@@ -13,7 +13,7 @@ ExprNode *ExprNode::castTo(Type *ty, Environ *e) {
|
||||
ex("Illegal type conversion");
|
||||
}
|
||||
|
||||
ExprNode *cast = d_new CastNode(this, ty);
|
||||
ExprNode *cast = new CastNode(this, ty);
|
||||
cast->semant(e);
|
||||
return cast;
|
||||
}
|
||||
@@ -25,9 +25,9 @@ ExprNode *CastNode::semant(Environ *e) {
|
||||
|
||||
if (ConstNode *c = expr->constNode()) {
|
||||
ExprNode *e;
|
||||
if (type == Type::int_type) e = d_new IntConstNode(c->intValue());
|
||||
else if (type == Type::float_type) e = d_new FloatConstNode(c->floatValue());
|
||||
else e = d_new StringConstNode(c->stringValue());
|
||||
if (type == Type::int_type) e = new IntConstNode(c->intValue());
|
||||
else if (type == Type::float_type) e = new FloatConstNode(c->floatValue());
|
||||
else e = new StringConstNode(c->stringValue());
|
||||
delete this;
|
||||
return e;
|
||||
}
|
||||
@@ -43,11 +43,11 @@ TNode *CastNode::translate(Codegen *g) {
|
||||
TNode *t = expr->translate(g);
|
||||
if (expr->sem_type == Type::float_type && sem_type == Type::int_type) {
|
||||
//float->int
|
||||
return d_new TNode(IR_CAST, t, 0);
|
||||
return new TNode(IR_CAST, t, 0);
|
||||
}
|
||||
if (expr->sem_type == Type::int_type && sem_type == Type::float_type) {
|
||||
//int->float
|
||||
return d_new TNode(IR_FCAST, t, 0);
|
||||
return new TNode(IR_FCAST, t, 0);
|
||||
}
|
||||
if (expr->sem_type == Type::string_type && sem_type == Type::int_type) {
|
||||
//str->int
|
||||
@@ -92,17 +92,17 @@ TNode *ExprSeqNode::translate(Codegen *g, bool cfunc) {
|
||||
if (ty->stringType()) {
|
||||
q = call("__bbStrToCStr", q);
|
||||
} else if (ty->structType()) {
|
||||
q = d_new TNode(IR_MEM, q);
|
||||
q = new TNode(IR_MEM, q);
|
||||
} else if (ty == Type::void_type) {
|
||||
q = d_new TNode(IR_MEM, add(q, iconst(4)));
|
||||
q = new TNode(IR_MEM, add(q, iconst(4)));
|
||||
}
|
||||
}
|
||||
|
||||
TNode *p;
|
||||
p = d_new TNode(IR_ARG, 0, 0, k * 4);
|
||||
p = d_new TNode(IR_MEM, p, 0);
|
||||
p = d_new TNode(IR_MOVE, q, p);
|
||||
p = d_new TNode(IR_SEQ, p, 0);
|
||||
p = new TNode(IR_ARG, 0, 0, k * 4);
|
||||
p = new TNode(IR_MEM, p, 0);
|
||||
p = new TNode(IR_MOVE, q, p);
|
||||
p = new TNode(IR_SEQ, p, 0);
|
||||
if (l) l->r = p;
|
||||
else t = p;
|
||||
l = p;
|
||||
@@ -167,14 +167,14 @@ TNode *CallNode::translate(Codegen *g) {
|
||||
TNode *r = exprs->translate(g, f->cfunc);
|
||||
|
||||
if (f->userlib) {
|
||||
l = d_new TNode(IR_MEM, l);
|
||||
l = new TNode(IR_MEM, l);
|
||||
usedfuncs.insert(ident);
|
||||
}
|
||||
|
||||
if (sem_type == Type::float_type) {
|
||||
t = d_new TNode(IR_FCALL, l, r, exprs->size() * 4);
|
||||
t = new TNode(IR_FCALL, l, r, exprs->size() * 4);
|
||||
} else {
|
||||
t = d_new TNode(IR_CALL, l, r, exprs->size() * 4);
|
||||
t = new TNode(IR_CALL, l, r, exprs->size() * 4);
|
||||
}
|
||||
|
||||
if (f->returnType->stringType()) {
|
||||
@@ -209,7 +209,7 @@ IntConstNode::IntConstNode(int n) :value(n) {
|
||||
}
|
||||
|
||||
TNode *IntConstNode::translate(Codegen *g) {
|
||||
return d_new TNode(IR_CONST, 0, 0, value);
|
||||
return new TNode(IR_CONST, 0, 0, value);
|
||||
}
|
||||
|
||||
int IntConstNode::intValue() {
|
||||
@@ -232,7 +232,7 @@ FloatConstNode::FloatConstNode(float f) :value(f) {
|
||||
}
|
||||
|
||||
TNode *FloatConstNode::translate(Codegen *g) {
|
||||
return d_new TNode(IR_CONST, 0, 0, *(int*)&value);
|
||||
return new TNode(IR_CONST, 0, 0, *(int*)&value);
|
||||
}
|
||||
|
||||
int FloatConstNode::intValue() {
|
||||
@@ -291,17 +291,17 @@ ExprNode *UniExprNode::semant(Environ *e) {
|
||||
ExprNode *e;
|
||||
if (sem_type == Type::int_type) {
|
||||
switch (op) {
|
||||
case '+':e = d_new IntConstNode(+c->intValue()); break;
|
||||
case '-':e = d_new IntConstNode(-c->intValue()); break;
|
||||
case ABS:e = d_new IntConstNode(c->intValue() >= 0 ? c->intValue() : -c->intValue()); break;
|
||||
case SGN:e = d_new IntConstNode(c->intValue() > 0 ? 1 : (c->intValue() < 0 ? -1 : 0)); break;
|
||||
case '+':e = new IntConstNode(+c->intValue()); break;
|
||||
case '-':e = new IntConstNode(-c->intValue()); break;
|
||||
case ABS:e = new IntConstNode(c->intValue() >= 0 ? c->intValue() : -c->intValue()); break;
|
||||
case SGN:e = new IntConstNode(c->intValue() > 0 ? 1 : (c->intValue() < 0 ? -1 : 0)); break;
|
||||
}
|
||||
} else {
|
||||
switch (op) {
|
||||
case '+':e = d_new FloatConstNode(+c->floatValue()); break;
|
||||
case '-':e = d_new FloatConstNode(-c->floatValue()); break;
|
||||
case ABS:e = d_new FloatConstNode(c->floatValue() >= 0 ? c->floatValue() : -c->floatValue()); break;
|
||||
case SGN:e = d_new FloatConstNode(c->floatValue() > 0 ? 1 : (c->floatValue() < 0 ? -1 : 0)); break;
|
||||
case '+':e = new FloatConstNode(+c->floatValue()); break;
|
||||
case '-':e = new FloatConstNode(-c->floatValue()); break;
|
||||
case ABS:e = new FloatConstNode(c->floatValue() >= 0 ? c->floatValue() : -c->floatValue()); break;
|
||||
case SGN:e = new FloatConstNode(c->floatValue() > 0 ? 1 : (c->floatValue() < 0 ? -1 : 0)); break;
|
||||
}
|
||||
}
|
||||
delete this;
|
||||
@@ -328,7 +328,7 @@ TNode *UniExprNode::translate(Codegen *g) {
|
||||
case SGN:return fcall("__bbFSgn", l);
|
||||
}
|
||||
}
|
||||
return d_new TNode(n, l, 0);
|
||||
return new TNode(n, l, 0);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@@ -341,12 +341,12 @@ ExprNode *BinExprNode::semant(Environ *e) {
|
||||
if (lc && rc) {
|
||||
ExprNode *expr = nullptr;
|
||||
switch (op) {
|
||||
case AND:expr = d_new IntConstNode(lc->intValue() & rc->intValue()); break;
|
||||
case OR: expr = d_new IntConstNode(lc->intValue() | rc->intValue()); break;
|
||||
case XOR:expr = d_new IntConstNode(lc->intValue() ^ rc->intValue()); break;
|
||||
case SHL:expr = d_new IntConstNode(lc->intValue() << rc->intValue()); break;
|
||||
case SHR:expr = d_new IntConstNode((unsigned)lc->intValue() >> rc->intValue()); break;
|
||||
case SAR:expr = d_new IntConstNode(lc->intValue() >> rc->intValue()); break;
|
||||
case AND:expr = new IntConstNode(lc->intValue() & rc->intValue()); break;
|
||||
case OR: expr = new IntConstNode(lc->intValue() | rc->intValue()); break;
|
||||
case XOR:expr = new IntConstNode(lc->intValue() ^ rc->intValue()); break;
|
||||
case SHL:expr = new IntConstNode(lc->intValue() << rc->intValue()); break;
|
||||
case SHR:expr = new IntConstNode((unsigned)lc->intValue() >> rc->intValue()); break;
|
||||
case SAR:expr = new IntConstNode(lc->intValue() >> rc->intValue()); break;
|
||||
}
|
||||
delete this;
|
||||
return expr;
|
||||
@@ -363,7 +363,7 @@ TNode *BinExprNode::translate(Codegen *g) {
|
||||
case AND:n = IR_AND; break; case OR:n = IR_OR; break; case XOR:n = IR_XOR; break;
|
||||
case SHL:n = IR_SHL; break; case SHR:n = IR_SHR; break; case SAR:n = IR_SAR; break;
|
||||
}
|
||||
return d_new TNode(n, l, r);
|
||||
return new TNode(n, l, r);
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
@@ -397,23 +397,23 @@ ExprNode *ArithExprNode::semant(Environ *e) {
|
||||
if (lc && rc) {
|
||||
ExprNode *expr = nullptr;
|
||||
if (sem_type == Type::string_type) {
|
||||
expr = d_new StringConstNode(lc->stringValue() + rc->stringValue());
|
||||
expr = new StringConstNode(lc->stringValue() + rc->stringValue());
|
||||
} else if (sem_type == Type::int_type) {
|
||||
switch (op) {
|
||||
case '+':expr = d_new IntConstNode(lc->intValue() + rc->intValue()); break;
|
||||
case '-':expr = d_new IntConstNode(lc->intValue() - rc->intValue()); break;
|
||||
case '*':expr = d_new IntConstNode(lc->intValue()*rc->intValue()); break;
|
||||
case '/':expr = d_new IntConstNode(lc->intValue() / rc->intValue()); break;
|
||||
case MOD:expr = d_new IntConstNode(lc->intValue() % rc->intValue()); break;
|
||||
case '+':expr = new IntConstNode(lc->intValue() + rc->intValue()); break;
|
||||
case '-':expr = new IntConstNode(lc->intValue() - rc->intValue()); break;
|
||||
case '*':expr = new IntConstNode(lc->intValue()*rc->intValue()); break;
|
||||
case '/':expr = new IntConstNode(lc->intValue() / rc->intValue()); break;
|
||||
case MOD:expr = new IntConstNode(lc->intValue() % rc->intValue()); break;
|
||||
}
|
||||
} else {
|
||||
switch (op) {
|
||||
case '+':expr = d_new FloatConstNode(lc->floatValue() + rc->floatValue()); break;
|
||||
case '-':expr = d_new FloatConstNode(lc->floatValue() - rc->floatValue()); break;
|
||||
case '*':expr = d_new FloatConstNode(lc->floatValue()*rc->floatValue()); break;
|
||||
case '/':expr = d_new FloatConstNode(lc->floatValue() / rc->floatValue()); break;
|
||||
case MOD:expr = d_new FloatConstNode(fmod(lc->floatValue(), rc->floatValue())); break;
|
||||
case '^':expr = d_new FloatConstNode(pow(lc->floatValue(), rc->floatValue())); break;
|
||||
case '+':expr = new FloatConstNode(lc->floatValue() + rc->floatValue()); break;
|
||||
case '-':expr = new FloatConstNode(lc->floatValue() - rc->floatValue()); break;
|
||||
case '*':expr = new FloatConstNode(lc->floatValue()*rc->floatValue()); break;
|
||||
case '/':expr = new FloatConstNode(lc->floatValue() / rc->floatValue()); break;
|
||||
case MOD:expr = new FloatConstNode(fmod(lc->floatValue(), rc->floatValue())); break;
|
||||
case '^':expr = new FloatConstNode(pow(lc->floatValue(), rc->floatValue())); break;
|
||||
}
|
||||
}
|
||||
delete this;
|
||||
@@ -443,7 +443,7 @@ TNode *ArithExprNode::translate(Codegen *g) {
|
||||
case '^':return fcall("__bbFPow", l, r);
|
||||
}
|
||||
}
|
||||
return d_new TNode(n, l, r);
|
||||
return new TNode(n, l, r);
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
@@ -470,30 +470,30 @@ ExprNode *RelExprNode::semant(Environ *e) {
|
||||
ExprNode *expr = nullptr;
|
||||
if (opType == Type::string_type) {
|
||||
switch (op) {
|
||||
case '<':expr = d_new IntConstNode(lc->stringValue() < rc->stringValue()); break;
|
||||
case '=':expr = d_new IntConstNode(lc->stringValue() == rc->stringValue()); break;
|
||||
case '>':expr = d_new IntConstNode(lc->stringValue() > rc->stringValue()); break;
|
||||
case LE: expr = d_new IntConstNode(lc->stringValue() <= rc->stringValue()); break;
|
||||
case NE: expr = d_new IntConstNode(lc->stringValue() != rc->stringValue()); break;
|
||||
case GE: expr = d_new IntConstNode(lc->stringValue() >= rc->stringValue()); break;
|
||||
case '<':expr = new IntConstNode(lc->stringValue() < rc->stringValue()); break;
|
||||
case '=':expr = new IntConstNode(lc->stringValue() == rc->stringValue()); break;
|
||||
case '>':expr = new IntConstNode(lc->stringValue() > rc->stringValue()); break;
|
||||
case LE: expr = new IntConstNode(lc->stringValue() <= rc->stringValue()); break;
|
||||
case NE: expr = new IntConstNode(lc->stringValue() != rc->stringValue()); break;
|
||||
case GE: expr = new IntConstNode(lc->stringValue() >= rc->stringValue()); break;
|
||||
}
|
||||
} else if (opType == Type::float_type) {
|
||||
switch (op) {
|
||||
case '<':expr = d_new IntConstNode(lc->floatValue() < rc->floatValue()); break;
|
||||
case '=':expr = d_new IntConstNode(lc->floatValue() == rc->floatValue()); break;
|
||||
case '>':expr = d_new IntConstNode(lc->floatValue() > rc->floatValue()); break;
|
||||
case LE: expr = d_new IntConstNode(lc->floatValue() <= rc->floatValue()); break;
|
||||
case NE: expr = d_new IntConstNode(lc->floatValue() != rc->floatValue()); break;
|
||||
case GE: expr = d_new IntConstNode(lc->floatValue() >= rc->floatValue()); break;
|
||||
case '<':expr = new IntConstNode(lc->floatValue() < rc->floatValue()); break;
|
||||
case '=':expr = new IntConstNode(lc->floatValue() == rc->floatValue()); break;
|
||||
case '>':expr = new IntConstNode(lc->floatValue() > rc->floatValue()); break;
|
||||
case LE: expr = new IntConstNode(lc->floatValue() <= rc->floatValue()); break;
|
||||
case NE: expr = new IntConstNode(lc->floatValue() != rc->floatValue()); break;
|
||||
case GE: expr = new IntConstNode(lc->floatValue() >= rc->floatValue()); break;
|
||||
}
|
||||
} else {
|
||||
switch (op) {
|
||||
case '<':expr = d_new IntConstNode(lc->intValue() < rc->intValue()); break;
|
||||
case '=':expr = d_new IntConstNode(lc->intValue() == rc->intValue()); break;
|
||||
case '>':expr = d_new IntConstNode(lc->intValue() > rc->intValue()); break;
|
||||
case LE: expr = d_new IntConstNode(lc->intValue() <= rc->intValue()); break;
|
||||
case NE: expr = d_new IntConstNode(lc->intValue() != rc->intValue()); break;
|
||||
case GE: expr = d_new IntConstNode(lc->intValue() >= rc->intValue()); break;
|
||||
case '<':expr = new IntConstNode(lc->intValue() < rc->intValue()); break;
|
||||
case '=':expr = new IntConstNode(lc->intValue() == rc->intValue()); break;
|
||||
case '>':expr = new IntConstNode(lc->intValue() > rc->intValue()); break;
|
||||
case LE: expr = new IntConstNode(lc->intValue() <= rc->intValue()); break;
|
||||
case NE: expr = new IntConstNode(lc->intValue() != rc->intValue()); break;
|
||||
case GE: expr = new IntConstNode(lc->intValue() >= rc->intValue()); break;
|
||||
}
|
||||
}
|
||||
delete this;
|
||||
@@ -591,7 +591,7 @@ ExprNode *NullNode::semant(Environ *e) {
|
||||
}
|
||||
|
||||
TNode *NullNode::translate(Codegen *g) {
|
||||
return d_new TNode(IR_CONST, 0, 0, 0);
|
||||
return new TNode(IR_CONST, 0, 0, 0);
|
||||
}
|
||||
|
||||
/////////////////
|
||||
|
||||
+31
-31
@@ -29,7 +29,7 @@ void Node::ex( const string &e,int pos,const string &f ){
|
||||
VarNode *Node::genLocal( Environ *e,Type *ty ){
|
||||
string t=genLabel();
|
||||
Decl *d=e->decls->insertDecl( t,ty,DECL_LOCAL );
|
||||
return d_new DeclVarNode( d );
|
||||
return new DeclVarNode( d );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
@@ -39,9 +39,9 @@ ConstNode *Node::constValue( Type *ty ){
|
||||
ConstType *c=ty->constType();
|
||||
if( !c ) return 0;
|
||||
ty=c->valueType;
|
||||
if( ty==Type::int_type ) return d_new IntConstNode( c->intValue );
|
||||
if( ty==Type::float_type ) return d_new FloatConstNode( c->floatValue );
|
||||
return d_new StringConstNode( c->stringValue );
|
||||
if( ty==Type::int_type ) return new IntConstNode( c->intValue );
|
||||
if( ty==Type::float_type ) return new FloatConstNode( c->floatValue );
|
||||
return new StringConstNode( c->stringValue );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
@@ -74,10 +74,10 @@ TNode *Node::createVars( Environ *e ){
|
||||
Decl *d=e->decls->decls[k];
|
||||
if( d->kind!=DECL_LOCAL ) continue;
|
||||
if( d->type->vectorType() ) continue;
|
||||
if( !t ) t=d_new TNode( IR_CONST,0,0,0 );
|
||||
TNode *p=d_new TNode( IR_LOCAL,0,0,d->offset );
|
||||
p=d_new TNode( IR_MEM,p,0 );
|
||||
t=d_new TNode( IR_MOVE,t,p );
|
||||
if( !t ) t=new TNode( IR_CONST,0,0,0 );
|
||||
TNode *p=new TNode( IR_LOCAL,0,0,d->offset );
|
||||
p=new TNode( IR_MEM,p,0 );
|
||||
t=new TNode( IR_MOVE,t,p );
|
||||
}
|
||||
//initialize vectors
|
||||
for( k=0;k<e->decls->size();++k ){
|
||||
@@ -123,7 +123,7 @@ TNode *Node::deleteVars( Environ *e ){
|
||||
}
|
||||
}
|
||||
if( !func.size() ) continue;
|
||||
p=d_new TNode( IR_SEQ,call( func,p1,p2 ),0 );
|
||||
p=new TNode( IR_SEQ,call( func,p1,p2 ),0 );
|
||||
(l ? l->r : t)=p;
|
||||
l=p;
|
||||
}
|
||||
@@ -150,12 +150,12 @@ TNode *Node::compare( int op,TNode *l,TNode *r,Type *ty ){
|
||||
}
|
||||
if( ty==Type::string_type ){
|
||||
l=call( "__bbStrCompare",l,r );
|
||||
r=d_new TNode( IR_CONST,0,0,0 );
|
||||
r=new TNode( IR_CONST,0,0,0 );
|
||||
}else if( ty->structType() ){
|
||||
l=call( "__bbObjCompare",l,r );
|
||||
r=d_new TNode( IR_CONST,0,0,0 );
|
||||
r=new TNode( IR_CONST,0,0,0 );
|
||||
}
|
||||
return d_new TNode( n,l,r );
|
||||
return new TNode( n,l,r );
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
@@ -196,8 +196,8 @@ TNode *Node::call( const string &func,TNode *a0,TNode *a1,TNode *a2 ){
|
||||
}
|
||||
}
|
||||
}
|
||||
TNode *l=d_new TNode( IR_GLOBAL,0,0,func );
|
||||
return d_new TNode( IR_CALL,l,t,size );
|
||||
TNode *l=new TNode( IR_GLOBAL,0,0,func );
|
||||
return new TNode( IR_CALL,l,t,size );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
@@ -218,67 +218,67 @@ TNode *Node::fcall( const string &func,TNode *a0,TNode *a1,TNode *a2 ){
|
||||
}
|
||||
}
|
||||
}
|
||||
TNode *l=d_new TNode( IR_GLOBAL,0,0,func );
|
||||
return d_new TNode( IR_FCALL,l,t,size );
|
||||
TNode *l=new TNode( IR_GLOBAL,0,0,func );
|
||||
return new TNode( IR_FCALL,l,t,size );
|
||||
}
|
||||
|
||||
TNode *Node::seq( TNode *l,TNode *r ){
|
||||
return d_new TNode( IR_SEQ,l,r );
|
||||
return new TNode( IR_SEQ,l,r );
|
||||
}
|
||||
|
||||
TNode *Node::move( TNode *src,TNode *dest ){
|
||||
return d_new TNode( IR_MOVE,src,dest );
|
||||
return new TNode( IR_MOVE,src,dest );
|
||||
}
|
||||
|
||||
TNode *Node::global( const string &s ){
|
||||
return d_new TNode( IR_GLOBAL,0,0,s );
|
||||
return new TNode( IR_GLOBAL,0,0,s );
|
||||
}
|
||||
|
||||
TNode *Node::local( int offset ){
|
||||
return d_new TNode( IR_LOCAL,0,0,offset );
|
||||
return new TNode( IR_LOCAL,0,0,offset );
|
||||
}
|
||||
|
||||
TNode *Node::arg( int offset ){
|
||||
return d_new TNode( IR_ARG,0,0,offset );
|
||||
return new TNode( IR_ARG,0,0,offset );
|
||||
}
|
||||
|
||||
TNode *Node::mem( TNode *ref ){
|
||||
return d_new TNode( IR_MEM,ref,0 );
|
||||
return new TNode( IR_MEM,ref,0 );
|
||||
}
|
||||
|
||||
TNode *Node::add( TNode *l,TNode *r ){
|
||||
return d_new TNode( IR_ADD,l,r );
|
||||
return new TNode( IR_ADD,l,r );
|
||||
}
|
||||
|
||||
TNode *Node::mul( TNode *l,TNode *r ){
|
||||
return d_new TNode( IR_MUL,l,r );
|
||||
return new TNode( IR_MUL,l,r );
|
||||
}
|
||||
|
||||
TNode *Node::iconst( int n ){
|
||||
return d_new TNode( IR_CONST,0,0,n );
|
||||
return new TNode( IR_CONST,0,0,n );
|
||||
}
|
||||
|
||||
TNode *Node::ret(){
|
||||
return d_new TNode( IR_RET,0,0 );
|
||||
return new TNode( IR_RET,0,0 );
|
||||
}
|
||||
|
||||
TNode *Node::jsr( const string &s ){
|
||||
return d_new TNode( IR_JSR,0,0,s );
|
||||
return new TNode( IR_JSR,0,0,s );
|
||||
}
|
||||
|
||||
TNode *Node::jump( const string &s ){
|
||||
return d_new TNode( IR_JUMP,0,0,s );
|
||||
return new TNode( IR_JUMP,0,0,s );
|
||||
}
|
||||
|
||||
TNode *Node::jumpt( TNode *expr,const string &s ){
|
||||
return d_new TNode( IR_JUMPT,expr,0,s );
|
||||
return new TNode( IR_JUMPT,expr,0,s );
|
||||
}
|
||||
|
||||
TNode *Node::jumpf( TNode *expr,const string &s ){
|
||||
return d_new TNode( IR_JUMPF,expr,0,s );
|
||||
return new TNode( IR_JUMPF,expr,0,s );
|
||||
}
|
||||
|
||||
TNode *Node::jumpge( TNode *l,TNode *r,const string &s ){
|
||||
return d_new TNode( IR_JUMPGE,l,r,s );
|
||||
return new TNode( IR_JUMPGE,l,r,s );
|
||||
}
|
||||
|
||||
|
||||
+78
-78
@@ -22,10 +22,10 @@ ProgNode *Parser::parse( const string &main ){
|
||||
|
||||
incfile=main;
|
||||
|
||||
consts=d_new DeclSeqNode();
|
||||
structs=d_new DeclSeqNode();
|
||||
funcs=d_new DeclSeqNode();
|
||||
datas=d_new DeclSeqNode();
|
||||
consts=new DeclSeqNode();
|
||||
structs=new DeclSeqNode();
|
||||
funcs=new DeclSeqNode();
|
||||
datas=new DeclSeqNode();
|
||||
StmtSeqNode *stmts=0;
|
||||
|
||||
try{
|
||||
@@ -36,7 +36,7 @@ ProgNode *Parser::parse( const string &main ){
|
||||
throw;
|
||||
}
|
||||
|
||||
return d_new ProgNode( consts,structs,funcs,datas,stmts );
|
||||
return new ProgNode( consts,structs,funcs,datas,stmts );
|
||||
}
|
||||
|
||||
void Parser::ex( const string &s ){
|
||||
@@ -71,7 +71,7 @@ void Parser::parseChar( int c ){
|
||||
}
|
||||
|
||||
StmtSeqNode *Parser::parseStmtSeq( int scope ){
|
||||
a_ptr<StmtSeqNode> stmts( d_new StmtSeqNode( incfile ) );
|
||||
a_ptr<StmtSeqNode> stmts( new StmtSeqNode( incfile ) );
|
||||
parseStmtSeq( stmts,scope );
|
||||
return stmts.release();
|
||||
}
|
||||
@@ -116,7 +116,7 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
a_ptr<StmtSeqNode> ss( parseStmtSeq( scope ) );
|
||||
if( toker->curr()!=EOF ) exp( "end-of-file" );
|
||||
|
||||
result=d_new IncludeNode( incfile,ss.release() );
|
||||
result=new IncludeNode( incfile,ss.release() );
|
||||
|
||||
toker=t_toker;
|
||||
incfile=t_inc;
|
||||
@@ -146,14 +146,14 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
toker->next();
|
||||
}else exprs=parseExprSeq();
|
||||
}else exprs=parseExprSeq();
|
||||
CallNode *call=d_new CallNode( ident,tag,exprs );
|
||||
result=d_new ExprStmtNode( call );
|
||||
CallNode *call=new CallNode( ident,tag,exprs );
|
||||
result=new ExprStmtNode( call );
|
||||
}else{
|
||||
//must be a var
|
||||
a_ptr<VarNode> var( parseVar( ident,tag ) );
|
||||
if( toker->curr()!='=' ) exp( "variable assignment" );
|
||||
toker->next();ExprNode *expr=parseExpr( false );
|
||||
result=d_new AssNode( var.release(),expr );
|
||||
result=new AssNode( var.release(),expr );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -171,7 +171,7 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
int pos=toker->pos();
|
||||
if( toker->curr()!=WEND ) exp( "'Wend'" );
|
||||
toker->next();
|
||||
result=d_new WhileNode( expr.release(),stmts.release(),pos );
|
||||
result=new WhileNode( expr.release(),stmts.release(),pos );
|
||||
}
|
||||
break;
|
||||
case REPEAT:
|
||||
@@ -182,13 +182,13 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
int pos=toker->pos();
|
||||
if( curr!=UNTIL && curr!=FOREVER ) exp( "'Until' or 'Forever'" );
|
||||
toker->next();if( curr==UNTIL ) expr=parseExpr( false );
|
||||
result=d_new RepeatNode( stmts.release(),expr,pos );
|
||||
result=new RepeatNode( stmts.release(),expr,pos );
|
||||
}
|
||||
break;
|
||||
case SELECT:
|
||||
{
|
||||
toker->next();ExprNode *expr=parseExpr( false );
|
||||
a_ptr<SelectNode> selNode( d_new SelectNode( expr ) );
|
||||
a_ptr<SelectNode> selNode( new SelectNode( expr ) );
|
||||
for(;;){
|
||||
while( isTerm( toker->curr() ) ) toker->next();
|
||||
if( toker->curr()==CASE ){
|
||||
@@ -196,7 +196,7 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
a_ptr<ExprSeqNode> exprs( parseExprSeq() );
|
||||
if( !exprs->size() ) exp( "expression sequence" );
|
||||
a_ptr<StmtSeqNode> stmts( parseStmtSeq( STMTS_BLOCK ) );
|
||||
selNode->push_back( d_new CaseNode( exprs.release(),stmts.release() ) );
|
||||
selNode->push_back( new CaseNode( exprs.release(),stmts.release() ) );
|
||||
continue;
|
||||
}else if( toker->curr()==DEFAULT ){
|
||||
toker->next();
|
||||
@@ -226,7 +226,7 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
int pos=toker->pos();
|
||||
if( toker->curr()!=NEXT ) exp( "'Next'" );
|
||||
toker->next();
|
||||
result=d_new ForEachNode( var.release(),ident,stmts.release(),pos );
|
||||
result=new ForEachNode( var.release(),ident,stmts.release(),pos );
|
||||
}else{
|
||||
a_ptr<ExprNode> from,to,step;
|
||||
from=parseExpr( false );
|
||||
@@ -235,43 +235,43 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
//step...
|
||||
if( toker->curr()==STEP ){
|
||||
toker->next();step=parseExpr( false );
|
||||
}else step=d_new IntConstNode( 1 );
|
||||
}else step=new IntConstNode( 1 );
|
||||
stmts=parseStmtSeq( STMTS_BLOCK );
|
||||
int pos=toker->pos();
|
||||
if( toker->curr()!=NEXT ) exp( "'Next'" );
|
||||
toker->next();
|
||||
result=d_new ForNode( var.release(),from.release(),to.release(),step.release(),stmts.release(),pos );
|
||||
result=new ForNode( var.release(),from.release(),to.release(),step.release(),stmts.release(),pos );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EXIT:
|
||||
{
|
||||
toker->next();result=d_new ExitNode();
|
||||
toker->next();result=new ExitNode();
|
||||
}
|
||||
break;
|
||||
case GOTO:
|
||||
{
|
||||
toker->next();string t=parseIdent();result=d_new GotoNode( t );
|
||||
toker->next();string t=parseIdent();result=new GotoNode( t );
|
||||
}
|
||||
break;
|
||||
case GOSUB:
|
||||
{
|
||||
toker->next();string t=parseIdent();result=d_new GosubNode( t );
|
||||
toker->next();string t=parseIdent();result=new GosubNode( t );
|
||||
}
|
||||
break;
|
||||
case RETURN:
|
||||
{
|
||||
toker->next();result=d_new ReturnNode( parseExpr( true ) );
|
||||
toker->next();result=new ReturnNode( parseExpr( true ) );
|
||||
}
|
||||
break;
|
||||
case BBDELETE:
|
||||
{
|
||||
if( toker->next()==EACH ){
|
||||
toker->next();string t=parseIdent();
|
||||
result=d_new DeleteEachNode( t );
|
||||
result=new DeleteEachNode( t );
|
||||
}else{
|
||||
ExprNode *expr=parseExpr( false );
|
||||
result=d_new DeleteNode( expr );
|
||||
result=new DeleteNode( expr );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -282,28 +282,28 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
if( toker->curr()!=BEFORE && toker->curr()!=AFTER ) exp( "'Before' or 'After'" );
|
||||
bool before=toker->curr()==BEFORE;toker->next();
|
||||
a_ptr<ExprNode> expr2( parseExpr( false ) );
|
||||
result=d_new InsertNode( expr1.release(),expr2.release(),before );
|
||||
result=new InsertNode( expr1.release(),expr2.release(),before );
|
||||
}
|
||||
break;
|
||||
case READ:
|
||||
do{
|
||||
toker->next();VarNode *var=parseVar();
|
||||
StmtNode *stmt=d_new ReadNode( var );
|
||||
StmtNode *stmt=new ReadNode( var );
|
||||
stmt->pos=pos;pos=toker->pos();
|
||||
stmts->push_back( stmt );
|
||||
}while( toker->curr()==',' );
|
||||
break;
|
||||
case RESTORE:
|
||||
if( toker->next()==IDENT ){
|
||||
result=d_new RestoreNode( toker->text() );toker->next();
|
||||
}else result=d_new RestoreNode( "" );
|
||||
result=new RestoreNode( toker->text() );toker->next();
|
||||
}else result=new RestoreNode( "" );
|
||||
break;
|
||||
case DATA:
|
||||
if( scope!=STMTS_PROG ) ex( "'Data' can only appear in main program" );
|
||||
do{
|
||||
toker->next();
|
||||
ExprNode *expr=parseExpr( false );
|
||||
datas->push_back( d_new DataDeclNode( expr ) );
|
||||
datas->push_back( new DataDeclNode( expr ) );
|
||||
}while( toker->curr()==',' );
|
||||
break;
|
||||
case TYPE:
|
||||
@@ -332,7 +332,7 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
do{
|
||||
toker->next();
|
||||
DeclNode *d=parseVarDecl( DECL_LOCAL,false );
|
||||
StmtNode *stmt=d_new DeclStmtNode( d );
|
||||
StmtNode *stmt=new DeclStmtNode( d );
|
||||
stmt->pos=pos;pos=toker->pos();
|
||||
stmts->push_back( stmt );
|
||||
}while( toker->curr()==',' );
|
||||
@@ -342,7 +342,7 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
do{
|
||||
toker->next();
|
||||
DeclNode *d=parseVarDecl( DECL_GLOBAL,false );
|
||||
StmtNode *stmt=d_new DeclStmtNode( d );
|
||||
StmtNode *stmt=new DeclStmtNode( d );
|
||||
stmt->pos=pos;pos=toker->pos();
|
||||
stmts->push_back( stmt );
|
||||
}while( toker->curr()==',' );
|
||||
@@ -350,7 +350,7 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){
|
||||
case '.':
|
||||
{
|
||||
toker->next();string t=parseIdent();
|
||||
result=d_new LabelNode( t,datas->size() );
|
||||
result=new LabelNode( t,datas->size() );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -387,23 +387,23 @@ VarNode *Parser::parseVar( const string &ident,const string &tag ){
|
||||
a_ptr<ExprSeqNode> exprs( parseExprSeq() );
|
||||
if( toker->curr()!=')' ) exp( "')'" );
|
||||
toker->next();
|
||||
var=d_new ArrayVarNode( ident,tag,exprs.release() );
|
||||
}else var=d_new IdentVarNode( ident,tag );
|
||||
var=new ArrayVarNode( ident,tag,exprs.release() );
|
||||
}else var=new IdentVarNode( ident,tag );
|
||||
|
||||
for(;;){
|
||||
if( toker->curr()=='\\' ){
|
||||
toker->next();
|
||||
string ident=parseIdent();
|
||||
string tag=parseTypeTag();
|
||||
ExprNode *expr=d_new VarExprNode( var.release() );
|
||||
var=d_new FieldVarNode( expr,ident,tag );
|
||||
ExprNode *expr=new VarExprNode( var.release() );
|
||||
var=new FieldVarNode( expr,ident,tag );
|
||||
}else if( toker->curr()=='[' ){
|
||||
toker->next();
|
||||
a_ptr<ExprSeqNode> exprs( parseExprSeq() );
|
||||
if( exprs->exprs.size()!=1 || toker->curr()!=']' ) exp( "']'" );
|
||||
toker->next();
|
||||
ExprNode *expr=d_new VarExprNode( var.release() );
|
||||
var=d_new VectorVarNode( expr,exprs.release() );
|
||||
ExprNode *expr=new VarExprNode( var.release() );
|
||||
var=new VectorVarNode( expr,exprs.release() );
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
@@ -422,13 +422,13 @@ DeclNode *Parser::parseVarDecl( int kind,bool constant ){
|
||||
a_ptr<ExprSeqNode> exprs( parseExprSeq() );
|
||||
if( exprs->size()!=1 || toker->curr()!=']' ) exp( "']'" );
|
||||
toker->next();
|
||||
d=d_new VectorDeclNode( ident,tag,exprs.release(),kind );
|
||||
d=new VectorDeclNode( ident,tag,exprs.release(),kind );
|
||||
}else{
|
||||
ExprNode *expr=0;
|
||||
if( toker->curr()=='=' ){
|
||||
toker->next();expr=parseExpr( false );
|
||||
}else if( constant ) ex( "Constants must be initialized" );
|
||||
d=d_new VarDeclNode( ident,tag,kind,constant,expr );
|
||||
d=new VarDeclNode( ident,tag,kind,constant,expr );
|
||||
}
|
||||
d->pos=pos;d->file=incfile;
|
||||
return d;
|
||||
@@ -443,7 +443,7 @@ DimNode *Parser::parseArrayDecl(){
|
||||
if( toker->curr()!=')' ) exp( "')'" );
|
||||
if( !exprs->size() ) ex( "can't have a 0 dimensional array" );
|
||||
toker->next();
|
||||
DimNode *d=d_new DimNode( ident,tag,exprs.release() );
|
||||
DimNode *d=new DimNode( ident,tag,exprs.release() );
|
||||
arrayDecls[ident]=d;
|
||||
d->pos=pos;
|
||||
return d;
|
||||
@@ -454,7 +454,7 @@ DeclNode *Parser::parseFuncDecl(){
|
||||
string ident=parseIdent();
|
||||
string tag=parseTypeTag();
|
||||
if( toker->curr()!='(' ) exp( "'('" );
|
||||
a_ptr<DeclSeqNode> params( d_new DeclSeqNode() );
|
||||
a_ptr<DeclSeqNode> params( new DeclSeqNode() );
|
||||
if( toker->next()!=')' ){
|
||||
for(;;){
|
||||
params->push_back( parseVarDecl( DECL_PARAM,false ) );
|
||||
@@ -466,9 +466,9 @@ DeclNode *Parser::parseFuncDecl(){
|
||||
toker->next();
|
||||
a_ptr<StmtSeqNode> stmts( parseStmtSeq( STMTS_BLOCK ) );
|
||||
if( toker->curr()!=ENDFUNCTION ) exp( "'End Function'" );
|
||||
StmtNode *ret=d_new ReturnNode(0);ret->pos=toker->pos();
|
||||
StmtNode *ret=new ReturnNode(0);ret->pos=toker->pos();
|
||||
stmts->push_back( ret );toker->next();
|
||||
DeclNode *d=d_new FuncDeclNode( ident,tag,params.release(),stmts.release() );
|
||||
DeclNode *d=new FuncDeclNode( ident,tag,params.release(),stmts.release() );
|
||||
d->pos=pos;d->file=incfile;
|
||||
return d;
|
||||
}
|
||||
@@ -477,7 +477,7 @@ DeclNode *Parser::parseStructDecl(){
|
||||
int pos=toker->pos();
|
||||
string ident=parseIdent();
|
||||
while( toker->curr()=='\n' ) toker->next();
|
||||
a_ptr<DeclSeqNode> fields( d_new DeclSeqNode() );
|
||||
a_ptr<DeclSeqNode> fields( new DeclSeqNode() );
|
||||
while( toker->curr()==FIELD ){
|
||||
do{
|
||||
toker->next();
|
||||
@@ -487,7 +487,7 @@ DeclNode *Parser::parseStructDecl(){
|
||||
}
|
||||
if( toker->curr()!=ENDTYPE ) exp( "'Field' or 'End Type'" );
|
||||
toker->next();
|
||||
DeclNode *d=d_new StructDeclNode( ident,fields.release() );
|
||||
DeclNode *d=new StructDeclNode( ident,fields.release() );
|
||||
d->pos=pos;d->file=incfile;
|
||||
return d;
|
||||
}
|
||||
@@ -507,7 +507,7 @@ IfNode *Parser::parseIf(){
|
||||
toker->next();
|
||||
IfNode *ifnode=parseIf();
|
||||
ifnode->pos=pos;
|
||||
elseOpt=d_new StmtSeqNode( incfile );
|
||||
elseOpt=new StmtSeqNode( incfile );
|
||||
elseOpt->push_back( ifnode );
|
||||
}else if( toker->curr()==ELSE ){
|
||||
toker->next();
|
||||
@@ -517,11 +517,11 @@ IfNode *Parser::parseIf(){
|
||||
if( toker->curr()!=ENDIF ) exp( "'EndIf'" );
|
||||
}else if( toker->curr()!='\n' ) exp( "end-of-line" );
|
||||
|
||||
return d_new IfNode( expr.release(),stmts.release(),elseOpt.release() );
|
||||
return new IfNode( expr.release(),stmts.release(),elseOpt.release() );
|
||||
}
|
||||
|
||||
ExprSeqNode *Parser::parseExprSeq(){
|
||||
a_ptr<ExprSeqNode> exprs( d_new ExprSeqNode() );
|
||||
a_ptr<ExprSeqNode> exprs( new ExprSeqNode() );
|
||||
bool opt=true;
|
||||
while( ExprNode *e=parseExpr( opt ) ){
|
||||
exprs->push_back( e );
|
||||
@@ -535,7 +535,7 @@ ExprNode *Parser::parseExpr( bool opt ){
|
||||
if( toker->curr()==NOT ){
|
||||
toker->next();
|
||||
ExprNode *expr=parseExpr1( false );
|
||||
return d_new RelExprNode( '=',expr,d_new IntConstNode( 0 ) );
|
||||
return new RelExprNode( '=',expr,new IntConstNode( 0 ) );
|
||||
}
|
||||
return parseExpr1( opt );
|
||||
}
|
||||
@@ -548,7 +548,7 @@ ExprNode *Parser::parseExpr1( bool opt ){
|
||||
int c=toker->curr();
|
||||
if( c!=AND && c!=OR && c!=XOR ) return lhs.release();
|
||||
toker->next();ExprNode *rhs=parseExpr2( false );
|
||||
lhs=d_new BinExprNode( c,lhs.release(),rhs );
|
||||
lhs=new BinExprNode( c,lhs.release(),rhs );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ ExprNode *Parser::parseExpr2( bool opt ){
|
||||
int c=toker->curr();
|
||||
if( c!='<' && c!='>' && c!='=' && c!=LE && c!=GE && c!=NE ) return lhs.release();
|
||||
toker->next();ExprNode *rhs=parseExpr3( false );
|
||||
lhs=d_new RelExprNode( c,lhs.release(),rhs );
|
||||
lhs=new RelExprNode( c,lhs.release(),rhs );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ ExprNode *Parser::parseExpr3( bool opt ){
|
||||
int c=toker->curr();
|
||||
if( c!='+' && c!='-' ) return lhs.release();
|
||||
toker->next();ExprNode *rhs=parseExpr4( false );
|
||||
lhs=d_new ArithExprNode( c,lhs.release(),rhs );
|
||||
lhs=new ArithExprNode( c,lhs.release(),rhs );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,7 +583,7 @@ ExprNode *Parser::parseExpr4( bool opt ){
|
||||
int c=toker->curr();
|
||||
if( c!=SHL && c!=SHR && c!=SAR ) return lhs.release();
|
||||
toker->next();ExprNode *rhs=parseExpr5( false );
|
||||
lhs=d_new BinExprNode( c,lhs.release(),rhs );
|
||||
lhs=new BinExprNode( c,lhs.release(),rhs );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ ExprNode *Parser::parseExpr5( bool opt ){
|
||||
int c=toker->curr();
|
||||
if( c!='*' && c!='/' && c!=MOD ) return lhs.release();
|
||||
toker->next();ExprNode *rhs=parseExpr6( false );
|
||||
lhs=d_new ArithExprNode( c,lhs.release(),rhs );
|
||||
lhs=new ArithExprNode( c,lhs.release(),rhs );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,7 +607,7 @@ ExprNode *Parser::parseExpr6( bool opt ){
|
||||
int c=toker->curr();
|
||||
if( c!='^' ) return lhs.release();
|
||||
toker->next();ExprNode *rhs=parseUniExpr( false );
|
||||
lhs=d_new ArithExprNode( c,lhs.release(),rhs );
|
||||
lhs=new ArithExprNode( c,lhs.release(),rhs );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,46 +621,46 @@ ExprNode *Parser::parseUniExpr( bool opt ){
|
||||
case BBINT:
|
||||
if( toker->next()=='%' ) toker->next();
|
||||
result=parseUniExpr( false );
|
||||
result=d_new CastNode( result,Type::int_type );
|
||||
result=new CastNode( result,Type::int_type );
|
||||
break;
|
||||
case BBFLOAT:
|
||||
if( toker->next()=='#' ) toker->next();
|
||||
result=parseUniExpr( false );
|
||||
result=d_new CastNode( result,Type::float_type );
|
||||
result=new CastNode( result,Type::float_type );
|
||||
break;
|
||||
case BBSTR:
|
||||
if( toker->next()=='$' ) toker->next();
|
||||
result=parseUniExpr( false );
|
||||
result=d_new CastNode( result,Type::string_type );
|
||||
result=new CastNode( result,Type::string_type );
|
||||
break;
|
||||
case OBJECT:
|
||||
if( toker->next()=='.' ) toker->next();
|
||||
t=parseIdent();
|
||||
result=parseUniExpr( false );
|
||||
result=d_new ObjectCastNode( result,t );
|
||||
result=new ObjectCastNode( result,t );
|
||||
break;
|
||||
case BBHANDLE:
|
||||
toker->next();
|
||||
result=parseUniExpr( false );
|
||||
result=d_new ObjectHandleNode( result );
|
||||
result=new ObjectHandleNode( result );
|
||||
break;
|
||||
case BEFORE:
|
||||
toker->next();
|
||||
result=parseUniExpr( false );
|
||||
result=d_new BeforeNode( result );
|
||||
result=new BeforeNode( result );
|
||||
break;
|
||||
case AFTER:
|
||||
toker->next();
|
||||
result=parseUniExpr( false );
|
||||
result=d_new AfterNode( result );
|
||||
result=new AfterNode( result );
|
||||
break;
|
||||
case '+':case '-':case '~':case ABS:case SGN:
|
||||
toker->next();
|
||||
result=parseUniExpr( false );
|
||||
if( c=='~' ){
|
||||
result=d_new BinExprNode( XOR,result,d_new IntConstNode( -1 ) );
|
||||
result=new BinExprNode( XOR,result,new IntConstNode( -1 ) );
|
||||
}else{
|
||||
result=d_new UniExprNode( c,result );
|
||||
result=new UniExprNode( c,result );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -686,53 +686,53 @@ ExprNode *Parser::parsePrimary( bool opt ){
|
||||
break;
|
||||
case BBNEW:
|
||||
toker->next();t=parseIdent();
|
||||
result=d_new NewNode( t );
|
||||
result=new NewNode( t );
|
||||
break;
|
||||
case FIRST:
|
||||
toker->next();t=parseIdent();
|
||||
result=d_new FirstNode( t );
|
||||
result=new FirstNode( t );
|
||||
break;
|
||||
case LAST:
|
||||
toker->next();t=parseIdent();
|
||||
result=d_new LastNode( t );
|
||||
result=new LastNode( t );
|
||||
break;
|
||||
case BBNULL:
|
||||
result=d_new NullNode();
|
||||
result=new NullNode();
|
||||
toker->next();
|
||||
break;
|
||||
case INTCONST:
|
||||
result=d_new IntConstNode( atoi( toker->text() ) );
|
||||
result=new IntConstNode( atoi( toker->text() ) );
|
||||
toker->next();
|
||||
break;
|
||||
case FLOATCONST:
|
||||
result=d_new FloatConstNode( atof( toker->text() ) );
|
||||
result=new FloatConstNode( atof( toker->text() ) );
|
||||
toker->next();
|
||||
break;
|
||||
case STRINGCONST:
|
||||
t=toker->text();
|
||||
result=d_new StringConstNode( t.substr( 1,t.size()-2 ) );
|
||||
result=new StringConstNode( t.substr( 1,t.size()-2 ) );
|
||||
toker->next();
|
||||
break;
|
||||
case BINCONST:
|
||||
n=0;t=toker->text();
|
||||
for( k=1;k<t.size();++k ) n=(n<<1)|(t[k]=='1');
|
||||
result=d_new IntConstNode( n );
|
||||
result=new IntConstNode( n );
|
||||
toker->next();
|
||||
break;
|
||||
case HEXCONST:
|
||||
n=0;t=toker->text();
|
||||
for( k=1;k<t.size();++k ) n=(n<<4)|( isdigit(t[k]) ? t[k]&0xf : (t[k]&7)+9 );
|
||||
result=d_new IntConstNode( n );
|
||||
result=new IntConstNode( n );
|
||||
toker->next();
|
||||
break;
|
||||
case PI:
|
||||
result=d_new FloatConstNode( 3.1415926535897932384626433832795f );
|
||||
result=new FloatConstNode( 3.1415926535897932384626433832795f );
|
||||
toker->next();break;
|
||||
case BBTRUE:
|
||||
result=d_new IntConstNode( 1 );
|
||||
result=new IntConstNode( 1 );
|
||||
toker->next();break;
|
||||
case BBFALSE:
|
||||
result=d_new IntConstNode( 0 );
|
||||
result=new IntConstNode( 0 );
|
||||
toker->next();break;
|
||||
case IDENT:
|
||||
ident=toker->text();
|
||||
@@ -743,11 +743,11 @@ ExprNode *Parser::parsePrimary( bool opt ){
|
||||
a_ptr<ExprSeqNode> exprs( parseExprSeq() );
|
||||
if( toker->curr()!=')' ) exp( "')'" );
|
||||
toker->next();
|
||||
result=d_new CallNode( ident,tag,exprs.release() );
|
||||
result=new CallNode( ident,tag,exprs.release() );
|
||||
}else{
|
||||
//must be a var
|
||||
VarNode *var=parseVar( ident,tag );
|
||||
result=d_new VarExprNode( var );
|
||||
result=new VarExprNode( var );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -11,7 +11,7 @@ Environ *ProgNode::semant( Environ *e ){
|
||||
|
||||
StmtSeqNode::reset( stmts->file,file_lab );
|
||||
|
||||
a_ptr<Environ> env( d_new Environ( genLabel(),Type::int_type,0,e ) );
|
||||
a_ptr<Environ> env( new Environ( genLabel(),Type::int_type,0,e ) );
|
||||
|
||||
consts->proto( env->decls,env );
|
||||
structs->proto( env->typeDecls,env );
|
||||
@@ -75,7 +75,7 @@ void ProgNode::translate( Codegen *g,const vector<UserFunc> &usrfuncs ){
|
||||
//leave main program
|
||||
g->label( sem_env->funcLabel+"_leave" );
|
||||
t=deleteVars( sem_env );
|
||||
if( g->debug ) t=d_new TNode( IR_SEQ,call( "__bbDebugLeave" ),t );
|
||||
if( g->debug ) t=new TNode( IR_SEQ,call( "__bbDebugLeave" ),t );
|
||||
g->leave( t,0 );
|
||||
|
||||
//structs
|
||||
|
||||
+11
-11
@@ -94,7 +94,7 @@ void DimNode::semant(Environ *e) {
|
||||
} else {
|
||||
if (e->level > 0) ex("Array not found in main program");
|
||||
if (!t) t = Type::int_type;
|
||||
sem_type = d_new ArrayType(t, exprs->size());
|
||||
sem_type = new ArrayType(t, exprs->size());
|
||||
sem_decl = e->decls->insertDecl(ident, sem_type, DECL_ARRAY);
|
||||
e->types.push_back(sem_type);
|
||||
}
|
||||
@@ -255,7 +255,7 @@ void ExitNode::semant(Environ *e) {
|
||||
}
|
||||
|
||||
void ExitNode::translate(Codegen *g) {
|
||||
g->code(d_new TNode(IR_JUMP, 0, 0, sem_brk));
|
||||
g->code(new TNode(IR_JUMP, 0, 0, sem_brk));
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
@@ -340,7 +340,7 @@ void ForNode::translate(Codegen *g) {
|
||||
//execute the step part
|
||||
debug(nextPos, g);
|
||||
int op = ty == Type::int_type ? IR_ADD : IR_FADD;
|
||||
t = d_new TNode(op, var->load(g), stepExpr->translate(g));
|
||||
t = new TNode(op, var->load(g), stepExpr->translate(g));
|
||||
g->code(var->store(g, t));
|
||||
|
||||
//test for loop cond
|
||||
@@ -408,13 +408,13 @@ void ReturnNode::semant(Environ *e) {
|
||||
if (e->level > 0) {
|
||||
if (!expr) {
|
||||
if (e->returnType == Type::float_type) {
|
||||
expr = d_new FloatConstNode(0);
|
||||
expr = new FloatConstNode(0);
|
||||
} else if (e->returnType == Type::string_type) {
|
||||
expr = d_new StringConstNode("");
|
||||
expr = new StringConstNode("");
|
||||
} else if (e->returnType->structType()) {
|
||||
expr = d_new NullNode();
|
||||
expr = new NullNode();
|
||||
} else {
|
||||
expr = d_new IntConstNode(0);
|
||||
expr = new IntConstNode(0);
|
||||
}
|
||||
}
|
||||
expr = expr->semant(e);
|
||||
@@ -425,16 +425,16 @@ void ReturnNode::semant(Environ *e) {
|
||||
|
||||
void ReturnNode::translate(Codegen *g) {
|
||||
if (!expr) {
|
||||
g->code(d_new TNode(IR_RET, 0, 0));
|
||||
g->code(new TNode(IR_RET, 0, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
TNode *t = expr->translate(g);
|
||||
|
||||
if (expr->sem_type == Type::float_type) {
|
||||
g->code(d_new TNode(IR_FRETURN, t, 0, returnLabel));
|
||||
g->code(new TNode(IR_FRETURN, t, 0, returnLabel));
|
||||
} else {
|
||||
g->code(d_new TNode(IR_RETURN, t, 0, returnLabel));
|
||||
g->code(new TNode(IR_RETURN, t, 0, returnLabel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ void SelectNode::semant(Environ *e) {
|
||||
|
||||
//we need a temp var
|
||||
Decl *d = e->decls->insertDecl(genLabel(), expr->sem_type, DECL_LOCAL);
|
||||
sem_temp = d_new DeclVarNode(d);
|
||||
sem_temp = new DeclVarNode(d);
|
||||
|
||||
for (int k = 0; k < cases.size(); ++k) {
|
||||
CaseNode *c = cases[k];
|
||||
|
||||
Reference in New Issue
Block a user