Ignore:
Timestamp:
Nov 14, 2023, 12:19:09 PM (23 months ago)
Author:
caparson <caparson@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/Generate.cc

    rdf8ba61a r8d182b1  
    1919#include <string>                    // for operator<<
    2020
    21 #include "CodeGeneratorNew.hpp"      // for CodeGenerator_new, doSemicolon, ...
    22 #include "CodeGenerator.h"           // for CodeGenerator, doSemicolon, oper...
     21#include "CodeGeneratorNew.hpp"      // for CodeGenerator, doSemicolon, ...
    2322#include "GenType.h"                 // for genPrettyType
    24 #include "Common/PassVisitor.h"      // for PassVisitor
    25 #include "SynTree/LinkageSpec.h"     // for isBuiltin, isGeneratable
    26 #include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
    27 #include "SynTree/Declaration.h"     // for Declaration
    28 #include "SynTree/Type.h"            // for Type
    2923
    3024using namespace std;
    3125
    3226namespace CodeGen {
    33         namespace {
    34                 /// Removes misc. nodes that should not exist in CodeGen
    35                 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                 } // cleanTree
    47         } // namespace
    48 
    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                                 } // if
    60                                 os << cgv.pass.endl;
    61                         } // if
    62                 } // for
    63         }
    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         } // namespace
    9627
    9728namespace {
     
    10132
    10233        /// Removes various nodes that should not exist in CodeGen.
    103         struct TreeCleaner_new {
     34        struct TreeCleaner final {
    10435                ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ) {
    10536                        auto mutStmt = ast::mutate( stmt );
     
    12051                bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) {
    12152        erase_if( translationUnit.decls, shouldClean );
    122         ast::Pass<TreeCleaner_new>::run( translationUnit );
     53        ast::Pass<TreeCleaner>::run( translationUnit );
    12354
    124         ast::Pass<CodeGenerator_new> cgv( os,
     55        ast::Pass<CodeGenerator> cgv( os,
    12556                        Options( pretty, generateC, lineMarks, printExprTypes ) );
    12657        for ( auto & decl : translationUnit.decls ) {
Note: See TracChangeset for help on using the changeset viewer.