Skip to content

Commit f4d8ef7

Browse files
author
Daniel Kroening
committed
add next_symbol_exprt
1 parent d87c2db commit f4d8ef7

File tree

3 files changed

+102
-39
lines changed

3 files changed

+102
-39
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ std::string expr2ct::convert_norep(
16601660
}
16611661

16621662
std::string expr2ct::convert_symbol(
1663-
const exprt &src,
1663+
const symbol_exprt &src,
16641664
unsigned &precedence)
16651665
{
16661666
const irep_idt &id=src.get(ID_identifier);
@@ -1701,6 +1701,14 @@ std::string expr2ct::convert_symbol(
17011701
return dest;
17021702
}
17031703

1704+
std::string expr2ct::convert_next_symbol(
1705+
const next_symbol_exprt &src,
1706+
unsigned &precedence)
1707+
{
1708+
const irep_idt id=src.get_identifier();
1709+
return "NEXT("+id2string(id)+")";
1710+
}
1711+
17041712
std::string expr2ct::convert_nondet_symbol(
17051713
const nondet_symbol_exprt &src,
17061714
unsigned &precedence)
@@ -3844,10 +3852,10 @@ std::string expr2ct::convert_with_precedence(
38443852
return precedence=16, convert_index_designator(src);
38453853

38463854
else if(src.id()==ID_symbol)
3847-
return convert_symbol(src, precedence);
3855+
return convert_symbol(to_symbol_expr(src), precedence);
38483856

38493857
else if(src.id()==ID_next_symbol)
3850-
return convert_symbol(src, precedence);
3858+
return convert_next_symbol(to_next_symbol_expr(src), precedence);
38513859

38523860
else if(src.id()==ID_nondet_symbol)
38533861
return convert_nondet_symbol(to_nondet_symbol_expr(src), precedence);

src/ansi-c/expr2c_class.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ class expr2ct
223223
// NOLINTNEXTLINE(whitespace/line_length)
224224
std::string convert_statement_expression(const exprt &src, unsigned &precendence);
225225

226-
virtual std::string convert_symbol(const exprt &src, unsigned &precedence);
226+
virtual std::string convert_symbol(const symbol_exprt &src, unsigned &precedence);
227+
virtual std::string convert_next_symbol(const next_symbol_exprt &src, unsigned &precedence);
227228
std::string convert_predicate_symbol(const exprt &src, unsigned &precedence);
228229
// NOLINTNEXTLINE(whitespace/line_length)
229230
std::string convert_predicate_next_symbol(const exprt &src, unsigned &precedence);

src/util/std_expr.h

Lines changed: 89 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,95 @@ class symbol_exprt:public exprt
131131
}
132132
};
133133

