44 static const char* s_cpEmpty =
"vector is empty";
48 static const aint uiNotFound = 0;
49 static const aint uiFound = 1;
50 static const aint uiOpen = 2;
71 static void vFreeAll(
backref* spCtx);
73 static void vRestoreCheckPoints(
backref* spCtx,
aint* uipCheckPoints);
74 static void vSetCheckPoints(
backref* spCtx,
aint* uipCheckPoints);
75 static void vPushEmptyPhrase(
backref* spCtx);
102 aint* uipCounters = NULL;
104 void* vpReturn = NULL;
106 aint uiCount = spParserCtx->uiRuleCount + spParserCtx->uiUdtCount;
112 spCtx->spParserCtx = spParserCtx;
117 memset((
void*) uipCounters, 0, ((
aint)
sizeof(
aint) * uiCount));
122 memset((
void*) spCtx->spRules, 0, ((
aint)
sizeof(
bkr_rule) * spParserCtx->uiRuleCount));
123 if (spParserCtx->uiUdtCount) {
125 ((
aint)
sizeof(
bkr_udt) * spParserCtx->uiUdtCount));
127 for (ui = 0; ui < spParserCtx->uiRuleCount; ui += 1) {
128 spCtx->spRules[ui].spRule = &spParserCtx->spRules[ui];
129 spCtx->spRules[ui].uiIsBackRef =
APG_FALSE;
130 spCtx->spRules[ui].uiHasBackRef = uiUndefined;
131 spCtx->spRules[ui].uiBackRefIndex = uiUndefined;
133 for (ui = 0; ui < spParserCtx->uiUdtCount; ui += 1) {
134 spCtx->spUdts[ui].spUdt = &spParserCtx->spUdts[ui];
135 spCtx->spUdts[ui].uiIsBackRef =
APG_FALSE;
136 spCtx->spUdts[ui].uiBackRefIndex = uiUndefined;
140 spCtx->uiBkrCount = 0;
141 for (ui = 0; ui < spParserCtx->uiOpcodeCount; ui += 1) {
142 if (spParserCtx->spOpcodes[ui].sGen.uiId ==
ID_BKR) {
143 if (spParserCtx->spOpcodes[ui].sBkr.uiMode ==
ID_BKR_MODE_P) {
144 uiIndex = spParserCtx->spOpcodes[ui].sBkr.uiRuleIndex;
145 if (uipCounters[uiIndex] == 0) {
146 if (uiIndex < spParserCtx->uiRuleCount) {
147 spCtx->spRules[uiIndex].uiIsBackRef =
APG_TRUE;
148 spCtx->spRules[uiIndex].uiBackRefIndex = spCtx->uiBkrCount;
150 spCtx->spUdts[uiIndex - spParserCtx->uiRuleCount].uiIsBackRef =
APG_TRUE;
151 spCtx->spUdts[uiIndex - spParserCtx->uiRuleCount].uiBackRefIndex = spCtx->uiBkrCount;
153 spCtx->uiBkrCount += 1;
155 uipCounters[uiIndex] += 1;
186 if (spCtx->uiBkrCount == 0) {
192 spCtx->vppPhraseStacks = (
void**)
vpMemAlloc(spParserCtx->vpMem, ((
aint)
sizeof(
void*) * spCtx->uiBkrCount));
193 memset(spCtx->vppPhraseStacks, 0, ((
aint)
sizeof(
void*) * spCtx->uiBkrCount));
195 for (ui = 0; ui < uiCount; ui += 1) {
196 if (uipCounters[ui]) {
203 if (!uiSESTWalk(spCtx)) {
226 spCtx->vpCheckPoints =
vpVecCtor(spParserCtx->vpMem, ((
aint)
sizeof(
aint) * spCtx->uiBkrCount), 100);
231 spCtx->vpValidate = (
void*) spCtx;
232 vpReturn = (
void*) spCtx;
242 vMemFree(spParserCtx->vpMem, uipCounters);
248 aint* uipCheckPoints;
253 vSetCheckPoints(spCtx, uipCheckPoints);
258 vPushEmptyPhrase(spCtx);
267 aint* uipCheckPoints;
275 vRestoreCheckPoints(spCtx, uipCheckPoints);
297 aint* uipCheckPoints;
304 vSetCheckPoints(spCtx, uipCheckPoints);
310 aint* uipCheckPoints;
317 if (!uipCheckPoints) {
321 vRestoreCheckPoints(spCtx, uipCheckPoints);
330 if (uiIndex < spCtx->spParserCtx->uiRuleCount) {
360 static void vFreeAll(
backref* spCtx){
373 memset((
void*)spCtx, 0,
sizeof(*spCtx));
377 static void vSetCheckPoints(
backref* spCtx,
aint* uipCheckPoints) {
379 for (ui = 0; ui < spCtx->
uiBkrCount; ui += 1) {
383 static void vRestoreCheckPoints(
backref* spCtx,
aint* uipCheckPoints) {
385 for (ui = 0; ui < spCtx->
uiBkrCount; ui += 1) {
395 for(ui = 0; ui < uiLen; ui++, spPhrase++){
403 static void vPushEmptyPhrase(
backref* spCtx) {
419 for (; ui < uiLen; ui += 1) {
432 vSetAllParents(spCtx, spInput);
444 vSetAllParents(spCtx, spInput);
460 vOpWalk(spCtx, spInput);
475 vSetAllParents(spCtx, spInput);
491 const aint* uipChildBeg = spInput->
spOp->sAlt.uipChildList;
492 const aint* uipChildEnd = uipChildBeg + spInput->
spOp->sAlt.uiChildCount;
493 for (; uipChildBeg < uipChildEnd; uipChildBeg++) {
495 vOpWalk(spCtx, spInput);
499 const aint* uipChildBeg = spInput->
spOp->sCat.uipChildList;
500 const aint* uipChildEnd = uipChildBeg + spInput->
spOp->sCat.uiChildCount;
501 for (; uipChildBeg < uipChildEnd; uipChildBeg++) {
503 vOpWalk(spCtx, spInput);
508 vOpWalk(spCtx, spInput);
511 switch (spInput->
spOp->sGen.uiId) {
514 vRnmWalk(spCtx, spInput);
518 vSetAllParents(spCtx, spInput);
522 vAltWalk(spCtx, spInput);
525 vCatWalk(spCtx, spInput);
528 vRepWalk(spCtx, spInput);
546 for (ui = 0; ui < spCtx->
spParserCtx->uiRuleCount; ui += 1) {
550 vRnmWalk(spCtx, &sInput);