[fpc-devel] current_tokenpos/filepos

Florian Klämpfl florian at freepascal.org
Sun Sep 5 15:13:48 CEST 2010


Am 05.09.2010 15:34, schrieb 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...

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.



More information about the fpc-devel mailing list