autodoc: Compare operators

This commit is contained in:
Der Teufel 2022-09-01 15:17:14 +02:00
parent 2b92c5a23e
commit 3bbf08e98a
2 changed files with 68 additions and 0 deletions

View File

@ -1405,6 +1405,30 @@ var zigAnalysis;
operator += "**"; operator += "**";
break; break;
} }
case "cmp_eq": {
operator += "==";
break;
}
case "cmp_neq": {
operator += "!=";
break;
}
case "cmp_gt": {
operator += ">";
break;
}
case "cmp_gte": {
operator += ">=";
break;
}
case "cmp_lt": {
operator += "<";
break;
}
case "cmp_lte": {
operator += "<=";
break;
}
default: default:
console.log("operator not handled yet or doesn't exist!"); console.log("operator not handled yet or doesn't exist!");
} }

View File

@ -1278,6 +1278,50 @@ fn walkInstruction(
.expr = .{ .binOpIndex = binop_index }, .expr = .{ .binOpIndex = binop_index },
}; };
}, },
// compare operators
.cmp_eq,
.cmp_neq,
.cmp_gt,
.cmp_gte,
.cmp_lt,
.cmp_lte,
=> {
const pl_node = data[inst_index].pl_node;
const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
const binop_index = self.exprs.items.len;
try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });
var lhs: DocData.WalkResult = try self.walkRef(
file,
parent_scope,
parent_line,
extra.data.lhs,
false,
);
var rhs: DocData.WalkResult = try self.walkRef(
file,
parent_scope,
parent_line,
extra.data.rhs,
false,
);
const lhs_index = self.exprs.items.len;
try self.exprs.append(self.arena, lhs.expr);
const rhs_index = self.exprs.items.len;
try self.exprs.append(self.arena, rhs.expr);
self.exprs.items[binop_index] = .{ .binOp = .{
.name = @tagName(tags[inst_index]),
.lhs = lhs_index,
.rhs = rhs_index,
} };
return DocData.WalkResult{
.typeRef = .{ .type = @enumToInt(Ref.bool_type) },
.expr = .{ .binOpIndex = binop_index },
};
},
// builtin functions // builtin functions
.align_of, .align_of,