@@ -43,13 +43,23 @@ export function new_ast_op_h({
4343 return name ;
4444 } ;
4545
46+ emit ( ` // base nodes` ) ;
4647 by_base . forEach ( ( nodes , base ) => {
4748 if ( base === "AST" ) return ;
48- emit ( ` struct ${ chopAST ( base ) } Result {} ;` ) ;
49+ emit ( ` struct ${ chopAST ( base ) } Result;` ) ;
4950 } ) ;
50- emit ( ) ;
51+
52+ emit ( ` // misc nodes` ) ;
5153 by_base . get ( "AST" ) ?. forEach ( ( { name } ) => {
52- emit ( ` struct ${ chopAST ( name ) } Result {};` ) ;
54+ emit ( ` struct ${ chopAST ( name ) } Result;` ) ;
55+ } ) ;
56+
57+ emit ( ` // visitors` ) ;
58+ by_base . forEach ( ( nodes , base ) => {
59+ if ( ! Array . isArray ( nodes ) ) throw new Error ( "not an array" ) ;
60+ if ( base === "AST" ) return ;
61+ const className = chopAST ( base ) ;
62+ emit ( ` struct ${ className } Visitor;` ) ;
5363 } ) ;
5464
5565 emit ( ) ;
@@ -63,24 +73,7 @@ export function new_ast_op_h({
6373 emit ( ` // run on the misc nodes` ) ;
6474 by_base . get ( "AST" ) ?. forEach ( ( { name } ) => {
6575 const resultTy = `${ chopAST ( name ) } Result` ;
66- emit ( ` auto operator()(${ name } * ast) -> ${ resultTy } ;` ) ;
67- } ) ;
68-
69- emit ( ) ;
70- emit ( `private:` ) ;
71- by_base . forEach ( ( nodes , base ) => {
72- if ( ! Array . isArray ( nodes ) ) throw new Error ( "not an array" ) ;
73- if ( base === "AST" ) return ;
74- const className = chopAST ( base ) ;
75- const resultTy = `${ chopAST ( base ) } Result` ;
76- emit ( ) ;
77- emit ( ` struct ${ className } Visitor {` ) ;
78- emit ( ` ${ opName } & accept;` ) ;
79- nodes . forEach ( ( { name } ) => {
80- emit ( ) ;
81- emit ( ` [[nodiscard]] auto operator()(${ name } * ast) -> ${ resultTy } ;` ) ;
82- } ) ;
83- emit ( ` };` ) ;
76+ emit ( ` [[nodiscard]] auto operator()(${ name } * ast) -> ${ resultTy } ;` ) ;
8477 } ) ;
8578
8679 const out = `${ cpy_header }
@@ -96,16 +89,18 @@ class Control;
9689
9790class ${ opName } {
9891public:
99- explicit ${ opName } (TranslationUnit* unit);
100- ~${ opName } ();
92+ explicit ${ opName } (TranslationUnit* unit);
93+ ~${ opName } ();
10194
102- [[nodiscard]] auto translationUnit() const -> TranslationUnit* { return unit_; }
95+ [[nodiscard]] auto translationUnit() const -> TranslationUnit* { return unit_; }
10396
104- [[nodiscard]] auto control() const -> Control*;
97+ [[nodiscard]] auto control() const -> Control*;
10598
99+ private:
106100${ code . join ( "\n" ) }
107101
108- TranslationUnit* unit_ = nullptr;
102+ private:
103+ TranslationUnit* unit_ = nullptr;
109104};
110105
111106} // namespace cxx
0 commit comments