source: src/SynTree/FunctionDecl.cc@ 3f80888

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 with_gc
Last change on this file since 3f80888 was dd020c0, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

first attempt to create function specifiers

  • Property mode set to 100644
File size: 3.0 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
[dd020c0]12// Last Modified On : Fri Mar 3 21:29:41 2017
13// Update Count : 55
[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"
[13de47bc]24#include "CodeGen/FixMain.h"
[51b73452]25
[3fe34ae]26extern bool translation_unit_nomain;
27
[dd020c0]28FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, std::list< Attribute * > attributes, DeclarationNode::FuncSpec fs )
29 : Parent( name, sc, linkage, attributes, fs ), type( type ), statements( statements ) {
30 set_functionSpecifiers( fs );
31
32 // hack forcing the function "main" to have Cforall linkage to replace main even if it is inside an extern
[0dd3a2f]33 if ( name == "main" ) {
[13de47bc]34 set_linkage( CodeGen::FixMain::mainLinkage() );
[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;
[51b73452]45}
46
[c11e31c]47Type * FunctionDecl::get_type() const {
[0dd3a2f]48 return type;
[51b73452]49}
50
[c11e31c]51void FunctionDecl::set_type( Type *t ) {
[0dd3a2f]52 type = dynamic_cast< FunctionType* >( t );
53 assert( type );
[51b73452]54}
55
[c11e31c]56void FunctionDecl::print( std::ostream &os, int indent ) const {
[0dd3a2f]57 using std::endl;
58 using std::string;
[9243a501]59
[0dd3a2f]60 if ( get_name() != "" ) {
[5f2f2d7]61 os << get_name() << ": ";
[0dd3a2f]62 } // if
63 if ( get_linkage() != LinkageSpec::Cforall ) {
[faddbd8]64 os << LinkageSpec::linkageName( get_linkage() ) << " ";
[0dd3a2f]65 } // if
[7baed7d]66
[f9cebb5]67 printAll( get_attributes(), os, indent );
[7baed7d]68
[68cd1ce]69 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
[dd020c0]70 os << DeclarationNode::storageClassNames[ get_storageClass() ] << ' ';
[0dd3a2f]71 } // if
[dd020c0]72 DeclarationNode::print_FuncSpec( os, get_funcSpec() );
73
[0dd3a2f]74 if ( get_type() ) {
75 get_type()->print( os, indent );
76 } else {
77 os << "untyped entity ";
78 } // if
[843054c2]79
[0dd3a2f]80 if ( statements ) {
[de62360d]81 os << string( indent + 2, ' ' ) << "with body " << endl;
[9243a501]82 os << string( indent + 4, ' ' );
[de62360d]83 statements->print( os, indent + 4 );
[0dd3a2f]84 } // if
[51b73452]85}
86
[c11e31c]87void FunctionDecl::printShort( std::ostream &os, int indent ) const {
[0dd3a2f]88 using std::endl;
89 using std::string;
[9243a501]90
[0dd3a2f]91 if ( get_name() != "" ) {
[5f2f2d7]92 os << get_name() << ": ";
[0dd3a2f]93 } // if
[7baed7d]94
95 // xxx - should printShort print attributes?
96
[68cd1ce]97 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
[dd020c0]98 os << DeclarationNode::storageClassNames[ get_storageClass() ] << ' ';
[0dd3a2f]99 } // if
[dd020c0]100 DeclarationNode::print_FuncSpec( os, get_funcSpec() );
101
[0dd3a2f]102 if ( get_type() ) {
103 get_type()->print( os, indent );
104 } else {
105 os << "untyped entity ";
106 } // if
[51b73452]107}
[0dd3a2f]108
109// Local Variables: //
110// tab-width: 4 //
111// mode: c++ //
112// compile-command: "make install" //
113// End: //
Note: See TracBrowser for help on using the repository browser.