diff --git a/src/cc65/compile.c b/src/cc65/compile.c index d7167706b..f619d5b59 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2009, Ullrich von Bassewitz */ +/* (C) 2000-2012, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -93,7 +93,7 @@ static void Parse (void) /* Disallow ASM statements on global level */ if (CurTok.Tok == TOK_ASM) { - Error ("__asm__ is not allowed here"); + Error ("__asm__ is not allowed here"); /* Parse and remove the statement for error recovery */ AsmStatement (); ConsumeSemi (); @@ -209,9 +209,7 @@ static void Parse (void) * the element qualifiers, since not the array but its * elements are const. */ - if (IsQualConst (Decl.Type) || - (IsTypeArray (Decl.Type) && - IsQualConst (GetElementType (Decl.Type)))) { + if (IsQualConst (GetBaseElementType (Decl.Type))) { g_userodata (); } else { g_usedata (); diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 0d7b27c60..c1f86062f 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2012, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -654,6 +654,20 @@ Type* GetElementType (Type* T) +Type* GetBaseElementType (Type* T) +/* Return the base element type of a given type. If T is not an array, this + * will return. Otherwise it will return the base element type, which means + * the element type that is not an array. + */ +{ + while (IsTypeArray (T)) { + ++T; + } + return T; +} + + + SymEntry* GetSymEntry (const Type* T) /* Return a SymEntry pointer from a type */ { diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 0fe46f6d2..3cc6ec5b5 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2010, Ullrich von Bassewitz */ +/* (C) 1998-2012, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -640,6 +640,12 @@ void SetElementCount (Type* T, long Count); Type* GetElementType (Type* T); /* Return the element type of the given array type. */ +Type* GetBaseElementType (Type* T); +/* Return the base element type of a given type. If T is not an array, this + * will return. Otherwise it will return the base element type, which means + * the element type that is not an array. + */ + struct SymEntry* GetSymEntry (const Type* T) attribute ((const)); /* Return a SymEntry pointer from a type */ diff --git a/src/cc65/locals.c b/src/cc65/locals.c index 710d05e33..3e1002add 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -356,11 +356,10 @@ static unsigned ParseStaticDecl (Declaration* Decl, unsigned* SC) if (CurTok.Tok == TOK_ASSIGN) { /* Initialization ahead, switch to data segment and define a label. - * For arrays, we need to check the elements of the array for + * For arrays, we need to check the elements of the array for * constness, not the array itself. */ - if (IsQualConst (Decl->Type) || - (IsTypeArray (Decl->Type) && IsQualConst (GetElementType (Decl->Type)))) { + if (IsQualConst (GetBaseElementType (Decl->Type))) { SymData = AllocLabel (g_userodata); } else { SymData = AllocLabel (g_usedata);