source: src/SynTree/ReferenceToType.cc@ a9fc180

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 a9fc180 was 4a9ccc3, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

propagate sized status through trait instances

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