[0dd3a2f] | 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 | // |
---|
[89231bc] | 7 | // ApplicationExpr.cc.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[89231bc] | 11 | // Last Modified By : Rob Schluntz |
---|
| 12 | // Last Modified On : Tue Apr 26 12:41:06 2016 |
---|
[0dd3a2f] | 13 | // Update Count : 4 |
---|
| 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include <cassert> |
---|
| 17 | |
---|
| 18 | #include "Expression.h" |
---|
| 19 | #include "Declaration.h" |
---|
| 20 | #include "Type.h" |
---|
| 21 | #include "TypeSubstitution.h" |
---|
[d3b7937] | 22 | #include "Common/utility.h" |
---|
[51b7345] | 23 | |
---|
| 24 | |
---|
[0dd3a2f] | 25 | ParamEntry::ParamEntry( const ParamEntry &other ) : |
---|
| 26 | decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) { |
---|
[51b7345] | 27 | } |
---|
| 28 | |
---|
[0dd3a2f] | 29 | ParamEntry &ParamEntry::operator=( const ParamEntry &other ) { |
---|
| 30 | if ( &other == this ) return *this; |
---|
| 31 | decl = other.decl; |
---|
| 32 | actualType = maybeClone( other.actualType ); |
---|
| 33 | formalType = maybeClone( other.formalType ); |
---|
| 34 | expr = maybeClone( other.expr ); |
---|
| 35 | return *this; |
---|
[51b7345] | 36 | } |
---|
| 37 | |
---|
[0dd3a2f] | 38 | ParamEntry::~ParamEntry() { |
---|
| 39 | delete actualType; |
---|
| 40 | delete formalType; |
---|
| 41 | delete expr; |
---|
[51b7345] | 42 | } |
---|
| 43 | |
---|
[0dd3a2f] | 44 | ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) { |
---|
| 45 | PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() ); |
---|
| 46 | assert( pointer ); |
---|
| 47 | FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); |
---|
| 48 | assert( function ); |
---|
[89231bc] | 49 | |
---|
[0dd3a2f] | 50 | for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { |
---|
| 51 | get_results().push_back( (*i)->get_type()->clone() ); |
---|
| 52 | } // for |
---|
[51b7345] | 53 | } |
---|
| 54 | |
---|
[0dd3a2f] | 55 | ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) : |
---|
| 56 | Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) { |
---|
| 57 | cloneAll( other.args, args ); |
---|
[51b7345] | 58 | } |
---|
| 59 | |
---|
[0dd3a2f] | 60 | ApplicationExpr::~ApplicationExpr() { |
---|
| 61 | delete function; |
---|
| 62 | deleteAll( args ); |
---|
[51b7345] | 63 | } |
---|
| 64 | |
---|
[0dd3a2f] | 65 | void ApplicationExpr::print( std::ostream &os, int indent ) const { |
---|
[9554d9b] | 66 | os << "Application of" << std::endl << std::string(indent+2, ' '); |
---|
[0dd3a2f] | 67 | function->print( os, indent+2 ); |
---|
| 68 | if ( ! args.empty() ) { |
---|
| 69 | os << std::string( indent, ' ' ) << "to arguments" << std::endl; |
---|
| 70 | printAll( args, os, indent+2 ); |
---|
| 71 | } // if |
---|
| 72 | if ( ! inferParams.empty() ) { |
---|
| 73 | os << std::string(indent, ' ') << "with inferred parameters:" << std::endl; |
---|
| 74 | for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { |
---|
| 75 | os << std::string(indent+2, ' '); |
---|
| 76 | Declaration::declFromId( i->second.decl )->printShort( os, indent+2 ); |
---|
| 77 | os << std::endl; |
---|
| 78 | } // for |
---|
| 79 | } // if |
---|
| 80 | Expression::print( os, indent ); |
---|
[51b7345] | 81 | } |
---|
| 82 | |
---|
[0dd3a2f] | 83 | // Local Variables: // |
---|
| 84 | // tab-width: 4 // |
---|
| 85 | // mode: c++ // |
---|
| 86 | // compile-command: "make install" // |
---|
| 87 | // End: // |
---|