source: src/SynTree/ReferenceToType.cc @ 122cac7

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 122cac7 was 4040425, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change keyword type to otype and context to trait

  • Property mode set to 100644
File size: 3.9 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//
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
[4040425]12// Last Modified On : Wed Mar  2 17:28:51 2016
13// Update Count     : 5
[0dd3a2f]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"
[d3b7937]23#include "Common/utility.h"
[51b7345]24
[0dd3a2f]25ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) {
[51b7345]26}
27
[0dd3a2f]28ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) {
[a08ba92]29        cloneAll( other.parameters, parameters );
[51b7345]30}
31
[0dd3a2f]32ReferenceToType::~ReferenceToType() {
[a08ba92]33        deleteAll( parameters );
[51b7345]34}
35
[0dd3a2f]36void ReferenceToType::print( std::ostream &os, int indent ) const {
[a08ba92]37        using std::endl;
38       
39        Type::print( os, indent );
40        os << "instance of " << typeString() << " " << name << " ";
41        if ( ! parameters.empty() ) {
[0dd3a2f]42                os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
43                printAll( parameters, os, indent+2 );
[a08ba92]44        } // if
[51b7345]45}
46
47namespace {
[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
59std::string StructInstType::typeString() const { return "struct"; }
60
[ed94eac]61std::list<TypeDecl*>* StructInstType::get_baseParameters() {
62        if ( ! baseStruct ) return NULL;
63        return &baseStruct->get_parameters();
64}
[37a3b8f9]65
[0dd3a2f]66void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
[a08ba92]67        assert( baseStruct );
68        doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls );
[51b7345]69}
70
71std::string UnionInstType::typeString() const { return "union"; }
72
[ed94eac]73std::list<TypeDecl*>* UnionInstType::get_baseParameters() {
74        if ( ! baseUnion ) return NULL;
75        return &baseUnion->get_parameters();
76}
[37a3b8f9]77
[0dd3a2f]78void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
[a08ba92]79        assert( baseUnion );
80        doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls );
[51b7345]81}
82
83std::string EnumInstType::typeString() const { return "enum"; }
84
[4040425]85std::string TraitInstType::typeString() const { return "context"; }
[51b7345]86
[4040425]87TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) {
[a08ba92]88        cloneAll( other.members, members );
[51b7345]89}
90
[4040425]91TraitInstType::~TraitInstType() {
[a08ba92]92        deleteAll( members );
[51b7345]93}
94
[0dd3a2f]95TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) {
[a08ba92]96        set_baseType( baseType );
[51b7345]97}
98
[0dd3a2f]99TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) {
[51b7345]100}
101
[0dd3a2f]102void TypeInstType::set_baseType( TypeDecl *newValue ) {
[a08ba92]103        baseType = newValue;
104        isFtype = newValue->get_kind() == TypeDecl::Ftype;
[51b7345]105}
106
107std::string TypeInstType::typeString() const { return "type"; }
108
[0dd3a2f]109void TypeInstType::print( std::ostream &os, int indent ) const {
[a08ba92]110        using std::endl;
111       
112        Type::print( os, indent );
[5f2f2d7]113        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
[a08ba92]114        if ( ! parameters.empty() ) {
[0dd3a2f]115                os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
116                printAll( parameters, os, indent+2 );
[a08ba92]117        } // if
[51b7345]118}
119
[0dd3a2f]120// Local Variables: //
121// tab-width: 4 //
122// mode: c++ //
123// compile-command: "make install" //
124// End: //
Note: See TracBrowser for help on using the repository browser.