<commit_before>/*
 * Copyright 2015 - 2019 <EMAIL>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <ox/std/byteswap.hpp>
#include <ox/std/hashmap.hpp>
#include <ox/std/string.hpp>
#include <ox/std/types.hpp>
#include <ox/std/vector.hpp>
#include <ox/trace/trace.hpp>

#include "deftypes.hpp"
#include "err.hpp"
#include "optype.hpp"

namespace ox {

template<typename T>
static constexpr int indirectionLevels(T) {
	return 0;
}

template<typename T>
static constexpr int indirectionLevels(T *t) {
	return 1 + indirectionLevels(*t);
}

class MetalClawDefWriter {

	private:
		mc::TypeStore *m_typeStoreOwnerRef = nullptr;
		mc::TypeStore *m_typeStore = nullptr;
		mc::Type *m_type = nullptr;

	public:
		explicit MetalClawDefWriter(mc::TypeStore *typeStore = nullptr);

		~MetalClawDefWriter();

		template<typename T>
		int op(const char *name, T *val, std::size_t valLen);

		template<std::size_t L>
		int op(const char *name, const char *val);

		template<std::size_t L>
		int op(const char *name, ox::BString<L> *val);

		template<typename T>
		constexpr int op(const char *name, T *val);

		constexpr void setTypeInfo(const char *name, int fields);

      constexpr OpType opType() {
          return OpType::Write;
      }

	private:
		constexpr mc::Type *type(int8_t *val);
		constexpr mc::Type *type(int16_t *val);
		constexpr mc::Type *type(int32_t *val);
		constexpr mc::Type *type(int64_t *val);

		constexpr mc::Type *type(uint8_t *val);
		constexpr mc::Type *type(uint16_t *val);
		constexpr mc::Type *type(uint32_t *val);
		constexpr mc::Type *type(uint64_t *val);

		constexpr mc::Type *type(bool *val);

		constexpr mc::Type *type(const char *val);

		template<std::size_t L>
		constexpr mc::Type *type(ox::BString<L> *val);

		template<typename T>
		mc::Type *type(T *val);

		constexpr mc::Type *getPrimitive(mc::TypeName tn, mc::PrimitiveType t, int b = 0);
};

// array handler<commit_msg>[ox/mc] Fix MetalClawDefWriter OpType<commit_after>/*
 * Copyright 2015 - 2019 <EMAIL>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <ox/std/byteswap.hpp>
#include <ox/std/hashmap.hpp>
#include <ox/std/string.hpp>
#include <ox/std/types.hpp>
#include <ox/std/vector.hpp>
#include <ox/trace/trace.hpp>

#include "deftypes.hpp"
#include "err.hpp"
#include "optype.hpp"

namespace ox {

template<typename T>
static constexpr int indirectionLevels(T) {
	return 0;
}

template<typename T>
static constexpr int indirectionLevels(T *t) {
	return 1 + indirectionLevels(*t);
}

class MetalClawDefWriter {

	private:
		mc::TypeStore *m_typeStoreOwnerRef = nullptr;
		mc::TypeStore *m_typeStore = nullptr;
		mc::Type *m_type = nullptr;

	public:
		explicit MetalClawDefWriter(mc::TypeStore *typeStore = nullptr);

		~MetalClawDefWriter();

		template<typename T>
		int op(const char *name, T *val, std::size_t valLen);

		template<std::size_t L>
		int op(const char *name, const char *val);

		template<std::size_t L>
		int op(const char *name, ox::BString<L> *val);

		template<typename T>
		constexpr int op(const char *name, T *val);

		constexpr void setTypeInfo(const char *name, int fields);

      constexpr OpType opType() {
			return OpType::WriteDefinition;
      }

	private:
		constexpr mc::Type *type(int8_t *val);
		constexpr mc::Type *type(int16_t *val);
		constexpr mc::Type *type(int32_t *val);
		constexpr mc::Type *type(int64_t *val);

		constexpr mc::Type *type(uint8_t *val);
		constexpr mc::Type *type(uint16_t *val);
		constexpr mc::Type *type(uint32_t *val);
		constexpr mc::Type *type(uint64_t *val);

		constexpr mc::Type *type(bool *val);

		constexpr mc::Type *type(const char *val);

		template<std::size_t L>
		constexpr mc::Type *type(ox::BString<L> *val);

		template<typename T>
		mc::Type *type(T *val);

		constexpr mc::Type *getPrimitive(mc::TypeName tn, mc::PrimitiveType t, int b = 0);
};

// array handler
{'fraction_non_alphanumeric': 0.14028008544979825, 'fraction_numerical': 0.0137669119392357, 'mean_word_length': 4.515706806282722, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4098922', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1534, 'n_words': 420}