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

59 Commits

Author SHA1 Message Date
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
13ed557b92 Fixed compatibility checking of function declarations by using the composite types of them. 2020-08-14 18:33:54 +02:00
acqn
80b0e57543 Changed parameter constness of TypeConversion(). 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
acqn
30fd8592ae Avoid internal errors when using function-type objects in expressions. 2020-08-02 12:28:11 +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
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
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
66ecc0e52c New utility to get the proper replacement type for passing structs/unions by value.
New utility to get basic type names such as 'struct', 'union' and so on.
2020-07-19 10:58:33 +02:00
Greg King
6230b6a813 Completed the cc65 code that recognizes __CDECL__ as a calling convention qualifier. 2015-03-09 19:39:04 -04:00
Greg King
0390c34e88 Changed multi-line C comments into another style.
The left side doesn't look unbalanced.
2014-06-30 16:51:07 -04:00
Oliver Schmidt
4185caf855 Normalized code. 2014-03-04 01:11:19 +01:00
Oliver Schmidt
85885001b1 Removed (pretty inconsistently used) tab chars from source code base. 2013-05-09 13:57:12 +02:00
uz
724d1b9160 Fixed an error: When determining where to place initialized data, the compiler
didn't look "deep enough" into nested arrays to determine the constness
correctly.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5622 b7a2c559-68d2-44c3-8de9-860c34a00d81
2012-03-24 14:28:59 +00:00
uz
54740da820 More preparations for an extension of the calling conventions.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4650 b7a2c559-68d2-44c3-8de9-860c34a00d81
2010-04-29 20:30:49 +00:00
uz
03e206a44f Make the SIZEOF_XXX constants resolve to unsigned values.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4087 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-08-30 08:36:56 +00:00
uz
bd872a6324 Added code to parse bit fields and enter them into the symbol table. They're
not supported in code generation until now.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4072 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-08-29 17:38:53 +00:00
uz
32348f5778 Fixed an error: If an expression is loaded into the primary, a function must
be converted to pointer-to-function and an array to pointer-to-member resp.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3977 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-07-28 18:56:16 +00:00
uz
17ac0cb4fa Fixed the macro versions of several inline functions.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3900 b7a2c559-68d2-44c3-8de9-860c34a00d81
2008-08-31 18:31:18 +00:00
uz
1e46bc16e4 More changes to support address size qualifiers.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3899 b7a2c559-68d2-44c3-8de9-860c34a00d81
2008-08-31 18:24:33 +00:00
uz
cc36f8a93a Moved the fascall and near/far flags from the function desriptor into the
type. Started to add general handling of address size flags in types.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3891 b7a2c559-68d2-44c3-8de9-860c34a00d81
2008-08-24 17:33:30 +00:00
uz
0b4f6426e2 Some more floating point support.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3886 b7a2c559-68d2-44c3-8de9-860c34a00d81
2008-08-11 17:51:00 +00:00
cuz
10c949062b Fixed a bug: The compiler evaluated constant expressions internally always
using signed integers as data types. This led to wrong results for mod, div
and compares.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3797 b7a2c559-68d2-44c3-8de9-860c34a00d81
2007-08-26 18:53:46 +00:00
cuz
4c0720709b Fixed a few errors in the macros used by the Watcom compiler.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3712 b7a2c559-68d2-44c3-8de9-860c34a00d81
2006-03-30 19:49:03 +00:00
cuz
f196e7c5c9 Cleanup. Added a few general purpose functions.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3710 b7a2c559-68d2-44c3-8de9-860c34a00d81
2006-02-19 15:53:11 +00:00
cuz
de3a20a898 Changed the low level type representation from a strung of unsigned short
elements to a string of structs, each representing one type element. This
should fix problems on unusual architectures, since it is no longer necessary
to embedd pointers and other data converted to numbers in the string of
unsigned shorts.
Increased the TypeCode length to unsigned long to make room for more type
bits.
Inline more functions in datatype.h.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3709 b7a2c559-68d2-44c3-8de9-860c34a00d81
2006-02-19 12:29:37 +00:00
cuz
1375c85405 Removed an unneeded struct forward
git-svn-id: svn://svn.cc65.org/cc65/trunk@3708 b7a2c559-68d2-44c3-8de9-860c34a00d81
2006-02-18 12:23:07 +00:00
cuz
64921852dd Parse the C99 "restrict" keyword correctly (but ignore it otherwise).
git-svn-id: svn://svn.cc65.org/cc65/trunk@3706 b7a2c559-68d2-44c3-8de9-860c34a00d81
2006-02-17 20:19:35 +00:00
cuz
dd9ee0ae37 New function PtrConversion
git-svn-id: svn://svn.cc65.org/cc65/trunk@3168 b7a2c559-68d2-44c3-8de9-860c34a00d81
2004-08-02 16:37:00 +00:00
cuz
daf8e0d1e6 Added license information preproc.h
git-svn-id: svn://svn.cc65.org/cc65/trunk@3135 b7a2c559-68d2-44c3-8de9-860c34a00d81
2004-06-29 20:26:27 +00:00
cuz
651c6e5cbf Add predefined type strings for float and double
git-svn-id: svn://svn.cc65.org/cc65/trunk@3105 b7a2c559-68d2-44c3-8de9-860c34a00d81
2004-06-06 10:49:59 +00:00
cuz
3a144965fa Added T_SIZE_T as an alias for T_UINT
git-svn-id: svn://svn.cc65.org/cc65/trunk@3090 b7a2c559-68d2-44c3-8de9-860c34a00d81
2004-06-04 17:52:19 +00:00
cuz
f817b05fa9 Allow initialization of flexible array struct members
git-svn-id: svn://svn.cc65.org/cc65/trunk@1928 b7a2c559-68d2-44c3-8de9-860c34a00d81
2003-02-05 22:02:48 +00:00
cuz
c123666d24 Added flexible array members for structs
git-svn-id: svn://svn.cc65.org/cc65/trunk@1925 b7a2c559-68d2-44c3-8de9-860c34a00d81
2003-02-03 22:14:20 +00:00
cuz
5f666a19b8 Replaced the solution for the array conversion problem by a better one.
git-svn-id: svn://svn.cc65.org/cc65/trunk@1784 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-12-17 12:12:44 +00:00
cuz
ede471904c Reenable register variables
git-svn-id: svn://svn.cc65.org/cc65/trunk@1625 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-11-24 23:31:54 +00:00
cuz
c6abc5d9d4 Make small functions inline
git-svn-id: svn://svn.cc65.org/cc65/trunk@1519 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-11-14 22:51:39 +00:00
cuz
dadd136ae1 Use constants for datatype sizes
git-svn-id: svn://svn.cc65.org/cc65/trunk@1480 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-11-02 12:39:10 +00:00
cuz
8810e38bb7 Move the assignment parser into a separate module.
When assigning structures, copy them using the primary register when the
size is 1, 2, or 4.
When assigning structures, allow structures by value when the size is 1,
2, or 4. These structures are expected to be in the primary register. The
only case when this can happen is by return from function, so this change
makes div() work.


