source: translator/SynTree/ReferenceToType.cc @ 48e99f2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 48e99f2 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: ReferenceToType.cc,v 1.16 2005/08/29 20:59:26 rcbilson Exp $
5 *
6 */
7
8#include <string>
9#include <cassert>
10
11#include "Type.h"
12#include "Declaration.h"
13#include "Expression.h"
14#include "TypeSubstitution.h"
15#include "utility.h"
16
17
18ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name )
19    : Type( tq ), name( name )
20{
21}
22
23ReferenceToType::ReferenceToType( const ReferenceToType &other )
24    : Type( other ), name( other.name )
25{
26    cloneAll( other.parameters, parameters );
27}
28
29ReferenceToType::~ReferenceToType()
30{
31    deleteAll( parameters );
32}
33
34void 
35ReferenceToType::print( std::ostream &os, int indent ) const
36{
37    using std::endl;
38   
39    Type::print( os, indent );
40    os << "instance of " << typeString() << " " << name << " ";
41    if( !parameters.empty() ) {
42        os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
43        printAll( parameters, os, indent+2 );
44    }
45}
46
47namespace {
48
49void
50doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls )
51{
52    std::list< Declaration* > found;
53    for( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
54        if( (*i)->get_name() == name ) {
55            found.push_back( *i );
56        }
57    }
58    applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) );
59}
60
61} // namespace
62
63std::string StructInstType::typeString() const { return "struct"; }
64
65void
66StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const
67{
68    assert( baseStruct );
69    doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls );
70}
71
72std::string UnionInstType::typeString() const { return "union"; }
73
74void
75UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const
76{
77    assert( baseUnion );
78    doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls );
79}
80
81std::string EnumInstType::typeString() const { return "enum"; }
82
83std::string ContextInstType::typeString() const { return "context"; }
84
85ContextInstType::ContextInstType( const ContextInstType &other )
86    : Parent( other )
87{
88    cloneAll( other.members, members );
89}
90
91ContextInstType::~ContextInstType()
92{
93    deleteAll( members );
94}
95
96TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name )
97{
98    set_baseType( baseType );
99}
100
101TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype )
102{
103}
104
105void TypeInstType::set_baseType( TypeDecl *newValue )
106{
107    baseType = newValue;
108    isFtype = newValue->get_kind() == TypeDecl::Ftype;
109}
110
111std::string TypeInstType::typeString() const { return "type"; }
112
113void 
114TypeInstType::print( std::ostream &os, int indent ) const
115{
116    using std::endl;
117   
118    Type::print( os, indent );
119    os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) ";
120    if( !parameters.empty() ) {
121        os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
122        printAll( parameters, os, indent+2 );
123    }
124}
125
Note: See TracBrowser for help on using the repository browser.