summaryrefslogtreecommitdiff
path: root/modules/lang/c++/c_common.hpp
blob: 968c4c0a188ff95142881f64ac532da3fe103482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

namespace saw {
namespace lang {
struct RemoteC {};
}

namespace lang_c {
struct config {
	std::string prefix;
};

struct transfer_binding_state {
	struct info {
		std::string type;
	};

	std::map<uint32_t, binding_state::info> hashes;

	struct transpiled_element {
		uint32_t crc32;
		std::string header;
		std::string source;
	};

	std::vector<transfer_binding_state::transpiled_element> tp_elements;

	error_or<uint64_t> find_id_by_crc32(uint32_t hash){
		for(uint64_t iter = 0; iter < tp_elements.size(); ++iter){
			if(tp_elements.at(iter).crc32 == hash){
				return iter;
			}
		}

		return make_error<err::not_found>();
	}

	error_or<uint64_t> add_tp_element(uint32_t hash){
		uint64_t id{};

		try {
			language_binding_state::transpiled_element ele;

			ele.crc32 = hash;

			id = tp_elements.size();
			tp_elements.emplace_back(std::move(ele));
		}catch(const std::exception&){
			return make_error<err::out_of_memory>();
		}

		return id;
	}
};
}
}