authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-09-20 21:37:56-07:00
committergravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-09-20 21:37:56-07:00
log4c8443d96db4a441b393ea0c3c8d76a7493f46d0
treec608163493a3329e1e8b82e0e1b83c2fcb76e610
parent05c1a8b3cc09860052c7dba2a795ada5f7e00811

logical and, logical or


3 files changed, 22 insertions(+), 8 deletions(-)

src/ast_render.cpp+2-2
......@@ -14,8 +14,8 @@
1414static const char *bin_op_str(BinOpType bin_op) {
1515 switch (bin_op) {
1616 case BinOpTypeInvalid: return "(invalid)";
17 case BinOpTypeBoolOr: return "||";
18 case BinOpTypeBoolAnd: return "&&";
17 case BinOpTypeBoolOr: return "or";
18 case BinOpTypeBoolAnd: return "and";
1919 case BinOpTypeCmpEq: return "==";
2020 case BinOpTypeCmpNotEq: return "!=";
2121 case BinOpTypeCmpLessThan: return "<";
src/parsec.cpp+4-6
......@@ -976,8 +976,7 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
976976 case BO_GE:
977977 return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpGreaterOrEq, stmt->getRHS());
978978 case BO_EQ:
979 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_EQ");
980 return nullptr;
979 return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpEq, stmt->getRHS());
981980 case BO_NE:
982981 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_NE");
983982 return nullptr;
......@@ -991,11 +990,10 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
991990 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Or");
992991 return nullptr;
993992 case BO_LAnd:
994 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_LAnd");
995 return nullptr;
993 return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeBoolAnd, stmt->getRHS());
996994 case BO_LOr:
997 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_LOr");
998 return nullptr;
995 // TODO: int vs bool
996 return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeBoolOr, stmt->getRHS());
999997 case BO_Assign:
1000998 (void)result_used;
1001999 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Assign");
test/parsec.zig+16
......@@ -373,6 +373,22 @@ pub fn addCases(cases: &tests.ParseCContext) {
373373 \\}
374374 );
375375
376 cases.add("logical and, logical or",
377 \\int max(int a, int b) {
378 \\ if (a < b || a == b)
379 \\ return b;
380 \\ if (a >= b && a == b)
381 \\ return a;
382 \\ return a;
383 \\}
384 ,
385 \\export fn max(a: c_int, b: c_int) -> c_int {
386 \\ if ((a < b) or (a == b)) return b;
387 \\ if ((a >= b) and (a == b)) return a;
388 \\ return a;
389 \\}
390 );
391
376392 cases.add("shift right assign with a fixed size type",
377393 \\#include <stdint.h>
378394 \\int log2(uint32_t a) {