[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 | // |
---|
[7b5694d] | 7 | // ApplicationExpr.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[14388c1] | 11 | // Last Modified By : Andrew Beach |
---|
| 12 | // Last Modified On : Mon Aug 12 14:28:00 2019 |
---|
| 13 | // Update Count : 5 |
---|
[0dd3a2f] | 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 |
---|
[51b7345] | 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 |
---|
[849720f] | 27 | #include "InitTweak/InitTweak.h" // for getFunction |
---|
[7b5694d] | 28 | #include "ResolvExpr/Unify.h" // for extractResultType |
---|
[ea6332d] | 29 | #include "Type.h" // for Type, PointerType, FunctionType |
---|
[51b7345] | 30 | |
---|
[462a7c7] | 31 | ParamEntry::ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr ) |
---|
| 32 | : decl( decl ), declptr( declptr ), actualType( actualType ), formalType( formalType ), expr( expr ) { |
---|
| 33 | } |
---|
[51b7345] | 34 | |
---|
[462a7c7] | 35 | ParamEntry::ParamEntry( const ParamEntry &other ) : |
---|
[07d867b] | 36 | decl( other.decl ), declptr( other.declptr ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) { |
---|
[51b7345] | 37 | } |
---|
| 38 | |
---|
[0dd3a2f] | 39 | ParamEntry::~ParamEntry() { |
---|
[07d867b] | 40 | // delete declptr; |
---|
[0dd3a2f] | 41 | delete actualType; |
---|
| 42 | delete formalType; |
---|
| 43 | delete expr; |
---|
[51b7345] | 44 | } |
---|
| 45 | |
---|
[4d6d62e] | 46 | ParamEntry::ParamEntry( ParamEntry && other ) : |
---|
[462a7c7] | 47 | decl( other.decl ), declptr( other.declptr ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ) { |
---|
| 48 | new (&other) ParamEntry(); |
---|
[4d6d62e] | 49 | } |
---|
| 50 | |
---|
| 51 | ParamEntry & ParamEntry::operator=( ParamEntry && other ) { |
---|
| 52 | if ( &other == this ) return *this; |
---|
[462a7c7] | 53 | this->~ParamEntry(); |
---|
| 54 | new (this) ParamEntry(other.decl, other.declptr, other.actualType, other.formalType, other.expr); |
---|
| 55 | new (&other) ParamEntry(); |
---|
| 56 | |
---|
[4d6d62e] | 57 | return *this; |
---|
| 58 | } |
---|
| 59 | |
---|
[f19339e] | 60 | ApplicationExpr::ApplicationExpr( Expression *funcExpr, const std::list<Expression *> & args ) : function( funcExpr ), args( args ) { |
---|
[e3e16bc] | 61 | PointerType *pointer = strict_dynamic_cast< PointerType* >( funcExpr->get_result() ); |
---|
| 62 | FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() ); |
---|
[906e24d] | 63 | |
---|
| 64 | set_result( ResolvExpr::extractResultType( function ) ); |
---|
| 65 | |
---|
[d29fa5f] | 66 | assert( result ); |
---|
[51b7345] | 67 | } |
---|
| 68 | |
---|
[0dd3a2f] | 69 | ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) : |
---|
[df626eb] | 70 | Expression( other ), function( maybeClone( other.function ) ) { |
---|
[0dd3a2f] | 71 | cloneAll( other.args, args ); |
---|
[51b7345] | 72 | } |
---|
| 73 | |
---|
[0dd3a2f] | 74 | ApplicationExpr::~ApplicationExpr() { |
---|
| 75 | delete function; |
---|
| 76 | deleteAll( args ); |
---|
[51b7345] | 77 | } |
---|
| 78 | |
---|
[14388c1] | 79 | bool ApplicationExpr::get_lvalue() const { |
---|
[849720f] | 80 | // from src/GenPoly/Lvalue.cc: isIntrinsicReference |
---|
| 81 | static std::set<std::string> lvalueFunctions = { "*?", "?[?]" }; |
---|
| 82 | if ( const DeclarationWithType * func = InitTweak::getFunction( this ) ) { |
---|
| 83 | return func->linkage == LinkageSpec::Intrinsic && lvalueFunctions.count(func->name); |
---|
| 84 | } |
---|
| 85 | return false; |
---|
[14388c1] | 86 | } |
---|
| 87 | |
---|
[50377a4] | 88 | void ApplicationExpr::print( std::ostream &os, Indenter indent ) const { |
---|
| 89 | os << "Application of" << std::endl << indent+1; |
---|
| 90 | function->print( os, indent+1 ); |
---|
| 91 | os << std::endl; |
---|
[6c3a988f] | 92 | if ( ! args.empty() ) { |
---|
[50377a4] | 93 | os << indent << "... to arguments" << std::endl; |
---|
| 94 | printAll( args, os, indent+1 ); |
---|
[6c3a988f] | 95 | } // if |
---|
[0dd3a2f] | 96 | Expression::print( os, indent ); |
---|
[51b7345] | 97 | } |
---|
| 98 | |
---|
[0dd3a2f] | 99 | // Local Variables: // |
---|
| 100 | // tab-width: 4 // |
---|
| 101 | // mode: c++ // |
---|
| 102 | // compile-command: "make install" // |
---|
| 103 | // End: // |
---|