diff options
| author | grischka <grischka> | 2010-01-14 20:58:03 +0100 |
|---|---|---|
| committer | grischka <grischka> | 2010-01-14 20:59:44 +0100 |
| commit | 4e5170d4a59a6cadb3d11d918f5dd674141e3266 (patch) | |
| tree | 0bead08f4d436e581dcdec5f352647afb6d0a00b /tccpp.c | |
| parent | 280e20b1d3a6c5ef88db4bfb074be771e595179f (diff) | |
| download | tinycc-4e5170d4a59a6cadb3d11d918f5dd674141e3266.tar.gz tinycc-4e5170d4a59a6cadb3d11d918f5dd674141e3266.tar.bz2 | |
tccpp: convert TOK_GET macro into function
Diffstat (limited to 'tccpp.c')
| -rw-r--r-- | tccpp.c | 131 |
1 files changed, 63 insertions, 68 deletions
@@ -42,7 +42,7 @@ ST_DATA int parse_flags; ST_DATA struct BufferedFile *file; ST_DATA int ch, tok; ST_DATA CValue tokc; -ST_DATA int *macro_ptr; +ST_DATA const int *macro_ptr; ST_DATA CString tokcstr; /* current parsed string, if any */ /* display benchmark infos */ @@ -54,7 +54,7 @@ ST_DATA TokenSym **table_ident; /* ------------------------------------------------------------------------- */ static int *macro_ptr_allocated; -static int *unget_saved_macro_ptr; +static const int *unget_saved_macro_ptr; static int unget_saved_buffer[TOK_MAX_SIZE + 1]; static int unget_buffer_enabled; static TokenSym *hash_ident[TOK_HASH_SIZE]; @@ -75,7 +75,7 @@ static const unsigned char tok_two_chars[] = struct macro_level { struct macro_level *prev; - int *p; + const int *p; }; ST_FUNC void next_nomacro(void); @@ -940,61 +940,54 @@ ST_FUNC void tok_str_add_tok(TokenString *s) tok_str_add2(s, tok, &tokc); } +/* get a token from an integer array and increment pointer + accordingly. we code it as a macro to avoid pointer aliasing. */ +static inline void TOK_GET(int *t, const int **pp, CValue *cv) +{ + const int *p = *pp; + int n, *tab; + + tab = cv->tab; + switch(*t = *p++) { + case TOK_CINT: + case TOK_CUINT: + case TOK_CCHAR: + case TOK_LCHAR: + case TOK_CFLOAT: + case TOK_LINENUM: + tab[0] = *p++; + break; + case TOK_STR: + case TOK_LSTR: + case TOK_PPNUM: + cv->cstr = (CString *)p; + cv->cstr->data = (char *)p + sizeof(CString); + p += (sizeof(CString) + cv->cstr->size + 3) >> 2; + break; + case TOK_CDOUBLE: + case TOK_CLLONG: + case TOK_CULLONG: + n = 2; + goto copy; + case TOK_CLDOUBLE: #if LDOUBLE_SIZE == 16 -#define LDOUBLE_GET(p, cv) \ - cv.tab[0] = p[0]; \ - cv.tab[1] = p[1]; \ - cv.tab[2] = p[2]; \ - cv.tab[3] = p[3]; + n = 4; #elif LDOUBLE_SIZE == 12 -#define LDOUBLE_GET(p, cv) \ - cv.tab[0] = p[0]; \ - cv.tab[1] = p[1]; \ - cv.tab[2] = p[2]; + n = 3; #elif LDOUBLE_SIZE == 8 -#define LDOUBLE_GET(p, cv) \ - cv.tab[0] = p[0]; \ - cv.tab[1] = p[1]; + n = 2; #else -#error add long double size support +# error add long double size support #endif - - -/* get a token from an integer array and increment pointer - accordingly. we code it as a macro to avoid pointer aliasing. */ -#define TOK_GET(t, p, cv) \ -{ \ - t = *p++; \ - switch(t) { \ - case TOK_CINT: \ - case TOK_CUINT: \ - case TOK_CCHAR: \ - case TOK_LCHAR: \ - case TOK_CFLOAT: \ - case TOK_LINENUM: \ - cv.tab[0] = *p++; \ - break; \ - case TOK_STR: \ - case TOK_LSTR: \ - case TOK_PPNUM: \ - cv.cstr = (CString *)p; \ - cv.cstr->data = (char *)p + sizeof(CString);\ - p += (sizeof(CString) + cv.cstr->size + 3) >> 2;\ - break; \ - case TOK_CDOUBLE: \ - case TOK_CLLONG: \ - case TOK_CULLONG: \ - cv.tab[0] = p[0]; \ - cv.tab[1] = p[1]; \ - p += 2; \ - break; \ - case TOK_CLDOUBLE: \ - LDOUBLE_GET(p, cv); \ - p += LDOUBLE_SIZE / 4; \ - break; \ - default: \ - break; \ - } \ + copy: + do + *tab++ = *p++; + while (--n); + break; + default: + break; + } + *pp = p; } static int macro_is_equal(const int *a, const int *b) @@ -1003,9 +996,9 @@ static int macro_is_equal(const int *a, const int *b) CValue cv; int t; while (*a && *b) { - TOK_GET(t, a, cv); + TOK_GET(&t, &a, &cv); pstrcpy(buf, sizeof buf, get_tok_str(t, &cv)); - TOK_GET(t, b, cv); + TOK_GET(&t, &b, &cv); if (strcmp(buf, get_tok_str(t, &cv))) return 0; } @@ -1163,7 +1156,7 @@ static void tok_print(int *str) printf("<"); while (1) { - TOK_GET(t, str, cval); + TOK_GET(&t, &str, &cval); if (!t) break; printf("%s", get_tok_str(t, &cval)); @@ -2498,7 +2491,7 @@ static void next_nomacro_spc(void) redo: tok = *macro_ptr; if (tok) { - TOK_GET(tok, macro_ptr, tokc); + TOK_GET(&tok, ¯o_ptr, &tokc); if (tok == TOK_LINENUM) { file->line_num = tokc.i; goto redo; @@ -2517,9 +2510,10 @@ ST_FUNC void next_nomacro(void) } /* substitute args in macro_str and return allocated string */ -static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) +static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) { - int *st, last_tok, t, spc; + int last_tok, t, spc; + const int *st; Sym *s; CValue cval; TokenString str; @@ -2528,12 +2522,12 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) tok_str_new(&str); last_tok = 0; while(1) { - TOK_GET(t, macro_str, cval); + TOK_GET(&t, ¯o_str, &cval); if (!t) break; if (t == '#') { /* stringize */ - TOK_GET(t, macro_str, cval); + TOK_GET(&t, ¯o_str, &cval); if (!t) break; s = sym_find2(args, t); @@ -2542,7 +2536,7 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) st = s->d; spc = 0; while (*st) { - TOK_GET(t, st, cval); + TOK_GET(&t, &st, &cval); if (!check_space(t, &spc)) cstr_cat(&cstr, get_tok_str(t, &cval)); } @@ -2584,7 +2578,7 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) int t1; add_var: for(;;) { - TOK_GET(t1, st, cval); + TOK_GET(&t1, &st, &cval); if (!t1) break; tok_str_add2(&str, t1, &cval); @@ -2621,7 +2615,8 @@ static int macro_subst_tok(TokenString *tok_str, Sym **nested_list, Sym *s, struct macro_level **can_read_stream) { Sym *args, *sa, *sa1; - int mstr_allocated, parlevel, *mstr, t, t1, *p, spc; + int mstr_allocated, parlevel, *mstr, t, t1, spc; + const int *p; TokenString str; char *cstrval; CValue cval; @@ -2785,7 +2780,7 @@ static inline int *macro_twosharps(const int *macro_str) /* we search the first '##' */ for(ptr = macro_str;;) { - TOK_GET(t, ptr, cval); + TOK_GET(&t, &ptr, &cval); if (t == TOK_TWOSHARPS) break; /* nothing more to do if end of string */ @@ -2796,7 +2791,7 @@ static inline int *macro_twosharps(const int *macro_str) /* we saw '##', so we need more processing to handle it */ tok_str_new(¯o_str1); for(ptr = macro_str;;) { - TOK_GET(tok, ptr, tokc); + TOK_GET(&tok, &ptr, &tokc); if (tok == 0) break; if (tok == TOK_TWOSHARPS) @@ -2804,7 +2799,7 @@ static inline int *macro_twosharps(const int *macro_str) while (*ptr == TOK_TWOSHARPS) { t = *++ptr; if (t && t != TOK_TWOSHARPS) { - TOK_GET(t, ptr, cval); + TOK_GET(&t, &ptr, &cval); /* We concatenate the two tokens */ cstr_new(&cstr); @@ -2859,7 +2854,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, file stream due to a macro function call */ if (ptr == NULL) break; - TOK_GET(t, ptr, cval); + TOK_GET(&t, &ptr, &cval); if (t == 0) break; s = define_find(t); |
