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
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.40 06/22/18 */
/* */
/* REORDER HEADER FILE */
/*******************************************************/
/*************************************************************/
/* Purpose: Provides routines necessary for converting the */
/* the LHS of a rule into an appropriate form suitable for */
/* the KB Rete topology. This includes transforming the */
/* LHS so there is at most one "or" CE (and this is the */
/* first CE of the LHS if it is used), adding initial */
/* patterns to the LHS (if no LHS is specified or a "test" */
/* or "not" CE is the first pattern within an "and" CE), */
/* removing redundant CEs, and determining appropriate */
/* information on nesting for implementing joins from the */
/* right. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
/* */
/* Revision History: */
/* */
/* 6.30: Support for join network changes. */
/* */
/* Changes to the algorithm for processing */
/* not/and CE groups. */
/* */
/* Additional optimizations for combining */
/* conditional elements. */
/* */
/* Added support for hashed alpha memories. */
/* */
/* 6.31: Removed the marked flag used for not/and */
/* unification. */
/* */
/* 6.40: Removed LOCALE definition. */
/* */
/* Pragma once and other inclusion changes. */
/* */
/* Added support for booleans with <stdbool.h>. */
/* */
/* Removed use of void pointers for specific */
/* data structures. */
/* */
/*************************************************************/
#ifndef _H_reorder
#pragma once
#define _H_reorder
struct lhsParseNode;
#include "expressn.h"
#include "pattern.h"
#include "ruledef.h"
typedef enum
{
PATTERN_CE_NODE = 2049,
AND_CE_NODE,
OR_CE_NODE,
NOT_CE_NODE,
TEST_CE_NODE,
NAND_CE_NODE,
EXISTS_CE_NODE,
FORALL_CE_NODE,
SF_WILDCARD_NODE,
MF_WILDCARD_NODE,
SF_VARIABLE_NODE,
MF_VARIABLE_NODE,
GBL_VARIABLE_NODE,
PREDICATE_CONSTRAINT_NODE,
RETURN_VALUE_CONSTRAINT_NODE,
FCALL_NODE,
GCALL_NODE,
PCALL_NODE,
INTEGER_NODE,
FLOAT_NODE,
SYMBOL_NODE,
STRING_NODE,
INSTANCE_NAME_NODE,
FACT_STORE_MULTIFIELD_NODE,
DEFTEMPLATE_PTR_NODE,
DEFCLASS_PTR_NODE,
UNKNOWN_NODE
} ParseNodeType;
#define UNSPECIFIED_SLOT USHRT_MAX
#define NO_INDEX USHRT_MAX
/***********************************************************************/
/* lhsParseNode structure: Stores information about the intermediate */
/* parsed representation of the lhs of a rule. */
/***********************************************************************/
struct lhsParseNode
{
ParseNodeType pnType;
union
{
void *value;
CLIPSLexeme *lexemeValue;
struct functionDefinition *functionValue;
};
unsigned int negated : 1;
unsigned int exists : 1;
unsigned int existsNand : 1;
unsigned int logical : 1;
unsigned int multifieldSlot : 1;
unsigned int bindingVariable : 1;
unsigned int derivedConstraints : 1;
unsigned int userCE : 1;
unsigned int whichCE : 7;
//unsigned int marked : 1;
unsigned int withinMultifieldSlot : 1;
unsigned short multiFieldsBefore;
unsigned short multiFieldsAfter;
unsigned short singleFieldsBefore;
unsigned short singleFieldsAfter;
struct constraintRecord *constraints;
struct lhsParseNode *referringNode;
struct patternParser *patternType;
short pattern;
unsigned short index; // TBD is this 1 or 0 based?
CLIPSLexeme *slot;
unsigned short slotNumber; // TBD 1 or 0 based?
int beginNandDepth;
int endNandDepth;
unsigned short joinDepth;
struct expr *networkTest;
struct expr *externalNetworkTest;
struct expr *secondaryNetworkTest;
struct expr *externalLeftHash;
struct expr *externalRightHash;
struct expr *constantSelector;
struct expr *constantValue;
struct expr *leftHash;
struct expr *rightHash;
struct expr *betaHash;
struct lhsParseNode *expression;
struct lhsParseNode *secondaryExpression;
void *userData;
struct lhsParseNode *right;
struct lhsParseNode *bottom;
};
struct lhsParseNode *ReorderPatterns(Environment *,struct lhsParseNode *,bool *);
struct lhsParseNode *CopyLHSParseNodes(Environment *,struct lhsParseNode *);
void CopyLHSParseNode(Environment *,struct lhsParseNode *,struct lhsParseNode *,bool);
struct lhsParseNode *GetLHSParseNode(Environment *);
void ReturnLHSParseNodes(Environment *,struct lhsParseNode *);
struct lhsParseNode *ExpressionToLHSParseNodes(Environment *,struct expr *);
struct expr *LHSParseNodesToExpression(Environment *,struct lhsParseNode *);
void AddInitialPatterns(Environment *,struct lhsParseNode *);
bool IsExistsSubjoin(struct lhsParseNode *,int);
struct lhsParseNode *CombineLHSParseNodes(Environment *,struct lhsParseNode *,struct lhsParseNode *);
bool ConstantNode(struct lhsParseNode *);
unsigned short NodeTypeToType(struct lhsParseNode *);
ParseNodeType TypeToNodeType(unsigned short);
#endif /* _H_reorder */