Commit Graph

450 Commits

Author SHA1 Message Date
Jonas Maebe
c9dbd60b92 * allow "static" for external methods (for Java classes)
git-svn-id: branches/jvmbackend@18369 -
2011-08-20 07:52:51 +00:00
Jonas Maebe
eb5814a868 * implemented declaring and calling constructors for Java classes
o handle them like for regular classes (return a class instance,
     although this is technically not true since they don't return
     anything; will be changed in the future)
   o because of the previous point, make sure that we handle the
     "function result" properly and don't pop too many values from
     the evaluation stack when calling one constructor from another
   o added "extra_pre_call_code" method used by njvmcal to insert
     the "new" opcode to create the new class instance before
     calling a constructor
   o when a constructor does not call any other constructor (inherited
     or otherwise), automatically insert a call to the inherited
     parameterless constructor as required by the jvm standard)
   TODO: check that *if* an inherited or other constructor is called
     from another constructor, that it does so as the first statement/
     call

git-svn-id: branches/jvmbackend@18328 -
2011-08-20 07:46:37 +00:00
Jonas Maebe
6e82417a51 * various small support fixes for Java classes:
o support formal external definitions (like for objcclass)
   o allow specifying an "import_dll" for external Java classes, which can
     be used to specify the Java package name (like the dll for cppclass)
   o take the package name into account when mangling the Java class name
   o several messages that were specific to Objective-Pascal classes have
     been generalised because they also apply to Java classes, same for
     several compiler function names
   o disabled some proccall directives for Java, but more needs to happen
     (Java methods are always either instance-virtual or class-static)

git-svn-id: branches/jvmbackend@18319 -
2011-08-20 07:38:26 +00:00
sergei
bbae63a4f2 * Check that a single interface is only delegated to a single property within a class.
* Disallow simultaneous use of method resolution and delegation for the same interface. An interface with method resolution must be implemented directly. This is Delphi compatible and resolves #18058.

git-svn-id: trunk@18179 -
2011-08-12 14:42:30 +00:00
pierre
4d50a95320 Use FPC_HAS_SYSTEMS_INTERRUPT_TABLE conditional
undefined for now as long as
  systems_interrupt_table set
  defined in systems unit is empty.
  This removes several warnings from compiler compilation.

git-svn-id: trunk@17871 -
2011-06-29 15:03:55 +00:00
pierre
47ff755068 symdef.pas New make_dllmangledname function
used both in pdecvar and pdecsub units to generate a mangled name
  for externals imported from a dynamic library.

git-svn-id: trunk@17850 -
2011-06-28 05:38:05 +00:00
florian
3938f5e0b9 + merge support for boolean16, boolean32 and boolean64 into trunk
git-svn-id: trunk@17846 -
2011-06-27 19:21:07 +00:00
pierre
548ee755b1 * Use crc for special dllnames in proc_get_importname
git-svn-id: trunk@17844 -
2011-06-27 16:23:33 +00:00
florian
d35d1ed357 + initial support for pascal booleans with sizes 2, 4 and 8
git-svn-id: branches/pasboolxx@17836 -
2011-06-26 15:02:37 +00:00
pierre
239944f8d0 + Use DLL name in assembler labels used to import DLL functions/variables
in Windows, Emx and OS2 targets.
    This fixes test failures: test/library/tlib1b.pp and lib2b.pp

    link unit TLinker.AddImportSymbol: Added symmangledname parameter.
    ogbase unit TImportSymbol.Create: Add AMangledName parameter.
    fmodule unit TModule.AddExternalImport: Add symmangledname parameter.
    fppu unit: Also put mangled name string for imported symbol.
    ppu unit: Increase PPUVersion
    utils/ppudump.pp: Adapt to PPU change above.
    systems/T_OS units: Use ImportSymbol.MangledName property to create
    import libraries or .idata sections.

git-svn-id: trunk@17804 -
2011-06-23 11:38:57 +00:00
joost
45bc3fcae0 * Enabled safecall on x86_64-linux
git-svn-id: trunk@17629 -
2011-06-02 10:43:18 +00:00
svenbarth
35b47e491c Rebase to revision 17306
git-svn-id: branches/svenbarth/classhelpers@17314 -
2011-04-13 10:04:14 +00:00
florian
3ce9ff93f1 + patch by Jeppe Johansen to support automatic interrupt table generation by using the interrupt directive with an offset. Not activated yet because it requires to change also the startup code of the different mcus.
git-svn-id: trunk@17279 -
2011-04-10 15:59:06 +00:00
svenbarth
d0705a1779 Rebase to revision 17236
git-svn-id: branches/svenbarth/classhelpers@17241 -
2011-04-03 17:24:35 +00:00
svenbarth
a944be69a6 * nflw.pas: search for enumerators in helpers for records as well
* pdecobj.pas:
- parse_object_members: in record helpers class methods need to be declared as "static" like in records
- object_dec: 
 - allow "published" in helpers as well
 - disallow inheritance for record helpers in mode Delphi (and remove the forward declaration flag in that case)
