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
RevLine 
[0dd3a2f]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
[de62360d]12// Last Modified On : Sat Jun 13 09:10:32 2015
13// Update Count : 16
[0dd3a2f]14//
15
[51b73452]16#include <cassert>
17
18#include "Declaration.h"
19#include "Statement.h"
20#include "Type.h"
21#include "utility.h"
22
[de62360d]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 ) {
[0dd3a2f]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
[51b73452]29}
30
31FunctionDecl::FunctionDecl( const FunctionDecl &other )
[de62360d]32 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ), isNoreturn( other.isNoreturn ) {
[51b73452]33}
34
[c11e31c]35FunctionDecl::~FunctionDecl() {
[0dd3a2f]36 delete type;
37 delete statements;
[51b73452]38}
39
[c11e31c]40Type * FunctionDecl::get_type() const {
[0dd3a2f]41 return type;
[51b73452]42}
43
[c11e31c]44void FunctionDecl::set_type( Type *t ) {
[0dd3a2f]45 type = dynamic_cast< FunctionType* >( t );
46 assert( type );
[51b73452]47}
48
[c11e31c]49void FunctionDecl::print( std::ostream &os, int indent ) const {
[0dd3a2f]50 using std::endl;
51 using std::string;
52
53 if ( get_name() != "" ) {
[5f2f2d7]54 os << get_name() << ": ";
[0dd3a2f]55 } // if
56 if ( get_linkage() != LinkageSpec::Cforall ) {
57 os << LinkageSpec::toString( get_linkage() ) << " ";
58 } // if
59 if ( isInline ) {
60 os << "inline ";
61 } // if
[de62360d]62 if ( isNoreturn ) {
63 os << "_Noreturn ";
64 } // if
[68cd1ce]65 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
66 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
[0dd3a2f]67 } // if
68 if ( get_type() ) {
69 get_type()->print( os, indent );
70 } else {
71 os << "untyped entity ";
72 } // if
[843054c2]73
[0dd3a2f]74 if ( ! oldIdents.empty() ) {
[de62360d]75 os << string( indent + 2, ' ' ) << "with parameter names" << endl;
[0dd3a2f]76 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
[de62360d]77 os << string( indent + 4, ' ' ) << *i << endl;
[0dd3a2f]78 } // for
79 } // if
[843054c2]80
[0dd3a2f]81 if ( ! oldDecls.empty() ) {
[de62360d]82 os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
83 printAll( oldDecls, os, indent + 4 );
[0dd3a2f]84 } // if
85 if ( statements ) {
[de62360d]86 os << string( indent + 2, ' ' ) << "with body " << endl;
87 statements->print( os, indent + 4 );
[0dd3a2f]88 } // if
[51b73452]89}
90
[c11e31c]91void FunctionDecl::printShort( std::ostream &os, int indent ) const {
[0dd3a2f]92 using std::endl;
93 using std::string;
94
95 if ( get_name() != "" ) {
[5f2f2d7]96 os << get_name() << ": ";
[0dd3a2f]97 } // if
98 if ( isInline ) {
99 os << "inline ";
100 } // if
[de62360d]101 if ( isNoreturn ) {
102 os << "_Noreturn ";
103 } // if
[68cd1ce]104 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
105 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
[0dd3a2f]106 } // if
107 if ( get_type() ) {
108 get_type()->print( os, indent );
109 } else {
110 os << "untyped entity ";
111 } // if
[51b73452]112}
[0dd3a2f]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.