Declaration specifier flags cleanup.

This commit is contained in:
acqn 2023-12-10 15:43:24 +08:00
parent 79b4690077
commit a1a060c291
4 changed files with 22 additions and 18 deletions

View File

@ -350,11 +350,11 @@ static void UseDefaultType (DeclSpec* Spec, typespec_t TSFlags)
/* Use the default type for the type specifier */
{
if ((TSFlags & TS_MASK_DEFAULT_TYPE) == TS_DEFAULT_TYPE_NONE) {
Spec->Flags |= DS_NO_TYPE;
Spec->Flags = (Spec->Flags & ~DS_TYPE_MASK) | DS_NONE;
Spec->Type[0].C = T_INT;
Spec->Type[1].C = T_END;
} else {
Spec->Flags |= DS_DEF_TYPE;
Spec->Flags = (Spec->Flags & ~DS_TYPE_MASK) | DS_DEF_TYPE;
Spec->Type[0].C = T_INT;
Spec->Type[1].C = T_END;
}
@ -1413,8 +1413,8 @@ static void ParseTypeSpec (DeclSpec* Spec, typespec_t TSFlags)
SymEntry* TagEntry;
TypeCode Qualifiers = T_QUAL_NONE;
/* Assume we have an explicit type */
Spec->Flags &= ~DS_DEF_TYPE;
/* Assume we have an explicitly specified type */
Spec->Flags = (Spec->Flags & ~DS_TYPE_MASK) | DS_EXPLICIT_TYPE;
/* Read storage specifiers and/or type qualifiers if we have any */
OptionalSpecifiers (Spec, &Qualifiers, TSFlags);
@ -1767,7 +1767,7 @@ static void ParseOldStyleParamList (FuncDesc* F)
}
/* Type must be specified */
if ((Spec.Flags & DS_NO_TYPE) != 0) {
if ((Spec.Flags & DS_TYPE_MASK) == DS_NONE) {
Error ("Expected declaration specifiers");
break;
}
@ -1860,7 +1860,7 @@ static void ParseAnsiParamList (FuncDesc* F)
}
/* Type must be specified */
if ((Spec.Flags & DS_NO_TYPE) != 0) {
if ((Spec.Flags & DS_TYPE_MASK) == DS_NONE) {
Error ("Type specifier missing");
}
@ -2100,7 +2100,7 @@ static void DirectDecl (DeclSpec* Spec, Declarator* D, declmode_t Mode)
if (Mode == DM_IDENT_OR_EMPTY) {
Spec->Flags |= DS_NO_EMPTY_DECL;
if (D->Ident[0] == '\0') {
if ((Spec->Flags & DS_DEF_TYPE) == 0) {
if ((Spec->Flags & DS_TYPE_MASK) != DS_NONE) {
Error ("Identifier or ';' expected after declaration specifiers");
} else {
Error ("Identifier expected");
@ -2200,7 +2200,8 @@ int ParseDecl (DeclSpec* Spec, Declarator* D, declmode_t Mode)
/* If there is no explicit type specifier, an optional identifier becomes
** required.
*/
if (Mode == DM_IDENT_OR_EMPTY && (Spec->Flags & DS_DEF_TYPE) != 0) {
if (Mode == DM_IDENT_OR_EMPTY &&
(Spec->Flags & DS_TYPE_MASK) == DS_DEF_TYPE) {
Spec->Flags |= DS_NO_EMPTY_DECL;
}
@ -2237,7 +2238,7 @@ int ParseDecl (DeclSpec* Spec, Declarator* D, declmode_t Mode)
ParseAttribute (D);
/* Check a few pre-C99 things */
if (D->Ident[0] != '\0' && (Spec->Flags & DS_DEF_TYPE) != 0) {
if (D->Ident[0] != '\0' && (Spec->Flags & DS_TYPE_MASK) == DS_DEF_TYPE) {
/* Check and warn about an implicit int return in the function */
if (IsTypeFunc (D->Type) && IsRankInt (GetFuncReturnType (D->Type))) {
/* Function has an implicit int return. Output a warning if we don't
@ -2286,8 +2287,8 @@ int ParseDecl (DeclSpec* Spec, Declarator* D, declmode_t Mode)
}
if (PrevErrorCount != ErrorCount) {
if ((Spec->Flags & DS_DEF_TYPE) == 0 &&
(Spec->Flags & DS_NO_EMPTY_DECL) != 0 &&
if ((Spec->Flags & DS_TYPE_MASK) != DS_DEF_TYPE &&
(Spec->Flags & DS_NO_EMPTY_DECL) != 0 &&
D->Ident[0] == '\0') {
/* Use a fictitious name for the identifier if it is missing */
const char* Level = "";

View File

@ -65,15 +65,18 @@ enum typespec_t {
TS_DEFAULT_TYPE_AUTO = 0x02, /* C23 type inference with auto */
/* Whether to allow certain kinds of specifiers */
TS_STORAGE_CLASS_SPEC = 0x04, /* Allow storage storage class specifiers */
TS_FUNCTION_SPEC = 0x08, /* Allow function specifiers */
TS_STORAGE_CLASS_SPEC = 0x04, /* Allow storage class specifiers */
TS_FUNCTION_SPEC = 0x08, /* Allow function specifiers */
};
/* Masks for the Flags field in DeclSpec */
#define DS_NONE 0x0000U /* Nothing specified or used */
#define DS_DEF_STORAGE 0x0001U /* Default storage class used */
#define DS_NO_TYPE 0x0002U /* No type explicitly specified */
#define DS_DEF_TYPE 0x0006U /* Default type used */
#define DS_EXTRA_TYPE 0x0008U /* Extra type declared */
#define DS_EXPLICIT_TYPE 0x0002U /* Type specified */
#define DS_DEF_TYPE 0x0004U /* Implicit type used */
#define DS_AUTO_TYPE 0x0006U /* C23 auto type used */
#define DS_TYPE_MASK 0x0006U /* Mask for type of spec decl */
#define DS_EXTRA_TYPE 0x0008U /* ESU type in declaration */
#define DS_NEW_TYPE_DECL 0x0010U /* New type declared */
#define DS_NEW_TYPE_DEF 0x0020U /* New type defined */
#define DS_NEW_TYPE (DS_NEW_TYPE_DECL | DS_NEW_TYPE_DEF)

View File

@ -1414,7 +1414,7 @@ static void Primary (ExprDesc* E)
DeclSpec Spec;
ParseDeclSpec (&Spec, TS_DEFAULT_TYPE_NONE, SC_AUTO);
if ((Spec.Flags & DS_DEF_TYPE) == 0) {
if ((Spec.Flags & DS_TYPE_MASK) != DS_NONE) {
/* Recognized but not supported */
Error ("Mixed declarations and code are not supported in cc65");

View File

@ -575,7 +575,7 @@ void DeclareLocals (void)
** assumed that we have reached the end of declarations.
*/
if ((Spec.Flags & DS_DEF_STORAGE) != 0 && /* No storage spec */
(Spec.Flags & DS_DEF_TYPE) == DS_DEF_TYPE && /* No type given */
(Spec.Flags & DS_TYPE_MASK) == DS_DEF_TYPE && /* No type given */
GetQualifier (Spec.Type) == T_QUAL_NONE) { /* No type qualifier */
break;
}