| 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 | //
|
|---|
| 7 | // ReferenceToType.cc --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Richard C. Bilson
|
|---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Thu Feb 23 16:38:54 2017
|
|---|
| 13 | // Update Count : 24
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include <string>
|
|---|
| 17 | #include <cassert>
|
|---|
| 18 |
|
|---|
| 19 | #include "Type.h"
|
|---|
| 20 | #include "Declaration.h"
|
|---|
| 21 | #include "Expression.h"
|
|---|
| 22 | #include "TypeSubstitution.h"
|
|---|
| 23 | #include "Common/utility.h"
|
|---|
| 24 |
|
|---|
| 25 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) {
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) {
|
|---|
| 29 | cloneAll( other.parameters, parameters );
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | ReferenceToType::~ReferenceToType() {
|
|---|
| 33 | deleteAll( parameters );
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | void ReferenceToType::print( std::ostream &os, int indent ) const {
|
|---|
| 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 | } // if
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | namespace {
|
|---|
| 48 | void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {
|
|---|
| 49 | for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
|
|---|
| 50 | if ( (*i)->get_name() == name ) {
|
|---|
| 51 | foundDecls.push_back( *i );
|
|---|
| 52 | } // if
|
|---|
| 53 | } // for
|
|---|
| 54 | }
|
|---|
| 55 | } // namespace
|
|---|
| 56 |
|
|---|
| 57 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
|
|---|
| 58 | Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
|
|---|
| 59 |
|
|---|
| 60 | std::string StructInstType::typeString() const { return "struct"; }
|
|---|
| 61 |
|
|---|
| 62 | std::list<TypeDecl*>* StructInstType::get_baseParameters() {
|
|---|
| 63 | if ( ! baseStruct ) return NULL;
|
|---|
| 64 | return &baseStruct->get_parameters();
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
|
|---|
| 68 |
|
|---|
| 69 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
|
|---|
| 70 | assert( baseStruct );
|
|---|
| 71 | doLookup( baseStruct->get_members(), name, foundDecls );
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 92 | std::string UnionInstType::typeString() const { return "union"; }
|
|---|
| 93 |
|
|---|
| 94 | std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
|
|---|
| 95 | if ( ! baseUnion ) return NULL;
|
|---|
| 96 | return &baseUnion->get_parameters();
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
|
|---|
| 100 |
|
|---|
| 101 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
|
|---|
| 102 | assert( baseUnion );
|
|---|
| 103 | doLookup( baseUnion->get_members(), name, foundDecls );
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 124 | std::string EnumInstType::typeString() const { return "enum"; }
|
|---|
| 125 |
|
|---|
| 126 | bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
|
|---|
| 127 |
|
|---|
| 128 | std::string TraitInstType::typeString() const { return "trait"; }
|
|---|
| 129 |
|
|---|
| 130 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) {
|
|---|
| 131 | cloneAll( other.members, members );
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | TraitInstType::~TraitInstType() {
|
|---|
| 135 | deleteAll( members );
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | bool TraitInstType::isComplete() const { assert( false ); }
|
|---|
| 139 |
|
|---|
| 140 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
|
|---|
| 141 | set_baseType( baseType );
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 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 ) {
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | TypeInstType::~TypeInstType() {
|
|---|
| 152 | // delete baseType; //This is shared and should not be deleted
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | void TypeInstType::set_baseType( TypeDecl *newValue ) {
|
|---|
| 156 | baseType = newValue;
|
|---|
| 157 | isFtype = newValue->get_kind() == TypeDecl::Ftype;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | std::string TypeInstType::typeString() const { return "type"; }
|
|---|
| 161 |
|
|---|
| 162 | bool TypeInstType::isComplete() const { return baseType->isComplete(); }
|
|---|
| 163 |
|
|---|
| 164 | void TypeInstType::print( std::ostream &os, int indent ) const {
|
|---|
| 165 | using std::endl;
|
|---|
| 166 |
|
|---|
| 167 | Type::print( os, indent );
|
|---|
| 168 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
|
|---|
| 169 | if ( ! parameters.empty() ) {
|
|---|
| 170 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
|
|---|
| 171 | printAll( parameters, os, indent+2 );
|
|---|
| 172 | } // if
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | // Local Variables: //
|
|---|
| 176 | // tab-width: 4 //
|
|---|
| 177 | // mode: c++ //
|
|---|
| 178 | // compile-command: "make install" //
|
|---|
| 179 | // End: //
|
|---|