Sign in Join

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

Mailing lists / lazarus / 2015-10

Codetools question

12 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt

Hi,

Mainly for Mattias, I suppose:

The SetString routine in the system unit has become a compiler procedure in 3.0:

{$ifdef FPC_HAS_CPSTRING}
Procedure fpc_setstring_ansistr_pansichar(out S : RawByteString; Buf : PAnsiChar; Len : SizeInt; cp: TSystemCodePage); rtlproc; compilerproc;
{$else}
Procedure SetString(out S : AnsiString; Buf : PAnsiChar; Len : SizeInt);
{$endif}
begin
   SetLength(S,Len);
{$ifdef FPC_HAS_CPSTRING}
   SetCodePage(S,cp,false);
{$endif}
   If (BufNil) then
     fpc_pchar_ansistr_intern_charmove(Buf,0,S,0,Len);
end;

This means the codetools are no longer able to find the SetString declaration.

Is there any way to fix this kind of things (i.e. find compiler procs) in the code tools ?

Michael.

Reply by email

Ondrej Pokorny
to Michael Van Canneyt
Michael Van Canneyt wrote 28 lines
Hi, Mainly for Mattias, I suppose: The SetString routine in the system unit has become a compiler procedure in 3.0: {$ifdef FPC_HAS_CPSTRING} Procedure fpc_setstring_ansistr_pansichar(out S : RawByteString; Buf : PAnsiChar; Len : SizeInt; cp: TSystemCodePage); rtlproc; compilerproc; {$else} Procedure SetString(out S : AnsiString; Buf : PAnsiChar; Len : SizeInt); {$endif} begin SetLength(S,Len); {$ifdef FPC_HAS_CPSTRING} SetCodePage(S,cp,false); {$endif} If (BufNil) then fpc_pchar_ansistr_intern_charmove(Buf,0,S,0,Len); end; This means the codetools are no longer able to find the SetString declaration. Is there any way to fix this kind of things (i.e. find compiler procs) in the code tools ?

Yes, see TIdentCompletionTool.GatherPredefinedIdentifiers() in IdentCompletionTool.pas

Add this line there:

     AddCompilerProcedure('SetString','out
S:RawByteString;Buf:PAnsiChar;Len:SizeInt;cp:TSystemCodePage');

Ondrej

Reply by email

Michael Van Canneyt
to Ondrej Pokorny
Ondrej Pokorny wrote 37 lines
On 10.10.2015 12:35, Michael Van Canneyt wrote: > > Hi, > > Mainly for Mattias, I suppose: > > The SetString routine in the system unit has become a compiler procedure in > 3.0: > > {$ifdef FPC_HAS_CPSTRING} > Procedure fpc_setstring_ansistr_pansichar(out S : RawByteString; Buf : > PAnsiChar; Len : SizeInt; cp: TSystemCodePage); rtlproc; compilerproc; > {$else} > Procedure SetString(out S : AnsiString; Buf : PAnsiChar; Len : SizeInt); > {$endif} > begin > SetLength(S,Len); > {$ifdef FPC_HAS_CPSTRING} > SetCodePage(S,cp,false); > {$endif} > If (BufNil) then > fpc_pchar_ansistr_intern_charmove(Buf,0,S,0,Len); > end; > > This means the codetools are no longer able to find the SetString > declaration. > > Is there any way to fix this kind of things (i.e. find compiler procs) in > the code tools ? Yes, see TIdentCompletionTool.GatherPredefinedIdentifiers() in IdentCompletionTool.pas Add this line there: AddCompilerProcedure('SetString','out S:RawByteString;Buf:PAnsiChar;Len:SizeInt;cp:TSystemCodePage');

Oh cool :-)
I didn't know this existed, I keep underestimating the Lazarus IDE ;) How to detect the compiler version ? Because it is only for 3.0+, I suppose.

Michael.

Reply by email

Ondrej Pokorny
to Michael Van Canneyt
Michael Van Canneyt wrote 48 lines
On Sat, 10 Oct 2015, Ondrej Pokorny wrote: > On 10.10.2015 12:35, Michael Van Canneyt wrote: >> >> Hi, >> >> Mainly for Mattias, I suppose: >> >> The SetString routine in the system unit has become a compiler >> procedure in 3.0: >> >> {$ifdef FPC_HAS_CPSTRING} >> Procedure fpc_setstring_ansistr_pansichar(out S : RawByteString; Buf >> : PAnsiChar; Len : SizeInt; cp: TSystemCodePage); rtlproc; >> compilerproc; >> {$else} >> Procedure SetString(out S : AnsiString; Buf : PAnsiChar; Len : >> SizeInt); >> {$endif} >> begin >> SetLength(S,Len); >> {$ifdef FPC_HAS_CPSTRING} >> SetCodePage(S,cp,false); >> {$endif} >> If (BufNil) then >> fpc_pchar_ansistr_intern_charmove(Buf,0,S,0,Len); >> end; >> >> This means the codetools are no longer able to find the SetString >> declaration. >> >> Is there any way to fix this kind of things (i.e. find compiler >> procs) in the code tools ? > > Yes, see TIdentCompletionTool.GatherPredefinedIdentifiers() in > IdentCompletionTool.pas > > Add this line there: > > AddCompilerProcedure('SetString','out > S:RawByteString;Buf:PAnsiChar;Len:SizeInt;cp:TSystemCodePage'); Oh cool :-) I didn't know this existed, I keep underestimating the Lazarus IDE ;) How to detect the compiler version ? Because it is only for 3.0+, I suppose.

I think it is save to assume that Lazarus was compiled with the same FPC version that is also used for the sources in editor. Therefore you can use the same compiler directive:

{$ifdef FPC_HAS_CPSTRING}
    AddCompilerProcedure('SetString','out
S:RawByteString;Buf:PAnsiChar;Len:SizeInt;cp:TSystemCodePage');
{$endif}

Ondrej

Reply by email

Michael Van Canneyt
to Ondrej Pokorny
Ondrej Pokorny wrote 51 lines
On 10.10.2015 12:43, Michael Van Canneyt wrote: > > > On Sat, 10 Oct 2015, Ondrej Pokorny wrote: > >> On 10.10.2015 12:35, Michael Van Canneyt wrote: >>> >>> Hi, >>> >>> Mainly for Mattias, I suppose: >>> >>> The SetString routine in the system unit has become a compiler procedure >>> in 3.0: >>> >>> {$ifdef FPC_HAS_CPSTRING} >>> Procedure fpc_setstring_ansistr_pansichar(out S : RawByteString; Buf : >>> PAnsiChar; Len : SizeInt; cp: TSystemCodePage); rtlproc; compilerproc; >>> {$else} >>> Procedure SetString(out S : AnsiString; Buf : PAnsiChar; Len : SizeInt); >>> {$endif} >>> begin >>> SetLength(S,Len); >>> {$ifdef FPC_HAS_CPSTRING} >>> SetCodePage(S,cp,false); >>> {$endif} >>> If (BufNil) then >>> fpc_pchar_ansistr_intern_charmove(Buf,0,S,0,Len); >>> end; >>> >>> This means the codetools are no longer able to find the SetString >>> declaration. >>> >>> Is there any way to fix this kind of things (i.e. find compiler procs) in >>> the code tools ? >> >> Yes, see TIdentCompletionTool.GatherPredefinedIdentifiers() in >> IdentCompletionTool.pas >> >> Add this line there: >> >> AddCompilerProcedure('SetString','out >> S:RawByteString;Buf:PAnsiChar;Len:SizeInt;cp:TSystemCodePage'); > > Oh cool :-) > I didn't know this existed, I keep underestimating the Lazarus IDE ;) > How to detect the compiler version ? Because it is only for 3.0+, I > suppose. I think it is save to assume that Lazarus was compiled with the same FPC version that is also used for the sources in editor. Therefore you can use the same compiler directive:

This is definitely not so :-(
I compile lazarus with 2.6.4, but work with compiler set to 3.0 or even jvm.

That is how I bumped into the problem to begin with... :-)

Michael.

Reply by email

Ondrej Pokorny
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
This is definitely not so :-( I compile lazarus with 2.6.4, but work with compiler set to 3.0 or even jvm. That is how I bumped into the problem to begin with... :-)

