shithub: scc

Download patch

ref: 27a96ef16da16b72fd0917120f5235f4fa9d94e9
parent: 09c14bf22ea534174eb70df46456ad5a19d042a6
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Jun 4 16:58:10 EDT 2012

Added support for qualifiers in the type base

--- a/decl.c
+++ b/decl.c
@@ -79,10 +79,10 @@
 
 static struct type *specifier(void)
 {
-	static char sign, sclass, tqlf, nt;
-	struct type *t;
+	auto unsigned char sign, sclass, tqlf, nt;
+	auto struct type *t;
 
-repeat:
+	puts("especifier");
 	t = NULL;
 	tqlf = sign = sclass = 0;
 	for (;; next()) {
@@ -92,9 +92,18 @@
 				error("Two or more storage specifier");
 			sclass = yytoken;
 			continue;
-		case CONST: case VOLATILE: case RESTRICTED:
-			/* TODO */
+		case CONST:
+			if (!(tqlf ^= T_CONST))
+				goto duplicated_qlf;
 			continue;
+		case RESTRICTED:
+			if (!(tqlf ^= T_RESTRICTED))
+				goto duplicated_qlf;
+			continue;
+		case VOLATILE:
+			if (!(tqlf ^= T_VOLATILE))
+				goto duplicated_qlf;
+			continue;
 		case VOID:   nt = F_VOID;   goto check_type;
 		case CHAR:   nt = F_CHAR;   goto check_type;
 		case SHORT:  nt = F_SHORT;  goto check_type;
@@ -116,6 +125,20 @@
 		case UNION:	/* TODO */
 		case ENUM:	/* TODO */
 		default:
+			if (tqlf) {
+				if (t == NULL) {
+					warning_error(user_opt.implicit_int,
+						      "type defaults to 'int' "
+						      "in declaration of '%s'",
+						      yytext);
+					t = T_INT;
+				}
+				if (tqlf & T_CONST)	  pushtype(CONST);
+				if (tqlf & T_RESTRICTED)  pushtype(RESTRICTED);
+				if (tqlf & T_VOLATILE)	  pushtype(VOLATILE);
+				t = decl_type(t);
+			}
+			puts("leaving especifier");
 			return t;
 		}
 	check_type:
@@ -144,6 +167,8 @@
 			goto incorrect_sign;
 		}
 	}
+duplicated_qlf:
+	error("duplicated '%s'", yytext);
 two_or_more_btype:
 	error("two or more basic types");
 incorrect_sign:
@@ -173,15 +198,15 @@
 	repeat_qlf:
 		switch (next()) {
 		case CONST:
-			if (!(*bp ^= 1))
+			if (!(*bp ^= T_CONST))
 				goto duplicated;
 			goto repeat_qlf;
 		case RESTRICTED:
-			if (!(*bp ^= 2))
+			if (!(*bp ^= T_RESTRICTED))
 				goto duplicated;
 			goto repeat_qlf;
 		case VOLATILE:
-			if (!(*bp ^= 4))
+			if (!(*bp ^= T_VOLATILE))
 				goto duplicated;
 			goto repeat_qlf;
 		default:
@@ -195,9 +220,9 @@
 	dirdcl();
 
 	while (bp-- != qlf) {
-		if (*bp & 1)  pushtype(CONST);
-		if (*bp & 2)  pushtype(RESTRICTED);
-		if (*bp & 4)  pushtype(VOLATILE);
+		if (*bp & T_CONST)	 pushtype(CONST);
+		if (*bp & T_RESTRICTED)  pushtype(RESTRICTED);
+		if (*bp & T_VOLATILE)	 pushtype(VOLATILE);
 		pushtype(PTR);
 	}
 
--- a/types.h
+++ b/types.h
@@ -44,6 +44,9 @@
 #define ARY		1
 #define PTR		2
 #define FTN		3
+#define T_CONST		1
+#define T_RESTRICTED	2
+#define T_VOLATILE	4
 
 #define QLF(x)   (VOLATILE - x + 1)