Merge pull request #1968 from mseabold/master
Allow line_bynumber to return more than one result
This commit is contained in:
@@ -4736,14 +4736,18 @@ static SpanInfoListEntry* FindSpanInfoByAddr (const SpanInfoList* L, cc65_addr A
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static LineInfo* FindLineInfoByLine (const Collection* LineInfos, cc65_line Line)
|
static int FindLineInfoByLine (const Collection* LineInfos, cc65_line Line,
|
||||||
/* Find the LineInfo for a given line number. The function returns the line
|
unsigned *Index)
|
||||||
** info or NULL if none was found.
|
/* Find the LineInfo for a given line number. The function returns true if the
|
||||||
|
** name was found. In this case, Index contains the index of the first item
|
||||||
|
** that matches. If the item wasn't found, the function returns false and
|
||||||
|
** Index contains the insert position for Name.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Do a binary search */
|
/* Do a binary search */
|
||||||
int Lo = 0;
|
int Lo = 0;
|
||||||
int Hi = (int) CollCount (LineInfos) - 1;
|
int Hi = (int) CollCount (LineInfos) - 1;
|
||||||
|
int Found = 0;
|
||||||
while (Lo <= Hi) {
|
while (Lo <= Hi) {
|
||||||
|
|
||||||
/* Mid of range */
|
/* Mid of range */
|
||||||
@@ -4755,16 +4759,20 @@ static LineInfo* FindLineInfoByLine (const Collection* LineInfos, cc65_line Line
|
|||||||
/* Found? */
|
/* Found? */
|
||||||
if (Line > CurItem->Line) {
|
if (Line > CurItem->Line) {
|
||||||
Lo = Cur + 1;
|
Lo = Cur + 1;
|
||||||
} else if (Line < CurItem->Line) {
|
|
||||||
Hi = Cur - 1;
|
|
||||||
} else {
|
} else {
|
||||||
/* Found */
|
Hi = Cur - 1;
|
||||||
return CurItem;
|
/* Since we may have duplicates, repeat the search until we've
|
||||||
|
** the first item that has a match.
|
||||||
|
*/
|
||||||
|
if(Line == CurItem->Line) {
|
||||||
|
Found = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not found */
|
/* Pass back the index. This is also the insert position */
|
||||||
return 0;
|
*Index = Lo;
|
||||||
|
return Found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -6127,13 +6135,17 @@ const cc65_lineinfo* cc65_line_byid (cc65_dbginfo Handle, unsigned Id)
|
|||||||
const cc65_lineinfo* cc65_line_bynumber (cc65_dbginfo Handle, unsigned FileId,
|
const cc65_lineinfo* cc65_line_bynumber (cc65_dbginfo Handle, unsigned FileId,
|
||||||
cc65_line Line)
|
cc65_line Line)
|
||||||
/* Return line information for a source file/line number combination. The
|
/* Return line information for a source file/line number combination. The
|
||||||
** function returns NULL if no line information was found.
|
** function returns NULL if no line information was found, otherwise a list
|
||||||
|
** of line infos.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
const DbgInfo* Info;
|
const DbgInfo* Info;
|
||||||
const FileInfo* F;
|
const FileInfo* F;
|
||||||
cc65_lineinfo* D;
|
cc65_lineinfo* D;
|
||||||
LineInfo* L = 0;
|
LineInfo* L = 0;
|
||||||
|
unsigned I;
|
||||||
|
unsigned Index;
|
||||||
|
unsigned Count;
|
||||||
|
|
||||||
/* Check the parameter */
|
/* Check the parameter */
|
||||||
assert (Handle != 0);
|
assert (Handle != 0);
|
||||||
@@ -6150,18 +6162,31 @@ const cc65_lineinfo* cc65_line_bynumber (cc65_dbginfo Handle, unsigned FileId,
|
|||||||
F = CollAt (&Info->FileInfoById, FileId);
|
F = CollAt (&Info->FileInfoById, FileId);
|
||||||
|
|
||||||
/* Search in the file for the given line */
|
/* Search in the file for the given line */
|
||||||
L = FindLineInfoByLine (&F->LineInfoByLine, Line);
|
if(!FindLineInfoByLine (&F->LineInfoByLine, Line, &Index)) {
|
||||||
|
/* Not found */
|
||||||
/* Bail out if we didn't find the line */
|
|
||||||
if (L == 0) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Index contains the first position. Count how many lines with this number
|
||||||
|
** we have. Skip the first one, since we have at least one.
|
||||||
|
*/
|
||||||
|
Count = 1;
|
||||||
|
|
||||||
|
while ((unsigned) Index + Count < CollCount( &F->LineInfoByLine)) {
|
||||||
|
L = CollAt (&F->LineInfoByLine, (unsigned) Index + Count);
|
||||||
|
if (L->Line != Line) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++Count;
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare the struct we will return to the caller */
|
/* Prepare the struct we will return to the caller */
|
||||||
D = new_cc65_lineinfo (1);
|
D = new_cc65_lineinfo (Count);
|
||||||
|
|
||||||
/* Copy the data */
|
/* Copy the data */
|
||||||
CopyLineInfo (D->data, L);
|
for (I = 0; I < Count; ++I) {
|
||||||
|
CopyLineInfo (D->data + I, CollAt (&F->LineInfoByLine, Index++));
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the allocated struct */
|
/* Return the allocated struct */
|
||||||
return D;
|
return D;
|
||||||
|
|||||||
@@ -258,7 +258,8 @@ const cc65_lineinfo* cc65_line_bynumber (cc65_dbginfo handle,
|
|||||||
unsigned source_id,
|
unsigned source_id,
|
||||||
cc65_line line);
|
cc65_line line);
|
||||||
/* Return line information for a source file/line number combination. The
|
/* Return line information for a source file/line number combination. The
|
||||||
** function returns NULL if no line information was found.
|
** function returns NULL if no line information was found, otherwise a list
|
||||||
|
** of line infos.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const cc65_lineinfo* cc65_line_bysource (cc65_dbginfo Handle, unsigned source_id);
|
const cc65_lineinfo* cc65_line_bysource (cc65_dbginfo Handle, unsigned source_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user