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 : Wed Mar 15 23:33:43 2017 |
---|
13 | // Update Count : 72 |
---|
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 | #include "CodeGen/FixMain.h" |
---|
25 | |
---|
26 | extern bool translation_unit_nomain; |
---|
27 | |
---|
28 | FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, std::list< Attribute * > attributes, DeclarationNode::FuncSpecifiers fs ) |
---|
29 | : Parent( name, scs, linkage, attributes, fs ), type( type ), statements( statements ) { |
---|
30 | // hack forcing the function "main" to have Cforall linkage to replace main even if it is inside an extern |
---|
31 | if ( name == "main" ) { |
---|
32 | set_linkage( CodeGen::FixMain::mainLinkage() ); |
---|
33 | } // if |
---|
34 | } |
---|
35 | |
---|
36 | FunctionDecl::FunctionDecl( const FunctionDecl &other ) |
---|
37 | : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) { |
---|
38 | } |
---|
39 | |
---|
40 | FunctionDecl::~FunctionDecl() { |
---|
41 | delete type; |
---|
42 | delete statements; |
---|
43 | } |
---|
44 | |
---|
45 | Type * FunctionDecl::get_type() const { |
---|
46 | return type; |
---|
47 | } |
---|
48 | |
---|
49 | void FunctionDecl::set_type( Type *t ) { |
---|
50 | type = dynamic_cast< FunctionType* >( t ); |
---|
51 | assert( type ); |
---|
52 | } |
---|
53 | |
---|
54 | void FunctionDecl::print( std::ostream &os, int indent ) const { |
---|
55 | using std::endl; |
---|
56 | using std::string; |
---|
57 | |
---|
58 | if ( get_name() != "" ) { |
---|
59 | os << get_name() << ": "; |
---|
60 | } // if |
---|
61 | if ( get_linkage() != LinkageSpec::Cforall ) { |
---|
62 | os << LinkageSpec::linkageName( get_linkage() ) << " "; |
---|
63 | } // if |
---|
64 | |
---|
65 | printAll( get_attributes(), os, indent ); |
---|
66 | |
---|
67 | get_storageClasses().print( os ); |
---|
68 | get_funcSpec().print( os ); |
---|
69 | |
---|
70 | if ( get_type() ) { |
---|
71 | get_type()->print( os, indent ); |
---|
72 | } else { |
---|
73 | os << "untyped entity "; |
---|
74 | } // if |
---|
75 | |
---|
76 | if ( statements ) { |
---|
77 | os << string( indent + 2, ' ' ) << "with body " << endl; |
---|
78 | os << string( indent + 4, ' ' ); |
---|
79 | statements->print( os, indent + 4 ); |
---|
80 | } // if |
---|
81 | } |
---|
82 | |
---|
83 | void FunctionDecl::printShort( std::ostream &os, int indent ) const { |
---|
84 | using std::endl; |
---|
85 | using std::string; |
---|
86 | |
---|
87 | if ( get_name() != "" ) { |
---|
88 | os << get_name() << ": "; |
---|
89 | } // if |
---|
90 | |
---|
91 | // xxx - should printShort print attributes? |
---|
92 | |
---|
93 | get_storageClasses().print( os ); |
---|
94 | get_funcSpec().print( os ); |
---|
95 | |
---|
96 | if ( get_type() ) { |
---|
97 | get_type()->print( os, indent ); |
---|
98 | } else { |
---|
99 | os << "untyped entity "; |
---|
100 | } // if |
---|
101 | } |
---|
102 | |
---|
103 | // Local Variables: // |
---|
104 | // tab-width: 4 // |
---|
105 | // mode: c++ // |
---|
106 | // compile-command: "make install" // |
---|
107 | // End: // |
---|