source: src/SynTree/ApplicationExpr.cc @ 2fd9f24

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 2fd9f24 was 4d6d62e, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Add move operators for ParamEntry?

  • Property mode set to 100644
File size: 3.6 KB
Line 
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//
7// ApplicationExpr.cc.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Tue Apr 26 12:41:06 2016
13// Update Count     : 4
14//
15
16#include <cassert>               // for strict_dynamic_cast, assert
17#include <list>                  // for list
18#include <map>                   // for _Rb_tree_const_iterator, map, map<>:...
19#include <memory>                // for unique_ptr
20#include <ostream>               // for operator<<, ostream, basic_ostream
21#include <string>                // for operator<<, string, char_traits
22#include <utility>               // for pair
23
24#include "Common/utility.h"      // for maybeClone, cloneAll, deleteAll, pri...
25#include "Declaration.h"         // for Declaration
26#include "Expression.h"          // for ParamEntry, ApplicationExpr, Expression
27#include "ResolvExpr/typeops.h"  // for extractResultType
28#include "Type.h"                // for Type, PointerType, FunctionType
29
30ParamEntry::ParamEntry( const ParamEntry &other ) :
31                decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) {
32}
33
34ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
35        if ( &other == this ) return *this;
36        decl = other.decl;
37        // xxx - this looks like a memory leak
38        actualType = maybeClone( other.actualType );
39        formalType = maybeClone( other.formalType );
40        expr = maybeClone( other.expr );
41        *inferParams = *other.inferParams;
42        return *this;
43}
44
45ParamEntry::~ParamEntry() {
46        delete actualType;
47        delete formalType;
48        delete expr;
49}
50
51ParamEntry::ParamEntry( ParamEntry && other ) :
52                decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ), inferParams( std::move( other.inferParams ) ) {
53        other.actualType = nullptr;
54        other.formalType = nullptr;
55        other.expr = nullptr;
56}
57
58ParamEntry & ParamEntry::operator=( ParamEntry && other ) {
59        if ( &other == this ) return *this;
60        delete actualType;
61        delete formalType;
62        delete expr;
63        decl = other.decl;
64        actualType = other.actualType;
65        formalType = other.formalType;
66        expr = other.expr;
67        other.actualType = nullptr;
68        other.formalType = nullptr;
69        other.expr = nullptr;
70        inferParams = std::move( other.inferParams );
71        return *this;
72}
73
74ApplicationExpr::ApplicationExpr( Expression *funcExpr, const std::list<Expression *> & args ) : function( funcExpr ), args( args ) {
75        PointerType *pointer = strict_dynamic_cast< PointerType* >( funcExpr->get_result() );
76        FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() );
77
78        set_result( ResolvExpr::extractResultType( function ) );
79
80        assert( result );
81}
82
83ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
84                Expression( other ), function( maybeClone( other.function ) ) {
85        cloneAll( other.args, args );
86}
87
88ApplicationExpr::~ApplicationExpr() {
89        delete function;
90        deleteAll( args );
91}
92
93void ApplicationExpr::print( std::ostream &os, Indenter indent ) const {
94        os << "Application of" << std::endl << indent+1;
95        function->print( os, indent+1 );
96        os << std::endl;
97        if ( ! args.empty() ) {
98                os << indent << "... to arguments" << std::endl;
99                printAll( args, os, indent+1 );
100        } // if
101        Expression::print( os, indent );
102}
103
104// Local Variables: //
105// tab-width: 4 //
106// mode: c++ //
107// compile-command: "make install" //
108// End: //
Note: See TracBrowser for help on using the repository browser.