source: src/SynTree/ReferenceToType.cc @ d807ca28

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since d807ca28 was 9bfc9da, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Refactor makeSub into genericSubstitution

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