| 1 |
(* m2block.def definition module for m2block.cc. |
| 2 |
|
| 3 |
Copyright (C) 2011-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 FOR "C" m2block ; |
| 23 |
|
| 24 |
FROM gcctypes IMPORT location_t, tree ; |
| 25 |
FROM CDataTypes IMPORT CharStar ; |
| 26 |
|
| 27 |
|
| 28 |
(* |
| 29 |
init - initialise the data structures in this module. |
| 30 |
*) |
| 31 |
|
| 32 |
PROCEDURE init ; |
| 33 |
|
| 34 |
|
| 35 |
(* |
| 36 |
toplevel - return TRUE if we are in the global scope. |
| 37 |
*) |
| 38 |
|
| 39 |
PROCEDURE toplevel () : BOOLEAN ; |
| 40 |
|
| 41 |
|
| 42 |
(* |
| 43 |
global_constant - t is a constant, we keep a chain of all constants |
| 44 |
in the global binding level. |
| 45 |
*) |
| 46 |
|
| 47 |
PROCEDURE global_constant (t: tree) : tree ; |
| 48 |
|
| 49 |
|
| 50 |
(* |
| 51 |
RememberInitModuleFunction - records tree, t, in the global binding level. |
| 52 |
So that it will not be garbage collected. |
| 53 |
In theory the inner modules could be placed |
| 54 |
inside the current_binding_level I suspect. |
| 55 |
*) |
| 56 |
|
| 57 |
PROCEDURE RememberInitModuleFunction (t: tree) : tree ; |
| 58 |
|
| 59 |
|
| 60 |
(* |
| 61 |
DumpGlobalConstants - displays all global constants and checks none are |
| 62 |
poisoned. |
| 63 |
*) |
| 64 |
|
| 65 |
PROCEDURE DumpGlobalConstants () : tree ; |
| 66 |
|
| 67 |
|
| 68 |
(* |
| 69 |
RememberConstant - adds a tree, t, onto the list of constants to be marked |
| 70 |
whenever the ggc re-marks all used storage. Constants |
| 71 |
live throughout the whole compilation - and they |
| 72 |
can be used by many different functions if necessary. |
| 73 |
*) |
| 74 |
|
| 75 |
PROCEDURE RememberConstant (t: tree) : tree ; |
| 76 |
|
| 77 |
|
| 78 |
(* |
| 79 |
RememberType - remember the type, t, in the ggc marked list. |
| 80 |
*) |
| 81 |
|
| 82 |
PROCEDURE RememberType (t: tree) : tree ; |
| 83 |
|
| 84 |
|
| 85 |
(* |
| 86 |
pushDecl - pushes a declaration onto the current binding level. |
| 87 |
*) |
| 88 |
|
| 89 |
PROCEDURE pushDecl (decl: tree) : tree ; |
| 90 |
|
| 91 |
|
| 92 |
(* |
| 93 |
popGlobalScope - pops the current binding level, it expects this binding level |
| 94 |
to be the global binding level. |
| 95 |
*) |
| 96 |
|
| 97 |
PROCEDURE popGlobalScope ; |
| 98 |
|
| 99 |
|
| 100 |
(* |
| 101 |
pushGlobalScope - push the global scope onto the binding level stack. |
| 102 |
There can only ever be one instance of the global binding |
| 103 |
level on the stack. |
| 104 |
*) |
| 105 |
|
| 106 |
PROCEDURE pushGlobalScope ; |
| 107 |
|
| 108 |
|
| 109 |
(* |
| 110 |
popFunctionScope - pops a binding level, returning the function associated with the |
| 111 |
binding level. |
| 112 |
*) |
| 113 |
|
| 114 |
PROCEDURE popFunctionScope () : tree ; |
| 115 |
|
| 116 |
|
| 117 |
(* |
| 118 |
pushFunctionScope - push a binding level. |
| 119 |
*) |
| 120 |
|
| 121 |
PROCEDURE pushFunctionScope (fndecl: tree) ; |
| 122 |
|
| 123 |
|
| 124 |
(* |
| 125 |
finishFunctionCode - adds cur_stmt_list to fndecl. The current binding level |
| 126 |
is then able to be destroyed by a call to popFunctionScope. |
| 127 |
The cur_stmt_list is appended to the STATEMENT_LIST. |
| 128 |
*) |
| 129 |
|
| 130 |
PROCEDURE finishFunctionCode (fndecl: tree) ; |
| 131 |
|
| 132 |
|
| 133 |
(* |
| 134 |
finishFunctionDecl - removes declarations from the current binding level and places |
| 135 |
them inside fndecl. The current binding level is then able to |
| 136 |
be destroyed by a call to popFunctionScope. |
| 137 |
|
| 138 |
The extra tree nodes associated with fndecl will be created |
| 139 |
such as BIND_EXPR, BLOCK and the initial STATEMENT_LIST |
| 140 |
containing the DECL_EXPR is also created. |
| 141 |
*) |
| 142 |
|
| 143 |
PROCEDURE finishFunctionDecl (location: location_t; fndecl: tree) ; |
| 144 |
|
| 145 |
|
| 146 |
(* |
| 147 |
getLabel - return the label, name, or create a label, name |
| 148 |
in the current scope. |
| 149 |
*) |
| 150 |
|
| 151 |
PROCEDURE getLabel (location: location_t; name: CharStar) : tree ; |
| 152 |
|
| 153 |
|
| 154 |
(* |
| 155 |
GetErrorNode - returns the gcc error_mark_node. |
| 156 |
*) |
| 157 |
|
| 158 |
PROCEDURE GetErrorNode () : tree ; |
| 159 |
|
| 160 |
|
| 161 |
(* |
| 162 |
includeDecl - pushes a declaration onto the current binding level providing |
| 163 |
it is not already present. |
| 164 |
*) |
| 165 |
|
| 166 |
PROCEDURE includeDecl (decl: tree) ; |
| 167 |
|
| 168 |
|
| 169 |
(* |
| 170 |
GetGlobals - returns a list of global variables, functions, constants. |
| 171 |
*) |
| 172 |
|
| 173 |
PROCEDURE GetGlobals () : tree ; |
| 174 |
|
| 175 |
|
| 176 |
(* |
| 177 |
GetGlobalContext - returns the global context tree. |
| 178 |
*) |
| 179 |
|
| 180 |
PROCEDURE GetGlobalContext () : tree ; |
| 181 |
|
| 182 |
|
| 183 |
(* |
| 184 |
begin_statement_list - starts a tree statement. It pushes the |
| 185 |
statement list and returns the list node. |
| 186 |
*) |
| 187 |
|
| 188 |
PROCEDURE begin_statement_list () : tree ; |
| 189 |
|
| 190 |
|
| 191 |
(* |
| 192 |
push_statement_list - pushes the statement list, t, onto the |
| 193 |
current binding level. |
| 194 |
*) |
| 195 |
|
| 196 |
PROCEDURE push_statement_list (t: tree) : tree ; |
| 197 |
|
| 198 |
|
| 199 |
(* |
| 200 |
pop_statement_list - pops and returns a statement list from the |
| 201 |
current binding level. |
| 202 |
*) |
| 203 |
|
| 204 |
PROCEDURE pop_statement_list () : tree ; |
| 205 |
|
| 206 |
|
| 207 |
(* |
| 208 |
addStmtNote - remember this location represents the start of a Modula-2 |
| 209 |
statement. It is flushed if another different location is |
| 210 |
generated or another tree is given to add_stmt. |
| 211 |
*) |
| 212 |
|
| 213 |
PROCEDURE addStmtNote (location: location_t) ; |
| 214 |
|
| 215 |
|
| 216 |
(* |
| 217 |
removeStmtNote - removes any pending stmt note. |
| 218 |
*) |
| 219 |
|
| 220 |
PROCEDURE removeStmtNote ; |
| 221 |
|
| 222 |
|
| 223 |
END m2block. |