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

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

Issue 29426559: Issue 5137 - [emscripten] Added basic filter storage implementation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Rebased Created May 10, 2017, 12:36 p.m.
Right Patch Set: Fixed bogus assert Created Aug. 31, 2017, 12:44 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
« no previous file with change/comment | « compiled/FilterNotifier.h ('k') | compiled/bindings/generator.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-present 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 185
186 struct ClassInfo 186 struct ClassInfo
187 { 187 {
188 TYPEID id; 188 TYPEID id;
189 TYPEID baseClass; 189 TYPEID baseClass;
190 std::string name; 190 std::string name;
191 Properties properties; 191 Properties properties;
192 Methods methods; 192 Methods methods;
193 DifferentiatorInfo subclass_differentiator; 193 DifferentiatorInfo subclass_differentiator;
194 ptrdiff_t ref_counted_offset; 194 ptrdiff_t ref_counted_offset;
195 }; 195 FunctionInfo instanceGetter;
196
197 struct NamespaceInfo
198 {
199 std::string name;
200 Properties properties;
201 Methods methods;
202 }; 196 };
203 197
204 void register_class(const char* name, TYPEID classID, TYPEID baseClassID, 198 void register_class(const char* name, TYPEID classID, TYPEID baseClassID,
205 ptrdiff_t ref_counted_offset); 199 ptrdiff_t ref_counted_offset,
200 const FunctionInfo& instanceGetter = FunctionInfo());
206 201
207 void register_property(TYPEID classID, const char* name, 202 void register_property(TYPEID classID, const char* name,
208 const FunctionInfo& getter, const FunctionInfo& setter, 203 const FunctionInfo& getter, const FunctionInfo& setter,
209 const char* jsValue = ""); 204 const char* jsValue = "");
210 205
211 void register_method(TYPEID classID, const char* name, 206 void register_method(TYPEID classID, const char* name,
212 const FunctionInfo& call); 207 const FunctionInfo& call);
213 208
214 void register_differentiator(TYPEID classID, size_t offset, 209 void register_differentiator(TYPEID classID, size_t offset,
215 std::vector<std::pair<int, std::string>>& mapping); 210 std::vector<std::pair<int, std::string>>& mapping);
216 211
217 void register_namespace(const char* name); 212 std::string wrapCall(const FunctionInfo& call, bool isFunction = true,
218 213 const FunctionInfo& instanceGetter = FunctionInfo());
219 void register_namespace_property(const char* namespaceName, const char* name,
220 const FunctionInfo& getter, const FunctionInfo& setter);
221
222 void register_namespace_method(const char* namespaceName, const char* name,
223 const FunctionInfo& call);
224
225 std::string wrapCall(const FunctionInfo& call, bool isFunction = true);
226 } 214 }
227 215
228 template<typename ClassType, 216 template<typename ClassType,
229 typename BaseClass = bindings_internal::NoBaseClass, 217 typename BaseClass = bindings_internal::NoBaseClass,
230 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr> 218 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr>
231 class class_ 219 class class_
232 { 220 {
233 public: 221 public:
234 class_(const char* name) 222 class_(const char* name)
235 { 223 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 std::vector<std::pair<int, std::string>> mapping; 287 std::vector<std::pair<int, std::string>> mapping;
300 for (const auto& item : list) 288 for (const auto& item : list)
301 mapping.emplace_back(item.first, item.second); 289 mapping.emplace_back(item.first, item.second);
302 290
303 bindings_internal::register_differentiator( 291 bindings_internal::register_differentiator(
304 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 292 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
305 return *this; 293 return *this;
306 } 294 }
307 }; 295 };
308 296
309 class namespace_ 297 template<typename ClassType>
298 class singleton
310 { 299 {
311 private:
312 const char* mName;
313
314 public: 300 public:
315 namespace_(const char* name) 301 singleton(const char* name, ClassType* (*instanceGetter)())
316 : mName(name) 302 {
317 { 303 bindings_internal::register_class(name,
318 bindings_internal::register_namespace(name); 304 bindings_internal::TypeInfo<ClassType>(),
305 bindings_internal::TypeInfo<bindings_internal::NoBaseClass>(),
306 0,
307 instanceGetter
308 );
319 } 309 }
320 310
321 template<typename FieldType> 311 template<typename FieldType>
322 namespace_& property(const char* name, 312 const singleton& property(const char* name,
323 FieldType (*getter)(), 313 FieldType (ClassType::*getter)() const,
324 void (*setter)(FieldType) = nullptr) 314 void (ClassType::*setter)(FieldType) = nullptr) const
325 { 315 {
326 bindings_internal::register_namespace_property(mName, name, getter, 316 bindings_internal::register_property(
327 setter); 317 bindings_internal::TypeInfo<ClassType>(), name, getter, setter);
328 return *this; 318 return *this;
329 } 319 }
330 320
331 template<typename ReturnType, typename... Args> 321 template<typename ReturnType, typename... Args>
332 namespace_& function(const char* name, ReturnType (*method)(Args...)) 322 const singleton& function(const char* name, ReturnType (ClassType::*method)(Ar gs...)) const
333 { 323 {
334 bindings_internal::register_namespace_method(mName, name, method); 324 bindings_internal::register_method(
325 bindings_internal::TypeInfo<ClassType>(), name, method);
326 return *this;
327 }
328
329 template<typename ReturnType, typename... Args>
330 const singleton& function(const char* name, ReturnType (ClassType::*method)(Ar gs...) const) const
331 {
332 bindings_internal::register_method(
333 bindings_internal::TypeInfo<ClassType>(), name, method);
335 return *this; 334 return *this;
336 } 335 }
337 }; 336 };
338 337
339 void printBindings(); 338 void printBindings();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld