source: src/SynTree/FunctionDecl.cc@ dfee306

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since dfee306 was de62360d, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

fix computed goto, fixed -std=, implicit typedefs for enum and aggregates, add _Noreturn _Thread_local

  • Property mode set to 100644
File size: 3.2 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 Jun 13 09:10:32 2015
13// Update Count : 16
14//
15
16#include <cassert>
17
18#include "Declaration.h"
19#include "Statement.h"
20#include "Type.h"
21#include "utility.h"
22
23FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn )
24 : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ), isNoreturn( isNoreturn ) {
25 // this is a brazen hack to force the function "main" to have C linkage
26 if ( name == "main" ) {
27 set_linkage( LinkageSpec::C );
28 } // if
29}
30
31FunctionDecl::FunctionDecl( const FunctionDecl &other )
32 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ), isNoreturn( other.isNoreturn ) {
33}
34
35FunctionDecl::~FunctionDecl() {
36 delete type;
37 delete statements;
38}
39
40Type * FunctionDecl::get_type() const {
41 return type;
42}
43
44void FunctionDecl::set_type( Type *t ) {
45 type = dynamic_cast< FunctionType* >( t );
46 assert( type );
47}
48
49void FunctionDecl::print( std::ostream &os, int indent ) const {
50 using std::endl;
51 using std::string;
52
53 if ( get_name() != "" ) {
54 os << get_name() << ": ";
55 } // if
56 if ( get_linkage() != LinkageSpec::Cforall ) {
57 os << LinkageSpec::toString( get_linkage() ) << " ";
58 } // if
59 if ( isInline ) {
60 os << "inline ";
61 } // if
62 if ( isNoreturn ) {
63 os << "_Noreturn ";
64 } // if
65 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
66 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
67 } // if
68 if ( get_type() ) {
69 get_type()->print( os, indent );
70 } else {
71 os << "untyped entity ";
72 } // if
73
74 if ( ! oldIdents.empty() ) {
75 os << string( indent + 2, ' ' ) << "with parameter names" << endl;
76 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
77 os << string( indent + 4, ' ' ) << *i << endl;
78 } // for
79 } // if
80
81 if ( ! oldDecls.empty() ) {
82 os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
83 printAll( oldDecls, os, indent + 4 );
84 } // if
85 if ( statements ) {
86 os << string( indent + 2, ' ' ) << "with body " << endl;
87 statements->print( os, indent + 4 );
88 } // if
89}
90
91void FunctionDecl::printShort( std::ostream &os, int indent ) const {
92 using std::endl;
93 using std::string;
94
95 if ( get_name() != "" ) {
96 os << get_name() << ": ";
97 } // if
98 if ( isInline ) {
99 os << "inline ";
100 } // if
101 if ( isNoreturn ) {
102 os << "_Noreturn ";
103 } // if
104 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
105 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
106 } // if
107 if ( get_type() ) {
108 get_type()->print( os, indent );
109 } else {
110 os << "untyped entity ";
111 } // if
112}
113
114// Local Variables: //
115// tab-width: 4 //
116// mode: c++ //
117// compile-command: "make install" //
118// End: //
Note: See TracBrowser for help on using the repository browser.