source: src/SynTree/ReferenceToType.cc@ 903f7c3

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 903f7c3 was 43c89a7, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

add hoistType flag (currently unused)

  • Property mode set to 100644
File size: 6.0 KB
Line 
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 <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
25ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) {
26}
27
28ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) {
29 cloneAll( other.parameters, parameters );
30}
31
32ReferenceToType::~ReferenceToType() {
33 deleteAll( parameters );
34}
35
36void 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
47namespace {
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
57StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
58 Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
59
60std::string StructInstType::typeString() const { return "struct"; }
61
62std::list<TypeDecl*>* StructInstType::get_baseParameters() {
63 if ( ! baseStruct ) return NULL;
64 return &baseStruct->get_parameters();
65}
66
67bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
68
69void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
70 assert( baseStruct );
71 doLookup( baseStruct->get_members(), name, foundDecls );
72}
73
74void StructInstType::print( std::ostream &os, int indent ) const {
75 using std::endl;
76
77 if ( baseStruct == NULL ) ReferenceToType::print( os, indent );
78 else {
79 Type::print( os, indent );
80 os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
81 if ( ! parameters.empty() ) {
82 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
83 printAll( parameters, os, indent+2 );
84 } // if
85 } // if
86}
87
88
89UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
90 Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
91
92std::string UnionInstType::typeString() const { return "union"; }
93
94std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
95 if ( ! baseUnion ) return NULL;
96 return &baseUnion->get_parameters();
97}
98
99bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
100
101void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
102 assert( baseUnion );
103 doLookup( baseUnion->get_members(), name, foundDecls );
104}
105
106void UnionInstType::print( std::ostream &os, int indent ) const {
107 using std::endl;
108
109 if ( baseUnion == NULL ) ReferenceToType::print( os, indent );
110 else {
111 Type::print( os, indent );
112 os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
113 if ( ! parameters.empty() ) {
114 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
115 printAll( parameters, os, indent+2 );
116 } // if
117 } // if
118}
119
120
121EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
122 Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
123
124std::string EnumInstType::typeString() const { return "enum"; }
125
126bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
127
128std::string TraitInstType::typeString() const { return "trait"; }
129
130TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) {
131 cloneAll( other.members, members );
132}
133
134TraitInstType::~TraitInstType() {
135 deleteAll( members );
136}
137
138bool TraitInstType::isComplete() const { assert( false ); }
139
140TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
141 set_baseType( baseType );
142}
143
144TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ), baseType( 0 ), isFtype( isFtype ) {
145}
146
147TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
148}
149
150
151TypeInstType::~TypeInstType() {
152 // delete baseType; //This is shared and should not be deleted
153}
154
155void TypeInstType::set_baseType( TypeDecl *newValue ) {
156 baseType = newValue;
157 isFtype = newValue->get_kind() == TypeDecl::Ftype;
158}
159
160std::string TypeInstType::typeString() const { return "type"; }
161
162bool TypeInstType::isComplete() const { return baseType->isComplete(); }
163
164void TypeInstType::print( std::ostream &os, int indent ) const {
165 using std::endl;
166
167 Type::print( os, indent );
168 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
169 if ( ! parameters.empty() ) {
170 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
171 printAll( parameters, os, indent+2 );
172 } // if
173}
174
175// Local Variables: //
176// tab-width: 4 //
177// mode: c++ //
178// compile-command: "make install" //
179// End: //
Note: See TracBrowser for help on using the repository browser.