[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 | // |
---|
| 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 : Mon May 18 10:49:00 2015 |
---|
| 13 | // Update Count : 2 |
---|
| 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #include <string> |
---|
| 17 | #include <cassert> |
---|
| 18 | |
---|
| 19 | #include "Type.h" |
---|
| 20 | #include "Declaration.h" |
---|
| 21 | #include "Expression.h" |
---|
| 22 | #include "TypeSubstitution.h" |
---|
| 23 | #include "utility.h" |
---|
| 24 | |
---|
[0dd3a2f] | 25 | ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) { |
---|
[51b7345] | 26 | } |
---|
| 27 | |
---|
[0dd3a2f] | 28 | ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) { |
---|
[51b7345] | 29 | cloneAll( other.parameters, parameters ); |
---|
| 30 | } |
---|
| 31 | |
---|
[0dd3a2f] | 32 | ReferenceToType::~ReferenceToType() { |
---|
[51b7345] | 33 | deleteAll( parameters ); |
---|
| 34 | } |
---|
| 35 | |
---|
[0dd3a2f] | 36 | void ReferenceToType::print( std::ostream &os, int indent ) const { |
---|
[51b7345] | 37 | using std::endl; |
---|
| 38 | |
---|
| 39 | Type::print( os, indent ); |
---|
| 40 | os << "instance of " << typeString() << " " << name << " "; |
---|
[a32b204] | 41 | if ( ! parameters.empty() ) { |
---|
[0dd3a2f] | 42 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 43 | printAll( parameters, os, indent+2 ); |
---|
| 44 | } // if |
---|
[51b7345] | 45 | } |
---|
| 46 | |
---|
| 47 | namespace { |
---|
[0dd3a2f] | 48 | void doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) { |
---|
| 49 | std::list< Declaration* > found; |
---|
| 50 | for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { |
---|
| 51 | if ( (*i)->get_name() == name ) { |
---|
| 52 | found.push_back( *i ); |
---|
| 53 | } // if |
---|
| 54 | } // for |
---|
| 55 | applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) ); |
---|
[51b7345] | 56 | } |
---|
| 57 | } // namespace |
---|
| 58 | |
---|
| 59 | std::string StructInstType::typeString() const { return "struct"; } |
---|
| 60 | |
---|
[0dd3a2f] | 61 | void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[51b7345] | 62 | assert( baseStruct ); |
---|
| 63 | doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls ); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | std::string UnionInstType::typeString() const { return "union"; } |
---|
| 67 | |
---|
[0dd3a2f] | 68 | void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { |
---|
[51b7345] | 69 | assert( baseUnion ); |
---|
| 70 | doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls ); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | std::string EnumInstType::typeString() const { return "enum"; } |
---|
| 74 | |
---|
| 75 | std::string ContextInstType::typeString() const { return "context"; } |
---|
| 76 | |
---|
[0dd3a2f] | 77 | ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) { |
---|
[51b7345] | 78 | cloneAll( other.members, members ); |
---|
| 79 | } |
---|
| 80 | |
---|
[0dd3a2f] | 81 | ContextInstType::~ContextInstType() { |
---|
[51b7345] | 82 | deleteAll( members ); |
---|
| 83 | } |
---|
| 84 | |
---|
[0dd3a2f] | 85 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { |
---|
[51b7345] | 86 | set_baseType( baseType ); |
---|
| 87 | } |
---|
| 88 | |
---|
[0dd3a2f] | 89 | TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) { |
---|
[51b7345] | 90 | } |
---|
| 91 | |
---|
[0dd3a2f] | 92 | void TypeInstType::set_baseType( TypeDecl *newValue ) { |
---|
[51b7345] | 93 | baseType = newValue; |
---|
| 94 | isFtype = newValue->get_kind() == TypeDecl::Ftype; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | std::string TypeInstType::typeString() const { return "type"; } |
---|
| 98 | |
---|
[0dd3a2f] | 99 | void TypeInstType::print( std::ostream &os, int indent ) const { |
---|
[51b7345] | 100 | using std::endl; |
---|
| 101 | |
---|
| 102 | Type::print( os, indent ); |
---|
| 103 | os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) "; |
---|
[a32b204] | 104 | if ( ! parameters.empty() ) { |
---|
[0dd3a2f] | 105 | os << endl << std::string( indent, ' ' ) << "with parameters" << endl; |
---|
| 106 | printAll( parameters, os, indent+2 ); |
---|
| 107 | } // if |
---|
[51b7345] | 108 | } |
---|
| 109 | |
---|
[0dd3a2f] | 110 | // Local Variables: // |
---|
| 111 | // tab-width: 4 // |
---|
| 112 | // mode: c++ // |
---|
| 113 | // compile-command: "make install" // |
---|
| 114 | // End: // |
---|