Files
doslang-mirror/fec/src/diag.h
T
coolguy 38dddc234c implement: load the unit graph -- imports, cycles, bindings
The driver handled one file. It now loads the graph rooted at the entry file
and checks every unit in it.

The import root is derived rather than configured: a unit named `a.b` read
from `<root>/a/b.fe` fixes `<root>`, so a sibling `import c.d;` is looked for
at `<root>/c/d.fe`. That is enough for the fixtures and for any tree that
follows 8.1, and it means there is no path flag to get wrong yet.

Loading is depth-first with the chain of units currently open kept on a stack,
so meeting one again is a cycle rather than a revisit -- a unit reached twice
by different paths is loaded once. Cycles, imports with no source file, and two
imports claiming the same binding are all reported.

One thing this exposed: FeDiags held a single source buffer, so once a build
spanned several files every excerpt was drawn from whichever file was parsed
last. `cycle/b.fe:3` printed the text of a.fe. fe_diags_source switches it, and
loading and checking both set it per unit.

The cycle fixtures lost their line markers on purpose. Which import closes the
cycle depends on which file you enter from -- entering at a.fe reports b.fe,
entering at b.fe reports a.fe -- so pinning a line would pin an arbitrary half
of a symmetric pair. The message is pinned; the line is not.

units: missing, bindconf and cycle pass, on top of the identity cases.
146 -> 148 of 188. What is left in units/ needs cross-unit name resolution and
visibility: an importer still cannot see `util.answer`.
2026-08-17 03:54:43 +09:00

37 lines
1.3 KiB
C

#ifndef FE_DIAG_H
#define FE_DIAG_H
#include <stdio.h>
typedef struct FeLoc {
const char *file;
unsigned long line;
unsigned long col;
} FeLoc;
typedef struct FeDiags {
unsigned long errors;
unsigned long warnings;
const char *source;
unsigned long source_len;
} FeDiags;
/* Stream diagnostics are written to. Defaults to stderr; returns stdout when
FE_DIAG_STDOUT is set in the environment. DOS offers no way to redirect
handle 2 -- COMMAND.COM understands ">" and nothing else -- so under the test
runner every error message would otherwise be written straight to the screen
and lost. Interactive use is unaffected: both streams reach the console. */
FILE *fe_diag_stream(void);
void fe_diags_init(FeDiags *d, const char *source, unsigned long source_len);
/* Point the excerpt printer at a different file. A build spans several
units, and an excerpt drawn from the wrong buffer is worse than none. */
void fe_diags_source(FeDiags *d, const char *source, unsigned long source_len);
void fe_diag_error(FeDiags *d, FeLoc loc, const char *msg);
void fe_diag_errorf(FeDiags *d, FeLoc loc, const char *msg, const char *arg);
void fe_diag_note(FeLoc loc, const char *msg);
void fe_diag_note_src(FeDiags *d, FeLoc loc, const char *msg);
#endif