aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
Commit message (Collapse)AuthorAgeFilesLines
* Clean up lots of rogue tabs.gus knight2015-07-271-4/+4
| | | | | | Still some more tabs to be taken care of. arm-gen.c and tcccoff.c have so many style issues that I'm just going to throw clang-format at them.
* Trim trailing spaces everywhere.gus knight2015-07-271-36/+36
|
* redo of the -dD optionseyko2015-05-131-60/+100
| | | | | | | | functionality was broken some time ago and was removed by the "tccpp: fix issues, add tests" fix: LINE_MACRO_OUTPUT_FORMAT_NONE in pp_line() means: output '\n' and not "don't output at all"
* minor pp optimizationsseyko2015-05-121-3/+0
| | | | | | * remove free_defines() from tcc_preprocess() all cleanup will be done in tcc_delete * move a preprocessor file closing to tcc_delete too
* SYMBOL_NAME_LABEL(X) X##:seyko2015-05-121-1/+3
| | | | | | | | | | In the linux kernel sources: #ifdef __STDC__ #define SYMBOL_NAME_LABEL(X) X##: #else #define SYMBOL_NAME_LABEL(X) X/**/: #endif tcc is a STDC compiler and must handle 'X##:' case.
* tccpp: fix issues, add testsgrischka2015-05-091-711/+680
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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)
* Mostly revert "tccpp.c: minor fix I'd accidentally not committed"Philip2015-05-021-40/+17
| | | | | | | This reverts commit 27ec4f67a33a354c8f377dd4a5b42491c2b43beb. Sorry about that, I included changes which are still being tested, by accident.
* tccpp.c: minor fix I'd accidentally not committedPhilip2015-05-021-19/+43
| | | | Sorry about that. This should definitely fix Sergey's issue.
* minor fixPhilip2015-05-021-1/+2
| | | | | | | Fixes the issue reported by Sergey at http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00007.html I hope.
* tccpp.c: unterminated macro argument error messagePhilip2015-05-021-0/+2
| | | | | | | | #define a(x) x a(( would produce "error: , expected" when what's actually expected is a ')'.
* tccpp.c: fix GNU comma handlingPhilip2015-05-021-19/+34
| | | | | | | | | This requires moving TOK_PLCHLDR handling, but the new logic should make things easier even if (when?) GNU comma handling is removed. (Somewhat confusingly, GCC no longer supports GNU commas. See http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html for a description of past and current GCC behaviour.)
* tccpp.c: restore whitespace after failed macroPhilip2015-05-021-12/+35
| | | | | | | | | This fixes test7 described in: http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html Note that the current code still adds excessive forced blank characters to its output, so this patch might not change visible behaviour.
* tccpp.c: correct # stringificationPhilip2015-05-021-4/+23
| | | | | | | | | | | | | | | | | | 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
* tccpp.c: parse flag to accept stray \Philip2015-05-021-2/+8
| | | | | | | | | | | | | | | | | | | This adds a PARSE_FLAG_ACCEPT_STRAYS parse flag to accept stray backslashes in the source code, and uses it for pure preprocessing. For absolutely correct behaviour of # stringification, we need to use this flag when parsing macro definitions and in macro arguments, as well; this patch does not yet do so. The test case for that is something like #define STRINGIFY2(x) #x #define STRINGIFY(x) STRINGIFY2(x) STRINGIFY(\n) which should produce "\n", not a parse error or "\\n". See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
* tccpp.c: fix endless loopPhilip2015-05-021-2/+3
| | | | | | | | | | Perhaps a better fix would be to ensure tok is set to TOK_EOF rather than 0 at the end of a macro stream. This partially fixes test2 of the examples given in: http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html It's still failing, but at least it's not running out of memory now.
* tccpp.c: reset spc after macro_subst_tok()Philip2015-05-021-0/+1
| | | | | | | This bug doesn't seem to affect anything currently, but does interfere with miscellaneous tccpp.c fixes for the test cases described here: http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
* tccpp.c: fix ##-in-macros logicPhilip2015-05-021-2/+2
| | | | | | | | | | | | | The old code had an inverted condition, so #define a(b)## b would be accepted while #define a(b,c) b ## ## c would be rejected with the confusing error message "'##' invalid at start of macro".
* tccpp.c: fix empty stringifyPhilip2015-05-011-1/+1
| | | | | | | | #define STRINGIFY2(x) #x #define STRINGIFY(x) STRINGIFY2(x) STRINGIFY() should produce "", not "\301".
* fix a potential end-of-buffer issue in tccelf.cPhilip2015-04-301-1/+1
| | | | | also read characters one at a time when PARSE_DEBUG is set; after this patch, things seem to work with that.
* fix end-of-buffer error in tccpp.cPhilip2015-04-301-1/+1
| | | | | | | | | | | | Quick fix for http://lists.nongnu.org/archive/html/tinycc-devel/2015-04/msg00160.html. I don't fully understand the intended semantics of when file->buf_ptr[0] is valid, but the rest of the code doesn't have any obvious spots with the same bug. Feel free to revert this if I'm mistaken or we need to discuss this change further.
* replace PARSE_FLAG_ASM_COMMENTS with PARSE_FLAG_ASM_FILEseyko2015-04-271-7/+7
| | | | | after "assign PARSE_FLAG_ASM_COMMENTS only for asm files" functions of this flags are identical
* fixes for "tcc -E -dD"seyko2015-04-271-2/+16
| | | | | | * print "// #pragma push_macro(XXX)" * keep output line numbers in sync with source (don't output \n in printf)
* preprocess: "assign PARSE_FLAG_ASM_COMMENTS only for asm files"seyko2015-04-271-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | resolve a problem with the following test.c program, tcc -E test.c #ifdef _XOPEN_SOURCE # define __USE_XOPEN 1 # if (_XOPEN_SOURCE - 0) >= 500 # define __USE_XOPEN_EXTENDED 1 # define __USE_UNIX98 1 # undef _LARGEFILE_SOURCE # define _LARGEFILE_SOURCE 1 # if (_XOPEN_SOURCE - 0) >= 600 # define __USE_XOPEN2K 1 # undef __USE_ISOC99 # define __USE_ISOC99 1 # endif # else # ifdef _XOPEN_SOURCE_EXTENDED # define __USE_XOPEN_EXTENDED 1 # endif # endif #endif int main() {} // # 17 "aaa.c" // aaa.c:17: error: #endif without matching #if
* tccpp: alternative #pragma push/pop_macrogrischka2015-04-231-11/+36
| | | | | | | using next_nomacro() so that for example #define push_macro foobar does not affect how the pragma works (same behavior as gcc, albeit not MS's cl).
* Revert "* and #pragma pop_macro("macro_name")"grischka2015-04-231-32/+0
| | | | | | | | | | | | - pop_macro incorrect with initially undefined macro - horrible implementation (tcc_open_bf) - crashes eventually (abuse of Sym->prev_tok) - the (unrelated) asm_label part is the opposite of a fix (Despite of its name this variable has nothing to do with the built-in assembler) This reverts commit 0c8447db7970813292a8be74ee50e49091be5d15.
* "#pragma once" implementationseyko2015-04-211-1/+3
|
* * and #pragma pop_macro("macro_name")seyko2015-04-211-0/+34
| | | | | | | | | | * give warning if pragma is unknown for tcc * don't free asm_label in sym_free(), it's a job of the asm_free_labels(). The above pragmas are used in the mingw headers. Thise pragmas are implemented in gcc-4.5+ and current clang.
* -fdollar-in-identifiers addonseyko2015-04-201-7/+11
| | | | | | | * disable a -fdollar-in-identifiers option in assembler files * a test is added This is a patch addon from Daniel Holden.
* clarify error message when library not foundseyko2015-04-161-2/+1
| | | | | a prior error message: cannot find 'program_resolve_lib' after a patch: cannot find library 'libprogram_resolve_lib'
* implement #pragma comment(lib,...)Steven G. Messervey2015-04-151-0/+27
|
* Revert "implement #pragma comment(lib,...)"Steven G. Messervey2015-04-151-38/+0
| | | | | | This reverts commit 8615bb40fb39bf7435462ca54cbbc24aaecae502. Reverting as it breaks on MinGW targets
* implement #pragma comment(lib,...)Steven G. Messervey2015-04-151-0/+38
|
* -fdollar-in-identifiers switch which enables '$' in identifiersseyko2015-04-121-4/+8
| | | | | | | | | | library Cello: http://libcello.org/ which uses `$` and several variations of as macros. There is also RayLanguage which also uses it as a macro for a kind of ObjC style message passing: https://github.com/kojiba/RayLanguage This is a patch from Daniel Holden.
* fix a preprocessor for .Sseyko2015-04-101-3/+16
| | | | | | Lets assume that in *.S files a preprocessor directive follow '#' char w/o spaces between. Otherwise there is too many problems with the content of the comments.
* fix a preprocessor for .Sseyko2015-04-101-2/+6
| | | | | A test program (tcc -E test.S): # .. or else we have a high. This is a test.S
* fix a preprocessor for .Sseyko2015-04-101-17/+13
| | | | | | | | | | | | | | | | | | | | | | | | * tell a right line number in error message if a #line directive is wrong * don't print an error message if we preprocess a .S file and #line directive is wrong. This is the case of the # 4026 bytes comment in *.S file. * preprocess_skip: skip a line with if (parse_flags & PARSE_FLAG_ASM_COMMENTS) p = parse_line_comment(p); if line starts with # and a preprocessor command not found. A test program: #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) # This repeats until either a device doesn't exist, or until #endif * remove a second definition of the TOK_FLAG_* and PARSE_FLAG_* from the tccpp.c
* fix to allow build tcc by build-tcc.batseyko2015-03-191-1/+1
| | | | | move call to print_defines() from tcc.c to the libtcc.c define a print_defines() as a ST_FUNC
* tcc_free(table_ident) in preprocess_new() if table_ident != NULLseyko2015-03-031-1/+4
|
* Add a debug info when a #line directive is handled.seyko2015-03-031-0/+2
| | | | | The problem was: a debug info for the file which contain a #line directive (for example a preprocessed one) was wrong.
* pp-many-files: don't drop a preprocessor defines when tcc going to ↵seyko2015-03-031-4/+0
| | | | | | | | | | | | | | preprocess a next file in the same pass like tcc -E one.c two.c three.c -o combined.i This will allow to speed up a compilation process by using a commamd like tcc -E *.c | tcc -o program.exe -xc - It looks that multi-times initialization don't affect anything. Only call to the free_defines(define_start) in tcc_preprocess() is removed in assumption that free_defines(NULL) in tcc_cleanup() will free all defines.
* A gcc preprocessor option -dD addedseyko2015-03-031-22/+69
| | | | | | | | | With this option on a defines are included into the output (inside comments). This will allow to debug a problems like: In file included from math.c:8: In file included from /usr/include/math.h:43: /usr/include/bits/nan.h:52: warning: NAN redefined
* Added a gcc preprocessor options -P, -P1seyko2015-03-031-10/+34
| | | | | | | | | | | tcc -E -P do not output a #line directive, a gcc compatible option tcc -E -P1 don't follow a gcc preprocessor style and do output a standard #line directive. In such case we don't lose a location info when we going to compile a resulting file wtith a compiler not understanding a gnu style line info.
* Move a line_ref variable from tcc_preprocess() function into struct ↵seyko2015-03-031-5/+5
| | | | | | | BufferedFile. This id needed for a right ouput in other places, precisely to calculate a number of empty lines which are waiting to output.
* A preprocessor should Interpret an input line "# NUM FILENAME" as "#line NUM ↵seyko2015-03-031-1/+6
| | | | | | | | | | | FILENAME" A cpp from gcc do this. A test case: tcc -E tccasm.c -o tccasm.i tcc -E tccasm.i -o tccasm.ii After a patch the line numbers in tccasm.ii are the same as in tccasm.i
* The "open a whisky and cut your finger open" patchThomas Preud'homme2015-02-181-34/+41
| | | | Make integer constant parsing C99 compliant
* Fix macro expansion of empty args.Reimar Döffinger2015-01-181-1/+1
| | | | Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
* Fix parsing of binary floating point numberLee Duhem2014-12-151-1/+1
| | | | | | | * tccpp.c (parse_number): `shift' should be 1 while parsing binary floating point number. * tests/tests2/70_floating_point_literals.c: New test cases for floating point number parsing.
* bug:jiang2014-06-291-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ---------------------------------------------------------------------- #define hexCh(c (c >= 10 ? 'a' + c - 10 : '0' + c) hexCh(c); out: jiang@jiang:~/test$ ./tcc -E c4.c # 1 "c4.c" (c >= 10 ? 'a' + c - 10 : '0' + c); --------------------------------------------------------------- #define hexCh(c/3) (c >= 10 ? 'a' + c - 10 : '0' + c) hexCh(c); out: jiang@jiang:~/test$ ./tcc -E c4.c # 1 "c4.c" /3) (c >= 10 ? 'a' + c - 10 : '0' + c); jiang@jiang:~/test$ after patch: # 1 "c4.c" c4.c:1: error: may not appear in macro parameter list: "(" jiang@jiang:~/test$ jiang@jiang:~/test$ ./tcc -E c4.c # 1 "c4.c" c4.c:1: error: may not appear in macro parameter list: "/" jiang@jiang:~/test$
* Improve efficiency of macro concatenationThomas Preud'homme2014-04-141-26/+2
| | | | | | As per grischka comment, always output a space after macro concatenation instead of trying to detect if it's necessary as the current approach has a huge cost.
* Fix preprocessor concat with empty argThomas Preud'homme2014-04-121-5/+37
|