motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 33784871ec8d809d513193f5e24865059231b1f3 (tree)
parent f7cb77a02c2e32e9522b247e4653f1c03a677266
Author: Josh Wolfe <thejoshwolfe@gmail.com>
Date:   Wed, 20 Sep 2017 22:14:39 -0700

assign

Diffstat:
Msrc/parsec.cpp | 8+++++---
Mtest/parsec.zig | 12++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/parsec.cpp b/src/parsec.cpp @@ -995,9 +995,11 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo // TODO: int vs bool return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeBoolOr, stmt->getRHS()); case BO_Assign: - (void)result_used; - emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Assign"); - return nullptr; + if (result_used) { + emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Assign with result_used"); + return nullptr; + } + return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeAssign, stmt->getRHS()); case BO_MulAssign: emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_MulAssign"); return nullptr; diff --git a/test/parsec.zig b/test/parsec.zig @@ -415,6 +415,18 @@ pub fn addCases(cases: &tests.ParseCContext) { \\} ); + cases.add("assign", + \\int max(int a) { + \\ int tmp; + \\ tmp = a; + \\} + , + \\export fn max(a: c_int) -> c_int { + \\ var tmp: c_int; + \\ tmp = a; + \\} + ); + cases.add("shift right assign with a fixed size type", \\#include <stdint.h> \\int log2(uint32_t a) {