source: src/SynTree/ReferenceToType.cc @ 1cdfa82

new-envwith_gc
Last change on this file since 1cdfa82 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
Line 
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 <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==
20
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
26
27class Attribute;
28
29ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) {
30}
31
32ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) {
33        cloneAll( other.parameters, parameters );
34}
35
36void ReferenceToType::print( std::ostream &os, Indenter 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 << indent << "... with parameters" << endl;
43                printAll( parameters, os, indent+1 );
44        } // if
45}
46
47namespace {
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
57StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
58                Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
59
60std::string StructInstType::typeString() const { return "struct"; }
61
62const std::list<TypeDecl*>* StructInstType::get_baseParameters() const {
63        if ( ! baseStruct ) return nullptr;
64        return &baseStruct->get_parameters();
65}
66
67std::list<TypeDecl*>* StructInstType::get_baseParameters() {
68        if ( ! baseStruct ) return nullptr;
69        return &baseStruct->get_parameters();
70}
71
72bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
73
74AggregateDecl * StructInstType::getAggr() { return baseStruct; }
75
76TypeSubstitution StructInstType::genericSubstitution() const {
77        return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
78}
79
80void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
81        assert( baseStruct );
82        doLookup( baseStruct->get_members(), name, foundDecls );
83}
84
85void StructInstType::print( std::ostream &os, Indenter indent ) const {
86        using std::endl;
87
88        if ( baseStruct == nullptr ) ReferenceToType::print( os, indent );
89        else {
90                Type::print( os, indent );
91                os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
92                if ( ! parameters.empty() ) {
93                        os << endl << indent << "... with parameters" << endl;
94                        printAll( parameters, os, indent+1 );
95                } // if
96        } // if
97}
98
99
100UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
101                Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
102
103std::string UnionInstType::typeString() const { return "union"; }
104
105std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
106        if ( ! baseUnion ) return nullptr;
107        return &baseUnion->get_parameters();
108}
109
110const std::list< TypeDecl * > * UnionInstType::get_baseParameters() const {
111        if ( ! baseUnion ) return nullptr;
112        return &baseUnion->get_parameters();
113}
114
115bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
116
117AggregateDecl * UnionInstType::getAggr() { return baseUnion; }
118
119TypeSubstitution UnionInstType::genericSubstitution() const {
120        return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
121}
122
123void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
124        assert( baseUnion );
125        doLookup( baseUnion->get_members(), name, foundDecls );
126}
127
128void UnionInstType::print( std::ostream &os, Indenter indent ) const {
129        using std::endl;
130
131        if ( baseUnion == nullptr ) ReferenceToType::print( os, indent );
132        else {
133                Type::print( os, indent );
134                os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
135                if ( ! parameters.empty() ) {
136                        os << endl << indent << "... with parameters" << endl;
137                        printAll( parameters, os, indent+1 );
138                } // if
139        } // if
140}
141
142
143EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
144                Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
145
146std::string EnumInstType::typeString() const { return "enum"; }
147
148bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
149
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
161std::string TraitInstType::typeString() const { return "trait"; }
162
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 ) {
166}
167
168bool TraitInstType::isComplete() const { assert( false ); }
169
170TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
171        set_baseType( baseType );
172}
173
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 ) {
175}
176
177TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
178}
179
180void TypeInstType::set_baseType( TypeDecl *newValue ) {
181        baseType = newValue;
182        isFtype = newValue->get_kind() == TypeDecl::Ftype;
183}
184
185std::string TypeInstType::typeString() const { return "type"; }
186
187bool TypeInstType::isComplete() const { return baseType->isComplete(); }
188
189void TypeInstType::print( std::ostream &os, Indenter indent ) const {
190        using std::endl;
191
192        Type::print( os, indent );
193        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
194        if ( ! parameters.empty() ) {
195                os << endl << indent << "... with parameters" << endl;
196                printAll( parameters, os, indent+1 );
197        } // if
198}
199
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.