Commit graph

19 commits

Author SHA1 Message Date
Ori Bernstein 0366f11300 cpp: fix mutually recursive macros
Handle cases where parameterless macros expand to each other:

	#define FOO BAR
	#define BAR FOO
	FOO

There were cases where the macros didn't make it into the hidesets,
and we would recurse infinitely. This fixes that.
2020-07-13 18:50:14 -07:00
Ori Bernstein dcf96a006d missing headers rate a FATAL. 2020-04-27 20:13:16 -07:00
Ori Bernstein c6f7989176 copy all the tokens from the tokenrows with a paste.
if we do 'CAT(foo bar, baz quux)', the resulting token row
should have 3 tokens: 'foo', 'barbaz', 'quux'.

tested by jonasa, rebuilding /sys/src, perl, netsurf, and nuklear.
2020-04-26 09:32:42 -07:00
Ori Bernstein d52d7bc121 Backed out changeset 2737b9af622b
not what I wanted to commit.
2020-04-25 10:57:17 -07:00
Ori Bernstein 2de164c51d fix typos in time calculation
the results of the time calculation were garbled -- and
apparently negative on my system when testing, so the
test passed when it shouldn't have.
2020-04-25 10:43:39 -07:00
Ori Bernstein 260d1eaaa7 Make priority array max size explicit.
we were implicitly depending on UMINUS being the last entry
in the operator table -- that's fragile.
2020-04-19 11:26:31 -07:00
Ori Bernstein 15a32f0683 fix cpp operator associativity
We used to treat all operators as right associative,
which means that we would evaluate them incorrecty.
For example, '2 - 1 + 1' would evaluate as '2 - (1 + 2)',
instead of '(2 - 1) + 1'.

This adds an assoc parameter to struct pri, and then uses
it to decide how to evaluate operators.
2020-04-19 11:15:13 -07:00
Ori Bernstein 21831527cb dont overflow the stack
when pushing expressions in cpp, particularly complex ones could
overflow the stack and silently corrupt our data structures. add
checks when we push, and bump the stack size up.
2020-04-19 09:02:21 -07:00
Ori Bernstein 3fe2924287 evaluate #if expressions using vlong
#if expressions are expected to be evaluated using intmax_t,
according to the C99 spec, 6.10.1 p3. On plan9, intmax_t maps
to vlong.
2020-03-23 09:18:44 -07:00
Ori Bernstein 37b86df09f Improve the posix preprocessor.
This fixes token pasting, making it expand when
it should expand, and paste before expansion when
it should paste before expanding.

	#define CAT(a, b) a ## b
	#define BAR	3
	#define FOO	CAT(BAR, 3)
	FOO

now produces 33, while

	#define CAT(a, b) a ## b
	#define EOF	(-1)
	#define NOP(x)	x
	NOP(CAT(foo, EOF))
	CAT(,EOF)
	CAT(,)

produces

	fooEOF
	(-1)
	<empty>

respectively.
2020-03-17 22:03:25 -07:00
Ori Bernstein 94fb8869df Always turn on the -+ flag in cpp
C99 comments have been the default in compilers for something like 20 years
now. This means we don't need to remember to turn it on when porting software,
and gets rid of cryptic errors about unterminated character constants when
someone writes something like:

	// Didn't need to...

We still accept the flag to avoid breaking mkfiles, but we do nothing with it.

This also removes the documentation, since the option does nothing now.
2019-06-18 22:47:15 -07:00
ftrvxmtrx 0930f44feb cmd: remove a bit of unused stuff 2016-11-17 02:59:40 +01:00
cinap_lenrek 917da0089d cpp: handle 4 byte utf sequences (21-bit runes) 2015-09-24 12:23:17 +02:00
cinap_lenrek bba6d26ca2 cpp: fix memory corruption due to input buffer relocation
the dynamic input buffer resize code (fillbuf()) is broken as
the calling code assumes that memory wont relocate. instead
of trying to work out all the cases where this happens, i'm
getting rid of fillbuf() and just read the whole file into
memory in setsource().

the bug could be reproduced with something as simple as:

@{for(i in `{seq 1 10000}){echo $i ', \'; }} | cpp
2015-09-24 05:13:03 +02:00
cinap_lenrek cd9da74cbc cpp: search source file directory first for quoted #include (thanks Ori_B)
foo.c includes bar/bar.h, which includes "baz.h"; it wants bar/baz.h
meanwhile, it also includes meh/quux.h, which includes "baz.h"; it wants meh/baz.h
2015-07-13 00:54:56 +02:00
cinap_lenrek dd318f09cd cpp: fd <= 0 vs. fd < 0 2012-04-20 16:42:12 +02:00
cinap_lenrek 2a65b9d550 cpp: raise macro argument count to 64 (sic) for freetype 2011-12-03 18:29:23 +01:00
Taru Karttunen a9060cc06b Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
Taru Karttunen e5888a1ffd Import sources from 2011-03-30 iso image 2011-03-30 15:46:40 +03:00