source: src/SynTree/FunctionDecl.cc@ a1d6d80

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 with_gc
Last change on this file since a1d6d80 was 9243a501, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

fixed printing in MemberExpr, FunctionDecl, ObjectDecl, etc.

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