Changeset d99a716 for src


Ignore:
Timestamp:
Jan 4, 2023, 1:44:19 PM (3 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
339e30a, a14926b
Parents:
0348fd8 (diff), 66a89e7 (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

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.hpp

    r0348fd8 rd99a716  
    8686        {
    8787                // After the pass is constructed, check if it wants the have a pointer to the wrapping visitor
    88                 type * const * visitor = __pass::visitor(core, 0);
    89                 if(visitor) {
     88                type * const * visitor = __pass::visitor( core, 0 );
     89                if ( visitor ) {
    9090                        *const_cast<type **>( visitor ) = this;
    9191                }
     
    9898
    9999        /// If the core defines a result, call it if possible, otherwise return it.
    100         inline auto get_result() -> decltype( __pass::get_result( core, '0' ) ) {
    101                 return __pass::get_result( core, '0' );
     100        inline auto get_result() -> decltype( __pass::result::get( core, '0' ) ) {
     101                return __pass::result::get( core, '0' );
    102102        }
    103103
  • src/AST/Pass.proto.hpp

    r0348fd8 rd99a716  
    489489                template<typename core_t>
    490490                static inline auto replace( core_t &, long, const ast::TypeInstType *& ) {}
    491 
    492491        } // namespace forall
    493492
     
    506505        }
    507506
    508         template<typename core_t>
    509         static inline auto get_result( core_t & core, char ) -> decltype( core.result() ) {
    510                 return core.result();
    511         }
    512 
    513         template<typename core_t>
    514         static inline auto get_result( core_t & core, int ) -> decltype( core.result ) {
    515                 return core.result;
    516         }
    517 
    518         template<typename core_t>
    519         static inline void get_result( core_t &, long ) {}
     507        // For passes, usually utility passes, that have a result.
     508        namespace result {
     509                template<typename core_t>
     510                static inline auto get( core_t & core, char ) -> decltype( core.result() ) {
     511                        return core.result();
     512                }
     513
     514                template<typename core_t>
     515                static inline auto get( core_t & core, int ) -> decltype( core.result ) {
     516                        return core.result;
     517                }
     518
     519                template<typename core_t>
     520                static inline void get( core_t &, long ) {}
     521        }
    520522} // namespace __pass
    521523} // namespace ast
  • src/CompilationState.cc

    r0348fd8 rd99a716  
    3333        useNewAST = true,
    3434        nomainp = false,
    35         parsep = false,
    3635        resolvep = false,
    3736        resolvprotop = false,
  • src/CompilationState.h

    r0348fd8 rd99a716  
    3232        useNewAST,
    3333        nomainp,
    34         parsep,
    3534        resolvep,
    3635        resolvprotop,
  • src/GenPoly/Box.cc

    r0348fd8 rd99a716  
    424424        namespace {
    425425                std::string makePolyMonoSuffix( FunctionType const * function, const TyVarMap &tyVars ) {
    426                         std::stringstream name;
    427 
    428426                        // NOTE: this function previously used isPolyObj, which failed to produce
    429427                        // the correct thing in some situations. It's not clear to me why this wasn't working.
     
    432430                        // to take those polymorphic types as pointers. Therefore, there can be two different functions
    433431                        // with the same mangled name, so we need to further mangle the names.
     432                        std::stringstream name;
    434433                        for ( DeclarationWithType const * const ret : function->returnVals ) {
    435                                 if ( isPolyType( ret->get_type(), tyVars ) ) {
    436                                         name << "P";
    437                                 } else {
    438                                         name << "M";
    439                                 }
    440                         }
    441                         name << "_";
     434                                name << ( isPolyType( ret->get_type(), tyVars ) ? 'P' : 'M' );
     435                        }
     436                        name << '_';
    442437                        for ( DeclarationWithType const * const arg : function->parameters ) {
    443                                 if ( isPolyType( arg->get_type(), tyVars ) ) {
    444                                         name << "P";
    445                                 } else {
    446                                         name << "M";
    447                                 }
    448                         } // for
     438                                name << ( isPolyType( arg->get_type(), tyVars ) ? 'P' : 'M' );
     439                        }
    449440                        return name.str();
    450441                }
     
    565556                        // even when converted to strings, sort in the original order.
    566557                        // (At least, that is the best explination I have.)
    567                         for ( std::pair<std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {
     558                        for ( std::pair<const std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {
    568559                                if ( !tyParam.second.isComplete ) continue;
    569560                                Type *concrete = env->lookup( tyParam.first );
  • src/GenPoly/ScrubTyVars.cc

    r0348fd8 rd99a716  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct  7 15:42:00 2022
    13 // Update Count     : 5
     12// Last Modified On : Wed Dec  7 17:01:00 2022
     13// Update Count     : 6
    1414//
    1515
     
    117117namespace {
    118118
    119 enum class ScrubMode {
    120         FromMap,
    121         DynamicFromMap,
    122         All,
    123 };
    124 
    125119struct ScrubTypeVars :
    126120        public ast::WithGuards,
     
    253247}
    254248
     249} // namespace
     250
    255251const ast::Node * scrubTypeVarsBase(
    256                 const ast::Node * target,
    257                 ScrubMode mode, const TypeVarMap * typeVars ) {
     252                const ast::Node * node, const TypeVarMap * typeVars, ScrubMode mode ) {
    258253        if ( ScrubMode::All == mode ) {
    259254                assert( nullptr == typeVars );
     
    262257        }
    263258        ast::Pass<ScrubTypeVars> visitor( mode, typeVars );
    264         return target->accept( visitor );
    265 }
    266 
    267 } // namespace
    268 
    269 template<>
    270 ast::Node const * scrubTypeVars<ast::Node>(
    271         const ast::Node * target, const TypeVarMap & typeVars ) {
    272         return scrubTypeVarsBase( target, ScrubMode::FromMap, &typeVars );
    273 }
    274 
    275 template<>
    276 ast::Node const * scrubTypeVarsDynamic<ast::Node>(
    277         ast::Node const * target, const TypeVarMap & typeVars ) {
    278         return scrubTypeVarsBase( target, ScrubMode::DynamicFromMap, &typeVars );
    279 }
    280 
    281 template<>
    282 ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target ) {
    283         return scrubTypeVarsBase( target, ScrubMode::All, nullptr );
     259        return node->accept( visitor );
    284260}
    285261
  • src/GenPoly/ScrubTyVars.h

    r0348fd8 rd99a716  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct  7 15:51:00 2022
    13 // Update Count     : 4
     12// Last Modified On : Wed Dec  7 16:57:00 2022
     13// Update Count     : 5
    1414//
    1515
     
    109109        }
    110110
     111// ScrubMode and scrubTypeVarsBase are internal.
     112enum class ScrubMode { FromMap, DynamicFromMap, All };
     113
     114const ast::Node * scrubTypeVarsBase(
     115        const ast::Node * target, const TypeVarMap * typeVars, ScrubMode mode );
     116
     117
    111118/// For all polymorphic types with type variables in `typeVars`,
    112119/// replaces generic types, dtypes, and ftypes with the appropriate void type,
     
    116123                node_t const * target, const TypeVarMap & typeVars ) {
    117124        return strict_dynamic_cast<node_t const *>(
    118                         scrubTypeVars<ast::Node>( target, typeVars ) );
     125                        scrubTypeVarsBase( target, &typeVars, ScrubMode::FromMap ) );
    119126}
    120127
     
    123130/// and sizeof/alignof expressions with the proper variable.
    124131template<typename node_t>
    125 ast::Node const * scrubTypeVarsDynamic(
     132node_t const * scrubTypeVarsDynamic(
    126133                node_t const * target, const TypeVarMap & typeVars ) {
    127134        return strict_dynamic_cast<node_t const *>(
    128                         scrubTypeVarsDynamic<ast::Node>( target, typeVars ) );
     135                        scrubTypeVarsBase( target, &typeVars, ScrubMode::DynamicFromMap ) );
    129136}
    130137
     
    134141node_t const * scrubAllTypeVars( node_t const * target ) {
    135142        return strict_dynamic_cast<node_t const *>(
    136                         scrubAllTypeVars<ast::Node>( target ) );
     143                        scrubTypeVarsBase( target, nullptr, ScrubMode::All ) );
    137144}
    138 
    139 // We specialize for Node as a base case.
    140 template<>
    141 ast::Node const * scrubTypeVars<ast::Node>(
    142                 const ast::Node * target, const TypeVarMap & typeVars );
    143 
    144 template<>
    145 ast::Node const * scrubTypeVarsDynamic<ast::Node>(
    146                 ast::Node const * target, const TypeVarMap & typeVars );
    147 
    148 template<>
    149 ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target );
    150145
    151146} // namespace GenPoly
  • src/Parser/RunParser.cpp

    r0348fd8 rd99a716  
    1010// Created On       : Mon Dec 19 11:00:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Dec 19 11:15:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Thr Dec 22 10:18:00 2022
     13// Update Count     : 1
    1414//
    1515
    1616#include "RunParser.hpp"
    1717
     18#include "AST/Convert.hpp"                  // for convert
     19#include "AST/TranslationUnit.hpp"          // for TranslationUnit
     20#include "CodeTools/TrackLoc.h"             // for fillLocations
     21#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
    1822#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
    1923#include "Parser/TypedefTable.h"            // for TypedefTable
     
    4145} // parse
    4246
    43 void dumpParseTree( std::ostream & out ) {
    44         parseTree->printList( out );
    45         delete parseTree;
    46         parseTree = nullptr;
    47 }
    48 
    49 std::list<Declaration *> buildUnit(void) {
     47ast::TranslationUnit buildUnit(void) {
    5048        std::list<Declaration *> translationUnit;
    5149        buildList( parseTree, translationUnit );
     
    5452        parseTree = nullptr;
    5553
    56         return translationUnit;
     54        // When the parse/buildList code is translated to the new ast, these
     55        // fill passes (and the one after 'Hoist Type Decls') should be redundent
     56        // because the code locations should already be filled.
     57        CodeTools::fillLocations( translationUnit );
     58        ast::TranslationUnit transUnit = convert( std::move( translationUnit ) );
     59        forceFillCodeLocations( transUnit );
     60        return transUnit;
    5761}
    5862
  • src/Parser/RunParser.hpp

    r0348fd8 rd99a716  
    1010// Created On       : Mon Dec 19 10:42:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Dec 19 11:15:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Thr Dec 22 10:23:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    1717
    1818#include <iosfwd>                           // for ostream
    19 #include <list>                             // for list
    2019
    2120#include "SynTree/LinkageSpec.h"            // for Spec
    22 class Declaration;
     21namespace ast {
     22        class TranslationUnit;
     23}
    2324
    2425// The Parser does not have an enclosing namespace.
     
    3031void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit = false );
    3132
    32 /// Drain the internal accumulator of parsed code and print it to the stream.
    33 void dumpParseTree( std::ostream & );
    34 
    3533/// Drain the internal accumulator of parsed code and build a translation
    3634/// unit from it.
    37 std::list<Declaration *> buildUnit(void);
     35ast::TranslationUnit buildUnit(void);
    3836
    3937// Local Variables: //
  • src/main.cc

    r0348fd8 rd99a716  
    228228        ostream * output = & cout;
    229229        list< Declaration * > translationUnit;
     230        ast::TranslationUnit transUnit;
    230231
    231232        Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO );
     
    294295                parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, yydebug );
    295296
    296                 if ( parsep ) {
    297                         dumpParseTree( cout );
    298                         return EXIT_SUCCESS;
    299                 } // if
    300 
    301                 translationUnit = buildUnit();
     297                transUnit = buildUnit();
    302298
    303299                if ( astp ) {
    304                         dump( translationUnit );
    305                         return EXIT_SUCCESS;
    306                 } // if
    307 
    308                 // Temporary: fill locations after parsing so that every node has a location, for early error messages.
    309                 // Eventually we should pass the locations from the parser to every node, but this quick and dirty solution
    310                 // works okay for now.
    311                 CodeTools::fillLocations( translationUnit );
     300                        dump( std::move( transUnit ) );
     301                        return EXIT_SUCCESS;
     302                } // if
     303
    312304                Stats::Time::StopBlock();
    313305
     
    316308                        ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New");
    317309                }
    318                 auto transUnit = convert( std::move( translationUnit ) );
    319 
    320                 forceFillCodeLocations( transUnit );
    321 
    322                 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) );
    323                 if ( exdeclp ) {
    324                         dump( std::move( transUnit ) );
    325                         return EXIT_SUCCESS;
    326                 }
    327 
    328                 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) );
     310
    329311                PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) );
    330312                // Hoist Type Decls pulls some declarations out of contexts where
     
    333315                forceFillCodeLocations( transUnit );
    334316
     317                PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) );
     318                if ( exdeclp ) {
     319                        dump( std::move( transUnit ) );
     320                        return EXIT_SUCCESS;
     321                }
     322
     323                PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) );
    335324                PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) );
    336325                PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) );
     
    474463                if ( errorp ) {
    475464                        cerr << "---AST at error:---" << endl;
    476                         dump( translationUnit, cerr );
     465                        // We check which section the errors came from without looking at
     466                        // transUnit because std::move means it could look like anything.
     467                        if ( !translationUnit.empty() ) {
     468                                dump( translationUnit, cerr );
     469                        } else {
     470                                dump( std::move( transUnit ), cerr );
     471                        }
    477472                        cerr << endl << "---End of AST, begin error message:---\n" << endl;
    478473                } // if
     
    578573        { "rproto", resolvprotop, true, "resolver-proto instance" },
    579574        { "rsteps", resolvep, true, "print resolver steps" },
    580         { "tree", parsep, true, "print parse tree" },
    581575        // code dumps
    582576        { "ast", astp, true, "print AST after parsing" },
Note: See TracChangeset for help on using the changeset viewer.