Ignore:
Timestamp:
May 18, 2015, 11:20:23 AM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
51587aa
Parents:
a32b204
Message:

licencing: third groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/SynTree/TypeSubstitution.cc

    ra32b204 r0dd3a2f  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypeSubstitution.cc,v 1.9 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
     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// TypeSubstitution.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 11:10:04 2015
     13// Update Count     : 2
     14//
    715
    816#include "Type.h"
    917#include "TypeSubstitution.h"
    1018
    11 
    12 TypeSubstitution::TypeSubstitution()
    13 {
     19TypeSubstitution::TypeSubstitution() {
    1420}
    1521
    16 TypeSubstitution::TypeSubstitution( const TypeSubstitution &other )
    17 {
    18     initialize( other, *this );
     22TypeSubstitution::TypeSubstitution( const TypeSubstitution &other ) {
     23        initialize( other, *this );
    1924}
    2025
    21 TypeSubstitution::~TypeSubstitution()
    22 {
    23     for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    24         delete( i->second );
    25     }
    26     for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
    27         delete( i->second );
    28     }
     26TypeSubstitution::~TypeSubstitution() {
     27        for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     28                delete( i->second );
     29        }
     30        for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
     31                delete( i->second );
     32        }
    2933}
    3034
    31 TypeSubstitution &
    32 TypeSubstitution::operator=( const TypeSubstitution &other )
    33 {
    34     if ( this == &other ) return *this;
    35     initialize( other, *this );
    36     return *this;
     35TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) {
     36        if ( this == &other ) return *this;
     37        initialize( other, *this );
     38        return *this;
    3739}
    3840
    39 void
    40 TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest )
    41 {
    42     dest.typeEnv.clear();
    43     dest.varEnv.clear();
    44     dest.add( src );
     41void TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) {
     42        dest.typeEnv.clear();
     43        dest.varEnv.clear();
     44        dest.add( src );
    4545}
    4646
    47 void
    48 TypeSubstitution::add( const TypeSubstitution &other )
    49 {
    50     for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) {
    51         typeEnv[ i->first ] = i->second->clone();
    52     }
    53     for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) {
    54         varEnv[ i->first ] = i->second->clone();
    55     }
     47void TypeSubstitution::add( const TypeSubstitution &other ) {
     48        for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) {
     49                typeEnv[ i->first ] = i->second->clone();
     50        } // for
     51        for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) {
     52                varEnv[ i->first ] = i->second->clone();
     53        } // for
    5654}
    5755
    58 void
    59 TypeSubstitution::add( std::string formalType, Type *actualType )
    60 {
    61     TypeEnvType::iterator i = typeEnv.find( formalType );
    62     if ( i != typeEnv.end() ) {
    63         delete i->second;
    64     }
    65     typeEnv[ formalType ] = actualType->clone();
     56void TypeSubstitution::add( std::string formalType, Type *actualType ) {
     57        TypeEnvType::iterator i = typeEnv.find( formalType );
     58        if ( i != typeEnv.end() ) {
     59                delete i->second;
     60        } // if
     61        typeEnv[ formalType ] = actualType->clone();
    6662}
    6763
    68 void
    69 TypeSubstitution::remove( std::string formalType )
    70 {
    71     TypeEnvType::iterator i = typeEnv.find( formalType );
    72     if ( i != typeEnv.end() ) {
    73         delete i->second;
    74         typeEnv.erase( formalType );
    75     }
     64void TypeSubstitution::remove( std::string formalType ) {
     65        TypeEnvType::iterator i = typeEnv.find( formalType );
     66        if ( i != typeEnv.end() ) {
     67                delete i->second;
     68                typeEnv.erase( formalType );
     69        } // if
    7670}
    7771
    78 Type *
    79 TypeSubstitution::lookup( std::string formalType ) const
    80 {
    81     TypeEnvType::const_iterator i = typeEnv.find( formalType );
    82     if ( i == typeEnv.end() ) {
    83         return 0;
    84     } else {
    85         return i->second;
    86     }
     72Type *TypeSubstitution::lookup( std::string formalType ) const {
     73        TypeEnvType::const_iterator i = typeEnv.find( formalType );
     74        if ( i == typeEnv.end() ) {
     75                return 0;
     76        } else {
     77                return i->second;
     78        } // if
    8779}
    8880
    89 bool
    90 TypeSubstitution::empty() const
    91 {
    92     return typeEnv.empty() && varEnv.empty();
     81bool TypeSubstitution::empty() const {
     82        return typeEnv.empty() && varEnv.empty();
    9383}
    9484
    95 void
    96 TypeSubstitution::normalize()
    97 {
    98     do {
    99         subCount = 0;
    100         freeOnly = true;
    101         for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    102             i->second = i->second->acceptMutator( *this );
    103         }
    104     } while ( subCount );
     85void TypeSubstitution::normalize() {
     86        do {
     87                subCount = 0;
     88                freeOnly = true;
     89                for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     90                        i->second = i->second->acceptMutator( *this );
     91                }
     92        } while ( subCount );
    10593}
    10694
    107 Type*
    108 TypeSubstitution::mutate(TypeInstType *inst)
    109 {
    110     BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() );
    111     if ( bound != boundVars.end() ) return inst;
    112    
    113     TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() );
    114     if ( i == typeEnv.end() ) {
    115         return inst;
    116     } else {
     95Type * TypeSubstitution::mutate( TypeInstType *inst ) {
     96        BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() );
     97        if ( bound != boundVars.end() ) return inst;
     98       
     99        TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() );
     100        if ( i == typeEnv.end() ) {
     101                return inst;
     102        } else {
    117103///         std::cout << "found " << inst->get_name() << ", replacing with ";
    118104///         i->second->print( std::cout );
    119105///         std::cout << std::endl;
    120         subCount++;
    121         Type *newtype = i->second->clone();
    122         newtype->get_qualifiers() += inst->get_qualifiers();
    123         delete inst;
    124         return newtype;
    125     }
     106                subCount++;
     107                Type *newtype = i->second->clone();
     108                newtype->get_qualifiers() += inst->get_qualifiers();
     109                delete inst;
     110                return newtype;
     111        } // if
    126112}
    127113
    128 Expression*
    129 TypeSubstitution::mutate(NameExpr *nameExpr)
    130 {
    131     VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() );
    132     if ( i == varEnv.end() ) {
    133         return nameExpr;
    134     } else {
    135         subCount++;
    136         delete nameExpr;
    137         return i->second->clone();
    138     }
     114Expression * TypeSubstitution::mutate( NameExpr *nameExpr ) {
     115        VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() );
     116        if ( i == varEnv.end() ) {
     117                return nameExpr;
     118        } else {
     119                subCount++;
     120                delete nameExpr;
     121                return i->second->clone();
     122        } // if
    139123}
    140124
    141125template< typename TypeClass >
    142 Type *
    143 TypeSubstitution::handleType( TypeClass *type )
    144 {
    145     BoundVarsType oldBoundVars( boundVars );
    146     if ( freeOnly ) {
    147         for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
    148             boundVars.insert( (*tyvar)->get_name() );
    149         }
    150     }
    151     Type *ret = Mutator::mutate( type );
    152     boundVars = oldBoundVars;
    153     return ret;
     126Type *TypeSubstitution::handleType( TypeClass *type ) {
     127        BoundVarsType oldBoundVars( boundVars );
     128        if ( freeOnly ) {
     129                for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {
     130                        boundVars.insert( (*tyvar )->get_name() );
     131                } // for
     132        } // if
     133        Type *ret = Mutator::mutate( type );
     134        boundVars = oldBoundVars;
     135        return ret;
    154136}
    155137
    156 Type*
    157 TypeSubstitution::mutate(VoidType *basicType)
    158 {
    159     return handleType( basicType );
     138Type * TypeSubstitution::mutate( VoidType *basicType ) {
     139        return handleType( basicType );
    160140}
    161141
    162 Type*
    163 TypeSubstitution::mutate(BasicType *basicType)
    164 {
    165     return handleType( basicType );
     142Type * TypeSubstitution::mutate( BasicType *basicType ) {
     143        return handleType( basicType );
    166144}
    167145
    168 Type*
    169 TypeSubstitution::mutate(PointerType *pointerType)
    170 {
    171     return handleType( pointerType );
     146Type * TypeSubstitution::mutate( PointerType *pointerType ) {
     147        return handleType( pointerType );
    172148}
    173149
    174 Type*
    175 TypeSubstitution::mutate(ArrayType *arrayType)
    176 {
    177     return handleType( arrayType );
     150Type * TypeSubstitution::mutate( ArrayType *arrayType ) {
     151        return handleType( arrayType );
    178152}
    179153
    180 Type*
    181 TypeSubstitution::mutate(FunctionType *functionType)
    182 {
    183     return handleType( functionType );
     154Type * TypeSubstitution::mutate( FunctionType *functionType ) {
     155        return handleType( functionType );
    184156}
    185157
    186 Type*
    187 TypeSubstitution::mutate(StructInstType *aggregateUseType)
    188 {
    189     return handleType( aggregateUseType );
     158Type * TypeSubstitution::mutate( StructInstType *aggregateUseType ) {
     159        return handleType( aggregateUseType );
    190160}
    191161
    192 Type*
    193 TypeSubstitution::mutate(UnionInstType *aggregateUseType)
    194 {
    195     return handleType( aggregateUseType );
     162Type * TypeSubstitution::mutate( UnionInstType *aggregateUseType ) {
     163        return handleType( aggregateUseType );
    196164}
    197165
    198 Type*
    199 TypeSubstitution::mutate(EnumInstType *aggregateUseType)
    200 {
    201     return handleType( aggregateUseType );
     166Type * TypeSubstitution::mutate( EnumInstType *aggregateUseType ) {
     167        return handleType( aggregateUseType );
    202168}
    203169
    204 Type*
    205 TypeSubstitution::mutate(ContextInstType *aggregateUseType)
    206 {
    207     return handleType( aggregateUseType );
     170Type * TypeSubstitution::mutate( ContextInstType *aggregateUseType ) {
     171        return handleType( aggregateUseType );
    208172}
    209173
    210 Type*
    211 TypeSubstitution::mutate(TupleType *tupleType)
    212 {
    213     return handleType( tupleType );
     174Type * TypeSubstitution::mutate( TupleType *tupleType ) {
     175        return handleType( tupleType );
    214176}
    215177
    216 void
    217 TypeSubstitution::print( std::ostream &os, int indent ) const
    218 {
    219     os << std::string( indent, ' ' ) << "Types:" << std::endl;
    220     for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    221         os << std::string( indent+2, ' ' ) << i->first << " -> ";
    222         i->second->print( os, indent+4 );
    223         os << std::endl;
    224     }
    225     os << std::string( indent, ' ' ) << "Non-types:" << std::endl;
    226     for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
    227         os << std::string( indent+2, ' ' ) << i->first << " -> ";
    228         i->second->print( os, indent+4 );
    229         os << std::endl;
    230     }
     178void TypeSubstitution::print( std::ostream &os, int indent ) const {
     179        os << std::string( indent, ' ' ) << "Types:" << std::endl;
     180        for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     181                os << std::string( indent+2, ' ' ) << i->first << " -> ";
     182                i->second->print( os, indent+4 );
     183                os << std::endl;
     184        } // for
     185        os << std::string( indent, ' ' ) << "Non-types:" << std::endl;
     186        for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
     187                os << std::string( indent+2, ' ' ) << i->first << " -> ";
     188                i->second->print( os, indent+4 );
     189                os << std::endl;
     190        } // for
    231191}
    232192
     193// Local Variables: //
     194// tab-width: 4 //
     195// mode: c++ //
     196// compile-command: "make install" //
     197// End: //
Note: See TracChangeset for help on using the changeset viewer.