/* * This file is part of the Cforall project * * $Id: ReferenceToType.cc,v 1.16 2005/08/29 20:59:26 rcbilson Exp $ * */ #include #include #include "Type.h" #include "Declaration.h" #include "Expression.h" #include "TypeSubstitution.h" #include "utility.h" ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) { } ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) { cloneAll( other.parameters, parameters ); } ReferenceToType::~ReferenceToType() { deleteAll( parameters ); } void ReferenceToType::print( std::ostream &os, int indent ) const { using std::endl; Type::print( os, indent ); os << "instance of " << typeString() << " " << name << " "; if( !parameters.empty() ) { os << endl << std::string( indent, ' ' ) << "with parameters" << endl; printAll( parameters, os, indent+2 ); } } namespace { void doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) { std::list< Declaration* > found; for( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { if( (*i)->get_name() == name ) { found.push_back( *i ); } } applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) ); } } // namespace std::string StructInstType::typeString() const { return "struct"; } void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { assert( baseStruct ); doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls ); } std::string UnionInstType::typeString() const { return "union"; } void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { assert( baseUnion ); doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls ); } std::string EnumInstType::typeString() const { return "enum"; } std::string ContextInstType::typeString() const { return "context"; } ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) { cloneAll( other.members, members ); } ContextInstType::~ContextInstType() { deleteAll( members ); } TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { set_baseType( baseType ); } TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) { } void TypeInstType::set_baseType( TypeDecl *newValue ) { baseType = newValue; isFtype = newValue->get_kind() == TypeDecl::Ftype; } std::string TypeInstType::typeString() const { return "type"; } void TypeInstType::print( std::ostream &os, int indent ) const { using std::endl; Type::print( os, indent ); os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) "; if( !parameters.empty() ) { os << endl << std::string( indent, ' ' ) << "with parameters" << endl; printAll( parameters, os, indent+2 ); } }