Commit Graph

219 Commits

Author SHA1 Message Date
svenbarth
39016c032e Fix for Mantis #28442. Do not generate the VMT record definition for generic classes. It isn't used anyway.
nobj.pas, TVMTBuilder:
  * generate_vmt_def: check for df_generic (not is_generic!) and abort if set

+ added test

git-svn-id: trunk@31301 -
2015-08-07 15:02:55 +00:00
Jonas Maebe
6f5905684f + support for specifying the name of fields added to anonymous record
types that are constructed on the fly by the high level typed const
    builder

git-svn-id: trunk@31249 -
2015-07-30 16:57:58 +00:00
Jonas Maebe
b55c7df996 * factored out internal type prefixes
git-svn-id: trunk@31248 -
2015-07-30 16:57:55 +00:00
Jonas Maebe
508828958c * changed getprocaddressprocvar() into a tprocvardef.getreusableprocaddr()
class method

git-svn-id: trunk@31148 -
2015-06-23 21:23:22 +00:00
Jonas Maebe
3f736f6114 * handle the loading of VMT entries at the node level, so it's done in a
type-safe way (for LLVM, and also internal consistency checking between
    the VMT as generated in nobj.pas and ncgvmt.pas)
   o also converted the VMT validity checking to the node level

git-svn-id: trunk@30950 -
2015-05-31 16:50:47 +00:00
nickysn
89e9fac562 * TVMTBuilder.intf_allocate_vtbls: fixed the Ioffset calculation in i8086 far
data memory models

git-svn-id: trunk@27728 -
2014-05-03 17:05:50 +00:00
Jonas Maebe
43992495cb * moved jvm tprocdef name mangling to jvm-specific descendant class
git-svn-id: trunk@27395 -
2014-03-30 21:04:29 +00:00
sergei
d54d38b4ab * Moved all code responsible for writing VMTs and interface wrappers (nobj.TVMTWriter, ncgutil.gen_intf_wrappers, ptype.write_persistent_type_info) into a new unit ncgvmt.pas.
This improves compiling speed a bit (two iterations over symtables replaced by one, code generator is created once per unit rather than once per class).
In perspective it makes possible to reduce amount of generated smartlink sections and global labels.

git-svn-id: trunk@24269 -
2013-04-19 13:31:27 +00:00
florian
63f6afffd5 + make empty proc. removal switchable by removeemptyprocs
git-svn-id: trunk@23621 -
2013-02-14 21:40:04 +00:00
florian
4d3df8f518 * stupid typo in TVMTWriter.RedirectToEmpty fixed, resolves #23763
git-svn-id: trunk@23569 -
2013-02-03 22:02:02 +00:00
Jonas Maebe
e7315d035c * inherit po_auto_raised_visibility flag when the visibility of a method is
raised because it was automatically raised in the parent class (can happen
    for the JVM target when letting the compiler generate getters/setters for
    properties)

git-svn-id: trunk@23522 -
2013-01-26 16:52:28 +00:00
sergei
ad1621df3f * Revert part of r22548, correct fix for the issue is provided by r23188.
Only referencing data labels from code should change "GOT is needed" property. Writing data labels or referencing them from data should have no effect on it.

git-svn-id: trunk@23363 -
2013-01-11 15:31:12 +00:00
florian
198907797b * don't replace vmt entries of empty methods by FPC_EMPTYMETHOD
if the code is compiled for x86 and returns the result in an fpu register

git-svn-id: trunk@23304 -
2013-01-03 23:01:07 +00:00
florian
24f518f232 + redirect calls to empty virtual methods to FPC_EMPTYMETHOD
* do empty subroutine/method optimization only for O2 and higer

git-svn-id: trunk@23276 -
2013-01-01 16:43:27 +00:00
Jonas Maebe
4aa05f5133 + support for automatically generating setters/getters for properties on the
JVM target, since Java bytecode itself has no support for properties and
    hence exposing properties to external Java code can only be done through
    getters/setters. Use the new parameters to do so:
      -CTautogetterprefix=XXX
      -CTautosetterprefix=YYY
    The getter/setter will get the same visibility as the property. If a
    getter/setter with the same naming convention was already specified for a
    property and this getter/setter is declared in the same class as the
    property, then the visibility of this existing getter/setter is
    modified and no new routine is generated.

    Newly generated getters/setters are virtual methods, because that is
    the only way in Java bytecode to allow redefining these getters/setters
    in child classes. However, that also means that using these switches can
    change the behvaviour of code, since normally the used property definition
    is only determined by the declared type of its associated class instance,
    and not by the actual instance type. The compiler will therefore warn when
    such an automatically generated getter/setter is overridden by another
    automatically generated getter/setter in a child class.

git-svn-id: trunk@22959 -
2012-11-08 20:18:08 +00:00
pierre
78d31eb3cd Add missing of pi_needs_got found by sparc compiler compiled with -dCHECK_PIC
git-svn-id: trunk@22548 -
2012-10-05 15:02:47 +00:00
Jonas Maebe
fe90823b01 * support the "overload" modifier for Objective-C methods
* only check whether the message identifier of an Objective-C method
    matches the one from a method with the same name in a parent class
    if the parameters match (todo: should be refined to "if the
    encoded Objective-C selector names match")

git-svn-id: trunk@22373 -
2012-09-11 21:58:40 +00:00
Jonas Maebe
c2be657671 * give an error instead of a note on the JVM target when overriding a
method by one with a lower visibility, because calling the overriding
    method results in a java.lang.AbstractMethodError in that case

git-svn-id: trunk@21839 -
2012-07-10 09:20:11 +00:00
Jonas Maebe
50659b7e7f * give an error if a routine definition defines default values for
parameters that do not appear in forward/interface definitions
    (mantis #19434)
  * added test for #17136 already works

git-svn-id: trunk@21524 -
2012-06-07 22:36:39 +00:00
Jonas Maebe
834026bfb5 * synchronised with trunk up to r21067
git-svn-id: branches/jvmbackend@21068 -
2012-04-26 21:24:20 +00:00
Jonas Maebe
6502717e67 * align all code/data sections to sizeof(pint), instead of sometimes
to 0 or 1 (section alignment <> alignment of individual data
    elements in section on some platforms, such as AIX)
  * set constalignmin and varalignmin to 8 bytes for AIX/ppc64

git-svn-id: trunk@21044 -
2012-04-25 20:27:41 +00:00
Jonas Maebe
aee5380ae0 * merged trunk up to r20882
o support for the new codepage-aware ansistrings in the jvm branch
   o empty ansistrings are now always represented by a nil pointer rather than
     by an empty string, because an empty string also has a code page which
     can confuse code (although this will make ansistrings harder to use
     in Java code)
   o more string helpers code shared between the general and jvm rtl
   o support for indexbyte/word in the jvm rtl (warning: first parameter
     is an open array rather than an untyped parameter there, so
     indexchar(pcharvar^,10,0) will be equivalent to
     indexchar[pcharvar^],10,0) there, which is different from what is
     intended; changing it to an untyped parameter wouldn't help though)
   o default() support is not yet complete
   o calling fpcres is currently broken due to limitations in
     sysutils.executeprocess() regarding handling unix quoting and
     the compiler using the same command lines for scripts and directly
     calling external programs
   o compiling the Java compiler currently requires adding ALLOW_WARNINGS=1
     to the make command line

git-svn-id: branches/jvmbackend@20887 -
2012-04-15 15:54:10 +00:00
sergei
429af6f40b * nobj.pas, finished refactoring VMT generation code, now all child structures except RTTI are written to same data section with VMT itself and their labels are local (since child structures are accessible only through VMT, smartlinking them into different sections is useless).
* Reference GUID/string labels of implemented interfaces instead of duplicating them on every occurrence.

git-svn-id: trunk@20344 -
2012-02-13 18:49:48 +00:00
sergei
3eeca2b172 * Emit published method table into single object section (previously every method name was written into a section of its own), labels for method names no longer have to be global.
* Pass target asmlist as parameter to genpublishedmethodstable and generate_field_table.
* Omit field table if there are no published fields (Delphi compatible).

git-svn-id: trunk@20310 -
2012-02-11 13:51:29 +00:00
sergei
3b006c4a9c nobj.pas, cleanup/refactoring:
- removed empty destructors, overriding destructor without calling inherited is incorrect (although harmless here).
* pass target asmlist as parameter to message table generation procedures, instead of using global variables.

git-svn-id: trunk@20303 -
2012-02-11 09:27:03 +00:00
Jonas Maebe
3b47c40ed2 * check whether methods that implement interface methods are public
or published, because interface methods are always public and
    hence mapping them to a private/protected method increases the
    visibility of the underlying method (error on JVM target because
    the JVM doesn't like that, warning on other platforms)

git-svn-id: branches/jvmbackend@19156 -
2011-09-19 21:22:44 +00:00
Jonas Maebe
c163a327d7 * fixed abstract method accounting for external Objective-C/Java classes:
in that case if an "override" directive is missing but we interpret
    the declaration as an "override" anyway, make sure to replace the vmtpd
    with the overriding definition or child classes will keep seeing
    the abstract method in the base class and keep decreasing their abstract
    method count below zero
  * only decrease the abstract method count in case we're not processing
    category methods

git-svn-id: branches/jvmbackend@18923 -
2011-08-31 19:20:59 +00:00
Jonas Maebe
18310034d7 * never allow hiding an inherited virtual class method or virtual constructor
by a non-virtual classmethod/constructor on the JVM target, because they
    would also be picked up by the dynamic dispatch

git-svn-id: branches/jvmbackend@18713 -
2011-08-20 08:26:57 +00:00
Jonas Maebe
ee75bfaaf4 * change non-virtual instance methods to "virtual; final;" methods on the
JVM target, because that's the only way to guarantee their semantics on
    that platform (see comments in pdecobj)
  * allow starting new inheritance trees (which is the same as adding a new
    non-virtual method as of this revision) on the JVM target in case the
    parameters of the new routine match the old one, but the complete mangled
    name does not (because then the JVM won't consider them to be the same
    either -> Pascal semantics are matched)

git-svn-id: branches/jvmbackend@18695 -
2011-08-20 08:25:24 +00:00
Jonas Maebe
7e7bdc3c55 * make the real name of methods implementing interface methods the same as
as the real name of the declaration in the interface, so that the JVM
    case-sensitive mapping works out
  * process the interface mappings for the compiler-constructed classes for
    enums and procvars

git-svn-id: branches/jvmbackend@18693 -
2011-08-20 08:25:14 +00:00
Jonas Maebe
586d4f4108 * fixed keeping track of the number of abstract methods in external classes
git-svn-id: branches/jvmbackend@18676 -
2011-08-20 08:23:39 +00:00
Jonas Maebe
6154f1b0d9 * keep track of the number of abstract methods per class via a counter
* use this counter to mark classes containing abstract methods as
    "abstract" in the bytecode per the JVM spec
  * also use the counter to short-circuit printing of all abstract
    methods in a class when creating a new instance (we build the list
    of abstract methods every time a new instance is created, which is
    a waste of time if there are none in the first place)

git-svn-id: branches/jvmbackend@18635 -
2011-08-20 08:17:12 +00:00
Jonas Maebe
d6a56cfda6 * change the realname of procsyms belonging to overriding methods to
that of the overridden method for Java classes, since the realname
    is used as method identifier (and overriding is name-based and
    case-sensitive in Java)

git-svn-id: branches/jvmbackend@18464 -
2011-08-20 08:02:02 +00:00
Jonas Maebe
fc2d239f95 * fixed checking for missing "override" for Java code
git-svn-id: branches/jvmbackend@18438 -
2011-08-20 07:59:35 +00:00
Jonas Maebe
5f17c0e970 * do not check whether all interface methods are implemented in abstract
Java classes. TODO: do perform this check in the first non-abstract
    Java class that descends from such classes

git-svn-id: branches/jvmbackend@18402 -
2011-08-20 07:56:38 +00:00
Jonas Maebe
28740dce2d - removed extra "fordefinition" parameter again from tprocdef.mangledname(),
since the definition-specific adorning of JVM mangled names is Jasmin-
    specific, and such code has no place in symdef
  * moved code to adorn JVM mangled names for Jasmin definitions to agjasmin

git-svn-id: branches/jvmbackend@18346 -
2011-08-20 07:49:31 +00:00
Jonas Maebe
83dc297346 + Java interface support, mostly the same as Objective-C protocols
(generalised some error messages that were specific to protocols
     so they can also be used for Java interfaces)
  o note, Java interface support requires a fix to Jasmin 2.4:
    http://sourceforge.net/tracker/?func=detail&aid=2897170&group_id=100746&atid=628212

git-svn-id: branches/jvmbackend@18344 -
2011-08-20 07:49:19 +00:00
Jonas Maebe
0ee702b3a2 * tprocdef.mangledname now gets an extra boolean parameter indicating
whether the mangled name is for defining a symbol, or for referencing
    it later (e.g. for a call or load of its address). The reason is that
    on the JVM both cases are different.
  + jvmdef unit to encode types according to the JVM rules
  + tprocdef.jvmmangledname() to encode a procdef's JVM mangled name
    (the common part of defining/referencing it; tprocdef.mangledname
     afterwards adorns it as required)

git-svn-id: branches/jvmbackend@18288 -
2011-08-20 07:22:00 +00:00
sergei
25bf0012f2 * When the interface method mapping is present, being unable to find the implementing procedure using the mapped name is a error condition. No attempt to find implementing procedure using symbol name should be made in this case. Resolves #19591.
git-svn-id: trunk@18166 -
2011-08-10 21:33:39 +00:00
florian
589d061c3d * when comparing overridden methods, ignore hidden parameters because overridden methods does not
need to repeat a calling convention specifier so if the calling convention specifier 
  influences the hidden parameters, the methods are not considered equal, resolves #19159

git-svn-id: trunk@17832 -
2011-06-26 12:34:59 +00:00
sergei
7d99f95c45 * Always create a section before emitting data to current_asmdata.asmlists[al_typedconsts]. Without it, such data ends up in sections created elsewhere, creating very non-obvious dependencies on other parts of compiler.
git-svn-id: trunk@17816 -
2011-06-24 02:05:56 +00:00
svenbarth
f7f357f18e * symconst.pas:
- remove thelpersearch again => adjustments to searchsym_in_class and calls to it
- rename sto_has_classhelper to sto_has_helper
* symbase.pas: make push and pop in tsymtablestack virtual
* symdef.pas:
- add a new class tdefawaresymtablestack which overrides push and pop of tsymtablestack and adjusts the new extendeddefs field of the current tmodule
- tobjectdef.create: sto_has_classhelper => sto_has_helper
* fmodule.pas:
- add new hash object list to tmodule (key: mangled type name) which holds object list instances that contain all helpers currently active for a given type (= key of the hash list)
- tmodule.create: the hash list owns the sublists (but those don't own the defs)
- tmodule.destroy: free the hash list
* pdecobjpas:
- rename parse_extended_class to parse_extended_type
- parsing of constructors:
# for all helper types: no class constructors allowed
# for record helpers: as long as constructors for records themselves are disabled they are for record helpers as well
- object_dec: manually add the helper to the extendeddefs if the overall owner of the current def is a static symtable (implementation section or program/library main file), because the symtable won't be popped and pushed then
* parser.pas: instantiate the new stack class
* psub.pas: backup the extendeddefs in specialize_objectdefs as well
* ptype.pas:
- generate_specialization: backup the extendeddefs as well
- record_dec: _RECORD is now consumed in read_named_type itself
- read_named_type: parse "record helper" if advanced record syntax is enabled
* symtable.pas:
- correct searchsym_in_class declaration => adjustments in this unit as well
- add the possibility to pass a context def to search_last_objectpascal_helper
- rename search_objectpascal_class_helper to search_objectpascal_helper
- rename search_class_helper to search_objc_helper
- searchsym_in_class: 
# search for helpers in every level of the tree of the class
# the contextclassh can also be a subclass of the extendeddef
- searchsym_in_record: search for helper methods as well
- searchsym_in_helper:
# search for symbols in class and record helpers is the same except for the search in the class' ancestors
# search the extendeddef directly and rely on searchsym_in_class only for the class' ancestors as we need to find the helpers there as well
- search_last_objectpascal_helper: use the extendeddefs list of current_module instead of scanning the symbol stack itself
* pexpr.pas: adjustments because of renaming of sto_has_classhelper
* pinline.pas: adjustment because of removing of thelpersearch
* nflw.pas: 
- renamed classhelper to helperdef
- adjusted search_last_objectpascal_helper call
* msg*:
- adjusted error message for constructors in records (this currently applies to record helpers as well)
- renamed parser_e_not_allowed_in_classhelper to parser_e_not_allowed_in_helper => adjustments in code
- added parser_e_no_class_constructors_in_helpers
* pdecsub.pas: adjusted renamed error message
* htypechk.pas: check for helpers in every step of the hierarchy
* nobj.pas: search_class_helper => search_objc_helper
* utils/ppudump.pas: adjust, because of renames

Note: the define "useoldsearch" will be only used for performance comparison on my (faster) Linux machine; that (and its associated code) will be removed afterwards

git-svn-id: branches/svenbarth/classhelpers@17151 -
2011-03-20 11:27:27 +00:00
svenbarth
96116a6c3a Several adjustments because virtual methods in helpers are just normal methods and a VMT isn't generated for them either.
* $CPU/cgcpu.pas: disable the generation of VMT loading code
* dbgstabs.pas, dbgdwarf.pas: treat virtual methods of helpers as normal methods
* ncgcal.pas: don't register virtual helper methods for WPO 
* ncgrtti.pas: write virtual helper methods as normal methods to RTTI
* nobj.pas: correctly handle final and override cases in helpers
* pdecvar.pas: property getters
* rautils.pas: no VMT offset in records

git-svn-id: branches/svenbarth/classhelpers@17150 -
2011-03-20 10:41:45 +00:00
paul
dc5f5c3f63 compiler: use current_structdef instead of current_objectdef in more places
git-svn-id: trunk@16658 -
2010-12-30 06:46:06 +00:00
paul
56bf42de57 compiler: implement record methods and class methods:
- rename tprocdef._class to tprocdef.struct and change the type from tobjectdef to tabstractrecorddef because methods can belong not to classes only now but to records too
  - replace in many places use of current_objectdef to current_structdef with typcast where is needed
  - add an argument to comp_expr, expr, factor, sub_expr to notify that we are searching type only symbol to solve the problem with records,objects,classes which contains fields with the same name as previosly declared type (like:
  HWND = type Handle;
  rec = record 
    hWnd: HWND;
  end;)
  - disable check in factor_read_id which was made for object that only static fields can be accessed as TObjectType.FieldName outside the object because it makes SizeOf(TObjectType.FieldName) imposible and since the same method was extended to handle records it also breaks a52 package compilation
  - rename tcallcandidates.collect_overloads_in_class to tcallcandidates.collect_overloads_in_struct and addapt the code to handle overloads in records too
  - fix searchsym_type to search also in object ancestors if we found an object symtable
  - add pd_record, pd_notrecord flags to mark procedure modifies which can or can't be used with records. Disallow the next modifiers for records: abstract, dynamic, export, external, far, far16, final, forward, internconst, internproc, interrupt, message, near, override, public, reintroduce, virtual, weakexternal,
Allow the next modifiers for records: static

git-svn-id: branches/paul/extended_records@16526 -
2010-12-09 02:24:46 +00:00
paul
d9a43f7858 compiler: cleanup
git-svn-id: trunk@16488 -
2010-12-01 07:40:09 +00:00
tom_at_work
8a2696eb24 * limit the number of string message methods per class to 2^31 independent of architecture width: this avoids lots of compiler changes when allowing 2^63 (for 64 bit targets)
* fix string message method handling data structures to reflect this change, and also use the correct types for accessing them (longint vs. dword)
* output proper alignment code for string message method data structures to avoid issues on big-endian 64 bit architectures or architectures requiring proper alignment
* same for integer message methods; also, like string message method data structures, do not use packed records for them when accessing
* extend the test case (tw14145) do do multiple message dispatches, both integer and string ones, to complete successfully

git-svn-id: trunk@16254 -
2010-10-29 13:26:50 +00:00
Jonas Maebe
92a53a9cf1 * moved initialisation of overridesclasshelper "out" parameter to correct
place (was in a nested procedure instead of in the main one, fix for
    r16035)

git-svn-id: trunk@16039 -
2010-09-24 23:48:14 +00:00
Jonas Maebe
1633341906 * treat methods added via an objccategory to an objcclass in exactly the
same way as regular methods as far as overriding is concerned ("override"
    is now allowed, and even required, to override them in a descendent class;
    and similarly, "reintroduce" must be used if a category wants to replace
    a method in a child class if that method was  added by another category in
    a parent class)
  * print the name of owning objcclass/category of the original method in case
    override/reintroduce is missing for objc methods, since this is no longer
    always the parent class

git-svn-id: trunk@16035 -
2010-09-22 21:26:58 +00:00
florian
0712dbe25d * white space fixes
git-svn-id: trunk@15709 -
2010-08-05 19:11:25 +00:00