* pdecsub.pas:
pd_abstract: "abstract" isn't allowed in either mode
* pexpr.pas: multiple corrections because of "inherited" and records
- allow "inherited" for "record helpers" (except for mode Delphi)
- load the symbol from the correct class (I hope...)
- give a more precise error message if "inherited" is used in records
* ptype.pas: I forgot to adjust the "(bit)packed record" case
* symtable.pas:
- searchsym_in_helper: "result" was not initialized (and identation fix)
- search_last_objectpascal_helper:
 - don't search if there are no helpers (useful for projects that does not contain helpers like the compiler itself)
 - don't search if the type to search helpers for is defined locally
 - don't search if the type is a anonymous record
- search_struct_member: search for symbols in helpers as well
- msg*: 
* correct the message for "parser_e_not_allowed_in_helper"
* add message "parser_e_inherited_not_in_record" which is used to tell that the use of "inherited" is not allowed in records and (in mode Delphi) record helpers

git-svn-id: branches/svenbarth/classhelpers@17239 -
2011-04-03 14:03:17 +00:00
Jonas Maebe
bc46ea5cba * use compare_defs() instead of a plain "=" comparison to check that the
return type of the interface and implementation declaration of a function
    match (so that in case the "real defs" match as described in the comment
    of r17201, they are accepted as being the same)

git-svn-id: trunk@17207 -
2011-03-29 18:51:36 +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
963a4d7b23 Commit of a completely restructured helper implementation. Instead of changing objectdefs with odt_classhelper to odt_class, they'll have the odt_helper type assigned to and this will be kept. This also implies that the parent of a helper is its true parent while the extended type is set to a field in tobjectdef (extendeddef).
This change became necessary of the following reasons:
- Records don't support inheritance, thus for "record helpers" some creativity would have been necessary to implement them; with the new implementation this is more easily
- the new approach allows for easy checks regarding virtual methods and their overrides which would have been more complicated in the old variant
- if someone feels the need the types of helpers (object, interface) can be added rather easily
- unnecessary things like VMT generation can be disabled now

