Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread Alexey Barkovoy
{$mode delphi}
type aenum=510..517;
aset = set of aenum;
begin
 Writeln(sizeof(aset));
end.
xbla.pp(5,25) Error: illegal type declaration of set elements
xbla.pp(10,4) Fatal: There were 1 errors compiling module, stopping
Delphi dowsn't allow sets with ordinal values larger than 255 too:
Borland Delphi  Version 13.0  Copyright (c) 1983,99 Inprise Corporation
1.pas(2) Error: Sets may have at most 256 elements
1.pas(8)
=
Borland Delphi for Win32 compiler version 17.0
Copyright (c) 1983,2004 Borland Software Corporation
1.pas(2) Error: E2028 Sets may have at most 256 elements
1.pas(8)
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread Marco van de Voort
> > Older Delphi (and TP?) versions implemented sets of subranges (e.g. set
> > of 510..515) by "stripping" unused bytes in front of the set. The lowest
> > bit in a set variable always had an ordinal value of 2^n, and above set
> > would occupy 2 bytes, equaling an set of (504..519). In newer Delphi
> > versions the lowest bit exactly corresponds to the lowest ordinal value
> > in the range, the above set only occupies one byte (510..517).
> 
> Supported by FPC

{$mode delphi}

type aenum=510..517;
 aset = set of aenum;


begin
  Writeln(sizeof(aset));
end.

xbla.pp(5,25) Error: illegal type declaration of set elements
xbla.pp(10,4) Fatal: There were 1 errors compiling module, stopping

Redone with 200..207;-> size = 32 byte = 256 element, so the behaviour
of the older version.

 

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread Peter Vreman
> Older Delphi (and TP?) versions implemented sets of subranges (e.g. set
> of 510..515) by "stripping" unused bytes in front of the set. The lowest
> bit in a set variable always had an ordinal value of 2^n, and above set
> would occupy 2 bytes, equaling an set of (504..519). In newer Delphi
> versions the lowest bit exactly corresponds to the lowest ordinal value
> in the range, the above set only occupies one byte (510..517).

Supported by FPC

> AFAIR D6 introduced "open" enums, with arbitrary (discontinuous...)
> values for the members. IMO this only is an attempt to closer reflect C
> enums, but sets of such enumerated types are not allowed.

Supported by FPC



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


RE: [fpc-devel] TShiftState as enum

2005-02-17 Thread Jose Manuel


>
> Can somebody enlighten me, what code exactly fails in D6?
> What extension does FPC have, that Delphi doesn't have?
>
> And what "iteration" is desired? I'd use: For Low(x) To High(x)...

>
> Let me add some more notes, regarding Delphi compatibility:
>
> Older Delphi (and TP?) versions implemented sets of subranges (e.g. set
> of 510..515)

i don't want to become heavy, but a subrange it's a subrange and a set is a
set.
If you'd use Low() and High(), your treating a set as if it were an array,
that can be handy sometimes, but strictly speaking, a set has no lower or
higher elements.
As far as I can remember, in TP, sets were represented with a single byte,
that is, the 255 bits were on or off (1 or 0) and represented the existance
or the lack of it in the set.
AFAICK, you can check for a determinate value in a set, but you can't
"navigate" through it as if it were an array. OK, you can use Boolean
operators (Union, Intersection, Rest...) and the Include, Exclude functions,
etc..., if you feel more comfortable. But there's no firt element, there are
no repeated elements, etc... It's a set

> AFAIR D6 introduced "open" enums, with arbitrary (discontinuous...)
> values for the members. IMO this only is an attempt to closer reflect C
> enums, but sets of such enumerated types are not allowed.

That's right. Enumerated open types (C-alike), such as (GREY=14, RED,
BLUE=21, ...) were introduced in D6, but anyway don?t have nothing to do
with sets.
>
>
> I do not ask for any compatibility in these cases, in detail when the
> Delphi implementation differs amongst compiler versions.

I really don't know, but I guess you are right, it must be a compiler
dependence.

