/* * This file is part of the Cforall project * * $Id: FunctionDecl.cc,v 1.15 2005/08/29 20:59:25 rcbilson Exp $ * */ #include #include "Declaration.h" #include "Statement.h" #include "Type.h" #include "utility.h" FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ) : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) { // this is a pretty brazen hack to force the function "main" to have C linkage if( name == "main" ) { set_linkage( LinkageSpec::C ); } } FunctionDecl::FunctionDecl( const FunctionDecl &other ) : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) { } FunctionDecl::~FunctionDecl() { delete type; delete statements; } Type* FunctionDecl::get_type() const { return type; } void FunctionDecl::set_type(Type *t) { type = dynamic_cast< FunctionType* >( t ); assert( type ); } void FunctionDecl::print( std::ostream &os, int indent ) const { using std::endl; using std::string; if( get_name() != "" ) { os << get_name() << ": a "; } if( get_linkage() != LinkageSpec::Cforall ) { os << LinkageSpec::toString( get_linkage() ) << " "; } if( isInline ) { os << "inline "; } if( get_storageClass() != NoStorageClass ) { os << storageClassName[ get_storageClass() ] << ' '; } if( get_type() ) { get_type()->print( os, indent ); } else { os << "untyped entity "; } if( !oldIdents.empty() ) { os << string( indent+2, ' ' ) << "with parameter names" << endl; for( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) { os << string( indent+4, ' ' ) << *i << endl; } } if( !oldDecls.empty() ) { os << string( indent+2, ' ' ) << "with parameter declarations" << endl; printAll( oldDecls, os, indent+4 ); } if( statements ) { os << string( indent+2, ' ' ) << "with body " << endl; statements->print( os, indent+4 ); } } void FunctionDecl::printShort( std::ostream &os, int indent ) const { using std::endl; using std::string; if( get_name() != "" ) { os << get_name() << ": a "; } if( isInline ) { os << "inline "; } if( get_storageClass() != NoStorageClass ) { os << storageClassName[ get_storageClass() ] << ' '; } if( get_type() ) { get_type()->print( os, indent ); } else { os << "untyped entity "; } }