// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // ReferenceToType.cc -- // // Author : Richard C. Bilson // Created On : Mon May 18 07:44:20 2015 // Last Modified By : Peter A. Buhr // Last Modified On : Wed Jul 13 18:03:30 2016 // Update Count : 9 // #include #include #include "Type.h" #include "Declaration.h" #include "Expression.h" #include "TypeSubstitution.h" #include "Common/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 ); } // if } 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 ); } // if } // for applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) ); } } // namespace std::string StructInstType::typeString() const { return "struct"; } std::list* StructInstType::get_baseParameters() { if ( ! baseStruct ) return NULL; return &baseStruct->get_parameters(); } void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { assert( baseStruct ); doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls ); } void StructInstType::print( std::ostream &os, int indent ) const { using std::endl; if ( baseStruct == NULL ) ReferenceToType::print( os, indent ); else { Type::print( os, indent ); os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " "; if ( ! parameters.empty() ) { os << endl << std::string( indent, ' ' ) << "with parameters" << endl; printAll( parameters, os, indent+2 ); } // if } // if } std::string UnionInstType::typeString() const { return "union"; } std::list* UnionInstType::get_baseParameters() { if ( ! baseUnion ) return NULL; return &baseUnion->get_parameters(); } void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { assert( baseUnion ); doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls ); } void UnionInstType::print( std::ostream &os, int indent ) const { using std::endl; if ( baseUnion == NULL ) ReferenceToType::print( os, indent ); else { Type::print( os, indent ); os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " "; if ( ! parameters.empty() ) { os << endl << std::string( indent, ' ' ) << "with parameters" << endl; printAll( parameters, os, indent+2 ); } // if } // if } std::string EnumInstType::typeString() const { return "enum"; } std::string TraitInstType::typeString() const { return "context"; } TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) { cloneAll( other.members, members ); } TraitInstType::~TraitInstType() { 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 ) { } TypeInstType::~TypeInstType() { // delete baseType; //This is shared and should not be deleted } 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" ) << " function type) "; if ( ! parameters.empty() ) { os << endl << std::string( indent, ' ' ) << "with parameters" << endl; printAll( parameters, os, indent+2 ); } // if } // Local Variables: // // tab-width: 4 // // mode: c++ // // compile-command: "make install" // // End: //