FFI: Ignore number parsing errors while skipping definitions.

master
Mike Pall 2011-12-17 15:02:53 +01:00
parent d050b2fff5
commit 248cf2ffa9
2 changed files with 4 additions and 1 deletions

View File

@ -187,7 +187,7 @@ static CPToken cp_integer(CPState *cp)
break;
cp_get(cp);
}
if (lj_char_isident(cp->c))
if (lj_char_isident(cp->c) && !(cp->mode & CPARSE_MODE_SKIP))
cp_errmsg(cp, cp->c, LJ_ERR_XNUMBER);
return CTOK_INTEGER;
}
@ -1593,12 +1593,14 @@ static void cp_decl_func(CPState *cp, CPDecl *fdecl)
cp_check(cp, ')');
if (cp_opt(cp, '{')) { /* Skip function definition. */
int level = 1;
cp->mode |= CPARSE_MODE_SKIP;
for (;;) {
if (cp->tok == '{') level++;
else if (cp->tok == '}' && --level == 0) break;
else if (cp->tok == CTOK_EOF) cp_err_token(cp, '}');
cp_next(cp);
}
cp->mode &= ~CPARSE_MODE_SKIP;
cp->tok = ';'; /* Ok for cp_decl_multi(), error in cp_decl_single(). */
}
info |= (fdecl->fattr & ~CTMASK_CID);

View File

@ -23,6 +23,7 @@
#define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */
#define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */
#define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */
#define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */
typedef int CPChar; /* C parser character. Unsigned ext. from char. */
typedef int CPToken; /* C parser token. */