source: src/SynTree/FunctionDecl.cc @ 1e6b350

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 1e6b350 was 3a5131ed, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

handle KR function declarations

  • Property mode set to 100644
File size: 3.1 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
[3a5131ed]12// Last Modified On : Thu Feb 16 15:01:52 2017
13// Update Count     : 23
[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;
[51b7345]46}
47
[c11e31c]48Type * FunctionDecl::get_type() const {
[0dd3a2f]49        return type;
[51b7345]50}
51
[c11e31c]52void FunctionDecl::set_type( Type *t ) {
[0dd3a2f]53        type = dynamic_cast< FunctionType* >( t );
54        assert( type );
[51b7345]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 ( statements ) {
[de62360d]86                os << string( indent + 2, ' ' ) << "with body " << endl;
[9243a501]87                os << string( indent + 4, ' ' );
[de62360d]88                statements->print( os, indent + 4 );
[0dd3a2f]89        } // if
[51b7345]90}
91
[c11e31c]92void FunctionDecl::printShort( std::ostream &os, int indent ) const {
[0dd3a2f]93        using std::endl;
94        using std::string;
[9243a501]95
[0dd3a2f]96        if ( get_name() != "" ) {
[5f2f2d7]97                os << get_name() << ": ";
[0dd3a2f]98        } // if
[1db21619]99        if ( get_isInline() ) {
[0dd3a2f]100                os << "inline ";
101        } // if
[1db21619]102        if ( get_isNoreturn() ) {
[de62360d]103                os << "_Noreturn ";
104        } // if
[7baed7d]105
106        // xxx - should printShort print attributes?
107
[68cd1ce]108        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
109                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
[0dd3a2f]110        } // if
111        if ( get_type() ) {
112                get_type()->print( os, indent );
113        } else {
114                os << "untyped entity ";
115        } // if
[51b7345]116}
[0dd3a2f]117
118// Local Variables: //
119// tab-width: 4 //
120// mode: c++ //
121// compile-command: "make install" //
122// End: //
Note: See TracBrowser for help on using the repository browser.