Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: compiled/bindings/generator.h

Issue 29410617: Issue 5131 - [emscripten] Clean separation of bindings code and runtime code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created April 12, 2017, 2:07 p.m.
Right Patch Set: Rebased Created April 20, 2017, 1:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 24 matching lines...) Expand all
35 { 35 {
36 typedef void* TYPEID; 36 typedef void* TYPEID;
37 37
38 enum class TypeCategory 38 enum class TypeCategory
39 { 39 {
40 UNKNOWN, 40 UNKNOWN,
41 VOID, 41 VOID,
42 INT, 42 INT,
43 INT64, 43 INT64,
44 FLOAT, 44 FLOAT,
45 DOUBLE,
45 DEPENDENT_STRING, 46 DEPENDENT_STRING,
46 OWNED_STRING, 47 OWNED_STRING,
47 STRING_REF, 48 STRING_REF,
48 CLASS_PTR 49 CLASS_PTR
49 }; 50 };
50 51
51 template<typename T> 52 template<typename T>
52 struct TypeInfo 53 struct TypeInfo
53 { 54 {
54 /* 55 /*
(...skipping 14 matching lines...) Expand all
69 { 70 {
70 if (std::is_void<T>()) 71 if (std::is_void<T>())
71 return TypeCategory::VOID; 72 return TypeCategory::VOID;
72 73
73 if (std::is_same<T, uint64_t>()) 74 if (std::is_same<T, uint64_t>())
74 return TypeCategory::INT64; 75 return TypeCategory::INT64;
75 76
76 if (std::is_integral<T>() || std::is_enum<T>()) 77 if (std::is_integral<T>() || std::is_enum<T>())
77 return TypeCategory::INT; 78 return TypeCategory::INT;
78 79
79 if (std::is_floating_point<T>()) 80 if (std::is_same<T, float>())
80 return TypeCategory::FLOAT; 81 return TypeCategory::FLOAT;
82
83 if (std::is_same<T, double>())
84 return TypeCategory::DOUBLE;
81 85
82 if (std::is_same<DependentString, T>() || std::is_same<const DependentStri ng, T>()) 86 if (std::is_same<DependentString, T>() || std::is_same<const DependentStri ng, T>())
83 return TypeCategory::DEPENDENT_STRING; 87 return TypeCategory::DEPENDENT_STRING;
84 88
85 if (std::is_same<OwnedString, T>() || std::is_same<const OwnedString, T>() ) 89 if (std::is_same<OwnedString, T>() || std::is_same<const OwnedString, T>() )
86 return TypeCategory::OWNED_STRING; 90 return TypeCategory::OWNED_STRING;
87 91
88 if (std::is_same<String&, T>() || std::is_same<const String&, T>() || 92 if (std::is_same<String&, T>() || std::is_same<const String&, T>() ||
89 std::is_same<DependentString&, T>()) 93 std::is_same<DependentString&, T>())
90 { 94 {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 struct ClassInfo 185 struct ClassInfo
182 { 186 {
183 TYPEID id; 187 TYPEID id;
184 TYPEID baseClass; 188 TYPEID baseClass;
185 std::string name; 189 std::string name;
186 std::vector<PropertyInfo> properties; 190 std::vector<PropertyInfo> properties;
187 std::vector<MethodInfo> methods; 191 std::vector<MethodInfo> methods;
188 DifferentiatorInfo subclass_differentiator; 192 DifferentiatorInfo subclass_differentiator;
189 ptrdiff_t ref_counted_offset; 193 ptrdiff_t ref_counted_offset;
190 }; 194 };
191
192 typedef std::function<void()> CustomGenerator;
193 195
194 void register_class(const char* name, TYPEID classID, TYPEID baseClassID, 196 void register_class(const char* name, TYPEID classID, TYPEID baseClassID,
195 ptrdiff_t ref_counted_offset); 197 ptrdiff_t ref_counted_offset);
196 198
197 void register_property(TYPEID classID, const char* name, 199 void register_property(TYPEID classID, const char* name,
198 const FunctionInfo& getter, const FunctionInfo& setter, 200 const FunctionInfo& getter, const FunctionInfo& setter,
199 const char* jsValue = ""); 201 const char* jsValue = "");
200 202
201 void register_method(TYPEID classID, const char* name, 203 void register_method(TYPEID classID, const char* name,
202 const FunctionInfo& call); 204 const FunctionInfo& call);
(...skipping 12 matching lines...) Expand all
215 217
216 void printClass(const ClassInfo& cls); 218 void printClass(const ClassInfo& cls);
217 } 219 }
218 220
219 template<typename ClassType, 221 template<typename ClassType,
220 typename BaseClass = bindings_internal::NoBaseClass, 222 typename BaseClass = bindings_internal::NoBaseClass,
221 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr> 223 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr>
222 class class_ 224 class class_
223 { 225 {
224 public: 226 public:
225 class_(const char* name) 227 class_(const char* name)
Wladimir Palant 2017/04/12 14:17:00 I would have preferred to move the implementations
226 { 228 {
227 ClassType* ptr = reinterpret_cast<ClassType*>(0x10000000); 229 ClassType* ptr = reinterpret_cast<ClassType*>(0x10000000);
228 ptrdiff_t ref_counted_offset = 230 ptrdiff_t ref_counted_offset =
229 reinterpret_cast<char*>(static_cast<ref_counted*>(ptr)) - 231 reinterpret_cast<char*>(static_cast<ref_counted*>(ptr)) -
230 reinterpret_cast<char*>(ptr); 232 reinterpret_cast<char*>(ptr);
231 bindings_internal::register_class(name, 233 bindings_internal::register_class(name,
232 bindings_internal::TypeInfo<ClassType>(), 234 bindings_internal::TypeInfo<ClassType>(),
233 bindings_internal::TypeInfo<BaseClass>(), 235 bindings_internal::TypeInfo<BaseClass>(),
234 ref_counted_offset 236 ref_counted_offset
235 ); 237 );
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 std::vector<std::pair<int, std::string>> mapping; 292 std::vector<std::pair<int, std::string>> mapping;
291 for (const auto& item : list) 293 for (const auto& item : list)
292 mapping.emplace_back(item.first, item.second); 294 mapping.emplace_back(item.first, item.second);
293 295
294 bindings_internal::register_differentiator( 296 bindings_internal::register_differentiator(
295 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 297 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
296 return *this; 298 return *this;
297 } 299 }
298 }; 300 };
299 301
300 void custom_generator(bindings_internal::CustomGenerator generator);
301
302 void printBindings(); 302 void printBindings();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld