source: src/SynTree/ReferenceToType.cc@ 054514d

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since 054514d was 9bfc9da, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Refactor makeSub into genericSubstitution

  • Property mode set to 100644
File size: 7.6 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
36ReferenceToType::~ReferenceToType() {
37 deleteAll( parameters );
38}
39
40void ReferenceToType::print( std::ostream &os, Indenter indent ) const {
41 using std::endl;
42
43 Type::print( os, indent );
44 os << "instance of " << typeString() << " " << name << " ";
45 if ( ! parameters.empty() ) {
46 os << endl << indent << "... with parameters" << endl;
47 printAll( parameters, os, indent+1 );
48 } // if
49}
50
51namespace {
52 void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {
53 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
54 if ( (*i)->get_name() == name ) {
55 foundDecls.push_back( *i );
56 } // if
57 } // for
58 }
59} // namespace
60
61StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
62 Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
63
64std::string StructInstType::typeString() const { return "struct"; }
65
66const std::list<TypeDecl*>* StructInstType::get_baseParameters() const {
67 if ( ! baseStruct ) return nullptr;
68 return &baseStruct->get_parameters();
69}
70
71std::list<TypeDecl*>* StructInstType::get_baseParameters() {
72 if ( ! baseStruct ) return nullptr;
73 return &baseStruct->get_parameters();
74}
75
76bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
77
78AggregateDecl * StructInstType::getAggr() { return baseStruct; }
79
80TypeSubstitution StructInstType::genericSubstitution() const {
81 return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
82}
83
84void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
85 assert( baseStruct );
86 doLookup( baseStruct->get_members(), name, foundDecls );
87}
88
89void StructInstType::print( std::ostream &os, Indenter indent ) const {
90 using std::endl;
91
92 if ( baseStruct == nullptr ) ReferenceToType::print( os, indent );
93 else {
94 Type::print( os, indent );
95 os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
96 if ( ! parameters.empty() ) {
97 os << endl << indent << "... with parameters" << endl;
98 printAll( parameters, os, indent+1 );
99 } // if
100 } // if
101}
102
103
104UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
105 Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
106
107std::string UnionInstType::typeString() const { return "union"; }
108
109std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
110 if ( ! baseUnion ) return nullptr;
111 return &baseUnion->get_parameters();
112}
113
114const std::list< TypeDecl * > * UnionInstType::get_baseParameters() const {
115 if ( ! baseUnion ) return nullptr;
116 return &baseUnion->get_parameters();
117}
118
119bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
120
121AggregateDecl * UnionInstType::getAggr() { return baseUnion; }
122
123TypeSubstitution UnionInstType::genericSubstitution() const {
124 return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
125}
126
127void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
128 assert( baseUnion );
129 doLookup( baseUnion->get_members(), name, foundDecls );
130}
131
132void UnionInstType::print( std::ostream &os, Indenter indent ) const {
133 using std::endl;
134
135 if ( baseUnion == nullptr ) ReferenceToType::print( os, indent );
136 else {
137 Type::print( os, indent );
138 os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
139 if ( ! parameters.empty() ) {
140 os << endl << indent << "... with parameters" << endl;
141 printAll( parameters, os, indent+1 );
142 } // if
143 } // if
144}
145
146
147EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
148 Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
149
150std::string EnumInstType::typeString() const { return "enum"; }
151
152bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
153
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
165std::string TraitInstType::typeString() const { return "trait"; }
166
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 ) {
170}
171
172TraitInstType::~TraitInstType() {
173}
174
175bool TraitInstType::isComplete() const { assert( false ); }
176
177TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
178 set_baseType( baseType );
179}
180
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 ) {
182}
183
184TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
185}
186
187
188TypeInstType::~TypeInstType() {
189 // delete baseType; //This is shared and should not be deleted
190}
191
192void TypeInstType::set_baseType( TypeDecl *newValue ) {
193 baseType = newValue;
194 isFtype = newValue->get_kind() == TypeDecl::Ftype;
195}
196
197std::string TypeInstType::typeString() const { return "type"; }
198
199bool TypeInstType::isComplete() const { return baseType->isComplete(); }
200
201void TypeInstType::print( std::ostream &os, Indenter indent ) const {
202 using std::endl;
203
204 Type::print( os, indent );
205 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
206 if ( ! parameters.empty() ) {
207 os << endl << indent << "... with parameters" << endl;
208 printAll( parameters, os, indent+1 );
209 } // if
210}
211
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.