Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.hpp

    r9b4f329 r20a5977  
    2828
    2929// Must be included in *all* AST classes; should be #undef'd at the end of the file
    30 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node);
     30#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
     31
     32class ConverterOldToNew;
    3133
    3234namespace ast {
     
    106108                        case Params: assert(!"Cannot return to resnSlots from Params");
    107109                        }
     110                        return *((ResnSlots*)nullptr);
     111                }
     112
     113                const ResnSlots& resnSlotsConst() const {
     114                        if (mode == Slots) {
     115                                return data.resnSlots;
     116                        }
     117                        assert(!"Mode was not already resnSlots");
     118                        return *((ResnSlots*)nullptr);
    108119                }
    109120
     
    114125                        case Params: return data.inferParams;
    115126                        }
     127                        return *((InferredParams*)nullptr);
     128                }
     129
     130                const InferredParams& inferParamsConst() const {
     131                        if (mode == Params) {
     132                                return data.inferParams;
     133                        }
     134                        assert(!"Mode was not already Params");
     135                        return *((InferredParams*)nullptr);
    116136                }
    117137        };
     
    133153};
    134154
    135 /// The application of a function to a set of parameters. 
     155/// The application of a function to a set of parameters.
    136156/// Post-resolver form of `UntypedExpr`
    137157class ApplicationExpr final : public Expr {
     
    218238        GeneratedFlag isGenerated;
    219239
    220         CastExpr( const CodeLocation & loc, const Expr * a, const Type * to, 
     240        CastExpr( const CodeLocation & loc, const Expr * a, const Type * to,
    221241                GeneratedFlag g = GeneratedCast ) : Expr( loc, to ), arg( a ), isGenerated( g ) {}
    222242        /// Cast-to-void
     
    311331                unsigned long long ival;
    312332                double dval;
    313                
     333
    314334                Val( unsigned long long i ) : ival( i ) {}
    315335                Val( double d ) : dval( d ) {}
     
    317337public:
    318338        std::string rep;
    319 
    320         ConstantExpr(
    321                 const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v )
    322         : Expr( loc, ty ), val( v ), rep( r ) {}
     339        enum Kind { Integer, FloatingPoint, String } kind;
     340
     341        ConstantExpr(
     342                const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v,
     343                Kind k = Integer )
     344        : Expr( loc, ty ), val( v ), rep( r ), kind( k ) {}
    323345        ConstantExpr( const CodeLocation & loc, const Type * ty, const std::string & r, double v )
    324         : Expr( loc, ty ), val( v ), rep( r ) {}
    325        
     346        : Expr( loc, ty ), val( v ), rep( r ), kind( FloatingPoint ) {}
     347
    326348        /// Gets the value of this constant as an integer
    327349        long long int intValue() const;
     
    464486        ptr<Expr> arg2;
    465487
    466         CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 ) 
     488        CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 )
    467489        : Expr( loc ), arg1( a1 ), arg2( a2 ) {}
    468490
     
    503525};
    504526
    505 /// The application of a function to a set of parameters, along with a set of copy constructor 
     527/// The application of a function to a set of parameters, along with a set of copy constructor
    506528/// calls, one for each argument
    507529class ImplicitCopyCtorExpr final : public Expr {
     
    510532        std::vector<ptr<ObjectDecl>> tempDecls;
    511533        std::vector<ptr<ObjectDecl>> returnDecls;
    512         std::vector<ptr<ObjectDecl>> dtors;
     534        std::vector<ptr<Expr>> dtors;
    513535
    514536        ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call )
     
    603625};
    604626
    605 /// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression. 
    606 /// multiple-assignment: both sides of the assignment have tuple type, 
     627/// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression.
     628/// multiple-assignment: both sides of the assignment have tuple type,
    607629///     e.g. `[a, b, c] = [d, e, f];`
    608630/// mass-assignment: left-hand side has tuple type and right-hand side does not:
     
    612634        ptr<StmtExpr> stmtExpr;
    613635
    614         TupleAssignExpr( 
    615                 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 
     636        TupleAssignExpr(
     637                const CodeLocation & loc, std::vector<ptr<Expr>> && assigns,
    616638                std::vector<ptr<ObjectDecl>> && tempDecls );
    617        
    618         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     639
     640        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     641
     642        friend class ::ConverterOldToNew;
     643
    619644private:
    620645        TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; }
     646    TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s );
     647
    621648        MUTATE_FRIEND
    622649};
     
    754781};
    755782
    756 //=================================================================================================
    757 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    758 /// remove only if there is a better solution
    759 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    760 /// forward declarations
    761 inline void increment( const class Expr * node, Node::ref_type ref ) { node->increment(ref); }
    762 inline void decrement( const class Expr * node, Node::ref_type ref ) { node->decrement(ref); }
    763 inline void increment( const class ApplicationExpr * node, Node::ref_type ref ) { node->increment(ref); }
    764 inline void decrement( const class ApplicationExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    765 inline void increment( const class UntypedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    766 inline void decrement( const class UntypedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    767 inline void increment( const class NameExpr * node, Node::ref_type ref ) { node->increment(ref); }
    768 inline void decrement( const class NameExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    769 inline void increment( const class AddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    770 inline void decrement( const class AddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    771 inline void increment( const class LabelAddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    772 inline void decrement( const class LabelAddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    773 inline void increment( const class CastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    774 inline void decrement( const class CastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    775 inline void increment( const class KeywordCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    776 inline void decrement( const class KeywordCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    777 inline void increment( const class VirtualCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    778 inline void decrement( const class VirtualCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    779 inline void increment( const class MemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    780 inline void decrement( const class MemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    781 inline void increment( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    782 inline void decrement( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    783 inline void increment( const class VariableExpr * node, Node::ref_type ref ) { node->increment(ref); }
    784 inline void decrement( const class VariableExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    785 inline void increment( const class ConstantExpr * node, Node::ref_type ref ) { node->increment(ref); }
    786 inline void decrement( const class ConstantExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    787 inline void increment( const class SizeofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    788 inline void decrement( const class SizeofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    789 inline void increment( const class AlignofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    790 inline void decrement( const class AlignofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    791 inline void increment( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    792 inline void decrement( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    793 inline void increment( const class OffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    794 inline void decrement( const class OffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    795 inline void increment( const class OffsetPackExpr * node, Node::ref_type ref ) { node->increment(ref); }
    796 inline void decrement( const class OffsetPackExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    797 inline void increment( const class LogicalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    798 inline void decrement( const class LogicalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    799 inline void increment( const class ConditionalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    800 inline void decrement( const class ConditionalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    801 inline void increment( const class CommaExpr * node, Node::ref_type ref ) { node->increment(ref); }
    802 inline void decrement( const class CommaExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    803 inline void increment( const class TypeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    804 inline void decrement( const class TypeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    805 inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); }
    806 inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    807 inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    808 inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    809 inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    810 inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    811 inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); }
    812 inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    813 inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    814 inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    815 inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    816 inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    817 inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    818 inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    819 inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); }
    820 inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    821 inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); }
    822 inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    823 inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); }
    824 inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    825 inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); }
    826 inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    827 inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    828 inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    829 inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    830 inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    831 inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    832 inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    833 inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); }
    834 inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    835 inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); }
    836 inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     783
    837784}
    838785
Note: See TracChangeset for help on using the changeset viewer.