- Makefile: don't produce unknown targets - libtcc.c: tcc_set_linker(): improve parser - tcc.h: tcc_internal_error(): don't record __FILE__ (for privacy reasons) - tccgen.c: - reject pointer + float operation - use 'int level' for builtin_frame/return_address - save_regs(): remove VT_ARRAY (confuses riscv64-gen) - tccpe.c: store just basename of loaded dlls (rather than full path) - tccpp.c: remove unused TAL defines - *-link.c: add missing ST_FUNC - i386-gen.c: fix thiscall - riscv64-asm.c/arm-asm.c: stay simple C89 - avoid .designators, decl after statement - avoid multiple instances of same static const objects - use skip() instead of next() & expect() - use cstr_printf() instead of snprintf() & cstr_cat() - tcc_error(), expect(): never return
Showing the changes to tccpp.c (1 of 20 files). Show all
Unified · Split
| @@ -92,7 +92,6 @@ static const unsigned char tok_two_chars[] = · 91 unmodified lines | ||
| 92 | 92 | '-','>', TOK_ARROW, |
| 93 | 93 | '.','.', TOK_TWODOTS, |
| 94 | 94 | '#','#', TOK_TWOSHARPS, |
| 95 | − '#','#', TOK_PPJOIN, | |
| 96 | 95 | 0 |
| 97 | 96 | }; |
| 98 | 97 | |
| @@ -137,10 +136,8 @@ ST_FUNC void expect(const char *msg) · 38 unmodified lines | ||
| 137 | 136 | |
| 138 | 137 | #define TOKSYM_TAL_SIZE (768 * 1024) /* allocator for tiny TokenSym in table_ident */ |
| 139 | 138 | #define TOKSTR_TAL_SIZE (768 * 1024) /* allocator for tiny TokenString instances */ |
| 140 | −#define CSTR_TAL_SIZE (256 * 1024) /* allocator for tiny CString instances */ | |
| 141 | −#define TOKSYM_TAL_LIMIT 256 /* prefer unique limits to distinguish allocators debug msgs */ | |
| 142 | −#define TOKSTR_TAL_LIMIT 128 /* 32 * sizeof(int) */ | |
| 143 | −#define CSTR_TAL_LIMIT 1024 | |
| 139 | +#define TOKSYM_TAL_LIMIT 256 /* prefer unique limits to distinguish allocators debug msgs */ | |
| 140 | +#define TOKSTR_TAL_LIMIT 1024 /* 256 * sizeof(int) */ | |
| 144 | 141 | |
| 145 | 142 | typedef struct TinyAlloc { |
| 146 | 143 | unsigned limit; |
| @@ -185,8 +182,8 @@ tail_call: · 38 unmodified lines | ||
| 185 | 182 | if (!al) |
| 186 | 183 | return; |
| 187 | 184 | #ifdef TAL_INFO |
| 188 | − fprintf(stderr, "limit=%5d, size=%5g MB, nb_peak=%6d, nb_total=%8d, nb_missed=%6d, usage=%5.1f%%\n", | |
| 189 | − al->limit, al->size / 1024.0 / 1024.0, al->nb_peak, al->nb_total, al->nb_missed, | |
| 185 | + fprintf(stderr, "limit %4d size %7d nb_peak %5d nb_total %7d nb_missed %5d usage %5.1f%%\n", | |
| 186 | + al->limit, al->size, al->nb_peak, al->nb_total, al->nb_missed, | |
| 190 | 187 | (al->peak_p - al->buffer) * 100.0 / al->size); |
| 191 | 188 | #endif |
| 192 | 189 | #if TAL_DEBUG && TAL_DEBUG != 3 /* do not check TAL leaks with -DMEM_DEBUG=3 */ |
| @@ -345,7 +342,7 @@ ST_INLN void cstr_ccat(CString *cstr, int ch) · 152 unmodified lines | ||
| 345 | 342 | size = cstr->size + 1; |
| 346 | 343 | if (size > cstr->size_allocated) |
| 347 | 344 | cstr_realloc(cstr, size); |
| 348 | − ((unsigned char *)cstr->data)[size - 1] = ch; | |
| 345 | + cstr->data[size - 1] = ch; | |
| 349 | 346 | cstr->size = size; |
| 350 | 347 | } |
| 351 | 348 | |
| @@ -368,6 +365,7 @@ ST_INLN void cstr_u8cat(CString *cstr, int ch) · 16 unmodified lines | ||
| 368 | 365 | cstr_cat(cstr, buf, e - buf); |
| 369 | 366 | } |
| 370 | 367 | |
| 368 | +/* add string of 'len', or of its len/len+1 when 'len' == -1/0 */ | |
| 371 | 369 | ST_FUNC void cstr_cat(CString *cstr, const char *str, int len) |
| 372 | 370 | { |
| 373 | 371 | int size; |
| @@ -376,7 +374,7 @@ ST_FUNC void cstr_cat(CString *cstr, const char *str, int len) · 2 unmodified lines | ||
| 376 | 374 | size = cstr->size + len; |
| 377 | 375 | if (size > cstr->size_allocated) |
| 378 | 376 | cstr_realloc(cstr, size); |
| 379 | − memmove(((unsigned char *)cstr->data) + cstr->size, str, len); | |
| 377 | + memmove(cstr->data + cstr->size, str, len); | |
| 380 | 378 | cstr->size = size; |
| 381 | 379 | } |
| 382 | 380 | |
| @@ -387,7 +385,7 @@ ST_FUNC void cstr_wccat(CString *cstr, int ch) · 4 unmodified lines | ||
| 387 | 385 | size = cstr->size + sizeof(nwchar_t); |
| 388 | 386 | if (size > cstr->size_allocated) |
| 389 | 387 | cstr_realloc(cstr, size); |
| 390 | − *(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = ch; | |
| 388 | + *(nwchar_t *)(cstr->data + size - sizeof(nwchar_t)) = ch; | |
| 391 | 389 | cstr->size = size; |
| 392 | 390 | } |
| 393 | 391 | |
| @@ -418,7 +416,7 @@ ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap) · 24 unmodified lines | ||
| 418 | 416 | cstr_realloc(cstr, size); |
| 419 | 417 | size = cstr->size_allocated - cstr->size; |
| 420 | 418 | va_copy(v, ap); |
| 421 | − len = vsnprintf((char*)cstr->data + cstr->size, size, fmt, v); | |
| 419 | + len = vsnprintf(cstr->data + cstr->size, size, fmt, v); | |
| 422 | 420 | va_end(v); |
| 423 | 421 | if (len >= 0 && len < size) |
| 424 | 422 | break; |
| @@ -1920,7 +1918,8 @@ ST_FUNC void preprocess(int is_bof) · 1495 unmodified lines | ||
| 1920 | 1918 | if (file->fd > 0) |
| 1921 | 1919 | total_lines += file->line_num - n; |
| 1922 | 1920 | file->line_num = n; |
| 1923 | − break; | |
| 1921 | + goto ignore; /* skip optional level number */ | |
| 1922 | + | |
| 1924 | 1923 | case TOK_ERROR: |
| 1925 | 1924 | case TOK_WARNING: |
| 1926 | 1925 | q = buf; |
| @@ -3070,12 +3069,13 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) · 1143 unmodified lines | ||
| 3070 | 3069 | /* handle the '##' operator. return the resulting string (which must be freed). */ |
| 3071 | 3070 | static inline int *macro_twosharps(const int *ptr0) |
| 3072 | 3071 | { |
| 3073 | − int t1, t2, n; | |
| 3072 | + int t1, t2, n, l; | |
| 3074 | 3073 | CValue cv1, cv2; |
| 3075 | 3074 | TokenString macro_str1; |
| 3076 | 3075 | const int *ptr; |
| 3077 | 3076 | |
| 3078 | 3077 | tok_str_new(¯o_str1); |
| 3078 | + cstr_reset(&tokcstr); | |
| 3079 | 3079 | for (ptr = ptr0;;) { |
| 3080 | 3080 | TOK_GET(&t1, &ptr, &cv1); |
| 3081 | 3081 | if (t1 == 0) |
| @@ -3090,29 +3090,31 @@ static inline int *macro_twosharps(const int *ptr0) · 8 unmodified lines | ||
| 3090 | 3090 | while ((t2 = *++ptr) == ' ' || t2 == TOK_PPJOIN) |
| 3091 | 3091 | ; |
| 3092 | 3092 | TOK_GET(&t2, &ptr, &cv2); |
| 3093 | − if (t1 == TOK_PLCHLDR && t2 == TOK_PLCHLDR) | |
| 3093 | + if (t2 == TOK_PLCHLDR) | |
| 3094 | 3094 | continue; |
| 3095 | − cstr_reset(&tokcstr); | |
| 3096 | − if (t1 != TOK_PLCHLDR) | |
| 3095 | + if (t1 != TOK_PLCHLDR) { | |
| 3097 | 3096 | cstr_cat(&tokcstr, get_tok_str(t1, &cv1), -1); |
| 3098 | − n = tokcstr.size; | |
| 3099 | − if (t2 != TOK_PLCHLDR) | |
| 3100 | − cstr_cat(&tokcstr, get_tok_str(t2, &cv2), -1); | |
| 3101 | − cstr_ccat(&tokcstr, '\0'); | |
| 3102 | − //printf("paste <%s>\n", (char*)tokcstr.data); | |
| 3097 | + t1 = TOK_PLCHLDR; | |
| 3098 | + } | |
| 3099 | + cstr_cat(&tokcstr, get_tok_str(t2, &cv2), -1); | |
| 3100 | + } | |
| 3101 | + if (tokcstr.size) { | |
| 3102 | + cstr_ccat(&tokcstr, 0); | |
| 3103 | 3103 | tcc_open_bf(tcc_state, ":paste:", tokcstr.size); |
| 3104 | 3104 | memcpy(file->buffer, tokcstr.data, tokcstr.size); |
| 3105 | 3105 | tok_flags = 0; /* don't interpret '#' */ |
| 3106 | − next_nomacro(); | |
| 3107 | − if (*file->buf_ptr == 0) { | |
| 3108 | − t1 = tok, cv1 = tokc; | |
| 3109 | − } else { | |
| 3106 | + for (n = 0;;n = l) { | |
| 3107 | + next_nomacro(); | |
| 3108 | + tok_str_add2(¯o_str1, tok, &tokc); | |
| 3109 | + if (*file->buf_ptr == 0) | |
| 3110 | + break; | |
| 3111 | + tok_str_add(¯o_str1, ' '); | |
| 3112 | + l = file->buf_ptr - file->buffer; | |
| 3110 | 3113 | tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid" |
| 3111 | − " preprocessing token", n, file->buffer, file->buffer + n); | |
| 3112 | − tok_str_add2(¯o_str1, t1, &cv1); | |
| 3113 | − t1 = t2, cv1 = cv2; | |
| 3114 | + " preprocessing token", l - n, file->buffer + n, file->buf_ptr); | |
| 3114 | 3115 | } |
| 3115 | 3116 | tcc_close(); |
| 3117 | + cstr_reset(&tokcstr); | |
| 3116 | 3118 | } |
| 3117 | 3119 | if (t1 != TOK_PLCHLDR) |
| 3118 | 3120 | tok_str_add2(¯o_str1, t1, &cv1); |
| @@ -3450,9 +3452,8 @@ redo: · 331 unmodified lines | ||
| 3450 | 3452 | /* do nothing */ |
| 3451 | 3453 | } else { |
| 3452 | 3454 | ++macro_ptr; |
| 3453 | − if (t >= TOK_IDENT) { | |
| 3454 | − t &= ~SYM_FIELD; /* remove 'nosubst' marker */ | |
| 3455 | − } else if (t == '\\') { | |
| 3455 | + t &= ~SYM_FIELD; /* remove 'nosubst' marker */ | |
| 3456 | + if (t == '\\') { | |
| 3456 | 3457 | if (!(parse_flags & PARSE_FLAG_ACCEPT_STRAYS)) |
| 3457 | 3458 | tcc_error("stray '\\' in program"); |
| 3458 | 3459 | } |