source: src/SynTree/ApplicationExpr.cc @ 6b0b624

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 6b0b624 was 6c3a988f, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

fix inferred parameter data structures to correctly associate parameters with the entity that requested them, modify tuple specialization and unification to work with self-recursive assertions

  • Property mode set to 100644
File size: 2.9 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>
17
18#include "Expression.h"
19#include "Declaration.h"
20#include "Type.h"
21#include "TypeSubstitution.h"
22#include "Common/utility.h"
23#include "ResolvExpr/typeops.h"
24
25ParamEntry::ParamEntry( const ParamEntry &other ) :
26                decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) {
27}
28
29ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
30        if ( &other == this ) return *this;
31        decl = other.decl;
32        // xxx - this looks like a memory leak
33        actualType = maybeClone( other.actualType );
34        formalType = maybeClone( other.formalType );
35        expr = maybeClone( other.expr );
36        *inferParams = *other.inferParams;
37        return *this;
38}
39
40ParamEntry::~ParamEntry() {
41        delete actualType;
42        delete formalType;
43        delete expr;
44}
45
46ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) {
47        PointerType *pointer = safe_dynamic_cast< PointerType* >( funcExpr->get_result() );
48        FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
49
50        set_result( ResolvExpr::extractResultType( function ) );
51
52        assert( has_result() );
53}
54
55ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
56                Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) {
57        cloneAll( other.args, args );
58}
59
60ApplicationExpr::~ApplicationExpr() {
61        delete function;
62        deleteAll( args );
63}
64
65void printInferParams( const InferredParams & inferParams, std::ostream &os, int indent, int level ) {
66        if ( ! inferParams.empty() ) {
67                os << std::string(indent, ' ') << "with inferred parameters " << level << ":" << std::endl;
68                for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
69                        os << std::string(indent+2, ' ');
70                        Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
71                        os << std::endl;
72                        printInferParams( *i->second.inferParams, os, indent+2, level+1 );
73                } // for
74        } // if
75}
76
77void ApplicationExpr::print( std::ostream &os, int indent ) const {
78        os << "Application of" << std::endl << std::string(indent+2, ' ');
79        function->print( os, indent+2 );
80        if ( ! args.empty() ) {
81                os << std::string( indent, ' ' ) << "to arguments" << std::endl;
82                printAll( args, os, indent+2 );
83        } // if
84        printInferParams( inferParams, os, indent+2, 0 );
85        Expression::print( os, indent );
86}
87
88// Local Variables: //
89// tab-width: 4 //
90// mode: c++ //
91// compile-command: "make install" //
92// End: //
Note: See TracBrowser for help on using the repository browser.