changeset 19:b62230ea38f6

ifdef debug
author kono
date Mon, 03 Feb 2003 17:27:05 +0900
parents df7fa8cee67b
children 8d3db5fc8a97
files mc-parse.c mc.h stdio.h
diffstat 3 files changed, 66 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/mc-parse.c	Sat Feb 01 22:19:29 2003 +0900
+++ b/mc-parse.c	Mon Feb 03 17:27:05 2003 +0900
@@ -153,6 +153,7 @@
     }
     if (!chk)
 	if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR);
+printf("test\n");
     init();
     while(1) {	
 	for (nptr = &ntable[GSYMS],i=LSYMS; i--;) {
@@ -284,6 +285,9 @@
     reserve("register",REGISTER);
     reserve("code",CODE);
     reserve("environment",ENVIRONMENT);
+
+    reserve("__micro_c__",0);
+
     gpc=glineno=mflag=0;
     gfree=ilabel=1;
     labelno=2;
@@ -317,7 +321,12 @@
     if (cheapp+i >= cheap+CHEAPSIZE) error(STRERR);
     name[i++] = 0;
     (nptr = gsearch())->sc = RESERVE;
-    nptr->dsp = d;
+    if (d==0) {
+	nptr->sc = MACRO;
+	nptr->dsp = (int)"1";
+    } else {
+	nptr->dsp = d;
+    }
 }
 
 static
@@ -1699,7 +1708,10 @@
 	return(car(e)==CONST?list2(CONST,~cadr(e)):list2(BNOT,e));
     case LNOT:
 	getsym();
-	return(list2(LNOT,rvalue(expr13())));
+	e=rvalue(expr13());
+	if(!integral(type)) 
+	    error(TYERR);
+	return(car(e)==CONST?list2(CONST,!cadr(e)):list2(LNOT,e));
     case SIZEOF:
 	if(getsym()==LPAR) {
 	    if(typeid(getsym())) {	
@@ -2173,9 +2185,6 @@
 	    return getsym();
 	}
 	if (mode==IFDEF) {
-	    /* undo gsearch */
-	    nptr0->sc = 0;
-	    cheapp = nptr0->nm;
 	    return (symval=0);
 	}
 	if (nptr0->sc == RESERVE) return sym = nptr0->dsp;
@@ -2515,40 +2524,55 @@
     int mode_save;
 
     ++chptr;
-    if (macroeq("if")) {	
+    if (macroeq("ifdef") || macroeq("ifndef")) {
+	c = (chptr[-3]=='n');
 	macro_if_current++;
 	if (!macro_if_skip) {
+	    mode_save = mode; mode = IFDEF;
+	    ch= *chptr;
+	    i = getsym();
+	    mode = mode_save;
+	    macro_if_depth = macro_if_current;
+	    macro_if_skip = (!i)^c;
+	}
+fprintf(stderr,"macro ifdef %d %d %d %d %s\n",macro_if_skip,macro_if_current,macro_if_depth,lineno,linebuf);
+	return;
+    } else if (macroeq("if")) {	
+	macro_if_current++;
+	if (!macro_if_skip) {
+	    ch= *chptr;
 	    getsym();
 	    i=cexpr(expr());
 	    macro_if_depth = macro_if_current;
 	    macro_if_skip = !i;
 	}
-    } else if (macroeq("ifdef") || macroeq("ifndef")) {
-	c = (chptr[-4]=='n');
-	macro_if_current++;
-	if (!macro_if_skip) {
-	    mode_save = mode; mode = IFDEF;
-	    i = getsym();
-	    mode = mode_save;
-	    macro_if_depth = macro_if_current;
-	    macro_if_skip = (!i)^c;
-	}
+fprintf(stderr,"macro if    %d %d %d %d %s\n",macro_if_skip,macro_if_current,macro_if_depth,lineno,linebuf);
+	return;
     } else if (macroeq("else")) {	
 	if (macro_if_current==0) {
 	    error(MCERR); /* extra #else */
+	    return;
 	}
 	if (macro_if_current == macro_if_depth) 
 	    macro_if_skip = !macro_if_skip;
+fprintf(stderr,"macro else  %d %d %d %d %s\n",macro_if_skip,macro_if_current,macro_if_depth,lineno,linebuf);
+	return;
     } else if (macroeq("endif")) {	
 	if (macro_if_current == macro_if_depth) {
 	    macro_if_skip = 0;
+	    macro_if_depth = --macro_if_current;
 	} else {
-	    macro_if_current--;
-	    if (macro_if_current<0) {
+	    if (macro_if_current<=0) {
 		error(MCERR); /* extra #if */
+		return;
 	    }
+	    macro_if_current--;
 	}
-    } else if (macroeq("define")) {	
+fprintf(stderr,"macro endif %d %d %d %d %s\n",macro_if_skip,macro_if_current,macro_if_depth,lineno,linebuf);
+	return;
+    }
+    if (macro_if_skip) return;
+    if (macroeq("define")) {	
 	i=mode;
 	mode=GDECL;
 	ch= *chptr;
@@ -2561,11 +2585,21 @@
 		*cheapp++ = '\0';
 		if (cheapp >= cheap+CHEAPSIZE)
 		    error(STRERR);
-		if (!c) error(EOFERR);
+		/* if (!c) error(EOFERR); ???  #define hoge only case */
 	    } else error(MCERR);
 	} else error(MCERR);
 	mode=i;
 	*(chptr = linebuf) = '\0';
+    } else if (macroeq("undef")) {	
+	i=mode;
+	mode=GDECL;
+	ch= *chptr;
+	if (getsym() == IDENT) {	
+	    if (nptr->sc == MACRO) {	
+	        nptr->sc = EMPTY;
+	    } else error(MCERR);
+	}
+	mode=i;
     } else if (macroeq("include")) {	
 	if(filep+1 >= filestack + FILES) error(FILERR);
 	if ( ((filep+1)->fcb=getfname()) == NULL) error(FILERR);
--- a/mc.h	Sat Feb 01 22:19:29 2003 +0900
+++ b/mc.h	Mon Feb 03 17:27:05 2003 +0900
@@ -3,8 +3,11 @@
 #define DEBUG	error(-1)
 
 /*#include "CCLIB.TXT" */
-#include "stdio.h" 
-/* #include <stdio.h> */
+#ifdef __micro_c__
+#include "stdio.h"
+#else
+#include <stdio.h> 
+#endif
 
 #define SIZE_INT   4
 
--- a/stdio.h	Sat Feb 01 22:19:29 2003 +0900
+++ b/stdio.h	Mon Feb 03 17:27:05 2003 +0900
@@ -1,4 +1,6 @@
-/* #define const  */
+#ifdef __micro_c__
+#define const
+#endif
 
 typedef	struct {
 	/* this is all wrong, but so what? */
@@ -21,6 +23,7 @@
 #define	stdout	(&__sstdout)
 #define	stderr	(&__sstderr)
 #endif
+
 #define	BUFSIZ	1024		/* size of buffer used by setbuf */
 #define	EOF	(-1)
 #define	NULL	0
@@ -38,13 +41,16 @@
 int	 fgetpos(FILE *, fpos_t *);
 int	 fileno(FILE *);
 void	 flockfile();
+
 int	 fprintf(FILE *, const char *, ...);
 int	 fpurge();
 int	 fputc(int, FILE *);
 int	 fputs(const char *, FILE *);
 size_t	 fread(void *, size_t, size_t, FILE *);
 int	 fscanf(FILE *, const char *, ...);
+
 /* int	 fseek(FILE *, long int, int); */
+
 int	 fsetpos(FILE *, const fpos_t *);
 long	 ftell(FILE *);
 int	 ftrylockfile();