1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-26 20:29:34 +00:00
Commit Graph

351 Commits

Author SHA1 Message Date
acqn
16a8a64746 Use a dedicated expression parser for the preprocessor. 2022-07-21 11:10:02 +08:00
Bob Andrews
6b0afe0834
Merge pull request #1785 from acqn/Effectless
[cc65] Avoid generating asm from C code that has no observable effects
2022-07-19 17:38:03 +02:00
Bob Andrews
c802980d6a
Merge pull request #1784 from acqn/Diagnostics
[cc65] Slight improvements on diagnostics
2022-07-19 17:37:42 +02:00
acqn
2324bd62f6 If __A__,__AX__ or __EAX__ is used, post-inc/dec within the same statement will not modify it.
Moved testcase from src/test/todo to src/test/val plus minor improvement on portability.
2021-06-08 14:16:14 +08:00
acqn
f5dacda69b NoCodeConstExpr() fix to avoid exessive error messages. 2021-05-16 19:08:43 +08:00
acqn
2d014383cd Replaced certain usage of "(New-)PointerTo()" with "AddressOf()". 2021-06-08 00:43:26 +08:00
acqn
924fcf5d06 Replaced several occurance of PtrConversion() with StdConversion().
Variadic arguments of functions should be default-promoted.
2021-06-08 09:32:58 +08:00
acqn
e9545d68ee Minor clean-ups and typo fixes. 2021-04-17 11:43:03 +08:00
acqn
21858b52e7 Separated data initializer stuff from declaration stuff. 2022-01-03 13:10:32 +08:00
acqn
2d96f79bc7 Added and used new utility type functions for bit-fields.
Fixed GetUnderlyingTypeCode() for bit-fields with widths > 16.
2021-12-01 09:45:17 +08:00
mrdudz
3c1bb85b8e remove dangling spaces 2022-04-17 16:07:09 +02:00
acqn
c8956ce19b Fixed signed long comparisons with smaller unsigned types. 2022-03-03 20:24:14 +08:00
Bob Andrews
0587d9f5d4
Merge pull request #1675 from acqn/ShiftFix
[cc65] Fixed bitwise shift with numeric constant operand(s)
2022-03-01 19:50:21 +01:00
Jeff Tranter
2bf8be5b3b Fix some commonly made spelling errors in comments. 2022-02-21 15:44:31 -05:00
acqn
2bda128ef1 Fixed LimitExprValue() for 64-bit long env. 2022-02-26 23:02:51 +08:00
acqn
25a35d6b59 Fixed result type of certain operations, which was broken with the bit-field fix. 2021-06-10 21:54:32 +02:00
acqn
5adb29ce31 Made "bit-field-ness" a type property instead of a SymbolEntry or ExprDesc property.
Fixed integer promotion and result type in certain operations.
Fixed bit-fields 'op=' and postfix inc/dec operators.
2021-06-09 08:03:12 +02:00
acqn
dcacba472a Moved ArithmeticConvert() from cc65/expr.c to cc65/datatype.c.
Reorganized a few functions in cc65/datatype.c.
Added SignedType() and UnsignedType() for future usage.
Made LimitExprValue() external so that it can be used more often.
2021-06-09 08:03:12 +02:00
acqn
1450f146a5 Fixed '[]', '()' '.' and '->' operators following a postfix increment/decrement. 2021-05-16 20:43:49 +02:00
acqn
dfba8d77ca Error messages shouldn't raise warnings about unused expressions by themselves. 2021-05-14 10:48:17 +02:00
mrdudz
18f94d1fe0 rework to use a magic value instead of a flag, as suggested by Oliver 2021-05-11 14:00:49 +02:00
mrdudz
c9f242e566 Extend #pragma wrapped-call to support "bank" argument 2021-05-05 14:42:29 +02:00
acqn
71bd6415d6 No more unnecessary jump-over labels generated for logical OR false cases. 2021-04-24 23:53:26 +02:00
acqn
9cea9ce5e2 Made the code more constness-correct with 'Type' usage. 2021-04-19 15:36:55 +02:00
acqn
24d36854d2 Minor cleanups with array element qualifiers. 2021-04-19 15:36:55 +02:00
acqn
bfb7c936aa Preparation for constness-correction. 2021-04-19 15:36:55 +02:00
acqn
6e61093e79 Fixed pointer subtraction in certain very rare cases. 2021-04-17 11:14:37 +02:00
acqn
bd8eae67f1 Fixed local struct field access via the address of the struct. 2021-04-05 15:49:54 +02:00
acqn
1a3628df1a Fixed the term 'argument' vs 'parameter' in function parser. 2021-04-03 17:50:46 +02:00
acqn
91fd30611a Fixed ICE on error cases such as '&func + int a'. 2021-04-03 17:45:52 +02:00
acqn
b802efde54 Fixed ternary result type detection with pointer types.
Fixed pointer type comparison and conversion, especially regarding qualifiers.
Improved diagnostics about type comparison and conversion.
Reorganized some type-comparison/conversion functions.
2021-03-30 19:41:20 +02:00
acqn
f273b1ebcb Fixed crash with non-inlined __fastcall__ function invocation with no arguments. 2021-03-26 11:02:46 +08:00
acqn
3755e4a863 Replaced checking for __fastcall__ aginst AutoCDecl etc. with IsFastcallFunc(). 2021-03-24 14:35:44 +08:00
acqn
3c2e7ce41c More reliable test for true/false with addresses for AND, OR and ternary operators.
Minor comment typo fix.
2021-03-20 01:39:32 +01:00
acqn
325b7b4ab3 Enabled 'a ? b, c : d'. 2021-03-20 00:09:47 +01:00
acqn
a51d6d40de Ternary fix for some obscure cases. 2021-03-20 00:09:47 +01:00
acqn
6974c1ff12 Fixed and cleaned up codegen logic with arithmetic conversion in addition and subtraction. 2021-03-19 16:35:03 +01:00
acqn
8eeaaa3f36 Made certain types of comparison between addresses in constant expressions work. 2021-03-16 22:29:20 +01:00
acqn
99c7fe0ada Reusing code from parseadd() for ArrayRef().
Now index[ptr] works in constant expressions.
Fixed codegen for cast type in constant expressions.
Calls on swapstk in 'i[ptr]' is avoided when possible.
2021-03-16 22:29:20 +01:00
acqn
f5972dfd08 Made int+pointer work in constant expressions.
Fixed codegen for cast type addition in constant expressions.
Calls on swapstk in 'i+ptr' is avoided when possible.
2021-03-16 22:29:20 +01:00
acqn
aa6fdf58b8 Addresses in constant subtraction expressions now work.
Fixed codegen for cast type subtraction in constant expressions.
2021-03-16 22:29:20 +01:00
acqn
3caceb8174 Fixed result type in certain contant expression addition cases. 2021-02-26 19:45:46 +01:00
acqn
f2eed38fc8 Fixed expression type of the result of numeric constant comparison. 2021-02-26 19:45:46 +01:00
acqn
ea0c634e12 Improved codegen for unsigned char type comparison with numeric constants. 2021-02-23 22:06:21 +01:00
acqn
d628772cd1 Fixed signed char type comparison with unsigned numeric constants. 2021-02-23 22:06:21 +01:00
acqn
f1c715c455 Fixed a bug that pointer subtraction results from two absolute addresses are calculated as unsigned long. 2021-02-22 14:14:59 -05:00
acqn
81d6321cd7 Fixed internal representation of calculated constant results.
Minor clean-up.
2021-02-22 14:14:59 -05:00
acqn
eadaf2fef8 Fixed deferred post-inc and post-dec in unevaluated context such as 'sizeof(i++)'. 2021-02-22 11:02:47 +01:00
acqn
40b26f4060 Now the compiler removes code that has no observable effect. 2021-02-22 13:47:32 +08:00
acqn
7f05bd797f Now the compiler tracks code that has no observable effect. 2021-02-21 16:36:29 +08:00
acqn
bfc7a51a44 Fixed Issue #1265 according to C89/C99 standards. 2021-01-30 14:31:51 +01:00
Greg King
8b42f570e9 Fixed code that caused a seg-fault after parsing a (deferred) post-count argument followed by a (nested) function-call argument.
The old broken code defers the count until the end of the (parent function's) argument list.  But, a nested function call clears the pointer to the deferred type.  That leads to an access violation.
The new code defers only until the end of each argument.  Fixes #1320.
2020-11-20 17:45:14 -05:00
Polluks
bd6e5927c4 Fixed #1341 2020-11-18 10:28:19 +01:00
Jesse Rosenstock
060417b0dc Adjust type of int constants that fit in char
When there is an integral constant like `3` in an expression, it has
type `int` according to the C spec, even though it can be represented
as an `unsigned char`.  Change codegen (`hie_internal` and `typeadjust`)
to treat it as `unsigned char` instead of `int` so that faster,
unsigned operations can be used.

For the test case in #1298, reduces the cycles per iteration from
4311 to 1884.  This is a great improvement, but still much worse than
the 1053 cycles/iter from `c4698df~`, so more work remains to be done.

Further partial fix for #1298 and #1308.
2020-11-16 00:56:19 +01:00
acqn
5c43d1e04f Changed codegen for postfix inc/dec operations by deferring them till sequence points.
This usually allows faster & smaller code.
Note that deferred operations must still be called at sequence points even if the whole expressions containing them had constant values.
2020-10-20 22:01:55 +02:00
acqn
86ced2bd4c Avoided unnecessarily boosting the code label numbers with boolean AND. 2020-09-18 08:59:56 +02:00
acqn
ab7e9f8424 Hotfix for Issue #1250. 2020-09-08 16:28:21 +02:00
acqn
e2f950b15e Avoided referencing string literals with sizeof so that they are not output if unused elsewhere. 2020-09-05 13:21:21 +02:00
acqn
903e84c24c Std-functions are no longer inlined if they are unevaluated. 2020-09-05 13:21:21 +02:00
acqn
f849de6769 Object addresses as non-NULL for comparison with NULL. 2020-09-04 19:50:32 +02:00
acqn
8e0b2f0833 Object addresses as non-NULL in boolean context. 2020-09-04 19:50:32 +02:00
acqn
bc5570b708 Fixed logical-NOT in constant context. 2020-09-04 19:50:32 +02:00
acqn
fb6bc275bc Fixed evaluation flags propagation to subexpressions in assignments and function calls. 2020-09-02 21:36:59 +02:00
acqn
2379504449 Fixed AND/OR in certain cases where the 'E_NEED_TEST' flag set for usage only in subexpressions should be cleared. 2020-09-02 21:36:59 +02:00
acqn
28de3423eb Merged some switch cases in code generation subroutines. 2020-08-31 09:12:03 +02:00
acqn
6b64b43395 Made local static data use a separated label pool from the code label pool. 2020-08-31 09:12:03 +02:00
Oliver Schmidt
bee559d5f4
Merge pull request #1220 from acqn/StaticConst
[cc65] Fixed constant boolean expressions
2020-08-31 08:59:25 +02:00
acqn
74def4608a The 'E_NEED_TEST' flag shouldn't be overwritten when loading the expression result. 2020-08-31 02:30:12 +08:00
acqn
c0a873e0c8 Reduced exess errors on wrong initializations with curly braces. 2020-08-30 17:35:48 +02:00
acqn
60c59f59a3 Renamed StaticConstExpr() and StaticConstAbsIntExpr() with clearer comments. 2020-08-30 00:26:52 +08:00
acqn
0a96ffc878 Fixed function parameter checking.
Fixed function return type checking.
2020-08-29 16:37:16 +02:00
acqn
504aee3835
Merge branch 'master' into StaticConst 2020-08-27 06:27:23 +08:00
acqn
bb9c203222 Fixed integer promotion of unary operations. 2020-08-26 22:17:16 +02:00
acqn
f289ea6c14 Avoided generating unnecessary true-case labels in logic AND/OR. 2020-08-22 11:10:17 +08:00
acqn
0536f4f9bd Minor fixes on constant expression checking and comments. 2020-08-21 23:27:41 +02:00
acqn
85ea06687b Fixed logical AND and logical OR. 2020-08-20 07:52:15 +08:00
acqn
725511131a Fixed constant expression checks with no-code requirement.
Used return-by-value initialization for ExprDesc.
2020-08-20 07:52:11 +08:00
acqn
3ea3887c77 Fixed warnings on const comparison.
Warnings on expressions with no effects.
Fixed const ternary.
Fixed ternary with struct/union types as the true/false-branch expressions.
2020-08-20 07:52:06 +08:00
acqn
17bbba7327 Added integer boolean type string.
No longer set the "expression tested" flag with constant results in comparison.
2020-08-20 07:52:03 +08:00
acqn
87889df9e9 Fixed type checking in relation operations. 2020-08-18 09:39:43 +02:00
acqn
ebae994dc9 Fixed CHECK failure when calling functions defined with repeated parameter names.
Clarified the terms "parameter" vs "argument" in FunctionParamList().
2020-08-17 20:27:57 +02:00
Jesse Rosenstock
c4698dfd07 Use C89 semantics for integer conversions
Previously, the following rules were used for binary operators:
* If one of the values is a long, the result is long.
* If one of the values is unsigned, the result is also unsigned.
* Otherwise the result is an int.

C89 specifies the "usual arithmetic conversions" as:
* The integral promotions are performed on both operands.
* Then the following rules are applied:
  * If either operand has type unsigned long int, the other operand is
    converted to unsigned long int.
  * Otherwise, if one operand has type long int and the other has type
    unsigned int, if a long int can represent all values of an unsigned int,
    the operand of type unsigned int is converted to long int; if a long int
    cannot represent all the values of an unsigned int, both operands are
    converted to unsigned long int.
  * Otherwise, if either operand has type long int, the other operand is
    converted to long int.
  * Otherwise, if either operand has type unsigned int, the other operand is
    converted to unsigned int.
  * Otherwise, both operands have type int.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.5

As one example, these rules give a different result for an operator
with one long operand and one unsigned int operand.  Previously,
the result type was unsigned long.  With C89 semantics, it is just long,
since long can represent all unsigned ints.

Integral promotions convert types shorter than int to int (or unsigned int).
Both char and unsigned char are promoted to int since int can represent
all unsigned chars.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.1

Rename promoteint to ArithmeticConvert, since this is more accurate.

Fixes #170
2020-08-15 19:14:31 +02:00
acqn
0dfe9ff5fe Fixed testing 'struct->field'. 2020-08-14 08:32:22 +08:00
acqn
9317db6642 Slightly improved type error messages of 'op='. 2020-08-12 15:01:31 +02:00
acqn
68d63b089d Reduced error flood raised by misplaced variable declarations. 2020-08-12 15:01:31 +02:00
acqn
fdef067629 Fixed tentative definition of variables of incomplete types that may be completed later.
Tenative arrays that never get completed are now assumed each to have one element.
2020-08-07 10:16:33 +02:00
acqn
6df4f1996b Improved diagnostics with more detailed type names. 2020-08-02 23:51:11 +02:00
acqn
003d47cc8b Improved type conversion diagnostic messages.
Allowed incompatible pointer assignments with warnings.
Fixed Issue #1089.
2020-08-02 18:55:46 +02:00
acqn
30fd8592ae Avoid internal errors when using function-type objects in expressions. 2020-08-02 12:28:11 +02:00
acqn
25d10d9d9a Fixed nested struct/union initialization.
Fixed bit-fields offsets in anonymous structs.
2020-07-30 08:38:24 +02:00
acqn
65081aebed Made able to recognize global declarations of static arrays. Fixed Issue #975. 2020-07-21 18:23:52 +02:00
acqn
0250c87ac6 Fixed SC_* type masks by making them all bitwise-exclusive. 2020-07-21 18:23:52 +02:00
acqn
b67b8ddd38 Disabled applying 'sizeof' to bit-fields. 2020-07-20 14:54:32 +02:00
acqn
62a6e37487 Made the code handling '&expression' slightly tidier. 2020-07-20 14:54:32 +02:00
Greg King
fd0a6955da Changed "IsTypeStruct() || IsTypeUnion()" expressions into shorter "IsClassStruct()" expressions.
Type-classes are groups of types that can be handled in the same way (similar syntax).
2020-07-19 14:30:22 -04:00
acqn
29c50ab25f Corrected the error message about struct/union members not found. 2020-07-19 12:57:59 +02:00
acqn
768e03a474 Small fixes and tidy-up based on PR review.
Renamed GetReplacementType() to GetStructReplacementType().
Clarified in comments that most *Struct* facilities work for unions as well.
Made it clear in some error messages with regards to structs/unions.
2020-07-19 10:58:33 +02:00
acqn
b45d373fd6 Fixed passing by value structs/unions <= 4 bytes in size to functions. Larger ones are forbidden for now. 2020-07-19 10:58:33 +02:00
acqn
9f67b45ea0 Fixed returning by value structs/unions <= 4 bytes in size from functions. Larger ones are forbidden for now. 2020-07-19 10:58:33 +02:00
acqn
333fa97326 Whitespaces/newlines fixes. 2020-07-18 12:54:29 +02:00