SymInfo* Info; /* Pointer to label symbol */
} Label;
Collection SpanInfoList; /* List of spans for this scope */
- Collection* ChildScopes; /* Child scopes of this scope */
+ Collection SymInfoByName; /* Symbols in this scope */
+ Collection* ChildScopeList; /* Child scopes of this scope */
char Name[1]; /* Name of scope */
};
/* Initialize the fields as necessary */
CollInit (&S->SpanInfoList);
- S->ChildScopes = 0;
+ CollInit (&S->SymInfoByName);
+ S->ChildScopeList = 0;
memcpy (S->Name, SB_GetConstBuf (Name), SB_GetLen (Name) + 1);
/* Return it */
/* Free a ScopeInfo struct */
{
CollDone (&S->SpanInfoList);
- CollFree (S->ChildScopes);
+ CollDone (&S->SymInfoByName);
+ CollFree (S->ChildScopeList);
xfree (S);
}
S->Parent.Info = CollAt (&D->Info->ScopeInfoById, S->Parent.Id);
/* Set a backpointer in the parent */
- if (S->Parent.Info->ChildScopes == 0) {
- S->Parent.Info->ChildScopes = CollNew ();
+ if (S->Parent.Info->ChildScopeList == 0) {
+ S->Parent.Info->ChildScopeList = CollNew ();
}
- CollAppend (S->Parent.Info->ChildScopes, S);
+ CollAppend (S->Parent.Info->ChildScopeList, S);
}
/* Resolve the label */
S->Scope.Info = 0;
} else {
S->Scope.Info = CollAt (&D->Info->ScopeInfoById, S->Scope.Id);
+
+ /* Place a backpointer to the symbol in the scope */
+ CollAppend (&S->Scope.Info->SymInfoByName, S);
}
/* Resolve the parent */
}
}
+ /* Walk over the scopes and sort the symbols in the scope by name */
+ for (I = 0; I < CollCount (&D->Info->ScopeInfoById); ++I) {
+
+ /* Get the scope info */
+ ScopeInfo* S = CollAt (&D->Info->ScopeInfoById, I);
+
+ /* Sort the symbols in this scope by name */
+ CollSort (&S->SymInfoByName, CompareSymInfoByName);
+ }
+
/* Sort the symbol infos */
CollSort (&D->Info->SymInfoByName, CompareSymInfoByName);
CollSort (&D->Info->SymInfoByVal, CompareSymInfoByVal);
+const cc65_symbolinfo* cc65_symbol_byscope (cc65_dbginfo Handle, unsigned ScopeId)
+/* Return a list of symbols in the given scope. This includes cheap local
+ * symbols, but not symbols in subscopes. The function returns NULL if the
+ * scope id is invalid (no such scope) and otherwise a - possibly empty -
+ * symbol list.
+ */
+{
+ DbgInfo* Info;
+ cc65_symbolinfo* D;
+ ScopeInfo* S;
+ unsigned I;
+
+
+ /* Check the parameter */
+ assert (Handle != 0);
+
+ /* The handle is actually a pointer to a debug info struct */
+ Info = (DbgInfo*) Handle;
+
+ /* Check if the id is valid */
+ if (ScopeId >= CollCount (&Info->ScopeInfoById)) {
+ return 0;
+ }
+
+ /* Get the scope */
+ S = CollAt (&Info->ScopeInfoById, ScopeId);
+
+ /* Allocate memory for the data structure returned to the caller */
+ D = new_cc65_symbolinfo (CollCount (&S->SymInfoByName));
+
+ /* Fill in the data */
+ for (I = 0; I < CollCount (&S->SymInfoByName); ++I) {
+ /* Copy the data */
+ CopySymInfo (D->data + I, CollConstAt (&S->SymInfoByName, I));
+ }
+
+ /* Return the result */
+ return D;
+}
+
+
+
const cc65_symbolinfo* cc65_symbol_inrange (cc65_dbginfo Handle, cc65_addr Start,
cc65_addr End)
/* Return a list of labels in the given range. End is inclusive. The function
S = CollAt (&Info->ScopeInfoById, Id);
/* Allocate memory for the data structure returned to the caller */
- D = new_cc65_scopeinfo (S->ChildScopes? CollCount (S->ChildScopes) : 0);
+ D = new_cc65_scopeinfo (S->ChildScopeList? CollCount (S->ChildScopeList) : 0);
/* Fill in the data */
for (I = 0; I < D->count; ++I) {
- CopyScopeInfo (D->data + I, CollConstAt (S->ChildScopes, I));
+ CopyScopeInfo (D->data + I, CollConstAt (S->ChildScopeList, I));
}
/* Return the result */