| 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 <ostream>               // for operator<<, ostream, basic_ostream | 
|---|
| 20 | #include <string>                // for operator<<, string, char_traits | 
|---|
| 21 | #include <utility>               // for pair | 
|---|
| 22 |  | 
|---|
| 23 | #include "Common/utility.h"      // for maybeClone, cloneAll, deleteAll, pri... | 
|---|
| 24 | #include "Declaration.h"         // for Declaration | 
|---|
| 25 | #include "Expression.h"          // for ParamEntry, ApplicationExpr, Expression | 
|---|
| 26 | #include "ResolvExpr/typeops.h"  // for extractResultType | 
|---|
| 27 | #include "Type.h"                // for Type, PointerType, FunctionType | 
|---|
| 28 |  | 
|---|
| 29 | ParamEntry::ParamEntry( const ParamEntry &other ) : | 
|---|
| 30 | decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) { | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 | ParamEntry &ParamEntry::operator=( const ParamEntry &other ) { | 
|---|
| 34 | if ( &other == this ) return *this; | 
|---|
| 35 | decl = other.decl; | 
|---|
| 36 | // xxx - this looks like a memory leak | 
|---|
| 37 | actualType = maybeClone( other.actualType ); | 
|---|
| 38 | formalType = maybeClone( other.formalType ); | 
|---|
| 39 | expr = maybeClone( other.expr ); | 
|---|
| 40 | *inferParams = *other.inferParams; | 
|---|
| 41 | return *this; | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | ParamEntry::ParamEntry( ParamEntry && other ) : | 
|---|
| 45 | decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ), inferParams( std::move( other.inferParams ) ) { | 
|---|
| 46 | other.actualType = nullptr; | 
|---|
| 47 | other.formalType = nullptr; | 
|---|
| 48 | other.expr = nullptr; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | ParamEntry & ParamEntry::operator=( ParamEntry && other ) { | 
|---|
| 52 | if ( &other == this ) return *this; | 
|---|
| 53 | decl = other.decl; | 
|---|
| 54 | actualType = other.actualType; | 
|---|
| 55 | formalType = other.formalType; | 
|---|
| 56 | expr = other.expr; | 
|---|
| 57 | other.actualType = nullptr; | 
|---|
| 58 | other.formalType = nullptr; | 
|---|
| 59 | other.expr = nullptr; | 
|---|
| 60 | inferParams = std::move( other.inferParams ); | 
|---|
| 61 | return *this; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | ApplicationExpr::ApplicationExpr( Expression *funcExpr, const std::list<Expression *> & args ) : function( funcExpr ), args( args ) { | 
|---|
| 65 | PointerType *pointer = strict_dynamic_cast< PointerType* >( funcExpr->get_result() ); | 
|---|
| 66 | FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() ); | 
|---|
| 67 |  | 
|---|
| 68 | set_result( ResolvExpr::extractResultType( function ) ); | 
|---|
| 69 |  | 
|---|
| 70 | assert( result ); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) : | 
|---|
| 74 | Expression( other ), function( maybeClone( other.function ) ) { | 
|---|
| 75 | cloneAll( other.args, args ); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | void ApplicationExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
| 79 | os << "Application of" << std::endl << indent+1; | 
|---|
| 80 | function->print( os, indent+1 ); | 
|---|
| 81 | os << std::endl; | 
|---|
| 82 | if ( ! args.empty() ) { | 
|---|
| 83 | os << indent << "... to arguments" << std::endl; | 
|---|
| 84 | printAll( args, os, indent+1 ); | 
|---|
| 85 | } // if | 
|---|
| 86 | Expression::print( os, indent ); | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | // Local Variables: // | 
|---|
| 90 | // tab-width: 4 // | 
|---|
| 91 | // mode: c++ // | 
|---|
| 92 | // compile-command: "make install" // | 
|---|
| 93 | // End: // | 
|---|