[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 | |
---|
[ea6332d] | 16 | #include <cassert> // for assert |
---|
| 17 | #include <list> // for list, _List_const_iterator, list<>::cons... |
---|
| 18 | #include <ostream> // for operator<<, basic_ostream, ostream, endl |
---|
| 19 | #include <string> // for string, operator<<, char_traits, operator== |
---|
[51b7345] | 20 | |
---|
[ea6332d] | 21 | #include "Common/utility.h" // for printAll, cloneAll, deleteAll |
---|
| 22 | #include "Declaration.h" // for StructDecl, UnionDecl, EnumDecl, Declara... |
---|
| 23 | #include "Expression.h" // for Expression |
---|
| 24 | #include "Type.h" // for TypeInstType, StructInstType, UnionInstType |
---|
| 25 | |
---|
| 26 | class Attribute; |
---|
[51b7345] | 27 | |
---|
[43c89a7] | 28 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) { |
---|
[51b7345] | 29 | } |
---|
| 30 | |
---|
[43c89a7] | 31 | ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) { |
---|
[a08ba92] | 32 | cloneAll( other.parameters, parameters ); |
---|
[51b7345] | 33 | } |
---|
| 34 | |
---|
[0dd3a2f] | 35 | ReferenceToType::~ReferenceToType() { |
---|
[a08ba92] | 36 | deleteAll( parameters ); |
---|
[51b7345] | 37 | } |
---|
| 38 | |
---|
[50377a4] | 39 | void ReferenceToType::print( std::ostream &os, Indenter indent ) const { |
---|
[a08ba92] | 40 | using std::endl; |
---|
[1e8b02f5] | 41 | |
---|
[a08ba92] | 42 | Type::print( os, indent ); |
---|
| 43 | os << "instance of " << typeString() << " " << name << " "; |
---|
| 44 | if ( ! parameters.empty() ) { |
---|
[50377a4] | 45 | os << endl << indent << "... with parameters" << endl; |
---|
| 46 | printAll( parameters, os, indent+1 ); |
---|
[a08ba92] | 47 | } // if |
---|
[51b7345] | 48 | } |
---|
| 49 | |
---|
| 50 | namespace { |
---|
[33a7b6d] | 51 | void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) { |
---|
[0dd3a2f] | 52 | for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { |
---|
| 53 | if ( (*i)->get_name() == name ) { |
---|
[33a7b6d] | 54 | foundDecls.push_back( *i ); |
---|
[0dd3a2f] | 55 | } // if |
---|
| 56 | } // for |
---|
[51b7345] | 57 | } |
---|
| 58 | } // namespace |
---|
| 59 | |
---|
[c0aa336] | 60 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) : |
---|
| 61 | Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {} |
---|
[f006f01] | 62 | |
---|
[51b7345] | 63 | std::string StructInstType::typeString() const { return "struct"; } |
---|
| 64 | |
---|
[ed94eac] | 65 | std::list<TypeDecl*>* StructInstType::get_baseParameters() { |
---|
[50377a4] | 66 | if ( ! baseStruct ) return nullptr; |
---|
[ed94eac] | 67 | return &baseStruct->get_parameters(); |
---|
| 68 | } |
---|
[37a3b8f9] | 69 | |
---|
[c0aa336] | 70 | bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; } |
---|
[4a9ccc3] | 71 | |
---|
[373d0b5] | 72 | AggregateDecl * StructInstType::getAggr() { return baseStruct; } |
---|
| 73 | |
---|
[0dd3a2f] | 74 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[a08ba92] | 75 | assert( baseStruct ); |
---|
[33a7b6d] | 76 | doLookup( baseStruct->get_members(), name, foundDecls ); |
---|
[51b7345] | 77 | } |
---|
| 78 | |
---|
[50377a4] | 79 | void StructInstType::print( std::ostream &os, Indenter indent ) const { |
---|
[5d125e4] | 80 | using std::endl; |
---|
| 81 | |
---|
[50377a4] | 82 | if ( baseStruct == nullptr ) ReferenceToType::print( os, indent ); |
---|
[5d125e4] | 83 | else { |
---|
| 84 | Type::print( os, indent ); |
---|
| 85 | os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " "; |
---|
| 86 | if ( ! parameters.empty() ) { |
---|
[50377a4] | 87 | os << endl << indent << "... with parameters" << endl; |
---|
| 88 | printAll( parameters, os, indent+1 ); |
---|
[5d125e4] | 89 | } // if |
---|
| 90 | } // if |
---|
| 91 | } |
---|
| 92 | |
---|
[c0aa336] | 93 | |
---|
| 94 | UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) : |
---|
| 95 | Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {} |
---|
| 96 | |
---|
[51b7345] | 97 | std::string UnionInstType::typeString() const { return "union"; } |
---|
| 98 | |
---|
[c0aa336] | 99 | std::list< TypeDecl * > * UnionInstType::get_baseParameters() { |
---|
[50377a4] | 100 | if ( ! baseUnion ) return nullptr; |
---|
[ed94eac] | 101 | return &baseUnion->get_parameters(); |
---|
| 102 | } |
---|
[37a3b8f9] | 103 | |
---|
[c0aa336] | 104 | bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; } |
---|
[4a9ccc3] | 105 | |
---|
[373d0b5] | 106 | AggregateDecl * UnionInstType::getAggr() { return baseUnion; } |
---|
| 107 | |
---|
[0dd3a2f] | 108 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[a08ba92] | 109 | assert( baseUnion ); |
---|
[33a7b6d] | 110 | doLookup( baseUnion->get_members(), name, foundDecls ); |
---|
[51b7345] | 111 | } |
---|
| 112 | |
---|
[50377a4] | 113 | void UnionInstType::print( std::ostream &os, Indenter indent ) const { |
---|
[5d125e4] | 114 | using std::endl; |
---|
| 115 | |
---|
[50377a4] | 116 | if ( baseUnion == nullptr ) ReferenceToType::print( os, indent ); |
---|
[5d125e4] | 117 | else { |
---|
| 118 | Type::print( os, indent ); |
---|
| 119 | os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " "; |
---|
| 120 | if ( ! parameters.empty() ) { |
---|
[50377a4] | 121 | os << endl << indent << "... with parameters" << endl; |
---|
| 122 | printAll( parameters, os, indent+1 ); |
---|
[5d125e4] | 123 | } // if |
---|
| 124 | } // if |
---|
| 125 | } |
---|
| 126 | |
---|
[c0aa336] | 127 | |
---|
| 128 | EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) : |
---|
| 129 | Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {} |
---|
| 130 | |
---|
[51b7345] | 131 | std::string EnumInstType::typeString() const { return "enum"; } |
---|
| 132 | |
---|
[c0aa336] | 133 | bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; } |
---|
| 134 | |
---|
[6137fbb] | 135 | void EnumInstType::print( std::ostream &os, Indenter indent ) const { |
---|
| 136 | using std::endl; |
---|
| 137 | |
---|
| 138 | if ( baseEnum == nullptr ) ReferenceToType::print( os, indent ); |
---|
| 139 | else { |
---|
| 140 | Type::print( os, indent ); |
---|
| 141 | os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body() << " "; |
---|
| 142 | } // if |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
[4a9ccc3] | 146 | std::string TraitInstType::typeString() const { return "trait"; } |
---|
[51b7345] | 147 | |
---|
[be9036d] | 148 | TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {} |
---|
| 149 | |
---|
| 150 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) { |
---|
[51b7345] | 151 | } |
---|
| 152 | |
---|
[4040425] | 153 | TraitInstType::~TraitInstType() { |
---|
[51b7345] | 154 | } |
---|
| 155 | |
---|
[4a9ccc3] | 156 | bool TraitInstType::isComplete() const { assert( false ); } |
---|
| 157 | |
---|
[c0aa336] | 158 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) { |
---|
[a08ba92] | 159 | set_baseType( baseType ); |
---|
[51b7345] | 160 | } |
---|
| 161 | |
---|
[c0aa336] | 162 | 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] | 163 | } |
---|
| 164 | |
---|
[2c57025] | 165 | TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) { |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | |
---|
[1e8b02f5] | 169 | TypeInstType::~TypeInstType() { |
---|
| 170 | // delete baseType; //This is shared and should not be deleted |
---|
| 171 | } |
---|
| 172 | |
---|
[0dd3a2f] | 173 | void TypeInstType::set_baseType( TypeDecl *newValue ) { |
---|
[a08ba92] | 174 | baseType = newValue; |
---|
| 175 | isFtype = newValue->get_kind() == TypeDecl::Ftype; |
---|
[51b7345] | 176 | } |
---|
| 177 | |
---|
| 178 | std::string TypeInstType::typeString() const { return "type"; } |
---|
| 179 | |
---|
[4a9ccc3] | 180 | bool TypeInstType::isComplete() const { return baseType->isComplete(); } |
---|
| 181 | |
---|
[50377a4] | 182 | void TypeInstType::print( std::ostream &os, Indenter indent ) const { |
---|
[a08ba92] | 183 | using std::endl; |
---|
[1e8b02f5] | 184 | |
---|
[a08ba92] | 185 | Type::print( os, indent ); |
---|
[5f2f2d7] | 186 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) "; |
---|
[a08ba92] | 187 | if ( ! parameters.empty() ) { |
---|
[50377a4] | 188 | os << endl << indent << "... with parameters" << endl; |
---|
| 189 | printAll( parameters, os, indent+1 ); |
---|
[a08ba92] | 190 | } // if |
---|
[51b7345] | 191 | } |
---|
| 192 | |
---|
[0dd3a2f] | 193 | // Local Variables: // |
---|
| 194 | // tab-width: 4 // |
---|
| 195 | // mode: c++ // |
---|
| 196 | // compile-command: "make install" // |
---|
| 197 | // End: // |
---|