source: src/SynTree/FunctionDecl.cc @ 8d2844a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 8d2844a 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
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// FunctionDecl.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Aug 18 23:50:14 2016
13// Update Count     : 20
14//
15
16#include <cassert>
17
18#include "Declaration.h"
19#include "Statement.h"
20#include "Type.h"
21#include "Attribute.h"
22#include "Common/utility.h"
23
24FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
25                : Parent( name, sc, linkage, attributes ), type( type ), statements( statements ) {
26        set_isInline( isInline );
27        set_isNoreturn( isNoreturn );
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
32}
33
34FunctionDecl::FunctionDecl( const FunctionDecl &other )
35        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
36}
37
38FunctionDecl::~FunctionDecl() {
39        delete type;
40        delete statements;
41        deleteAll( oldDecls );
42}
43
44Type * FunctionDecl::get_type() const {
45        return type;
46}
47
48void FunctionDecl::set_type( Type *t ) {
49        type = dynamic_cast< FunctionType* >( t );
50        assert( type );
51}
52
53void FunctionDecl::print( std::ostream &os, int indent ) const {
54        using std::endl;
55        using std::string;
56
57        if ( get_name() != "" ) {
58                os << get_name() << ": ";
59        } // if
60        if ( get_linkage() != LinkageSpec::Cforall ) {
61                os << LinkageSpec::toString( get_linkage() ) << " ";
62        } // if
63        if ( get_isInline() ) {
64                os << "inline ";
65        } // if
66        if ( get_isNoreturn() ) {
67                os << "_Noreturn ";
68        } // if
69
70        printAll( get_attributes(), os, indent );
71
72        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
73                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
74        } // if
75        if ( get_type() ) {
76                get_type()->print( os, indent );
77        } else {
78                os << "untyped entity ";
79        } // if
80
81        if ( ! oldIdents.empty() ) {
82                os << string( indent + 2, ' ' ) << "with parameter names" << endl;
83                for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
84                        os << string( indent + 4, ' ' ) << *i << endl;
85                } // for
86        } // if
87
88        if ( ! oldDecls.empty() ) {
89                os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
90                printAll( oldDecls, os, indent + 4 );
91        } // if
92        if ( statements ) {
93                os << string( indent + 2, ' ' ) << "with body " << endl;
94                os << string( indent + 4, ' ' );
95                statements->print( os, indent + 4 );
96        } // if
97}
98
99void FunctionDecl::printShort( std::ostream &os, int indent ) const {
100        using std::endl;
101        using std::string;
102
103        if ( get_name() != "" ) {
104                os << get_name() << ": ";
105        } // if
106        if ( get_isInline() ) {
107                os << "inline ";
108        } // if
109        if ( get_isNoreturn() ) {
110                os << "_Noreturn ";
111        } // if
112
113        // xxx - should printShort print attributes?
114
115        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
116                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
117        } // if
118        if ( get_type() ) {
119                get_type()->print( os, indent );
120        } else {
121                os << "untyped entity ";
122        } // if
123}
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.