<commit_before>/* argument.cpp                                 -*- C++ -*-
   <NAME> (<EMAIL>), 29 Mar 2014
   FreeBSD-style copyright and disclaimer apply

   Implementation of argument thingy.
*/

#include "reflect.h"

#include <sstream>

namespace reflect {

/******************************************************************************/
/* ARGUMENT                                                                   */
/******************************************************************************/

Argument::
Argument() : type_(reflect::type<void>()) {}

Argument::
Argument(const Type* type, RefType refType, bool isConst) :
    type_(type), refType_(refType), isConst_(isConst)
{}

bool
Argument::
isVoid() const
{
    return type_ == reflect::type<void>();
}

bool
Argument::
isConstRef() const
{
    return isConst() && refType_ == RefType::LValue;
}

bool
Argument::
isTemporary() const
{
    return refType_ == RefType::RValue
        || refType_ == RefType::Copy;
}

bool
Argument::
isConvertibleTo(const Argument& target) const
{
    static Type* valueType = reflect::type<Value>();

    if ((type() == valueType) ^ (target.type() == valueType))
        return true;

    if (type()->hasConverter(target.type())) {
        if (target.refType() == RefType::LValue && !target.isConst())
            return false;
        return true;
    }

    if (target.refType() != RefType::Copy) {
        if (!testConstConversion(isConst(), target.isConst()))
            return false;
    }

    if (target.refType() == RefType::LValue) {
        if (target.isConst()) {}
        else if (isConst()) return false;
        else if (refType() != RefType::LValue) return false;
    }

    else if (target.refType() == RefType::RValue) {
        if (refType() == RefType::LValue) return false;
    }

    return target.type()->isParentOf(type());
}


std::string
Argument::
print() const
{
    std::stringstream ss;

    if (isConst_) ss << "const ";

    ss << type_->id();

    if (refType_ == RefType::LValue) ss << "&";<commit_msg>Argument::isConvertibleTo no longer allows Copy -> RValue.<commit_after>/* argument.cpp                                 -*- C++ -*-
   <NAME> (<EMAIL>), 29 Mar 2014
   FreeBSD-style copyright and disclaimer apply

   Implementation of argument thingy.
*/

#include "reflect.h"

#include <sstream>

namespace reflect {

/******************************************************************************/
/* ARGUMENT                                                                   */
/******************************************************************************/

Argument::
Argument() : type_(reflect::type<void>()) {}

Argument::
Argument(const Type* type, RefType refType, bool isConst) :
    type_(type), refType_(refType), isConst_(isConst)
{}

bool
Argument::
isVoid() const
{
    return type_ == reflect::type<void>();
}

bool
Argument::
isConstRef() const
{
    return isConst() && refType_ == RefType::LValue;
}

bool
Argument::
isTemporary() const
{
    return refType_ == RefType::RValue
        || refType_ == RefType::Copy;
}

bool
Argument::
isConvertibleTo(const Argument& target) const
{
    static Type* valueType = reflect::type<Value>();

    if ((type() == valueType) ^ (target.type() == valueType))
        return true;

    if (type()->hasConverter(target.type())) {
        if (target.refType() == RefType::LValue && !target.isConst())
            return false;
        return true;
    }

    if (target.refType() != RefType::Copy) {
        if (!testConstConversion(isConst(), target.isConst()))
            return false;
    }

    if (target.refType() == RefType::LValue) {
        if (target.isConst()) {}
        else if (isConst()) return false;
        else if (refType() != RefType::LValue) return false;
    }

    else if (target.refType() == RefType::RValue) {
        if (refType() != RefType::RValue) return false;
    }

    return target.type()->isParentOf(type());
}


std::string
Argument::
print() const
{
    std::stringstream ss;

    if (isConst_) ss << "const ";

    ss << type_->id();

    if (refType_ == RefType::LValue) ss << "&";
{'fraction_non_alphanumeric': 0.225273390036452, 'fraction_numerical': 0.0029161603888213854, 'mean_word_length': 2.908831908831909, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6671219', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1162, 'n_words': 285}