source: src/ResolvExpr/TypeEnvironment.h @ fda7e90

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since fda7e90 was 8c49c0e, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

decouple code that uses Type's forall list from std::list in preparation for trying to replace with a managed list

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[a32b204]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//
[03da511]7// TypeEnvironment.h --
[a32b204]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//
[51b7345]15
[a32b204]16#ifndef TYPEENVIRONMENT_H
17#define TYPEENVIRONMENT_H
[51b7345]18
19#include <string>
20#include <set>
21#include <list>
22#include <iostream>
23
24#include "SynTree/SynTree.h"
25#include "SynTree/Type.h"
26#include "SynTree/TypeSubstitution.h"
27#include "SynTree/Declaration.h"
28
29namespace ResolvExpr {
[03da511]30        struct AssertCompare {
31                bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 );
32        };
33        typedef std::map< DeclarationWithType*, bool, AssertCompare > AssertionSet;
[a32b204]34        typedef std::map< std::string, TypeDecl::Kind > OpenVarSet;
[51b7345]35
[a32b204]36        void printAssertionSet( const AssertionSet &, std::ostream &, int indent = 0 );
37        void printOpenVarSet( const OpenVarSet &, std::ostream &, int indent = 0 );
[51b7345]38
[a32b204]39        struct EqvClass {
40                std::set< std::string > vars;
41                Type *type;
42                bool allowWidening;
43                TypeDecl::Kind kind;
[03da511]44
[a32b204]45                void initialize( const EqvClass &src, EqvClass &dest );
46                EqvClass();
47                EqvClass( const EqvClass &other );
48                EqvClass &operator=( const EqvClass &other );
49                ~EqvClass();
50                void print( std::ostream &os, int indent = 0 ) const;
51        };
[51b7345]52
[a32b204]53        class TypeEnvironment {
54          public:
55                bool lookup( const std::string &var, EqvClass &eqvClass ) const;
56                void add( const EqvClass &eqvClass );
[8c49c0e]57                void add( const Type::ForallList &tyDecls );
[a32b204]58                template< typename SynTreeClass > int apply( SynTreeClass *&type ) const;
59                template< typename SynTreeClass > int applyFree( SynTreeClass *&type ) const;
60                void makeSubstitution( TypeSubstitution &result ) const;
61                bool isEmpty() const { return env.empty(); }
62                void print( std::ostream &os, int indent = 0 ) const;
63                void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );
64                void simpleCombine( const TypeEnvironment &second );
65                void extractOpenVars( OpenVarSet &openVars ) const;
66                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
[03da511]67
[a32b204]68                typedef std::list< EqvClass >::iterator iterator;
69                iterator begin() { return env.begin(); }
70                iterator end() { return env.end(); }
71                typedef std::list< EqvClass >::const_iterator const_iterator;
72                const_iterator begin() const { return env.begin(); }
73                const_iterator end() const { return env.end(); }
74          private:
75                std::list< EqvClass > env;
76                std::list< EqvClass >::iterator internal_lookup( const std::string &var );
77        };
[51b7345]78
[a32b204]79        template< typename SynTreeClass >
80        int TypeEnvironment::apply( SynTreeClass *&type ) const {
81                TypeSubstitution sub;
82                makeSubstitution( sub );
83                return sub.apply( type );
84        }
[51b7345]85
[a32b204]86        template< typename SynTreeClass >
87        int TypeEnvironment::applyFree( SynTreeClass *&type ) const {
88                TypeSubstitution sub;
89                makeSubstitution( sub );
90                return sub.applyFree( type );
91        }
[51b7345]92} // namespace ResolvExpr
93
[a32b204]94#endif // TYPEENVIRONMENT_H */
95
96// Local Variables: //
97// tab-width: 4 //
98// mode: c++ //
99// compile-command: "make install" //
100// End: //
Note: See TracBrowser for help on using the repository browser.