Changeset 8941b6b for src/CodeGen/Generate.cc
- Timestamp:
- Oct 25, 2023, 6:33:25 PM (6 months ago)
- Branches:
- master
- Children:
- bef4f1a
- Parents:
- d22bf87
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/Generate.cc
rd22bf87 r8941b6b 19 19 #include <string> // for operator<< 20 20 21 #include "CodeGeneratorNew.hpp" // for CodeGenerator_new, doSemicolon, ... 21 22 #include "CodeGenerator.h" // for CodeGenerator, doSemicolon, oper... 22 23 #include "GenType.h" // for genPrettyType … … 93 94 } 94 95 } // namespace 96 97 namespace { 98 bool shouldClean( ast::Decl const * decl ) { 99 return dynamic_cast<ast::TraitDecl const *>( decl ); 100 } 101 102 /// Removes various nodes that should not exist in CodeGen. 103 struct TreeCleaner_new { 104 ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ) { 105 auto mutStmt = ast::mutate( stmt ); 106 erase_if( mutStmt->kids, []( ast::Stmt const * stmt ){ 107 auto declStmt = dynamic_cast<ast::DeclStmt const *>( stmt ); 108 return ( declStmt ) ? shouldClean( declStmt->decl ) : false; 109 } ); 110 return mutStmt; 111 } 112 113 ast::Stmt const * postvisit( ast::ImplicitCtorDtorStmt const * stmt ) { 114 return stmt->callStmt; 115 } 116 }; 117 } // namespace 118 119 void generate( ast::TranslationUnit & translationUnit, std::ostream & os, bool doIntrinsics, 120 bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) { 121 erase_if( translationUnit.decls, shouldClean ); 122 ast::Pass<TreeCleaner_new>::run( translationUnit ); 123 124 ast::Pass<CodeGenerator_new> cgv( os, 125 Options( pretty, generateC, lineMarks, printExprTypes ) ); 126 for ( auto & decl : translationUnit.decls ) { 127 if ( decl->linkage.is_generatable && (doIntrinsics || !decl->linkage.is_builtin ) ) { 128 cgv.core.updateLocation( decl ); 129 decl->accept( cgv ); 130 if ( doSemicolon( decl ) ) { 131 os << ";"; 132 } 133 os << cgv.core.endl; 134 } 135 } 136 } 137 95 138 } // namespace CodeGen 96 139
Note: See TracChangeset
for help on using the changeset viewer.