Commit Graph

99 Commits

Author SHA1 Message Date
Jonas Maebe
cf47b8d422 * fixed all known memory leaks in the code added for the JVM port
git-svn-id: branches/jvmbackend@19248 -
2011-09-26 19:31:34 +00:00
Jonas Maebe
26b19274a3 + create an nested interface type called "Callback" inside the classes that
are used to implement procvar types, and add a constructor to the procvar
    types that accept an instance implementing this interface -> much easier
    and more natural to use procvar types from Java code

git-svn-id: branches/jvmbackend@19216 -
2011-09-24 20:32:01 +00:00
Jonas Maebe
125c0cf225 + support for generics on the JVM target:
o don't try to create .class files for generic types
   o still generate all JVM-specific wrappers for generic types even though they
     won't be written out, because when specializing all the defid's have to
     match exactly
   o add synthetic routine implementations after generating the specializations,
     so that the synthetic routines for those specializations are also generated
     (we don't specialize generic versions of the synthetic generic routines
      because it's not easy or even always possible to create valid generic
      versions of synthetic routines)
   o Note: these are Pascal-style generics, not Java-style generics. The generic
     types nor their specializations are usable from Java code (specializations
     may become usable in the future)

git-svn-id: branches/jvmbackend@19047 -
2011-09-11 11:54:37 +00:00
Jonas Maebe
019a58ab1d * always save/restore the current_filepos when injecting code, sometimes it
isn't reset yet before a message is printed after parsing injected source
    code

git-svn-id: branches/jvmbackend@18982 -
2011-09-05 17:41:44 +00:00
Jonas Maebe
3d22aa3cd1 + support for synthetic procdefs that are not part of a structdef
(previously, they would not get an implementation)

git-svn-id: branches/jvmbackend@18878 -
2011-08-28 19:22:00 +00:00
Jonas Maebe
1d2748fa69 * fixed insertion of typed constants twice in bss after r18723
for non-jvm targets (and once using a mangled name for global
    variables rather than for typed constants)

git-svn-id: branches/jvmbackend@18794 -
2011-08-20 20:37:14 +00:00
Jonas Maebe
48710a5a3f * print the owning class/record of internally generated methods when
parsing their implementation if -vd is specified

git-svn-id: branches/jvmbackend@18754 -
2011-08-20 08:32:57 +00:00
Jonas Maebe
0b7b6361fe * ignore methods that are added for the purpose of the JVM (inherited
constructors, inherited virtual class methods) when deciding which
    overloaded version of a routine to call. Otherwise they can change
    which variant is called compared to code on platforms where such
    implicit methods are not added

git-svn-id: branches/jvmbackend@18752 -
2011-08-20 08:32:47 +00:00
Jonas Maebe
6fe124507e * fixed calling procvars with copyout parameters
git-svn-id: branches/jvmbackend@18733 -
2011-08-20 08:29:24 +00:00
Jonas Maebe
3791f0de1c * fixed mangled name of JVM class vars with an external name in case their
type is a forward-defined class whose full definition hasn't been parsed
    yet and if the full definition changes the external name of the class

git-svn-id: branches/jvmbackend@18727 -
2011-08-20 08:28:09 +00:00
Jonas Maebe
df5fc421ce + support for increasing the visibility of fields using properties
on the JVM target (at the Pascal level), by automatically generating
    getters/setters of the same visibility as the property that are used
    instead of directly accessing the fields when translating the property

git-svn-id: branches/jvmbackend@18724 -
2011-08-20 08:27:53 +00:00
Jonas Maebe
b3072b3dab * extracted the code to deal with static fields into a routine
(make_field_static() ) and replaced semi-duplicates of that
    code with calls to this routine
  * made the handling of static fields for the JVM target more
    similar to that on the other targets, so that class properties
    now also work there (-> updated JVM-specific code in several
    places to deal with this new handling)

git-svn-id: branches/jvmbackend@18723 -
2011-08-20 08:27:48 +00:00
Jonas Maebe
dbe55d1f6f * only override "clone" for records that contain fields that require a
deep copy, and for those records no longer call the inherited clone.
    Instead, declare a local variable of the record type, assign its
    address to the function and then copy all field contents to this local
    variable. Since it's dynamically allocated at the JVM level, it will
    survive the function exit.

    The problem with calling the inherited clone function is that it will
    copy the pointers of the implicit pointer fields (records, sets, …)
    from the old to the new instance, and that we (currently) have no way
    at the Pascal level to change those and make them point to new
    instances.

