Exemplo n.º 1
0
/**
 * Change the parent of a talloc'ed memory chunk. This will affect the
 * dependencies of the entire subtree rooted at the given chunk.
 *
 * @param mem     pointer to previously talloc'ed memory chunk.
 * @param parent  pointer to previously talloc'ed memory chunk from which this
 *                chunk depends, or NULL.
 */
void talloc_set_parent(void *mem, void *parent) {

    if (!mem)
        return;

    if (!is_root(mem)) {

        /* Remove node from old tree. */

        if (next(mem))
            prev(next(mem)) = prev(mem);

        if (!is_first(mem))
            next(prev(mem)) = next(mem);

        if (is_first(mem))
            child(parent(mem)) = next(mem);
    }

    next(mem) = prev(mem) = NULL;

    if (parent) {

        /* Insert node into new tree. */

        if (child(parent)) {
            next(mem) = child(parent);
            prev(child(parent)) = mem;
        }

        parent(mem) = parent;
        child(parent) = mem;
    }
}
Exemplo n.º 2
0
void* linkedlist_remove(linkedlist _list, void* data)
{
    linkedlist_t* list = (linkedlist_t*) _list;
    node* n = find_by_data(list, data);

    if(NULL == n)
        return NULL;

    if(is_first(list, n)) // at the first
    {
        if(is_last(list, n)) // only one exists
        {
            set_head(list, NULL);
            set_tail(list, NULL);
        }
        else // one or more exist
        {
            set_head(list, get_next(n));
            set_prev(n, NULL);
        }
    }
    else if(is_last((linkedlist_t*)_list, n))
    {
        set_next(get_prev(n), NULL);
        set_tail(list, get_prev(n));
    }
    else
    {
        set_prev(get_next(n), get_prev(n));
        set_next(get_prev(n), get_next(n));
    }
    list->size--;
    free(n);
    return data;
}
Exemplo n.º 3
0
 void ASTIterator::rewind()
 {
     reset();
     while (!is_first())
     {
         previous();
     }
 }
Exemplo n.º 4
0
/**
 * Get the parent of a talloc'ed memory chunk (the chunk on which it depends).
 *
 * @param mem  pointer to previously talloc'ed memory chunk.
 *
 * @return pointer to the parent memory chunk (could be NULL).
 */
