| 1 | #include <cassert> | 
|---|
| 2 |  | 
|---|
| 3 | #include "Expression.h" | 
|---|
| 4 | #include "Declaration.h" | 
|---|
| 5 | #include "Type.h" | 
|---|
| 6 | #include "TypeSubstitution.h" | 
|---|
| 7 | #include "utility.h" | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 | ParamEntry::ParamEntry( const ParamEntry &other ) | 
|---|
| 11 | : decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) | 
|---|
| 12 | { | 
|---|
| 13 | } | 
|---|
| 14 |  | 
|---|
| 15 | ParamEntry & | 
|---|
| 16 | ParamEntry::operator=( const ParamEntry &other ) | 
|---|
| 17 | { | 
|---|
| 18 | if( &other == this ) return *this; | 
|---|
| 19 | decl = other.decl; | 
|---|
| 20 | actualType = maybeClone( other.actualType ); | 
|---|
| 21 | formalType = maybeClone( other.formalType ); | 
|---|
| 22 | expr = maybeClone( other.expr ); | 
|---|
| 23 | return *this; | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | ParamEntry::~ParamEntry() | 
|---|
| 27 | { | 
|---|
| 28 | delete actualType; | 
|---|
| 29 | delete formalType; | 
|---|
| 30 | delete expr; | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 | ApplicationExpr::ApplicationExpr( Expression *funcExpr ) | 
|---|
| 34 | : function( funcExpr ) | 
|---|
| 35 | { | 
|---|
| 36 | PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() ); | 
|---|
| 37 | assert( pointer ); | 
|---|
| 38 | FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); | 
|---|
| 39 | assert( function ); | 
|---|
| 40 |  | 
|---|
| 41 | for( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { | 
|---|
| 42 | get_results().push_back( (*i)->get_type()->clone() ); | 
|---|
| 43 | } | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) | 
|---|
| 47 | : Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) | 
|---|
| 48 | { | 
|---|
| 49 | cloneAll( other.args, args ); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | ApplicationExpr::~ApplicationExpr() | 
|---|
| 53 | { | 
|---|
| 54 | delete function; | 
|---|
| 55 | deleteAll( args ); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | void | 
|---|
| 59 | ApplicationExpr::print( std::ostream &os, int indent ) const | 
|---|
| 60 | { | 
|---|
| 61 | os << std::string( indent, ' ' ) << "Application of" << std::endl; | 
|---|
| 62 | function->print( os, indent+2 ); | 
|---|
| 63 | if( !args.empty() ) { | 
|---|
| 64 | os << std::string( indent, ' ' ) << "to arguments" << std::endl; | 
|---|
| 65 | printAll( args, os, indent+2 ); | 
|---|
| 66 | } | 
|---|
| 67 | if( !inferParams.empty() ) { | 
|---|
| 68 | os << std::string(indent, ' ') << "with inferred parameters:" << std::endl; | 
|---|
| 69 | for( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { | 
|---|
| 70 | os << std::string(indent+2, ' '); | 
|---|
| 71 | Declaration::declFromId( i->second.decl )->printShort( os, indent+2 ); | 
|---|
| 72 | os << std::endl; | 
|---|
| 73 | } | 
|---|
| 74 | } | 
|---|
| 75 | Expression::print( os, indent ); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|