Ignore:
Timestamp:
Oct 29, 2021, 4:03:07 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
8e48fca4
Parents:
f42fc13
Message:

Implemented new AST version of the Fix Names pass.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixMain.cc

    rf42fc13 r0c577f7  
    2222#include <string>                  // for operator<<
    2323
     24#include "AST/Decl.hpp"
     25#include "AST/Type.hpp"
    2426#include "Common/PassVisitor.h"
    2527#include "Common/SemanticError.h"  // for SemanticError
     
    105107}
    106108
     109bool is_main( const std::string & mangled_name ) {
     110        // This breaks if you move it out of the function.
     111        static const std::string mangled_mains[] = {
     112                mangled_0_argument_main(),
     113                mangled_2_argument_main(),
     114                //mangled_3_argument_main(),
     115        };
     116
     117        for ( auto main_name : mangled_mains ) {
     118                if ( main_name == mangled_name ) return true;
     119        }
     120        return false;
     121}
     122
    107123struct FindMainCore {
    108124        void previsit( FunctionDecl * decl ) {
     
    116132
    117133bool FixMain::isMain( FunctionDecl * decl ) {
    118         // This breaks if you move it out of the function.
    119         static const std::string mangled_mains[] = {
    120                 mangled_0_argument_main(),
    121                 mangled_2_argument_main(),
    122                 //mangled_3_argument_main(),
    123         };
    124 
    125134        if ( std::string("main") != decl->name ) {
    126135                return false;
    127136        }
    128         auto mangled_name = SymTab::Mangler::mangle( decl, true, true );
    129         for ( auto main_name : mangled_mains ) {
    130                 if ( main_name == mangled_name ) return true;
     137        return is_main( SymTab::Mangler::mangle( decl, true, true ) );
     138}
     139
     140bool FixMain::isMain( const ast::FunctionDecl * decl ) {
     141        if ( std::string("main") != decl->name ) {
     142                return false;
    131143        }
    132         return false;
     144        return is_main( Mangle::mangle( decl, Mangle::Type ) );
    133145}
    134146
Note: See TracChangeset for help on using the changeset viewer.