| 1 | #include "Declaration.h"
|
|---|
| 2 | #include "Type.h"
|
|---|
| 3 | #include "Initializer.h"
|
|---|
| 4 | #include "Expression.h"
|
|---|
| 5 | #include "utility.h"
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | ObjectDecl::ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init )
|
|---|
| 9 | : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | ObjectDecl::ObjectDecl( const ObjectDecl &other )
|
|---|
| 13 | : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | ObjectDecl::~ObjectDecl() {
|
|---|
| 17 | delete type;
|
|---|
| 18 | delete init;
|
|---|
| 19 | delete bitfieldWidth;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | void ObjectDecl::print( std::ostream &os, int indent ) const {
|
|---|
| 23 | if ( get_name() != "" ) {
|
|---|
| 24 | os << get_name() << ": a ";
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | if ( get_linkage() != LinkageSpec::Cforall ) {
|
|---|
| 28 | os << LinkageSpec::toString( get_linkage() ) << " ";
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | if ( get_storageClass() != NoStorageClass ) {
|
|---|
| 32 | os << storageClassName[ get_storageClass() ] << ' ';
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | if ( get_type() ) {
|
|---|
| 36 | get_type()->print( os, indent );
|
|---|
| 37 | } else {
|
|---|
| 38 | os << "untyped entity ";
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | if ( init ) {
|
|---|
| 42 | os << "with initializer ";
|
|---|
| 43 | init->print( os, indent );
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | if ( bitfieldWidth ) {
|
|---|
| 47 | os << "with bitfield width ";
|
|---|
| 48 | bitfieldWidth->print( os );
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | void ObjectDecl::printShort( std::ostream &os, int indent ) const {
|
|---|
| 53 | if ( get_name() != "" ) {
|
|---|
| 54 | os << get_name() << ": a ";
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | if ( get_storageClass() != NoStorageClass ) {
|
|---|
| 58 | os << storageClassName[ get_storageClass() ] << ' ';
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | if ( get_type() ) {
|
|---|
| 62 | get_type()->print( os, indent );
|
|---|
| 63 | } else {
|
|---|
| 64 | os << "untyped entity ";
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | if ( bitfieldWidth ) {
|
|---|
| 68 | os << "with bitfield width ";
|
|---|
| 69 | bitfieldWidth->print( os );
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|