void *talloc_get_parent(void *mem) {

    if (!mem || is_root(mem))
        return NULL;

    while (!is_first(mem))
        mem = prev(mem);

    return parent(mem);
}
Exemplo n.º 5
0
void		ft_inter(char *s1, char *s2)
{
	int i;

	i = 0;
	while (s1[i])
	{
		if (is_in_string(s2, s1[i]) && is_first(s1, s1[i], i))
			write(1, &s1[i], 1);
		i++;
	}
}
Exemplo n.º 6
0
Arquivo: inter.c Projeto: Magatte/fdf
void		inter(char *str, char *str2)
{
	int		i;

	i = 0;
	while (str[i])
	{
		if (is_instring(str2, str[i]) & is_first(str, str[i], i))
			ft_putchar(str[i]);
		++i;
	}
}
Exemplo n.º 7
0
std::string sequence_formatter::
value_for_position(const infix_configuration& ic) const {
    if (is_single()) {
        if (!ic.first().empty()) {
            // when we are single, first takes priority if supplied.
            return ic.first();
        }
        return ic.last();
    } else if (is_first() && !ic.first().empty()) {
        // if is first and first has been supplied, it takes precedence.
        return ic.first();
    } else if (!is_last() && !ic.not_last().empty()) {
        // if we are not last (including first) and not last has been
        // supplied.
        return ic.not_last();
    } else if (!is_first() && (!is_last() || !ic.not_first().empty())) {
        // when we are last, not first takes precedence if supplied.
        return ic.not_first();
    } else if (is_last())
        return ic.last();

    return empty;
}
Exemplo n.º 8
0
void sequence_formatter::log_current_state() const {
    BOOST_LOG_SEV(lg, debug) << "Position: " << position_
                             << " element separator: " << element_separator_
                             << " is first: " << is_first()
                             << " is last: " << is_last()
                             << " is single: " << is_single();

    BOOST_LOG_SEV(lg, debug) << "Prefix configuration: "
                             << prefix_configuration_;
    BOOST_LOG_SEV(lg, debug) << "Value for prefix position: "
                             << value_for_position(prefix_configuration_);

    BOOST_LOG_SEV(lg, debug) << "Postfix configuration: "
                             << postfix_configuration_;
    BOOST_LOG_SEV(lg, debug) << "Value for postfix position: "
                             << value_for_position(postfix_configuration_);
}
Exemplo n.º 9
0
bool sequence_formatter::is_single() const {
    return is_first() && is_last();
}
void generate_literal_chain(ast::tree& ast, ast::node* root, formatter& output)
{
    plnnrc_assert(ast::is_op_not(root) || ast::is_term_call(root) || is_atom(root) || is_comparison_op(root));

    ast::node* atom = root;

    if (ast::is_op_not(root))
    {
        atom = root->first_child;
    }

    if (ast::is_comparison_op(atom))
    {
        generate_literal_chain_comparison(ast, root, atom, output);
        return;
    }

    if (ast::is_term_call(atom))
    {
        generate_literal_chain_call_term(ast, root, atom, output);
        return;
    }

    const char* atom_id = atom->s_expr->token;
    int atom_index = ast::annotation<ast::atom_ann>(atom)->index;

    if (ast::is_op_not(root) && all_unbound(atom))
    {
        output.writeln("if (!tuple_list::head<%i_tuple>(world.atoms[atom_%i]))", atom_id, atom_id);
        {
            scope s(output);

            if (root->next_sibling)
            {
                generate_literal_chain(ast, root->next_sibling, output);
            }
            else
            {
                output.writeln("PLNNR_COROUTINE_YIELD(state);");
            }
        }
    }
    else if (ast::is_op_not(root) && all_bound(atom))
    {
        output.writeln("for (state.%i_%d = tuple_list::head<%i_tuple>(world.atoms[atom_%i]); state.%i_%d != 0; state.%i_%d = state.%i_%d->next)",
            atom_id, atom_index,
            atom_id,
            atom_id,
            atom_id, atom_index,
            atom_id, atom_index,
            atom_id, atom_index);
        {
            scope s(output);

            int atom_param_index = 0;

            for (ast::node* term = atom->first_child; term != 0; term = term->next_sibling)
            {
                if (ast::is_term_variable(term))
                {
                    int var_index = ast::annotation<ast::term_ann>(term)->var_index;

                    output.writeln("if (state.%i_%d->_%d == state._%d)", atom_id, atom_index, atom_param_index, var_index);
                    {
                        scope s(output, !is_last(term));
                        output.writeln("break;");
                    }
                }

                if (ast::is_term_call(term))
                {
                    paste_precondition_function_call paste(term, "state._");

                    output.writeln("if (state.%i_%d->_%d == world.%p)", atom_id, atom_index, atom_param_index, &paste);
                    {
                        scope s(output, !is_last(term));
                        output.writeln("break;");
                    }
                }

                ++atom_param_index;
            }
        }

        output.writeln("if (state.%i_%d == 0)", atom_id, atom_index);
        {
            scope s(output, is_first(root));

            if (root->next_sibling)
            {
                generate_literal_chain(ast, root->next_sibling, output);
            }
            else
            {
                output.writeln("PLNNR_COROUTINE_YIELD(state);");
            }
        }
    }
    else
    {
        output.writeln("for (state.%i_%d = tuple_list::head<%i_tuple>(world.atoms[atom_%i]); state.%i_%d != 0; state.%i_%d = state.%i_%d->next)",
            atom_id, atom_index,
            atom_id,
            atom_id,
            atom_id, atom_index,
            atom_id, atom_index,
            atom_id, atom_index);
        {
            scope s(output, is_first(root));

            const char* comparison_op = "!=";

            if (ast::is_op_not(root))
            {
                comparison_op = "==";
            }

            int atom_param_index = 0;

            for (ast::node* term = atom->first_child; term != 0; term = term->next_sibling)
            {
                if (ast::is_term_variable(term) && definition(term))
                {
                    int var_index = ast::annotation<ast::term_ann>(term)->var_index;

                    output.writeln("if (state.%i_%d->_%d %s state._%d)", atom_id, atom_index, atom_param_index, comparison_op, var_index);
                    {
                        scope s(output);
                        output.writeln("continue;");
                    }
                }

                if (ast::is_term_call(term))
                {
                    paste_precondition_function_call paste(term, "state._");

                    output.writeln("if (state.%i_%d->_%d %s world.%p)", atom_id, atom_index, atom_param_index, comparison_op, &paste);
                    {
                        scope s(output);
                        output.writeln("continue;");
                    }
                }

                ++atom_param_index;
            }

            atom_param_index = 0;

            for (ast::node* term = atom->first_child; term != 0; term = term->next_sibling)
            {
                if (ast::is_term_variable(term) && !definition(term))
                {
                    int var_index = ast::annotation<ast::term_ann>(term)->var_index;
                    output.writeln("state._%d = state.%i_%d->_%d;", var_index, atom_id, atom_index, atom_param_index);
                    output.newline();
                }

                ++atom_param_index;
            }

            if (root->next_sibling)
            {
                generate_literal_chain(ast, root->next_sibling, output);
            }
            else
            {
                output.writeln("PLNNR_COROUTINE_YIELD(state);");
            }
        }
    }
}