]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/gm2-compiler/M2LexBuf.def
Merge modula-2 front end onto gcc.
[thirdparty/gcc.git] / gcc / m2 / gm2-compiler / M2LexBuf.def
1 (* M2LexBuf.def provides a buffer for m2.lex.
2
3 Copyright (C) 2001-2022 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
21
22 DEFINITION MODULE M2LexBuf ;
23
24 (*
25 Title : M2LexBuf
26 Author : Gaius Mulley
27 System : UNIX (GNU Modula-2)
28 Date : Fri Jul 27 12:42:13 2001
29 Description: provides a buffer for the all the tokens created by m2.lex.
30 *)
31
32 FROM SYSTEM IMPORT ADDRESS ;
33 FROM M2Reserved IMPORT toktype ;
34 FROM DynamicStrings IMPORT String ;
35 FROM m2linemap IMPORT location_t ;
36 FROM NameKey IMPORT Name ;
37
38 EXPORT QUALIFIED OpenSource, CloseSource, ReInitialize, GetToken, InsertToken,
39 InsertTokenAndRewind, GetPreviousTokenLineNo, GetLineNo,
40 GetColumnNo, GetTokenNo, TokenToLineNo, TokenToColumnNo,
41 TokenToLocation, GetTokenName,
42 FindFileNameFromToken, GetFileName,
43 ResetForNewPass,
44 currenttoken, currentstring, currentinteger,
45 AddTok, AddTokCharStar, AddTokInteger, MakeVirtualTok,
46 SetFile, PushFile, PopFile,
47 PrintTokenNo, DisplayToken, DumpTokens,
48 BuiltinTokenNo, UnknownTokenNo ;
49
50 CONST
51 UnknownTokenNo = 0 ;
52 BuiltinTokenNo = 1 ;
53
54 VAR
55 currenttoken : toktype ;
56 currentstring : ADDRESS ;
57 currentcolumn : CARDINAL ;
58 currentinteger: INTEGER ;
59
60
61 (*
62 OpenSource - Attempts to open the source file, s.
63 The success of the operation is returned.
64 *)
65
66 PROCEDURE OpenSource (s: String) : BOOLEAN ;
67
68
69 (*
70 CloseSource - closes the current open file.
71 *)
72
73 PROCEDURE CloseSource ;
74
75
76 (*
77 ReInitialize - re-initialize the all the data structures.
78 *)
79
80 PROCEDURE ReInitialize ;
81
82
83 (*
84 ResetForNewPass - reset the buffer pointers to the beginning ready for
85 a new pass
86 *)
87
88 PROCEDURE ResetForNewPass ;
89
90
91 (*
92 GetToken - gets the next token into currenttoken.
93 *)
94
95 PROCEDURE GetToken ;
96
97
98 (*
99 InsertToken - inserts a symbol, token, infront of the current token
100 ready for the next pass.
101 *)
102
103 PROCEDURE InsertToken (token: toktype) ;
104
105
106 (*
107 InsertTokenAndRewind - inserts a symbol, token, infront of the current token
108 and then moves the token stream back onto the inserted token.
109 *)
110
111 PROCEDURE InsertTokenAndRewind (token: toktype) ;
112
113
114 (*
115 GetPreviousTokenLineNo - returns the line number of the previous token.
116 *)
117
118 PROCEDURE GetPreviousTokenLineNo () : CARDINAL ;
119
120
121 (*
122 GetLineNo - returns the current line number where the symbol occurs in
123 the source file.
124 *)
125
126 PROCEDURE GetLineNo () : CARDINAL ;
127
128
129 (*
130 GetTokenNo - returns the current token number.
131 *)
132
133 PROCEDURE GetTokenNo () : CARDINAL ;
134
135
136 (*
137 GetTokenName - returns the token name given the tokenno.
138 *)
139
140 PROCEDURE GetTokenName (tokenno: CARDINAL) : Name ;
141
142
143 (*
144 TokenToLineNo - returns the line number of the current file for the
145 TokenNo. The depth refers to the include depth.
146 A depth of 0 is the current file, depth of 1 is the file
147 which included the current file. Zero is returned if the
148 depth exceeds the file nesting level.
149 *)
150
151 PROCEDURE TokenToLineNo (TokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ;
152
153
154 (*
155 GetColumnNo - returns the current column where the symbol occurs in
156 the source file.
157 *)
158
159 PROCEDURE GetColumnNo () : CARDINAL ;
160
161
162 (*
163 TokenToColumnNo - returns the column number of the current file for the
164 TokenNo. The depth refers to the include depth.
165 A depth of 0 is the current file, depth of 1 is the file
166 which included the current file. Zero is returned if the
167 depth exceeds the file nesting level.
168 *)
169
170 PROCEDURE TokenToColumnNo (TokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ;
171
172
173 (*
174 TokenToLocation - returns the location_t corresponding to, TokenNo.
175 *)
176
177 PROCEDURE TokenToLocation (TokenNo: CARDINAL) : location_t ;
178
179
180 (*
181 FindFileNameFromToken - returns the complete FileName for the appropriate
182 source file yields the token number, TokenNo.
183 The, Depth, indicates the include level: 0..n
184 Level 0 is the current. NIL is returned if n+1
185 is requested.
186 *)
187
188 PROCEDURE FindFileNameFromToken (TokenNo: CARDINAL; depth: CARDINAL) : String ;
189
190
191 (*
192 GetFileName - returns a String defining the current file.
193 *)
194
195 PROCEDURE GetFileName () : String ;
196
197
198 (*
199 MakeVirtualTok - creates and return a new tokenno which is created from
200 tokenno range1 and range2.
201 *)
202
203 PROCEDURE MakeVirtualTok (caret, left, right: CARDINAL) : CARDINAL ;
204
205
206 (* ***********************************************************************
207 *
208 * These functions allow m2.lex to deliver tokens into the buffer
209 *
210 ************************************************************************* *)
211
212 (*
213 AddTok - adds a token to the buffer.
214 *)
215
216 PROCEDURE AddTok (t: toktype) ;
217
218
219 (*
220 AddTokCharStar - adds a token to the buffer and an additional string, s.
221 A copy of string, s, is made.
222 *)
223
224 PROCEDURE AddTokCharStar (t: toktype; s: ADDRESS) ;
225
226
227 (*
228 AddTokInteger - adds a token and an integer to the buffer.
229 *)
230
231 PROCEDURE AddTokInteger (t: toktype; i: INTEGER) ;
232
233
234 (*
235 SetFile - sets the current filename to, filename.
236 *)
237
238 PROCEDURE SetFile (filename: ADDRESS) ;
239
240
241 (*
242 PushFile - indicates that, filename, has just been included.
243 *)
244
245 PROCEDURE PushFile (filename: ADDRESS) ;
246
247
248 (*
249 PopFile - indicates that we are returning to, filename, having finished
250 an include.
251 *)
252
253 PROCEDURE PopFile (filename: ADDRESS) ;
254
255
256 (*
257 PrintTokenNo - displays token and the location of the token.
258 *)
259
260 PROCEDURE PrintTokenNo (tokenno: CARDINAL) ;
261
262
263 (*
264 DisplayToken - display the token name using printf0 no newline is emitted.
265 *)
266
267 PROCEDURE DisplayToken (tok: toktype) ;
268
269
270 (*
271 DumpTokens - developer debugging aid.
272 *)
273
274 PROCEDURE DumpTokens ;
275
276
277 END M2LexBuf.