Commit Graph

109 Commits

Author SHA1 Message Date
svenbarth
598ac21791 * if the generic dummy symbol is a procsym (with procdefs added) then this is the symbol that should be resolved to
git-svn-id: trunk@39232 -
2018-06-15 13:49:21 +00:00
svenbarth
06d7e26df0 * move code to add a symbol to the current module's generic dummy symbols into a new function pgenutil.add_generic_dummysym()
git-svn-id: trunk@36466 -
2017-06-09 14:30:23 +00:00
florian
b1dff29cbf * removed unused units
git-svn-id: trunk@36165 -
2017-05-09 19:53:14 +00:00
svenbarth
8024fcd7ec * if an operator overload in a structured type is invalid print an error only for the declaration and not the implementation as well
This fixes Mantis #31634 as far as I see it useful to; anything further would probably require extension of the message generation system by a context or such so that the compiler could write "Error in TFoo<Integer>: ..." instead of merely "Error: ..." or something like that.
No test added due to the nature of the bug.

git-svn-id: trunk@35748 -
2017-04-07 13:24:58 +00:00
maciej-izak
e4565378db * Allow for "record constraint" in Delphi mode more types like: ordinal, float, classical objects, enumerations (instead of just record). Delphi compatibility. Fix for mantis #24073.
git-svn-id: trunk@35739 -
2017-04-05 13:12:30 +00:00
svenbarth
d34acf3bc7 * fix for Mantis #31120: check current_genericdef only if the current_procinfo isn't used
+ added test

Note: the test is added to webtbs although it's right now still failing, cause I'll remove the restriction for nested procedures since the compiler now supports them correctly. Due to the way we handle generics we don't have problems with them unlike Delphi.

git-svn-id: trunk@35147 -
2016-12-17 21:20:44 +00:00
svenbarth
6ba85c2a70 * second fix for Mantis #30626: also search in parent classes for a suitable pre-existing specialization
+ added test

git-svn-id: trunk@35014 -
2016-11-29 17:04:07 +00:00
svenbarth
0a1e080089 * only create a new procsym for a specialization if it's indeed needed
git-svn-id: trunk@35013 -
2016-11-29 14:13:06 +00:00
svenbarth
a535d54bcb * fix for Mantis #30939: Rework generation of the generic name to be less relying on the type hierarchy as a specialization inside the parameter declaration would want to have the full name of the procdef including its parameters, but those are still parsed at that stage (the pretty name is still a topic onto itself however...)
+ added tests (original test was only mode fpc, test for mode delphi is added as well)

git-svn-id: trunk@35010 -
2016-11-28 18:16:49 +00:00
svenbarth
ee466b9a28 * extend tdef.fullownerhierarchyname() with a parameter that skips the inclusion of a procdef's parameter declaration using the new pno_noparams option
git-svn-id: trunk@35009 -
2016-11-28 18:06:35 +00:00
svenbarth
63b0024e4c * fix for Mantis #30626: unset current_procinfo so that further specializations don't use a symtable to specialize themselves in that they shouldn't use (cause current_procinfo takes precedence)
git-svn-id: trunk@34916 -
2016-11-18 16:17:09 +00:00
svenbarth
fd7daf91df + new overload for generate_specialization_phase1() which allows to pass a specific symbol name without the need to specify a file position
git-svn-id: trunk@34529 -
2016-09-16 15:10:51 +00:00
svenbarth
627e30f47f * factor() might return a typenode with a errordef, so check for that and don't add the typesymbol to the parameter list in that case; fixes the access violation of tw17181.pp
git-svn-id: trunk@34472 -
2016-09-09 13:04:41 +00:00
svenbarth
80c2e3b51a * special detection of an ongoing specialization for the case that a function that belongs to a generic and has said generic as parameter or result is in turn specialized as a parameter or result of another generic function
git-svn-id: trunk@34412 -
2016-09-02 15:52:03 +00:00
svenbarth
6a14bb5014 * check the owner of current_specializedef as that is Nil if a generic routine is specialized and this is the specialization of one of its parameters or its result type
git-svn-id: trunk@34411 -
2016-09-02 15:48:30 +00:00
pierre
22a7ce8972 Fix memory leak due to double srsym allocation
git-svn-id: trunk@34364 -
2016-08-21 22:26:59 +00:00
Jonas Maebe
95f28e5e0c * avoid a crash when processing synthetic methods of specialised classes:
these are generated after the other specialisation methods (via
    add_synthetic_method_implementations, rather than via
    generate_specialization_procs)
   o fixes crash in tests/test/jvm/tw20212.pp

