source: src/SynTree/ReferenceToType.cc @ 7bd3bf2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 7bd3bf2 was 08222c7, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Fixed some errors with incorrect trailing whitespace in the tests

  • 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 {
[4e7cc5ce]52        void doLookup( const std::list< Declaration * > & members, const std::string & name, std::list< Declaration* > & foundDecls ) {
53                for ( Declaration * decl : members ) {
54                        if ( decl->name == name ) {
55                                foundDecls.push_back( decl );
[0dd3a2f]56                        } // if
57                } // for
[51b7345]58        }
59} // namespace
60
[c0aa336]61StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
[4e7cc5ce]62                Parent( tq, baseStruct->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
[0b3b2ae]78AggregateDecl * StructInstType::getAggr() const { return baseStruct; }
[373d0b5]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 );
[4e7cc5ce]86        doLookup( baseStruct->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 );
[08222c7]95                os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body();
[5d125e4]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 ) :
[4e7cc5ce]105                Parent( tq, baseUnion->name, attributes ), baseUnion( baseUnion ) {}
[c0aa336]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
[0b3b2ae]121AggregateDecl * UnionInstType::getAggr() const { return baseUnion; }
[373d0b5]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 );
[4e7cc5ce]129        doLookup( baseUnion->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 );
[08222c7]138                os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body();
[5d125e4]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
[0b3b2ae]154AggregateDecl * EnumInstType::getAggr() const { return baseEnum; }
155
[6137fbb]156void EnumInstType::print( std::ostream &os, Indenter indent ) const {
157        using std::endl;
158
159        if ( baseEnum == nullptr ) ReferenceToType::print( os, indent );
160        else {
161                Type::print( os, indent );
[08222c7]162                os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body();
[6137fbb]163        } // if
164}
165
166
[4a9ccc3]167std::string TraitInstType::typeString() const { return "trait"; }
[51b7345]168
[be9036d]169TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {}
170
171TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) {
[51b7345]172}
173
[4040425]174TraitInstType::~TraitInstType() {
[51b7345]175}
176
[4a9ccc3]177bool TraitInstType::isComplete() const { assert( false ); }
178
[c0aa336]179TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
[a08ba92]180        set_baseType( baseType );
[51b7345]181}
182
[c0aa336]183TypeInstType::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]184}
185
[2c57025]186TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
187}
188
189
[1e8b02f5]190TypeInstType::~TypeInstType() {
191        // delete baseType; //This is shared and should not be deleted
192}
193
[0dd3a2f]194void TypeInstType::set_baseType( TypeDecl *newValue ) {
[a08ba92]195        baseType = newValue;
196        isFtype = newValue->get_kind() == TypeDecl::Ftype;
[51b7345]197}
198
199std::string TypeInstType::typeString() const { return "type"; }
200
[4a9ccc3]201bool TypeInstType::isComplete() const { return baseType->isComplete(); }
202
[50377a4]203void TypeInstType::print( std::ostream &os, Indenter indent ) const {
[a08ba92]204        using std::endl;
[1e8b02f5]205
[a08ba92]206        Type::print( os, indent );
[5f2f2d7]207        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
[a08ba92]208        if ( ! parameters.empty() ) {
[50377a4]209                os << endl << indent << "... with parameters" << endl;
210                printAll( parameters, os, indent+1 );
[a08ba92]211        } // if
[51b7345]212}
213
[0dd3a2f]214// Local Variables: //
215// tab-width: 4 //
216// mode: c++ //
217// compile-command: "make install" //
218// End: //
Note: See TracBrowser for help on using the repository browser.