1 /********************* */
2 /*! \file declaration_scope.h
4 ** Original author: cconway
5 ** Major contributors: none
6 ** Minor contributors (to current version): dejan, mdeters
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief Convenience class for scoping variable and type declarations.
16 ** Convenience class for scoping variable and type declarations.
19 #include "cvc4_public.h"
21 #ifndef __CVC4__DECLARATION_SCOPE_H
22 #define __CVC4__DECLARATION_SCOPE_H
26 #include <ext/hash_map>
28 #include "expr/expr.h"
29 #include "util/hash.h"
31 #include "context/cdset_forward.h"
32 #include "context/cdmap_forward.h"
40 }/* CVC4::context namespace */
42 class CVC4_PUBLIC ScopeException
: public Exception
{
43 };/* class ScopeException */
46 * A convenience class for handling scoped declarations. Implements the usual
47 * nested scoping rules for declarations, with separate bindings for expressions
50 class CVC4_PUBLIC DeclarationScope
{
51 /** The context manager for the scope maps. */
52 context::Context
*d_context
;
54 /** A map for expressions. */
55 context::CDMap
<std::string
, Expr
, StringHashFunction
> *d_exprMap
;
57 /** A map for types. */
58 context::CDMap
<std::string
, std::pair
<std::vector
<Type
>, Type
>, StringHashFunction
> *d_typeMap
;
60 /** A set of defined functions. */
61 context::CDSet
<Expr
, ExprHashFunction
> *d_functions
;
64 /** Create a declaration scope. */
67 /** Destroy a declaration scope. */
71 * Bind an expression to a name in the current scope level. If
72 * <code>name</code> is already bound to an expression in the current
73 * level, then the binding is replaced. If <code>name</code> is bound
74 * in a previous level, then the binding is "covered" by this one
75 * until the current scope is popped.
77 * @param name an identifier
78 * @param obj the expression to bind to <code>name</code>
80 void bind(const std::string
& name
, Expr obj
) throw(AssertionException
);
83 * Bind a function body to a name in the current scope. If
84 * <code>name</code> is already bound to an expression in the current
85 * level, then the binding is replaced. If <code>name</code> is bound
86 * in a previous level, then the binding is "covered" by this one
87 * until the current scope is popped. Same as bind() but registers
88 * this as a function (so that isBoundDefinedFunction() returns true).
90 * @param name an identifier
91 * @param obj the expression to bind to <code>name</code>
93 void bindDefinedFunction(const std::string
& name
, Expr obj
) throw(AssertionException
);
96 * Bind a type to a name in the current scope. If <code>name</code>
97 * is already bound to a type in the current level, then the binding
98 * is replaced. If <code>name</code> is bound in a previous level,
99 * then the binding is "covered" by this one until the current scope
102 * @param name an identifier
103 * @param t the type to bind to <code>name</code>
105 void bindType(const std::string
& name
, Type t
) throw();
108 * Bind a type to a name in the current scope. If <code>name</code>
109 * is already bound to a type or type constructor in the current
110 * level, then the binding is replaced. If <code>name</code> is
111 * bound in a previous level, then the binding is "covered" by this
112 * one until the current scope is popped.
114 * @param name an identifier
115 * @param params the parameters to the type
116 * @param t the type to bind to <code>name</code>
118 void bindType(const std::string
& name
,
119 const std::vector
<Type
>& params
,
123 * Check whether a name is bound to an expression with either bind()
124 * or bindDefinedFunction().
126 * @param name the identifier to check.
127 * @returns true iff name is bound in the current scope.
129 bool isBound(const std::string
& name
) const throw();
132 * Check whether a name was bound to a function with bindDefinedFunction().
134 bool isBoundDefinedFunction(const std::string
& name
) const throw();
137 * Check whether a name is bound to a type (or type constructor).
139 * @param name the identifier to check.
140 * @returns true iff name is bound to a type in the current scope.
142 bool isBoundType(const std::string
& name
) const throw();
145 * Lookup a bound expression.
147 * @param name the identifier to lookup
148 * @returns the expression bound to <code>name</code> in the current scope.
150 Expr
lookup(const std::string
& name
) const throw(AssertionException
);
153 * Lookup a bound type.
155 * @param name the type identifier to lookup
156 * @returns the type bound to <code>name</code> in the current scope.
158 Type
lookupType(const std::string
& name
) const throw(AssertionException
);
161 * Lookup a bound parameterized type.
163 * @param name the type-constructor identifier to lookup
164 * @param params the types to use to parameterize the type
165 * @returns the type bound to <code>name(<i>params</i>)</code> in
168 Type
lookupType(const std::string
& name
,
169 const std::vector
<Type
>& params
) const throw(AssertionException
);
172 * Pop a scope level. Deletes all bindings since the last call to
173 * <code>pushScope</code>. Calls to <code>pushScope</code> and
174 * <code>popScope</code> must be "properly nested." I.e., a call to
175 * <code>popScope</code> is only legal if the number of prior calls to
176 * <code>pushScope</code> on this <code>DeclarationScope</code> is strictly
177 * greater than then number of prior calls to <code>popScope</code>. */
178 void popScope() throw(ScopeException
);
180 /** Push a scope level. */
181 void pushScope() throw();
183 };/* class DeclarationScope */
185 }/* CVC4 namespace */
187 #endif /* __CVC4__DECLARATION_SCOPE_H */