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: Improved type names and added finally block Created May 8, 2017, 12:53 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 generateCall(const FunctionInfo& call,
226 std::vector<std::string>& params);
227
228 std::string wrapCall(const FunctionInfo& call, bool isFunction = true);
229
230 void printHelpers();
231
232 void printClass(const ClassInfo& cls);
233 } 214 }
234 215
235 template<typename ClassType, 216 template<typename ClassType,
236 typename BaseClass = bindings_internal::NoBaseClass, 217 typename BaseClass = bindings_internal::NoBaseClass,
237 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>
238 class class_ 219 class class_
239 { 220 {
240 public: 221 public:
241 class_(const char* name) 222 class_(const char* name)
242 { 223 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 std::vector<std::pair<int, std::string>> mapping; 287 std::vector<std::pair<int, std::string>> mapping;
307 for (const auto& item : list) 288 for (const auto& item : list)
308 mapping.emplace_back(item.first, item.second); 289 mapping.emplace_back(item.first, item.second);
309 290
310 bindings_internal::register_differentiator( 291 bindings_internal::register_differentiator(
311 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 292 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
312 return *this; 293 return *this;
313 } 294 }
314 }; 295 };
315 296
316 class namespace_ 297 template<typename ClassType>
298 class singleton
317 { 299 {
318 private:
319 const char* mName;
320
321 public: 300 public:
322 namespace_(const char* name) 301 singleton(const char* name, ClassType* (*instanceGetter)())
323 : mName(name) 302 {
324 { 303 bindings_internal::register_class(name,
325 bindings_internal::register_namespace(name); 304 bindings_internal::TypeInfo<ClassType>(),
305 bindings_internal::TypeInfo<bindings_internal::NoBaseClass>(),
306 0,
307 instanceGetter
308 );
326 } 309 }
327 310
328 template<typename FieldType> 311 template<typename FieldType>
329 namespace_& property(const char* name, 312 const singleton& property(const char* name,
330 FieldType (*getter)(), 313 FieldType (ClassType::*getter)() const,
331 void (*setter)(FieldType) = nullptr) 314 void (ClassType::*setter)(FieldType) = nullptr) const
332 { 315 {
333 bindings_internal::register_namespace_property(mName, name, getter, 316 bindings_internal::register_property(
334 setter); 317 bindings_internal::TypeInfo<ClassType>(), name, getter, setter);
335 return *this; 318 return *this;
336 } 319 }
337 320
338 template<typename ReturnType, typename... Args> 321 template<typename ReturnType, typename... Args>
339 namespace_& function(const char* name, ReturnType (*method)(Args...)) 322 const singleton& function(const char* name, ReturnType (ClassType::*method)(Ar gs...)) const
340 { 323 {
341 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);
342 return *this; 334 return *this;
343 } 335 }
344 }; 336 };
345 337
346 void printBindings(); 338 void printBindings();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld