/*
 * This file is part of the Cforall project
 *
 * $Id: AggregateDecl.cc,v 1.7 2005/08/29 20:59:25 rcbilson Exp $
 *
 */

#include "Declaration.h"
#include "Type.h"
#include "utility.h"


AggregateDecl::AggregateDecl( const std::string &name )
    : Parent( name, Declaration::NoStorageClass, LinkageSpec::Cforall )
{
}

AggregateDecl::AggregateDecl( const AggregateDecl &other )
    : Parent( other )
{
    cloneAll( other.members, members );
    cloneAll( other.parameters, parameters );
}

AggregateDecl::~AggregateDecl()
{
    deleteAll( members );
    deleteAll( parameters );
}

void 
AggregateDecl::print( std::ostream &os, int indent ) const
{
    using std::string;
    using std::endl;

    os << typeString() << " " << get_name();
    if( !parameters.empty() ) {
	os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
	printAll( parameters, os, indent+4 );
    }
    if( !members.empty() ) {
	os << endl << string( indent+2, ' ' ) << "with members" << endl;
	printAll( members, os, indent+4 );
    }
}

void 
AggregateDecl::printShort( std::ostream &os, int indent ) const
{
    using std::string;
    using std::endl;

    os << typeString() << " " << get_name();
    if( !parameters.empty() ) {
	os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
	printAll( parameters, os, indent+4 );
    }
}

std::string StructDecl::typeString() const { return "struct"; }

std::string UnionDecl::typeString() const { return "union"; }

std::string EnumDecl::typeString() const { return "enum"; }

std::string ContextDecl::typeString() const { return "context"; }

