2009-05-05 22:17:11 +04:00
|
|
|
/*
|
|
|
|
* TCC - Tiny C Compiler
|
2015-07-29 23:53:57 +03:00
|
|
|
*
|
2009-05-05 22:17:11 +04:00
|
|
|
* Copyright (c) 2001-2004 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
#include "tcc.h"
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* global variables */
|
|
|
|
|
|
|
|
ST_DATA int tok_flags;
|
|
|
|
ST_DATA int parse_flags;
|
|
|
|
|
|
|
|
ST_DATA struct BufferedFile *file;
|
|
|
|
ST_DATA int ch, tok;
|
|
|
|
ST_DATA CValue tokc;
|
2010-01-14 22:58:03 +03:00
|
|
|
ST_DATA const int *macro_ptr;
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_DATA CString tokcstr; /* current parsed string, if any */
|
|
|
|
|
|
|
|
/* display benchmark infos */
|
|
|
|
ST_DATA int total_lines;
|
|
|
|
ST_DATA int total_bytes;
|
|
|
|
ST_DATA int tok_ident;
|
|
|
|
ST_DATA TokenSym **table_ident;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static TokenSym *hash_ident[TOK_HASH_SIZE];
|
|
|
|
static char token_buf[STRING_MAX_SIZE + 1];
|
2016-04-17 16:37:23 +03:00
|
|
|
static CString cstr_buf;
|
2016-12-20 07:38:44 +03:00
|
|
|
static CString macro_equal_buf;
|
2016-04-17 16:37:23 +03:00
|
|
|
static TokenString tokstr_buf;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
static unsigned char isidnum_table[256 - CH_EOF];
|
2016-05-05 15:12:53 +03:00
|
|
|
static int pp_debug_tok, pp_debug_symv;
|
2016-10-01 21:03:48 +03:00
|
|
|
static int pp_once;
|
2017-06-05 14:21:39 +03:00
|
|
|
static int pp_expr;
|
2017-07-23 22:24:11 +03:00
|
|
|
static int pp_counter;
|
2016-05-05 15:12:53 +03:00
|
|
|
static void tok_print(const char *msg, const int *str);
|
|
|
|
|
2016-10-01 21:26:50 +03:00
|
|
|
static struct TinyAlloc *toksym_alloc;
|
|
|
|
static struct TinyAlloc *tokstr_alloc;
|
|
|
|
static struct TinyAlloc *cstr_alloc;
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
static TokenString *macro_stack;
|
2009-05-05 22:30:39 +04:00
|
|
|
|
2015-07-29 23:53:57 +03:00
|
|
|
static const char tcc_keywords[] =
|
2009-05-05 22:30:39 +04:00
|
|
|
#define DEF(id, str) str "\0"
|
|
|
|
#include "tcctok.h"
|
|
|
|
#undef DEF
|
|
|
|
;
|
|
|
|
|
|
|
|
/* WARNING: the content of this string encodes token numbers */
|
2009-07-19 00:07:42 +04:00
|
|
|
static const unsigned char tok_two_chars[] =
|
2014-03-29 19:40:54 +04:00
|
|
|
/* outdated -- gr
|
2009-07-19 00:07:42 +04:00
|
|
|
"<=\236>=\235!=\225&&\240||\241++\244--\242==\224<<\1>>\2+=\253"
|
|
|
|
"-=\255*=\252/=\257%=\245&=\246^=\336|=\374->\313..\250##\266";
|
2014-03-29 19:40:54 +04:00
|
|
|
*/{
|
|
|
|
'<','=', TOK_LE,
|
|
|
|
'>','=', TOK_GE,
|
|
|
|
'!','=', TOK_NE,
|
|
|
|
'&','&', TOK_LAND,
|
|
|
|
'|','|', TOK_LOR,
|
|
|
|
'+','+', TOK_INC,
|
|
|
|
'-','-', TOK_DEC,
|
|
|
|
'=','=', TOK_EQ,
|
|
|
|
'<','<', TOK_SHL,
|
2014-03-31 17:24:32 +04:00
|
|
|
'>','>', TOK_SAR,
|
2014-03-29 19:40:54 +04:00
|
|
|
'+','=', TOK_A_ADD,
|
|
|
|
'-','=', TOK_A_SUB,
|
|
|
|
'*','=', TOK_A_MUL,
|
|
|
|
'/','=', TOK_A_DIV,
|
|
|
|
'%','=', TOK_A_MOD,
|
|
|
|
'&','=', TOK_A_AND,
|
|
|
|
'^','=', TOK_A_XOR,
|
|
|
|
'|','=', TOK_A_OR,
|
|
|
|
'-','>', TOK_ARROW,
|
2017-09-24 19:57:48 +03:00
|
|
|
'.','.', TOK_TWODOTS,
|
2014-03-29 19:40:54 +04:00
|
|
|
'#','#', TOK_TWOSHARPS,
|
|
|
|
0
|
|
|
|
};
|
2009-05-05 22:30:39 +04:00
|
|
|
|
2009-05-11 20:45:56 +04:00
|
|
|
static void next_nomacro_spc(void);
|
2009-12-20 03:53:49 +03:00
|
|
|
|
|
|
|
ST_FUNC void skip(int c)
|
|
|
|
{
|
|
|
|
if (tok != c)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("'%c' expected (got \"%s\")", c, get_tok_str(tok, &tokc));
|
2009-12-20 03:53:49 +03:00
|
|
|
next();
|
|
|
|
}
|
2009-05-11 20:45:56 +04:00
|
|
|
|
2011-08-11 18:55:30 +04:00
|
|
|
ST_FUNC void expect(const char *msg)
|
|
|
|
{
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("%s expected", msg);
|
2011-08-11 18:55:30 +04:00
|
|
|
}
|
|
|
|
|
2016-10-01 21:26:50 +03:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Custom allocator for tiny objects */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2016-10-01 21:26:50 +03:00
|
|
|
#define USE_TAL
|
|
|
|
|
|
|
|
#ifndef USE_TAL
|
|
|
|
#define tal_free(al, p) tcc_free(p)
|
|
|
|
#define tal_realloc(al, p, size) tcc_realloc(p, size)
|
|
|
|
#define tal_new(a,b,c)
|
|
|
|
#define tal_delete(a)
|
|
|
|
#else
|
|
|
|
#if !defined(MEM_DEBUG)
|
|
|
|
#define tal_free(al, p) tal_free_impl(al, p)
|
|
|
|
#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size)
|
|
|
|
#define TAL_DEBUG_PARAMS
|
|
|
|
#else
|
|
|
|
#define TAL_DEBUG 1
|
2016-10-09 21:33:14 +03:00
|
|
|
//#define TAL_INFO 1 /* collect and dump allocators stats */
|
2016-10-01 21:26:50 +03:00
|
|
|
#define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__)
|
|
|
|
#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__)
|
|
|
|
#define TAL_DEBUG_PARAMS , const char *file, int line
|
2017-06-05 14:21:39 +03:00
|
|
|
#define TAL_DEBUG_FILE_LEN 40
|
2016-10-01 21:26:50 +03:00
|
|
|
#endif
|
2016-10-09 21:33:14 +03:00
|
|
|
|
|
|
|
#define TOKSYM_TAL_SIZE (768 * 1024) /* allocator for tiny TokenSym in table_ident */
|
|
|
|
#define TOKSTR_TAL_SIZE (768 * 1024) /* allocator for tiny TokenString instances */
|
|
|
|
#define CSTR_TAL_SIZE (256 * 1024) /* allocator for tiny CString instances */
|
|
|
|
#define TOKSYM_TAL_LIMIT 256 /* prefer unique limits to distinguish allocators debug msgs */
|
|
|
|
#define TOKSTR_TAL_LIMIT 128 /* 32 * sizeof(int) */
|
|
|
|
#define CSTR_TAL_LIMIT 1024
|
2016-10-01 21:26:50 +03:00
|
|
|
|
|
|
|
typedef struct TinyAlloc {
|
2016-12-19 00:05:42 +03:00
|
|
|
unsigned limit;
|
|
|
|
unsigned size;
|
2016-10-01 21:26:50 +03:00
|
|
|
uint8_t *buffer;
|
|
|
|
uint8_t *p;
|
2016-12-19 00:05:42 +03:00
|
|
|
unsigned nb_allocs;
|
2016-10-01 21:26:50 +03:00
|
|
|
struct TinyAlloc *next, *top;
|
|
|
|
#ifdef TAL_INFO
|
2016-12-19 00:05:42 +03:00
|
|
|
unsigned nb_peak;
|
|
|
|
unsigned nb_total;
|
|
|
|
unsigned nb_missed;
|
2016-10-01 21:26:50 +03:00
|
|
|
uint8_t *peak_p;
|
|
|
|
#endif
|
|
|
|
} TinyAlloc;
|
|
|
|
|
|
|
|
typedef struct tal_header_t {
|
2016-12-19 00:05:42 +03:00
|
|
|
unsigned size;
|
2016-10-01 21:26:50 +03:00
|
|
|
#ifdef TAL_DEBUG
|
|
|
|
int line_num; /* negative line_num used for double free check */
|
|
|
|
char file_name[TAL_DEBUG_FILE_LEN + 1];
|
|
|
|
#endif
|
|
|
|
} tal_header_t;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2016-04-17 16:22:50 +03:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2016-12-19 00:05:42 +03:00
|
|
|
static TinyAlloc *tal_new(TinyAlloc **pal, unsigned limit, unsigned size)
|
2016-04-17 16:22:50 +03:00
|
|
|
{
|
|
|
|
TinyAlloc *al = tcc_mallocz(sizeof(TinyAlloc));
|
|
|
|
al->p = al->buffer = tcc_malloc(size);
|
|
|
|
al->limit = limit;
|
|
|
|
al->size = size;
|
|
|
|
if (pal) *pal = al;
|
|
|
|
return al;
|
|
|
|
}
|
|
|
|
|
2016-12-19 00:05:42 +03:00
|
|
|
static void tal_delete(TinyAlloc *al)
|
2016-04-17 16:22:50 +03:00
|
|
|
{
|
|
|
|
TinyAlloc *next;
|
|
|
|
|
|
|
|
tail_call:
|
|
|
|
if (!al)
|
|
|
|
return;
|
|
|
|
#ifdef TAL_INFO
|
|
|
|
fprintf(stderr, "limit=%5d, size=%5g MB, nb_peak=%6d, nb_total=%8d, nb_missed=%6d, usage=%5.1f%%\n",
|
|
|
|
al->limit, al->size / 1024.0 / 1024.0, al->nb_peak, al->nb_total, al->nb_missed,
|
|
|
|
(al->peak_p - al->buffer) * 100.0 / al->size);
|
|
|
|
#endif
|
|
|
|
#ifdef TAL_DEBUG
|
|
|
|
if (al->nb_allocs > 0) {
|
2016-10-01 21:26:50 +03:00
|
|
|
uint8_t *p;
|
2016-12-19 00:57:03 +03:00
|
|
|
fprintf(stderr, "TAL_DEBUG: memory leak %d chunk(s) (limit= %d)\n",
|
2016-04-17 16:22:50 +03:00
|
|
|
al->nb_allocs, al->limit);
|
2016-10-01 21:26:50 +03:00
|
|
|
p = al->buffer;
|
2016-04-17 16:22:50 +03:00
|
|
|
while (p < al->p) {
|
|
|
|
tal_header_t *header = (tal_header_t *)p;
|
|
|
|
if (header->line_num > 0) {
|
2016-12-19 00:57:03 +03:00
|
|
|
fprintf(stderr, "%s:%d: chunk of %d bytes leaked\n",
|
2016-04-17 16:22:50 +03:00
|
|
|
header->file_name, header->line_num, header->size);
|
|
|
|
}
|
|
|
|
p += header->size + sizeof(tal_header_t);
|
|
|
|
}
|
2016-12-19 00:05:42 +03:00
|
|
|
#if MEM_DEBUG-0 == 2
|
|
|
|
exit(2);
|
|
|
|
#endif
|
2016-04-17 16:22:50 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
next = al->next;
|
|
|
|
tcc_free(al->buffer);
|
|
|
|
tcc_free(al);
|
|
|
|
al = next;
|
|
|
|
goto tail_call;
|
|
|
|
}
|
|
|
|
|
2016-12-19 00:05:42 +03:00
|
|
|
static void tal_free_impl(TinyAlloc *al, void *p TAL_DEBUG_PARAMS)
|
2016-04-17 16:22:50 +03:00
|
|
|
{
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
tail_call:
|
|
|
|
if (al->buffer <= (uint8_t *)p && (uint8_t *)p < al->buffer + al->size) {
|
|
|
|
#ifdef TAL_DEBUG
|
|
|
|
tal_header_t *header = (((tal_header_t *)p) - 1);
|
|
|
|
if (header->line_num < 0) {
|
2016-12-19 00:05:42 +03:00
|
|
|
fprintf(stderr, "%s:%d: TAL_DEBUG: double frees chunk from\n",
|
2016-04-17 16:22:50 +03:00
|
|
|
file, line);
|
2016-12-19 00:05:42 +03:00
|
|
|
fprintf(stderr, "%s:%d: %d bytes\n",
|
|
|
|
header->file_name, (int)-header->line_num, (int)header->size);
|
2016-04-17 16:22:50 +03:00
|
|
|
} else
|
|
|
|
header->line_num = -header->line_num;
|
|
|
|
#endif
|
|
|
|
al->nb_allocs--;
|
|
|
|
if (!al->nb_allocs)
|
|
|
|
al->p = al->buffer;
|
|
|
|
} else if (al->next) {
|
|
|
|
al = al->next;
|
|
|
|
goto tail_call;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tcc_free(p);
|
|
|
|
}
|
|
|
|
|
2016-12-19 00:05:42 +03:00
|
|
|
static void *tal_realloc_impl(TinyAlloc **pal, void *p, unsigned size TAL_DEBUG_PARAMS)
|
2016-04-17 16:22:50 +03:00
|
|
|
{
|
|
|
|
tal_header_t *header;
|
|
|
|
void *ret;
|
|
|
|
int is_own;
|
2016-12-19 00:05:42 +03:00
|
|
|
unsigned adj_size = (size + 3) & -4;
|
2016-04-17 16:22:50 +03:00
|
|
|
TinyAlloc *al = *pal;
|
|
|
|
|
|
|
|
tail_call:
|
|
|
|
is_own = (al->buffer <= (uint8_t *)p && (uint8_t *)p < al->buffer + al->size);
|
|
|
|
if ((!p || is_own) && size <= al->limit) {
|
|
|
|
if (al->p + adj_size + sizeof(tal_header_t) < al->buffer + al->size) {
|
|
|
|
header = (tal_header_t *)al->p;
|
|
|
|
header->size = adj_size;
|
|
|
|
#ifdef TAL_DEBUG
|
2016-10-01 21:26:50 +03:00
|
|
|
{ int ofs = strlen(file) - TAL_DEBUG_FILE_LEN;
|
2016-04-17 16:22:50 +03:00
|
|
|
strncpy(header->file_name, file + (ofs > 0 ? ofs : 0), TAL_DEBUG_FILE_LEN);
|
|
|
|
header->file_name[TAL_DEBUG_FILE_LEN] = 0;
|
2016-10-01 21:26:50 +03:00
|
|
|
header->line_num = line; }
|
2016-04-17 16:22:50 +03:00
|
|
|
#endif
|
|
|
|
ret = al->p + sizeof(tal_header_t);
|
|
|
|
al->p += adj_size + sizeof(tal_header_t);
|
|
|
|
if (is_own) {
|
|
|
|
header = (((tal_header_t *)p) - 1);
|
|
|
|
memcpy(ret, p, header->size);
|
|
|
|
#ifdef TAL_DEBUG
|
|
|
|
header->line_num = -header->line_num;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
al->nb_allocs++;
|
|
|
|
}
|
|
|
|
#ifdef TAL_INFO
|
|
|
|
if (al->nb_peak < al->nb_allocs)
|
|
|
|
al->nb_peak = al->nb_allocs;
|
|
|
|
if (al->peak_p < al->p)
|
|
|
|
al->peak_p = al->p;
|
|
|
|
al->nb_total++;
|
|
|
|
#endif
|
|
|
|
return ret;
|
2016-04-22 20:32:15 +03:00
|
|
|
} else if (is_own) {
|
2016-04-17 16:22:50 +03:00
|
|
|
al->nb_allocs--;
|
|
|
|
ret = tal_realloc(*pal, 0, size);
|
|
|
|
header = (((tal_header_t *)p) - 1);
|
|
|
|
memcpy(ret, p, header->size);
|
|
|
|
#ifdef TAL_DEBUG
|
|
|
|
header->line_num = -header->line_num;
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (al->next) {
|
|
|
|
al = al->next;
|
|
|
|
} else {
|
|
|
|
TinyAlloc *bottom = al, *next = al->top ? al->top : al;
|
|
|
|
|
|
|
|
al = tal_new(pal, next->limit, next->size * 2);
|
|
|
|
al->next = next;
|
|
|
|
bottom->top = al;
|
|
|
|
}
|
|
|
|
goto tail_call;
|
|
|
|
}
|
|
|
|
if (is_own) {
|
|
|
|
al->nb_allocs--;
|
|
|
|
ret = tcc_malloc(size);
|
|
|
|
header = (((tal_header_t *)p) - 1);
|
|
|
|
memcpy(ret, p, header->size);
|
|
|
|
#ifdef TAL_DEBUG
|
|
|
|
header->line_num = -header->line_num;
|
|
|
|
#endif
|
|
|
|
} else if (al->next) {
|
|
|
|
al = al->next;
|
|
|
|
goto tail_call;
|
|
|
|
} else
|
|
|
|
ret = tcc_realloc(p, size);
|
|
|
|
#ifdef TAL_INFO
|
|
|
|
al->nb_missed++;
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-10-01 21:26:50 +03:00
|
|
|
#endif /* USE_TAL */
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* CString handling */
|
|
|
|
static void cstr_realloc(CString *cstr, int new_size)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = cstr->size_allocated;
|
2016-04-17 16:37:23 +03:00
|
|
|
if (size < 8)
|
2009-12-20 03:53:49 +03:00
|
|
|
size = 8; /* no need to allocate a too small first string */
|
|
|
|
while (size < new_size)
|
|
|
|
size = size * 2;
|
2016-10-01 21:26:50 +03:00
|
|
|
cstr->data = tal_realloc(cstr_alloc, cstr->data, size);
|
2009-12-20 03:53:49 +03:00
|
|
|
cstr->size_allocated = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a byte */
|
2016-10-01 21:26:50 +03:00
|
|
|
ST_INLN void cstr_ccat(CString *cstr, int ch)
|
2009-12-20 03:53:49 +03:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
size = cstr->size + 1;
|
|
|
|
if (size > cstr->size_allocated)
|
|
|
|
cstr_realloc(cstr, size);
|
|
|
|
((unsigned char *)cstr->data)[size - 1] = ch;
|
|
|
|
cstr->size = size;
|
|
|
|
}
|
|
|
|
|
2016-04-17 16:37:23 +03:00
|
|
|
ST_FUNC void cstr_cat(CString *cstr, const char *str, int len)
|
2009-12-20 03:53:49 +03:00
|
|
|
{
|
2016-04-17 16:37:23 +03:00
|
|
|
int size;
|
|
|
|
if (len <= 0)
|
|
|
|
len = strlen(str) + 1 + len;
|
|
|
|
size = cstr->size + len;
|
|
|
|
if (size > cstr->size_allocated)
|
|
|
|
cstr_realloc(cstr, size);
|
2016-04-22 18:21:09 +03:00
|
|
|
memmove(((unsigned char *)cstr->data) + cstr->size, str, len);
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr->size = size;
|
2009-12-20 03:53:49 +03:00
|
|
|
}
|
2009-05-11 20:45:56 +04:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* add a wide char */
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC void cstr_wccat(CString *cstr, int ch)
|
2009-12-20 03:53:49 +03:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
size = cstr->size + sizeof(nwchar_t);
|
|
|
|
if (size > cstr->size_allocated)
|
|
|
|
cstr_realloc(cstr, size);
|
|
|
|
*(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = ch;
|
|
|
|
cstr->size = size;
|
|
|
|
}
|
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC void cstr_new(CString *cstr)
|
2009-12-20 03:53:49 +03:00
|
|
|
{
|
|
|
|
memset(cstr, 0, sizeof(CString));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free string and reset it to NULL */
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC void cstr_free(CString *cstr)
|
2009-12-20 03:53:49 +03:00
|
|
|
{
|
2016-10-01 21:26:50 +03:00
|
|
|
tal_free(cstr_alloc, cstr->data);
|
2009-12-20 03:53:49 +03:00
|
|
|
cstr_new(cstr);
|
|
|
|
}
|
|
|
|
|
Optimize cstr_reset() to only reset string to empty, not call free() and later malloc()
A CString could be reset to empty just setting its .size to 0.
If memory was already allocated, that would be remembered in
.data_allocated and .size_allocated and on consequent string
manipulations that memory will be used without immediate need to call
malloc().
For
$ ./tcc -B. -bench -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -c tcc.c
after the patch malloc/free are called less often:
(tcc is run in loop; perf record -a sleep 10 && perf report)
before:
# Overhead Command Shared Object Symbol
# ........ ........... .................. ..........................................
#
13.89% tcc tcc [.] next_nomacro1
4.73% tcc libc-2.13.so [.] _int_malloc
4.39% tcc tcc [.] next
2.94% tcc tcc [.] tok_str_add2
2.78% tcc tcc [.] macro_subst_tok
2.75% tcc libc-2.13.so [.] free
2.74% tcc tcc [.] macro_subst
2.63% tcc libc-2.13.so [.] _int_free
2.28% tcc tcc [.] vswap
2.24% tcc tcc [.] next_nomacro_spc
2.06% tcc libc-2.13.so [.] realloc
2.00% tcc libc-2.13.so [.] malloc
1.99% tcc tcc [.] unary
1.85% tcc libc-2.13.so [.] __i686.get_pc_thunk.bx
1.76% kworker/0:1 [kernel.kallsyms] [k] delay_tsc
1.70% tcc tcc [.] next_nomacro
1.62% tcc tcc [.] preprocess
1.41% tcc libc-2.13.so [.] __memcmp_ssse3
1.38% tcc [kernel.kallsyms] [k] memset
1.10% tcc tcc [.] g
1.06% tcc tcc [.] parse_btype
1.05% tcc tcc [.] sym_push2
1.04% tcc libc-2.13.so [.] _int_realloc
1.00% tcc libc-2.13.so [.] malloc_consolidate
after:
# Overhead Command Shared Object Symbol
# ........ ........... .................. ..............................................
#
15.26% tcc tcc [.] next_nomacro1
5.07% tcc libc-2.13.so [.] _int_malloc
4.62% tcc tcc [.] next
3.22% tcc tcc [.] tok_str_add2
3.03% tcc tcc [.] macro_subst_tok
3.02% tcc tcc [.] macro_subst
2.59% tcc tcc [.] next_nomacro_spc
2.44% tcc tcc [.] vswap
2.39% tcc libc-2.13.so [.] _int_free
2.28% tcc libc-2.13.so [.] free
2.22% tcc tcc [.] unary
2.07% tcc libc-2.13.so [.] realloc
1.97% tcc libc-2.13.so [.] malloc
1.70% tcc tcc [.] preprocess
1.69% tcc libc-2.13.so [.] __i686.get_pc_thunk.bx
1.68% tcc tcc [.] next_nomacro
1.59% tcc [kernel.kallsyms] [k] memset
1.55% tcc libc-2.13.so [.] __memcmp_ssse3
1.22% tcc tcc [.] parse_comment
1.11% tcc tcc [.] g
1.11% tcc tcc [.] sym_push2
1.10% tcc tcc [.] parse_btype
1.10% tcc libc-2.13.so [.] _int_realloc
1.06% tcc tcc [.] vsetc
0.98% tcc libc-2.13.so [.] malloc_consolidate
and this gains small speedup for tcc:
# best of 5 runs
before: 8268 idents, 47191 lines, 1526670 bytes, 0.153 s, 307997 lines/s, 10.0 MB/s
after: 8268 idents, 47203 lines, 1526763 bytes, 0.148 s, 319217 lines/s, 10.3 MB/s
2012-12-21 12:21:59 +04:00
|
|
|
/* reset string to empty */
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC void cstr_reset(CString *cstr)
|
Optimize cstr_reset() to only reset string to empty, not call free() and later malloc()
A CString could be reset to empty just setting its .size to 0.
If memory was already allocated, that would be remembered in
.data_allocated and .size_allocated and on consequent string
manipulations that memory will be used without immediate need to call
malloc().
For
$ ./tcc -B. -bench -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -c tcc.c
after the patch malloc/free are called less often:
(tcc is run in loop; perf record -a sleep 10 && perf report)
before:
# Overhead Command Shared Object Symbol
# ........ ........... .................. ..........................................
#
13.89% tcc tcc [.] next_nomacro1
4.73% tcc libc-2.13.so [.] _int_malloc
4.39% tcc tcc [.] next
2.94% tcc tcc [.] tok_str_add2
2.78% tcc tcc [.] macro_subst_tok
2.75% tcc libc-2.13.so [.] free
2.74% tcc tcc [.] macro_subst
2.63% tcc libc-2.13.so [.] _int_free
2.28% tcc tcc [.] vswap
2.24% tcc tcc [.] next_nomacro_spc
2.06% tcc libc-2.13.so [.] realloc
2.00% tcc libc-2.13.so [.] malloc
1.99% tcc tcc [.] unary
1.85% tcc libc-2.13.so [.] __i686.get_pc_thunk.bx
1.76% kworker/0:1 [kernel.kallsyms] [k] delay_tsc
1.70% tcc tcc [.] next_nomacro
1.62% tcc tcc [.] preprocess
1.41% tcc libc-2.13.so [.] __memcmp_ssse3
1.38% tcc [kernel.kallsyms] [k] memset
1.10% tcc tcc [.] g
1.06% tcc tcc [.] parse_btype
1.05% tcc tcc [.] sym_push2
1.04% tcc libc-2.13.so [.] _int_realloc
1.00% tcc libc-2.13.so [.] malloc_consolidate
after:
# Overhead Command Shared Object Symbol
# ........ ........... .................. ..............................................
#
15.26% tcc tcc [.] next_nomacro1
5.07% tcc libc-2.13.so [.] _int_malloc
4.62% tcc tcc [.] next
3.22% tcc tcc [.] tok_str_add2
3.03% tcc tcc [.] macro_subst_tok
3.02% tcc tcc [.] macro_subst
2.59% tcc tcc [.] next_nomacro_spc
2.44% tcc tcc [.] vswap
2.39% tcc libc-2.13.so [.] _int_free
2.28% tcc libc-2.13.so [.] free
2.22% tcc tcc [.] unary
2.07% tcc libc-2.13.so [.] realloc
1.97% tcc libc-2.13.so [.] malloc
1.70% tcc tcc [.] preprocess
1.69% tcc libc-2.13.so [.] __i686.get_pc_thunk.bx
1.68% tcc tcc [.] next_nomacro
1.59% tcc [kernel.kallsyms] [k] memset
1.55% tcc libc-2.13.so [.] __memcmp_ssse3
1.22% tcc tcc [.] parse_comment
1.11% tcc tcc [.] g
1.11% tcc tcc [.] sym_push2
1.10% tcc tcc [.] parse_btype
1.10% tcc libc-2.13.so [.] _int_realloc
1.06% tcc tcc [.] vsetc
0.98% tcc libc-2.13.so [.] malloc_consolidate
and this gains small speedup for tcc:
# best of 5 runs
before: 8268 idents, 47191 lines, 1526670 bytes, 0.153 s, 307997 lines/s, 10.0 MB/s
after: 8268 idents, 47203 lines, 1526763 bytes, 0.148 s, 319217 lines/s, 10.3 MB/s
2012-12-21 12:21:59 +04:00
|
|
|
{
|
|
|
|
cstr->size = 0;
|
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* XXX: unicode ? */
|
2012-04-18 20:32:37 +04:00
|
|
|
static void add_char(CString *cstr, int c)
|
2009-12-20 03:53:49 +03:00
|
|
|
{
|
|
|
|
if (c == '\'' || c == '\"' || c == '\\') {
|
|
|
|
/* XXX: could be more precise if char or string */
|
|
|
|
cstr_ccat(cstr, '\\');
|
|
|
|
}
|
|
|
|
if (c >= 32 && c <= 126) {
|
|
|
|
cstr_ccat(cstr, c);
|
|
|
|
} else {
|
|
|
|
cstr_ccat(cstr, '\\');
|
|
|
|
if (c == '\n') {
|
|
|
|
cstr_ccat(cstr, 'n');
|
|
|
|
} else {
|
|
|
|
cstr_ccat(cstr, '0' + ((c >> 6) & 7));
|
|
|
|
cstr_ccat(cstr, '0' + ((c >> 3) & 7));
|
|
|
|
cstr_ccat(cstr, '0' + (c & 7));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2009-05-05 22:30:39 +04:00
|
|
|
/* allocate a new token */
|
|
|
|
static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
|
|
|
|
{
|
|
|
|
TokenSym *ts, **ptable;
|
|
|
|
int i;
|
|
|
|
|
2015-07-29 23:53:57 +03:00
|
|
|
if (tok_ident >= SYM_FIRST_ANOM)
|
2014-01-06 22:56:26 +04:00
|
|
|
tcc_error("memory full (symbols)");
|
2009-05-05 22:30:39 +04:00
|
|
|
|
|
|
|
/* expand token table if needed */
|
|
|
|
i = tok_ident - TOK_IDENT;
|
|
|
|
if ((i % TOK_ALLOC_INCR) == 0) {
|
|
|
|
ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
|
|
|
|
table_ident = ptable;
|
|
|
|
}
|
|
|
|
|
2016-04-17 16:22:50 +03:00
|
|
|
ts = tal_realloc(toksym_alloc, 0, sizeof(TokenSym) + len);
|
2009-05-05 22:30:39 +04:00
|
|
|
table_ident[i] = ts;
|
|
|
|
ts->tok = tok_ident++;
|
|
|
|
ts->sym_define = NULL;
|
|
|
|
ts->sym_label = NULL;
|
|
|
|
ts->sym_struct = NULL;
|
|
|
|
ts->sym_identifier = NULL;
|
|
|
|
ts->len = len;
|
|
|
|
ts->hash_next = NULL;
|
|
|
|
memcpy(ts->str, str, len);
|
|
|
|
ts->str[len] = '\0';
|
|
|
|
*pts = ts;
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TOK_HASH_INIT 1
|
2016-04-17 16:37:23 +03:00
|
|
|
#define TOK_HASH_FUNC(h, c) ((h) + ((h) << 5) + ((h) >> 27) + (c))
|
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
|
|
|
|
/* find a token and add it if not found */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC TokenSym *tok_alloc(const char *str, int len)
|
2009-05-05 22:30:39 +04:00
|
|
|
{
|
|
|
|
TokenSym *ts, **pts;
|
|
|
|
int i;
|
|
|
|
unsigned int h;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
h = TOK_HASH_INIT;
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
h = TOK_HASH_FUNC(h, ((unsigned char *)str)[i]);
|
|
|
|
h &= (TOK_HASH_SIZE - 1);
|
|
|
|
|
|
|
|
pts = &hash_ident[h];
|
|
|
|
for(;;) {
|
|
|
|
ts = *pts;
|
|
|
|
if (!ts)
|
|
|
|
break;
|
|
|
|
if (ts->len == len && !memcmp(ts->str, str, len))
|
|
|
|
return ts;
|
|
|
|
pts = &(ts->hash_next);
|
|
|
|
}
|
|
|
|
return tok_alloc_new(pts, str, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: buffer overflow */
|
|
|
|
/* XXX: float tokens */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
ST_FUNC const char *get_tok_str(int v, CValue *cv)
|
2009-05-05 22:30:39 +04:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int i, len;
|
|
|
|
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_reset(&cstr_buf);
|
2016-03-13 05:26:45 +03:00
|
|
|
p = cstr_buf.data;
|
2009-05-05 22:30:39 +04:00
|
|
|
|
|
|
|
switch(v) {
|
|
|
|
case TOK_CINT:
|
|
|
|
case TOK_CUINT:
|
mutiples fix for _Generic
* check that _Generic don't match unsigned char * with char *
this case is usefull as with -funsigned-char, 'char *' are unsigned
* change VT_LONG so it's now a qualifier
VT_LONG are never use for code generation, but only durring parsing state,
in _Generic we need to be able to make diference between
'long' and 'long long'
So VT_LONG is now use as a type qualifier, it's old behaviour is still
here, but we can keep trace of what was a long and what wasn't
* add TOK_CLONG and TOK_CULONG
tcc was directly converting value like '7171L' into TOK_CLLONG or
TOK_CINT depending of the machine architecture.
because of that, we was unable to make diference between a long and a
long long, which doesn't work with _Generic.
So now 7171L is a TOK_CLONG, and we can handle _Generic properly
* check that _Generic can make diference between long and long long
* uncomment "type match twice" as it should now pass tests on any platforms
* add inside_generic global
the point of this variable is to use VT_LONG in comparaison only
when we are evaluating a _Generic.
problem is with my lastest patchs tcc can now make the diference between
a 'long long' and a 'long', but in 64 bit stddef.h typedef uint64_t as
typedef signed long long int int64_t and stdint.h as unsigned long int, so tcc
break when stdint.h and stddef.h are include together.
Another solution woud be to modifie include/stddef.h so it define uint64_t as
unsigned long int when processor is 64 bit, but this could break some
legacy code, so for now, VT_LONG are use only inside generc.
* check that _Generic parse first argument correctly
* check that _Generic evaluate correctly exresion like "f() / 2"
2017-07-10 18:44:53 +03:00
|
|
|
case TOK_CLONG:
|
|
|
|
case TOK_CULONG:
|
2009-05-05 22:30:39 +04:00
|
|
|
case TOK_CLLONG:
|
|
|
|
case TOK_CULLONG:
|
|
|
|
/* XXX: not quite exact, but only useful for testing */
|
2009-07-19 00:05:58 +04:00
|
|
|
#ifdef _WIN32
|
2015-11-17 22:09:35 +03:00
|
|
|
sprintf(p, "%u", (unsigned)cv->i);
|
2009-07-19 00:05:58 +04:00
|
|
|
#else
|
2015-11-17 22:09:35 +03:00
|
|
|
sprintf(p, "%llu", (unsigned long long)cv->i);
|
2009-07-19 00:05:58 +04:00
|
|
|
#endif
|
2009-05-05 22:30:39 +04:00
|
|
|
break;
|
|
|
|
case TOK_LCHAR:
|
|
|
|
cstr_ccat(&cstr_buf, 'L');
|
|
|
|
case TOK_CCHAR:
|
|
|
|
cstr_ccat(&cstr_buf, '\'');
|
|
|
|
add_char(&cstr_buf, cv->i);
|
|
|
|
cstr_ccat(&cstr_buf, '\'');
|
|
|
|
cstr_ccat(&cstr_buf, '\0');
|
|
|
|
break;
|
|
|
|
case TOK_PPNUM:
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
case TOK_PPSTR:
|
2015-11-21 14:23:53 +03:00
|
|
|
return (char*)cv->str.data;
|
2009-05-05 22:30:39 +04:00
|
|
|
case TOK_LSTR:
|
|
|
|
cstr_ccat(&cstr_buf, 'L');
|
|
|
|
case TOK_STR:
|
|
|
|
cstr_ccat(&cstr_buf, '\"');
|
|
|
|
if (v == TOK_STR) {
|
2015-11-21 14:23:53 +03:00
|
|
|
len = cv->str.size - 1;
|
2009-05-05 22:30:39 +04:00
|
|
|
for(i=0;i<len;i++)
|
2015-11-21 14:23:53 +03:00
|
|
|
add_char(&cstr_buf, ((unsigned char *)cv->str.data)[i]);
|
2009-05-05 22:30:39 +04:00
|
|
|
} else {
|
2015-11-21 14:23:53 +03:00
|
|
|
len = (cv->str.size / sizeof(nwchar_t)) - 1;
|
2009-05-05 22:30:39 +04:00
|
|
|
for(i=0;i<len;i++)
|
2015-11-21 14:23:53 +03:00
|
|
|
add_char(&cstr_buf, ((nwchar_t *)cv->str.data)[i]);
|
2009-05-05 22:30:39 +04:00
|
|
|
}
|
|
|
|
cstr_ccat(&cstr_buf, '\"');
|
|
|
|
cstr_ccat(&cstr_buf, '\0');
|
|
|
|
break;
|
2014-03-29 19:40:54 +04:00
|
|
|
|
|
|
|
case TOK_CFLOAT:
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_cat(&cstr_buf, "<float>", 0);
|
2015-11-20 13:22:56 +03:00
|
|
|
break;
|
2014-03-29 19:40:54 +04:00
|
|
|
case TOK_CDOUBLE:
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_cat(&cstr_buf, "<double>", 0);
|
2015-11-20 13:22:56 +03:00
|
|
|
break;
|
2014-03-29 19:40:54 +04:00
|
|
|
case TOK_CLDOUBLE:
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_cat(&cstr_buf, "<long double>", 0);
|
2015-11-20 13:22:56 +03:00
|
|
|
break;
|
2014-03-29 19:40:54 +04:00
|
|
|
case TOK_LINENUM:
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_cat(&cstr_buf, "<linenumber>", 0);
|
2015-11-20 13:22:56 +03:00
|
|
|
break;
|
2014-03-29 19:40:54 +04:00
|
|
|
|
|
|
|
/* above tokens have value, the ones below don't */
|
2009-05-05 22:30:39 +04:00
|
|
|
case TOK_LT:
|
|
|
|
v = '<';
|
|
|
|
goto addv;
|
|
|
|
case TOK_GT:
|
|
|
|
v = '>';
|
|
|
|
goto addv;
|
|
|
|
case TOK_DOTS:
|
|
|
|
return strcpy(p, "...");
|
|
|
|
case TOK_A_SHL:
|
|
|
|
return strcpy(p, "<<=");
|
|
|
|
case TOK_A_SAR:
|
|
|
|
return strcpy(p, ">>=");
|
2017-07-09 13:07:40 +03:00
|
|
|
case TOK_EOF:
|
|
|
|
return strcpy(p, "<eof>");
|
2009-05-05 22:30:39 +04:00
|
|
|
default:
|
|
|
|
if (v < TOK_IDENT) {
|
|
|
|
/* search in two bytes table */
|
2009-07-19 00:07:42 +04:00
|
|
|
const unsigned char *q = tok_two_chars;
|
2009-05-05 22:30:39 +04:00
|
|
|
while (*q) {
|
|
|
|
if (q[2] == v) {
|
|
|
|
*p++ = q[0];
|
|
|
|
*p++ = q[1];
|
|
|
|
*p = '\0';
|
2016-03-13 05:26:45 +03:00
|
|
|
return cstr_buf.data;
|
2009-05-05 22:30:39 +04:00
|
|
|
}
|
|
|
|
q += 3;
|
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (v >= 127) {
|
2016-03-13 05:26:45 +03:00
|
|
|
sprintf(cstr_buf.data, "<%02x>", v);
|
|
|
|
return cstr_buf.data;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
}
|
2009-05-05 22:30:39 +04:00
|
|
|
addv:
|
|
|
|
*p++ = v;
|
|
|
|
*p = '\0';
|
|
|
|
} else if (v < tok_ident) {
|
|
|
|
return table_ident[v - TOK_IDENT]->str;
|
|
|
|
} else if (v >= SYM_FIRST_ANOM) {
|
|
|
|
/* special name for anonymous symbol */
|
|
|
|
sprintf(p, "L.%u", v - SYM_FIRST_ANOM);
|
|
|
|
} else {
|
|
|
|
/* should never happen */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return cstr_buf.data;
|
|
|
|
}
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* return the current character, handling end of block if necessary
|
|
|
|
(but not stray) */
|
|
|
|
ST_FUNC int handle_eob(void)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
BufferedFile *bf = file;
|
2009-05-05 22:17:49 +04:00
|
|
|
int len;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* only tries to read if really end of buffer */
|
|
|
|
if (bf->buf_ptr >= bf->buf_end) {
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
if (bf->fd >= 0) {
|
2009-05-05 22:17:49 +04:00
|
|
|
#if defined(PARSE_DEBUG)
|
2015-05-01 00:31:32 +03:00
|
|
|
len = 1;
|
2009-05-05 22:17:49 +04:00
|
|
|
#else
|
|
|
|
len = IO_BUF_SIZE;
|
|
|
|
#endif
|
2013-01-14 20:34:07 +04:00
|
|
|
len = read(bf->fd, bf->buffer, len);
|
2009-05-05 22:17:49 +04:00
|
|
|
if (len < 0)
|
|
|
|
len = 0;
|
|
|
|
} else {
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
total_bytes += len;
|
|
|
|
bf->buf_ptr = bf->buffer;
|
|
|
|
bf->buf_end = bf->buffer + len;
|
|
|
|
*bf->buf_end = CH_EOB;
|
|
|
|
}
|
|
|
|
if (bf->buf_ptr < bf->buf_end) {
|
|
|
|
return bf->buf_ptr[0];
|
|
|
|
} else {
|
|
|
|
bf->buf_ptr = bf->buf_end;
|
|
|
|
return CH_EOF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read next char from current input file and handle end of input buffer */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_INLN void inp(void)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
ch = *(++(file->buf_ptr));
|
|
|
|
/* end of buffer/file handling */
|
|
|
|
if (ch == CH_EOB)
|
|
|
|
ch = handle_eob();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle '\[\r]\n' */
|
|
|
|
static int handle_stray_noerror(void)
|
|
|
|
{
|
|
|
|
while (ch == '\\') {
|
|
|
|
inp();
|
|
|
|
if (ch == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
inp();
|
|
|
|
} else if (ch == '\r') {
|
|
|
|
inp();
|
|
|
|
if (ch != '\n')
|
|
|
|
goto fail;
|
|
|
|
file->line_num++;
|
|
|
|
inp();
|
|
|
|
} else {
|
|
|
|
fail:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_stray(void)
|
|
|
|
{
|
|
|
|
if (handle_stray_noerror())
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("stray '\\' in program");
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* skip the stray and handle the \\n case. Output an error if
|
|
|
|
incorrect char after the stray */
|
|
|
|
static int handle_stray1(uint8_t *p)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
file->buf_ptr = p;
|
2009-05-05 22:17:49 +04:00
|
|
|
if (p >= file->buf_end) {
|
|
|
|
c = handle_eob();
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (c != '\\')
|
|
|
|
return c;
|
2009-05-05 22:17:49 +04:00
|
|
|
p = file->buf_ptr;
|
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
ch = *p;
|
|
|
|
if (handle_stray_noerror()) {
|
|
|
|
if (!(parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
|
|
|
|
tcc_error("stray '\\' in program");
|
|
|
|
*--file->buf_ptr = '\\';
|
|
|
|
}
|
|
|
|
p = file->buf_ptr;
|
|
|
|
c = *p;
|
2009-05-05 22:17:49 +04:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle just the EOB case, but not stray */
|
|
|
|
#define PEEKC_EOB(c, p)\
|
|
|
|
{\
|
|
|
|
p++;\
|
|
|
|
c = *p;\
|
|
|
|
if (c == '\\') {\
|
|
|
|
file->buf_ptr = p;\
|
|
|
|
c = handle_eob();\
|
|
|
|
p = file->buf_ptr;\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle the complicated stray case */
|
|
|
|
#define PEEKC(c, p)\
|
|
|
|
{\
|
|
|
|
p++;\
|
|
|
|
c = *p;\
|
|
|
|
if (c == '\\') {\
|
|
|
|
c = handle_stray1(p);\
|
|
|
|
p = file->buf_ptr;\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
|
|
|
/* input with '\[\r]\n' handling. Note that this function cannot
|
|
|
|
handle other characters after '\', so you cannot call it inside
|
|
|
|
strings or comments */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void minp(void)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
inp();
|
2015-07-29 23:53:57 +03:00
|
|
|
if (ch == '\\')
|
2009-05-05 22:17:49 +04:00
|
|
|
handle_stray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* single line C++ comments */
|
2016-05-05 15:12:53 +03:00
|
|
|
static uint8_t *parse_line_comment(uint8_t *p)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
p++;
|
|
|
|
for(;;) {
|
|
|
|
c = *p;
|
|
|
|
redo:
|
|
|
|
if (c == '\n' || c == CH_EOF) {
|
|
|
|
break;
|
|
|
|
} else if (c == '\\') {
|
|
|
|
file->buf_ptr = p;
|
|
|
|
c = handle_eob();
|
|
|
|
p = file->buf_ptr;
|
|
|
|
if (c == '\\') {
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
if (c == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
} else if (c == '\r') {
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
if (c == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto redo;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* C comments */
|
2016-05-05 15:12:53 +03:00
|
|
|
ST_FUNC uint8_t *parse_comment(uint8_t *p)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
int c;
|
2016-04-15 17:15:11 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
p++;
|
|
|
|
for(;;) {
|
|
|
|
/* fast skip loop */
|
|
|
|
for(;;) {
|
|
|
|
c = *p;
|
|
|
|
if (c == '\n' || c == '*' || c == '\\')
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
c = *p;
|
|
|
|
if (c == '\n' || c == '*' || c == '\\')
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
/* now we can handle all the cases */
|
|
|
|
if (c == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
p++;
|
|
|
|
} else if (c == '*') {
|
|
|
|
p++;
|
|
|
|
for(;;) {
|
|
|
|
c = *p;
|
|
|
|
if (c == '*') {
|
|
|
|
p++;
|
|
|
|
} else if (c == '/') {
|
|
|
|
goto end_of_comment;
|
|
|
|
} else if (c == '\\') {
|
|
|
|
file->buf_ptr = p;
|
|
|
|
c = handle_eob();
|
|
|
|
p = file->buf_ptr;
|
2015-10-15 21:02:58 +03:00
|
|
|
if (c == CH_EOF)
|
|
|
|
tcc_error("unexpected end of file in comment");
|
2009-05-05 22:17:49 +04:00
|
|
|
if (c == '\\') {
|
|
|
|
/* skip '\[\r]\n', otherwise just skip the stray */
|
|
|
|
while (c == '\\') {
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
if (c == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
} else if (c == '\r') {
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
if (c == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto after_star;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
after_star: ;
|
|
|
|
} else {
|
|
|
|
/* stray, eob or eof */
|
|
|
|
file->buf_ptr = p;
|
|
|
|
c = handle_eob();
|
|
|
|
p = file->buf_ptr;
|
|
|
|
if (c == CH_EOF) {
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("unexpected end of file in comment");
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if (c == '\\') {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end_of_comment:
|
|
|
|
p++;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:21:27 +03:00
|
|
|
ST_FUNC int set_idnum(int c, int val)
|
2016-08-25 17:40:50 +03:00
|
|
|
{
|
2017-07-20 23:21:27 +03:00
|
|
|
int prev = isidnum_table[c - CH_EOF];
|
2016-08-25 17:40:50 +03:00
|
|
|
isidnum_table[c - CH_EOF] = val;
|
2017-07-20 23:21:27 +03:00
|
|
|
return prev;
|
2016-08-25 17:40:50 +03:00
|
|
|
}
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
#define cinp minp
|
|
|
|
|
|
|
|
static inline void skip_spaces(void)
|
|
|
|
{
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
while (isidnum_table[ch - CH_EOF] & IS_SPC)
|
2009-05-05 22:17:49 +04:00
|
|
|
cinp();
|
|
|
|
}
|
|
|
|
|
2015-07-29 23:53:57 +03:00
|
|
|
static inline int check_space(int t, int *spc)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (t < 256 && (isidnum_table[t - CH_EOF] & IS_SPC)) {
|
2015-07-29 23:53:57 +03:00
|
|
|
if (*spc)
|
2009-05-05 22:17:49 +04:00
|
|
|
return 1;
|
|
|
|
*spc = 1;
|
2015-07-29 23:53:57 +03:00
|
|
|
} else
|
2009-05-05 22:17:49 +04:00
|
|
|
*spc = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse a string without interpreting escapes */
|
|
|
|
static uint8_t *parse_pp_string(uint8_t *p,
|
|
|
|
int sep, CString *str)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
p++;
|
|
|
|
for(;;) {
|
|
|
|
c = *p;
|
|
|
|
if (c == sep) {
|
|
|
|
break;
|
|
|
|
} else if (c == '\\') {
|
|
|
|
file->buf_ptr = p;
|
|
|
|
c = handle_eob();
|
|
|
|
p = file->buf_ptr;
|
|
|
|
if (c == CH_EOF) {
|
|
|
|
unterminated_string:
|
|
|
|
/* XXX: indicate line number of start of string */
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("missing terminating %c character", sep);
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if (c == '\\') {
|
|
|
|
/* escape : just skip \[\r]\n */
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
if (c == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
p++;
|
|
|
|
} else if (c == '\r') {
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
if (c != '\n')
|
|
|
|
expect("'\n' after '\r'");
|
|
|
|
file->line_num++;
|
|
|
|
p++;
|
|
|
|
} else if (c == CH_EOF) {
|
|
|
|
goto unterminated_string;
|
|
|
|
} else {
|
|
|
|
if (str) {
|
|
|
|
cstr_ccat(str, '\\');
|
|
|
|
cstr_ccat(str, c);
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c == '\n') {
|
|
|
|
file->line_num++;
|
|
|
|
goto add_char;
|
|
|
|
} else if (c == '\r') {
|
|
|
|
PEEKC_EOB(c, p);
|
|
|
|
if (c != '\n') {
|
|
|
|
if (str)
|
|
|
|
cstr_ccat(str, '\r');
|
|
|
|
} else {
|
|
|
|
file->line_num++;
|
|
|
|
goto add_char;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
add_char:
|
|
|
|
if (str)
|
|
|
|
cstr_ccat(str, c);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip block of text until #else, #elif or #endif. skip also pairs of
|
|
|
|
#if/#endif */
|
2009-12-20 03:53:49 +03:00
|
|
|
static void preprocess_skip(void)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
int a, start_of_line, c, in_warn_or_error;
|
|
|
|
uint8_t *p;
|
|
|
|
|
|
|
|
p = file->buf_ptr;
|
|
|
|
a = 0;
|
|
|
|
redo_start:
|
|
|
|
start_of_line = 1;
|
|
|
|
in_warn_or_error = 0;
|
|
|
|
for(;;) {
|
|
|
|
redo_no_start:
|
|
|
|
c = *p;
|
|
|
|
switch(c) {
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
case '\f':
|
|
|
|
case '\v':
|
|
|
|
case '\r':
|
|
|
|
p++;
|
|
|
|
goto redo_no_start;
|
|
|
|
case '\n':
|
|
|
|
file->line_num++;
|
|
|
|
p++;
|
|
|
|
goto redo_start;
|
|
|
|
case '\\':
|
|
|
|
file->buf_ptr = p;
|
|
|
|
c = handle_eob();
|
|
|
|
if (c == CH_EOF) {
|
|
|
|
expect("#endif");
|
|
|
|
} else if (c == '\\') {
|
|
|
|
ch = file->buf_ptr[0];
|
|
|
|
handle_stray_noerror();
|
|
|
|
}
|
|
|
|
p = file->buf_ptr;
|
|
|
|
goto redo_no_start;
|
|
|
|
/* skip strings */
|
|
|
|
case '\"':
|
|
|
|
case '\'':
|
|
|
|
if (in_warn_or_error)
|
|
|
|
goto _default;
|
|
|
|
p = parse_pp_string(p, c, NULL);
|
|
|
|
break;
|
|
|
|
/* skip comments */
|
|
|
|
case '/':
|
|
|
|
if (in_warn_or_error)
|
|
|
|
goto _default;
|
|
|
|
file->buf_ptr = p;
|
|
|
|
ch = *p;
|
|
|
|
minp();
|
|
|
|
p = file->buf_ptr;
|
|
|
|
if (ch == '*') {
|
2016-05-05 15:12:53 +03:00
|
|
|
p = parse_comment(p);
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if (ch == '/') {
|
2016-05-05 15:12:53 +03:00
|
|
|
p = parse_line_comment(p);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
p++;
|
|
|
|
if (start_of_line) {
|
|
|
|
file->buf_ptr = p;
|
|
|
|
next_nomacro();
|
|
|
|
p = file->buf_ptr;
|
2015-07-29 23:53:57 +03:00
|
|
|
if (a == 0 &&
|
2009-05-05 22:17:49 +04:00
|
|
|
(tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF))
|
|
|
|
goto the_end;
|
|
|
|
if (tok == TOK_IF || tok == TOK_IFDEF || tok == TOK_IFNDEF)
|
|
|
|
a++;
|
|
|
|
else if (tok == TOK_ENDIF)
|
|
|
|
a--;
|
|
|
|
else if( tok == TOK_ERROR || tok == TOK_WARNING)
|
|
|
|
in_warn_or_error = 1;
|
2011-03-06 21:13:12 +03:00
|
|
|
else if (tok == TOK_LINEFEED)
|
|
|
|
goto redo_start;
|
2016-04-14 21:46:46 +03:00
|
|
|
else if (parse_flags & PARSE_FLAG_ASM_FILE)
|
2016-10-01 23:01:25 +03:00
|
|
|
p = parse_line_comment(p - 1);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} else if (parse_flags & PARSE_FLAG_ASM_FILE)
|
2016-10-01 23:01:25 +03:00
|
|
|
p = parse_line_comment(p - 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
|
|
|
_default:
|
|
|
|
default:
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
start_of_line = 0;
|
|
|
|
}
|
|
|
|
the_end: ;
|
|
|
|
file->buf_ptr = p;
|
|
|
|
}
|
|
|
|
|
2017-04-25 22:01:54 +03:00
|
|
|
#if 0
|
|
|
|
/* return the number of additional 'ints' necessary to store the
|
|
|
|
token */
|
|
|
|
static inline int tok_size(const int *p)
|
|
|
|
{
|
|
|
|
switch(*p) {
|
|
|
|
/* 4 bytes */
|
|
|
|
case TOK_CINT:
|
|
|
|
case TOK_CUINT:
|
|
|
|
case TOK_CCHAR:
|
|
|
|
case TOK_LCHAR:
|
|
|
|
case TOK_CFLOAT:
|
|
|
|
case TOK_LINENUM:
|
|
|
|
return 1 + 1;
|
|
|
|
case TOK_STR:
|
|
|
|
case TOK_LSTR:
|
|
|
|
case TOK_PPNUM:
|
|
|
|
case TOK_PPSTR:
|
|
|
|
return 1 + ((sizeof(CString) + ((CString *)(p+1))->size + 3) >> 2);
|
2017-09-24 19:57:48 +03:00
|
|
|
case TOK_CLONG:
|
|
|
|
case TOK_CULONG:
|
|
|
|
return 1 + LONG_SIZE / 4;
|
2017-04-25 22:01:54 +03:00
|
|
|
case TOK_CDOUBLE:
|
|
|
|
case TOK_CLLONG:
|
|
|
|
case TOK_CULLONG:
|
|
|
|
return 1 + 2;
|
|
|
|
case TOK_CLDOUBLE:
|
|
|
|
return 1 + LDOUBLE_SIZE / 4;
|
|
|
|
default:
|
|
|
|
return 1 + 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
|
2017-04-25 22:01:54 +03:00
|
|
|
/* token string handling */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_INLN void tok_str_new(TokenString *s)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
s->str = NULL;
|
2017-06-05 14:21:39 +03:00
|
|
|
s->len = s->lastlen = 0;
|
2009-05-05 22:17:49 +04:00
|
|
|
s->allocated_len = 0;
|
|
|
|
s->last_line_num = -1;
|
|
|
|
}
|
|
|
|
|
2016-10-01 21:26:50 +03:00
|
|
|
ST_FUNC TokenString *tok_str_alloc(void)
|
|
|
|
{
|
|
|
|
TokenString *str = tal_realloc(tokstr_alloc, 0, sizeof *str);
|
|
|
|
tok_str_new(str);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2016-04-17 16:37:23 +03:00
|
|
|
ST_FUNC int *tok_str_dup(TokenString *s)
|
|
|
|
{
|
|
|
|
int *str;
|
|
|
|
|
2016-04-17 16:22:50 +03:00
|
|
|
str = tal_realloc(tokstr_alloc, 0, s->len * sizeof(int));
|
2016-04-17 16:37:23 +03:00
|
|
|
memcpy(str, s->str, s->len * sizeof(int));
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:25:13 +03:00
|
|
|
ST_FUNC void tok_str_free_str(int *str)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
2016-04-17 16:22:50 +03:00
|
|
|
tal_free(tokstr_alloc, str);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
2016-11-11 22:25:13 +03:00
|
|
|
ST_FUNC void tok_str_free(TokenString *str)
|
|
|
|
{
|
|
|
|
tok_str_free_str(str->str);
|
|
|
|
tal_free(tokstr_alloc, str);
|
|
|
|
}
|
|
|
|
|
2016-04-17 16:37:23 +03:00
|
|
|
ST_FUNC int *tok_str_realloc(TokenString *s, int new_size)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
2016-04-17 16:37:23 +03:00
|
|
|
int *str, size;
|
2009-05-05 22:17:49 +04:00
|
|
|
|
2016-04-17 16:37:23 +03:00
|
|
|
size = s->allocated_len;
|
|
|
|
if (size < 16)
|
|
|
|
size = 16;
|
|
|
|
while (size < new_size)
|
|
|
|
size = size * 2;
|
|
|
|
if (size > s->allocated_len) {
|
2016-04-17 16:22:50 +03:00
|
|
|
str = tal_realloc(tokstr_alloc, s->str, size * sizeof(int));
|
2016-04-17 16:37:23 +03:00
|
|
|
s->allocated_len = size;
|
|
|
|
s->str = str;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2016-04-17 16:37:23 +03:00
|
|
|
return s->str;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void tok_str_add(TokenString *s, int t)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
int len, *str;
|
|
|
|
|
|
|
|
len = s->len;
|
|
|
|
str = s->str;
|
|
|
|
if (len >= s->allocated_len)
|
2016-04-17 16:37:23 +03:00
|
|
|
str = tok_str_realloc(s, len + 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
str[len++] = t;
|
|
|
|
s->len = len;
|
|
|
|
}
|
|
|
|
|
2016-10-01 21:26:50 +03:00
|
|
|
ST_FUNC void begin_macro(TokenString *str, int alloc)
|
|
|
|
{
|
|
|
|
str->alloc = alloc;
|
|
|
|
str->prev = macro_stack;
|
|
|
|
str->prev_ptr = macro_ptr;
|
2017-07-20 23:21:27 +03:00
|
|
|
str->save_line_num = file->line_num;
|
2016-10-01 21:26:50 +03:00
|
|
|
macro_ptr = str->str;
|
|
|
|
macro_stack = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
ST_FUNC void end_macro(void)
|
|
|
|
{
|
|
|
|
TokenString *str = macro_stack;
|
|
|
|
macro_stack = str->prev;
|
|
|
|
macro_ptr = str->prev_ptr;
|
2017-07-20 23:21:27 +03:00
|
|
|
file->line_num = str->save_line_num;
|
2016-10-01 21:26:50 +03:00
|
|
|
if (str->alloc == 2) {
|
|
|
|
str->alloc = 3; /* just mark as finished */
|
|
|
|
} else {
|
2016-11-11 22:25:13 +03:00
|
|
|
tok_str_free(str);
|
2016-10-01 21:26:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
static void tok_str_add2(TokenString *s, int t, CValue *cv)
|
|
|
|
{
|
|
|
|
int len, *str;
|
|
|
|
|
2017-06-05 14:21:39 +03:00
|
|
|
len = s->lastlen = s->len;
|
2009-05-05 22:17:49 +04:00
|
|
|
str = s->str;
|
|
|
|
|
|
|
|
/* allocate space for worst case */
|
2016-04-17 16:37:23 +03:00
|
|
|
if (len + TOK_MAX_SIZE >= s->allocated_len)
|
|
|
|
str = tok_str_realloc(s, len + TOK_MAX_SIZE + 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
str[len++] = t;
|
|
|
|
switch(t) {
|
|
|
|
case TOK_CINT:
|
|
|
|
case TOK_CUINT:
|
|
|
|
case TOK_CCHAR:
|
|
|
|
case TOK_LCHAR:
|
|
|
|
case TOK_CFLOAT:
|
|
|
|
case TOK_LINENUM:
|
2017-09-24 19:57:48 +03:00
|
|
|
#if LONG_SIZE == 4
|
mutiples fix for _Generic
* check that _Generic don't match unsigned char * with char *
this case is usefull as with -funsigned-char, 'char *' are unsigned
* change VT_LONG so it's now a qualifier
VT_LONG are never use for code generation, but only durring parsing state,
in _Generic we need to be able to make diference between
'long' and 'long long'
So VT_LONG is now use as a type qualifier, it's old behaviour is still
here, but we can keep trace of what was a long and what wasn't
* add TOK_CLONG and TOK_CULONG
tcc was directly converting value like '7171L' into TOK_CLLONG or
TOK_CINT depending of the machine architecture.
because of that, we was unable to make diference between a long and a
long long, which doesn't work with _Generic.
So now 7171L is a TOK_CLONG, and we can handle _Generic properly
* check that _Generic can make diference between long and long long
* uncomment "type match twice" as it should now pass tests on any platforms
* add inside_generic global
the point of this variable is to use VT_LONG in comparaison only
when we are evaluating a _Generic.
problem is with my lastest patchs tcc can now make the diference between
a 'long long' and a 'long', but in 64 bit stddef.h typedef uint64_t as
typedef signed long long int int64_t and stdint.h as unsigned long int, so tcc
break when stdint.h and stddef.h are include together.
Another solution woud be to modifie include/stddef.h so it define uint64_t as
unsigned long int when processor is 64 bit, but this could break some
legacy code, so for now, VT_LONG are use only inside generc.
* check that _Generic parse first argument correctly
* check that _Generic evaluate correctly exresion like "f() / 2"
2017-07-10 18:44:53 +03:00
|
|
|
case TOK_CLONG:
|
|
|
|
case TOK_CULONG:
|
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
str[len++] = cv->tab[0];
|
|
|
|
break;
|
|
|
|
case TOK_PPNUM:
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
case TOK_PPSTR:
|
2009-05-05 22:17:49 +04:00
|
|
|
case TOK_STR:
|
|
|
|
case TOK_LSTR:
|
|
|
|
{
|
2015-11-21 14:23:53 +03:00
|
|
|
/* Insert the string into the int array. */
|
|
|
|
size_t nb_words =
|
|
|
|
1 + (cv->str.size + sizeof(int) - 1) / sizeof(int);
|
2016-04-17 16:37:23 +03:00
|
|
|
if (len + nb_words >= s->allocated_len)
|
|
|
|
str = tok_str_realloc(s, len + nb_words + 1);
|
2015-11-21 14:23:53 +03:00
|
|
|
str[len] = cv->str.size;
|
|
|
|
memcpy(&str[len + 1], cv->str.data, cv->str.size);
|
2009-05-05 22:17:49 +04:00
|
|
|
len += nb_words;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TOK_CDOUBLE:
|
|
|
|
case TOK_CLLONG:
|
|
|
|
case TOK_CULLONG:
|
2017-09-24 19:57:48 +03:00
|
|
|
#if LONG_SIZE == 8
|
mutiples fix for _Generic
* check that _Generic don't match unsigned char * with char *
this case is usefull as with -funsigned-char, 'char *' are unsigned
* change VT_LONG so it's now a qualifier
VT_LONG are never use for code generation, but only durring parsing state,
in _Generic we need to be able to make diference between
'long' and 'long long'
So VT_LONG is now use as a type qualifier, it's old behaviour is still
here, but we can keep trace of what was a long and what wasn't
* add TOK_CLONG and TOK_CULONG
tcc was directly converting value like '7171L' into TOK_CLLONG or
TOK_CINT depending of the machine architecture.
because of that, we was unable to make diference between a long and a
long long, which doesn't work with _Generic.
So now 7171L is a TOK_CLONG, and we can handle _Generic properly
* check that _Generic can make diference between long and long long
* uncomment "type match twice" as it should now pass tests on any platforms
* add inside_generic global
the point of this variable is to use VT_LONG in comparaison only
when we are evaluating a _Generic.
problem is with my lastest patchs tcc can now make the diference between
a 'long long' and a 'long', but in 64 bit stddef.h typedef uint64_t as
typedef signed long long int int64_t and stdint.h as unsigned long int, so tcc
break when stdint.h and stddef.h are include together.
Another solution woud be to modifie include/stddef.h so it define uint64_t as
unsigned long int when processor is 64 bit, but this could break some
legacy code, so for now, VT_LONG are use only inside generc.
* check that _Generic parse first argument correctly
* check that _Generic evaluate correctly exresion like "f() / 2"
2017-07-10 18:44:53 +03:00
|
|
|
case TOK_CLONG:
|
|
|
|
case TOK_CULONG:
|
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
#if LDOUBLE_SIZE == 8
|
|
|
|
case TOK_CLDOUBLE:
|
|
|
|
#endif
|
|
|
|
str[len++] = cv->tab[0];
|
|
|
|
str[len++] = cv->tab[1];
|
|
|
|
break;
|
|
|
|
#if LDOUBLE_SIZE == 12
|
|
|
|
case TOK_CLDOUBLE:
|
|
|
|
str[len++] = cv->tab[0];
|
|
|
|
str[len++] = cv->tab[1];
|
|
|
|
str[len++] = cv->tab[2];
|
|
|
|
#elif LDOUBLE_SIZE == 16
|
|
|
|
case TOK_CLDOUBLE:
|
|
|
|
str[len++] = cv->tab[0];
|
|
|
|
str[len++] = cv->tab[1];
|
|
|
|
str[len++] = cv->tab[2];
|
|
|
|
str[len++] = cv->tab[3];
|
|
|
|
#elif LDOUBLE_SIZE != 8
|
|
|
|
#error add long double size support
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the current parse token in token string 's' */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void tok_str_add_tok(TokenString *s)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
CValue cval;
|
|
|
|
|
|
|
|
/* save line number info */
|
|
|
|
if (file->line_num != s->last_line_num) {
|
|
|
|
s->last_line_num = file->line_num;
|
|
|
|
cval.i = s->last_line_num;
|
|
|
|
tok_str_add2(s, TOK_LINENUM, &cval);
|
|
|
|
}
|
|
|
|
tok_str_add2(s, tok, &tokc);
|
|
|
|
}
|
|
|
|
|
2010-01-14 22:58:03 +03:00
|
|
|
/* 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++) {
|
2017-09-24 19:57:48 +03:00
|
|
|
#if LONG_SIZE == 4
|
|
|
|
case TOK_CLONG:
|
|
|
|
#endif
|
2010-01-14 22:58:03 +03:00
|
|
|
case TOK_CINT:
|
|
|
|
case TOK_CCHAR:
|
|
|
|
case TOK_LCHAR:
|
|
|
|
case TOK_LINENUM:
|
2017-09-24 19:57:48 +03:00
|
|
|
cv->i = *p++;
|
|
|
|
break;
|
|
|
|
#if LONG_SIZE == 4
|
mutiples fix for _Generic
* check that _Generic don't match unsigned char * with char *
this case is usefull as with -funsigned-char, 'char *' are unsigned
* change VT_LONG so it's now a qualifier
VT_LONG are never use for code generation, but only durring parsing state,
in _Generic we need to be able to make diference between
'long' and 'long long'
So VT_LONG is now use as a type qualifier, it's old behaviour is still
here, but we can keep trace of what was a long and what wasn't
* add TOK_CLONG and TOK_CULONG
tcc was directly converting value like '7171L' into TOK_CLLONG or
TOK_CINT depending of the machine architecture.
because of that, we was unable to make diference between a long and a
long long, which doesn't work with _Generic.
So now 7171L is a TOK_CLONG, and we can handle _Generic properly
* check that _Generic can make diference between long and long long
* uncomment "type match twice" as it should now pass tests on any platforms
* add inside_generic global
the point of this variable is to use VT_LONG in comparaison only
when we are evaluating a _Generic.
problem is with my lastest patchs tcc can now make the diference between
a 'long long' and a 'long', but in 64 bit stddef.h typedef uint64_t as
typedef signed long long int int64_t and stdint.h as unsigned long int, so tcc
break when stdint.h and stddef.h are include together.
Another solution woud be to modifie include/stddef.h so it define uint64_t as
unsigned long int when processor is 64 bit, but this could break some
legacy code, so for now, VT_LONG are use only inside generc.
* check that _Generic parse first argument correctly
* check that _Generic evaluate correctly exresion like "f() / 2"
2017-07-10 18:44:53 +03:00
|
|
|
case TOK_CULONG:
|
|
|
|
#endif
|
2017-09-24 19:57:48 +03:00
|
|
|
case TOK_CUINT:
|
|
|
|
cv->i = (unsigned)*p++;
|
2010-01-14 22:58:03 +03:00
|
|
|
break;
|
2017-03-06 23:45:41 +03:00
|
|
|
case TOK_CFLOAT:
|
|
|
|
tab[0] = *p++;
|
|
|
|
break;
|
2010-01-14 22:58:03 +03:00
|
|
|
case TOK_STR:
|
|
|
|
case TOK_LSTR:
|
|
|
|
case TOK_PPNUM:
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
case TOK_PPSTR:
|
2015-11-21 14:23:53 +03:00
|
|
|
cv->str.size = *p++;
|
|
|
|
cv->str.data = p;
|
|
|
|
p += (cv->str.size + sizeof(int) - 1) / sizeof(int);
|
2010-01-14 22:58:03 +03:00
|
|
|
break;
|
|
|
|
case TOK_CDOUBLE:
|
|
|
|
case TOK_CLLONG:
|
|
|
|
case TOK_CULLONG:
|
2017-09-24 19:57:48 +03:00
|
|
|
#if LONG_SIZE == 8
|
mutiples fix for _Generic
* check that _Generic don't match unsigned char * with char *
this case is usefull as with -funsigned-char, 'char *' are unsigned
* change VT_LONG so it's now a qualifier
VT_LONG are never use for code generation, but only durring parsing state,
in _Generic we need to be able to make diference between
'long' and 'long long'
So VT_LONG is now use as a type qualifier, it's old behaviour is still
here, but we can keep trace of what was a long and what wasn't
* add TOK_CLONG and TOK_CULONG
tcc was directly converting value like '7171L' into TOK_CLLONG or
TOK_CINT depending of the machine architecture.
because of that, we was unable to make diference between a long and a
long long, which doesn't work with _Generic.
So now 7171L is a TOK_CLONG, and we can handle _Generic properly
* check that _Generic can make diference between long and long long
* uncomment "type match twice" as it should now pass tests on any platforms
* add inside_generic global
the point of this variable is to use VT_LONG in comparaison only
when we are evaluating a _Generic.
problem is with my lastest patchs tcc can now make the diference between
a 'long long' and a 'long', but in 64 bit stddef.h typedef uint64_t as
typedef signed long long int int64_t and stdint.h as unsigned long int, so tcc
break when stdint.h and stddef.h are include together.
Another solution woud be to modifie include/stddef.h so it define uint64_t as
unsigned long int when processor is 64 bit, but this could break some
legacy code, so for now, VT_LONG are use only inside generc.
* check that _Generic parse first argument correctly
* check that _Generic evaluate correctly exresion like "f() / 2"
2017-07-10 18:44:53 +03:00
|
|
|
case TOK_CLONG:
|
|
|
|
case TOK_CULONG:
|
|
|
|
#endif
|
2010-01-14 22:58:03 +03:00
|
|
|
n = 2;
|
|
|
|
goto copy;
|
|
|
|
case TOK_CLDOUBLE:
|
2009-05-05 22:17:49 +04:00
|
|
|
#if LDOUBLE_SIZE == 16
|
2010-01-14 22:58:03 +03:00
|
|
|
n = 4;
|
2009-05-05 22:17:49 +04:00
|
|
|
#elif LDOUBLE_SIZE == 12
|
2010-01-14 22:58:03 +03:00
|
|
|
n = 3;
|
2009-05-05 22:17:49 +04:00
|
|
|
#elif LDOUBLE_SIZE == 8
|
2010-01-14 22:58:03 +03:00
|
|
|
n = 2;
|
2009-05-05 22:17:49 +04:00
|
|
|
#else
|
2010-01-14 22:58:03 +03:00
|
|
|
# error add long double size support
|
2009-05-05 22:17:49 +04:00
|
|
|
#endif
|
2010-01-14 22:58:03 +03:00
|
|
|
copy:
|
|
|
|
do
|
|
|
|
*tab++ = *p++;
|
|
|
|
while (--n);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*pp = p;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
2010-01-14 22:57:50 +03:00
|
|
|
static int macro_is_equal(const int *a, const int *b)
|
|
|
|
{
|
After several days searching why my code refactoring to remove globals was crashing,
I found the problem it was because CValue stack variables have rubish as it inital values
and assigning to a member that is smaller than the big union item and trying to
recover it later as a different member gives bak garbage.
ST_FUNC void vset(TCCState* tcc_state, CType *type, int r, int v)
{
CValue cval;
memset(&cval, 0, sizeof(CValue));
cval.i = v; //,<<<<<<<<<<< here is the main bug that mix with garbage
vsetc(tcc_state, type, r, &cval);
}
/* store a value or an expression directly in global data or in local array */
static void init_putv(TCCState* tcc_state, CType *type, Section *sec, unsigned long c,
int v, int expr_type)
{
...
case VT_PTR:
if (tcc_state->tccgen_vtop->r & VT_SYM) {
greloc(tcc_state, sec, tcc_state->tccgen_vtop->sym, c, R_DATA_PTR);
}
//<<< on the next line is where we try to get the assigned value to cvalue.i as cvalue.ull
*(addr_t *)ptr |= (tcc_state->tccgen_vtop->c.ull & bit_mask) << bit_pos;
break;
Also this patch makes vla tests pass on linux 32 bits
2014-03-27 00:14:39 +04:00
|
|
|
CValue cv;
|
2014-04-04 22:18:39 +04:00
|
|
|
int t;
|
2016-05-05 15:12:53 +03:00
|
|
|
|
|
|
|
if (!a || !b)
|
|
|
|
return 1;
|
|
|
|
|
2010-01-14 22:57:50 +03:00
|
|
|
while (*a && *b) {
|
2016-12-20 07:38:44 +03:00
|
|
|
/* first time preallocate macro_equal_buf, next time only reset position to start */
|
|
|
|
cstr_reset(¯o_equal_buf);
|
2010-01-14 22:58:03 +03:00
|
|
|
TOK_GET(&t, &a, &cv);
|
2016-12-20 07:38:44 +03:00
|
|
|
cstr_cat(¯o_equal_buf, get_tok_str(t, &cv), 0);
|
2010-01-14 22:58:03 +03:00
|
|
|
TOK_GET(&t, &b, &cv);
|
2016-12-20 07:38:44 +03:00
|
|
|
if (strcmp(macro_equal_buf.data, get_tok_str(t, &cv)))
|
2010-01-14 22:57:50 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return !(*a || *b);
|
|
|
|
}
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* defines handling */
|
2016-10-01 21:26:50 +03:00
|
|
|
ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
2016-05-05 15:12:53 +03:00
|
|
|
Sym *s, *o;
|
2010-01-14 22:57:50 +03:00
|
|
|
|
2016-05-05 15:12:53 +03:00
|
|
|
o = define_find(v);
|
2009-07-06 23:16:41 +04:00
|
|
|
s = sym_push2(&define_stack, v, macro_type, 0);
|
2016-10-01 21:26:50 +03:00
|
|
|
s->d = str;
|
2009-05-05 22:17:49 +04:00
|
|
|
s->next = first_arg;
|
|
|
|
table_ident[v - TOK_IDENT]->sym_define = s;
|
2016-05-05 15:12:53 +03:00
|
|
|
|
2016-05-25 19:51:36 +03:00
|
|
|
if (o && !macro_is_equal(o->d, s->d))
|
|
|
|
tcc_warning("%s redefined", get_tok_str(v, NULL));
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* undefined a define symbol. Its name is just set to zero */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void define_undef(Sym *s)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
2015-05-13 12:16:00 +03:00
|
|
|
int v = s->v;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (v >= TOK_IDENT && v < tok_ident)
|
2009-05-05 22:17:49 +04:00
|
|
|
table_ident[v - TOK_IDENT]->sym_define = NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_INLN Sym *define_find(int v)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
v -= TOK_IDENT;
|
|
|
|
if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
|
|
|
|
return NULL;
|
|
|
|
return table_ident[v]->sym_define;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free define stack until top reaches 'b' */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void free_defines(Sym *b)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
2016-10-01 20:58:13 +03:00
|
|
|
while (define_stack != b) {
|
|
|
|
Sym *top = define_stack;
|
|
|
|
define_stack = top->prev;
|
2016-11-11 22:25:13 +03:00
|
|
|
tok_str_free_str(top->d);
|
2016-10-01 20:58:13 +03:00
|
|
|
define_undef(top);
|
2009-05-05 22:17:49 +04:00
|
|
|
sym_free(top);
|
|
|
|
}
|
2016-10-01 20:58:13 +03:00
|
|
|
|
2017-02-13 20:23:55 +03:00
|
|
|
/* restore remaining (-D or predefined) symbols if they were
|
|
|
|
#undef'd in the file */
|
2016-10-01 20:58:13 +03:00
|
|
|
while (b) {
|
|
|
|
int v = b->v;
|
|
|
|
if (v >= TOK_IDENT && v < tok_ident) {
|
|
|
|
Sym **d = &table_ident[v - TOK_IDENT]->sym_define;
|
|
|
|
if (!*d)
|
|
|
|
*d = b;
|
|
|
|
}
|
|
|
|
b = b->prev;
|
|
|
|
}
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* label lookup */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC Sym *label_find(int v)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
v -= TOK_IDENT;
|
|
|
|
if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
|
|
|
|
return NULL;
|
|
|
|
return table_ident[v]->sym_label;
|
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC Sym *label_push(Sym **ptop, int v, int flags)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
Sym *s, **ps;
|
|
|
|
s = sym_push2(ptop, v, 0, 0);
|
|
|
|
s->r = flags;
|
|
|
|
ps = &table_ident[v - TOK_IDENT]->sym_label;
|
|
|
|
if (ptop == &global_label_stack) {
|
|
|
|
/* modify the top most local identifier, so that
|
|
|
|
sym_identifier will point to 's' when popped */
|
|
|
|
while (*ps != NULL)
|
|
|
|
ps = &(*ps)->prev_tok;
|
|
|
|
}
|
|
|
|
s->prev_tok = *ps;
|
|
|
|
*ps = s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pop labels until element last is reached. Look if any labels are
|
|
|
|
undefined. Define symbols if '&&label' was used. */
|
2017-07-10 23:25:11 +03:00
|
|
|
ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
Sym *s, *s1;
|
|
|
|
for(s = *ptop; s != slast; s = s1) {
|
|
|
|
s1 = s->prev;
|
|
|
|
if (s->r == LABEL_DECLARED) {
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_warning("label '%s' declared but not used", get_tok_str(s->v, NULL));
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if (s->r == LABEL_FORWARD) {
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("label '%s' used but not defined",
|
2009-05-05 22:17:49 +04:00
|
|
|
get_tok_str(s->v, NULL));
|
|
|
|
} else {
|
|
|
|
if (s->c) {
|
|
|
|
/* define corresponding symbol. A size of
|
|
|
|
1 is put. */
|
2009-07-19 00:05:58 +04:00
|
|
|
put_extern_sym(s, cur_text_section, s->jnext, 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* remove label */
|
|
|
|
table_ident[s->v - TOK_IDENT]->sym_label = s->prev_tok;
|
2017-07-10 23:25:11 +03:00
|
|
|
if (!keep)
|
|
|
|
sym_free(s);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2017-07-10 23:25:11 +03:00
|
|
|
if (!keep)
|
|
|
|
*ptop = slast;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:21:27 +03:00
|
|
|
/* fake the nth "#if defined test_..." for tcc -dt -run */
|
2017-07-23 22:24:11 +03:00
|
|
|
static void maybe_run_test(TCCState *s)
|
2017-07-20 23:21:27 +03:00
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
if (s->include_stack_ptr != s->include_stack)
|
|
|
|
return;
|
|
|
|
p = get_tok_str(tok, NULL);
|
|
|
|
if (0 != memcmp(p, "test_", 5))
|
|
|
|
return;
|
|
|
|
if (0 != --s->run_test)
|
|
|
|
return;
|
|
|
|
fprintf(s->ppfp, "\n[%s]\n" + !(s->dflag & 32), p), fflush(s->ppfp);
|
2017-07-23 22:24:11 +03:00
|
|
|
define_push(tok, MACRO_OBJ, NULL, NULL);
|
2017-07-20 23:21:27 +03:00
|
|
|
}
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* eval an expression for #if/#elif */
|
|
|
|
static int expr_preprocess(void)
|
|
|
|
{
|
|
|
|
int c, t;
|
2016-10-01 21:26:50 +03:00
|
|
|
TokenString *str;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2016-10-01 21:26:50 +03:00
|
|
|
str = tok_str_alloc();
|
2017-06-05 14:21:39 +03:00
|
|
|
pp_expr = 1;
|
2009-05-05 22:17:49 +04:00
|
|
|
while (tok != TOK_LINEFEED && tok != TOK_EOF) {
|
|
|
|
next(); /* do macro subst */
|
|
|
|
if (tok == TOK_DEFINED) {
|
|
|
|
next_nomacro();
|
|
|
|
t = tok;
|
2015-07-29 23:53:57 +03:00
|
|
|
if (t == '(')
|
2009-05-05 22:17:49 +04:00
|
|
|
next_nomacro();
|
2017-06-05 14:21:39 +03:00
|
|
|
if (tok < TOK_IDENT)
|
|
|
|
expect("identifier");
|
2017-07-20 23:21:27 +03:00
|
|
|
if (tcc_state->run_test)
|
2017-07-23 22:24:11 +03:00
|
|
|
maybe_run_test(tcc_state);
|
|
|
|
c = define_find(tok) != 0;
|
2017-06-05 14:21:39 +03:00
|
|
|
if (t == '(') {
|
2009-05-05 22:17:49 +04:00
|
|
|
next_nomacro();
|
2017-06-05 14:21:39 +03:00
|
|
|
if (tok != ')')
|
|
|
|
expect("')'");
|
|
|
|
}
|
2009-05-05 22:17:49 +04:00
|
|
|
tok = TOK_CINT;
|
|
|
|
tokc.i = c;
|
|
|
|
} else if (tok >= TOK_IDENT) {
|
|
|
|
/* if undefined macro */
|
|
|
|
tok = TOK_CINT;
|
|
|
|
tokc.i = 0;
|
|
|
|
}
|
2016-10-01 21:26:50 +03:00
|
|
|
tok_str_add_tok(str);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2017-06-05 14:21:39 +03:00
|
|
|
pp_expr = 0;
|
2016-10-01 21:26:50 +03:00
|
|
|
tok_str_add(str, -1); /* simulate end of file */
|
|
|
|
tok_str_add(str, 0);
|
2009-05-05 22:17:49 +04:00
|
|
|
/* now evaluate C constant expression */
|
2016-10-01 21:26:50 +03:00
|
|
|
begin_macro(str, 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
next();
|
|
|
|
c = expr_const();
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
end_macro();
|
2009-05-05 22:17:49 +04:00
|
|
|
return c != 0;
|
|
|
|
}
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* parse after #define */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void parse_define(void)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
Sym *s, *first, **ps;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
int v, t, varg, is_vaargs, spc;
|
|
|
|
int saved_parse_flags = parse_flags;
|
2014-04-08 18:19:48 +04:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
v = tok;
|
2017-06-05 14:21:39 +03:00
|
|
|
if (v < TOK_IDENT || v == TOK_DEFINED)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc));
|
2009-05-05 22:17:49 +04:00
|
|
|
/* XXX: should check if same macro (ANSI) */
|
|
|
|
first = NULL;
|
|
|
|
t = MACRO_OBJ;
|
2016-08-25 17:40:50 +03:00
|
|
|
/* We have to parse the whole define as if not in asm mode, in particular
|
|
|
|
no line comment with '#' must be ignored. Also for function
|
|
|
|
macros the argument list must be parsed without '.' being an ID
|
|
|
|
character. */
|
|
|
|
parse_flags = ((parse_flags & ~PARSE_FLAG_ASM_FILE) | PARSE_FLAG_SPACES);
|
2009-05-05 22:17:49 +04:00
|
|
|
/* '(' must be just after macro definition for MACRO_FUNC */
|
|
|
|
next_nomacro_spc();
|
|
|
|
if (tok == '(') {
|
2017-07-20 23:21:27 +03:00
|
|
|
int dotid = set_idnum('.', 0);
|
2009-05-05 22:17:49 +04:00
|
|
|
next_nomacro();
|
|
|
|
ps = &first;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (tok != ')') for (;;) {
|
2009-05-05 22:17:49 +04:00
|
|
|
varg = tok;
|
|
|
|
next_nomacro();
|
|
|
|
is_vaargs = 0;
|
|
|
|
if (varg == TOK_DOTS) {
|
|
|
|
varg = TOK___VA_ARGS__;
|
|
|
|
is_vaargs = 1;
|
|
|
|
} else if (tok == TOK_DOTS && gnu_ext) {
|
|
|
|
is_vaargs = 1;
|
|
|
|
next_nomacro();
|
|
|
|
}
|
|
|
|
if (varg < TOK_IDENT)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
bad_list:
|
|
|
|
tcc_error("bad macro parameter list");
|
2009-05-05 22:17:49 +04:00
|
|
|
s = sym_push2(&define_stack, varg | SYM_FIELD, is_vaargs, 0);
|
|
|
|
*ps = s;
|
|
|
|
ps = &s->next;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (tok == ')')
|
|
|
|
break;
|
|
|
|
if (tok != ',' || is_vaargs)
|
|
|
|
goto bad_list;
|
2009-05-05 22:17:49 +04:00
|
|
|
next_nomacro();
|
|
|
|
}
|
2014-06-29 16:35:57 +04:00
|
|
|
next_nomacro_spc();
|
2009-05-05 22:17:49 +04:00
|
|
|
t = MACRO_FUNC;
|
2017-07-20 23:21:27 +03:00
|
|
|
set_idnum('.', dotid);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2016-04-17 16:37:23 +03:00
|
|
|
|
|
|
|
tokstr_buf.len = 0;
|
2009-05-05 22:17:49 +04:00
|
|
|
spc = 2;
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
parse_flags |= PARSE_FLAG_ACCEPT_STRAYS | PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED;
|
2016-08-25 17:40:50 +03:00
|
|
|
/* The body of a macro definition should be parsed such that identifiers
|
|
|
|
are parsed like the file mode determines (i.e. with '.' being an
|
|
|
|
ID character in asm mode). But '#' should be retained instead of
|
|
|
|
regarded as line comment leader, so still don't set ASM_FILE
|
|
|
|
in parse_flags. */
|
2009-05-05 22:17:49 +04:00
|
|
|
while (tok != TOK_LINEFEED && tok != TOK_EOF) {
|
2014-04-08 18:19:48 +04:00
|
|
|
/* remove spaces around ## and after '#' */
|
2009-05-05 22:17:49 +04:00
|
|
|
if (TOK_TWOSHARPS == tok) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (2 == spc)
|
|
|
|
goto bad_twosharp;
|
2009-05-05 22:17:49 +04:00
|
|
|
if (1 == spc)
|
2016-04-17 16:37:23 +03:00
|
|
|
--tokstr_buf.len;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
spc = 3;
|
2016-10-31 05:59:31 +03:00
|
|
|
tok = TOK_PPJOIN;
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if ('#' == tok) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
spc = 4;
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if (check_space(tok, &spc)) {
|
|
|
|
goto skip;
|
|
|
|
}
|
2016-04-17 16:37:23 +03:00
|
|
|
tok_str_add2(&tokstr_buf, tok, &tokc);
|
2009-05-05 22:17:49 +04:00
|
|
|
skip:
|
|
|
|
next_nomacro_spc();
|
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
parse_flags = saved_parse_flags;
|
2009-05-05 22:17:49 +04:00
|
|
|
if (spc == 1)
|
2016-04-17 16:37:23 +03:00
|
|
|
--tokstr_buf.len; /* remove trailing space */
|
|
|
|
tok_str_add(&tokstr_buf, 0);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (3 == spc)
|
|
|
|
bad_twosharp:
|
|
|
|
tcc_error("'##' cannot appear at either end of macro");
|
2016-10-01 21:26:50 +03:00
|
|
|
define_push(v, t, tok_str_dup(&tokstr_buf), first);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
2016-10-01 21:03:48 +03:00
|
|
|
static CachedInclude *search_cached_include(TCCState *s1, const char *filename, int add)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
const unsigned char *s;
|
|
|
|
unsigned int h;
|
2016-10-01 21:03:48 +03:00
|
|
|
CachedInclude *e;
|
|
|
|
int i;
|
2009-05-05 22:17:49 +04:00
|
|
|
|
|
|
|
h = TOK_HASH_INIT;
|
2014-03-09 18:52:31 +04:00
|
|
|
s = (unsigned char *) filename;
|
2009-05-05 22:17:49 +04:00
|
|
|
while (*s) {
|
2016-10-01 21:03:48 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
h = TOK_HASH_FUNC(h, toup(*s));
|
|
|
|
#else
|
2009-05-05 22:17:49 +04:00
|
|
|
h = TOK_HASH_FUNC(h, *s);
|
2016-10-01 21:03:48 +03:00
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
h &= (CACHED_INCLUDES_HASH_SIZE - 1);
|
|
|
|
|
|
|
|
i = s1->cached_includes_hash[h];
|
|
|
|
for(;;) {
|
|
|
|
if (i == 0)
|
|
|
|
break;
|
|
|
|
e = s1->cached_includes[i - 1];
|
2013-01-06 20:20:44 +04:00
|
|
|
if (0 == PATHCMP(e->filename, filename))
|
2009-05-05 22:17:49 +04:00
|
|
|
return e;
|
|
|
|
i = e->hash_next;
|
|
|
|
}
|
2016-10-01 21:03:48 +03:00
|
|
|
if (!add)
|
|
|
|
return NULL;
|
2009-05-05 22:17:49 +04:00
|
|
|
|
|
|
|
e = tcc_malloc(sizeof(CachedInclude) + strlen(filename));
|
|
|
|
strcpy(e->filename, filename);
|
2016-10-01 21:03:48 +03:00
|
|
|
e->ifndef_macro = e->once = 0;
|
2017-02-13 20:23:43 +03:00
|
|
|
dynarray_add(&s1->cached_includes, &s1->nb_cached_includes, e);
|
2009-05-05 22:17:49 +04:00
|
|
|
/* add in hash table */
|
|
|
|
e->hash_next = s1->cached_includes_hash[h];
|
|
|
|
s1->cached_includes_hash[h] = s1->nb_cached_includes;
|
2016-10-01 21:03:48 +03:00
|
|
|
#ifdef INC_DEBUG
|
|
|
|
printf("adding cached '%s'\n", filename);
|
|
|
|
#endif
|
|
|
|
return e;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pragma_parse(TCCState *s1)
|
|
|
|
{
|
2015-04-24 00:27:36 +03:00
|
|
|
next_nomacro();
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (tok == TOK_push_macro || tok == TOK_pop_macro) {
|
|
|
|
int t = tok, v;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
if (next(), tok != '(')
|
|
|
|
goto pragma_err;
|
|
|
|
if (next(), tok != TOK_STR)
|
|
|
|
goto pragma_err;
|
2015-11-21 14:23:53 +03:00
|
|
|
v = tok_alloc(tokc.str.data, tokc.str.size - 1)->tok;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (next(), tok != ')')
|
|
|
|
goto pragma_err;
|
|
|
|
if (t == TOK_push_macro) {
|
|
|
|
while (NULL == (s = define_find(v)))
|
|
|
|
define_push(v, 0, NULL, NULL);
|
|
|
|
s->type.ref = s; /* set push boundary */
|
|
|
|
} else {
|
|
|
|
for (s = define_stack; s; s = s->prev)
|
|
|
|
if (s->v == v && s->type.ref == s) {
|
|
|
|
s->type.ref = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s)
|
|
|
|
table_ident[v - TOK_IDENT]->sym_define = s->d ? s : NULL;
|
|
|
|
else
|
|
|
|
tcc_warning("unbalanced #pragma pop_macro");
|
2016-05-05 15:12:53 +03:00
|
|
|
pp_debug_tok = t, pp_debug_symv = v;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
|
|
|
} else if (tok == TOK_once) {
|
2016-10-01 21:03:48 +03:00
|
|
|
search_cached_include(s1, file->filename, 1)->once = pp_once;
|
|
|
|
|
2017-07-20 23:21:27 +03:00
|
|
|
} else if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* tcc -E: keep pragmas below unchanged */
|
|
|
|
unget_tok(' ');
|
|
|
|
unget_tok(TOK_PRAGMA);
|
|
|
|
unget_tok('#');
|
|
|
|
unget_tok(TOK_LINEFEED);
|
|
|
|
|
|
|
|
} else if (tok == TOK_pack) {
|
|
|
|
/* This may be:
|
|
|
|
#pragma pack(1) // set
|
|
|
|
#pragma pack() // reset to default
|
|
|
|
#pragma pack(push,1) // push & set
|
|
|
|
#pragma pack(pop) // restore previous */
|
2009-05-05 22:17:49 +04:00
|
|
|
next();
|
|
|
|
skip('(');
|
|
|
|
if (tok == TOK_ASM_pop) {
|
|
|
|
next();
|
|
|
|
if (s1->pack_stack_ptr <= s1->pack_stack) {
|
|
|
|
stk_error:
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("out of pack stack");
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
s1->pack_stack_ptr--;
|
|
|
|
} else {
|
2015-04-24 00:27:36 +03:00
|
|
|
int val = 0;
|
2009-05-05 22:17:49 +04:00
|
|
|
if (tok != ')') {
|
|
|
|
if (tok == TOK_ASM_push) {
|
|
|
|
next();
|
|
|
|
if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE - 1)
|
|
|
|
goto stk_error;
|
|
|
|
s1->pack_stack_ptr++;
|
|
|
|
skip(',');
|
|
|
|
}
|
2015-04-24 00:27:36 +03:00
|
|
|
if (tok != TOK_CINT)
|
|
|
|
goto pragma_err;
|
2009-05-05 22:17:49 +04:00
|
|
|
val = tokc.i;
|
|
|
|
if (val < 1 || val > 16 || (val & (val - 1)) != 0)
|
2015-04-24 00:27:36 +03:00
|
|
|
goto pragma_err;
|
2009-05-05 22:17:49 +04:00
|
|
|
next();
|
|
|
|
}
|
|
|
|
*s1->pack_stack_ptr = val;
|
|
|
|
}
|
2015-04-24 00:27:36 +03:00
|
|
|
if (tok != ')')
|
|
|
|
goto pragma_err;
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} else if (tok == TOK_comment) {
|
2017-07-14 20:26:01 +03:00
|
|
|
char *p; int t;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
next();
|
|
|
|
skip('(');
|
2017-07-14 20:26:01 +03:00
|
|
|
t = tok;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
next();
|
|
|
|
skip(',');
|
|
|
|
if (tok != TOK_STR)
|
2015-04-24 00:27:36 +03:00
|
|
|
goto pragma_err;
|
2017-07-14 20:26:01 +03:00
|
|
|
p = tcc_strdup((char *)tokc.str.data);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
next();
|
|
|
|
if (tok != ')')
|
2015-04-24 00:27:36 +03:00
|
|
|
goto pragma_err;
|
2017-07-14 20:26:01 +03:00
|
|
|
if (t == TOK_lib) {
|
|
|
|
dynarray_add(&s1->pragma_libs, &s1->nb_pragma_libs, p);
|
|
|
|
} else {
|
|
|
|
if (t == TOK_option)
|
|
|
|
tcc_set_options(s1, p);
|
|
|
|
tcc_free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (s1->warn_unsupported) {
|
|
|
|
tcc_warning("#pragma %s is ignored", get_tok_str(tok, &tokc));
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2015-04-24 00:27:36 +03:00
|
|
|
return;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2015-04-24 00:27:36 +03:00
|
|
|
pragma_err:
|
|
|
|
tcc_error("malformed #pragma directive");
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
return;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* is_bof is true if first non space token at beginning of file */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void preprocess(int is_bof)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
TCCState *s1 = tcc_state;
|
2009-05-11 20:55:16 +04:00
|
|
|
int i, c, n, saved_parse_flags;
|
2009-05-05 22:17:49 +04:00
|
|
|
char buf[1024], *q;
|
|
|
|
Sym *s;
|
2009-05-11 20:55:16 +04:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
saved_parse_flags = parse_flags;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
parse_flags = PARSE_FLAG_PREPROCESS
|
|
|
|
| PARSE_FLAG_TOK_NUM
|
|
|
|
| PARSE_FLAG_TOK_STR
|
|
|
|
| PARSE_FLAG_LINEFEED
|
|
|
|
| (parse_flags & PARSE_FLAG_ASM_FILE)
|
|
|
|
;
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
next_nomacro();
|
|
|
|
redo:
|
|
|
|
switch(tok) {
|
|
|
|
case TOK_DEFINE:
|
2016-05-05 15:12:53 +03:00
|
|
|
pp_debug_tok = tok;
|
2009-05-05 22:17:49 +04:00
|
|
|
next_nomacro();
|
2016-05-05 15:12:53 +03:00
|
|
|
pp_debug_symv = tok;
|
2009-05-05 22:17:49 +04:00
|
|
|
parse_define();
|
|
|
|
break;
|
|
|
|
case TOK_UNDEF:
|
2016-05-05 15:12:53 +03:00
|
|
|
pp_debug_tok = tok;
|
2009-05-05 22:17:49 +04:00
|
|
|
next_nomacro();
|
2016-05-05 15:12:53 +03:00
|
|
|
pp_debug_symv = tok;
|
2009-05-05 22:17:49 +04:00
|
|
|
s = define_find(tok);
|
|
|
|
/* undefine symbol by putting an invalid name */
|
|
|
|
if (s)
|
|
|
|
define_undef(s);
|
|
|
|
break;
|
|
|
|
case TOK_INCLUDE:
|
|
|
|
case TOK_INCLUDE_NEXT:
|
|
|
|
ch = file->buf_ptr[0];
|
2015-11-20 14:05:55 +03:00
|
|
|
/* XXX: incorrect if comments : use next_nomacro with a special mode */
|
|
|
|
skip_spaces();
|
|
|
|
if (ch == '<') {
|
2009-05-05 22:17:49 +04:00
|
|
|
c = '>';
|
2015-11-20 14:05:55 +03:00
|
|
|
goto read_name;
|
|
|
|
} else if (ch == '\"') {
|
2009-05-05 22:17:49 +04:00
|
|
|
c = ch;
|
2015-11-20 14:05:55 +03:00
|
|
|
read_name:
|
2009-05-05 22:17:49 +04:00
|
|
|
inp();
|
|
|
|
q = buf;
|
|
|
|
while (ch != c && ch != '\n' && ch != CH_EOF) {
|
|
|
|
if ((q - buf) < sizeof(buf) - 1)
|
|
|
|
*q++ = ch;
|
|
|
|
if (ch == '\\') {
|
|
|
|
if (handle_stray_noerror() == 0)
|
|
|
|
--q;
|
|
|
|
} else
|
|
|
|
inp();
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
minp();
|
2015-11-20 14:05:55 +03:00
|
|
|
#if 0
|
|
|
|
/* eat all spaces and comments after include */
|
|
|
|
/* XXX: slightly incorrect */
|
|
|
|
while (ch1 != '\n' && ch1 != CH_EOF)
|
|
|
|
inp();
|
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
2016-08-08 23:26:11 +03:00
|
|
|
int len;
|
|
|
|
/* computed #include : concatenate everything up to linefeed,
|
|
|
|
the result must be one of the two accepted forms.
|
|
|
|
Don't convert pp-tokens to tokens here. */
|
|
|
|
parse_flags = (PARSE_FLAG_PREPROCESS
|
|
|
|
| PARSE_FLAG_LINEFEED
|
|
|
|
| (parse_flags & PARSE_FLAG_ASM_FILE));
|
2009-05-05 22:17:49 +04:00
|
|
|
next();
|
|
|
|
buf[0] = '\0';
|
2016-08-08 23:26:11 +03:00
|
|
|
while (tok != TOK_LINEFEED) {
|
|
|
|
pstrcat(buf, sizeof(buf), get_tok_str(tok, &tokc));
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
len = strlen(buf);
|
|
|
|
/* check syntax and remove '<>|""' */
|
|
|
|
if ((len < 2 || ((buf[0] != '"' || buf[len-1] != '"') &&
|
|
|
|
(buf[0] != '<' || buf[len-1] != '>'))))
|
|
|
|
tcc_error("'#include' expects \"FILENAME\" or <FILENAME>");
|
|
|
|
c = buf[len-1];
|
|
|
|
memmove(buf, buf + 1, len - 2);
|
|
|
|
buf[len - 2] = '\0';
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
2009-05-11 20:55:16 +04:00
|
|
|
if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("#include recursion too deep");
|
2015-11-20 14:05:55 +03:00
|
|
|
/* store current file in stack, but increment stack later below */
|
|
|
|
*s1->include_stack_ptr = file;
|
|
|
|
i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0;
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
|
2015-11-05 19:52:49 +03:00
|
|
|
for (; i < n; ++i) {
|
2009-05-11 20:55:16 +04:00
|
|
|
char buf1[sizeof file->filename];
|
|
|
|
CachedInclude *e;
|
|
|
|
const char *path;
|
|
|
|
|
2015-11-20 14:05:55 +03:00
|
|
|
if (i == 0) {
|
2009-05-11 20:55:16 +04:00
|
|
|
/* check absolute include path */
|
|
|
|
if (!IS_ABSPATH(buf))
|
|
|
|
continue;
|
|
|
|
buf1[0] = 0;
|
|
|
|
|
2015-11-20 14:05:55 +03:00
|
|
|
} else if (i == 1) {
|
2016-10-04 18:31:40 +03:00
|
|
|
/* search in file's dir if "header.h" */
|
2009-05-11 20:55:16 +04:00
|
|
|
if (c != '\"')
|
|
|
|
continue;
|
2017-04-25 22:32:41 +03:00
|
|
|
/* https://savannah.nongnu.org/bugs/index.php?50847 */
|
2017-07-09 13:07:40 +03:00
|
|
|
path = file->true_filename;
|
2013-01-14 20:34:07 +04:00
|
|
|
pstrncpy(buf1, path, tcc_basename(path) - path);
|
2009-05-11 20:55:16 +04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* search in all the include paths */
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
int j = i - 2, k = j - s1->nb_include_paths;
|
|
|
|
path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k];
|
2009-05-05 22:17:49 +04:00
|
|
|
pstrcpy(buf1, sizeof(buf1), path);
|
|
|
|
pstrcat(buf1, sizeof(buf1), "/");
|
2009-05-11 20:55:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pstrcat(buf1, sizeof(buf1), buf);
|
2016-10-01 21:03:48 +03:00
|
|
|
e = search_cached_include(s1, buf1, 0);
|
|
|
|
if (e && (define_find(e->ifndef_macro) || e->once == pp_once)) {
|
2015-11-20 14:05:55 +03:00
|
|
|
/* no need to parse the include because the 'ifndef macro'
|
2016-10-01 21:03:48 +03:00
|
|
|
is defined (or had #pragma once) */
|
2015-11-20 14:05:55 +03:00
|
|
|
#ifdef INC_DEBUG
|
|
|
|
printf("%s: skipping cached %s\n", file->filename, buf1);
|
|
|
|
#endif
|
|
|
|
goto include_done;
|
|
|
|
}
|
2009-05-11 20:55:16 +04:00
|
|
|
|
2015-11-05 19:52:49 +03:00
|
|
|
if (tcc_open(s1, buf1) < 0)
|
2009-05-11 20:55:16 +04:00
|
|
|
continue;
|
2015-10-20 07:32:53 +03:00
|
|
|
|
2015-11-20 14:05:55 +03:00
|
|
|
file->include_next_index = i + 1;
|
|
|
|
#ifdef INC_DEBUG
|
|
|
|
printf("%s: including %s\n", file->prev->filename, file->filename);
|
|
|
|
#endif
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-20 20:08:12 +04:00
|
|
|
/* update target deps */
|
2017-02-13 20:23:43 +03:00
|
|
|
dynarray_add(&s1->target_deps, &s1->nb_target_deps,
|
2015-11-20 14:05:55 +03:00
|
|
|
tcc_strdup(buf1));
|
|
|
|
/* push current file in stack */
|
|
|
|
++s1->include_stack_ptr;
|
2009-05-05 22:17:49 +04:00
|
|
|
/* add include file debug info */
|
2010-11-25 15:29:15 +03:00
|
|
|
if (s1->do_debug)
|
2009-05-05 22:17:49 +04:00
|
|
|
put_stabs(file->filename, N_BINCL, 0, 0, 0);
|
|
|
|
tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL;
|
|
|
|
ch = file->buf_ptr[0];
|
2015-11-20 14:05:55 +03:00
|
|
|
goto the_end;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2015-11-20 14:05:55 +03:00
|
|
|
tcc_error("include file '%s' not found", buf);
|
|
|
|
include_done:
|
|
|
|
break;
|
2009-05-05 22:17:49 +04:00
|
|
|
case TOK_IFNDEF:
|
|
|
|
c = 1;
|
|
|
|
goto do_ifdef;
|
|
|
|
case TOK_IF:
|
|
|
|
c = expr_preprocess();
|
|
|
|
goto do_if;
|
|
|
|
case TOK_IFDEF:
|
|
|
|
c = 0;
|
|
|
|
do_ifdef:
|
|
|
|
next_nomacro();
|
|
|
|
if (tok < TOK_IDENT)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("invalid argument for '#if%sdef'", c ? "n" : "");
|
2009-05-05 22:17:49 +04:00
|
|
|
if (is_bof) {
|
|
|
|
if (c) {
|
2015-11-20 14:05:55 +03:00
|
|
|
#ifdef INC_DEBUG
|
|
|
|
printf("#ifndef %s\n", get_tok_str(tok, NULL));
|
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
file->ifndef_macro = tok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c = (define_find(tok) != 0) ^ c;
|
|
|
|
do_if:
|
|
|
|
if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE)
|
2014-01-06 22:56:26 +04:00
|
|
|
tcc_error("memory full (ifdef)");
|
2009-05-05 22:17:49 +04:00
|
|
|
*s1->ifdef_stack_ptr++ = c;
|
|
|
|
goto test_skip;
|
|
|
|
case TOK_ELSE:
|
|
|
|
if (s1->ifdef_stack_ptr == s1->ifdef_stack)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("#else without matching #if");
|
2009-05-05 22:17:49 +04:00
|
|
|
if (s1->ifdef_stack_ptr[-1] & 2)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("#else after #else");
|
2009-05-05 22:17:49 +04:00
|
|
|
c = (s1->ifdef_stack_ptr[-1] ^= 3);
|
2009-07-23 21:21:14 +04:00
|
|
|
goto test_else;
|
2009-05-05 22:17:49 +04:00
|
|
|
case TOK_ELIF:
|
|
|
|
if (s1->ifdef_stack_ptr == s1->ifdef_stack)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("#elif without matching #if");
|
2009-05-05 22:17:49 +04:00
|
|
|
c = s1->ifdef_stack_ptr[-1];
|
|
|
|
if (c > 1)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("#elif after #else");
|
2009-05-05 22:17:49 +04:00
|
|
|
/* last #if/#elif expression was true: we skip */
|
2016-10-04 18:31:40 +03:00
|
|
|
if (c == 1) {
|
|
|
|
c = 0;
|
|
|
|
} else {
|
|
|
|
c = expr_preprocess();
|
|
|
|
s1->ifdef_stack_ptr[-1] = c;
|
|
|
|
}
|
2009-07-23 21:21:14 +04:00
|
|
|
test_else:
|
|
|
|
if (s1->ifdef_stack_ptr == file->ifdef_stack_ptr + 1)
|
|
|
|
file->ifndef_macro = 0;
|
2009-05-05 22:17:49 +04:00
|
|
|
test_skip:
|
|
|
|
if (!(c & 1)) {
|
|
|
|
preprocess_skip();
|
|
|
|
is_bof = 0;
|
|
|
|
goto redo;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TOK_ENDIF:
|
|
|
|
if (s1->ifdef_stack_ptr <= file->ifdef_stack_ptr)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("#endif without matching #if");
|
2009-05-05 22:17:49 +04:00
|
|
|
s1->ifdef_stack_ptr--;
|
|
|
|
/* '#ifndef macro' was at the start of file. Now we check if
|
|
|
|
an '#endif' is exactly at the end of file */
|
|
|
|
if (file->ifndef_macro &&
|
|
|
|
s1->ifdef_stack_ptr == file->ifdef_stack_ptr) {
|
|
|
|
file->ifndef_macro_saved = file->ifndef_macro;
|
|
|
|
/* need to set to zero to avoid false matches if another
|
|
|
|
#ifndef at middle of file */
|
|
|
|
file->ifndef_macro = 0;
|
|
|
|
while (tok != TOK_LINEFEED)
|
|
|
|
next_nomacro();
|
|
|
|
tok_flags |= TOK_FLAG_ENDIF;
|
|
|
|
goto the_end;
|
|
|
|
}
|
|
|
|
break;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
case TOK_PPNUM:
|
2015-11-21 14:23:53 +03:00
|
|
|
n = strtoul((char*)tokc.str.data, &q, 10);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
goto _line_num;
|
2009-05-05 22:17:49 +04:00
|
|
|
case TOK_LINE:
|
|
|
|
next();
|
|
|
|
if (tok != TOK_CINT)
|
2016-10-04 18:31:40 +03:00
|
|
|
_line_err:
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tcc_error("wrong #line format");
|
|
|
|
n = tokc.i;
|
2016-10-04 18:31:40 +03:00
|
|
|
_line_num:
|
2009-05-05 22:17:49 +04:00
|
|
|
next();
|
|
|
|
if (tok != TOK_LINEFEED) {
|
2017-07-09 13:07:40 +03:00
|
|
|
if (tok == TOK_STR) {
|
|
|
|
if (file->true_filename == file->filename)
|
|
|
|
file->true_filename = tcc_strdup(file->filename);
|
2015-11-21 14:23:53 +03:00
|
|
|
pstrcpy(file->filename, sizeof(file->filename), (char *)tokc.str.data);
|
2017-07-09 13:07:40 +03:00
|
|
|
} else if (parse_flags & PARSE_FLAG_ASM_FILE)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
goto _line_err;
|
|
|
|
--n;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (file->fd > 0)
|
|
|
|
total_lines += file->line_num - n;
|
|
|
|
file->line_num = n;
|
2015-03-03 14:46:44 +03:00
|
|
|
if (s1->do_debug)
|
2015-07-29 23:53:57 +03:00
|
|
|
put_stabs(file->filename, N_BINCL, 0, 0, 0);
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
|
|
|
case TOK_ERROR:
|
|
|
|
case TOK_WARNING:
|
|
|
|
c = tok;
|
|
|
|
ch = file->buf_ptr[0];
|
|
|
|
skip_spaces();
|
|
|
|
q = buf;
|
|
|
|
while (ch != '\n' && ch != CH_EOF) {
|
|
|
|
if ((q - buf) < sizeof(buf) - 1)
|
|
|
|
*q++ = ch;
|
|
|
|
if (ch == '\\') {
|
|
|
|
if (handle_stray_noerror() == 0)
|
|
|
|
--q;
|
|
|
|
} else
|
|
|
|
inp();
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
if (c == TOK_ERROR)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("#error %s", buf);
|
2009-05-05 22:17:49 +04:00
|
|
|
else
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_warning("#warning %s", buf);
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
|
|
|
case TOK_PRAGMA:
|
|
|
|
pragma_parse(s1);
|
|
|
|
break;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
case TOK_LINEFEED:
|
|
|
|
goto the_end;
|
2009-05-05 22:17:49 +04:00
|
|
|
default:
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* ignore gas line comment in an 'S' file. */
|
|
|
|
if (saved_parse_flags & PARSE_FLAG_ASM_FILE)
|
|
|
|
goto ignore;
|
|
|
|
if (tok == '!' && is_bof)
|
|
|
|
/* '!' is ignored at beginning to allow C scripts. */
|
|
|
|
goto ignore;
|
|
|
|
tcc_warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc));
|
|
|
|
ignore:
|
2016-10-01 23:01:25 +03:00
|
|
|
file->buf_ptr = parse_line_comment(file->buf_ptr - 1);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
goto the_end;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
/* ignore other preprocess commands or #! for C scripts */
|
|
|
|
while (tok != TOK_LINEFEED)
|
|
|
|
next_nomacro();
|
|
|
|
the_end:
|
|
|
|
parse_flags = saved_parse_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* evaluate escape codes in a string. */
|
|
|
|
static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long)
|
|
|
|
{
|
|
|
|
int c, n;
|
|
|
|
const uint8_t *p;
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
for(;;) {
|
|
|
|
c = *p;
|
|
|
|
if (c == '\0')
|
|
|
|
break;
|
|
|
|
if (c == '\\') {
|
|
|
|
p++;
|
|
|
|
/* escape */
|
|
|
|
c = *p;
|
|
|
|
switch(c) {
|
|
|
|
case '0': case '1': case '2': case '3':
|
|
|
|
case '4': case '5': case '6': case '7':
|
|
|
|
/* at most three octal digits */
|
|
|
|
n = c - '0';
|
|
|
|
p++;
|
|
|
|
c = *p;
|
|
|
|
if (isoct(c)) {
|
|
|
|
n = n * 8 + c - '0';
|
|
|
|
p++;
|
|
|
|
c = *p;
|
|
|
|
if (isoct(c)) {
|
|
|
|
n = n * 8 + c - '0';
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c = n;
|
|
|
|
goto add_char_nonext;
|
|
|
|
case 'x':
|
|
|
|
case 'u':
|
|
|
|
case 'U':
|
|
|
|
p++;
|
|
|
|
n = 0;
|
|
|
|
for(;;) {
|
|
|
|
c = *p;
|
|
|
|
if (c >= 'a' && c <= 'f')
|
|
|
|
c = c - 'a' + 10;
|
|
|
|
else if (c >= 'A' && c <= 'F')
|
|
|
|
c = c - 'A' + 10;
|
|
|
|
else if (isnum(c))
|
|
|
|
c = c - '0';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
n = n * 16 + c;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
c = n;
|
|
|
|
goto add_char_nonext;
|
|
|
|
case 'a':
|
|
|
|
c = '\a';
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
c = '\b';
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
c = '\f';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
c = '\n';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
c = '\r';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
c = '\t';
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
c = '\v';
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
if (!gnu_ext)
|
|
|
|
goto invalid_escape;
|
|
|
|
c = 27;
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
case '\"':
|
2015-07-29 23:53:57 +03:00
|
|
|
case '\\':
|
2009-05-05 22:17:49 +04:00
|
|
|
case '?':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
invalid_escape:
|
|
|
|
if (c >= '!' && c <= '~')
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_warning("unknown escape sequence: \'\\%c\'", c);
|
2009-05-05 22:17:49 +04:00
|
|
|
else
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_warning("unknown escape sequence: \'\\x%x\'", c);
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
|
|
|
}
|
2017-09-09 15:37:43 +03:00
|
|
|
} else if (is_long && c >= 0x80) {
|
|
|
|
/* assume we are processing UTF-8 sequence */
|
|
|
|
/* reference: The Unicode Standard, Version 10.0, ch3.9 */
|
|
|
|
|
|
|
|
int cont; /* count of continuation bytes */
|
2017-09-25 04:03:26 +03:00
|
|
|
int skip; /* how many bytes should skip when error occurred */
|
2017-09-09 15:37:43 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* decode leading byte */
|
|
|
|
if (c < 0xC2) {
|
|
|
|
skip = 1; goto invalid_utf8_sequence;
|
|
|
|
} else if (c <= 0xDF) {
|
|
|
|
cont = 1; n = c & 0x1f;
|
|
|
|
} else if (c <= 0xEF) {
|
|
|
|
cont = 2; n = c & 0xf;
|
|
|
|
} else if (c <= 0xF4) {
|
|
|
|
cont = 3; n = c & 0x7;
|
|
|
|
} else {
|
|
|
|
skip = 1; goto invalid_utf8_sequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* decode continuation bytes */
|
|
|
|
for (i = 1; i <= cont; i++) {
|
|
|
|
int l = 0x80, h = 0xBF;
|
|
|
|
|
|
|
|
/* adjust limit for second byte */
|
|
|
|
if (i == 1) {
|
|
|
|
switch (c) {
|
|
|
|
case 0xE0: l = 0xA0; break;
|
|
|
|
case 0xED: h = 0x9F; break;
|
|
|
|
case 0xF0: l = 0x90; break;
|
|
|
|
case 0xF4: h = 0x8F; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p[i] < l || p[i] > h) {
|
|
|
|
skip = i; goto invalid_utf8_sequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = (n << 6) | (p[i] & 0x3f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* advance pointer */
|
|
|
|
p += 1 + cont;
|
|
|
|
c = n;
|
|
|
|
goto add_char_nonext;
|
|
|
|
|
|
|
|
/* error handling */
|
|
|
|
invalid_utf8_sequence:
|
|
|
|
tcc_warning("ill-formed UTF-8 subsequence starting with: \'\\x%x\'", c);
|
|
|
|
c = 0xFFFD;
|
|
|
|
p += skip;
|
|
|
|
goto add_char_nonext;
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
p++;
|
|
|
|
add_char_nonext:
|
|
|
|
if (!is_long)
|
|
|
|
cstr_ccat(outstr, c);
|
2017-09-09 15:37:43 +03:00
|
|
|
else {
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
/* store as UTF-16 */
|
|
|
|
if (c < 0x10000) {
|
|
|
|
cstr_wccat(outstr, c);
|
|
|
|
} else {
|
|
|
|
c -= 0x10000;
|
|
|
|
cstr_wccat(outstr, (c >> 10) + 0xD800);
|
|
|
|
cstr_wccat(outstr, (c & 0x3FF) + 0xDC00);
|
|
|
|
}
|
|
|
|
#else
|
2009-05-05 22:17:49 +04:00
|
|
|
cstr_wccat(outstr, c);
|
2017-09-09 15:37:43 +03:00
|
|
|
#endif
|
|
|
|
}
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
/* add a trailing '\0' */
|
|
|
|
if (!is_long)
|
|
|
|
cstr_ccat(outstr, '\0');
|
|
|
|
else
|
|
|
|
cstr_wccat(outstr, '\0');
|
|
|
|
}
|
|
|
|
|
2016-09-26 05:32:41 +03:00
|
|
|
static void parse_string(const char *s, int len)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
{
|
|
|
|
uint8_t buf[1000], *p = buf;
|
|
|
|
int is_long, sep;
|
|
|
|
|
|
|
|
if ((is_long = *s == 'L'))
|
|
|
|
++s, --len;
|
|
|
|
sep = *s++;
|
|
|
|
len -= 2;
|
|
|
|
if (len >= sizeof buf)
|
|
|
|
p = tcc_malloc(len + 1);
|
|
|
|
memcpy(p, s, len);
|
|
|
|
p[len] = 0;
|
|
|
|
|
|
|
|
cstr_reset(&tokcstr);
|
|
|
|
parse_escape_string(&tokcstr, p, is_long);
|
|
|
|
if (p != buf)
|
|
|
|
tcc_free(p);
|
|
|
|
|
|
|
|
if (sep == '\'') {
|
2017-09-24 19:57:48 +03:00
|
|
|
int char_size, i, n, c;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* XXX: make it portable */
|
|
|
|
if (!is_long)
|
2017-09-24 19:57:48 +03:00
|
|
|
tok = TOK_CCHAR, char_size = 1;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
else
|
2017-09-24 19:57:48 +03:00
|
|
|
tok = TOK_LCHAR, char_size = sizeof(nwchar_t);
|
|
|
|
n = tokcstr.size / char_size - 1;
|
|
|
|
if (n < 1)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tcc_error("empty character constant");
|
2017-09-24 19:57:48 +03:00
|
|
|
if (n > 1)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tcc_warning("multi-character character constant");
|
2017-09-24 19:57:48 +03:00
|
|
|
for (c = i = 0; i < n; ++i) {
|
|
|
|
if (is_long)
|
|
|
|
c = ((nwchar_t *)tokcstr.data)[i];
|
|
|
|
else
|
|
|
|
c = (c << 8) | ((char *)tokcstr.data)[i];
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
}
|
2017-09-24 19:57:48 +03:00
|
|
|
tokc.i = c;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} else {
|
2015-11-21 14:23:53 +03:00
|
|
|
tokc.str.size = tokcstr.size;
|
|
|
|
tokc.str.data = tokcstr.data;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (!is_long)
|
|
|
|
tok = TOK_STR;
|
|
|
|
else
|
|
|
|
tok = TOK_LSTR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* we use 64 bit numbers */
|
|
|
|
#define BN_SIZE 2
|
|
|
|
|
|
|
|
/* bn = (bn << shift) | or_val */
|
2009-12-20 03:53:49 +03:00
|
|
|
static void bn_lshift(unsigned int *bn, int shift, int or_val)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned int v;
|
|
|
|
for(i=0;i<BN_SIZE;i++) {
|
|
|
|
v = bn[i];
|
|
|
|
bn[i] = (v << shift) | or_val;
|
|
|
|
or_val = v >> (32 - shift);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
static void bn_zero(unsigned int *bn)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;i<BN_SIZE;i++) {
|
|
|
|
bn[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse number in null terminated string 'p' and return it in the
|
|
|
|
current token */
|
2009-12-20 03:53:49 +03:00
|
|
|
static void parse_number(const char *p)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
int b, t, shift, frac_bits, s, exp_val, ch;
|
|
|
|
char *q;
|
|
|
|
unsigned int bn[BN_SIZE];
|
|
|
|
double d;
|
|
|
|
|
|
|
|
/* number */
|
|
|
|
q = token_buf;
|
|
|
|
ch = *p++;
|
|
|
|
t = ch;
|
|
|
|
ch = *p++;
|
|
|
|
*q++ = t;
|
|
|
|
b = 10;
|
|
|
|
if (t == '.') {
|
|
|
|
goto float_frac_parse;
|
|
|
|
} else if (t == '0') {
|
|
|
|
if (ch == 'x' || ch == 'X') {
|
|
|
|
q--;
|
|
|
|
ch = *p++;
|
|
|
|
b = 16;
|
|
|
|
} else if (tcc_ext && (ch == 'b' || ch == 'B')) {
|
|
|
|
q--;
|
|
|
|
ch = *p++;
|
|
|
|
b = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* parse all digits. cannot check octal numbers at this stage
|
|
|
|
because of floating point constants */
|
|
|
|
while (1) {
|
|
|
|
if (ch >= 'a' && ch <= 'f')
|
|
|
|
t = ch - 'a' + 10;
|
|
|
|
else if (ch >= 'A' && ch <= 'F')
|
|
|
|
t = ch - 'A' + 10;
|
|
|
|
else if (isnum(ch))
|
|
|
|
t = ch - '0';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
if (t >= b)
|
|
|
|
break;
|
|
|
|
if (q >= token_buf + STRING_MAX_SIZE) {
|
|
|
|
num_too_long:
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("number too long");
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
*q++ = ch;
|
|
|
|
ch = *p++;
|
|
|
|
}
|
|
|
|
if (ch == '.' ||
|
|
|
|
((ch == 'e' || ch == 'E') && b == 10) ||
|
|
|
|
((ch == 'p' || ch == 'P') && (b == 16 || b == 2))) {
|
|
|
|
if (b != 10) {
|
|
|
|
/* NOTE: strtox should support that for hexa numbers, but
|
|
|
|
non ISOC99 libcs do not support it, so we prefer to do
|
|
|
|
it by hand */
|
|
|
|
/* hexadecimal or binary floats */
|
|
|
|
/* XXX: handle overflows */
|
|
|
|
*q = '\0';
|
|
|
|
if (b == 16)
|
|
|
|
shift = 4;
|
2015-07-29 23:53:57 +03:00
|
|
|
else
|
2014-12-15 11:32:08 +03:00
|
|
|
shift = 1;
|
2009-05-05 22:17:49 +04:00
|
|
|
bn_zero(bn);
|
|
|
|
q = token_buf;
|
|
|
|
while (1) {
|
|
|
|
t = *q++;
|
|
|
|
if (t == '\0') {
|
|
|
|
break;
|
|
|
|
} else if (t >= 'a') {
|
|
|
|
t = t - 'a' + 10;
|
|
|
|
} else if (t >= 'A') {
|
|
|
|
t = t - 'A' + 10;
|
|
|
|
} else {
|
|
|
|
t = t - '0';
|
|
|
|
}
|
|
|
|
bn_lshift(bn, shift, t);
|
|
|
|
}
|
|
|
|
frac_bits = 0;
|
|
|
|
if (ch == '.') {
|
|
|
|
ch = *p++;
|
|
|
|
while (1) {
|
|
|
|
t = ch;
|
|
|
|
if (t >= 'a' && t <= 'f') {
|
|
|
|
t = t - 'a' + 10;
|
|
|
|
} else if (t >= 'A' && t <= 'F') {
|
|
|
|
t = t - 'A' + 10;
|
|
|
|
} else if (t >= '0' && t <= '9') {
|
|
|
|
t = t - '0';
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (t >= b)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("invalid digit");
|
2009-05-05 22:17:49 +04:00
|
|
|
bn_lshift(bn, shift, t);
|
|
|
|
frac_bits += shift;
|
|
|
|
ch = *p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ch != 'p' && ch != 'P')
|
|
|
|
expect("exponent");
|
|
|
|
ch = *p++;
|
|
|
|
s = 1;
|
|
|
|
exp_val = 0;
|
|
|
|
if (ch == '+') {
|
|
|
|
ch = *p++;
|
|
|
|
} else if (ch == '-') {
|
|
|
|
s = -1;
|
|
|
|
ch = *p++;
|
|
|
|
}
|
|
|
|
if (ch < '0' || ch > '9')
|
|
|
|
expect("exponent digits");
|
|
|
|
while (ch >= '0' && ch <= '9') {
|
|
|
|
exp_val = exp_val * 10 + ch - '0';
|
|
|
|
ch = *p++;
|
|
|
|
}
|
|
|
|
exp_val = exp_val * s;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* now we can generate the number */
|
|
|
|
/* XXX: should patch directly float number */
|
|
|
|
d = (double)bn[1] * 4294967296.0 + (double)bn[0];
|
|
|
|
d = ldexp(d, exp_val - frac_bits);
|
|
|
|
t = toup(ch);
|
|
|
|
if (t == 'F') {
|
|
|
|
ch = *p++;
|
|
|
|
tok = TOK_CFLOAT;
|
|
|
|
/* float : should handle overflow */
|
|
|
|
tokc.f = (float)d;
|
|
|
|
} else if (t == 'L') {
|
|
|
|
ch = *p++;
|
2009-07-19 00:07:17 +04:00
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
tok = TOK_CDOUBLE;
|
|
|
|
tokc.d = d;
|
|
|
|
#else
|
2009-05-05 22:17:49 +04:00
|
|
|
tok = TOK_CLDOUBLE;
|
|
|
|
/* XXX: not large enough */
|
|
|
|
tokc.ld = (long double)d;
|
2009-07-19 00:07:17 +04:00
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
|
|
|
tok = TOK_CDOUBLE;
|
|
|
|
tokc.d = d;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* decimal floats */
|
|
|
|
if (ch == '.') {
|
|
|
|
if (q >= token_buf + STRING_MAX_SIZE)
|
|
|
|
goto num_too_long;
|
|
|
|
*q++ = ch;
|
|
|
|
ch = *p++;
|
|
|
|
float_frac_parse:
|
|
|
|
while (ch >= '0' && ch <= '9') {
|
|
|
|
if (q >= token_buf + STRING_MAX_SIZE)
|
|
|
|
goto num_too_long;
|
|
|
|
*q++ = ch;
|
|
|
|
ch = *p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ch == 'e' || ch == 'E') {
|
|
|
|
if (q >= token_buf + STRING_MAX_SIZE)
|
|
|
|
goto num_too_long;
|
|
|
|
*q++ = ch;
|
|
|
|
ch = *p++;
|
|
|
|
if (ch == '-' || ch == '+') {
|
|
|
|
if (q >= token_buf + STRING_MAX_SIZE)
|
|
|
|
goto num_too_long;
|
|
|
|
*q++ = ch;
|
|
|
|
ch = *p++;
|
|
|
|
}
|
|
|
|
if (ch < '0' || ch > '9')
|
|
|
|
expect("exponent digits");
|
|
|
|
while (ch >= '0' && ch <= '9') {
|
|
|
|
if (q >= token_buf + STRING_MAX_SIZE)
|
|
|
|
goto num_too_long;
|
|
|
|
*q++ = ch;
|
|
|
|
ch = *p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
t = toup(ch);
|
|
|
|
errno = 0;
|
|
|
|
if (t == 'F') {
|
|
|
|
ch = *p++;
|
|
|
|
tok = TOK_CFLOAT;
|
|
|
|
tokc.f = strtof(token_buf, NULL);
|
|
|
|
} else if (t == 'L') {
|
|
|
|
ch = *p++;
|
2009-07-19 00:07:17 +04:00
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
tok = TOK_CDOUBLE;
|
|
|
|
tokc.d = strtod(token_buf, NULL);
|
|
|
|
#else
|
2009-05-05 22:17:49 +04:00
|
|
|
tok = TOK_CLDOUBLE;
|
|
|
|
tokc.ld = strtold(token_buf, NULL);
|
2009-07-19 00:07:17 +04:00
|
|
|
#endif
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
|
|
|
tok = TOK_CDOUBLE;
|
|
|
|
tokc.d = strtod(token_buf, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned long long n, n1;
|
2017-09-24 19:57:48 +03:00
|
|
|
int lcount, ucount, ov = 0;
|
2015-02-18 07:22:25 +03:00
|
|
|
const char *p1;
|
2009-05-05 22:17:49 +04:00
|
|
|
|
|
|
|
/* integer number */
|
|
|
|
*q = '\0';
|
|
|
|
q = token_buf;
|
|
|
|
if (b == 10 && *q == '0') {
|
|
|
|
b = 8;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
n = 0;
|
|
|
|
while(1) {
|
|
|
|
t = *q++;
|
|
|
|
/* no need for checks except for base 10 / 8 errors */
|
2015-02-18 07:22:25 +03:00
|
|
|
if (t == '\0')
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
2015-02-18 07:22:25 +03:00
|
|
|
else if (t >= 'a')
|
2009-05-05 22:17:49 +04:00
|
|
|
t = t - 'a' + 10;
|
2015-02-18 07:22:25 +03:00
|
|
|
else if (t >= 'A')
|
2009-05-05 22:17:49 +04:00
|
|
|
t = t - 'A' + 10;
|
2015-02-18 07:22:25 +03:00
|
|
|
else
|
2009-05-05 22:17:49 +04:00
|
|
|
t = t - '0';
|
2015-02-18 07:22:25 +03:00
|
|
|
if (t >= b)
|
|
|
|
tcc_error("invalid digit");
|
2009-05-05 22:17:49 +04:00
|
|
|
n1 = n;
|
|
|
|
n = n * b + t;
|
|
|
|
/* detect overflow */
|
2017-09-24 19:57:48 +03:00
|
|
|
if (n1 >= 0x1000000000000000ULL && n / b != n1)
|
|
|
|
ov = 1;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2015-02-18 07:22:25 +03:00
|
|
|
|
|
|
|
/* Determine the characteristics (unsigned and/or 64bit) the type of
|
|
|
|
the constant must have according to the constant suffix(es) */
|
2017-09-24 19:57:48 +03:00
|
|
|
lcount = ucount = 0;
|
2015-02-18 07:22:25 +03:00
|
|
|
p1 = p;
|
2009-05-05 22:17:49 +04:00
|
|
|
for(;;) {
|
|
|
|
t = toup(ch);
|
|
|
|
if (t == 'L') {
|
|
|
|
if (lcount >= 2)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("three 'l's in integer constant");
|
2015-02-18 07:22:25 +03:00
|
|
|
if (lcount && *(p - 1) != ch)
|
|
|
|
tcc_error("incorrect integer suffix: %s", p1);
|
2009-05-05 22:17:49 +04:00
|
|
|
lcount++;
|
|
|
|
ch = *p++;
|
|
|
|
} else if (t == 'U') {
|
|
|
|
if (ucount >= 1)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("two 'u's in integer constant");
|
2009-05-05 22:17:49 +04:00
|
|
|
ucount++;
|
|
|
|
ch = *p++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 07:22:25 +03:00
|
|
|
|
2017-09-24 19:57:48 +03:00
|
|
|
/* Determine if it needs 64 bits and/or unsigned in order to fit */
|
|
|
|
if (ucount == 0 && b == 10) {
|
|
|
|
if (lcount <= (LONG_SIZE == 4)) {
|
|
|
|
if (n >= 0x80000000U)
|
|
|
|
lcount = (LONG_SIZE == 4) + 1;
|
|
|
|
}
|
|
|
|
if (n >= 0x8000000000000000ULL)
|
|
|
|
ov = 1, ucount = 1;
|
|
|
|
} else {
|
|
|
|
if (lcount <= (LONG_SIZE == 4)) {
|
|
|
|
if (n >= 0x100000000ULL)
|
|
|
|
lcount = (LONG_SIZE == 4) + 1;
|
|
|
|
else if (n >= 0x80000000U)
|
|
|
|
ucount = 1;
|
|
|
|
}
|
|
|
|
if (n >= 0x8000000000000000ULL)
|
|
|
|
ucount = 1;
|
2015-02-18 07:22:25 +03:00
|
|
|
}
|
|
|
|
|
2017-09-24 19:57:48 +03:00
|
|
|
if (ov)
|
|
|
|
tcc_warning("integer constant overflow");
|
2015-02-18 07:22:25 +03:00
|
|
|
|
2017-09-24 19:57:48 +03:00
|
|
|
tok = TOK_CINT;
|
|
|
|
if (lcount) {
|
|
|
|
tok = TOK_CLONG;
|
|
|
|
if (lcount == 2)
|
|
|
|
tok = TOK_CLLONG;
|
|
|
|
}
|
|
|
|
if (ucount)
|
|
|
|
++tok; /* TOK_CU... */
|
2016-08-16 22:22:59 +03:00
|
|
|
tokc.i = n;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
if (ch)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("invalid number\n");
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define PARSE2(c1, tok1, c2, tok2) \
|
|
|
|
case c1: \
|
|
|
|
PEEKC(c, p); \
|
|
|
|
if (c == c2) { \
|
|
|
|
p++; \
|
|
|
|
tok = tok2; \
|
|
|
|
} else { \
|
|
|
|
tok = tok1; \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* return next token without macro substitution */
|
|
|
|
static inline void next_nomacro1(void)
|
|
|
|
{
|
2016-04-17 16:37:23 +03:00
|
|
|
int t, c, is_long, len;
|
2009-05-05 22:17:49 +04:00
|
|
|
TokenSym *ts;
|
|
|
|
uint8_t *p, *p1;
|
|
|
|
unsigned int h;
|
|
|
|
|
|
|
|
p = file->buf_ptr;
|
|
|
|
redo_no_start:
|
|
|
|
c = *p;
|
|
|
|
switch(c) {
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
tok = c;
|
|
|
|
p++;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (parse_flags & PARSE_FLAG_SPACES)
|
|
|
|
goto keep_tok_flags;
|
|
|
|
while (isidnum_table[*p - CH_EOF] & IS_SPC)
|
|
|
|
++p;
|
|
|
|
goto redo_no_start;
|
2009-05-05 22:17:49 +04:00
|
|
|
case '\f':
|
|
|
|
case '\v':
|
|
|
|
case '\r':
|
|
|
|
p++;
|
|
|
|
goto redo_no_start;
|
|
|
|
case '\\':
|
|
|
|
/* first look if it is in fact an end of buffer */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
c = handle_stray1(p);
|
|
|
|
p = file->buf_ptr;
|
|
|
|
if (c == '\\')
|
|
|
|
goto parse_simple;
|
|
|
|
if (c != CH_EOF)
|
2009-05-05 22:17:49 +04:00
|
|
|
goto redo_no_start;
|
|
|
|
{
|
|
|
|
TCCState *s1 = tcc_state;
|
|
|
|
if ((parse_flags & PARSE_FLAG_LINEFEED)
|
|
|
|
&& !(tok_flags & TOK_FLAG_EOF)) {
|
|
|
|
tok_flags |= TOK_FLAG_EOF;
|
|
|
|
tok = TOK_LINEFEED;
|
|
|
|
goto keep_tok_flags;
|
2010-01-14 23:00:05 +03:00
|
|
|
} else if (!(parse_flags & PARSE_FLAG_PREPROCESS)) {
|
|
|
|
tok = TOK_EOF;
|
|
|
|
} else if (s1->ifdef_stack_ptr != file->ifdef_stack_ptr) {
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("missing #endif");
|
2010-01-14 23:00:05 +03:00
|
|
|
} else if (s1->include_stack_ptr == s1->include_stack) {
|
2009-05-05 22:17:49 +04:00
|
|
|
/* no include left : end of file. */
|
|
|
|
tok = TOK_EOF;
|
|
|
|
} else {
|
|
|
|
tok_flags &= ~TOK_FLAG_EOF;
|
|
|
|
/* pop include file */
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* test if previous '#endif' was after a #ifdef at
|
|
|
|
start of file */
|
|
|
|
if (tok_flags & TOK_FLAG_ENDIF) {
|
|
|
|
#ifdef INC_DEBUG
|
|
|
|
printf("#endif %s\n", get_tok_str(file->ifndef_macro_saved, NULL));
|
|
|
|
#endif
|
2016-10-01 21:03:48 +03:00
|
|
|
search_cached_include(s1, file->filename, 1)
|
|
|
|
->ifndef_macro = file->ifndef_macro_saved;
|
2013-01-06 20:20:44 +04:00
|
|
|
tok_flags &= ~TOK_FLAG_ENDIF;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add end of include file debug info */
|
2009-05-11 20:45:44 +04:00
|
|
|
if (tcc_state->do_debug) {
|
2009-05-05 22:17:49 +04:00
|
|
|
put_stabd(N_EINCL, 0, 0);
|
|
|
|
}
|
|
|
|
/* pop include stack */
|
2010-11-25 15:29:15 +03:00
|
|
|
tcc_close();
|
2009-05-05 22:17:49 +04:00
|
|
|
s1->include_stack_ptr--;
|
|
|
|
p = file->buf_ptr;
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
if (p == file->buffer)
|
|
|
|
tok_flags = TOK_FLAG_BOF|TOK_FLAG_BOL;
|
2009-05-05 22:17:49 +04:00
|
|
|
goto redo_no_start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
file->line_num++;
|
|
|
|
tok_flags |= TOK_FLAG_BOL;
|
|
|
|
p++;
|
2009-07-06 23:12:45 +04:00
|
|
|
maybe_newline:
|
2009-05-05 22:17:49 +04:00
|
|
|
if (0 == (parse_flags & PARSE_FLAG_LINEFEED))
|
|
|
|
goto redo_no_start;
|
|
|
|
tok = TOK_LINEFEED;
|
|
|
|
goto keep_tok_flags;
|
|
|
|
|
|
|
|
case '#':
|
|
|
|
/* XXX: simplify */
|
|
|
|
PEEKC(c, p);
|
2015-07-29 23:53:57 +03:00
|
|
|
if ((tok_flags & TOK_FLAG_BOL) &&
|
2009-05-05 22:17:49 +04:00
|
|
|
(parse_flags & PARSE_FLAG_PREPROCESS)) {
|
|
|
|
file->buf_ptr = p;
|
|
|
|
preprocess(tok_flags & TOK_FLAG_BOF);
|
|
|
|
p = file->buf_ptr;
|
2009-07-06 23:12:45 +04:00
|
|
|
goto maybe_newline;
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
|
|
|
if (c == '#') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_TWOSHARPS;
|
|
|
|
} else {
|
2015-04-27 16:36:58 +03:00
|
|
|
if (parse_flags & PARSE_FLAG_ASM_FILE) {
|
2016-05-05 15:12:53 +03:00
|
|
|
p = parse_line_comment(p - 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
goto redo_no_start;
|
|
|
|
} else {
|
|
|
|
tok = '#';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2015-04-20 03:44:08 +03:00
|
|
|
/* dollar is allowed to start identifiers when not parsing asm */
|
|
|
|
case '$':
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (!(isidnum_table[c - CH_EOF] & IS_ID)
|
|
|
|
|| (parse_flags & PARSE_FLAG_ASM_FILE))
|
|
|
|
goto parse_simple;
|
2015-04-20 03:44:08 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
case 'a': case 'b': case 'c': case 'd':
|
|
|
|
case 'e': case 'f': case 'g': case 'h':
|
|
|
|
case 'i': case 'j': case 'k': case 'l':
|
|
|
|
case 'm': case 'n': case 'o': case 'p':
|
|
|
|
case 'q': case 'r': case 's': case 't':
|
|
|
|
case 'u': case 'v': case 'w': case 'x':
|
2015-07-29 23:53:57 +03:00
|
|
|
case 'y': case 'z':
|
2009-05-05 22:17:49 +04:00
|
|
|
case 'A': case 'B': case 'C': case 'D':
|
|
|
|
case 'E': case 'F': case 'G': case 'H':
|
2015-07-29 23:53:57 +03:00
|
|
|
case 'I': case 'J': case 'K':
|
2009-05-05 22:17:49 +04:00
|
|
|
case 'M': case 'N': case 'O': case 'P':
|
|
|
|
case 'Q': case 'R': case 'S': case 'T':
|
|
|
|
case 'U': case 'V': case 'W': case 'X':
|
2015-07-29 23:53:57 +03:00
|
|
|
case 'Y': case 'Z':
|
2009-05-05 22:17:49 +04:00
|
|
|
case '_':
|
|
|
|
parse_ident_fast:
|
|
|
|
p1 = p;
|
|
|
|
h = TOK_HASH_INIT;
|
|
|
|
h = TOK_HASH_FUNC(h, c);
|
2016-04-05 11:19:09 +03:00
|
|
|
while (c = *++p, isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
|
2009-05-05 22:17:49 +04:00
|
|
|
h = TOK_HASH_FUNC(h, c);
|
2016-04-17 16:37:23 +03:00
|
|
|
len = p - p1;
|
2009-05-05 22:17:49 +04:00
|
|
|
if (c != '\\') {
|
|
|
|
TokenSym **pts;
|
|
|
|
|
|
|
|
/* fast case : no stray found, so we have the full token
|
|
|
|
and we have already hashed it */
|
|
|
|
h &= (TOK_HASH_SIZE - 1);
|
|
|
|
pts = &hash_ident[h];
|
|
|
|
for(;;) {
|
|
|
|
ts = *pts;
|
|
|
|
if (!ts)
|
|
|
|
break;
|
|
|
|
if (ts->len == len && !memcmp(ts->str, p1, len))
|
|
|
|
goto token_found;
|
|
|
|
pts = &(ts->hash_next);
|
|
|
|
}
|
2014-03-09 18:52:31 +04:00
|
|
|
ts = tok_alloc_new(pts, (char *) p1, len);
|
2009-05-05 22:17:49 +04:00
|
|
|
token_found: ;
|
|
|
|
} else {
|
|
|
|
/* slower case */
|
|
|
|
cstr_reset(&tokcstr);
|
2017-03-28 09:51:39 +03:00
|
|
|
cstr_cat(&tokcstr, (char *) p1, len);
|
2009-05-05 22:17:49 +04:00
|
|
|
p--;
|
|
|
|
PEEKC(c, p);
|
|
|
|
parse_ident_slow:
|
2016-04-13 10:23:46 +03:00
|
|
|
while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
|
|
|
|
{
|
2009-05-05 22:17:49 +04:00
|
|
|
cstr_ccat(&tokcstr, c);
|
|
|
|
PEEKC(c, p);
|
|
|
|
}
|
|
|
|
ts = tok_alloc(tokcstr.data, tokcstr.size);
|
|
|
|
}
|
|
|
|
tok = ts->tok;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
t = p[1];
|
|
|
|
if (t != '\\' && t != '\'' && t != '\"') {
|
|
|
|
/* fast case */
|
|
|
|
goto parse_ident_fast;
|
|
|
|
} else {
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '\'' || c == '\"') {
|
|
|
|
is_long = 1;
|
|
|
|
goto str_const;
|
|
|
|
} else {
|
|
|
|
cstr_reset(&tokcstr);
|
|
|
|
cstr_ccat(&tokcstr, 'L');
|
|
|
|
goto parse_ident_slow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2016-05-04 22:27:39 +03:00
|
|
|
case '0': case '1': case '2': case '3':
|
2009-05-05 22:17:49 +04:00
|
|
|
case '4': case '5': case '6': case '7':
|
|
|
|
case '8': case '9':
|
2016-10-01 22:58:02 +03:00
|
|
|
t = c;
|
|
|
|
PEEKC(c, p);
|
2016-05-04 22:27:39 +03:00
|
|
|
/* after the first digit, accept digits, alpha, '.' or sign if
|
|
|
|
prefixed by 'eEpP' */
|
2009-05-05 22:17:49 +04:00
|
|
|
parse_num:
|
2016-10-01 22:58:02 +03:00
|
|
|
cstr_reset(&tokcstr);
|
2009-05-05 22:17:49 +04:00
|
|
|
for(;;) {
|
2016-10-01 22:58:02 +03:00
|
|
|
cstr_ccat(&tokcstr, t);
|
2016-05-04 22:27:39 +03:00
|
|
|
if (!((isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
|
|
|
|
|| c == '.'
|
|
|
|
|| ((c == '+' || c == '-')
|
2016-10-01 22:58:02 +03:00
|
|
|
&& (((t == 'e' || t == 'E')
|
|
|
|
&& !(parse_flags & PARSE_FLAG_ASM_FILE
|
|
|
|
/* 0xe+1 is 3 tokens in asm */
|
|
|
|
&& ((char*)tokcstr.data)[0] == '0'
|
|
|
|
&& toup(((char*)tokcstr.data)[1]) == 'X'))
|
|
|
|
|| t == 'p' || t == 'P'))))
|
2016-05-04 22:27:39 +03:00
|
|
|
break;
|
2016-10-01 22:58:02 +03:00
|
|
|
t = c;
|
|
|
|
PEEKC(c, p);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
/* We add a trailing '\0' to ease parsing */
|
|
|
|
cstr_ccat(&tokcstr, '\0');
|
2015-11-21 14:23:53 +03:00
|
|
|
tokc.str.size = tokcstr.size;
|
|
|
|
tokc.str.data = tokcstr.data;
|
2009-05-05 22:17:49 +04:00
|
|
|
tok = TOK_PPNUM;
|
|
|
|
break;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
case '.':
|
|
|
|
/* special dot handling because it can also start a number */
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (isnum(c)) {
|
2016-10-01 22:58:02 +03:00
|
|
|
t = '.';
|
2009-05-05 22:17:49 +04:00
|
|
|
goto parse_num;
|
2016-08-25 17:40:50 +03:00
|
|
|
} else if ((isidnum_table['.' - CH_EOF] & IS_ID)
|
2016-04-22 18:29:56 +03:00
|
|
|
&& (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))) {
|
2016-03-14 19:14:52 +03:00
|
|
|
*--p = c = '.';
|
|
|
|
goto parse_ident_fast;
|
2016-03-24 17:58:32 +03:00
|
|
|
} else if (c == '.') {
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '.') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_DOTS;
|
|
|
|
} else {
|
|
|
|
*--p = '.'; /* may underflow into file->unget[] */
|
|
|
|
tok = '.';
|
|
|
|
}
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
|
|
|
tok = '.';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
case '\"':
|
|
|
|
is_long = 0;
|
|
|
|
str_const:
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
cstr_reset(&tokcstr);
|
|
|
|
if (is_long)
|
|
|
|
cstr_ccat(&tokcstr, 'L');
|
|
|
|
cstr_ccat(&tokcstr, c);
|
|
|
|
p = parse_pp_string(p, c, &tokcstr);
|
|
|
|
cstr_ccat(&tokcstr, c);
|
|
|
|
cstr_ccat(&tokcstr, '\0');
|
2015-11-21 14:23:53 +03:00
|
|
|
tokc.str.size = tokcstr.size;
|
|
|
|
tokc.str.data = tokcstr.data;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tok = TOK_PPSTR;
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '<':
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_LE;
|
|
|
|
} else if (c == '<') {
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_A_SHL;
|
|
|
|
} else {
|
|
|
|
tok = TOK_SHL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tok = TOK_LT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_GE;
|
|
|
|
} else if (c == '>') {
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_A_SAR;
|
|
|
|
} else {
|
|
|
|
tok = TOK_SAR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tok = TOK_GT;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
case '&':
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '&') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_LAND;
|
|
|
|
} else if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_A_AND;
|
|
|
|
} else {
|
|
|
|
tok = '&';
|
|
|
|
}
|
|
|
|
break;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
case '|':
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '|') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_LOR;
|
|
|
|
} else if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_A_OR;
|
|
|
|
} else {
|
|
|
|
tok = '|';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '+') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_INC;
|
|
|
|
} else if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_A_ADD;
|
|
|
|
} else {
|
|
|
|
tok = '+';
|
|
|
|
}
|
|
|
|
break;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
case '-':
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '-') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_DEC;
|
|
|
|
} else if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_A_SUB;
|
|
|
|
} else if (c == '>') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_ARROW;
|
|
|
|
} else {
|
|
|
|
tok = '-';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
PARSE2('!', '!', '=', TOK_NE)
|
|
|
|
PARSE2('=', '=', '=', TOK_EQ)
|
|
|
|
PARSE2('*', '*', '=', TOK_A_MUL)
|
|
|
|
PARSE2('%', '%', '=', TOK_A_MOD)
|
|
|
|
PARSE2('^', '^', '=', TOK_A_XOR)
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* comments or operator */
|
|
|
|
case '/':
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '*') {
|
2016-05-05 15:12:53 +03:00
|
|
|
p = parse_comment(p);
|
2011-03-01 04:19:43 +03:00
|
|
|
/* comments replaced by a blank */
|
|
|
|
tok = ' ';
|
|
|
|
goto keep_tok_flags;
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if (c == '/') {
|
2016-05-05 15:12:53 +03:00
|
|
|
p = parse_line_comment(p);
|
2011-03-01 04:19:43 +03:00
|
|
|
tok = ' ';
|
|
|
|
goto keep_tok_flags;
|
2009-05-05 22:17:49 +04:00
|
|
|
} else if (c == '=') {
|
|
|
|
p++;
|
|
|
|
tok = TOK_A_DIV;
|
|
|
|
} else {
|
|
|
|
tok = '/';
|
|
|
|
}
|
|
|
|
break;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* simple tokens */
|
|
|
|
case '(':
|
|
|
|
case ')':
|
|
|
|
case '[':
|
|
|
|
case ']':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
case ',':
|
|
|
|
case ';':
|
|
|
|
case ':':
|
|
|
|
case '?':
|
|
|
|
case '~':
|
2015-04-12 15:32:03 +03:00
|
|
|
case '@': /* only used in assembler */
|
|
|
|
parse_simple:
|
2009-05-05 22:17:49 +04:00
|
|
|
tok = c;
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
default:
|
2016-10-01 21:26:50 +03:00
|
|
|
if (c >= 0x80 && c <= 0xFF) /* utf8 identifiers */
|
|
|
|
goto parse_ident_fast;
|
2016-04-14 21:46:46 +03:00
|
|
|
if (parse_flags & PARSE_FLAG_ASM_FILE)
|
|
|
|
goto parse_simple;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tcc_error("unrecognized character \\x%02x", c);
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
tok_flags = 0;
|
|
|
|
keep_tok_flags:
|
|
|
|
file->buf_ptr = p;
|
|
|
|
#if defined(PARSE_DEBUG)
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
printf("token = %d %s\n", tok, get_tok_str(tok, &tokc));
|
2009-05-05 22:17:49 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return next token without macro substitution. Can read input from
|
|
|
|
macro_ptr buffer */
|
|
|
|
static void next_nomacro_spc(void)
|
|
|
|
{
|
|
|
|
if (macro_ptr) {
|
|
|
|
redo:
|
|
|
|
tok = *macro_ptr;
|
|
|
|
if (tok) {
|
2010-01-14 22:58:03 +03:00
|
|
|
TOK_GET(&tok, ¯o_ptr, &tokc);
|
2009-05-05 22:17:49 +04:00
|
|
|
if (tok == TOK_LINENUM) {
|
|
|
|
file->line_num = tokc.i;
|
|
|
|
goto redo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
next_nomacro1();
|
|
|
|
}
|
2017-07-09 05:30:36 +03:00
|
|
|
//printf("token = %s\n", get_tok_str(tok, &tokc));
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void next_nomacro(void)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
do {
|
|
|
|
next_nomacro_spc();
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} while (tok < 256 && (isidnum_table[tok - CH_EOF] & IS_SPC));
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2015-07-29 23:53:57 +03:00
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
|
|
|
static void macro_subst(
|
|
|
|
TokenString *tok_str,
|
|
|
|
Sym **nested_list,
|
2017-07-09 05:53:24 +03:00
|
|
|
const int *macro_str
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
);
|
|
|
|
|
2014-04-12 08:00:13 +04:00
|
|
|
/* substitute arguments in replacement lists in macro_str by the values in
|
|
|
|
args (field d) and return allocated string */
|
2010-01-14 22:58:03 +03:00
|
|
|
static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
int t, t0, t1, spc;
|
2010-01-14 22:58:03 +03:00
|
|
|
const int *st;
|
2009-05-05 22:17:49 +04:00
|
|
|
Sym *s;
|
2014-04-04 22:18:39 +04:00
|
|
|
CValue cval;
|
2009-05-05 22:17:49 +04:00
|
|
|
TokenString str;
|
|
|
|
CString cstr;
|
|
|
|
|
|
|
|
tok_str_new(&str);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
t0 = t1 = 0;
|
2009-05-05 22:17:49 +04:00
|
|
|
while(1) {
|
2010-01-14 22:58:03 +03:00
|
|
|
TOK_GET(&t, ¯o_str, &cval);
|
2009-05-05 22:17:49 +04:00
|
|
|
if (!t)
|
|
|
|
break;
|
|
|
|
if (t == '#') {
|
|
|
|
/* stringize */
|
2010-01-14 22:58:03 +03:00
|
|
|
TOK_GET(&t, ¯o_str, &cval);
|
2009-05-05 22:17:49 +04:00
|
|
|
if (!t)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
goto bad_stringy;
|
2009-05-05 22:17:49 +04:00
|
|
|
s = sym_find2(args, t);
|
|
|
|
if (s) {
|
|
|
|
cstr_new(&cstr);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
cstr_ccat(&cstr, '\"');
|
2009-07-06 23:16:41 +04:00
|
|
|
st = s->d;
|
2009-05-05 22:17:49 +04:00
|
|
|
spc = 0;
|
2017-07-09 05:30:36 +03:00
|
|
|
while (*st >= 0) {
|
2010-01-14 22:58:03 +03:00
|
|
|
TOK_GET(&t, &st, &cval);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (t != TOK_PLCHLDR
|
|
|
|
&& t != TOK_NOSUBST
|
|
|
|
&& 0 == check_space(t, &spc)) {
|
|
|
|
const char *s = get_tok_str(t, &cval);
|
|
|
|
while (*s) {
|
2016-03-14 19:26:41 +03:00
|
|
|
if (t == TOK_PPSTR && *s != '\'')
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
add_char(&cstr, *s);
|
|
|
|
else
|
|
|
|
cstr_ccat(&cstr, *s);
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
}
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
cstr.size -= spc;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
cstr_ccat(&cstr, '\"');
|
2009-05-05 22:17:49 +04:00
|
|
|
cstr_ccat(&cstr, '\0');
|
|
|
|
#ifdef PP_DEBUG
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
printf("\nstringize: <%s>\n", (char *)cstr.data);
|
2009-05-05 22:17:49 +04:00
|
|
|
#endif
|
|
|
|
/* add string */
|
2015-11-21 14:23:53 +03:00
|
|
|
cval.str.size = cstr.size;
|
|
|
|
cval.str.data = cstr.data;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tok_str_add2(&str, TOK_PPSTR, &cval);
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_free(&cstr);
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
bad_stringy:
|
|
|
|
expect("macro parameter after '#'");
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
} else if (t >= TOK_IDENT) {
|
|
|
|
s = sym_find2(args, t);
|
|
|
|
if (s) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
int l0 = str.len;
|
2009-07-06 23:16:41 +04:00
|
|
|
st = s->d;
|
2009-05-05 22:17:49 +04:00
|
|
|
/* if '##' is present before or after, no arg substitution */
|
2016-10-31 05:59:31 +03:00
|
|
|
if (*macro_str == TOK_PPJOIN || t1 == TOK_PPJOIN) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* special case for var arg macros : ## eats the ','
|
|
|
|
if empty VA_ARGS variable. */
|
2016-10-31 05:59:31 +03:00
|
|
|
if (t1 == TOK_PPJOIN && t0 == ',' && gnu_ext && s->type.t) {
|
2017-07-09 05:30:36 +03:00
|
|
|
if (*st <= 0) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* suppress ',' '##' */
|
|
|
|
str.len -= 2;
|
|
|
|
} else {
|
|
|
|
/* suppress '##' and add variable */
|
|
|
|
str.len--;
|
|
|
|
goto add_var;
|
|
|
|
}
|
2015-05-02 17:27:49 +03:00
|
|
|
}
|
|
|
|
} else {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
add_var:
|
2017-07-09 06:30:47 +03:00
|
|
|
if (!s->next) {
|
|
|
|
/* Expand arguments tokens and store them. In most
|
|
|
|
cases we could also re-expand each argument if
|
|
|
|
used multiple times, but not if the argument
|
|
|
|
contains the __COUNTER__ macro. */
|
|
|
|
TokenString str2;
|
|
|
|
sym_push2(&s->next, s->v, s->type.t, 0);
|
|
|
|
tok_str_new(&str2);
|
|
|
|
macro_subst(&str2, nested_list, st);
|
|
|
|
tok_str_add(&str2, 0);
|
|
|
|
s->next->d = str2.str;
|
|
|
|
}
|
|
|
|
st = s->next->d;
|
|
|
|
}
|
|
|
|
for(;;) {
|
|
|
|
int t2;
|
|
|
|
TOK_GET(&t2, &st, &cval);
|
|
|
|
if (t2 <= 0)
|
|
|
|
break;
|
|
|
|
tok_str_add2(&str, t2, &cval);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2017-05-08 07:38:09 +03:00
|
|
|
if (str.len == l0) /* expanded to empty string */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tok_str_add(&str, TOK_PLCHLDR);
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
|
|
|
tok_str_add(&str, t);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tok_str_add2(&str, t, &cval);
|
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
t0 = t1, t1 = t;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
tok_str_add(&str, 0);
|
|
|
|
return str.str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char const ab_month_name[12][4] =
|
|
|
|
{
|
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
|
|
};
|
|
|
|
|
2017-07-09 05:53:24 +03:00
|
|
|
static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2)
|
|
|
|
{
|
|
|
|
CString cstr;
|
|
|
|
int n, ret = 1;
|
|
|
|
|
|
|
|
cstr_new(&cstr);
|
|
|
|
if (t1 != TOK_PLCHLDR)
|
|
|
|
cstr_cat(&cstr, get_tok_str(t1, v1), -1);
|
|
|
|
n = cstr.size;
|
|
|
|
if (t2 != TOK_PLCHLDR)
|
|
|
|
cstr_cat(&cstr, get_tok_str(t2, v2), -1);
|
|
|
|
cstr_ccat(&cstr, '\0');
|
|
|
|
|
|
|
|
tcc_open_bf(tcc_state, ":paste:", cstr.size);
|
|
|
|
memcpy(file->buffer, cstr.data, cstr.size);
|
2017-07-20 23:21:27 +03:00
|
|
|
tok_flags = 0;
|
2017-07-09 05:53:24 +03:00
|
|
|
for (;;) {
|
|
|
|
next_nomacro1();
|
|
|
|
if (0 == *file->buf_ptr)
|
|
|
|
break;
|
|
|
|
if (is_space(tok))
|
|
|
|
continue;
|
|
|
|
tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid"
|
|
|
|
" preprocessing token", n, cstr.data, (char*)cstr.data + n);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tcc_close();
|
|
|
|
//printf("paste <%s>\n", (char*)cstr.data);
|
|
|
|
cstr_free(&cstr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle the '##' operator. Return NULL if no '##' seen. Otherwise
|
|
|
|
return the resulting string (which must be freed). */
|
|
|
|
static inline int *macro_twosharps(const int *ptr0)
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
CValue cval;
|
|
|
|
TokenString macro_str1;
|
|
|
|
int start_of_nosubsts = -1;
|
|
|
|
const int *ptr;
|
|
|
|
|
|
|
|
/* we search the first '##' */
|
|
|
|
for (ptr = ptr0;;) {
|
|
|
|
TOK_GET(&t, &ptr, &cval);
|
|
|
|
if (t == TOK_PPJOIN)
|
|
|
|
break;
|
|
|
|
if (t == 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tok_str_new(¯o_str1);
|
|
|
|
|
|
|
|
//tok_print(" $$$", ptr0);
|
|
|
|
for (ptr = ptr0;;) {
|
|
|
|
TOK_GET(&t, &ptr, &cval);
|
|
|
|
if (t == 0)
|
|
|
|
break;
|
|
|
|
if (t == TOK_PPJOIN)
|
|
|
|
continue;
|
|
|
|
while (*ptr == TOK_PPJOIN) {
|
|
|
|
int t1; CValue cv1;
|
|
|
|
/* given 'a##b', remove nosubsts preceding 'a' */
|
|
|
|
if (start_of_nosubsts >= 0)
|
|
|
|
macro_str1.len = start_of_nosubsts;
|
|
|
|
/* given 'a##b', remove nosubsts preceding 'b' */
|
|
|
|
while ((t1 = *++ptr) == TOK_NOSUBST)
|
|
|
|
;
|
|
|
|
if (t1 && t1 != TOK_PPJOIN) {
|
|
|
|
TOK_GET(&t1, &ptr, &cv1);
|
|
|
|
if (t != TOK_PLCHLDR || t1 != TOK_PLCHLDR) {
|
|
|
|
if (paste_tokens(t, &cval, t1, &cv1)) {
|
|
|
|
t = tok, cval = tokc;
|
|
|
|
} else {
|
|
|
|
tok_str_add2(¯o_str1, t, &cval);
|
|
|
|
t = t1, cval = cv1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (t == TOK_NOSUBST) {
|
|
|
|
if (start_of_nosubsts < 0)
|
|
|
|
start_of_nosubsts = macro_str1.len;
|
|
|
|
} else {
|
|
|
|
start_of_nosubsts = -1;
|
|
|
|
}
|
|
|
|
tok_str_add2(¯o_str1, t, &cval);
|
|
|
|
}
|
|
|
|
tok_str_add(¯o_str1, 0);
|
|
|
|
//tok_print(" ###", macro_str1.str);
|
|
|
|
return macro_str1.str;
|
|
|
|
}
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* peek or read [ws_str == NULL] next token from function macro call,
|
|
|
|
walking up macro levels up to the file if necessary */
|
2017-07-09 05:53:24 +03:00
|
|
|
static int next_argstream(Sym **nested_list, TokenString *ws_str)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
{
|
|
|
|
int t;
|
|
|
|
const int *p;
|
|
|
|
Sym *sa;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (macro_ptr) {
|
|
|
|
p = macro_ptr, t = *p;
|
|
|
|
if (ws_str) {
|
2017-04-15 20:24:13 +03:00
|
|
|
while (is_space(t) || TOK_LINEFEED == t || TOK_PLCHLDR == t)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tok_str_add(ws_str, t), t = *++p;
|
|
|
|
}
|
2017-07-09 05:30:36 +03:00
|
|
|
if (t == 0) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
end_macro();
|
|
|
|
/* also, end of scope for nested defined symbol */
|
|
|
|
sa = *nested_list;
|
2016-04-29 20:00:33 +03:00
|
|
|
while (sa && sa->v == 0)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
sa = sa->prev;
|
|
|
|
if (sa)
|
2016-04-29 20:00:33 +03:00
|
|
|
sa->v = 0;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ch = handle_eob();
|
|
|
|
if (ws_str) {
|
|
|
|
while (is_space(ch) || ch == '\n' || ch == '/') {
|
|
|
|
if (ch == '/') {
|
|
|
|
int c;
|
|
|
|
uint8_t *p = file->buf_ptr;
|
|
|
|
PEEKC(c, p);
|
|
|
|
if (c == '*') {
|
2016-05-05 15:12:53 +03:00
|
|
|
p = parse_comment(p);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
file->buf_ptr = p - 1;
|
|
|
|
} else if (c == '/') {
|
2016-05-05 15:12:53 +03:00
|
|
|
p = parse_line_comment(p);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
file->buf_ptr = p - 1;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
ch = ' ';
|
|
|
|
}
|
2017-07-20 23:21:27 +03:00
|
|
|
if (ch == '\n')
|
|
|
|
file->line_num++;
|
2016-10-09 21:33:14 +03:00
|
|
|
if (!(ch == '\f' || ch == '\v' || ch == '\r'))
|
|
|
|
tok_str_add(ws_str, ch);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
cinp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ws_str)
|
|
|
|
return t;
|
|
|
|
next_nomacro_spc();
|
|
|
|
return tok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* do macro substitution of current token with macro 's' and add
|
|
|
|
result to (tok_str,tok_len). 'nested_list' is the list of all
|
|
|
|
macros we got inside to avoid recursing. Return non zero if no
|
|
|
|
substitution needs to be done */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
static int macro_subst_tok(
|
|
|
|
TokenString *tok_str,
|
|
|
|
Sym **nested_list,
|
2017-07-09 05:53:24 +03:00
|
|
|
Sym *s)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
Sym *args, *sa, *sa1;
|
2017-07-23 22:24:11 +03:00
|
|
|
int parlevel, t, t1, spc;
|
2009-05-05 22:17:49 +04:00
|
|
|
TokenString str;
|
|
|
|
char *cstrval;
|
2014-04-04 22:18:39 +04:00
|
|
|
CValue cval;
|
2009-05-05 22:17:49 +04:00
|
|
|
CString cstr;
|
|
|
|
char buf[32];
|
2017-07-23 22:24:11 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* if symbol is a macro, prepare substitution */
|
|
|
|
/* special macros */
|
2017-07-09 06:30:47 +03:00
|
|
|
if (tok == TOK___LINE__ || tok == TOK___COUNTER__) {
|
2017-07-23 22:24:11 +03:00
|
|
|
t = tok == TOK___LINE__ ? file->line_num : pp_counter++;
|
2017-07-09 06:30:47 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%d", t);
|
2009-05-05 22:17:49 +04:00
|
|
|
cstrval = buf;
|
|
|
|
t1 = TOK_PPNUM;
|
|
|
|
goto add_cstr1;
|
|
|
|
} else if (tok == TOK___FILE__) {
|
|
|
|
cstrval = file->filename;
|
|
|
|
goto add_cstr;
|
|
|
|
} else if (tok == TOK___DATE__ || tok == TOK___TIME__) {
|
|
|
|
time_t ti;
|
|
|
|
struct tm *tm;
|
|
|
|
|
|
|
|
time(&ti);
|
|
|
|
tm = localtime(&ti);
|
|
|
|
if (tok == TOK___DATE__) {
|
2015-07-29 23:53:57 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s %2d %d",
|
2009-05-05 22:17:49 +04:00
|
|
|
ab_month_name[tm->tm_mon], tm->tm_mday, tm->tm_year + 1900);
|
|
|
|
} else {
|
2015-07-29 23:53:57 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%02d:%02d:%02d",
|
2009-05-05 22:17:49 +04:00
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
|
}
|
|
|
|
cstrval = buf;
|
|
|
|
add_cstr:
|
|
|
|
t1 = TOK_STR;
|
|
|
|
add_cstr1:
|
|
|
|
cstr_new(&cstr);
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_cat(&cstr, cstrval, 0);
|
2015-11-21 14:23:53 +03:00
|
|
|
cval.str.size = cstr.size;
|
|
|
|
cval.str.data = cstr.data;
|
2009-05-05 22:17:49 +04:00
|
|
|
tok_str_add2(tok_str, t1, &cval);
|
|
|
|
cstr_free(&cstr);
|
2017-07-23 22:24:11 +03:00
|
|
|
} else if (s->d) {
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
int saved_parse_flags = parse_flags;
|
2017-07-09 05:53:24 +03:00
|
|
|
int *joined_str = NULL;
|
2017-07-23 22:24:11 +03:00
|
|
|
int *mstr = s->d;
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
if (s->type.t == MACRO_FUNC) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* whitespace between macro name and argument list */
|
|
|
|
TokenString ws_str;
|
2015-05-02 16:55:42 +03:00
|
|
|
tok_str_new(&ws_str);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2015-05-02 16:55:42 +03:00
|
|
|
spc = 0;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
parse_flags |= PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED
|
|
|
|
| PARSE_FLAG_ACCEPT_STRAYS;
|
|
|
|
|
|
|
|
/* get next token from argument stream */
|
2017-07-09 05:53:24 +03:00
|
|
|
t = next_argstream(nested_list, &ws_str);
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
if (t != '(') {
|
2015-05-02 16:55:42 +03:00
|
|
|
/* not a macro substitution after all, restore the
|
|
|
|
* macro token plus all whitespace we've read.
|
|
|
|
* whitespace is intentionally not merged to preserve
|
|
|
|
* newlines. */
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
parse_flags = saved_parse_flags;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tok_str_add(tok_str, tok);
|
|
|
|
if (parse_flags & PARSE_FLAG_SPACES) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < ws_str.len; i++)
|
|
|
|
tok_str_add(tok_str, ws_str.str[i]);
|
|
|
|
}
|
2016-11-11 22:25:13 +03:00
|
|
|
tok_str_free_str(ws_str.str);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
return 0;
|
2015-05-02 16:55:42 +03:00
|
|
|
} else {
|
2016-11-11 22:25:13 +03:00
|
|
|
tok_str_free_str(ws_str.str);
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
}
|
2017-04-15 20:24:13 +03:00
|
|
|
do {
|
|
|
|
next_nomacro(); /* eat '(' */
|
|
|
|
} while (tok == TOK_PLCHLDR);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* argument macro */
|
|
|
|
args = NULL;
|
|
|
|
sa = s->next;
|
|
|
|
/* NOTE: empty args are allowed, except if no args */
|
|
|
|
for(;;) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
do {
|
2017-07-09 05:53:24 +03:00
|
|
|
next_argstream(nested_list, NULL);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} while (is_space(tok) || TOK_LINEFEED == tok);
|
|
|
|
empty_arg:
|
2009-05-05 22:17:49 +04:00
|
|
|
/* handle '()' case */
|
|
|
|
if (!args && !sa && tok == ')')
|
|
|
|
break;
|
|
|
|
if (!sa)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("macro '%s' used with too many args",
|
2009-05-05 22:17:49 +04:00
|
|
|
get_tok_str(s->v, 0));
|
|
|
|
tok_str_new(&str);
|
|
|
|
parlevel = spc = 0;
|
|
|
|
/* NOTE: non zero sa->t indicates VA_ARGS */
|
2015-07-29 23:53:57 +03:00
|
|
|
while ((parlevel > 0 ||
|
|
|
|
(tok != ')' &&
|
2015-05-02 15:33:45 +03:00
|
|
|
(tok != ',' || sa->type.t)))) {
|
|
|
|
if (tok == TOK_EOF || tok == 0)
|
|
|
|
break;
|
2009-05-05 22:17:49 +04:00
|
|
|
if (tok == '(')
|
|
|
|
parlevel++;
|
|
|
|
else if (tok == ')')
|
|
|
|
parlevel--;
|
|
|
|
if (tok == TOK_LINEFEED)
|
|
|
|
tok = ' ';
|
|
|
|
if (!check_space(tok, &spc))
|
|
|
|
tok_str_add2(&str, tok, &tokc);
|
2017-07-09 05:53:24 +03:00
|
|
|
next_argstream(nested_list, NULL);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2015-05-02 17:47:11 +03:00
|
|
|
if (parlevel)
|
|
|
|
expect(")");
|
2009-05-05 22:17:49 +04:00
|
|
|
str.len -= spc;
|
2017-07-09 05:30:36 +03:00
|
|
|
tok_str_add(&str, -1);
|
2009-05-05 22:17:49 +04:00
|
|
|
tok_str_add(&str, 0);
|
2009-07-06 23:16:41 +04:00
|
|
|
sa1 = sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, 0);
|
|
|
|
sa1->d = str.str;
|
2009-05-05 22:17:49 +04:00
|
|
|
sa = sa->next;
|
|
|
|
if (tok == ')') {
|
|
|
|
/* special case for gcc var args: add an empty
|
|
|
|
var arg argument if it is omitted */
|
|
|
|
if (sa && sa->type.t && gnu_ext)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
goto empty_arg;
|
|
|
|
break;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2015-05-02 23:30:07 +03:00
|
|
|
if (tok != ',')
|
|
|
|
expect(",");
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
if (sa) {
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("macro '%s' used with too few args",
|
2009-05-05 22:17:49 +04:00
|
|
|
get_tok_str(s->v, 0));
|
|
|
|
}
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
parse_flags = saved_parse_flags;
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* now subst each arg */
|
|
|
|
mstr = macro_arg_subst(nested_list, mstr, args);
|
|
|
|
/* free memory */
|
|
|
|
sa = args;
|
|
|
|
while (sa) {
|
|
|
|
sa1 = sa->prev;
|
2016-11-11 22:25:13 +03:00
|
|
|
tok_str_free_str(sa->d);
|
2017-07-09 06:30:47 +03:00
|
|
|
if (sa->next) {
|
|
|
|
tok_str_free_str(sa->next->d);
|
|
|
|
sym_free(sa->next);
|
|
|
|
}
|
2009-05-05 22:17:49 +04:00
|
|
|
sym_free(sa);
|
|
|
|
sa = sa1;
|
|
|
|
}
|
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
sym_push2(nested_list, s->v, 0, 0);
|
tccpp.c: correct # stringification
Fix handling of escape characters, spaces, and line feeds in macros or
macro arguments that might yet be subject to # stringification.
Should this be an -f option? I think memory usage increases only very
slightly (in particular, while line feeds, stray \s, and spaces are
preserved, comments are not), so it's probably not worth it to make it
one.
Note that macro_subst now checks for stray \s which are still left in
the input stream after macro substitution, if desired.
This patch depends on the previous patch, so if you revert that, please
revert this patch, too.
See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
2015-05-02 16:19:14 +03:00
|
|
|
parse_flags = saved_parse_flags;
|
2017-07-09 05:53:24 +03:00
|
|
|
joined_str = macro_twosharps(mstr);
|
|
|
|
macro_subst(tok_str, nested_list, joined_str ? joined_str : mstr);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* pop nested defined symbol */
|
|
|
|
sa1 = *nested_list;
|
|
|
|
*nested_list = sa1->prev;
|
|
|
|
sym_free(sa1);
|
2017-07-09 05:53:24 +03:00
|
|
|
if (joined_str)
|
|
|
|
tok_str_free_str(joined_str);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (mstr != s->d)
|
2016-11-11 22:25:13 +03:00
|
|
|
tok_str_free_str(mstr);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do macro substitution of macro_str and add result to
|
|
|
|
(tok_str,tok_len). 'nested_list' is the list of all macros we got
|
|
|
|
inside to avoid recursing. */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
static void macro_subst(
|
|
|
|
TokenString *tok_str,
|
|
|
|
Sym **nested_list,
|
2017-07-09 05:53:24 +03:00
|
|
|
const int *macro_str
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
Sym *s;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
int t, spc, nosubst;
|
2014-04-04 22:18:39 +04:00
|
|
|
CValue cval;
|
2015-07-29 23:53:57 +03:00
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
spc = nosubst = 0;
|
tcc -E: append a ' ' after subst
We need a ' ' after subst of m in the following case
#define m(name,r) name ## r
#define m0(a,b,c) int m(a,b) c
#define m1(a,b,c) int m(a,b)c
m0(a, b, c);
m1(a, b, c);
2011-02-27 05:15:15 +03:00
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
while (1) {
|
2017-07-09 05:53:24 +03:00
|
|
|
TOK_GET(&t, ¯o_str, &cval);
|
2017-07-09 05:30:36 +03:00
|
|
|
if (t <= 0)
|
2009-05-05 22:17:49 +04:00
|
|
|
break;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
|
|
|
if (t >= TOK_IDENT && 0 == nosubst) {
|
|
|
|
s = define_find(t);
|
|
|
|
if (s == NULL)
|
|
|
|
goto no_subst;
|
|
|
|
|
2009-05-05 22:17:49 +04:00
|
|
|
/* if nested substitution, do nothing */
|
2011-02-02 00:23:40 +03:00
|
|
|
if (sym_find2(*nested_list, t)) {
|
|
|
|
/* and mark it as TOK_NOSUBST, so it doesn't get subst'd again */
|
|
|
|
tok_str_add2(tok_str, TOK_NOSUBST, NULL);
|
2009-05-05 22:17:49 +04:00
|
|
|
goto no_subst;
|
2011-02-02 00:23:40 +03:00
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
TokenString str;
|
2017-07-09 05:53:24 +03:00
|
|
|
str.str = (int*)macro_str;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
begin_macro(&str, 2);
|
|
|
|
|
|
|
|
tok = t;
|
2017-07-09 05:53:24 +03:00
|
|
|
macro_subst_tok(tok_str, nested_list, s);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
|
|
|
if (str.alloc == 3) {
|
|
|
|
/* already finished by reading function macro arguments */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-07-09 05:53:24 +03:00
|
|
|
macro_str = macro_ptr;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
end_macro ();
|
|
|
|
}
|
2017-06-05 14:21:39 +03:00
|
|
|
if (tok_str->len)
|
|
|
|
spc = is_space(t = tok_str->str[tok_str->lastlen]);
|
2009-05-05 22:17:49 +04:00
|
|
|
} else {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (t == '\\' && !(parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
|
|
|
|
tcc_error("stray '\\' in program");
|
|
|
|
no_subst:
|
|
|
|
if (!check_space(t, &spc))
|
2009-05-05 22:17:49 +04:00
|
|
|
tok_str_add2(tok_str, t, &cval);
|
2017-06-05 14:21:39 +03:00
|
|
|
|
|
|
|
if (nosubst) {
|
|
|
|
if (nosubst > 1 && (spc || (++nosubst == 3 && t == '(')))
|
|
|
|
continue;
|
|
|
|
nosubst = 0;
|
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (t == TOK_NOSUBST)
|
|
|
|
nosubst = 1;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
2017-09-25 04:03:26 +03:00
|
|
|
/* GCC supports 'defined' as result of a macro substitution */
|
2017-06-05 14:21:39 +03:00
|
|
|
if (t == TOK_DEFINED && pp_expr)
|
|
|
|
nosubst = 2;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return next token with macro substitution */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void next(void)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
|
|
|
redo:
|
|
|
|
if (parse_flags & PARSE_FLAG_SPACES)
|
|
|
|
next_nomacro_spc();
|
|
|
|
else
|
|
|
|
next_nomacro();
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
|
|
|
if (macro_ptr) {
|
|
|
|
if (tok == TOK_NOSUBST || tok == TOK_PLCHLDR) {
|
|
|
|
/* discard preprocessor markers */
|
2009-05-05 22:17:49 +04:00
|
|
|
goto redo;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} else if (tok == 0) {
|
|
|
|
/* end of macro or unget token string */
|
|
|
|
end_macro();
|
|
|
|
goto redo;
|
|
|
|
}
|
|
|
|
} else if (tok >= TOK_IDENT && (parse_flags & PARSE_FLAG_PREPROCESS)) {
|
|
|
|
Sym *s;
|
|
|
|
/* if reading from file, try to substitute macros */
|
|
|
|
s = define_find(tok);
|
|
|
|
if (s) {
|
2016-05-04 22:14:39 +03:00
|
|
|
Sym *nested_list = NULL;
|
|
|
|
tokstr_buf.len = 0;
|
2017-07-09 05:53:24 +03:00
|
|
|
macro_subst_tok(&tokstr_buf, &nested_list, s);
|
2016-04-17 16:37:23 +03:00
|
|
|
tok_str_add(&tokstr_buf, 0);
|
|
|
|
begin_macro(&tokstr_buf, 2);
|
2011-02-02 00:23:40 +03:00
|
|
|
goto redo;
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* convert preprocessor tokens into C tokens */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (tok == TOK_PPNUM) {
|
|
|
|
if (parse_flags & PARSE_FLAG_TOK_NUM)
|
2015-11-21 14:23:53 +03:00
|
|
|
parse_number((char *)tokc.str.data);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} else if (tok == TOK_PPSTR) {
|
|
|
|
if (parse_flags & PARSE_FLAG_TOK_STR)
|
2015-11-21 14:23:53 +03:00
|
|
|
parse_string((char *)tokc.str.data, tokc.str.size - 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push back current token and set current token to 'last_tok'. Only
|
|
|
|
identifier case handled for labels. */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_INLN void unget_tok(int last_tok)
|
2009-05-05 22:17:49 +04:00
|
|
|
{
|
2016-10-01 21:26:50 +03:00
|
|
|
|
|
|
|
TokenString *str = tok_str_alloc();
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tok_str_add2(str, tok, &tokc);
|
|
|
|
tok_str_add(str, 0);
|
|
|
|
begin_macro(str, 1);
|
2009-05-05 22:17:49 +04:00
|
|
|
tok = last_tok;
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:21:27 +03:00
|
|
|
ST_FUNC void preprocess_start(TCCState *s1, int is_asm)
|
2009-05-05 22:30:39 +04:00
|
|
|
{
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
CString cstr;
|
|
|
|
int i;
|
2017-02-13 20:23:55 +03:00
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
s1->include_stack_ptr = s1->include_stack;
|
|
|
|
s1->ifdef_stack_ptr = s1->ifdef_stack;
|
|
|
|
file->ifdef_stack_ptr = s1->ifdef_stack_ptr;
|
2017-07-23 22:24:11 +03:00
|
|
|
pp_expr = 0;
|
|
|
|
pp_counter = 0;
|
|
|
|
pp_debug_tok = pp_debug_symv = 0;
|
2016-10-01 21:03:48 +03:00
|
|
|
pp_once++;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
pvtop = vtop = vstack - 1;
|
2009-05-05 22:30:39 +04:00
|
|
|
s1->pack_stack[0] = 0;
|
|
|
|
s1->pack_stack_ptr = s1->pack_stack;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2016-08-25 17:40:50 +03:00
|
|
|
set_idnum('$', s1->dollars_in_identifiers ? IS_ID : 0);
|
2017-07-20 23:21:27 +03:00
|
|
|
set_idnum('.', is_asm ? IS_ID : 0);
|
2017-02-13 20:23:55 +03:00
|
|
|
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
cstr_new(&cstr);
|
|
|
|
cstr_cat(&cstr, "\"", -1);
|
|
|
|
cstr_cat(&cstr, file->filename, -1);
|
|
|
|
cstr_cat(&cstr, "\"", 0);
|
|
|
|
tcc_define_symbol(s1, "__BASE_FILE__", cstr.data);
|
|
|
|
|
|
|
|
cstr_reset(&cstr);
|
|
|
|
for (i = 0; i < s1->nb_cmd_include_files; i++) {
|
|
|
|
cstr_cat(&cstr, "#include \"", -1);
|
|
|
|
cstr_cat(&cstr, s1->cmd_include_files[i], -1);
|
|
|
|
cstr_cat(&cstr, "\"\n", -1);
|
|
|
|
}
|
|
|
|
if (cstr.size) {
|
2016-06-27 17:40:00 +03:00
|
|
|
*s1->include_stack_ptr++ = file;
|
|
|
|
tcc_open_bf(s1, "<command line>", cstr.size);
|
|
|
|
memcpy(file->buffer, cstr.data, cstr.size);
|
|
|
|
}
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
cstr_free(&cstr);
|
2017-07-20 23:21:27 +03:00
|
|
|
|
|
|
|
if (is_asm)
|
|
|
|
tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
|
|
|
|
|
|
|
|
parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0;
|
|
|
|
tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup from error/setjmp */
|
|
|
|
ST_FUNC void preprocess_end(TCCState *s1)
|
|
|
|
{
|
|
|
|
while (macro_stack)
|
|
|
|
end_macro();
|
|
|
|
macro_ptr = NULL;
|
2009-05-05 22:30:39 +04:00
|
|
|
}
|
|
|
|
|
2016-10-18 00:24:01 +03:00
|
|
|
ST_FUNC void tccpp_new(TCCState *s)
|
2009-05-05 22:30:39 +04:00
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
const char *p, *r;
|
|
|
|
|
2016-10-18 00:24:01 +03:00
|
|
|
/* might be used in error() before preprocess_start() */
|
|
|
|
s->include_stack_ptr = s->include_stack;
|
2017-07-20 23:21:27 +03:00
|
|
|
s->ppfp = stdout;
|
2016-10-18 00:24:01 +03:00
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
/* init isid table */
|
2016-04-05 13:05:09 +03:00
|
|
|
for(i = CH_EOF; i<128; i++)
|
2016-08-25 17:40:50 +03:00
|
|
|
set_idnum(i,
|
|
|
|
is_space(i) ? IS_SPC
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
: isid(i) ? IS_ID
|
|
|
|
: isnum(i) ? IS_NUM
|
2016-08-25 17:40:50 +03:00
|
|
|
: 0);
|
2015-04-20 03:44:08 +03:00
|
|
|
|
2016-04-05 13:05:09 +03:00
|
|
|
for(i = 128; i<256; i++)
|
2016-08-25 17:40:50 +03:00
|
|
|
set_idnum(i, IS_ID);
|
2016-04-05 13:05:09 +03:00
|
|
|
|
2016-04-17 16:22:50 +03:00
|
|
|
/* init allocators */
|
|
|
|
tal_new(&toksym_alloc, TOKSYM_TAL_LIMIT, TOKSYM_TAL_SIZE);
|
|
|
|
tal_new(&tokstr_alloc, TOKSTR_TAL_LIMIT, TOKSTR_TAL_SIZE);
|
|
|
|
tal_new(&cstr_alloc, CSTR_TAL_LIMIT, CSTR_TAL_SIZE);
|
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
memset(hash_ident, 0, TOK_HASH_SIZE * sizeof(TokenSym *));
|
2016-04-17 16:37:23 +03:00
|
|
|
cstr_new(&cstr_buf);
|
|
|
|
cstr_realloc(&cstr_buf, STRING_MAX_SIZE);
|
|
|
|
tok_str_new(&tokstr_buf);
|
|
|
|
tok_str_realloc(&tokstr_buf, TOKSTR_MAX_SIZE);
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
tok_ident = TOK_IDENT;
|
|
|
|
p = tcc_keywords;
|
|
|
|
while (*p) {
|
|
|
|
r = p;
|
|
|
|
for(;;) {
|
|
|
|
c = *r++;
|
|
|
|
if (c == '\0')
|
|
|
|
break;
|
|
|
|
}
|
2011-05-16 16:15:32 +04:00
|
|
|
tok_alloc(p, r - p - 1);
|
2009-05-05 22:30:39 +04:00
|
|
|
p = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 00:24:01 +03:00
|
|
|
ST_FUNC void tccpp_delete(TCCState *s)
|
2015-03-03 14:19:14 +03:00
|
|
|
{
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
int i, n;
|
2015-03-03 14:19:14 +03:00
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* free -D and compiler defines */
|
|
|
|
free_defines(NULL);
|
2015-03-03 14:19:14 +03:00
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* free tokens */
|
|
|
|
n = tok_ident - TOK_IDENT;
|
|
|
|
for(i = 0; i < n; i++)
|
2016-04-17 16:22:50 +03:00
|
|
|
tal_free(toksym_alloc, table_ident[i]);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
tcc_free(table_ident);
|
|
|
|
table_ident = NULL;
|
2016-04-17 16:37:23 +03:00
|
|
|
|
|
|
|
/* free static buffers */
|
|
|
|
cstr_free(&tokcstr);
|
|
|
|
cstr_free(&cstr_buf);
|
2016-12-20 07:38:44 +03:00
|
|
|
cstr_free(¯o_equal_buf);
|
2016-11-11 22:25:13 +03:00
|
|
|
tok_str_free_str(tokstr_buf.str);
|
2016-04-17 16:22:50 +03:00
|
|
|
|
|
|
|
/* free allocators */
|
|
|
|
tal_delete(toksym_alloc);
|
|
|
|
toksym_alloc = NULL;
|
|
|
|
tal_delete(tokstr_alloc);
|
|
|
|
tokstr_alloc = NULL;
|
|
|
|
tal_delete(cstr_alloc);
|
|
|
|
cstr_alloc = NULL;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
}
|
|
|
|
|
2016-05-05 15:12:53 +03:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* tcc -E [-P[1]] [-dD} support */
|
|
|
|
|
|
|
|
static void tok_print(const char *msg, const int *str)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
2017-07-20 23:21:27 +03:00
|
|
|
int t, s = 0;
|
2016-05-05 15:12:53 +03:00
|
|
|
CValue cval;
|
|
|
|
|
|
|
|
fp = tcc_state->ppfp;
|
2017-07-20 23:21:27 +03:00
|
|
|
fprintf(fp, "%s", msg);
|
2016-05-05 15:12:53 +03:00
|
|
|
while (str) {
|
|
|
|
TOK_GET(&t, &str, &cval);
|
|
|
|
if (!t)
|
|
|
|
break;
|
2017-07-20 23:21:27 +03:00
|
|
|
fprintf(fp, " %s" + s, get_tok_str(t, &cval)), s = 1;
|
2016-05-05 15:12:53 +03:00
|
|
|
}
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pp_line(TCCState *s1, BufferedFile *f, int level)
|
|
|
|
{
|
|
|
|
int d = f->line_num - f->line_ref;
|
2016-10-09 21:33:14 +03:00
|
|
|
|
2016-05-05 15:12:53 +03:00
|
|
|
if (s1->dflag & 4)
|
|
|
|
return;
|
2016-10-09 21:33:14 +03:00
|
|
|
|
2016-05-05 15:12:53 +03:00
|
|
|
if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) {
|
2016-10-09 21:33:14 +03:00
|
|
|
;
|
2016-05-05 15:12:53 +03:00
|
|
|
} else if (level == 0 && f->line_ref && d < 8) {
|
|
|
|
while (d > 0)
|
|
|
|
fputs("\n", s1->ppfp), --d;
|
|
|
|
} else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) {
|
|
|
|
fprintf(s1->ppfp, "#line %d \"%s\"\n", f->line_num, f->filename);
|
|
|
|
} else {
|
|
|
|
fprintf(s1->ppfp, "# %d \"%s\"%s\n", f->line_num, f->filename,
|
|
|
|
level > 0 ? " 1" : level < 0 ? " 2" : "");
|
|
|
|
}
|
|
|
|
f->line_ref = f->line_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void define_print(TCCState *s1, int v)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
s = define_find(v);
|
|
|
|
if (NULL == s || NULL == s->d)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fp = s1->ppfp;
|
|
|
|
fprintf(fp, "#define %s", get_tok_str(v, NULL));
|
|
|
|
if (s->type.t == MACRO_FUNC) {
|
|
|
|
Sym *a = s->next;
|
|
|
|
fprintf(fp,"(");
|
|
|
|
if (a)
|
|
|
|
for (;;) {
|
|
|
|
fprintf(fp,"%s", get_tok_str(a->v & ~SYM_FIELD, NULL));
|
|
|
|
if (!(a = a->next))
|
|
|
|
break;
|
|
|
|
fprintf(fp,",");
|
|
|
|
}
|
|
|
|
fprintf(fp,")");
|
|
|
|
}
|
|
|
|
tok_print("", s->d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pp_debug_defines(TCCState *s1)
|
|
|
|
{
|
|
|
|
int v, t;
|
|
|
|
const char *vs;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
t = pp_debug_tok;
|
|
|
|
if (t == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
file->line_num--;
|
|
|
|
pp_line(s1, file, 0);
|
|
|
|
file->line_ref = ++file->line_num;
|
|
|
|
|
|
|
|
fp = s1->ppfp;
|
|
|
|
v = pp_debug_symv;
|
|
|
|
vs = get_tok_str(v, NULL);
|
|
|
|
if (t == TOK_DEFINE) {
|
|
|
|
define_print(s1, v);
|
|
|
|
} else if (t == TOK_UNDEF) {
|
|
|
|
fprintf(fp, "#undef %s\n", vs);
|
|
|
|
} else if (t == TOK_push_macro) {
|
|
|
|
fprintf(fp, "#pragma push_macro(\"%s\")\n", vs);
|
|
|
|
} else if (t == TOK_pop_macro) {
|
|
|
|
fprintf(fp, "#pragma pop_macro(\"%s\")\n", vs);
|
|
|
|
}
|
|
|
|
pp_debug_tok = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pp_debug_builtins(TCCState *s1)
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
for (v = TOK_IDENT; v < tok_ident; ++v)
|
|
|
|
define_print(s1, v);
|
|
|
|
}
|
|
|
|
|
2016-10-01 22:52:11 +03:00
|
|
|
/* Add a space between tokens a and b to avoid unwanted textual pasting */
|
|
|
|
static int pp_need_space(int a, int b)
|
2016-05-04 23:37:11 +03:00
|
|
|
{
|
2016-10-01 22:52:11 +03:00
|
|
|
return 'E' == a ? '+' == b || '-' == b
|
|
|
|
: '+' == a ? TOK_INC == b || '+' == b
|
|
|
|
: '-' == a ? TOK_DEC == b || '-' == b
|
|
|
|
: a >= TOK_IDENT ? b >= TOK_IDENT
|
2017-07-09 05:30:36 +03:00
|
|
|
: a == TOK_PPNUM ? b >= TOK_IDENT
|
2016-10-01 22:52:11 +03:00
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maybe hex like 0x1e */
|
|
|
|
static int pp_check_he0xE(int t, const char *p)
|
|
|
|
{
|
|
|
|
if (t == TOK_PPNUM && toup(strchr(p, 0)[-1]) == 'E')
|
|
|
|
return 'E';
|
|
|
|
return t;
|
2016-05-04 23:37:11 +03:00
|
|
|
}
|
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
/* Preprocess the current file */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int tcc_preprocess(TCCState *s1)
|
2009-05-05 22:30:39 +04:00
|
|
|
{
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
BufferedFile **iptr;
|
|
|
|
int token_seen, spcs, level;
|
2016-10-01 22:52:11 +03:00
|
|
|
const char *p;
|
2017-07-20 23:21:27 +03:00
|
|
|
char white[400];
|
2009-05-05 22:30:39 +04:00
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
parse_flags = PARSE_FLAG_PREPROCESS
|
|
|
|
| (parse_flags & PARSE_FLAG_ASM_FILE)
|
|
|
|
| PARSE_FLAG_LINEFEED
|
|
|
|
| PARSE_FLAG_SPACES
|
|
|
|
| PARSE_FLAG_ACCEPT_STRAYS
|
|
|
|
;
|
2016-05-12 11:25:50 +03:00
|
|
|
/* Credits to Fabrice Bellard's initial revision to demonstrate its
|
|
|
|
capability to compile and run itself, provided all numbers are
|
|
|
|
given as decimals. tcc -E -P10 will do. */
|
2017-03-28 09:51:39 +03:00
|
|
|
if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_P10)
|
2016-05-12 11:25:50 +03:00
|
|
|
parse_flags |= PARSE_FLAG_TOK_NUM, s1->Pflag = 1;
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
#ifdef PP_BENCH
|
2016-05-05 15:12:53 +03:00
|
|
|
/* for PP benchmarks */
|
2016-05-18 21:30:09 +03:00
|
|
|
do next(); while (tok != TOK_EOF);
|
|
|
|
return 0;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
#endif
|
|
|
|
|
2016-05-05 15:12:53 +03:00
|
|
|
if (s1->dflag & 1) {
|
|
|
|
pp_debug_builtins(s1);
|
|
|
|
s1->dflag &= ~1;
|
|
|
|
}
|
|
|
|
|
|
|
|
token_seen = TOK_LINEFEED, spcs = 0;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
pp_line(s1, file, 0);
|
2009-05-05 22:30:39 +04:00
|
|
|
for (;;) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
iptr = s1->include_stack_ptr;
|
2009-05-05 22:30:39 +04:00
|
|
|
next();
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
if (tok == TOK_EOF)
|
2009-05-05 22:30:39 +04:00
|
|
|
break;
|
2017-07-20 23:21:27 +03:00
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
level = s1->include_stack_ptr - iptr;
|
|
|
|
if (level) {
|
|
|
|
if (level > 0)
|
|
|
|
pp_line(s1, *iptr, 0);
|
|
|
|
pp_line(s1, file, level);
|
|
|
|
}
|
2017-07-20 23:21:27 +03:00
|
|
|
if (s1->dflag & 7) {
|
2016-05-05 15:12:53 +03:00
|
|
|
pp_debug_defines(s1);
|
|
|
|
if (s1->dflag & 4)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:21:27 +03:00
|
|
|
if (is_space(tok)) {
|
|
|
|
if (spcs < sizeof white - 1)
|
|
|
|
white[spcs++] = tok;
|
|
|
|
continue;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} else if (tok == TOK_LINEFEED) {
|
2017-07-20 23:21:27 +03:00
|
|
|
spcs = 0;
|
|
|
|
if (token_seen == TOK_LINEFEED)
|
|
|
|
continue;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
++file->line_ref;
|
2017-07-20 23:21:27 +03:00
|
|
|
} else if (token_seen == TOK_LINEFEED) {
|
|
|
|
pp_line(s1, file, 0);
|
|
|
|
} else if (spcs == 0 && pp_need_space(token_seen, tok)) {
|
|
|
|
white[spcs++] = ' ';
|
2009-05-05 22:30:39 +04:00
|
|
|
}
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
|
2017-07-20 23:21:27 +03:00
|
|
|
white[spcs] = 0, fputs(white, s1->ppfp), spcs = 0;
|
2016-10-01 22:52:11 +03:00
|
|
|
fputs(p = get_tok_str(tok, &tokc), s1->ppfp);
|
2017-07-20 23:21:27 +03:00
|
|
|
token_seen = pp_check_he0xE(tok, p);
|
2016-05-05 15:12:53 +03:00
|
|
|
}
|
|
|
|
return 0;
|
2016-04-13 14:32:51 +03:00
|
|
|
}
|
|
|
|
|
2016-05-05 15:12:53 +03:00
|
|
|
/* ------------------------------------------------------------------------- */
|