source: src/SynTree/FunctionDecl.cc @ ced2e989

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since ced2e989 was 2037f82, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

added many missing calls to delete, still a long way to go...

  • Property mode set to 100644
File size: 3.4 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//
[9243a501]7// FunctionDecl.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[8b7ee09]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Aug 18 23:50:14 2016
13// Update Count     : 20
[0dd3a2f]14//
15
[51b7345]16#include <cassert>
17
18#include "Declaration.h"
19#include "Statement.h"
20#include "Type.h"
[7baed7d]21#include "Attribute.h"
[d3b7937]22#include "Common/utility.h"
[51b7345]23
[8b7ee09]24FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
[f9cebb5]25                : Parent( name, sc, linkage, attributes ), type( type ), statements( statements ) {
[1db21619]26        set_isInline( isInline );
27        set_isNoreturn( isNoreturn );
[0dd3a2f]28        // this is a brazen hack to force the function "main" to have C linkage
29        if ( name == "main" ) {
30                set_linkage( LinkageSpec::C );
31        } // if
[51b7345]32}
33
34FunctionDecl::FunctionDecl( const FunctionDecl &other )
[7baed7d]35        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
[51b7345]36}
37
[c11e31c]38FunctionDecl::~FunctionDecl() {
[0dd3a2f]39        delete type;
40        delete statements;
[2037f82]41        deleteAll( oldDecls );
[51b7345]42}
43
[c11e31c]44Type * FunctionDecl::get_type() const {
[0dd3a2f]45        return type;
[51b7345]46}
47
[c11e31c]48void FunctionDecl::set_type( Type *t ) {
[0dd3a2f]49        type = dynamic_cast< FunctionType* >( t );
50        assert( type );
[51b7345]51}
52
[c11e31c]53void FunctionDecl::print( std::ostream &os, int indent ) const {
[0dd3a2f]54        using std::endl;
55        using std::string;
[9243a501]56
[0dd3a2f]57        if ( get_name() != "" ) {
[5f2f2d7]58                os << get_name() << ": ";
[0dd3a2f]59        } // if
60        if ( get_linkage() != LinkageSpec::Cforall ) {
61                os << LinkageSpec::toString( get_linkage() ) << " ";
62        } // if
[1db21619]63        if ( get_isInline() ) {
[0dd3a2f]64                os << "inline ";
65        } // if
[1db21619]66        if ( get_isNoreturn() ) {
[de62360d]67                os << "_Noreturn ";
68        } // if
[7baed7d]69
[f9cebb5]70        printAll( get_attributes(), os, indent );
[7baed7d]71
[68cd1ce]72        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
73                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
[0dd3a2f]74        } // if
75        if ( get_type() ) {
76                get_type()->print( os, indent );
77        } else {
78                os << "untyped entity ";
79        } // if
[843054c2]80
[0dd3a2f]81        if ( ! oldIdents.empty() ) {
[de62360d]82                os << string( indent + 2, ' ' ) << "with parameter names" << endl;
[0dd3a2f]83                for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
[de62360d]84                        os << string( indent + 4, ' ' ) << *i << endl;
[0dd3a2f]85                } // for
86        } // if
[843054c2]87
[0dd3a2f]88        if ( ! oldDecls.empty() ) {
[de62360d]89                os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
90                printAll( oldDecls, os, indent + 4 );
[0dd3a2f]91        } // if
92        if ( statements ) {
[de62360d]93                os << string( indent + 2, ' ' ) << "with body " << endl;
[9243a501]94                os << string( indent + 4, ' ' );
[de62360d]95                statements->print( os, indent + 4 );
[0dd3a2f]96        } // if
[51b7345]97}
98
[c11e31c]99void FunctionDecl::printShort( std::ostream &os, int indent ) const {
[0dd3a2f]100        using std::endl;
101        using std::string;
[9243a501]102
[0dd3a2f]103        if ( get_name() != "" ) {
[5f2f2d7]104                os << get_name() << ": ";
[0dd3a2f]105        } // if
[1db21619]106        if ( get_isInline() ) {
[0dd3a2f]107                os << "inline ";
108        } // if
[1db21619]109        if ( get_isNoreturn() ) {
[de62360d]110                os << "_Noreturn ";
111        } // if
[7baed7d]112
113        // xxx - should printShort print attributes?
114
[68cd1ce]115        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
116                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
[0dd3a2f]117        } // if
118        if ( get_type() ) {
119                get_type()->print( os, indent );
120        } else {
121                os << "untyped entity ";
122        } // if
[51b7345]123}
[0dd3a2f]124
125// Local Variables: //
126// tab-width: 4 //
127// mode: c++ //
128// compile-command: "make install" //
129// End: //
Note: See TracBrowser for help on using the repository browser.