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::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) { |
---|
49 | std::list< Declaration* > found; |
---|
50 | for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { |
---|
51 | if ( (*i)->get_name() == name ) { |
---|
52 | found.push_back( *i ); |
---|
53 | } // if |
---|
54 | } // for |
---|
55 | applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) ); |
---|
56 | } |
---|
57 | } // namespace |
---|
58 | |
---|
59 | StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct ) : Parent( tq, baseStruct->get_name() ), baseStruct( baseStruct ) {} |
---|
60 | |
---|
61 | std::string StructInstType::typeString() const { return "struct"; } |
---|
62 | |
---|
63 | std::list<TypeDecl*>* StructInstType::get_baseParameters() { |
---|
64 | if ( ! baseStruct ) return NULL; |
---|
65 | return &baseStruct->get_parameters(); |
---|
66 | } |
---|
67 | |
---|
68 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
69 | assert( baseStruct ); |
---|
70 | doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls ); |
---|
71 | } |
---|
72 | |
---|
73 | void StructInstType::print( std::ostream &os, int indent ) const { |
---|
74 | using std::endl; |
---|
75 | |
---|
76 | if ( baseStruct == NULL ) ReferenceToType::print( os, indent ); |
---|
77 | else { |
---|
78 | Type::print( os, indent ); |
---|
79 | os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " "; |
---|
80 | if ( ! parameters.empty() ) { |
---|
81 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
82 | printAll( parameters, os, indent+2 ); |
---|
83 | } // if |
---|
84 | } // if |
---|
85 | } |
---|
86 | |
---|
87 | std::string UnionInstType::typeString() const { return "union"; } |
---|
88 | |
---|
89 | std::list<TypeDecl*>* UnionInstType::get_baseParameters() { |
---|
90 | if ( ! baseUnion ) return NULL; |
---|
91 | return &baseUnion->get_parameters(); |
---|
92 | } |
---|
93 | |
---|
94 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
95 | assert( baseUnion ); |
---|
96 | doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls ); |
---|
97 | } |
---|
98 | |
---|
99 | void UnionInstType::print( std::ostream &os, int indent ) const { |
---|
100 | using std::endl; |
---|
101 | |
---|
102 | if ( baseUnion == NULL ) ReferenceToType::print( os, indent ); |
---|
103 | else { |
---|
104 | Type::print( os, indent ); |
---|
105 | os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " "; |
---|
106 | if ( ! parameters.empty() ) { |
---|
107 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
108 | printAll( parameters, os, indent+2 ); |
---|
109 | } // if |
---|
110 | } // if |
---|
111 | } |
---|
112 | |
---|
113 | std::string EnumInstType::typeString() const { return "enum"; } |
---|
114 | |
---|
115 | std::string TraitInstType::typeString() const { return "context"; } |
---|
116 | |
---|
117 | TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) { |
---|
118 | cloneAll( other.members, members ); |
---|
119 | } |
---|
120 | |
---|
121 | TraitInstType::~TraitInstType() { |
---|
122 | deleteAll( members ); |
---|
123 | } |
---|
124 | |
---|
125 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { |
---|
126 | set_baseType( baseType ); |
---|
127 | } |
---|
128 | |
---|
129 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) { |
---|
130 | } |
---|
131 | |
---|
132 | TypeInstType::~TypeInstType() { |
---|
133 | // delete baseType; //This is shared and should not be deleted |
---|
134 | } |
---|
135 | |
---|
136 | void TypeInstType::set_baseType( TypeDecl *newValue ) { |
---|
137 | baseType = newValue; |
---|
138 | isFtype = newValue->get_kind() == TypeDecl::Ftype; |
---|
139 | } |
---|
140 | |
---|
141 | std::string TypeInstType::typeString() const { return "type"; } |
---|
142 | |
---|
143 | void TypeInstType::print( std::ostream &os, int indent ) const { |
---|
144 | using std::endl; |
---|
145 | |
---|
146 | Type::print( os, indent ); |
---|
147 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) "; |
---|
148 | if ( ! parameters.empty() ) { |
---|
149 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
150 | printAll( parameters, os, indent+2 ); |
---|
151 | } // if |
---|
152 | } |
---|
153 | |
---|
154 | // Local Variables: // |
---|
155 | // tab-width: 4 // |
---|
156 | // mode: c++ // |
---|
157 | // compile-command: "make install" // |
---|
158 | // End: // |
---|