git-svn-id: trunk@34036 -
2016-06-30 15:33:54 +00:00
svenbarth
6c3dd6b601 Another system, another regression... (this time tests/test/tgenfunc15.pp on i386-win32)
pgenutil.pas:
  * generate_specialization_phase2 & generate_specialization_procs: don't add pending specializations if we're currently parsing a generic

git-svn-id: trunk@33885 -
2016-06-03 12:36:27 +00:00
svenbarth
fd98ec56e9 Fix (hopefully last) regression introduced due to the reworking specialization of routine bodies.
pgenutil.pas:
  * process_abstractrecorddef & generate_specialization_procs: also check for a forward def is the other module is still compiling (thus an access to tprocdef.forwarddef should still be possible); this might happen due to circular references like in tests/test/tgeneric91.pp

git-svn-id: trunk@33872 -
2016-06-01 19:03:54 +00:00
florian
04a68d9b94 * fix compilation with -Oodfa
git-svn-id: trunk@33865 -
2016-05-31 21:14:53 +00:00
svenbarth
1bd43d9e37 Fix regressions.
pgenutil.pas:
  + new function maybe_add_pending_specialization() to add a pending specialization if it belongs to the current unit
  * generate_specialization_phase2: don't set up the owner as this leads to problems when using overloaded generic routines and don't add it to the pending list if it's a procdef
ncal.pas, tcallnode:
  * pass_typecheck: if we have a specialization then add it to the pending specializations once we know that we use it

git-svn-id: trunk@33843 -
2016-05-28 22:12:45 +00:00
svenbarth
1d7c19aaf0 Fix regressions.
pgenutil.pas:
  * process_procdef & process_abstractrecorddef: only check whether the procdef's generic is still a forward declaration if it's in the current unit (otherwise we would trigger an internal error)

git-svn-id: trunk@33828 -
2016-05-27 16:29:22 +00:00
svenbarth
f27ce0b159 Rework the way the method bodies for specializations are generated: instead of walking the global and local symboltable all pending specializations are kept in a list of the current module which is (for now) walked at the end of a unit/program to generate the method bodies as before.
fmodule.pas, tmodule:
  + new list pendingspecializations which keeps track of all pending specializations of the current module
psub.pas:
  * move generate_specialization_procs and related routines to pgenutil
  + new procedure read_proc_body to read a routine's body, cause generate_specialization_procs needs it (unlike the already existing overload in the implementation section, this one can only handle bodies of non-nested routines) 
pgenutil.pas:
  * generate_specialization_phase2: add the newly specialized generic to the current module's pending specializations
  * generate_specialization_procs: reworked so that it uses the new pendingspecializations field instead of walking the global and local symboltable of the current unit
pmodules.pas:
  + add pgenutil to uses due to the moved generate_specialization_procs

+ added test

git-svn-id: trunk@33826 -
2016-05-26 18:56:16 +00:00
svenbarth
2f6a1c01ba pgenutil.pas, generate_specialization_phase2:
* ensure that the owner of the newly greated def is set to the symtable we specialize in (happens with generic routines)

git-svn-id: trunk@33825 -
2016-05-26 18:37:37 +00:00
svenbarth
f8def6dbc9 Store and use procedure directives of generic routines.
scanner.pas, tscannerfile:
  + new method is_recording_tokens to check whether token recording is already active
pdecsub.pas, parse_proc_directives:
  * record tokens into the declaration token buffer of a generic routine if necessary
pgenutil.pas, generate_specialization_phase2:
  * process the procedure directives that had been recorded with the generic routine

git-svn-id: trunk@33824 -
2016-05-26 18:35:08 +00:00
svenbarth
d07b49270f Fix for Mantis #30030.
pgenutil.pas:
  * parse_generic_specialization_types_internal: ignore the parasymtable of procvars (as before the addition of generic routines) and instead use the type's hierarchy name
  * generate_specialization_phase2: specialize types of procvars into the parameter symtable as they don't have a local one

+ added test

git-svn-id: trunk@33544 -
2016-04-22 13:07:48 +00:00
svenbarth
e9fab1bfee Fix for Mantis #29080.
psub.pas, tcgprocinfo.parse_body:
  * ensure that parse_generic and current_genericdef are set correctly when parsing a generic routine
