Changeset c11e31c for translator/SynTree/FunctionDecl.cc
- Timestamp:
- May 14, 2015, 1:44:55 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 4bf5298
- Parents:
- d4778a6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/FunctionDecl.cc
rd4778a6 rc11e31c 1 /*2 * This file is part of the Cforall project3 *4 * $Id: FunctionDecl.cc,v 1.15 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 … … 14 7 15 8 16 FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, 17 CompoundStmt *statements, bool isInline ) 18 : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) 19 { 20 // this is a pretty brazen hack to force the function "main" to have C linkage 21 if( name == "main" ) { 9 FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ) 10 : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) { 11 // this is a brazen hack to force the function "main" to have C linkage 12 if ( name == "main" ) { 22 13 set_linkage( LinkageSpec::C ); 23 14 } … … 25 16 26 17 FunctionDecl::FunctionDecl( const FunctionDecl &other ) 27 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), 28 isInline( other.isInline ) 29 { 18 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) { 30 19 } 31 20 32 FunctionDecl::~FunctionDecl() 33 { 21 FunctionDecl::~FunctionDecl() { 34 22 delete type; 35 23 delete statements; 36 24 } 37 25 38 Type* 39 FunctionDecl::get_type() const 40 { 26 Type * FunctionDecl::get_type() const { 41 27 return type; 42 28 } 43 29 44 void 45 FunctionDecl::set_type(Type *t) 46 { 30 void FunctionDecl::set_type( Type *t ) { 47 31 type = dynamic_cast< FunctionType* >( t ); 48 32 assert( type ); 49 33 } 50 34 51 void 52 FunctionDecl::print( std::ostream &os, int indent ) const 53 { 35 void FunctionDecl::print( std::ostream &os, int indent ) const { 54 36 using std::endl; 55 37 using std::string; 56 38 57 if ( get_name() != "" ) {39 if ( get_name() != "" ) { 58 40 os << get_name() << ": a "; 59 41 } 60 if ( get_linkage() != LinkageSpec::Cforall ) {42 if ( get_linkage() != LinkageSpec::Cforall ) { 61 43 os << LinkageSpec::toString( get_linkage() ) << " "; 62 44 } 63 if ( isInline ) {45 if ( isInline ) { 64 46 os << "inline "; 65 47 } 66 if ( get_storageClass() != NoStorageClass ) {48 if ( get_storageClass() != NoStorageClass ) { 67 49 os << storageClassName[ get_storageClass() ] << ' '; 68 50 } 69 if ( get_type() ) {51 if ( get_type() ) { 70 52 get_type()->print( os, indent ); 71 53 } else { 72 54 os << "untyped entity "; 73 55 } 74 if ( !oldIdents.empty() ) {56 if ( ! oldIdents.empty() ) { 75 57 os << string( indent+2, ' ' ) << "with parameter names" << endl; 76 58 for( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) { … … 78 60 } 79 61 } 80 if ( !oldDecls.empty() ) {62 if ( ! oldDecls.empty() ) { 81 63 os << string( indent+2, ' ' ) << "with parameter declarations" << endl; 82 64 printAll( oldDecls, os, indent+4 ); 83 65 } 84 if ( statements ) {66 if ( statements ) { 85 67 os << string( indent+2, ' ' ) << "with body " << endl; 86 68 statements->print( os, indent+4 ); … … 88 70 } 89 71 90 void 91 FunctionDecl::printShort( std::ostream &os, int indent ) const 92 { 72 void FunctionDecl::printShort( std::ostream &os, int indent ) const { 93 73 using std::endl; 94 74 using std::string; 95 75 96 if ( get_name() != "" ) {76 if ( get_name() != "" ) { 97 77 os << get_name() << ": a "; 98 78 } 99 if ( isInline ) {79 if ( isInline ) { 100 80 os << "inline "; 101 81 } 102 if ( get_storageClass() != NoStorageClass ) {82 if ( get_storageClass() != NoStorageClass ) { 103 83 os << storageClassName[ get_storageClass() ] << ' '; 104 84 } 105 if ( get_type() ) {85 if ( get_type() ) { 106 86 get_type()->print( os, indent ); 107 87 } else { … … 109 89 } 110 90 } 111
Note: See TracChangeset
for help on using the changeset viewer.