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