| 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 )
|
|---|
| 8 | {}
|
|---|
| 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 |
|
|---|
| 17 | NamedTypeDecl::~NamedTypeDecl() {
|
|---|
| 18 | delete base;
|
|---|
| 19 | deleteAll( parameters );
|
|---|
| 20 | deleteAll( assertions );
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | void NamedTypeDecl::print( std::ostream &os, int indent ) const {
|
|---|
| 24 | using namespace std;
|
|---|
| 25 |
|
|---|
| 26 | if ( get_name() != "" ) {
|
|---|
| 27 | os << get_name() << ": a ";
|
|---|
| 28 | } // if
|
|---|
| 29 | if ( get_storageClass() != NoStorageClass ) {
|
|---|
| 30 | os << storageClassName[ get_storageClass() ] << ' ';
|
|---|
| 31 | } // if
|
|---|
| 32 | os << typeString();
|
|---|
| 33 | if ( base ) {
|
|---|
| 34 | os << " for ";
|
|---|
| 35 | base->print( os, indent );
|
|---|
| 36 | } // if
|
|---|
| 37 | if ( !parameters.empty() ) {
|
|---|
| 38 | os << endl << string( indent, ' ' ) << "with parameters" << endl;
|
|---|
| 39 | printAll( parameters, os, indent+2 );
|
|---|
| 40 | } // if
|
|---|
| 41 | if ( !assertions.empty() ) {
|
|---|
| 42 | os << endl << string( indent, ' ' ) << "with assertions" << endl;
|
|---|
| 43 | printAll( assertions, os, indent+2 );
|
|---|
| 44 | } // if
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void NamedTypeDecl::printShort( std::ostream &os, int indent ) const {
|
|---|
| 48 | using namespace std;
|
|---|
| 49 |
|
|---|
| 50 | if ( get_name() != "" ) {
|
|---|
| 51 | os << get_name() << ": a ";
|
|---|
| 52 | } // if
|
|---|
| 53 | if ( get_storageClass() != NoStorageClass ) {
|
|---|
| 54 | os << storageClassName[ get_storageClass() ] << ' ';
|
|---|
| 55 | } // if
|
|---|
| 56 | os << typeString();
|
|---|
| 57 | if ( base ) {
|
|---|
| 58 | os << " for ";
|
|---|
| 59 | base->print( os, indent );
|
|---|
| 60 | } // if
|
|---|
| 61 | if ( !parameters.empty() ) {
|
|---|
| 62 | os << endl << string( indent, ' ' ) << "with parameters" << endl;
|
|---|
| 63 | printAll( parameters, os, indent+2 );
|
|---|
| 64 | } // if
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | std::string TypedefDecl::typeString() const { return "typedef"; }
|
|---|