source: src/SynTree/FunctionDecl.cc @ 75626a1

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 75626a1 was 75626a1, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Add newFunction helper to FunctionDecl?

  • 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
[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
[ea6332d]16#include <cassert>               // for assert
17#include <list>                  // for list
18#include <ostream>               // for operator<<, ostream, basic_ostream
19#include <string>                // for operator<<, string, char_traits, ope...
[51b7345]20
[ea6332d]21#include "Attribute.h"           // for Attribute
22#include "CodeGen/FixMain.h"     // for FixMain
23#include "Common/utility.h"      // for maybeClone, printAll
24#include "Declaration.h"         // for FunctionDecl, FunctionDecl::Parent
25#include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
26#include "Statement.h"           // for CompoundStmt
27#include "Type.h"                // for Type, FunctionType, Type::FuncSpecif...
[51b7345]28
[3fe34ae]29extern bool translation_unit_nomain;
30
[ddfd945]31FunctionDecl::FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, std::list< Attribute * > attributes, Type::FuncSpecifiers fs )
[a7c90d4]32        : Parent( name, scs, linkage, attributes, fs ), type( type ), statements( statements ) {
[dd020c0]33        // hack forcing the function "main" to have Cforall linkage to replace 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 )
[a7c90d4]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
[75626a1]48FunctionDecl * FunctionDecl::newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements ) {
49        return new FunctionDecl( name, Type::StorageClasses(), LinkageSpec::C, type, statements );
50}
51
[c11e31c]52void FunctionDecl::print( std::ostream &os, int indent ) const {
[0dd3a2f]53        using std::endl;
54        using std::string;
[9243a501]55
[0dd3a2f]56        if ( get_name() != "" ) {
[5f2f2d7]57                os << get_name() << ": ";
[0dd3a2f]58        } // if
59        if ( get_linkage() != LinkageSpec::Cforall ) {
[faddbd8]60                os << LinkageSpec::linkageName( get_linkage() ) << " ";
[0dd3a2f]61        } // if
[7baed7d]62
[f9cebb5]63        printAll( get_attributes(), os, indent );
[7baed7d]64
[6e8bd43]65        get_storageClasses().print( os );
66        get_funcSpec().print( os );
[dd020c0]67
[0dd3a2f]68        if ( get_type() ) {
69                get_type()->print( os, indent );
70        } else {
71                os << "untyped entity ";
72        } // if
[843054c2]73
[0dd3a2f]74        if ( statements ) {
[de62360d]75                os << string( indent + 2, ' ' ) << "with body " << endl;
[9243a501]76                os << string( indent + 4, ' ' );
[de62360d]77                statements->print( os, indent + 4 );
[0dd3a2f]78        } // if
[51b7345]79}
80
[c11e31c]81void FunctionDecl::printShort( std::ostream &os, int indent ) const {
[0dd3a2f]82        using std::endl;
83        using std::string;
[9243a501]84
[0dd3a2f]85        if ( get_name() != "" ) {
[5f2f2d7]86                os << get_name() << ": ";
[0dd3a2f]87        } // if
[7baed7d]88
89        // xxx - should printShort print attributes?
90
[6e8bd43]91        get_storageClasses().print( os );
92        get_funcSpec().print( os );
[dd020c0]93
[0dd3a2f]94        if ( get_type() ) {
95                get_type()->print( os, indent );
96        } else {
97                os << "untyped entity ";
98        } // if
[51b7345]99}
[0dd3a2f]100
101// Local Variables: //
102// tab-width: 4 //
103// mode: c++ //
104// compile-command: "make install" //
105// End: //
Note: See TracBrowser for help on using the repository browser.