Sign in Join

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

Mailing lists / lazarus / 2014-11

PScanner tkComment token type

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Frederic Da Vitoria

Hello,

I am starting to use fpprofiler. Because I did not know what parameters should be sent to fpc, I decided to use fppinsert. At least one type of "instrumented" code fails to compile:
// some code { some comment }
is wrongly changed into
{ some code { some comment } }
which does not compile.

AFAICS the issue comes from the fact that PScanner only has the tkComment type, so that when fppinsert tries to rebuild the code, it has no way to know if it should use '//' or '{ }'.

Of course, I can't simply replace tkComment with 2 new distinct types, there is probably some other code somewhere, not even in the Lazarus repository, which uses the current set of token types.

I see at least 3 ways to solve my issue
1 - change fppinsert so that if it finds a bracket in the token, it should use '//' - I don't like much this solution
2 - use a flag in TPascalScanner (something like CommentType) allowing to know the type of comment if needed
3 - add 2 types tkCommentSlash and tkCommentBrackets into TToken plus an option to TPOptions so that the calling code could choose to use the simple tkComment or the more specific tkCommentSlash and tkCommentBrackets

I like the third method best, but I may be missing some drawbacks in these options, so what would be the preferred way to do it? Maybe a fourth idea?

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141120/8dd0349b/attachment.html>

Reply by email

Mattias Gaertner
to Frederic Da Vitoria
Show quoted text 9 lines
Hello, I am starting to use fpprofiler. Because I did not know what parameters should be sent to fpc, I decided to use fppinsert. At least one type of "instrumented" code fails to compile: // some code { some comment } is wrongly changed into { some code { some comment } } which does not compile.

Note: In FPC default $mode FPC and Lazarus default $mode ObjFPC nested comments are allowed. It is not allowed in $mode Delphi.

Mattias

Reply by email

Frederic Da Vitoria
to Mattias Gaertner

2014-11-20 23:51 GMT+01:00 Mattias Gaertner :

Show quoted text 16 lines
On Thu, 20 Nov 2014 23:39:59 +0100 Frederic Da Vitoria wrote: > Hello, > > I am starting to use fpprofiler. Because I did not know what parameters > should be sent to fpc, I decided to use fppinsert. At least one type of > "instrumented" code fails to compile: > // some code { some comment } > is wrongly changed into > { some code { some comment } } > which does not compile. Note: In FPC default $mode FPC and Lazarus default $mode ObjFPC nested comments are allowed. It is not allowed in $mode Delphi.

Ah, the fourth way I wrote about :-) Yes, I could try this. but I am a bit anxious at the idea of switching mode now. Couldn't there be code which would still compile but with different results, thus creating unexpected bugs? Oh well, I could try. I have enough test cases to be reasonably sure.

So I am less anxious to change something in the scanner, but wouldn't something like what I suggested still be an improvement?

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141121/5d97278d/attachment-0001.html>

Reply by email

Mattias Gaertner
to Frederic Da Vitoria
Show quoted text 9 lines
[...] > Note: In FPC default $mode FPC and Lazarus default $mode ObjFPC nested > comments are allowed. It is not allowed in $mode Delphi. > Ah, the fourth way I wrote about :-) Yes, I could try this. but I am a bit anxious at the idea of switching mode now. Couldn't there be code which would still compile but with different results, thus creating unexpected bugs?

I guess yes. Although it is unlikely, because mode ObjFPC is usually more strict than mode Delphi.

Oh well, I could try. I have enough test cases to be reasonably sure. So I am less anxious to change something in the scanner, but wouldn't something like what I suggested still be an improvement?

I'm not familiar with the fpprofiler code, so I can't help you here.

Mattias

Reply by email

Frederic Da Vitoria
to Mattias Gaertner

2014-11-21 0:58 GMT+01:00 Mattias Gaertner :

Show quoted text 24 lines
On Fri, 21 Nov 2014 00:24:11 +0100 Frederic Da Vitoria wrote: >[...] > > Note: In FPC default $mode FPC and Lazarus default $mode ObjFPC nested > > comments are allowed. It is not allowed in $mode Delphi. > > > > Ah, the fourth way I wrote about :-) Yes, I could try this. but I am a bit > anxious at the idea of switching mode now. Couldn't there be code which > would still compile but with different results, thus creating unexpected > bugs? I guess yes. Although it is unlikely, because mode ObjFPC is usually more strict than mode Delphi. > Oh well, I could try. I have enough test cases to be reasonably sure. > > So I am less anxious to change something in the scanner, but wouldn't > something like what I suggested still be an improvement? I'm not familiar with the fpprofiler code, so I can't help you here.

Thanks for trying :-) I thought that PScanner was outside of fpprofiler, but I just saw that it is actually part of fpprofiler, so I should feel free to implement the modifications I want, provided of course that I don't lose any functionality.

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141121/55012033/attachment.html>

Reply by email