Changeset 4551a6e


Ignore:
Timestamp:
Jun 21, 2017, 11:42:45 AM (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:
af5c204
Parents:
0508ab3
Message:

update PassVisitor? and Expression documentation, move reset_visit out of if statement

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r0508ab3 r4551a6e  
    1919// To use declare a PassVisitor< YOUR VISITOR TYPE >
    2020// The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired.
     21// Note: previsit/postvisit/premutate/postmutate must be **public** members
    2122//
    2223// Several additional features are available through inheritance
  • src/Common/PassVisitor.impl.h

    r0508ab3 r4551a6e  
    66        call_previsit( node );                    \
    77        if( visit_children() ) {                  \
    8                 reset_visit();                      \
    98
    109#define VISIT_END( node )                       \
    1110        }                                         \
     11        reset_visit();                            \
    1212        call_postvisit( node );                   \
    1313
     
    1717        call_premutate( node );                   \
    1818        if( visit_children() ) {                  \
    19                 reset_visit();                      \
    2019
    2120#define MUTATE_END( type, node )                \
    2221        }                                         \
     22        reset_visit();                            \
    2323        return call_postmutate< type * >( node ); \
    2424
     
    159159template< typename pass_type >
    160160void PassVisitor< pass_type >::visit( ObjectDecl * node ) {
    161         VISIT_BODY( node ); 
     161        VISIT_BODY( node );
    162162}
    163163
    164164template< typename pass_type >
    165165void PassVisitor< pass_type >::visit( FunctionDecl * node ) {
    166         VISIT_BODY( node ); 
     166        VISIT_BODY( node );
    167167}
    168168
    169169template< typename pass_type >
    170170void PassVisitor< pass_type >::visit( StructDecl * node ) {
    171         VISIT_BODY( node ); 
     171        VISIT_BODY( node );
    172172}
    173173
    174174template< typename pass_type >
    175175void PassVisitor< pass_type >::visit( UnionDecl * node ) {
    176         VISIT_BODY( node ); 
     176        VISIT_BODY( node );
    177177}
    178178
    179179template< typename pass_type >
    180180void PassVisitor< pass_type >::visit( EnumDecl * node ) {
    181         VISIT_BODY( node ); 
     181        VISIT_BODY( node );
    182182}
    183183
    184184template< typename pass_type >
    185185void PassVisitor< pass_type >::visit( TraitDecl * node ) {
    186         VISIT_BODY( node ); 
     186        VISIT_BODY( node );
    187187}
    188188
    189189template< typename pass_type >
    190190void PassVisitor< pass_type >::visit( TypeDecl * node ) {
    191         VISIT_BODY( node ); 
     191        VISIT_BODY( node );
    192192}
    193193
    194194template< typename pass_type >
    195195void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
    196         VISIT_BODY( node ); 
     196        VISIT_BODY( node );
    197197}
    198198
    199199template< typename pass_type >
    200200void PassVisitor< pass_type >::visit( AsmDecl * node ) {
    201         VISIT_BODY( node ); 
     201        VISIT_BODY( node );
    202202}
    203203
     
    250250template< typename pass_type >
    251251void PassVisitor< pass_type >::visit( AsmStmt * node ) {
    252         VISIT_BODY( node ); 
     252        VISIT_BODY( node );
    253253}
    254254
     
    257257template< typename pass_type >
    258258void PassVisitor< pass_type >::visit( IfStmt * node ) {
    259         VISIT_START( node ); 
     259        VISIT_START( node );
    260260
    261261        visitExpression( node->get_condition() );
     
    268268template< typename pass_type >
    269269Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
    270         MUTATE_START( node ); 
     270        MUTATE_START( node );
    271271
    272272        node->set_condition( mutateExpression( node->get_condition() ) );
     
    281281template< typename pass_type >
    282282void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    283         VISIT_START( node ); 
     283        VISIT_START( node );
    284284
    285285        visitExpression( node->get_condition() );
     
    291291template< typename pass_type >
    292292Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
    293         MUTATE_START( node ); 
     293        MUTATE_START( node );
    294294
    295295        node->set_condition( mutateExpression( node->get_condition() ) );
     
    303303template< typename pass_type >
    304304void PassVisitor< pass_type >::visit( ForStmt * node ) {
    305         VISIT_START( node ); 
     305        VISIT_START( node );
    306306
    307307        acceptAll( node->get_initialization(), *this );
     
    315315template< typename pass_type >
    316316Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
    317         MUTATE_START( node ); 
     317        MUTATE_START( node );
    318318
    319319        mutateAll( node->get_initialization(), *this );
     
    329329template< typename pass_type >
    330330void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    331         VISIT_START( node ); 
     331        VISIT_START( node );
    332332
    333333        visitExpression( node->get_condition() );
     
    339339template< typename pass_type >
    340340Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
    341         MUTATE_START( node ); 
    342        
     341        MUTATE_START( node );
     342
    343343        node->set_condition( mutateExpression( node->get_condition() ) );
    344344        mutateStatementList( node->get_statements() );
    345        
     345
    346346        MUTATE_END( Statement, node );
    347347}
     
    351351template< typename pass_type >
    352352void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    353         VISIT_START( node ); 
    354        
     353        VISIT_START( node );
     354
    355355        visitExpression( node->get_condition() );
    356356        visitStatementList( node->get_statements() );
    357        
     357
    358358        VISIT_END( node );
    359359}
     
    361361template< typename pass_type >
    362362Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
    363         MUTATE_START( node ); 
    364        
     363        MUTATE_START( node );
     364
    365365        node->set_condition(  mutateExpression( node->get_condition() ) );
    366366        mutateStatementList( node->get_statements() );
    367        
     367
    368368        MUTATE_END( Statement, node );
    369369}
     
    371371template< typename pass_type >
    372372void PassVisitor< pass_type >::visit( BranchStmt * node ) {
    373         VISIT_BODY( node ); 
     373        VISIT_BODY( node );
    374374}
    375375
     
    425425        node->set_block(  maybeMutate( node->get_block(), *this ) );
    426426        mutateAll( node->get_catchers(), *this );
    427        
     427
    428428        MUTATE_END( Statement, node );
    429429}
     
    444444Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    445445        MUTATE_START( node );
    446        
     446
    447447        node->set_body(  mutateStatement( node->get_body() ) );
    448448        node->set_decl(  maybeMutate( node->get_decl(), *this ) );
    449        
     449
    450450        MUTATE_END( Statement, node );
    451451}
     
    453453template< typename pass_type >
    454454void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
    455         VISIT_BODY( node ); 
     455        VISIT_BODY( node );
    456456}
    457457
    458458template< typename pass_type >
    459459void PassVisitor< pass_type >::visit( NullStmt * node ) {
    460         VISIT_BODY( node ); 
     460        VISIT_BODY( node );
    461461}
    462462
    463463template< typename pass_type >
    464464void PassVisitor< pass_type >::visit( DeclStmt * node ) {
    465         VISIT_BODY( node ); 
     465        VISIT_BODY( node );
    466466}
    467467
    468468template< typename pass_type >
    469469void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
    470         VISIT_BODY( node ); 
     470        VISIT_BODY( node );
    471471}
    472472
    473473template< typename pass_type >
    474474void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
    475         VISIT_BODY( node ); 
     475        VISIT_BODY( node );
    476476}
    477477
     
    502502template< typename pass_type >
    503503void PassVisitor< pass_type >::visit( NameExpr * node ) {
    504         VISIT_BODY( node ); 
     504        VISIT_BODY( node );
    505505}
    506506
    507507template< typename pass_type >
    508508void PassVisitor< pass_type >::visit( CastExpr * node ) {
    509         VISIT_BODY( node ); 
     509        VISIT_BODY( node );
    510510}
    511511
    512512template< typename pass_type >
    513513void PassVisitor< pass_type >::visit( AddressExpr * node ) {
    514         VISIT_BODY( node ); 
     514        VISIT_BODY( node );
    515515}
    516516
    517517template< typename pass_type >
    518518void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
    519         VISIT_BODY( node ); 
     519        VISIT_BODY( node );
    520520}
    521521
    522522template< typename pass_type >
    523523void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
    524         VISIT_BODY( node ); 
     524        VISIT_BODY( node );
    525525}
    526526
    527527template< typename pass_type >
    528528void PassVisitor< pass_type >::visit( MemberExpr * node ) {
    529         VISIT_BODY( node ); 
     529        VISIT_BODY( node );
    530530}
    531531
    532532template< typename pass_type >
    533533void PassVisitor< pass_type >::visit( VariableExpr * node ) {
    534         VISIT_BODY( node ); 
     534        VISIT_BODY( node );
    535535}
    536536
    537537template< typename pass_type >
    538538void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
    539         VISIT_BODY( node ); 
     539        VISIT_BODY( node );
    540540}
    541541
    542542template< typename pass_type >
    543543void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
    544         VISIT_BODY( node ); 
     544        VISIT_BODY( node );
    545545}
    546546
    547547template< typename pass_type >
    548548void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
    549         VISIT_BODY( node ); 
     549        VISIT_BODY( node );
    550550}
    551551
    552552template< typename pass_type >
    553553void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
    554         VISIT_BODY( node ); 
     554        VISIT_BODY( node );
    555555}
    556556
    557557template< typename pass_type >
    558558void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
    559         VISIT_BODY( node ); 
     559        VISIT_BODY( node );
    560560}
    561561
    562562template< typename pass_type >
    563563void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
    564         VISIT_BODY( node ); 
     564        VISIT_BODY( node );
    565565}
    566566
    567567template< typename pass_type >
    568568void PassVisitor< pass_type >::visit( AttrExpr * node ) {
    569         VISIT_BODY( node ); 
     569        VISIT_BODY( node );
    570570}
    571571
    572572template< typename pass_type >
    573573void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
    574         VISIT_BODY( node ); 
     574        VISIT_BODY( node );
    575575}
    576576
    577577template< typename pass_type >
    578578void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
    579         VISIT_BODY( node ); 
     579        VISIT_BODY( node );
    580580}
    581581
    582582template< typename pass_type >
    583583void PassVisitor< pass_type >::visit( CommaExpr * node ) {
    584         VISIT_BODY( node ); 
     584        VISIT_BODY( node );
    585585}
    586586
    587587template< typename pass_type >
    588588void PassVisitor< pass_type >::visit( TypeExpr * node ) {
    589         VISIT_BODY( node ); 
     589        VISIT_BODY( node );
    590590}
    591591
    592592template< typename pass_type >
    593593void PassVisitor< pass_type >::visit( AsmExpr * node ) {
    594         VISIT_BODY( node ); 
     594        VISIT_BODY( node );
    595595}
    596596
    597597template< typename pass_type >
    598598void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
    599         VISIT_BODY( node ); 
     599        VISIT_BODY( node );
    600600}
    601601
    602602template< typename pass_type >
    603603void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
    604         VISIT_BODY( node ); 
     604        VISIT_BODY( node );
    605605}
    606606
     
    617617template< typename pass_type >
    618618void PassVisitor< pass_type >::visit( RangeExpr * node ) {
    619         VISIT_BODY( node ); 
     619        VISIT_BODY( node );
    620620}
    621621
    622622template< typename pass_type >
    623623void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) {
    624         VISIT_BODY( node ); 
     624        VISIT_BODY( node );
    625625}
    626626
    627627template< typename pass_type >
    628628void PassVisitor< pass_type >::visit( TupleExpr * node ) {
    629         VISIT_BODY( node ); 
     629        VISIT_BODY( node );
    630630}
    631631
    632632template< typename pass_type >
    633633void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
    634         VISIT_BODY( node ); 
     634        VISIT_BODY( node );
    635635}
    636636
    637637template< typename pass_type >
    638638void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
    639         VISIT_BODY( node ); 
     639        VISIT_BODY( node );
    640640}
    641641
     
    659659Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
    660660        MUTATE_START( node );
    661        
     661
    662662        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    663663        ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     
    672672template< typename pass_type >
    673673void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
    674         VISIT_BODY( node ); 
     674        VISIT_BODY( node );
    675675}
    676676
    677677template< typename pass_type >
    678678void PassVisitor< pass_type >::visit( VoidType * node ) {
    679         VISIT_BODY( node ); 
     679        VISIT_BODY( node );
    680680}
    681681
    682682template< typename pass_type >
    683683void PassVisitor< pass_type >::visit( BasicType * node ) {
    684         VISIT_BODY( node ); 
     684        VISIT_BODY( node );
    685685}
    686686
    687687template< typename pass_type >
    688688void PassVisitor< pass_type >::visit( PointerType * node ) {
    689         VISIT_BODY( node ); 
     689        VISIT_BODY( node );
    690690}
    691691
    692692template< typename pass_type >
    693693void PassVisitor< pass_type >::visit( ArrayType * node ) {
    694         VISIT_BODY( node ); 
     694        VISIT_BODY( node );
    695695}
    696696
    697697template< typename pass_type >
    698698void PassVisitor< pass_type >::visit( FunctionType * node ) {
    699         VISIT_BODY( node ); 
     699        VISIT_BODY( node );
    700700}
    701701
    702702template< typename pass_type >
    703703void PassVisitor< pass_type >::visit( StructInstType * node ) {
    704         VISIT_BODY( node ); 
     704        VISIT_BODY( node );
    705705}
    706706
    707707template< typename pass_type >
    708708void PassVisitor< pass_type >::visit( UnionInstType * node ) {
    709         VISIT_BODY( node ); 
     709        VISIT_BODY( node );
    710710}
    711711
    712712template< typename pass_type >
    713713void PassVisitor< pass_type >::visit( EnumInstType * node ) {
    714         VISIT_BODY( node ); 
     714        VISIT_BODY( node );
    715715}
    716716
    717717template< typename pass_type >
    718718void PassVisitor< pass_type >::visit( TraitInstType * node ) {
    719         VISIT_BODY( node ); 
     719        VISIT_BODY( node );
    720720}
    721721
    722722template< typename pass_type >
    723723void PassVisitor< pass_type >::visit( TypeInstType * node ) {
    724         VISIT_BODY( node ); 
     724        VISIT_BODY( node );
    725725}
    726726
    727727template< typename pass_type >
    728728void PassVisitor< pass_type >::visit( TupleType * node ) {
    729         VISIT_BODY( node ); 
     729        VISIT_BODY( node );
    730730}
    731731
    732732template< typename pass_type >
    733733void PassVisitor< pass_type >::visit( TypeofType * node ) {
    734         VISIT_BODY( node ); 
     734        VISIT_BODY( node );
    735735}
    736736
    737737template< typename pass_type >
    738738void PassVisitor< pass_type >::visit( AttrType * node ) {
    739         VISIT_BODY( node ); 
     739        VISIT_BODY( node );
    740740}
    741741
    742742template< typename pass_type >
    743743void PassVisitor< pass_type >::visit( VarArgsType * node ) {
    744         VISIT_BODY( node ); 
     744        VISIT_BODY( node );
    745745}
    746746
    747747template< typename pass_type >
    748748void PassVisitor< pass_type >::visit( ZeroType * node ) {
    749         VISIT_BODY( node ); 
     749        VISIT_BODY( node );
    750750}
    751751
    752752template< typename pass_type >
    753753void PassVisitor< pass_type >::visit( OneType * node ) {
    754         VISIT_BODY( node ); 
     754        VISIT_BODY( node );
    755755}
    756756
     
    777777template< typename pass_type >
    778778void PassVisitor< pass_type >::visit( ListInit * node ) {
    779         VISIT_BODY( node ); 
     779        VISIT_BODY( node );
    780780}
    781781
    782782template< typename pass_type >
    783783void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
    784         VISIT_BODY( node ); 
     784        VISIT_BODY( node );
    785785}
    786786
    787787template< typename pass_type >
    788788void PassVisitor< pass_type >::visit( Subrange * node ) {
    789         VISIT_BODY( node ); 
     789        VISIT_BODY( node );
    790790}
    791791
    792792template< typename pass_type >
    793793void PassVisitor< pass_type >::visit( Constant * node ) {
    794         VISIT_BODY( node ); 
     794        VISIT_BODY( node );
    795795}
    796796
  • src/SynTree/Expression.cc

    r0508ab3 r4551a6e  
    288288}
    289289
    290 // CastExpr *CastExpr::clone() const { return 0; }
    291 
    292290void CastExpr::print( std::ostream &os, int indent ) const {
    293291        os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
     
    355353}
    356354
    357 //// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...
    358355MemberExpr::MemberExpr( const MemberExpr &other ) :
    359356                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
     
    361358
    362359MemberExpr::~MemberExpr() {
    363         // delete member;
     360        // don't delete the member declaration, since it points somewhere else in the tree
    364361        delete aggregate;
    365362}
  • src/SynTree/Expression.h

    r0508ab3 r4551a6e  
    226226};
    227227
    228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
     228/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
     229/// Does not take ownership of member.
    229230class MemberExpr : public Expression {
    230231  public:
     
    247248};
    248249
    249 /// VariableExpr represents an expression that simply refers to the value of a named variable
     250/// VariableExpr represents an expression that simply refers to the value of a named variable.
     251/// Does not take ownership of var.
    250252class VariableExpr : public Expression {
    251253  public:
Note: See TracChangeset for help on using the changeset viewer.