source: src/SynTree/FunctionDecl.cc @ 7cc2c8d

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 7cc2c8d was 3fe34ae, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Added bootloader.cf which contains the main that wraps the user main

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