| 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 : Rob Schluntz
 | 
|---|
| 12 | // Last Modified On : Tue Apr 26 12:41:06 2016
 | 
|---|
| 13 | // Update Count     : 4
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <cassert>               // for strict_dynamic_cast, assert
 | 
|---|
| 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
 | 
|---|
| 23 | 
 | 
|---|
| 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
 | 
|---|
| 29 | 
 | 
|---|
| 30 | ParamEntry::ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr )
 | 
|---|
| 31 |                 : decl( decl ), declptr( declptr ), actualType( actualType ), formalType( formalType ), expr( expr ) {
 | 
|---|
| 32 |         }
 | 
|---|
| 33 | 
 | 
|---|
| 34 | ParamEntry::ParamEntry( const ParamEntry &other ) :
 | 
|---|
| 35 |                 decl( other.decl ), declptr( maybeClone( other.declptr ) ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) {
 | 
|---|
| 36 | }
 | 
|---|
| 37 | 
 | 
|---|
| 38 | ParamEntry::~ParamEntry() {
 | 
|---|
| 39 |         delete declptr;
 | 
|---|
| 40 |         delete actualType;
 | 
|---|
| 41 |         delete formalType;
 | 
|---|
| 42 |         delete expr;
 | 
|---|
| 43 | }
 | 
|---|
| 44 | 
 | 
|---|
| 45 | ParamEntry::ParamEntry( ParamEntry && other ) :
 | 
|---|
| 46 |                 decl( other.decl ), declptr( other.declptr ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ) {
 | 
|---|
| 47 |         new (&other) ParamEntry();
 | 
|---|
| 48 | }
 | 
|---|
| 49 | 
 | 
|---|
| 50 | ParamEntry & ParamEntry::operator=( ParamEntry && other ) {
 | 
|---|
| 51 |         if ( &other == this ) return *this;
 | 
|---|
| 52 |         this->~ParamEntry();
 | 
|---|
| 53 |         new (this) ParamEntry(other.decl, other.declptr, other.actualType, other.formalType, other.expr);
 | 
|---|
| 54 |         new (&other) ParamEntry();
 | 
|---|
| 55 | 
 | 
|---|
| 56 |         return *this;
 | 
|---|
| 57 | }
 | 
|---|
| 58 | 
 | 
|---|
| 59 | ApplicationExpr::ApplicationExpr( Expression *funcExpr, const std::list<Expression *> & args ) : function( funcExpr ), args( args ) {
 | 
|---|
| 60 |         PointerType *pointer = strict_dynamic_cast< PointerType* >( funcExpr->get_result() );
 | 
|---|
| 61 |         FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() );
 | 
|---|
| 62 | 
 | 
|---|
| 63 |         set_result( ResolvExpr::extractResultType( function ) );
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         assert( result );
 | 
|---|
| 66 | }
 | 
|---|
| 67 | 
 | 
|---|
| 68 | ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
 | 
|---|
| 69 |                 Expression( other ), function( maybeClone( other.function ) ) {
 | 
|---|
| 70 |         cloneAll( other.args, args );
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | ApplicationExpr::~ApplicationExpr() {
 | 
|---|
| 74 |         delete function;
 | 
|---|
| 75 |         deleteAll( args );
 | 
|---|
| 76 | }
 | 
|---|
| 77 | 
 | 
|---|
| 78 | void ApplicationExpr::print( std::ostream &os, Indenter indent ) const {
 | 
|---|
| 79 |         os << "Application of" << std::endl << indent+1;
 | 
|---|
| 80 |         function->print( os, indent+1 );
 | 
|---|
| 81 |         os << std::endl;
 | 
|---|
| 82 |         if ( ! args.empty() ) {
 | 
|---|
| 83 |                 os << indent << "... to arguments" << std::endl;
 | 
|---|
| 84 |                 printAll( args, os, indent+1 );
 | 
|---|
| 85 |         } // if
 | 
|---|
| 86 |         Expression::print( os, indent );
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | // Local Variables: //
 | 
|---|
| 90 | // tab-width: 4 //
 | 
|---|
| 91 | // mode: c++ //
 | 
|---|
| 92 | // compile-command: "make install" //
 | 
|---|
| 93 | // End: //
 | 
|---|