mirror of
https://github.com/cc65/cc65.git
synced 2025-01-10 19:29:45 +00:00
Declaration specifier flags cleanup.
This commit is contained in:
parent
79b4690077
commit
a1a060c291
@ -350,11 +350,11 @@ static void UseDefaultType (DeclSpec* Spec, typespec_t TSFlags)
|
|||||||
/* Use the default type for the type specifier */
|
/* Use the default type for the type specifier */
|
||||||
{
|
{
|
||||||
if ((TSFlags & TS_MASK_DEFAULT_TYPE) == TS_DEFAULT_TYPE_NONE) {
|
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[0].C = T_INT;
|
||||||
Spec->Type[1].C = T_END;
|
Spec->Type[1].C = T_END;
|
||||||
} else {
|
} else {
|
||||||
Spec->Flags |= DS_DEF_TYPE;
|
Spec->Flags = (Spec->Flags & ~DS_TYPE_MASK) | DS_DEF_TYPE;
|
||||||
Spec->Type[0].C = T_INT;
|
Spec->Type[0].C = T_INT;
|
||||||
Spec->Type[1].C = T_END;
|
Spec->Type[1].C = T_END;
|
||||||
}
|
}
|
||||||
@ -1413,8 +1413,8 @@ static void ParseTypeSpec (DeclSpec* Spec, typespec_t TSFlags)
|
|||||||
SymEntry* TagEntry;
|
SymEntry* TagEntry;
|
||||||
TypeCode Qualifiers = T_QUAL_NONE;
|
TypeCode Qualifiers = T_QUAL_NONE;
|
||||||
|
|
||||||
/* Assume we have an explicit type */
|
/* Assume we have an explicitly specified type */
|
||||||
Spec->Flags &= ~DS_DEF_TYPE;
|
Spec->Flags = (Spec->Flags & ~DS_TYPE_MASK) | DS_EXPLICIT_TYPE;
|
||||||
|
|
||||||
/* Read storage specifiers and/or type qualifiers if we have any */
|
/* Read storage specifiers and/or type qualifiers if we have any */
|
||||||
OptionalSpecifiers (Spec, &Qualifiers, TSFlags);
|
OptionalSpecifiers (Spec, &Qualifiers, TSFlags);
|
||||||
@ -1767,7 +1767,7 @@ static void ParseOldStyleParamList (FuncDesc* F)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Type must be specified */
|
/* Type must be specified */
|
||||||
if ((Spec.Flags & DS_NO_TYPE) != 0) {
|
if ((Spec.Flags & DS_TYPE_MASK) == DS_NONE) {
|
||||||
Error ("Expected declaration specifiers");
|
Error ("Expected declaration specifiers");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1860,7 +1860,7 @@ static void ParseAnsiParamList (FuncDesc* F)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Type must be specified */
|
/* Type must be specified */
|
||||||
if ((Spec.Flags & DS_NO_TYPE) != 0) {
|
if ((Spec.Flags & DS_TYPE_MASK) == DS_NONE) {
|
||||||
Error ("Type specifier missing");
|
Error ("Type specifier missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2100,7 +2100,7 @@ static void DirectDecl (DeclSpec* Spec, Declarator* D, declmode_t Mode)
|
|||||||
if (Mode == DM_IDENT_OR_EMPTY) {
|
if (Mode == DM_IDENT_OR_EMPTY) {
|
||||||
Spec->Flags |= DS_NO_EMPTY_DECL;
|
Spec->Flags |= DS_NO_EMPTY_DECL;
|
||||||
if (D->Ident[0] == '\0') {
|
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");
|
Error ("Identifier or ';' expected after declaration specifiers");
|
||||||
} else {
|
} else {
|
||||||
Error ("Identifier expected");
|
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
|
/* If there is no explicit type specifier, an optional identifier becomes
|
||||||
** required.
|
** 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;
|
Spec->Flags |= DS_NO_EMPTY_DECL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2237,7 +2238,7 @@ int ParseDecl (DeclSpec* Spec, Declarator* D, declmode_t Mode)
|
|||||||
ParseAttribute (D);
|
ParseAttribute (D);
|
||||||
|
|
||||||
/* Check a few pre-C99 things */
|
/* 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 */
|
/* Check and warn about an implicit int return in the function */
|
||||||
if (IsTypeFunc (D->Type) && IsRankInt (GetFuncReturnType (D->Type))) {
|
if (IsTypeFunc (D->Type) && IsRankInt (GetFuncReturnType (D->Type))) {
|
||||||
/* Function has an implicit int return. Output a warning if we don't
|
/* 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 (PrevErrorCount != ErrorCount) {
|
||||||
if ((Spec->Flags & DS_DEF_TYPE) == 0 &&
|
if ((Spec->Flags & DS_TYPE_MASK) != DS_DEF_TYPE &&
|
||||||
(Spec->Flags & DS_NO_EMPTY_DECL) != 0 &&
|
(Spec->Flags & DS_NO_EMPTY_DECL) != 0 &&
|
||||||
D->Ident[0] == '\0') {
|
D->Ident[0] == '\0') {
|
||||||
/* Use a fictitious name for the identifier if it is missing */
|
/* Use a fictitious name for the identifier if it is missing */
|
||||||
const char* Level = "";
|
const char* Level = "";
|
||||||
|
@ -65,15 +65,18 @@ enum typespec_t {
|
|||||||
TS_DEFAULT_TYPE_AUTO = 0x02, /* C23 type inference with auto */
|
TS_DEFAULT_TYPE_AUTO = 0x02, /* C23 type inference with auto */
|
||||||
|
|
||||||
/* Whether to allow certain kinds of specifiers */
|
/* Whether to allow certain kinds of specifiers */
|
||||||
TS_STORAGE_CLASS_SPEC = 0x04, /* Allow storage storage class specifiers */
|
TS_STORAGE_CLASS_SPEC = 0x04, /* Allow storage class specifiers */
|
||||||
TS_FUNCTION_SPEC = 0x08, /* Allow function specifiers */
|
TS_FUNCTION_SPEC = 0x08, /* Allow function specifiers */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Masks for the Flags field in DeclSpec */
|
/* 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_DEF_STORAGE 0x0001U /* Default storage class used */
|
||||||
#define DS_NO_TYPE 0x0002U /* No type explicitly specified */
|
#define DS_EXPLICIT_TYPE 0x0002U /* Type specified */
|
||||||
#define DS_DEF_TYPE 0x0006U /* Default type used */
|
#define DS_DEF_TYPE 0x0004U /* Implicit type used */
|
||||||
#define DS_EXTRA_TYPE 0x0008U /* Extra type declared */
|
#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_DECL 0x0010U /* New type declared */
|
||||||
#define DS_NEW_TYPE_DEF 0x0020U /* New type defined */
|
#define DS_NEW_TYPE_DEF 0x0020U /* New type defined */
|
||||||
#define DS_NEW_TYPE (DS_NEW_TYPE_DECL | DS_NEW_TYPE_DEF)
|
#define DS_NEW_TYPE (DS_NEW_TYPE_DECL | DS_NEW_TYPE_DEF)
|
||||||
|
@ -1414,7 +1414,7 @@ static void Primary (ExprDesc* E)
|
|||||||
DeclSpec Spec;
|
DeclSpec Spec;
|
||||||
ParseDeclSpec (&Spec, TS_DEFAULT_TYPE_NONE, SC_AUTO);
|
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 */
|
/* Recognized but not supported */
|
||||||
Error ("Mixed declarations and code are not supported in cc65");
|
Error ("Mixed declarations and code are not supported in cc65");
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ void DeclareLocals (void)
|
|||||||
** assumed that we have reached the end of declarations.
|
** assumed that we have reached the end of declarations.
|
||||||
*/
|
*/
|
||||||
if ((Spec.Flags & DS_DEF_STORAGE) != 0 && /* No storage spec */
|
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 */
|
GetQualifier (Spec.Type) == T_QUAL_NONE) { /* No type qualifier */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user