Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-03

All constant operators

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

Can anyone help complete a list of all possible operators that could be used with constants in a record? I keep finding bugs with new operators so I need an exhaustive list for testing. The goal is complete the parser phase for the generic without getting errors so that only when it’s specialized you get specific errors if the wrong type was used.

Here’s what I have so far in my test:

type
  generic TUnaryOp<const I> = record
    const
      d0 = -I;
      d1 = +I;
      d2 = not I;
  end;
type
  generic TBinaryOp<const I> = record
    const
      d0 = I + I;
      d1 = I - I;
      d2 = I * I;
      d3 = I / I;
      d4 = I div I;
      d5 = I mod I;
      d6 = I and I;
      d7 = I or I;
  end;

In addition to this are there other places where constants could be used in a record? I’m only aware of default values for function parameters.

type
  generic TRoutines<const I> = record
    procedure DoThis(param: integer = I);
  end;

Regards,
Ryan Joseph

Reply by email

Ryan Joseph
to Ryan Joseph
Show quoted text 22 lines
On Mar 18, 2019, at 11:23 AM, Ryan Joseph wrote: type generic TUnaryOp<const I> = record const d0 = -I; d1 = +I; d2 = not I; end; type generic TBinaryOp<const I> = record const d0 = I + I; d1 = I - I; d2 = I * I; d3 = I / I; d4 = I div I; d5 = I mod I; d6 = I and I; d7 = I or I; end;

The new list. Anything I missed? I found the set operators crashed also so I need to test absolutely everything constants can do.

type
  generic TArray<const I> = record
    type
      t0 = array[0..I - 1] of integer;
      t1 = array[0..high(I)] of integer;
      t2 = array[0..low(I)] of integer;
      t3 = array[0..sizeof(I)] of integer;
    public
      d0: array[0..I - 1] of integer;
      d1: array[0..high(I)] of integer;
      d2: array[0..low(I)] of integer;
      d3: array[0..sizeof(I)] of integer;
  end;
  generic TUnaryOp<const I> = record
    const
      d0 = -I;
      d1 = +I;
      d2 = not I;
  end;
  generic TBinaryOp<const I> = record
    const
      // Arithmetic operators
      // https://freepascal.org/docs-html/ref/refsu45.html
      d0 = I + I;
      d1 = I - I;
      d2 = I * I;
      d3 = I / I;
      d4 = I div I;
      d5 = I mod I;
      // Boolean operators
      // https://freepascal.org/docs-html/ref/refsu47.html
      d6 = I and I;
      d7 = I or I;
      d8 = I xor I;
      // Logical operators
      // https://freepascal.org/docs-html/ref/refsu46.html
      d9 = I shl I;
      d10 = I shr I;
      d11 = I << I;
      d12 = I >> I;
      // Relational operators
      // https://freepascal.org/docs-html/ref/refsu50.html#x153-17500012.8.6
      d13 = I  I;
      d14 = I < I;
      d15 = I > I;
      d16 = I <= I;
      d17 = I >= I;
      d18 = I = I;
  end;
  Day = (mon,tue,wed,thu,fri,sat,sun);
  Days = set of Day;
  generic TSet<const I: Days> = record
    const
      d0 = I + I;   // Union
      d1 = I - I;   // Difference
      d2 = I * I;   // Intersection
      d3 = I >< I;  // Symmetric difference
      d4 = I <= I;  // Contains
      d5 = mon in I;
  end;
  generic TOther<const I> = record
    procedure DoThis(param: integer = I);
  end;

Regards,
Ryan Joseph

Reply by email