source: src/SynTree/ApplicationExpr.cc@ dc5072f

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since dc5072f was aaeacf4, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Removed global look-up table from UniqueId to Decl

  • Property mode set to 100644
File size: 4.1 KB
Line 
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
30ParamEntry::ParamEntry( const ParamEntry &other ) :
31 decl( other.decl ), declptr( maybeClone( other.declptr ) ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) )/*, inferParams( new InferredParams( *other.inferParams ) )*/ {
32}
33
34ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
35 if ( &other == this ) return *this;
36 const_cast<UniqueId &>(decl) = other.decl;
37 const_cast<Declaration * &>(declptr) = maybeClone( other.declptr );
38 // xxx - this looks like a memory leak
39 const_cast<Type * &>(actualType) = maybeClone( other.actualType );
40 const_cast<Type * &>(formalType) = maybeClone( other.formalType );
41 expr = maybeClone( other.expr );
42 // *inferParams = *other.inferParams;
43 return *this;
44}
45
46ParamEntry::~ParamEntry() {
47 delete declptr;
48 delete actualType;
49 delete formalType;
50 delete expr;
51}
52
53ParamEntry::ParamEntry( ParamEntry && other ) :
54 decl( other.decl ), declptr( other.declptr ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr )/*, inferParams( std::move( other.inferParams ) )*/ {
55 const_cast<Declaration * &>(other.declptr) = nullptr;
56 const_cast<Type * &>(other.actualType) = nullptr;
57 const_cast<Type * &>(other.formalType) = nullptr;
58 other.expr = nullptr;
59}
60
61ParamEntry & ParamEntry::operator=( ParamEntry && other ) {
62 if ( &other == this ) return *this;
63 delete declptr;
64 delete actualType;
65 delete formalType;
66 delete expr;
67 const_cast<UniqueId &>(decl) = other.decl;
68 const_cast<Declaration * &>(declptr) = other.declptr;
69 const_cast<Type * &>(actualType) = other.actualType;
70 const_cast<Type * &>(formalType) = other.formalType;
71 expr = other.expr;
72 const_cast<Declaration * &>(other.declptr) = nullptr;
73 const_cast<Type * &>(other.actualType) = nullptr;
74 const_cast<Type * &>(other.formalType) = nullptr;
75 other.expr = nullptr;
76 // inferParams = std::move( other.inferParams );
77 return *this;
78}
79
80ApplicationExpr::ApplicationExpr( Expression *funcExpr, const std::list<Expression *> & args ) : function( funcExpr ), args( args ) {
81 PointerType *pointer = strict_dynamic_cast< PointerType* >( funcExpr->get_result() );
82 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() );
83
84 set_result( ResolvExpr::extractResultType( function ) );
85
86 assert( result );
87}
88
89ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
90 Expression( other ), function( maybeClone( other.function ) ) {
91 cloneAll( other.args, args );
92}
93
94ApplicationExpr::~ApplicationExpr() {
95 delete function;
96 deleteAll( args );
97}
98
99void ApplicationExpr::print( std::ostream &os, Indenter indent ) const {
100 os << "Application of" << std::endl << indent+1;
101 function->print( os, indent+1 );
102 os << std::endl;
103 if ( ! args.empty() ) {
104 os << indent << "... to arguments" << std::endl;
105 printAll( args, os, indent+1 );
106 } // if
107 Expression::print( os, indent );
108}
109
110// Local Variables: //
111// tab-width: 4 //
112// mode: c++ //
113// compile-command: "make install" //
114// End: //
Note: See TracBrowser for help on using the repository browser.