source: src/SynTree/FunctionDecl.cc @ 0270824

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

Replace user main with custom main, prototype

  • Property mode set to 100644
File size: 3.5 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 : Sat Oct  1 23:06:32 2016
13// Update Count     : 21
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#include "InitTweak/InitTweak.h"
24
25FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
26                : Parent( name, sc, linkage, attributes ), type( type ), statements( statements ) {
27        set_isInline( isInline );
28        set_isNoreturn( isNoreturn );
29        // this is a brazen hack to force the function "main" to have Cforall linkage
30        // because we want to replace the main even if it is inside an extern
31        if ( name == "main" ) {
32                set_linkage( LinkageSpec::Cforall );
33        } // if
34}
35
36FunctionDecl::FunctionDecl( const FunctionDecl &other )
37        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
38}
39
40FunctionDecl::~FunctionDecl() {
41        delete type;
42        delete statements;
43        deleteAll( oldDecls );
44}
45
46Type * FunctionDecl::get_type() const {
47        return type;
48}
49
50void FunctionDecl::set_type( Type *t ) {
51        type = dynamic_cast< FunctionType* >( t );
52        assert( type );
53}
54
55void FunctionDecl::print( std::ostream &os, int indent ) const {
56        using std::endl;
57        using std::string;
58
59        if ( get_name() != "" ) {
60                os << get_name() << ": ";
61        } // if
62        if ( get_linkage() != LinkageSpec::Cforall ) {
63                os << LinkageSpec::linkageName( get_linkage() ) << " ";
64        } // if
65        if ( get_isInline() ) {
66                os << "inline ";
67        } // if
68        if ( get_isNoreturn() ) {
69                os << "_Noreturn ";
70        } // if
71
72        printAll( get_attributes(), os, indent );
73
74        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
75                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
76        } // if
77        if ( get_type() ) {
78                get_type()->print( os, indent );
79        } else {
80                os << "untyped entity ";
81        } // if
82
83        if ( ! oldIdents.empty() ) {
84                os << string( indent + 2, ' ' ) << "with parameter names" << endl;
85                for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
86                        os << string( indent + 4, ' ' ) << *i << endl;
87                } // for
88        } // if
89
90        if ( ! oldDecls.empty() ) {
91                os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
92                printAll( oldDecls, os, indent + 4 );
93        } // if
94        if ( statements ) {
95                os << string( indent + 2, ' ' ) << "with body " << endl;
96                os << string( indent + 4, ' ' );
97                statements->print( os, indent + 4 );
98        } // if
99}
100
101void FunctionDecl::printShort( std::ostream &os, int indent ) const {
102        using std::endl;
103        using std::string;
104
105        if ( get_name() != "" ) {
106                os << get_name() << ": ";
107        } // if
108        if ( get_isInline() ) {
109                os << "inline ";
110        } // if
111        if ( get_isNoreturn() ) {
112                os << "_Noreturn ";
113        } // if
114
115        // xxx - should printShort print attributes?
116
117        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
118                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
119        } // if
120        if ( get_type() ) {
121                get_type()->print( os, indent );
122        } else {
123                os << "untyped entity ";
124        } // if
125}
126
127// Local Variables: //
128// tab-width: 4 //
129// mode: c++ //
130// compile-command: "make install" //
131// End: //
Note: See TracBrowser for help on using the repository browser.