| 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 : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Mon May 18 07:54:17 2015
|
|---|
| 13 | // Update Count : 4
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include <cassert>
|
|---|
| 17 |
|
|---|
| 18 | #include "Expression.h"
|
|---|
| 19 | #include "Declaration.h"
|
|---|
| 20 | #include "Type.h"
|
|---|
| 21 | #include "TypeSubstitution.h"
|
|---|
| 22 | #include "Common/utility.h"
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | ParamEntry::ParamEntry( const ParamEntry &other ) :
|
|---|
| 26 | decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) {
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 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;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | ParamEntry::~ParamEntry() {
|
|---|
| 39 | delete actualType;
|
|---|
| 40 | delete formalType;
|
|---|
| 41 | delete expr;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 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 );
|
|---|
| 49 |
|
|---|
| 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
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
|
|---|
| 56 | Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) {
|
|---|
| 57 | cloneAll( other.args, args );
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | ApplicationExpr::~ApplicationExpr() {
|
|---|
| 61 | delete function;
|
|---|
| 62 | deleteAll( args );
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | void ApplicationExpr::print( std::ostream &os, int indent ) const {
|
|---|
| 66 | os << std::string( indent, ' ' ) << "Application of" << std::endl;
|
|---|
| 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 );
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | // Local Variables: //
|
|---|
| 84 | // tab-width: 4 //
|
|---|
| 85 | // mode: c++ //
|
|---|
| 86 | // compile-command: "make install" //
|
|---|
| 87 | // End: //
|
|---|