X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fdatatype.c;h=282385ed7e211c34173ff7dae4609f006ea80aa3;hb=92dfde6c4e748946c5e13323bb48bf2abd72c2b3;hp=3996e04a52d324d10588ea2306dd14bf90f07c73;hpb=c6abc5d9d4bbb48f91c12f34fcf67ff4380d185c;p=cc65 diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 3996e04a5..282385ed7 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -6,9 +6,9 @@ /* */ /* */ /* */ -/* (C) 1998-2002 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ +/* (C) 1998-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ /* EMail: uz@musoftware.de */ /* */ /* */ @@ -342,6 +342,9 @@ void PrintFuncSig (FILE* F, const char* Name, type* Type) if (I > 0) { fprintf (F, ", "); } + if (SymIsRegVar (E)) { + fprintf (F, "register "); + } PrintType (F, E->Type); E = E->NextSym; } @@ -365,7 +368,7 @@ void PrintRawType (FILE* F, const type* Type) void Encode (type* Type, unsigned long Val) -/* Encode p[0] and p[1] so that neither p[0] nore p[1] is zero */ +/* Encode Val into the given type string */ { int I; for (I = 0; I < DECODE_SIZE; ++I) { @@ -426,6 +429,7 @@ unsigned SizeOf (const type* T) /* Compute size of object represented by type array. */ { SymEntry* Entry; + long ElementCount; switch (UnqualifiedType (T[0])) { @@ -467,11 +471,17 @@ unsigned SizeOf (const type* T) case T_STRUCT: case T_UNION: - Entry = (SymEntry*) DecodePtr (T+1); + Entry = DecodePtr (T+1); return Entry->V.S.Size; case T_ARRAY: - return (Decode (T+ 1) * SizeOf (T + DECODE_SIZE + 1)); + ElementCount = GetElementCount (T); + if (ElementCount < 0) { + /* Array with unspecified size */ + return 0; + } else { + return ElementCount * SizeOf (T + DECODE_SIZE + 1); + } default: Internal ("Unknown type in SizeOf: %04X", *T); @@ -561,7 +571,7 @@ unsigned TypeOf (const type* T) return CF_LONG | CF_UNSIGNED; case T_FUNC: - F = (FuncDesc*) DecodePtr (T+1); + F = DecodePtr (T+1); return (F->Flags & FD_VARIADIC)? 0 : CF_FIXARGC; case T_STRUCT: @@ -595,6 +605,18 @@ type* Indirect (type* T) +type* ArrayToPtr (const type* T) +/* Convert an array to a pointer to it's first element */ +{ + /* Function must only be called for an array */ + CHECK ((T[0] & T_MASK_TYPE) == T_TYPE_ARRAY); + + /* Return pointer to first element */ + return PointerTo (T + DECODE_SIZE + 1); +} + + + int IsClassInt (const type* T) /* Return true if this is an integer type */ { @@ -699,7 +721,7 @@ FuncDesc* GetFuncDesc (const type* T) CHECK (T[0] == T_FUNC); /* Decode the function descriptor and return it */ - return (FuncDesc*) DecodePtr (T+1); + return DecodePtr (T+1); } @@ -722,3 +744,23 @@ type* GetFuncReturn (type* T) +long GetElementCount (const type* T) +/* Get the element count of the array specified in T (which must be of + * array type). + */ +{ + CHECK (IsTypeArray (T)); + return (unsigned) Decode (T+1); +} + + + +type* GetElementType (type* T) +/* Return the element type of the given array type. */ +{ + CHECK (IsTypeArray (T)); + return T + DECODE_SIZE + 1; +} + + +