Skip to content

Commit

Permalink
bugzilla 3378 [tdpl] ++x should be an lvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Bright committed Mar 6, 2010
1 parent 425b7d0 commit e8361e7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
51 changes: 51 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -5541,6 +5541,57 @@ Expression *BinAssignExp::commonSemanticAssignIntegral(Scope *sc)
return this;
}

#if DMDV2
int BinAssignExp::isLvalue()
{
return 1;
}

Expression *BinAssignExp::toLvalue(Scope *sc, Expression *ex)
{ Expression *e;

if (e1->op == TOKvar)
{
/* Convert (e1 op= e2) to
* e1 op= e2;
* e1
*/
e = e1->copy();
e = new CommaExp(loc, this, e);
e = e->semantic(sc);
}
else
{
/* Convert (e1 op= e2) to
* ref v = e1;
* v op= e2;
* v
*/

// ref v = e1;
Identifier *id = Lexer::uniqueId("__assignop");
ExpInitializer *ei = new ExpInitializer(loc, e1);
VarDeclaration *v = new VarDeclaration(loc, e1->type, id, ei);
v->storage_class |= STCref | STCforeach;
Expression *de = new DeclarationExp(loc, v);

// v op= e2
e1 = new VarExp(e1->loc, v);

e = new CommaExp(loc, de, this);
e = new CommaExp(loc, e, new VarExp(loc, v));
e = e->semantic(sc);
}
return e;
}

Expression *BinAssignExp::modifiableLvalue(Scope *sc, Expression *e)
{
return toLvalue(sc, this);
}

#endif

/************************************************************/

CompileExp::CompileExp(Loc loc, Expression *e)
Expand Down
4 changes: 4 additions & 0 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@ struct BinAssignExp : BinExp
Expression *commonSemanticAssignIntegral(Scope *sc);

Expression *op_overload(Scope *sc);

int isLvalue();
Expression *toLvalue(Scope *sc, Expression *ex);
Expression *modifiableLvalue(Scope *sc, Expression *e);
};

/****************************************************************/
Expand Down
8 changes: 6 additions & 2 deletions src/linux.mak
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DMD_OBJS = \
unialpha.o toobj.o toctype.o toelfdebug.o entity.o doc.o macro.o \
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
builtin.o clone.o aliasthis.o \
man.o arrayop.o port.o response.o async.o json.o \
man.o arrayop.o port.o response.o async.o json.o speller.o \
libelf.o elfobj.o

SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
Expand Down Expand Up @@ -80,7 +80,8 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
$(ROOT)/rmem.h $(ROOT)/rmem.c $(ROOT)/port.h $(ROOT)/port.c \
$(ROOT)/gnuc.h $(ROOT)/gnuc.c $(ROOT)/man.c \
$(ROOT)/stringtable.h $(ROOT)/stringtable.c \
$(ROOT)/response.c $(ROOT)/async.h $(ROOT)/async.c
$(ROOT)/response.c $(ROOT)/async.h $(ROOT)/async.c \
$(ROOT)/speller.h $(ROOT)/speller.c


all: dmd
Expand Down Expand Up @@ -433,6 +434,9 @@ s2ir.o : $C/rtlsym.h statement.h s2ir.c
scope.o: scope.c
$(CC) -c $(CFLAGS) $<

speller.o: $(ROOT)/speller.c
$(CC) -c $(GFLAGS) -I$(ROOT) $<

statement.o: statement.c
$(CC) -c $(CFLAGS) $<

Expand Down
8 changes: 6 additions & 2 deletions src/osx.mak
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DMD_OBJS = \
unialpha.o toobj.o toctype.o toelfdebug.o entity.o doc.o macro.o \
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
builtin.o clone.o aliasthis.o \
man.o arrayop.o port.o response.o async.o json.o \
man.o arrayop.o port.o response.o async.o json.o speller.o \
libmach.o machobj.o

SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
Expand Down Expand Up @@ -88,7 +88,8 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
$(ROOT)/rmem.h $(ROOT)/rmem.c $(ROOT)/port.h $(ROOT)/port.c \
$(ROOT)/gnuc.h $(ROOT)/gnuc.c $(ROOT)/man.c \
$(ROOT)/stringtable.h $(ROOT)/stringtable.c \
$(ROOT)/response.c $(ROOT)/async.h $(ROOT)/async.c
$(ROOT)/response.c $(ROOT)/async.h $(ROOT)/async.c \
$(ROOT)/speller.h $(ROOT)/speller.c


all: dmd
Expand Down Expand Up @@ -441,6 +442,9 @@ s2ir.o : $C/rtlsym.h statement.h s2ir.c
scope.o: scope.c
$(CC) -c $(CFLAGS) $<

speller.o: $(ROOT)/speller.c
$(CC) -c $(GFLAGS) -I$(ROOT) $<

statement.o: statement.c
$(CC) -c $(CFLAGS) $<

Expand Down

0 comments on commit e8361e7

Please sign in to comment.