1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-15 17:30:06 +00:00

Minor cleanups with array element qualifiers.

This commit is contained in:
acqn 2021-04-05 16:40:32 +08:00 committed by Oliver Schmidt
parent 896f463a23
commit 24d36854d2

View File

@ -3132,44 +3132,28 @@ static void parseadd (ExprDesc* Expr, int DoArrayRef)
/* Deal with array ref */
if (DoArrayRef) {
TypeCode Qualifiers = T_QUAL_NONE;
Type* ElementType;
/* Check the types of array and subscript */
if (IsClassPtr (lhst)) {
if (!IsClassInt (rhst)) {
Error ("Array subscript is not an integer");
ED_MakeConstAbs (Expr, 0, GetCharArrayType (1));
} else if (IsTypeArray (lhst)) {
Qualifiers = GetQualifier (lhst);
}
} else if (IsClassInt (lhst)) {
if (!IsClassPtr (rhst)) {
Error ("Subscripted value is neither array nor pointer");
ED_MakeConstAbs (Expr, 0, GetCharArrayType (1));
} else if (IsTypeArray (rhst)) {
Qualifiers = GetQualifier (rhst);
}
} else {
Error ("Cannot subscript");
ED_MakeConstAbs (Expr, 0, GetCharArrayType (1));
}
/* The element type has the combined qualifiers from itself and the array,
** it is a member of (if any).
*/
ElementType = Indirect (Expr->Type);
if (GetQualifier (ElementType) != (GetQualifier (ElementType) | Qualifiers)) {
ElementType = TypeDup (ElementType);
ElementType->C |= Qualifiers;
}
/* The final result is usually an lvalue expression of element type
** referenced in the primary, unless it is once again an array. We can just
** assume the usual case first, and change it later if necessary.
*/
ED_IndExpr (Expr);
Expr->Type = ElementType;
Expr->Type = Indirect (Expr->Type);
/* An array element is actually a variable. So the rules for variables with
** respect to the reference type apply: If it's an array, it is virtually