diff -r 765ab1b672a3 -r 8a31742781c1 jitcraft/SemanticAnalysis.cpp --- a/jitcraft/SemanticAnalysis.cpp Sun Jul 01 16:36:39 2012 -0700 +++ b/jitcraft/SemanticAnalysis.cpp Sun Jul 01 18:21:15 2012 -0700 @@ -211,30 +211,46 @@ return left; } +Type * +SemanticAnalysis::visitForLValue(Expression *expression) +{ + if (expression->isIndexExpression()) { + expression->accept(this); + if (!expression->type()) + return NULL; + return expression->type()->contained(); + } + + if (!expression->isNameProxy()) { + assert(false); + return NULL; + } + + NameProxy *proxy = expression->toNameProxy(); + if (!proxy->binding()->kind() == BoundName::VARIABLE) { + fprintf(stderr, "error\n"); + return NULL; + } + + Variable *var = proxy->binding()->toVariable(); + if (!var->type()) + return NULL; + + if (var->type()->isReference()) + return var->type()->contained(); + return var->type(); +} + void SemanticAnalysis::visit(Assignment *node) { visitForLoad(node->expression()); - if (node->lvalue()->isIndexExpression()) { - node->lvalue()->accept(this); - node->setType(node->lvalue()->type()->contained()); - } else { - NameProxy *proxy = node->lvalue()->toNameProxy(); - if (!proxy->binding()->kind() == BoundName::VARIABLE) { - fprintf(stderr, "error\n"); - return; - } - - Variable *var = proxy->binding()->toVariable(); - if (!var->type()) - return; - - if (var->type()->isReference()) - node->setType(var->type()->contained()); - else - node->setType(var->type()); - } + // :TODO: use Local + Type *type = visitForLValue(node->lvalue()); + if (!type) + return; + node->setType(type); if (node->token() != TOK_ASSIGN) assert(TypeCheckBinary(node->token(), node->type(), node->expression()->type())); @@ -243,6 +259,25 @@ } void +SemanticAnalysis::visit(IncDecExpression *node) +{ + // :TODO: use Local + Type *type = visitForLValue(node->expression()); + if (!type) + return; + + assert(!type->isReference()); + if (type->isArray()) { + // can't a[]++ + assert(false); + return; + } + + assert((type->isInt32() && !type->tag()) || type->isFloat()); + node->setType(type); +} + +void SemanticAnalysis::visit(BinaryExpression *node) { // :TODO: use Local