added support for win32 wchar_t (Filip Navara)
This commit is contained in:
parent
bb24eb9de4
commit
6f8b8887b1
1 changed files with 27 additions and 9 deletions
36
tcc.c
36
tcc.c
|
@ -137,9 +137,15 @@ typedef struct TokenSym {
|
||||||
char str[1];
|
char str[1];
|
||||||
} TokenSym;
|
} TokenSym;
|
||||||
|
|
||||||
|
#ifdef TCC_TARGET_PE
|
||||||
|
typedef unsigned short nwchar_t;
|
||||||
|
#else
|
||||||
|
typedef int nwchar_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct CString {
|
typedef struct CString {
|
||||||
int size; /* size in bytes */
|
int size; /* size in bytes */
|
||||||
void *data; /* either 'char *' or 'int *' */
|
void *data; /* either 'char *' or 'nwchar_t *' */
|
||||||
int size_allocated;
|
int size_allocated;
|
||||||
void *data_allocated; /* if non NULL, data has been malloced */
|
void *data_allocated; /* if non NULL, data has been malloced */
|
||||||
} CString;
|
} CString;
|
||||||
|
@ -1562,10 +1568,10 @@ static void cstr_cat(CString *cstr, const char *str)
|
||||||
static void cstr_wccat(CString *cstr, int ch)
|
static void cstr_wccat(CString *cstr, int ch)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
size = cstr->size + sizeof(int);
|
size = cstr->size + sizeof(nwchar_t);
|
||||||
if (size > cstr->size_allocated)
|
if (size > cstr->size_allocated)
|
||||||
cstr_realloc(cstr, size);
|
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;
|
cstr->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1655,9 +1661,9 @@ char *get_tok_str(int v, CValue *cv)
|
||||||
for(i=0;i<len;i++)
|
for(i=0;i<len;i++)
|
||||||
add_char(&cstr_buf, ((unsigned char *)cstr->data)[i]);
|
add_char(&cstr_buf, ((unsigned char *)cstr->data)[i]);
|
||||||
} else {
|
} else {
|
||||||
len = (cstr->size / sizeof(int)) - 1;
|
len = (cstr->size / sizeof(nwchar_t)) - 1;
|
||||||
for(i=0;i<len;i++)
|
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, '\"');
|
||||||
cstr_ccat(&cstr_buf, '\0');
|
cstr_ccat(&cstr_buf, '\0');
|
||||||
|
@ -3730,7 +3736,7 @@ static inline void next_nomacro1(void)
|
||||||
if (!is_long)
|
if (!is_long)
|
||||||
char_size = 1;
|
char_size = 1;
|
||||||
else
|
else
|
||||||
char_size = sizeof(int);
|
char_size = sizeof(nwchar_t);
|
||||||
if (tokcstr.size <= char_size)
|
if (tokcstr.size <= char_size)
|
||||||
error("empty character constant");
|
error("empty character constant");
|
||||||
if (tokcstr.size > 2 * char_size)
|
if (tokcstr.size > 2 * char_size)
|
||||||
|
@ -3739,7 +3745,7 @@ static inline void next_nomacro1(void)
|
||||||
tokc.i = *(int8_t *)tokcstr.data;
|
tokc.i = *(int8_t *)tokcstr.data;
|
||||||
tok = TOK_CCHAR;
|
tok = TOK_CCHAR;
|
||||||
} else {
|
} else {
|
||||||
tokc.i = *(int *)tokcstr.data;
|
tokc.i = *(nwchar_t *)tokcstr.data;
|
||||||
tok = TOK_LCHAR;
|
tok = TOK_LCHAR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -7135,7 +7141,11 @@ static void unary(void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TOK_LSTR:
|
case TOK_LSTR:
|
||||||
|
#ifdef TCC_TARGET_PE
|
||||||
|
t = VT_SHORT | VT_UNSIGNED;
|
||||||
|
#else
|
||||||
t = VT_INT;
|
t = VT_INT;
|
||||||
|
#endif
|
||||||
goto str_init;
|
goto str_init;
|
||||||
case TOK_STR:
|
case TOK_STR:
|
||||||
/* string parsing */
|
/* 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
|
/* only parse strings here if correct type (otherwise: handle
|
||||||
them as ((w)char *) expressions */
|
them as ((w)char *) expressions */
|
||||||
if ((tok == TOK_LSTR &&
|
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) ||
|
(t1->t & VT_BTYPE) == VT_INT) ||
|
||||||
|
#endif
|
||||||
(tok == TOK_STR &&
|
(tok == TOK_STR &&
|
||||||
(t1->t & VT_BTYPE) == VT_BYTE)) {
|
(t1->t & VT_BTYPE) == VT_BYTE)) {
|
||||||
while (tok == TOK_STR || tok == TOK_LSTR) {
|
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)
|
if (tok == TOK_STR)
|
||||||
cstr_len = cstr->size;
|
cstr_len = cstr->size;
|
||||||
else
|
else
|
||||||
cstr_len = cstr->size / sizeof(int);
|
cstr_len = cstr->size / sizeof(nwchar_t);
|
||||||
cstr_len--;
|
cstr_len--;
|
||||||
nb = cstr_len;
|
nb = cstr_len;
|
||||||
if (n >= 0 && nb > (n - array_length))
|
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)
|
if (tok == TOK_STR)
|
||||||
ch = ((unsigned char *)cstr->data)[i];
|
ch = ((unsigned char *)cstr->data)[i];
|
||||||
else
|
else
|
||||||
ch = ((int *)cstr->data)[i];
|
ch = ((nwchar_t *)cstr->data)[i];
|
||||||
init_putv(t1, sec, c + (array_length + i) * size1,
|
init_putv(t1, sec, c + (array_length + i) * size1,
|
||||||
ch, EXPR_VAL);
|
ch, EXPR_VAL);
|
||||||
}
|
}
|
||||||
|
@ -9758,7 +9772,11 @@ TCCState *tcc_new(void)
|
||||||
/* tiny C & gcc defines */
|
/* tiny C & gcc defines */
|
||||||
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int");
|
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int");
|
||||||
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "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");
|
tcc_define_symbol(s, "__WCHAR_TYPE__", "int");
|
||||||
|
#endif
|
||||||
|
|
||||||
/* default library paths */
|
/* default library paths */
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
|
|
Loading…
Add table
Reference in a new issue