History

div fixes

- 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

grischka committed 2 years ago

Commit 6b78e561 parent 3b943be20 files · +227 −508Browse files

Showing the changes to tccpp.c (1 of 20 files). Show all

Unified · Split

tccpp.c+32−31
@@ -92,7 +92,6 @@ static const unsigned char tok_two_chars[] = · 91 unmodified lines
9292 '-','>', TOK_ARROW,
9393 '.','.', TOK_TWODOTS,
9494 '#','#', TOK_TWOSHARPS,
95− '#','#', TOK_PPJOIN,
9695 0
9796 };
9897
@@ -137,10 +136,8 @@ ST_FUNC void expect(const char *msg) · 38 unmodified lines
137136
138137 #define TOKSYM_TAL_SIZE (768 * 1024) /* allocator for tiny TokenSym in table_ident */
139138 #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) */
144141
145142 typedef struct TinyAlloc {
146143 unsigned limit;
@@ -185,8 +182,8 @@ tail_call: · 38 unmodified lines
185182 if (!al)
186183 return;
187184 #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,
190187 (al->peak_p - al->buffer) * 100.0 / al->size);
191188 #endif
192189 #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
345342 size = cstr->size + 1;
346343 if (size > cstr->size_allocated)
347344 cstr_realloc(cstr, size);
348− ((unsigned char *)cstr->data)[size - 1] = ch;
345+ cstr->data[size - 1] = ch;
349346 cstr->size = size;
350347 }
351348
@@ -368,6 +365,7 @@ ST_INLN void cstr_u8cat(CString *cstr, int ch) · 16 unmodified lines
368365 cstr_cat(cstr, buf, e - buf);
369366 }
370367
368+/* add string of 'len', or of its len/len+1 when 'len' == -1/0 */
371369 ST_FUNC void cstr_cat(CString *cstr, const char *str, int len)
372370 {
373371 int size;
@@ -376,7 +374,7 @@ ST_FUNC void cstr_cat(CString *cstr, const char *str, int len) · 2 unmodified lines
376374 size = cstr->size + len;
377375 if (size > cstr->size_allocated)
378376 cstr_realloc(cstr, size);
379− memmove(((unsigned char *)cstr->data) + cstr->size, str, len);
377+ memmove(cstr->data + cstr->size, str, len);
380378 cstr->size = size;
381379 }
382380
@@ -387,7 +385,7 @@ ST_FUNC void cstr_wccat(CString *cstr, int ch) · 4 unmodified lines
387385 size = cstr->size + sizeof(nwchar_t);
388386 if (size > cstr->size_allocated)
389387 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;
391389 cstr->size = size;
392390 }
393391
@@ -418,7 +416,7 @@ ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap) · 24 unmodified lines
418416 cstr_realloc(cstr, size);
419417 size = cstr->size_allocated - cstr->size;
420418 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);
422420 va_end(v);
423421 if (len >= 0 && len < size)
424422 break;
@@ -1920,7 +1918,8 @@ ST_FUNC void preprocess(int is_bof) · 1495 unmodified lines
19201918 if (file->fd > 0)
19211919 total_lines += file->line_num - n;
19221920 file->line_num = n;
1923− break;
1921+ goto ignore; /* skip optional level number */
1922+
19241923 case TOK_ERROR:
19251924 case TOK_WARNING:
19261925 q = buf;
@@ -3070,12 +3069,13 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) · 1143 unmodified lines
30703069 /* handle the '##' operator. return the resulting string (which must be freed). */
30713070 static inline int *macro_twosharps(const int *ptr0)
30723071 {
3073− int t1, t2, n;
3072+ int t1, t2, n, l;
30743073 CValue cv1, cv2;
30753074 TokenString macro_str1;
30763075 const int *ptr;
30773076
30783077 tok_str_new(&macro_str1);
3078+ cstr_reset(&tokcstr);
30793079 for (ptr = ptr0;;) {
30803080 TOK_GET(&t1, &ptr, &cv1);
30813081 if (t1 == 0)
@@ -3090,29 +3090,31 @@ static inline int *macro_twosharps(const int *ptr0) · 8 unmodified lines
30903090 while ((t2 = *++ptr) == ' ' || t2 == TOK_PPJOIN)
30913091 ;
30923092 TOK_GET(&t2, &ptr, &cv2);
3093− if (t1 == TOK_PLCHLDR && t2 == TOK_PLCHLDR)
3093+ if (t2 == TOK_PLCHLDR)
30943094 continue;
3095− cstr_reset(&tokcstr);
3096− if (t1 != TOK_PLCHLDR)
3095+ if (t1 != TOK_PLCHLDR) {
30973096 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);
31033103 tcc_open_bf(tcc_state, ":paste:", tokcstr.size);
31043104 memcpy(file->buffer, tokcstr.data, tokcstr.size);
31053105 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(&macro_str1, tok, &tokc);
3109+ if (*file->buf_ptr == 0)
3110+ break;
3111+ tok_str_add(&macro_str1, ' ');
3112+ l = file->buf_ptr - file->buffer;
31103113 tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid"
3111− " preprocessing token", n, file->buffer, file->buffer + n);
3112− tok_str_add2(&macro_str1, t1, &cv1);
3113− t1 = t2, cv1 = cv2;
3114+ " preprocessing token", l - n, file->buffer + n, file->buf_ptr);
31143115 }
31153116 tcc_close();
3117+ cstr_reset(&tokcstr);
31163118 }
31173119 if (t1 != TOK_PLCHLDR)
31183120 tok_str_add2(&macro_str1, t1, &cv1);
@@ -3450,9 +3452,8 @@ redo: · 331 unmodified lines
34503452 /* do nothing */
34513453 } else {
34523454 ++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 == '\\') {
34563457 if (!(parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
34573458 tcc_error("stray '\\' in program");
34583459 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t