source: src/ResolvExpr/TypeEnvironment.h @ 03bb816

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 03bb816 was 6c3a988f, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

fix inferred parameter data structures to correctly associate parameters with the entity that requested them, modify tuple specialization and unification to work with self-recursive assertions

  • Property mode set to 100644
File size: 3.5 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 : Sun May 17 12:26:52 2015
13// Update Count     : 2
14//
15
16#ifndef TYPEENVIRONMENT_H
17#define TYPEENVIRONMENT_H
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 {
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#endif // TYPEENVIRONMENT_H */
102
103// Local Variables: //
104// tab-width: 4 //
105// mode: c++ //
106// compile-command: "make install" //
107// End: //
Note: See TracBrowser for help on using the repository browser.