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