[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 |
---|
[5d125e4] | 12 | // Last Modified On : Wed Jul 13 18:03:30 2016 |
---|
| 13 | // Update Count : 9 |
---|
[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 | |
---|
[0dd3a2f] | 25 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) { |
---|
[51b7345] | 26 | } |
---|
| 27 | |
---|
[0dd3a2f] | 28 | ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) { |
---|
[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 | |
---|
[f006f01] | 57 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct ) : Parent( tq, baseStruct->get_name() ), baseStruct( baseStruct ) {} |
---|
| 58 | |
---|
[51b7345] | 59 | std::string StructInstType::typeString() const { return "struct"; } |
---|
| 60 | |
---|
[ed94eac] | 61 | std::list<TypeDecl*>* StructInstType::get_baseParameters() { |
---|
| 62 | if ( ! baseStruct ) return NULL; |
---|
| 63 | return &baseStruct->get_parameters(); |
---|
| 64 | } |
---|
[37a3b8f9] | 65 | |
---|
[4a9ccc3] | 66 | bool StructInstType::isComplete() const { return baseStruct->has_body(); } |
---|
| 67 | |
---|
[0dd3a2f] | 68 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[a08ba92] | 69 | assert( baseStruct ); |
---|
[33a7b6d] | 70 | doLookup( baseStruct->get_members(), name, foundDecls ); |
---|
[51b7345] | 71 | } |
---|
| 72 | |
---|
[5d125e4] | 73 | void StructInstType::print( std::ostream &os, int indent ) const { |
---|
| 74 | using std::endl; |
---|
| 75 | |
---|
| 76 | if ( baseStruct == NULL ) ReferenceToType::print( os, indent ); |
---|
| 77 | else { |
---|
| 78 | Type::print( os, indent ); |
---|
| 79 | os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " "; |
---|
| 80 | if ( ! parameters.empty() ) { |
---|
| 81 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 82 | printAll( parameters, os, indent+2 ); |
---|
| 83 | } // if |
---|
| 84 | } // if |
---|
| 85 | } |
---|
| 86 | |
---|
[51b7345] | 87 | std::string UnionInstType::typeString() const { return "union"; } |
---|
| 88 | |
---|
[ed94eac] | 89 | std::list<TypeDecl*>* UnionInstType::get_baseParameters() { |
---|
| 90 | if ( ! baseUnion ) return NULL; |
---|
| 91 | return &baseUnion->get_parameters(); |
---|
| 92 | } |
---|
[37a3b8f9] | 93 | |
---|
[4a9ccc3] | 94 | bool UnionInstType::isComplete() const { return baseUnion->has_body(); } |
---|
| 95 | |
---|
[0dd3a2f] | 96 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[a08ba92] | 97 | assert( baseUnion ); |
---|
[33a7b6d] | 98 | doLookup( baseUnion->get_members(), name, foundDecls ); |
---|
[51b7345] | 99 | } |
---|
| 100 | |
---|
[5d125e4] | 101 | void UnionInstType::print( std::ostream &os, int indent ) const { |
---|
| 102 | using std::endl; |
---|
| 103 | |
---|
| 104 | if ( baseUnion == NULL ) ReferenceToType::print( os, indent ); |
---|
| 105 | else { |
---|
| 106 | Type::print( os, indent ); |
---|
| 107 | os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " "; |
---|
| 108 | if ( ! parameters.empty() ) { |
---|
| 109 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 110 | printAll( parameters, os, indent+2 ); |
---|
| 111 | } // if |
---|
| 112 | } // if |
---|
| 113 | } |
---|
| 114 | |
---|
[51b7345] | 115 | std::string EnumInstType::typeString() const { return "enum"; } |
---|
| 116 | |
---|
[4a9ccc3] | 117 | std::string TraitInstType::typeString() const { return "trait"; } |
---|
[51b7345] | 118 | |
---|
[4040425] | 119 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) { |
---|
[a08ba92] | 120 | cloneAll( other.members, members ); |
---|
[51b7345] | 121 | } |
---|
| 122 | |
---|
[4040425] | 123 | TraitInstType::~TraitInstType() { |
---|
[a08ba92] | 124 | deleteAll( members ); |
---|
[51b7345] | 125 | } |
---|
| 126 | |
---|
[4a9ccc3] | 127 | bool TraitInstType::isComplete() const { assert( false ); } |
---|
| 128 | |
---|
[0dd3a2f] | 129 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { |
---|
[a08ba92] | 130 | set_baseType( baseType ); |
---|
[51b7345] | 131 | } |
---|
| 132 | |
---|
[0dd3a2f] | 133 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) { |
---|
[51b7345] | 134 | } |
---|
| 135 | |
---|
[2c57025] | 136 | TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) { |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[1e8b02f5] | 140 | TypeInstType::~TypeInstType() { |
---|
| 141 | // delete baseType; //This is shared and should not be deleted |
---|
| 142 | } |
---|
| 143 | |
---|
[0dd3a2f] | 144 | void TypeInstType::set_baseType( TypeDecl *newValue ) { |
---|
[a08ba92] | 145 | baseType = newValue; |
---|
| 146 | isFtype = newValue->get_kind() == TypeDecl::Ftype; |
---|
[51b7345] | 147 | } |
---|
| 148 | |
---|
| 149 | std::string TypeInstType::typeString() const { return "type"; } |
---|
| 150 | |
---|
[4a9ccc3] | 151 | bool TypeInstType::isComplete() const { return baseType->isComplete(); } |
---|
| 152 | |
---|
[0dd3a2f] | 153 | void TypeInstType::print( std::ostream &os, int indent ) const { |
---|
[a08ba92] | 154 | using std::endl; |
---|
[1e8b02f5] | 155 | |
---|
[a08ba92] | 156 | Type::print( os, indent ); |
---|
[5f2f2d7] | 157 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) "; |
---|
[a08ba92] | 158 | if ( ! parameters.empty() ) { |
---|
[0dd3a2f] | 159 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 160 | printAll( parameters, os, indent+2 ); |
---|
[a08ba92] | 161 | } // if |
---|
[51b7345] | 162 | } |
---|
| 163 | |
---|
[0dd3a2f] | 164 | // Local Variables: // |
---|
| 165 | // tab-width: 4 // |
---|
| 166 | // mode: c++ // |
---|
| 167 | // compile-command: "make install" // |
---|
| 168 | // End: // |
---|