/* */
/* */
/* */
-/* (C) 2000-2012, Ullrich von Bassewitz */
+/* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
* This means that "extern int i;" will not get storage allocated.
*/
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
- (Decl.StorageClass & SC_TYPEDEF) != SC_TYPEDEF &&
+ (Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF &&
((Spec.Flags & DS_DEF_STORAGE) != 0 ||
(Decl.StorageClass & (SC_EXTERN|SC_STATIC)) == SC_STATIC ||
((Decl.StorageClass & SC_EXTERN) != 0 &&
/* */
/* */
/* */
-/* (C) 1998-2010, Ullrich von Bassewitz */
+/* (C) 1998-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-static SymEntry* StructOrUnionForwardDecl (const char* Name)
+static SymEntry* StructOrUnionForwardDecl (const char* Name, unsigned Type)
/* Handle a struct or union forward decl */
{
- /* Try to find a struct with the given name. If there is none,
+ /* Try to find a struct/union with the given name. If there is none,
* insert a forward declaration into the current lexical level.
*/
SymEntry* Entry = FindTagSym (Name);
if (Entry == 0) {
- Entry = AddStructSym (Name, 0, 0);
- } else if (SymIsLocal (Entry) && (Entry->Flags & SC_STRUCT) != SC_STRUCT) {
- /* Already defined in the level, but no struct */
+ Entry = AddStructSym (Name, Type, 0, 0);
+ } else if ((Entry->Flags & SC_TYPEMASK) != Type) {
+ /* Already defined, but no struct */
Error ("Symbol `%s' is already different kind", Name);
}
return Entry;
/* Enter a copy of this symbol adjusting the offset. We will just
* reuse the type string here.
*/
- AddLocalSym (Entry->Name, Entry->Type,SC_STRUCTFIELD, Offs + Entry->V.Offs);
+ AddLocalSym (Entry->Name, Entry->Type, SC_STRUCTFIELD, Offs + Entry->V.Offs);
/* Currently, there can not be any attributes, but if there will be
* some in the future, we want to know this.
if (CurTok.Tok != TOK_LCURLY) {
/* Just a forward declaration. */
- return StructOrUnionForwardDecl (Name);
+ return StructOrUnionForwardDecl (Name, SC_UNION);
}
/* Add a forward declaration for the struct in the current lexical level */
- Entry = AddStructSym (Name, 0, 0);
+ Entry = AddStructSym (Name, SC_UNION, 0, 0);
/* Skip the curly brace */
NextToken ();
LeaveStructLevel ();
/* Make a real entry from the forward decl and return it */
- return AddStructSym (Name, UnionSize, FieldTab);
+ return AddStructSym (Name, SC_UNION, UnionSize, FieldTab);
}
if (CurTok.Tok != TOK_LCURLY) {
/* Just a forward declaration. */
- return StructOrUnionForwardDecl (Name);
+ return StructOrUnionForwardDecl (Name, SC_STRUCT);
}
/* Add a forward declaration for the struct in the current lexical level */
- Entry = AddStructSym (Name, 0, 0);
+ Entry = AddStructSym (Name, SC_STRUCT, 0, 0);
/* Skip the curly brace */
NextToken ();
LeaveStructLevel ();
/* Make a real entry from the forward decl and return it */
- return AddStructSym (Name, StructSize, FieldTab);
+ return AddStructSym (Name, SC_STRUCT, StructSize, FieldTab);
}
* int declaration.
*/
if ((D->StorageClass & SC_FUNC) != SC_FUNC &&
- (D->StorageClass & SC_TYPEDEF) != SC_TYPEDEF) {
+ (D->StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
/* If the standard was not set explicitly to C89, print a warning
* for variables with implicit int type.
*/
/* */
/* */
/* */
-/* (C) 2000-2009, Ullrich von Bassewitz */
+/* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-static void ParseAutoDecl (Declaration* Decl)
+static void ParseAutoDecl (Declaration* Decl)
/* Parse the declaration of an auto variable. */
{
unsigned Flags;
/* Handle anything that needs storage (no functions, no typdefs) */
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
- (Decl.StorageClass & SC_TYPEDEF) != SC_TYPEDEF) {
+ (Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
/* If we have a register variable, try to allocate a register and
* convert the declaration to "auto" if this is not possible.
/* */
/* */
/* */
-/* (C) 2000-2009, Ullrich von Bassewitz */
+/* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
{ "SC_TYPEDEF", SC_TYPEDEF },
{ "SC_BITFIELD", SC_BITFIELD },
{ "SC_STRUCTFIELD", SC_STRUCTFIELD },
+ { "SC_UNION", SC_UNION },
{ "SC_STRUCT", SC_STRUCT },
{ "SC_AUTO", SC_AUTO },
{ "SC_REGISTER", SC_REGISTER },
/* Print the assembler name if we have one */
if (E->AsmName) {
fprintf (F, " AsmName: %s\n", E->AsmName);
- }
+ }
/* Print the flags */
SymFlags = E->Flags;
/* Cannot be used to change the name */
PRECONDITION (Sym->AsmName == 0);
-
+
/* The assembler name starts with an underline */
Len = strlen (Sym->Name);
Sym->AsmName = xmalloc (Len + 2);
/* */
/* */
/* */
-/* (C) 2000-2009, Ullrich von Bassewitz */
+/* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
#define SC_REF 0x2000U /* Symbol is referenced */
#define SC_TYPE 0x4000U /* This is a type, struct, typedef, etc. */
-#define SC_STRUCT 0x4001U /* Struct or union */
-#define SC_STRUCTFIELD 0x4002U /* Struct or union field */
+#define SC_STRUCT 0x4001U /* Struct */
+#define SC_UNION 0x4002U /* Union */
+#define SC_STRUCTFIELD 0x4003U /* Struct or union field */
#define SC_BITFIELD 0x4004U /* A bit-field inside a struct or union */
-#define SC_TYPEDEF 0x4008U /* A typedef */
+#define SC_TYPEDEF 0x4005U /* A typedef */
+#define SC_TYPEMASK 0x400FU /* Mask for above types */
#define SC_ZEROPAGE 0x8000U /* Symbol marked as zeropage */
/* */
/* */
/* */
-/* (C) 2000-2011, Ullrich von Bassewitz */
+/* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab)
+SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable* Tab)
/* Add a struct/union entry and return it */
{
+ SymEntry* Entry;
+
+ /* Type must be struct or union */
+ PRECONDITION (Type == SC_STRUCT || Type == SC_UNION);
+
/* Do we have an entry with this name already? */
- SymEntry* Entry = FindSymInTable (TagTab, Name, HashStr (Name));
+ Entry = FindSymInTable (TagTab, Name, HashStr (Name));
if (Entry) {
/* We do have an entry. This may be a forward, so check it. */
- if ((Entry->Flags & SC_STRUCT) == 0) {
+ if ((Entry->Flags & SC_TYPEMASK) != Type) {
/* Existing symbol is not a struct */
Error ("Symbol `%s' is already different kind", Name);
} else if (Size > 0 && Entry->V.S.Size > 0) {
} else {
/* Create a new entry */
- Entry = NewSymEntry (Name, SC_STRUCT);
+ Entry = NewSymEntry (Name, Type);
/* Set the struct data */
Entry->V.S.SymTab = Tab;
/* */
/* */
/* */
-/* (C) 2000-2009, Ullrich von Bassewitz */
+/* (C) 2000-2013, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-SymEntry* AddStructSym (const char* Name, unsigned Size, SymTable* Tab);
+SymEntry* AddStructSym (const char* Name, unsigned Type, unsigned Size, SymTable* Tab);
/* Add a struct/union entry and return it */
SymEntry* AddBitField (const char* Name, unsigned Offs, unsigned BitOffs, unsigned Width);