mirror of
https://github.com/cc65/cc65.git
synced 2024-12-25 02:29:52 +00:00
Using typdefs, it is possible to construct types that have qualifiers
attached to an array (not the elementtype). Fix these problems by tranfering the qualifiers to the elements. git-svn-id: svn://svn.cc65.org/cc65/trunk@3774 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
4c91b95d30
commit
030ce6ad28
@ -125,7 +125,7 @@ static TypeCode OptionalQualifiers (TypeCode Q)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void optionalint (void)
|
static void OptionalInt (void)
|
||||||
/* Eat an optional "int" token */
|
/* Eat an optional "int" token */
|
||||||
{
|
{
|
||||||
if (CurTok.Tok == TOK_INT) {
|
if (CurTok.Tok == TOK_INT) {
|
||||||
@ -136,7 +136,7 @@ static void optionalint (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void optionalsigned (void)
|
static void OptionalSigned (void)
|
||||||
/* Eat an optional "signed" token */
|
/* Eat an optional "signed" token */
|
||||||
{
|
{
|
||||||
if (CurTok.Tok == TOK_SIGNED) {
|
if (CurTok.Tok == TOK_SIGNED) {
|
||||||
@ -212,6 +212,32 @@ static void AddArrayToDeclaration (Declaration* D, long Size)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void FixArrayQualifiers (Type* T)
|
||||||
|
/* Using typedefs, it is possible to generate declarations that have
|
||||||
|
* type qualifiers attached to an array, not the element type. Go and
|
||||||
|
* fix these here.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
TypeCode Q = T_QUAL_NONE;
|
||||||
|
while (T->C != T_END) {
|
||||||
|
if (IsTypeArray (T)) {
|
||||||
|
/* Extract any type qualifiers */
|
||||||
|
Q |= T->C & T_MASK_QUAL;
|
||||||
|
T->C = UnqualifiedType (T->C);
|
||||||
|
} else {
|
||||||
|
/* Add extracted type qualifiers here */
|
||||||
|
T->C |= Q;
|
||||||
|
Q = T_QUAL_NONE;
|
||||||
|
}
|
||||||
|
++T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Q must be empty now */
|
||||||
|
CHECK (Q == T_QUAL_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void ParseStorageClass (DeclSpec* D, unsigned DefStorage)
|
static void ParseStorageClass (DeclSpec* D, unsigned DefStorage)
|
||||||
/* Parse a storage class */
|
/* Parse a storage class */
|
||||||
{
|
{
|
||||||
@ -453,12 +479,12 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
if (CurTok.Tok == TOK_UNSIGNED) {
|
if (CurTok.Tok == TOK_UNSIGNED) {
|
||||||
NextToken ();
|
NextToken ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_ULONG;
|
D->Type[0].C = T_ULONG;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
} else {
|
} else {
|
||||||
optionalsigned ();
|
OptionalSigned ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_LONG;
|
D->Type[0].C = T_LONG;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
}
|
}
|
||||||
@ -468,12 +494,12 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
if (CurTok.Tok == TOK_UNSIGNED) {
|
if (CurTok.Tok == TOK_UNSIGNED) {
|
||||||
NextToken ();
|
NextToken ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_USHORT;
|
D->Type[0].C = T_USHORT;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
} else {
|
} else {
|
||||||
optionalsigned ();
|
OptionalSigned ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_SHORT;
|
D->Type[0].C = T_SHORT;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
}
|
}
|
||||||
@ -497,14 +523,14 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
|||||||
|
|
||||||
case TOK_SHORT:
|
case TOK_SHORT:
|
||||||
NextToken ();
|
NextToken ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_SHORT;
|
D->Type[0].C = T_SHORT;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_LONG:
|
case TOK_LONG:
|
||||||
NextToken ();
|
NextToken ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_LONG;
|
D->Type[0].C = T_LONG;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
break;
|
break;
|
||||||
@ -532,14 +558,14 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
|||||||
|
|
||||||
case TOK_SHORT:
|
case TOK_SHORT:
|
||||||
NextToken ();
|
NextToken ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_USHORT;
|
D->Type[0].C = T_USHORT;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_LONG:
|
case TOK_LONG:
|
||||||
NextToken ();
|
NextToken ();
|
||||||
optionalint ();
|
OptionalInt ();
|
||||||
D->Type[0].C = T_ULONG;
|
D->Type[0].C = T_ULONG;
|
||||||
D->Type[1].C = T_END;
|
D->Type[1].C = T_END;
|
||||||
break;
|
break;
|
||||||
@ -1131,16 +1157,19 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */
|
NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */
|
||||||
TypeCpy (D->Type + D->Index, Spec->Type);
|
TypeCpy (D->Type + D->Index, Spec->Type);
|
||||||
|
|
||||||
|
/* Fix any type qualifiers attached to an array type */
|
||||||
|
FixArrayQualifiers (D->Type);
|
||||||
|
|
||||||
/* Check the size of the generated type */
|
/* Check the size of the generated type */
|
||||||
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
||||||
unsigned Size = SizeOf (D->Type);
|
unsigned Size = SizeOf (D->Type);
|
||||||
if (Size >= 0x10000) {
|
if (Size >= 0x10000) {
|
||||||
if (D->Ident[0] != '\0') {
|
if (D->Ident[0] != '\0') {
|
||||||
Error ("Size of `%s' is invalid (0x%06X)", D->Ident, Size);
|
Error ("Size of `%s' is invalid (0x%06X)", D->Ident, Size);
|
||||||
} else {
|
} else {
|
||||||
Error ("Invalid size in declaration (0x%06X)", Size);
|
Error ("Invalid size in declaration (0x%06X)", Size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user