source: src/SynTree/FunctionDecl.cc @ 7a560c1

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 7a560c1 was 13de47bc, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Proper bootloader boilerplate implemented

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