Changes in / [54cd1a51:4d5c5b6a]


Ignore:
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r54cd1a51 r4d5c5b6a  
    2626#include "Stmt.hpp"
    2727#include "Type.hpp"
     28#include "Util.hpp"                // for TranslationDeps
    2829#include "TypeSubstitution.hpp"
    2930#include "Common/Utility.hpp"
     
    280281// --- SizeofExpr
    281282
    282 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type )
    283 : SizeofExpr( loc, type, nullptr ) {}
    284 
    285 SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type, const Type * result )
    286 : Expr( loc, result ), type( type ) {}
     283SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * t )
     284: Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {}
    287285
    288286// --- AlignofExpr
    289287
    290 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type )
    291 : AlignofExpr( loc, type, nullptr ) {}
    292 
    293 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type, const Type * result )
    294 : Expr( loc, result ), type( type ) {}
     288AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t )
     289: Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {}
    295290
    296291// --- CountofExpr
    297292
    298293CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t )
    299 : Expr( loc ), type( t ) {}
     294: Expr( loc, ast::TranslationDeps::getSizeType() ), type( t ) {}
    300295
    301296// --- OffsetofExpr
    302297
    303298OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem )
    304 : OffsetofExpr( loc, ty, mem, nullptr ) {}
    305 
    306 OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res )
    307 : Expr( loc, res ), type( ty ), member( mem ) {
     299: Expr( loc, ast::TranslationDeps::getSizeType() ), type( ty ), member( mem ) {
    308300        assert( type );
    309301        assert( member );
     
    313305
    314306OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty )
    315 : Expr( loc ), type( ty ) {
     307: Expr( loc, new ArrayType{
     308        ast::TranslationDeps::getSizeType(), nullptr, FixedLen, DynamicDim }
     309), type( ty ) {
    316310        assert( type );
    317311}
  • src/AST/Expr.hpp

    r54cd1a51 r4d5c5b6a  
    483483
    484484        SizeofExpr( const CodeLocation & loc, const Type * t );
    485         SizeofExpr( const CodeLocation & loc, const Type * t, const Type * r );
    486485
    487486        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    497496
    498497        AlignofExpr( const CodeLocation & loc, const Type * t );
    499         AlignofExpr( const CodeLocation & loc, const Type * t, const Type * r );
    500498
    501499        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    540538
    541539        OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem );
    542         OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res );
    543540
    544541        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Util.cpp

    r54cd1a51 r4d5c5b6a  
    384384}
    385385
     386namespace {
     387        const TranslationUnit * transUnit = 0;
     388}
     389
     390void TranslationDeps::evolve( TranslationUnit & u ) {
     391        transUnit = &u;
     392}
     393
     394const 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
    386413} // namespace ast
  • src/AST/Util.hpp

    r54cd1a51 r4d5c5b6a  
    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.
     34class 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
    2852}
  • src/ResolvExpr/CandidateFinder.cpp

    r54cd1a51 r4d5c5b6a  
    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();
    14901488                addCandidate(
    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 ),
     1489                        new ast::SizeofExpr{
     1490                                sizeofExpr->location, resolveTypeof( sizeofExpr->type, context ) },
    15001491                        tenv );
    15011492        }
     
    15251516        }
    15261517
     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
    15271525        void Finder::postvisit( const ast::UntypedOffsetofExpr * offsetofExpr ) {
    15281526                const ast::BaseInstType * aggInst;
     
    15311529                else return;
    15321530
    1533                 const ast::Type * sizeType = context.global.sizeType.get();
    15341531                for ( const ast::Decl * member : aggInst->lookup( offsetofExpr->member ) ) {
    15351532                        auto dwt = strict_dynamic_cast< const ast::DeclWithType * >( member );
    15361533                        addCandidate(
    1537                                 new ast::OffsetofExpr( offsetofExpr->location, aggInst, dwt, sizeType ), tenv );
     1534                                new ast::OffsetofExpr{ offsetofExpr->location, aggInst, dwt }, tenv );
    15381535                }
    15391536        }
  • src/main.cpp

    r54cd1a51 r4d5c5b6a  
    199199                Stats::Time::StopBlock();
    200200
     201                ast::TranslationDeps::evolve( transUnit );
     202
    201203                PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit );
    202204
  • tests/.expect/alloc-ERROR.arm64.txt

    r54cd1a51 r4d5c5b6a  
    1616          Name: stp
    1717
     18      ... with resolved type:
     19        unsigned long int
    1820
    1921
  • tests/.expect/alloc-ERROR.x64.txt

    r54cd1a51 r4d5c5b6a  
    1616          Name: stp
    1717
     18      ... with resolved type:
     19        unsigned long int
    1820
    1921
  • tests/.expect/alloc-ERROR.x86.txt

    r54cd1a51 r4d5c5b6a  
    1616          Name: stp
    1717
     18      ... with resolved type:
     19        unsigned int
    1820
    1921
Note: See TracChangeset for help on using the changeset viewer.