Commit Graph

211 Commits

Author SHA1 Message Date
svenbarth
956b26bc97 Completely reworked implementation of generic constraints, by moving the generic constraint data from the symbols to the definitions (I originally thought that this would simplyfy things, but the more correct approach is to add it to the defs).
symsym.pas:
    - remove "tgenericconstraintdata" and any using/loading/writing of it in "ttypesym"
    - remove "tgenericconstraintflag"
symdef.pas:
    + add "tgenericconstraintdata"
    + load and write "genconstraintdata" in "tstoreddef"
symconst.pas:
    + add "tgenericconstraintflag" so it can be used in "ppudump" as well
defcmp.pas, compare_defs_ext:
    * as we allow global operator overloads we can't really determine whether two defs are compatible, because a valid operator for the specialization types might just happen to be in scope of the generic; so for now constraints are only strictly checked when declaring a specialization
pgenutil.pas:
    * adjust "parse_generic_parameters" and "check_generic_constraints" to the new location of the constraint data
ppudump.pp:
    * corrrectly parse defs which contain generic constraints

git-svn-id: trunk@24628 -
2013-05-29 08:19:02 +00:00
svenbarth
cc5a108cca Allocate the list for generic parameters in tstoreddef only on demand as most defs won't contain generic parameters anyway (avoids a little bit of runtime and memory overhead per def).
symdef.pas, tstoreddef:
  + comment that the list is allocated on demand (and thus should be checked for Nil)
  + fillgenericparas: create the list when adding at least one generic parameter symbol
  - create & ppuload: don't create list instance anymore
  + is_generic & is_specialization: check whether the list is assigned
defcmp.pas, compare_defs_ext:
  + check whether "genericparas" list is assigned
pgenutil.pas:
  + check_generic_constraints: check whether "genericparas" is assigned
  + insert_generic_parameter_types: create list before adding generic parameters

