Changeset 0dd3a2f for translator/SynTree/FunctionDecl.cc
- Timestamp:
- May 18, 2015, 11:20:23 AM (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:
- 51587aa
- Parents:
- a32b204
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/FunctionDecl.cc
ra32b204 r0dd3a2f 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 // 7 // FunctionDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:48:46 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 17 … … 6 21 #include "utility.h" 7 22 8 9 23 FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ) 10 24 : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) { 11 12 13 set_linkage( LinkageSpec::C );14 } 25 // this is a brazen hack to force the function "main" to have C linkage 26 if ( name == "main" ) { 27 set_linkage( LinkageSpec::C ); 28 } // if 15 29 } 16 30 17 31 FunctionDecl::FunctionDecl( const FunctionDecl &other ) 18 32 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) { 19 33 } 20 34 21 35 FunctionDecl::~FunctionDecl() { 22 23 36 delete type; 37 delete statements; 24 38 } 25 39 26 40 Type * FunctionDecl::get_type() const { 27 41 return type; 28 42 } 29 43 30 44 void FunctionDecl::set_type( Type *t ) { 31 32 45 type = dynamic_cast< FunctionType* >( t ); 46 assert( type ); 33 47 } 34 48 35 49 void FunctionDecl::print( std::ostream &os, int indent ) const { 36 37 38 39 40 os << get_name() << ": a ";41 } 42 43 os << LinkageSpec::toString( get_linkage() ) << " ";44 } 45 46 os << "inline ";47 } 48 49 os << storageClassName[ get_storageClass() ] << ' ';50 } 51 52 get_type()->print( os, indent );53 54 os << "untyped entity ";55 } 56 57 os << string( indent+2, ' ' ) << "with parameter names" << endl;58 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {59 60 }61 } 62 63 os << string( indent+2, ' ' ) << "with parameter declarations" << endl;64 printAll( oldDecls, os, indent+4 );65 } 66 67 os << string( indent+2, ' ' ) << "with body " << endl;68 statements->print( os, indent+4 );69 } 50 using std::endl; 51 using std::string; 52 53 if ( get_name() != "" ) { 54 os << get_name() << ": a "; 55 } // if 56 if ( get_linkage() != LinkageSpec::Cforall ) { 57 os << LinkageSpec::toString( get_linkage() ) << " "; 58 } // if 59 if ( isInline ) { 60 os << "inline "; 61 } // if 62 if ( get_storageClass() != NoStorageClass ) { 63 os << storageClassName[ get_storageClass() ] << ' '; 64 } // if 65 if ( get_type() ) { 66 get_type()->print( os, indent ); 67 } else { 68 os << "untyped entity "; 69 } // if 70 if ( ! oldIdents.empty() ) { 71 os << string( indent+2, ' ' ) << "with parameter names" << endl; 72 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) { 73 os << string( indent+4, ' ' ) << *i << endl; 74 } // for 75 } // if 76 if ( ! oldDecls.empty() ) { 77 os << string( indent+2, ' ' ) << "with parameter declarations" << endl; 78 printAll( oldDecls, os, indent+4 ); 79 } // if 80 if ( statements ) { 81 os << string( indent+2, ' ' ) << "with body " << endl; 82 statements->print( os, indent+4 ); 83 } // if 70 84 } 71 85 72 86 void FunctionDecl::printShort( std::ostream &os, int indent ) const { 73 74 75 76 77 os << get_name() << ": a ";78 } 79 80 os << "inline ";81 } 82 83 os << storageClassName[ get_storageClass() ] << ' ';84 } 85 86 get_type()->print( os, indent );87 88 os << "untyped entity ";89 } 87 using std::endl; 88 using std::string; 89 90 if ( get_name() != "" ) { 91 os << get_name() << ": a "; 92 } // if 93 if ( isInline ) { 94 os << "inline "; 95 } // if 96 if ( get_storageClass() != NoStorageClass ) { 97 os << storageClassName[ get_storageClass() ] << ' '; 98 } // if 99 if ( get_type() ) { 100 get_type()->print( os, indent ); 101 } else { 102 os << "untyped entity "; 103 } // if 90 104 } 105 106 // Local Variables: // 107 // tab-width: 4 // 108 // mode: c++ // 109 // compile-command: "make install" // 110 // End: //
Note: See TracChangeset
for help on using the changeset viewer.