Changeset 366f5cd for src/AST/Expr.cpp


Ignore:
Timestamp:
Jun 23, 2026, 1:57:51 PM (26 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
9d7a19f
Parents:
45d0e65
Message:

differentiate between C _Alignof and gcc alignof

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r45d0e65 r366f5cd  
    1111// Last Modified By : Peter A. Buhr
    1212// Created On       : Wed May 18 13:56:00 2022
    13 // Update Count     : 12
     13// Update Count     : 18
    1414//
    1515
     
    4646// --- ApplicationExpr
    4747
    48 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f,
    49         std::vector<ptr<Expr>> && as )
    50 : Expr( loc ), func( f ), args( std::move(as) ) {
     48ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f,     std::vector<ptr<Expr>> && as )
     49                : Expr( loc ), func( f ), args( std::move(as) ) {
    5150        // ensure that `ApplicationExpr` result type is `FuncExpr`
    5251        const PointerType * pt = strict_dynamic_cast< const PointerType * >( f->result.get() );
     
    103102}
    104103
    105 UntypedExpr * UntypedExpr::createCall( const CodeLocation & loc,
    106                 const std::string & name, std::vector<ptr<Expr>> && args ) {
     104UntypedExpr * UntypedExpr::createCall( const CodeLocation & loc, const std::string & name, std::vector<ptr<Expr>> && args ) {
    107105        return new UntypedExpr( loc,
    108106                        new NameExpr( loc, name ), std::move( args ) );
     
    111109// --- VariableExpr
    112110
    113 VariableExpr::VariableExpr( const CodeLocation & loc )
    114 : Expr( loc ), var( nullptr ) {}
    115 
    116 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v )
    117 : Expr( loc ), var( v ) {
     111VariableExpr::VariableExpr( const CodeLocation & loc ) : Expr( loc ), var( nullptr ) {}
     112
     113VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v ) : Expr( loc ), var( v ) {
    118114        assert( var );
    119115        assert( var->get_type() );
     
    130126}
    131127
    132 VariableExpr * VariableExpr::functionPointer(
    133                 const CodeLocation & loc, const FunctionDecl * decl ) {
     128VariableExpr * VariableExpr::functionPointer( const CodeLocation & loc, const FunctionDecl * decl ) {
    134129        // wrap usually-determined result type in a pointer
    135130        VariableExpr * funcExpr = new VariableExpr{ loc, decl };
     
    178173}
    179174
    180 AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) :
    181         Expr( loc, addrExprType( loc, a ) ), arg( a )
    182 {}
     175AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc, addrExprType( loc, a ) ), arg( a ) {}
    183176
    184177// --- LabelAddressExpr
     
    191184
    192185CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g, CastKind kind )
    193 : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ), kind( kind ) {}
     186                : Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ), kind( kind ) {}
    194187
    195188bool CastExpr::get_lvalue() const {
     
    213206
    214207MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg )
    215 : Expr( loc ), member( mem ), aggregate( agg ) {
     208                : Expr( loc ), member( mem ), aggregate( agg ) {
    216209        assert( member );
    217210        assert( aggregate );
     
    249242
    250243ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) {
    251         return new ConstantExpr{
    252                 loc, new BasicType{ BasicKind::Bool }, b ? "1" : "0", (unsigned long long)b };
     244        return new ConstantExpr{ loc, new BasicType{ BasicKind::Bool }, b ? "1" : "0", (unsigned long long)b };
    253245}
    254246
    255247ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) {
    256         return new ConstantExpr{
    257                 loc, new BasicType{ BasicKind::SignedInt }, std::to_string( i ), (unsigned long long)i };
     248        return new ConstantExpr{ loc, new BasicType{ BasicKind::SignedInt }, std::to_string( i ), (unsigned long long)i };
    258249}
    259250
    260251ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) {
    261         return new ConstantExpr{
    262                 loc, new BasicType{ BasicKind::LongUnsignedInt }, std::to_string( i ),
    263                 (unsigned long long)i };
     252        return new ConstantExpr{ loc, new BasicType{ BasicKind::LongUnsignedInt }, std::to_string( i ), (unsigned long long)i };
    264253}
    265254
     
    274263
    275264ConstantExpr * ConstantExpr::null( const CodeLocation & loc, const Type * ptrType ) {
    276         return new ConstantExpr{
    277                 loc, ptrType ? ptrType : new PointerType{ new VoidType{} }, "0", (unsigned long long)0 };
     265        return new ConstantExpr{ loc, ptrType ? ptrType : new PointerType{ new VoidType{} }, "0", (unsigned long long)0 };
    278266}
    279267
    280268// --- SizeofExpr
    281269
    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 ) {}
     270SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type ) : SizeofExpr( loc, type, nullptr ) {}
     271
     272SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * type, const Type * result ) : Expr( loc, result ), type( type ) {}
    287273
    288274// --- AlignofExpr
    289275
    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 ) {}
     276AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type, const Alignment kind ) : AlignofExpr( loc, type, nullptr, kind ) {}
     277
     278AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * type, const Type * result, const Alignment kind )
     279                : Expr( loc, result ), type( type ), kind( kind ) {}
    295280
    296281// --- CountofExpr
    297282
    298 CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t )
    299 : Expr( loc ), type( t ) {}
     283CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t ) : Expr( loc ), type( t ) {}
    300284
    301285// --- OffsetofExpr
    302286
    303287OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res )
    304 : Expr( loc, res ), type( ty ), member( mem ) {
     288                : Expr( loc, res ), type( ty ), member( mem ) {
    305289        assert( type );
    306290        assert( member );
     
    309293// --- OffsetPackExpr
    310294
    311 OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty )
    312 : Expr( loc ), type( ty ) {
     295OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ) : Expr( loc ), type( ty ) {
    313296        assert( type );
    314297}
     
    316299// --- LogicalExpr
    317300
    318 LogicalExpr::LogicalExpr(
    319         const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia )
    320 : Expr( loc, new BasicType{ BasicKind::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
     301LogicalExpr::LogicalExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia )
     302                : Expr( loc, new BasicType{ BasicKind::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
    321303
    322304// --- CommaExpr
     
    330312// --- ConstructorExpr
    331313
    332 ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call )
    333 : Expr( loc ), callExpr( call ) {
     314ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) : Expr( loc ), callExpr( call ) {
    334315        // allow resolver to type a constructor used as an expression if it has the same type as its
    335316        // first argument
     
    342323// --- CompoundLiteralExpr
    343324
    344 CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i )
    345 : Expr( loc ), init( i ) {
     325CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ) : Expr( loc ), init( i ) {
    346326        assert( t && i );
    347327        result = t;
     
    354334// --- TupleExpr
    355335
    356 TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs )
    357 : Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {}
     336TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ) : Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {}
    358337
    359338// --- TupleIndexExpr
    360339
    361 TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i )
    362 : Expr( loc ), tuple( t ), index( i ) {
     340TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ) : Expr( loc ), tuple( t ), index( i ) {
    363341        const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result.get() );
    364342        assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested "
     
    374352// --- TupleAssignExpr
    375353
    376 TupleAssignExpr::TupleAssignExpr(
    377         const CodeLocation & loc, std::vector<ptr<Expr>> && assigns,
    378         std::vector<ptr<ObjectDecl>> && tempDecls )
    379 : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() {
     354TupleAssignExpr::TupleAssignExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, std::vector<ptr<ObjectDecl>> && tempDecls )
     355                : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() {
    380356        // convert internally into a StmtExpr which contains the declarations and produces the tuple of
    381357        // the assignments
     
    392368// --- StmtExpr
    393369
    394 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss )
    395 : Expr( loc ), stmts( ss ) { computeResult(); }
     370StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) : Expr( loc ), stmts( ss ) { computeResult(); }
    396371
    397372void StmtExpr::computeResult() {
     
    411386unsigned long long UniqueExpr::nextId = 0;
    412387
    413 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i )
    414 : Expr( loc, e->result ), expr( e ), id( i ) {
     388UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i ) : Expr( loc, e->result ), expr( e ), id( i ) {
    415389        assert( expr );
    416390        if ( id == -1ull ) {
Note: See TracChangeset for help on using the changeset viewer.