Commit Graph

404 Commits

Author SHA1 Message Date
sergei
1744988962 * Modified behavior of CExtended type in overload selection: it is made more compatible to Extended than to Double and Single. Also an Extended parameter selects a CExtended overload (if available) instead of Double.
+ Test.

git-svn-id: trunk@27366 -
2014-03-30 07:31:58 +00:00
florian
3e4198ea45 * take care of dyn. arrays in cse
git-svn-id: trunk@26740 -
2014-02-08 21:47:46 +00:00
florian
1366498255 + nf_addr_taken: it marks nodes which address is taken
+ check if tnodeflags is 4 bytes or less
* do not do cse on expressions which address is taken

git-svn-id: trunk@26713 -
2014-02-07 20:40:42 +00:00
Jonas Maebe
89d97a3c2e * only consider tc_pointer_to_array typeconversions to determine whether a
pointer->array type conversion implies an implicit dereference operation
    (mantis #25622)

git-svn-id: trunk@26608 -
2014-01-28 20:14:24 +00:00
florian
4d5119bf1c * fixes several issues which cause warnings by the dfa code when using it to detect uninitialized variables
git-svn-id: trunk@26161 -
2013-12-01 17:02:08 +00:00
florian
6f03d04fe1 * when using a pointer as array, the pointer is never written, only read
git-svn-id: trunk@25964 -
2013-11-06 21:10:30 +00:00
svenbarth
798bb91e90 Extract tdef.is_related plus its overrides in tobjectdef, trecorddef and tstringdef into a new function def_is_related in unit defcmp.
defcmp.pas:
  + add new function "def_is_related" which combines the "is_related" overloads of "tobjectdef", "trecorddef" and "tstringdef" (it returns "false" for other def types which is what "tdef.is_related" did)
  * compare_defs_ext & compatible_childmethod_resultdef: change call from "x.is_related" to "def_is_related(x,...)"
symtype.pas, tdef:
  - remove "is_related" method
symdef.pas:
  - remove "is_related" in "tobjectdef", "trecorddef" and "tstringdef"
  * tobjectdef.needs_inittable: for checking whether a Corba interface somehow inherits from a IInterface don't use "is_related" anymore (we want to avoid the dependency after all), but mimic the necessary functionality of "def_is_related"
htypechk.pas, nadd.pas, ncal.pas, ncnv.pas, ngtcon.pas, nld.pas, optvirt.pas, pdecobj.pas, pdecvar.pas, pexpr.pas, pgenutil.pas:
  * change call from "x.is_related" to "def_is_related(x,...)"
symtable.pas
  + use unit defcmp
  * change call from "x.is_related" to "def_is_related(x,...)"
jvm/njvmcnv.pas, jvm/njvmflw.pas:
  * change call from "x.is_related" to "def_is_related(x,...)"

git-svn-id: trunk@25847 -
2013-10-25 19:44:27 +00:00
svenbarth
168c9d152f Small optimization for the search of operator overloads. Add a flag "sto_has_generic" to all symtables that contain an operator overload (the flag propagates up the owning symtables) and check this flag when searching for units with operators.
symconst.pas:
  + add "sto_has_operator" to "tsymtableoption"
pdecsub.pas:
  + include the flag "sto_has_operator" for all operator declarations and their owning symtables
htypechk.pas, tcallcandidates:
  * create_candidate_list: only check for operator overloads if the record does indeed declare some
  * collect_overloads_in_units: only check for operator overloads if the unit does indeed declare some
utils/ppudump.pp:
  + respect the new "sto_has_operator" flag

git-svn-id: trunk@23688 -
2013-03-04 16:02:18 +00:00
florian
b43b4bb455 + pseudo procedure aligned: tells the compiler to assume that the given parameter is naturally aligned, counterpart of unaligned
git-svn-id: trunk@23310 -
2013-01-04 19:13:24 +00:00
florian
728c074bd6 * accept with statements with generic variables having a generic parameter type, resolves #21329
git-svn-id: trunk@23243 -
2012-12-28 19:48:33 +00:00
Jonas Maebe
fd8827d379 * prevent compiler crash caused by double freeing after reporting not
overloaded operator errors

git-svn-id: trunk@22833 -
2012-10-23 16:50:30 +00:00
Jonas Maebe
76b0ee9925 * treat all "uninitialized" hints as warnings on JVM platforms, because
they generally result in fatal run time errors there

git-svn-id: trunk@22571 -
2012-10-07 09:10:08 +00:00
Jonas Maebe
5ea03973d3 * reject assignments to vecn[rangen] (mantis #22941)
git-svn-id: trunk@22434 -
2012-09-21 22:42:30 +00:00
florian
ca5fabda6d * cleanup some unused units from uses clauses
git-svn-id: trunk@22433 -
2012-09-21 18:53:46 +00:00
pierre
1550c623c3 Avoid memory leak in isbinaryoverloaded function
git-svn-id: trunk@22425 -
2012-09-19 07:59:12 +00:00
Jonas Maebe
3b968b4b35 * don't allow overloading enum/int operations, because they should be
interpreted as internally define operations in case of enum type
    definitions in {$mode delphi} (mantis #22860)

git-svn-id: trunk@22377 -
2012-09-12 16:03:09 +00:00
Jonas Maebe
cf4a2bd392 * fixed java.lang.String and Pascal string comparisons after operator
overloading rewrite (consider java_jlstring to be "stringlike")

git-svn-id: trunk@22127 -
2012-08-19 13:57:48 +00:00
Jonas Maebe
f3ad4af343 * make sure valid_for_assign() returns false for inlined function bodies
(mantis #22613)

git-svn-id: trunk@22099 -
2012-08-16 19:22:17 +00:00
svenbarth
360592d1f4 Some corrections after the loosening of operator overloads:
* check "A op B" and "B op A" again for operators that can be commutative (all binary ones except shl, shr, div, mod, **, / and -)
* also check for Nil for classrefdefs if left side is a pointer (allows "TClass var" <>/= Nil again, after the above changes)
* don't allow overloads for "implicit pointer type <>/= pointer" and the other way around (this fixes non compiling Objective Pascal test tobjc21.pp and also the new toperator87.pp test)
* some formating corrections

+ added test for "TObject <> Pointer"
+ added test for "TClass <>/= Nil"

git-svn-id: trunk@21983 -
2012-07-29 12:38:09 +00:00
svenbarth
b0458b55a3 Loosen the restriction regarding operator overloads by applying a (modified) patch from JC Chu. This fixes Mantis #22359.
The changes are built up in a way that all operators on two given types are not allowed if a default implementation for that operator exists. This implies that there is a possibility to have a overload work for (in this order) type A and B, but not for B and A. This is for example the case for Set + Enum (which seems to have a default implementation) where Enum + Set is allowed. The added tests try to detect as many default implementations as feasible, but can't cover everything...

git-svn-id: trunk@21975 -
2012-07-26 18:02:01 +00:00
Jonas Maebe
fdbe35aadf * only try to call procvars while choosing overloads in case they don't
require any parameters (mantis #22320)

git-svn-id: trunk@21729 -
2012-06-28 14:41:31 +00:00
Jonas Maebe
12553a9367 * don't give -CO warnings or hints for ordinal constants, because those
are already checked by range checking (and were checked wrongly by -CO
    checking) (mantis #19581)

git-svn-id: trunk@21504 -
2012-06-06 19:28:22 +00:00
Jonas Maebe
95b8b95c9c * fixed (harmless) class cast error
git-svn-id: trunk@21260 -
2012-05-08 20:02:18 +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
5f3db3c1ba * if we assign something to a record field whose type is not regable by
itself (e.g. a 3-byte record as field insde a 4 byte record), make
    the parent record non-regable either. The reason is that the parent
    record will be forced to memory in that case when subscripting, and
    the assignment will happen to this temporary memory location.
    Fixes tests/test/tw15357.pp on ppc64 when compiled with -O2 and
    without -Cg (not sure why enabling PIC disables global regvars)

git-svn-id: trunk@20959 -
2012-04-21 18:38:31 +00:00
paul
b80e7c8fba compiler: change candidates search preference for variant arguments based on testing delphi XE + fixing tests
before the change order was (from better to worse): shortstring, ansistring, widestring, unicodestring
now the order is (from better to worse): widestring, unicodestring, ansistring, shortstring

git-svn-id: trunk@20907 -
2012-04-18 09:13:24 +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
florian
ce845bf97c * introduction of in_generic in r20699 was unneeded, replaced by parse_generic
git-svn-id: trunk@20858 -
2012-04-12 21:53:10 +00:00
florian
79a77ae7d6 + in_generic for testing if currently a generic declaration/definition is parsed/record
* omit several error messages when in_generic is true because the error can be checked only during specialisation, resolves the issue reported in #21592

git-svn-id: trunk@20699 -
2012-04-03 19:29:09 +00:00
svenbarth
bd19a16be9 Add support for Default() intrinsic. For now this is only (fully) supported
in code and not in constants. In the case of primitive types constant nodes
are used while complex types like arrays, records and objects use a local
variable which is initialized to zero once at the entry of the method (the
variable is reused if Default() is used for the same type multiple times in
the same method). For this a new compilerproc was added which uses FillChar
to initialize the given memory area to zero.
This fixes Mantis #9420.

+ psystem.pas: Added Default symbol to system unit
+ htypechk.pas: Added function "is_valid_for_default" which checks recursively
                whether the given type can be used with Default at all. 
                Forbidden types are files, helpers, ObjC and C++ types. This
                check is used for records, arrays and objects only if the mode
                is a non-Delphi one, as Delphi ignores these types on lower
                levels.
+ msg/errore.msg: Added error message for unsupported types for Default()
+ symconst.pas: Added a new enum value vo_is_default_var which is used for the
                local variables utilized by Default() so their initalization
                and finalization can be avoided.
+ pexpr.pas: Add handling of Default() intrinsic to "statement_syssym"
+ ninl.pas: Extended tinlinenode by a method which returns the correct node for
            a Default() and used that method in handle_typecheck.
* ncgutil.pas: Check for new flag "vo_is_default_var" when initializing and
               finalizing local variables.
* ppu.pas: increase PPU version
+ psub.pas: 
  * Added a new routine which zeros defaultvars of a symtable.
  * Use this routine inside "initializevars".
  * Also use this routine to initialize the staticsymtable of the unit/program.
* Adjusted ppudump, because of the new enum value.
+ Added implementation of fpc_zeromem to system unit.
+ Added tests for Default()

git-svn-id: trunk@20629 -
2012-03-25 16:02:27 +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
Jonas Maebe
e5c097a6e2 * mark nodes that have been created by transforming a read-accessor of
of a property with nf_no_lvalue flag, and check that such nodes are
    never used in direct assignments (fixes mantis #21087 and a couple of
    other cases of invalid assignments to properties)

git-svn-id: trunk@20140 -
2012-01-21 19:09:30 +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
florian
6ec0f2549a * factored load node flags out of node flags to gain space
+ implemented iso mode mod, resolves #17685

git-svn-id: trunk@19558 -
2011-10-30 15:14:21 +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
florian
df75368d0b --- Merging r19281 into '.':
U    compiler\pdecsub.pas
U    compiler\symdef.pas
U    compiler\pdecobj.pas
U    compiler\htypechk.pas
U    compiler\ncal.pas
U    compiler\symtable.pas
--- Recording mergeinfo for merge of r19281 into '.':
 U   .
--- Merging r19282 into '.':
A    tests\webtbf\tw19975.pp
--- Recording mergeinfo for merge of r19282 into '.':
 G   .

git-svn-id: trunk@19343 -
2011-10-03 20:43:19 +00:00
florian
4868b09844 * patch by alexvin to replace $ifopt by $push/$pop, resolves #20332
git-svn-id: trunk@19239 -
2011-09-25 21:19:50 +00:00
Jonas Maebe
dff5ac3b0a * don't allow passing a field of a record that's not an lvalue as
var-parameter, nor allowing taking its address (mantis #20095)

git-svn-id: trunk@19199 -
2011-09-23 21:21:49 +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
7dd8a97487 compiler: allow "with" to search members in nested types properly
git-svn-id: trunk@18987 -
2011-09-06 10:23: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
a73d5b6da7 * only set the assignmentside flag for typeconversion nodes in
valid_for_assign() if that routine returns true (in some cases,
    it's used to simply check whether we could possibly put it on
    the assignment side)

git-svn-id: branches/jvmbackend@18751 -
2011-08-20 08:32:41 +00:00
Jonas Maebe
1c74072748 * moved handle_staticfield_access() from pexpr to nutils so it can
be reused elsewhere
  * moved check_hints() from htypechk to symsym (so it can be called
    from nutils, and it's also more about symbols than about types)

git-svn-id: branches/jvmbackend@18722 -
2011-08-20 08:27:42 +00:00
Jonas Maebe
3320fee51c * use symbol type instead of sp_static flag to determine whether a final
symbol can only be assigned in the constructor or class constructor

git-svn-id: branches/jvmbackend@18611 -
2011-08-20 08:15:00 +00:00
Jonas Maebe
10a7532968 * differentiate between typecasts on the assignment side or not, because we
cannot insert typecasting checks on the assignment side, only on the
    values that are being assigned
   o since valid_for_assignment() is called in tassignmentnode.typecheckpass()
     after typecheckpassing left and right, moved the conversion of the
     typecheck nodes into JVM-specific constructs from typecheckpass to
     pass_1, so that they can use the information whether they are on
     the assignment side or not
  * forbid casting a child type to a parent type on the assignment side on
    managed platforms, because that circumvents the type checking

git-svn-id: branches/jvmbackend@18515 -
2011-08-20 08:06:20 +00:00
Jonas Maebe
694ccf3df3 + dummy support for untyped var/const/out parameters on the JVM target
o includes basic "auto-boxing" infrastructure to support Delphi.NET-
     compatible untyped parameters as described at
     http://hallvards.blogspot.com/2007/10/dn4dp24-net-vs-win32-untyped-parameters.html

git-svn-id: branches/jvmbackend@18510 -
2011-08-20 08:05:54 +00:00
Jonas Maebe
d79160a6af * correctly handle explicit typecasts between records and jlobject/
fpcbaserecordtype for the JVM target (intercept in ncnv via new
    target_specific_general_typeconv helper, handle in as/is code)
  * not only check for related types in htypechk in case they are
    objdefs, but always do so (records are related to jlobject/fpcbaserecord
    on the JVM target)

git-svn-id: branches/jvmbackend@18458 -
2011-08-20 08:01:29 +00:00
Jonas Maebe
37b5c061e3 + support for "final" fields in *external* (Java and other) classes, enabled
via {$modeswitch finalfields} (on by default on the JVM target). The
    meaning is the same as in Java: a final (class) field can only be set
    in a (class) constructor of the class it's defined in, and can only be
    written once there (and *must* be set there). They are currently only
    supported for external classes since that basically turns them into
    constants, since for non-external classes we need full dataflow analysis
  o refactored pdecobj.parse_object_members() a bit in the process to reduce
    the amount of repetition (which would have been further increased for
    the support for final fields)
  o made error message about "wrong use of absolute" for fields etc generic,
    so it gives a proper error depending on which token was used (it had
    to be made generic for "final" support, but already was used for other
    things that were wrongly reported as "absolute" misusages)

git-svn-id: branches/jvmbackend@18398 -
2011-08-20 07:56:18 +00:00