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 <stddef.h> // for NULL
|
---|
17 | #include <cassert> // for assert
|
---|
18 | #include <list> // for list, _List_const_iterator, list<>::cons...
|
---|
19 | #include <ostream> // for operator<<, basic_ostream, ostream, endl
|
---|
20 | #include <string> // for string, operator<<, char_traits, operator==
|
---|
21 |
|
---|
22 | #include "Common/utility.h" // for printAll, cloneAll, deleteAll
|
---|
23 | #include "Declaration.h" // for StructDecl, UnionDecl, EnumDecl, Declara...
|
---|
24 | #include "Expression.h" // for Expression
|
---|
25 | #include "Type.h" // for TypeInstType, StructInstType, UnionInstType
|
---|
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 | ReferenceToType::~ReferenceToType() {
|
---|
37 | deleteAll( parameters );
|
---|
38 | }
|
---|
39 |
|
---|
40 | void ReferenceToType::print( std::ostream &os, int 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 << std::string( indent, ' ' ) << "with parameters" << endl;
|
---|
47 | printAll( parameters, os, indent+2 );
|
---|
48 | } // if
|
---|
49 | }
|
---|
50 |
|
---|
51 | namespace {
|
---|
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 |
|
---|
61 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
|
---|
62 | Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
|
---|
63 |
|
---|
64 | std::string StructInstType::typeString() const { return "struct"; }
|
---|
65 |
|
---|
66 | std::list<TypeDecl*>* StructInstType::get_baseParameters() {
|
---|
67 | if ( ! baseStruct ) return NULL;
|
---|
68 | return &baseStruct->get_parameters();
|
---|
69 | }
|
---|
70 |
|
---|
71 | bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
|
---|
72 |
|
---|
73 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
|
---|
74 | assert( baseStruct );
|
---|
75 | doLookup( baseStruct->get_members(), name, foundDecls );
|
---|
76 | }
|
---|
77 |
|
---|
78 | void StructInstType::print( std::ostream &os, int indent ) const {
|
---|
79 | using std::endl;
|
---|
80 |
|
---|
81 | if ( baseStruct == NULL ) ReferenceToType::print( os, indent );
|
---|
82 | else {
|
---|
83 | Type::print( os, indent );
|
---|
84 | os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
|
---|
85 | if ( ! parameters.empty() ) {
|
---|
86 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
|
---|
87 | printAll( parameters, os, indent+2 );
|
---|
88 | } // if
|
---|
89 | } // if
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
|
---|
94 | Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
|
---|
95 |
|
---|
96 | std::string UnionInstType::typeString() const { return "union"; }
|
---|
97 |
|
---|
98 | std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
|
---|
99 | if ( ! baseUnion ) return NULL;
|
---|
100 | return &baseUnion->get_parameters();
|
---|
101 | }
|
---|
102 |
|
---|
103 | bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
|
---|
104 |
|
---|
105 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
|
---|
106 | assert( baseUnion );
|
---|
107 | doLookup( baseUnion->get_members(), name, foundDecls );
|
---|
108 | }
|
---|
109 |
|
---|
110 | void UnionInstType::print( std::ostream &os, int indent ) const {
|
---|
111 | using std::endl;
|
---|
112 |
|
---|
113 | if ( baseUnion == NULL ) ReferenceToType::print( os, indent );
|
---|
114 | else {
|
---|
115 | Type::print( os, indent );
|
---|
116 | os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
|
---|
117 | if ( ! parameters.empty() ) {
|
---|
118 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
|
---|
119 | printAll( parameters, os, indent+2 );
|
---|
120 | } // if
|
---|
121 | } // if
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
|
---|
126 | Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
|
---|
127 |
|
---|
128 | std::string EnumInstType::typeString() const { return "enum"; }
|
---|
129 |
|
---|
130 | bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
|
---|
131 |
|
---|
132 | std::string TraitInstType::typeString() const { return "trait"; }
|
---|
133 |
|
---|
134 | TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {}
|
---|
135 |
|
---|
136 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) {
|
---|
137 | }
|
---|
138 |
|
---|
139 | TraitInstType::~TraitInstType() {
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool TraitInstType::isComplete() const { assert( false ); }
|
---|
143 |
|
---|
144 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
|
---|
145 | set_baseType( baseType );
|
---|
146 | }
|
---|
147 |
|
---|
148 | 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 ) {
|
---|
149 | }
|
---|
150 |
|
---|
151 | TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | TypeInstType::~TypeInstType() {
|
---|
156 | // delete baseType; //This is shared and should not be deleted
|
---|
157 | }
|
---|
158 |
|
---|
159 | void TypeInstType::set_baseType( TypeDecl *newValue ) {
|
---|
160 | baseType = newValue;
|
---|
161 | isFtype = newValue->get_kind() == TypeDecl::Ftype;
|
---|
162 | }
|
---|
163 |
|
---|
164 | std::string TypeInstType::typeString() const { return "type"; }
|
---|
165 |
|
---|
166 | bool TypeInstType::isComplete() const { return baseType->isComplete(); }
|
---|
167 |
|
---|
168 | void TypeInstType::print( std::ostream &os, int indent ) const {
|
---|
169 | using std::endl;
|
---|
170 |
|
---|
171 | Type::print( os, indent );
|
---|
172 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
|
---|
173 | if ( ! parameters.empty() ) {
|
---|
174 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
|
---|
175 | printAll( parameters, os, indent+2 );
|
---|
176 | } // if
|
---|
177 | }
|
---|
178 |
|
---|
179 | // Local Variables: //
|
---|
180 | // tab-width: 4 //
|
---|
181 | // mode: c++ //
|
---|
182 | // compile-command: "make install" //
|
---|
183 | // End: //
|
---|