1 /*****************************************************************************/
5 /* Source file line info structure */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
36 /* Note: The line infos kept here are additional line infos supplied by the
37 * ".dbg line" command. The native line infos are always kept in the fragments
38 * itself (because one fragment always originates from one line). The
39 * additional line infos (which may not exist if none are supplied in the
40 * source) may have several fragments attached (as is the case with sources
41 * generated by the C compiler).
55 /*****************************************************************************/
57 /*****************************************************************************/
61 /* Linked list of all line infos */
62 LineInfo* LineInfoRoot = 0;
63 LineInfo* LineInfoLast = 0;
64 unsigned LineInfoCount = 0;
65 unsigned LineInfoValid = 0; /* Valid, that is, used entries */
67 /* Static pointer to last line info or NULL if not active */
68 LineInfo* CurLineInfo = 0;
72 /*****************************************************************************/
74 /*****************************************************************************/
78 static LineInfo* NewLineInfo (unsigned FileIndex, unsigned long LineNum)
79 /* Create and return a new line info. Usage will be zero. */
82 LineInfo* LI = xmalloc (sizeof (LineInfo));
84 /* Initialize the fields */
87 LI->Index = 0; /* Currently invalid */
88 LI->Pos.Line = LineNum;
90 LI->Pos.Name = FileIndex;
92 /* Insert this structure into the line info list */
93 if (LineInfoLast == 0) {
96 LineInfoLast->Next = LI;
100 /* Count the line infos */
103 /* Return the new struct */
109 LineInfo* UseLineInfo (LineInfo* LI)
110 /* Increase the reference count of the given line info and return it. The
111 * function will gracefully accept NULL pointers and do nothing in this case.
122 void GenLineInfo (unsigned FileIndex, unsigned long LineNum)
123 /* Generate a new line info */
125 /* Create a new line info and make it current */
126 CurLineInfo = NewLineInfo (FileIndex, LineNum);
131 void MakeLineInfoIndex (void)
132 /* Walk over the line info list and make an index of all entries ignoring
133 * those with a usage count of zero.
136 LineInfo* LI = LineInfoRoot;
140 LI->Index = LineInfoValid++;