JMR



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread DrDiettrich
Marco van de Voort wrote:
> 
> > > TShiftState is defined as TShiftState = set of (...);
> > >
> > > How can I iterate through the enums? If not, can we split and add an
> > > enum:
> > >
> > > TShiftStateEnum = (...)
> > > TShiftState = set of TShiftStateEnum;
> > >
> > > ?
> >
> > Of course that is possible. It requires some imagination though (and a feel
> > for obfuscated Pascal)
> 
> The example fails in Delphi 6 btw, but works in FPC :-)
> Delphi does not allow low/high on sets
> 
> (I vote to keep this FPC extension btw)

Can somebody enlighten me, what code exactly fails in D6?
What extension does FPC have, that Delphi doesn't have?

And what "iteration" is desired? I'd use: For Low(x) To High(x)...


Let me add some more notes, regarding Delphi compatibility:

Older Delphi (and TP?) versions implemented sets of subranges (e.g. set
of 510..515) by "stripping" unused bytes in front of the set. The lowest
bit in a set variable always had an ordinal value of 2^n, and above set
would occupy 2 bytes, equaling an set of (504..519). In newer Delphi
versions the lowest bit exactly corresponds to the lowest ordinal value
in the range, the above set only occupies one byte (510..517).

AFAIR D6 introduced "open" enums, with arbitrary (discontinuous...)
values for the members. IMO this only is an attempt to closer reflect C
enums, but sets of such enumerated types are not allowed.


I do not ask for any compatibility in these cases, in detail when the
Delphi implementation differs amongst compiler versions.

DoDi


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Abbrevia and Delphi compatibility

2005-02-17 Thread DrDiettrich
Peter Vreman wrote:

> > 1) Properties for Object type.
> 
> Since which Delphi version is a property allowed in an normal object?

I'm not sure, but at least D4 supports such properties.

> Currently FPC has special code that forbids property in objects for delphi
> mode.

Then it would be sufficient to remove that special code?

BTW, I didn't find object properties mentioned in the FPC documentation
(HTML). Properties only are described for Class types?


> We can't promise anything.

Granted ;-)

DoDi



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Abbrevia and Delphi compatibility

2005-02-17 Thread DrDiettrich
Marco van de Voort wrote:
> 
> > 2) Sets with minimal size, at least with 1 and 2 bytes for replacement
> > of Byte and Word types.
> >
> > I consider both features as vital in translations from C to Pascal, and
> > in the detection and elimination of bugs. Will it be possible to add
> > these features to FPC, this year?
> 
> I'm interested in the last one. What is exactly the problem with it, except
> foreign data, like API declarations (which are rare anyway), and binary
> files?

The size restriction applies almost only to filed records, whereas
in-memory data structures usually can be realigned at will.

The use of enums and sets allows for safer code, instead of working with
bitmasks and general ordinal data types and constants. According (set)
variables can be found in many data structures, so that it would be nice
to retype such fields as appropriate sets in Pascal code.
 
> The C argument is a bit doubtful, since there are more such problems (like
> bitpacking, not being able to exactly duplicate any union), so 1:1 remapping
> is not really possible anyway.

Even C bitfields can be emulated perfectly in Pascal, with Object types
and properties.
Named C unions can be emulated by variant records in Pascal, only
anonymous unions sometimes require changes to the code, or the use of
objects with properties. But also some (legacy) Pascal constructs (file
open mode...) could be much nicer and safer with structured data types.

DoDi



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


RE: [fpc-devel] TShiftState as enum

2005-02-17 Thread Jose Manuel
> Jose Manuel wrote:
>
> >I think sets are sets and enumerated types are enumerated types,
> and Pascal
> >is Pascal-
> >
> >
> Ok, but in pascal the elements in a set can only be of ordered
> type anyway.

Yes, of course. Maybe I haven't explained myself. Indeed, and you are quite
right you'got to define a set of ... (an scalar or enumerated type you've
previously defined), but once you're created the set is a "set", there are
no order established. I think this is no place nor time to talk about Cantor
or whether a subset is part of itself, etc. I just keep on my opinion (until
you refuse me with arguments, and I will accept them gratefully, don't doubt
on that), that casting that way is against Pascal's spirit (and against
Boolean Algebra, I think).

Anyway, it's only my opinion.
As Michael would say, there are more (and more neccessary) things to do than
to speak in this list about angels' sex.


JMR



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread Nikolay Nikolov
Jose Manuel wrote:
Well, sets are by definition a kind of bag. No enumeration or any kind of
order are suited to sets.
Can be handy, I agree, under certain situations, but then we are getting
back to C.
I think sets are sets and enumerated types are enumerated types, and Pascal
is Pascal-
 

Ok, but in pascal the elements in a set can only be of ordered type anyway.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


RE: [fpc-devel] TShiftState as enum

2005-02-17 Thread Jose Manuel


> > >
> > > > TShiftStateEnum = (...)
> > > > TShiftState = set of TShiftStateEnum;
> > > >
> > > > ?
> > >
> > > Of course that is possible. It requires some imagination though (and
> > > a feel for obfuscated Pascal)
> >
> >
> > The example fails in Delphi 6 btw, but works in FPC :-)
>
> Interesting :)
>
> But in this case: why not simply add one line to classes.pp?
>
>
> > Delphi does not allow low/high on sets
> >
> > (I vote to keep this FPC extension btw)
>
> Yes.

Well, sets are by definition a kind of bag. No enumeration or any kind of
order are suited to sets.
Can be handy, I agree, under certain situations, but then we are getting
back to C.
I think sets are sets and enumerated types are enumerated types, and Pascal
is Pascal-

> Mattias

Only IMHO, of course

JMR



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread Marco van de Voort
> [EMAIL PROTECTED] (Marco van de Voort) wrote:
> > 
> > The example fails in Delphi 6 btw, but works in FPC :-)
> 
> Interesting :)

Yeah, D2005 for IN syntax is also useful for this (if it operates on sets)
 
> But in this case: why not simply add one line to classes.pp?

That is not as much fun!

(But I meanwhile already committed and forwarded the tag (so it will be in
1.9.8))

> > Delphi does not allow low/high on sets
> > 
> > (I vote to keep this FPC extension btw)
> 
> Yes.

I also submitted it as bug/wishlist to Borland.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread Vinzent Hoefler
On Thursday 17 February 2005 07:37, Marco van de Voort wrote:

> type myset = set of ( a1,a2,a3,a4,a5,a6);
>
> // workaround types
> const
>  beginmyset=ord(low(myset));
>  endmyset=ord(high(myset));
> type
>  uglyenum = beginmyset..endmyset;
>  uglyset= set of uglyenum;
>
> var b : myset;
> i : integer;
>
> begin
>   b:=[a1,a2,a3];
>   for i:=ord(low(myset)) to ord(high(myset)) do
> if i in uglyset(b) then writeln(i);
> end.

"Almost every complex solution ...":

type
   My_Set = set of (a1, a2, a3, a4, a5, a6);

// workaround type
type
   Ugly_Enum = Low (My_Set) .. High (My_Set);

var
   b : My_Set;
   i : Ugly_Enum;

begin
   b := [a1, a2, a3, a5];

   for i := Low (b) to High (b) do
  if i in b then
 WriteLn (Ord (i));
end.

Personally I would prefer to first define the enum and the "set of enum" 
then. While looking at it: Notice that the code above just reverses the 
order of the definitions which you need anyway. Quite awkward, I think.


Vinzent.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] TShiftState as enum

2005-02-17 Thread Mattias Gaertner
On Thu, 17 Feb 2005 08:58:01 +0100 (CET)
[EMAIL PROTECTED] (Marco van de Voort) wrote:

> > > TShiftState is defined as TShiftState = set of (...);
> > > 
> > > How can I iterate through the enums? If not, can we split and add
> > > an enum:
> > > 
> > > TShiftStateEnum = (...)
> > > TShiftState = set of TShiftStateEnum;
> > > 
> > > ?
> > 
> > Of course that is possible. It requires some imagination though (and
> > a feel for obfuscated Pascal)
> 
> 
> The example fails in Delphi 6 btw, but works in FPC :-)

Interesting :)

But in this case: why not simply add one line to classes.pp?


> Delphi does not allow low/high on sets
> 
> (I vote to keep this FPC extension btw)

Yes.

Mattias

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel