diff --git a/src/cpp.c b/src/cpp.c index d41242516c2f92499ee7bbd396ad8f0f55626b8b..346e16603fe82aea7a1d926f8130eff653f5b903 100644 --- a/src/cpp.c +++ b/src/cpp.c @@ -118,7 +118,7 @@ struct define struct define_part parts[1]; }; -#define find_define(N) \ +#define FIND_DEFINE(N) \ (this->defines?BASEOF(hash_lookup(this->defines, N), define, link):0) struct cpp @@ -866,7 +866,7 @@ static void check_defined(struct cpp *this, struct pike_string *s = NULL; PCHARP x = MKPCHARP(args[0].arg.ptr,args[0].arg.shift); s = binary_findstring_pcharp( x, args[0].len ); - if(s && find_define(s)) + if(s && FIND_DEFINE(s)) { string_builder_binary_strcat(tmp, " 1 ", 3); }else{ @@ -1079,7 +1079,7 @@ static p_wchar2 readchar( PCHARP data, ptrdiff_t *pos, struct cpp *this ) } -static ptrdiff_t readstring( struct cpp *this, PCHARP data, ptrdiff_t len, ptrdiff_t pos, +static ptrdiff_t readstring( struct cpp *this, const PCHARP data, ptrdiff_t len, ptrdiff_t pos, struct string_builder*nf, int nl_ok) { while(1) @@ -1131,8 +1131,8 @@ static ptrdiff_t readstring( struct cpp *this, PCHARP data, ptrdiff_t len, ptrdi return pos; } -static ptrdiff_t fixstring(struct cpp *this,PCHARP data,ptrdiff_t len, - ptrdiff_t pos,struct string_builder*nf, int outp) +static ptrdiff_t fixstring(struct cpp *this, const PCHARP data, ptrdiff_t len, + ptrdiff_t pos, struct string_builder *nf, int outp) { int trailing_newlines=0; if(outp) string_builder_putchar(nf, '"'); @@ -1180,7 +1180,8 @@ static ptrdiff_t fixstring(struct cpp *this,PCHARP data,ptrdiff_t len, return pos; } -static ptrdiff_t find_end_of_line( struct cpp *this, PCHARP data, ptrdiff_t len, ptrdiff_t pos, int emit) +static ptrdiff_t find_end_of_line( struct cpp *this, const PCHARP data, + ptrdiff_t len, ptrdiff_t pos, int emit ) { while(pos < len) { switch (INDEX_PCHARP(data,pos++)) { @@ -1204,7 +1205,8 @@ static ptrdiff_t find_end_of_line( struct cpp *this, PCHARP data, ptrdiff_t len, } -static ptrdiff_t find_end_of_comment( struct cpp *this, PCHARP data, ptrdiff_t len,ptrdiff_t pos, int emit) +static ptrdiff_t find_end_of_comment( struct cpp *this, const PCHARP data, ptrdiff_t len, + ptrdiff_t pos, int emit) { pos++; @@ -1230,7 +1232,8 @@ static ptrdiff_t find_end_of_comment( struct cpp *this, PCHARP data, ptrdiff_t l return pos + 2; } -static ptrdiff_t find_end_of_string2( struct cpp *this, PCHARP data, ptrdiff_t len, ptrdiff_t pos) +static ptrdiff_t find_end_of_string2( struct cpp *this, const PCHARP data, + ptrdiff_t len, ptrdiff_t pos) { while(1) { @@ -1263,7 +1266,8 @@ static ptrdiff_t find_end_of_string2( struct cpp *this, PCHARP data, ptrdiff_t l } -static ptrdiff_t find_end_of_string( struct cpp *this, PCHARP data, ptrdiff_t len, ptrdiff_t pos) +static ptrdiff_t find_end_of_string( struct cpp *this, const PCHARP data, + ptrdiff_t len, ptrdiff_t pos) { while(1) { @@ -1296,7 +1300,7 @@ static ptrdiff_t find_end_of_string( struct cpp *this, PCHARP data, ptrdiff_t le return pos; } -static ptrdiff_t find_end_of_char( struct cpp *this, PCHARP data, ptrdiff_t len, ptrdiff_t pos) +static ptrdiff_t find_end_of_char( struct cpp *this, const PCHARP data, ptrdiff_t len, ptrdiff_t pos) { int e=0; while(1) @@ -1559,7 +1563,7 @@ static void undefine(struct cpp *this, INT32 e; struct define *d; - d=find_define(name); + d=FIND_DEFINE(name); if(!d) return; @@ -1967,9 +1971,8 @@ static void free_one_define(struct hash_entry *h) * Generic macros */ -#define STRCAT(X,Y) _STRCAT(X,Y,flags,this) -#define CHECKWORD2(X,LEN) (begins_with(X,ADD_PCHARP(data,pos),(LEN),len-pos,1)) -#define WGOBBLE2(X) (CHECKWORD2(X,NELEM(X)) ? (pos+=NELEM(X)),1 : 0) +#define CHECK_WORD(X,LEN) (begins_with(X,ADD_PCHARP(data,pos),(LEN),len-pos,1)) +#define GOBBLE_WORD(X) (CHECK_WORD(X,NELEM(X)) ? (pos+=NELEM(X)),1 : 0) #define FIND_END_OF_STRING() (pos=find_end_of_string(this,data,len,pos)) #define FIND_END_OF_STRING2() (pos=find_end_of_string2(this,data,len,pos)) #define FIND_END_OF_CHAR() (pos=find_end_of_char(this,data,len,pos)) @@ -1997,7 +2000,7 @@ static void free_one_define(struct hash_entry *h) #define GOBBLE_IDENTIFIER() dmalloc_touch (struct pike_string *, gobble_identifier(this,data,&pos)) #define READCHAR(C) (C=readchar(data,&pos,this)) #define DATA(X) INDEX_PCHARP(data,X) -#define GOBBLEOP2(X) \ +#define HAS_PREFIX(X) \ ((begins_with(X,ADD_PCHARP(data,pos),sizeof(X),len-pos,0)) ? (pos += NELEM(X)),1 : 0) @@ -2045,7 +2048,7 @@ static ptrdiff_t find_eos( struct cpp *this, PCHARP data, ptrdiff_t len, ptrdiff return pos; } -static ptrdiff_t skipwhite(struct cpp *this,PCHARP data, ptrdiff_t pos) +static ptrdiff_t skipwhite(struct cpp *this, PCHARP data, ptrdiff_t pos) { do { @@ -2079,7 +2082,7 @@ static ptrdiff_t skipwhite(struct cpp *this,PCHARP data, ptrdiff_t pos) return pos; } -static ptrdiff_t skipspace(struct cpp *this,PCHARP data, ptrdiff_t pos, int emit) +static ptrdiff_t skipspace(struct cpp *this, PCHARP data, ptrdiff_t pos, int emit) { do { int c; @@ -2107,17 +2110,6 @@ static ptrdiff_t skipspace(struct cpp *this,PCHARP data, ptrdiff_t pos, int emit return pos; } -static void _STRCAT(char *str, int len, int flags,struct cpp *this) -{ - ptrdiff_t x; - if(OUTP()) - string_builder_binary_strcat(&this->buf, str, len); - else - for(x=0;x<len;x++) - if(str[x]=='\n') - string_builder_putchar(&this->buf, '\n'); -} - static const char eq_[] = { '=', '=' }; static const char ne_[] = { '!', '=' }; static const char land_[] = { '&', '&' }; @@ -2531,7 +2523,7 @@ static ptrdiff_t calc8(struct cpp *this, PCHARP data, ptrdiff_t len, { CALC_DUMPPOS("inside calc8"); SKIPWHITE(); - if(GOBBLEOP2(lsh_)) + if(HAS_PREFIX(lsh_)) { CALC_DUMPPOS("Found <<"); pos=calc9(this,data,len,pos,flags); @@ -2540,7 +2532,7 @@ static ptrdiff_t calc8(struct cpp *this, PCHARP data, ptrdiff_t len, break; } - if(GOBBLEOP2(rsh_)) + if(HAS_PREFIX(rsh_)) { CALC_DUMPPOS("Found >>"); pos=calc9(this,data,len,pos,flags); @@ -2616,7 +2608,7 @@ static ptrdiff_t calc7(struct cpp *this, PCHARP data, ptrdiff_t len, CALC_DUMPPOS("inside calc7"); SKIPWHITE(); - if(GOBBLEOP2(eq_)) + if(HAS_PREFIX(eq_)) { pos=calc7b(this,data,len,pos,flags); if(OUTP()) @@ -2624,7 +2616,7 @@ static ptrdiff_t calc7(struct cpp *this, PCHARP data, ptrdiff_t len, continue; } - if(GOBBLEOP2(ne_)) + if(HAS_PREFIX(ne_)) { pos=calc7b(this,data,len,pos,flags); if(OUTP()) @@ -2704,7 +2696,7 @@ static ptrdiff_t calc3(struct cpp *this, PCHARP data, ptrdiff_t len, pos=calc4(this,data,len,pos,flags); SKIPWHITE(); - while(GOBBLEOP2(land_)) + while(HAS_PREFIX(land_)) { CALC_DUMPPOS("inside calc3"); @@ -2732,7 +2724,7 @@ static ptrdiff_t calc2(struct cpp *this, PCHARP data, ptrdiff_t len, pos=calc3(this,data,len,pos,flags); SKIPWHITE(); - while(GOBBLEOP2(lor_)) + while(HAS_PREFIX(lor_)) { CALC_DUMPPOS("inside calc2"); diff --git a/src/preprocessor.h b/src/preprocessor.h index 59cfd8105a7d36e3dd305231920350c6960c770c..7826de5f6de936946bb0052528f4f308ded6bcd6 100644 --- a/src/preprocessor.h +++ b/src/preprocessor.h @@ -131,7 +131,7 @@ static ptrdiff_t low_cpp(struct cpp *this, */ d = defined_macro; }else{ - d=find_define(s); + d=FIND_DEFINE(s); } if(d && !(d->inside & 1)) @@ -408,7 +408,7 @@ static ptrdiff_t low_cpp(struct cpp *this, if(s) { - if((d=find_define(s))) + if((d=FIND_DEFINE(s))) d->inside = inside; free_string(s); @@ -479,8 +479,8 @@ static ptrdiff_t low_cpp(struct cpp *this, } SKIPSPACE(); - if (!CHECKWORD2(string_recur_, NELEM(string_recur_)) - && !CHECKWORD2(include_recur_, NELEM(include_recur_))) + if (!CHECK_WORD(string_recur_, NELEM(string_recur_)) + && !CHECK_WORD(include_recur_, NELEM(include_recur_))) { if (this->prefix) { @@ -508,7 +508,7 @@ static ptrdiff_t low_cpp(struct cpp *this, { case 'l': { - if(WGOBBLE2(line_)) + if(GOBBLE_WORD(line_)) { /* FIXME: Why not use SKIPSPACE()? */ /* Because SKIPSPACE skips newlines? - Hubbe */ @@ -577,12 +577,12 @@ static ptrdiff_t low_cpp(struct cpp *this, case 's': { - if(WGOBBLE2(string_)) + if(GOBBLE_WORD(string_)) { include_mode = 1; goto do_include; } - if(WGOBBLE2(string_recur_)) + if(GOBBLE_WORD(string_recur_)) { include_mode = 3; goto do_include; @@ -594,7 +594,7 @@ static ptrdiff_t low_cpp(struct cpp *this, { int recur = 0; - if(WGOBBLE2(include_) || (recur = WGOBBLE2(include_recur_))) + if(GOBBLE_WORD(include_) || (recur = GOBBLE_WORD(include_recur_))) { if (recur) { include_mode = 2; @@ -814,7 +814,7 @@ static ptrdiff_t low_cpp(struct cpp *this, } } - if(WGOBBLE2(if_)) + if(GOBBLE_WORD(if_)) { struct string_builder save, tmp; INT32 nflags = 0; @@ -848,7 +848,7 @@ static ptrdiff_t low_cpp(struct cpp *this, break; } - if(WGOBBLE2(ifdef_)) + if(GOBBLE_WORD(ifdef_)) { INT32 nflags; struct pike_string *s; @@ -862,7 +862,7 @@ static ptrdiff_t low_cpp(struct cpp *this, if(!OUTP()) nflags|=CPP_REALLY_NO_OUTPUT; if (s) { - if(find_define(s)) + if(FIND_DEFINE(s)) nflags&=~CPP_NO_OUTPUT; free_string (s); } @@ -872,7 +872,7 @@ static ptrdiff_t low_cpp(struct cpp *this, break; } - if(WGOBBLE2(ifndef_)) + if(GOBBLE_WORD(ifndef_)) { INT32 nflags; struct pike_string *s; @@ -886,7 +886,7 @@ static ptrdiff_t low_cpp(struct cpp *this, if(!OUTP()) nflags|=CPP_REALLY_NO_OUTPUT; if (s) { - if(find_define(s)) + if(FIND_DEFINE(s)) nflags|=CPP_NO_OUTPUT; free_string (s); } @@ -900,7 +900,7 @@ static ptrdiff_t low_cpp(struct cpp *this, } case 'e': /* endif, else, elif, error */ { - if(WGOBBLE2(endif_)) + if(GOBBLE_WORD(endif_)) { if(!(flags & CPP_EXPECT_ENDIF)) cpp_error(this, "Unmatched #endif."); @@ -908,7 +908,7 @@ static ptrdiff_t low_cpp(struct cpp *this, return pos; } - if(WGOBBLE2(else_)) + if(GOBBLE_WORD(else_)) { if(!(flags & CPP_EXPECT_ELSE)) cpp_error(this, "Unmatched #else."); @@ -924,7 +924,7 @@ static ptrdiff_t low_cpp(struct cpp *this, break; } - if(WGOBBLE2(elif_) || WGOBBLE2(elseif_)) + if(GOBBLE_WORD(elif_) || GOBBLE_WORD(elseif_)) { if(!(flags & CPP_EXPECT_ELSE)) cpp_error(this, "Unmatched #elif."); @@ -956,7 +956,7 @@ static ptrdiff_t low_cpp(struct cpp *this, break; } - if(WGOBBLE2(error_)) + if(GOBBLE_WORD(error_)) { ptrdiff_t foo; @@ -976,7 +976,7 @@ static ptrdiff_t low_cpp(struct cpp *this, case 'd': /* define */ { - if(WGOBBLE2(define_)) + if(GOBBLE_WORD(define_)) { struct string_builder str; INT32 argno=-1; @@ -1234,7 +1234,7 @@ static ptrdiff_t low_cpp(struct cpp *this, #endif { struct define *d; - if ((d = find_define(def->link.s)) && (d->inside)) { + if ((d = FIND_DEFINE(def->link.s)) && (d->inside)) { cpp_error(this, "Illegal to redefine a macro during its expansion."); free_one_define(&(def->link)); @@ -1255,7 +1255,7 @@ static ptrdiff_t low_cpp(struct cpp *this, { /* NOTE: Reuses undefine_ for undef_ */ - if(WGOBBLE2(undefine_) || WGOBBLE2(undef_)) + if(GOBBLE_WORD(undefine_) || GOBBLE_WORD(undef_)) { struct pike_string *s; SKIPSPACE(); @@ -1277,7 +1277,7 @@ static ptrdiff_t low_cpp(struct cpp *this, case 'c': /* charset */ { - if (WGOBBLE2(charset_)) { + if (GOBBLE_WORD(charset_)) { ptrdiff_t p; struct pike_string *s; @@ -1324,15 +1324,15 @@ static ptrdiff_t low_cpp(struct cpp *this, case 'p': /* pragma */ { - if(WGOBBLE2(pragma_)) + if(GOBBLE_WORD(pragma_)) { if(OUTP()) - STRCAT("#pragma", 7); + string_builder_strcat(&this->buf, "#pragma"); else FIND_EOL(); break; } - if(WGOBBLE2(pike_)) + if(GOBBLE_WORD(pike_)) { if(OUTP()) { @@ -1340,7 +1340,7 @@ static ptrdiff_t low_cpp(struct cpp *this, ptrdiff_t tmp; PCHARP ptr; - STRCAT("#pike", 5); + string_builder_strcat(&this->buf, "#pike"); tmp= this->buf.s->len; pos += low_cpp(this, ADD_PCHARP(data,pos), len-pos, CPP_END_AT_NEWLINE | CPP_DO_IF, @@ -1367,7 +1367,7 @@ static ptrdiff_t low_cpp(struct cpp *this, } case 'r': /* require */ { - if(WGOBBLE2(require_)) + if(GOBBLE_WORD(require_)) { struct string_builder save, tmp; save = this->buf; @@ -1391,7 +1391,7 @@ static ptrdiff_t low_cpp(struct cpp *this, } case 'w': /* warning */ { - if(WGOBBLE2(warning_)) + if(GOBBLE_WORD(warning_)) { ptrdiff_t foo;