| 1 | /*
|
|---|
| 2 | * This file is part of the Cforall project
|
|---|
| 3 | *
|
|---|
| 4 | * $Id: ReferenceToType.cc,v 1.16 2005/08/29 20:59:26 rcbilson Exp $
|
|---|
| 5 | *
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include <string>
|
|---|
| 9 | #include <cassert>
|
|---|
| 10 |
|
|---|
| 11 | #include "Type.h"
|
|---|
| 12 | #include "Declaration.h"
|
|---|
| 13 | #include "Expression.h"
|
|---|
| 14 | #include "TypeSubstitution.h"
|
|---|
| 15 | #include "utility.h"
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name )
|
|---|
| 19 | : Type( tq ), name( name )
|
|---|
| 20 | {
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | ReferenceToType::ReferenceToType( const ReferenceToType &other )
|
|---|
| 24 | : Type( other ), name( other.name )
|
|---|
| 25 | {
|
|---|
| 26 | cloneAll( other.parameters, parameters );
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | ReferenceToType::~ReferenceToType()
|
|---|
| 30 | {
|
|---|
| 31 | deleteAll( parameters );
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | void
|
|---|
| 35 | ReferenceToType::print( std::ostream &os, int indent ) const
|
|---|
| 36 | {
|
|---|
| 37 | using std::endl;
|
|---|
| 38 |
|
|---|
| 39 | Type::print( os, indent );
|
|---|
| 40 | os << "instance of " << typeString() << " " << name << " ";
|
|---|
| 41 | if( !parameters.empty() ) {
|
|---|
| 42 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
|
|---|
| 43 | printAll( parameters, os, indent+2 );
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | namespace {
|
|---|
| 48 |
|
|---|
| 49 | void
|
|---|
| 50 | doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls )
|
|---|
| 51 | {
|
|---|
| 52 | std::list< Declaration* > found;
|
|---|
| 53 | for( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
|
|---|
| 54 | if( (*i)->get_name() == name ) {
|
|---|
| 55 | found.push_back( *i );
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) );
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | } // namespace
|
|---|
| 62 |
|
|---|
| 63 | std::string StructInstType::typeString() const { return "struct"; }
|
|---|
| 64 |
|
|---|
| 65 | void
|
|---|
| 66 | StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const
|
|---|
| 67 | {
|
|---|
| 68 | assert( baseStruct );
|
|---|
| 69 | doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls );
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | std::string UnionInstType::typeString() const { return "union"; }
|
|---|
| 73 |
|
|---|
| 74 | void
|
|---|
| 75 | UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const
|
|---|
| 76 | {
|
|---|
| 77 | assert( baseUnion );
|
|---|
| 78 | doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls );
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | std::string EnumInstType::typeString() const { return "enum"; }
|
|---|
| 82 |
|
|---|
| 83 | std::string ContextInstType::typeString() const { return "context"; }
|
|---|
| 84 |
|
|---|
| 85 | ContextInstType::ContextInstType( const ContextInstType &other )
|
|---|
| 86 | : Parent( other )
|
|---|
| 87 | {
|
|---|
| 88 | cloneAll( other.members, members );
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | ContextInstType::~ContextInstType()
|
|---|
| 92 | {
|
|---|
| 93 | deleteAll( members );
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name )
|
|---|
| 97 | {
|
|---|
| 98 | set_baseType( baseType );
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype )
|
|---|
| 102 | {
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | void TypeInstType::set_baseType( TypeDecl *newValue )
|
|---|
| 106 | {
|
|---|
| 107 | baseType = newValue;
|
|---|
| 108 | isFtype = newValue->get_kind() == TypeDecl::Ftype;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | std::string TypeInstType::typeString() const { return "type"; }
|
|---|
| 112 |
|
|---|
| 113 | void
|
|---|
| 114 | TypeInstType::print( std::ostream &os, int indent ) const
|
|---|
| 115 | {
|
|---|
| 116 | using std::endl;
|
|---|
| 117 |
|
|---|
| 118 | Type::print( os, indent );
|
|---|
| 119 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) ";
|
|---|
| 120 | if( !parameters.empty() ) {
|
|---|
| 121 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
|
|---|
| 122 | printAll( parameters, os, indent+2 );
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|