Commit Graph

35014 Commits

Author SHA1 Message Date
Jonas Maebe
ad871b6acd * automatically generate versions of inherited virtual class methods that
call through to the parent method in case they are not overridden in
    the child class, because otherwise the dynamic dispatch fails (looking
    up a class method only checks that particular class, since they are
    never virtual in Java and hence not inherited either)

git-svn-id: branches/jvmbackend@18715 -
2011-08-20 08:27:07 +00:00
Jonas Maebe
57c7e21d8f * support propagating a function result (if any) from functions called
via tsk_anon_inherited synthetic functions

git-svn-id: branches/jvmbackend@18714 -
2011-08-20 08:27:02 +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
7419c97e0a * do not call the virtual class method/constructor dispatching lookup
when calling the inherited version, since that one is also known at
    compile time

git-svn-id: branches/jvmbackend@18712 -
2011-08-20 08:26:52 +00:00
Jonas Maebe
ddf6591f7f + support "reintroduce" for Java classes. Although in most cases this won't
work because you cannot start new inheritance trees, it can work under some
    circumstances if the parameters are not exact. In case there is a problem,
    this will be detected later by TVMTBuilder.is_new_vmt_entry().

git-svn-id: branches/jvmbackend@18711 -
2011-08-20 08:26:46 +00:00
Jonas Maebe
1d0388d40a + support for virtual constructors for the JVM platform. We simply
create a virtual class (factory) method that calls the constructor,
    and then let the existing support for virtual class methods handle
    everything

git-svn-id: branches/jvmbackend@18710 -
2011-08-20 08:26:40 +00:00
Jonas Maebe
e38cfc307b * renamed pc_procvar2bareproc to pc_bareproc, and allow it also to
be used to create bare procdef->procdef copy

git-svn-id: branches/jvmbackend@18709 -
2011-08-20 08:26:35 +00:00
Jonas Maebe
2a9043f4bc * keep the node flags when replacing a call to a virtual class method with
a call to its wrapper

git-svn-id: branches/jvmbackend@18708 -
2011-08-20 08:26:30 +00:00
Jonas Maebe
e9d27c3efe * mark copied virtual parent constructors as "override"
git-svn-id: branches/jvmbackend@18707 -
2011-08-20 08:26:26 +00:00
Jonas Maebe
f20e206849 * make compatible_childmethod_resultdef() also work for Java classes
(so that you can override a method in a child class with one that
     returns a descendent of the original return type -- since the JVM
     will always select the version with the most specific return type,
     that even corresponds perfectly to standard JVM behaviour)

git-svn-id: branches/jvmbackend@18706 -
2011-08-20 08:26:21 +00:00
Jonas Maebe
3eb588cca7 * some improvements to replace_scanner():
o also save/restore orgpattern (and restore pattern) when saving/restoring
     the scanner state, since it's used by e.g. the _INTCONST token
   o also bail out on _CWCHAR and _CWSTRING tokens, since that requires saving
     the scanner widestring state

git-svn-id: branches/jvmbackend@18705 -
2011-08-20 08:26:16 +00:00
Jonas Maebe
7d8cbe80f5 + support for virtual class methods on the JVM platform. The JVM does not
support those natively, so they are emulated via the procvar infrastructure
    (and hence not very fast). Could probably be optimized somewhat by adding
    a cache (hashmap of procvars) to the class hierarchies, maybe in the
    future.

git-svn-id: branches/jvmbackend@18704 -
2011-08-20 08:26:11 +00:00
Jonas Maebe
cd6b8b9dd1 * correctly create procvars for procdefs that have an import_name set
git-svn-id: branches/jvmbackend@18703 -
2011-08-20 08:26:05 +00:00
Jonas Maebe
1ac7146182 * synchronised code of fpc_ansistr_to_chararray() with
fpc_shortstr_to_chararray()
  * same for fpc_unicodestr_to_chararray() + fixes

git-svn-id: branches/jvmbackend@18702 -
2011-08-20 08:26:00 +00:00
Jonas Maebe
02f443ce68 * support source/destinationshortstrings of different length in
ShortStringClass.FpcDeepCopy (can happen when copying value
    parameters like string[4] into local storage in case a string
    longer than 4 characters was passed)
  * create chararray of the correct maximum length when constructing
    a chararray from a constant string
  * don't pass invalid ranges to JLArrays.fill() when padding a
    chararray after filling it using the contents of shortstring

