Changeset 0b5e780 for src/main.cc


Ignore:
Timestamp:
Oct 27, 2023, 2:42:26 PM (7 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
3c714ad
Parents:
f43146e4
Message:

Code dumps (under the -P flag) no longer convert to the old ast to print.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rf43146e4 r0b5e780  
    3131#include "AST/Convert.hpp"
    3232#include "AST/Pass.hpp"                     // for pass_visitor_stats
     33#include "AST/Print.hpp"                    // for printAll
    3334#include "AST/TranslationUnit.hpp"          // for TranslationUnit
    3435#include "AST/Util.hpp"                     // for checkInvariants
     
    132133
    133134static void parse_cmdline( int argc, char * argv[] );
    134 static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
    135135static void dump( ast::TranslationUnit && transUnit, ostream & out = cout );
    136136
     
    246246        FILE * input;                                                                           // use FILE rather than istream because yyin is FILE
    247247        ostream * output = & cout;
    248         list< Declaration * > translationUnit;
    249248        ast::TranslationUnit transUnit;
    250249
     
    440439                if ( errorp ) {
    441440                        cerr << "---AST at error:---" << endl;
    442                         // We check which section the errors came from without looking at
    443                         // transUnit because std::move means it could look like anything.
    444                         if ( !translationUnit.empty() ) {
    445                                 dump( translationUnit, cerr );
    446                         } else {
    447                                 dump( std::move( transUnit ), cerr );
    448                         }
     441                        dump( std::move( transUnit ), cerr );
    449442                        cerr << endl << "---End of AST, begin error message:---\n" << endl;
    450443                } // if
     
    472465        } // try
    473466
    474         deleteAll( translationUnit );
    475467        Stats::print();
    476468        return EXIT_SUCCESS;
     
    702694} // parse_cmdline
    703695
    704 static bool notPrelude( Declaration * decl ) {
    705         return ! LinkageSpec::isBuiltin( decl->get_linkage() );
    706 } // notPrelude
    707 
    708 static void dump( list< Declaration * > & translationUnit, ostream & out ) {
    709         list< Declaration * > decls;
    710 
     696static bool notPrelude( ast::ptr<ast::Decl> & decl ) {
     697        return !decl->linkage.is_builtin;
     698}
     699
     700static void dump( ast::TranslationUnit && unit, std::ostream & out ) {
     701        // May filter out all prelude declarations.
    711702        if ( genproto ) {
    712                 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude );
     703                std::list<ast::ptr<ast::Decl>> decls;
     704                std::copy_if( unit.decls.begin(), unit.decls.end(),
     705                        std::back_inserter( decls ), notPrelude );
     706                decls.swap( unit.decls );
     707        }
     708
     709        // May print as full dump or as code generation.
     710        if ( codegenp ) {
     711                CodeGen::generate( unit, out, !genproto, prettycodegenp, false, false, false );
    713712        } else {
    714                 decls = translationUnit;
    715         } // if
    716 
    717         // depending on commandline options, either generate code or dump the AST
    718         if ( codegenp ) {
    719                 CodeGen::generate( decls, out, ! genproto, prettycodegenp );
    720         } else {
    721                 printAll( decls, out );
    722         } // if
    723         deleteAll( translationUnit );
    724 } // dump
    725 
    726 static void dump( ast::TranslationUnit && transUnit, ostream & out ) {
    727         std::list< Declaration * > translationUnit = convert( std::move( transUnit ) );
    728         dump( translationUnit, out );
     713                ast::printAll( out, unit.decls );
     714        }
    729715}
    730716
Note: See TracChangeset for help on using the changeset viewer.