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 |
|
---|
27 | class Attribute;
|
---|
28 |
|
---|
29 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) {
|
---|
30 | }
|
---|
31 |
|
---|
32 | ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) {
|
---|
33 | cloneAll( other.parameters, parameters );
|
---|
34 | }
|
---|
35 |
|
---|
36 | void 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 |
|
---|
47 | namespace {
|
---|
48 | void doLookup( const std::list< Declaration * > & members, const std::string & name, std::list< Declaration* > & foundDecls ) {
|
---|
49 | for ( Declaration * decl : members ) {
|
---|
50 | if ( decl->name == name ) {
|
---|
51 | foundDecls.push_back( decl );
|
---|
52 | } // if
|
---|
53 | } // for
|
---|
54 | }
|
---|
55 | } // namespace
|
---|
56 |
|
---|
57 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
|
---|
58 | Parent( tq, baseStruct->name, attributes ), baseStruct( baseStruct ) {}
|
---|
59 |
|
---|
60 | std::string StructInstType::typeString() const { return "struct"; }
|
---|
61 |
|
---|
62 | const std::list<TypeDecl*>* StructInstType::get_baseParameters() const {
|
---|
63 | if ( ! baseStruct ) return nullptr;
|
---|
64 | return &baseStruct->get_parameters();
|
---|
65 | }
|
---|
66 |
|
---|
67 | std::list<TypeDecl*>* StructInstType::get_baseParameters() {
|
---|
68 | if ( ! baseStruct ) return nullptr;
|
---|
69 | return &baseStruct->get_parameters();
|
---|
70 | }
|
---|
71 |
|
---|
72 | bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
|
---|
73 |
|
---|
74 | AggregateDecl * StructInstType::getAggr() { return baseStruct; }
|
---|
75 |
|
---|
76 | TypeSubstitution StructInstType::genericSubstitution() const {
|
---|
77 | return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
|
---|
78 | }
|
---|
79 |
|
---|
80 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
|
---|
81 | assert( baseStruct );
|
---|
82 | doLookup( baseStruct->members, name, foundDecls );
|
---|
83 | }
|
---|
84 |
|
---|
85 | void 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 |
|
---|
100 | UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
|
---|
101 | Parent( tq, baseUnion->name, attributes ), baseUnion( baseUnion ) {}
|
---|
102 |
|
---|
103 | std::string UnionInstType::typeString() const { return "union"; }
|
---|
104 |
|
---|
105 | std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
|
---|
106 | if ( ! baseUnion ) return nullptr;
|
---|
107 | return &baseUnion->get_parameters();
|
---|
108 | }
|
---|
109 |
|
---|
110 | const std::list< TypeDecl * > * UnionInstType::get_baseParameters() const {
|
---|
111 | if ( ! baseUnion ) return nullptr;
|
---|
112 | return &baseUnion->get_parameters();
|
---|
113 | }
|
---|
114 |
|
---|
115 | bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
|
---|
116 |
|
---|
117 | AggregateDecl * UnionInstType::getAggr() { return baseUnion; }
|
---|
118 |
|
---|
119 | TypeSubstitution UnionInstType::genericSubstitution() const {
|
---|
120 | return TypeSubstitution( get_baseParameters()->begin(), get_baseParameters()->end(), parameters.begin() );
|
---|
121 | }
|
---|
122 |
|
---|
123 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
|
---|
124 | assert( baseUnion );
|
---|
125 | doLookup( baseUnion->members, name, foundDecls );
|
---|
126 | }
|
---|
127 |
|
---|
128 | void 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 |
|
---|
143 | EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
|
---|
144 | Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
|
---|
145 |
|
---|
146 | std::string EnumInstType::typeString() const { return "enum"; }
|
---|
147 |
|
---|
148 | bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
|
---|
149 |
|
---|
150 | void 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 |
|
---|
161 | std::string TraitInstType::typeString() const { return "trait"; }
|
---|
162 |
|
---|
163 | TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {}
|
---|
164 |
|
---|
165 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) {
|
---|
166 | }
|
---|
167 |
|
---|
168 | bool TraitInstType::isComplete() const { assert( false ); }
|
---|
169 |
|
---|
170 | TypeInstType::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 |
|
---|
174 | TypeInstType::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 |
|
---|
177 | TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
|
---|
178 | }
|
---|
179 |
|
---|
180 | void TypeInstType::set_baseType( TypeDecl *newValue ) {
|
---|
181 | baseType = newValue;
|
---|
182 | isFtype = newValue->get_kind() == TypeDecl::Ftype;
|
---|
183 | }
|
---|
184 |
|
---|
185 | std::string TypeInstType::typeString() const { return "type"; }
|
---|
186 |
|
---|
187 | bool TypeInstType::isComplete() const { return baseType->isComplete(); }
|
---|
188 |
|
---|
189 | void 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: //
|
---|