git-svn-id: trunk@24627 -
2013-05-29 07:50:49 +00:00
nickysn
b0f7786782 + added support for special versions of near data pointers associated with a x86 segment register. They are supported on all x86 platforms: i8086, i386 and x86_64
git-svn-id: trunk@24453 -
2013-05-05 17:22:37 +00:00
Jonas Maebe
1244cdff70 * don't treat bitpacked arrays of subranges of char that can be represented
using less than 8 bits per element the same as regular char arrays as far
    as automatic type conversions are concerned (they have to be explicitly
    packed/unpacked) (mantis #24013)

git-svn-id: trunk@23739 -
2013-03-09 10:37:30 +00:00
svenbarth
9ef4a35a7b Fix the fix for Mantis #21538. The check never really worked up to now...
defcmp.pas, compare_defs_ext:
  use "equal_defs" instead of a reference comparison to check whether the type defs are equal
pgenutil.pas, insert_generic_parameter_types:
  * add to each (specialized) generic parameter the "sp_generic_para" flag so that it will be added to the "genericparas" list upon ppu loading
  * add the generic parameter to the genericparas list as well, so that the comparison in "compare_defs_ext" is triggered at all... (up to now the list was always empty -.-)
ppu.pas:
  * increase PPU version

git-svn-id: trunk@23149 -
2012-12-15 21:43:52 +00:00
Jonas Maebe
c7255f153e * sets with the same base/range can still have a different size (and hence
not be equal) due to different packset settings -> still need conversion
    (mantis #23204)

git-svn-id: trunk@23054 -
2012-11-24 12:32:57 +00:00
svenbarth
2414c55ca0 Fix for Mantis #21538.
* defcmp.pas, compare_defs_ext: 
  use the new genericparas list to check whether two specializations of the same generic can be considered equal
+ added test

git-svn-id: trunk@22454 -
2012-09-25 10:25:30 +00:00
Jonas Maebe
85765364ee * properly compare parameter lists involving pointers to or classrefdefs of
forward defined types by maing sure that we always compare typesyms in
    that case instead of the forwarddefs (mantis #22705)

git-svn-id: trunk@22215 -
2012-08-23 20:58:22 +00:00
Jonas Maebe
4d31fbc31d * also allow conversion of niln to forward-defined pointerdef
(mantis #22593)

git-svn-id: trunk@22026 -
2012-08-07 11:23:00 +00:00
Jonas Maebe
a63a603cc1 * allow conversion from niln to not-yet-fully-resolved classrefdefs
(mantis #22593)

git-svn-id: trunk@22025 -
2012-08-07 09:56:08 +00:00
Jonas Maebe
63ab1bae3e * don't allow ordinal->ptr-based-objectdef conversions on managed platforms,
even in Delphi mode (mantis #22401)

git-svn-id: trunk@21840 -
2012-07-10 09:24:13 +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
ffe68ca284 * do not search overloaded assignment/conversion operators for internal
type conversions (those should always re-interpret the raw bits),
    except for variants (because those are sometimes generated internally)
    -- done so that -gt code at the node tree level can insert explicit
    typecasts to integer types without triggering overloaded explicit
    typecast operators such as in tests/test/terecs14

git-svn-id: trunk@21381 -
2012-05-24 15:34:27 +00:00
Jonas Maebe
99e70e7128 * do not allow implicit conversions from currency to orddef even if currency
is implemented via int64 (prevents e.g. calling abs(int64) for
    abs(currency) on non-x86)

git-svn-id: trunk@21097 -
2012-04-28 14:27:17 +00:00
paul
1a724f3e11 compiler:
- prefer UnicodeString, WideString, PWideChar, PAnsiChar, AnsiString, ShortString when passing a string constant if default string is UnicodeString,
  - change default string type to UnicodeString for MODE DelphiUnicode

git-svn-id: trunk@21094 -
2012-04-28 08:19:10 +00:00
paul
c7e057a835 compiler: use is_wide_or_unicode_string() istead of using is_widestring() or is_unicodestring()
git-svn-id: trunk@21086 -
2012-04-28 03:32:06 +00:00
Jonas Maebe
564445da8c * re-enabled enum -> dispinterface typecasts after r21069, bug noticed by
Paul

git-svn-id: trunk@21076 -
2012-04-27 09:30:25 +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
paul
a26bc50ca6 compiler: change ShortString->(Some)String and AnsiString->(Some)String overload precedence both for variables and string constants, change unicode constant type from widestring to unicodestring (Delphi compatibility)
new ShortString->(Some)String precedence: ShortString, UTF8String, AnsiString, AnsiString(CodePage) and RawByteString, UnicodeString, WideString and other string types
new AnsiString->(Some)String precedence: RawByteString, UTF8String, AnsiString, AnsiString(CodePage), UnicodeString, WideString, ShortString and other string types

The new logic makes UTF8String more preferrable than other AnsiString types, AnsiString more preferrable than other  AnsiStrings(codepage) and also makes UnicodeString more preferrable than WideString.

git-svn-id: trunk@21057 -
2012-04-26 02:33:57 +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
paul
2499b5514f compiler: change overload search for char constants (for delphi compatibility):
- for AnsiChar prefer ShortString, AnsiString, UnicodeString, WideString, ... (LongString?)
  - for WideChar prefer UnicodeString, WideString, AnsiString, ShortString, ... (LongString?)
  - remove old code from htypechk which made AnsiChar const = AnsiString,ShortString and WideChar const = WideString,UnicodeString - it is no longer needed since defcmp performs the required comparisons
  + test

git-svn-id: trunk@20348 -
2012-02-14 06:52:33 +00:00
svenbarth
2a872978dc Fix Mantis #21179
* defcmp.pas:
        + Extend compare_def_ext by the possiblity to specify whether strict or
          loose comparison of undefined defs should be applied.
          * in strict mode undefined defs are incompatible to all other defs
            except other undefined defs
          * in loose mode undefined defs are equal to anything (this is how
            FPC behaved up to now)
        + Enable the strict mode in compare_paras so that overloads with
          generic type parameters are possible
* ptype.pas, single_type:
        If the generic dummy of the currently parsed generic is encountered in
        non-Delphi modes then we need to return the current genericdef. This
        condition needs to be checked using the ObjName of the def, because
        the link from the type symbol to the current def is not yet 
        established 
+ added test for bug report

git-svn-id: trunk@20345 -
2012-02-13 21:17:54 +00:00
paul
3b153c223a compiler:
- treat the defs equal when convert from rawbytstring to any ansistring type (delphi compatible)
  - set result of ansistring copy() function to the type of first argument for ansistring arguments and to ansistring for pchar and char array arguments (delphi compatible)
  + test

git-svn-id: trunk@20285 -
2012-02-09 08:22:38 +00:00
Jonas Maebe
0d5b2b84a8 + Android/JVM target, including a translation of the Android r14 SDK
(= Android 4.0) java headers: java.*, javax.*, org.*, junit.*, android.*).
    The RTL can also be used to target earlier versions of the Android
    platform, but you manually have to take care of not using APIs that
    weren't available yet. Adding separate units for separate platform
    versions would only partly solve the problem, because some of the
    classes used inside the system unit have also changed across
    versions.

    Use -Tandroid while compiling to select the Android OS as target
    platform.

git-svn-id: branches/jvmbackend@19830 -
2011-12-12 02:34:34 +00:00
paul
c6ca9e5091 compiler:
- add helper function getansistringcodepage which returns explicitly set codepage or 0 in other case
  - add helper function getansistringdef which return a def with explicitly set codepage or cansistringtype in other case
  - change tstoreddef.createnai constructor to allow set codepage in constructor
  - don't convert string constants to rawbytestring. if string constant already has a codepage - preserve it or convert to ansistring codepage (delphi compatible)
  - don't perform string conversion from ansistring to strings with explicitly set codepage (by directive or by compiler switch) and vice versa (delphi compatible)
  + test which covers most of the cases

git-svn-id: trunk@19510 -
2011-10-19 02:45:52 +00:00
paul
a99ffb3097 compiler: apply patches from Inoussa and Jonas:
defcmp: Address code paged' string type comparison taking care of the code page
  ncnv: Remove un-needed code page comparison to CP_UTF8, some fixes regarding shortstrings and wide char/string 
  ncon: For the case of tstringconstnode.changestringtype (ncon.pas) where the code page are of CP_NONE or 0 no translation is done as :
    * CP_NONE is compatible to all
    * For 0 the raw bytes are just copied.
 My changes:
  - change ascii2unicode to allow pass source codepage, 
  - convert in both cases when source or destination is UTF8

git-svn-id: trunk@19457 -
2011-10-11 01:21:07 +00:00
paul
e0fecf5332 compiler: revert r19358. As stated by Florian, compiler should be able to compile with the latest RTL.
git-svn-id: trunk@19360 -
2011-10-04 10:12:49 +00:00
paul
ee2e0a0c1d compiler: remove CP_xxx constants since they are present in the system unit now
git-svn-id: trunk@19358 -
2011-10-04 06:03:03 +00:00
paul
a769ef0ad2 compiler: don't return te_eual when we convert from RawByteString to another codepage
git-svn-id: trunk@19283 -
2011-09-29 12:03:11 +00:00
paul
00396da30c compiler: cleanup
git-svn-id: trunk@19208 -
2011-09-24 17:41:13 +00:00
paul
005795495d merge r17552 from cpstrnew branch by inoussa:
*In normal procedure "var" and "out" RawByteString parameters does not accept other string types. Procedures with
"compilerproc" directive or the newly added "rtlproc" directive accept that. Please note that it is up to the
procedure coder to ensure the correctness of the code page in that case. The new directive is needed to handle 
the RTL procedures/functions that are not marked as "compilerproc" such as "UniqueString", "Insert" and "Delete".

*Correct "fpc_ansistr_concat" to handle code page correctly.

*Default "ansitring" type is now created with code page set to "0" instead of "65535". Before that change it was 
impossible to distinguish a "RawByteString" with the default "ansistring". At runtime "ansistring" variable'code
page is set to DefaultSystemCodePage

*UniqueString flavor of "SetLength" has been updated to release memory when shrinked to at least 50%, like ansitring
does.

git-svn-id: trunk@19118 -
2011-09-17 13:52:09 +00:00
paul
723f3424d4 merge r17484 from cpstrnew branch by michael:
* Patch from Inoussa:
* defcmp.pas
    ** ansistring to/from RawByteString are evaluated "te_equal"
    ** ansistring to UTF8string is evaluated (te_convert_l1,tc_string_2_string)

* ncnv.pas
    ** "ttypeconvnode.typecheck_char_to_string" : WideChar to AnsiString/ShortString
        is possible if the source code page is not utf8
    ** "ttypeconvnode.typecheck_char_to_char" : WideChar to AnsiChar
        is possible if the source code page is not utf8

* ncon.pas
    ** "tstringconstnode.changestringtype" : Unicode to utf8string bug fix(set the encoding),
       constants in the source code with code page set utf8 should be converted back to utf8

* nopt.pas
    ** "genmultistringadd" : fpc_<stringname>_concat_multi have a new parameter "cp"
        to indicate the "DestS" code page if the variable content is nil. This is required
        in order not to loose the declared code page.

* pinline.pas
    ** "inline_setlength" : a new parameter "cp" to indicate the code page if the variable content
       is nil. This is required in order not to loose the declared code page.
* ptconst.pas
    ** "parse_arraydef" : for string const to array of ansichar/widechar conversion check for wide string and
        convert if it is required. For char const to array of ansichar/widechar conversion check for wide char and
        convert if it is required.

git-svn-id: trunk@19113 -
2011-09-17 13:30:09 +00:00
paul
8f3f583199 merge r14140 from cpstrnew branch by paul:
prefer exact string const matches

git-svn-id: trunk@19096 -
2011-09-17 11:48:18 +00:00
paul
ae0d732c8f merge r13485 from cpstrnew branch by florian:
* fixed compilation of system unit after last changes

git-svn-id: trunk@19083 -
2011-09-17 11:01:42 +00:00
paul
8a4634a7b1 merge r13481 from cpstrnew branch by florian
+ support parsing of strings with code page specification
+ added encoding and elementsize field to ansi- and unicodestring records
+ some basic rtl support routines for encoding aware strings
+ DefaultSystemCodePage
+ DefaultUnicodeCodePage
+ ppu writing/loading of code page aware strings

git-svn-id: trunk@19080 -
2011-09-17 10:37:36 +00:00
paul
a95512f0ec merge cpstrnew branch r13480 by florian:
* merged old cpstr branch

git-svn-id: trunk@19079 -
2011-09-17 10:03:59 +00:00
Jonas Maebe
7fe0485a4e * always allow typecasts between enums and pointers/classes on the JVM target
and treat them like tc_equal rather than tc_int_2_int, because enums /are/
    class instances there

git-svn-id: branches/jvmbackend@18811 -
2011-08-23 15:25:47 +00:00
Jonas Maebe
28c20cfc5e * the default string type for the JVM target is no longer automatically
unicodestring = java.lang.String. The reason this was the default in
    the past is that this was the first string type that was implemented,
    and without it being the default most code involving string operations
    would fail. Now the default strings types are the same as for other
    targets
  + new {$modeswitch unicodestrings} directive, that when activated
    *together* with {$h+},
   1) changes char into an alias for widechar
   2) changes string into an alias for unicodestring
   3) changes the preferred string evaluation type (in case of uncertainty)
      to unicodestring
    {$modeswitch unicodestrings} with {$h-} does not change anything at all
    regarding the string type (it still changes the char type)
  + new uuchar unit that redefines char as widechar, and which is automatically
    included by the compiler if {$modeswitch unicodestrings} is enabled

git-svn-id: branches/jvmbackend@18781 -
2011-08-20 08:35:47 +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
40fdc62e74 + support for automatically converting char/widechar to java.lang.String
git-svn-id: branches/jvmbackend@18653 -
2011-08-20 08:21:34 +00:00
Jonas Maebe
9aae0c47bd * manual merge of svn r17800 (open array overload choosing)
git-svn-id: branches/jvmbackend@18606 -
2011-08-20 08:14:36 +00:00
Jonas Maebe
aa1f299a17 + added hook for "individual value to open array of one element"-conversion,
so it can be intercepted by the JVM backend (it has to create an actual
    array)
  + JVM support for the elem_2_open_array hook

git-svn-id: branches/jvmbackend@18561 -
2011-08-20 08:10:31 +00:00
Jonas Maebe
6614f3220c * check implementedinterfaces also when going from a Java class to
a Java interface

git-svn-id: branches/jvmbackend@18532 -
2011-08-20 08:07:50 +00:00
Jonas Maebe
91855becfe + unicodestring support for the JVM target (except for multiple adds
in a single statement, to be added later)
   o the unicodestrings are internally simply java.lang.String instances
   o at the language level, the unicodestrings are assignment-compatible
     with java.lang.String
   o constant strings can be implicitly converted to java.lang.String
   o since java.lang.String is immutable, in particular changing a
     single character in a string is extremely inefficient. This could
     be solved by letting unicodestring map to java.lang.StringBuilder,
     but that would make integration with plain Java code harder

git-svn-id: branches/jvmbackend@18470 -
2011-08-20 08:02:33 +00:00
Jonas Maebe
7200245337 + cs_unicodestrings global switch to indicate that the default string type
is unicodestring (does *not* change the type of "char" to "unicodechar"
    (yet)). Not yet (un)selectable via a directive.
  + systems_default_unicodestring set containing systems on which the
    default string type is unicodestring

git-svn-id: branches/jvmbackend@18415 -
2011-08-20 07:57:45 +00:00
Jonas Maebe
b5f2b463b8 * mention that Java classes also have anonymous/formal external definitions
git-svn-id: branches/jvmbackend@18413 -
2011-08-20 07:57:36 +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
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
Jonas Maebe
19fb48dfa9 * prefer "any array" -> "open array" over "single element" -> "open array"
conversions, instead failing to choose the best overload (Delphi-compatible)

git-svn-id: trunk@17800 -
2011-06-22 19:32:28 +00:00
florian
37b8b791d5 * overloaded versions of IsNan, resolves #14351
* prefer <ord> -> single over <ord> -> double/extended, this is delphi compatible

git-svn-id: trunk@17758 -
2011-06-14 20:38:51 +00:00