From a29456369d0e7120929a062fcb4759f2be52b84b Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Fri, 11 Apr 2003 18:23:03 +0000 Subject: [PATCH] preassert-postassert patch. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4680 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/emit.cxx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index a38ecdeec..679bc5eb3 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -360,7 +360,22 @@ void replace_args(Parm *p, String *s) { p = nextSibling(p); } } - + +/* replace_contract_args. This function replaces argument names in contract + specifications. Used in conjunction with the %contract directive. */ + +static +void replace_contract_args(Parm *cp, Parm *rp, String *s) { + while (cp && rp) { + String *n = Getattr(cp,"name"); + if (n) { + Replace(s,n,Getattr(rp,"lname"), DOH_REPLACE_ID); + } + cp = nextSibling(cp); + rp = nextSibling(rp); + } +} + /* ----------------------------------------------------------------------------- * int emit_action() * @@ -413,8 +428,7 @@ void emit_action(Node *n, Wrapper *f) { /* Preassert -- EXPERIMENTAL */ tm = Getattr(n,"feature:preassert"); if (tm) { - p = Getattr(n,"parms"); - replace_args(p,tm); + replace_contract_args(Getmeta(tm,"parms"), Getattr(n,"parms"),tm); Printv(f->code,tm,"\n",NIL); } @@ -465,8 +479,7 @@ void emit_action(Node *n, Wrapper *f) { /* Postassert - EXPERIMENTAL */ tm = Getattr(n,"feature:postassert"); if (tm) { - p = Getattr(n,"parms"); - replace_args(p,tm); + replace_contract_args(Getmeta(tm,"parms"), Getattr(n,"parms"),tm); Printv(f->code,tm,"\n",NIL); } }