Sign in Join

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

Mailing lists / fpc-devel / 2010-09

Re: current_tokenpos/filepos

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Florian Klämpfl
to Hans-Peter Diettrich: Some questions about tfileposinfo position variables: 1) What's the difference between…
Hans-Peter Diettrich wrote
Some questions about tfileposinfo position variables: 1) What's the difference between current_tokenpos and current_filepos? Normally the scanner updates both vars to the same value...

Current_tokenpos means the scanner position, current_filepos the compiler position in the code. While scanning and parsing, they are indeed equal. But when compiling a procedure, after parsing current_tokenpos is at the end of the procedure. Now, e.g. when the code is generated, current_filepos is set back to the positions where the node were read (the position is stored in tnode.fileinfo). So e.g. in case of an error, the compiler displays the correct location of the error.

2) What's the meaning of the tailineinfo.fileinfo value? The default constructor inits fileinfo to current_filepos.

The position where tailineinfo was created.

3) What's the meaning of the tnode.fileinfo value? The default constructor inits fileinfo to current_filepos.

See above.

4) What's the meaning of the tsym.fileinfo value? The default constructor inits fileinfo to current_tokenpos.

See above.

5) Some (parser) procedures modify current_tokenpos/filepos temporarily, and restore the old values later. What's the purpose of such changes?

To get correct file positions in debugging code and error messages.

Reply by email

Hans-Peter Diettrich

Some questions about tfileposinfo position variables:

1) What's the difference between current_tokenpos and current_filepos? Normally the scanner updates both vars to the same value...

2) What's the meaning of the tailineinfo.fileinfo value? The default constructor inits fileinfo to current_filepos.

3) What's the meaning of the tnode.fileinfo value? The default constructor inits fileinfo to current_filepos.

4) What's the meaning of the tsym.fileinfo value?
The default constructor inits fileinfo to current_tokenpos.

5) Some (parser) procedures modify current_tokenpos/filepos temporarily, and restore the old values later. What's the purpose of such changes?

DoDi

Reply by email

Hans-Peter Diettrich
to Florian Klämpfl: Current_tokenpos means the scanner position, current_filepos the compiler position in the…
Show quoted text 5 lines
> 1) What's the difference between current_tokenpos and current_filepos? > Normally the scanner updates both vars to the same value... Current_tokenpos means the scanner position, current_filepos the compiler position in the code.

Thanks, that explains a lot :-)

Show quoted text 5 lines
> 5) Some (parser) procedures modify current_tokenpos/filepos temporarily, > and restore the old values later. What's the purpose of such changes? > To get correct file positions in debugging code and error messages.

So every temporary change of current_tokenpos should be considered wrong? According to your above description I'd make current_tokenpos a read-only property of the scanner...

DoDi

Reply by email

Florian Klaempfl
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 9 lines
>> 5) Some (parser) procedures modify current_tokenpos/filepos temporarily, >> and restore the old values later. What's the purpose of such changes? >> > > To get correct file positions in debugging code and error messages. So every temporary change of current_tokenpos should be considered wrong? According to your above description I'd make current_tokenpos a read-only property of the scanner...

I'am not sure what e.g. generics do with it.

Reply by email

Hans-Peter Diettrich
to Florian Klaempfl
Show quoted text 5 lines
> So every temporary change of current_tokenpos should be considered > wrong? According to your above description I'd make current_tokenpos a > read-only property of the scanner... I'am not sure what e.g. generics do with it.

Me 2 :-(

Therefore my questions about the values in concrete classes, whose answers could shed a light on the according use in macro expansion and generics. Probably generics require both information, about the locations of the declarations and their extensions, in order to generate useful error messages. But I never used generics myself, and consequently don't know anything about possible problems...

DoDi

Reply by email

Paul Ishenin
to Florian Klaempfl: I'am not sure what e.g. generics do with it.
Florian Klaempfl wrote 9 lines
Am 06.09.2010 05:29, schrieb Hans-Peter Diettrich: >>> 5) Some (parser) procedures modify current_tokenpos/filepos temporarily, >>> and restore the old values later. What's the purpose of such changes? >>> >> To get correct file positions in debugging code and error messages. > So every temporary change of current_tokenpos should be considered > wrong? According to your above description I'd make current_tokenpos a > read-only property of the scanner... I'am not sure what e.g. generics do with it.

Generics need to replay tokens with their position for debugging purposes.

Best regards,
Paul Ishenin

Reply by email

Hans-Peter Diettrich
to Paul Ishenin
Generics need to replay tokens with their position for debugging purposes.

I.e. the tokens have to be stored and replayed with their original positions. Most probably the current_filepos should not be modified during replay (in contrast to normal token scanning)?

The replay procedure is a bit cryptic, since positions are encoded in special tokens, and it's not obvious in which places such tokens occur in the stored token stream.

DoDi

Reply by email