[Lazarus] Lazarus in trunk not working after Rev 50151 on MacOSX
Mattias Gaertner
nc-gaertnma at netcologne.de
Tue Nov 3 20:26:07 CET 2015
On Tue, 3 Nov 2015 19:37:04 +0100
Ondrej Pokorny <lazarus at kluug.net> wrote:
> On 03.11.2015 17:34, Mattias Gaertner wrote:
> > codetools use only a simple heuristic to calculate the type of a
> > binary operator.
> > The function TFindDeclarationTool.CalculateBinaryOperator needs to be
> > extended for Alias types (e.g. 'integer' instead of longint) and for
> > ranges (e.g. if the operands do not fit into an integer).
>
> Maybe you are talking about the same, but just to be sure: IMO using
> hard-coded alias types is not a good idea (theoretically the user can
> redefine them).
No, I meant that 'integer' is defined as
type integer = longint;
For the compiler 'integer' is just an alias for longint.
But codetools should use the alias as much as possible instead of the
underlying base type.
Maybe I should have used 'SizeInt' as an example. SizeInt can be
longint or int64. When a function returns SizeInt codetools should
declare the variable as SizeInt instead of the current base in order to
help creating cross platform code.
> Instead the type evaluation should go to the end type
> (e.g. from Integer to *longint*) and then the end types should be
> compared. The comparison can then be done with a hard-coded table (you
> need it only for the basic types, so it is OK and safe) and the type
> that wins, will be used as the result type (obviously the originally
> used alias).
>
> E.g.:
>
> procedure Test;
> var
> I: Integer;
> S: SmallInt;
> begin
> Res := I + S;
> end;
>
> Something like:
> 1.)
> I = (Integer -> longint)
> S = SmallInt
> 2.)
> ResultBasicType = Compare(longint, SmallInt) -> longint -> I
> 3.)
> ResultType = ResultBasicType -> I -> *Integer*
That would fail with the following example:
var
i: SizeInt;
j: SmallInt;
begin
k:=i+j;
end;
The result should be SizeInt, not Integer.
Of course there are some hard coded defaults in codetools. For example
"i:=3" can be any integer type. In TP/Delphi/LCL applications
"integer" is used so often it is a good default.
Same for "String".
But what type should "i:=3.0" create? Single, Double, Extended,
glFloat?
It would be nice if codetools could guess the "usual" type from the
surrounding code or if it can be set via an IDE/project/package option.
Mattias
More information about the Lazarus
mailing list