source: src/ResolvExpr/TypeEnvironment.h@ c93bc28

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since c93bc28 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change #ifndef to #pragma once

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