binpac: BIT-1914: Implement &check

Patch submitted by Antoine
This commit is contained in:
Jon Siwek 2018-04-18 18:07:59 -05:00 committed by Tim Wojtulewicz
parent 0b84838465
commit 0ecf7755ea
2 changed files with 23 additions and 0 deletions

View file

@ -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:

View file

@ -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