Ignore:
Timestamp:
May 17, 2015, 1:19:35 PM (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:
0dd3a2f
Parents:
b87a5ed
Message:

licencing: second groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/ResolvExpr/TypeEnvironment.h

    rb87a5ed ra32b204  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypeEnvironment.h,v 1.8 2005/08/29 20:14:16 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// TypeEnvironment.h --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 12:24:58 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 12:26:52 2015
     13// Update Count     : 2
     14//
    715
    8 #ifndef RESOLVEXPR_TYPEENVIRONMENT_H
    9 #define RESOLVEXPR_TYPEENVIRONMENT_H
     16#ifndef TYPEENVIRONMENT_H
     17#define TYPEENVIRONMENT_H
    1018
    1119#include <string>
     
    2028
    2129namespace ResolvExpr {
     30        typedef std::map< DeclarationWithType*, bool > AssertionSet;
     31        typedef std::map< std::string, TypeDecl::Kind > OpenVarSet;
    2232
    23 typedef std::map< DeclarationWithType*, bool > AssertionSet;
    24 typedef std::map< std::string, TypeDecl::Kind > OpenVarSet;
     33        void printAssertionSet( const AssertionSet &, std::ostream &, int indent = 0 );
     34        void printOpenVarSet( const OpenVarSet &, std::ostream &, int indent = 0 );
    2535
    26 void printAssertionSet( const AssertionSet &, std::ostream &, int indent = 0 );
    27 void printOpenVarSet( const OpenVarSet &, std::ostream &, int indent = 0 );
     36        struct EqvClass {
     37                std::set< std::string > vars;
     38                Type *type;
     39                bool allowWidening;
     40                TypeDecl::Kind kind;
     41 
     42                void initialize( const EqvClass &src, EqvClass &dest );
     43                EqvClass();
     44                EqvClass( const EqvClass &other );
     45                EqvClass &operator=( const EqvClass &other );
     46                ~EqvClass();
     47                void print( std::ostream &os, int indent = 0 ) const;
     48        };
    2849
    29 struct EqvClass
    30 {
    31   std::set< std::string > vars;
    32   Type *type;
    33   bool allowWidening;
    34   TypeDecl::Kind kind;
     50        class TypeEnvironment {
     51          public:
     52                bool lookup( const std::string &var, EqvClass &eqvClass ) const;
     53                void add( const EqvClass &eqvClass );
     54                void add( const std::list< TypeDecl* > &tyDecls );
     55                template< typename SynTreeClass > int apply( SynTreeClass *&type ) const;
     56                template< typename SynTreeClass > int applyFree( SynTreeClass *&type ) const;
     57                void makeSubstitution( TypeSubstitution &result ) const;
     58                bool isEmpty() const { return env.empty(); }
     59                void print( std::ostream &os, int indent = 0 ) const;
     60                void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );
     61                void simpleCombine( const TypeEnvironment &second );
     62                void extractOpenVars( OpenVarSet &openVars ) const;
     63                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
    3564 
    36   void initialize( const EqvClass &src, EqvClass &dest );
    37   EqvClass();
    38   EqvClass( const EqvClass &other );
    39   EqvClass &operator=( const EqvClass &other );
    40   ~EqvClass();
    41   void print( std::ostream &os, int indent = 0 ) const;
    42 };
     65                typedef std::list< EqvClass >::iterator iterator;
     66                iterator begin() { return env.begin(); }
     67                iterator end() { return env.end(); }
     68                typedef std::list< EqvClass >::const_iterator const_iterator;
     69                const_iterator begin() const { return env.begin(); }
     70                const_iterator end() const { return env.end(); }
     71          private:
     72                std::list< EqvClass > env;
     73                std::list< EqvClass >::iterator internal_lookup( const std::string &var );
     74        };
    4375
    44 class TypeEnvironment
    45 {
    46 public:
    47   bool lookup( const std::string &var, EqvClass &eqvClass ) const;
    48   void add( const EqvClass &eqvClass );
    49   void add( const std::list< TypeDecl* > &tyDecls );
    50   template< typename SynTreeClass > int apply( SynTreeClass *&type ) const;
    51   template< typename SynTreeClass > int applyFree( SynTreeClass *&type ) const;
    52   void makeSubstitution( TypeSubstitution &result ) const;
    53   bool isEmpty() const { return env.empty(); }
    54   void print( std::ostream &os, int indent = 0 ) const;
    55   void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );
    56   void simpleCombine( const TypeEnvironment &second );
    57   void extractOpenVars( OpenVarSet &openVars ) const;
    58   TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
    59  
    60   typedef std::list< EqvClass >::iterator iterator;
    61   iterator begin() { return env.begin(); }
    62   iterator end() { return env.end(); }
    63   typedef std::list< EqvClass >::const_iterator const_iterator;
    64   const_iterator begin() const { return env.begin(); }
    65   const_iterator end() const { return env.end(); }
    66 private:
    67   std::list< EqvClass > env;
    68  
    69   std::list< EqvClass >::iterator internal_lookup( const std::string &var );
    70 };
     76        template< typename SynTreeClass >
     77        int TypeEnvironment::apply( SynTreeClass *&type ) const {
     78                TypeSubstitution sub;
     79                makeSubstitution( sub );
     80                return sub.apply( type );
     81        }
    7182
    72 template< typename SynTreeClass >
    73 int
    74 TypeEnvironment::apply( SynTreeClass *&type ) const
    75 {
    76   TypeSubstitution sub;
    77   makeSubstitution( sub );
    78   return sub.apply( type );
    79 }
    80 
    81 template< typename SynTreeClass >
    82 int
    83 TypeEnvironment::applyFree( SynTreeClass *&type ) const
    84 {
    85   TypeSubstitution sub;
    86   makeSubstitution( sub );
    87   return sub.applyFree( type );
    88 }
    89 
     83        template< typename SynTreeClass >
     84        int TypeEnvironment::applyFree( SynTreeClass *&type ) const {
     85                TypeSubstitution sub;
     86                makeSubstitution( sub );
     87                return sub.applyFree( type );
     88        }
    9089} // namespace ResolvExpr
    9190
    92 #endif /* #ifndef RESOLVEXPR_TYPEENVIRONMENT_H */
     91#endif // TYPEENVIRONMENT_H */
     92
     93// Local Variables: //
     94// tab-width: 4 //
     95// mode: c++ //
     96// compile-command: "make install" //
     97// End: //
Note: See TracChangeset for help on using the changeset viewer.