source: src/SynTree/FunctionDecl.cc@ b7ea418

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since b7ea418 was f9cebb5, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

add gcc attributes to ObjectDecl, hoist destructed static variables, add breaks to end of generated switch

  • Property mode set to 100644
File size: 3.3 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 "Attribute.h"
22#include "Common/utility.h"
23
24FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type 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}
42
43Type * FunctionDecl::get_type() const {
44 return type;
45}
46
47void FunctionDecl::set_type( Type *t ) {
48 type = dynamic_cast< FunctionType* >( t );
49 assert( type );
50}
51
52void FunctionDecl::print( std::ostream &os, int indent ) const {
53 using std::endl;
54 using std::string;
55
56 if ( get_name() != "" ) {
57 os << get_name() << ": ";
58 } // if
59 if ( get_linkage() != LinkageSpec::Cforall ) {
60 os << LinkageSpec::toString( get_linkage() ) << " ";
61 } // if
62 if ( get_isInline() ) {
63 os << "inline ";
64 } // if
65 if ( get_isNoreturn() ) {
66 os << "_Noreturn ";
67 } // if
68
69 printAll( get_attributes(), os, indent );
70
71 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
72 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
73 } // if
74 if ( get_type() ) {
75 get_type()->print( os, indent );
76 } else {
77 os << "untyped entity ";
78 } // if
79
80 if ( ! oldIdents.empty() ) {
81 os << string( indent + 2, ' ' ) << "with parameter names" << endl;
82 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
83 os << string( indent + 4, ' ' ) << *i << endl;
84 } // for
85 } // if
86
87 if ( ! oldDecls.empty() ) {
88 os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
89 printAll( oldDecls, os, indent + 4 );
90 } // if
91 if ( statements ) {
92 os << string( indent + 2, ' ' ) << "with body " << endl;
93 os << string( indent + 4, ' ' );
94 statements->print( os, indent + 4 );
95 } // if
96}
97
98void FunctionDecl::printShort( std::ostream &os, int indent ) const {
99 using std::endl;
100 using std::string;
101
102 if ( get_name() != "" ) {
103 os << get_name() << ": ";
104 } // if
105 if ( get_isInline() ) {
106 os << "inline ";
107 } // if
108 if ( get_isNoreturn() ) {
109 os << "_Noreturn ";
110 } // if
111
112 // xxx - should printShort print attributes?
113
114 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
115 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
116 } // if
117 if ( get_type() ) {
118 get_type()->print( os, indent );
119 } else {
120 os << "untyped entity ";
121 } // if
122}
123
124// Local Variables: //
125// tab-width: 4 //
126// mode: c++ //
127// compile-command: "make install" //
128// End: //
Note: See TracBrowser for help on using the repository browser.