source: src/SynTree/ApplicationExpr.cc @ 9643b31

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 9643b31 was 6c3a988f, checked in by Rob Schluntz <rschlunt@…>, 8 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
RevLine 
[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//
[89231bc]7// ApplicationExpr.cc.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[89231bc]11// Last Modified By : Rob Schluntz
12// Last Modified On : Tue Apr 26 12:41:06 2016
[0dd3a2f]13// Update Count     : 4
14//
15
[51b7345]16#include <cassert>
17
18#include "Expression.h"
19#include "Declaration.h"
20#include "Type.h"
21#include "TypeSubstitution.h"
[d3b7937]22#include "Common/utility.h"
[906e24d]23#include "ResolvExpr/typeops.h"
[51b7345]24
[0dd3a2f]25ParamEntry::ParamEntry( const ParamEntry &other ) :
[6c3a988f]26                decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) {
[51b7345]27}
28
[0dd3a2f]29ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
30        if ( &other == this ) return *this;
31        decl = other.decl;
[2c57025]32        // xxx - this looks like a memory leak
[0dd3a2f]33        actualType = maybeClone( other.actualType );
34        formalType = maybeClone( other.formalType );
35        expr = maybeClone( other.expr );
[6c3a988f]36        *inferParams = *other.inferParams;
[0dd3a2f]37        return *this;
[51b7345]38}
39
[0dd3a2f]40ParamEntry::~ParamEntry() {
41        delete actualType;
42        delete formalType;
43        delete expr;
[51b7345]44}
45
[0dd3a2f]46ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) {
[906e24d]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() );
[51b7345]53}
54
[0dd3a2f]55ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) :
56                Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) {
57        cloneAll( other.args, args );
[51b7345]58}
59
[0dd3a2f]60ApplicationExpr::~ApplicationExpr() {
61        delete function;
62        deleteAll( args );
[51b7345]63}
64
[6c3a988f]65void printInferParams( const InferredParams & inferParams, std::ostream &os, int indent, int level ) {
[0dd3a2f]66        if ( ! inferParams.empty() ) {
[6c3a988f]67                os << std::string(indent, ' ') << "with inferred parameters " << level << ":" << std::endl;
[0dd3a2f]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;
[6c3a988f]72                        printInferParams( *i->second.inferParams, os, indent+2, level+1 );
[0dd3a2f]73                } // for
74        } // if
[6c3a988f]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 );
[0dd3a2f]85        Expression::print( os, indent );
[51b7345]86}
87
[0dd3a2f]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.