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