1 /*****************************************************************************/
5 /* Source file line info structure */
9 /* (C) 2001-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
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 /*****************************************************************************/
53 /*****************************************************************************/
55 /*****************************************************************************/
64 /*****************************************************************************/
66 /*****************************************************************************/
70 /* Structure holding line information. The Pos.Name field is always the
71 * global string id of the file name. If the line info was read from the
72 * object file, the File pointer is valid, otherwise it is NULL.
74 typedef struct LineInfo LineInfo;
76 struct FileInfo* File; /* File struct for this line if any */
77 unsigned Type; /* Type of line info */
78 FilePos Pos; /* Position in file */
79 Collection Fragments; /* Fragments for this line */
80 Collection Spans; /* Spans for this line */
85 /*****************************************************************************/
87 /*****************************************************************************/
91 LineInfo* GenLineInfo (const FilePos* Pos);
92 /* Generate a new (internally used) line info with the given information */
94 LineInfo* ReadLineInfo (FILE* F, struct ObjData* O);
95 /* Read a line info from a file and return it */
97 void FreeLineInfo (LineInfo* LI);
98 /* Free a LineInfo structure. This function will not handle a non empty
99 * Fragments collection, it can only be used to free incomplete line infos.
102 void ReadLineInfoList (FILE* F, struct ObjData* O, Collection* LineInfos);
103 /* Read a list of line infos stored as a list of indices in the object file,
104 * make real line infos from them and place them into the passed collection.
107 void RelocLineInfo (struct Segment* S);
108 /* Relocate the line info for a segment. */
110 #if defined(HAVE_INLINE)
111 INLINE const FilePos* GetSourcePos (const LineInfo* LI)
112 /* Return the source file position from the given line info */
117 # define GetSourcePos(LI) (&(LI)->Pos)
120 #if defined(HAVE_INLINE)
121 INLINE const char* GetSourceName (const LineInfo* LI)
122 /* Return the name of a source file from the given line info */
124 return GetString (LI->Pos.Name);
127 # define GetSourceName(LI) (GetString ((LI)->Pos.Name))
130 #if defined(HAVE_INLINE)
131 INLINE unsigned long GetSourceLine (const LineInfo* LI)
132 /* Return the source file line from the given line info */
137 # define GetSourceLine(LI) ((LI)->Pos.Line)
140 #if defined(HAVE_INLINE)
141 INLINE unsigned GetSourceCol (const LineInfo* LI)
142 /* Return the source file column from the given line info */
147 # define GetSourceCol(LI) ((LI)->Pos.Col)
150 #if defined(HAVE_INLINE)
151 INLINE const char* GetSourceNameFromList (const Collection* LineInfos)
152 /* Return the name of a source file from a list of line infos */
154 /* The relevant entry is in slot zero */
155 return GetSourceName (CollConstAt (LineInfos, 0));
158 # define GetSourceNameFromList(LineInfos) \
159 GetSourceName ((const LineInfo*) CollConstAt ((LineInfos), 0))
162 #if defined(HAVE_INLINE)
163 INLINE unsigned long GetSourceLineFromList (const Collection* LineInfos)
164 /* Return the source file line from a list of line infos */
166 /* The relevant entry is in slot zero */
167 return GetSourceLine (CollConstAt (LineInfos, 0));
170 # define GetSourceLineFromList(LineInfos) \
171 GetSourceLine ((const LineInfo*) CollConstAt ((LineInfos), 0))
176 /* End of lineinfo.h */