source: src/SynTree/ReferenceToType.cc@ b05a4eb

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 b05a4eb was 50377a4, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Refactor tree print code to use Indenter

  • Property mode set to 100644
File size: 6.5 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
72void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
73 assert( baseStruct );
74 doLookup( baseStruct->get_members(), name, foundDecls );
75}
76
77void StructInstType::print( std::ostream &os, Indenter indent ) const {
78 using std::endl;
79
80 if ( baseStruct == nullptr ) ReferenceToType::print( os, indent );
81 else {
82 Type::print( os, indent );
83 os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
84 if ( ! parameters.empty() ) {
85 os << endl << indent << "... with parameters" << endl;
86 printAll( parameters, os, indent+1 );
87 } // if
88 } // if
89}
90
91
92UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
93 Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
94
95std::string UnionInstType::typeString() const { return "union"; }
96
97std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
98 if ( ! baseUnion ) return nullptr;
99 return &baseUnion->get_parameters();
100}
101
102bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
103
104void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
105 assert( baseUnion );
106 doLookup( baseUnion->get_members(), name, foundDecls );
107}
108
109void UnionInstType::print( std::ostream &os, Indenter indent ) const {
110 using std::endl;
111
112 if ( baseUnion == nullptr ) ReferenceToType::print( os, indent );
113 else {
114 Type::print( os, indent );
115 os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
116 if ( ! parameters.empty() ) {
117 os << endl << indent << "... with parameters" << endl;
118 printAll( parameters, os, indent+1 );
119 } // if
120 } // if
121}
122
123
124EnumInstType::EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes ) :
125 Parent( tq, baseEnum->get_name(), attributes ), baseEnum( baseEnum ) {}
126
127std::string EnumInstType::typeString() const { return "enum"; }
128
129bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
130
131std::string TraitInstType::typeString() const { return "trait"; }
132
133TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {}
134
135TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) {
136}
137
138TraitInstType::~TraitInstType() {
139}
140
141bool TraitInstType::isComplete() const { assert( false ); }
142
143TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ) {
144 set_baseType( baseType );
145}
146
147TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype, const std::list< Attribute * > & attributes ) : Parent( tq, name, attributes ), baseType( 0 ), isFtype( isFtype ) {
148}
149
150TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {
151}
152
153
154TypeInstType::~TypeInstType() {
155 // delete baseType; //This is shared and should not be deleted
156}
157
158void TypeInstType::set_baseType( TypeDecl *newValue ) {
159 baseType = newValue;
160 isFtype = newValue->get_kind() == TypeDecl::Ftype;
161}
162
163std::string TypeInstType::typeString() const { return "type"; }
164
165bool TypeInstType::isComplete() const { return baseType->isComplete(); }
166
167void TypeInstType::print( std::ostream &os, Indenter indent ) const {
168 using std::endl;
169
170 Type::print( os, indent );
171 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
172 if ( ! parameters.empty() ) {
173 os << endl << indent << "... with parameters" << endl;
174 printAll( parameters, os, indent+1 );
175 } // if
176}
177
178// Local Variables: //
179// tab-width: 4 //
180// mode: c++ //
181// compile-command: "make install" //
182// End: //
Note: See TracBrowser for help on using the repository browser.