Commit Graph

267 Commits

Author SHA1 Message Date
florian
aec18c2426 * weight currency->float conversions the same regardless if
the currency type is handled by the integer unit or the x87 fpu,
    resolves #38309

git-svn-id: trunk@48089 -
2021-01-05 22:39:16 +00:00
florian
1266afc0d0 * in equal_genfunc_paradefs take care of the fact that typesym might not be assigned for open array parameters, resolves #38012
git-svn-id: trunk@47253 -
2020-10-29 21:00:03 +00:00
svenbarth
2ff18e48a0 * fix for Mantis #36909: apply patch by Ryan Joseph so that array constructors can be used for static arrays as well.
+ added test

git-svn-id: trunk@46891 -
2020-09-18 15:00:15 +00:00
Jonas Maebe
23956e9f10 * prevent quadratic complexity in the size of the inheritance chain when
comparing objectdefs for equality

git-svn-id: trunk@46774 -
2020-09-05 12:25:13 +00:00
svenbarth
fa0c9adbf4 * extract checking whether two parameter defs of two procdefs are equal into a separate function
git-svn-id: trunk@45972 -
2020-07-31 15:55:31 +00:00
yury
72dc2145e9 * In Delphi mode throw a conversion error when trying to typecast a pointer to a procdef when they use different memory models.
git-svn-id: trunk@45856 -
2020-07-25 17:13:29 +00:00
svenbarth
52678562e3 * correctly handle selection between Single and Double overloads for Currency
+ added test

git-svn-id: trunk@45707 -
2020-06-27 22:33:36 +00:00
svenbarth
eaa2a2006c * fix for Mantis #37272: also allow the empty set for dynamic array parameters; Delphi probably started to allow that together with array constructors.
+ added tests

git-svn-id: trunk@45706 -
2020-06-27 22:33:31 +00:00
yury
2808873d1b * Reworked the optimization of unused $parentfp for nested routines.
- Do not remove the $parentfp parameter as was done in the previous optimization approach. Instead when $parentfp is unused to the following:
      - On the caller side: Omit passing the value for $parentfp for targets where tcgcallparanode.push_zero_sized_value_para=false (classic CPU targets). 
          Pass 0/nil as $parentfp for targets where tcgcallparanode.push_zero_sized_value_para=true;
      - On the callee side: Prevent allocation of registers/resources for $parentfp.
  - When possible keep $parentfp in a register.
  - Set the pio_nested_access flag in tprocinfo.set_needs_parentfp() to properly handle deep nesting levels;

git-svn-id: trunk@45436 -
2020-05-19 13:17:47 +00:00
yury
40504a6f9d * If a nested procedure does not access its parent's frame pointer, optimize it by removing the hidden $parentfp parameter.
* Improved the tisogoto1.pp test.

git-svn-id: trunk@45292 -
2020-05-06 14:43:49 +00:00
svenbarth
60345366f2 * fix for Mantis #35140: apply patch by Ryan Joseph together with some further changes by me to add support for constant parameters in generics
+ added tests