details:
- msg*: 
* moved some messages from parser to type
* adjusted a message ("class helper" => "helper")
- symdef.pas:
* renamed "helperparent" to "extendeddef" and changed its type from "tobjectdef" to "tabstractrecorddef", so records can be extended as well (somewhen in the near future)
* removed "finish_class_helper" method as it isn't necessary (luckily I haven't yet adjusted the ObjC variant)
* changed name of "is_objectpascal_classhelper" to "is_objectpascal_helper" to reflect that this function applies to all helper types
* tobjectdef.create: ImplementedInterfaces isn't created for odt_helper anymore
* tobjectdef.alignment: for helpers it's the same as for classes although this shouldn't be used anywhere...
* tobjectdef.vmtmethodoffset: set to 0 for helpers to be sure...
* tobjectdef.needs_inittable: not needed for helpers (no fields allowed)
* is_objectpascal_helper: only needs check for "odt_helper" object type
- symconst.pas:
* changed odt_classhelper to more general odt_helper
* added new type "thelpertype" which is used to check that "(record|class) helper" corresponds with the given extended type (as Delphi XE checks this as well this strict solution can be kept for modes Delphi and ObjFPC)
- symtable.pas:
* extended "searchsym_in_class" with the possibility to disable the search for helper methods (needed for inherited) => this implies changing all occurences of "searchsym_in_class" with a "true" except some special locations
* renamed "search_objectpascal_classhelper" to "search_objectpascal_helper"
* searchsym_in_class: 
** when an extended method is defined with "overload" it can be that a same named method of the extended class might be called (sadly this means that this search was unnecessary...)
** contextclassh is the def of the helper in the case of an inherited call inside the helper's implementation
** when methods inside a helper are searched, it must be searched in the extended type first
- ptype.pas:
* single_type is used to parse the parent of a helper as well, so allow a helper if the stoParseClassParent is given (needs check in pdecobj.pas/parse_class_parents for normal classes)
* read_named_type: currently the only case when something <> ht_none is passed to the modified parse_objdec (see below) is when the combination "class helper" is encountered ("record helper" will be another one)
- pinline.pas: adjustment for extended "searchsym_in_class"
- pexpr.pas:
* adjustments regarding "searchsym_in_class" and "is_objectpascal_helper"
* factor/factor_read_id: moved the check for "TSomeClassType.SomeMethod" outside of the "is_class" check
* factor: 
** in case of an inherited we need to search inside the extended type first (Note: this needs to be extended to find methods in the helper parent if no method is found in the extended type)
** we also need to disable the search for helper methods when searching for an inherited method (Note: it might be better to introduce a enum to decide whether a helper method should search before or after the methods of the extended type or even never)
- pdecsub.pas:
* insert_self_and_vmt_para: in a helper the type of Self is of the extended type
* pd_abstract, pd_final: more nice error message
* pd_override, pd_message, pd_reintroduce: adjusted checks because now "is_class" is no longer true for helpers
* proc_direcdata: allowed "abstract" for helpers (only to produce a more nice error message)
* parse_proc_direc: adjustment because of "is_objectpascal_helper"
- pdecobj.pas:
* adjustments regarding "is_objectpascal_helper"
* adjusted object_dec to take the type of the helper (class, record) as a parameter to be able to check whether the correct extended type was given
* struct_property_dec: properties are allowed in helpers
* parse_object_options: nothing to be parsed for helpers (at least I hope so ^^)
* parse_parent_classes: 
** the parent of a helper is now parsed as a normal parent, the extended type is parsed in an extra procedure
** check for "sealed" no longer needed
** added check that the parsed parent of a helper is indeed a helper
** allow to parse the closing ")" of the helper's parent
* parse_extended_class:
** new procedure that parses the type which is extended
** it checks that the extended type is a class for "class helper" and a record for "record helper"
** it checks that a helper extends the same class or a subclass for class helpers
** it checks that a helper extends the same record for record helpers
* parse_object_members:
** "type", "const", "var" is allowed in helpers
** don't exclude flags regarding virtual methods, they are needed for the checks in mode Delphi (this implies that VMT loading must be disabled for helpers)
* object_dec:
** don't change "odt_helper" to "odt_class", but still include the "oo_is_classhelper" flag
** allow the parsing of object options (there are none)
** parse the extended type for helpers
- pdecl.pas
* adjustment because of extension of object_dec
* types_dec: remove the call to finish_classhelper
- objcdef.pas
* objcaddencodedtype, objcdochecktype: add references to helpers as implicit pointers although that should not be used in any way...
- nld.pas
* tloadnode.pass_typecheck: self is a reference to the extended type
- nflw.pas
* create_for_in_loop: adjustment because of changed procedure and inheritance type
- ncgrtti.pas
* TRTTIWriter.write_rtti_data: disable for helpers for now (I need to check what Delphi does here)
- ncgld.pas
* tcgloadnode.pass_generate_code: virtual methods of helpers are treated as normal methods
- ncgcal.pas
* tcgcallnode.pass_generate_code: virtual methods of helpers are treated as normal methods
- ncal.pas
* tcallnode.pass_typecheck: adjust for extension of tcallcandidates constructor
- htypechk.pas
* tcallcandidates declaration: extend some methods to (dis)allow the search for helper methods (needed for inherited)
* tcallcandidates.collect_overloads_in_struct: 
** search first in helpers for methods and stop if none carries the "overload" flag
** move the addition of the procsyms to an extra nested procedure because it's used for helper methods and normal struct methods

git-svn-id: branches/svenbarth/classhelpers@16947 -
2011-02-20 11:41:55 +00:00
svenbarth
07eebff55c Rebase to revision 16827
adjusted nflw.pas to compile again

git-svn-id: branches/svenbarth/classhelpers@16831 -
2011-01-28 22:15:34 +00:00
paul
a39733a0a2 compiler: extend enumerator support for records:
- search GetEnumerator method in records too (while searching a enumerator for structure)
  - allow enumerator operator return type to be a record
  - copy/adapt enumerator helpers from tobjectdef to tabstractrecorddef
  + test

