/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 2000-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* Phong Vo <[email protected]> *18* *19***********************************************************************/20#pragma prototyped21/*22* include this file to instantiate a private ire exec23* parameterized on these macros24*25* IREINIT the re element integral type26* IRENEXT the re advance function27* IREEXEC the re exec function28*29* macros must be defined before include30* macros undefined after include31*32* Glenn Fowler33* AT&T Research34*/3536/*37* advance IREINT re until success:1 or failure:038*/3940static int41IRENEXT(Ire_t* ire, register Re_t* re, int must, IREINT* lp, IREINT* rp)42{43register int i;44register int j;45register int n;46IREINT* bp;47IREINT* cp;48IREINT* ep;4950if (!re)51return !ire->right || lp >= rp;52if ((rp - lp) < must)53return 0;54if (re->lo)55{56must -= re->lo;57bp = lp + re->lo - 1;58}59else if (IRENEXT(ire, re->next, must, lp, rp))60return 1;61else62bp = lp;63if ((rp - bp) < must)64return 0;65if (!re->hi || re->hi > (rp - lp))66ep = rp;67else68ep = lp + re->hi;69if ((rp - ep) < must)70ep = rp - must;71for (cp = lp; cp < ep; cp++)72{73if (*cp == ire->group && ire->group)74{75j = *++cp;76if (cp < bp)77{78bp += j + 1;79ep += j + 1;80}81cp += j;82j = 1 - j;83}84else85j = 0;86if (re->n)87{88while (j < 1)89{90n = cp[j++];91for (i = 0; i < re->n; i++)92if (n == re->id[i])93{94if (re->invert)95return 0;96goto hit;97}98}99if (!re->invert)100return 0;101}102hit:103if (cp >= bp && IRENEXT(ire, re->next, must, cp + 1, rp))104return 1;105}106return 0;107}108109/*110* IREINT ire exec111*/112113static int114IREEXEC(Ire_t* ire, void* data, size_t size)115{116register Re_t* re = ire->re;117IREINT* lp = (IREINT*)data;118IREINT* rp = lp + size / sizeof(IREINT);119int left = ire->left;120int must = ire->must;121122do123{124if (IRENEXT(ire, re, must, lp, rp))125return 1;126if (*lp++ == ire->group && ire->group)127lp += *lp + 1;128} while (!left && lp < rp);129return 0;130}131132#undef IREINT133#undef IRENEXT134#undef IREEXEC135136137