mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
binpac: BIT-1914: Implement &check
Patch submitted by Antoine
This commit is contained in:
parent
0b84838465
commit
0ecf7755ea
2 changed files with 23 additions and 0 deletions
|
@ -22,6 +22,15 @@ protected:
|
|||
string msg_;
|
||||
};
|
||||
|
||||
class ExceptionCheckViolation : public Exception
|
||||
{
|
||||
public:
|
||||
ExceptionCheckViolation(const char* where)
|
||||
{
|
||||
append(binpac_fmt("check violation : %s", where));
|
||||
}
|
||||
};
|
||||
|
||||
class ExceptionOutOfBound : public Exception
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -784,6 +784,20 @@ void Type::GenParseCode3(Output* out_cc, Env* env, const DataPtr& data, int flag
|
|||
|
||||
if ( size_var() )
|
||||
ASSERT(env->Evaluated(size_var()));
|
||||
|
||||
foreach(i, ExprList, attr_checks_)
|
||||
{
|
||||
Expr* check = *i;
|
||||
const char* check_expr = check->EvalExpr(out_cc, env);
|
||||
out_cc->println("// Evaluate '&check' attribute");
|
||||
out_cc->println("if (!%s)", check_expr);
|
||||
out_cc->inc_indent();
|
||||
out_cc->println("{");
|
||||
out_cc->println("throw binpac::ExceptionCheckViolation(\"%s\");", data_id_str_.c_str());
|
||||
out_cc->println("}");
|
||||
out_cc->dec_indent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Type *Type::MemberDataType(const ID *member_id) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue