Commit graph

4405 commits

Author SHA1 Message Date
Bill Currie
ab34cb7df4 [qfcc] Accept @id as one token in macro bodies
I'm undecided about @ in macro names, but treating @id as one token in
the body is necessary with the single-pass tokenizing. Fixes an infinite
macro expansion loop in vecaddr.r (`#define dot @dot`), but that's
really only a bandaid for *that* issue as there are plenty of other
cases where macros will loop.
2023-10-30 13:28:45 +09:00
Bill Currie
071e529b0e [qfcc] Implement parsing side of ... macros
Expansion is not yet implemented (need __VA_OPT__ and __VA_ARGS__), but
this gets scheme compiling.
2023-10-30 13:28:01 +09:00
Bill Currie
eab561f279 [qfcc] Handle * strings in /* */ comments correctly
The *s were consuming the final star in */, so fancy comments were
breaking.
2023-10-30 13:22:57 +09:00
Bill Currie
61948b2469 [qfcc] Rework function-type macro expansion
It turns out that the recursive lexing was over-complicated as the
tokens for nested macros need to come from the expanded stream, not the
raw input stream.
2023-10-30 00:41:06 +09:00
Bill Currie
243a3de629 [qfcc] Grab undef id early
I'm unsure of the small string handling is a premature optimization, but
when most tokens are small...
2023-10-29 18:23:39 +09:00
Bill Currie
e402d0fa21 [qfcc] Implement command-line macro definitions
This takes care of __QFCC__ not being defined
2023-10-29 18:19:03 +09:00
Bill Currie
dfd57ed74f [qfcc] Generate dependencies only if not using cpp
cpp does this for us so the double-generation is redundant (and
currently wrong anyway with things like <built-in> and <command-line>
getting into the list of dependencies).
2023-10-29 14:00:37 +09:00
Bill Currie
6fa1d9caa2 [qfcc] Handle q-string in preprocessor expressions
This fixes line directives not parsing as they were getting c-string but
the preprocessor parser wasn't expecting them (and I suspect it
shouldn't).
2023-10-29 13:59:17 +09:00
Bill Currie
0990401a87 [qfcc] Get vkgen compiling
Or at least mostly so. The __QFCC__ define isn't visible, and it seems
undef might not be working properly (ruamoko/lib/types.r doesn't
compile). Of course, there's still the issue of whether it's compiling
correctly.
2023-10-28 23:51:12 +09:00
Bill Currie
c6ab5cd0ec [qfcc] Use generated tag for reporting errors
Avoids a segfault when the supplied tag is null (often the case when
qfcc defines the struct). Avoids a segfault when other errors cause
problems.
2023-10-28 08:45:27 +09:00
Bill Currie
b52b803c2a [qfcc] Add a #notice directive
Haven't got things working properly and I'm already extending the
preprocessor :P. It proved handy for debugging :)
2023-10-28 08:43:17 +09:00
Bill Currie
80c9132199 [qfcc] Treat all identifiers as undefined
If ID gets to the preprocessor parser in expressions, the ID is not
defined because if it was defined, it would have been expanded. Thus,
all IDs are 0.
2023-10-27 17:27:52 +09:00
Bill Currie
4214b90de3 [qfcc] Handle macros in preprocessor directors
I had forgotten that ids in preprocessor directives had a different
token type.
2023-10-27 17:27:02 +09:00
Bill Currie
733d242552 [qfcc] Don't try to define macros in suppressed code
Doing so kind of defeats the purpose of suppressing code.
2023-10-27 17:26:00 +09:00
Bill Currie
3bd391d01f [qfcc] Handle h-string and q-string only in #include
And #embed, though that's not implemented yet. Comparisons eating
multiple lines results in some rather interesting errors.
2023-10-27 17:24:54 +09:00
Bill Currie
823a9bd8d9 [qfcc] Implement dependency tracking generation
And now an issue with the vulkan headers shows up. Still, progress :)
2023-10-26 22:20:19 +09:00
Bill Currie
ae3a6c8b90 [qfcc] Move the dependency option handling to cpp.c
This cleans up options.c a little more and prepares for implementing
dependency tracking with the built-in preprocessor.
2023-10-26 21:21:00 +09:00
Bill Currie
92832a3b2c [qfcc] Improve handling of suppressed and continued lines
Now vkalias.r compiles with the builtin preprocessor. However, the build
fails due to the automatic dependency files not being generated.
2023-10-26 20:31:54 +09:00
Bill Currie
47c60f2bbf [qfcc] Handle quote includes better
The path for the current file wasn't being set correctly at startup and
"error: success" never makes much sense.
2023-10-26 20:28:43 +09:00
Bill Currie
ffb2514e75 [qfcc] Implement #include and search paths
Other than some trouble with line comments and continuation lines, it
seems to work nicely.
2023-10-25 21:07:50 +09:00
Bill Currie
f1f0a4a260 [qfcc] Update line directive handling
In addition to cleaning up the old flex line rules, this improves
handling of the '# num "file" flags' from cpp to at least parse the
additional flags (support for the system header flag might come later,
but I doubt the extern-c flag will have much meaning).

