andgineer / TRegExpr

Regular expressions (regex), pascal.
https://regex.sorokin.engineer/en/latest/
MIT License
174 stars 62 forks source link

function regNextQuick(p: PRegExprChar): PRegExprChar has problem with inline in delphi #350

Closed dkounal closed 9 months ago

dkounal commented 10 months ago
  1. inline is not accepted in implementation
  2. [dcc32 Error] regexpr.pas(5279): E2441 Inline function declared in interface section must not use local symbol 'PRENextOff'
Alexey-T commented 10 months ago

i use Linux, so please test this: find

function TRegExpr.regNextQuick(p: PRegExprChar): PRegExprChar; {$IFDEF InlineFuncs}inline;{$ENDIF}

and remove trailing 'inline' with IFDEF. but keep 'inline' in the 'interface' part.

dkounal commented 10 months ago

I did this and it works

dkounal commented 10 months ago
function regNextQuick(p: PRegExprChar): PRegExprChar; in definition needs also not be inline
Alexey-T commented 10 months ago

New fix made, must be OK now..

dkounal commented 10 months ago

It is ok, but probably the delphi compiler is correct, see the description of the error: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/E2441_Inline_function_declared_in_interface_section_must_not_use_local_symbol_%27%25s%27_(Delphi) The problem is that the following are declared in the implementation section for an inline function declared in the interface section TRENextOff = PtrInt; // internal Next "pointer" (offset to current p-code) PRENextOff = ^TRENextOff; // used for extracting Next "pointers" from compiled r.e.

Is it a problem for this declaration to be in the interface section?

Alexey-T commented 10 months ago

then we need AlignToPtr also in interface part, which is worse.

dkounal commented 10 months ago

Can we have the regNextQuick inside a class helper in the implementation section? I did it and the compiler does not produce error even it is inline

Alexey-T commented 10 months ago

inside a class helper

class helper won't be compiled by old Delphi...

dkounal commented 10 months ago

I think it is since Delphi 7 the class helper

Alexey-T commented 10 months ago

but see here:

A feature of the Delphi language added some years ago (way back in in Delphi 2005) called "Class Helpers" is designed to let you add new functionality

https://www.thoughtco.com/understanding-delphi-class-and-record-helpers-1058281

dkounal commented 10 months ago

You have right. Probably not inline for old Delphi and class helper for new versions through preprocessor commands?

Alexey-T commented 9 months ago

no, making 2 versions of function is not good. better we will have smaller speed in Delphi (not much smaller).