Commit graph

408 commits

Author SHA1 Message Date
Bill Currie
1eef2a8b5e [qfcc] Implement type aliasing again
When a type is aliased, the alias has two type chains: the simple type
chain with all other aliases stripped, and the full type chain. There
are still plenty of bugs in it, but having the clean type chain takes
care of the major issue that was in the previous attempt as only the
head of the type-chain needs to be skipped for type comparison.

Most of the bugs are in finding the locations where the head needs to be
skipped.
2020-03-28 12:10:23 +09:00
Bill Currie
653eabfdbf [qfcc] Clean up inconsistent type building idioms 2020-03-27 22:11:18 +09:00
Bill Currie
01cf28e436 [qfcc] Treat C-style function decls as prototypes
This removes the need for extern from the declaration.
2020-03-27 18:08:26 +09:00
Bill Currie
ab3d91f0c3 [qfcc] Clean up simple type checking
All simple type checks are now done using is_* helper functions. This
will help hide the implementation details of the type system from the
rest of the compiler (especially the changes needed for type aliasing).
2020-03-27 15:16:41 +09:00
Bill Currie
7447854d7c [qfcc] Recover from syntax errors in abstract_decl 2020-03-19 11:01:26 +09:00
Bill Currie
e1140d476a [qfcc] Handle syntax errors in method protos 2020-03-15 16:19:45 +09:00
Bill Currie
d150210888 [qfcc] Nuke PAS from orbit
And there was much rejoicing. I hated having to create that opcode.
2020-03-13 21:03:48 +09:00
Bill Currie
8d10b0f4aa [qfcc] Support compound initializers for return 2020-03-13 09:58:52 +09:00
Bill Currie
b6439e8dc1 [qfcc] Support compound init in assignment and params
foo({...}) and bar = {...}
2020-03-11 19:48:25 +09:00
Bill Currie
afd31ed292 [qfcc] Rename cexpr to comma_expr
It took me too long to figure out what cexpr was for.
2020-03-11 16:07:58 +09:00
Bill Currie
d1e83b9d48 [qfcc] Create a compound initializer expression type
This fixes the problem of using the return value of a function as an
element in a compound initializer. The cause of the problem is that
compound initializers were represented by block expressions, but
function calls are contained within block expressions, so def
initialization saw the block expression and thought it was a nested
compound initializer.

