source: src/SynTree/ReferenceToType.cc @ c6747a1

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 c6747a1 was 6137fbb, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Print EnumInstType? body flag and other minor cleanup

  • Property mode set to 100644
File size: 6.8 KB
RevLine 
[0dd3a2f]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//
[1e8b02f5]7// ReferenceToType.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
[43c89a7]12// Last Modified On : Thu Feb 23 16:38:54 2017
13// Update Count     : 24
[0dd3a2f]14//
[51b7345]15
[ea6332d]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==
[51b7345]20
[ea6332d]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;
[51b7345]27
[43c89a7]28ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), name( name ), hoistType( false ) {
[51b7345]29}
30
[43c89a7]31ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) {
[a08ba92]32        cloneAll( other.parameters, parameters );
[51b7345]33}
34
[0dd3a2f]35ReferenceToType::~ReferenceToType() {
[a08ba92]36        deleteAll( parameters );
[51b7345]37}
38
[50377a4]39void ReferenceToType::print( std::ostream &os, Indenter indent ) const {
[a08ba92]40        using std::endl;
[1e8b02f5]41
[a08ba92]42        Type::print( os, indent );
43        os << "instance of " << typeString() << " " << name << " ";
44        if ( ! parameters.empty() ) {
[50377a4]45                os << endl << indent << "... with parameters" << endl;
46                printAll( parameters, os, indent+1 );
[a08ba92]47        } // if
[51b7345]48}
49
50namespace {
[33a7b6d]51        void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {
[0dd3a2f]52                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
53                        if ( (*i)->get_name() == name ) {
[33a7b6d]54                                foundDecls.push_back( *i );
[0dd3a2f]55                        } // if
56                } // for
[51b7345]57        }
58} // namespace
59
[c0aa336]60StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
61                Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
[f006f01]62
[51b7345]63std::string StructInstType::typeString() const { return "struct"; }
64
[ed94eac]65std::list<TypeDecl*>* StructInstType::get_baseParameters() {
[50377a4]66        if ( ! baseStruct ) return nullptr;
[ed94eac]67        return &baseStruct->get_parameters();
68}
[37a3b8f9]69
[c0aa336]70bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
[4a9ccc3]71
[0dd3a2f]72void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
[a08ba92]73        assert( baseStruct );
[33a7b6d]74        doLookup( baseStruct->get_members(), name, foundDecls );
[51b7345]75}
76
[50377a4]77void StructInstType::print( std::ostream &os, Indenter indent ) const {
[5d125e4]78        using std::endl;
79
[50377a4]80        if ( baseStruct == nullptr ) ReferenceToType::print( os, indent );
[5d125e4]81        else {
82                Type::print( os, indent );
83                os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
84                if ( ! parameters.empty() ) {
[50377a4]85                        os << endl << indent << "... with parameters" << endl;
86                        printAll( parameters, os, indent+1 );
[5d125e4]87                } // if
88        } // if
89}
90
[c0aa336]91
92UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
93                Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
94
[51b7345]95std::string UnionInstType::typeString() const { return "union"; }
96
[c0aa336]97std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
[50377a4]98        if ( ! baseUnion ) return nullptr;
[ed94eac]99        return &baseUnion->get_parameters();
100}
[37a3b8f9]101
[c0aa336]102bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
[4a9ccc3]103
[0dd3a2f]104void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
[a08ba92]105        assert( baseUnion );
[33a7b6d]106        doLookup( baseUnion->get_members(), name, foundDecls );
[51b7345]107}
108
[50377a4]109void UnionInstType::print( std::ostream &os, Indenter indent ) const {
[5d125e4]110        using std::endl;
111
[50377a4]112        if ( baseUnion == nullptr ) ReferenceToType::print( os, indent );
[5d125e4]113        else {
114                Type::print( os, indent );
115                os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
116                if ( ! parameters.empty() ) {
[50377a4]117                        os << endl << indent << "... with parameters" << endl;
118                        printAll( parameters, os, indent+1 );
[5d125e4]119                } // if
120        } // if
121}
122
[c0aa336]123
124EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
125                Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
126
[51b7345]127std::string EnumInstType::typeString() const { return "enum"; }
128
[c0aa336]129bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
130
[6137fbb]131void EnumInstType::print( std::ostream &os, Indenter indent ) const {
132        using std::endl;
133
134        if ( baseEnum == nullptr ) ReferenceToType::print( os, indent );
135        else {
136                Type::print( os, indent );
137                os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body() << " ";
138        } // if
139}
140
141
[4a9ccc3]142std::string TraitInstType::typeString() const { return "trait"; }
[51b7345]143
[be9036d]144TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {}
145
146TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) {
[51b7345]147}
148
[4040425]149TraitInstType::~TraitInstType() {
[51b7345]150}
151
[4a9ccc3]152bool TraitInstType::isComplete() const { assert( false ); }
153
[c0aa336]154TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
[a08ba92]155        set_baseType( baseType );
[51b7345]156}
157
[c0aa336]158TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ), baseType( 0 ), isFtype( isFtype ) {
[51b7345]159}
160
[2c57025]161TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
162}
163
164
[1e8b02f5]165TypeInstType::~TypeInstType() {
166        // delete baseType; //This is shared and should not be deleted
167}
168
[0dd3a2f]169void TypeInstType::set_baseType( TypeDecl *newValue ) {
[a08ba92]170        baseType = newValue;
171        isFtype = newValue->get_kind() == TypeDecl::Ftype;
[51b7345]172}
173
174std::string TypeInstType::typeString() const { return "type"; }
175
[4a9ccc3]176bool TypeInstType::isComplete() const { return baseType->isComplete(); }
177
[50377a4]178void TypeInstType::print( std::ostream &os, Indenter indent ) const {
[a08ba92]179        using std::endl;
[1e8b02f5]180
[a08ba92]181        Type::print( os, indent );
[5f2f2d7]182        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
[a08ba92]183        if ( ! parameters.empty() ) {
[50377a4]184                os << endl << indent << "... with parameters" << endl;
185                printAll( parameters, os, indent+1 );
[a08ba92]186        } // if
[51b7345]187}
188
[0dd3a2f]189// Local Variables: //
190// tab-width: 4 //
191// mode: c++ //
192// compile-command: "make install" //
193// End: //
Note: See TracBrowser for help on using the repository browser.