diff --git a/tools/binpac/lib/binpac_exception.h b/tools/binpac/lib/binpac_exception.h index 328f8c696d..4a4ae40e31 100644 --- a/tools/binpac/lib/binpac_exception.h +++ b/tools/binpac/lib/binpac_exception.h @@ -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)); } }; diff --git a/tools/binpac/src/pac_attr.h b/tools/binpac/src/pac_attr.h index 67bdbedc8d..85d7f19afb 100644 --- a/tools/binpac/src/pac_attr.h +++ b/tools/binpac/src/pac_attr.h @@ -8,6 +8,7 @@ enum AttrType { ATTR_BYTEORDER, ATTR_CHECK, ATTR_CHUNKED, + ATTR_ENFORCE, ATTR_EXPORTSOURCEDATA, ATTR_IF, ATTR_LENGTH, diff --git a/tools/binpac/src/pac_parse.yy b/tools/binpac/src/pac_parse.yy index 5bf3c96434..178af0604e 100644 --- a/tools/binpac/src/pac_parse.yy +++ b/tools/binpac/src/pac_parse.yy @@ -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); diff --git a/tools/binpac/src/pac_scan.ll b/tools/binpac/src/pac_scan.ll index 0324ef0aa8..f5dab77c64 100644 --- a/tools/binpac/src/pac_scan.ll +++ b/tools/binpac/src/pac_scan.ll @@ -184,6 +184,7 @@ ESCSEQ (\\([^\n]|[0-7]{3}|x[[:xdigit:]]{2})) &byteorder return TOK_ATTR_BYTEORDER; &check return TOK_ATTR_CHECK; &chunked return TOK_ATTR_CHUNKED; +&enforce return TOK_ATTR_ENFORCE; &exportsourcedata return TOK_ATTR_EXPORTSOURCEDATA; &if return TOK_ATTR_IF; &length return TOK_ATTR_LENGTH; diff --git a/tools/binpac/src/pac_type.cc b/tools/binpac/src/pac_type.cc index 5f06b2b760..044a5305d1 100644 --- a/tools/binpac/src/pac_type.cc +++ b/tools/binpac/src/pac_type.cc @@ -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(); } diff --git a/tools/binpac/src/pac_type.h b/tools/binpac/src/pac_type.h index 6590a94a5a..2de0a6fc76 100644 --- a/tools/binpac/src/pac_type.h +++ b/tools/binpac/src/pac_type.h @@ -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_;