source: translator/SynTree/ApplicationExpr.cc@ 643a2e1

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 643a2e1 was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include <cassert>
2
3#include "Expression.h"
4#include "Declaration.h"
5#include "Type.h"
6#include "TypeSubstitution.h"
7#include "utility.h"
8
9
10ParamEntry::ParamEntry( const ParamEntry &other )
11 : decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) )
12{
13}
14
15ParamEntry &
16ParamEntry::operator=( const ParamEntry &other )
17{
18 if( &other == this ) return *this;
19 decl = other.decl;
20 actualType = maybeClone( other.actualType );
21 formalType = maybeClone( other.formalType );
22 expr = maybeClone( other.expr );
23 return *this;
24}
25
26ParamEntry::~ParamEntry()
27{
28 delete actualType;
29 delete formalType;
30 delete expr;
31}
32
33ApplicationExpr::ApplicationExpr( Expression *funcExpr )
34 : function( funcExpr )
35{
36 PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() );
37 assert( pointer );
38 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
39 assert( function );
40
41 for( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {
42 get_results().push_back( (*i)->get_type()->clone() );
43 }
44}
45
46ApplicationExpr::ApplicationExpr( const ApplicationExpr &other )
47 : Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams )
48{
49 cloneAll( other.args, args );
50}
51
52ApplicationExpr::~ApplicationExpr()
53{
54 delete function;
55 deleteAll( args );
56}
57
58void
59ApplicationExpr::print( std::ostream &os, int indent ) const
60{
61 os << std::string( indent, ' ' ) << "Application of" << std::endl;
62 function->print( os, indent+2 );
63 if( !args.empty() ) {
64 os << std::string( indent, ' ' ) << "to arguments" << std::endl;
65 printAll( args, os, indent+2 );
66 }
67 if( !inferParams.empty() ) {
68 os << std::string(indent, ' ') << "with inferred parameters:" << std::endl;
69 for( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
70 os << std::string(indent+2, ' ');
71 Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
72 os << std::endl;
73 }
74 }
75 Expression::print( os, indent );
76}
77
Note: See TracBrowser for help on using the repository browser.