QuakePascal has lost its line directive handling (no errors, but dead
rules) for now. Eventually the lexers will be merged.
2023-10-25 12:22:33 +09:00
Bill Currie
717be4a12d [qfcc] Update pragma handling for the preprocessor
This removes the now redundant flex rules, though does spread
preprocess-only checks around a little more.
2023-10-25 09:25:00 +09:00
Bill Currie
31ee99ee0a [qfcc] Record identifiers in macros as rua_id
This ensures they always get recognized as identifiers in later stages.
2023-10-25 01:09:36 +09:00
Bill Currie
9dda656e1b [qfcc] Don't create macro params struct for object macros
Fixes object macros not expanding.
2023-10-25 00:52:36 +09:00
Bill Currie
4e922008eb [qfcc] Collect all arg tokens for stringification
Now all the tokens in the arg go into the one string.
2023-10-25 00:25:41 +09:00
Bill Currie
dc598c58b5 [qfcc] Record and expand macro arguments
Stringizing doesn't work correctly (stringizes only the first token, not
the whole argument), but things seems to work otherwise.
2023-10-24 23:32:13 +09:00
Bill Currie
9b717c2e1e [qfcc] Strip leading white space from message text
This fixes the missing text in #warning and #error messages.
2023-10-24 22:18:23 +09:00
Bill Currie
e60f538664 [qfcc] Implement function-type macro argument parsing
The arguments are not recorded yet, but argument parsing can consume the
whole file if the closing ) is missing (same as gcc).
2023-10-24 22:06:01 +09:00
Bill Currie
4b36817592 [qfcc] Silence report function for preprocessor-only
The preprocessor doesn't know what a function is and the main parser
isn't run, so the errors are always "At top level".
2023-10-24 22:01:03 +09:00
Bill Currie
2849ed06cd [qfcc] Skip converting preprocessor in macros
This fixes a segfault when parsing code resulting from expanded macros
with numbers in them.
2023-10-24 21:51:57 +09:00
Bill Currie
dd17e45052 [qfcc] Use a prefix for qc tokens
I had wanted to do this earlier but shied away from the large edit. Now
it became more necessary (and will become even more necessary when I get
to the glsl front-end).
2023-10-24 19:50:31 +09:00
Bill Currie
3307ef77ec [qfcc] Implement object-type macro expansion
Really, function-type macros expand too, but incorrectly as the
parameters are not parsed and thus not expanded, but this gets the basic
handling implemented, including # and ## processing.
2023-10-24 15:58:37 +09:00
Bill Currie
45e61544bb [qfcc] Improve handling of spaces in macro definitions
Avoids space tokens on either side of ## and after #
2023-10-24 14:17:05 +09:00
Bill Currie
5590ea5b75 [qfcc] Delay conversion of preprocessor tokens
Converting ID and char constants too early resulted in poor handling of
keywords and spurious diagnostics about multi-byte character constants,
particularly with -E (preprocess-only)
2023-10-24 13:23:06 +09:00
Bill Currie
e71816f9c4 [qfcc] Implement preprocessor-only output
Currently only to stdout, but it makes debugging preprocessing much
easier.
2023-10-23 22:28:03 +09:00
Bill Currie
8341f48f9d [qfcc] Implement #undef
That was pleasantly easy :)
2023-10-23 19:00:37 +09:00
Bill Currie
5cab587207 [qfcc] Implement macro recording and defined()
So far, very consistent with gcc's cpp from my limited testing, though
some error handling may be a little different.
2023-10-23 19:00:30 +09:00
Bill Currie
5794c68bda [qfcc] Implement basic conditional compilation
Just #if, #else and #endif for now. However, much of the preprocessor
parsing working minus the semantics (expressions do work, though).
2023-10-23 00:10:25 +09:00
Bill Currie
df3ffaaf0f [qfcc] Speed up comment processing significantly
Somewhere between 1.5x and 2x as fast (for 17MB of comments).
2023-10-21 11:35:58 +09:00
Bill Currie
2694aa4f1f [qfcc] Use flex's state stack
This will make handling preprocessor directives much easier.
2023-10-21 10:12:41 +09:00
Bill Currie
76cf0bf008 [qfcc] Clean up the rules a little
Mostly white space, but a little more consistency in handling and remove
the use of REJECT (which does actually seem to make a difference, but it
could be just noise).
2023-10-21 07:22:05 +09:00
Bill Currie
67642e5119 [qfcc] Clean up string lexing for preprocessing 2023-10-21 01:15:40 +09:00
Bill Currie
d800eea1db [qfcc] Use preprocessor numbers for literals
As far as I can tell, the preprocessor numbers conform with C23 except
for a couple of extensions (both ' and _ work for digit separators, and
d/D work for explicit doubles (since qfcc current defaults to float
instead of double)). This massively cleaned up the numeric rules and
even took care of some UB in the vector parsing code (I'm not sure which
is more surprising: that I didn't see it at the time, or that it was
blindingly obvious now).
2023-10-20 21:42:47 +09:00
Bill Currie
b973c5a738 [qfcc] Support implicit typing for new_value_expr
This makes creating implicitly type vector literals much easier.
2023-10-20 20:51:19 +09:00
Bill Currie
93247163b3 [qfcc] Create a preprocessor token type
This will be used for unifying preprocessing and parsing, the idea being
that the tokens will be recorded for later expansion via macros, without
the need to retokenize.
2023-10-20 20:39:13 +09:00
Bill Currie
28478befa6 Adjust lex files to work with updated git flex
While my modified version is needed to actually avoid warnings (vs
upstream git flex), the files still work with debian's flex (with no
warnings). I needed to update (and fix) flex so the lexer line numbers
would be correct.
2023-10-19 23:10:27 +09:00
Bill Currie
76c92fada0 [qfcc] Clean up implicit int exprs
Hides the const-cast away where the expression is created. Just cleaner
in general.
2023-10-19 22:52:17 +09:00
Bill Currie
12e53737ba [qfcc] Switch the parsers and lexers to full reentrant
This should make it more feasible to implement a preprocessor, and
definitely cleans some things up a little bit.
2023-10-12 23:49:37 +09:00
Bill Currie
3f0e793747 [qfcc] Set up to use bison locations
The improved location tracking isn't used yet, but was fairly invasive
on the bison-flex api.

It also cleans up some of the ancient workarounds for bad flex cores.
2023-10-08 11:02:49 +09:00
Bill Currie
a42f0a6bf4 [qfcc] Handle continuation lines in the lexer
It turns out I need to create my own cpp in order to handle glsl's
directives. I've decided to make a unified lexer, and continuation lines
seemed a good place to start.
2023-10-08 01:50:06 +09:00