Debian Codegraph @

gcc/m2/gm2-compiler/CLexBuf.def

raw
1 (* CLexBuf.def provides a lexical buffer for clex.
2
3 Copyright (C) 2003-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
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 CLexBuf ;
23
24 (*
25 Title : CLexBuf
26 Author : Gaius Mulley
27 System : GNU Modula-2
28 Date : Thu Jan 23 12:32:36 2003
29 Revision : $Version$
30 Description: provides a lexical buffer for clex.
31 *)
32
33 FROM SYSTEM IMPORT ADDRESS ;
34 FROM DynamicStrings IMPORT String ;
35 FROM NameKey IMPORT Name ;
36 EXPORT QUALIFIED toktype,
37 IsMacroDefined, NoArgs, DefineMacro, UnDefineMacro,
38 OpenSource, CloseSource, ReInitialize, GetToken, InsertToken,
39 InsertTokenAndRewind, GetLineNo,
40 GetTokenNo, TokenToLineNo, FindFileNameFromToken, GetFileName,
41 ResetForNewPass,
42 currenttoken, currentstring, currentinteger,
43 EnableMacroSubstitutions,
44 AddTok, AddTokCharStar, AddTokInteger,
45 SetFile, PushFile, PopFile, FlushTokens ;
46
47 TYPE
48 toktype = (eoftok, startok, arrowtok, structtok, lsbratok, rsbratok,
49 lcbratok, rcbratok, lparatok, rparatok, semicolontok,
50 longtok, inttok, chartok, enumtok, typedeftok,
51 floattok, doubletok, unsignedtok, consttok,
52 periodperiodperiodtok,
53 integertok, hexintegertok, octintegertok,
54 identtok, realtok, conststringtok, constchartok, codetok,
55 starthashtok, endhashtok, definetok, undeftok, iftok, elsetok,
56 endiftok, ifdeftok, ifndeftok, includetok,
57 nottok, commatok,
58 periodtok,
59 gretok, lesstok, ortok, andtok, bartok, ambersandtok,
60 shiftlefttok, shiftrighttok, divtok, modtok,
61 sizeoftok, definedtok, hattok, equaltok, notequaltok,
62 greequaltok, lessequaltok, plustok, minustok, tildetok,
63 externtok, statictok, autotok, registertok,
64 voidtok, shorttok, signedtok, uniontok, colontok, becomestok,
65 volatiletok, typetok) ;
66
67 VAR
68 currenttoken : toktype ;
69 currentstring : ADDRESS ;
70 currentinteger: INTEGER ;
71
72
73 (*
74 EnableMacroSubstitutions -
75 *)
76
77 PROCEDURE EnableMacroSubstitutions (b: BOOLEAN) ;
78
79
80 (*
81 IsMacroDefined - returns TRUE if macro, n, was defined.
82 *)
83
84 PROCEDURE IsMacroDefined (n: Name) : BOOLEAN ;
85
86
87 (*
88 NoArgs - returns the number of arguments for macro, n.
89 -1 if the macro does not exist
90 *)
91
92 PROCEDURE NoArgs (n: Name) : INTEGER ;
93
94
95 (*
96 DefineMacro - defines macro, n, as defined to start at token, t.
97 *)
98
99 PROCEDURE DefineMacro (n: Name; t: CARDINAL) ;
100
101
102 (*
103 UnDefineMacro -
104 *)
105
106 PROCEDURE UnDefineMacro (n: Name) ;
107
108
109 (*
110 OpenSource - Attempts to open the source file, s.
111 The success of the operation is returned.
112 *)
113
114 PROCEDURE OpenSource (s: String) : BOOLEAN ;
115
116
117 (*
118 CloseSource - closes the current open file.
119 *)
120
121 PROCEDURE CloseSource ;
122
123
124 (*
125 ReInitialize - re-initialize the all the data structures.
126 *)
127
128 PROCEDURE ReInitialize ;
129
130
131 (*
132 ResetForNewPass - reset the buffer pointers to the beginning ready for
133 a new pass
134 *)
135
136 PROCEDURE ResetForNewPass ;
137
138
139 (*
140 GetToken - gets the next token into currenttoken.
141 *)
142
143 PROCEDURE GetToken ;
144
145
146 (*
147 InsertToken - inserts a symbol, token, infront of the current token
148 ready for the next pass.
149 *)
150
151 PROCEDURE InsertToken (token: toktype) ;
152
153
154 (*
155 InsertTokenAndRewind - inserts a symbol, token, infront of the current token
156 and then moves the token stream back onto the inserted token.
157 *)
158
159 PROCEDURE InsertTokenAndRewind (token: toktype) ;
160
161
162 (*
163 GetLineNo - returns the current line number where the symbol occurs in
164 the source file.
165 *)
166
167 PROCEDURE GetLineNo () : CARDINAL ;
168
169
170 (*
171 GetTokenNo - returns the number of tokens read from
172 the source file by the lexical analaysis.
173 *)
174
175 PROCEDURE GetTokenNo () : CARDINAL ;
176
177
178 (*
179 TokenToLineNo - returns the line number of the current file for the
180 TokenNo. The depth refers to the include depth.
181 A depth of 0 is the current file, depth of 1 is the file
182 which included the current file. Zero is returned if the
183 depth exceeds the file nesting level.
184 *)
185
186 PROCEDURE TokenToLineNo (TokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ;
187
188
189 (*
190 FindFileNameFromToken - returns the complete FileName for the appropriate
191 source file yields the token number, TokenNo.
192 The, Depth, indicates the include level: 0..n
193 Level 0 is the current. NIL is returned if n+1
194 is requested.
195 *)
196
197 PROCEDURE FindFileNameFromToken (TokenNo: CARDINAL; depth: CARDINAL) : String ;
198
199
200 (*
201 GetFileName - assigns, a, to the current file name.
202 *)
203
204 PROCEDURE GetFileName () : String ;
205
206
207 (* ***********************************************************************
208 *
209 * These functions allow c.lex to deliver tokens into the buffer
210 *
211 ************************************************************************* *)
212
213 (*
214 AddTok - adds a token to the buffer.
215 *)
216
217 PROCEDURE AddTok (t: toktype) ;
218
219
220 (*
221 AddTokCharStar - adds a token to the buffer and an additional string, s.
222 A copy of string, s, is made.
223 *)
224
225 PROCEDURE AddTokCharStar (t: toktype; s: ADDRESS) ;
226
227
228 (*
229 AddTokInteger - adds a token and an integer to the buffer.
230 *)
231
232 PROCEDURE AddTokInteger (t: toktype; i: INTEGER) ;
233
234
235 (*
236 SetFile - sets the current filename to, filename.
237 *)
238
239 PROCEDURE SetFile (filename: ADDRESS) ;
240
241
242 (*
243 PushFile - indicates that, filename, has just been included.
244 *)
245
246 PROCEDURE PushFile (filename: ADDRESS) ;
247
248
249 (*
250 PopFile - indicates that we are returning to, filename, having finished
251 an include.
252 *)
253
254 PROCEDURE PopFile (filename: ADDRESS) ;
255
256
257 (*
258 FlushTokens - removes the last token.
259 *)
260
261 PROCEDURE FlushTokens ;
262
263
264 END CLexBuf.