source: src/ResolvExpr/TypeEnvironment.h @ b128d3e

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 b128d3e was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 3.8 KB
Line 
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 : Sat Jul 22 09:35:45 2017
13// Update Count     : 3
14//
15
16#pragma once
17
18#include <iostream>                    // for ostream
19#include <list>                        // for list, list<>::iterator, list<>...
20#include <map>                         // for map, map<>::value_compare
21#include <set>                         // for set
22#include <string>                      // for string
23
24#include "SynTree/Declaration.h"       // for TypeDecl::Data, DeclarationWit...
25#include "SynTree/SynTree.h"           // for UniqueId
26#include "SynTree/Type.h"              // for Type, Type::ForallList
27#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
28
29namespace ResolvExpr {
30        struct AssertCompare {
31                bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const;
32        };
33        struct AssertionSetValue {
34                bool isUsed;
35                // chain of Unique IDs of the assertion declarations. The first ID in the chain is the ID of an assertion on the current type,
36                // with each successive ID being the ID of an assertion pulled in by the previous ID. The last ID in the chain is
37                // the ID of the assertion that pulled in the current assertion.
38                std::list< UniqueId > idChain;
39        };
40        typedef std::map< DeclarationWithType*, AssertionSetValue, AssertCompare > AssertionSet;
41        typedef std::map< std::string, TypeDecl::Data > OpenVarSet;
42
43        void printAssertionSet( const AssertionSet &, std::ostream &, int indent = 0 );
44        void printOpenVarSet( const OpenVarSet &, std::ostream &, int indent = 0 );
45
46        struct EqvClass {
47                std::set< std::string > vars;
48                Type *type;
49                bool allowWidening;
50                TypeDecl::Data data;
51
52                void initialize( const EqvClass &src, EqvClass &dest );
53                EqvClass();
54                EqvClass( const EqvClass &other );
55                EqvClass &operator=( const EqvClass &other );
56                ~EqvClass();
57                void print( std::ostream &os, int indent = 0 ) const;
58        };
59
60        class TypeEnvironment {
61          public:
62                bool lookup( const std::string &var, EqvClass &eqvClass ) const;
63                void add( const EqvClass &eqvClass );
64                void add( const Type::ForallList &tyDecls );
65                template< typename SynTreeClass > int apply( SynTreeClass *&type ) const;
66                template< typename SynTreeClass > int applyFree( SynTreeClass *&type ) const;
67                void makeSubstitution( TypeSubstitution &result ) const;
68                bool isEmpty() const { return env.empty(); }
69                void print( std::ostream &os, int indent = 0 ) const;
70                void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );
71                void simpleCombine( const TypeEnvironment &second );
72                void extractOpenVars( OpenVarSet &openVars ) const;
73                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
74
75                typedef std::list< EqvClass >::iterator iterator;
76                iterator begin() { return env.begin(); }
77                iterator end() { return env.end(); }
78                typedef std::list< EqvClass >::const_iterator const_iterator;
79                const_iterator begin() const { return env.begin(); }
80                const_iterator end() const { return env.end(); }
81          private:
82                std::list< EqvClass > env;
83                std::list< EqvClass >::iterator internal_lookup( const std::string &var );
84        };
85
86        template< typename SynTreeClass >
87        int TypeEnvironment::apply( SynTreeClass *&type ) const {
88                TypeSubstitution sub;
89                makeSubstitution( sub );
90                return sub.apply( type );
91        }
92
93        template< typename SynTreeClass >
94        int TypeEnvironment::applyFree( SynTreeClass *&type ) const {
95                TypeSubstitution sub;
96                makeSubstitution( sub );
97                return sub.applyFree( type );
98        }
99} // namespace ResolvExpr
100
101// Local Variables: //
102// tab-width: 4 //
103// mode: c++ //
104// compile-command: "make install" //
105// End: //
Note: See TracBrowser for help on using the repository browser.