Mercurial > hg > qcc
changeset 384:7242363aa96d
[project @ 2005-09-03 21:54:47 by bellard]
added support for win32 wchar_t (Filip Navara)
author | bellard |
---|---|
date | Sat, 03 Sep 2005 21:54:47 +0000 |
parents | 7b0992df204d |
children | 14ff3d95e91b |
files | tcc.c |
diffstat | 1 files changed, 27 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/tcc.c Sat Sep 03 21:32:06 2005 +0000 +++ b/tcc.c Sat Sep 03 21:54:47 2005 +0000 @@ -137,9 +137,15 @@ char str[1]; } TokenSym; +#ifdef TCC_TARGET_PE +typedef unsigned short nwchar_t; +#else +typedef int nwchar_t; +#endif + typedef struct CString { int size; /* size in bytes */ - void *data; /* either 'char *' or 'int *' */ + void *data; /* either 'char *' or 'nwchar_t *' */ int size_allocated; void *data_allocated; /* if non NULL, data has been malloced */ } CString; @@ -1562,10 +1568,10 @@ static void cstr_wccat(CString *cstr, int ch) { int size; - size = cstr->size + sizeof(int); + size = cstr->size + sizeof(nwchar_t); if (size > cstr->size_allocated) cstr_realloc(cstr, size); - *(int *)(((unsigned char *)cstr->data) + size - sizeof(int)) = ch; + *(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = ch; cstr->size = size; } @@ -1655,9 +1661,9 @@ for(i=0;i<len;i++) add_char(&cstr_buf, ((unsigned char *)cstr->data)[i]); } else { - len = (cstr->size / sizeof(int)) - 1; + len = (cstr->size / sizeof(nwchar_t)) - 1; for(i=0;i<len;i++) - add_char(&cstr_buf, ((int *)cstr->data)[i]); + add_char(&cstr_buf, ((nwchar_t *)cstr->data)[i]); } cstr_ccat(&cstr_buf, '\"'); cstr_ccat(&cstr_buf, '\0'); @@ -3730,7 +3736,7 @@ if (!is_long) char_size = 1; else - char_size = sizeof(int); + char_size = sizeof(nwchar_t); if (tokcstr.size <= char_size) error("empty character constant"); if (tokcstr.size > 2 * char_size) @@ -3739,7 +3745,7 @@ tokc.i = *(int8_t *)tokcstr.data; tok = TOK_CCHAR; } else { - tokc.i = *(int *)tokcstr.data; + tokc.i = *(nwchar_t *)tokcstr.data; tok = TOK_LCHAR; } } else { @@ -7135,7 +7141,11 @@ } break; case TOK_LSTR: +#ifdef TCC_TARGET_PE + t = VT_SHORT | VT_UNSIGNED; +#else t = VT_INT; +#endif goto str_init; case TOK_STR: /* string parsing */ @@ -8416,7 +8426,11 @@ /* only parse strings here if correct type (otherwise: handle them as ((w)char *) expressions */ if ((tok == TOK_LSTR && +#ifdef TCC_TARGET_PE + (t1->t & VT_BTYPE) == VT_SHORT && (t1->t & VT_UNSIGNED)) || +#else (t1->t & VT_BTYPE) == VT_INT) || +#endif (tok == TOK_STR && (t1->t & VT_BTYPE) == VT_BYTE)) { while (tok == TOK_STR || tok == TOK_LSTR) { @@ -8428,7 +8442,7 @@ if (tok == TOK_STR) cstr_len = cstr->size; else - cstr_len = cstr->size / sizeof(int); + cstr_len = cstr->size / sizeof(nwchar_t); cstr_len--; nb = cstr_len; if (n >= 0 && nb > (n - array_length)) @@ -8446,7 +8460,7 @@ if (tok == TOK_STR) ch = ((unsigned char *)cstr->data)[i]; else - ch = ((int *)cstr->data)[i]; + ch = ((nwchar_t *)cstr->data)[i]; init_putv(t1, sec, c + (array_length + i) * size1, ch, EXPR_VAL); } @@ -9758,7 +9772,11 @@ /* tiny C & gcc defines */ tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int"); tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int"); +#ifdef TCC_TARGET_PE + tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short"); +#else tcc_define_symbol(s, "__WCHAR_TYPE__", "int"); +#endif /* default library paths */ #ifdef TCC_TARGET_PE