Mercurial > hg > CbC > old > device
changeset 923:080d87432ff3
macro fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 11 Apr 2014 20:02:17 +0900 |
parents | 3cdc3c1d83bd |
children | bd9bd4ba2f1c 2ec436d10c65 |
files | mc-macro.c mc-parse.c |
diffstat | 2 files changed, 21 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-macro.c Fri Apr 11 19:41:24 2014 +0900 +++ b/mc-macro.c Fri Apr 11 20:02:17 2014 +0900 @@ -882,6 +882,22 @@ return reverse0(args); } +extern int current_scope; + +char * +shallow_scope(int scope, char *name) +{ + scope = car(scope); + for(int i = scope;i;i = cadr(i)) { + NMTBL *n = ncaddr(i); + if (!neqname(name,n->nm)) { + return ncaddr(car(i))->nm; + } + } + return name; +} + + /* output macro expansion This is a recursive interpreter. @@ -913,10 +929,12 @@ // define all arguments locally // #define arg0 arg0_value // #define arg1 arg2_value .... + int upper = current_scope; enter_scope(); while(args) { mappend0(reverse0(car(evalues)),¯o); - local_define(scaddr(args),macro, scaddr(values)); + char *shallow = shallow_scope(upper,scaddr(values)); + local_define(scaddr(args),macro, shallow); args = cadr(args); evalues = cadr(evalues); values = cadr(values);
--- a/mc-parse.c Fri Apr 11 19:41:24 2014 +0900 +++ b/mc-parse.c Fri Apr 11 20:02:17 2014 +0900 @@ -72,7 +72,8 @@ static struct cheap *nptr_pool,*nptr_pool0; static NMTBL *free_nptr_list; -static int current_scope; // scope unwinder +extern int current_scope; // scope unwinder +int current_scope; // scope unwinder int attribute; // current attribte list