Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansionNew.cpp

    rce1d721 re9e9f56  
    1010// Created On       : Mon Aug 23 15:36:09 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jul 29 14:06:00 2022
    13 // Update Count     : 2
     12// Last Modified On : Tue Sep 20 16:17:00 2022
     13// Update Count     : 4
    1414//
    1515
     
    100100}
    101101
    102 struct TupleAssignExpander {
     102/// Replaces Tuple Assign & Index Expressions, and Tuple Types.
     103struct TupleMainExpander final :
     104                public ast::WithCodeLocation,
     105                public ast::WithDeclsToAdd<>,
     106                public ast::WithGuards,
     107                public ast::WithVisitorRef<TupleMainExpander> {
    103108        ast::Expr const * postvisit( ast::TupleAssignExpr const * expr ) {
    104109                // Just move the env on the new top level expression.
     
    106111                        &ast::TupleAssignExpr::env, expr->env.get() );
    107112        }
    108 };
    109 
    110 struct 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 );
     113
     114        void previsit( ast::CompoundStmt const * ) {
    120115                GuardScope( typeMap );
    121116        }
     
    185180                return newType;
    186181        }
    187 private:
    188         ScopedMap< int, ast::StructDecl const * > typeMap;
    189         CodeLocation const * location = nullptr;
    190 };
    191 
    192 struct TupleIndexExpander {
     182
    193183        ast::Expr const * postvisit( ast::TupleIndexExpr const * expr ) {
    194184                CodeLocation const & location = expr->location;
     
    221211                return memberExpr;
    222212        }
     213private:
     214        ScopedMap< int, ast::StructDecl const * > typeMap;
    223215};
    224216
     
    257249}
    258250
    259 struct TupleExprExpander {
     251struct TupleExprExpander final {
    260252        ast::Expr const * postvisit( ast::TupleExpr const * expr ) {
    261253                return replaceTupleExpr( expr->location,
     
    275267
    276268void expandTuples( ast::TranslationUnit & 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 );
     269        // These can't just be combined simply (there might be a way with work).
     270        ast::Pass<TupleMainExpander>::run( translationUnit );
    281271        ast::Pass<TupleExprExpander>::run( translationUnit );
    282272}
Note: See TracChangeset for help on using the changeset viewer.