git-svn-id: branches/jvmbackend@18721 -
2011-08-20 08:27:37 +00:00
Jonas Maebe
3ac950eed7 * changed the parameter of fpcDeepCopy() from an out-parameter of the
actual recordtype into FpcBaseRecordType so we can also use
    the deep copy routine in the RTL
  + added abstract fpcDeepCopy() declaration to FpcBaseRecordType class

git-svn-id: branches/jvmbackend@18718 -
2011-08-20 08:27:22 +00:00
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
e9d27c3efe * mark copied virtual parent constructors as "override"
git-svn-id: branches/jvmbackend@18707 -
2011-08-20 08:26:26 +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
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
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
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
102e9cf8f4 * mark implicitly created typesyms immediately as "referenced" to avoid hints
about them not being used

git-svn-id: branches/jvmbackend@18664 -
2011-08-20 08:22:33 +00:00
Jonas Maebe
37aa2d8443 + full support for sets on the JVM target
o sets of enums are handled as JUEnumSet instances, others as JUBitSet
     derivatives (both smallsets and varsets, to make interoperability with
     Java easier)
   o special handling of set constants: these have to be constructed at run
     time. In case of constants in the code, create an internal constsym to
     represent them. These and regular constsyms are then aliased by an
     another internal staticvarsym that is used to initialise them in the
     unit initialisation code.
   o until they are constructed at run time, set constants are encoded as
     constant Java strings (with the characters containing the set bits)
   o hlcgobj conversion of tcginnode.pass_generate_code() for the genjumps
     part (that's the only part of the generic code that's used by the JVM
     target)
   o as far as explicit typecasting support is concerned, currently the
     following ones are supported (both from/to setdefs): ordinal types,
     enums, any other set types (whose size is the same on native targets)
   o enum setdefs also emit signatures
   o overloading routines for different ordinal set types, or for different
     enum set types, is not supported on the JVM target

git-svn-id: branches/jvmbackend@18662 -
2011-08-20 08:22:22 +00:00
Jonas Maebe
5ea497857d + FpcEnumValueObtainable interface that's implemented by all FPC
enums (for use in set factory helpers)

git-svn-id: branches/jvmbackend@18651 -
2011-08-20 08:21:24 +00:00
Jonas Maebe
466f6751c8 + getpointerdef() function that returns a pointerdef for the passed def.
Multiple calls to getpointerdef() for the same def in a single module
    return the same pointerdef

git-svn-id: branches/jvmbackend@18644 -
2011-08-20 08:20:51 +00:00
Jonas Maebe
1ad834f5f9 * in case a property uses a getter/setter with lower visibility than the
property, generate a wrapper with the same visibility as the property
    that calls through to the original getter/setter (JVM target only:
    ensures that the JVM verifier doesn't complain about calling methods
    that are not visible to the current class when using such properties
    from other units/classes)

git-svn-id: branches/jvmbackend@18632 -
2011-08-20 08:16:56 +00:00
Jonas Maebe
b50bd9534d * name nestedfpstruct types so they can no longer be confused with names of
nested classes by e.G. the bcel bytecode verification library

git-svn-id: branches/jvmbackend@18629 -
2011-08-20 08:16:42 +00:00
Jonas Maebe
569228447d * converted all enum handling for the JVM target so that it uses the
JDK class-style enums rather than plain ordinals like in Pascal
   o for Pascal code, nothing changes, except that for the JVM target
     you can always typecast any enum into a class instance (to interface
     with the JDK)
   o to Java programs, FPC enums look exactly like Java enum types

git-svn-id: branches/jvmbackend@18620 -
2011-08-20 08:15:54 +00:00
Jonas Maebe
13b0ac91d9 + generate java.lang.Enum descendant classes for Pascal enum types
o these classes get an "enum" flag in the class files
   o these classes get a class field (whose type is that same enum
     class) per enum in the type, which also gets the "enum" flag
   o those class fields are initialised in the class constructor
     with the name of the enum and their order in the declaration
   o if the enum has jumps in FPC (lowest value is not 0, or not
     all values are contiguous), then we add an extra field
     to hold the FPC ordinal value of the enum
   o these classes get a class field valled $VALUES that contains
     a reference to the aforementioned class fields in order of
     declaration (= ordinal->instance mapping, JDK-mandated)
   o apart from the JDK-mandated instance methods (values, valueOf),
     also add FPCOrdinal (returns FPC ordinal value; same as order
     of declaration in case of no jumps) instance method and FPCValueOf
     (returns enum corresponding to FPC ordinal value) static class
     method
   o the mapping between FPC ordinals and enum instances in case of
     jumps is stored in a hashmap whose size is the next prime number
     greater or equal than the number of enum elements
   o moved several extra JDK types to the system unit for the enum
     support, and for future boxing and Java set support
   o several new synthetic method identifiers to generate the enum class
     methods/constructor/class constructor
   o enums with jumps are ordered by FPC ordinal value in the JVM
     $VALUES array so that the java.lang.Enum.doCompare() method
     will properly compare them