git-svn-id: trunk@16807 -
2011-01-24 04:13:28 +00:00
paul
9499692eeb compiler: allow Assignment and Explicit operators for undefined defs (issue #0018567)
git-svn-id: trunk@16805 -
2011-01-24 03:06:27 +00:00
svenbarth
433851ab36 - compiler/pdecsub.pas:
* added flag pd_nothelper which tells the "directive parser" not to use this directive with class helpers
* added pd_nothelper flag to definitely forbidden directive (I'm not so happy about "abstract" though, as the error message because of this isn't very descriptive, because abstract is treated as field)
* some directives that are useless in class helpers are forbidden in mode ObjFPC only (e.g. "message", "virtual", "override")
- compiler/pdecobj.pas: as class helpers don't support some concepts used in normal classes (e.g. virtual methods) they are simply ignored and thus the corresponding flags are removed (this is for mode Delphi)

git-svn-id: branches/svenbarth/classhelpers@16793 -
2011-01-19 19:46:35 +00:00
paul
0c9b40acb7 compiler: record operators
- allow operator also if return type match the structure type (before at least one parameter had to match)
  - search both operands symbol tables for a suitable assignment operator
  - test
based on patch of Blaise Thorn (issue #0018490)

git-svn-id: trunk@16762 -
2011-01-14 02:25:48 +00:00
paul
f9f316ac45 compiler: don't set a structure to routine if it accidentally match some (bug #0018452)
git-svn-id: trunk@16747 -
2011-01-11 02:00:27 +00:00
paul
86482658a8 compiler: fix tgeneric11 test:
- add stoAllowSpecialization to TSingleTypeOption enum to differentiate between any new type definition and only generic specialization
  - allow only specializations for class parents (not any other type definition)
  - allow specialization for method arguments and return types (maybe this must be allowed only in delphi mode but in this case tgeneric11 must fail)

git-svn-id: trunk@16738 -
2011-01-08 16:14:22 +00:00
paul
31de2aab1b compiler: change parse_proc_head pd argument access type from var to out
git-svn-id: trunk@16723 -
2011-01-06 17:14:09 +00:00
paul
749075a851 compiler: ignore case when check type parameters for identity
git-svn-id: trunk@16710 -
2011-01-05 18:27:05 +00:00
paul
bd64575add compiler: require generic name with type parameters for the method class prefix (like TGenericClass<T>.MethodName instead of TGenericClass.MethodName) in delphi mode
git-svn-id: trunk@16707 -
2011-01-05 04:35:56 +00:00
paul
fa41b6ffe3 compiler: allow generic classes to derive from generic classes and generic interfaces
- change id_type to single_type in readImplementedInterfacesAndProtocols to allow use of interface specializations inside class parent block
  - change single_type boolean arguments to set, add stoParseClassParent option to that set
  - move parse_generic variable assignment from parse_object_members to outer routine to setup it before parsing class parents
  - return paticular generic in generate_specialization instead of undefineddef to pass class/interface checks inside parent class block
  - add test for delphi mode
  - modify tw11431 to be syntatically correct

git-svn-id: trunk@16706 -
2011-01-04 18:20:40 +00:00
Jonas Maebe
3ca3276400 * changed syntax of external objcclasses (see wiki/FPC_PasCocoa). Another
change is that it is now also allowed to specify an external name for
    formal external class definitions, but if they are later mixed with
    regular class definitions the external names have to match.
   o because the "external" status of methods is now set while parsing the
     class rather than afterwards, some procdir compatibility checks had to
     be inlined because they only have to be performed for 
  * also adapted the syntax for external cppclasses in the same way
  * fixed return type of NSObject.retainCount and NSObject.hash
    (NSUInteger instead of cint)
  * moved "patches" directory from cocoaint/src to cocoaint/utils/cocoa-skel
    so they are used by the conversion script when re-parsing the headers
  * updated Objective-C header parser script to
   o use the new external class syntax
   o not write inheritance information for root classes (NSObject, NSProxy)
   o use internal translation tables for some conflicting method names that
    are named specially in objcbase.pp
   and updated parsed headers
  * fixed rtl/inc/objcbase.pp and tests to conform to the new external class
    syntax

git-svn-id: trunk@16684 -
2011-01-02 14:50:46 +00:00
paul
e8502b8ec2 compiler: make current_genericdef, current_specializedef tstoreddef instead of tabstractrecorddef to implement generic arrays
git-svn-id: trunk@16671 -
2010-12-31 04:39:16 +00:00
paul
52667b6822 compiler: implement generics for records based on generic objects implementation + 1 test
git-svn-id: trunk@16670 -
2010-12-31 03:43:16 +00:00
paul
ee78cf0f06 compiler: use current_structdef in more places where current_objectdef was used, change type of current_genericdef and current_specializedef to tabstractrecorddef for future use with generic records
git-svn-id: trunk@16659 -
2010-12-30 07:33:57 +00:00
paul
210e78e4fa compiler: allow objects and records to have members which point to themself. only don't permit this to regular fields.
- remove testcurobject hack and perform a check only for regular fields
  - move is_holded_by to interface and rename it to is_owned_by
  - don't check static symbols in _needs_init_final because they always point to symbols registered on unit level
  - don't check object type in id_type, read_named_type when we are looking for type of structure member - the only check will be performed for record/object fields now
  + tests

git-svn-id: trunk@16646 -
2010-12-27 05:47:25 +00:00
paul
e098046608 compiler: fix typo
git-svn-id: trunk@16645 -
2010-12-27 03:43:42 +00:00
paul
51a9d3280c compiler: require at least one argument of class operator to be of type of structure where this operator is declared
git-svn-id: trunk@16644 -
2010-12-27 02:33:17 +00:00
paul
ee6fe6c4f5 compiler: add unary plus node, search for unary plus operator if a type cannot be handled by compiler, increase ppu version because of node types change
git-svn-id: trunk@16640 -
2010-12-26 12:19:28 +00:00
paul
c0c7e40b65 compiler: allow Inc, Dec, Explicit operators for other fpc modes
git-svn-id: trunk@16637 -
2010-12-25 11:31:07 +00:00
paul
66b128efb3 compiler: map delphi Implicit operator to := operator of FPC, add Explicit operator for delphi only (for now) which works when explicit type conversion happens + extend test
git-svn-id: trunk@16636 -
2010-12-25 11:08:02 +00:00
paul
4531e1231b compiler: implement Inc, Dec class operators
- extend tok2node array to store inline function number for the case when nodetype = inlinen, add Inc, Dec operators to array
 - implement inline function support in isunaryoverloaded
 - check for operator overload if Inc, Dec is not used for standard types
 - extend test to check Inc,Dec operators

git-svn-id: trunk@16629 -
2010-12-24 09:26:52 +00:00
paul
8c8c1fc151 compiler:
- parse operator return type the same way as we parse function return type - which pushing structures into the symtable and allowing self references, 
  - this change allows class operators to have return type = structure where they are defined
  - extend test to check LogicalNot operator which can be finally compiled now

git-svn-id: trunk@16627 -
2010-12-24 07:22:48 +00:00
paul
3c6fde4acc compiler: rename parser_e_constructors_always_objects message to parser_e_only_methods_allowed and extended the meaning it has, don't allow class constructors to be declared outside the class/record + test
git-svn-id: trunk@16626 -
2010-12-24 06:41:41 +00:00
paul
b811f1be15 compiler: implement delphi style class operators:
- add delphi operator tokens into token enum
  - move optoken search from parse_proc_dec to parse_proc_head and add delphi operator name search
  - map delphi operators to existent fpc operators and skip some delphi operators for now
  - implement store operators in record symtable and search in it

git-svn-id: trunk@16624 -
2010-12-24 05:43:36 +00:00
paul
d97cf8ed9d compiler: implement IN operator which was known by compiler but was not supported. + test
git-svn-id: trunk@16622 -
2010-12-24 02:25:22 +00:00
paul
92d6503704 compiler: rename _EQUAL token to _EQ to prevent problems with adding delphi operator names which contains "EQUAL" name, also rename _UNEQUAL to _NE for consistency
git-svn-id: trunk@16608 -
2010-12-22 02:01:40 +00:00
paul
8c0c614d5a compiler: allow <> operator overload. search for "<>" operator first for "<>" expressions and if not found then use "=" operator + test
git-svn-id: trunk@16603 -
2010-12-21 04:44:37 +00:00
paul
742b0bb686 compiler: partly revert r16560 and disable (at least temporary) constructors in records
git-svn-id: branches/paul/extended_records@16568 -
2010-12-16 03:37:16 +00:00
paul
8c56269076 compiler: fix record constructor return type when parsing procedure declaration
git-svn-id: branches/paul/extended_records@16562 -
2010-12-13 07:04:56 +00:00
paul
11d4eddf67 compiler: a trial to implement record constructor
- map self to constructor result
  - don't push vmt for records

At the moment generated assembler has errors although node tree is correct

git-svn-id: branches/paul/extended_records@16560 -
2010-12-13 06:39:29 +00:00
paul
289c9bd192 compiler: remove unneeded checks and typecasting caused by move of objectoptions into tabstractrecorddef
git-svn-id: branches/paul/extended_records@16542 -
2010-12-11 07:00:46 +00:00