⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reorder.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
   /* Return the newly expanded CEs. */   /*================================*/   return(copyOfCEs);  }/***********************************************************//* CompressCEs:              *//***********************************************************/static struct lhsParseNode *CompressCEs(  void *theEnv,  struct lhsParseNode *theLHS,  int *newChange)  {   struct lhsParseNode *argPtr, *lastArg, *nextArg;   struct lhsParseNode *tempArg;   int change;   struct expr *e1, *e2;   /*======================================================*/   /* Loop through the CEs as long as changes can be made. */   /*======================================================*/   change = TRUE;   *newChange = FALSE;   while (change)     {      change = FALSE;      lastArg = NULL;      for (argPtr = theLHS->right;           argPtr != NULL;)        {         /*=====================================*/         /* Remove duplication of or CEs within */         /* or CEs and and CEs within and CEs.  */         /*=====================================*/         if (((theLHS->type == OR_CE) && (argPtr->type == OR_CE)) ||             ((theLHS->type == AND_CE) && (argPtr->type == AND_CE)))           {            if (argPtr->logical) theLHS->logical = TRUE;            change = TRUE;            *newChange = TRUE;            tempArg = argPtr->right;            nextArg = argPtr->bottom;            argPtr->right = NULL;            argPtr->bottom = NULL;            ReturnLHSParseNodes(theEnv,argPtr);            if (lastArg == NULL)              { theLHS->right = tempArg; }            else              { lastArg->bottom = tempArg; }            argPtr = tempArg;            while (tempArg->bottom != NULL) tempArg = tempArg->bottom;            tempArg->bottom = nextArg;           }         /*=======================================================*/         /* Replace not CEs containing a test CE with just a test */         /* CE with the original test CE condition negated.       */         /*=======================================================*/         else if ((theLHS->type == NOT_CE) && (argPtr->type == TEST_CE))           {            change = TRUE;            *newChange = TRUE;            e1 = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_NOT);            e2 = LHSParseNodesToExpression(theEnv,argPtr->expression);            e1->arg_list = e2;            CopyLHSParseNode(theEnv,theLHS,argPtr,TRUE);            ReturnLHSParseNodes(theEnv,argPtr);            ReturnLHSParseNodes(theEnv,theLHS->expression);            theLHS->expression = ExpressionToLHSParseNodes(theEnv,e1);            theLHS->right = NULL;            ReturnExpression(theEnv,e1);            break;           }         /*==============================*/         /* Two adjacent test CEs within */         /* an and CE can be combined.   */         /*==============================*/         else if ((theLHS->type == AND_CE) && (argPtr->type == TEST_CE) &&                  ((argPtr->bottom != NULL) ? argPtr->bottom->type == TEST_CE :                                              FALSE) &&                   (argPtr->beginNandDepth == argPtr->endNandDepth) &&                   (argPtr->endNandDepth == argPtr->bottom->beginNandDepth))           {            change = TRUE;            *newChange = TRUE;            e1 = LHSParseNodesToExpression(theEnv,argPtr->expression);            e2 = LHSParseNodesToExpression(theEnv,argPtr->bottom->expression);            e1 = CombineExpressions(theEnv,e1,e2);            ReturnLHSParseNodes(theEnv,argPtr->expression);            argPtr->expression = ExpressionToLHSParseNodes(theEnv,e1);            ReturnExpression(theEnv,e1);            tempArg = argPtr->bottom;            argPtr->bottom = tempArg->bottom;            tempArg->bottom = NULL;            ReturnLHSParseNodes(theEnv,tempArg);           }         /*=====================================*/         /* Replace and CEs containing a single */         /* test CE with just a test CE.        */         /*=====================================*/         else if ((theLHS->type == AND_CE) && (argPtr->type == TEST_CE) &&                  (theLHS->right == argPtr) && (argPtr->bottom == NULL))           {            change = TRUE;            *newChange = TRUE;            CopyLHSParseNode(theEnv,theLHS,argPtr,TRUE);            theLHS->right = NULL;            ReturnLHSParseNodes(theEnv,argPtr);            break;           }         /*===================================================*/         /* If no changes are needed, move on to the next CE. */         /*===================================================*/         else           {            lastArg = argPtr;            argPtr = argPtr->bottom;           }        }     }   /*===========================*/   /* Return the reordered LHS. */   /*===========================*/   return(theLHS);  }/*********************************************************************//* CopyLHSParseNodes: Copies a linked group of conditional elements. *//*********************************************************************/globle struct lhsParseNode *CopyLHSParseNodes(  void *theEnv,  struct lhsParseNode *listOfCEs)  {   struct lhsParseNode *newList;   if (listOfCEs == NULL)     { return(NULL); }   newList = get_struct(theEnv,lhsParseNode);   CopyLHSParseNode(theEnv,newList,listOfCEs,TRUE);   newList->right = CopyLHSParseNodes(theEnv,listOfCEs->right);   newList->bottom = CopyLHSParseNodes(theEnv,listOfCEs->bottom);   return(newList);  }/**********************************************************//* CopyLHSParseNode: Copies a single conditional element. *//**********************************************************/globle void CopyLHSParseNode(  void *theEnv,  struct lhsParseNode *dest,  struct lhsParseNode *src,  int duplicate)  {   dest->type = src->type;   dest->value = src->value;   dest->negated = src->negated;   dest->exists = src->exists;   dest->existsNand = src->existsNand;   dest->bindingVariable = src->bindingVariable;   dest->withinMultifieldSlot = src->withinMultifieldSlot;   dest->multifieldSlot = src->multifieldSlot;   dest->multiFieldsBefore = src->multiFieldsBefore;   dest->multiFieldsAfter = src->multiFieldsAfter;   dest->singleFieldsBefore = src->singleFieldsBefore;   dest->singleFieldsAfter = src->singleFieldsAfter;   dest->logical = src->logical;   dest->userCE = src->userCE;   dest->referringNode = src->referringNode;   dest->patternType = src->patternType;   dest->pattern = src->pattern;   dest->index = src->index;   dest->slot = src->slot;   dest->slotNumber = src->slotNumber;   dest->beginNandDepth = src->beginNandDepth;   dest->endNandDepth = src->endNandDepth;   dest->joinDepth = src->joinDepth;   /*==========================================================*/   /* The duplicate flag controls whether pointers to existing */   /* data structures are used when copying some slots or if   */   /* new copies of the data structures are made.              */   /*==========================================================*/   if (duplicate)     {      dest->networkTest = CopyExpression(theEnv,src->networkTest);      dest->externalNetworkTest = CopyExpression(theEnv,src->externalNetworkTest);      dest->secondaryNetworkTest = CopyExpression(theEnv,src->secondaryNetworkTest);      dest->secondaryExternalNetworkTest = CopyExpression(theEnv,src->secondaryExternalNetworkTest);      dest->externalRightHash = CopyExpression(theEnv,src->externalRightHash);      dest->externalLeftHash = CopyExpression(theEnv,src->externalLeftHash);      dest->constantSelector = CopyExpression(theEnv,src->constantSelector);      dest->constantValue = CopyExpression(theEnv,src->constantValue);      dest->leftHash = CopyExpression(theEnv,src->leftHash);      dest->betaHash = CopyExpression(theEnv,src->betaHash);      dest->rightHash = CopyExpression(theEnv,src->rightHash);      if (src->userData == NULL)        { dest->userData = NULL; }      else if (src->patternType->copyUserDataFunction == NULL)        { dest->userData = src->userData; }      else        { dest->userData = (*src->patternType->copyUserDataFunction)(theEnv,src->userData); }      dest->expression = CopyLHSParseNodes(theEnv,src->expression);      dest->constraints = CopyConstraintRecord(theEnv,src->constraints);      if (dest->constraints != NULL) dest->derivedConstraints = TRUE;      else dest->derivedConstraints = FALSE;     }   else     {      dest->networkTest = src->networkTest;      dest->externalNetworkTest = src->externalNetworkTest;      dest->secondaryNetworkTest = src->secondaryNetworkTest;      dest->secondaryExternalNetworkTest = src->secondaryExternalNetworkTest;      dest->externalRightHash = src->externalRightHash;      dest->externalLeftHash = src->externalLeftHash;      dest->constantSelector = src->constantSelector;      dest->constantValue = src->constantValue;      dest->leftHash = src->leftHash;      dest->betaHash = src->betaHash;      dest->rightHash = src->rightHash;      dest->userData = src->userData;      dest->expression = src->expression;      dest->derivedConstraints = FALSE;      dest->constraints = src->constraints;     }  }/****************************************************//* GetLHSParseNode: Creates an empty node structure *//*   used for building conditional elements.        *//****************************************************/globle struct lhsParseNode *GetLHSParseNode(  void *theEnv)  {   struct lhsParseNode *newNode;   newNode = get_struct(theEnv,lhsParseNode);   newNode->type = UNKNOWN_VALUE;   newNode->value = NULL;   newNode->negated = FALSE;   newNode->exists = FALSE;   newNode->existsNand = FALSE;   newNode->bindingVariable = FALSE;   newNode->withinMultifieldSlot = FALSE;   newNode->multifieldSlot = FALSE;   newNode->multiFieldsBefore = 0;   newNode->multiFieldsAfter = 0;   newNode->singleFieldsBefore = 0;   newNode->singleFieldsAfter = 0;   newNode->logical = FALSE;   newNode->derivedConstraints = FALSE;   newNode->userCE = TRUE;   newNode->constraints = NULL;   newNode->referringNode = NULL;   newNode->patternType = NULL;   newNode->pattern = -1;   newNode->index = -1;   newNode->slot = NULL;   newNode->slotNumber = -1;   newNode->beginNandDepth = 1;   newNode->endNandDepth = 1;   newNode->joinDepth = 0;   newNode->userData = NULL;   newNode->networkTest = NULL;   newNode->externalNetworkTest = NULL;   newNode->secondaryNetworkTest = NULL;   newNode->secondaryExternalNetworkTest = NULL;   newNode->externalRightHash = NULL;   newNode->externalLeftHash = NULL;   newNode->constantSelector = NULL;   newNode->constantValue = NULL;   newNode->leftHash = NULL;   newNode->betaHash = NULL;   newNode->rightHash = NULL;   newNode->expression = NULL;   newNode->right = NULL;   newNode->bottom = NULL;   return(newNode);  }/********************************************************//* ReturnLHSParseNodes:  Returns a multiply linked list *//*   of lhsParseNode structures to the memory manager.  *//********************************************************/globle void ReturnLHSParseNodes(  void *theEnv,  struct lhsParseNode *waste)  {   if (waste != NULL)     {      ReturnExpression(theEnv,waste->networkTest);      ReturnExpression(theEnv,waste->externalNetworkTest);      ReturnExpression(theEnv,waste->secondaryNetworkTest);      ReturnExpression(theEnv,waste->secondaryExternalNetworkTest);      ReturnExpression(theEnv,waste->externalRightHash);      ReturnExpression(theEnv,waste->externalLeftHash);      ReturnExpression(theEnv,waste->constantSelector);      ReturnExpression(theEnv,waste->constantValue);      ReturnExpression(theEnv,waste->leftHash);      ReturnExpression(theEnv,waste->betaHash);      ReturnExpression(theEnv,waste->rightHash);      ReturnLHSParseNodes(theEnv,waste->right);      ReturnLHSParseNodes(theEnv,waste->bottom);      ReturnLHSParseNodes(theEnv,waste->expression);      if (waste->derivedConstraints) RemoveConstraint(theEnv,waste->constraints);      if ((waste->userData != NULL) &&          (waste->patternType->returnUserDataFunction != NULL))        { (*waste->patternType->returnUserDataFunction)(theEnv,waste->userData); }      rtn_struct(theEnv,lhsParseNode,waste);     }  }/********************************************************//* ExpressionToLHSParseNodes: Copies an expression into *//*   the equivalent lhsParseNode data structures.       *//********************************************************/globle struct lhsParseNode *ExpressionToLHSParseNodes(  void *theEnv,  struct expr *expressionList)  {   struct lhsParseNode *newList, *theList;   struct FunctionDefinition *theFunction;   int i, theRestriction;   /*===========================================*/   /* A NULL expression requires no conversion. */   /*===========================================*/   if (expressionList == NULL) return(NULL);   /*====================================*/   /* Recursively convert the expression */   /* to lhsParseNode data structures.   */   /*====================================*/   newList = GetLHSParseNode(theEnv);   newList->type = expressionList->type;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -