Loading...
Searching...
No Matches
Context

Definition

Source context information used for diagnostics and error reporting.

This module defines the lightweight context type used throughout the fpx preprocessor to associate source-location information with diagnostics, warnings, notes, and error messages.

Every diagnostic emitted by fpx is accompanied by a context object describing where the event occurred. This enables the generation of modern compiler-style messages containing file names, line numbers, source snippets, and caret annotations.

A context captures:

  • the original source line,
  • the corresponding 1-based line number,
  • the path of the source file being processed.

The information stored in a context is consumed primarily by the fpx_logging module to produce precise and user-friendly diagnostics.

For example:

error: undefined macro 'DEBUG'
--> src/main.f90:42
|
42 | #ifdef DEBUG
| ^^^^^ not defined

Accurate context information becomes particularly important when processing nested include files, evaluating conditional directives, or reporting errors originating from macro expansions.

Examples

  1. Creating a context object:
    type(context) :: ctx
    ctx = context( &
    content='real :: x = PI*r**2', &
    line=27, &
    path='src/utils.F90')
  2. Using context when reporting diagnostics:
    call printf(render(diagnostic_report( &
    level_error, &
    message='Undefined macro', &
    source=ctx%path), &
    ctx%content, ctx%line))
  3. Updating context during include processing:
    included_ctx = context( &
    content=first_line, &
    line=1, &
    path=resolved_include_path)

Data Types

type  context
 Snapshot of a source location within the preprocessing stream. More...