51 static const char* s_cpEmpty =
"vector is empty";
55 static const aint uiNotFound = 0;
56 static const aint uiFound = 1;
57 static const aint uiOpen = 2;
72 static void vSESTWalk(
backref* spCtx);
78 static void vFreeAll(
backref* spCtx);
80 static void vRestoreCheckPoints(
backref* spCtx,
aint* uipCheckPoints);
81 static void vSetCheckPoints(
backref* spCtx,
aint* uipCheckPoints);
105 aint* uipCounters = NULL;
107 void* vpReturn = NULL;
109 aint uiCount = spParserCtx->uiRuleCount + spParserCtx->uiUdtCount;
115 spCtx->spParserCtx = spParserCtx;
120 memset((
void*) uipCounters, 0, ((
aint)
sizeof(
aint) * uiCount));
125 memset((
void*) spCtx->spRules, 0, ((
aint)
sizeof(
bkr_rule) * spParserCtx->uiRuleCount));
126 if (spParserCtx->uiUdtCount) {
128 ((
aint)
sizeof(
bkr_udt) * spParserCtx->uiUdtCount));
130 for (ui = 0; ui < spParserCtx->uiRuleCount; ui += 1) {
131 spCtx->spRules[ui].spRule = &spParserCtx->spRules[ui];
132 spCtx->spRules[ui].uiIsBackRef =
APG_FALSE;
133 spCtx->spRules[ui].uiHasBackRef = uiUndefined;
134 spCtx->spRules[ui].uiBackRefIndex = uiUndefined;
136 for (ui = 0; ui < spParserCtx->uiUdtCount; ui += 1) {
137 spCtx->spUdts[ui].spUdt = &spParserCtx->spUdts[ui];
138 spCtx->spUdts[ui].uiIsBackRef =
APG_FALSE;
139 spCtx->spUdts[ui].uiBackRefIndex = uiUndefined;
143 spCtx->uiBkrCount = 0;
144 for (ui = 0; ui < spParserCtx->uiOpcodeCount; ui += 1) {
145 if (spParserCtx->spOpcodes[ui].sGen.uiId ==
ID_BKR) {
146 if (spParserCtx->spOpcodes[ui].sBkr.uiMode ==
ID_BKR_MODE_U) {
147 uiIndex = spParserCtx->spOpcodes[ui].sBkr.uiRuleIndex;
148 if (uipCounters[uiIndex] == 0) {
149 if (uiIndex < spParserCtx->uiRuleCount) {
150 spCtx->spRules[uiIndex].uiIsBackRef =
APG_TRUE;
151 spCtx->spRules[uiIndex].uiBackRefIndex = spCtx->uiBkrCount;
153 spCtx->spUdts[uiIndex - spParserCtx->uiRuleCount].uiIsBackRef =
APG_TRUE;
154 spCtx->spUdts[uiIndex - spParserCtx->uiRuleCount].uiBackRefIndex = spCtx->uiBkrCount;
156 spCtx->uiBkrCount += 1;
158 uipCounters[uiIndex] += 1;
190 if (spCtx->uiBkrCount == 0) {
196 spCtx->vppPhraseStacks = (
void**)
vpMemAlloc(spParserCtx->vpMem, ((
aint)
sizeof(
void*) * spCtx->uiBkrCount));
197 memset(spCtx->vppPhraseStacks, 0, ((
aint)
sizeof(
void*) * spCtx->uiBkrCount));
199 for (ui = 0; ui < uiCount; ui += 1) {
200 if (uipCounters[ui]) {
229 spCtx->vpCheckPoints =
vpVecCtor(spParserCtx->vpMem, ((
aint)
sizeof(
aint) * spCtx->uiBkrCount), 100);
234 spCtx->vpValidate = (
void*) spCtx;
235 vpReturn = (
void*) spCtx;
245 vMemFree(spParserCtx->vpMem, uipCounters);
249 static void vFreeAll(
backref* spCtx){
262 memset((
void*)spCtx, 0,
sizeof(*spCtx));
266 static void vSetCheckPoints(
backref* spCtx,
aint* uipCheckPoints) {
268 for (ui = 0; ui < spCtx->
uiBkrCount; ui += 1) {
272 static void vRestoreCheckPoints(
backref* spCtx,
aint* uipCheckPoints) {
274 for (ui = 0; ui < spCtx->
uiBkrCount; ui += 1) {
284 aint* uipCheckPoints;
289 vSetCheckPoints(spCtx, uipCheckPoints);
297 aint* uipCheckPoints;
310 vRestoreCheckPoints(spCtx, uipCheckPoints);
329 aint* uipCheckPoints;
336 vSetCheckPoints(spCtx, uipCheckPoints);
342 aint* uipCheckPoints;
353 vRestoreCheckPoints(spCtx, uipCheckPoints);
362 if (uiIndex < spCtx->spParserCtx->uiRuleCount) {
400 for (; ui < uiLen; ui += 1) {
413 vSetAllParents(spCtx, spInput);
426 vSetAllParents(spCtx, spInput);
442 vOpWalk(spCtx, spInput);
457 vSetAllParents(spCtx, spInput);
473 const aint* uipChildBeg = spInput->
spOp->sAlt.uipChildList;
474 const aint* uipChildEnd = uipChildBeg + spInput->
spOp->sAlt.uiChildCount;
475 for (; uipChildBeg < uipChildEnd; uipChildBeg++) {
477 vOpWalk(spCtx, spInput);
481 const aint* uipChildBeg = spInput->
spOp->sCat.uipChildList;
482 const aint* uipChildEnd = uipChildBeg + spInput->
spOp->sCat.uiChildCount;
483 for (; uipChildBeg < uipChildEnd; uipChildBeg++) {
485 vOpWalk(spCtx, spInput);
490 vOpWalk(spCtx, spInput);
493 switch (spInput->
spOp->sGen.uiId) {
496 vRnmWalk(spCtx, spInput);
500 vSetAllParents(spCtx, spInput);
504 vAltWalk(spCtx, spInput);
507 vCatWalk(spCtx, spInput);
510 vRepWalk(spCtx, spInput);
517 static void vSESTWalk(
backref* spCtx) {
523 XTHROW(spCtx->
spException,
"internal error - unexpected vpVecPop() error walking the tree");
527 for (ui = 0; ui < spCtx->
spParserCtx->uiRuleCount; ui += 1) {
531 vRnmWalk(spCtx, &sInput);