Changeset 17fa94f for src


Ignore:
Timestamp:
Feb 11, 2025, 11:24:07 AM (7 weeks ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
691bf0a
Parents:
3e5e32cf
Message:

Reworked some nodes so they can be typed or untyped. This allowed me to remove TranslationDeps? as the type information is only needed in the candidate finder, which can easily insert it.

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/AST/Expr.cpp

    r3e5e32cf r17fa94f  
    281281// --- SizeofExpr
    282282
    283 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * t )
    284 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {}
     283SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type )
     284: SizeofExpr( loc, type, nullptr ) {}
     285
     286SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type, const Type * result )
     287: Expr( loc, result ), type( type ) {}
    285288
    286289// --- AlignofExpr
    287290
    288 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t )
    289 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {}
     291AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type )
     292: AlignofExpr( loc, type, nullptr ) {}
     293
     294AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type, const Type * result )
     295: Expr( loc, result ), type( type ) {}
    290296
    291297// --- CountofExpr
    292298
    293299CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t )
    294 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {}
     300: Expr( loc ), type( t ) {}
    295301
    296302// --- OffsetofExpr
    297303
    298304OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem )
    299 : Expr( loc, ast::TranslationDeps::getSizeType() ), type( ty ), member( mem ) {
     305: OffsetofExpr( loc, ty, mem, nullptr ) {}
     306
     307OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res )
     308: Expr( loc, res ), type( ty ), member( mem ) {
    300309        assert( type );
    301310        assert( member );
     
    305314
    306315OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty )
    307 : Expr( loc, new ArrayType{
    308         ast::TranslationDeps::getSizeType(), nullptr, FixedLen, DynamicDim }
    309 ), type( ty ) {
     316: Expr( loc ), type( ty ) {
    310317        assert( type );
    311318}
  • TabularUnified src/AST/Expr.hpp

    r3e5e32cf r17fa94f  
    483483
    484484        SizeofExpr( const CodeLocation & loc, const Type * t );
     485        SizeofExpr( const CodeLocation & loc, const Type * t, const Type * r );
    485486
    486487        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    496497
    497498        AlignofExpr( const CodeLocation & loc, const Type * t );
     499        AlignofExpr( const CodeLocation & loc, const Type * t, const Type * r );
    498500
    499501        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    538540
    539541        OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem );
     542        OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res );
    540543
    541544        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • TabularUnified src/AST/Util.cpp

    r3e5e32cf r17fa94f  
    384384}
    385385
    386 namespace {
    387         const TranslationUnit * transUnit = 0;
    388 }
    389 
    390 void TranslationDeps::evolve( TranslationUnit & u ) {
    391         transUnit = &u;
    392 }
    393 
    394 const ast::Type * TranslationDeps::getSizeType() {
    395         static const ast::Type * zd_abstract = new TypeInstType{ "size_t", TypeDecl::Kind::Dtype };
    396         static const ast::Type * ld_concrete = new BasicType( BasicKind::LongUnsignedInt );
    397         if ( ! transUnit ) {
    398                 // early state
    399                 // as if `size_t` in program text were freshly parsed
    400                 return zd_abstract;
    401         } else if ( transUnit->global.sizeType ) {
    402                 // late state, normal run
    403                 // whatever size_t was defined as
    404                 return transUnit->global.sizeType;
    405         } else {
    406                 // late state, no prelude (-n)
    407                 // placeholder: cfa-cpp is being used experimentally, stay out of the way
    408                 return ld_concrete;
    409         }
    410 }
    411 
    412 
    413386} // namespace ast
  • TabularUnified src/AST/Util.hpp

    r3e5e32cf r17fa94f  
    2626void checkInvariants( TranslationUnit & );
    2727
    28 /// Maintains an AST-module state for contextual information needed in
    29 /// ast::* implementations, notably constructors:
    30 ///    early: while parsing, use bootstrap versions
    31 ///    late: once a whole TranslationUnit exists, use its answers
    32 /// When the program is in the later state, ast::* construcors effectively get
    33 /// the benefit of WithTranslationUnit, without having to pass them one.
    34 class TranslationDeps {
    35 
    36     TranslationDeps() = delete;
    37 
    38     friend class SizeofExpr;
    39     friend class AlignofExpr;
    40     friend class CountofExpr;
    41     friend class OffsetofExpr;
    42     friend class OffsetPackExpr;
    43 
    44     /// Appropriate return type for built-in expressions that report on sizes
    45     static const Type * getSizeType();
    46 
    47   public:
    48     /// Transition from early to late states
    49     static void evolve( TranslationUnit & );
    50 };
    51 
    5228}
  • TabularUnified src/ResolvExpr/CandidateFinder.cpp

    r3e5e32cf r17fa94f  
    14861486
    14871487        void Finder::postvisit( const ast::SizeofExpr * sizeofExpr ) {
     1488                const ast::Type * type = resolveTypeof( sizeofExpr->type, context );
     1489                const ast::Type * sizeType = context.global.sizeType.get();
    14881490                addCandidate(
    1489                         new ast::SizeofExpr{
    1490                                 sizeofExpr->location, resolveTypeof( sizeofExpr->type, context ) },
     1491                        new ast::SizeofExpr( sizeofExpr->location, type, sizeType ),
     1492                        tenv );
     1493        }
     1494
     1495        void Finder::postvisit( const ast::AlignofExpr * alignofExpr ) {
     1496                const ast::Type * type = resolveTypeof( alignofExpr->type, context );
     1497                const ast::Type * sizeType = context.global.sizeType.get();
     1498                addCandidate(
     1499                        new ast::AlignofExpr( alignofExpr->location, type, sizeType ),
    14911500                        tenv );
    14921501        }
     
    15161525        }
    15171526
    1518         void Finder::postvisit( const ast::AlignofExpr * alignofExpr ) {
    1519                 addCandidate(
    1520                         new ast::AlignofExpr{
    1521                                 alignofExpr->location, resolveTypeof( alignofExpr->type, context ) },
    1522                         tenv );
    1523         }
    1524 
    15251527        void Finder::postvisit( const ast::UntypedOffsetofExpr * offsetofExpr ) {
    15261528                const ast::BaseInstType * aggInst;
     
    15291531                else return;
    15301532
     1533                const ast::Type * sizeType = context.global.sizeType.get();
    15311534                for ( const ast::Decl * member : aggInst->lookup( offsetofExpr->member ) ) {
    15321535                        auto dwt = strict_dynamic_cast< const ast::DeclWithType * >( member );
    15331536                        addCandidate(
    1534                                 new ast::OffsetofExpr{ offsetofExpr->location, aggInst, dwt }, tenv );
     1537                                new ast::OffsetofExpr( offsetofExpr->location, aggInst, dwt, sizeType ), tenv );
    15351538                }
    15361539        }
  • TabularUnified src/main.cpp

    r3e5e32cf r17fa94f  
    199199                Stats::Time::StopBlock();
    200200
    201                 ast::TranslationDeps::evolve( transUnit );
    202 
    203201                PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit );
    204202
Note: See TracChangeset for help on using the changeset viewer.