diff --git a/tools/binpac/lib/binpac_exception.h b/tools/binpac/lib/binpac_exception.h index 6debf54466..328f8c696d 100644 --- a/tools/binpac/lib/binpac_exception.h +++ b/tools/binpac/lib/binpac_exception.h @@ -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: diff --git a/tools/binpac/src/pac_type.cc b/tools/binpac/src/pac_type.cc index 6c5adead08..5f06b2b760 100644 --- a/tools/binpac/src/pac_type.cc +++ b/tools/binpac/src/pac_type.cc @@ -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