source: src/ResolvExpr/Alternative.cc @ f229fc2

new-envwith_gc
Last change on this file since f229fc2 was f229fc2, checked in by Aaron Moss <a3moss@…>, 6 years ago

Modify resolver to use young-generation collection per-top-level expression

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[a32b204]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[906e24d]7// Alternative.cc --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sat May 16 23:44:23 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat May 16 23:54:23 2015
13// Update Count     : 2
[906e24d]14//
[a32b204]15
[51b7345]16#include "Alternative.h"
[ea6332d]17
18#include <ostream>                       // for operator<<, ostream, basic_o...
19#include <string>                        // for operator<<, char_traits, string
[bd4f2e9]20#include <utility>                       // for move
[ea6332d]21
[f229fc2]22#include "Common/GC.h"
23#include "Common/PassVisitor.h"
[ea6332d]24#include "Common/utility.h"              // for maybeClone
25#include "ResolvExpr/Cost.h"             // for Cost, Cost::zero, operator<<
26#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
27#include "SynTree/Expression.h"          // for Expression
[f229fc2]28#include "SynTree/GcTracer.h"
[ea6332d]29#include "SynTree/Type.h"                // for Type
[51b7345]30
31namespace ResolvExpr {
[3c13c03]32        Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
[a32b204]33
34        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
35                : cost( cost ), cvtCost( Cost::zero ), expr( expr ), env( env ) {}
36
37        Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost )
38                : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {}
39
[50377a4]40        void Alternative::print( std::ostream &os, Indenter indent ) const {
41                os << "Cost " << cost << ": ";
[a32b204]42                if ( expr ) {
[50377a4]43                        expr->print( os, indent+1 );
44                        os << std::endl << indent << "(types:" << std::endl;
45                        os << indent+1;
46                        expr->result->print( os, indent+1 );
47                        os << std::endl << indent << ")" << std::endl;
[a32b204]48                } else {
49                        os << "Null expression!" << std::endl;
50                } // if
[50377a4]51                os << indent << "Environment: ";
52                env.print( os, indent+1 );
[a32b204]53                os << std::endl;
[d9a0e76]54        }
[bd4f2e9]55
56        void splice( AltList& dst, AltList& src ) {
57                dst.reserve( dst.size() + src.size() );
58                for ( Alternative& alt : src ) {
59                        dst.push_back( std::move(alt) );
60                }
61                src.clear();
62        }
63
64        void spliceBegin( AltList& dst, AltList& src ) {
65                splice( src, dst );
66                dst.swap( src );
67        }
68
[f229fc2]69        const GC& operator<< ( const GC& gc, const Alternative& alt ) {
70                PassVisitor<GcTracer> tracer{ gc };
71                maybeAccept( alt.expr, tracer );
72                tracer << alt.env;
73                return gc;
74        }
75
[51b7345]76} // namespace ResolvExpr
[a32b204]77
78// Local Variables: //
79// tab-width: 4 //
80// mode: c++ //
81// compile-command: "make install" //
82// End: //
Note: See TracBrowser for help on using the repository browser.