/* unroll the stack until the last named context. * then discard it. Used to handle the : * let f x y = ... * in ... * where the context is reseted after the in. Context may have * been really nested before that. */ static void popLastNamed ( void ) { int i = getLastNamedIndex (); if (i >= 0) { stackIndex = i; toDoNext = stack[i].callback; vStringClear (stack[i].contextName); } else { /* ok, no named context found... * (should not happen). */ stackIndex = 0; toDoNext = &globalScope; } }
/* used to prepare tag for OCaml, just in case their is a need to * add additional information to the tag. */ static void prepareTag (tagEntryInfo * tag, vString const *name, ocamlKind kind) { int parentIndex; initTagEntry (tag, vStringValue (name), &(OcamlKinds[kind])); if (kind == K_MODULE) { tag->lineNumberEntry = TRUE; tag->lineNumber = 1; } parentIndex = getLastNamedIndex (); if (parentIndex >= 0) { tag->extensionFields.scopeKind = contextDescription (stack[parentIndex].type); tag->extensionFields.scopeName = vStringValue (stack[parentIndex].contextName); } }
/* Push a new context, handle null string */ static void pushContext (contextKind kind, contextType type, parseNext after, vString const *contextName) { int parentIndex; if (stackIndex >= OCAML_MAX_STACK_SIZE) { verbose ("OCaml Maximum depth reached"); return; } stack[stackIndex].kind = kind; stack[stackIndex].type = type; stack[stackIndex].callback = after; parentIndex = getLastNamedIndex (); if (contextName == NULL) { vStringClear (stack[stackIndex++].contextName); return; } if (parentIndex >= 0) { vStringCopy (stack[stackIndex].contextName, stack[parentIndex].contextName); vStringPut (stack[stackIndex].contextName, contextTypeSuffix (stack[parentIndex].type)); vStringCat (stack[stackIndex].contextName, contextName); } else vStringCopy (stack[stackIndex].contextName, contextName); stackIndex++; }