Skip to content
  • Sven/Sarah Barth's avatar
    Added support for partial specialization. This should fix a few problems with... · 639a59df
    Sven/Sarah Barth authored
    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 -
    639a59df