source: src/SynTree/FunctionDecl.cc @ 711eee5

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 711eee5 was 1f6e009, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

set main to Cforall linkage so that it will be mangled

  • Property mode set to 100644
File size: 3.0 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 Apr 01 11:40:07 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 )
24                : Parent( name, sc, linkage ), type( type ), statements( statements ) {
25        set_isInline( isInline );
26        set_isNoreturn( isNoreturn );
27}
28
29FunctionDecl::FunctionDecl( const FunctionDecl &other )
30        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
31}
32
33FunctionDecl::~FunctionDecl() {
34        delete type;
35        delete statements;
36}
37
38Type * FunctionDecl::get_type() const {
39        return type;
40}
41
42void FunctionDecl::set_type( Type *t ) {
43        type = dynamic_cast< FunctionType* >( t );
44        assert( type );
45}
46
47void FunctionDecl::print( std::ostream &os, int indent ) const {
48        using std::endl;
49        using std::string;
50
51        if ( get_name() != "" ) {
52                os << get_name() << ": ";
53        } // if
54        if ( get_linkage() != LinkageSpec::Cforall ) {
55                os << LinkageSpec::toString( get_linkage() ) << " ";
56        } // if
57        if ( get_isInline() ) {
58                os << "inline ";
59        } // if
60        if ( get_isNoreturn() ) {
61                os << "_Noreturn ";
62        } // if
63        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
64                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
65        } // if
66        if ( get_type() ) {
67                get_type()->print( os, indent );
68        } else {
69                os << "untyped entity ";
70        } // if
71
72        if ( ! oldIdents.empty() ) {
73                os << string( indent + 2, ' ' ) << "with parameter names" << endl;
74                for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
75                        os << string( indent + 4, ' ' ) << *i << endl;
76                } // for
77        } // if
78
79        if ( ! oldDecls.empty() ) {
80                os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
81                printAll( oldDecls, os, indent + 4 );
82        } // if
83        if ( statements ) {
84                os << string( indent + 2, ' ' ) << "with body " << endl;
85                statements->print( os, indent + 4 );
86        } // if
87}
88
89void FunctionDecl::printShort( std::ostream &os, int indent ) const {
90        using std::endl;
91        using std::string;
92
93        if ( get_name() != "" ) {
94                os << get_name() << ": ";
95        } // if
96        if ( get_isInline() ) {
97                os << "inline ";
98        } // if
99        if ( get_isNoreturn() ) {
100                os << "_Noreturn ";
101        } // if
102        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
103                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
104        } // if
105        if ( get_type() ) {
106                get_type()->print( os, indent );
107        } else {
108                os << "untyped entity ";
109        } // if
110}
111
112// Local Variables: //
113// tab-width: 4 //
114// mode: c++ //
115// compile-command: "make install" //
116// End: //
Note: See TracBrowser for help on using the repository browser.