/
cstrnchk.c
833 lines (694 loc) · 28.4 KB
/
cstrnchk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 07/01/05 */
/* */
/* CONSTRAINT CHECKING MODULE */
/*******************************************************/
/*************************************************************/
/* Purpose: Provides functions for constraint checking of */
/* data types. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
/* Brian Dantes */
/* */
/* Revision History: */
/* 6.23: Changed name of variable exp to theExp */
/* because of Unix compiler warnings of shadowed */
/* definitions. */
/* */
/* 6.24: Added allowed-classes slot facet. */
/* */
/* Renamed BOOLEAN macro type to intBool. */
/* */
/*************************************************************/
#define _CSTRNCHK_SOURCE_
#include <stdio.h>
#define _STDIO_INCLUDED_
#include <stdlib.h>
#include "setup.h"
#include "router.h"
#include "multifld.h"
#include "envrnmnt.h"
#include "extnfunc.h"
#include "cstrnutl.h"
#if OBJECT_SYSTEM
#include "inscom.h"
#include "insfun.h"
#include "classcom.h"
#include "classexm.h"
#endif
#include "cstrnchk.h"
/***************************************/
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
/***************************************/
static intBool CheckRangeAgainstCardinalityConstraint(void *,int,int,CONSTRAINT_RECORD *);
static int CheckFunctionReturnType(int,CONSTRAINT_RECORD *);
static intBool CheckTypeConstraint(int,CONSTRAINT_RECORD *);
static intBool CheckRangeConstraint(void *,int,void *,CONSTRAINT_RECORD *);
static void PrintRange(void *,char *,CONSTRAINT_RECORD *);
/******************************************************/
/* CheckFunctionReturnType: Checks a functions return */
/* type against a set of permissable return values. */
/* Returns TRUE if the return type is included */
/* among the permissible values, otherwise FALSE. */
/******************************************************/
static int CheckFunctionReturnType(
int functionReturnType,
CONSTRAINT_RECORD *constraints)
{
if (constraints == NULL) return(TRUE);
if (constraints->anyAllowed) return(TRUE);
switch(functionReturnType)
{
case 'c':
case 'w':
case 'b':
if (constraints->symbolsAllowed) return(TRUE);
else return(FALSE);
case 's':
if (constraints->stringsAllowed) return(TRUE);
else return(FALSE);
case 'j':
if ((constraints->symbolsAllowed) ||
(constraints->stringsAllowed) ||
(constraints->instanceNamesAllowed)) return(TRUE);
else return(FALSE);
case 'k':
if ((constraints->symbolsAllowed) || (constraints->stringsAllowed)) return(TRUE);
else return(FALSE);
case 'd':
case 'f':
if (constraints->floatsAllowed) return(TRUE);
else return(FALSE);
case 'i':
case 'l':
if (constraints->integersAllowed) return(TRUE);
else return(FALSE);
case 'n':
if ((constraints->integersAllowed) || (constraints->floatsAllowed)) return(TRUE);
else return(FALSE);
case 'm':
if (constraints->multifieldsAllowed) return(TRUE);
else return(FALSE);
case 'a':
if (constraints->externalAddressesAllowed) return(TRUE);
else return(FALSE);
case 'x':
if (constraints->instanceAddressesAllowed) return(TRUE);
else return(FALSE);
case 'o':
if (constraints->instanceNamesAllowed) return(TRUE);
else return(FALSE);
case 'u':
return(TRUE);
case 'v':
if (constraints->voidAllowed) return(TRUE);
}
return(TRUE);
}
/****************************************************/
/* CheckTypeConstraint: Determines if a primitive */
/* data type satisfies the type constraint fields */
/* of aconstraint record. */
/****************************************************/
static intBool CheckTypeConstraint(
int type,
CONSTRAINT_RECORD *constraints)
{
if (type == RVOID) return(FALSE);
if (constraints == NULL) return(TRUE);
if (constraints->anyAllowed == TRUE) return(TRUE);
if ((type == SYMBOL) && (constraints->symbolsAllowed != TRUE))
{ return(FALSE); }
if ((type == STRING) && (constraints->stringsAllowed != TRUE))
{ return(FALSE); }
if ((type == FLOAT) && (constraints->floatsAllowed != TRUE))
{ return(FALSE); }
if ((type == INTEGER) && (constraints->integersAllowed != TRUE))
{ return(FALSE); }
#if OBJECT_SYSTEM
if ((type == INSTANCE_NAME) && (constraints->instanceNamesAllowed != TRUE))
{ return(FALSE); }
if ((type == INSTANCE_ADDRESS) && (constraints->instanceAddressesAllowed != TRUE))
{ return(FALSE); }
#endif
if ((type == EXTERNAL_ADDRESS) && (constraints->externalAddressesAllowed != TRUE))
{ return(FALSE); }
if ((type == RVOID) && (constraints->voidAllowed != TRUE))
{ return(FALSE); }
if ((type == FACT_ADDRESS) && (constraints->factAddressesAllowed != TRUE))
{ return(FALSE); }
return(TRUE);
}
/********************************************************/
/* CheckCardinalityConstraint: Determines if an integer */
/* falls within the range of allowed cardinalities */
/* for a constraint record. */
/********************************************************/
globle intBool CheckCardinalityConstraint(
void *theEnv,
long number,
CONSTRAINT_RECORD *constraints)
{
/*=========================================*/
/* If the constraint record is NULL, there */
/* are no cardinality restrictions. */
/*=========================================*/
if (constraints == NULL) return(TRUE);
/*==================================*/
/* Determine if the integer is less */
/* than the minimum cardinality. */
/*==================================*/
if (constraints->minFields != NULL)
{
if (constraints->minFields->value != SymbolData(theEnv)->NegativeInfinity)
{
if (number < ValueToLong(constraints->minFields->value))
{ return(FALSE); }
}
}
/*=====================================*/
/* Determine if the integer is greater */
/* than the maximum cardinality. */
/*=====================================*/
if (constraints->maxFields != NULL)
{
if (constraints->maxFields->value != SymbolData(theEnv)->PositiveInfinity)
{
if (number > ValueToLong(constraints->maxFields->value))
{ return(FALSE); }
}
}
/*=========================================================*/
/* The integer falls within the allowed cardinality range. */
/*=========================================================*/
return(TRUE);
}
/*****************************************************************/
/* CheckRangeAgainstCardinalityConstraint: Determines if a range */
/* of numbers could possibly fall within the range of allowed */
/* cardinalities for a constraint record. Returns TRUE if at */
/* least one of the numbers in the range is within the allowed */
/* cardinality, otherwise FALSE is returned. */
/*****************************************************************/
static intBool CheckRangeAgainstCardinalityConstraint(
void *theEnv,
int min,
int max,
CONSTRAINT_RECORD *constraints)
{
/*=========================================*/
/* If the constraint record is NULL, there */
/* are no cardinality restrictions. */
/*=========================================*/
if (constraints == NULL) return(TRUE);
/*===============================================================*/
/* If the minimum value of the range is greater than the maximum */
/* value of the cardinality, then there are no numbers in the */
/* range which could fall within the cardinality range, and so */
/* FALSE is returned. */
/*===============================================================*/
if (constraints->maxFields != NULL)
{
if (constraints->maxFields->value != SymbolData(theEnv)->PositiveInfinity)
{
if (min > ValueToLong(constraints->maxFields->value))
{ return(FALSE); }
}
}
/*===============================================================*/
/* If the maximum value of the range is less than the minimum */
/* value of the cardinality, then there are no numbers in the */
/* range which could fall within the cardinality range, and so */
/* FALSE is returned. A maximum range value of -1 indicates that */
/* the maximum possible value of the range is positive infinity. */
/*===============================================================*/
if ((constraints->minFields != NULL) && (max != -1))
{
if (constraints->minFields->value != SymbolData(theEnv)->NegativeInfinity)
{
if (max < ValueToLong(constraints->minFields->value))
{ return(FALSE); }
}
}
/*=============================================*/
/* At least one number in the specified range */
/* falls within the allowed cardinality range. */
/*=============================================*/
return(TRUE);
}
/**********************************************************************/
/* CheckAllowedValuesConstraint: Determines if a primitive data type */
/* satisfies the allowed-... constraint fields of a constraint */
/* record. Returns TRUE if the constraints are satisfied, otherwise */
/* FALSE is returned. */
/**********************************************************************/
globle intBool CheckAllowedValuesConstraint(
int type,
void *vPtr,
CONSTRAINT_RECORD *constraints)
{
struct expr *tmpPtr;
/*=========================================*/
/* If the constraint record is NULL, there */
/* are no allowed-... restrictions. */
/*=========================================*/
if (constraints == NULL) return(TRUE);
/*=====================================================*/
/* Determine if there are any allowed-... restrictions */
/* for the type of the value being checked. */
/*=====================================================*/
switch (type)
{
case SYMBOL:
if ((constraints->symbolRestriction == FALSE) &&
(constraints->anyRestriction == FALSE))
{ return(TRUE); }
break;
#if OBJECT_SYSTEM
case INSTANCE_NAME:
if ((constraints->instanceNameRestriction == FALSE) &&
(constraints->anyRestriction == FALSE))
{ return(TRUE); }
break;
#endif
case STRING:
if ((constraints->stringRestriction == FALSE) &&
(constraints->anyRestriction == FALSE))
{ return(TRUE); }
break;
case INTEGER:
if ((constraints->integerRestriction == FALSE) &&
(constraints->anyRestriction == FALSE))
{ return(TRUE); }
break;
case FLOAT:
if ((constraints->floatRestriction == FALSE) &&
(constraints->anyRestriction == FALSE))
{ return(TRUE); }
break;
default:
return(TRUE);
}
/*=========================================================*/
/* Search through the restriction list to see if the value */
/* matches one of the allowed values in the list. */
/*=========================================================*/
for (tmpPtr = constraints->restrictionList;
tmpPtr != NULL;
tmpPtr = tmpPtr->nextArg)
{
if ((tmpPtr->type == type) && (tmpPtr->value == vPtr)) return(TRUE);
}
/*====================================================*/
/* If the value wasn't found in the list, then return */
/* FALSE because the constraint has been violated. */
/*====================================================*/
return(FALSE);
}
/**********************************************************************/
/* CheckAllowedClassesConstraint: Determines if a primitive data type */
/* satisfies the allowed-classes constraint fields of a constraint */
/* record. Returns TRUE if the constraints are satisfied, otherwise */
/* FALSE is returned. */
/**********************************************************************/
globle intBool CheckAllowedClassesConstraint(
void *theEnv,
int type,
void *vPtr,
CONSTRAINT_RECORD *constraints)
{
#if OBJECT_SYSTEM
struct expr *tmpPtr;
INSTANCE_TYPE *ins;
DEFCLASS *insClass, *cmpClass;
/*=========================================*/
/* If the constraint record is NULL, there */
/* is no allowed-classes restriction. */
/*=========================================*/
if (constraints == NULL) return(TRUE);
/*======================================*/
/* The constraint is satisfied if there */
/* aren't any class restrictions. */
/*======================================*/
if (constraints->classList == NULL)
{ return(TRUE); }
/*==================================*/
/* Class restrictions only apply to */
/* instances and instance names. */
/*==================================*/
if ((type != INSTANCE_ADDRESS) && (type != INSTANCE_NAME))
{ return(TRUE); }
/*=============================================*/
/* If an instance name is specified, determine */
/* whether the instance exists. */
/*=============================================*/
if (type == INSTANCE_ADDRESS)
{ ins = (INSTANCE_TYPE *) vPtr; }
else
{ ins = FindInstanceBySymbol(theEnv,(SYMBOL_HN *) vPtr); }
if (ins == NULL)
{ return(FALSE); }
/*======================================================*/
/* Search through the class list to see if the instance */
/* belongs to one of the allowed classes in the list. */
/*======================================================*/
insClass = (DEFCLASS *) EnvGetInstanceClass(theEnv,ins);
for (tmpPtr = constraints->classList;
tmpPtr != NULL;
tmpPtr = tmpPtr->nextArg)
{
cmpClass = (DEFCLASS *) EnvFindDefclass(theEnv,ValueToString(tmpPtr->value));
if (cmpClass == NULL) continue;
if (cmpClass == insClass) return(TRUE);
if (EnvSubclassP(theEnv,insClass,cmpClass)) return(TRUE);
}
/*=========================================================*/
/* If a parent class wasn't found in the list, then return */
/* FALSE because the constraint has been violated. */
/*=========================================================*/
return(FALSE);
#else
#if MAC_MCW || WIN_MCW || MAC_XCD
#pragma unused(theEnv)
#pragma unused(type)
#pragma unused(vPtr)
#pragma unused(constraints)
#endif
return(TRUE);
#endif
}
/*************************************************************/
/* CheckRangeConstraint: Determines if a primitive data type */
/* satisfies the range constraint of a constraint record. */
/*************************************************************/
static intBool CheckRangeConstraint(
void *theEnv,
int type,
void *vPtr,
CONSTRAINT_RECORD *constraints)
{
struct expr *minList, *maxList;
/*===================================*/
/* If the constraint record is NULL, */
/* there are no range restrictions. */
/*===================================*/
if (constraints == NULL) return(TRUE);
/*============================================*/
/* If the value being checked isn't a number, */
/* then the range restrictions don't apply. */
/*============================================*/
if ((type != INTEGER) && (type != FLOAT)) return(TRUE);
/*=====================================================*/
/* Check each of the range restrictions to see if the */
/* number falls within at least one of the allowed */
/* ranges. If it falls within one of the ranges, then */
/* return TRUE since the constraint is satisifed. */
/*=====================================================*/
minList = constraints->minValue;
maxList = constraints->maxValue;
while (minList != NULL)
{
if (CompareNumbers(theEnv,type,vPtr,minList->type,minList->value) == LESS_THAN)
{
minList = minList->nextArg;
maxList = maxList->nextArg;
}
else if (CompareNumbers(theEnv,type,vPtr,maxList->type,maxList->value) == GREATER_THAN)
{
minList = minList->nextArg;
maxList = maxList->nextArg;
}
else
{ return(TRUE); }
}
/*===========================================*/
/* Return FALSE since the number didn't fall */
/* within one of the allowed numeric ranges. */
/*===========================================*/
return(FALSE);
}
/************************************************/
/* ConstraintViolationErrorMessage: Generalized */
/* error message for constraint violations. */
/************************************************/
globle void ConstraintViolationErrorMessage(
void *theEnv,
char *theWhat,
char *thePlace,
int command,
int thePattern,
struct symbolHashNode *theSlot,
int theField,
int violationType,
CONSTRAINT_RECORD *theConstraint,
int printPrelude)
{
/*======================================================*/
/* Don't print anything other than the tail explanation */
/* of the error unless asked to do so. */
/*======================================================*/
if (printPrelude)
{
/*===================================*/
/* Print the name of the thing which */
/* caused the constraint violation. */
/*===================================*/
if (violationType == FUNCTION_RETURN_TYPE_VIOLATION)
{
PrintErrorID(theEnv,"CSTRNCHK",1,TRUE);
EnvPrintRouter(theEnv,WERROR,"The function return value ");
}
else if (theWhat != NULL)
{
PrintErrorID(theEnv,"CSTRNCHK",1,TRUE);
EnvPrintRouter(theEnv,WERROR,theWhat);
EnvPrintRouter(theEnv,WERROR," ");
}
/*=======================================*/
/* Print the location of the thing which */
/* caused the constraint violation. */
/*=======================================*/
if (thePlace != NULL)
{
EnvPrintRouter(theEnv,WERROR,"found in ");
if (command) EnvPrintRouter(theEnv,WERROR,"the ");
EnvPrintRouter(theEnv,WERROR,thePlace);
if (command) EnvPrintRouter(theEnv,WERROR," command");
}
/*================================================*/
/* If the violation occured in the LHS of a rule, */
/* indicate which pattern was at fault. */
/*================================================*/
if (thePattern > 0)
{
EnvPrintRouter(theEnv,WERROR,"found in CE #");
PrintLongInteger(theEnv,WERROR,(long int) thePattern);
}
}
/*===============================================================*/
/* Indicate the type of constraint violation (type, range, etc). */
/*===============================================================*/
if ((violationType == TYPE_VIOLATION) ||
(violationType == FUNCTION_RETURN_TYPE_VIOLATION))
{ EnvPrintRouter(theEnv,WERROR,"\ndoes not match the allowed types"); }
else if (violationType == RANGE_VIOLATION)
{
EnvPrintRouter(theEnv,WERROR,"\ndoes not fall in the allowed range ");
PrintRange(theEnv,WERROR,theConstraint);
}
else if (violationType == ALLOWED_VALUES_VIOLATION)
{ EnvPrintRouter(theEnv,WERROR,"\ndoes not match the allowed values"); }
else if (violationType == CARDINALITY_VIOLATION)
{ EnvPrintRouter(theEnv,WERROR,"\ndoes not satisfy the cardinality restrictions"); }
else if (violationType == ALLOWED_CLASSES_VIOLATION)
{ EnvPrintRouter(theEnv,WERROR,"\ndoes not match the allowed classes"); }
/*==============================================*/
/* Print either the slot name or field position */
/* where the constraint violation occured. */
/*==============================================*/
if (theSlot != NULL)
{
EnvPrintRouter(theEnv,WERROR," for slot ");
EnvPrintRouter(theEnv,WERROR,ValueToString(theSlot));
}
else if (theField > 0)
{
EnvPrintRouter(theEnv,WERROR," for field #");
PrintLongInteger(theEnv,WERROR,(long long) theField);
}
EnvPrintRouter(theEnv,WERROR,".\n");
}
/********************************************************************/
/* PrintRange: Prints the range restriction of a constraint record. */
/* For example, 8 to +00 (eight to positive infinity). */
/********************************************************************/
static void PrintRange(
void *theEnv,
char *logicalName,
CONSTRAINT_RECORD *theConstraint)
{
if (theConstraint->minValue->value == SymbolData(theEnv)->NegativeInfinity)
{ EnvPrintRouter(theEnv,logicalName,ValueToString(SymbolData(theEnv)->NegativeInfinity)); }
else PrintExpression(theEnv,logicalName,theConstraint->minValue);
EnvPrintRouter(theEnv,logicalName," to ");
if (theConstraint->maxValue->value == SymbolData(theEnv)->PositiveInfinity)
{ EnvPrintRouter(theEnv,logicalName,ValueToString(SymbolData(theEnv)->PositiveInfinity)); }
else PrintExpression(theEnv,logicalName,theConstraint->maxValue);
}
/*************************************************************/
/* ConstraintCheckDataObject: Given a value stored in a data */
/* object structure and a constraint record, determines if */
/* the data object satisfies the constraint record. */
/*************************************************************/
globle int ConstraintCheckDataObject(
void *theEnv,
DATA_OBJECT *theData,
CONSTRAINT_RECORD *theConstraints)
{
long i; /* 6.04 Bug Fix */
int rv;
struct field *theMultifield;
if (theConstraints == NULL) return(NO_VIOLATION);
if (theData->type == MULTIFIELD)
{
if (CheckCardinalityConstraint(theEnv,(theData->end - theData->begin) + 1,
theConstraints) == FALSE)
{ return(CARDINALITY_VIOLATION); }
theMultifield = ((struct multifield *) theData->value)->theFields;
for (i = theData->begin; i <= theData->end; i++)
{
if ((rv = ConstraintCheckValue(theEnv,theMultifield[i].type,
theMultifield[i].value,
theConstraints)) != NO_VIOLATION)
{ return(rv); }
}
return(NO_VIOLATION);
}
if (CheckCardinalityConstraint(theEnv,1L,theConstraints) == FALSE)
{ return(CARDINALITY_VIOLATION); }
return(ConstraintCheckValue(theEnv,theData->type,theData->value,theConstraints));
}
/****************************************************************/
/* ConstraintCheckValue: Given a value and a constraint record, */
/* determines if the value satisfies the constraint record. */
/****************************************************************/
globle int ConstraintCheckValue(
void *theEnv,
int theType,
void *theValue,
CONSTRAINT_RECORD *theConstraints)
{
if (CheckTypeConstraint(theType,theConstraints) == FALSE)
{ return(TYPE_VIOLATION); }
else if (CheckAllowedValuesConstraint(theType,theValue,theConstraints) == FALSE)
{ return(ALLOWED_VALUES_VIOLATION); }
else if (CheckAllowedClassesConstraint(theEnv,theType,theValue,theConstraints) == FALSE)
{ return(ALLOWED_CLASSES_VIOLATION); }
else if (CheckRangeConstraint(theEnv,theType,theValue,theConstraints) == FALSE)
{ return(RANGE_VIOLATION); }
else if (theType == FCALL)
{
if (CheckFunctionReturnType((int) ValueFunctionType(theValue),theConstraints) == FALSE)
{ return(FUNCTION_RETURN_TYPE_VIOLATION); }
}
return(NO_VIOLATION);
}
/********************************************************************/
/* ConstraintCheckExpressionChain: Checks an expression and nextArg */
/* links for constraint conflicts (argList is not followed). */
/********************************************************************/
globle int ConstraintCheckExpressionChain(
void *theEnv,
struct expr *theExpression,
CONSTRAINT_RECORD *theConstraints)
{
struct expr *theExp;
int min = 0, max = 0, vCode;
/*===========================================================*/
/* Determine the minimum and maximum number of value which */
/* can be derived from the expression chain (max of -1 means */
/* positive infinity). */
/*===========================================================*/
for (theExp = theExpression ; theExp != NULL ; theExp = theExp->nextArg)
{
if (ConstantType(theExp->type)) min++;
else if (theExp->type == FCALL)
{
if ((ExpressionFunctionType(theExp) != 'm') &&
(ExpressionFunctionType(theExp) != 'u')) min++;
else max = -1;
}
else max = -1;
}
/*====================================*/
/* Check for a cardinality violation. */
/*====================================*/
if (max == 0) max = min;
if (CheckRangeAgainstCardinalityConstraint(theEnv,min,max,theConstraints) == FALSE)
{ return(CARDINALITY_VIOLATION); }
/*========================================*/
/* Check for other constraint violations. */
/*========================================*/
for (theExp = theExpression ; theExp != NULL ; theExp = theExp->nextArg)
{
vCode = ConstraintCheckValue(theEnv,theExp->type,theExp->value,theConstraints);
if (vCode != NO_VIOLATION)
return(vCode);
}
return(NO_VIOLATION);
}
#if (! RUN_TIME) && (! BLOAD_ONLY)
/***************************************************/
/* ConstraintCheckExpression: Checks an expression */
/* for constraint conflicts. Returns TRUE if */
/* conflicts are found, otherwise FALSE. */
/***************************************************/
globle int ConstraintCheckExpression(
void *theEnv,
struct expr *theExpression,
CONSTRAINT_RECORD *theConstraints)
{
int rv = NO_VIOLATION;
if (theConstraints == NULL) return(rv);
while (theExpression != NULL)
{
rv = ConstraintCheckValue(theEnv,theExpression->type,
theExpression->value,
theConstraints);
if (rv != NO_VIOLATION) return(rv);
rv = ConstraintCheckExpression(theEnv,theExpression->argList,theConstraints);
if (rv != NO_VIOLATION) return(rv);
theExpression = theExpression->nextArg;
}
return(rv);
}
#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
#if (! RUN_TIME)
/*****************************************************/
/* UnmatchableConstraint: Determines if a constraint */
/* record can still be satisfied by some value. */
/*****************************************************/
globle intBool UnmatchableConstraint(
CONSTRAINT_RECORD *theConstraint)
{
if (theConstraint == NULL) return(FALSE);
if ((! theConstraint->anyAllowed) &&
(! theConstraint->symbolsAllowed) &&
(! theConstraint->stringsAllowed) &&
(! theConstraint->floatsAllowed) &&
(! theConstraint->integersAllowed) &&
(! theConstraint->instanceNamesAllowed) &&
(! theConstraint->instanceAddressesAllowed) &&
(! theConstraint->multifieldsAllowed) &&
(! theConstraint->externalAddressesAllowed) &&
(! theConstraint->voidAllowed) &&
(! theConstraint->factAddressesAllowed))
{ return(TRUE); }
return(FALSE);
}
#endif /* (! RUN_TIME) */