| 1 |
(* PCSymBuild.def pass C symbol creation. |
| 2 |
|
| 3 |
Copyright (C) 2001-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 PCSymBuild ; |
| 23 |
|
| 24 |
(* |
| 25 |
Title : PCSymBuild |
| 26 |
Author : Gaius Mulley |
| 27 |
System : UNIX (GNU Modula-2) |
| 28 |
Description: provides scope mainstance for Pass C it also resolves |
| 29 |
the import/export symbols and assigns types to constructors. |
| 30 |
*) |
| 31 |
|
| 32 |
|
| 33 |
(* |
| 34 |
CheckNotVar - checks to see that the top of stack is not a variable. |
| 35 |
*) |
| 36 |
|
| 37 |
PROCEDURE CheckNotVar (tok: CARDINAL) ; |
| 38 |
|
| 39 |
|
| 40 |
(* |
| 41 |
StartBuildDefinitionModule - Creates a definition module and starts |
| 42 |
a new scope. |
| 43 |
|
| 44 |
The Stack is expected: |
| 45 |
|
| 46 |
Entry Exit |
| 47 |
|
| 48 |
Ptr -> <- Ptr |
| 49 |
+------------+ +-----------+ |
| 50 |
| NameStart | | NameStart | |
| 51 |
|------------| |-----------| |
| 52 |
|
| 53 |
*) |
| 54 |
|
| 55 |
PROCEDURE PCStartBuildDefModule ; |
| 56 |
|
| 57 |
|
| 58 |
(* |
| 59 |
EndBuildDefinitionModule - Destroys the definition module scope and |
| 60 |
checks for correct name. |
| 61 |
|
| 62 |
The Stack is expected: |
| 63 |
|
| 64 |
Entry Exit |
| 65 |
|
| 66 |
Ptr -> |
| 67 |
+------------+ +-----------+ |
| 68 |
| NameEnd | | | |
| 69 |
|------------| |-----------| |
| 70 |
| NameStart | | | <- Ptr |
| 71 |
|------------| |-----------| |
| 72 |
*) |
| 73 |
|
| 74 |
PROCEDURE PCEndBuildDefModule ; |
| 75 |
|
| 76 |
|
| 77 |
(* |
| 78 |
StartBuildImplementationModule - Creates an implementation module and starts |
| 79 |
a new scope. |
| 80 |
|
| 81 |
The Stack is expected: |
| 82 |
|
| 83 |
Entry Exit |
| 84 |
|
| 85 |
Ptr -> <- Ptr |
| 86 |
+------------+ +-----------+ |
| 87 |
| NameStart | | NameStart | |
| 88 |
|------------| |-----------| |
| 89 |
|
| 90 |
*) |
| 91 |
|
| 92 |
PROCEDURE PCStartBuildImpModule ; |
| 93 |
|
| 94 |
|
| 95 |
(* |
| 96 |
EndBuildImplementationModule - Destroys the implementation module scope and |
| 97 |
checks for correct name. |
| 98 |
|
| 99 |
The Stack is expected: |
| 100 |
|
| 101 |
Entry Exit |
| 102 |
|
| 103 |
Ptr -> |
| 104 |
+------------+ +-----------+ |
| 105 |
| NameEnd | | | |
| 106 |
|------------| |-----------| |
| 107 |
| NameStart | | | <- Ptr |
| 108 |
|------------| |-----------| |
| 109 |
*) |
| 110 |
|
| 111 |
PROCEDURE PCEndBuildImpModule ; |
| 112 |
|
| 113 |
|
| 114 |
(* |
| 115 |
StartBuildProgramModule - Creates a program module and starts |
| 116 |
a new scope. |
| 117 |
|
| 118 |
The Stack is expected: |
| 119 |
|
| 120 |
Entry Exit |
| 121 |
|
| 122 |
Ptr -> <- Ptr |
| 123 |
+------------+ +-----------+ |
| 124 |
| NameStart | | NameStart | |
| 125 |
|------------| |-----------| |
| 126 |
|
| 127 |
*) |
| 128 |
|
| 129 |
PROCEDURE PCStartBuildProgModule ; |
| 130 |
|
| 131 |
|
| 132 |
(* |
| 133 |
EndBuildProgramModule - Destroys the program module scope and |
| 134 |
checks for correct name. |
| 135 |
|
| 136 |
The Stack is expected: |
| 137 |
|
| 138 |
Entry Exit |
| 139 |
|
| 140 |
Ptr -> |
| 141 |
+------------+ +-----------+ |
| 142 |
| NameEnd | | | |
| 143 |
|------------| |-----------| |
| 144 |
| NameStart | | | <- Ptr |
| 145 |
|------------| |-----------| |
| 146 |
*) |
| 147 |
|
| 148 |
PROCEDURE PCEndBuildProgModule ; |
| 149 |
|
| 150 |
|
| 151 |
(* |
| 152 |
StartBuildInnerModule - Creates an Inner module and starts |
| 153 |
a new scope. |
| 154 |
|
| 155 |
The Stack is expected: |
| 156 |
|
| 157 |
Entry Exit |
| 158 |
|
| 159 |
Ptr -> <- Ptr |
| 160 |
+------------+ +-----------+ |
| 161 |
| NameStart | | NameStart | |
| 162 |
|------------| |-----------| |
| 163 |
|
| 164 |
*) |
| 165 |
|
| 166 |
PROCEDURE PCStartBuildInnerModule ; |
| 167 |
|
| 168 |
|
| 169 |
(* |
| 170 |
EndBuildInnermModule - Destroys the Inner module scope and |
| 171 |
checks for correct name. |
| 172 |
|
| 173 |
The Stack is expected: |
| 174 |
|
| 175 |
Entry Exit |
| 176 |
|
| 177 |
Ptr -> |
| 178 |
+------------+ +-----------+ |
| 179 |
| NameEnd | | | |
| 180 |
|------------| |-----------| |
| 181 |
| NameStart | | | <- Ptr |
| 182 |
|------------| |-----------| |
| 183 |
*) |
| 184 |
|
| 185 |
PROCEDURE PCEndBuildInnerModule ; |
| 186 |
|
| 187 |
|
| 188 |
(* |
| 189 |
BuildProcedureHeading - Builds a procedure heading for the definition |
| 190 |
module procedures. |
| 191 |
|
| 192 |
Operation only performed if compiling a |
| 193 |
definition module. |
| 194 |
|
| 195 |
The Stack: |
| 196 |
|
| 197 |
Entry Exit |
| 198 |
|
| 199 |
Ptr -> |
| 200 |
+------------+ |
| 201 |
| ProcSym | Empty |
| 202 |
|------------| |
| 203 |
|
| 204 |
*) |
| 205 |
|
| 206 |
PROCEDURE PCBuildProcedureHeading ; |
| 207 |
|
| 208 |
|
| 209 |
(* |
| 210 |
StartBuildProcedure - Builds a Procedure. |
| 211 |
|
| 212 |
The Stack: |
| 213 |
|
| 214 |
Entry Exit |
| 215 |
|
| 216 |
<- Ptr |
| 217 |
+------------+ |
| 218 |
Ptr -> | ProcSym | |
| 219 |
+------------+ |------------| |
| 220 |
| Name | | Name | |
| 221 |
|------------| |------------| |
| 222 |
*) |
| 223 |
|
| 224 |
PROCEDURE PCStartBuildProcedure ; |
| 225 |
|
| 226 |
|
| 227 |
(* |
| 228 |
EndBuildProcedure - Ends building a Procedure. |
| 229 |
It checks the start procedure name matches the end |
| 230 |
procedure name. |
| 231 |
|
| 232 |
The Stack: |
| 233 |
|
| 234 |
|
| 235 |
Entry Exit |
| 236 |
|
| 237 |
Ptr -> |
| 238 |
+------------+ |
| 239 |
| NameEnd | |
| 240 |
|------------| |
| 241 |
| ProcSym | |
| 242 |
|------------| |
| 243 |
| NameStart | |
| 244 |
|------------| |
| 245 |
Empty |
| 246 |
*) |
| 247 |
|
| 248 |
PROCEDURE PCEndBuildProcedure ; |
| 249 |
|
| 250 |
|
| 251 |
(* |
| 252 |
EndBuildForward - Ends building a forward declaration. |
| 253 |
|
| 254 |
The Stack: |
| 255 |
|
| 256 |
Entry Exit |
| 257 |
|
| 258 |
Ptr -> |
| 259 |
+------------+ |
| 260 |
| ProcSym | |
| 261 |
|------------| |
| 262 |
| NameStart | |
| 263 |
|------------| |
| 264 |
Empty |
| 265 |
*) |
| 266 |
|
| 267 |
PROCEDURE PCEndBuildForward ; |
| 268 |
|
| 269 |
|
| 270 |
(* |
| 271 |
BuildImportOuterModule - Builds imported identifiers into an outer module |
| 272 |
from a definition module. |
| 273 |
|
| 274 |
The Stack is expected: |
| 275 |
|
| 276 |
Entry OR Entry |
| 277 |
|
| 278 |
Ptr -> Ptr -> |
| 279 |
+------------+ +-----------+ |
| 280 |
| # | | # | |
| 281 |
|------------| |-----------| |
| 282 |
| Id1 | | Id1 | |
| 283 |
|------------| |-----------| |
| 284 |
. . . . |
| 285 |
. . . . |
| 286 |
. . . . |
| 287 |
|------------| |-----------| |
| 288 |
| Id# | | Id# | |
| 289 |
|------------| |-----------| |
| 290 |
| ImportTok | | Ident | |
| 291 |
|------------| |-----------| |
| 292 |
|
| 293 |
IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ; |
| 294 |
|
| 295 |
|
| 296 |
Exit |
| 297 |
|
| 298 |
All above stack discarded |
| 299 |
*) |
| 300 |
|
| 301 |
PROCEDURE PCBuildImportOuterModule ; |
| 302 |
|
| 303 |
|
| 304 |
(* |
| 305 |
BuildImportInnerModule - Builds imported identifiers into an inner module |
| 306 |
from the last level of module. |
| 307 |
|
| 308 |
The Stack is expected: |
| 309 |
|
| 310 |
Entry OR Entry |
| 311 |
|
| 312 |
Ptr -> Ptr -> |
| 313 |
+------------+ +-----------+ |
| 314 |
| # | | # | |
| 315 |
|------------| |-----------| |
| 316 |
| Id1 | | Id1 | |
| 317 |
|------------| |-----------| |
| 318 |
. . . . |
| 319 |
. . . . |
| 320 |
. . . . |
| 321 |
|------------| |-----------| |
| 322 |
| Id# | | Id# | |
| 323 |
|------------| |-----------| |
| 324 |
| ImportTok | | Ident | |
| 325 |
|------------| |-----------| |
| 326 |
|
| 327 |
IMPORT Id1, .. Id# ; FROM Ident IMPORT Id1 .. Id# ; |
| 328 |
|
| 329 |
|
| 330 |
Error Condition |
| 331 |
Exit |
| 332 |
|
| 333 |
All above stack discarded |
| 334 |
*) |
| 335 |
|
| 336 |
PROCEDURE PCBuildImportInnerModule ; |
| 337 |
|
| 338 |
|
| 339 |
(* |
| 340 |
BuildNulName - Pushes a NulKey onto the top of the stack. |
| 341 |
The Stack: |
| 342 |
|
| 343 |
|
| 344 |
Entry Exit |
| 345 |
|
| 346 |
<- Ptr |
| 347 |
Empty +------------+ |
| 348 |
| NulKey | |
| 349 |
|------------| |
| 350 |
*) |
| 351 |
|
| 352 |
PROCEDURE BuildNulName ; |
| 353 |
|
| 354 |
|
| 355 |
(* |
| 356 |
BuildConst - builds a constant. |
| 357 |
Stack |
| 358 |
|
| 359 |
Entry Exit |
| 360 |
|
| 361 |
Ptr -> <- Ptr |
| 362 |
+------------+ +------------+ |
| 363 |
| Name | | Sym | |
| 364 |
|------------+ |------------| |
| 365 |
*) |
| 366 |
|
| 367 |
PROCEDURE BuildConst ; |
| 368 |
|
| 369 |
|
| 370 |
(* |
| 371 |
StartDesConst - |
| 372 |
*) |
| 373 |
|
| 374 |
PROCEDURE StartDesConst ; |
| 375 |
|
| 376 |
|
| 377 |
(* |
| 378 |
EndDesConst - |
| 379 |
*) |
| 380 |
|
| 381 |
PROCEDURE EndDesConst ; |
| 382 |
|
| 383 |
|
| 384 |
(* |
| 385 |
BuildRelationConst - builds a relationship binary operation. |
| 386 |
*) |
| 387 |
|
| 388 |
PROCEDURE BuildRelationConst ; |
| 389 |
|
| 390 |
|
| 391 |
(* |
| 392 |
BuildUnaryConst - builds a unary operator node. |
| 393 |
*) |
| 394 |
|
| 395 |
PROCEDURE BuildUnaryConst ; |
| 396 |
|
| 397 |
|
| 398 |
(* |
| 399 |
BuildBinaryConst - builds a binary operator node. |
| 400 |
*) |
| 401 |
|
| 402 |
PROCEDURE BuildBinaryConst ; |
| 403 |
|
| 404 |
|
| 405 |
(* |
| 406 |
PushConstFunctionType - |
| 407 |
*) |
| 408 |
|
| 409 |
PROCEDURE PushConstFunctionType ; |
| 410 |
|
| 411 |
|
| 412 |
(* |
| 413 |
PushIntegerType - pushes a ztype or char leaf. |
| 414 |
*) |
| 415 |
|
| 416 |
PROCEDURE PushIntegerType ; |
| 417 |
|
| 418 |
|
| 419 |
(* |
| 420 |
PushRType - |
| 421 |
*) |
| 422 |
|
| 423 |
PROCEDURE PushRType ; |
| 424 |
|
| 425 |
|
| 426 |
(* |
| 427 |
PushStringType - |
| 428 |
*) |
| 429 |
|
| 430 |
PROCEDURE PushStringType ; |
| 431 |
|
| 432 |
|
| 433 |
(* |
| 434 |
SkipConst - returns an alias to constant, sym, if one exists. |
| 435 |
Otherwise sym is returned. |
| 436 |
*) |
| 437 |
|
| 438 |
PROCEDURE SkipConst (sym: CARDINAL) : CARDINAL ; |
| 439 |
|
| 440 |
|
| 441 |
(* |
| 442 |
PushConstType - pushes a constant to the expression stack. |
| 443 |
*) |
| 444 |
|
| 445 |
PROCEDURE PushConstType ; |
| 446 |
|
| 447 |
|
| 448 |
(* |
| 449 |
PushConstAttributeType - |
| 450 |
*) |
| 451 |
|
| 452 |
PROCEDURE PushConstAttributeType ; |
| 453 |
|
| 454 |
|
| 455 |
(* |
| 456 |
PushConstAttributePairType - |
| 457 |
*) |
| 458 |
|
| 459 |
PROCEDURE PushConstAttributePairType ; |
| 460 |
|
| 461 |
|
| 462 |
(* |
| 463 |
PushConstructorCastType - |
| 464 |
*) |
| 465 |
|
| 466 |
PROCEDURE PushConstructorCastType ; |
| 467 |
|
| 468 |
|
| 469 |
(* |
| 470 |
PushInConstructor - |
| 471 |
*) |
| 472 |
|
| 473 |
PROCEDURE PushInConstructor ; |
| 474 |
|
| 475 |
|
| 476 |
(* |
| 477 |
PopInConstructor - |
| 478 |
*) |
| 479 |
|
| 480 |
PROCEDURE PopInConstructor ; |
| 481 |
|
| 482 |
|
| 483 |
(* |
| 484 |
ResolveConstTypes - resolves the types of all designator declared constants. |
| 485 |
*) |
| 486 |
|
| 487 |
PROCEDURE ResolveConstTypes ; |
| 488 |
|
| 489 |
|
| 490 |
END PCSymBuild. |