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

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 7bd1bb5 was ddfd945, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

move type FuncSpecifiers? from DeclarationNode? to Type

  • Property mode set to 100644
File size: 2.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
[ddfd945]12// Last Modified On : Thu Mar 16 08:33:41 2017
13// Update Count     : 74
[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
[ddfd945]28FunctionDecl::FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, std::list< Attribute * > attributes, Type::FuncSpecifiers fs )
[a7c90d4]29        : Parent( name, scs, linkage, attributes, fs ), type( type ), statements( statements ) {
[dd020c0]30        // hack forcing the function "main" to have Cforall linkage to replace main even if it is inside an extern
[0dd3a2f]31        if ( name == "main" ) {
[13de47bc]32                set_linkage( CodeGen::FixMain::mainLinkage() );
[0dd3a2f]33        } // if
[51b7345]34}
35
36FunctionDecl::FunctionDecl( const FunctionDecl &other )
[a7c90d4]37                : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
[51b7345]38}
39
[c11e31c]40FunctionDecl::~FunctionDecl() {
[0dd3a2f]41        delete type;
42        delete statements;
[51b7345]43}
44
[c11e31c]45Type * FunctionDecl::get_type() const {
[0dd3a2f]46        return type;
[51b7345]47}
48
[c11e31c]49void FunctionDecl::set_type( Type *t ) {
[0dd3a2f]50        type = dynamic_cast< FunctionType* >( t );
51        assert( type );
[51b7345]52}
53
[c11e31c]54void FunctionDecl::print( std::ostream &os, int indent ) const {
[0dd3a2f]55        using std::endl;
56        using std::string;
[9243a501]57
[0dd3a2f]58        if ( get_name() != "" ) {
[5f2f2d7]59                os << get_name() << ": ";
[0dd3a2f]60        } // if
61        if ( get_linkage() != LinkageSpec::Cforall ) {
[faddbd8]62                os << LinkageSpec::linkageName( get_linkage() ) << " ";
[0dd3a2f]63        } // if
[7baed7d]64
[f9cebb5]65        printAll( get_attributes(), os, indent );
[7baed7d]66
[6e8bd43]67        get_storageClasses().print( os );
68        get_funcSpec().print( os );
[dd020c0]69
[0dd3a2f]70        if ( get_type() ) {
71                get_type()->print( os, indent );
72        } else {
73                os << "untyped entity ";
74        } // if
[843054c2]75
[0dd3a2f]76        if ( statements ) {
[de62360d]77                os << string( indent + 2, ' ' ) << "with body " << endl;
[9243a501]78                os << string( indent + 4, ' ' );
[de62360d]79                statements->print( os, indent + 4 );
[0dd3a2f]80        } // if
[51b7345]81}
82
[c11e31c]83void FunctionDecl::printShort( std::ostream &os, int indent ) const {
[0dd3a2f]84        using std::endl;
85        using std::string;
[9243a501]86
[0dd3a2f]87        if ( get_name() != "" ) {
[5f2f2d7]88                os << get_name() << ": ";
[0dd3a2f]89        } // if
[7baed7d]90
91        // xxx - should printShort print attributes?
92
[6e8bd43]93        get_storageClasses().print( os );
94        get_funcSpec().print( os );
[dd020c0]95
[0dd3a2f]96        if ( get_type() ) {
97                get_type()->print( os, indent );
98        } else {
99                os << "untyped entity ";
100        } // if
[51b7345]101}
[0dd3a2f]102
103// Local Variables: //
104// tab-width: 4 //
105// mode: c++ //
106// compile-command: "make install" //
107// End: //
Note: See TracBrowser for help on using the repository browser.