git-svn-id: trunk@45080 -
2020-04-25 22:12:35 +00:00
florian
fd20dc1086 * support unique copies of currencies which are handles by torddef, resolves #36013
git-svn-id: trunk@42837 -
2019-08-26 19:31:48 +00:00
Jonas Maebe
956aab3be0 * implement support for the Objective-C "related result type" convention
as described on
    http://releases.llvm.org/8.0.0/tools/clang/docs/LanguageExtensions.html#objective-c-features
    (rest of mantis #35994)

git-svn-id: trunk@42816 -
2019-08-25 15:23:53 +00:00
svenbarth
44bfa98a30 * fix for Mantis #35955: when the element of an array constructer requires an operator for conversion we don't let the caller of compare_defs_ext know that, instead we simply say that some conversion is required and let the typecheck handler deal with the element wise conversion
+ added test

git-svn-id: trunk@42700 -
2019-08-15 14:33:00 +00:00
Jonas Maebe
1da43f67d4 * (non-ancient) Delphi versions that accept explicit ordinal -> floating
point typecasts behave the same as FPC (convert the value) rather than
    as Turbo Pascal (reinterpret the bit pattern) (mantis #35886)

git-svn-id: trunk@42507 -
2019-07-28 11:14:54 +00:00
Jonas Maebe
c038e4c3f2 * relaxation of r42272: again only show warnings rather than errors for
out-of-range constants, because of the comments mentioned in #35753
    (except for enums, as apparently Delphi does the same)
  * added range check warnings about explicit type casts that throw away
    bits (e.g. byte($fff)), without giving warnings for most common cases
    (like cardinal(-1))
  * fixed masking/sign exting constant array indices (must be based on index
    range type size/signedness rather than on array size/"signedness")

git-svn-id: trunk@42275 -
2019-06-23 14:12:33 +00:00
Jonas Maebe
77658b925b * disable regular array -> dynamic array type coversion support unless
{$modeswitch arraytodynarray} is active (mantis #35576)
   o changed compiler to compile without this modeswitch
   o added the modeswitch to a test that depends on it

git-svn-id: trunk@42118 -
2019-05-25 12:31:32 +00:00
Jonas Maebe
281b3ad276 * fix case completeness and unreachable code warnings in compiler that would
be introduced by the next commit

git-svn-id: trunk@42046 -
2019-05-12 14:29:03 +00:00
florian
925531b99c * constrained generics are also compatible with formaldefs, resolves #34893
git-svn-id: trunk@40921 -
2019-01-19 21:23:36 +00:00
Jonas Maebe
50ab607676 + customint torddef type to create arbitraty bit-width integers
o use this to handle non-power-of-two-sized parameters for llvm
   o no general support in the parser/code generator, so don't expose

git-svn-id: trunk@40398 -
2018-11-29 20:57:08 +00:00
Jonas Maebe
9bd931e931 * make "formal const/var" parameters the least preferred conversion
(mantis #32179)
  - removed code to handle conversion to formaldef parameters that are not by
    reference (so the default conversion preference is kept)

git-svn-id: trunk@40012 -
2018-10-21 21:02:17 +00:00
Jonas Maebe
2c7c0d1144 * handle widechar constants directly in the scanner, instead of in the
overload selection (where you can't even know whether the string is
    a valid widechar constant) (mantis #33875)

git-svn-id: trunk@40009 -
2018-10-21 17:34:00 +00:00
Jonas Maebe
0b246f3dbd * converted Boolean8 to an internal type, and mapped Boolean to the
new internal pasbool1(type) (part of mantis #34411)
   o apply the _Bool x86-64 parameter passing rules only to pasbool1

git-svn-id: trunk@39949 -
2018-10-16 21:14:18 +00:00
florian
eea088c5f5 * allow nil to be assigned to generic types, resolves #34037
* niln is also a constant node

git-svn-id: trunk@39934 -
2018-10-14 07:38:13 +00:00
Jonas Maebe
1f9d518c57 * support for non-ASCII widechar constants (mantis #31605)
* also improved type checking for converting constant strings to integers
    in MacPas mode

git-svn-id: trunk@38730 -
2018-04-10 19:24:15 +00:00
nickysn
85ca504f4a * make near and far procedures/procvars incompatible with each other
git-svn-id: trunk@38645 -
2018-03-29 15:39:54 +00:00
svenbarth
5971e1327e * fix for Mantis #31756: have array constructors prefer open array parameters instead of dynamic array parameters for backwards compatibility
+ added test

git-svn-id: trunk@36175 -
2017-05-10 21:01:23 +00:00
svenbarth
bdef19fd79 * indeed allow the conversion of array constructors to dynamic arrays
git-svn-id: trunk@36100 -
2017-05-04 21:54:27 +00:00
svenbarth
df893b4a30 * implement a type conversion from an array constructor to a dynamic array
git-svn-id: trunk@36095 -
2017-05-04 21:34:38 +00:00
maciej-izak
ff28d5c85d * Fix usage of class operators in generics types. If we have generic type declaration/implementation then constraint in comparison to not specialized generic is not "exact" nor "incompatible". Mantis #30534.
git-svn-id: trunk@35740 -
2017-04-05 13:47:21 +00:00
svenbarth
5fa181b5d9 * second fix for Mantis #31033: also check for df_specialization instead of is_specialization for parameters to correctly handle nested types that aren't really true specializations themselves
+ added additional test

git-svn-id: trunk@35103 -
2016-12-10 19:47:09 +00:00
Jonas Maebe
94d7a7274b * compare floating point default parameter values bytewise instead of as
floating point values, so that NaNs can also be compared (mantis #30299)

git-svn-id: trunk@34597 -
2016-10-02 12:56:49 +00:00
svenbarth
0500c678e5 * fix for Mantis #30534: don't consider all types with generic constraints as equal, but at least ensure that they have the same basetype (Note: this still needs a bit more improvement)
+ added test

git-svn-id: trunk@34526 -
2016-09-16 13:24:28 +00:00
florian
a4d2f71d3d * better estimation of compatibility of array constructors with open arrays, resolves issue #29244
git-svn-id: trunk@32846 -
2016-01-04 23:10:45 +00:00
Jonas Maebe
9258b5d76b + non-functional 128 bit integer types (inaccessible from Pascal), for use
in the LLVM high level code generator to implement overflow checking

git-svn-id: trunk@32735 -
2015-12-26 20:00:33 +00:00
Jonas Maebe
8087389f63 * support assigning static methods to regular procvars in (obj)fpc mode
(patch by Ondrej Pokorny, mantis #27414)

git-svn-id: trunk@32216 -
2015-11-01 18:02:46 +00:00
Jonas Maebe
4f7b4a2735 * changed {$ifdef x86} code in defcmp into virtual methods
git-svn-id: trunk@32180 -
2015-10-28 18:06:27 +00:00
nickysn
e2740f0fd7 * disallow procvar to pointer conversion, if the pointer type isn't the default
code pointer type for the current memory model

git-svn-id: trunk@32165 -
2015-10-27 17:23:50 +00:00
svenbarth
8fbd57080b defcmp.pas, compare_paras:
+ new flag cpo_generic to allow a declaration of a generic function in the interface to be matched to its implementation as for each new undefined defs for the type parameters will be created

git-svn-id: trunk@31594 -
2015-09-11 13:42:51 +00:00
Jonas Maebe
dd3d0ae5bc * set the type of the hidden $vmt parameter to the correct classrefdef and
adjust the parameter comparison code to ignore types of $vmt parameters
    when comparing (previously they were all voidpointer and hence also
    equal)

git-svn-id: trunk@30955 -
2015-05-31 16:51:02 +00:00
svenbarth
19c6d72c7b Fix for Mantis #27750.
pgenutil.pas:
  * parse_generic_parameters: create explicit undefineddefs for type parameters that don't have a constraint
  * insert_generic_parameter_types: move the created undefineddefs from the parent symtable to the generic's symtable
defcmp.pas, compare_defs_ext:
  * in case the flag for strict undefineddef checks is set don't consider two different undefineddefs as compatible
+ added tests

git-svn-id: trunk@30705 -
2015-04-24 14:51:22 +00:00
Jonas Maebe
2bc8afaa63 + support for calling a method via a block: we capture the method as a
procvar in the local state of the block, and then call it insde the
    generated invoke routine. We can't call it directly there, because
    due to visibility reasons it may not be accessible from a regular
    procedure (e.g. if it is a strict private method)

git-svn-id: branches/blocks@28234 -
2014-07-18 09:15:35 +00:00
Jonas Maebe
bd09b88a5b + support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension)
o blocks are implemented as a variation of procedure variables
   o declaration of a block variable: "test: procedure(c: char) is block;"
     (C equivalent: (void)(^test)(char c) )
   o the compiler automatically converts procedures/functions whose address
     is passed to a block parameter or assigned to a block variable into
     a "block". This consists of
    1) generating a block descriptor (containing the size of the "block
       literal" (see below) and the signature of the invocation function
       encoded as an Objective-C selector)
    2) generating a wrapper function around the original funcion (with C
       calling convention), that has an extra first hidden parameter
       (marked as vo_is_parentfp in the compiler) whose type is a pointer
       to the describing "block literal"
    3) generating the "block literal", which contains a pointer to an
       external variable indicating whether this block captures context or
       not, some flags (see compiler/blockutl.get_block_literal_flags for
       info), a pointer to the wrapper function and a pointer to the
       descriptor. In the future, it will also contain captured variables.
   o right now, only global procedures/functions can be converted to blocks
     (because they don't require state capturing). The next steps are (Object
     Pascal) methods (not Objective-C methods, because Objective-C method
     procvars don't exist) and finally nested functions
   o on Mac OS X, the functionality will only work on Mac OS X 10.7 and later,
     because we have to use the so-called "ABI.2010.3.16" to ensure that
     our blocks aren't called as variadic functions by the runtime (which
     came out after the Mac OS X 10.6 release)
   o while the currently implemented functionality does not require any
     library support at all, there's no use enabling it on other platforms
     because unless it has been confirmed to work with a blocks runtime,
     there's no point in using blocks (they're just somewhat bulky procvars
     right now). Enabling it on other platforms (in combination with the
     GNUStep Objective-C run time), should simply be a matter of adding
     the right {$linklib xxx} statement to rtl/inc/blockrtl.pp file, adding
     that file to Makefile.fpc for that platform and adding that platform
     to the compiler/systems.systems_blocks_supported set

git-svn-id: branches/blocks@28232 -
2014-07-18 09:15:22 +00:00
Jonas Maebe
f29a7b827e * initialise doconv after comparing procvars, and in particular set it to
tc_proc_to_procvar in case the comparison returns something different
    from te_equal (so that not just the resulttype is changed of the
    existing type conversion node, but a new typeconversion node is created
    and processed)

git-svn-id: branches/blocks@28231 -
2014-07-18 09:15:15 +00:00
svenbarth
639a59df92 Added support for partial specialization. This should fix a few problems with generics, the tests for which will be added in the next days after I've verified them.
For partial specialization only the declaration is reparsed, but not method bodies.

The way generic parameters are passed around inside the compiler is changed: instead of creating new type symbols we keep a (name,def) pair so that the code in insert_generic_parameter_types can decide whether it needs to add a type symbol (for new undefined defs) or not (for real types and undefined defs that were passed on from the parent generic). This required the tfpobjectlist type of the genericlist variables/parameters to be changed to tfphashobjectlist.

For correctly parsing Delphi specializations as parameters in functions of records (or objects) the relationship between the def and its typesym must already be established during the parsing. For this the checks for forcing a "type is not completely defined" message needed to be adjusted to correctly handle nested types as well. This should as a sideeffect also allow the usage of nested constants, etc like was fixed for classes some months ago.

ToDo: 
  - if a generic is specialized with only fully defined types then we could generate the in the unit where it's used. This is not yet done.
  - currently we don't specialize generics that are currently parsed; maybe this could be improved in the future for better type compatibility checks
  - check whether the pausing of token recording for partial specializations works correct in context of hint modifiers

pgenutil.pas:
  * parse_generic_parameters: return a tfphashobjectlist instead of a tfpobjectlist (requires a few type adjustments in various other declarations)
  * maybe_insert_generic_rename_symbol, insert_generic_parameter_types: change genericlist from tfpobjectlist to tfphashobjectlist
  * parse_generic_specialization_types_internal: use is_generic instead of checking for df_generic
  * generate_specialization:
      + add a nested function to disable the requirement to check for method bodies
      * use the "simple" parameter parsing only for error recovery
      * instead of already creating a new type symbol for a parameter we use the found symbol's name and its def and maybe create it later on (therefor the type of tfpobjectlist was changed to tfphashobjectlist)
      * a partial specialization is specialized into the symtable of the def it is specialized in instead of one of the two global symtables
      * for now we handle partial specializations of generics we are currently parsing like before
      * don't continue recording generic tokens while we do a partial specialization
      * use the new unset_forwarddef function on the newly created defs
  * insert_generic_parameter_types: only create a new type symbol if the found type symbol does not yet have an owner (thus was freshly created for this generic declaration)

pdecobj.pas, object_dec:
  * change type of genericlist from tfpobjectlist to tfphashobjectlist
  * set the type sym for all object types that can be generic or inside a generic (needed for correctly parsing Delphi style generic declarations)

pdecsub.pas, parse_proc_head:
  * consume_generic_interface: always generate the specialization name as now all generics are "specialized" inside a generic
  * the assumption that the def index numbers are the same is no longer true as the genericdef might contain the defs of partial specializations which are not generated for full specializations

pdecvar.pas, read_record_fields:
  * we also need to check nested types whether they contain a not yet completely parsed record or object

ptype.pas:
  * read_named_type: 
      * change genericlist from tfpobjectlist to tfphashobjectlist
      * pass the typesymbol along to record_dec
  * resolve_forward_types: use is_generic instead of checking for df_generic
  * single_type: 
      * use is_generic instead of checking for df_generic
      * no need to check generic parameters
  * parse_record_members:
      + add parameter for the record's type symbol
      * setup the typesym <=> def relationship
  + record_dec: add parameter for the type symbol and pass it to parse_record_members
  * read_named_type, expr_type: use is_generic instead of checking for df_generic
  * array_dec & procvar_dec: change genericlist from tfpobjectlist to tfphashobjectlist

symdef.pas, tstoreddef:
  * improve the checks used in is_generic and is_specialization to really only work on true generics and true (and partial) specializations respectively
  * don't search the type parameters in the symtable, but store them in the PPU and load them from there
  - remove fillgenericparas method (including the calls in the descendants tarraydef, tprocvardef, tobjectdef and trecorddef)

defcmp.pas, compare_defs_ext:
  * handle partial specializations: specializations with only undefineddefs are compatible to generic defs

pdecl.pas, types_dec:
  * switch generictypelist from tfpobjectlist to tfphashobjectlist

ppu.pas:
  * increase PPU version

+ added tests that ensure that "not completely defined" checks for records (and objects) still work correctly

git-svn-id: trunk@27861 -
2014-06-05 20:05:05 +00:00
Jonas Maebe
338c064beb * moved x86-specific tpointerdef functionality to architecture-specific
descendants

git-svn-id: trunk@27397 -
2014-03-30 21:04:36 +00:00
svenbarth
c077adf499 Fix for Mantis #25132
defcmp.pas, objectdef_is_related:
  * use "equal_defs" instead of "=", as the former also handles equivalence of specializations

+ added test

git-svn-id: trunk@25848 -
2013-10-25 19:50:56 +00:00
svenbarth
798bb91e90 Extract tdef.is_related plus its overrides in tobjectdef, trecorddef and tstringdef into a new function def_is_related in unit defcmp.
defcmp.pas:
  + add new function "def_is_related" which combines the "is_related" overloads of "tobjectdef", "trecorddef" and "tstringdef" (it returns "false" for other def types which is what "tdef.is_related" did)
  * compare_defs_ext & compatible_childmethod_resultdef: change call from "x.is_related" to "def_is_related(x,...)"
symtype.pas, tdef:
  - remove "is_related" method
symdef.pas:
  - remove "is_related" in "tobjectdef", "trecorddef" and "tstringdef"
  * tobjectdef.needs_inittable: for checking whether a Corba interface somehow inherits from a IInterface don't use "is_related" anymore (we want to avoid the dependency after all), but mimic the necessary functionality of "def_is_related"
htypechk.pas, nadd.pas, ncal.pas, ncnv.pas, ngtcon.pas, nld.pas, optvirt.pas, pdecobj.pas, pdecvar.pas, pexpr.pas, pgenutil.pas:
  * change call from "x.is_related" to "def_is_related(x,...)"
symtable.pas
  + use unit defcmp
  * change call from "x.is_related" to "def_is_related(x,...)"
jvm/njvmcnv.pas, jvm/njvmflw.pas:
  * change call from "x.is_related" to "def_is_related(x,...)"

git-svn-id: trunk@25847 -
2013-10-25 19:44:27 +00:00
svenbarth
76f6de5cf1 Refactor tobjectdef.find_implemented_interface out into unit defcmp so that the recently introduced cycle between symdef and defcmp can be broken again.
defcmp.pas:
  + add function "find_implemented_interface"
  * change method call of "find_implemented_interface" into function call
symdef.pas:
  - tobjectdef: remove method "find_implemented_interface"
  - remove use of unit "defcmp"
pgenutil.pas:
  * change method call of "find_implemented_interface" into function call
  + add use of unit "defcmp"
ncgcnv.pas, ncnv.pas, pdecobj.pas, pdecsub.pas, pdecvar.pas:
  * change method call of "find_implemented_interface" into function call

git-svn-id: trunk@25844 -
2013-10-23 19:05:00 +00:00
Jonas Maebe
de56f909d5 * synchronized with trunk up to and including r25430
git-svn-id: branches/cpstrrtl@25431 -
2013-09-06 10:09:26 +00:00