Skip to content
UNDER THE HOOD

weavec::Frontend — Clang integration

lib/Frontend adapts the analysis to Clang’s frontend machinery:

  • WeaveCAction is an ASTFrontendAction whose consumer hands the whole translation unit to TranslationUnitAnalyzer; every definition contributes a summary, but by default only those in the main file are reported. The same consumer (createWeaveCConsumer) is what weavec-cc multiplexes beside Clang’s code generator. FrontendOptions carries the analysis options, the program database to consult, the diagnostics already reported for the unit, and a receiver for the unit’s exports.
  • ClangDiagnosticSink forwards core::Diagnostics (including fix-its) to Clang’s DiagnosticsEngine, so WeaveC’s output is rendered exactly like Clang’s own (carets, colours, -fdiagnostics-format=, -fdiagnostics-parseable-fixits, -Werror, …). DiagnosticControl applies -Wno-weavec-<id>, -Wno-error=weavec-<id>, -Werror=weavec and friends before the sink sees a diagnostic; FilteringSink drops diagnostics already reported by an earlier step and repeats of a boundary warning within a program.
  • ProgramAnalysis is the whole-program algorithm over an abstract ProgramUnit (something that can parse a unit and run an action over it): discover every unit’s exports, build the unit graph (who imports whose definitions, who calls through a type someone else has a candidate for), analyse acyclic units once and cyclic groups to a fixpoint, each against the database of what has been analysed so far, then one more reporting pass over the units that looked up a sized field the program confirmed after they were analysed (RFC 0012; a fact about a type, which the call graph’s order does not carry). CompilationDatabaseUnit parses from a compilation database.
  • Sidecar.h reads and writes foo.o.weavec: the unit’s exports, the cc1 command that produced it and the diagnostics already reported, in a line-oriented text format versioned by its weavec-summaries 23 header.
  • Driver.h is weavec-cc: Clang’s driver::Driver plans the jobs, each -cc1 job runs in-process with WeaveC’s consumer multiplexed beside Clang’s, the compile step writes the sidecar, and the link step runs ProgramAnalysis over the sidecars of the objects being linked before the linker.
  • ResourceDir.h locates weavec.h, Clang’s resource directory and the clang binary in installed and build-tree layouts.