Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Alternative.cc

    r234b1cb r4e7cc5ce  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sat May 16 23:44:23 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu Oct 11 10:55:00 2018
    13 // Update Count     : 3
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat May 16 23:54:23 2015
     13// Update Count     : 2
    1414//
    1515
     
    2020#include <utility>                       // for move
    2121
    22 #include "Common/utility.h"              // for cloneAll
     22#include "Common/utility.h"              // for maybeClone
    2323#include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<<
    2424#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
     
    2727
    2828namespace ResolvExpr {
    29         Alternative::Alternative()
    30         : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ), env(), openVars(), need() {}
     29        Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {}
    3130
    32         Alternative::Alternative( Expression *expr, const TypeEnvironment &env )
    33         : cost( Cost::zero ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars(), need() {}
    34        
    35         Alternative::Alternative( const Alternative &o, Expression *expr, const Cost &cost )
    36         : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( o.env ), openVars( o.openVars ),
    37           need() { cloneAll( o.need, need ); }
     31        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
     32                : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) {}
    3833
    39         Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
    40                 const OpenVarSet& openVars, const AssertionList& oneed, const Cost& cost )
    41         : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars( openVars ),
    42           need() { cloneAll( oneed, need ); }
     34        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
     35                : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {}
    4336
    44         Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
    45                 const OpenVarSet& openVars, const AssertionList& oneed, const Cost& cost,
    46                 const Cost &cvtCost )
    47         : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ), openVars( openVars ),
    48           need() { cloneAll( oneed, need ); }
    49        
    50         Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
    51                 const OpenVarSet &openVars, const AssertionSet &oneed, const Cost &cost)
    52         : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ), openVars( openVars ),
    53           need() { cloneAll( oneed, need ); }
    54        
    55         Alternative::Alternative( Expression *expr, const TypeEnvironment &env,
    56                 const OpenVarSet &openVars, const AssertionSet &oneed, const Cost &cost,
    57                 const Cost& cvtCost )
    58         : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ), openVars( openVars ),
    59           need() { cloneAll( oneed, need ); }
    60        
    61         Alternative::Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars,
    62                 AssertionSet &&needSet, const Cost &cost )
    63         : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( std::move(env) ),
    64           openVars( std::move(openVars) ), need( needSet.begin(), needSet.end() ) {}
    65        
    66         Alternative::Alternative( Expression *expr, TypeEnvironment &&env, OpenVarSet &&openVars,
    67                 AssertionSet &&needSet, const Cost &cost, const Cost &cvtCost )
    68         : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( std::move(env) ),
    69           openVars( std::move(openVars) ), need( needSet.begin(), needSet.end() ) {}
    70 
    71         Alternative::Alternative( const Alternative &other )
    72         : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ),
    73           env( other.env ), openVars( other.openVars ), need() { cloneAll( other.need, need ); }
     37        Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) {
     38        }
    7439
    7540        Alternative &Alternative::operator=( const Alternative &other ) {
     
    8045                expr = maybeClone( other.expr );
    8146                env = other.env;
    82                 openVars = other.openVars;
    83                 need.clear();
    84                 cloneAll( other.need, need );
    8547                return *this;
    8648        }
    8749
    88         Alternative::Alternative( Alternative && other )
    89         : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ),
    90           env( std::move( other.env ) ), openVars( std::move( other.openVars ) ),
    91           need( std::move( other.need ) ) { other.expr = nullptr; }
     50        Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( std::move( other.env ) ) {
     51                other.expr = nullptr;
     52        }
    9253
    9354        Alternative & Alternative::operator=( Alternative && other ) {
     
    9859                expr = other.expr;
    9960                env = std::move( other.env );
    100                 openVars = std::move( other.openVars );
    101                 need = std::move( other.need );
    10261                other.expr = nullptr;
    10362                return *this;
     
    10564
    10665        Alternative::~Alternative() {
    107                 for ( AssertionItem& n : need ) { delete n.decl; }
    10866                delete expr;
    10967        }
     
    12078                        os << "Null expression!" << std::endl;
    12179                } // if
    122                 os << indent << "Environment:";
     80                os << indent << "Environment: ";
    12381                env.print( os, indent+1 );
    12482                os << std::endl;
     83        }
     84
     85        void splice( AltList& dst, AltList& src ) {
     86                dst.reserve( dst.size() + src.size() );
     87                for ( Alternative& alt : src ) {
     88                        dst.push_back( std::move(alt) );
     89                }
     90                src.clear();
     91        }
     92
     93        void spliceBegin( AltList& dst, AltList& src ) {
     94                splice( src, dst );
     95                dst.swap( src );
    12596        }
    12697
Note: See TracChangeset for help on using the changeset viewer.