Skip to content

auto include headers#98

Merged
kwabenantim merged 4 commits into
developfrom
97-auto-include-headers
Jul 21, 2026
Merged

auto include headers#98
kwabenantim merged 4 commits into
developfrom
97-auto-include-headers

Conversation

@kwabenantim

Copy link
Copy Markdown
Member

Fixes #97

kwabenantim and others added 3 commits July 21, 2026 13:15
Add an opt-in auto_includes flag (tri-state, inherits package/module/class,
off by default). When enabled for a class, cppwg scans its wrapped
method/constructor signatures and adds the header of every project type they
reference that the class's own header does not already provide - the
MeshFactory<MESH> returning a forward-declared PottsMesh pattern - so those no
longer need hand-written source_includes entries.

Factor the exclusion-aware member walk out of prune_uninstantiated_dependencies
into a shared _iter_wrapped_arg_return_types() generator, used by both pruning
and auto-include resolution so they cannot diverge from the writers. Resolve the
type->header map by scanning the project's source headers (definition sites),
not the parsed namespace - a templated class's instantiation decl reports its
location as the generated header collection, not its defining header. Library
types and ambiguous names are left for manual source_includes; the option is a
no-op with common_include_file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace MeshFactory's hand-written source_includes: [PottsMesh.hpp] with
auto_includes: True. cppwg resolves PottsMesh.hpp from the wrapped generateMesh
signature, so the generated wrapper is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a README Tips entry describing auto_includes (what it resolves, that only
project types are covered, and the common_include_file / custom_generator
caveats), plus a commented reference block in the shapes package_info.yaml.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in auto_includes mechanism to automatically include project headers required by wrapped class signatures when common_include_file is disabled, addressing compilation failures like the one described in issue #97.

Changes:

  • Introduces auto_includes (tri-state, inheritable) and resolves per-class auto_include_headers by scanning wrapped method/constructor arg+return types and mapping referenced project types to defining headers.
  • Emits resolved headers in generated wrapper include blocks (deduped and ordered before the class’s own header).
  • Adds unit tests plus documentation/examples describing the new configuration and behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_package_info.py Adds tests for header-resolution behavior, opt-in semantics, and ambiguous-type handling.
tests/test_package_info_parser.py Verifies YAML parsing and defaulting for auto_includes.
tests/test_class_writer.py Ensures wrapper include blocks emit and dedupe auto-includes correctly.
README.md Documents auto_includes purpose, constraints, and configuration example.
examples/shapes/wrapper/package_info.yaml Adds commented guidance for enabling auto_includes.
examples/cells/dynamic/config.yaml Updates MeshFactory example to use auto_includes instead of manual source_includes.
cppwg/writers/class_writer.py Emits class_info.auto_include_headers in non-common include mode.
cppwg/parsers/package_info_parser.py Adds auto_includes to the base parsed config so it can be set at package/module/class levels.
cppwg/info/package_info.py Implements type→header mapping and resolve_auto_includes(), plus shared wrapped-signature type iteration.
cppwg/info/class_info.py Adds auto_include_headers storage on class info objects.
cppwg/info/base_info.py Documents and wires auto_includes onto the info tree as a tri-state inheritable option.
cppwg/generators.py Runs auto-include resolution after pruning/sorting so results match the final wrapped set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Move auto_includes from MeshFactory to the package level so it inherits to every
class, demonstrating the option's package-wide use. Beyond MeshFactory<PottsMesh>
resolving PottsMesh.hpp, AbstractMesh's AddNode(Node<SPACE_DIM>) signature now
resolves Node.hpp (regenerated wrapper).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kwabenantim
kwabenantim marked this pull request as ready for review July 21, 2026 13:59
@kwabenantim
kwabenantim merged commit cca1826 into develop Jul 21, 2026
13 checks passed
@kwabenantim
kwabenantim deleted the 97-auto-include-headers branch July 21, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-include headers for wrapped classes

2 participants