pgenutil.pas, generate_specialization_phase2:
  * when we're specializing inside a generic we don't want to have the routine definitions, so let the compiler assume that the routine is no longer a forward definition

+ added test

git-svn-id: trunk@33275 -
2016-03-18 16:31:23 +00:00
svenbarth
0ff87336aa Convert the Boolean parameters accept_equal, typeonly and hadspecialize of comp_expr(), sub_expr() and factor() to a set parameter and adjust all calls.
pexpr.pas:
  + new enum texprflag and corresponding set texprflags
  * comp_expr: replace accept_equal and typeonly with texprflags parameter
  * factor: replace typeonly and hadspecialize with texprflags parameter
  * sub_expr: replace accept_equal and typeonly with texprflags parameter
  * adjust calls to comp_expr(), factor() and sub_expr()
other units:
  * adjust calls to comp_expr(), factor() and sub_expr() 

git-svn-id: trunk@32269 -
2015-11-07 21:45:03 +00:00
Jonas Maebe
2cea723a0d * only write the parts of the unit localsymtables that are actually needed:
the defs and syms (recursively) referred by inline routines and by the WPO
    info
   o defs and syms are no longer added immediately to the module's deflist/
     symlist, even if they are created as "registered". Instead,
     "doregister=true" simply means "add it to the symbol table at the
     top of the symtable stack"
   o normally only when a sym/def is deref'ed, it gets added to the module
     symlist/deflist and defid/symid gets a (unique) value
   o in cases where we use(d) the defid to construct unique names within the
     current module, you now have to call call the tdef.new unique_id_str()
     method. If the def was not yet registered, we will reserve room for it
     in the deflist (to get a unique id), but the defid gets set to a
     negative value computed from its position in the deflist. Should it
     have to be written to the ppu file later on, the defid will be
     modified to the actual position in the deflist. For both values,
     new unique_id_str() will return the same result so that references
     to this def before and after actual registrations are the same (needed
     for the JVM backend, but also a good principle in general)

   Overall: don't directly use symid/defid anymore to get unique identifiers,
     but use tdef.new unique_id_str() instead (if necessary, a similar routine
     for tsym can be added)

   The result is the ppu file size gets reduced significantly after its big
   increase as a result of the high level typed constant builder (which creates
   a lot of defs). The result is even more efficient than before, as other
   unneeded defs/syms from the localsymtables don't get saved/restored anymore
   either.

git-svn-id: trunk@32153 -
2015-10-25 19:22:00 +00:00
svenbarth
96a9273fba pdecsub.pas:
+ export parse_proc_dec_finish() from the unit
pgenutil.pas:
  * adjust generate_specialization_phase2() to correctly specialize procdefs

git-svn-id: trunk@31772 -
2015-09-18 21:51:17 +00:00
svenbarth
35d8a51730 pexpr.pas:
* extend factor() with the ability to deal with an already parsed "specialize"

git-svn-id: trunk@31768 -
2015-09-18 15:38:09 +00:00
svenbarth
2e24d6dffb htypechk.pas:
* extend tcallcandidates by the ability to handle generic procdefs
pgenutil.pas:
  + export check_generic_constraints

git-svn-id: trunk@31760 -
2015-09-18 14:37:47 +00:00
svenbarth
e8c68a09c1 pgenutil.pas, parse_generic_parameters:
* no longer create the type symbol and the defs as registered
pdecl.pas, types_dec:
  * register the syms and defs of the parsed generic parameters

git-svn-id: trunk@31758 -
2015-09-18 13:16:25 +00:00
svenbarth
040786e5bb + extend tundefineddef with the possiblity to create it as unregistered
* for now all undefineddefs are created as registered
Note: an additional parameter instead of an overload is used for tundefineddef.create as otherwise both constructors would need to be overridden in potential descendant CPU-specific classes...

git-svn-id: trunk@31757 -
2015-09-18 13:08:58 +00:00
svenbarth
4b98b36212 pgenutil.pas:
* make generate_specialization_phase1() and generate_specialization_phase2() aware of the existance of procdefs

git-svn-id: trunk@31756 -
2015-09-18 12:53:42 +00:00
yury
d27964bd1a * Removed unused chunk of code. Looks like a not needed leftover.
git-svn-id: trunk@31741 -
2015-09-17 15:11:03 +00:00
yury
432248cbf1 * Removed lot of unused vars.
git-svn-id: trunk@31732 -
2015-09-17 12:48:58 +00:00
svenbarth
00f776ef76 pgenutil.pas, parse_generic_specialization_types_internal:
* in case of an inline specialization inside a generic function's/method's parameter list using type parameters of the generic function/method itself fulltypename of the generic type parameter must not be used as the procdef is not yet owned by anyone; this is no problem for non-generic functions/methods or specializations with type parameters that don't belong to the generic function/method, because they don't have the generic, ownerless procdef as owner => use a name that provides sufficient uniqueness

