*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4875 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
18f16faf21
commit
dde9afd927
4 changed files with 156 additions and 59 deletions
|
|
@ -1,5 +1,10 @@
|
|||
Version 1.3.20 (In progress)
|
||||
============================
|
||||
06/10/2002: Tiger
|
||||
Modified contract code for error message output.
|
||||
Contract code can now print out simple error message.
|
||||
Modified contract code to prepare for inheritance
|
||||
|
||||
06/03/2003: mkoeppe
|
||||
[Guile] Applied Guile module updates contributed by
|
||||
John Lenz <jelenz@students.wisc.edu>.
|
||||
|
|
|
|||
|
|
@ -407,18 +407,14 @@ SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
|
|||
|
||||
/* Contract support */
|
||||
|
||||
#define SWIG_preassert(x) if (!(x)) { PyErr_SetString(PyExc_RuntimeError, "preassertion failure: " #x); goto fail; } else
|
||||
#define SWIG_postassert(x) if (!(x)) { PyErr_SetString(PyExc_RuntimeError, "postassertion failure: " #x); goto fail; } else
|
||||
#define SWIG_invariant(x) if (!(x)) { PyErr_SetString(PyExc_RuntimeError, "invariant failure: " #x); goto fail; } else
|
||||
#define SWIG_invariant_begin(x) if (!(x)) { PyErr_SetString(PyExc_RuntimeError, "invariant failure at begining: " #x); goto fail; } else
|
||||
#define SWIG_invariant_end(x) if (!(x)) { PyErr_SetString(PyExc_RuntimeError, "invariant failure at ending: " #x); goto fail; } else
|
||||
#define SWIG_preassert(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, msg #expr ); goto fail; } else
|
||||
#define SWIG_postassert(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, msg #expr ); goto fail; } else
|
||||
|
||||
#define SWIG_invariant(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, msg #expr ); goto fail; } else
|
||||
#define SWIG_invariant_begin(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, msg #expr ); goto fail; } else
|
||||
#define SWIG_invariant_end(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, msg #expr ); goto fail; } else
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -133,32 +133,27 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
Setattr(n, "feature:preassert", preassert);
|
||||
Setattr(n, "feature:preassert", preassert);
|
||||
Setattr(n, "feature:postassert", postassert);
|
||||
Setattr(n, "feature:invariant", invariant);
|
||||
Setattr(n, "feature:invariant", invariant);
|
||||
Delete(contract);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int AssertModify(Node *n, int flag) {
|
||||
String *str_assert, *s, *tag, *tag_sync;
|
||||
String *str_assert, *expr, *tag_sync;
|
||||
List *list_assert;
|
||||
ParmList *list_params;
|
||||
|
||||
if (flag == 1) { /* preassert */
|
||||
str_assert = NewString(Getattr(n, "feature:preassert"));
|
||||
tag = NewString(" SWIG_preassert(");
|
||||
} else if (flag == 2){ /* postassert */
|
||||
str_assert = NewString(Getattr(n, "feature:postassert"));
|
||||
tag = NewString(" SWIG_postassert(");
|
||||
} else if (flag == 3){
|
||||
} else if (flag == 3){ /* invariant */
|
||||
str_assert = NewString(Getattr(n, "feature:invariant"));
|
||||
tag = NewString(" SWIG_invariant(");
|
||||
} else
|
||||
return SWIG_ERROR;
|
||||
|
||||
/* Modify format into { SWIG_xxxassert(...);\n ...}
|
||||
Omit all unuseful characters and split by ; */
|
||||
|
||||
/* Omit all unuseful characters and split by ; */
|
||||
Replaceall(str_assert, "\n", "");
|
||||
Replaceall(str_assert, "{", "");
|
||||
Replaceall(str_assert, "}", "");
|
||||
|
|
@ -167,33 +162,135 @@ public:
|
|||
Delete(str_assert);
|
||||
|
||||
/* build up new assertion */
|
||||
str_assert = NewString("{");
|
||||
for (s = Firstitem(list_assert); s; s = Nextitem(list_assert)) {
|
||||
if (Len(s)) {
|
||||
if (Strstr(s, SWIG_BEFORE)) { /* before sync assertion */
|
||||
str_assert = NewString("");
|
||||
for (expr = Firstitem(list_assert); expr; expr = Nextitem(list_assert)) {
|
||||
if (Len(expr)) {
|
||||
/* All sync staff are not complete and only experimental */
|
||||
if (Strstr(expr, SWIG_BEFORE)) { /* before sync assertion */
|
||||
tag_sync = NewString(" SWIG_sync(");
|
||||
Append(tag_sync, Getattr(n, "name"));
|
||||
Append(tag_sync, ", ");
|
||||
Replaceall(s, SWIG_BEFORE, tag_sync);
|
||||
Append(str_assert, s);
|
||||
Replaceall(expr, SWIG_BEFORE, tag_sync);
|
||||
Append(str_assert, expr);
|
||||
Append(str_assert, ";\n");
|
||||
Delete(tag_sync);
|
||||
} else if (Strstr(s, SWIG_AFTER)) { /* after sync assertion */
|
||||
} else if (Strstr(expr, SWIG_AFTER)) { /* after sync assertion */
|
||||
tag_sync = NewString(" SWIG_sync(");
|
||||
Replaceall(s, SWIG_AFTER, tag_sync);
|
||||
Replaceall(s, ")", ", ");
|
||||
Append(str_assert, s);
|
||||
Replaceall(expr, SWIG_AFTER, tag_sync);
|
||||
Replaceall(expr, ")", ", ");
|
||||
Append(str_assert, expr);
|
||||
Append(str_assert, Getattr(n,"name"));
|
||||
Append(str_assert, ");\n");
|
||||
Delete(tag_sync);
|
||||
} else { /* no sync assertion */
|
||||
Append(str_assert, tag);
|
||||
Append(str_assert, s);
|
||||
Append(str_assert, ");\n");
|
||||
} else { /* no sync assertion, only basic pre- post-, invar- */
|
||||
Replaceid(expr, Getattr(n,"name"), "result");
|
||||
if (Len(str_assert))
|
||||
Append(str_assert, "&&");
|
||||
Printf(str_assert, "(%s)", expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Append(str_assert, "}");
|
||||
|
||||
if (flag == 1) {
|
||||
Setattr(n, "feature:preassert", str_assert);
|
||||
} else if (flag == 2) {
|
||||
Setattr(n, "feature:postassert", str_assert);
|
||||
} else {
|
||||
Setattr(n, "feature:invariant", str_assert);
|
||||
}
|
||||
|
||||
Delete(str_assert);
|
||||
Delete(list_assert);
|
||||
Delete(expr);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* Modify format into { SWIG_xxxassert(...);\n ...} */
|
||||
int AssertAddTag(Node *n) {
|
||||
String *str_assert, *tag;
|
||||
/* preassert */
|
||||
str_assert = NewString(Getattr(n, "feature:preassert"));
|
||||
if (Len(str_assert)) {
|
||||
tag = NewString(" SWIG_preassert(");
|
||||
Append(tag, str_assert);
|
||||
Append(tag, ");\n");
|
||||
Setattr(n, "feature:preassert", tag);
|
||||
Delete(tag);
|
||||
}
|
||||
Delete(str_assert);
|
||||
|
||||
/* postassert */
|
||||
str_assert = NewString(Getattr(n, "feature:postassert"));
|
||||
if (Len(str_assert)) {
|
||||
tag = NewString(" SWIG_postassert(");
|
||||
Append(tag, str_assert);
|
||||
Append(tag, ");\n");
|
||||
Setattr(n, "feature:postassert", tag);
|
||||
Delete(tag);
|
||||
}
|
||||
Delete(str_assert);
|
||||
|
||||
/* invariant */
|
||||
str_assert = NewString(Getattr(n, "feature:invariant"));
|
||||
if (Len(str_assert)) {
|
||||
tag = NewString(" SWIG_invariant(");
|
||||
Append(tag, str_assert);
|
||||
Append(tag, ");\n");
|
||||
Setattr(n, "feature:invariant", tag);
|
||||
Delete(tag);
|
||||
}
|
||||
Delete(str_assert);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* Append error message */
|
||||
int AssertAddErrorMsg(Node *n) {
|
||||
String *str_assert, *error_msg;
|
||||
/* preassert */
|
||||
str_assert = NewString(Getattr(n, "feature:preassert"));
|
||||
Replaceall(str_assert, ");\n", "");
|
||||
if (Len(str_assert)) {
|
||||
error_msg = NewString("\\nRequire assertion violation,");
|
||||
Printf(error_msg, "in function of <<%s>>\\n", Getattr(n, "name"));
|
||||
Printf(str_assert, ", \"%s\");\n", error_msg);
|
||||
Setattr(n, "feature:preassert", str_assert);
|
||||
Delete(error_msg);
|
||||
}
|
||||
Delete(str_assert);
|
||||
|
||||
/* postassert */
|
||||
str_assert = NewString(Getattr(n, "feature:postassert"));
|
||||
Replaceall(str_assert, ");\n", "");
|
||||
if (Len(str_assert)) {
|
||||
error_msg = NewString("\\nEnsure assertion violation,");
|
||||
Printf(error_msg, "in function of <<%s>>\\n", Getattr(n, "name"));
|
||||
Printf(str_assert, ", \"%s\");\n", error_msg);
|
||||
Setattr(n, "feature:postassert", str_assert);
|
||||
Delete(error_msg);
|
||||
}
|
||||
Delete(str_assert);
|
||||
|
||||
/* invariant */
|
||||
str_assert = NewString(Getattr(n, "feature:invariant"));
|
||||
Replaceall(str_assert, ");\n", "");
|
||||
if (Len(str_assert)) {
|
||||
error_msg = NewString("\\nInvariant assertion violation,");
|
||||
Printf(error_msg, "in function of <<%s>>\\n", Getattr(n, "name"));
|
||||
Printf(str_assert, ", \"%s\");\n", error_msg);
|
||||
Setattr(n, "feature:invariant", str_assert);
|
||||
Delete(error_msg);
|
||||
}
|
||||
Delete(str_assert);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int AssertSetParms(Node *n) {
|
||||
ParmList *list_params;
|
||||
String *str_assert_pre,*str_assert_post,*str_assert_invar;
|
||||
|
||||
str_assert_pre = NewString(Getattr(n, "feature:preassert"));
|
||||
str_assert_post = NewString(Getattr(n, "feature:postassert"));
|
||||
str_assert_invar = NewString(Getattr(n, "feature:invariant"));
|
||||
|
||||
/* Set the params in preassert & postassert */
|
||||
list_params = Getmeta(Getattr(n, "feature:contract"), "parms");
|
||||
|
|
@ -205,22 +302,18 @@ public:
|
|||
set_nextSibling(p, list_params);
|
||||
list_params = p;
|
||||
}
|
||||
Setmeta(str_assert, "parms", list_params);
|
||||
Setmeta(str_assert_pre, "parms", list_params);
|
||||
Setmeta(str_assert_post, "parms", list_params);
|
||||
Setmeta(str_assert_invar, "parms", list_params);
|
||||
|
||||
if (flag == 1) {
|
||||
Replaceid(str_assert, Getattr(n,"name"), "result");
|
||||
Setattr(n, "feature:preassert", str_assert);
|
||||
} else if (flag == 2) {
|
||||
Replaceid(str_assert, Getattr(n,"name"), "result");
|
||||
Setattr(n, "feature:postassert", str_assert);
|
||||
} else {
|
||||
Setattr(n, "feature:invariant", str_assert);
|
||||
}
|
||||
|
||||
Delete(list_assert);
|
||||
Setattr(n, "feature:preassert", str_assert_pre);
|
||||
Setattr(n, "feature:postassert", str_assert_post);
|
||||
Setattr(n, "feature:invariant", str_assert_invar);
|
||||
|
||||
Delete(list_params);
|
||||
Delete(s);
|
||||
Delete(tag);
|
||||
Delete(str_assert_pre);
|
||||
Delete(str_assert_post);
|
||||
Delete(str_assert_invar);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
|
@ -228,17 +321,20 @@ public:
|
|||
int ret = SWIG_OK;
|
||||
if (!Getattr(n, "feature:contract"))
|
||||
return SWIG_ERROR;
|
||||
/*Printf(stdout, "--------In emit_contract code:\nname is : %s\n",
|
||||
Getattr(n,"name")); */
|
||||
/* Printf(stdout, "--------In emit_contract code:\nname is : %s\n",
|
||||
Getattr(n,"name")); */
|
||||
|
||||
/* Split contracqt into preassert & postassert */
|
||||
if (!SliptContract(n))
|
||||
return SWIG_ERROR;
|
||||
|
||||
/* Modify pre- , post- * invar- */
|
||||
ret = AssertModify(n, 1);
|
||||
ret = AssertModify(n, 2);
|
||||
ret = AssertModify(n, 3);
|
||||
ret = ret && AssertModify(n, 1);
|
||||
ret = ret && AssertModify(n, 2);
|
||||
ret = ret && AssertModify(n, 3);
|
||||
ret = ret && AssertAddTag(n);
|
||||
ret = ret && AssertAddErrorMsg(n);
|
||||
ret = ret && AssertSetParms(n);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ void emit_action(Node *n, Wrapper *f) {
|
|||
tm = Getattr(n,"feature:preassert");
|
||||
if (tm) {
|
||||
replace_contract_args(Getmeta(tm,"parms"), Getattr(n,"parms"),tm);
|
||||
/* Printf(stdout, "name: %s, preassert: %s\n", Getattr(n,"name"), tm); */
|
||||
Printf(stdout, "name: %s, preassert: %s\n", Getattr(n,"name"), tm);
|
||||
Printv(f->code,tm,"\n",NIL);
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +439,7 @@ void emit_action(Node *n, Wrapper *f) {
|
|||
if (tm) {
|
||||
replace_contract_args(Getmeta(tm,"parms"), Getattr(n,"parms"),tm);
|
||||
Replaceid(tm, "SWIG_invariant", "SWIG_invariant_begin");
|
||||
/* Printf(stdout, "name: %s, invarassert: %s\n", Getattr(n,"name"), tm); */
|
||||
Printf(stdout, "name: %s, invarassert: %s\n", Getattr(n,"name"), tm);
|
||||
Printv(f->code,tm,"\n",NIL);
|
||||
}
|
||||
}
|
||||
|
|
@ -494,14 +494,14 @@ void emit_action(Node *n, Wrapper *f) {
|
|||
if (tm) {
|
||||
replace_contract_args(Getmeta(tm,"parms"), Getattr(n,"parms"),tm);
|
||||
Replaceid(tm, "SWIG_invariant", "SWIG_invariant_end");
|
||||
/* Printf(stdout, "name: %s, invarassert: %s\n", Getattr(n,"name"), tm); */
|
||||
Printf(stdout, "name: %s, invarassert: %s\n", Getattr(n,"name"), tm);
|
||||
Printv(f->code,tm,"\n",NIL);
|
||||
}
|
||||
/* Postassertion - EXPERIMENTAL */
|
||||
tm = Getattr(n,"feature:postassert");
|
||||
if (tm) {
|
||||
replace_contract_args(Getmeta(tm,"parms"), Getattr(n,"parms"),tm);
|
||||
/* Printf(stdout, "name: %s, postassert: %s\n", Getattr(n,"name"), tm); */
|
||||
Printf(stdout, "name: %s, postassert: %s\n", Getattr(n,"name"), tm);
|
||||
Printv(f->code,tm,"\n",NIL);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue