Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansionNew.cpp

    re9e9f56 rce1d721  
    1010// Created On       : Mon Aug 23 15:36:09 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Sep 20 16:17:00 2022
    13 // Update Count     : 4
     12// Last Modified On : Mon Jul 29 14:06:00 2022
     13// Update Count     : 2
    1414//
    1515
     
    100100}
    101101
    102 /// Replaces Tuple Assign & Index Expressions, and Tuple Types.
    103 struct TupleMainExpander final :
    104                 public ast::WithCodeLocation,
    105                 public ast::WithDeclsToAdd<>,
    106                 public ast::WithGuards,
    107                 public ast::WithVisitorRef<TupleMainExpander> {
     102struct TupleAssignExpander {
    108103        ast::Expr const * postvisit( ast::TupleAssignExpr const * expr ) {
    109104                // Just move the env on the new top level expression.
     
    111106                        &ast::TupleAssignExpr::env, expr->env.get() );
    112107        }
    113 
    114         void previsit( ast::CompoundStmt const * ) {
     108};
     109
     110struct TupleTypeReplacer :
     111                public ast::WithGuards,
     112                public ast::WithVisitorRef<TupleTypeReplacer>,
     113                public ast::WithDeclsToAdd<> {
     114        void previsit( ast::ParseNode const * node ) {
     115                GuardValue( location ) = &node->location;
     116        }
     117
     118        void previsit( ast::CompoundStmt const * stmt ) {
     119                previsit( (ast::ParseNode const *)stmt );
    115120                GuardScope( typeMap );
    116121        }
     
    180185                return newType;
    181186        }
    182 
     187private:
     188        ScopedMap< int, ast::StructDecl const * > typeMap;
     189        CodeLocation const * location = nullptr;
     190};
     191
     192struct TupleIndexExpander {
    183193        ast::Expr const * postvisit( ast::TupleIndexExpr const * expr ) {
    184194                CodeLocation const & location = expr->location;
     
    211221                return memberExpr;
    212222        }
    213 private:
    214         ScopedMap< int, ast::StructDecl const * > typeMap;
    215223};
    216224
     
    249257}
    250258
    251 struct TupleExprExpander final {
     259struct TupleExprExpander {
    252260        ast::Expr const * postvisit( ast::TupleExpr const * expr ) {
    253261                return replaceTupleExpr( expr->location,
     
    267275
    268276void expandTuples( ast::TranslationUnit & translationUnit ) {
    269         // These can't just be combined simply (there might be a way with work).
    270         ast::Pass<TupleMainExpander>::run( translationUnit );
     277        // These may not have to be seperate passes.
     278        ast::Pass<TupleAssignExpander>::run( translationUnit );
     279        ast::Pass<TupleTypeReplacer>::run( translationUnit );
     280        ast::Pass<TupleIndexExpander>::run( translationUnit );
    271281        ast::Pass<TupleExprExpander>::run( translationUnit );
    272282}
Note: See TracChangeset for help on using the changeset viewer.