Changeset b6f2e7ab for src/AST


Ignore:
Timestamp:
Sep 9, 2024, 5:15:32 PM (14 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
f5dbc8d
Parents:
5c6d439
Message:

Removed SizeofExpr::expr and AlignofExpr::expr, expressions that would be stored there are wrapped in TypeofType and stored in the type field. Some special cases to hide the typeof in code generation were added. In addition, initializer length is calculated in more cases so that the full type of more arrays is known sooner. Other than that, most of the code changes were just stripping out the conditional code and checks no longer needed. Some tests had to be updated, because the typeof is not hidden in dumps and the resolver replaces known typeof expressions with the type. The extension case caused some concern but it appears that just hides warnings in the expression which no longer exists.

Location:
src/AST
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r5c6d439 rb6f2e7ab  
    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

    r5c6d439 rb6f2e7ab  
    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.impl.hpp

    r5c6d439 rb6f2e7ab  
    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

    r5c6d439 rb6f2e7ab  
    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

    r5c6d439 rb6f2e7ab  
    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
     
    163154        void previsit( const SizeofExpr * node ) {
    164155                previsit( (const ParseNode *)node );
    165                 oneOfExprOrType( node );
    166156        }
    167157
    168158        void previsit( const AlignofExpr * node ) {
    169159                previsit( (const ParseNode *)node );
    170                 oneOfExprOrType( node );
    171160        }
    172161
Note: See TracChangeset for help on using the changeset viewer.