From owner-p4-projects@FreeBSD.ORG Sat Aug 19 20:12:06 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D90C916A4DD; Sat, 19 Aug 2006 20:12:05 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8743F16A4F8 for ; Sat, 19 Aug 2006 20:12:05 +0000 (UTC) (envelope-from swhitman@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 48B5B43D76 for ; Sat, 19 Aug 2006 20:11:59 +0000 (GMT) (envelope-from swhitman@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k7JKBxwI096661 for ; Sat, 19 Aug 2006 20:11:59 GMT (envelope-from swhitman@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k7JKBwJY096658 for perforce@freebsd.org; Sat, 19 Aug 2006 20:11:58 GMT (envelope-from swhitman@FreeBSD.org) Date: Sat, 19 Aug 2006 20:11:58 GMT Message-Id: <200608192011.k7JKBwJY096658@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to swhitman@FreeBSD.org using -f From: Spencer Whitman To: Perforce Change Reviews Cc: Subject: PERFORCE change 104562 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Aug 2006 20:12:06 -0000 http://perforce.freebsd.org/chv.cgi?CH=104562 Change 104562 by swhitman@swhitman_joethecat on 2006/08/19 20:11:34 More work on macro replacment. Affected files ... .. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#18 edit Differences ... ==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#18 (text+ko) ==== @@ -191,49 +191,34 @@ fprintf(stderr, "PRAGMA: <%V>\n", String(b, e)); } -#if 0 - static const char * -replace_word(const char * word) { +replace_word(const char * word, const char * newend) { + /* XXX set new end to the end of the string */ struct define * tmp; TAILQ_FOREACH(tmp, &define, list) { - if (String(word,NULL) == (tmp->name)) { + if (word == (tmp->name)) { return (tmp->value); } } return word; } +/* Puts the begining of the first word from begin in s and the end in e */ +static void +grab_word(const char * begin, const char * end, const char * s, const char * e) +{ + const char * tmp; + s = e = NULL; + for(tmp = begin; tmp < end; tmp++) { + /* Find the first char of an identifier */ + /* Check if the identifier could be a macro */ + /* Stop if it can, continue if it can't */ + } -static const char * -expand_macro(struct define * mac, struct arg_ind * head) { - -} - - -static const char * -get_name(const char * word) { - const char e = strstr(word,"("); - if(e == NULL) - return word; - - return String(word,e); -} - -static const char * -get_arg(const char * word) { - const char e = NULL; } -static const char * -expand_string(const char * str) { - -} - -#endif - /* -------------------------------------------------------------------*/ static void @@ -244,16 +229,28 @@ assert(e != NULL); if (s == e) return; - - /* Expand any macros before passing String(s,e) to the lexer */ - - /* Search through and grab each word to test if it is a macro */ - for(;;) { - break; + + const char * curr; + const char * tempstart = NULL; + const char * tempend = NULL; + const char * new_end = NULL; + const char * new_word; + + for(curr = s; curr < e; curr++) { + /* Search through and grab each word to test if it is a macro */ + grab_word(curr,e,tempstart,tempend); + new_word = replace_word(String(tempstart,tempend), newend); + + if(new_word == tempstart) { /* Didn't macro expand, this string is ready to lex */ + D(0x10, "expand <%V>\n", String(s, e)); + Lexer(cfs->h->tokens, s, e); + } else /* We did some expansions. Re expand the expanded output */ + cpp_expand(cfs,rr,new_word,new_end); /* XXX This does not catch recursive macro's */ + /* XXX So #define FOO FOO will cause this to */ + /* XXX loop forever */ + curr = tempend; } - D(0x10, "expand <%V>\n", String(s, e)); - Lexer(cfs->h->tokens, s, e); } /* -------------------------------------------------------------------*/