git-svn-id: branches/jvmbackend@18616 -
2011-08-20 08:15:28 +00:00
Jonas Maebe
30478a14b6 + new vis_none visibility specifier that can be used as "neutral"
* make it possible to force the visibility of added constructors
    in add_missing_parent_constructors_intf() to a particular
    setting (use vis_none to keep the visibility of the inherited
    constructor)

git-svn-id: branches/jvmbackend@18614 -
2011-08-20 08:15:15 +00:00
Jonas Maebe
4f52639871 * use procdef.defid instead of procdef.procsym.symid to make the names of
parentfpstructs unique (a single procsym can have multiple overloaded
    procdefs, but a single procdef is unique)

git-svn-id: branches/jvmbackend@18607 -
2011-08-20 08:14:41 +00:00
Jonas Maebe
ad6ae44093 * force mode objfpc for synthetic method implementations (to guarantee
that e.g. "out" and &-escaping are possible)

git-svn-id: branches/jvmbackend@18590 -
2011-08-20 08:13:11 +00:00
Jonas Maebe
8fa42c206f + support for nested procedures for the JVM target
o since the JVM target has no stack/framepointer that can be passed
     on to nested routines, all local variables and parameters accessed
     from nested routines are grouped into a local record whose address
     is passed to nested routines. The same technique is also required
     for LLVM in the future

git-svn-id: branches/jvmbackend@18588 -
2011-08-20 08:12:59 +00:00
Jonas Maebe
0706cb5eb6 + support for pointers to types that are implicit pointer types in the JVM
(non-dynamic arrays, records, shortstrings)
  - removed the ability to typecast such types directly into related class
    types, you have to use the @-operator first now to get a pointer to
    the type
   o updated the RTL and internal compiler code to properly use this
     new convention
   o allowed removing several special cases from
     tjvmtypeconvnode.target_specific_general_typeconv(), and that
     method can probably be removed completely over time
  * no longer give compile time errors for pointer-related typecasts that
    will fail at run time, because the checking was too complex and could
    be worked around via actual pointer typecasts anyway
  * removed some unnecessary checkcast operations (for shortstring/
    shortstringclass)

git-svn-id: branches/jvmbackend@18574 -
2011-08-20 08:11:49 +00:00
Jonas Maebe
1b0b6a9d6d * also print method implementation when reusing a forward definition
git-svn-id: branches/jvmbackend@18548 -
2011-08-20 08:09:26 +00:00
Jonas Maebe
f2374ce24d * save block_type before creating a temporary scanner and restore afterwards,
because creating a new scanner sets the block_type back to bt_general
    (while we want to inject something in the current context)

git-svn-id: branches/jvmbackend@18493 -
2011-08-20 08:04:25 +00:00
Jonas Maebe
f27ebf8b6d + explicitly add constructors of parent class that do not appear in the
current class, since constructors are not automatically inherited in
    Java
   o tprocdef.getcopy() implementation, which returns an (unfinished) copy
     of a tprocdef. Finalise by calling symcreat.finish_copied_procdef()
   o made it possible to specify an existing procdef as argument to
     read_proc(), in which case it won't try to parse a procedure declaration,
     but only a body and associate it with the passed procdef. This is
     required for the inherited constructor support, since we cannot generate
     a textual representation of inherited constructors that is guaranteed to
     parse in the context of the current unit (e.g., if they use types from
     a unit that is not in the uses clause of the current unit)
   o folded tprocsym.find_procdef_bypara_no_rettype() into
     Tprocsym.Find_procdef_bypara, by interpreting specifying nil as
     retdef as not having to check the return def (required to compare
     parent constructors with child constructors to see whether they
     match, since the returndef will always be the current class type)

git-svn-id: branches/jvmbackend@18488 -
2011-08-20 08:04:01 +00:00
Jonas Maebe
1b401399a4 * pd.owner.defowner -> pd.struct
git-svn-id: branches/jvmbackend@18483 -
2011-08-20 08:03:38 +00:00
Jonas Maebe
834ea45be8 * (class_)constructor/destructor_head() now also parses hints,
handles modifiers and adds the procdefinition. This code was
    duplicated in several places (for objects and records)
  * properly handle introducing artificial class constructors
    (the manually constructed procdefs were wrong, now use
     str_parse_method_dec)

