Changeset 1fbeebd


Ignore:
Timestamp:
Nov 30, 2017, 5:37:15 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
ef3d798
Parents:
1cb934d
git-author:
Rob Schluntz <rschlunt@…> (11/30/17 17:12:26)
git-committer:
Rob Schluntz <rschlunt@…> (11/30/17 17:37:15)
Message:

Convert LabelFixer? to PassVisitor?

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/LabelFixer.cc

    r1cb934d r1fbeebd  
    3737        }
    3838
    39         void LabelFixer::visit( FunctionDecl *functionDecl ) {
     39        void LabelFixer::previsit( FunctionDecl * ) {
    4040                // need to go into a nested function in a fresh state
    41                 std::map < Label, Entry *> oldLabelTable = labelTable;
     41                GuardValue( labelTable );
    4242                labelTable.clear();
     43        }
    4344
    44                 maybeAccept( functionDecl->get_statements(), *this );
    45 
     45        void LabelFixer::postvisit( FunctionDecl * functionDecl ) {
    4646                MLEMutator mlemut( resolveJumps(), generator );
    4747                functionDecl->acceptMutator( mlemut );
    48 
    49                 // and remember the outer function's labels when
    50                 // returning to it
    51                 labelTable = oldLabelTable;
    5248        }
    5349
    5450        // prune to at most one label definition for each statement
    55         void LabelFixer::visit( Statement *stmt ) {
     51        void LabelFixer::previsit( Statement *stmt ) {
    5652                std::list< Label > &labels = stmt->get_labels();
    5753
     
    6258        }
    6359
    64         void LabelFixer::visit( BranchStmt *branchStmt ) {
    65                 visit ( ( Statement * )branchStmt );
     60        void LabelFixer::previsit( BranchStmt *branchStmt ) {
     61                previsit( ( Statement *)branchStmt );
    6662
    6763                // for labeled branches, add an entry to the label table
     
    7268        }
    7369
    74         void LabelFixer::visit( UntypedExpr *untyped ) {
    75                 if ( NameExpr * func = dynamic_cast< NameExpr * >( untyped->get_function() ) ) {
    76                         if ( func->get_name() == "&&" ) {
    77                                 NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() );
    78                                 Label target = arg->get_name();
    79                                 assert( target != "" );
    80                                 setLabelsUsg( target, untyped );
    81                         } else {
    82                                 Visitor::visit( untyped );
    83                         }
    84                 }
     70        void LabelFixer::previsit( LabelAddressExpr * addrExpr ) {
     71                Label & target = addrExpr->arg;
     72                assert( target != "" );
     73                setLabelsUsg( target, addrExpr );
    8574        }
    8675
  • src/ControlStruct/LabelFixer.h

    r1cb934d r1fbeebd  
    1919#include <map>                     // for map
    2020
     21#include "Common/PassVisitor.h"
    2122#include "Common/SemanticError.h"  // for SemanticError
    2223#include "SynTree/Label.h"         // for Label
     
    2627namespace ControlStruct {
    2728        /// normalizes label definitions and generates multi-level exit labels
    28 class LabelGenerator;
     29        class LabelGenerator;
    2930
    30         class LabelFixer final : public Visitor {
    31                 typedef Visitor Parent;
     31        class LabelFixer final : public WithGuards {
    3232          public:
    3333                LabelFixer( LabelGenerator *gen = 0 );
     
    3535                std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );
    3636
    37                 using Visitor::visit;
    38 
    3937                // Declarations
    40                 virtual void visit( FunctionDecl *functionDecl ) override;
     38                void previsit( FunctionDecl *functionDecl );
     39                void postvisit( FunctionDecl *functionDecl );
    4140
    4241                // Statements
    43                 void visit( Statement *stmt );
     42                void previsit( Statement *stmt );
     43                void previsit( BranchStmt *branchStmt );
    4444
    45                 virtual void visit( CompoundStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    46                 virtual void visit( NullStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    47                 virtual void visit( ExprStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    48                 virtual void visit( IfStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    49                 virtual void visit( WhileStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    50                 virtual void visit( ForStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    51                 virtual void visit( SwitchStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    52                 virtual void visit( CaseStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    53                 virtual void visit( ReturnStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    54                 virtual void visit( TryStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    55                 virtual void visit( CatchStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    56                 virtual void visit( DeclStmt *stmt ) override { visit( (Statement *)stmt ); return Parent::visit( stmt ); }
    57                 virtual void visit( BranchStmt *branchStmt ) override;
    58                 virtual void visit( UntypedExpr *untyped ) override;
     45                // Expressions
     46                void previsit( LabelAddressExpr *addrExpr );
    5947
    6048                Label setLabelsDef( std::list< Label > &, Statement *definition );
  • src/ControlStruct/Mutate.cc

    r1cb934d r1fbeebd  
    2424#include "SynTree/Declaration.h"   // for Declaration
    2525#include "SynTree/Mutator.h"       // for mutateAll
    26 //#include "ExceptMutator.h"
    2726
    2827#include "Common/PassVisitor.h"    // for PassVisitor
     
    3736
    3837                // normalizes label definitions and generates multi-level exit labels
    39                 LabelFixer lfix;
    40 
    41                 //ExceptMutator exc;
     38                PassVisitor<LabelFixer> lfix;
    4239
    4340                mutateAll( translationUnit, formut );
    4441                acceptAll( translationUnit, lfix );
    45                 //mutateAll( translationUnit, exc );
    4642        }
    4743} // namespace CodeGen
  • src/InitTweak/InitTweak.cc

    r1cb934d r1fbeebd  
    3030namespace InitTweak {
    3131        namespace {
    32                 class HasDesignations : public WithShortCircuiting {
    33                 public:
     32                struct HasDesignations : public WithShortCircuiting {
    3433                        bool hasDesignations = false;
    3534
Note: See TracChangeset for help on using the changeset viewer.