[0dd3a2f] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[1e8b02f5] | 7 | // ReferenceToType.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[43c89a7] | 12 | // Last Modified On : Thu Feb 23 16:38:54 2017 |
---|
| 13 | // Update Count : 24 |
---|
[0dd3a2f] | 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #include <string> |
---|
| 17 | #include <cassert> |
---|
| 18 | |
---|
| 19 | #include "Type.h" |
---|
| 20 | #include "Declaration.h" |
---|
| 21 | #include "Expression.h" |
---|
| 22 | #include "TypeSubstitution.h" |
---|
[d3b7937] | 23 | #include "Common/utility.h" |
---|
[51b7345] | 24 | |
---|
[43c89a7] | 25 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) { |
---|
[51b7345] | 26 | } |
---|
| 27 | |
---|
[43c89a7] | 28 | ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) { |
---|
[a08ba92] | 29 | cloneAll( other.parameters, parameters ); |
---|
[51b7345] | 30 | } |
---|
| 31 | |
---|
[0dd3a2f] | 32 | ReferenceToType::~ReferenceToType() { |
---|
[a08ba92] | 33 | deleteAll( parameters ); |
---|
[51b7345] | 34 | } |
---|
| 35 | |
---|
[0dd3a2f] | 36 | void ReferenceToType::print( std::ostream &os, int indent ) const { |
---|
[a08ba92] | 37 | using std::endl; |
---|
[1e8b02f5] | 38 | |
---|
[a08ba92] | 39 | Type::print( os, indent ); |
---|
| 40 | os << "instance of " << typeString() << " " << name << " "; |
---|
| 41 | if ( ! parameters.empty() ) { |
---|
[0dd3a2f] | 42 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 43 | printAll( parameters, os, indent+2 ); |
---|
[a08ba92] | 44 | } // if |
---|
[51b7345] | 45 | } |
---|
| 46 | |
---|
| 47 | namespace { |
---|
[33a7b6d] | 48 | void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) { |
---|
[0dd3a2f] | 49 | for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { |
---|
| 50 | if ( (*i)->get_name() == name ) { |
---|
[33a7b6d] | 51 | foundDecls.push_back( *i ); |
---|
[0dd3a2f] | 52 | } // if |
---|
| 53 | } // for |
---|
[51b7345] | 54 | } |
---|
| 55 | } // namespace |
---|
| 56 | |
---|
[c0aa336] | 57 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) : |
---|
| 58 | Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {} |
---|
[f006f01] | 59 | |
---|
[51b7345] | 60 | std::string StructInstType::typeString() const { return "struct"; } |
---|
| 61 | |
---|
[ed94eac] | 62 | std::list<TypeDecl*>* StructInstType::get_baseParameters() { |
---|
| 63 | if ( ! baseStruct ) return NULL; |
---|
| 64 | return &baseStruct->get_parameters(); |
---|
| 65 | } |
---|
[37a3b8f9] | 66 | |
---|
[c0aa336] | 67 | bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; } |
---|
[4a9ccc3] | 68 | |
---|
[0dd3a2f] | 69 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[a08ba92] | 70 | assert( baseStruct ); |
---|
[33a7b6d] | 71 | doLookup( baseStruct->get_members(), name, foundDecls ); |
---|
[51b7345] | 72 | } |
---|
| 73 | |
---|
[5d125e4] | 74 | void StructInstType::print( std::ostream &os, int indent ) const { |
---|
| 75 | using std::endl; |
---|
| 76 | |
---|
| 77 | if ( baseStruct == NULL ) ReferenceToType::print( os, indent ); |
---|
| 78 | else { |
---|
| 79 | Type::print( os, indent ); |
---|
| 80 | os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " "; |
---|
| 81 | if ( ! parameters.empty() ) { |
---|
| 82 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 83 | printAll( parameters, os, indent+2 ); |
---|
| 84 | } // if |
---|
| 85 | } // if |
---|
| 86 | } |
---|
| 87 | |
---|
[c0aa336] | 88 | |
---|
| 89 | UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) : |
---|
| 90 | Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {} |
---|
| 91 | |
---|
[51b7345] | 92 | std::string UnionInstType::typeString() const { return "union"; } |
---|
| 93 | |
---|
[c0aa336] | 94 | std::list< TypeDecl * > * UnionInstType::get_baseParameters() { |
---|
[ed94eac] | 95 | if ( ! baseUnion ) return NULL; |
---|
| 96 | return &baseUnion->get_parameters(); |
---|
| 97 | } |
---|
[37a3b8f9] | 98 | |
---|
[c0aa336] | 99 | bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; } |
---|
[4a9ccc3] | 100 | |
---|
[0dd3a2f] | 101 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[a08ba92] | 102 | assert( baseUnion ); |
---|
[33a7b6d] | 103 | doLookup( baseUnion->get_members(), name, foundDecls ); |
---|
[51b7345] | 104 | } |
---|
| 105 | |
---|
[5d125e4] | 106 | void UnionInstType::print( std::ostream &os, int indent ) const { |
---|
| 107 | using std::endl; |
---|
| 108 | |
---|
| 109 | if ( baseUnion == NULL ) ReferenceToType::print( os, indent ); |
---|
| 110 | else { |
---|
| 111 | Type::print( os, indent ); |
---|
| 112 | os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " "; |
---|
| 113 | if ( ! parameters.empty() ) { |
---|
| 114 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 115 | printAll( parameters, os, indent+2 ); |
---|
| 116 | } // if |
---|
| 117 | } // if |
---|
| 118 | } |
---|
| 119 | |
---|
[c0aa336] | 120 | |
---|
| 121 | EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) : |
---|
| 122 | Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {} |
---|
| 123 | |
---|
[51b7345] | 124 | std::string EnumInstType::typeString() const { return "enum"; } |
---|
| 125 | |
---|
[c0aa336] | 126 | bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; } |
---|
| 127 | |
---|
[4a9ccc3] | 128 | std::string TraitInstType::typeString() const { return "trait"; } |
---|
[51b7345] | 129 | |
---|
[4040425] | 130 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) { |
---|
[a08ba92] | 131 | cloneAll( other.members, members ); |
---|
[51b7345] | 132 | } |
---|
| 133 | |
---|
[4040425] | 134 | TraitInstType::~TraitInstType() { |
---|
[a08ba92] | 135 | deleteAll( members ); |
---|
[51b7345] | 136 | } |
---|
| 137 | |
---|
[4a9ccc3] | 138 | bool TraitInstType::isComplete() const { assert( false ); } |
---|
| 139 | |
---|
[c0aa336] | 140 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) { |
---|
[a08ba92] | 141 | set_baseType( baseType ); |
---|
[51b7345] | 142 | } |
---|
| 143 | |
---|
[c0aa336] | 144 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ), baseType( 0 ), isFtype( isFtype ) { |
---|
[51b7345] | 145 | } |
---|
| 146 | |
---|
[2c57025] | 147 | TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) { |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
[1e8b02f5] | 151 | TypeInstType::~TypeInstType() { |
---|
| 152 | // delete baseType; //This is shared and should not be deleted |
---|
| 153 | } |
---|
| 154 | |
---|
[0dd3a2f] | 155 | void TypeInstType::set_baseType( TypeDecl *newValue ) { |
---|
[a08ba92] | 156 | baseType = newValue; |
---|
| 157 | isFtype = newValue->get_kind() == TypeDecl::Ftype; |
---|
[51b7345] | 158 | } |
---|
| 159 | |
---|
| 160 | std::string TypeInstType::typeString() const { return "type"; } |
---|
| 161 | |
---|
[4a9ccc3] | 162 | bool TypeInstType::isComplete() const { return baseType->isComplete(); } |
---|
| 163 | |
---|
[0dd3a2f] | 164 | void TypeInstType::print( std::ostream &os, int indent ) const { |
---|
[a08ba92] | 165 | using std::endl; |
---|
[1e8b02f5] | 166 | |
---|
[a08ba92] | 167 | Type::print( os, indent ); |
---|
[5f2f2d7] | 168 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) "; |
---|
[a08ba92] | 169 | if ( ! parameters.empty() ) { |
---|
[0dd3a2f] | 170 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 171 | printAll( parameters, os, indent+2 ); |
---|
[a08ba92] | 172 | } // if |
---|
[51b7345] | 173 | } |
---|
| 174 | |
---|
[0dd3a2f] | 175 | // Local Variables: // |
---|
| 176 | // tab-width: 4 // |
---|
| 177 | // mode: c++ // |
---|
| 178 | // compile-command: "make install" // |
---|
| 179 | // End: // |
---|