shithub: scc

Download patch

ref: d1c3a0d77670defbdac8bc39a5182170934d8063
parent: 813b9848feb7c50708fee6fd00f006a85ca4779e
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Mar 30 16:25:37 EDT 2014

Fix bool type

It is easier considerer bool as int with size 0.

--- a/expr.c
+++ b/expr.c
@@ -56,9 +56,9 @@
 	t1 = tp1->op, t2 = tp2->op;
 
 	switch (t1) {
-	case BOOL: case INT:
+	case INT:
 		switch (t2) {
-		case BOOL: case INT:
+		case INT:
 			if (tp1 != tp2)
 				intconv(&np1, &np2);
 			break;
@@ -79,7 +79,7 @@
 			if (tp1 != tp2)
 				floatconv(&np1, &np2);
 			break;
-		case BOOL: case INT:
+		case INT:
 int_float:		np2 = unarycode(OCAST, np1->type, np2);
 			break;
 		default:
--- a/types.c
+++ b/types.c
@@ -13,6 +13,9 @@
 	*voidtype = &(Type) {
 		.op = VOID
 	},
+	*booltype = &(Type) {
+		.op = INT,
+	},
 	*uchartype = &(Type) {
 		.op = INT,
 		.size = CHARSIZE,
@@ -38,7 +41,7 @@
 	},
 	*shortype = &(Type) {
 		.op = INT,
-		.size = INTSIZE,
+		.size = SHORTSIZE,
 	},
 	*longtype = &(Type) {
 		.op = INT,
@@ -113,6 +116,7 @@
 
 	switch (type) {
 	case VOID:                      return voidtype;
+	case BOOL:                      return booltype;
 	case CHAR:                      return (sign) ? uchartype  : chartype;
 	case INT: switch (size) {
 		case 0:                 return (sign) ? uinttype   : inttype;