git-svn-id: svn://svn.cc65.org/cc65/trunk@1477 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-11-01 21:27:31 +00:00
cuz
872c2b4453 Made a lot of short functions inline
git-svn-id: svn://svn.cc65.org/cc65/trunk@1456 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-10-10 20:23:41 +00:00
cuz
d92676ef60 Add SB_GetNumber to scanstrbuf.c.
Rewrite of CharMapPragma in pragma.c
Fixed bug in scanner.c: Invalid octal constants containing the numbers 8
and 9 were accepted by the compiler.
Moved SignExtendChar from scanner.c to datatype.c.


git-svn-id: svn://svn.cc65.org/cc65/trunk@1416 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-09-30 18:46:08 +00:00
cuz
0355c34199 Fixed problems with incomplete types (structs and arrays) that could cause
internal compiler errors in several places.
An old cc65 extension (variables of type void) was broken and did no longer
work. Fixed that.


git-svn-id: svn://svn.cc65.org/cc65/trunk@1184 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-03-10 20:44:58 +00:00
cuz
f4fbbc3dcc Track usage of the sreg and several other zero page registers and remove
unused stores into these registers.
Because of this, the old code using regsave does no longer work. Started
to rewrite it.


git-svn-id: svn://svn.cc65.org/cc65/trunk@966 b7a2c559-68d2-44c3-8de9-860c34a00d81
2001-09-24 22:36:35 +00:00
cuz
8eadb8aee0 Working on the new backend
git-svn-id: svn://svn.cc65.org/cc65/trunk@706 b7a2c559-68d2-44c3-8de9-860c34a00d81
2001-05-03 17:34:54 +00:00
cuz
544705e6f4 * Added several type casts to increase C++ compatibility.
* __fixargs__ is now an actual function symbol and no longer handled in the
   scanner.
 * Additional symbol __argsize__ that is a constant in normal functions and
   a const local variable for variadic functions. Using this symbol, the
   va_arg macro gets a lot simpler and smaller.
 * Added special code to handle the fixed parameters of a variadic function.
   The code has some overhead, but the va_fix macro is no longer needed (and
   the compiler generated code is better than va_fix anyway).


git-svn-id: svn://svn.cc65.org/cc65/trunk@652 b7a2c559-68d2-44c3-8de9-860c34a00d81
2001-03-23 19:17:04 +00:00
cuz
4357bb4760 Allow __fastcall__ for C function. Contrary to the name, this is a size
optimization for C functions. The last parameter is not pushed onto the
stack by the caller but in the function entry code, so there is no speed
but a size gain.


git-svn-id: svn://svn.cc65.org/cc65/trunk@645 b7a2c559-68d2-44c3-8de9-860c34a00d81
2001-03-22 21:02:01 +00:00