| 1 |
(* M2Base.def provides a mechanism to check fundamental types. |
| 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 M2Base ; |
| 23 |
|
| 24 |
(* M2Base implements the default base types and base procedures in the |
| 25 |
Modula-2 front end. *) |
| 26 |
|
| 27 |
FROM NameKey IMPORT Name ; |
| 28 |
FROM gcctypes IMPORT location_t ; |
| 29 |
|
| 30 |
|
| 31 |
VAR |
| 32 |
TemplateProcedure, |
| 33 |
ActivationPointer, |
| 34 |
|
| 35 |
Nil, |
| 36 |
Cardinal, Integer, |
| 37 |
Boolean, True, False, |
| 38 |
Char, Proc, |
| 39 |
LongInt, LongCard, |
| 40 |
ShortInt, ShortCard, |
| 41 |
ZType, RType, CType, |
| 42 |
Real, |
| 43 |
LongReal, ShortReal, |
| 44 |
Complex, LongComplex, |
| 45 |
ShortComplex, |
| 46 |
High, LengthS, |
| 47 |
Cap, Abs, Odd, |
| 48 |
Convert, Val, |
| 49 |
Chr, |
| 50 |
Re, Im, Cmplx, |
| 51 |
Min, Max, |
| 52 |
New, Dispose, |
| 53 |
Inc, Dec, |
| 54 |
Incl, Excl, |
| 55 |
ExceptionAssign, |
| 56 |
ExceptionReturn, |
| 57 |
ExceptionInc, |
| 58 |
ExceptionDec, |
| 59 |
ExceptionIncl, |
| 60 |
ExceptionExcl, |
| 61 |
ExceptionShift, |
| 62 |
ExceptionRotate, |
| 63 |
ExceptionStaticArray, |
| 64 |
ExceptionDynamicArray, |
| 65 |
ExceptionForLoopBegin, |
| 66 |
ExceptionForLoopTo, |
| 67 |
ExceptionForLoopEnd, |
| 68 |
ExceptionPointerNil, |
| 69 |
ExceptionNoReturn, |
| 70 |
ExceptionCase, |
| 71 |
ExceptionNonPosDiv, |
| 72 |
ExceptionNonPosMod, |
| 73 |
ExceptionZeroDiv, |
| 74 |
ExceptionZeroRem, |
| 75 |
ExceptionWholeValue, |
| 76 |
ExceptionRealValue, |
| 77 |
ExceptionParameterBounds, |
| 78 |
ExceptionNo : CARDINAL ; |
| 79 |
|
| 80 |
|
| 81 |
(* |
| 82 |
InitBase - initializes the base types and functions |
| 83 |
used in the Modula-2 compiler. |
| 84 |
*) |
| 85 |
|
| 86 |
PROCEDURE InitBase (location: location_t; VAR sym: CARDINAL) ; |
| 87 |
|
| 88 |
|
| 89 |
(* |
| 90 |
GetBaseTypeMinMax - returns the minimum and maximum values for a |
| 91 |
given base type. This procedure should only |
| 92 |
be called if the type is NOT a subrange. |
| 93 |
*) |
| 94 |
|
| 95 |
PROCEDURE GetBaseTypeMinMax (type: CARDINAL; VAR min, max: CARDINAL) ; |
| 96 |
|
| 97 |
|
| 98 |
(* |
| 99 |
IsPseudoBaseFunction - returns true if Sym is a Base function. |
| 100 |
*) |
| 101 |
|
| 102 |
PROCEDURE IsPseudoBaseFunction (Sym: CARDINAL) : BOOLEAN ; |
| 103 |
|
| 104 |
|
| 105 |
(* |
| 106 |
IsPseudoBaseProcedure - returns true if Sym is a Base procedure. |
| 107 |
*) |
| 108 |
|
| 109 |
PROCEDURE IsPseudoBaseProcedure (Sym: CARDINAL) : BOOLEAN ; |
| 110 |
|
| 111 |
|
| 112 |
(* |
| 113 |
IsNeededAtRunTime - returns TRUE if procedure, sym, is a |
| 114 |
runtime procedure. Ie a procedure which is |
| 115 |
not a pseudo procedure and which is implemented |
| 116 |
in M2RTS or SYSTEM and also exported. |
| 117 |
*) |
| 118 |
|
| 119 |
PROCEDURE IsNeededAtRunTime (tok: CARDINAL; sym: CARDINAL) : BOOLEAN ; |
| 120 |
|
| 121 |
|
| 122 |
(* |
| 123 |
IsBaseType - returns TRUE if Sym is a Base type. |
| 124 |
*) |
| 125 |
|
| 126 |
PROCEDURE IsBaseType (Sym: CARDINAL) : BOOLEAN ; |
| 127 |
|
| 128 |
|
| 129 |
(* |
| 130 |
IsOrdinalType - returns TRUE if, sym, is an ordinal type. |
| 131 |
An ordinal type is defined as: |
| 132 |
a base type which contains whole numbers or |
| 133 |
a subrange type or an enumeration type. |
| 134 |
*) |
| 135 |
|
| 136 |
PROCEDURE IsOrdinalType (Sym: CARDINAL) : BOOLEAN ; |
| 137 |
|
| 138 |
|
| 139 |
(* |
| 140 |
IsOrd - returns TRUE if, sym, is ORD or its typed counterparts |
| 141 |
ORDL, ORDS. |
| 142 |
*) |
| 143 |
|
| 144 |
PROCEDURE IsOrd (sym: CARDINAL) : BOOLEAN ; |
| 145 |
|
| 146 |
|
| 147 |
(* |
| 148 |
IsTrunc - returns TRUE if, sym, is TRUNC or its typed counterparts |
| 149 |
TRUNCL, TRUNCS. |
| 150 |
*) |
| 151 |
|
| 152 |
PROCEDURE IsTrunc (sym: CARDINAL) : BOOLEAN ; |
| 153 |
|
| 154 |
|
| 155 |
(* |
| 156 |
IsFloat - returns TRUE if, sym, is FLOAT or its typed counterparts |
| 157 |
FLOATL, FLOATS. |
| 158 |
*) |
| 159 |
|
| 160 |
PROCEDURE IsFloat (sym: CARDINAL) : BOOLEAN ; |
| 161 |
|
| 162 |
|
| 163 |
(* |
| 164 |
IsInt - returns TRUE if, sym, is INT or its typed counterparts |
| 165 |
INTL, INTS. |
| 166 |
*) |
| 167 |
|
| 168 |
PROCEDURE IsInt (sym: CARDINAL) : BOOLEAN ; |
| 169 |
|
| 170 |
|
| 171 |
(* |
| 172 |
AssignmentRequiresWarning - returns TRUE if t1 and t2 can be used during |
| 173 |
an assignment, but should generate a warning. |
| 174 |
For example in PIM we can assign ADDRESS |
| 175 |
and WORD providing they are both the |
| 176 |
same size. |
| 177 |
*) |
| 178 |
|
| 179 |
PROCEDURE AssignmentRequiresWarning (t1, t2: CARDINAL) : BOOLEAN ; |
| 180 |
|
| 181 |
|
| 182 |
(* |
| 183 |
IsAssignmentCompatible - returns TRUE if t1 and t2 are assignment |
| 184 |
compatible. |
| 185 |
*) |
| 186 |
|
| 187 |
PROCEDURE IsAssignmentCompatible (t1, t2: CARDINAL) : BOOLEAN ; |
| 188 |
|
| 189 |
|
| 190 |
(* |
| 191 |
IsExpressionCompatible - returns TRUE if t1 and t2 are expression |
| 192 |
compatible. |
| 193 |
*) |
| 194 |
|
| 195 |
PROCEDURE IsExpressionCompatible (t1, t2: CARDINAL) : BOOLEAN ; |
| 196 |
|
| 197 |
|
| 198 |
(* |
| 199 |
IsParameterCompatible - returns TRUE if types t1 and t2 are parameter |
| 200 |
compatible. |
| 201 |
*) |
| 202 |
|
| 203 |
PROCEDURE IsParameterCompatible (t1, t2: CARDINAL) : BOOLEAN ; |
| 204 |
|
| 205 |
|
| 206 |
(* |
| 207 |
IsComparisonCompatible - returns TRUE if t1 and t2 are comparison |
| 208 |
compatible. PIM allows INTEGER and ADDRESS within |
| 209 |
expressions but we warn against their comparison. |
| 210 |
*) |
| 211 |
|
| 212 |
PROCEDURE IsComparisonCompatible (t1, t2: CARDINAL) : BOOLEAN ; |
| 213 |
|
| 214 |
|
| 215 |
(* |
| 216 |
IsValidParameter - returns TRUE if an, actual, parameter can be passed |
| 217 |
to the, formal, parameter. This differs from |
| 218 |
IsParameterCompatible as this procedure includes checks |
| 219 |
for unbounded formal parameters, var parameters and |
| 220 |
constant actual parameters. |
| 221 |
*) |
| 222 |
|
| 223 |
PROCEDURE IsValidParameter (formal, actual: CARDINAL) : BOOLEAN ; |
| 224 |
|
| 225 |
|
| 226 |
(* |
| 227 |
CheckExpressionCompatible - returns if t1 and t2 are compatible types for |
| 228 |
+, -, *, DIV, >, <, =, etc. |
| 229 |
If t1 and t2 are not compatible then an error |
| 230 |
message is displayed. |
| 231 |
*) |
| 232 |
|
| 233 |
PROCEDURE CheckExpressionCompatible (tok: CARDINAL; |
| 234 |
left, right: CARDINAL) ; |
| 235 |
|
| 236 |
|
| 237 |
(* |
| 238 |
CheckAssignmentCompatible - returns if t1 and t2 are compatible types for |
| 239 |
:=, =, #. |
| 240 |
If t1 and t2 are not compatible then an error |
| 241 |
message is displayed. |
| 242 |
*) |
| 243 |
|
| 244 |
PROCEDURE CheckAssignmentCompatible (tok: CARDINAL; |
| 245 |
left, right: CARDINAL) ; |
| 246 |
|
| 247 |
|
| 248 |
(* |
| 249 |
CheckParameterCompatible - checks to see if types, t1, and, t2, are |
| 250 |
compatible for parameter passing. |
| 251 |
*) |
| 252 |
|
| 253 |
PROCEDURE CheckParameterCompatible (tok: CARDINAL; |
| 254 |
t1, t2: CARDINAL) ; |
| 255 |
|
| 256 |
|
| 257 |
(* |
| 258 |
CannotCheckTypeInPass3 - returns TRUE if we are unable to check the |
| 259 |
type of, e, in pass 3. |
| 260 |
*) |
| 261 |
|
| 262 |
PROCEDURE CannotCheckTypeInPass3 (e: CARDINAL) : BOOLEAN ; |
| 263 |
|
| 264 |
|
| 265 |
(* |
| 266 |
MixTypes - given types leftType and rightType return a type symbol that |
| 267 |
provides expression type compatibility. |
| 268 |
NearTok is used to identify the source position if a type |
| 269 |
incompatability occurs. |
| 270 |
*) |
| 271 |
|
| 272 |
PROCEDURE MixTypes (leftType, rightType: CARDINAL; NearTok: CARDINAL) : CARDINAL ; |
| 273 |
|
| 274 |
|
| 275 |
(* |
| 276 |
MixTypesDecl - returns a type symbol which provides expression compatibility |
| 277 |
between leftType and rightType. An error is emitted if this |
| 278 |
is not possible. left and right are the source (variable, |
| 279 |
constant) of leftType and rightType respectively. |
| 280 |
*) |
| 281 |
|
| 282 |
PROCEDURE MixTypesDecl (left, right, leftType, rightType: CARDINAL; |
| 283 |
NearTok: CARDINAL) : CARDINAL ; |
| 284 |
|
| 285 |
|
| 286 |
(* |
| 287 |
NegateType - if the type is unsigned then returns the |
| 288 |
signed equivalent. |
| 289 |
*) |
| 290 |
|
| 291 |
PROCEDURE NegateType (type: CARDINAL (* ; sympos: CARDINAL *) ) : CARDINAL ; |
| 292 |
|
| 293 |
|
| 294 |
(* |
| 295 |
IsMathType - returns TRUE if the type is a mathematical type. |
| 296 |
A mathematical type has a range larger than INTEGER. |
| 297 |
(Typically REAL/LONGREAL/LONGINT) |
| 298 |
*) |
| 299 |
|
| 300 |
PROCEDURE IsMathType (type: CARDINAL) : BOOLEAN ; |
| 301 |
|
| 302 |
|
| 303 |
(* |
| 304 |
IsRealType - returns TRUE if, t, is a real type. |
| 305 |
*) |
| 306 |
|
| 307 |
PROCEDURE IsRealType (t: CARDINAL) : BOOLEAN ; |
| 308 |
|
| 309 |
|
| 310 |
(* |
| 311 |
IsComplexType - returns TRUE if, sym, is COMPLEX, |
| 312 |
LONGCOMPLEX or SHORTCOMPLEX. |
| 313 |
*) |
| 314 |
|
| 315 |
PROCEDURE IsComplexType (sym: CARDINAL) : BOOLEAN ; |
| 316 |
|
| 317 |
|
| 318 |
(* |
| 319 |
ComplexToScalar - returns the scalar (or base type) of the complex type, sym. |
| 320 |
*) |
| 321 |
|
| 322 |
PROCEDURE ComplexToScalar (sym: CARDINAL) : CARDINAL ; |
| 323 |
|
| 324 |
|
| 325 |
(* |
| 326 |
ScalarToComplex - given a real type, t, return the equivalent complex type. |
| 327 |
*) |
| 328 |
|
| 329 |
PROCEDURE ScalarToComplex (sym: CARDINAL) : CARDINAL ; |
| 330 |
|
| 331 |
|
| 332 |
(* |
| 333 |
GetCmplxReturnType - this code implements the table given in the |
| 334 |
ISO standard Page 293 with an addition for |
| 335 |
SHORTCOMPLEX and the fixed sized COMPLEX |
| 336 |
types found in the GNU Modula-2 SYSTEM |
| 337 |
Module. |
| 338 |
*) |
| 339 |
|
| 340 |
PROCEDURE GetCmplxReturnType (t1, t2: CARDINAL) : CARDINAL ; |
| 341 |
|
| 342 |
|
| 343 |
END M2Base. |