overrides but before generating the VMT, so that these hidden parameters
are part of the procdefs stored in the VMT (fixes some LLVM type errors
after r41716)
git-svn-id: trunk@41884 -
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 -
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 -
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 -
+ 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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
+ export parse_proc_dec_finish() from the unit
pgenutil.pas:
* adjust generate_specialization_phase2() to correctly specialize procdefs
git-svn-id: trunk@31772 -
* 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 -
* 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 -
* 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 -
* 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 -
* 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 -
* 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 -
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 -
(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 -
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 -
pgenutil.pas:
* parse_generic_parameters: a ';' terminates a parameter group, so correctly adjust firstidx in that case
+ added test
git-svn-id: trunk@29685 -
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 -
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 -
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 -
pgenutils.pas, check_generic_constraints:
* correctly handle forward defs if the constraint is either a single IInterface/IUnknown or a TObject/class
+ added tests
git-svn-id: trunk@28601 -
pgenutil.pas, generate_specialization:
* also search for the generic type in general if it was previously found in a record/class as there might be a non-generic type (or one with a different number of parameters) defined elsewhere
+ added test
git-svn-id: trunk@28244 -
ptype.pas:
* read_named_type: change hadtypetoken from a value to a var parameter and set it to false if a type helper is parsed so that calling code does not handle it as unique
* read_anon_type: handle that hadtypetoken is now a var parameter
pgenutil.pas, generate_specialization:
* handle that hadtypetoken of read_named_type is now a var parameter
+ added test
git-svn-id: trunk@27870 -
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 -
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 -
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 -
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 -
pgenutil.pas, generate_specializations:
* use splite_generic_name
* use the genericparas list instead of iterating the complete symlist
pgenutil.pas, split_generic_name:
* leave the loop instead of providing an internal error if the right part is not a number
git-svn-id: trunk@25580 -
pgenutil.pas:
+ add new function could_be_generic which checks whether a given symbol name could be a generic (which is determined using the genericdummysyms list for the current module)
pexpr.pas:
* factor: only do a typecheck pass (postfixoperators does one as well) if the found node can not be a generic type
* sub_expr: do a typecheck pass if it isn't a specialization
+ added test
git-svn-id: trunk@25579 -
pgenutil.pas, generate_specialization:
* use "is_generic" instead of "df_generic in defoptions" as nested non generic types will have that flag set as well and thus would be acceptable for the "<...>" notation although no generic version of it exists
ptype.pas, single_type:
* check for nested types after doing a specialization
+ added tests (one for now working case and one for now forbidden case)
git-svn-id: trunk@25578 -
symtable.pas:
+ add new tsymbol_search_flag type which can be passed to various searchsym* routines
+ add support to not call "addsymref"
+ add new searchsym_with_flags function that calls searchsym_maybe_with_symoption
* adjust searchsym_maybe_with_symoption, searchsym_in_class & searchsym_in_helper to use new flag type instead of Boolean arguments
* adjust searchsym & searchsym_with_symoption which call the modified functions
nutils.pas, handle_staticfield_access:
* adjust searchsym_in_class call
pexpr.pas, handle_factor_typenode, postfixoperators, factor:
* adjust searchsym_in_helper and searchsym_in_class calls
pinline.pas, new_function:
* adjust searchsym_in_class call
scanner.pas, try_consume_nestedsym:
* adjust searchsym_in_class call
fmodule.pas, tmodule:
+ add genericdummysyms field which is a TFPHashObjectList that contains TFPObjectList instances per generic dummy that in turn contains tgenericdummysyms instances
pgenutil.pas:
+ add function split_generic_name to split a generic name into non-generic name and count value of type parameters
+ add function resolve_generic_dummysym which tries to use the new genericdummysyms field to find the real symbol of a dummy sym
* generate_specialization: adjust searchsym_in_class call
* specialization_init/specialization_done: save/restore genericdummysyms of module
symdef.pas, tdefawaresymtablestack:
+ add new intermediate method pushcommon which is used by both push and pushafter
+ add new intermediate method remove_helpers_and_generics (which calls remove_generics and remove_helpers if necessary)
* rename removehelpers to remove_helpers
* rename addhelpers to add_helpers_and_generics and extend it to correctly fill current_module.genericdummysyms
* call remove_helpers_and_generics from pop instead of remove_helpers
ptype.pas, single_type, read_named_type.expr_type, read_named_type:
* try to resolve symbols with sp_generic_dummy with resolve_generic_dummysym
+ added test
git-svn-id: trunk@25519 -
pgenutil.pas, parse_generic_parameters:
* set the typesym of the newly created def so that inline specializations in pexpr.pas, sub_expr can check it correctly
git-svn-id: trunk@25410 -
symtype.pas, tdef:
+ add method "fullownerhierarchyname" which allows to retrieve the owner hierarchy name including procedure/function/method names
+ add method "fulltypename" which uses "fullownerhierarchyname" to return a full type name
symdef.pas, tstoreddef:
* implement "fullownerhierarchyname" (including caching of the result)
pgenutil.pas, parse_generic_specialization_types_internal:
* use "tdef.fulltypename" instead of "tdef.typename" to have unique values for each parsed type and thus for the specialization itself
+ tests
git-svn-id: trunk@25175 -
symsym.pas:
- remove "tgenericconstraintdata" and any using/loading/writing of it in "ttypesym"
- remove "tgenericconstraintflag"
symdef.pas:
+ add "tgenericconstraintdata"
+ load and write "genconstraintdata" in "tstoreddef"
symconst.pas:
+ add "tgenericconstraintflag" so it can be used in "ppudump" as well
defcmp.pas, compare_defs_ext:
* as we allow global operator overloads we can't really determine whether two defs are compatible, because a valid operator for the specialization types might just happen to be in scope of the generic; so for now constraints are only strictly checked when declaring a specialization
pgenutil.pas:
* adjust "parse_generic_parameters" and "check_generic_constraints" to the new location of the constraint data
ppudump.pp:
* corrrectly parse defs which contain generic constraints
git-svn-id: trunk@24628 -
symdef.pas, tstoreddef:
+ comment that the list is allocated on demand (and thus should be checked for Nil)
+ fillgenericparas: create the list when adding at least one generic parameter symbol
- create & ppuload: don't create list instance anymore
+ is_generic & is_specialization: check whether the list is assigned
defcmp.pas, compare_defs_ext:
+ check whether "genericparas" list is assigned
pgenutil.pas:
+ check_generic_constraints: check whether "genericparas" is assigned
+ insert_generic_parameter_types: create list before adding generic parameters
git-svn-id: trunk@24627 -
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 -
pgenutil.pas, generate_specialization:
in case of "assigned(parsedtype)" an ">" could immediately follow (only one type parameter), so don't necessarily expect a type identifier
git-svn-id: trunk@23347 -
pgenutil.pas:
generate_specialization:
+ instead of giving an internal error if "symname" is empty and "tt" is "nil" we now do an error recovery by parsing the specialization parameters and returning an errordef (this happens if the "generic" type before the "<" is not found)
* handle "<>" specially by giving an approbiate error message (both when doing a recovery/parsing a generic and during normal specialization)
parse_generic_parameters:
* set the "block_type" to "bt_type" to be on the safe side
* don't continue with inspecting the def (especially hard typecasting) if the found def is not an "objectdef"
Added tests.
git-svn-id: trunk@23344 -
symconst.pas:
+ extend "tdefoptions" by a "df_genconstraint" which will be used to mark dummy defs that should mainly satisfy the compiler's type checking without to much changes
symsym.pas:
+ add a class "tgenericconstraintdata" which will hold information about the constraints associated with a specific generic type parameter (designed for future extensions)
+ extend "ttypesym" by a reference to a "tgenericconstraintdata" which is written to the ppu only if needed
symtype.pas:
+ add a pointer to "tderef" as this is needed for the ppu reading/writing code for the "tgenericconstraintdata"
pdecl.pas, types_dec:
+ call "parse_generic_parameters" so that constraints are allowed
pgenutil.pas:
+ extend "generate_specialization" by a "parsedpos" to give in the file position of the first parsed parameter (needed for correct error locations when checking the constraints)
+ add an overloaded call of "generate_specialization" to differentiate between the use cases "first parameter parsed by generate_specialization" and "first parameter parsed by other code"; this also allows to write the "fillchar" for the "parampos" parameter only once ( => otherwise a warning is triggered => error in compilation)
+ extend the "parse_generic_specialization_types" by a "poslist" parameter which will contain the positions of all parsed type parameters (can only be used in the case that all parameters are parsed)
* move the original code of "parse_generic_specialization_types" to a new procedure "parse_generic_specialization_types_internal" which take an additional "parsedpos" parameter which will be added to the "poslist" before all others; "parse_generic_specialization_types" calls this new procedure with a dummy argument (which won't be used)
+ extend "parse_generic_parameters" by the parsing of generic constraints which constructs correct defs for the parameters and fills in the new "tgenericconstraintdata" object for each parameter (note: the "constructor" constraint is only parsed for Delphi compatibility and basically means the same as a "class" constraint... (it's a relict of Delphi.NET))
* adjust "insert_generic_parameter_types" as specializations and generics can no longer be differed by whether the type parameters are of type "undefineddef"
pdecsub.pas, parse_proc_head, consume_generic_interface:
* adjust call to "generate_specialization"
+ add a new function "check_generic_constraints" which is used from within "generate_specialization" to ensure that the given specialization parameters are compatible with the constraints of the generic parameters
ptype.pas:
* single_type: adjust call to "generate_specialization"
* read_named_type, expr_type: adjust call to "generate_specialization"
+ write_persistent_type_info: don't write typeinfo for constraints
pexpr.pas, sub_expr:
* adjust call to "generate_specialization"
* adjusted ppudump, because of added "tdefoptions.df_genconstraint" value
+ added tests for generic constraints
* modified test for class helper inside a generic which extends a class type parameter
+ added test for record helper inside a generic which extends a record type parameter
git-svn-id: trunk@23158 -
defcmp.pas, compare_defs_ext:
use "equal_defs" instead of a reference comparison to check whether the type defs are equal
pgenutil.pas, insert_generic_parameter_types:
* add to each (specialized) generic parameter the "sp_generic_para" flag so that it will be added to the "genericparas" list upon ppu loading
* add the generic parameter to the genericparas list as well, so that the comparison in "compare_defs_ext" is triggered at all... (up to now the list was always empty -.-)
ppu.pas:
* increase PPU version
git-svn-id: trunk@23149 -
* pgenutil.pas, generate_specialization:
* return a generrordef instead of Nil when returning because of an error
* always check "genname" for a generic count string as a mode ObjFPC generic specialized in a mode Delphi unit will already contain a "$X" suffix and only symname will be set.
+ add (corrected) test
git-svn-id: trunk@22462 -
The cause of the internal error was the following:
We have a generic in an unit ("A") which uses another unit ("B") in the implementation section and this other unit uses unit A in the interface section. Now the generic is specialized in the interface section of B. This leads to the problem that in unit A when it tries to load the globalsymtable of unit B that globalsymtable will be Nil, because parsing of the interface section is not yet finished. Thus the change in pgenutil.pas, specialization_init: if the unit is still "in_interface" the localsymtable needs to be used instead of the globalsymtable.
This doesn't necessarily lead to a compiling test though, as there is the following possibility:
Unit A contains a generic class/record (with methods) and uses unit B in the implementation section. This unit B also contains a generic class/record (with methods) and uses unit A in the implementation section. Both units contain a specialization of the other unit's generic outside of it's own generics (such that generate_specialization is fully triggered). Let's assume compilation starts with unit A and we reach the uses of unit B. Now compilation switches to unit B and completes as unit A is already registered and in compilation. The problem now is that the generic in unit A still contains unresolved forward declarations as the implementation section of A was not yet parsed which will lead to "forward declaration not solved" errors (Note: Delphi compiles this).
The solution to this is the following: if a generic is specialized from another unit which is not in state ms_compiled then the unit of the specialization needs to wait for the unit of the generic. So the specialization's unit adds itself into a list of waiting units of the generic's unit. Now inside "proc_unit" we need to check whether this module is waiting for other modules and if so avoid "finishing" the unit (which means generating the methods of the specialization, generating assembler code and ultimately freeing the scanner and PPU). Now when the generic's unit finishes we need to check whether other modules are waiting for it and finish them (of course it's a bit more complicated in reality, but that pretty much sums it up).
+ globstat.pas: Added an unit which handles the saving and restoring of the global state which was originally inside "parser.pas, compile" so that Don't Repeat Yourself (DRY) is respected.
* fmodule.pas, tmodule:
+ add fields to keep track of the units the module is waiting for and which modules are waiting for the module
+ add field for the saved global state (raw pointer to avoid circles)
+ add field for the state which is needed to finish the unit (raw pointer to avoid circles)
+ move the code which was used in "parser.pas, compile" after a module was successfully compiled to the new virtual method "end_of_parsing"
+ fppu.pas, tppumodule.end_of_parsing:
free the ppufile here
* pgenutil.pas:
+ add new procedure "maybe_add_waiting_unit" which adds the specialization's unit to the waiting list of the generic if that unit is not yet compiled
* generate_specialization: call the new function when we add a new (true) specialization
* specialization_init: instead of not adding implementation units at all check whether the unit is still parsing the interface section and add the localsymtable in that case
* pmodules.pas:
* change "proc_unit" to a function which returns "true" if the unit was already finished (no need to wait for other units)
+ move the code from "proc_unit" from "generate_specialization_procs" on to a new procedure "finish_unit" which
* this procedure is either called immediately in "proc_unit" if the unit does not need to wait for other units or from "finish_unit" itself if a unit that is waiting for the given unit does no longer wait for another module (special care is taken in proc_unit to avoid circles)
* parser.pas, compile:
* correctly handle the case if an unit is not finished
* use the new global state functionality from globstat.pas
* pay special attention when calling "set_current_module" (see comment at that call)
+ add tests from 22160
+ add test for above mentioned "diamond" case
git-svn-id: trunk@22452 -
+ symconst.pas: add a new flag to symtables to mark them as containing at least one generic (will be used to decide whether an expression like "Foo<Bar" should even remotely be considered a specialization)
* utils/ppudump.pp: respect the new flag
* pdecl.pas, types_dec: add the flag for every generic we have parsed
* pgenutil.pas, generate_specialization: add the flag to the specialize symtable if a nested generic set it for the temporary symtable (does not happen currently, but will in the future when nested generics are supported)
+ keep references to all generic para symbols in the def; this way the symtable containing the type parameters does not need to be walked every time we need to do something with the parameters
git-svn-id: trunk@22379 -
pgenutil.pas, specialization_init:
* don't add implementation units of the generic's unit to the symtable stack if we are specializing in a different unit (thus the generic needs to be defined in the interface section) as there is the possibility that the globalsymtable of an implementation unit is not yet defined if the specialization unit is used in the interface section of an implementation unit
git-svn-id: trunk@21763 -
* pgenutil.pas: factor out the reading of generic specialization parameters (parse_generic_specialization_types) and the generation of a generic type name (generate_generic_name)
* pdecsub.pas, parse_proc_head:
* also allow an interface alias declaration if an identifier is followed by a "<" (which starts a specialization)
+ add a procedure "consume_generic_interface" which parses such a specialization (by using "parse_generic_specialization_types") - this is needed, because "consume_generic_type_parameter" can (and should not!) handle "ISomeIntf<Integer, T>" or (somewhen in the future) "ISomeIntf<TSomeOtherGeneric<T>>" - and finds the correct symbol for the interface (by utilizing the "generate_generic_name" function)
* generate the correct mapping entry (for the generic it's only needed for checking (if any), but for a specialization it's essential that we reference the correct specialization)
+ add tests which were included with the issue and also two additional ones
Note: In non-Delphi modes an interface alias can be done like in Delphi mode; "specialization" is not necessary and furthermore not even allowed!
git-svn-id: trunk@21656 -
+ pgenutil.pas:
add a procedure which adds a type symbol to a non-Delphi-mode generic class or record which has the same name as the unit global dummy symbol for that generic. I don't know why I had that idea earlier as this will simplify some of the conditions in the parser again (I haven't changed these yet, but I hope to do that at least when I start working on generic functions).
* pgenutil.pas, generate_specialization:
correctly handle "specialize TSomeGeneric<T>" as method parameter in a generic with the newly added rename symbol
* pdecobj.pas, object_dec & ptype.pas, record_dec:
call the procedure to add the rename symbol (the procedure checks whether the mode is correct)
* ppu.pas:
increase PPU version so that we don't use non-Delphi mode units with generics, but without the rename symbol
+ added tests:
the one in webtbs are for classes/objects and those in test are for records
git-svn-id: trunk@21603 -
* pgenutil.pas, generate_specialization: Correctly change the ownership of extracted symbols and defs by calling ChangeOwner on the symbol/def which does all the magic of changing the owner and adding it to the corresponding list of the given symtable. This fixes Mantis #21550
* Adjusted tw21550.pp so that it enforces the generation of debug information which (as this was the option which caused the above mentioned bug to show)
git-svn-id: trunk@21270 -
When parsing an inline specialization inside a generic we need to
respect the "parsedtype" parameter which tells us whether the first
generic parameter was already parsed. This fixes Mantis #20871 .
+ added test for this
git-svn-id: trunk@20251 -
- Remove unneeded check for "parse_generic" (it's already checked in the outer if-clause).
+ Check whether we are trying to specialize one of the surrounding type declarations of a
nested type (as long as nested generics are forbidden this is always the outermost generic
or specialization). This check can not rely on the symbol, because while parsing the
generic or the specialization the symbol's def is still an errordef. This fixes
Mantis #19498 .
+ Added test from bug report.
git-svn-id: trunk@20247 -
When specializing a generic the references from unitsyms to the loaded modules
needs to be reestablished, so that "unitidentifier.identifier" can be used
inside a generic without leading to an access violation.
Only global units are checked, because a generic must not use symbols from the
static symtable or from units used by the implementation section (the latter is
currently not checked)
+ added tests for the above problem for "normal" units as well as units with a namespace
git-svn-id: trunk@20245 -
* When building the typename for a generic use the full typename
including it's surrounding object- or abstractrecorddefs. This allows
that a nested non-generic type of a generic type A can be used as
type arguments for more than one specialization of another generic B
(there were some problems when B e.g. defined a pointer to the type
argument's type)
* Always CRC the constructed specialization name as otherwise it might
reach the limit of 255 characters (not yet including unit name,
method name or method arguments)
Note: Errors like "expected XYZ, but got ABC" will need to be
adjusted to use the prettyname...
* increased PPU version
+ added test for above's point 1
git-svn-id: trunk@20149 -