/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
typedef struct Collection Collection;
struct Collection {
- unsigned Count; /* Number of items in the list */
- unsigned Size; /* Size of allocated array */
+ unsigned Count; /* Number of items in the list */
+ unsigned Size; /* Size of allocated array */
CollEntry* Items; /* Array with dynamic size */
};
TOK_SCOPE, /* SCOPE keyword */
TOK_SEGMENT, /* SEGMENT keyword */
TOK_SIZE, /* SIZE keyword */
- TOK_SPAN, /* SPAN keyword */
+ TOK_SPAN, /* SPAN keyword */
TOK_START, /* START keyword */
TOK_STATIC, /* STATIC keyword */
TOK_STRUCT, /* STRUCT keyword */
Collection ModInfoById; /* Module infos sorted by id */
Collection ScopeInfoById; /* Scope infos sorted by id */
Collection SegInfoById; /* Segment infos sorted by id */
- Collection SpanInfoById; /* Span infos sorted by id */
+ Collection SpanInfoById; /* Span infos sorted by id */
Collection SymInfoById; /* Symbol infos sorted by id */
Collection TypeInfoById; /* Type infos sorted by id */
/* Collections with other sort criteria */
Collection CSymFuncByName; /* C functions sorted by name */
Collection FileInfoByName; /* File infos sorted by name */
- Collection ModInfoByName; /* Module info sorted by name */
+ Collection ModInfoByName; /* Module info sorted by name */
Collection ScopeInfoByName;/* Scope infos sorted by name */
Collection SegInfoByName; /* Segment infos sorted by name */
Collection SymInfoByName; /* Symbol infos sorted by name */
SymInfo* Info; /* Pointer to label symbol */
} Label;
CSymInfo* CSymFunc; /* C function for this scope */
- Collection SpanInfoList; /* List of spans for this scope */
+ Collection SpanInfoList; /* List of spans for this scope */
Collection SymInfoByName; /* Symbols in this scope */
Collection* CSymInfoByName; /* C symbols for this scope */
Collection* ChildScopeList; /* Child scopes of this scope */
cc65_addr Start; /* Start of span */
cc65_addr End; /* End of span */
union {
- unsigned Id; /* Id of segment */
- SegInfo* Info; /* Pointer to segment */
+ unsigned Id; /* Id of segment */
+ SegInfo* Info; /* Pointer to segment */
} Seg;
union {
unsigned Id; /* Id of type */
TypeInfo* Info; /* Pointer to type */
} Type;
- Collection* ScopeInfoList; /* Scopes for this span */
+ Collection* ScopeInfoList; /* Scopes for this span */
Collection* LineInfoList; /* Lines for this span */
};
/* Get the current size, use a minimum of 8 bytes */
unsigned NewAllocated = B->Allocated;
if (NewAllocated == 0) {
- NewAllocated = 8;
+ NewAllocated = 8;
}
/* Round up to the next power of two */
while (NewAllocated < NewSize) {
- NewAllocated *= 2;
+ NewAllocated *= 2;
}
/* Reallocate the buffer. Beware: The allocated size may be zero while the
/* Get the current size, use a minimum of 8 bytes */
unsigned NewAllocated = B->Allocated;
if (NewAllocated == 0) {
- NewAllocated = 8;
+ NewAllocated = 8;
}
/* Round up to the next power of two */
while (NewAllocated < NewSize) {
- NewAllocated *= 2;
+ NewAllocated *= 2;
}
/* Free the old buffer if there is one */
{
unsigned NewLen = B->Len + 1;
if (NewLen > B->Allocated) {
- SB_Realloc (B, NewLen);
+ SB_Realloc (B, NewLen);
}
B->Buf[B->Len] = '\0';
}
{
unsigned NewLen = B->Len + 1;
if (NewLen > B->Allocated) {
- SB_Realloc (B, NewLen);
+ SB_Realloc (B, NewLen);
}
B->Buf[B->Len] = (char) C;
B->Len = NewLen;
{
/* Accept NULL pointers */
if (C) {
- xfree (C->Items);
- xfree (C);
+ xfree (C->Items);
+ xfree (C);
}
}
/* Grow the array if necessary */
if (C->Count >= C->Size) {
- /* Must grow */
+ /* Must grow */
CollGrow (C, (C->Size == 0)? 1 : C->Size * 2);
}
/* Move the existing elements if needed */
if (C->Count != Index) {
- memmove (C->Items+Index+1, C->Items+Index, (C->Count-Index) * sizeof (void*));
+ memmove (C->Items+Index+1, C->Items+Index, (C->Count-Index) * sizeof (void*));
}
++C->Count;
}
static void CollQuickSort (Collection* C, int Lo, int Hi,
- int (*Compare) (const void*, const void*))
+ int (*Compare) (const void*, const void*))
/* Internal recursive sort function. */
{
/* Get a pointer to the items */
/* Quicksort */
while (Hi > Lo) {
- int I = Lo + 1;
- int J = Hi;
- while (I <= J) {
- while (I <= J && Compare (Items[Lo].Ptr, Items[I].Ptr) >= 0) {
- ++I;
- }
- while (I <= J && Compare (Items[Lo].Ptr, Items[J].Ptr) < 0) {
- --J;
- }
- if (I <= J) {
- /* Swap I and J */
- CollEntry Tmp = Items[I];
- Items[I] = Items[J];
- Items[J] = Tmp;
- ++I;
- --J;
- }
- }
- if (J != Lo) {
- /* Swap J and Lo */
- CollEntry Tmp = Items[J];
- Items[J] = Items[Lo];
- Items[Lo] = Tmp;
- }
- if (J > (Hi + Lo) / 2) {
- CollQuickSort (C, J + 1, Hi, Compare);
- Hi = J - 1;
- } else {
- CollQuickSort (C, Lo, J - 1, Compare);
- Lo = J + 1;
- }
+ int I = Lo + 1;
+ int J = Hi;
+ while (I <= J) {
+ while (I <= J && Compare (Items[Lo].Ptr, Items[I].Ptr) >= 0) {
+ ++I;
+ }
+ while (I <= J && Compare (Items[Lo].Ptr, Items[J].Ptr) < 0) {
+ --J;
+ }
+ if (I <= J) {
+ /* Swap I and J */
+ CollEntry Tmp = Items[I];
+ Items[I] = Items[J];
+ Items[J] = Tmp;
+ ++I;
+ --J;
+ }
+ }
+ if (J != Lo) {
+ /* Swap J and Lo */
+ CollEntry Tmp = Items[J];
+ Items[J] = Items[Lo];
+ Items[Lo] = Tmp;
+ }
+ if (J > (Hi + Lo) / 2) {
+ CollQuickSort (C, J + 1, Hi, Compare);
+ Hi = J - 1;
+ } else {
+ CollQuickSort (C, Lo, J - 1, Compare);
+ Lo = J + 1;
+ }
}
}
/* Return the value for a numeric digit. Return -1 if C is invalid */
{
if (isdigit (C)) {
- return C - '0';
+ return C - '0';
} else if (isxdigit (C)) {
- return toupper (C) - 'A' + 10;
+ return toupper (C) - 'A' + 10;
} else {
return -1;
}
{ "scope", TOK_SCOPE },
{ "seg", TOK_SEGMENT },
{ "size", TOK_SIZE },
- { "span", TOK_SPAN },
+ { "span", TOK_SPAN },
{ "start", TOK_START },
{ "static", TOK_STATIC },
{ "struct", TOK_STRUCT },
/* Skip whitespace */
while (D->C == ' ' || D->C == '\t' || D->C == '\r') {
- NextChar (D);
+ NextChar (D);
}
/* Remember the current position as start of the next token */
const struct KeywordEntry* Entry;
- /* Read the identifier */
+ /* Read the identifier */
SB_Clear (&D->SVal);
- while (D->C == '_' || isalnum (D->C)) {
+ while (D->C == '_' || isalnum (D->C)) {
SB_AppendChar (&D->SVal, D->C);
- NextChar (D);
- }
- SB_Terminate (&D->SVal);
+ NextChar (D);
+ }
+ SB_Terminate (&D->SVal);
/* Search the identifier in the keyword table */
Entry = bsearch (SB_GetConstBuf (&D->SVal),
} else {
D->Tok = Entry->Tok;
}
- return;
+ return;
}
/* Number? */
} else {
Base = 10;
}
- D->IVal = 0;
+ D->IVal = 0;
while ((Val = DigitVal (D->C)) >= 0 && Val < Base) {
- D->IVal = D->IVal * Base + Val;
- NextChar (D);
- }
- D->Tok = TOK_INTCON;
- return;
+ D->IVal = D->IVal * Base + Val;
+ NextChar (D);
+ }
+ D->Tok = TOK_INTCON;
+ return;
}
/* Other characters */
D->Tok = TOK_PLUS;
break;
- case ',':
- NextChar (D);
- D->Tok = TOK_COMMA;
- break;
+ case ',':
+ NextChar (D);
+ D->Tok = TOK_COMMA;
+ break;
- case '=':
- NextChar (D);
- D->Tok = TOK_EQUAL;
- break;
+ case '=':
+ NextChar (D);
+ D->Tok = TOK_EQUAL;
+ break;
case '\"':
SB_Clear (&D->SVal);
}
SB_Terminate (&D->SVal);
D->Tok = TOK_STRCON;
- break;
+ break;
case '\n':
NextChar (D);
break;
case EOF:
- D->Tok = TOK_EOF;
- break;
+ D->Tok = TOK_EOF;
+ break;
- default:
- ParseError (D, CC65_ERROR, "Invalid input character `%c'", D->C);
+ default:
+ ParseError (D, CC65_ERROR, "Invalid input character `%c'", D->C);
}
}
case TOK_FILE:
CollGrow (&D->Info->FileInfoById, D->IVal);
- CollGrow (&D->Info->FileInfoByName, D->IVal);
+ CollGrow (&D->Info->FileInfoByName, D->IVal);
break;
case TOK_LIBRARY:
case TOK_MODULE:
CollGrow (&D->Info->ModInfoById, D->IVal);
- CollGrow (&D->Info->ModInfoByName, D->IVal);
+ CollGrow (&D->Info->ModInfoByName, D->IVal);
break;
case TOK_SCOPE:
case TOK_SEGMENT:
CollGrow (&D->Info->SegInfoById, D->IVal);
- CollGrow (&D->Info->SegInfoByName, D->IVal);
+ CollGrow (&D->Info->SegInfoByName, D->IVal);
break;
case TOK_SPAN:
case TOK_SYM:
CollGrow (&D->Info->SymInfoById, D->IVal);
CollGrow (&D->Info->SymInfoByName, D->IVal);
- CollGrow (&D->Info->SymInfoByVal, D->IVal);
+ CollGrow (&D->Info->SymInfoByVal, D->IVal);
break;
case TOK_TYPE:
InfoBits |= ibLine;
break;
- case TOK_SPAN:
+ case TOK_SPAN:
while (1) {
if (!IntConstFollows (D)) {
goto ErrorExit;
StrBuf Name = STRBUF_INITIALIZER;
unsigned ModId = CC65_INV_ID;
unsigned ParentId = CC65_INV_ID;
- Collection SpanIds = COLLECTION_INITIALIZER;
+ Collection SpanIds = COLLECTION_INITIALIZER;
unsigned SymId = CC65_INV_ID;
ScopeInfo* S;
enum {
ibName = 0x004,
ibParentId = 0x008,
ibSize = 0x010,
- ibSpanId = 0x020,
+ ibSpanId = 0x020,
ibSymId = 0x040,
ibType = 0x080,
/* Something we know? */
if (D->Tok != TOK_ID && D->Tok != TOK_MODULE &&
D->Tok != TOK_NAME && D->Tok != TOK_PARENT &&
- D->Tok != TOK_SIZE && D->Tok != TOK_SPAN &&
- D->Tok != TOK_SYM && D->Tok != TOK_TYPE) {
+ D->Tok != TOK_SIZE && D->Tok != TOK_SPAN &&
+ D->Tok != TOK_SYM && D->Tok != TOK_TYPE) {
/* Try smart error recovery */
if (D->Tok == TOK_IDENT || TokenIsKeyword (D->Tok)) {
NextToken (D);
break;
- case TOK_SPAN:
+ case TOK_SPAN:
while (1) {
if (!IntConstFollows (D)) {
goto ErrorExit;
unsigned Id = 0;
cc65_addr Start = 0;
cc65_addr Size = 0;
- unsigned SegId = CC65_INV_ID;
+ unsigned SegId = CC65_INV_ID;
unsigned TypeId = CC65_INV_ID;
SpanInfo* S;
enum {
ibNone = 0x000,
ibId = 0x01,
- ibSegId = 0x02,
+ ibSegId = 0x02,
ibSize = 0x04,
ibStart = 0x08,
ibType = 0x10,
Token Tok;
/* Something we know? */
- if (D->Tok != TOK_ID && D->Tok != TOK_SEGMENT &&
- D->Tok != TOK_SIZE && D->Tok != TOK_START &&
+ if (D->Tok != TOK_ID && D->Tok != TOK_SEGMENT &&
+ D->Tok != TOK_SIZE && D->Tok != TOK_START &&
D->Tok != TOK_TYPE) {
/* Try smart error recovery */
CollAppend (&L->File.Info->LineInfoByLine, L);
}
- /* Resolve the spans ids */
+ /* Resolve the spans ids */
for (J = 0; J < CollCount (&L->SpanInfoList); ++J) {
/* Get the id of this span */
CollReplace (&L->SpanInfoList, SP, J);
/* Insert a backpointer into the span */
- if (SP->LineInfoList == 0) {
- SP->LineInfoList = CollNew ();
- }
+ if (SP->LineInfoList == 0) {
+ SP->LineInfoList = CollNew ();
+ }
CollAppend (SP->LineInfoList, L);
}
}
}
/* Resolve the library */
- if (M->Lib.Id == CC65_INV_ID) {
+ if (M->Lib.Id == CC65_INV_ID) {
M->Lib.Info = 0;
} else if (M->Lib.Id >= CollCount (&D->Info->LibInfoById)) {
ParseError (D,
S->Label.Info = CollAt (&D->Info->SymInfoById, S->Label.Id);
}
- /* Resolve the spans ids */
+ /* Resolve the spans ids */
for (J = 0; J < CollCount (&S->SpanInfoList); ++J) {
/* Get the id of this span */
CollReplace (&S->SpanInfoList, SP, J);
/* Insert a backpointer into the span */
- if (SP->ScopeInfoList == 0) {
- SP->ScopeInfoList = CollNew ();
- }
+ if (SP->ScopeInfoList == 0) {
+ SP->ScopeInfoList = CollNew ();
+ }
CollAppend (SP->ScopeInfoList, S);
}
}
ParseSegment (&D);
break;
- case TOK_SPAN:
- ParseSpan (&D);
- break;
+ case TOK_SPAN:
+ ParseSpan (&D);
+ break;
case TOK_SYM:
ParseSym (&D);