source: src/SynTree/FunctionDecl.cc @ 89ce869

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 89ce869 was 9e2c1f0, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Merge branch 'global-init' into ctor and add global destroy function to call destructors on global objects

Conflicts:

src/CodeGen/CodeGenerator.cc
src/InitTweak/module.mk
src/Makefile.in
src/SynTree/Declaration.h
src/SynTree/FunctionDecl.cc
src/main.cc

  • Property mode set to 100644
File size: 3.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// FunctionDecl.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 : Fri May 06 15:59:48 2016
13// Update Count     : 19
14//
15
16#include <cassert>
17
18#include "Declaration.h"
19#include "Statement.h"
20#include "Type.h"
21#include "Common/utility.h"
22
23FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute )
24                : Parent( name, sc, linkage ), type( type ), statements( statements ), attribute( attribute ) {
25        set_isInline( isInline );
26        set_isNoreturn( isNoreturn );
27        // this is a brazen hack to force the function "main" to have C linkage
28        if ( name == "main" ) {
29                set_linkage( LinkageSpec::C );
30        } // if
31}
32
33FunctionDecl::FunctionDecl( const FunctionDecl &other )
34        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), attribute( other.attribute ) {
35}
36
37FunctionDecl::~FunctionDecl() {
38        delete type;
39        delete statements;
40}
41
42Type * FunctionDecl::get_type() const {
43        return type;
44}
45
46void FunctionDecl::set_type( Type *t ) {
47        type = dynamic_cast< FunctionType* >( t );
48        assert( type );
49}
50
51void FunctionDecl::print( std::ostream &os, int indent ) const {
52        using std::endl;
53        using std::string;
54
55        if ( get_name() != "" ) {
56                os << get_name() << ": ";
57        } // if
58        if ( get_linkage() != LinkageSpec::Cforall ) {
59                os << LinkageSpec::toString( get_linkage() ) << " ";
60        } // if
61        if ( get_isInline() ) {
62                os << "inline ";
63        } // if
64        if ( get_isNoreturn() ) {
65                os << "_Noreturn ";
66        } // if
67        switch ( attribute.type ) {
68                case Attribute::Constructor:
69                        os << "Global Constructor ";
70                        break;
71                case Attribute::Destructor:
72                        os << "Global Destructor ";
73                        break;
74                default:
75                        break;
76        }
77        if ( attribute.priority != Attribute::Default ) {
78                os << "with priority " << attribute.priority << " ";
79        }
80        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
81                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
82        } // if
83        if ( get_type() ) {
84                get_type()->print( os, indent );
85        } else {
86                os << "untyped entity ";
87        } // if
88
89        if ( ! oldIdents.empty() ) {
90                os << string( indent + 2, ' ' ) << "with parameter names" << endl;
91                for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
92                        os << string( indent + 4, ' ' ) << *i << endl;
93                } // for
94        } // if
95
96        if ( ! oldDecls.empty() ) {
97                os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
98                printAll( oldDecls, os, indent + 4 );
99        } // if
100        if ( statements ) {
101                os << string( indent + 2, ' ' ) << "with body " << endl;
102                os << string( indent + 4, ' ' );
103                statements->print( os, indent + 4 );
104        } // if
105}
106
107void FunctionDecl::printShort( std::ostream &os, int indent ) const {
108        using std::endl;
109        using std::string;
110
111        if ( get_name() != "" ) {
112                os << get_name() << ": ";
113        } // if
114        if ( get_isInline() ) {
115                os << "inline ";
116        } // if
117        if ( get_isNoreturn() ) {
118                os << "_Noreturn ";
119        } // if
120        switch ( attribute.type ) {
121                case Attribute::Constructor:
122                        os << " Global Constructor ";
123                        break;
124                case Attribute::Destructor:
125                        os << " Global Destructor ";
126                        break;
127                default:
128                        break;
129        }
130        if ( attribute.priority != Attribute::Default ) {
131                os << "with priority " << attribute.priority << " ";
132        }
133        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
134                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
135        } // if
136        if ( get_type() ) {
137                get_type()->print( os, indent );
138        } else {
139                os << "untyped entity ";
140        } // if
141}
142
143// Local Variables: //
144// tab-width: 4 //
145// mode: c++ //
146// compile-command: "make install" //
147// End: //
Note: See TracBrowser for help on using the repository browser.