Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Alternative.cc

    rf6f0cca3 r4e7cc5ce  
    2020#include <utility>                       // for move
    2121
    22 #include "Common/GC.h"
    23 #include "Common/PassVisitor.h"
    2422#include "Common/utility.h"              // for maybeClone
    2523#include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<<
    2624#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    2725#include "SynTree/Expression.h"          // for Expression
    28 #include "SynTree/GcTracer.h"
    2926#include "SynTree/Type.h"                // for Type
    3027
    3128namespace ResolvExpr {
    32         Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
     29        Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {}
    3330
    3431        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
     
    3734        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
    3835                : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {}
    39        
    40         Alternative::Alternative( const Alternative& o )
    41                 : cost( o.cost ), cvtCost( o.cvtCost ), expr( maybeClone( o.expr ) ), env( o.env ) {}
    42        
    43         Alternative & Alternative::operator= ( const Alternative& o ) {
    44                 if ( &o == this ) return *this;
    45                 cost = o.cost;
    46                 cvtCost = o.cvtCost;
    47                 expr = maybeClone( o.expr );
    48                 env = o.env;
     36
     37        Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) {
     38        }
     39
     40        Alternative &Alternative::operator=( const Alternative &other ) {
     41                if ( &other == this ) return *this;
     42                delete expr;
     43                cost = other.cost;
     44                cvtCost = other.cvtCost;
     45                expr = maybeClone( other.expr );
     46                env = other.env;
    4947                return *this;
     48        }
     49
     50        Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( std::move( other.env ) ) {
     51                other.expr = nullptr;
     52        }
     53
     54        Alternative & Alternative::operator=( Alternative && other ) {
     55                if ( &other == this )  return *this;
     56                delete expr;
     57                cost = other.cost;
     58                cvtCost = other.cvtCost;
     59                expr = other.expr;
     60                env = std::move( other.env );
     61                other.expr = nullptr;
     62                return *this;
     63        }
     64
     65        Alternative::~Alternative() {
     66                delete expr;
    5067        }
    5168
     
    7996        }
    8097
    81         const GC& operator<< ( const GC& gc, const Alternative& alt ) {
    82                 PassVisitor<GcTracer> tracer{ gc };
    83                 maybeAccept( alt.expr, tracer );
    84                 tracer << alt.env;
    85                 return gc;
    86         }
    87 
    8898} // namespace ResolvExpr
    8999
Note: See TracChangeset for help on using the changeset viewer.