acqn
0536f4f9bd
Minor fixes on constant expression checking and comments.
2020-08-21 23:27:41 +02:00
acqn
63256fd15d
Changed negation of signed long stored in unsigned long to unsigned subtraction.
2020-08-21 23:16:17 +02:00
acqn
f59c2a08d9
Added support for changing multiplications with certain negative multipliers into bit-shifts. Only enable certain kinds of signed mul replacements with shift according to the code size factor settings.
2020-08-21 23:16:17 +02:00
acqn
ea7336591c
Removed special-casing code for scaling up. Now it uses the normal multiplying code.
2020-08-21 23:16:17 +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
9fcde120aa
Made function signatures in asm output use the parameter lists from original definitions instead of the composites.
2020-08-19 08:40:19 +02:00
Greg King
36dd82f0e6
Added g_branch() to cc65's code generator.
...
It uses BRA if the platform's CPU has BRA. Else, it generates a JMP.
(Used it in the bitfield sign-extending code.)
2020-08-18 19:11:18 -04:00
Jesse Rosenstock
ff535b8e1a
Treat signed int bit-fields as signed
...
Prior to this PR, `int`, `signed int`, and `unsigned int`
bitfields are all treated as `unsigned int`.
With this PR, `signed int` will be treated as `signed int`,
and the others remain unsigned.
Since `Type` does not distinguish between `int` and `signed int`,
add an extra `int* SignenessSpecified` param to `ParseTypeSpec`
so we can tell these apart for bit-fields and treat plain `int : N`
as `unsigned int : N` since it is more efficient to zero-extend
than sign-extend.
Fixes #1095
2020-08-18 12:23:20 +02:00
Jesse Rosenstock
55cebc7b9e
Move bit-field adjustment to codegen.c
...
Extract functions g_testbitfield and g_extractbitfield from LoadExpr.
This helps prepare for #1192 , since g_extractbitfield will get much
longer and call AddCodeLine.
2020-08-18 10:55:31 +02:00
acqn
56b659c0be
Made char type a distinct type.
2020-08-18 10:48:38 +02:00
acqn
87889df9e9
Fixed type checking in relation operations.
2020-08-18 09:39:43 +02:00
acqn
f206833a20
Alternative fix for Issue #1167 .
2020-08-17 20:31:02 +02:00
acqn
0afa1a9a95
Fixed function signatures in asm output.
...
Improved full type name production.
2020-08-17 20:30:32 +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
acqn
15f28c3a8c
Fixed getting the basic raw type names.
2020-08-17 00:00:03 +02:00
acqn
11cd3e5cbd
Utility for checking general datatype categories, incomplete ESU types and arrays of unknown sizes.
2020-08-17 00:00:03 +02:00
Jesse Rosenstock
1cf9404c19
Support C2X _Static_assert(expr) syntax
...
This makes the message in _Static_assert(expr, message) optional.
Fixes #1188 .
2020-08-16 11:38:20 +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
b19bb14348
Fixed checking conflitcing declarations with external vs other linkage.
2020-08-14 18:33:54 +02:00
acqn
13ed557b92
Fixed compatibility checking of function declarations by using the composite types of them.
2020-08-14 18:33:54 +02:00
acqn
44d52935da
Utility for getting the composite types of functions.
2020-08-14 18:33:54 +02:00
acqn
8a417ff039
Improved ESU declaration failure handling.
2020-08-14 18:15:31 +02:00
acqn
0dfe9ff5fe
Fixed testing 'struct->field'.
2020-08-14 08:32:22 +08:00
acqn
0fa18886c0
Fixed copying structs/unions > 4 bytes.
2020-08-13 08:59:05 +02:00
acqn
03b37cf712
Fixed type comparisons of typedefs and arrays.
2020-08-12 15:04:26 +02:00
acqn
eb4464e828
Fixed type comparisons of ESU types with stricter rules.
2020-08-12 15:04:26 +02:00
acqn
fe44fe963f
Disallowed empty enums.
2020-08-12 15:02:43 +02:00
acqn
97065faf1a
Disallowed struct/union types of 0 size as cc65 is not ready to support them.
2020-08-12 15:02:43 +02:00
acqn
4dfc1a5ded
Using a dedicated SC_FICTITIOUS flag in case of parsing errors.
2020-08-12 15:01:31 +02:00
acqn
bde5be6793
Improved error message on initializing extern variables inside functions.
2020-08-12 15:01:31 +02:00
acqn
b62b1650f5
Improved error messages on struct/union type multiple definitions.
2020-08-12 15:01:31 +02:00
acqn
fe3f726fd6
Improved incomplete enum typed diagnostics.
2020-08-12 15:01:31 +02:00
acqn
0d53806490
Avoided excess errors in incomplete struct assignment.
2020-08-12 15:01:31 +02:00
acqn
9317db6642
Slightly improved type error messages of 'op='.
2020-08-12 15:01:31 +02:00
acqn
9fcfa3fc49
Fixed full type names of functions with "empty" parameter list.
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
0f1a5e0520
Set enum tag definition flags.
2020-08-09 22:12:36 +02:00
acqn
1dd899c7c9
Fixed non-file-scope multiple definition checking.
2020-08-09 22:12:36 +02:00
acqn
d68cd90e47
Function declaration in functions cannot have storage classes other than 'extern'.
2020-08-07 10:16:33 +02:00
acqn
43efc256f1
Changed error/warning messages not using the term 'tentative' according to PR reviews.
2020-08-07 10:16:33 +02:00
acqn
b2d3b8379c
Warning about forward declaration of enum types in non-cc65 modes.
2020-08-07 10:16:33 +02:00
acqn
8cdffc1944
No storage for unsuccessfully parsed variables.
2020-08-07 10:16:33 +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
fdd120db49
Enabled to output errors and warnings about tentative definitions.
2020-08-07 10:16:33 +02:00
acqn
f59d6b8f6a
Redefining enums/structs/unions of 0 size is no longer treated as declarations and thus forbidden.
2020-08-07 10:16:33 +02:00
Jesse Rosenstock
cdfc1afd89
Fix vacuous comparison warning from 0df45fe
...
cc65/symentry.c:306:60: warning: address of array 'Sym->Name' will always evaluate to 'true' [-Wpointer-bool-conversion]
sprintf (TypeName, "%s %s", GetBasicTypeName (T), Sym->Name ? Sym->Name : "<unknown>");
~~~~~^~~~ ~
2020-08-05 17:48:13 +02:00
Jesse Rosenstock
d8f9201ecd
LoadExpr: Optimize <= 8-bit bit-field loads
...
Set CF_FORCECHAR to do as many operations as char ops as possible.
Clear high byte at the end.
2020-08-05 12:49:46 +02:00
Jesse Rosenstock
0c72647edd
Remove extra ED_TestDone call
...
Accidentally added in #1141 .
2020-08-03 12:40:58 +02:00
acqn
bae431eab0
Fixed error message of CheckedPSizeOf().
2020-08-03 06:18:28 +02:00
acqn
d6aa446b54
Error info for loading expressions of incomplete enum types.
...
No more "Illegal type 0016".
2020-08-02 23:51:11 +02:00
acqn
6df4f1996b
Improved diagnostics with more detailed type names.
2020-08-02 23:51:11 +02:00
acqn
11a5f0edf1
No "Statement has no effect" warnings on statements with errors.
2020-08-02 23:51:11 +02:00
acqn
7e68a24625
Clearer warning messages on unused symbols.
2020-08-02 23:51:11 +02:00
acqn
e8c2886455
Improved error messages on redefinitions of constants and bit-fields.
2020-08-02 23:51:11 +02:00
acqn
ef5a4db12e
Improved warning messages on UB shifts.
2020-08-02 23:51:11 +02:00
acqn
2ab7272673
Improved warning on comparison of unsigned type < 0.
2020-08-02 23:51:11 +02:00
acqn
99ac1c46da
Made errors/warnings statistic message visible when there are errors.
2020-08-02 23:51:11 +02:00
acqn
44e3080ea9
Increased upper limit of allowed errors before aborting.
2020-08-02 23:51:11 +02:00
acqn
00c16d34a4
Minor fixes for HandleSymRedefinition().
2020-08-02 23:51:11 +02:00
acqn
80b0e57543
Changed parameter constness of TypeConversion().
2020-08-02 18:55:46 +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
d841bbe498
Utility to check for castability.
2020-08-02 18:55:46 +02:00
acqn
52051f444e
Using tracked individual string buffers instead of a shared static string buffer for full type names.
2020-08-02 18:55:46 +02:00
acqn
4ccf10f3fa
Utility to get full type names.
2020-08-02 18:55:46 +02:00
acqn
0df45fe2f2
Utility for getting ESU tag type symbols.
2020-08-02 18:55:46 +02:00
Oliver Schmidt
c831f40e9b
Unfortunately there's no other way than using the absolute path to init the correct MSVC 2017 environment.
2020-08-02 18:44:13 +02:00
Oliver Schmidt
992596c981
Initialize MSVC 2017 environment before build.
2020-08-02 17:32:36 +02:00
Jesse Rosenstock
adda28f5c5
LoadExpr: Set CF_FORCECHAR if test is required
...
If we are testing, we do not need to load the high byte(s).
2020-08-02 12:31:57 +02:00
acqn
2a555d198c
Changed 'switch' to 'if' according PR review comments.
2020-08-02 12:28:11 +02:00
acqn
30fd8592ae
Avoid internal errors when using function-type objects in expressions.
2020-08-02 12:28:11 +02:00
acqn
e526cbbff6
Fixed handling multiple storage specifiers in one declaration.
2020-08-02 02:20:25 +02:00
Oliver Schmidt
e1043fac12
Adjusted to https://github.com/cc65/cc65/pull/1124 .
2020-08-01 10:56:05 +02:00
Jesse Rosenstock
9c70bd44a6
Clarify comment about large shift
...
This is to avoid overflow on host platform.
2020-07-31 19:33:28 +02:00
Jesse Rosenstock
847982c6bf
Handle bit-field test after shift/mask
...
Previously, bit-field tests were incorrectly combined with load in
`if (x.bitfield)`. Delay the test until after the shift/mask
is done. Still combine tests with load if no shift/mask is required.
Fixes #1139
2020-07-31 19:33:28 +02:00
Jesse Rosenstock
d0c7108dcf
Change copyright notice to "The cc65 Authors"
2020-07-30 19:17:11 +02:00
Jesse Rosenstock
3df6c383c0
Add support for static_assert
...
Add C11's _Static_assert and static_assert macro.
This is like #error, but is handled at a later stage
of translation, so it is possible to check sizes of
types, values of enums, etc.
https://en.cppreference.com/w/c/language/_Static_assert
https://port70.net/~nsz/c/c11/n1570.html#6.7.10
2020-07-30 19:17:11 +02:00
Jesse Rosenstock
2d5fd0fc63
Use char ops if possible for bit-field loads
...
Set CF_FORCECHAR and change type to char once we have
shifted into a char.
This saves some unnecessary ldx #0 instructions.
2020-07-30 14:59:23 +02:00
acqn
e38f601fcc
Fixed padding at the ends of structs with bit-fields.
2020-07-30 08:38:24 +02:00
acqn
8a511bb63d
Fixed nested array initializers.
2020-07-30 08:38:24 +02:00
acqn
9075a853dc
Allows one trailing comma before the closing curly of a struct/union initializer.
2020-07-30 08:38:24 +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
d6d667a688
Improved error handling with symbol redefinitions.
2020-07-30 08:22:29 +02:00
acqn
92de4fa0d0
Enabled to recognize labels when parsing local variable declarations.
2020-07-30 08:22:29 +02:00
acqn
19c81ed866
Fixed type mask usage.
2020-07-30 08:13:23 +02:00
Jesse Rosenstock
fb9b50ff9c
Move type checks before bit-field width parsing
2020-07-30 08:10:38 +02:00
Jesse Rosenstock
a2561d07f3
Remove special-case bit-field width code
...
cbb33f8
restricted allowed bit-field types to int,
so this is equivalent for now, but forward-compatible.
Fixes FIXME
Also move the int type check before parsing the colon.
2020-07-30 08:10:38 +02:00
Oliver Schmidt
8eab28012a
Adjusted project name.
2020-07-28 23:29:16 +02:00
acqn
cbb33f86e8
Disabled using non-int-size types to declare bit-fields.
2020-07-28 23:26:25 +02:00
acqn
c37f9f1a41
Check if the integer size is known in GetIntegerTypeMin/Max() to prevent potential misuse.
2020-07-28 23:26:25 +02:00
acqn
0f412b6beb
Small fixes according to PR review.
2020-07-28 23:26:25 +02:00
acqn
7e243e0f2c
Allowed using all integer types including enum and char types to define bit-fields,
...
but kept the currently behavior that all of them are treated as unsigned int.
2020-07-28 23:26:25 +02:00
acqn
d8184fbe54
No longer insert all enums in the global symbol table.
2020-07-28 23:26:25 +02:00
acqn
daa65199b3
Fixed underlying types of enums.
...
Made enumerator diagnostics more sensible.
Fixed Issue #1048 as a natural result.
2020-07-28 23:26:25 +02:00
Greg King
44c82eb1c3
Made da65 disassemble branch instructions with relative address expression operands if there's no label.
2020-07-21 18:43:32 -04:00
acqn
07e18774f7
Added spaces around '|' with regex replacement.
2020-07-21 18:23:52 +02:00
acqn
c66d0881b9
Made the enum/enumerator types clearer and improved DumpSymEntry() output.
2020-07-21 18:23:52 +02:00
acqn
18bd76bb90
Minor fixes and improvements.
2020-07-21 18:23:52 +02:00