134+
/*! \brief Cast a generic exprt to a \ref symbol_exprt
135+
*
136+
* This is an unchecked conversion. \a expr must be known to be \ref
137+
* symbol_exprt.
138+
*
139+
* \param expr Source expression
140+
* \return Object of type \ref symbol_exprt
141+
*
142+
* \ingroup gr_std_expr
143+
*/
144+
inline const symbol_exprt &to_symbol_expr(const exprt &expr)
145+
{
146+
PRECONDITION(expr.id()==ID_symbol);
147+
DATA_INVARIANT(!expr.has_operands(), "Symbols must not have operands");
148+
return static_cast<const symbol_exprt &>(expr);
149+
}
150+
151+
/*! \copydoc to_symbol_expr(const exprt &)
152+
* \ingroup gr_std_expr
153+
*/
154+
inline symbol_exprt &to_symbol_expr(exprt &expr)
155+
{
156+
PRECONDITION(expr.id()==ID_symbol);
157+
DATA_INVARIANT(!expr.has_operands(), "Symbols must not have operands");
158+
return static_cast<symbol_exprt &>(expr);
159+
}
160+
161+
template<> inline bool can_cast_expr<symbol_exprt>(const exprt &base)
162+
{
163+
return base.id()==ID_symbol;
164+
}
165+
inline void validate_expr(const symbol_exprt &value)
166+
{
167+
validate_operands(value, 0, "Symbols must not have operands");
168+
}
169+
170+
/*! \brief Expression to hold a "next state" symbol (variable)
171+
*/
172+
class next_symbol_exprt:public symbol_exprt
173+
{
174+
public:
175+
/*! \brief Constructor
176+
* \param identifier Name of symbol
177+
* \param type Type of symbol
178+
*/
179+
next_symbol_exprt(
180+
const irep_idt &identifier,
181+
const typet &type):symbol_exprt(identifier, type)
182+
{
183+
id(ID_next_symbol);
184+
}
185+
};
186+
187+
/*! \brief Cast a generic exprt to a \ref next_symbol_exprt
188+
*
189+
* This is an unchecked conversion. \a expr must be known to be \ref
190+
* next_symbol_exprt.
191+
*
192+
* \param expr Source expression
193+
* \return Object of type \ref next_symbol_exprt
194+
*
195+
* \ingroup gr_std_expr
196+
*/
197+
inline const next_symbol_exprt &to_next_symbol_expr(const exprt &expr)
198+
{
199+
PRECONDITION(expr.id()==ID_next_symbol);
200+
DATA_INVARIANT(!expr.has_operands(), "Symbols must not have operands");
201+
return static_cast<const next_symbol_exprt &>(expr);
202+
}
203+
204+
/*! \copydoc to_next_symbol_expr(const exprt &)
205+
* \ingroup gr_std_expr
206+
*/
207+
inline next_symbol_exprt &to_next_symbol_expr(exprt &expr)
208+
{
209+
PRECONDITION(expr.id()==ID_next_symbol);
210+
DATA_INVARIANT(!expr.has_operands(), "Symbols must not have operands");
211+
return static_cast<next_symbol_exprt &>(expr);
212+
}
213+
214+
template<> inline bool can_cast_expr<next_symbol_exprt>(const exprt &base)
215+
{
216+
return base.id()==ID_next_symbol;
217+
}
218+
inline void validate_expr(const next_symbol_exprt &value)
219+
{
220+
validate_operands(value, 0, "Symbols must not have operands");
221+
}
222+
134223
/*! \brief Expression to hold a symbol (variable)
135224
*/
136225
class decorated_symbol_exprt:public symbol_exprt
@@ -197,41 +286,6 @@ class decorated_symbol_exprt:public symbol_exprt
197286
}
198287
};
199288

200-
/*! \brief Cast a generic exprt to a \ref symbol_exprt
201-
*
202-
* This is an unchecked conversion. \a expr must be known to be \ref
203-
* symbol_exprt.
204-
*
205-
* \param expr Source expression
206-
* \return Object of type \ref symbol_exprt
207-
*
208-
* \ingroup gr_std_expr
209-
*/
210-
inline const symbol_exprt &to_symbol_expr(const exprt &expr)
211-
{
212-
PRECONDITION(expr.id()==ID_symbol);
213-
DATA_INVARIANT(!expr.has_operands(), "Symbols must not have operands");
214-
return static_cast<const symbol_exprt &>(expr);
215-
}
216-
217-
/*! \copydoc to_symbol_expr(const exprt &)
218-
* \ingroup gr_std_expr
219-
*/
220-
inline symbol_exprt &to_symbol_expr(exprt &expr)
221-
{
222-
PRECONDITION(expr.id()==ID_symbol);
223-
DATA_INVARIANT(!expr.has_operands(), "Symbols must not have operands");
224-
return static_cast<symbol_exprt &>(expr);
225-
}
226-
227-
template<> inline bool can_cast_expr<symbol_exprt>(const exprt &base)
228-
{
229-
return base.id()==ID_symbol;
230-
}
231-
inline void validate_expr(const symbol_exprt &value)
232-
{
233-
validate_operands(value, 0, "Symbols must not have operands");
234-
}
235289

236290

237291
/*! \brief Expression to hold a nondeterministic choice

0 commit comments

Comments
 (0)