<commit_before>/**
 * \file wave_coordinate.h
 * \brief Wave coordinate
 * \author <NAME>
 * \date 2014
 * \copyright MIT License
 */
/* The MIT License (MIT)
 *
 * Copyright (c) 2014 <NAME>, <NAME>, <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef __WAVE_COORDINATE_H__
#define __WAVE_COORDINATE_H__

#include <stdlib.h>
#include <stdio.h>

#include "wave/ast/wave_int_list.h"

////////////////////////////////////////////////////////////////////////////////
// Enums, Structs, Typedefs.
////////////////////////////////////////////////////////////////////////////////

/**
 * \brief Wave coordinate type.
 */
typedef enum wave_coordinate_type
{
    WAVE_COORD_CONSTANT,        /**<- Constant. */
    WAVE_COORD_PLUS,            /**<- Plus. */
    WAVE_COORD_TIMES,           /**<- Times. */
    WAVE_COORD_VAR,             /**<- Var. */
    WAVE_COORD_UNKNOWN,         /**<- Unknown. */
} wave_coordinate_type;

/**
 * \brief Wave coordinate.
 */
typedef struct wave_coordinate
{
    wave_coordinate_type _type;                 /**<- Type. */
    union
    {
        int _constant;                          /**<- Constant. */
        wave_int_list * _var;                   /**<- Var. */
        struct
        {
            struct wave_coordinate * _left;     /**<- Plus left value. */
            struct wave_coordinate * _right;    /**<- Plus right value. */
        } _binary;                                /**<- Plus. */
    } _content;                                 /**<- Content. */
} wave_coordinate;

////////////////////////////////////////////////////////////////////////////////
// Initialization, clean.
////////////////////////////////////////////////////////////////////////////////

/**
 * \brief Initialize a wave_coordinate.
 * \param c Coordinate.
 * \relatesalso wave_coordinate
 * \warning \c c must be not \c NULL.
 */
void wave_coordinate_init (wave_coordinate * c);

void wave_coordinate_clean (wave_coordinate * c);

////////////////////////////////////////////////////////////////////////////////
// Allocation, free.
////////////////////////////////////////////////////////////////////////////////

/**
 * \brief Allocation for wave_coordinate
 * \return pointer to a wave_coordinate
 * \relatesalso wave_coordinate
 */
void * wave_coordinate_alloc (void);

/**
 * \brief Free a wave_coordinate
 * \param c Coordinate
 * \relatesalso wave_coordinate
 */
void wave_coordinate_free (wave_coordinate * c);

/**
 * \brief Copy a wave_coordinate.
 * \param c Coordinate
 * \relatesalso wave_coordinate
 */
void * wave_coordinate_copy (const wave_coordinate * c);<commit_msg>update wave_coordinate doc<commit_after>/**
 * \file wave_coordinate.h
 * \brief Wave coordinate
 * \author <NAME>
 * \date 2014
 * \copyright MIT License
 */
/* The MIT License (MIT)
 *
 * Copyright (c) 2014 <NAME>, <NAME>, <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef __WAVE_COORDINATE_H__
#define __WAVE_COORDINATE_H__

#include <stdlib.h>
#include <stdio.h>

#include "wave/ast/wave_int_list.h"

////////////////////////////////////////////////////////////////////////////////
// Enums, Structs, Typedefs.
////////////////////////////////////////////////////////////////////////////////

/**
 * \brief Wave coordinate type.
 */
typedef enum wave_coordinate_type
{
    WAVE_COORD_CONSTANT,        /**<- Constant. */
    WAVE_COORD_PLUS,            /**<- Plus. */
    WAVE_COORD_TIMES,           /**<- Times. */
    WAVE_COORD_VAR,             /**<- Var. */
    WAVE_COORD_UNKNOWN,         /**<- Unknown. */
} wave_coordinate_type;