git-svn-id: branches/jvmbackend@18701 -
2011-08-20 08:25:54 +00:00
Jonas Maebe
5a1bca3b75 * small optimization
git-svn-id: branches/jvmbackend@18700 -
2011-08-20 08:25:49 +00:00
Jonas Maebe
249b56d742 * fixed calling non-static class methods via procvars: since we can't known
on the caller side whether it's a normal or class method that we are
    calling, add the self-class parameter inside the invoke method if
    necessary (by simply counting the number of parameters and inserting
    it if we're one short)

git-svn-id: branches/jvmbackend@18699 -
2011-08-20 08:25:44 +00:00
Jonas Maebe
d8977b0342 - disabled the set constant caching via static variables for now because
their initialization can cause races between the unit they are declared
    in and the class constructor they are initialized in (even if both
    would be moved to the unit initialization code, a class constructor
    using the set constant could run before the unit initialization code has
    run)

git-svn-id: branches/jvmbackend@18698 -
2011-08-20 08:25:39 +00:00
Jonas Maebe
c8c75d7e1d * convert non-constant enums in in-expressions to longint if we use the
generic jumps code

git-svn-id: branches/jvmbackend@18697 -
2011-08-20 08:25:33 +00:00
Jonas Maebe
478a0376e3 * make sure that wrapped methods for property accesses are added to the
symtable of the current structdef

git-svn-id: branches/jvmbackend@18696 -
2011-08-20 08:25:29 +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
4074bf412b - removed po_java procoption, since it wasn't really used for anything
git-svn-id: branches/jvmbackend@18694 -
2011-08-20 08:25:19 +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
4557938e62 - removed no longer needed/used {$ifndef nounsupported} code
git-svn-id: branches/jvmbackend@18692 -
2011-08-20 08:25:08 +00:00
Jonas Maebe
4363a0633e * use procdef.defid instead of procdef.procsym.symid to make local typed
constant names unique, since the symid is the same for overloads

git-svn-id: branches/jvmbackend@18691 -
2011-08-20 08:25:03 +00:00
Jonas Maebe
979f55e1db + support for procedural variables for the JVM target
o every porocedural variable type is represented by a class with one
     public "invoke" method whose signature matches the signature of the
     procvar
   o internally, dispatching happens via java.lang.reflect.Method.invoke().
     WARNING: while this allows calling private/protected or other methods
     that are normally not accessible from another context, a security
     manger can override this. If such a security manager is installed,
     most procvars will cause security exceptions
   o such dispatching also requires that all arguments are wrapped, but
     that's done in the compiler-generated body of the invoke method,
     so that procvars can also be called conveniently from Java code
   o typecasting between a procedure of object and tmethod is supported,
     as well as Delphi-style replacing of only the method pointer via
     @procvar1=@procvar2.
   o nested procvars are not yet supported, but most of the basic
     infrastructure for them is already present
  * all units/programs now get an internal __FPC_JVM_Module_Class_Alias$
    type when compiled for the JVM target, which is an "external" class
    that maps to the unit name. This is required to look up the
    JLRMethod instances for regular functions/procedures
  + new tabstractprocdef.copyas() method that allows to create a procvar
    from a procdef and vice versa

git-svn-id: branches/jvmbackend@18690 -
2011-08-20 08:24:58 +00:00
Jonas Maebe
b526505bbf * use paramanager.push_copyout_param() instead of duplicated/hardcoded logic
to determine whether a parameter will be wrapped via an array or not in
    tprocdef.jvmmangledbasename()

git-svn-id: branches/jvmbackend@18689 -
2011-08-20 08:24:50 +00:00
Jonas Maebe
8fcc88d763 * searchsym_in_named_module() for searching in the module we are currently
compiling

git-svn-id: branches/jvmbackend@18688 -
2011-08-20 08:24:45 +00:00
Jonas Maebe
69abbba6bb * split several parameter insertion helpers out from pdecsub for
easier reuse elsewhere

git-svn-id: branches/jvmbackend@18687 -
2011-08-20 08:24:40 +00:00
Jonas Maebe
b8286c729a * always write constant values as signed values, since the JVM does not support
unsigned values (and Jasmin therefore extends them to the next larger size
    if they become too big)

git-svn-id: branches/jvmbackend@18686 -
2011-08-20 08:24:34 +00:00
Jonas Maebe
834f8da885 + added extra parameter to jvmgetboxtype() to indicate whether all integer
types should be mapped onto jllong or rather onto the closes matching type

git-svn-id: branches/jvmbackend@18685 -
2011-08-20 08:24:29 +00:00
Jonas Maebe
61fd6ca4ee * zero-extend small unsigned integer parameters on function *entry*, because
the functions may be called from Java code or indirectly and in that case
    there's no way to guarantee that they'll be zero-extended on the caller
    side

git-svn-id: branches/jvmbackend@18684 -
2011-08-20 08:24:24 +00:00
Jonas Maebe
4e0ffdebfd * FPCJDynArrTypeEnumSet/FPCJDynArrTypeBitSet support in fpc_dynarray_copy()
git-svn-id: branches/jvmbackend@18683 -
2011-08-20 08:24:20 +00:00
Jonas Maebe
e61bc16799 - remove nounsupported ifdefs for formaldef handling
git-svn-id: branches/jvmbackend@18682 -
2011-08-20 08:24:12 +00:00
Jonas Maebe
cef61300ff + ttgobj.gethltemptyped() routine for allocating managed types with high level
code generator support
  * refactored some internal temp generator code

git-svn-id: branches/jvmbackend@18681 -
2011-08-20 08:24:07 +00:00
Jonas Maebe
085d0efead * some fixes for fake procvar support
git-svn-id: branches/jvmbackend@18680 -
2011-08-20 08:24:02 +00:00
Jonas Maebe
34bfe0bbfd * reparsed with varags -> const open array change
git-svn-id: branches/jvmbackend@18679 -
2011-08-20 08:23:56 +00:00
Jonas Maebe
35cb8516ff + support for detecting varargs functions -> mark their open array
parameters as const, since the callee cannot modify the array
    itself in that case

git-svn-id: branches/jvmbackend@18678 -
2011-08-20 08:23:51 +00:00
Jonas Maebe
e30319561f * correctly set the external name of nested classes (should not
include the parent class names, those are added by the compiler)

git-svn-id: branches/jvmbackend@18677 -
2011-08-20 08:23:45 +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
d6966e545b + support for formal var/out parameters on the JVM target:
o primitive types are first boxed
   o the parameter is passed inside an array of one class instance
   o changing the parameter inside the routine (by assigning a value to it
     like in Delphi.NET and different from regular Pascal code) will replace
     this class instance (again boxing the value if required)
   o on return, the class instance is extracted, unboxed if required, and
     assigned back to the original location
   o formal const parameters are handled without the extra array indirection,
     since they cannot be changed

  TODO: while writing tjvmcallparanode.handleformalcopyoutpara() I forgot that
    calling getcopy on ttemprefnodes whose ttempcreatenode hasn't been copied
    yet works fine, so that code is more complex than needed. Still have to
    fix.

git-svn-id: branches/jvmbackend@18675 -
2011-08-20 08:23:33 +00:00
Jonas Maebe
5bf16214cd * changed initialization of records from constructing a new instance and
copying that over the old one into calling a dedicated fpcInitializeRec()
    method that initializes the required fields. The reason is that this
    initialization is performed for out-parameters, and the fpcDeepCopy()
    method (used to copy one instance over another) has an out-parameter
    -> infinite loop

git-svn-id: branches/jvmbackend@18674 -
2011-08-20 08:23:27 +00:00
Jonas Maebe
b52dcd4a56 * changed var-parameter of secondpass() into a value parameter: secondpass
should never change any nodes, and this allows passing properties to
    secondpass

git-svn-id: branches/jvmbackend@18673 -
2011-08-20 08:23:22 +00:00
Jonas Maebe
40cf2cefa0 * when the user calls initialize(), force initialization to happen on the
JVM platform (normally it's not necessary because all types are
    automatically initialized)

git-svn-id: branches/jvmbackend@18672 -
2011-08-20 08:23:16 +00:00
Jonas Maebe
d0663411a5 * fixed order of operands on the jvm stack in case of a setlength(x,0) call
for a static field

git-svn-id: branches/jvmbackend@18671 -
2011-08-20 08:23:10 +00:00
Jonas Maebe
ff37507bca * save/result nestsym to ppufile for inline routines
git-svn-id: branches/jvmbackend@18670 -
2011-08-20 08:23:04 +00:00
Jonas Maebe
3a983d8ea5 * also escape the field names of records when used as source in fpcDeepCopy()
git-svn-id: branches/jvmbackend@18669 -
2011-08-20 08:22:59 +00:00
Jonas Maebe
7286e3b645 * when determining the type to use for checkcast, first always dereference
pointers to implicit pointer types so that afterwards we can set the
    appropriate corresponding class type

git-svn-id: branches/jvmbackend@18668 -
2011-08-20 08:22:52 +00:00
Jonas Maebe
6cced31157 * treat conversions involving arrays of sets also as pointer conversions
git-svn-id: branches/jvmbackend@18667 -
2011-08-20 08:22:47 +00:00
Jonas Maebe
94be1980b4 * fixed type conversions between signed and unsigned ordinals of the same
size when stored in memory

git-svn-id: branches/jvmbackend@18666 -
2011-08-20 08:22:42 +00:00