From owner-p4-projects@FreeBSD.ORG Tue Jul 25 15:27:52 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 C5C0316A4DE; Tue, 25 Jul 2006 15:27:52 +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 846B016A4DA for ; Tue, 25 Jul 2006 15:27:52 +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 389E243D49 for ; Tue, 25 Jul 2006 15:27:52 +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 k6PFRq6T065446 for ; Tue, 25 Jul 2006 15:27:52 GMT (envelope-from swhitman@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6PFRpFS065443 for perforce@freebsd.org; Tue, 25 Jul 2006 15:27:51 GMT (envelope-from swhitman@FreeBSD.org) Date: Tue, 25 Jul 2006 15:27:51 GMT Message-Id: <200607251527.k6PFRpFS065443@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 102377 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: Tue, 25 Jul 2006 15:27:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=102377 Change 102377 by swhitman@swhitman_joethecat on 2006/07/25 15:27:03 Minor additions to #define processing Affected files ... .. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#15 edit Differences ... ==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#15 (text+ko) ==== @@ -44,17 +44,12 @@ struct ref *r; }; -/* XXX These should be optimized, but work for now */ -/* Each argument has a list of indexes of where it appears in the macro string */ -struct arg_ind { - int offset; - TAILQ_ENTRY(arg_ind) list; -}; - +/* XXX This should be optimized, but works for now */ struct macro_arg { const char *name; /* Argument name */ - TAILQ_HEAD(,arg_ind) offsets; /* Offset list */ + int length /* Length of the arg name */ + int *offsets; /* Offset list */ TAILQ_ENTRY(macro_arg) list; /* Entry into the argument list */ }; @@ -66,11 +61,16 @@ int mac_type; /* Object or function like macro */ TAILQ_HEAD(,macro_arg) args; /* Head of argument list */ const char *value; /* Value of the macro */ + int length; /* Length of the macro value */ TAILQ_ENTRY(define) list; /* Link to list of macros */ }; -/* XXX Implement this */ -#define FREE_LIST(HEAD,TYPE) do { \ +#define FREE_LIST(HEAD,TYPE,LIST) do { \ + (TYPE) * tmpvar; \ + TAILQ_FOREACH(tmpvar, (HEAD), LIST) { \ + TAILQ_REMOVE(tmpvar, (HEAD), LIST); \ + free(tmpvar); \ + } \ }while(0) static TAILQ_HEAD(,iarg) iarg = TAILQ_HEAD_INITIALIZER(iarg); @@ -271,9 +271,9 @@ } static void -calculate_offsets(struct macro_arg *arg, struct define * mac __unused) +calculate_offsets(struct macro_arg *arg __unused, struct define * mac __unused) { - TAILQ_INIT(&arg->offsets); + /* XXX Use strstr to find substrings of arg in mac */ } @@ -303,6 +303,8 @@ } } + new_arg->length = strlen(new_arg->name); + calculate_offsets(new_arg,mac); printf("added argument named: <%V> to macro named <%V>\n",new_arg->name, @@ -394,7 +396,7 @@ /* Macro was ill-formed. Free everything and exit with error */ if(*p != ')') { - /* XXX Free everything */ + FREE_LIST(&mac->args, struct macro_args, list); free(mac); errx(1, "Function macro has no ending \')\'"); } @@ -405,13 +407,17 @@ break; } + mac->length = strlen(mac->value); + /* Add this macro to the defined list */ TAILQ_FOREACH(tmp, &define, list) { if(tmp == NULL) { TAILQ_INSERT_TAIL(&define, mac, list); break; } - + /* Warn if redefining a previous definition */ + if(tmp->name == mac->name) + cpp_warning(cfs,NULL,b,e); } }