mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
binpac: BIT-1914: move &check implementation to new &enforce attribute
&check returns to being a no-op to avoid unintentionally breaking existing code.
This commit is contained in:
parent
0ecf7755ea
commit
8a1c8db02e
6 changed files with 23 additions and 10 deletions
|
@ -22,12 +22,12 @@ protected:
|
|||
string msg_;
|
||||
};
|
||||
|
||||
class ExceptionCheckViolation : public Exception
|
||||
class ExceptionEnforceViolation : public Exception
|
||||
{
|
||||
public:
|
||||
ExceptionCheckViolation(const char* where)
|
||||
ExceptionEnforceViolation(const char* where)
|
||||
{
|
||||
append(binpac_fmt("check violation : %s", where));
|
||||
append(binpac_fmt("&enforce violation : %s", where));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ enum AttrType {
|
|||
ATTR_BYTEORDER,
|
||||
ATTR_CHECK,
|
||||
ATTR_CHUNKED,
|
||||
ATTR_ENFORCE,
|
||||
ATTR_EXPORTSOURCEDATA,
|
||||
ATTR_IF,
|
||||
ATTR_LENGTH,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
%token TOK_ID TOK_NUMBER TOK_REGEX TOK_STRING
|
||||
%token TOK_BEGIN_RE TOK_END_RE
|
||||
%token TOK_ATTR_ALSO
|
||||
%token TOK_ATTR_BYTEORDER TOK_ATTR_CHECK TOK_ATTR_CHUNKED
|
||||
%token TOK_ATTR_BYTEORDER TOK_ATTR_CHECK TOK_ATTR_CHUNKED TOK_ATTR_ENFORCE
|
||||
%token TOK_ATTR_EXPORTSOURCEDATA TOK_ATTR_IF
|
||||
%token TOK_ATTR_LENGTH TOK_ATTR_LET
|
||||
%token TOK_ATTR_LINEBREAKER TOK_ATTR_MULTILINE TOK_ATTR_ONELINE
|
||||
|
@ -994,6 +994,10 @@ attr : TOK_ATTR_BYTEORDER '=' expr
|
|||
{
|
||||
$$ = new Attr(ATTR_CHUNKED);
|
||||
}
|
||||
| TOK_ATTR_ENFORCE expr
|
||||
{
|
||||
$$ = new Attr(ATTR_ENFORCE, $2);
|
||||
}
|
||||
| TOK_ATTR_EXPORTSOURCEDATA
|
||||
{
|
||||
$$ = new Attr(ATTR_EXPORTSOURCEDATA);
|
||||
|
|
|
@ -184,6 +184,7 @@ ESCSEQ (\\([^\n]|[0-7]{3}|x[[:xdigit:]]{2}))
|
|||
<INITIAL>&byteorder return TOK_ATTR_BYTEORDER;
|
||||
<INITIAL>&check return TOK_ATTR_CHECK;
|
||||
<INITIAL>&chunked return TOK_ATTR_CHUNKED;
|
||||
<INITIAL>&enforce return TOK_ATTR_ENFORCE;
|
||||
<INITIAL>&exportsourcedata return TOK_ATTR_EXPORTSOURCEDATA;
|
||||
<INITIAL>&if return TOK_ATTR_IF;
|
||||
<INITIAL>&length return TOK_ATTR_LENGTH;
|
||||
|
|
|
@ -52,6 +52,7 @@ Type::Type(TypeType tot)
|
|||
attrs_ = new AttrList();
|
||||
attr_byteorder_expr_ = 0;
|
||||
attr_checks_ = new ExprList();
|
||||
attr_enforces_ = new ExprList();
|
||||
attr_chunked_ = false;
|
||||
attr_exportsourcedata_ = false;
|
||||
attr_if_expr_ = 0;
|
||||
|
@ -81,6 +82,7 @@ Type::~Type()
|
|||
delete attr_if_expr_;
|
||||
delete attr_length_expr_;
|
||||
delete_list(ExprList, attr_checks_);
|
||||
delete_list(ExprList, attr_enforces_);
|
||||
delete_list(ExprList, attr_requires_);
|
||||
}
|
||||
|
||||
|
@ -159,6 +161,10 @@ void Type::ProcessAttr(Attr* a)
|
|||
attr_checks_->push_back(a->expr());
|
||||
break;
|
||||
|
||||
case ATTR_ENFORCE:
|
||||
attr_enforces_->push_back(a->expr());
|
||||
break;
|
||||
|
||||
case ATTR_EXPORTSOURCEDATA:
|
||||
attr_exportsourcedata_ = true;
|
||||
break;
|
||||
|
@ -785,15 +791,15 @@ 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_)
|
||||
foreach(i, ExprList, attr_enforces_)
|
||||
{
|
||||
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);
|
||||
Expr* enforce = *i;
|
||||
const char* enforce_expr = enforce->EvalExpr(out_cc, env);
|
||||
out_cc->println("// Evaluate '&enforce' attribute");
|
||||
out_cc->println("if (!%s)", enforce_expr);
|
||||
out_cc->inc_indent();
|
||||
out_cc->println("{");
|
||||
out_cc->println("throw binpac::ExceptionCheckViolation(\"%s\");", data_id_str_.c_str());
|
||||
out_cc->println("throw binpac::ExceptionEnforceViolation(\"%s\");", data_id_str_.c_str());
|
||||
out_cc->println("}");
|
||||
out_cc->dec_indent();
|
||||
}
|
||||
|
|
|
@ -284,6 +284,7 @@ protected:
|
|||
|
||||
Expr *attr_byteorder_expr_;
|
||||
ExprList *attr_checks_;
|
||||
ExprList *attr_enforces_;
|
||||
bool attr_chunked_;
|
||||
bool attr_exportsourcedata_;
|
||||
Expr *attr_if_expr_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue