Commit 4c8443d96d
Changed files (3)
src/ast_render.cpp
@@ -14,8 +14,8 @@
static const char *bin_op_str(BinOpType bin_op) {
switch (bin_op) {
case BinOpTypeInvalid: return "(invalid)";
- case BinOpTypeBoolOr: return "||";
- case BinOpTypeBoolAnd: return "&&";
+ case BinOpTypeBoolOr: return "or";
+ case BinOpTypeBoolAnd: return "and";
case BinOpTypeCmpEq: return "==";
case BinOpTypeCmpNotEq: return "!=";
case BinOpTypeCmpLessThan: return "<";
src/parsec.cpp
@@ -976,8 +976,7 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
case BO_GE:
return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpGreaterOrEq, stmt->getRHS());
case BO_EQ:
- emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_EQ");
- return nullptr;
+ return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpEq, stmt->getRHS());
case BO_NE:
emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_NE");
return nullptr;
@@ -991,11 +990,10 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Or");
return nullptr;
case BO_LAnd:
- emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_LAnd");
- return nullptr;
+ return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeBoolAnd, stmt->getRHS());
case BO_LOr:
- emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_LOr");
- return nullptr;
+ // 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");
test/parsec.zig
@@ -373,6 +373,22 @@ pub fn addCases(cases: &tests.ParseCContext) {
\\}
);
+ cases.add("logical and, logical or",
+ \\int max(int a, int b) {
+ \\ if (a < b || a == b)
+ \\ return b;
+ \\ if (a >= b && a == b)
+ \\ return a;
+ \\ return a;
+ \\}
+ ,
+ \\export fn max(a: c_int, b: c_int) -> c_int {
+ \\ if ((a < b) or (a == b)) return b;
+ \\ if ((a >= b) and (a == b)) return a;
+ \\ return a;
+ \\}
+ );
+
cases.add("shift right assign with a fixed size type",
\\#include <stdint.h>
\\int log2(uint32_t a) {