00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #define _EXPRNOPS_SOURCE_
00026
00027 #include "setup.h"
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <ctype.h>
00034
00035 #include "memalloc.h"
00036 #include "envrnmnt.h"
00037 #include "router.h"
00038 #include "extnfunc.h"
00039 #include "cstrnchk.h"
00040 #include "prntutil.h"
00041 #include "cstrnutl.h"
00042 #include "cstrnops.h"
00043
00044 #include "exprnops.h"
00045
00046 #if (! RUN_TIME)
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 globle int CheckArgumentAgainstRestriction(
00078 void *theEnv,
00079 struct expr *theExpression,
00080 int theRestriction)
00081 {
00082 CONSTRAINT_RECORD *cr1, *cr2, *cr3;
00083
00084
00085
00086
00087
00088
00089 cr1 = ExpressionToConstraintRecord(theEnv,theExpression);
00090
00091
00092
00093
00094
00095
00096 cr2 = ArgumentTypeToConstraintRecord(theEnv,theRestriction);
00097
00098
00099
00100
00101
00102
00103 cr3 = IntersectConstraints(theEnv,cr1,cr2);
00104
00105 RemoveConstraint(theEnv,cr1);
00106 RemoveConstraint(theEnv,cr2);
00107
00108
00109
00110
00111
00112
00113
00114 if (UnmatchableConstraint(cr3))
00115 {
00116 RemoveConstraint(theEnv,cr3);
00117 return(TRUE);
00118 }
00119
00120
00121
00122
00123
00124 RemoveConstraint(theEnv,cr3);
00125 return(FALSE);
00126 }
00127
00128 #endif
00129
00130
00131
00132
00133
00134 globle intBool ConstantExpression(
00135 struct expr *testPtr)
00136 {
00137 while (testPtr != NULL)
00138 {
00139 if ((testPtr->type != SYMBOL) && (testPtr->type != STRING) &&
00140 #if OBJECT_SYSTEM
00141 (testPtr->type != INSTANCE_NAME) && (testPtr->type != INSTANCE_ADDRESS) &&
00142 #endif
00143 (testPtr->type != INTEGER) && (testPtr->type != FLOAT))
00144 { return(FALSE); }
00145 testPtr = testPtr->nextArg;
00146 }
00147
00148 return(TRUE);
00149 }
00150
00151
00152
00153
00154
00155 globle intBool ConstantType(
00156 int theType)
00157 {
00158 switch (theType)
00159 {
00160 case SYMBOL:
00161 case STRING:
00162 case INTEGER:
00163 case FLOAT:
00164 #if OBJECT_SYSTEM
00165 case INSTANCE_NAME:
00166 case INSTANCE_ADDRESS:
00167 #endif
00168 return(TRUE);
00169 }
00170
00171 return(FALSE);
00172 }
00173
00174
00175
00176
00177
00178 globle intBool IdenticalExpression(
00179 struct expr *firstList,
00180 struct expr *secondList)
00181 {
00182
00183
00184
00185
00186
00187 for (;
00188 (firstList != NULL) && (secondList != NULL);
00189 firstList = firstList->nextArg, secondList = secondList->nextArg)
00190 {
00191
00192
00193
00194
00195 if (firstList->type != secondList->type)
00196 { return(FALSE); }
00197
00198 if (firstList->value != secondList->value)
00199 { return (FALSE); }
00200
00201
00202
00203
00204
00205 if (IdenticalExpression(firstList->argList,secondList->argList) == FALSE)
00206 { return(FALSE); }
00207 }
00208
00209
00210
00211
00212
00213
00214
00215 if (firstList != secondList) return(FALSE);
00216
00217
00218
00219
00220
00221 return(TRUE);
00222 }
00223
00224
00225
00226
00227
00228
00229
00230 globle int CountArguments(
00231 struct expr *testPtr)
00232 {
00233 int size = 0;
00234
00235 while (testPtr != NULL)
00236 {
00237 size++;
00238 testPtr = testPtr->nextArg;
00239 }
00240
00241 return(size);
00242 }
00243
00244
00245
00246
00247 globle struct expr *CopyExpression(
00248 void *theEnv,
00249 struct expr *original)
00250 {
00251 struct expr *topLevel, *next, *last;
00252
00253 if (original == NULL) return(NULL);
00254
00255 topLevel = GenConstant(theEnv,original->type,original->value);
00256 topLevel->argList = CopyExpression(theEnv,original->argList);
00257
00258 last = topLevel;
00259 original = original->nextArg;
00260 while (original != NULL)
00261 {
00262 next = GenConstant(theEnv,original->type,original->value);
00263 next->argList = CopyExpression(theEnv,original->argList);
00264
00265 last->nextArg = next;
00266 last = next;
00267 original = original->nextArg;
00268 }
00269
00270 return(topLevel);
00271 }
00272
00273
00274
00275
00276
00277
00278 globle intBool ExpressionContainsVariables(
00279 struct expr *theExpression,
00280 intBool globalsAreVariables)
00281 {
00282 while (theExpression != NULL)
00283 {
00284 if (theExpression->argList != NULL)
00285 {
00286 if (ExpressionContainsVariables(theExpression->argList,globalsAreVariables))
00287 { return(TRUE); }
00288 }
00289
00290 if ((theExpression->type == MF_VARIABLE) ||
00291 (theExpression->type == SF_VARIABLE) ||
00292 (theExpression->type == FACT_ADDRESS) ||
00293 (((theExpression->type == GBL_VARIABLE) ||
00294 (theExpression->type == MF_GBL_VARIABLE)) &&
00295 (globalsAreVariables == TRUE)))
00296 { return(TRUE); }
00297
00298 theExpression = theExpression->nextArg;
00299 }
00300
00301 return(FALSE);
00302 }
00303
00304
00305
00306
00307
00308 globle long ExpressionSize(
00309 struct expr *testPtr)
00310 {
00311 long size = 0;
00312
00313 while (testPtr != NULL)
00314 {
00315 size++;
00316 if (testPtr->argList != NULL)
00317 { size += ExpressionSize(testPtr->argList); }
00318 testPtr = testPtr->nextArg;
00319 }
00320 return(size);
00321 }
00322
00323
00324
00325
00326
00327 globle struct expr *GenConstant(
00328 void *theEnv,
00329 unsigned short type,
00330 void *value)
00331 {
00332 struct expr *top;
00333
00334 top = get_struct(theEnv,expr);
00335 top->nextArg = NULL;
00336 top->argList = NULL;
00337 top->type = type;
00338 top->value = value;
00339
00340 return(top);
00341 }
00342
00343
00344
00345
00346 globle void PrintExpression(
00347 void *theEnv,
00348 char *fileid,
00349 struct expr *theExpression)
00350 {
00351 struct expr *oldExpression;
00352
00353 if (theExpression == NULL)
00354 { return; }
00355
00356 while (theExpression != NULL)
00357 {
00358 switch (theExpression->type)
00359 {
00360 case SF_VARIABLE:
00361 case GBL_VARIABLE:
00362 EnvPrintRouter(theEnv,fileid,"?");
00363 EnvPrintRouter(theEnv,fileid,ValueToString(theExpression->value));
00364 break;
00365
00366 case MF_VARIABLE:
00367 case MF_GBL_VARIABLE:
00368 EnvPrintRouter(theEnv,fileid,"$?");
00369 EnvPrintRouter(theEnv,fileid,ValueToString(theExpression->value));
00370 break;
00371
00372 case FCALL:
00373 EnvPrintRouter(theEnv,fileid,"(");
00374 EnvPrintRouter(theEnv,fileid,ValueToString(ExpressionFunctionCallName(theExpression)));
00375 if (theExpression->argList != NULL) { EnvPrintRouter(theEnv,fileid," "); }
00376 PrintExpression(theEnv,fileid,theExpression->argList);
00377 EnvPrintRouter(theEnv,fileid,")");
00378 break;
00379
00380 default:
00381 oldExpression = EvaluationData(theEnv)->CurrentExpression;
00382 EvaluationData(theEnv)->CurrentExpression = theExpression;
00383 PrintAtom(theEnv,fileid,theExpression->type,theExpression->value);
00384 EvaluationData(theEnv)->CurrentExpression = oldExpression;
00385 break;
00386 }
00387
00388 theExpression = theExpression->nextArg;
00389 if (theExpression != NULL) EnvPrintRouter(theEnv,fileid," ");
00390 }
00391
00392 return;
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 globle struct expr *CombineExpressions(
00405 void *theEnv,
00406 struct expr *expr1,
00407 struct expr *expr2)
00408 {
00409 struct expr *tempPtr;
00410
00411
00412
00413
00414
00415 if (expr1 == NULL) return(expr2);
00416
00417
00418
00419
00420
00421 if (expr2 == NULL) return(expr1);
00422
00423
00424
00425
00426
00427
00428
00429 if ((expr1->value == ExpressionData(theEnv)->PTR_AND) &&
00430 (expr2->value != ExpressionData(theEnv)->PTR_AND))
00431 {
00432 tempPtr = expr1->argList;
00433 if (tempPtr == NULL)
00434 {
00435 rtn_struct(theEnv,expr,expr1);
00436 return(expr2);
00437 }
00438
00439 while (tempPtr->nextArg != NULL)
00440 { tempPtr = tempPtr->nextArg; }
00441
00442 tempPtr->nextArg = expr2;
00443 return(expr1);
00444 }
00445
00446
00447
00448
00449
00450
00451
00452 if ((expr1->value != ExpressionData(theEnv)->PTR_AND) &&
00453 (expr2->value == ExpressionData(theEnv)->PTR_AND))
00454 {
00455 tempPtr = expr2->argList;
00456 if (tempPtr == NULL)
00457 {
00458 rtn_struct(theEnv,expr,expr2);
00459 return(expr1);
00460 }
00461
00462 expr2->argList = expr1;
00463 expr1->nextArg = tempPtr;
00464
00465 return(expr2);
00466 }
00467
00468
00469
00470
00471
00472
00473
00474 if ((expr1->value == ExpressionData(theEnv)->PTR_AND) &&
00475 (expr2->value == ExpressionData(theEnv)->PTR_AND))
00476 {
00477 tempPtr = expr1->argList;
00478 if (tempPtr == NULL)
00479 {
00480 rtn_struct(theEnv,expr,expr1);
00481 return(expr2);
00482 }
00483
00484 while (tempPtr->nextArg != NULL)
00485 { tempPtr = tempPtr->nextArg; }
00486
00487 tempPtr->nextArg = expr2->argList;
00488 rtn_struct(theEnv,expr,expr2);
00489
00490 return(expr1);
00491 }
00492
00493
00494
00495
00496
00497
00498
00499 tempPtr = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_AND);
00500 tempPtr->argList = expr1;
00501 expr1->nextArg = expr2;
00502 return(tempPtr);
00503 }
00504
00505
00506
00507
00508
00509 globle struct expr *AppendExpressions(
00510 struct expr *expr1,
00511 struct expr *expr2)
00512 {
00513 struct expr *tempPtr;
00514
00515
00516
00517
00518
00519 if (expr1 == NULL) return(expr2);
00520
00521
00522
00523
00524
00525 if (expr2 == NULL) return(expr1);
00526
00527
00528
00529
00530
00531
00532 tempPtr = expr1;
00533 while (tempPtr->nextArg != NULL) tempPtr = tempPtr->nextArg;
00534 tempPtr->nextArg = expr2;
00535
00536
00537
00538
00539
00540 return(expr1);
00541 }
00542