Commit 1e173eaa authored by Alexandre Julliard's avatar Alexandre Julliard

wrc: Use asserts instead of explicit internal error.

parent 04ae435f
...@@ -266,28 +266,26 @@ static void string_to_upper(string_t *str) ...@@ -266,28 +266,26 @@ static void string_to_upper(string_t *str)
{ {
int i; int i;
if(str->type == str_char) switch (str->type)
{ {
case str_char:
for (i = 0; i < str->size; i++) for (i = 0; i < str->size; i++)
if (str->str.cstr[i] >= 'a' && str->str.cstr[i] <= 'z') str->str.cstr[i] -= 32; if (str->str.cstr[i] >= 'a' && str->str.cstr[i] <= 'z') str->str.cstr[i] -= 32;
} break;
else if(str->type == str_unicode) case str_unicode:
{
for (i = 0; i < str->size; i++) for (i = 0; i < str->size; i++)
if (str->str.wstr[i] >= 'a' && str->str.wstr[i] <= 'z') str->str.wstr[i] -= 32; if (str->str.wstr[i] >= 'a' && str->str.wstr[i] <= 'z') str->str.wstr[i] -= 32;
} break;
else
{
internal_error(__FILE__, __LINE__, "Invalid string type %d\n", str->type);
} }
} }
static int parse_accel_string( const string_t *key, int flags ) static int parse_accel_string( const string_t *key, int flags )
{ {
int keycode; int keycode = 0;
if(key->type == str_char) switch (key->type)
{ {
case str_char:
if (key->str.cstr[0] == '#') return 0; /* ignore message contexts */ if (key->str.cstr[0] == '#') return 0; /* ignore message contexts */
if((flags & WRC_AF_VIRTKEY) && if((flags & WRC_AF_VIRTKEY) &&
!((key->str.cstr[0] >= 'A' && key->str.cstr[0] <= 'Z') || !((key->str.cstr[0] >= 'A' && key->str.cstr[0] <= 'Z') ||
...@@ -316,9 +314,9 @@ static int parse_accel_string( const string_t *key, int flags ) ...@@ -316,9 +314,9 @@ static int parse_accel_string( const string_t *key, int flags )
} }
else else
keycode = key->str.cstr[0]; keycode = key->str.cstr[0];
} break;
else
{ case str_unicode:
if (key->str.wstr[0] == '#') return 0; /* ignore message contexts */ if (key->str.wstr[0] == '#') return 0; /* ignore message contexts */
if((flags & WRC_AF_VIRTKEY) && if((flags & WRC_AF_VIRTKEY) &&
!((key->str.wstr[0] >= 'A' && key->str.wstr[0] <= 'Z') || !((key->str.wstr[0] >= 'A' && key->str.wstr[0] <= 'Z') ||
...@@ -346,6 +344,7 @@ static int parse_accel_string( const string_t *key, int flags ) ...@@ -346,6 +344,7 @@ static int parse_accel_string( const string_t *key, int flags )
} }
else else
keycode = key->str.wstr[0]; keycode = key->str.wstr[0];
break;
} }
return keycode; return keycode;
} }
...@@ -391,9 +390,7 @@ static void put_string(res_t *res, const string_t *str, int isterm, const langua ...@@ -391,9 +390,7 @@ static void put_string(res_t *res, const string_t *str, int isterm, const langua
} }
else else
{ {
if (str->type == str_unicode) assert( str->type == str_char );
internal_error(__FILE__, __LINE__, "Unicode string %s in 16-bit\n",
convert_string_utf8( str, 0 ));
if (!isterm) put_byte(res, str->size); if (!isterm) put_byte(res, str->size);
for(cnt = 0; cnt < str->size; cnt++) for(cnt = 0; cnt < str->size; cnt++)
{ {
...@@ -417,23 +414,20 @@ static void put_string(res_t *res, const string_t *str, int isterm, const langua ...@@ -417,23 +414,20 @@ static void put_string(res_t *res, const string_t *str, int isterm, const langua
*/ */
static void put_name_id(res_t *res, name_id_t *nid, int upcase, const language_t *lang) static void put_name_id(res_t *res, name_id_t *nid, int upcase, const language_t *lang)
{ {
if(nid->type == name_ord) switch (nid->type)
{ {
case name_ord:
if(win32) if(win32)
put_word(res, 0xffff); put_word(res, 0xffff);
else else
put_byte(res, 0xff); put_byte(res, 0xff);
put_word(res, (WORD)nid->name.i_name); put_word(res, (WORD)nid->name.i_name);
} break;
else if(nid->type == name_str) case name_str:
{
if(upcase) if(upcase)
string_to_upper(nid->name.s_name); string_to_upper(nid->name.s_name);
put_string(res, nid->name.s_name, TRUE, lang); put_string(res, nid->name.s_name, TRUE, lang);
} break;
else
{
internal_error(__FILE__, __LINE__, "Invalid name_id type %d\n", nid->type);
} }
} }
...@@ -703,10 +697,7 @@ static res_t *dialog2res(name_id_t *name, dialog_t *dlg) ...@@ -703,10 +697,7 @@ static res_t *dialog2res(name_id_t *name, dialog_t *dlg)
put_dword(res, ctrl->id); put_dword(res, ctrl->id);
else else
put_word(res, ctrl->id); put_word(res, ctrl->id);
if(ctrl->ctlclass) put_name_id(res, ctrl->ctlclass, FALSE, dlg->lvc.language);
put_name_id(res, ctrl->ctlclass, FALSE, dlg->lvc.language);
else
internal_error(__FILE__, __LINE__, "Control has no control-class\n");
if(ctrl->title) if(ctrl->title)
put_name_id(res, ctrl->title, FALSE, dlg->lvc.language); put_name_id(res, ctrl->title, FALSE, dlg->lvc.language);
else else
...@@ -764,19 +755,14 @@ static res_t *dialog2res(name_id_t *name, dialog_t *dlg) ...@@ -764,19 +755,14 @@ static res_t *dialog2res(name_id_t *name, dialog_t *dlg)
put_word(res, ctrl->height); put_word(res, ctrl->height);
put_word(res, ctrl->id); put_word(res, ctrl->id);
put_dword(res, ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD); put_dword(res, ctrl->gotstyle ? ctrl->style->or_mask: WS_CHILD);
if(ctrl->ctlclass) if(ctrl->ctlclass->type == name_ord
{ && ctrl->ctlclass->name.i_name >= 0x80
if(ctrl->ctlclass->type == name_ord && ctrl->ctlclass->name.i_name <= 0x85)
&& ctrl->ctlclass->name.i_name >= 0x80 put_byte(res, ctrl->ctlclass->name.i_name);
&& ctrl->ctlclass->name.i_name <= 0x85) else if(ctrl->ctlclass->type == name_str)
put_byte(res, ctrl->ctlclass->name.i_name); put_name_id(res, ctrl->ctlclass, FALSE, NULL);
else if(ctrl->ctlclass->type == name_str)
put_name_id(res, ctrl->ctlclass, FALSE, NULL);
else
error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name);
}
else else
internal_error(__FILE__, __LINE__, "Control has no control-class\n"); error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name);
if(ctrl->title) if(ctrl->title)
put_name_id(res, ctrl->title, FALSE, NULL); put_name_id(res, ctrl->title, FALSE, NULL);
else else
...@@ -1378,8 +1364,9 @@ static void versionblock2res(res_t *res, ver_block_t *blk, int level, const lang ...@@ -1378,8 +1364,9 @@ static void versionblock2res(res_t *res, ver_block_t *blk, int level, const lang
put_pad(res); put_pad(res);
for(val = blk->values; val; val = val->next) for(val = blk->values; val; val = val->next)
{ {
if(val->type == val_str) switch(val->type)
{ {
case val_str:
valblksizetag = res->size; valblksizetag = res->size;
put_word(res, 0); /* Will be overwritten later */ put_word(res, 0); /* Will be overwritten later */
valvalsizetag = res->size; valvalsizetag = res->size;
...@@ -1398,9 +1385,8 @@ static void versionblock2res(res_t *res, ver_block_t *blk, int level, const lang ...@@ -1398,9 +1385,8 @@ static void versionblock2res(res_t *res, ver_block_t *blk, int level, const lang
set_word(res, valvalsizetag, (WORD)(res->size - tag)); set_word(res, valvalsizetag, (WORD)(res->size - tag));
set_word(res, valblksizetag, (WORD)(res->size - valblksizetag)); set_word(res, valblksizetag, (WORD)(res->size - valblksizetag));
put_pad(res); put_pad(res);
} break;
else if(val->type == val_words) case val_words:
{
valblksizetag = res->size; valblksizetag = res->size;
put_word(res, 0); /* Will be overwritten later */ put_word(res, 0); /* Will be overwritten later */
valvalsizetag = res->size; valvalsizetag = res->size;
...@@ -1419,14 +1405,10 @@ static void versionblock2res(res_t *res, ver_block_t *blk, int level, const lang ...@@ -1419,14 +1405,10 @@ static void versionblock2res(res_t *res, ver_block_t *blk, int level, const lang
set_word(res, valvalsizetag, (WORD)(res->size - tag)); set_word(res, valvalsizetag, (WORD)(res->size - tag));
set_word(res, valblksizetag, (WORD)(res->size - valblksizetag)); set_word(res, valblksizetag, (WORD)(res->size - valblksizetag));
put_pad(res); put_pad(res);
} break;
else if(val->type == val_block) case val_block:
{
versionblock2res(res, val->value.block, level+1, lang); versionblock2res(res, val->value.block, level+1, lang);
} break;
else
{
internal_error(__FILE__, __LINE__, "Invalid value indicator %d in VERSIONINFO\n", val->type);
} }
} }
...@@ -1591,11 +1573,12 @@ static res_t *dlginit2res(name_id_t *name, dlginit_t *dit) ...@@ -1591,11 +1573,12 @@ static res_t *dlginit2res(name_id_t *name, dlginit_t *dit)
#define MAXNAMELEN 32 #define MAXNAMELEN 32
char *prep_nid_for_label(const name_id_t *nid) char *prep_nid_for_label(const name_id_t *nid)
{ {
static char buf[MAXNAMELEN+1]; static char buf[MAXNAMELEN+1];
assert(nid != NULL);
if(nid->type == name_str && nid->name.s_name->type == str_unicode) switch (nid->type)
{
case name_str:
if(nid->name.s_name->type == str_unicode)
{ {
WCHAR *sptr; WCHAR *sptr;
int i; int i;
...@@ -1610,7 +1593,7 @@ char *prep_nid_for_label(const name_id_t *nid) ...@@ -1610,7 +1593,7 @@ char *prep_nid_for_label(const name_id_t *nid)
} }
buf[i] = '\0'; buf[i] = '\0';
} }
else if(nid->type == name_str && nid->name.s_name->type == str_char) else
{ {
char *cptr; char *cptr;
int i; int i;
...@@ -1625,15 +1608,13 @@ char *prep_nid_for_label(const name_id_t *nid) ...@@ -1625,15 +1608,13 @@ char *prep_nid_for_label(const name_id_t *nid)
} }
buf[i] = '\0'; buf[i] = '\0';
} }
else if(nid->type == name_ord) break;
{
sprintf(buf, "%u", nid->name.i_name); case name_ord:
} sprintf(buf, "%u", nid->name.i_name);
else break;
{ }
internal_error(__FILE__, __LINE__, "Resource name_id with invalid type %d\n", nid->type); return buf;
}
return buf;
} }
#undef MAXNAMELEN #undef MAXNAMELEN
...@@ -1787,7 +1768,7 @@ void resources2res(resource_t *top) ...@@ -1787,7 +1768,7 @@ void resources2res(resource_t *top)
top->binres = anicurico2res(top->name, top->res.ani, top->type); top->binres = anicurico2res(top->name, top->res.ani, top->type);
break; break;
default: default:
internal_error(__FILE__, __LINE__, "Unknown resource type encountered %d in binary res generation\n", top->type); assert(0);
} }
top->c_name = make_c_name(get_c_typename(top->type), top->name, top->lan); top->c_name = make_c_name(get_c_typename(top->type), top->name, top->lan);
top = top->next; top = top->next;
......
...@@ -892,11 +892,11 @@ static void handle_ani_list(riff_tag_t *lst, enum res_e type, int isswapped) ...@@ -892,11 +892,11 @@ static void handle_ani_list(riff_tag_t *lst, enum res_e type, int isswapped)
rtp = NEXT_TAG(rtp); rtp = NEXT_TAG(rtp);
} }
else else
internal_error(__FILE__, __LINE__, "Unknown tag \"%c%c%c%c\" in RIFF file\n", error("Unknown tag \"%c%c%c%c\" in RIFF file\n",
isprint(rtp->tag[0]) ? rtp->tag[0] : '.', isprint(rtp->tag[0]) ? rtp->tag[0] : '.',
isprint(rtp->tag[1]) ? rtp->tag[1] : '.', isprint(rtp->tag[1]) ? rtp->tag[1] : '.',
isprint(rtp->tag[2]) ? rtp->tag[2] : '.', isprint(rtp->tag[2]) ? rtp->tag[2] : '.',
isprint(rtp->tag[3]) ? rtp->tag[3] : '.'); isprint(rtp->tag[3]) ? rtp->tag[3] : '.');
if((UINT_PTR)rtp & 1) if((UINT_PTR)rtp & 1)
rtp = SKIP_TAG(rtp,1); rtp = SKIP_TAG(rtp,1);
...@@ -1002,7 +1002,7 @@ ani_curico_t *new_ani_curico(enum res_e type, raw_data_t *rd, int *memopt) ...@@ -1002,7 +1002,7 @@ ani_curico_t *new_ani_curico(enum res_e type, raw_data_t *rd, int *memopt)
rtp = NEXT_TAG(rtp); rtp = NEXT_TAG(rtp);
} }
else else
internal_error(__FILE__, __LINE__, "Unknown tag \"%c%c%c%c\" in RIFF file\n", error("Unknown tag \"%c%c%c%c\" in RIFF file\n",
isprint(rtp->tag[0]) ? rtp->tag[0] : '.', isprint(rtp->tag[0]) ? rtp->tag[0] : '.',
isprint(rtp->tag[1]) ? rtp->tag[1] : '.', isprint(rtp->tag[1]) ? rtp->tag[1] : '.',
isprint(rtp->tag[2]) ? rtp->tag[2] : '.', isprint(rtp->tag[2]) ? rtp->tag[2] : '.',
...@@ -1098,7 +1098,7 @@ messagetable_t *new_messagetable(raw_data_t *rd, int *memopt) ...@@ -1098,7 +1098,7 @@ messagetable_t *new_messagetable(raw_data_t *rd, int *memopt)
* the ID, offset and length (and flag) fields to be very sure. * the ID, offset and length (and flag) fields to be very sure.
*/ */
if(hi && lo) if(hi && lo)
internal_error(__FILE__, __LINE__, "Messagetable contains more than 65535 blocks; cannot determine endian\n"); error("Messagetable contains more than 65535 blocks; cannot determine endian\n");
if(!hi && !lo) if(!hi && !lo)
parser_error("Invalid messagetable block count 0"); parser_error("Invalid messagetable block count 0");
......
...@@ -553,7 +553,7 @@ resource_definition ...@@ -553,7 +553,7 @@ resource_definition
{ {
$$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language); $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
} }
else if($1->type == res_curg) else /* res_curg */
{ {
cursor_t *cur; cursor_t *cur;
$$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language); $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
...@@ -567,8 +567,6 @@ resource_definition ...@@ -567,8 +567,6 @@ resource_definition
rsc->name->name.i_name = cur->id; rsc->name->name.i_name = cur->id;
} }
} }
else
internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource\n", $1->type);
free($1); free($1);
} }
| dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); } | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
...@@ -587,7 +585,7 @@ resource_definition ...@@ -587,7 +585,7 @@ resource_definition
{ {
$$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language); $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
} }
else if($1->type == res_icog) else /* res_icog */
{ {
icon_t *ico; icon_t *ico;
$$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language); $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
...@@ -601,8 +599,6 @@ resource_definition ...@@ -601,8 +599,6 @@ resource_definition
rsc->name->name.i_name = ico->id; rsc->name->name.i_name = ico->id;
} }
} }
else
internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource\n", $1->type);
free($1); free($1);
} }
| menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); } | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
...@@ -2258,10 +2254,13 @@ static raw_data_t *str2raw_data(string_t *str) ...@@ -2258,10 +2254,13 @@ static raw_data_t *str2raw_data(string_t *str)
rd = new_raw_data(); rd = new_raw_data();
rd->size = str->size * (str->type == str_char ? 1 : 2); rd->size = str->size * (str->type == str_char ? 1 : 2);
rd->data = xmalloc(rd->size); rd->data = xmalloc(rd->size);
if(str->type == str_char) switch (str->type)
memcpy(rd->data, str->str.cstr, rd->size);
else if(str->type == str_unicode)
{ {
case str_char:
memcpy(rd->data, str->str.cstr, rd->size);
break;
case str_unicode:
{
int i; int i;
switch(byteorder) switch(byteorder)
{ {
...@@ -2286,9 +2285,8 @@ static raw_data_t *str2raw_data(string_t *str) ...@@ -2286,9 +2285,8 @@ static raw_data_t *str2raw_data(string_t *str)
} }
break; break;
} }
}
} }
else
internal_error(__FILE__, __LINE__, "Invalid stringtype\n");
return rd; return rd;
} }
...@@ -2720,7 +2718,7 @@ static resource_t *build_fontdirs(resource_t *tail) ...@@ -2720,7 +2718,7 @@ static resource_t *build_fontdirs(resource_t *tail)
if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped)) if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
#endif #endif
{ {
internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping\n"); error("User supplied FONTDIR needs byteswapping\n");
} }
} }
......
...@@ -672,7 +672,7 @@ static struct list pp_includelogiclist = LIST_INIT( pp_includelogiclist ); ...@@ -672,7 +672,7 @@ static struct list pp_includelogiclist = LIST_INIT( pp_includelogiclist );
push_macro(ppp); push_macro(ppp);
break; break;
default: default:
pp_internal_error(__FILE__, __LINE__, "Invalid define type %d\n", ppp->type); assert(0);
} }
} }
else put_buffer(ppy_text, ppy_leng); else put_buffer(ppy_text, ppy_leng);
...@@ -916,8 +916,6 @@ static void expand_special(pp_entry_t *ppp) ...@@ -916,8 +916,6 @@ static void expand_special(pp_entry_t *ppp)
buf = xrealloc(buf, strlen(pp_status.input) + 3); buf = xrealloc(buf, strlen(pp_status.input) + 3);
sprintf(buf, "\"%s\"", pp_status.input); sprintf(buf, "\"%s\"", pp_status.input);
} }
else
pp_internal_error(__FILE__, __LINE__, "Special macro '%s' not found...\n", ppp->ident);
if(pp_flex_debug) if(pp_flex_debug)
fprintf(stderr, "expand_special(%d): %s:%d: '%s' -> '%s'\n", fprintf(stderr, "expand_special(%d): %s:%d: '%s' -> '%s'\n",
...@@ -1059,9 +1057,6 @@ static mtext_t *add_expand_text(mtext_t *mtp, macexpstackentry_t *mep, int *nnl) ...@@ -1059,9 +1057,6 @@ static mtext_t *add_expand_text(mtext_t *mtp, macexpstackentry_t *mep, int *nnl)
if(pp_flex_debug) if(pp_flex_debug)
fprintf(stderr, "add_expand_text: exp_subst(%d): '%s'\n", mtp->subst.argidx, exp); fprintf(stderr, "add_expand_text: exp_subst(%d): '%s'\n", mtp->subst.argidx, exp);
break; break;
default:
pp_internal_error(__FILE__, __LINE__, "Invalid expansion type (%d) in macro expansion\n", mtp->type);
} }
return mtp; return mtp;
} }
...@@ -1196,7 +1191,7 @@ static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop) ...@@ -1196,7 +1191,7 @@ static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop)
if(ppy_debug) if(ppy_debug)
printf("push_buffer(%d): %p %p %p %d\n", bufferstackidx, ppp, filename, incname, pop); printf("push_buffer(%d): %p %p %p %d\n", bufferstackidx, ppp, filename, incname, pop);
if(bufferstackidx >= MAXBUFFERSTACK) if(bufferstackidx >= MAXBUFFERSTACK)
pp_internal_error(__FILE__, __LINE__, "Buffer stack overflow"); error("Buffer stack overflow");
memset(&bufferstack[bufferstackidx], 0, sizeof(bufferstack[0])); memset(&bufferstack[bufferstackidx], 0, sizeof(bufferstack[0]));
bufferstack[bufferstackidx].bufferstate = YY_CURRENT_BUFFER; bufferstack[bufferstackidx].bufferstate = YY_CURRENT_BUFFER;
...@@ -1221,16 +1216,11 @@ static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop) ...@@ -1221,16 +1216,11 @@ static void push_buffer(pp_entry_t *ppp, char *filename, char *incname, int pop)
pp_status.input = filename; pp_status.input = filename;
ncontinuations = 0; ncontinuations = 0;
} }
else if(!pop)
pp_internal_error(__FILE__, __LINE__, "Pushing buffer without knowing where to go to");
bufferstackidx++; bufferstackidx++;
} }
static bufferstackentry_t *pop_buffer(void) static bufferstackentry_t *pop_buffer(void)
{ {
if(bufferstackidx < 0)
pp_internal_error(__FILE__, __LINE__, "Bufferstack underflow?");
if(bufferstackidx == 0) if(bufferstackidx == 0)
return NULL; return NULL;
...@@ -1295,10 +1285,8 @@ static bufferstackentry_t *pop_buffer(void) ...@@ -1295,10 +1285,8 @@ static bufferstackentry_t *pop_buffer(void)
if(bufferstack[bufferstackidx].should_pop) if(bufferstack[bufferstackidx].should_pop)
{ {
if(yy_current_state() == pp_macexp) assert( yy_current_state() == pp_macexp );
macro_add_expansion(); macro_add_expansion();
else
pp_internal_error(__FILE__, __LINE__, "Pop buffer and state without macro expansion state");
yy_pop_state(); yy_pop_state();
} }
...@@ -1332,8 +1320,7 @@ static macexpstackentry_t *top_macro(void) ...@@ -1332,8 +1320,7 @@ static macexpstackentry_t *top_macro(void)
static macexpstackentry_t *pop_macro(void) static macexpstackentry_t *pop_macro(void)
{ {
if(macexpstackidx <= 0) assert(macexpstackidx > 0);
pp_internal_error(__FILE__, __LINE__, "Macro expansion stack underflow\n");
return macexpstack[--macexpstackidx]; return macexpstack[--macexpstackidx];
} }
......
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
case SIZE_INT: BIN_OP_INT(r, v1, v2, OP); break; \ case SIZE_INT: BIN_OP_INT(r, v1, v2, OP); break; \
case SIZE_LONG: BIN_OP_LONG(r, v1, v2, OP); break; \ case SIZE_LONG: BIN_OP_LONG(r, v1, v2, OP); break; \
case SIZE_LONGLONG: BIN_OP_LONGLONG(r, v1, v2, OP); break; \ case SIZE_LONGLONG: BIN_OP_LONGLONG(r, v1, v2, OP); break; \
default: pp_internal_error(__FILE__, __LINE__, "Invalid type indicator (0x%04x)", v1.type); \ default: assert(0); \
} }
...@@ -219,8 +219,6 @@ preprocessor ...@@ -219,8 +219,6 @@ preprocessor
break; break;
case if_error: case if_error:
break; break;
default:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #elif directive", s);
} }
} }
| tELSE tNL { | tELSE tNL {
...@@ -245,8 +243,6 @@ preprocessor ...@@ -245,8 +243,6 @@ preprocessor
break; break;
case if_error: case if_error:
break; break;
default:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
} }
} }
| tENDIF tNL { | tENDIF tNL {
......
...@@ -85,16 +85,6 @@ int parser_warning(const char *s, ...) ...@@ -85,16 +85,6 @@ int parser_warning(const char *s, ...)
return 0; return 0;
} }
void internal_error(const char *file, int line, const char *s, ...)
{
va_list ap;
va_start(ap, s);
fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
vfprintf(stderr, s, ap);
va_end(ap);
exit(3);
}
void fatal_perror( const char *msg, ... ) void fatal_perror( const char *msg, ... )
{ {
va_list valist; va_list valist;
...@@ -264,36 +254,30 @@ int compare_striW( const WCHAR *str1, const WCHAR *str2 ) ...@@ -264,36 +254,30 @@ int compare_striW( const WCHAR *str1, const WCHAR *str2 )
*/ */
int compare_name_id(const name_id_t *n1, const name_id_t *n2) int compare_name_id(const name_id_t *n1, const name_id_t *n2)
{ {
if(n1->type == name_ord && n2->type == name_ord) switch (n1->type)
{ {
return n1->name.i_name - n2->name.i_name; case name_ord:
} if (n2->type == name_ord) return n1->name.i_name - n2->name.i_name;
else if(n1->type == name_str && n2->type == name_str) return 1;
case name_str:
if (n2->type == name_str)
{ {
if(n1->name.s_name->type == str_char if(n1->name.s_name->type == str_char
&& n2->name.s_name->type == str_char) && n2->name.s_name->type == str_char)
{ {
return compare_striA(n1->name.s_name->str.cstr, n2->name.s_name->str.cstr); return compare_striA(n1->name.s_name->str.cstr, n2->name.s_name->str.cstr);
} }
else if(n1->name.s_name->type == str_unicode
&& n2->name.s_name->type == str_unicode)
{
return compare_striW(n1->name.s_name->str.wstr, n2->name.s_name->str.wstr);
}
else else
{ {
internal_error(__FILE__, __LINE__, "Can't yet compare strings of mixed type\n"); assert( n1->name.s_name->type == str_unicode );
assert( n2->name.s_name->type == str_unicode );
return compare_striW(n1->name.s_name->str.wstr, n2->name.s_name->str.wstr);
} }
} }
else if(n1->type == name_ord && n2->type == name_str) return -1;
return 1; }
else if(n1->type == name_str && n2->type == name_ord) return 0; /* Keep the compiler happy */
return -1;
else
internal_error(__FILE__, __LINE__, "Comparing name-ids with unknown types (%d, %d)\n",
n1->type, n2->type);
return 0; /* Keep the compiler happy */
} }
#ifdef _WIN32 #ifdef _WIN32
......
...@@ -39,7 +39,6 @@ char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 ...@@ -39,7 +39,6 @@ char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2
int strendswith( const char *str, const char *end ); int strendswith( const char *str, const char *end );
int parser_error(const char *s, ...) __attribute__((format (printf, 1, 2))); int parser_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4), noreturn));
void fatal_perror( const char *msg, ... ) __attribute__((format (printf, 1, 2), noreturn)); void fatal_perror( const char *msg, ... ) __attribute__((format (printf, 1, 2), noreturn));
void error(const char *s, ...) __attribute__((format (printf, 1, 2), noreturn)); void error(const char *s, ...) __attribute__((format (printf, 1, 2), noreturn));
void warning(const char *s, ...) __attribute__((format (printf, 1, 2))); void warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
......
...@@ -428,7 +428,7 @@ static const char * const pp_if_state_str[] = { ...@@ -428,7 +428,7 @@ static const char * const pp_if_state_str[] = {
void pp_push_if(pp_if_state_t s) void pp_push_if(pp_if_state_t s)
{ {
if(if_stack_idx >= MAXIFSTACK) if(if_stack_idx >= MAXIFSTACK)
pp_internal_error(__FILE__, __LINE__, "#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK); error("#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK);
if(pp_flex_debug) if(pp_flex_debug)
fprintf(stderr, "Push if %s:%d: %s(%d) -> %s(%d)\n", pp_status.input, pp_status.line_number, pp_if_state_str[pp_if_state()], if_stack_idx, pp_if_state_str[s], if_stack_idx+1); fprintf(stderr, "Push if %s:%d: %s(%d) -> %s(%d)\n", pp_status.input, pp_status.line_number, pp_if_state_str[pp_if_state()], if_stack_idx, pp_if_state_str[s], if_stack_idx+1);
...@@ -446,8 +446,8 @@ void pp_push_if(pp_if_state_t s) ...@@ -446,8 +446,8 @@ void pp_push_if(pp_if_state_t s)
case if_ignore: case if_ignore:
pp_push_ignore_state(); pp_push_ignore_state();
break; break;
default: case if_error:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state()); assert(0);
} }
} }
...@@ -470,8 +470,8 @@ pp_if_state_t pp_pop_if(void) ...@@ -470,8 +470,8 @@ pp_if_state_t pp_pop_if(void)
case if_ignore: case if_ignore:
pp_pop_ignore_state(); pp_pop_ignore_state();
break; break;
default: case if_error:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state()); assert(0);
} }
if(pp_flex_debug) if(pp_flex_debug)
...@@ -509,8 +509,8 @@ void pp_next_if_state(int i) ...@@ -509,8 +509,8 @@ void pp_next_if_state(int i)
case if_ignore: case if_ignore:
pp_push_if(if_ignore); pp_push_if(if_ignore);
break; break;
default: case if_error:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #{if,ifdef,ifndef} directive", (int)pp_if_state()); assert(0);
} }
} }
...@@ -545,17 +545,6 @@ int ppy_warning(const char *s, ...) ...@@ -545,17 +545,6 @@ int ppy_warning(const char *s, ...)
return 0; return 0;
} }
void pp_internal_error(const char *file, int line, const char *s, ...)
{
va_list ap;
va_start(ap, s);
fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(3);
}
static void add_cmdline_defines(void) static void add_cmdline_defines(void)
{ {
struct define *def; struct define *def;
......
...@@ -168,7 +168,6 @@ int pp_get_if_depth(void); ...@@ -168,7 +168,6 @@ int pp_get_if_depth(void);
int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2))); int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
/* current preprocessor state */ /* current preprocessor state */
/* everything is in this structure to avoid polluting the global symbol space */ /* everything is in this structure to avoid polluting the global symbol space */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment