Changeset 8d182b1 for src/CodeGen/Generate.cc
- Timestamp:
- Nov 14, 2023, 12:19:09 PM (23 months ago)
- Branches:
- master
- Children:
- 1ccae59, 89a8bab
- Parents:
- df8ba61a (diff), 5625427 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/Generate.cc
rdf8ba61a r8d182b1 19 19 #include <string> // for operator<< 20 20 21 #include "CodeGeneratorNew.hpp" // for CodeGenerator_new, doSemicolon, ... 22 #include "CodeGenerator.h" // for CodeGenerator, doSemicolon, oper... 21 #include "CodeGeneratorNew.hpp" // for CodeGenerator, doSemicolon, ... 23 22 #include "GenType.h" // for genPrettyType 24 #include "Common/PassVisitor.h" // for PassVisitor25 #include "SynTree/LinkageSpec.h" // for isBuiltin, isGeneratable26 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode27 #include "SynTree/Declaration.h" // for Declaration28 #include "SynTree/Type.h" // for Type29 23 30 24 using namespace std; 31 25 32 26 namespace CodeGen { 33 namespace {34 /// Removes misc. nodes that should not exist in CodeGen35 struct TreeCleaner {36 void premutate( CompoundStmt * stmt );37 Statement * postmutate( ImplicitCtorDtorStmt * stmt );38 39 static bool shouldClean( Declaration * );40 };41 42 void cleanTree( std::list< Declaration * > & translationUnit ) {43 PassVisitor<TreeCleaner> cleaner;44 filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); }, false );45 mutateAll( translationUnit, cleaner );46 } // cleanTree47 } // namespace48 49 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) {50 cleanTree( translationUnit );51 52 PassVisitor<CodeGenerator> cgv( os, pretty, generateC, lineMarks, printExprTypes );53 for ( auto & dcl : translationUnit ) {54 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {55 cgv.pass.updateLocation( dcl );56 dcl->accept(cgv);57 if ( doSemicolon( dcl ) ) {58 os << ";";59 } // if60 os << cgv.pass.endl;61 } // if62 } // for63 }64 65 void generate( BaseSyntaxNode * node, std::ostream & os ) {66 if ( Type * type = dynamic_cast< Type * >( node ) ) {67 os << genPrettyType( type, "" );68 } else {69 PassVisitor<CodeGenerator> cgv( os, true, false, false, false );70 node->accept( cgv );71 }72 os << std::endl;73 }74 75 namespace {76 void TreeCleaner::premutate( CompoundStmt * cstmt ) {77 filter( cstmt->kids, [](Statement * stmt) {78 if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {79 return shouldClean( declStmt->decl );80 }81 return false;82 }, false );83 }84 85 Statement * TreeCleaner::postmutate( ImplicitCtorDtorStmt * stmt ) {86 Statement * callStmt = nullptr;87 std::swap( stmt->callStmt, callStmt );88 delete stmt;89 return callStmt;90 }91 92 bool TreeCleaner::shouldClean( Declaration * decl ) {93 return dynamic_cast< TraitDecl * >( decl );94 }95 } // namespace96 27 97 28 namespace { … … 101 32 102 33 /// Removes various nodes that should not exist in CodeGen. 103 struct TreeCleaner _new{34 struct TreeCleaner final { 104 35 ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ) { 105 36 auto mutStmt = ast::mutate( stmt ); … … 120 51 bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) { 121 52 erase_if( translationUnit.decls, shouldClean ); 122 ast::Pass<TreeCleaner _new>::run( translationUnit );53 ast::Pass<TreeCleaner>::run( translationUnit ); 123 54 124 ast::Pass<CodeGenerator _new> cgv( os,55 ast::Pass<CodeGenerator> cgv( os, 125 56 Options( pretty, generateC, lineMarks, printExprTypes ) ); 126 57 for ( auto & decl : translationUnit.decls ) {
Note:
See TracChangeset
for help on using the changeset viewer.