source: src/SynTree/FunctionDecl.cc@ 75c566a

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox 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 75c566a was 3a5131ed, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

handle KR function declarations

  • Property mode set to 100644
File size: 3.1 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 : Thu Feb 16 15:01:52 2017
13// Update Count : 23
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
26extern bool translation_unit_nomain;
27
28FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
29 : Parent( name, sc, linkage, attributes ), type( type ), statements( statements ) {
30 set_isInline( isInline );
31 set_isNoreturn( isNoreturn );
32 // this is a brazen hack to force the function "main" to have Cforall linkage
33 // because we want to replace the main even if it is inside an extern
34 if ( name == "main" ) {
35 set_linkage( CodeGen::FixMain::mainLinkage() );
36 } // if
37}
38
39FunctionDecl::FunctionDecl( const FunctionDecl &other )
40 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
41}
42
43FunctionDecl::~FunctionDecl() {
44 delete type;
45 delete statements;
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 ( statements ) {
86 os << string( indent + 2, ' ' ) << "with body " << endl;
87 os << string( indent + 4, ' ' );
88 statements->print( os, indent + 4 );
89 } // if
90}
91
92void FunctionDecl::printShort( std::ostream &os, int indent ) const {
93 using std::endl;
94 using std::string;
95
96 if ( get_name() != "" ) {
97 os << get_name() << ": ";
98 } // if
99 if ( get_isInline() ) {
100 os << "inline ";
101 } // if
102 if ( get_isNoreturn() ) {
103 os << "_Noreturn ";
104 } // if
105
106 // xxx - should printShort print attributes?
107
108 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
109 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
110 } // if
111 if ( get_type() ) {
112 get_type()->print( os, indent );
113 } else {
114 os << "untyped entity ";
115 } // if
116}
117
118// Local Variables: //
119// tab-width: 4 //
120// mode: c++ //
121// compile-command: "make install" //
122// End: //
Note: See TracBrowser for help on using the repository browser.