| [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 | 
 | 
|---|
| [51b73452] | 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"
 | 
|---|
| [906e24d] | 23 | #include "ResolvExpr/typeops.h"
 | 
|---|
| [51b73452] | 24 | 
 | 
|---|
| [0dd3a2f] | 25 | ParamEntry::ParamEntry( const ParamEntry &other ) :
 | 
|---|
| [6c3a988f] | 26 |                 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) {
 | 
|---|
| [51b73452] | 27 | }
 | 
|---|
 | 28 | 
 | 
|---|
| [0dd3a2f] | 29 | ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
 | 
|---|
 | 30 |         if ( &other == this ) return *this;
 | 
|---|
 | 31 |         decl = other.decl;
 | 
|---|
| [2c57025] | 32 |         // xxx - this looks like a memory leak
 | 
|---|
| [0dd3a2f] | 33 |         actualType = maybeClone( other.actualType );
 | 
|---|
 | 34 |         formalType = maybeClone( other.formalType );
 | 
|---|
 | 35 |         expr = maybeClone( other.expr );
 | 
|---|
| [6c3a988f] | 36 |         *inferParams = *other.inferParams;
 | 
|---|
| [0dd3a2f] | 37 |         return *this;
 | 
|---|
| [51b73452] | 38 | }
 | 
|---|
 | 39 | 
 | 
|---|
| [0dd3a2f] | 40 | ParamEntry::~ParamEntry() {
 | 
|---|
 | 41 |         delete actualType;
 | 
|---|
 | 42 |         delete formalType;
 | 
|---|
 | 43 |         delete expr;
 | 
|---|
| [51b73452] | 44 | }
 | 
|---|
 | 45 | 
 | 
|---|
| [0dd3a2f] | 46 | ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) {
 | 
|---|
| [906e24d] | 47 |         PointerType *pointer = safe_dynamic_cast< PointerType* >( funcExpr->get_result() );
 | 
|---|
 | 48 |         FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 |         set_result( ResolvExpr::extractResultType( function ) );
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 |         assert( has_result() );
 | 
|---|
| [51b73452] | 53 | }
 | 
|---|
 | 54 | 
 | 
|---|
| [0dd3a2f] | 55 | ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
 | 
|---|
 | 56 |                 Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) {
 | 
|---|
 | 57 |         cloneAll( other.args, args );
 | 
|---|
| [51b73452] | 58 | }
 | 
|---|
 | 59 | 
 | 
|---|
| [0dd3a2f] | 60 | ApplicationExpr::~ApplicationExpr() {
 | 
|---|
 | 61 |         delete function;
 | 
|---|
 | 62 |         deleteAll( args );
 | 
|---|
| [51b73452] | 63 | }
 | 
|---|
 | 64 | 
 | 
|---|
| [6c3a988f] | 65 | void printInferParams( const InferredParams & inferParams, std::ostream &os, int indent, int level ) {
 | 
|---|
| [0dd3a2f] | 66 |         if ( ! inferParams.empty() ) {
 | 
|---|
| [6c3a988f] | 67 |                 os << std::string(indent, ' ') << "with inferred parameters " << level << ":" << std::endl;
 | 
|---|
| [0dd3a2f] | 68 |                 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
 | 
|---|
 | 69 |                         os << std::string(indent+2, ' ');
 | 
|---|
 | 70 |                         Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
 | 
|---|
 | 71 |                         os << std::endl;
 | 
|---|
| [6c3a988f] | 72 |                         printInferParams( *i->second.inferParams, os, indent+2, level+1 );
 | 
|---|
| [0dd3a2f] | 73 |                 } // for
 | 
|---|
 | 74 |         } // if
 | 
|---|
| [6c3a988f] | 75 | }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 | void ApplicationExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
 | 78 |         os << "Application of" << std::endl << std::string(indent+2, ' ');
 | 
|---|
 | 79 |         function->print( os, indent+2 );
 | 
|---|
 | 80 |         if ( ! args.empty() ) {
 | 
|---|
 | 81 |                 os << std::string( indent, ' ' ) << "to arguments" << std::endl;
 | 
|---|
 | 82 |                 printAll( args, os, indent+2 );
 | 
|---|
 | 83 |         } // if
 | 
|---|
 | 84 |         printInferParams( inferParams, os, indent+2, 0 );
 | 
|---|
| [0dd3a2f] | 85 |         Expression::print( os, indent );
 | 
|---|
| [51b73452] | 86 | }
 | 
|---|
 | 87 | 
 | 
|---|
| [0dd3a2f] | 88 | // Local Variables: //
 | 
|---|
 | 89 | // tab-width: 4 //
 | 
|---|
 | 90 | // mode: c++ //
 | 
|---|
 | 91 | // compile-command: "make install" //
 | 
|---|
 | 92 | // End: //
 | 
|---|