source: translator/ResolvExpr/TypeEnvironment.h @ d0e8cfe4

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since d0e8cfe4 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
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 */
7
8#ifndef RESOLVEXPR_TYPEENVIRONMENT_H
9#define RESOLVEXPR_TYPEENVIRONMENT_H
10
11#include <string>
12#include <set>
13#include <list>
14#include <iostream>
15
16#include "SynTree/SynTree.h"
17#include "SynTree/Type.h"
18#include "SynTree/TypeSubstitution.h"
19#include "SynTree/Declaration.h"
20
21namespace ResolvExpr {
22
23typedef std::map< DeclarationWithType*, bool > AssertionSet;
24typedef std::map< std::string, TypeDecl::Kind > OpenVarSet;
25
26void printAssertionSet( const AssertionSet &, std::ostream &, int indent = 0 );
27void printOpenVarSet( const OpenVarSet &, std::ostream &, int indent = 0 );
28
29struct EqvClass
30{
31  std::set< std::string > vars;
32  Type *type;
33  bool allowWidening;
34  TypeDecl::Kind kind;
35 
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};
43
44class TypeEnvironment
45{
46public:
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(); }
66private:
67  std::list< EqvClass > env;
68 
69  std::list< EqvClass >::iterator internal_lookup( const std::string &var );
70};
71
72template< typename SynTreeClass >
73int 
74TypeEnvironment::apply( SynTreeClass *&type ) const
75{
76  TypeSubstitution sub;
77  makeSubstitution( sub );
78  return sub.apply( type );
79}
80
81template< typename SynTreeClass >
82int 
83TypeEnvironment::applyFree( SynTreeClass *&type ) const
84{
85  TypeSubstitution sub;
86  makeSubstitution( sub );
87  return sub.applyFree( type );
88}
89
90} // namespace ResolvExpr
91
92#endif /* #ifndef RESOLVEXPR_TYPEENVIRONMENT_H */
Note: See TracBrowser for help on using the repository browser.