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 : Wed Jul 13 18:03:30 2016 |
---|
13 | // Update Count : 9 |
---|
14 | // |
---|
15 | |
---|
16 | #include <string> |
---|
17 | #include <cassert> |
---|
18 | |
---|
19 | #include "Type.h" |
---|
20 | #include "Declaration.h" |
---|
21 | #include "Expression.h" |
---|
22 | #include "TypeSubstitution.h" |
---|
23 | #include "Common/utility.h" |
---|
24 | |
---|
25 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) { |
---|
26 | } |
---|
27 | |
---|
28 | ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) { |
---|
29 | cloneAll( other.parameters, parameters ); |
---|
30 | } |
---|
31 | |
---|
32 | ReferenceToType::~ReferenceToType() { |
---|
33 | deleteAll( parameters ); |
---|
34 | } |
---|
35 | |
---|
36 | void ReferenceToType::print( std::ostream &os, int 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 << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
43 | printAll( parameters, os, indent+2 ); |
---|
44 | } // if |
---|
45 | } |
---|
46 | |
---|
47 | namespace { |
---|
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 | |
---|
57 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct ) : Parent( tq, baseStruct->get_name() ), baseStruct( baseStruct ) {} |
---|
58 | |
---|
59 | std::string StructInstType::typeString() const { return "struct"; } |
---|
60 | |
---|
61 | std::list<TypeDecl*>* StructInstType::get_baseParameters() { |
---|
62 | if ( ! baseStruct ) return NULL; |
---|
63 | return &baseStruct->get_parameters(); |
---|
64 | } |
---|
65 | |
---|
66 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
67 | assert( baseStruct ); |
---|
68 | doLookup( baseStruct->get_members(), name, foundDecls ); |
---|
69 | } |
---|
70 | |
---|
71 | void StructInstType::print( std::ostream &os, int indent ) const { |
---|
72 | using std::endl; |
---|
73 | |
---|
74 | if ( baseStruct == NULL ) ReferenceToType::print( os, indent ); |
---|
75 | else { |
---|
76 | Type::print( os, indent ); |
---|
77 | os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " "; |
---|
78 | if ( ! parameters.empty() ) { |
---|
79 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
80 | printAll( parameters, os, indent+2 ); |
---|
81 | } // if |
---|
82 | } // if |
---|
83 | } |
---|
84 | |
---|
85 | std::string UnionInstType::typeString() const { return "union"; } |
---|
86 | |
---|
87 | std::list<TypeDecl*>* UnionInstType::get_baseParameters() { |
---|
88 | if ( ! baseUnion ) return NULL; |
---|
89 | return &baseUnion->get_parameters(); |
---|
90 | } |
---|
91 | |
---|
92 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
93 | assert( baseUnion ); |
---|
94 | doLookup( baseUnion->get_members(), name, foundDecls ); |
---|
95 | } |
---|
96 | |
---|
97 | void UnionInstType::print( std::ostream &os, int indent ) const { |
---|
98 | using std::endl; |
---|
99 | |
---|
100 | if ( baseUnion == NULL ) ReferenceToType::print( os, indent ); |
---|
101 | else { |
---|
102 | Type::print( os, indent ); |
---|
103 | os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " "; |
---|
104 | if ( ! parameters.empty() ) { |
---|
105 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
106 | printAll( parameters, os, indent+2 ); |
---|
107 | } // if |
---|
108 | } // if |
---|
109 | } |
---|
110 | |
---|
111 | std::string EnumInstType::typeString() const { return "enum"; } |
---|
112 | |
---|
113 | std::string TraitInstType::typeString() const { return "context"; } |
---|
114 | |
---|
115 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) { |
---|
116 | cloneAll( other.members, members ); |
---|
117 | } |
---|
118 | |
---|
119 | TraitInstType::~TraitInstType() { |
---|
120 | deleteAll( members ); |
---|
121 | } |
---|
122 | |
---|
123 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { |
---|
124 | set_baseType( baseType ); |
---|
125 | } |
---|
126 | |
---|
127 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) { |
---|
128 | } |
---|
129 | |
---|
130 | TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) { |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | TypeInstType::~TypeInstType() { |
---|
135 | // delete baseType; //This is shared and should not be deleted |
---|
136 | } |
---|
137 | |
---|
138 | void TypeInstType::set_baseType( TypeDecl *newValue ) { |
---|
139 | baseType = newValue; |
---|
140 | isFtype = newValue->get_kind() == TypeDecl::Ftype; |
---|
141 | } |
---|
142 | |
---|
143 | std::string TypeInstType::typeString() const { return "type"; } |
---|
144 | |
---|
145 | void TypeInstType::print( std::ostream &os, int indent ) const { |
---|
146 | using std::endl; |
---|
147 | |
---|
148 | Type::print( os, indent ); |
---|
149 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) "; |
---|
150 | if ( ! parameters.empty() ) { |
---|
151 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
152 | printAll( parameters, os, indent+2 ); |
---|
153 | } // if |
---|
154 | } |
---|
155 | |
---|
156 | // Local Variables: // |
---|
157 | // tab-width: 4 // |
---|
158 | // mode: c++ // |
---|
159 | // compile-command: "make install" // |
---|
160 | // End: // |
---|