/**
 * \brief Wave coordinate.
 * \sa wave_int_list
 * \warning The setters functions assume the coordinate is clean, if necessary,
 * it is up to the user to properly clean the coordinate before using a setter
 * function.
 *
 * Wave coordinates are used as annotations to the Wave AST. This structure
 * actually is used to represent both the “coordinates” of a collection and its
 * length.
 *
 * The coordinate of a collection usually is computed as the sum of the previous
 * collection's coordinate and length, hence the use of the same structure for
 * coordinates and lengths.
 *
 * ## Coordinate creation and destruction
 * Coordinates can be dynamically created using wave_coordinate_alloc(). Such
 * coordinates should be freed using wave_coordinate_free().
 *
 * ## Coordinate type
 * ### Existing types
 * A coordinate (or a “length”) can be:
 * - a constant (#WAVE_COORD_CONSTANT)
 * - a variable (#WAVE_COORD_VAR)
 * - the sum of two coordinates (#WAVE_COORD_PLUS)
 * - the product of two coordinates (#WAVE_COORD_TIMES)
 *
 * A “variable” coordinate is used to represent unknown (at compile time) lengths.
 * Sum and products of coordinates represent sum and products that cannot be
 * computed yet because at least one of the operands is “variable”.
 *
 * A coordinate of type #WAVE_COORD_UNKNOWN is a coordinate that has not been used
 * yet (meaning it does not represent any coordinate or length).
 *
 * ### Getting a coordinate's type
 * In order to know a coordinate's type, one must use wave_coordinate_get_type().
 *
 * ## Coordinate access
 * To get a coordinate's content, one can use one of the following functions:
 * - wave_coordinate_get_list()
 * - wave_coordinate_get_left()
 * - wave_coordinate_get_right()
 * - wave_coordinate_get_constant()
 *
 * ## Coordinate modification
 * Coordinates can be modified using one of the following functions:
 * - wave_coordinate_set_constant()
 * - wave_coordinate_set_list()
 * - wave_coordinate_set_plus_left_and_right()
 * - wave_coordinate_set_times_left_and_right()
 *
 * Please note that these functions automatically set the coordinate's type
 * appropriately.
 *
 * When setting a sum or a product, the setters will attempt to “shrink” the
 * result: operations that can already be computed (ie. operations on constants)
 * will be computed.
 */
typedef struct wave_coordinate
{
    wave_coordinate_type _type;                 /**<- Type. */
    union
    {
        int _constant;                          /**<- Constant. */
        wave_int_list * _var;                   /**<- Var. */
        struct
        {
            struct wave_coordinate * _left;     /**<- Left value. */
            struct wave_coordinate * _right;    /**<- Right value. */
        } _binary;                              /**<- Binary operands. */
    } _content;                                 /**<- Content. */
} wave_coordinate;

////////////////////////////////////////////////////////////////////////////////
// Initialization, clean.
////////////////////////////////////////////////////////////////////////////////

/**
 * \brief Initialize a wave_coordinate.
 * \param c Coordinate.
 * \relatesalso wave_coordinate
 * \warning \c c must be not \c NULL.
 */
void wave_coordinate_init (wave_coordinate * c);

/**
 * \brief Clean a wave_coordinate.
 * \param c Coordinate.
 * \relatesalso wave_coordinate.
 * \warning \c c must be not \c NULL.
 */
void wave_coordinate_clean (wave_coordinate * c);

////////////////////////////////////////////////////////////////////////////////
// Allocation, free.
////////////////////////////////////////////////////////////////////////////////

/**
 * \brief Allocation for wave_coordinate
 * \return pointer to a wave_coordinate
 * \relatesalso wave_coordinate
 */
void * wave_coordinate_alloc (void);

/**
 * \brief Free a wave_coordinate
 * \param c Coordinate
 * \relatesalso wave_coordinate
 */
void wave_coordinate_free (wave_coordinate * c);

/**
 * \brief Copy a wave_coordinate.
 * \param c Coordinate
 * \relatesalso wave_coordinate
 * \warning \c c must be not \c NULL.
 */
void * wave_coordinate_copy (const wave_coordinate * c);
{'fraction_non_alphanumeric': 0.18487050875217526, 'fraction_numerical': 0.0016378339645818406, 'mean_word_length': 2.0617361328737074, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '108378', 'n_tokens_mistral': 2604, 'n_tokens_neox': 2427, 'n_words': 944}