git-svn-id: trunk@31601 -
2015-09-11 15:18:44 +00:00
svenbarth
84b9d9839c + extend tobjectdef with the possiblity to create it as unregistered
* for now all objectdefs are created as registered
Note: an additional parameter instead of an overload is used for tobjectdef.create as otherwise both constructors would need to be overridden in potential descendant CPU-specific classes...

git-svn-id: trunk@31592 -
2015-09-11 13:28:49 +00:00
svenbarth
d45c275ef3 + extend ttypesym with the possiblity to create it as unregistered
* for now all typesyms are created as registered
Note: an additional parameter instead of an overload is used for ttypesym.create as otherwise both constructors would need to be overridden in potential descendant CPU-specific classes...

git-svn-id: trunk@31591 -
2015-09-11 13:22:12 +00:00
florian
83a7fa2320 o fix compilation of the compiler
* $warn x off does not work tokenwise yet
  * -O2+ is more picky about uninitialized variables, FPC does not do dynamic DFA 

git-svn-id: trunk@31546 -
2015-09-06 10:12:55 +00:00
svenbarth
eaab604f0c pgenutil.pas:
* split generate_specialization() into two phases: generate_specialization_phase1() and generate_specialization_phase2(); the former parses the generic parameters and determines the correct generic def while the latter does the real specialization. This is needed for generic functions/methods as no full specialization needs to be done until overload selection by tcallcandidates
pgentype.pas:
  + new type tspecializationcontext

git-svn-id: trunk@31514 -
2015-09-04 15:37:54 +00:00
svenbarth
e8fca1c9c0 * move tspecializationstate from pgenutil.pas into a new unit named pgentype.pas which contains types related to generics with as few dependencies as possible.
git-svn-id: trunk@31507 -
2015-09-04 13:37:06 +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
25e6eaf07f * store the to be used recordalignmin and maxcrecordalign settings inside
(abstract)recordsymtables, so that these settings don't depend on the
    current user settings when internally creating record definitions

git-svn-id: branches/hlcgllvm@30343 -
2015-03-27 21:25:56 +00:00
svenbarth
d849734acd Specialize the correct generic if it has the same name as another generic that is located at another place of the type hierarchy.
pgenutils.pas:
  + generate_generic_name: new parameter owner_hierarchy to further influence the specialization name
  * generate_specialization: pass the ownerhierarchy name to generate_generic_name
pdecsub.pas, parse_proc_head:
  * parse_generic_interface: for now pass '' to the hierarchy parameter; it needs to be checked whether Delphi allows nested interfaces there as well

git-svn-id: trunk@29769 -
2015-02-20 16:28:44 +00:00
svenbarth
04534d5dcf Fix for Mantis #27424.
pgenutil.pas:
  * parse_generic_parameters: a ';' terminates a parameter group, so correctly adjust firstidx in that case

+ added test

git-svn-id: trunk@29685 -
2015-02-13 13:50:47 +00:00
svenbarth
0d1d3d8e72 Fix for Mantis #25917. With this change the visibility of type parameters is changed from public to strict private as otherwise unexpected (and "unworkaroundable") errors might occur (like the one in the mentioned bug report).
pgenutil.pas:
  * parse_generic_parameters & insert_generic_parameter_types: create the type parameter symbols as strict private instead of public (which is the default visiblity)

* adjusted two tests which relied on this behavior (that's why I fixed the type aliases previously)
+ added test

git-svn-id: trunk@29486 -
2015-01-16 17:02:02 +00:00
svenbarth
fa1bc0757d Fix for Mantis #26922.
pgenutil.pas, specialization_init:
  * don't push the localsymtable if the unit does not have one available

+ added test (needs manual execution though... :/ )

git-svn-id: trunk@29172 -
2014-11-28 16:35:28 +00:00
svenbarth
16774350d7 Fix for Mantis #26749 .
pgenutil.pas, generate_specialization:
  * first check whether we can reuse the current specialization or another specialization and only /then/ retrieve the symtable to specialize to

+ added test

git-svn-id: trunk@28705 -
2014-09-21 19:15:37 +00:00