Loading...
Searching...
No Matches
Line

Definition

Standard #line directive support for the fpx Fortran preprocessor.

This module implements full support for the ISO C99/C11 #line directive, which is also widely used in Fortran preprocessors.

The #line directive allows changing the logical line number and/or source filename reported by the preprocessor. It is particularly useful for:

  • Code generators
  • Literate programming tools
  • Macro-heavy generated code
  • Accurate __LINE__ and __FILE__ expansion in included/generated files

Supported forms (standard compliant):

  • #line <number>
  • #line <number> "<filename>"

When a #line directive is encountered, the current context (line number and filename) is updated immediately. This affects all subsequent diagnostics, __LINE__, __FILE__, and __FILENAME__ macros.

Examples

  1. Basic line number reset:
    #line 100
    print *,
  2. Changing both line number and filename (common in generated code):
    #line 42
    integer :: x = 1 ! this will appear as line 42 in generated_code.f90
Remarks
  • The line number in #line N refers to the next line after the directive.
  • Filename must be quoted if provided.
  • Invalid line numbers or malformed directives emit a warning but are ignored.
  • Updates the shared context object used by the logging and macro systems.

Methods

◆ handle_line()

subroutine handle_line ( type(context), intent(inout) ctx,
character(*), intent(in) token )
private

Handle the standard line directive Supports two standard forms: line <number> line <number> "<filename>".

This updates the current line number (ctxline) and optionally the current filename (ctxpath) for subsequent diagnostics, __LINE__, and __FILE__ expansions.

Fully compliant with ISO C99 / C11 �6.10.4 and common Fortran preprocessor behavior.

Parameters
[in,out]ctxContext source line containing the line directive
[in]tokenUsually 'DEFINE' � keyword matched in lowercase

Remarks

Definition at line 67 of file line.f90.