CodeTools know what compiler constants are defined in the target tool. You have to check if FPC_HAS_CPSTRING is defined. This should be possible but I don't know how to do it. You'll have to wait for Mattias' answer.

Ondrej

Reply by email

Sven Barth
to Ondrej Pokorny: I think it is save to assume that Lazarus was compiled with the same FPC version that is…
"Ondrej Pokorny" wrote
I think it is save to assume that Lazarus was compiled with the same FPC

version that is also used for the sources in editor. Therefore you can use the same compiler directive:

Not necessarily. As a compiler developer I often switch between versions depending on whether I want to use a non-released feature or a stable compiler...

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151010/2b9f421a/attachment.html>

Reply by email

Mattias Gaertner
to Ondrej Pokorny: CodeTools know what compiler constants are defined in the target tool. You have to check…
Show quoted text 11 lines
On 10.10.2015 13:00, Michael Van Canneyt wrote: > This is definitely not so :-( > I compile lazarus with 2.6.4, but work with compiler set to 3.0 or > even jvm. > > That is how I bumped into the problem to begin with... :-) CodeTools know what compiler constants are defined in the target tool. You have to check if FPC_HAS_CPSTRING is defined. This should be possible but I don't know how to do it. You'll have to wait for Mattias' answer.

if Scanner.Values.IsDefined('FPC_HAS_CPSTRING') then ...

Mattias

Reply by email

Ondrej Pokorny
to Mattias Gaertner
Mattias Gaertner wrote 14 lines
On Sat, 10 Oct 2015 13:12:15 +0200 Ondrej Pokorny wrote: > On 10.10.2015 13:00, Michael Van Canneyt wrote: >> This is definitely not so :-( >> I compile lazarus with 2.6.4, but work with compiler set to 3.0 or >> even jvm. >> >> That is how I bumped into the problem to begin with... :-) > CodeTools know what compiler constants are defined in the target tool. > You have to check if FPC_HAS_CPSTRING is defined. This should be > possible but I don't know how to do it. You'll have to wait for Mattias' > answer. if Scanner.Values.IsDefined('FPC_HAS_CPSTRING') then ...

Great!

I added the procedure name to the list (see patch). It is shown without problems in the identifier completion window but it doesn't show any parameter hint help (ctrl+shift+space). I tried to register the procedure in "KeywordFuncLists.InternalInit" but it didn't help. Still no hint. What could be the problem?

Ondrej

Reply by email

Ondrej Pokorny
to Ondrej Pokorny
Ondrej Pokorny wrote
I added the procedure name to the list (see patch).
Forgot the file...
-------------- next part --------------
Index: components/codetools/identcompletiontool.pas
===================================================================
--- components/codetools/identcompletiontool.pas	(revision 50030)
+++ components/codetools/identcompletiontool.pas	(working copy)
@@ -1353,6 +1353,8 @@
     AddCompilerFunction('Seg','var X','LongInt');
     AddCompilerProcedure('SetLength','var S:String;NewLength:Integer');
     AddCompilerProcedure('SetLength','var A:Array;NewLength:Integer');
+    if Scanner.Values.IsDefined('FPC_HAS_CPSTRING') then
+      AddCompilerProcedure('SetString','out S:RawByteString;Buf:PAnsiChar;Len:SizeInt');
     AddCompilerFunction('SizeOf','Identifier','Integer');
     AddCompilerFunction('Slice','var A:Array;Count:Integer','Array');
     AddCompilerProcedure('Str','const X[:Width[:Decimals]];var S:String');

Reply by email

Mattias Gaertner
to Ondrej Pokorny: Great! I added the procedure name to the list (see patch). It is shown without problems…
Show quoted text 6 lines
[...] I added the procedure name to the list (see patch). It is shown without problems in the identifier completion window but it doesn't show any parameter hint help (ctrl+shift+space). I tried to register the procedure in "KeywordFuncLists.InternalInit" but it didn't help. Still no hint. What could be the problem?

KeywordFuncLists is for keywords.

The parameter hints are in codetools 'FindCodeContext'. I added it.

Mattias

Reply by email