Commit Graph

318 Commits

Author SHA1 Message Date
florian
637976e83f * patch by Marģers to unify internal error numbers, resolves #37888
git-svn-id: trunk@47103 -
2020-10-13 19:59:01 +00:00
svenbarth
04a50733ad * get rid of the scanner message for attributes for real this time (sometimes I *really* hate Git -.-)
git-svn-id: trunk@42413 -
2019-07-13 09:37:44 +00:00
svenbarth
6d0c470a40 * check for unbound attributes inside classes (currently they are only allowed for published properties)
Note: no tests yet as sooner or later most will be dropped once extended RTTI is added

git-svn-id: trunk@42408 -
2019-07-12 22:08:10 +00:00
svenbarth
402728239f * trtti_attribute_list.bind already checks whether the dangling attribute list is assigned or not
git-svn-id: trunk@42395 -
2019-07-12 22:07:24 +00:00
svenbarth
ced3885dbb * generate construction function for the attributes used in a unit using a more straight forward approach
ToDo: "collect" attributes of same type and same argument list and generate constructor only once for them

git-svn-id: trunk@42394 -
2019-07-12 22:07:20 +00:00
svenbarth
d9d2515ada * move binding of a dangling attribute list to a sym's/def's attribute list to a class procedure of trtti_attribute_list
git-svn-id: trunk@42392 -
2019-07-12 22:07:11 +00:00
svenbarth
b5e6c0b98d * ensure that any potentially created constructor call is freed if the attribute is not bound to a def or sym
git-svn-id: trunk@42383 -
2019-07-12 22:06:38 +00:00
svenbarth
ba413bcdfc * fix typo
git-svn-id: trunk@42363 -
2019-07-12 22:05:21 +00:00
svenbarth
39bab2dbcc * rename trtti_attributesdef to trtti_attributes_list
git-svn-id: trunk@42359 -
2019-07-12 22:05:00 +00:00
svenbarth
b2932393df Reintegration of Custom Attributes branch by Joost van der Sluis with patches reworked by Svetozar Belic [patch 1/3]
Implemented attributes for class types and properties (based on work by Joost van der Sluis). Added TCustomAttribute - a base class for attributes. Added TUnitInfo record to RTTI. It contains the unit name and unit options (for now only a flag which specifies if the unit contains attributes). Added several tests for attributes.

git-svn-id: trunk@42356 -
2019-07-12 22:04:48 +00:00
svenbarth
d0eddbcbb9 * fix for Mantis #35735: also handle "generic" keyword inside helper types
+ added test

git-svn-id: trunk@42328 -
2019-07-05 14:12:13 +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
Jonas Maebe
0b61b5d4cf * added extra header to ppu inside a subsection, so we won't run into
trouble when the ppu version hits 255
  * also moved several ppu flags to a set inside that section

git-svn-id: trunk@41846 -
2019-04-06 21:28:43 +00:00
Jonas Maebe
ed2ae508d0 * only add hidden parameters for objectdef methods after generating the vmt,
so that they take into account inherited calling conventions (mantis #35233)
   o don't needlessly calculate the paraloc info when generating a JVM mangled
     name

git-svn-id: trunk@41716 -
2019-03-16 19:14:14 +00:00
Jonas Maebe
91d5457b38 * moved around/replaced the following procedures to stop nflw from depending
on pdecsub (node units should not depend on parser units):
   o maybe_add_public_default_java_constructor()
   o handle_calling_convention()
   o create_finalizer_procdef() (replaced with create_outline_procdef())
   o insert_record_hidden_paras()
   o handle_calling_convention()
   o proc_add_definition()
   o build_parentfpstruct()
   o maybe_guarantee_record_typesym()
   o get_first_proc_str()
  * factored out the creation of a procinfo for a nested procdef based on a
    subnodetree of the current procdef into tprocinfo.create_for_outlining()

git-svn-id: trunk@40773 -
2019-01-05 16:26:33 +00:00
Jonas Maebe
28df55fe08 * moved handle_calling_convention() to pparautl
git-svn-id: trunk@40772 -
2019-01-05 16:26:29 +00:00
svenbarth
c3ca96279a + add support for threadvars inside classes
+ added tests

git-svn-id: trunk@39288 -
2018-06-23 13:49:12 +00:00
svenbarth
5510b13975 * ensure that sto_has_generic is set when a generic routine has been parsed
git-svn-id: trunk@39230 -
2018-06-15 13:49:03 +00:00
svenbarth
90bd408de4 * fix for Mantis #32355: adjust the meaning of the typehelpers modeswitch for Delphi modes in that it enables the "type helper" syntax as it is in the non-Delphi modes; extending primitive types with record helpers is now always enabled in Delphi modes
+ added test

git-svn-id: trunk@37225 -
2017-09-15 21:09:21 +00:00
svenbarth
a6821c63e0 * store the type of the helper that had been encountered during parsing in the objectdef and by extension the PPU
git-svn-id: trunk@37202 -
2017-09-13 21:24:06 +00:00
svenbarth
236a9b0aa5 * rework the checks for a helper's extended def to be a class so that it can be more easily extended by other objecttypes
git-svn-id: trunk@37022 -
2017-08-21 20:48:02 +00:00
svenbarth
324e63b5d3 * a bit of language consolidation: "type helper" can now be used for records and classes as well
git-svn-id: trunk@36938 -
2017-08-18 15:29:19 +00:00
svenbarth
b6a3d66224 * adjust check for non-static class methods in class helpers in so far that only classes allow such methods (interfaces and objects would not either)
git-svn-id: trunk@36937 -
2017-08-18 15:27:47 +00:00
svenbarth
eef06e9bc6 * move the check whether a subclassed type helper extends a suitable subtype of the parent's extended type to a nested procedure
git-svn-id: trunk@36936 -
2017-08-18 15:25:53 +00:00
florian
b1dff29cbf * removed unused units
git-svn-id: trunk@36165 -
2017-05-09 19:53:14 +00:00
maciej-izak
48b149acd4 New tokens for new management operators: Initialize, Finalize, AddRef and Copy. Small code adjustment for parser (pdecobj.pas, pstatmnt.pas, psub.pas, ptype.pas) was required because few of old token has from now value which is outside range of set: _CONSTRUCTOR, _FINALIZATION.
New tokens for operators:
  * _OP_INITIALIZE, _OP_FINALIZE, _OP_ADDREF, _OP_COPY

New tokens:
  * _INITIALIZE, _FINALIZE, _ADDREF, _COPY

git-svn-id: trunk@35438 -
2017-02-18 18:12:45 +00:00
svenbarth
c2fec2e819 * if the objecttype of the forward declaration mismatches use the objecttype previously parsed; fixes access violation of webtbf/tw11970.pp
git-svn-id: trunk@34461 -
2016-09-08 18:42:13 +00:00
svenbarth
0df57b3c87 * forward declarations of helper types are not allowed, so enforce them by trying to parse a "for"; fixes access violation of thlp9.pp
git-svn-id: trunk@34459 -
2016-09-08 18:33:12 +00:00
svenbarth
d3660fec31 Implement support for parsing "generic [class] procedure" and "generic [class] function" in non-Delphi modes. Since "generic" is a prefix it is quite ugly to implement, but from a Pascal language point of view it fits better than "procedure generic xyz".
Supporting such a prefix of course means that all section handling code ("var", "type", etc.) needs to respect the case of a "generic" token followed by "function", "procedure" or "class" and thus abort doing its own business.
Maybe I'll find the time somewhen in the future to rework the parser (plus scanner?) a bit so that code like this gets more easy to add and more importantly less ugly.

pdecsub.pas:
  * extend parse_proc_dec() and parse_record_method_dec() so that they can be told that they are supposed to handle the to be parsed function/procedure/method header as a generic
pdecvar.pas:
  + new entry for tvar_dec_option named "vd_check_generic" to tell read_var_decls() and read_record_fields() to look out for "generic"
  * extend read_var_decls() and read_record_fields() to check for "generic" if needed and to clean up correctly if it is encountered
pdecl.pas:
  * the section handling procedures types_dec(), resourcestring_dec(), var_dec(), threadvar_dec() and consts_dec() all return whether they had encountered a "generic" token that was followed by one of $
pdecobj.pas:
  * extend method_dec() to take a parameter that says whether the method is supposed to be a generic one
  * parse_object_members: while read_record_fields() can handle "generic" we also need to handle the case of "generic" if no fields are allowed anymore
psub.pas:
  * extend read_proc() by the possibility to tell it that the procedure/function to be parsed is supposed to be generic
  * adjust read_declarations() and read_interface_declarations() to keep track of parsed "generic" tokens and to pass them on accordingly
ptype.pas:
  * parse_record_members: same remark as for pdecobj.parse_object_members

git-svn-id: trunk@32380 -
2015-11-20 16:50:58 +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
svenbarth
d15cdefc37 pdecsub.pas:
* extend parse_proc_head() with the ability to deal with specializations of procdefs
Note: such a procdef is created as unregistered as this is used to determine the correct overload in tcallcandidates (through the use of the yet to be adapted generate_specialization_phase2())

git-svn-id: trunk@31771 -
2015-09-18 21:31:53 +00:00
svenbarth
17a0ac7fc0 pdecsub.pas:
* extend parse_proc_head() with support for /parsing/ generic functions (at least in mode Delphi, mode ObjFPC depends on the new isgeneric parameter to be set)
  * adjust parsing of interface mappings with a generic interface (note: in mode ObjFPC this now requires a "specialize" directly before the generic interface's name, which is more in line with other uses of "specialize")
pexpr.pas, factor:
  * don't call postfixoperators() if hadspecialize is set

tests/test/tgeneric79.pp:
  * adjust test to changed syntax

git-svn-id: trunk@31769 -
2015-09-18 16:24:07 +00:00
yury
432248cbf1 * Removed lot of unused vars.
git-svn-id: trunk@31732 -
2015-09-17 12:48:58 +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
florian
f1decfb6b6 * do not generate a vmt record for generics, they are only needed for specializations
git-svn-id: trunk@31261 -
2015-08-02 19:51:08 +00:00
Jonas Maebe
2dcd42d4f1 * fixed detection of an objcprotocols descending from a forward-defined
objcprotocol

git-svn-id: trunk@30169 -
2015-03-12 19:37:43 +00:00
svenbarth
7b216d7fa6 Fix for Mantis #27120.
pdecobj.pas, parse_object_members:
  * also allow class fields for helper types

+ added tests

git-svn-id: trunk@29270 -
2014-12-12 13:57:43 +00:00
svenbarth
49a9f4c1ea Fix for Mantis #26123.
pdecobj.pas, object_dec:
  * Always check for genericdef and genericlist and not genericdef and ifnot then genericlist.

+ added test

git-svn-id: trunk@27877 -
2014-06-06 15:19:45 +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
02d36c56f7 * fixed compilation (changes after testing :/ )
git-svn-id: trunk@27840 -
2014-06-01 14:34:47 +00:00
Jonas Maebe
5e1a895e95 * removed JVM-specific creation of methodpointertype and
nestedprocpointertype; this was done initially before the JVM target knew
    about the voidpointertype, but is no longer necessary (also fixes
    mantis #26251)

git-svn-id: trunk@27838 -
2014-06-01 14:13:36 +00:00
Jonas Maebe
b57c95043f + support overriding tdef/tsym methods with target-specific functionality:
o made all (non-abstract) tdef and tsym constructors virtual
   o added c*def/c*sym classref types for every (non-abstract) t*def/t*sym
     class
   o added cpusym unit for every architecture that derives a tcpu*def/tcpu*sym
     class from the base classes, and initialises the c*def/c*sym classes with
     them. This is done so that the llvm target will be able to derive from
     the tcpu*def/sym classes without umpteen ifdefs, and it also means that
     the WPO can devirtualise everything because the c* variables are only
     initialised with one class type
   o replaced all t*def/t*sym constructor calls with c*def/c*sym constructor
     calls

git-svn-id: trunk@27361 -
2014-03-29 22:31:55 +00:00
svenbarth
ddb78fefdc Add a modeswitch for type helpers as discussed in core on 24th October 2013. It is disabled by default in all modes (afterall type helper support in Delphi started only beginning with XE3)
+ globtype.pas: add new modeswitch to modeswitch enum and name array
* ptype.pas & pdecobj.pas: check for new modeswitch instead of modeswitch class
* ppu.pas: increase ppu version as we've added a new modeswitch which requires correctly compiled units

* adjusted tests to enabled the modeswitch when necessary
+ added three new tests that check for correct functionality of modeswitch typehelpers

git-svn-id: trunk@26796 -
2014-02-16 12:58:24 +00:00
florian
4d5119bf1c * fixes several issues which cause warnings by the dfa code when using it to detect uninitialized variables
git-svn-id: trunk@26161 -
2013-12-01 17:02:08 +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
svenbarth
d91d4afb0f Fix for Mantis #25210 .
compiler/pdecobj.pas, object_dec:
  * since revision 25518 the global symtable of the current module is no longer popped and pushed again so that the defaware symtablestack can add the helper; thus we need to do this not only for static symtables, but for global ones as well
  * adjusted comment to reflect current situation

git-svn-id: trunk@25834 -
2013-10-20 11:33:01 +00:00
florian
2fdd3e2d0a + introduce tvariantrecbranch to be able to store
all needed information for iso compatible variant records
* new for variant records as required by iso pascal
+ tests

git-svn-id: trunk@24241 -
2013-04-14 15:50:42 +00:00
Jonas Maebe
3a03586ca9 * give an error when declaring a class as conforming to a forward-declared
interface: the compiler does not/cannot check whether the class
    implements all required methods in that case, and it moreover leads to
    crashes (mantis #24184). Older versions of Delphi did allow this (and
    don't check whether the interface methods are implemented either), but
    that's simply a (similar) bug in Delphi that has been fixed in XE at
    least
  * fixed compilation of webtbs/tw2727 after this fix

git-svn-id: trunk@24177 -
2013-04-07 12:18:31 +00:00
svenbarth
344571cb4e Added support for type helpers. In non Delphi modes they use "type helper" and in mode Delphi they use "record helper". They can also be used on constants.
symconst.pas:
  + extend "thelpertype" by "ht_type" which tells the code in "pdecobj.parse_extended_type" that a type helper declaration has been parsed
node.pas:
  + add a constant which identifies all constant node types
ptype.pas:
  + read_named_type: add a parameter "hadtypetoken" to tell the code whether a "type" token had been parsed before
  + read_named_type: if an identifier "helper" is parsed we need to check whether "hadtypetoken" is true and the modeswitch "m_class" is set, but the "m_delphi" one is not; in that case we have a "type helper" declaration
pgenutil.pas, generate_specialization:
  * adjust call to read_named_type
pdecl.pas, types_dec:
  * adjust call to read_named_type

pdecobj.pas:
  * parse_extended_type: extend for correct handling of primitive types (includes Delphi compatible handling as well) and reject types that are explicitly not allowed
  * method_dec: require "static" for class methods in type helpers
  * method_doc: allow constructors for type helpers as well
paramgr.pas, tparamanager:
  * set_common_funcretloc_info: handle type helper constructors like record constructors
  * handle_common_ret_in_param: the "self" value of a type helper constructor is also returned in a parameter
pexpr.pas:
  + add a function to postfixoperators which tries to find and apply a type helper for a given type
  * postfixoperators: try to apply type helpers for ordinal constants
  * postfixoperators: use the correct string type for string constants
  * postfixoperators: try to apply type helpers for enum constants
  * postfixoperators: try to apply type helpers for arrays
  * postfixoperators: try to apply type helpers for Variant
  * postfixoperators: try to apply type helpers for pointer types
  * postfixoperators: try to apply type helpers for other types
  * factor: check postfixoperators after _REALNUMBER, _CCHAR, _CWCHAR, _TRUE and _FALSE
  * factor: also check postfixoperators if a _POINT follows a _NIL

symdef.pas, tdefawaresymtablestack.addhelpers:
  * use "generate_objectpascal_helper_key" to generate the key
symtable.pas:
  + add function to generate the key value for the map of extended types using the extended def
  * adjust "search_last_objectpascal_helper" and "search_objectpascal_helper" to handle primitive types as well
  * use the new "generate_objectpascal_helper_key" function to generate the key

pparautl.pas:
  * insert_self_and_vmt_para: don't insert the $vmt symbol for record or type helpers (ToDo: check whether class helpers really need the symbol as well)
  * insert_self_and_vmt_para: pass "self" as var parameter for type helpers as well
psub.pas, generate_bodyentry_block: 
  * also allow type helpers for constructor methods
ncal.pas, tcallnode.gen_self_tree:
  * also use a temp variable for type helper constructors
ncgcal.pas, tcgcallnode.secondcallparan:
  * allow Pointers to be passed as address param if it is the Self value of a type helper extending a pointer type
  * correctly handle the location in case of type helper constructors

+ add tests

git-svn-id: trunk@23580 -
2013-02-06 09:49:35 +00:00