]> git.sur5r.net Git - cc65/blob - src/ld65/lineinfo.h
54e40861ca250bc61d0cd946394f4eb3e729be9b
[cc65] / src / ld65 / lineinfo.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                lineinfo.h                                 */
4 /*                                                                           */
5 /*                      Source file line info structure                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001-2011, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef LINEINFO_H
37 #define LINEINFO_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "coll.h"
45 #include "filepos.h"
46
47 /* ld65 */
48 #include "span.h"
49 #include "spool.h"
50
51
52
53 /*****************************************************************************/
54 /*                                 Forwards                                  */
55 /*****************************************************************************/
56
57
58
59 struct ObjData;
60 struct Segment;
61
62
63
64 /*****************************************************************************/
65 /*                                   Data                                    */
66 /*****************************************************************************/
67
68
69
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.
73  */
74 typedef struct LineInfo LineInfo;
75 struct 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          Spans;          /* Spans for this line */
80 };
81
82
83
84 /*****************************************************************************/
85 /*                                   Code                                    */
86 /*****************************************************************************/
87
88
89
90 LineInfo* GenLineInfo (const FilePos* Pos);
91 /* Generate a new (internally used) line info with the given information */
92
93 LineInfo* ReadLineInfo (FILE* F, struct ObjData* O);
94 /* Read a line info from a file and return it */
95
96 void FreeLineInfo (LineInfo* LI);
97 /* Free a LineInfo structure. */
98
99 void ReadLineInfoList (FILE* F, struct ObjData* O, Collection* LineInfos);
100 /* Read a list of line infos stored as a list of indices in the object file,
101  * make real line infos from them and place them into the passed collection.
102  */
103
104 #if defined(HAVE_INLINE)
105 INLINE const FilePos* GetSourcePos (const LineInfo* LI)
106 /* Return the source file position from the given line info */
107 {
108     return &LI->Pos;
109 }
110 #else
111 #  define GetSourcePos(LI)      (&(LI)->Pos)
112 #endif
113
114 #if defined(HAVE_INLINE)
115 INLINE const char* GetSourceName (const LineInfo* LI)
116 /* Return the name of a source file from the given line info */
117 {
118     return GetString (LI->Pos.Name);
119 }
120 #else
121 #  define GetSourceName(LI)     (GetString ((LI)->Pos.Name))
122 #endif
123
124 #if defined(HAVE_INLINE)
125 INLINE unsigned long GetSourceLine (const LineInfo* LI)
126 /* Return the source file line from the given line info */
127 {
128     return LI->Pos.Line;
129 }
130 #else
131 #  define GetSourceLine(LI)     ((LI)->Pos.Line)
132 #endif
133
134 #if defined(HAVE_INLINE)
135 INLINE unsigned GetSourceCol (const LineInfo* LI)
136 /* Return the source file column from the given line info */
137 {
138     return LI->Pos.Col;
139 }
140 #else
141 #  define GetSourceCol(LI)      ((LI)->Pos.Col)
142 #endif
143
144 #if defined(HAVE_INLINE)
145 INLINE const char* GetSourceNameFromList (const Collection* LineInfos)
146 /* Return the name of a source file from a list of line infos */
147 {
148     /* The relevant entry is in slot zero */
149     return GetSourceName (CollConstAt (LineInfos, 0));
150 }
151 #else
152 #  define GetSourceNameFromList(LineInfos)      \
153         GetSourceName ((const LineInfo*) CollConstAt ((LineInfos), 0))
154 #endif
155
156 #if defined(HAVE_INLINE)
157 INLINE unsigned long GetSourceLineFromList (const Collection* LineInfos)
158 /* Return the source file line from a list of line infos */
159 {
160     /* The relevant entry is in slot zero */
161     return GetSourceLine (CollConstAt (LineInfos, 0));
162 }
163 #else
164 #  define GetSourceLineFromList(LineInfos)      \
165         GetSourceLine ((const LineInfo*) CollConstAt ((LineInfos), 0))
166 #endif
167
168 void PrintDbgLineInfo (FILE* F);
169 /* Output the line infos to a debug info file */
170
171
172
173 /* End of lineinfo.h */
174 #endif
175
176
177