Defined in header <cparse/Generator.hh>
virtual void generate() = 0;
The entry point. Perform the emission and return.
Parameters
None.
Return value
(none)
Exceptions
There is no defined exception contract — the base class does not call generate() itself, and it is not marked noexcept. Subclasses may throw or catch freely; the caller of generate() gets whatever the subclass propagates.
Notes
Errors are the subclass's own concern — Generator does not carry a diagnostic collector like Parser does. Options:
- Throw — clean for pipelines where any failure aborts the tool.
- Log to
std::clogorstd::cerr— pragmatic for CLI tools. - Accumulate in a member and expose via a subclass-specific method — for tools that continue emitting after recoverable errors.
Example
Minimal derivation:
class HelloGen : public fedem::parser::Generator {
std::ofstream out_;
fedem::parser::Indentation indent_;
public:
explicit HelloGen(std::string const& path) : out_(path) {}
std::ostream& getStream() override { return out_; }
Indentation& getIndentor() override { return indent_; }
void openNamespaceScope() noexcept override { /* ... */ }
void closeNamespaceScope() noexcept override { /* ... */ }
std::string getNamespacePath() const noexcept override { return {}; }
void generate() override {
getStream() << "// Auto-generated. Do not edit.\n";
getStream() << "int main() { return 0; }\n";
}
};
See also
- Generator::getStream — write here.
- Generator::getIndentor — indent tracker.
- User Guide › Code Generation — a fuller walkthrough.

