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