Technically, it was a bug in the nested element parsing code in that it
wasn't checking the result value of the block expression, but using a
whole new expression type makes things much cleaner and the work done
paves the way for labeled initializers and compound assignments.
2020-03-11 15:46:57 +09:00
Bill Currie
813319efc2 [qfcc] Implement goto
It's just too useful when used correctly.
2020-03-11 12:53:40 +09:00
Bill Currie
1cd5ea5732 [qfcc] Add support for named labels in statements
Yeah, I've finally decided to implement goto. Limited to function scope
of course.
2020-03-11 12:49:10 +09:00
Bill Currie
d5560434c0 [qfcc] Rename label to bool_label for clarity
And also so I can use `label' for source labels.
2020-03-11 11:06:09 +09:00
Bill Currie
07e6baf32f [qfcc] Support { } as nil in nested initializers
Did top-level earlier, but forgot to add support for deeper nestings.
2020-03-06 20:32:37 +09:00
Bill Currie
9b269c2f8e [qfcc] Fix mangled method parameters
Method parameters (ie, extra parameters without selector names) were
getting reversed during function type construction.
2020-03-06 17:37:58 +09:00
Bill Currie
94e35b5f57 [qfcc] Clean up error messages around superclass 2020-03-05 21:10:15 +09:00
Bill Currie
1bf56b28ac [qfcc] Warn when messaging a forward-declared class
But only once.
2020-03-05 15:39:34 +09:00
Bill Currie
efcbbbb641 [qfcc] Catch use of missing superclass interfaces 2020-03-05 08:50:29 +09:00
Bill Currie
896c14f33a [qfcc] Support anonymous structs in ivars
Missed this earlier.
2020-03-05 08:47:21 +09:00
Bill Currie
269a8a558a [qfcc] Allow bare enum and named struct declarations
Got a little overzealous there
2020-03-04 18:39:41 +09:00
Bill Currie
f532780dbe [qfcc] Treat opaque structs as not anonymous
I don't know why the segfault happened where it did, but
forward-declared structs certainly can't be used as anonymous structs.
2020-03-04 18:38:04 +09:00
Bill Currie
7a2335e9f4 [qfcc] Catch useless specifiers in function scope 2020-03-04 18:07:10 +09:00
Bill Currie
4c82114547 [qfcc] Catch several useless specifier expressions 2020-03-04 17:40:49 +09:00
Bill Currie
597890dda1 [qfcc] Catch duplicate field definitions 2020-03-04 16:32:04 +09:00
Bill Currie
e298904dc0 [qfcc] Implement anonymous structs and unions
For struct/union scope
2020-03-04 16:31:28 +09:00
Bill Currie
b186332da0 [qfcc] Make initialization of external vars an error 2020-03-03 17:33:56 +09:00
Bill Currie
16223098e5 [qfcc] Fix ivar visibility
It was broken by the big rewrite and I forgot to fix it.
2020-03-03 10:42:05 +09:00
Bill Currie
e33d83fc9e [qfcc] Accept "struct foo; struct foo { ... };"
That is, do not treat structure definition after declaration to be a
redefinition.
2020-03-02 20:16:29 +09:00
Bill Currie
0db617719e [qfcc] Improve error messages for bad qc builtins
While global quakec functions could not be initialized to another
function, the error messages were rather obscure.
2020-03-02 13:47:46 +09:00
Bill Currie
254bf29bd4 [qfcc] Handle protocol forward declarations 2020-03-01 19:37:40 +09:00
Bill Currie
caa297b756 [qfcc] Remove type alias encoding
It proved to be too fragile in its current implementation. It broke
pointers to incomplete structs and switch enum checking, and getting it
to work for other things was overly invasive. I still want the encoding,
but need to come up with something more robust.a
2020-03-01 16:13:18 +09:00
Bill Currie
b4aebc120e [qfcc] Treat { } as nil for initializing compound types 2020-02-27 20:30:39 +09:00
Bill Currie
7c9072aebf [qfcc] Create struct fields for "type typename"
Such declarations were being lost, thus in the following, the id field
never got added:
typedef struct qwaq_mevent_s {
    int         id;
    int         x, y, z;
    int         buttons;
} qwaq_mevent_t;
2020-02-27 17:50:11 +09:00
Bill Currie
dbbb8a1396 [qfcc] Fix syntax error for id as a field name
event.e.mouse.id produced a syntax error, which is contrary to
Objective-C.
2020-02-27 17:43:39 +09:00
Bill Currie
9610788dea Fix some more type aliasing issues
Getting there... (I knew this would be a big job)
2020-02-19 21:41:46 +09:00
Bill Currie
a5aba6c8ac Implement type aliasing
The separate types are in the file, but there are multiple issues
2020-02-19 21:41:46 +09:00
Bill Currie
7a315b4a89 Fix storage class for for-loop declarations
Getting "i redeclared" when i was declared in a for loop in two
different functions was a tad unexpected.
2020-02-19 21:41:46 +09:00
Bill Currie
ee228504aa Fix self-referenced enum declarations
eg:
typedef enum foo {
    bar = 1,
    baz = bar,
} foo;
2020-02-19 02:35:09 +09:00
Bill Currie
9d2d33fa50 Implement %% (true modulo) support in qfcc
However, it's not quite working yet
2020-02-16 11:57:58 +09:00
Bill Currie
ef4ad52239 Make binary_expr fold constants
This is where constant folding should have happened all along. While
unary_expr should fold constants too, it seems to already try to do so
and it's a bit much of a mess to clean up right now.
2019-06-10 00:36:13 +09:00
Bill Currie
e849c2d1ce Mark block expr result as rvalue when used as one
At least for return. There may be other cases that need it, but this
fixes comma-expr.r (minus int->float promotion issues).
2019-06-09 19:29:21 +09:00
Bill Currie
7fce68649a Implement comma expressions
Doesn't quite work (attempt to suppress warning for return a = 3, 5;
failed).
2019-06-09 16:56:20 +09:00
Bill Currie
689d1ad3ec Remove some debug prints 2019-06-09 16:45:01 +09:00
Bill Currie
ec89149b29 Build for loop decl inits correctly
The multiple expressions are chained together and evaluate in left to
right order.
2019-06-09 13:54:03 +09:00
Bill Currie
5bd3c8c985 Allow variable declarations in for loops
Matches C, C++ and C#
2019-06-08 21:52:17 +09:00
Bill Currie
be4c3a82a2 Detect redefinitions of structs and unions
While the redefinition was being detected, it was misreported as the tag
being wrong, and on the wrong line, too.
2019-06-08 19:25:25 +09:00
Bill Currie
4ef4a7e955 Start work on simple names in symbol tables
I don't remember what the goal was (stopped working on it eight months
ago), but some possibilities include:
 - better handling of nil (have trouble with assigning into struts)
 - automatic forward declarations ala C# and jai (I was watching vids
   about jai at the time)
 - something for pascal
 - simply that the default symbol type should not be var (in which case,
   goal accomplished)
2019-06-06 07:01:44 +09:00
Bill Currie
ff5c1cd4c2 Clean up redundant type parameter to initialize_def. 2018-10-15 22:11:20 +09:00
Bill Currie
3295370328 Expose and use field_expr().
This may cause problems later on, but it is needed for the binary_expr()
cleanup.
2013-09-27 23:15:57 +09:00