Ejemplo n.º 1
0
static unsigned
lr0_goto(struct lr0_machine_builder * builder, struct lr0_state * state, const struct lr0_point closure[], unsigned nclosure)
{
    unsigned nsym = 0;
    unsigned const grammar_size = builder->machine.grammar->n_terminals + builder->machine.grammar->n_nonterminals;
    union lr0_goto_scratch scratch[grammar_size];
    union lr0_goto_scratch *symlookup[grammar_size];
    memset(scratch, 0, sizeof(scratch));
    memset(symlookup, 0, sizeof(symlookup));
    /* First pass - determine used symbols and kernel sizes */
    for (unsigned i = 0; i < nclosure; ++i) {
        const struct rule * r = closure[i].rule;
        if (r->length <= closure[i].pos) /* nothing to add */
            continue;
        const struct symbol * fs = r->rs[closure[i].pos].sym;
        if (! symlookup[fs->id]) {
            symlookup[fs->id] = &scratch[nsym++];
            symlookup[fs->id]->tmp.sym = fs;
        }
        ++(symlookup[fs->id]->tmp.ssize);
    }
    for (unsigned i = 0; i < nsym; ++i) {
        struct lr0_state * state = calloc(1, sizeof_struct_lr0_state(scratch[i].tmp.ssize));
        if (! state)
            abort();
        state->access_sym = scratch[i].tmp.sym;
        scratch[i].state = state;
    }
    /* Second pass - actually build the kernels */
    for (unsigned i = 0; i < nclosure; ++i) {
        const struct rule * r = closure[i].rule;
        if (r->length <= closure[i].pos) /* nothing to add */
            continue;
        const struct symbol * fs = r->rs[closure[i].pos].sym;
        struct lr0_state * newstate = (struct lr0_state *) symlookup[fs->id]->state;
        newstate->points[newstate->npoints].rule = r;
        newstate->points[newstate->npoints].pos = closure[i].pos + 1;
        ++(newstate->npoints);
    }
    /* Done - get the result */
    qsort(scratch, nsym, sizeof(union lr0_goto_scratch), cmp_goto);
    struct lr0_gototab * gototab  = calloc(1, sizeof_struct_lr0_gototab(nsym));
    if (! gototab)
        abort();
    gototab->ngo = nsym;
    for (unsigned i = 0; i < nsym; ++i) {
        struct lr0_state * newstate = scratch[i].state;
        qsort(newstate->points, newstate->npoints, sizeof(struct lr0_point), cmp_point);
        gototab->go[i] = commit_state(builder, newstate);
    }
    state->gototab = gototab;
    return nsym;
}
Ejemplo n.º 2
0
static void
gtk_im_context_wayland_set_cursor_location (GtkIMContext *context,
                                            GdkRectangle *rect)
{
  GtkIMContextWayland *context_wayland;

  context_wayland = GTK_IM_CONTEXT_WAYLAND (context);

  context_wayland->cursor_rect = *rect;
  notify_cursor_location (context_wayland);
  commit_state (context_wayland);
}
Ejemplo n.º 3
0
void QWaylandTextInput::updateState()
{
    if (!QGuiApplication::focusObject())
        return;

    QInputMethodQueryEvent event(Qt::ImQueryAll);
    QCoreApplication::sendEvent(QGuiApplication::focusObject(), &event);

    const QString &text = event.value(Qt::ImSurroundingText).toString();
    const int cursor = event.value(Qt::ImCursorPosition).toInt();
    const int anchor = event.value(Qt::ImAnchorPosition).toInt();

    set_surrounding_text(text, text.leftRef(cursor).toUtf8().size(), text.leftRef(anchor).toUtf8().size());

    commit_state(++m_serial);
}
Ejemplo n.º 4
0
lr0_machine_t
lr0_build(const struct grammar *grammar)
{
    struct lr0_machine_builder * builder = calloc(1, sizeof(struct lr0_machine_builder));
    if (! builder)
        abort();
    builder->machine.grammar = grammar;

    struct lr0_state * state0 = calloc(1, sizeof_struct_lr0_state(1));
    if (! state0)
        abort();
    state0->npoints = 1;
    state0->points[0].rule = grammar->start->nt.rules; /* first rule */
    assert(state0->points[0].rule->next == NULL);
    state0->points[0].pos = 0;

    builder->nstates = 1;
    builder->machine.first_state = state0;
    builder->last_state = state0;

    {
        struct lr0_state * state_end = calloc(1, sizeof_struct_lr0_state(1));
        if (! state_end)
            abort();
        state_end->npoints = 1;
        state_end->points[0].rule = grammar->start->nt.rules; /* first rule */
        state_end->points[0].pos = 2;
        state_end->access_sym = grammar->symlist.first;
        assert(state_end->access_sym->id == 0);
        commit_state(builder, state_end);
    }

    for (struct lr0_state * s = state0; s; s = s->next) {
        struct lr0_point points[s->npoints + grammar->n_rules];
        unsigned n = lr0_closure(&builder->machine, points, s);
        s->nclosure = n;
        lr0_goto(builder, s, points, n);
    }
    lr0_machine_t mach = calloc(1, sizeof(struct lr0_machine));
    if (! mach)
        abort();
    *mach = builder->machine;
    free(builder);
    for (const struct lr0_state * s = mach->first_state; s; s = s->next)
        ((struct lr0_state*)s)->tmp.hash_next = NULL;
    return mach;
}
Ejemplo n.º 5
0
static void
gtk_im_context_wayland_set_surrounding (GtkIMContext *context,
                                        const gchar  *text,
                                        gint          len,
                                        gint          cursor_index)
{
  GtkIMContextWayland *context_wayland;

  context_wayland = GTK_IM_CONTEXT_WAYLAND (context);

  g_free (context_wayland->surrounding.text);
  context_wayland->surrounding.text = g_strdup (text);
  context_wayland->surrounding.cursor_idx = cursor_index;

  notify_surrounding_text (context_wayland);
  commit_state (context_wayland);
}
Ejemplo n.º 6
0
static void
gtk_im_context_wayland_focus_in (GtkIMContext *context)
{
  GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context);

  if (global->current == context)
    return;
  if (!global->text_input)
    return;

  global->current = context;
  enable_text_input (context_wayland, FALSE);
  notify_content_type (context_wayland);
  notify_surrounding_text (context_wayland);
  notify_cursor_location (context_wayland);
  commit_state (context_wayland);
}
Ejemplo n.º 7
0
static void
on_content_type_changed (GtkIMContextWayland *context)
{
  notify_content_type (context);
  commit_state (context);
}