mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-29 06:10:09 +08:00
added support for win32 wchar_t (Filip Navara)
This commit is contained in:
parent
bb24eb9de4
commit
6f8b8887b1
36
tcc.c
36
tcc.c
@ -137,9 +137,15 @@ typedef struct TokenSym {
|
||||
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_cat(CString *cstr, const char *str)
|
||||
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 @@ char *get_tok_str(int v, CValue *cv)
|
||||
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 @@ static inline void next_nomacro1(void)
|
||||
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 @@ static inline void next_nomacro1(void)
|
||||
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 @@ static void unary(void)
|
||||
}
|
||||
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 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
||||
/* 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 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
||||
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 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
||||
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 @@ TCCState *tcc_new(void)
|
||||
/* 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
|
||||
|
Loading…
Reference in New Issue
Block a user