[51b7345] | 1 | #include "Declaration.h" |
---|
| 2 | #include "Type.h" |
---|
| 3 | #include "utility.h" |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | NamedTypeDecl::NamedTypeDecl( const std::string &name, StorageClass sc, Type *base ) |
---|
| 7 | : Parent( name, sc, LinkageSpec::Cforall ), base( base ) |
---|
[17cd4eb] | 8 | {} |
---|
[51b7345] | 9 | |
---|
| 10 | NamedTypeDecl::NamedTypeDecl( const TypeDecl &other ) |
---|
| 11 | : Parent( other ), base( maybeClone( other.base ) ) |
---|
| 12 | { |
---|
| 13 | cloneAll( other.parameters, parameters ); |
---|
| 14 | cloneAll( other.assertions, assertions ); |
---|
| 15 | } |
---|
| 16 | |
---|
[17cd4eb] | 17 | NamedTypeDecl::~NamedTypeDecl() { |
---|
[51b7345] | 18 | delete base; |
---|
| 19 | deleteAll( parameters ); |
---|
| 20 | deleteAll( assertions ); |
---|
| 21 | } |
---|
| 22 | |
---|
[17cd4eb] | 23 | void NamedTypeDecl::print( std::ostream &os, int indent ) const { |
---|
[51b7345] | 24 | using namespace std; |
---|
| 25 | |
---|
[17cd4eb] | 26 | if ( get_name() != "" ) { |
---|
[51b7345] | 27 | os << get_name() << ": a "; |
---|
[17cd4eb] | 28 | } // if |
---|
| 29 | if ( get_storageClass() != NoStorageClass ) { |
---|
[51b7345] | 30 | os << storageClassName[ get_storageClass() ] << ' '; |
---|
[17cd4eb] | 31 | } // if |
---|
[51b7345] | 32 | os << typeString(); |
---|
[17cd4eb] | 33 | if ( base ) { |
---|
[51b7345] | 34 | os << " for "; |
---|
| 35 | base->print( os, indent ); |
---|
[17cd4eb] | 36 | } // if |
---|
| 37 | if ( !parameters.empty() ) { |
---|
[51b7345] | 38 | os << endl << string( indent, ' ' ) << "with parameters" << endl; |
---|
| 39 | printAll( parameters, os, indent+2 ); |
---|
[17cd4eb] | 40 | } // if |
---|
| 41 | if ( !assertions.empty() ) { |
---|
[51b7345] | 42 | os << endl << string( indent, ' ' ) << "with assertions" << endl; |
---|
| 43 | printAll( assertions, os, indent+2 ); |
---|
[17cd4eb] | 44 | } // if |
---|
[51b7345] | 45 | } |
---|
| 46 | |
---|
[17cd4eb] | 47 | void NamedTypeDecl::printShort( std::ostream &os, int indent ) const { |
---|
[51b7345] | 48 | using namespace std; |
---|
| 49 | |
---|
[17cd4eb] | 50 | if ( get_name() != "" ) { |
---|
[51b7345] | 51 | os << get_name() << ": a "; |
---|
[17cd4eb] | 52 | } // if |
---|
| 53 | if ( get_storageClass() != NoStorageClass ) { |
---|
[51b7345] | 54 | os << storageClassName[ get_storageClass() ] << ' '; |
---|
[17cd4eb] | 55 | } // if |
---|
[51b7345] | 56 | os << typeString(); |
---|
[17cd4eb] | 57 | if ( base ) { |
---|
[51b7345] | 58 | os << " for "; |
---|
| 59 | base->print( os, indent ); |
---|
[17cd4eb] | 60 | } // if |
---|
| 61 | if ( !parameters.empty() ) { |
---|
[51b7345] | 62 | os << endl << string( indent, ' ' ) << "with parameters" << endl; |
---|
| 63 | printAll( parameters, os, indent+2 ); |
---|
[17cd4eb] | 64 | } // if |
---|
[51b7345] | 65 | } |
---|
| 66 | |
---|
| 67 | std::string TypedefDecl::typeString() const { return "typedef"; } |
---|