source: src/SynTree/ReferenceToType.cc @ 824a2dc

new-envwith_gc
Last change on this file since 824a2dc was 68f9c43, checked in by Aaron Moss <a3moss@…>, 6 years ago

First pass at delete removal

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