source: src/SynTree/ReferenceToType.cc @ ea593a3

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since ea593a3 was cd6a6ff, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Improved coverage of deterministic_output to be much finer grain.

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