Permalink
Browse files

Parser returns parenthesized operator strings.

  • Loading branch information...
1 parent ca50256 commit 517697ccd11f43506a6d2707cba7f34028f1fa75 Jeremy Clifford committed Mar 18, 2012
Showing with 17 additions and 24 deletions.
  1. +4 −8 compiler/src/codegen.cpp
  2. +1 −6 compiler/src/desugar.cpp
  3. +1 −5 compiler/src/evaluator.cpp
  4. +9 −3 compiler/src/parser.cpp
  5. +2 −2 lib-clay/deques/deques.clay
View
@@ -3619,18 +3619,14 @@ bool codegenStatement(StatementPtr stmt,
case UPDATE_ASSIGNMENT : {
UpdateAssignment *x = (UpdateAssignment *)stmt.ptr();
PValuePtr pvLeft = safeAnalyzeOne(x->left, env);
- string s;
- s.push_back('(');
- s.append(x->op);
- s.push_back(')');
if (x->left->exprKind == INDEXING) {
Indexing *y = (Indexing *)x->left.ptr();
PValuePtr pvIndexable = safeAnalyzeOne(y->expr, env);
if (pvIndexable->type->typeKind != STATIC_TYPE) {
CallPtr call = new Call(
operator_expr_indexUpdateAssign(), new ExprList()
);
- call->parenArgs->add(new NameRef(new Identifier(s)));
+ call->parenArgs->add(new NameRef(new Identifier(x->op)));
call->parenArgs->add(y->expr);
call->parenArgs->add(y->args);
call->parenArgs->add(x->right);
@@ -3642,7 +3638,7 @@ bool codegenStatement(StatementPtr stmt,
CallPtr call = new Call(
operator_expr_staticIndexUpdateAssign(), new ExprList()
);
- call->parenArgs->add(new NameRef(new Identifier(s)));
+ call->parenArgs->add(new NameRef(new Identifier(x->op)));
call->parenArgs->add(y->expr);
ValueHolderPtr vh = sizeTToValueHolder(y->index);
call->parenArgs->add(new StaticExpr(new ObjectExpr(vh.ptr())));
@@ -3656,15 +3652,15 @@ bool codegenStatement(StatementPtr stmt,
CallPtr call = new Call(
operator_expr_fieldRefUpdateAssign(), new ExprList()
);
- call->parenArgs->add(new NameRef(new Identifier(s)));
+ call->parenArgs->add(new NameRef(new Identifier(x->op)));
call->parenArgs->add(y->expr);
call->parenArgs->add(new ObjectExpr(y->name.ptr()));
call->parenArgs->add(x->right);
return codegenStatement(new ExprStatement(call.ptr()), env, ctx);
}
}
CallPtr call = new Call(operator_expr_updateAssign(), new ExprList());
- call->parenArgs->add(new NameRef(new Identifier(s)));
+ call->parenArgs->add(new NameRef(new Identifier(x->op)));
call->parenArgs->add(x->left);
call->parenArgs->add(x->right);
return codegenStatement(new ExprStatement(call.ptr()), env, ctx);
View
@@ -62,14 +62,9 @@ ExprPtr desugarVariadicOp(VariadicOpPtr x) {
ExprPtr callable = lookupCallable(x->op);
CallPtr call = new Call(callable, new ExprList());
if (x->op == OPERATOR) {
- string s;
call->parenArgs->add(x->exprs->exprs.front());
for (int i = 0; i < x->ops.size(); ++i) {
- s.clear();
- s.push_back('(');
- s.append(x->ops[i]);
- s.push_back(')');
- call->parenArgs->add(new NameRef(new Identifier(s)));
+ call->parenArgs->add(new NameRef(new Identifier(x->ops[i])));
call->parenArgs->add(x->exprs->exprs[i+1]);
}
}
@@ -2114,11 +2114,7 @@ TerminationPtr evalStatement(StatementPtr stmt,
if (pvLeft->isTemp)
error(x->left, "cannot assign to a temporary");
CallPtr call = new Call(operator_expr_updateAssign(), new ExprList());
- string s;
- s.push_back('(');
- s.append(x->op);
- s.push_back(')');
- call->parenArgs->add(new NameRef(new Identifier(s)));
+ call->parenArgs->add(new NameRef(new Identifier(x->op)));
call->parenArgs->add(x->left);
call->parenArgs->add(x->right);
return evalStatement(new ExprStatement(call.ptr()), env, ctx);
View
@@ -637,7 +637,13 @@ static bool operatorOp(string &op) {
if (opsymbol(*a)) return false;
restore(p);
}
- return opstring(op);
+ string x;
+ if (!opstring(x)) return false;
+ op.clear();
+ op.push_back('(');
+ op.append(x);
+ op.push_back(')');
+ return true;
}
@@ -664,7 +670,7 @@ static bool operatorTail(VariadicOpPtr &x) {
exprs->add(b);
}
- x = new VariadicOp(OPERATOR, ops ,exprs);
+ x = new VariadicOp(OPERATOR, ops, exprs);
x->location = location;
return true;
}
@@ -1182,7 +1188,7 @@ static bool initAssignment(StatementPtr &x) {
static bool updateopstring(string &op) {
int p = save();
const char *s[] = {"+=", "-=", "*=", "/=","\\=", "%=", "++=", NULL};
- const string ops[] = {"+", "-", "*", "/", "\\", "%", "++"};
+ const string ops[] = {"(+)", "(-)", "(*)", "(/)", "(\\)", "(%)", "(++)"};
for (const char **a = s; *a; ++a) {
restore(p);
if (opsymbol(*a)) {
@@ -44,7 +44,7 @@ record DequeCoordinate[T] (
dec(i.current);
}
-[T, I | Integer?(I)] overload updateAssign((+), ref i: DequeCoordinate[T], n: I) {
+[T, I | Integer?(I)] overload updateAssign(add, ref i: DequeCoordinate[T], n: I) {
i += PtrInt(n);
}
@@ -69,7 +69,7 @@ record DequeCoordinate[T] (
j += n;
}
-[T, I | Integer?(I)] overload updateAssign((-), ref i: DequeCoordinate[T], n: I) {
+[T, I | Integer?(I)] overload updateAssign(subtract, ref i: DequeCoordinate[T], n: I) {
i += -PtrInt(n);
}

0 comments on commit 517697c

Please sign in to comment.