22 lines
660 B
C
22 lines
660 B
C
#include"commutativity.h"
|
|
|
|
#include"ast.h"
|
|
|
|
static void commutativity_visitor(AST **nptr, AST *stmt, AST *stmtPrev, AST *chunk, AST *tlc, void *ud) {
|
|
AST *n = *nptr;
|
|
|
|
if(n->nodeKind == AST_EXPR_BINARY_OP) {
|
|
if(binop_is_commutative(n->exprBinOp.operator)) {
|
|
if(n->exprBinOp.operands[0]->nodeKind == AST_EXPR_PRIMITIVE && n->exprBinOp.operands[1]->nodeKind != AST_EXPR_PRIMITIVE) {
|
|
AST *tmp = n->exprBinOp.operands[0];
|
|
n->exprBinOp.operands[0] = n->exprBinOp.operands[1];
|
|
n->exprBinOp.operands[1] = tmp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void ast_commutativity_pass(AST *tlc) {
|
|
generic_visitor(&tlc, NULL, NULL, tlc, tlc, NULL, NULL, commutativity_visitor);
|
|
}
|
|
|