git-svn-id: branches/jvmbackend@18482 -
2011-08-20 08:03:33 +00:00
Jonas Maebe
474b7446ad * set isclassmethod also for class constructors/destructors in
implement_empty()

git-svn-id: branches/jvmbackend@18481 -
2011-08-20 08:03:28 +00:00
Jonas Maebe
33bd3d7aa9 * set isclassmethod also for class constructors/destructors in
implement_anon_inherited()

git-svn-id: branches/jvmbackend@18480 -
2011-08-20 08:03:23 +00:00
Jonas Maebe
43c5ed20c2 + support for initialising typed constants via compiler-generated
assignment-nodes. For global typed constants and typed constants/
    local variable initialisers in regular functions/procedurs, the
    assignments are performed in the unit initialisation code. For
    those in object/record definitions and their methods, it's done
    in the class constructor. Since we may not yet have parsed all
    method implementations when the class constructor is parsed, part
    of these may be initialised in a helper routine called from the
    class constructor. The ones known when the class constructor is
    parsed are inited there, because the ones marked as "final" and
    declared as static class fields must be initialised in the class
    constructor for Java
   o new set systems_typed_constants_node_init in systems unit that
     indicates that a target uses node trees to initialise typed consts
     instead of an initialised data section
   o mark typed constants in {$j-} mode as "final" for JVM
   o mangle the name of staticvarsyms inside localtables a bit to avoid
     name clashes (only with procedure names for now, no parameters yet
     so can still cause problems with overloaded routines)
   o after a routine has been parsed, it is now processed by
     cnodeutils.wrap_proc_body(), which can add extra nodes before code
     generation (used for injected the typed constant node trees)

git-svn-id: branches/jvmbackend@18475 -
2011-08-20 08:02:58 +00:00
Jonas Maebe
91e06f7139 * also process nested records/objects when generating implementations
for synthetic methods

git-svn-id: branches/jvmbackend@18474 -
2011-08-20 08:02:52 +00:00
Jonas Maebe
e663f0f31f + support for class constructors for the JVM target
o initialise class vars that need initialisations (records, arrays) in
     class constructors
   o treat class constructors as having a "void" resultdef rather than the
     class type for JVM (maybe has to be done in general?)
   o make it possible to specify pno_noleadingdollar to
     tprocdef.customprocname() so it can be used for class constructors
     (their name is lower cased because it mustn't conflict with other
      identifiers, since their name doesn't matter anyway)
   o added tsk_empty synthetic procdef kind which, as the name implies,
     generates an empty body (for class generated constructors)
  + auto-generate class constructors in case a class has class vars that
    need initialisation

git-svn-id: branches/jvmbackend@18462 -
2011-08-20 08:01:51 +00:00
Jonas Maebe
40e0b4677a + support for (only named, for now) records in the JVM target:
implemented via classes, all descending from system.FpcBaseRecordType
    (records are also considered to be "related" to system.FpcBaseRecordType
     on the JVM target)
  * several routines are auto-generated for all record-classes: apart
    from a default constructor (if there is none), also clone (which
    returns a new instance containing a deep copy of the current
    instance) and deepCopy (which copies all fields of one instance
    into another one)
   o added new field "synthetickind" to tprocdef that indicates what
     kind of synthetically generated method it is (if any), and
     mark such methods also as "synthetic" in the JVM assembler code
   o split off the JVM-specific parser code (e.g., to add default
     constructors) into pjvm.pas

git-svn-id: branches/jvmbackend@18450 -
2011-08-20 08:00:50 +00:00
Jonas Maebe
009a30d8cf * reworked saving/restoring the scanner state (immediately replace scanner
with temporary one when saving, since it's also freed when restoring ->
    called replace_scanner() instead of save_scanner() now)
  * when using -vd, print out the text that is internally generated for
    injecting into the scanner

git-svn-id: branches/jvmbackend@18442 -
2011-08-20 07:59:54 +00:00
Jonas Maebe
42798fd26b * fixed saving/restoring scanner state
git-svn-id: branches/jvmbackend@18428 -
2011-08-20 07:58:49 +00:00
Jonas Maebe
019ca93a04 * symcreat functionality to use the parser from inside the compiler for
artificially generated stuff rather than directly working with defs/syms
   problems
    o scanner state saving/restoring, and avoiding problems in case of
      errors in the injected strings
    o in case of the actual application (adding overriding constructors):
      the parameters may be of types not visible in the current unit to
      newly written code -> can't just use the scanner...

git-svn-id: branches/jvmbackend@18427 -
2011-08-20 07:58:44 +00:00