Changeset 9b4f329


Ignore:
Timestamp:
May 16, 2019, 6:46:51 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
246c245
Parents:
f3cc5b6
Message:

Finished porting AST::Expr subclasses

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    rf3cc5b6 r9b4f329  
    2020#include <vector>
    2121
     22#include "Stmt.hpp"
    2223#include "Type.hpp"
    2324#include "Common/SemanticError.h"
     
    2526#include "InitTweak/InitTweak.h"   // for getPointerBase
    2627#include "ResolvExpr/typeops.h"    // for extractResultType
     28#include "Tuples/Tuples.h"         // for makeTupleType
    2729
    2830namespace ast {
     
    287289: Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
    288290
     291// --- ConstructorExpr
     292
     293ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call )
     294: Expr( loc ), callExpr( call ) {
     295        // allow resolver to type a constructor used as an expression if it has the same type as its
     296        // first argument
     297        assert( callExpr );
     298        const Expr * arg = InitTweak::getCallArg( callExpr, 0 );
     299        assert( arg );
     300        result = arg->result;
     301}
     302
     303// --- CompoundLiteralExpr
     304
     305CompoundLiteralExpr::CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i )
     306: Expr( loc ), init( i ) {
     307        assert( t && i );
     308        result.set_and_mutate( t )->set_lvalue( true );
     309}
     310
     311// --- TupleExpr
     312
     313TupleExpr::TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs )
     314: Expr( loc, Tuples::makeTupleType( xs ) ), exprs( xs ) {}
     315
     316// --- TupleIndexExpr
     317
     318TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i )
     319: Expr( loc ), tuple( t ), index( i ) {
     320        const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result );
     321        assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested "
     322                "index %d in expr %s", type->size(), index, toString( tuple ).c_str() );
     323        // like MemberExpr, TupleIndexExpr is always an lvalue
     324        result.set_and_mutate( type->types[ index ] )->set_lvalue( true );
     325}
     326
     327// --- TupleAssignExpr
     328
     329TupleAssignExpr::TupleAssignExpr(
     330        const CodeLocation & loc, std::vector<ptr<Expr>> && assigns,
     331        std::vector<ptr<ObjectDecl>> && tempDecls )
     332: Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() {
     333        // convert internally into a StmtExpr which contains the declarations and produces the tuple of
     334        // the assignments
     335        std::list<ptr<Stmt>> stmts;
     336        for ( const ObjectDecl * obj : tempDecls ) {
     337                stmts.emplace_back( new DeclStmt{ loc, obj } );
     338        }
     339        TupleExpr * tupleExpr = new TupleExpr{ loc, std::move(assigns) };
     340        assert( tupleExpr->result );
     341        stmts.emplace_back( new ExprStmt{ loc, tupleExpr } );
     342        stmtExpr = new StmtExpr{ loc, new CompoundStmt{ loc, std::move(stmts) } };
     343}
     344
     345// --- StmtExpr
     346
     347StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss )
     348: Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); }
     349
     350void StmtExpr::computeResult() {
     351        assert( stmts );
     352        const std::list<ptr<Stmt>> & body = stmts->kids;
     353        if ( ! returnDecls.empty() ) {
     354                // prioritize return decl for result type, since if a return decl exists, then the StmtExpr
     355                // is currently in an intermediate state where the body will always give a void result type
     356                result = returnDecls.front()->get_type();
     357        } else if ( ! body.empty() ) {
     358                if ( const ExprStmt * exprStmt = body.back().as< ExprStmt >() ) {
     359                        result = exprStmt->expr->result;
     360                }
     361        }
     362        // ensure a result type exists
     363        if ( ! result ) { result = new VoidType{}; }
     364}
     365
     366// --- UniqueExpr
     367
     368unsigned long long UniqueExpr::nextId = 0;
     369
     370UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1 )
     371: Expr( loc, e->result ), id( i ) {
     372        assert( expr );
     373        if ( id == -1 ) {
     374                assert( nextId != -1 );
     375                id = nextId++;
     376        }
    289377}
    290378
  • src/AST/Expr.hpp

    rf3cc5b6 r9b4f329  
    491491public:
    492492        ptr<Expr> inout;
    493         ptr<Expr> constraint;
     493        ptr<Expr> constraint;
     494        ptr<Expr> operand;
     495
     496        AsmExpr( const CodeLocation & loc, const Expr * io, const Expr * con, const Expr * op )
     497        : Expr( loc ), inout( io ), constraint( con ), operand( op ) {}
     498
     499        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     500private:
     501        AsmExpr * clone() const override { return new AsmExpr{ *this }; }
     502        MUTATE_FRIEND
     503};
     504
     505/// The application of a function to a set of parameters, along with a set of copy constructor
     506/// calls, one for each argument
     507class ImplicitCopyCtorExpr final : public Expr {
     508public:
     509        ptr<ApplicationExpr> callExpr;
     510        std::vector<ptr<ObjectDecl>> tempDecls;
     511        std::vector<ptr<ObjectDecl>> returnDecls;
     512        std::vector<ptr<ObjectDecl>> dtors;
     513
     514        ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call )
     515        : Expr( loc, call->result ), tempDecls(), returnDecls(), dtors() { assert( call ); }
     516
     517        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     518private:
     519        ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr{ *this }; }
     520        MUTATE_FRIEND
     521};
     522
     523/// Constructor in expression context, e.g. `int * x = alloc() { 42 };`
     524class ConstructorExpr final : public Expr {
     525public:
     526        ptr<Expr> callExpr;
     527
     528        ConstructorExpr( const CodeLocation & loc, const Expr * call );
     529
     530        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     531private:
     532        ConstructorExpr * clone() const override { return new ConstructorExpr{ *this }; }
     533        MUTATE_FRIEND
     534};
     535
     536/// A C99 compound literal, e.g. `(MyType){ a, b, c }`
     537class CompoundLiteralExpr final : public Expr {
     538public:
     539        ptr<Init> init;
     540
     541        CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i );
     542
     543        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     544private:
     545        CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr{ *this }; }
     546        MUTATE_FRIEND
     547};
     548
     549/// A range, e.g. `3 ... 5` or `1~10`
     550class RangeExpr final : public Expr {
     551public:
     552        ptr<Expr> low;
     553        ptr<Expr> high;
     554
     555        RangeExpr( const CodeLocation & loc, const Expr * l, const Expr * h )
     556        : Expr( loc ), low( l ), high( h ) {}
     557
     558        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     559private:
     560        RangeExpr * clone() const override { return new RangeExpr{ *this }; }
     561        MUTATE_FRIEND
     562};
     563
     564/// A tuple expression before resolution, e.g. `[a, b, c]`
     565class UntypedTupleExpr final : public Expr {
     566public:
     567        std::vector<ptr<Expr>> exprs;
     568
     569        UntypedTupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs )
     570        : Expr( loc ), exprs( std::move(xs) ) {}
     571
     572        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     573private:
     574        UntypedTupleExpr * clone() const override { return new UntypedTupleExpr{ *this }; }
     575        MUTATE_FRIEND
     576};
     577
     578/// A tuple expression after resolution, e.g. `[a, b, c]`
     579class TupleExpr final : public Expr {
     580public:
     581        std::vector<ptr<Expr>> exprs;
     582
     583        TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs );
     584
     585        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     586private:
     587        TupleExpr * clone() const override { return new TupleExpr{ *this }; }
     588        MUTATE_FRIEND
     589};
     590
     591/// An element selection operation on a tuple value, e.g. `t.3` after analysis
     592class TupleIndexExpr final : public Expr {
     593public:
     594        ptr<Expr> tuple;
     595        unsigned index;
     596
     597        TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i );
     598
     599        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     600private:
     601        TupleIndexExpr * clone() const override { return new TupleIndexExpr{ *this }; }
     602        MUTATE_FRIEND
     603};
     604
     605/// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression.
     606/// multiple-assignment: both sides of the assignment have tuple type,
     607///     e.g. `[a, b, c] = [d, e, f];`
     608/// mass-assignment: left-hand side has tuple type and right-hand side does not:
     609///     e.g. `[a, b, c] = 42;`
     610class TupleAssignExpr final : public Expr {
     611public:
     612        ptr<StmtExpr> stmtExpr;
     613
     614        TupleAssignExpr(
     615                const CodeLocation & loc, std::vector<ptr<Expr>> && assigns,
     616                std::vector<ptr<ObjectDecl>> && tempDecls );
     617       
     618        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     619private:
     620        TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; }
     621        MUTATE_FRIEND
     622};
     623
     624/// A GCC "statement expression", e.g. `({ int x = 5; x })`
     625class StmtExpr final : public Expr {
     626public:
     627        ptr<CompoundStmt> stmts;
     628        std::vector<ptr<ObjectDecl>> returnDecls;  ///< return variable(s) for statement expression
     629        std::vector<ptr<Expr>> dtors;              ///< destructor(s) for return variable(s)
     630
     631        StmtExpr( const CodeLocation & loc, const CompoundStmt * ss );
     632
     633        /// Set the result type of this StmtExpr based on its body
     634        void computeResult();
     635
     636        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     637private:
     638        StmtExpr * clone() const override { return new StmtExpr{ *this }; }
     639        MUTATE_FRIEND
     640};
     641
     642/// An expression which must only be evaluated once
     643class UniqueExpr final : public Expr {
     644        static unsigned long long nextId;
     645public:
     646        ptr<Expr> expr;
     647        ptr<ObjectDecl> object;
     648        ptr<VariableExpr> var;
     649        unsigned long long id;
     650
     651        UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1 );
     652
     653        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     654private:
     655        UniqueExpr * clone() const override { return new UniqueExpr{ *this }; }
     656        MUTATE_FRIEND
     657};
     658
     659/// One option for resolving an initializer expression
     660struct InitAlternative {
     661        ptr<Type> type;
     662        ptr<Designation> designation;
     663
     664        InitAlternative() = default;
     665        InitAlternative( const Type * ty, const Designation * des ) : type( ty ), designation( des ) {}
     666};
     667
     668/// Pre-resolution initializer expression
     669class UntypedInitExpr final : public Expr {
     670public:
     671        ptr<Expr> expr;
     672        std::vector<InitAlternative> initAlts;
     673
     674        UntypedInitExpr( const CodeLocation & loc, const Expr * e, std::vector<InitAlternative> && as )
     675        : Expr( loc ), expr( e ), initAlts( std::move(as) ) {}
     676
     677        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     678private:
     679        UntypedInitExpr * clone() const override { return new UntypedInitExpr{ *this }; }
     680        MUTATE_FRIEND
     681};
     682
     683/// Post-resolution initializer expression
     684class InitExpr final : public Expr {
     685public:
     686        ptr<Expr> expr;
     687        ptr<Designation> designation;
     688
     689        InitExpr( const CodeLocation & loc, const Expr * e, const Designation * des )
     690        : Expr( loc, e->result ), expr( e ), designation( des ) {}
     691
     692        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     693private:
     694        InitExpr * clone() const override { return new InitExpr{ *this }; }
     695        MUTATE_FRIEND
     696};
     697
     698/// Expression containing a deleted identifier.
     699/// Internal to resolver.
     700class DeletedExpr final : public Expr {
     701public:
     702        ptr<Expr> expr;
     703        readonly<Node> deleteStmt;
     704
     705        DeletedExpr( const CodeLocation & loc, const Expr * e, const Node * del )
     706        : Expr( loc, e->result ), expr( e ), deleteStmt( del ) { assert( expr->result ); }
     707
     708        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     709private:
     710        DeletedExpr * clone() const override { return new DeletedExpr{ *this }; }
     711        MUTATE_FRIEND
     712};
     713
     714/// Use of a default argument.
     715/// Internal to resolver.
     716class DefaultArgExpr final : public Expr {
     717public:
     718        ptr<Expr> expr;
     719
     720        DefaultArgExpr( const CodeLocation & loc, const Expr * e )
     721        : Expr( loc, e->result ), expr( e ) { assert( e->result ); }
     722
     723        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     724private:
     725        DefaultArgExpr * clone() const override { return new DefaultArgExpr{ *this }; }
     726        MUTATE_FRIEND
     727};
     728
     729/// C11 _Generic expression
     730class GenericExpr final : public Expr {
     731public:
     732        /// One arm of the _Generic expr
     733        struct Association {
     734                ptr<Type> type;
     735                ptr<Expr> expr;
     736
     737                Association() = default;
     738                // default case
     739                Association( const Expr * e ) : type(), expr( e ) {}
     740                // non-default case
     741                Association( const Type * t, const Expr * e ) : type( t ), expr( e ) {}
     742        };
     743
     744        ptr<Expr> control;
     745        std::vector<Association> associations;
     746
     747        GenericExpr( const CodeLocation & loc, const Expr * ctrl, std::vector<Association> && assns )
     748        : Expr( loc ), control( ctrl ), associations( std::move(assns) ) {}
     749
     750        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     751private:
     752        GenericExpr * clone() const override { return new GenericExpr{ *this }; }
     753        MUTATE_FRIEND
    494754};
    495755
     
    545805inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); }
    546806inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    547 // inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    548 // inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    549 // inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    550 // inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    551 // inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); }
    552 // inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    553 // inline void increment( const class UntypedValofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    554 // inline void decrement( const class UntypedValofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    555 // inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    556 // inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    557 // inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    558 // inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    559 // inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    560 // inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    561 // inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); }
    562 // inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    563 // inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); }
    564 // inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    565 // inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); }
    566 // inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    567 // inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); }
    568 // inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    569 // inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    570 // inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    571 // inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    572 // inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    573 // inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    574 // inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    575 // inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); }
    576 // inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    577 // inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); }
    578 // inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     807inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); }
     808inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     809inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); }
     810inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     811inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); }
     812inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     813inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); }
     814inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     815inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
     816inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     817inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
     818inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     819inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); }
     820inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     821inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); }
     822inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     823inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); }
     824inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     825inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); }
     826inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     827inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); }
     828inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     829inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); }
     830inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     831inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); }
     832inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     833inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); }
     834inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     835inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); }
     836inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    579837}
    580838
  • src/AST/Fwd.hpp

    rf3cc5b6 r9b4f329  
    8585class ConstructorExpr;
    8686class CompoundLiteralExpr;
    87 class UntypedValofExpr;
    8887class RangeExpr;
    8988class UntypedTupleExpr;
     
    267266inline void increment( const class CompoundLiteralExpr *, Node::ref_type );
    268267inline void decrement( const class CompoundLiteralExpr *, Node::ref_type );
    269 inline void increment( const class UntypedValofExpr *, Node::ref_type );
    270 inline void decrement( const class UntypedValofExpr *, Node::ref_type );
    271268inline void increment( const class RangeExpr *, Node::ref_type );
    272269inline void decrement( const class RangeExpr *, Node::ref_type );
  • src/AST/Type.hpp

    rf3cc5b6 r9b4f329  
    2323
    2424#include "CVQualifiers.hpp"
    25 #include "Decl.hpp"
     25#include "Decl.hpp"          // for AggregateDecl subclasses
    2626#include "Fwd.hpp"
    2727#include "Node.hpp"          // for Node, ptr
  • src/AST/porting.md

    rf3cc5b6 r9b4f329  
    6868* prefer `#pragma once` over `#ifdef` guards
    6969* namespaces that cover entire files don't get indented
     70* The general node headers only `#include "Fwd.hpp"` if they can get away with it
     71  * Anything that needs definitions goes in the .cpp file
     72  * `Type.hpp` includes `Decl.hpp` so that it knows the `AggregateDecl` subclasses for `ReferenceToType::aggr()` overloads
    7073
    7174### Documentation ###
     
    166169* un-defaulted constructor parameter determining `&&` or `||`
    167170
     171`CompoundLiteralExpr`
     172* `initializer` => `init`
     173
     174`RangeExpr`
     175* removed `set_low`, `set_high` due to disuse
     176
     177`TupleIndexExpr`
     178* removed `set_tuple`, `set_index` due to disuse
     179
     180`GenericExpr`
     181* `Association::isDefault` removed: `! type` is equivalent
     182
     183`StmtExpr`
     184* `statements` => `stmts`
     185
    168186`Init`
    169187* `bool maybeConstruct` => `enum ConstructFlag { DoConstruct, MaybeConstruct }`
  • src/InitTweak/InitTweak.cc

    rf3cc5b6 r9b4f329  
    55#include <memory>                  // for __shared_ptr
    66
     7#include "AST/Expr.hpp"
     8#include "AST/Stmt.hpp"
    79#include "AST/Type.hpp"
    810#include "Common/PassVisitor.h"
     
    2729#include "Tuples/Tuples.h"         // for Tuples::isTtype
    2830
    29 class UntypedValofExpr;
    30 
    3131namespace InitTweak {
    3232        namespace {
     
    433433                        assert( false );
    434434                }
     435
     436                // template<typename CallExpr>
     437                // const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) {
     438                //      if( pos >= call->args.size() ) {
     439                //              assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.",
     440                //                      pos, toString( call ).c_str() );
     441                //      }
     442                //      for ( const ast::Expr * arg : call->args ) {
     443                //              if ( pos == 0 ) return arg;
     444                //              --pos;
     445                //      }
     446                //      assert( false );
     447                // }
    435448        }
    436449
     
    452465                        assertf( false, "Unexpected expression type passed to getCallArg: %s", toString( callExpr ).c_str() );
    453466                }
     467        }
     468        const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos ) {
     469                assert(!"implemented; needs to build AST/Expr.cpp");
     470                // if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) {
     471                //      return callArg( app, pos );
     472                // } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) {
     473                //      return callArg( untyped, pos );
     474                // } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) {
     475                //      const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids;
     476                //      assertf( ! stmts.empty(), "TupleAssignExpr missing statements." );
     477                //      const ExprStmt * stmt = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back() );
     478                //      const TupleExpr * tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr );
     479                //      assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr.");
     480                //      return getCallArg( tuple->exprs.front(), pos );
     481                // } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) {
     482                //      return getCallArg( ctor->callExpr, pos );
     483                // } else {
     484                //      assertf( false, "Unexpected expression type passed to getCallArg: %s",
     485                //              toString( call ).c_str() );
     486                // }
    454487        }
    455488
     
    516549        const ast::Type* getPointerBase( const ast::Type* t ) {
    517550                assert(!"needs to build Type.cpp before inclusion");
    518                 // if ( const ast::PointerType* p = dynamic_cast< const ast::PointerType* >( t ) ) {
     551                // if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) {
    519552                //      return p->base;
    520                 // } else if ( const ast::ArrayType* a = dynamic_cast< const ast::ArrayType* >( t ) ) {
     553                // } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) {
    521554                //      return a->base;
    522                 // } else if ( const ast::ReferenceType* r = dynamic_cast< const ast::ReferenceType* >( t ) ) {
     555                // } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) {
    523556                //      return r->base;
    524557                // } else return nullptr;
  • src/InitTweak/InitTweak.h

    rf3cc5b6 r9b4f329  
    8181        /// returns the argument to a call expression in position N indexed from 0
    8282        Expression *& getCallArg( Expression * callExpr, unsigned int pos );
     83        const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos );
    8384
    8485        /// returns the base type of a PointerType or ArrayType, else returns NULL
  • src/SynTree/SynTree.h

    rf3cc5b6 r9b4f329  
    9090class ConstructorExpr;
    9191class CompoundLiteralExpr;
    92 class UntypedValofExpr;
    9392class RangeExpr;
    9493class UntypedTupleExpr;
  • src/Tuples/TupleExpansion.cc

    rf3cc5b6 r9b4f329  
    1717#include <cassert>                // for assert
    1818#include <list>                   // for list
    19 
     19#include <vector>
     20
     21#include "AST/CVQualifiers.hpp"
     22#include "AST/Expr.hpp"
     23#include "AST/Node.hpp"
     24#include "AST/Type.hpp"
    2025#include "Common/PassVisitor.h"   // for PassVisitor, WithDeclsToAdd, WithGu...
    2126#include "Common/ScopedMap.h"     // for ScopedMap
     
    314319                return new TupleType( qualifiers, types );
    315320        }
     321        const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ) {
     322                assert(!"implemented; needs Type.cpp in build");
     323                // // produce the TupleType which aggregates the types of the exprs
     324                // std::vector<ast::ptr<ast::Type>> types;
     325                // ast::CV::Qualifiers quals{
     326                //      ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue |
     327                //      ast::CV::Atomic | ast::CV::Mutex };
     328               
     329                // for ( const ast::Expr * expr : exprs ) {
     330                //      assert( expr->result );
     331                //      // if the type of any expr is void, the type of the entire tuple is void
     332                //      if ( expr->result->isVoid() ) return new ast::VoidType{};
     333
     334                //      // qualifiers on the tuple type are the qualifiers that exist on all components
     335                //      quals &= expr->result->qualifiers;
     336
     337                //      types.emplace_back( expr->result );
     338                // }
     339
     340                // if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; }
     341                // return new ast::TupleType{ std::move(types), quals };
     342        }
    316343
    317344        TypeInstType * isTtype( Type * type ) {
  • src/Tuples/Tuples.h

    rf3cc5b6 r9b4f329  
    1919#include <vector>
    2020
     21#include "AST/Fwd.hpp"
     22#include "AST/Node.hpp"
    2123#include "SynTree/Expression.h"
    2224#include "SynTree/Declaration.h"
     
    4244        /// returns VoidType if any of the expressions have Voidtype, otherwise TupleType of the Expression result types
    4345        Type * makeTupleType( const std::list< Expression * > & exprs );
     46        const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs );
    4447
    4548        /// returns a TypeInstType if `type` is a ttype, nullptr otherwise
Note: See TracChangeset for help on using the changeset viewer.