source: src/SynTree/ReferenceToType.cc @ 574894d

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 574894d was 373d0b5, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Refactor getAggr as a Type member function

  • Property mode set to 100644
File size: 6.9 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 <cassert>           // for assert
17#include <list>              // for list, _List_const_iterator, list<>::cons...
18#include <ostream>           // for operator<<, basic_ostream, ostream, endl
19#include <string>            // for string, operator<<, char_traits, operator==
20
21#include "Common/utility.h"  // for printAll, cloneAll, deleteAll
22#include "Declaration.h"     // for StructDecl, UnionDecl, EnumDecl, Declara...
23#include "Expression.h"      // for Expression
24#include "Type.h"            // for TypeInstType, StructInstType, UnionInstType
25
26class Attribute;
27
28ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) {
29}
30
31ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) {
32        cloneAll( other.parameters, parameters );
33}
34
35ReferenceToType::~ReferenceToType() {
36        deleteAll( parameters );
37}
38
39void ReferenceToType::print( std::ostream &os, Indenter indent ) const {
40        using std::endl;
41
42        Type::print( os, indent );
43        os << "instance of " << typeString() << " " << name << " ";
44        if ( ! parameters.empty() ) {
45                os << endl << indent << "... with parameters" << endl;
46                printAll( parameters, os, indent+1 );
47        } // if
48}
49
50namespace {
51        void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {
52                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
53                        if ( (*i)->get_name() == name ) {
54                                foundDecls.push_back( *i );
55                        } // if
56                } // for
57        }
58} // namespace
59
60StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
61                Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
62
63std::string StructInstType::typeString() const { return "struct"; }
64
65std::list<TypeDecl*>* StructInstType::get_baseParameters() {
66        if ( ! baseStruct ) return nullptr;
67        return &baseStruct->get_parameters();
68}
69
70bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
71
72AggregateDecl * StructInstType::getAggr() { return baseStruct; }
73
74void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
75        assert( baseStruct );
76        doLookup( baseStruct->get_members(), name, foundDecls );
77}
78
79void StructInstType::print( std::ostream &os, Indenter indent ) const {
80        using std::endl;
81
82        if ( baseStruct == nullptr ) ReferenceToType::print( os, indent );
83        else {
84                Type::print( os, indent );
85                os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
86                if ( ! parameters.empty() ) {
87                        os << endl << indent << "... with parameters" << endl;
88                        printAll( parameters, os, indent+1 );
89                } // if
90        } // if
91}
92
93
94UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
95                Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
96
97std::string UnionInstType::typeString() const { return "union"; }
98
99std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
100        if ( ! baseUnion ) return nullptr;
101        return &baseUnion->get_parameters();
102}
103
104bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
105
106AggregateDecl * UnionInstType::getAggr() { return baseUnion; }
107
108void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
109        assert( baseUnion );
110        doLookup( baseUnion->get_members(), name, foundDecls );
111}
112
113void UnionInstType::print( std::ostream &os, Indenter indent ) const {
114        using std::endl;
115
116        if ( baseUnion == nullptr ) ReferenceToType::print( os, indent );
117        else {
118                Type::print( os, indent );
119                os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
120                if ( ! parameters.empty() ) {
121                        os << endl << indent << "... with parameters" << endl;
122                        printAll( parameters, os, indent+1 );
123                } // if
124        } // if
125}
126
127
128EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
129                Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
130
131std::string EnumInstType::typeString() const { return "enum"; }
132
133bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
134
135void EnumInstType::print( std::ostream &os, Indenter indent ) const {
136        using std::endl;
137
138        if ( baseEnum == nullptr ) ReferenceToType::print( os, indent );
139        else {
140                Type::print( os, indent );
141                os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body() << " ";
142        } // if
143}
144
145
146std::string TraitInstType::typeString() const { return "trait"; }
147
148TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {}
149
150TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) {
151}
152
153TraitInstType::~TraitInstType() {
154}
155
156bool TraitInstType::isComplete() const { assert( false ); }
157
158TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
159        set_baseType( baseType );
160}
161
162TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ), baseType( 0 ), isFtype( isFtype ) {
163}
164
165TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
166}
167
168
169TypeInstType::~TypeInstType() {
170        // delete baseType; //This is shared and should not be deleted
171}
172
173void TypeInstType::set_baseType( TypeDecl *newValue ) {
174        baseType = newValue;
175        isFtype = newValue->get_kind() == TypeDecl::Ftype;
176}
177
178std::string TypeInstType::typeString() const { return "type"; }
179
180bool TypeInstType::isComplete() const { return baseType->isComplete(); }
181
182void TypeInstType::print( std::ostream &os, Indenter indent ) const {
183        using std::endl;
184
185        Type::print( os, indent );
186        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
187        if ( ! parameters.empty() ) {
188                os << endl << indent << "... with parameters" << endl;
189                printAll( parameters, os, indent+1 );
190        } // if
191}
192
193// Local Variables: //
194// tab-width: 4 //
195// mode: c++ //
196// compile-command: "make install" //
197// End: //
Note: See TracBrowser for help on using the repository browser.