Handling duplicate storage class specifiers
This commit is contained in:
parent
73dcf8a614
commit
937a4588ec
30
src/code.c
30
src/code.c
@ -466,22 +466,34 @@ int code_context_set_identifier(Code * code, char const * identifier)
|
|||||||
/* code_context_set_storage */
|
/* code_context_set_storage */
|
||||||
int code_context_set_storage(Code * code, CodeStorage storage)
|
int code_context_set_storage(Code * code, CodeStorage storage)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
struct
|
||||||
char const * str[CODE_STORAGE_COUNT] =
|
|
||||||
{
|
{
|
||||||
"NULL",
|
CodeStorage storage;
|
||||||
"TYPEDEF",
|
char const * name;
|
||||||
"EXTERN",
|
} sn[CODE_STORAGE_COUNT] =
|
||||||
"STATIC",
|
{
|
||||||
"AUTO",
|
{ CODE_STORAGE_NULL, "NULL" },
|
||||||
"REGISTER"
|
{ CODE_STORAGE_TYPEDEF, "typedef" },
|
||||||
|
{ CODE_STORAGE_EXTERN, "extern" },
|
||||||
|
{ CODE_STORAGE_STATIC, "static" },
|
||||||
|
{ CODE_STORAGE_AUTO, "auto" },
|
||||||
|
{ CODE_STORAGE_REGISTER,"register" }
|
||||||
};
|
};
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s(%s)\n", __func__, str[storage]);
|
fprintf(stderr, "DEBUG: %s(%s)\n", __func__, str[storage]);
|
||||||
#endif
|
#endif
|
||||||
/* FIXME should probably warn if already set */
|
if(!(code->storage & storage))
|
||||||
|
{
|
||||||
code->storage |= storage;
|
code->storage |= storage;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
for(i = 0; i < CODE_STORAGE_COUNT; i++)
|
||||||
|
if(sn[i].storage == storage)
|
||||||
|
return error_set_code(1, "%s\"%s\"", "Duplicate ",
|
||||||
|
sn[i].name);
|
||||||
|
return error_set_code(1, "%s", "Duplicate storage class specifier");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user