source: src/SynTree/ReferenceToType.cc @ 39c7fd0

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 39c7fd0 was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

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