| 1 |
(* M2Check.mod perform rigerous type checking for fully declared symbols. |
| 2 |
|
| 3 |
Copyright (C) 2020-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 |
IMPLEMENTATION MODULE M2Check ; |
| 23 |
|
| 24 |
(* |
| 25 |
Title : M2Check |
| 26 |
Author : Gaius Mulley |
| 27 |
System : GNU Modula-2 |
| 28 |
Date : Fri Mar 6 15:32:10 2020 |
| 29 |
Revision : $Version$ |
| 30 |
Description: provides a module to check the symbol type compatibility. |
| 31 |
It assumes that the declaration of all dependants |
| 32 |
is complete. |
| 33 |
*) |
| 34 |
|
| 35 |
FROM M2System IMPORT IsSystemType, IsGenericSystemType, IsSameSize, IsComplexN ; |
| 36 |
FROM M2Base IMPORT IsParameterCompatible, IsAssignmentCompatible, IsExpressionCompatible, IsComparisonCompatible, IsBaseType, IsMathType, ZType, CType, RType, IsComplexType, Char ; |
| 37 |
FROM Indexing IMPORT Index, InitIndex, GetIndice, PutIndice, KillIndex, HighIndice, LowIndice, IncludeIndiceIntoIndex, ForeachIndiceInIndexDo ; |
| 38 |
FROM M2Error IMPORT Error, InternalError, NewError, ErrorString, ChainError ; |
| 39 |
|
| 40 |
FROM M2MetaError IMPORT MetaErrorStringT0, MetaErrorStringT2, MetaErrorStringT3, |
| 41 |
MetaErrorStringT4, |
| 42 |
MetaString0, MetaString1, MetaString2, MetaString3, |
| 43 |
MetaString4, |
| 44 |
MetaError0, MetaError1 ; |
| 45 |
|
| 46 |
FROM StrLib IMPORT StrEqual ; |
| 47 |
FROM M2Debug IMPORT Assert ; |
| 48 |
|
| 49 |
FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, GetType, IsType, |
| 50 |
SkipType, IsProcedure, NoOfParamAny, IsVarParamAny, GetNth, |
| 51 |
GetNthParamAny, IsProcType, IsVar, IsEnumeration, IsArray, |
| 52 |
IsSubrange, GetArraySubscript, IsConst, |
| 53 |
IsReallyPointer, IsPointer, IsParameter, ModeOfAddr, |
| 54 |
GetMode, IsUnbounded, IsComposite, IsConstructor, |
| 55 |
IsParameter, IsConstString, IsConstLitInternal, IsConstLit, |
| 56 |
GetStringLength, GetProcedureProcType, IsHiddenType, |
| 57 |
IsHiddenReallyPointer, GetDimension, IsFieldEnumeration ; |
| 58 |
|
| 59 |
FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ; |
| 60 |
FROM M2System IMPORT Address ; |
| 61 |
FROM M2ALU IMPORT Equ, PushIntegerTree ; |
| 62 |
FROM M2Options IMPORT StrictTypeReason ; |
| 63 |
FROM m2expr IMPORT AreConstantsEqual ; |
| 64 |
FROM SymbolConversion IMPORT Mod2Gcc, GccKnowsAbout ; |
| 65 |
FROM DynamicStrings IMPORT String, InitString, KillString, ConCat, Mark ; |
| 66 |
FROM M2LexBuf IMPORT GetTokenNo ; |
| 67 |
FROM Storage IMPORT ALLOCATE ; |
| 68 |
FROM SYSTEM IMPORT ADR ; |
| 69 |
FROM libc IMPORT printf ; |
| 70 |
|
| 71 |
|
| 72 |
CONST |
| 73 |
debugging = FALSE ; |
| 74 |
MaxEquvalence = 20 ; |
| 75 |
|
| 76 |
TYPE |
| 77 |
errorSig = POINTER TO RECORD |
| 78 |
token: CARDINAL ; |
| 79 |
left, |
| 80 |
right: CARDINAL ; |
| 81 |
END ; |
| 82 |
|
| 83 |
pair = POINTER TO RECORD |
| 84 |
left, right: CARDINAL ; |
| 85 |
pairStatus : status ; |
| 86 |
next : pair ; |
| 87 |
END ; |
| 88 |
|
| 89 |
typeCheckFunction = PROCEDURE (status, tInfo, CARDINAL, CARDINAL) : status ; |
| 90 |
|
| 91 |
checkType = (parameter, assignment, expression) ; |
| 92 |
|
| 93 |
tInfo = POINTER TO RECORD |
| 94 |
reasonEnable: BOOLEAN ; |
| 95 |
reason, |
| 96 |
format : String ; |
| 97 |
kind : checkType ; |
| 98 |
token, |
| 99 |
actual, |
| 100 |
formal, |
| 101 |
left, |
| 102 |
right, |
| 103 |
procedure, |
| 104 |
nth : CARDINAL ; |
| 105 |
isvar : BOOLEAN ; |
| 106 |
strict : BOOLEAN ; (* Comparison expression. *) |
| 107 |
isin : BOOLEAN ; (* Expression created by IN? *) |
| 108 |
error : Error ; |
| 109 |
checkFunc : typeCheckFunction ; |
| 110 |
visited, |
| 111 |
resolved, |
| 112 |
unresolved: Index ; |
| 113 |
next : tInfo ; |
| 114 |
END ; |
| 115 |
|
| 116 |
status = (true, false, unknown, visited, unused) ; |
| 117 |
|
| 118 |
EquivalenceProcedure = PROCEDURE (status, tInfo, CARDINAL, CARDINAL) : status ; |
| 119 |
|
| 120 |
VAR |
| 121 |
pairFreeList : pair ; |
| 122 |
tinfoFreeList : tInfo ; |
| 123 |
errors : Index ; |
| 124 |
HighEquivalence: CARDINAL ; |
| 125 |
Equivalence : ARRAY [1..MaxEquvalence] OF EquivalenceProcedure ; |
| 126 |
|
| 127 |
|
| 128 |
(* |
| 129 |
dumpIndice - |
| 130 |
*) |
| 131 |
|
| 132 |
PROCEDURE dumpIndice (ptr: pair) ; |
| 133 |
BEGIN |
| 134 |
printf (" left (%d), right (%d), status ", |
| 135 |
ptr^.left, ptr^.right); |
| 136 |
CASE ptr^.pairStatus OF |
| 137 |
|
| 138 |
true : printf ("true") | |
| 139 |
false : printf ("false") | |
| 140 |
unknown: printf ("unknown") | |
| 141 |
visited: printf ("visited") | |
| 142 |
unused : printf ("unused") |
| 143 |
|
| 144 |
END ; |
| 145 |
printf ("\n") |
| 146 |
END dumpIndice ; |
| 147 |
|
| 148 |
|
| 149 |
(* |
| 150 |
dumpIndex - |
| 151 |
*) |
| 152 |
|
| 153 |
PROCEDURE dumpIndex (name: ARRAY OF CHAR; index: Index) ; |
| 154 |
BEGIN |
| 155 |
printf ("status: %s\n", ADR (name)) ; |
| 156 |
ForeachIndiceInIndexDo (index, dumpIndice) |
| 157 |
END dumpIndex ; |
| 158 |
|
| 159 |
|
| 160 |
(* |
| 161 |
dumptInfo - |
| 162 |
*) |
| 163 |
|
| 164 |
PROCEDURE dumptInfo (t: tInfo) ; |
| 165 |
BEGIN |
| 166 |
printf ("actual (%d), formal (%d), left (%d), right (%d), procedure (%d)\n", |
| 167 |
t^.actual, t^.formal, t^.left, t^.right, t^.procedure) ; |
| 168 |
dumpIndex ('visited', t^.visited) ; |
| 169 |
dumpIndex ('resolved', t^.resolved) ; |
| 170 |
dumpIndex ('unresolved', t^.unresolved) |
| 171 |
END dumptInfo ; |
| 172 |
|
| 173 |
|
| 174 |
(* |
| 175 |
falseReason2 - return false. It also stores the message as the |
| 176 |
reason for the false value. |
| 177 |
*) |
| 178 |
|
| 179 |
PROCEDURE falseReason2 (message: ARRAY OF CHAR; tinfo: tInfo; |
| 180 |
left, right: CARDINAL) : status ; |
| 181 |
BEGIN |
| 182 |
IF tinfo^.reasonEnable AND (tinfo^.reason = NIL) |
| 183 |
THEN |
| 184 |
tinfo^.reason := MetaString2 (InitString (message), left, right) |
| 185 |
END ; |
| 186 |
RETURN false |
| 187 |
END falseReason2 ; |
| 188 |
|
| 189 |
|
| 190 |
(* |
| 191 |
falseReason1 - return false. It also stores the message as the |
| 192 |
reason for the false value. |
| 193 |
*) |
| 194 |
|
| 195 |
PROCEDURE falseReason1 (message: ARRAY OF CHAR; tinfo: tInfo; |
| 196 |
operand: CARDINAL) : status ; |
| 197 |
BEGIN |
| 198 |
IF tinfo^.reasonEnable AND (tinfo^.reason = NIL) |
| 199 |
THEN |
| 200 |
tinfo^.reason := MetaString1 (InitString (message), operand) |
| 201 |
END ; |
| 202 |
RETURN false |
| 203 |
END falseReason1 ; |
| 204 |
|
| 205 |
|
| 206 |
(* |
| 207 |
falseReason0 - return false. It also stores the message as the |
| 208 |
reason for the false value. |
| 209 |
*) |
| 210 |
|
| 211 |
PROCEDURE falseReason0 (message: ARRAY OF CHAR; tinfo: tInfo) : status ; |
| 212 |
BEGIN |
| 213 |
IF tinfo^.reasonEnable AND (tinfo^.reason = NIL) |
| 214 |
THEN |
| 215 |
tinfo^.reason := MetaString0 (InitString (message)) |
| 216 |
END ; |
| 217 |
RETURN false |
| 218 |
END falseReason0 ; |
| 219 |
|
| 220 |
|
| 221 |
(* |
| 222 |
isKnown - returns BOOLEAN:TRUE if result is status:true or status:false. |
| 223 |
*) |
| 224 |
|
| 225 |
PROCEDURE isKnown (result: status) : BOOLEAN ; |
| 226 |
BEGIN |
| 227 |
RETURN (result = true) OR (result = false) OR (result = visited) |
| 228 |
END isKnown ; |
| 229 |
|
| 230 |
|
| 231 |
(* |
| 232 |
isTrue - returns BOOLEAN:TRUE if result is status:true |
| 233 |
|
| 234 |
PROCEDURE isTrue (result: status) : BOOLEAN ; |
| 235 |
BEGIN |
| 236 |
RETURN result = true |
| 237 |
END isTrue ; |
| 238 |
*) |
| 239 |
|
| 240 |
|
| 241 |
(* |
| 242 |
isFalse - returns BOOLEAN:TRUE if result is status:false |
| 243 |
*) |
| 244 |
|
| 245 |
PROCEDURE isFalse (result: status) : BOOLEAN ; |
| 246 |
BEGIN |
| 247 |
RETURN result = false |
| 248 |
END isFalse ; |
| 249 |
|
| 250 |
|
| 251 |
(* |
| 252 |
checkTypeEquivalence - returns TRUE if left and right can be skipped and found to be equal. |
| 253 |
*) |
| 254 |
|
| 255 |
PROCEDURE checkTypeEquivalence (result: status; |
| 256 |
tinfo: tInfo; |
| 257 |
left, right: CARDINAL) : status ; |
| 258 |
BEGIN |
| 259 |
IF left = right |
| 260 |
THEN |
| 261 |
RETURN true |
| 262 |
ELSIF IsType (left) AND IsType (right) |
| 263 |
THEN |
| 264 |
IF IsHiddenType (left) AND IsHiddenType (right) |
| 265 |
THEN |
| 266 |
RETURN falseReason2 ('opaque types {%1a} {%2a} differ', tinfo, left, right) |
| 267 |
ELSIF (IsHiddenType (left) AND (right = Address)) OR |
| 268 |
(IsHiddenType (right) AND (left = Address)) |
| 269 |
THEN |
| 270 |
RETURN true |
| 271 |
END |
| 272 |
ELSIF IsTypeEquivalence (left) |
| 273 |
THEN |
| 274 |
RETURN checkPair (result, tinfo, GetDType (left), right) |
| 275 |
ELSIF IsTypeEquivalence (right) |
| 276 |
THEN |
| 277 |
RETURN checkPair (result, tinfo, left, GetDType (right)) |
| 278 |
END ; |
| 279 |
RETURN result |
| 280 |
END checkTypeEquivalence ; |
| 281 |
|
| 282 |
|
| 283 |
(* |
| 284 |
checkSubrange - check to see if subrange types left and right have the same limits. |
| 285 |
*) |
| 286 |
|
| 287 |
PROCEDURE checkSubrange (result: status; tinfo: tInfo; left, right: CARDINAL) : status ; |
| 288 |
VAR |
| 289 |
lLow, rLow, |
| 290 |
lHigh, rHigh: CARDINAL ; |
| 291 |
BEGIN |
| 292 |
(* firstly check to see if we already have resolved this as false. *) |
| 293 |
IF isFalse (result) |
| 294 |
THEN |
| 295 |
RETURN result |
| 296 |
ELSE |
| 297 |
Assert (IsSubrange (left)) ; |
| 298 |
Assert (IsSubrange (right)) ; |
| 299 |
lLow := GetTypeMin (left) ; |
| 300 |
lHigh := GetTypeMax (left) ; |
| 301 |
rLow := GetTypeMin (right) ; |
| 302 |
rHigh := GetTypeMax (right) ; |
| 303 |
PushIntegerTree (Mod2Gcc (lLow)) ; |
| 304 |
PushIntegerTree (Mod2Gcc (rLow)) ; |
| 305 |
IF NOT Equ (tinfo^.token) |
| 306 |
THEN |
| 307 |
RETURN falseReason2 ('low values of the subrange types {%1a} {%2a} differ', |
| 308 |
tinfo, left, right) |
| 309 |
END ; |
| 310 |
PushIntegerTree (Mod2Gcc (lHigh)) ; |
| 311 |
PushIntegerTree (Mod2Gcc (rHigh)) ; |
| 312 |
IF NOT Equ (tinfo^.token) |
| 313 |
THEN |
| 314 |
RETURN falseReason2 ('high values of the subrange types {%1a} {%2a} differ', |
| 315 |
tinfo, left, right) |
| 316 |
END |
| 317 |
END ; |
| 318 |
RETURN true |
| 319 |
END checkSubrange ; |
| 320 |
|
| 321 |
|
| 322 |
(* |
| 323 |
checkUnboundedArray - returns status if unbounded is parameter compatible with array. |
| 324 |
It checks all type equivalences of the static array for a |
| 325 |
match with the dynamic (unbounded) array. |
| 326 |
*) |
| 327 |
|
| 328 |
PROCEDURE checkUnboundedArray (result: status; |
| 329 |
tinfo: tInfo; |
| 330 |
unbounded, array: CARDINAL) : status ; |
| 331 |
VAR |
| 332 |
dim : CARDINAL ; |
| 333 |
ubtype, |
| 334 |
type : CARDINAL ; |
| 335 |
BEGIN |
| 336 |
(* Firstly check to see if we have resolved this as false. *) |
| 337 |
IF isFalse (result) |
| 338 |
THEN |
| 339 |
RETURN result |
| 340 |
ELSE |
| 341 |
Assert (IsUnbounded (unbounded)) ; |
| 342 |
Assert (IsArray (array)) ; |
| 343 |
dim := GetDimension (unbounded) ; |
| 344 |
ubtype := GetDType (unbounded) ; |
| 345 |
type := array ; |
| 346 |
REPEAT |
| 347 |
type := GetDType (type) ; |
| 348 |
DEC (dim) ; |
| 349 |
(* Check type equivalences. *) |
| 350 |
IF checkTypeEquivalence (result, tinfo, type, ubtype) = true |
| 351 |
THEN |
| 352 |
RETURN true |
| 353 |
END ; |
| 354 |
type := SkipType (type) ; |
| 355 |
(* If we have run out of dimensions we conclude false. *) |
| 356 |
IF dim = 0 |
| 357 |
THEN |
| 358 |
RETURN falseReason0 ('unbounded array has less dimensions than the array', |
| 359 |
tinfo) |
| 360 |
END ; |
| 361 |
UNTIL NOT IsArray (type) |
| 362 |
END ; |
| 363 |
RETURN falseReason0 ('array has less dimensions than the unbounded array', |
| 364 |
tinfo) |
| 365 |
END checkUnboundedArray ; |
| 366 |
|
| 367 |
|
| 368 |
(* |
| 369 |
checkUnboundedUnbounded - check to see if formal and actual are compatible. |
| 370 |
Both are unbounded parameters. |
| 371 |
*) |
| 372 |
|
| 373 |
PROCEDURE checkUnboundedUnbounded (result: status; |
| 374 |
tinfo: tInfo; |
| 375 |
formal, actual: CARDINAL) : status ; |
| 376 |
BEGIN |
| 377 |
(* Firstly check to see if we have resolved this as false. *) |
| 378 |
IF isFalse (result) |
| 379 |
THEN |
| 380 |
RETURN result |
| 381 |
ELSE |
| 382 |
Assert (IsUnbounded (formal)) ; |
| 383 |
Assert (IsUnbounded (actual)) ; |
| 384 |
(* The actual parameter above might be a different symbol to the actual parameter |
| 385 |
symbol in the tinfo. So we must compare the original actual parameter against |
| 386 |
the formal. |
| 387 |
The actual above maybe a temporary which is created after derefencing an array. |
| 388 |
For example 'bar[10]' where bar is defined as ARRAY OF ARRAY OF CARDINAL. |
| 389 |
The GetDimension for 'bar[10]' is 1 indicating that one dimension has been |
| 390 |
referenced. We use GetDimension for 'bar' which is 2. *) |
| 391 |
IF GetDimension (formal) # GetDimension (tinfo^.actual) |
| 392 |
THEN |
| 393 |
RETURN falseReason2 ('the formal parameter unbounded array {%1a} has a different number' + |
| 394 |
' of dimensions to the actual parameter unbounded array {%2a}', |
| 395 |
tinfo, formal, actual) |
| 396 |
END ; |
| 397 |
IF checkTypeEquivalence (result, tinfo, GetType (formal), GetType (actual)) = true |
| 398 |
THEN |
| 399 |
RETURN true |
| 400 |
END |
| 401 |
END ; |
| 402 |
RETURN falseReason2 ('the formal unbounded array type {%1a}' + |
| 403 |
' and the actual unbounded array type {%2a} differ', |
| 404 |
tinfo, formal, actual) |
| 405 |
END checkUnboundedUnbounded ; |
| 406 |
|
| 407 |
|
| 408 |
(* |
| 409 |
checkUnbounded - check to see if the unbounded is type compatible with right. |
| 410 |
This is only allowed during parameter passing. |
| 411 |
*) |
| 412 |
|
| 413 |
PROCEDURE checkUnbounded (result: status; |
| 414 |
tinfo: tInfo; |
| 415 |
unbounded, right: CARDINAL) : status ; |
| 416 |
BEGIN |
| 417 |
(* Firstly check to see if we have resolved this as false. *) |
| 418 |
IF isFalse (result) |
| 419 |
THEN |
| 420 |
RETURN result |
| 421 |
ELSE |
| 422 |
Assert (IsUnbounded (unbounded)) ; |
| 423 |
IF tinfo^.kind = parameter |
| 424 |
THEN |
| 425 |
(* Check the unbounded data type against the type of right, SYSTEM types |
| 426 |
are compared by the caller, so no need to test for them again. *) |
| 427 |
IF isSkipEquivalence (GetType (unbounded), right) |
| 428 |
THEN |
| 429 |
RETURN true |
| 430 |
ELSIF IsType (right) |
| 431 |
THEN |
| 432 |
IF GetType (right) = NulSym |
| 433 |
THEN |
| 434 |
(* Base type check. *) |
| 435 |
RETURN checkPair (result, tinfo, GetType (unbounded), right) |
| 436 |
ELSE |
| 437 |
(* It is safe to GetType (right) and we check the pair |
| 438 |
[unbounded, GetType (right)]. *) |
| 439 |
RETURN checkPair (result, tinfo, unbounded, GetType (right)) |
| 440 |
END |
| 441 |
ELSIF IsArray (right) |
| 442 |
THEN |
| 443 |
RETURN checkUnboundedArray (result, tinfo, unbounded, right) |
| 444 |
ELSIF IsUnbounded (right) |
| 445 |
THEN |
| 446 |
RETURN checkUnboundedUnbounded (result, tinfo, unbounded, right) |
| 447 |
ELSE |
| 448 |
RETURN falseReason2 ('the formal unbounded array type {%1a}' + |
| 449 |
' and the actual unbounded array type {%2a} differ', |
| 450 |
tinfo, unbounded, right) |
| 451 |
END |
| 452 |
END |
| 453 |
END ; |
| 454 |
RETURN false |
| 455 |
END checkUnbounded ; |
| 456 |
|
| 457 |
|
| 458 |
(* |
| 459 |
checkArrayTypeEquivalence - check array and unbounded array type equivalence. |
| 460 |
*) |
| 461 |
|
| 462 |
PROCEDURE checkArrayTypeEquivalence (result: status; tinfo: tInfo; |
| 463 |
left, right: CARDINAL) : status ; |
| 464 |
VAR |
| 465 |
lSub , rSub: CARDINAL ; |
| 466 |
BEGIN |
| 467 |
IF isFalse (result) |
| 468 |
THEN |
| 469 |
RETURN result |
| 470 |
ELSIF IsArray (left) AND IsArray (right) |
| 471 |
THEN |
| 472 |
lSub := GetArraySubscript (left) ; |
| 473 |
rSub := GetArraySubscript (right) ; |
| 474 |
result := checkPair (result, tinfo, GetDType (left), GetDType (right)) ; |
| 475 |
IF (lSub # NulSym) AND (rSub # NulSym) |
| 476 |
THEN |
| 477 |
result := checkSubrange (result, tinfo, getSType (lSub), getSType (rSub)) |
| 478 |
END |
| 479 |
ELSIF IsUnbounded (left) AND (IsArray (right) OR IsUnbounded (right)) |
| 480 |
THEN |
| 481 |
IF IsGenericSystemType (getSType (left)) OR IsGenericSystemType (getSType (right)) |
| 482 |
THEN |
| 483 |
RETURN true |
| 484 |
ELSE |
| 485 |
result := checkUnbounded (result, tinfo, left, right) |
| 486 |
END |
| 487 |
ELSIF IsUnbounded (right) AND (IsArray (left) OR IsUnbounded (left)) |
| 488 |
THEN |
| 489 |
IF IsGenericSystemType (getSType (right)) OR IsGenericSystemType (getSType (left)) |
| 490 |
THEN |
| 491 |
RETURN true |
| 492 |
ELSE |
| 493 |
result := checkUnbounded (result, tinfo, right, left) |
| 494 |
END |
| 495 |
ELSIF IsArray (left) AND IsConst (right) |
| 496 |
THEN |
| 497 |
result := checkPair (result, tinfo, GetDType (left), GetDType (right)) |
| 498 |
ELSIF IsArray (right) AND IsConst (left) |
| 499 |
THEN |
| 500 |
result := checkPair (result, tinfo, GetDType (left), GetDType (right)) |
| 501 |
END ; |
| 502 |
RETURN result |
| 503 |
END checkArrayTypeEquivalence ; |
| 504 |
|
| 505 |
|
| 506 |
(* |
| 507 |
checkCharStringTypeEquivalence - check char and string constants for type equivalence. |
| 508 |
*) |
| 509 |
|
| 510 |
PROCEDURE checkCharStringTypeEquivalence (result: status; tinfo: tInfo; |
| 511 |
left, right: CARDINAL) : status ; |
| 512 |
BEGIN |
| 513 |
IF isFalse (result) |
| 514 |
THEN |
| 515 |
RETURN result |
| 516 |
ELSIF left = Char |
| 517 |
THEN |
| 518 |
IF IsConst (right) |
| 519 |
THEN |
| 520 |
(* We might not know the length of the string yet, in which case we return true. *) |
| 521 |
IF IsConstString (right) AND |
| 522 |
((NOT GccKnowsAbout (right)) OR (GetStringLength (tinfo^.token, right) <= 1)) |
| 523 |
THEN |
| 524 |
RETURN true |
| 525 |
ELSE |
| 526 |
RETURN falseReason2 ('the string {%2a} does not fit into a {%1a}', |
| 527 |
tinfo, left, right) |
| 528 |
END |
| 529 |
ELSIF IsParameter (right) |
| 530 |
THEN |
| 531 |
right := GetDType (right) ; |
| 532 |
IF (right = Char) OR (IsUnbounded (right) AND (SkipType (GetDType (right)) = Char)) |
| 533 |
THEN |
| 534 |
RETURN true |
| 535 |
END |
| 536 |
ELSIF IsArray (right) |
| 537 |
THEN |
| 538 |
IF Char = SkipType (GetDType (right)) |
| 539 |
THEN |
| 540 |
RETURN true |
| 541 |
END |
| 542 |
END |
| 543 |
ELSIF right = Char |
| 544 |
THEN |
| 545 |
RETURN checkCharStringTypeEquivalence (result, tinfo, right, left) |
| 546 |
END ; |
| 547 |
RETURN result |
| 548 |
END checkCharStringTypeEquivalence ; |
| 549 |
|
| 550 |
|
| 551 |
(* |
| 552 |
firstTime - returns TRUE if the triple (token, left, right) has not been seen before. |
| 553 |
*) |
| 554 |
|
| 555 |
PROCEDURE firstTime (token: CARDINAL; left, right: CARDINAL) : BOOLEAN ; |
| 556 |
VAR |
| 557 |
p : errorSig ; |
| 558 |
i, n: CARDINAL ; |
| 559 |
BEGIN |
| 560 |
i := 1 ; |
| 561 |
n := HighIndice (errors) ; |
| 562 |
WHILE i <= n DO |
| 563 |
p := GetIndice (errors, i) ; |
| 564 |
IF (p^.token = token) AND (p^.left = left) AND (p^.right = right) |
| 565 |
THEN |
| 566 |
RETURN FALSE |
| 567 |
END ; |
| 568 |
INC (i) |
| 569 |
END ; |
| 570 |
NEW (p) ; |
| 571 |
p^.token := token ; |
| 572 |
p^.left := left ; |
| 573 |
p^.right := right ; |
| 574 |
IncludeIndiceIntoIndex (errors, p) ; |
| 575 |
RETURN TRUE |
| 576 |
END firstTime ; |
| 577 |
|
| 578 |
|
| 579 |
(* |
| 580 |
buildError4 - generate a MetaString4 error. This is only used when checking |
| 581 |
parameter compatibility. |
| 582 |
*) |
| 583 |
|
| 584 |
PROCEDURE buildError4 (tinfo: tInfo; left, right: CARDINAL) ; |
| 585 |
VAR |
| 586 |
s: String ; |
| 587 |
BEGIN |
| 588 |
IF firstTime (tinfo^.token, left, right) |
| 589 |
THEN |
| 590 |
IF tinfo^.error = NIL |
| 591 |
THEN |
| 592 |
(* We need to create top level error message first. *) |
| 593 |
tinfo^.error := NewError (tinfo^.token) ; |
| 594 |
(* The parameters to MetaString4 in buildError4 must match the order |
| 595 |
of paramters passed to ParameterTypeCompatible. *) |
| 596 |
s := MetaString4 (tinfo^.format, |
| 597 |
tinfo^.procedure, |
| 598 |
tinfo^.formal, tinfo^.actual, |
| 599 |
tinfo^.nth) ; |
| 600 |
(* Append the overall reason for the failure. *) |
| 601 |
IF tinfo^.reason # NIL |
| 602 |
THEN |
| 603 |
(* The string tinfo^.reason is given to the error handler. *) |
| 604 |
s := ConCat (s, Mark (InitString (" because "))) ; |
| 605 |
s := ConCat (s, tinfo^.reason) ; |
| 606 |
tinfo^.reason := NIL (* Hand over deconstructing to M2MetaError. *) |
| 607 |
END ; |
| 608 |
ErrorString (tinfo^.error, s) |
| 609 |
END ; |
| 610 |
(* And now also generate a sub error containing detail. *) |
| 611 |
IF (left # tinfo^.left) OR (right # tinfo^.right) |
| 612 |
THEN |
| 613 |
MetaError1 ('formal parameter {%1EDad}', right) ; |
| 614 |
MetaError1 ('actual parameter {%1EDad}', left) |
| 615 |
END |
| 616 |
END |
| 617 |
END buildError4 ; |
| 618 |
|
| 619 |
|
| 620 |
(* |
| 621 |
buildError2 - generate a MetaString2 error. |
| 622 |
*) |
| 623 |
|
| 624 |
PROCEDURE buildError2 (tinfo: tInfo; left, right: CARDINAL) ; |
| 625 |
VAR |
| 626 |
s: String ; |
| 627 |
BEGIN |
| 628 |
IF firstTime (tinfo^.token, left, right) |
| 629 |
THEN |
| 630 |
IF tinfo^.error = NIL |
| 631 |
THEN |
| 632 |
(* Need to create top level error message first. *) |
| 633 |
tinfo^.error := NewError (tinfo^.token) ; |
| 634 |
s := MetaString2 (tinfo^.format, |
| 635 |
tinfo^.left, tinfo^.right) ; |
| 636 |
ErrorString (tinfo^.error, s) |
| 637 |
END ; |
| 638 |
(* Also generate a sub error containing detail. *) |
| 639 |
IF (left # tinfo^.left) OR (right # tinfo^.right) |
| 640 |
THEN |
| 641 |
tinfo^.error := ChainError (tinfo^.token, tinfo^.error) ; |
| 642 |
CASE tinfo^.kind OF |
| 643 |
|
| 644 |
parameter: s := MetaString2 (InitString ("{%1Ead} and {%2ad} are incompatible as formal and actual procedure parameters"), |
| 645 |
left, right) | |
| 646 |
assignment: s := MetaString2 (InitString ("{%1Ead} and {%2ad} are assignment incompatible"), |
| 647 |
left, right) | |
| 648 |
expression: s := MetaString2 (InitString ("{%1Ead} and {%2ad} are expression incompatible"), |
| 649 |
left, right) |
| 650 |
|
| 651 |
END ; |
| 652 |
(* Lastly the overall reason for the failure. *) |
| 653 |
IF tinfo^.reason # NIL |
| 654 |
THEN |
| 655 |
(* The string tinfo^.reason is given to the error handler. *) |
| 656 |
s := ConCat (s, Mark (InitString (" because "))) ; |
| 657 |
s := ConCat (s, tinfo^.reason) ; |
| 658 |
tinfo^.reason := NIL (* Hand over deconstructing to M2MetaError. *) |
| 659 |
END ; |
| 660 |
ErrorString (tinfo^.error, s) |
| 661 |
END |
| 662 |
END |
| 663 |
END buildError2 ; |
| 664 |
|
| 665 |
|
| 666 |
(* |
| 667 |
issueError - |
| 668 |
*) |
| 669 |
|
| 670 |
PROCEDURE issueError (result: BOOLEAN; tinfo: tInfo; left, right: CARDINAL) : status ; |
| 671 |
BEGIN |
| 672 |
IF result |
| 673 |
THEN |
| 674 |
RETURN true |
| 675 |
ELSE |
| 676 |
(* Check whether errors are required. *) |
| 677 |
IF tinfo^.format # NIL |
| 678 |
THEN |
| 679 |
CASE tinfo^.kind OF |
| 680 |
|
| 681 |
parameter : buildError4 (tinfo, left, right) | |
| 682 |
assignment: buildError2 (tinfo, left, right) | |
| 683 |
expression: buildError2 (tinfo, left, right) |
| 684 |
|
| 685 |
END ; |
| 686 |
tinfo^.format := NIL (* string is used by MetaError now. *) |
| 687 |
END ; |
| 688 |
RETURN false |
| 689 |
END |
| 690 |
END issueError ; |
| 691 |
|
| 692 |
|
| 693 |
(* |
| 694 |
checkBaseEquivalence - the catch all check for types not specifically |
| 695 |
handled by this module. |
| 696 |
*) |
| 697 |
|
| 698 |
PROCEDURE checkBaseEquivalence (result: status; tinfo: tInfo; |
| 699 |
left, right: CARDINAL) : status ; |
| 700 |
BEGIN |
| 701 |
IF isKnown (result) |
| 702 |
THEN |
| 703 |
RETURN result |
| 704 |
ELSE |
| 705 |
CASE tinfo^.kind OF |
| 706 |
|
| 707 |
parameter : IF tinfo^.isvar |
| 708 |
THEN |
| 709 |
RETURN issueError (IsExpressionCompatible (left, right), |
| 710 |
tinfo, left, right) |
| 711 |
ELSE |
| 712 |
RETURN issueError (IsAssignmentCompatible (left, right), |
| 713 |
tinfo, left, right) |
| 714 |
END | |
| 715 |
assignment: RETURN issueError (IsAssignmentCompatible (left, right), |
| 716 |
tinfo, left, right) | |
| 717 |
expression: IF tinfo^.isin |
| 718 |
THEN |
| 719 |
IF IsVar (right) OR IsConst (right) |
| 720 |
THEN |
| 721 |
right := getSType (right) |
| 722 |
END |
| 723 |
END ; |
| 724 |
IF tinfo^.strict |
| 725 |
THEN |
| 726 |
RETURN issueError (IsComparisonCompatible (left, right), |
| 727 |
tinfo, left, right) |
| 728 |
ELSE |
| 729 |
RETURN issueError (IsExpressionCompatible (left, right), |
| 730 |
tinfo, left, right) |
| 731 |
END |
| 732 |
|
| 733 |
ELSE |
| 734 |
InternalError ('unexpected kind value') |
| 735 |
END |
| 736 |
END |
| 737 |
(* should never reach here. *) |
| 738 |
END checkBaseEquivalence ; |
| 739 |
|
| 740 |
|
| 741 |
(* |
| 742 |
checkPair - check whether left and right are type compatible. |
| 743 |
It will update the visited, unresolved list before |
| 744 |
calling the docheckPair for the cascaded type checking. |
| 745 |
Pre-condition: tinfo is initialized. |
| 746 |
left and right are modula2 symbols. |
| 747 |
Post-condition: tinfo visited, resolved, unresolved lists |
| 748 |
are updated and the result status is |
| 749 |
returned. |
| 750 |
*) |
| 751 |
|
| 752 |
PROCEDURE checkPair (result: status; tinfo: tInfo; |
| 753 |
left, right: CARDINAL) : status ; |
| 754 |
BEGIN |
| 755 |
IF isFalse (result) |
| 756 |
THEN |
| 757 |
exclude (tinfo^.visited, left, right) ; |
| 758 |
RETURN result |
| 759 |
ELSE |
| 760 |
IF in (tinfo^.resolved, left, right) |
| 761 |
THEN |
| 762 |
exclude (tinfo^.visited, left, right) ; |
| 763 |
RETURN getStatus (tinfo^.resolved, left, right) |
| 764 |
ELSIF in (tinfo^.visited, left, right) |
| 765 |
THEN |
| 766 |
RETURN visited |
| 767 |
ELSE |
| 768 |
IF debugging |
| 769 |
THEN |
| 770 |
printf (" marked as visited (%d, %d)\n", left, right) |
| 771 |
END ; |
| 772 |
include (tinfo^.visited, left, right, unknown) ; |
| 773 |
include (tinfo^.unresolved, left, right, unknown) |
| 774 |
END ; |
| 775 |
RETURN doCheckPair (result, tinfo, left, right) |
| 776 |
END |
| 777 |
END checkPair ; |
| 778 |
|
| 779 |
|
| 780 |
(* |
| 781 |
useBaseCheck - |
| 782 |
*) |
| 783 |
|
| 784 |
PROCEDURE useBaseCheck (sym: CARDINAL) : BOOLEAN ; |
| 785 |
BEGIN |
| 786 |
RETURN IsBaseType (sym) OR IsSystemType (sym) OR IsMathType (sym) OR IsComplexType (sym) |
| 787 |
END useBaseCheck ; |
| 788 |
|
| 789 |
|
| 790 |
(* |
| 791 |
checkBaseTypeEquivalence - |
| 792 |
*) |
| 793 |
|
| 794 |
PROCEDURE checkBaseTypeEquivalence (result: status; tinfo: tInfo; |
| 795 |
left, right: CARDINAL) : status ; |
| 796 |
BEGIN |
| 797 |
IF isFalse (result) |
| 798 |
THEN |
| 799 |
RETURN result |
| 800 |
ELSIF useBaseCheck (left) AND useBaseCheck (right) |
| 801 |
THEN |
| 802 |
RETURN checkBaseEquivalence (result, tinfo, left, right) |
| 803 |
ELSE |
| 804 |
RETURN result |
| 805 |
END |
| 806 |
END checkBaseTypeEquivalence ; |
| 807 |
|
| 808 |
|
| 809 |
(* |
| 810 |
IsTyped - returns TRUE if sym will have a type. |
| 811 |
*) |
| 812 |
|
| 813 |
PROCEDURE IsTyped (sym: CARDINAL) : BOOLEAN ; |
| 814 |
BEGIN |
| 815 |
RETURN IsVar (sym) OR IsParameter (sym) OR IsConstructor (sym) OR |
| 816 |
(IsConst (sym) AND IsConstructor (sym)) OR IsParameter (sym) OR |
| 817 |
(IsConst (sym) AND (GetDType (sym) # NulSym)) |
| 818 |
END IsTyped ; |
| 819 |
|
| 820 |
|
| 821 |
(* |
| 822 |
IsTypeEquivalence - returns TRUE if sym is a type equivalence symbol. |
| 823 |
*) |
| 824 |
|
| 825 |
PROCEDURE IsTypeEquivalence (sym: CARDINAL) : BOOLEAN ; |
| 826 |
BEGIN |
| 827 |
RETURN IsType (sym) AND (GetDType (sym) # NulSym) AND (GetDType (sym) # sym) |
| 828 |
END IsTypeEquivalence ; |
| 829 |
|
| 830 |
|
| 831 |
(* |
| 832 |
isLValue - |
| 833 |
*) |
| 834 |
|
| 835 |
PROCEDURE isLValue (sym: CARDINAL) : BOOLEAN ; |
| 836 |
BEGIN |
| 837 |
RETURN IsVar (sym) AND (GetMode (sym) = LeftValue) |
| 838 |
END isLValue ; |
| 839 |
|
| 840 |
|
| 841 |
(* |
| 842 |
checkVarTypeEquivalence - |
| 843 |
*) |
| 844 |
|
| 845 |
PROCEDURE checkVarTypeEquivalence (result: status; tinfo: tInfo; |
| 846 |
left, right: CARDINAL) : status ; |
| 847 |
BEGIN |
| 848 |
IF isFalse (result) |
| 849 |
THEN |
| 850 |
RETURN result |
| 851 |
ELSIF (left = NulSym) OR (right = NulSym) |
| 852 |
THEN |
| 853 |
RETURN true |
| 854 |
ELSE |
| 855 |
IF IsVar (left) OR IsVar (right) |
| 856 |
THEN |
| 857 |
(* Either left or right will change, so we can call doCheckPair. *) |
| 858 |
IF IsVar (left) |
| 859 |
THEN |
| 860 |
left := getType (left) |
| 861 |
END ; |
| 862 |
IF IsVar (right) |
| 863 |
THEN |
| 864 |
right := getType (right) |
| 865 |
END ; |
| 866 |
RETURN doCheckPair (result, tinfo, left, right) |
| 867 |
END |
| 868 |
END ; |
| 869 |
RETURN result |
| 870 |
END checkVarTypeEquivalence ; |
| 871 |
|
| 872 |
|
| 873 |
(* |
| 874 |
checkVarEquivalence - this test must be done early as it checks the symbol mode. |
| 875 |
An LValue is treated as a pointer during assignment and the |
| 876 |
LValue is attached to a variable. This function skips the variable |
| 877 |
and checks the types - after it has considered a possible LValue. |
| 878 |
*) |
| 879 |
|
| 880 |
PROCEDURE checkVarEquivalence (result: status; tinfo: tInfo; |
| 881 |
des, expr: CARDINAL) : status ; |
| 882 |
BEGIN |
| 883 |
IF isFalse (result) |
| 884 |
THEN |
| 885 |
RETURN result |
| 886 |
ELSIF IsTyped (des) OR IsTyped (expr) |
| 887 |
THEN |
| 888 |
IF tinfo^.kind = assignment |
| 889 |
THEN |
| 890 |
IF GetDType (des) = GetDType (expr) |
| 891 |
THEN |
| 892 |
RETURN true |
| 893 |
(* LValues are only relevant during assignment. *) |
| 894 |
ELSIF isLValue (des) AND (NOT isLValue (expr)) |
| 895 |
THEN |
| 896 |
IF SkipType (getType (expr)) = Address |
| 897 |
THEN |
| 898 |
RETURN true |
| 899 |
ELSIF IsPointer (SkipType (getType (expr))) |
| 900 |
THEN |
| 901 |
expr := GetDType (SkipType (getType (expr))) ; |
| 902 |
RETURN doCheckPair (result, tinfo, getType (des), expr) |
| 903 |
END |
| 904 |
ELSIF isLValue (expr) AND (NOT isLValue (des)) |
| 905 |
THEN |
| 906 |
IF SkipType (getType (des)) = Address |
| 907 |
THEN |
| 908 |
RETURN true |
| 909 |
ELSIF IsPointer (SkipType (getType (des))) |
| 910 |
THEN |
| 911 |
des := GetDType (SkipType (getType (des))) ; |
| 912 |
RETURN doCheckPair (result, tinfo, des, getType (expr)) |
| 913 |
END |
| 914 |
END |
| 915 |
END ; |
| 916 |
RETURN doCheckPair (result, tinfo, getType (des), getType (expr)) |
| 917 |
END ; |
| 918 |
RETURN result |
| 919 |
END checkVarEquivalence ; |
| 920 |
|
| 921 |
|
| 922 |
(* |
| 923 |
checkConstMeta - performs a very course grained check against |
| 924 |
obviously incompatible type kinds. |
| 925 |
If left is a const string then it checks right against char. |
| 926 |
*) |
| 927 |
|
| 928 |
PROCEDURE checkConstMeta (result: status; tinfo: tInfo; |
| 929 |
left, right: CARDINAL) : status ; |
| 930 |
VAR |
| 931 |
typeLeft, |
| 932 |
typeRight: CARDINAL ; |
| 933 |
BEGIN |
| 934 |
Assert (IsConst (left)) ; |
| 935 |
IF isFalse (result) |
| 936 |
THEN |
| 937 |
RETURN result |
| 938 |
ELSIF IsConstString (left) |
| 939 |
THEN |
| 940 |
IF IsConstString (right) |
| 941 |
THEN |
| 942 |
RETURN true |
| 943 |
ELSIF IsTyped (right) |
| 944 |
THEN |
| 945 |
typeRight := GetDType (right) ; |
| 946 |
IF typeRight = NulSym |
| 947 |
THEN |
| 948 |
RETURN result |
| 949 |
ELSIF IsSet (typeRight) OR IsEnumeration (typeRight) OR |
| 950 |
IsProcedure (typeRight) OR IsRecord (typeRight) OR |
| 951 |
IsReallyPointer (typeRight) |
| 952 |
THEN |
| 953 |
RETURN falseReason1 ('constant string is incompatible with {%1ad}', |
| 954 |
tinfo, typeRight) |
| 955 |
ELSIF IsArray (typeRight) |
| 956 |
THEN |
| 957 |
RETURN doCheckPair (result, tinfo, Char, GetDType (typeRight)) |
| 958 |
ELSIF NOT GccKnowsAbout (left) |
| 959 |
THEN |
| 960 |
(* We do not know the length of this string, so assume true. *) |
| 961 |
RETURN true |
| 962 |
ELSIF GetStringLength (tinfo^.token, left) = 1 |
| 963 |
THEN |
| 964 |
RETURN doCheckPair (result, tinfo, Char, typeRight) |
| 965 |
END |
| 966 |
END |
| 967 |
ELSIF IsTyped (left) AND IsTyped (right) |
| 968 |
THEN |
| 969 |
typeRight := GetDType (right) ; |
| 970 |
typeLeft := GetDType (left) ; |
| 971 |
IF IsZRCType (typeLeft) AND IsUnbounded (typeRight) |
| 972 |
THEN |
| 973 |
RETURN falseReason2 ('the constant {%1a} is incompatible' + |
| 974 |
' with an unbounded array of {%2a}', |
| 975 |
tinfo, typeLeft, typeRight) |
| 976 |
ELSE |
| 977 |
RETURN doCheckPair (result, tinfo, typeLeft, typeRight) |
| 978 |
END |
| 979 |
END ; |
| 980 |
RETURN result |
| 981 |
END checkConstMeta ; |
| 982 |
|
| 983 |
|
| 984 |
(* |
| 985 |
checkEnumField - |
| 986 |
*) |
| 987 |
|
| 988 |
PROCEDURE checkEnumField (result: status; tinfo: tInfo; |
| 989 |
left, right: CARDINAL) : status ; |
| 990 |
VAR |
| 991 |
typeRight: CARDINAL ; |
| 992 |
BEGIN |
| 993 |
Assert (IsFieldEnumeration (left)) ; |
| 994 |
IF isFalse (result) |
| 995 |
THEN |
| 996 |
RETURN result |
| 997 |
ELSIF IsTyped (right) |
| 998 |
THEN |
| 999 |
typeRight := GetDType (right) ; |
| 1000 |
IF typeRight = NulSym |
| 1001 |
THEN |
| 1002 |
RETURN result |
| 1003 |
ELSE |
| 1004 |
RETURN doCheckPair (result, tinfo, GetDType (left), typeRight) |
| 1005 |
END |
| 1006 |
END ; |
| 1007 |
RETURN result |
| 1008 |
END checkEnumField ; |
| 1009 |
|
| 1010 |
|
| 1011 |
(* |
| 1012 |
checkEnumFieldEquivalence - |
| 1013 |
*) |
| 1014 |
|
| 1015 |
PROCEDURE checkEnumFieldEquivalence (result: status; tinfo: tInfo; |
| 1016 |
left, right: CARDINAL) : status ; |
| 1017 |
BEGIN |
| 1018 |
IF isFalse (result) |
| 1019 |
THEN |
| 1020 |
RETURN result |
| 1021 |
ELSIF (left = NulSym) OR (right = NulSym) |
| 1022 |
THEN |
| 1023 |
(* No option but to return true. *) |
| 1024 |
RETURN true |
| 1025 |
ELSIF IsFieldEnumeration (left) |
| 1026 |
THEN |
| 1027 |
RETURN checkEnumField (result, tinfo, left, right) |
| 1028 |
ELSIF IsFieldEnumeration (right) |
| 1029 |
THEN |
| 1030 |
RETURN checkEnumField (result, tinfo, right, left) |
| 1031 |
END ; |
| 1032 |
RETURN result |
| 1033 |
END checkEnumFieldEquivalence ; |
| 1034 |
|
| 1035 |
|
| 1036 |
(* |
| 1037 |
checkConstEquivalence - this check can be done first as it checks symbols which |
| 1038 |
may have no type. Ie constant strings. These constants |
| 1039 |
will likely have their type set during quadruple folding. |
| 1040 |
But we can check the meta type for obvious mismatches |
| 1041 |
early on. For example adding a string to an enum or set. |
| 1042 |
*) |
| 1043 |
|
| 1044 |
PROCEDURE checkConstEquivalence (result: status; tinfo: tInfo; |
| 1045 |
left, right: CARDINAL) : status ; |
| 1046 |
BEGIN |
| 1047 |
IF isFalse (result) |
| 1048 |
THEN |
| 1049 |
RETURN result |
| 1050 |
ELSIF (left = NulSym) OR (right = NulSym) |
| 1051 |
THEN |
| 1052 |
(* No option but to return true. *) |
| 1053 |
RETURN true |
| 1054 |
ELSIF IsConst (left) |
| 1055 |
THEN |
| 1056 |
RETURN checkConstMeta (result, tinfo, left, right) |
| 1057 |
ELSIF IsConst (right) |
| 1058 |
THEN |
| 1059 |
RETURN checkConstMeta (result, tinfo, right, left) |
| 1060 |
END ; |
| 1061 |
RETURN result |
| 1062 |
END checkConstEquivalence ; |
| 1063 |
|
| 1064 |
|
| 1065 |
(* |
| 1066 |
checkSubrangeTypeEquivalence - |
| 1067 |
*) |
| 1068 |
|
| 1069 |
PROCEDURE checkSubrangeTypeEquivalence (result: status; tinfo: tInfo; |
| 1070 |
left, right: CARDINAL) : status ; |
| 1071 |
BEGIN |
| 1072 |
IF isFalse (result) |
| 1073 |
THEN |
| 1074 |
RETURN result |
| 1075 |
ELSE |
| 1076 |
IF IsSubrange (left) |
| 1077 |
THEN |
| 1078 |
RETURN doCheckPair (result, tinfo, GetDType (left), right) |
| 1079 |
END ; |
| 1080 |
IF IsSubrange (right) |
| 1081 |
THEN |
| 1082 |
RETURN doCheckPair (result, tinfo, left, GetDType (right)) |
| 1083 |
END |
| 1084 |
END ; |
| 1085 |
RETURN result |
| 1086 |
END checkSubrangeTypeEquivalence ; |
| 1087 |
|
| 1088 |
|
| 1089 |
(* |
| 1090 |
IsZRCType - return TRUE if type is a ZType, RType or a CType. |
| 1091 |
*) |
| 1092 |
|
| 1093 |
PROCEDURE IsZRCType (type: CARDINAL) : BOOLEAN ; |
| 1094 |
BEGIN |
| 1095 |
RETURN (type = CType) OR (type = ZType) OR (type = RType) |
| 1096 |
END IsZRCType ; |
| 1097 |
|
| 1098 |
|
| 1099 |
(* |
| 1100 |
isZRC - return TRUE if zrc is a ZType, RType or a CType |
| 1101 |
and sym is either a complex type when zrc = CType |
| 1102 |
or is not a composite type when zrc is a RType or ZType. |
| 1103 |
*) |
| 1104 |
|
| 1105 |
PROCEDURE isZRC (zrc, sym: CARDINAL) : BOOLEAN ; |
| 1106 |
BEGIN |
| 1107 |
IF IsConst (sym) |
| 1108 |
THEN |
| 1109 |
sym := SkipType (GetDType (sym)) |
| 1110 |
END ; |
| 1111 |
IF (zrc = CType) AND (IsComplexN (sym) OR IsComplexType (sym)) |
| 1112 |
THEN |
| 1113 |
RETURN TRUE |
| 1114 |
END ; |
| 1115 |
RETURN (zrc = sym) OR ((zrc = ZType) OR (zrc = RType) AND (NOT IsComposite (sym))) |
| 1116 |
END isZRC ; |
| 1117 |
|
| 1118 |
|
| 1119 |
(* |
| 1120 |
isSameSizeConst - |
| 1121 |
|
| 1122 |
*) |
| 1123 |
|
| 1124 |
PROCEDURE isSameSizeConst (a, b: CARDINAL) : BOOLEAN ; |
| 1125 |
BEGIN |
| 1126 |
IF IsConst (a) |
| 1127 |
THEN |
| 1128 |
a := SkipType (GetDType (a)) ; |
| 1129 |
RETURN isZRC (a, b) OR (a = b) OR ((a # NulSym) AND isSameSize (a, b)) |
| 1130 |
ELSIF IsConst (b) |
| 1131 |
THEN |
| 1132 |
b := SkipType (GetDType (b)) ; |
| 1133 |
RETURN isZRC (b, a) OR (a = b) OR ((b # NulSym) AND isSameSize (a, b)) |
| 1134 |
END ; |
| 1135 |
RETURN FALSE |
| 1136 |
END isSameSizeConst ; |
| 1137 |
|
| 1138 |
|
| 1139 |
(* |
| 1140 |
isSameSize - should only be called if either a or b are WORD, BYTE, etc. |
| 1141 |
*) |
| 1142 |
|
| 1143 |
PROCEDURE isSameSize (a, b: CARDINAL) : BOOLEAN ; |
| 1144 |
BEGIN |
| 1145 |
RETURN isSameSizeConst (a, b) OR IsSameSize (a, b) |
| 1146 |
END isSameSize ; |
| 1147 |
|
| 1148 |
|
| 1149 |
(* |
| 1150 |
checkSystemEquivalence - check whether left and right are system types and whether they have the same size. |
| 1151 |
*) |
| 1152 |
|
| 1153 |
PROCEDURE checkSystemEquivalence (result: status; tinfo: tInfo <* unused *>; |
| 1154 |
left, right: CARDINAL) : status ; |
| 1155 |
BEGIN |
| 1156 |
IF isFalse (result) OR (result = visited) |
| 1157 |
THEN |
| 1158 |
RETURN result |
| 1159 |
ELSE |
| 1160 |
IF (IsGenericSystemType (left) OR IsGenericSystemType (right)) AND |
| 1161 |
GccKnowsAbout (left) AND GccKnowsAbout (right) AND |
| 1162 |
isSameSize (left, right) |
| 1163 |
THEN |
| 1164 |
RETURN true |
| 1165 |
END |
| 1166 |
END ; |
| 1167 |
RETURN result |
| 1168 |
END checkSystemEquivalence ; |
| 1169 |
|
| 1170 |
|
| 1171 |
(* |
| 1172 |
checkTypeKindViolation - returns false if one operand left or right is |
| 1173 |
a set, record or array. |
| 1174 |
*) |
| 1175 |
|
| 1176 |
PROCEDURE checkTypeKindViolation (result: status; tinfo: tInfo; |
| 1177 |
left, right: CARDINAL) : status ; |
| 1178 |
BEGIN |
| 1179 |
IF isFalse (result) OR (result = visited) |
| 1180 |
THEN |
| 1181 |
RETURN result |
| 1182 |
ELSE |
| 1183 |
(* We have checked IsSet (left) and IsSet (right) etc in doCheckPair. *) |
| 1184 |
IF (IsSet (left) OR IsSet (right)) OR |
| 1185 |
(IsRecord (left) OR IsRecord (right)) OR |
| 1186 |
(IsArray (left) OR IsArray (right)) |
| 1187 |
THEN |
| 1188 |
RETURN falseReason2 ('a {%1ad} is incompatible with a {%2ad}', |
| 1189 |
tinfo, left, right) |
| 1190 |
END |
| 1191 |
END ; |
| 1192 |
RETURN result |
| 1193 |
END checkTypeKindViolation ; |
| 1194 |
|
| 1195 |
|
| 1196 |
(* |
| 1197 |
doCheckPair - invoke a series of type checks checking compatibility |
| 1198 |
between left and right modula2 symbols. |
| 1199 |
Pre-condition: left and right are modula-2 symbols. |
| 1200 |
tinfo is configured. |
| 1201 |
Post-condition: status is returned determining the |
| 1202 |
correctness of the type check. |
| 1203 |
The tinfo resolved, unresolved, visited |
| 1204 |
lists will be updated. |
| 1205 |
*) |
| 1206 |
|
| 1207 |
PROCEDURE doCheckPair (result: status; tinfo: tInfo; |
| 1208 |
left, right: CARDINAL) : status ; |
| 1209 |
VAR |
| 1210 |
i: CARDINAL ; |
| 1211 |
BEGIN |
| 1212 |
IF (left = NulSym) OR (right = NulSym) |
| 1213 |
THEN |
| 1214 |
(* We cannot check NulSym. *) |
| 1215 |
RETURN true |
| 1216 |
ELSIF isKnown (result) |
| 1217 |
THEN |
| 1218 |
RETURN return (result, tinfo, left, right) |
| 1219 |
ELSIF left = right |
| 1220 |
THEN |
| 1221 |
RETURN return (true, tinfo, left, right) |
| 1222 |
ELSE |
| 1223 |
i := 1 ; |
| 1224 |
WHILE i <= HighEquivalence DO |
| 1225 |
result := Equivalence[i] (result, tinfo, left, right) ; |
| 1226 |
IF isKnown (result) |
| 1227 |
THEN |
| 1228 |
RETURN return (result, tinfo, left, right) |
| 1229 |
END ; |
| 1230 |
INC (i) |
| 1231 |
END |
| 1232 |
END ; |
| 1233 |
RETURN return (result, tinfo, left, right) |
| 1234 |
END doCheckPair ; |
| 1235 |
|
| 1236 |
|
| 1237 |
(* |
| 1238 |
InitEquivalenceArray - populate the Equivalence array with the |
| 1239 |
checking procedures. |
| 1240 |
*) |
| 1241 |
|
| 1242 |
PROCEDURE InitEquivalenceArray ; |
| 1243 |
BEGIN |
| 1244 |
HighEquivalence := 0 ; |
| 1245 |
addEquivalence (checkVarEquivalence) ; |
| 1246 |
addEquivalence (checkVarTypeEquivalence) ; |
| 1247 |
addEquivalence (checkCharStringTypeEquivalence) ; |
| 1248 |
addEquivalence (checkConstEquivalence); |
| 1249 |
addEquivalence (checkEnumFieldEquivalence) ; |
| 1250 |
addEquivalence (checkSystemEquivalence) ; |
| 1251 |
addEquivalence (checkSubrangeTypeEquivalence) ; |
| 1252 |
addEquivalence (checkBaseTypeEquivalence) ; |
| 1253 |
addEquivalence (checkTypeEquivalence) ; |
| 1254 |
addEquivalence (checkArrayTypeEquivalence) ; |
| 1255 |
addEquivalence (checkTypeKindEquivalence) ; |
| 1256 |
addEquivalence (checkTypeKindViolation) |
| 1257 |
END InitEquivalenceArray ; |
| 1258 |
|
| 1259 |
|
| 1260 |
(* |
| 1261 |
addEquivalence - places proc into Equivalence array. |
| 1262 |
*) |
| 1263 |
|
| 1264 |
PROCEDURE addEquivalence (proc: EquivalenceProcedure) ; |
| 1265 |
BEGIN |
| 1266 |
INC (HighEquivalence) ; |
| 1267 |
IF HighEquivalence <= MaxEquvalence |
| 1268 |
THEN |
| 1269 |
Equivalence[HighEquivalence] := proc |
| 1270 |
ELSE |
| 1271 |
InternalError ('increase MaxEquivalence constant in M2Check.mod') |
| 1272 |
END |
| 1273 |
END addEquivalence ; |
| 1274 |
|
| 1275 |
|
| 1276 |
(* |
| 1277 |
checkProcType - |
| 1278 |
*) |
| 1279 |
|
| 1280 |
PROCEDURE checkProcType (result: status; tinfo: tInfo; |
| 1281 |
left, right: CARDINAL) : status ; |
| 1282 |
VAR |
| 1283 |
i, n : CARDINAL ; |
| 1284 |
lt, rt: CARDINAL ; |
| 1285 |
BEGIN |
| 1286 |
Assert (IsProcType (right)) ; |
| 1287 |
Assert (IsProcType (left)) ; |
| 1288 |
IF isFalse (result) |
| 1289 |
THEN |
| 1290 |
RETURN result |
| 1291 |
ELSE |
| 1292 |
lt := GetDType (left) ; |
| 1293 |
rt := GetDType (right) ; |
| 1294 |
IF (lt = NulSym) AND (rt = NulSym) |
| 1295 |
THEN |
| 1296 |
result := unknown |
| 1297 |
ELSIF lt = NulSym |
| 1298 |
THEN |
| 1299 |
IF tinfo^.format # NIL |
| 1300 |
THEN |
| 1301 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure type {%1a} does not have a {%kRETURN} type whereas procedure type {%2ad} has a {%kRETURN} type {%3ad}"), left, right, rt) |
| 1302 |
END ; |
| 1303 |
RETURN return (false, tinfo, left, right) |
| 1304 |
ELSIF rt = NulSym |
| 1305 |
THEN |
| 1306 |
IF tinfo^.format # NIL |
| 1307 |
THEN |
| 1308 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure type {%1a} does not have a {%kRETURN} type whereas procedure type {%2ad} has a {%kRETURN} type {%3ad}"), right, left, lt) |
| 1309 |
END ; |
| 1310 |
RETURN return (false, tinfo, left, right) |
| 1311 |
ELSE |
| 1312 |
(* two return type seen so we check them. *) |
| 1313 |
result := checkPair (unknown, tinfo, lt, rt) |
| 1314 |
END ; |
| 1315 |
|
| 1316 |
IF NoOfParamAny (left) # NoOfParamAny (right) |
| 1317 |
THEN |
| 1318 |
IF tinfo^.format # NIL |
| 1319 |
THEN |
| 1320 |
MetaErrorStringT2 (tinfo^.token, InitString ("procedure type {%1a} has a different number of parameters from procedure type {%2ad}"), right, left) |
| 1321 |
END ; |
| 1322 |
RETURN return (false, tinfo, left, right) |
| 1323 |
END ; |
| 1324 |
i := 1 ; |
| 1325 |
n := NoOfParamAny (left) ; |
| 1326 |
WHILE i <= n DO |
| 1327 |
IF isFalse (result) OR (result = visited) |
| 1328 |
THEN |
| 1329 |
(* Seen a mismatch therefore return. *) |
| 1330 |
RETURN return (result, tinfo, left, right) |
| 1331 |
END ; |
| 1332 |
result := unknown ; (* Each parameter must match. *) |
| 1333 |
IF IsVarParamAny (left, i) # IsVarParamAny (right, i) |
| 1334 |
THEN |
| 1335 |
IF IsVarParamAny (left, i) |
| 1336 |
THEN |
| 1337 |
IF tinfo^.format # NIL |
| 1338 |
THEN |
| 1339 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure type {%2a} {%3n} parameter was declared as a {%kVAR} whereas procedure type {%1ad} {%3n} parameter was not"), right, left, i) |
| 1340 |
END |
| 1341 |
ELSE |
| 1342 |
IF tinfo^.format # NIL |
| 1343 |
THEN |
| 1344 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure type {%1a} {%3n} parameter was declared as a {%kVAR} whereas procedure type {%2ad} {%3n} parameter was not"), right, left, i) |
| 1345 |
END |
| 1346 |
END ; |
| 1347 |
RETURN return (false, tinfo, left, right) |
| 1348 |
END ; |
| 1349 |
result := checkPair (result, tinfo, GetDType (GetNthParamAny (left, i)), GetDType (GetNthParamAny (right, i))) ; |
| 1350 |
INC (i) |
| 1351 |
END |
| 1352 |
END ; |
| 1353 |
RETURN return (result, tinfo, left, right) |
| 1354 |
END checkProcType ; |
| 1355 |
|
| 1356 |
|
| 1357 |
(* |
| 1358 |
checkProcedureProcType - |
| 1359 |
*) |
| 1360 |
|
| 1361 |
PROCEDURE checkProcedureProcType (result: status; tinfo: tInfo; |
| 1362 |
left, right: CARDINAL) : status ; |
| 1363 |
VAR |
| 1364 |
i, n : CARDINAL ; |
| 1365 |
lt, rt: CARDINAL ; |
| 1366 |
BEGIN |
| 1367 |
Assert (IsProcedure (right)) ; |
| 1368 |
Assert (IsProcType (left)) ; |
| 1369 |
IF NOT isFalse (result) |
| 1370 |
THEN |
| 1371 |
lt := GetDType (left) ; |
| 1372 |
rt := GetDType (right) ; |
| 1373 |
IF (lt = NulSym) AND (rt = NulSym) |
| 1374 |
THEN |
| 1375 |
(* nothing. *) |
| 1376 |
ELSIF lt = NulSym |
| 1377 |
THEN |
| 1378 |
IF tinfo^.format # NIL |
| 1379 |
THEN |
| 1380 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure type {%1a} does not have a {%kRETURN} type whereas procedure {%2ad} has a {%kRETURN} type {%3ad}"), left, right, rt) |
| 1381 |
END ; |
| 1382 |
RETURN return (false, tinfo, left, right) |
| 1383 |
ELSIF rt = NulSym |
| 1384 |
THEN |
| 1385 |
IF tinfo^.format # NIL |
| 1386 |
THEN |
| 1387 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure {%1a} does not have a {%kRETURN} type whereas procedure type {%2ad} has a {%kRETURN} type {%3ad}"), right, left, lt) |
| 1388 |
END ; |
| 1389 |
RETURN return (false, tinfo, left, right) |
| 1390 |
ELSE |
| 1391 |
(* two return type seen so we check them. *) |
| 1392 |
result := checkPair (result, tinfo, lt, rt) |
| 1393 |
END ; |
| 1394 |
|
| 1395 |
IF NoOfParamAny (left) # NoOfParamAny (right) |
| 1396 |
THEN |
| 1397 |
IF tinfo^.format # NIL |
| 1398 |
THEN |
| 1399 |
MetaErrorStringT2 (tinfo^.token, InitString ("procedure {%1a} has a different number of parameters from procedure type {%2ad}"), right, left) |
| 1400 |
END ; |
| 1401 |
RETURN return (false, tinfo, left, right) |
| 1402 |
END ; |
| 1403 |
i := 1 ; |
| 1404 |
n := NoOfParamAny (left) ; |
| 1405 |
WHILE i <= n DO |
| 1406 |
IF IsVarParamAny (left, i) # IsVarParamAny (right, i) |
| 1407 |
THEN |
| 1408 |
IF IsVarParamAny (left, i) |
| 1409 |
THEN |
| 1410 |
IF tinfo^.format # NIL |
| 1411 |
THEN |
| 1412 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure type {%2a} {%3n} parameter was declared as a {%kVAR} whereas procedure {%1ad} {%3n} parameter was not"), right, left, i) |
| 1413 |
END |
| 1414 |
ELSE |
| 1415 |
IF tinfo^.format # NIL |
| 1416 |
THEN |
| 1417 |
MetaErrorStringT3 (tinfo^.token, InitString ("procedure {%1a} {%3n} parameter was declared as a {%kVAR} whereas procedure type {%2ad} {%3n} parameter was not"), right, left, i) |
| 1418 |
END |
| 1419 |
END ; |
| 1420 |
RETURN return (false, tinfo, left, right) |
| 1421 |
END ; |
| 1422 |
result := checkPair (result, tinfo, GetDType (GetNthParamAny (left, i)), GetDType (GetNthParamAny (right, i))) ; |
| 1423 |
INC (i) |
| 1424 |
END |
| 1425 |
END ; |
| 1426 |
RETURN return (result, tinfo, left, right) |
| 1427 |
END checkProcedureProcType ; |
| 1428 |
|
| 1429 |
|
| 1430 |
(* |
| 1431 |
checkProcedure - |
| 1432 |
*) |
| 1433 |
|
| 1434 |
PROCEDURE checkProcedure (result: status; tinfo: tInfo; |
| 1435 |
left, right: CARDINAL) : status ; |
| 1436 |
BEGIN |
| 1437 |
Assert (IsProcedure (right)) ; |
| 1438 |
IF isFalse (result) |
| 1439 |
THEN |
| 1440 |
RETURN result |
| 1441 |
ELSIF IsVar (left) |
| 1442 |
THEN |
| 1443 |
RETURN checkProcedure (result, tinfo, |
| 1444 |
GetDType (left), right) |
| 1445 |
ELSIF left = Address |
| 1446 |
THEN |
| 1447 |
RETURN true |
| 1448 |
ELSIF IsProcType (left) |
| 1449 |
THEN |
| 1450 |
RETURN checkProcedureProcType (result, tinfo, left, right) |
| 1451 |
ELSE |
| 1452 |
RETURN result |
| 1453 |
END |
| 1454 |
END checkProcedure ; |
| 1455 |
|
| 1456 |
|
| 1457 |
(* |
| 1458 |
checkEnumerationEquivalence - |
| 1459 |
*) |
| 1460 |
|
| 1461 |
PROCEDURE checkEnumerationEquivalence (result: status; |
| 1462 |
left, right: CARDINAL) : status ; |
| 1463 |
BEGIN |
| 1464 |
IF isFalse (result) |
| 1465 |
THEN |
| 1466 |
RETURN result |
| 1467 |
ELSIF left = right |
| 1468 |
THEN |
| 1469 |
RETURN true |
| 1470 |
ELSE |
| 1471 |
RETURN false |
| 1472 |
END |
| 1473 |
END checkEnumerationEquivalence ; |
| 1474 |
|
| 1475 |
|
| 1476 |
(* |
| 1477 |
checkPointerType - check whether left and right are equal or are of type ADDRESS. |
| 1478 |
*) |
| 1479 |
|
| 1480 |
PROCEDURE checkPointerType (result: status; left, right: CARDINAL) : status ; |
| 1481 |
BEGIN |
| 1482 |
IF isFalse (result) |
| 1483 |
THEN |
| 1484 |
RETURN result |
| 1485 |
ELSIF (left = right) OR (left = Address) OR (right = Address) |
| 1486 |
THEN |
| 1487 |
RETURN true |
| 1488 |
ELSE |
| 1489 |
RETURN false |
| 1490 |
END |
| 1491 |
END checkPointerType ; |
| 1492 |
|
| 1493 |
|
| 1494 |
(* |
| 1495 |
checkProcTypeEquivalence - allow proctype to be compared against another |
| 1496 |
proctype or procedure. It is legal to be compared |
| 1497 |
against an address. |
| 1498 |
*) |
| 1499 |
|
| 1500 |
PROCEDURE checkProcTypeEquivalence (result: status; tinfo: tInfo; |
| 1501 |
left, right: CARDINAL) : status ; |
| 1502 |
BEGIN |
| 1503 |
IF isFalse (result) |
| 1504 |
THEN |
| 1505 |
RETURN result |
| 1506 |
ELSIF IsProcedure (left) AND IsProcType (right) |
| 1507 |
THEN |
| 1508 |
RETURN checkProcedure (result, tinfo, right, left) |
| 1509 |
ELSIF IsProcType (left) AND IsProcedure (right) |
| 1510 |
THEN |
| 1511 |
RETURN checkProcedure (result, tinfo, left, right) |
| 1512 |
ELSIF IsProcType (left) AND IsProcType (right) |
| 1513 |
THEN |
| 1514 |
RETURN checkProcType (result, tinfo, left, right) |
| 1515 |
ELSIF (left = Address) OR (right = Address) |
| 1516 |
THEN |
| 1517 |
RETURN true |
| 1518 |
ELSE |
| 1519 |
RETURN false |
| 1520 |
END |
| 1521 |
END checkProcTypeEquivalence ; |
| 1522 |
|
| 1523 |
|
| 1524 |
(* |
| 1525 |
checkTypeKindEquivalence - |
| 1526 |
*) |
| 1527 |
|
| 1528 |
PROCEDURE checkTypeKindEquivalence (result: status; tinfo: tInfo; |
| 1529 |
left, right: CARDINAL) : status ; |
| 1530 |
BEGIN |
| 1531 |
IF isFalse (result) |
| 1532 |
THEN |
| 1533 |
RETURN result |
| 1534 |
ELSIF (left = NulSym) OR (right = NulSym) |
| 1535 |
THEN |
| 1536 |
RETURN true |
| 1537 |
ELSE |
| 1538 |
(* Long cascade of all type kinds. *) |
| 1539 |
IF IsSet (left) AND IsSet (right) |
| 1540 |
THEN |
| 1541 |
RETURN checkSetEquivalent (result, tinfo, left, right) |
| 1542 |
ELSIF IsArray (left) AND IsArray (right) |
| 1543 |
THEN |
| 1544 |
RETURN checkArrayTypeEquivalence (result, tinfo, left, right) |
| 1545 |
ELSIF IsRecord (left) AND IsRecord (right) |
| 1546 |
THEN |
| 1547 |
RETURN checkRecordEquivalence (result, left, right) |
| 1548 |
ELSIF IsEnumeration (left) AND IsEnumeration (right) |
| 1549 |
THEN |
| 1550 |
RETURN checkEnumerationEquivalence (result, left, right) |
| 1551 |
ELSIF IsProcType (left) OR IsProcType (right) |
| 1552 |
THEN |
| 1553 |
RETURN checkProcTypeEquivalence (result, tinfo, right, left) |
| 1554 |
ELSIF IsReallyPointer (left) AND IsReallyPointer (right) |
| 1555 |
THEN |
| 1556 |
RETURN checkPointerType (result, left, right) |
| 1557 |
ELSE |
| 1558 |
RETURN result |
| 1559 |
END |
| 1560 |
END |
| 1561 |
END checkTypeKindEquivalence ; |
| 1562 |
|
| 1563 |
|
| 1564 |
(* |
| 1565 |
isSkipEquivalence - |
| 1566 |
*) |
| 1567 |
|
| 1568 |
PROCEDURE isSkipEquivalence (left, right: CARDINAL) : BOOLEAN ; |
| 1569 |
BEGIN |
| 1570 |
RETURN SkipType (left) = SkipType (right) |
| 1571 |
END isSkipEquivalence ; |
| 1572 |
|
| 1573 |
|
| 1574 |
(* |
| 1575 |
checkValueEquivalence - check to see if left and right values are the same. |
| 1576 |
*) |
| 1577 |
|
| 1578 |
PROCEDURE checkValueEquivalence (result: status; left, right: CARDINAL) : status ; |
| 1579 |
BEGIN |
| 1580 |
IF isKnown (result) |
| 1581 |
THEN |
| 1582 |
RETURN result |
| 1583 |
ELSIF left = right |
| 1584 |
THEN |
| 1585 |
RETURN true |
| 1586 |
ELSE |
| 1587 |
IF AreConstantsEqual (Mod2Gcc (left), Mod2Gcc (right)) |
| 1588 |
THEN |
| 1589 |
RETURN true |
| 1590 |
ELSE |
| 1591 |
RETURN false |
| 1592 |
END |
| 1593 |
END |
| 1594 |
END checkValueEquivalence ; |
| 1595 |
|
| 1596 |
|
| 1597 |
(* |
| 1598 |
and - |
| 1599 |
*) |
| 1600 |
|
| 1601 |
PROCEDURE and (left, right: status) : status ; |
| 1602 |
BEGIN |
| 1603 |
IF (left = true) AND (right = true) |
| 1604 |
THEN |
| 1605 |
RETURN true |
| 1606 |
ELSE |
| 1607 |
RETURN false |
| 1608 |
END |
| 1609 |
END and ; |
| 1610 |
|
| 1611 |
|
| 1612 |
(* |
| 1613 |
checkTypeRangeEquivalence - |
| 1614 |
*) |
| 1615 |
|
| 1616 |
PROCEDURE checkTypeRangeEquivalence (result: status; tinfo: tInfo; |
| 1617 |
left, right: CARDINAL) : status ; |
| 1618 |
VAR |
| 1619 |
result2, result3: status ; |
| 1620 |
BEGIN |
| 1621 |
result := checkSkipEquivalence (result, left, right) ; |
| 1622 |
result2 := checkValueEquivalence (result, GetTypeMin (left), GetTypeMin (right)) ; |
| 1623 |
result3 := checkValueEquivalence (result, GetTypeMax (left), GetTypeMax (right)) ; |
| 1624 |
RETURN return (and (result2, result3), tinfo, left, right) |
| 1625 |
END checkTypeRangeEquivalence ; |
| 1626 |
|
| 1627 |
|
| 1628 |
(* |
| 1629 |
include - include pair left:right into pairs with status, s. |
| 1630 |
*) |
| 1631 |
|
| 1632 |
PROCEDURE include (pairs: Index; left, right: CARDINAL; s: status) ; |
| 1633 |
VAR |
| 1634 |
p: pair ; |
| 1635 |
BEGIN |
| 1636 |
p := newPair () ; |
| 1637 |
p^.left := left ; |
| 1638 |
p^.right := right ; |
| 1639 |
p^.pairStatus := s ; |
| 1640 |
p^.next := NIL ; |
| 1641 |
IncludeIndiceIntoIndex (pairs, p) |
| 1642 |
END include ; |
| 1643 |
|
| 1644 |
|
| 1645 |
(* |
| 1646 |
exclude - exclude pair left:right from pairs. |
| 1647 |
*) |
| 1648 |
|
| 1649 |
PROCEDURE exclude (pairs: Index; left, right: CARDINAL) ; |
| 1650 |
VAR |
| 1651 |
p : pair ; |
| 1652 |
i, n: CARDINAL ; |
| 1653 |
BEGIN |
| 1654 |
i := 1 ; |
| 1655 |
n := HighIndice (pairs) ; |
| 1656 |
WHILE i <= n DO |
| 1657 |
p := GetIndice (pairs, i) ; |
| 1658 |
IF (p # NIL) AND (p^.left = left) AND (p^.right = right) |
| 1659 |
THEN |
| 1660 |
PutIndice (pairs, i, NIL) ; |
| 1661 |
disposePair (p) ; |
| 1662 |
RETURN |
| 1663 |
END ; |
| 1664 |
INC (i) |
| 1665 |
END |
| 1666 |
END exclude ; |
| 1667 |
|
| 1668 |
|
| 1669 |
(* |
| 1670 |
getStatus - |
| 1671 |
*) |
| 1672 |
|
| 1673 |
PROCEDURE getStatus (pairs: Index; left, right: CARDINAL) : status ; |
| 1674 |
VAR |
| 1675 |
p : pair ; |
| 1676 |
i, n: CARDINAL ; |
| 1677 |
BEGIN |
| 1678 |
i := 1 ; |
| 1679 |
n := HighIndice (pairs) ; |
| 1680 |
WHILE i <= n DO |
| 1681 |
p := GetIndice (pairs, i) ; |
| 1682 |
IF (p # NIL) AND (p^.left = left) AND (p^.right = right) |
| 1683 |
THEN |
| 1684 |
RETURN p^.pairStatus |
| 1685 |
END ; |
| 1686 |
INC (i) |
| 1687 |
END ; |
| 1688 |
RETURN unknown |
| 1689 |
END getStatus ; |
| 1690 |
|
| 1691 |
|
| 1692 |
(* |
| 1693 |
return - |
| 1694 |
*) |
| 1695 |
|
| 1696 |
PROCEDURE return (result: status; tinfo: tInfo; left, right: CARDINAL) : status ; |
| 1697 |
BEGIN |
| 1698 |
IF result # unknown |
| 1699 |
THEN |
| 1700 |
IF isKnown (result) |
| 1701 |
THEN |
| 1702 |
include (tinfo^.resolved, left, right, result) ; |
| 1703 |
exclude (tinfo^.unresolved, left, right) ; |
| 1704 |
exclude (tinfo^.visited, left, right) (* no longer visiting as it is resolved. *) |
| 1705 |
END |
| 1706 |
END ; |
| 1707 |
IF result = false |
| 1708 |
THEN |
| 1709 |
RETURN issueError (FALSE, tinfo, left, right) |
| 1710 |
END ; |
| 1711 |
RETURN result |
| 1712 |
END return ; |
| 1713 |
|
| 1714 |
|
| 1715 |
(* |
| 1716 |
checkSkipEquivalence - return true if left right are equivalent. |
| 1717 |
*) |
| 1718 |
|
| 1719 |
PROCEDURE checkSkipEquivalence (result: status; left, right: CARDINAL) : status ; |
| 1720 |
BEGIN |
| 1721 |
IF isKnown (result) |
| 1722 |
THEN |
| 1723 |
RETURN result |
| 1724 |
ELSIF isSkipEquivalence (left, right) |
| 1725 |
THEN |
| 1726 |
RETURN true |
| 1727 |
ELSE |
| 1728 |
RETURN result |
| 1729 |
END |
| 1730 |
END checkSkipEquivalence ; |
| 1731 |
|
| 1732 |
|
| 1733 |
(* |
| 1734 |
checkSetEquivalent - compares set types, left and right. |
| 1735 |
*) |
| 1736 |
|
| 1737 |
PROCEDURE checkSetEquivalent (result: status; tinfo: tInfo; |
| 1738 |
left, right: CARDINAL) : status ; |
| 1739 |
BEGIN |
| 1740 |
result := checkSkipEquivalence (result, left, right) ; |
| 1741 |
result := checkTypeKindEquivalence (result, tinfo, GetDType (left), GetDType (right)) ; |
| 1742 |
result := checkTypeRangeEquivalence (result, tinfo, GetDType (left), GetDType (right)) ; |
| 1743 |
RETURN return (result, tinfo, left, right) |
| 1744 |
END checkSetEquivalent ; |
| 1745 |
|
| 1746 |
|
| 1747 |
(* |
| 1748 |
checkRecordEquivalence - compares record types, left and right. |
| 1749 |
*) |
| 1750 |
|
| 1751 |
PROCEDURE checkRecordEquivalence (result: status; left, right: CARDINAL) : status ; |
| 1752 |
BEGIN |
| 1753 |
IF isFalse (result) |
| 1754 |
THEN |
| 1755 |
RETURN result |
| 1756 |
ELSIF left = right |
| 1757 |
THEN |
| 1758 |
RETURN true |
| 1759 |
ELSE |
| 1760 |
RETURN false |
| 1761 |
END |
| 1762 |
END checkRecordEquivalence ; |
| 1763 |
|
| 1764 |
|
| 1765 |
(* |
| 1766 |
getType - only returns the type of symbol providing it is not a procedure. |
| 1767 |
*) |
| 1768 |
|
| 1769 |
PROCEDURE getType (sym: CARDINAL) : CARDINAL ; |
| 1770 |
BEGIN |
| 1771 |
IF (sym # NulSym) AND IsProcedure (sym) |
| 1772 |
THEN |
| 1773 |
RETURN GetProcedureProcType (sym) |
| 1774 |
ELSIF IsTyped (sym) |
| 1775 |
THEN |
| 1776 |
RETURN GetDType (sym) |
| 1777 |
ELSE |
| 1778 |
RETURN sym |
| 1779 |
END |
| 1780 |
END getType ; |
| 1781 |
|
| 1782 |
|
| 1783 |
(* |
| 1784 |
getSType - |
| 1785 |
*) |
| 1786 |
|
| 1787 |
PROCEDURE getSType (sym: CARDINAL) : CARDINAL ; |
| 1788 |
BEGIN |
| 1789 |
IF IsProcedure (sym) |
| 1790 |
THEN |
| 1791 |
RETURN Address |
| 1792 |
ELSE |
| 1793 |
RETURN GetDType (sym) |
| 1794 |
END |
| 1795 |
END getSType ; |
| 1796 |
|
| 1797 |
|
| 1798 |
(* |
| 1799 |
determineCompatible - check for compatibility by checking |
| 1800 |
equivalence, array, generic and type kind. |
| 1801 |
*) |
| 1802 |
|
| 1803 |
PROCEDURE determineCompatible (result: status; tinfo: tInfo; left, right: CARDINAL) : status ; |
| 1804 |
BEGIN |
| 1805 |
result := checkPair (result, tinfo, left, right) ; |
| 1806 |
RETURN return (result, tinfo, left, right) |
| 1807 |
END determineCompatible ; |
| 1808 |
|
| 1809 |
|
| 1810 |
(* |
| 1811 |
get - |
| 1812 |
*) |
| 1813 |
|
| 1814 |
PROCEDURE get (pairs: Index; VAR left, right: CARDINAL; s: status) : BOOLEAN ; |
| 1815 |
VAR |
| 1816 |
i, n: CARDINAL ; |
| 1817 |
p : pair ; |
| 1818 |
BEGIN |
| 1819 |
i := 1 ; |
| 1820 |
n := HighIndice (pairs) ; |
| 1821 |
WHILE i <= n DO |
| 1822 |
p := GetIndice (pairs, i) ; |
| 1823 |
IF (p # NIL) AND (p^.pairStatus = s) |
| 1824 |
THEN |
| 1825 |
left := p^.left ; |
| 1826 |
right := p^.right ; |
| 1827 |
RETURN TRUE |
| 1828 |
END ; |
| 1829 |
INC (i) |
| 1830 |
END ; |
| 1831 |
RETURN FALSE |
| 1832 |
END get ; |
| 1833 |
|
| 1834 |
|
| 1835 |
(* |
| 1836 |
isInternal - return TRUE if sym is a constant lit which was declared |
| 1837 |
as internal. |
| 1838 |
*) |
| 1839 |
|
| 1840 |
PROCEDURE isInternal (sym: CARDINAL) : BOOLEAN ; |
| 1841 |
BEGIN |
| 1842 |
RETURN IsConstLit (sym) AND IsConstLitInternal (sym) |
| 1843 |
END isInternal ; |
| 1844 |
|
| 1845 |
|
| 1846 |
(* |
| 1847 |
doCheck - keep obtaining an unresolved pair and check for the |
| 1848 |
type compatibility. This is the main check routine used by |
| 1849 |
parameter, assignment and expression compatibility. |
| 1850 |
It tests all unknown pairs and calls the appropriate |
| 1851 |
check function |
| 1852 |
*) |
| 1853 |
|
| 1854 |
PROCEDURE doCheck (tinfo: tInfo) : BOOLEAN ; |
| 1855 |
VAR |
| 1856 |
result : status ; |
| 1857 |
left, right: CARDINAL ; |
| 1858 |
BEGIN |
| 1859 |
IF debugging |
| 1860 |
THEN |
| 1861 |
dumptInfo (tinfo) |
| 1862 |
END ; |
| 1863 |
WHILE get (tinfo^.unresolved, left, right, unknown) DO |
| 1864 |
IF debugging |
| 1865 |
THEN |
| 1866 |
printf ("doCheck (%d, %d)\n", left, right) ; |
| 1867 |
dumptInfo (tinfo) |
| 1868 |
END ; |
| 1869 |
IF (left = NulSym) OR (right = NulSym) |
| 1870 |
THEN |
| 1871 |
(* Cannot test if a type is NulSym, we assume true. |
| 1872 |
It maybe that later on a symbols type is set and later |
| 1873 |
on checking will be called and more accurately resolved. |
| 1874 |
For example constant strings can be concatenated during |
| 1875 |
the quadruple folding phase. *) |
| 1876 |
RETURN TRUE |
| 1877 |
ELSIF isInternal (left) OR isInternal (right) |
| 1878 |
THEN |
| 1879 |
(* Do not check constants which have been generated internally. |
| 1880 |
Currently these are generated by the default BY constant |
| 1881 |
value in a FOR loop. *) |
| 1882 |
RETURN TRUE |
| 1883 |
END ; |
| 1884 |
(* |
| 1885 |
IF in (tinfo^.visited, left, right) |
| 1886 |
THEN |
| 1887 |
IF debugging |
| 1888 |
THEN |
| 1889 |
printf (" already visited (%d, %d)\n", left, right) |
| 1890 |
END ; |
| 1891 |
ELSE |
| 1892 |
IF debugging |
| 1893 |
THEN |
| 1894 |
printf (" not visited (%d, %d)\n", left, right) |
| 1895 |
END ; |
| 1896 |
*) |
| 1897 |
result := tinfo^.checkFunc (unknown, tinfo, left, right) ; |
| 1898 |
IF isKnown (result) |
| 1899 |
THEN |
| 1900 |
(* Remove this pair from the unresolved list. *) |
| 1901 |
exclude (tinfo^.unresolved, left, right) ; |
| 1902 |
(* Add it to the resolved list. *) |
| 1903 |
include (tinfo^.resolved, left, right, result) ; |
| 1904 |
IF result = false |
| 1905 |
THEN |
| 1906 |
IF debugging |
| 1907 |
THEN |
| 1908 |
printf (" known (%d, %d) false\n", left, right) |
| 1909 |
END ; |
| 1910 |
RETURN FALSE |
| 1911 |
ELSE |
| 1912 |
IF debugging |
| 1913 |
THEN |
| 1914 |
printf (" known (%d, %d) true\n", left, right) |
| 1915 |
END |
| 1916 |
END |
| 1917 |
END |
| 1918 |
END ; |
| 1919 |
RETURN TRUE |
| 1920 |
END doCheck ; |
| 1921 |
|
| 1922 |
|
| 1923 |
(* |
| 1924 |
in - returns TRUE if the pair is in the list. |
| 1925 |
*) |
| 1926 |
|
| 1927 |
PROCEDURE in (pairs: Index; left, right: CARDINAL) : BOOLEAN ; |
| 1928 |
VAR |
| 1929 |
i, n: CARDINAL ; |
| 1930 |
p : pair ; |
| 1931 |
BEGIN |
| 1932 |
i := 1 ; |
| 1933 |
n := HighIndice (pairs) ; |
| 1934 |
WHILE i <= n DO |
| 1935 |
p := GetIndice (pairs, i) ; |
| 1936 |
IF (p # NIL) AND (p^.left = left) AND (p^.right = right) |
| 1937 |
THEN |
| 1938 |
RETURN TRUE |
| 1939 |
END ; |
| 1940 |
INC (i) |
| 1941 |
END ; |
| 1942 |
RETURN FALSE |
| 1943 |
END in ; |
| 1944 |
|
| 1945 |
|
| 1946 |
(* |
| 1947 |
newPair - |
| 1948 |
*) |
| 1949 |
|
| 1950 |
PROCEDURE newPair () : pair ; |
| 1951 |
VAR |
| 1952 |
p: pair ; |
| 1953 |
BEGIN |
| 1954 |
IF pairFreeList = NIL |
| 1955 |
THEN |
| 1956 |
NEW (p) |
| 1957 |
ELSE |
| 1958 |
p := pairFreeList ; |
| 1959 |
pairFreeList := p^.next |
| 1960 |
END ; |
| 1961 |
Assert (p # NIL) ; |
| 1962 |
RETURN p |
| 1963 |
END newPair ; |
| 1964 |
|
| 1965 |
|
| 1966 |
(* |
| 1967 |
disposePair - adds pair, p, to the free list. |
| 1968 |
*) |
| 1969 |
|
| 1970 |
PROCEDURE disposePair (p: pair) ; |
| 1971 |
BEGIN |
| 1972 |
p^.next := pairFreeList ; |
| 1973 |
pairFreeList := p |
| 1974 |
END disposePair ; |
| 1975 |
|
| 1976 |
|
| 1977 |
(* |
| 1978 |
deconstructIndex - |
| 1979 |
*) |
| 1980 |
|
| 1981 |
PROCEDURE deconstructIndex (pairs: Index) : Index ; |
| 1982 |
VAR |
| 1983 |
p : pair ; |
| 1984 |
i, n: CARDINAL ; |
| 1985 |
BEGIN |
| 1986 |
i := 1 ; |
| 1987 |
n := HighIndice (pairs) ; |
| 1988 |
WHILE i <= n DO |
| 1989 |
p := GetIndice (pairs, i) ; |
| 1990 |
IF p # NIL |
| 1991 |
THEN |
| 1992 |
disposePair (p) |
| 1993 |
END ; |
| 1994 |
INC (i) |
| 1995 |
END ; |
| 1996 |
RETURN KillIndex (pairs) |
| 1997 |
END deconstructIndex ; |
| 1998 |
|
| 1999 |
|
| 2000 |
(* |
| 2001 |
deconstruct - deallocate the List data structure. |
| 2002 |
*) |
| 2003 |
|
| 2004 |
PROCEDURE deconstruct (tinfo: tInfo) ; |
| 2005 |
BEGIN |
| 2006 |
tinfo^.format := KillString (tinfo^.format) ; |
| 2007 |
tinfo^.reason := KillString (tinfo^.reason) ; |
| 2008 |
tinfo^.visited := deconstructIndex (tinfo^.visited) ; |
| 2009 |
tinfo^.resolved := deconstructIndex (tinfo^.resolved) ; |
| 2010 |
tinfo^.unresolved := deconstructIndex (tinfo^.unresolved) |
| 2011 |
END deconstruct ; |
| 2012 |
|
| 2013 |
|
| 2014 |
(* |
| 2015 |
newtInfo - |
| 2016 |
*) |
| 2017 |
|
| 2018 |
PROCEDURE newtInfo () : tInfo ; |
| 2019 |
VAR |
| 2020 |
tinfo: tInfo ; |
| 2021 |
BEGIN |
| 2022 |
IF tinfoFreeList = NIL |
| 2023 |
THEN |
| 2024 |
NEW (tinfo) |
| 2025 |
ELSE |
| 2026 |
tinfo := tinfoFreeList ; |
| 2027 |
tinfoFreeList := tinfoFreeList^.next |
| 2028 |
END ; |
| 2029 |
RETURN tinfo |
| 2030 |
END newtInfo ; |
| 2031 |
|
| 2032 |
|
| 2033 |
(* |
| 2034 |
collapseString - if the string, a, is "" then return NIL otherwise create |
| 2035 |
and return a dynamic string. |
| 2036 |
*) |
| 2037 |
|
| 2038 |
PROCEDURE collapseString (a: ARRAY OF CHAR) : String ; |
| 2039 |
BEGIN |
| 2040 |
IF StrEqual (a, "") |
| 2041 |
THEN |
| 2042 |
RETURN NIL |
| 2043 |
ELSE |
| 2044 |
RETURN InitString (a) |
| 2045 |
END |
| 2046 |
END collapseString ; |
| 2047 |
|
| 2048 |
|
| 2049 |
(* |
| 2050 |
AssignmentTypeCompatible - returns TRUE if the des and the expr are assignment compatible. |
| 2051 |
*) |
| 2052 |
|
| 2053 |
PROCEDURE AssignmentTypeCompatible (token: CARDINAL; format: ARRAY OF CHAR; |
| 2054 |
des, expr: CARDINAL; |
| 2055 |
enableReason: BOOLEAN) : BOOLEAN ; |
| 2056 |
VAR |
| 2057 |
tinfo: tInfo ; |
| 2058 |
BEGIN |
| 2059 |
tinfo := newtInfo () ; |
| 2060 |
tinfo^.reason := NIL ; |
| 2061 |
tinfo^.reasonEnable := enableReason AND StrictTypeReason ; |
| 2062 |
tinfo^.format := collapseString (format) ; |
| 2063 |
tinfo^.token := token ; |
| 2064 |
tinfo^.kind := assignment ; |
| 2065 |
tinfo^.actual := NulSym ; |
| 2066 |
tinfo^.formal := NulSym ; |
| 2067 |
tinfo^.procedure := NulSym ; |
| 2068 |
tinfo^.nth := 0 ; |
| 2069 |
tinfo^.isvar := FALSE ; |
| 2070 |
tinfo^.error := NIL ; |
| 2071 |
tinfo^.left := des ; |
| 2072 |
tinfo^.right := expr ; |
| 2073 |
tinfo^.checkFunc := determineCompatible ; |
| 2074 |
tinfo^.visited := InitIndex (1) ; |
| 2075 |
tinfo^.resolved := InitIndex (1) ; |
| 2076 |
tinfo^.unresolved := InitIndex (1) ; |
| 2077 |
include (tinfo^.unresolved, des, expr, unknown) ; |
| 2078 |
tinfo^.strict := FALSE ; |
| 2079 |
tinfo^.isin := FALSE ; |
| 2080 |
IF doCheck (tinfo) |
| 2081 |
THEN |
| 2082 |
deconstruct (tinfo) ; |
| 2083 |
RETURN TRUE |
| 2084 |
ELSE |
| 2085 |
deconstruct (tinfo) ; |
| 2086 |
RETURN FALSE |
| 2087 |
END |
| 2088 |
END AssignmentTypeCompatible ; |
| 2089 |
|
| 2090 |
|
| 2091 |
(* |
| 2092 |
ParameterTypeCompatible - returns TRUE if the nth procedure parameter formal |
| 2093 |
is compatible with actual. |
| 2094 |
*) |
| 2095 |
|
| 2096 |
PROCEDURE ParameterTypeCompatible (token: CARDINAL; format: ARRAY OF CHAR; |
| 2097 |
procedure, formal, actual, nth: CARDINAL; |
| 2098 |
isvar: BOOLEAN) : BOOLEAN ; |
| 2099 |
VAR |
| 2100 |
formalT, actualT: CARDINAL ; |
| 2101 |
tinfo : tInfo ; |
| 2102 |
BEGIN |
| 2103 |
tinfo := newtInfo () ; |
| 2104 |
formalT := getSType (formal) ; |
| 2105 |
actualT := getSType (actual) ; |
| 2106 |
tinfo^.reasonEnable := StrictTypeReason ; |
| 2107 |
tinfo^.reason := NIL ; |
| 2108 |
tinfo^.format := collapseString (format) ; |
| 2109 |
tinfo^.token := token ; |
| 2110 |
tinfo^.kind := parameter ; |
| 2111 |
tinfo^.actual := actual ; |
| 2112 |
tinfo^.formal := formal ; |
| 2113 |
tinfo^.procedure := procedure ; |
| 2114 |
tinfo^.nth := nth ; |
| 2115 |
tinfo^.isvar := isvar ; |
| 2116 |
tinfo^.error := NIL ; |
| 2117 |
tinfo^.left := formalT ; |
| 2118 |
tinfo^.right := actualT ; |
| 2119 |
tinfo^.checkFunc := determineCompatible ; |
| 2120 |
tinfo^.visited := InitIndex (1) ; |
| 2121 |
tinfo^.resolved := InitIndex (1) ; |
| 2122 |
tinfo^.unresolved := InitIndex (1) ; |
| 2123 |
tinfo^.strict := FALSE ; |
| 2124 |
tinfo^.isin := FALSE ; |
| 2125 |
include (tinfo^.unresolved, actual, formal, unknown) ; |
| 2126 |
IF debugging |
| 2127 |
THEN |
| 2128 |
dumptInfo (tinfo) |
| 2129 |
END ; |
| 2130 |
IF doCheck (tinfo) |
| 2131 |
THEN |
| 2132 |
deconstruct (tinfo) ; |
| 2133 |
RETURN TRUE |
| 2134 |
ELSE |
| 2135 |
deconstruct (tinfo) ; |
| 2136 |
RETURN FALSE |
| 2137 |
END |
| 2138 |
END ParameterTypeCompatible ; |
| 2139 |
|
| 2140 |
|
| 2141 |
(* |
| 2142 |
doExpressionTypeCompatible - |
| 2143 |
*) |
| 2144 |
|
| 2145 |
PROCEDURE doExpressionTypeCompatible (token: CARDINAL; format: ARRAY OF CHAR; |
| 2146 |
left, right: CARDINAL; |
| 2147 |
strict: BOOLEAN) : BOOLEAN ; |
| 2148 |
VAR |
| 2149 |
tinfo: tInfo ; |
| 2150 |
BEGIN |
| 2151 |
tinfo := newtInfo () ; |
| 2152 |
tinfo^.reasonEnable := StrictTypeReason ; |
| 2153 |
tinfo^.reason := NIL ; |
| 2154 |
tinfo^.format := collapseString (format) ; |
| 2155 |
tinfo^.token := token ; |
| 2156 |
tinfo^.kind := expression ; |
| 2157 |
tinfo^.actual := NulSym ; |
| 2158 |
tinfo^.formal := NulSym ; |
| 2159 |
tinfo^.procedure := NulSym ; |
| 2160 |
tinfo^.nth := 0 ; |
| 2161 |
tinfo^.isvar := FALSE ; |
| 2162 |
tinfo^.error := NIL ; |
| 2163 |
tinfo^.left := left ; |
| 2164 |
tinfo^.right := right ; |
| 2165 |
tinfo^.checkFunc := determineCompatible ; |
| 2166 |
tinfo^.visited := InitIndex (1) ; |
| 2167 |
tinfo^.resolved := InitIndex (1) ; |
| 2168 |
tinfo^.unresolved := InitIndex (1) ; |
| 2169 |
tinfo^.strict := strict ; |
| 2170 |
tinfo^.isin := FALSE ; |
| 2171 |
include (tinfo^.unresolved, left, right, unknown) ; |
| 2172 |
IF doCheck (tinfo) |
| 2173 |
THEN |
| 2174 |
deconstruct (tinfo) ; |
| 2175 |
RETURN TRUE |
| 2176 |
ELSE |
| 2177 |
deconstruct (tinfo) ; |
| 2178 |
RETURN FALSE |
| 2179 |
END |
| 2180 |
END doExpressionTypeCompatible ; |
| 2181 |
|
| 2182 |
|
| 2183 |
(* |
| 2184 |
ExpressionTypeCompatible - returns TRUE if the expressions, left and right, |
| 2185 |
are expression compatible. |
| 2186 |
*) |
| 2187 |
|
| 2188 |
PROCEDURE ExpressionTypeCompatible (token: CARDINAL; format: ARRAY OF CHAR; |
| 2189 |
left, right: CARDINAL; |
| 2190 |
strict, isin: BOOLEAN) : BOOLEAN ; |
| 2191 |
BEGIN |
| 2192 |
IF (left#NulSym) AND (right#NulSym) |
| 2193 |
THEN |
| 2194 |
IF isin |
| 2195 |
THEN |
| 2196 |
IF IsConst (right) OR IsVar (right) |
| 2197 |
THEN |
| 2198 |
right := getSType (right) |
| 2199 |
END ; |
| 2200 |
IF IsSet (right) |
| 2201 |
THEN |
| 2202 |
right := getSType (right) |
| 2203 |
END |
| 2204 |
END |
| 2205 |
END ; |
| 2206 |
RETURN doExpressionTypeCompatible (token, format, left, right, strict) |
| 2207 |
END ExpressionTypeCompatible ; |
| 2208 |
|
| 2209 |
|
| 2210 |
(* |
| 2211 |
init - initialise all global data structures for this module. |
| 2212 |
*) |
| 2213 |
|
| 2214 |
PROCEDURE init ; |
| 2215 |
BEGIN |
| 2216 |
pairFreeList := NIL ; |
| 2217 |
tinfoFreeList := NIL ; |
| 2218 |
errors := InitIndex (1) ; |
| 2219 |
InitEquivalenceArray |
| 2220 |
END init ; |
| 2221 |
|
| 2222 |
|
| 2223 |
BEGIN |
| 2224 |
init |
| 2225 |
END M2Check. |