1 /*****************************************************************************/
5 /* Source file line info structure */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 /*****************************************************************************/
50 /*****************************************************************************/
52 /*****************************************************************************/
56 /* Global pointer to line information for the current line */
57 static LineInfo* CurLineInfo = 0;
61 /*****************************************************************************/
63 /*****************************************************************************/
67 static LineInfo* NewLineInfo (struct IFile* F, unsigned LineNum, const char* Line)
68 /* Create and return a new line info. Ref count will be 1. */
74 /* Skip leading spaces in Line */
75 while (IsBlank (*Line)) {
79 /* Calculate the length of the line */
83 LI = xmalloc (sizeof (LineInfo) + Len);
85 /* Initialize the fields */
88 LI->LineNum = LineNum;
89 memcpy (LI->Line, Line, Len+1);
91 /* Replace tabs by spaces in the given line since tabs will give rather
92 * arbitrary results when used in the output later, and if we do it here,
93 * we won't need another copy.
103 /* Return the new struct */
109 static void FreeLineInfo (LineInfo* LI)
110 /* Free a LineInfo structure */
117 LineInfo* UseLineInfo (LineInfo* LI)
118 /* Increase the reference count of the given line info and return it. */
127 void ReleaseLineInfo (LineInfo* LI)
128 /* Release a reference to the given line info, free the structure if the
129 * reference count drops to zero.
132 CHECK (LI && LI->RefCount > 0);
133 if (--LI->RefCount == 0) {
134 /* No more references, free it */
141 LineInfo* GetCurLineInfo (void)
142 /* Return a pointer to the current line info. The reference count is NOT
143 * increased, use UseLineInfo for that purpose.
151 void UpdateLineInfo (struct IFile* F, unsigned LineNum, const char* Line)
152 /* Update the line info - called if a new line is read */
154 /* If a current line info exists, release it */
156 ReleaseLineInfo (CurLineInfo);
159 /* If we have intermixed assembly switched off, use an empty line instead
160 * of the supplied one to save some memory.
166 /* Create a new line info */
167 CurLineInfo = NewLineInfo (F, LineNum, Line);
172 const char* GetInputName (const LineInfo* LI)
173 /* Return the file name from a line info */
175 PRECONDITION (LI != 0);
176 return LI->InputFile->Name;
181 unsigned GetInputLine (const LineInfo* LI)
182 /* Return the line number from a line info */
184 PRECONDITION (LI != 0);