source: src/SynTree/FunctionDecl.cc@ 981bdc6

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 stuck-waitfor-destruct with_gc
Last change on this file since 981bdc6 was 3fe34ae, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Added bootloader.cf which contains the main that wraps the user main

  • Property mode set to 100644
File size: 3.6 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
[8b7ee09]11// Last Modified By : Peter A. Buhr
[faddbd8]12// Last Modified On : Sat Oct 1 23:06:32 2016
13// Update Count : 21
[0dd3a2f]14//
15
[51b73452]16#include <cassert>
17
18#include "Declaration.h"
19#include "Statement.h"
20#include "Type.h"
[7baed7d]21#include "Attribute.h"
[d3b7937]22#include "Common/utility.h"
[4d4882a]23#include "InitTweak/InitTweak.h"
[51b73452]24
[3fe34ae]25extern bool translation_unit_nomain;
26
[8b7ee09]27FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
[f9cebb5]28 : Parent( name, sc, linkage, attributes ), type( type ), statements( statements ) {
[1db21619]29 set_isInline( isInline );
30 set_isNoreturn( isNoreturn );
[0270824]31 // this is a brazen hack to force the function "main" to have Cforall linkage
32 // because we want to replace the main even if it is inside an extern
[0dd3a2f]33 if ( name == "main" ) {
[3fe34ae]34 set_linkage( translation_unit_nomain ? LinkageSpec::C : LinkageSpec::Cforall );
[0dd3a2f]35 } // if
[51b73452]36}
37
38FunctionDecl::FunctionDecl( const FunctionDecl &other )
[7baed7d]39 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
[51b73452]40}
41
[c11e31c]42FunctionDecl::~FunctionDecl() {
[0dd3a2f]43 delete type;
44 delete statements;
[2037f82]45 deleteAll( oldDecls );
[51b73452]46}
47
[c11e31c]48Type * FunctionDecl::get_type() const {
[0dd3a2f]49 return type;
[51b73452]50}
51
[c11e31c]52void FunctionDecl::set_type( Type *t ) {
[0dd3a2f]53 type = dynamic_cast< FunctionType* >( t );
54 assert( type );
[51b73452]55}
56
[c11e31c]57void FunctionDecl::print( std::ostream &os, int indent ) const {
[0dd3a2f]58 using std::endl;
59 using std::string;
[9243a501]60
[0dd3a2f]61 if ( get_name() != "" ) {
[5f2f2d7]62 os << get_name() << ": ";
[0dd3a2f]63 } // if
64 if ( get_linkage() != LinkageSpec::Cforall ) {
[faddbd8]65 os << LinkageSpec::linkageName( get_linkage() ) << " ";
[0dd3a2f]66 } // if
[1db21619]67 if ( get_isInline() ) {
[0dd3a2f]68 os << "inline ";
69 } // if
[1db21619]70 if ( get_isNoreturn() ) {
[de62360d]71 os << "_Noreturn ";
72 } // if
[7baed7d]73
[f9cebb5]74 printAll( get_attributes(), os, indent );
[7baed7d]75
[68cd1ce]76 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
77 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
[0dd3a2f]78 } // if
79 if ( get_type() ) {
80 get_type()->print( os, indent );
81 } else {
82 os << "untyped entity ";
83 } // if
[843054c2]84
[0dd3a2f]85 if ( ! oldIdents.empty() ) {
[de62360d]86 os << string( indent + 2, ' ' ) << "with parameter names" << endl;
[0dd3a2f]87 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
[de62360d]88 os << string( indent + 4, ' ' ) << *i << endl;
[0dd3a2f]89 } // for
90 } // if
[843054c2]91
[0dd3a2f]92 if ( ! oldDecls.empty() ) {
[de62360d]93 os << string( indent + 2, ' ' ) << "with parameter declarations" << endl;
94 printAll( oldDecls, os, indent + 4 );
[0dd3a2f]95 } // if
96 if ( statements ) {
[de62360d]97 os << string( indent + 2, ' ' ) << "with body " << endl;
[9243a501]98 os << string( indent + 4, ' ' );
[de62360d]99 statements->print( os, indent + 4 );
[0dd3a2f]100 } // if
[51b73452]101}
102
[c11e31c]103void FunctionDecl::printShort( std::ostream &os, int indent ) const {
[0dd3a2f]104 using std::endl;
105 using std::string;
[9243a501]106
[0dd3a2f]107 if ( get_name() != "" ) {
[5f2f2d7]108 os << get_name() << ": ";
[0dd3a2f]109 } // if
[1db21619]110 if ( get_isInline() ) {
[0dd3a2f]111 os << "inline ";
112 } // if
[1db21619]113 if ( get_isNoreturn() ) {
[de62360d]114 os << "_Noreturn ";
115 } // if
[7baed7d]116
117 // xxx - should printShort print attributes?
118
[68cd1ce]119 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
120 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
[0dd3a2f]121 } // if
122 if ( get_type() ) {
123 get_type()->print( os, indent );
124 } else {
125 os << "untyped entity ";
126 } // if
[51b73452]127}
[0dd3a2f]128
129// Local Variables: //
130// tab-width: 4 //
131// mode: c++ //
132// compile-command: "make install" //
133// End: //
Note: See TracBrowser for help on using the repository browser.