Changeset 3d618a0 for src/AST


Ignore:
Timestamp:
Sep 9, 2024, 6:16:09 PM (5 weeks ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
aa14aafe
Parents:
d93b813 (diff), f5dbc8d (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/AST
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    rd93b813 r3d618a0  
    276276// --- SizeofExpr
    277277
    278 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Expr * e )
    279 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
    280 
    281278SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * t )
    282 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
     279: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {}
    283280
    284281// --- CountExpr
     
    292289// --- AlignofExpr
    293290
    294 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Expr * e )
    295 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
    296 
    297291AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t )
    298 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
     292: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {}
    299293
    300294// --- OffsetofExpr
  • src/AST/Expr.hpp

    rd93b813 r3d618a0  
    480480class SizeofExpr final : public Expr {
    481481public:
     482        ptr<Type> type;
     483
     484        SizeofExpr( const CodeLocation & loc, const Type * t );
     485
     486        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     487private:
     488        SizeofExpr * clone() const override { return new SizeofExpr{ *this }; }
     489        MUTATE_FRIEND
     490};
     491
     492class CountExpr final : public Expr {
     493public:
    482494        ptr<Expr> expr;
    483495        ptr<Type> type;
    484496
    485         SizeofExpr( const CodeLocation & loc, const Expr * e );
    486         SizeofExpr( const CodeLocation & loc, const Type * t );
    487         // deliberately no disambiguating overload for nullptr_t
    488 
    489         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    490 private:
    491         SizeofExpr * clone() const override { return new SizeofExpr{ *this }; }
    492         MUTATE_FRIEND
    493 };
    494 
    495 class CountExpr final : public Expr {
    496 public:
    497         ptr<Expr> expr;
    498         ptr<Type> type;
    499 
    500497        CountExpr( const CodeLocation & loc, const Expr * t );
    501498        CountExpr( const CodeLocation & loc, const Type * t );
     
    510507class AlignofExpr final : public Expr {
    511508public:
    512         ptr<Expr> expr;
    513509        ptr<Type> type;
    514510
    515         AlignofExpr( const CodeLocation & loc, const Expr * e );
    516511        AlignofExpr( const CodeLocation & loc, const Type * t );
    517         // deliberately no disambiguating overload for nullptr_t
    518512
    519513        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Pass.hpp

    rd93b813 r3d618a0  
    342342/// set visit_children false of all child nodes should be ignored
    343343struct WithShortCircuiting {
    344         bool visit_children;
     344        bool visit_children = true;
    345345};
    346346
  • src/AST/Pass.impl.hpp

    rd93b813 r3d618a0  
    13191319                        maybe_accept( node, &SizeofExpr::result );
    13201320                }
    1321                 if ( node->type ) {
    1322                         maybe_accept( node, &SizeofExpr::type );
    1323                 } else {
    1324                         maybe_accept( node, &SizeofExpr::expr );
    1325                 }
     1321                maybe_accept( node, &SizeofExpr::type );
    13261322        }
    13271323
     
    13591355                        maybe_accept( node, &AlignofExpr::result );
    13601356                }
    1361                 if ( node->type ) {
    1362                         maybe_accept( node, &AlignofExpr::type );
    1363                 } else {
    1364                         maybe_accept( node, &AlignofExpr::expr );
    1365                 }
     1357                maybe_accept( node, &AlignofExpr::type );
    13661358        }
    13671359
  • src/AST/Print.cpp

    rd93b813 r3d618a0  
    11521152                os << "Sizeof Expression on: ";
    11531153                ++indent;
     1154                node->type->accept( *this );
     1155                --indent;
     1156                postprint( node );
     1157
     1158                return node;
     1159        }
     1160
     1161        virtual const ast::Expr * visit( const ast::CountExpr * node ) override final {
     1162                os << "Count Expression on: ";
     1163                ++indent;
    11541164                if ( node->type ) node->type->accept( *this );
    11551165                else safe_print( node->expr );
    11561166                --indent;
    11571167                postprint( node );
    1158 
    1159                 return node;
    1160         }
    1161 
    1162         virtual const ast::Expr * visit( const ast::CountExpr * node ) override final {
    1163                 os << "Count Expression on: ";
    1164                 ++indent;
    1165                 if ( node->type ) node->type->accept( *this );
    1166                 else safe_print( node->expr );
    1167                 --indent;
    1168                 postprint( node );
    11691168                return node;
    11701169        }
     
    11731172                os << "Alignof Expression on: ";
    11741173                ++indent;
    1175                 if ( node->type ) node->type->accept( *this );
    1176                 else safe_print( node->expr );
     1174                node->type->accept( *this );
    11771175                --indent;
    11781176                postprint( node );
  • src/AST/Util.cpp

    rd93b813 r3d618a0  
    104104        }
    105105        assertf( false, "Member not found." );
    106 }
    107 
    108 template<typename node_t>
    109 void oneOfExprOrType( const node_t * node ) {
    110         if ( node->expr ) {
    111                 assertf( node->expr && !node->type, "Exactly one of expr or type should be set." );
    112         } else {
    113                 assertf( !node->expr && node->type, "Exactly one of expr or type should be set." );
    114         }
    115106}
    116107
     
    159150                previsit( (const ParseNode *)node );
    160151                memberMatchesAggregate( node );
    161         }
    162 
    163         void previsit( const SizeofExpr * node ) {
    164                 previsit( (const ParseNode *)node );
    165                 oneOfExprOrType( node );
    166         }
    167 
    168         void previsit( const AlignofExpr * node ) {
    169                 previsit( (const ParseNode *)node );
    170                 oneOfExprOrType( node );
    171152        }
    172153
Note: See TracChangeset for help on using the changeset viewer.