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

Side by Side Diff: compiled/bindings/generator.h

Issue 29426559: Issue 5137 - [emscripten] Added basic filter storage implementation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created May 1, 2017, 2:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 std::string name; 173 std::string name;
174 FunctionInfo call; 174 FunctionInfo call;
175 }; 175 };
176 176
177 struct DifferentiatorInfo 177 struct DifferentiatorInfo
178 { 178 {
179 size_t offset; 179 size_t offset;
180 std::vector<std::pair<int, std::string>> mapping; 180 std::vector<std::pair<int, std::string>> mapping;
181 }; 181 };
182 182
183 typedef std::vector<PropertyInfo> PropertyList;
sergei 2017/05/08 10:54:39 It's usually a bad practice to call something like
Wladimir Palant 2017/05/08 12:55:41 Done.
184 typedef std::vector<MethodInfo> MethodList;
185
183 struct ClassInfo 186 struct ClassInfo
184 { 187 {
185 TYPEID id; 188 TYPEID id;
186 TYPEID baseClass; 189 TYPEID baseClass;
187 std::string name; 190 std::string name;
188 std::vector<PropertyInfo> properties; 191 PropertyList properties;
189 std::vector<MethodInfo> methods; 192 MethodList methods;
190 DifferentiatorInfo subclass_differentiator; 193 DifferentiatorInfo subclass_differentiator;
191 ptrdiff_t ref_counted_offset; 194 ptrdiff_t ref_counted_offset;
192 }; 195 };
193 196
197 struct NamespaceInfo
198 {
199 std::string name;
200 PropertyList properties;
201 MethodList methods;
202 };
203
194 void register_class(const char* name, TYPEID classID, TYPEID baseClassID, 204 void register_class(const char* name, TYPEID classID, TYPEID baseClassID,
195 ptrdiff_t ref_counted_offset); 205 ptrdiff_t ref_counted_offset);
196 206
197 void register_property(TYPEID classID, const char* name, 207 void register_property(TYPEID classID, const char* name,
198 const FunctionInfo& getter, const FunctionInfo& setter, 208 const FunctionInfo& getter, const FunctionInfo& setter,
199 const char* jsValue = ""); 209 const char* jsValue = "");
200 210
201 void register_method(TYPEID classID, const char* name, 211 void register_method(TYPEID classID, const char* name,
202 const FunctionInfo& call); 212 const FunctionInfo& call);
203 213
204 void register_differentiator(TYPEID classID, size_t offset, 214 void register_differentiator(TYPEID classID, size_t offset,
205 std::vector<std::pair<int, std::string>>& mapping); 215 std::vector<std::pair<int, std::string>>& mapping);
206 216
217 void register_namespace(const char* name);
218
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
207 std::string generateCall(const FunctionInfo& call, 225 std::string generateCall(const FunctionInfo& call,
208 std::vector<std::string>& params); 226 std::vector<std::string>& params);
209 227
210 std::string wrapCall(const FunctionInfo& call, bool isFunction = true); 228 std::string wrapCall(const FunctionInfo& call, bool isFunction = true);
211 229
212 void printHelpers(); 230 void printHelpers();
213 231
214 void printClass(const ClassInfo& cls); 232 void printClass(const ClassInfo& cls);
215 } 233 }
216 234
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 std::vector<std::pair<int, std::string>> mapping; 306 std::vector<std::pair<int, std::string>> mapping;
289 for (const auto& item : list) 307 for (const auto& item : list)
290 mapping.emplace_back(item.first, item.second); 308 mapping.emplace_back(item.first, item.second);
291 309
292 bindings_internal::register_differentiator( 310 bindings_internal::register_differentiator(
293 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 311 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
294 return *this; 312 return *this;
295 } 313 }
296 }; 314 };
297 315
316 class namespace_
317 {
318 private:
319 const char* mName;
320
321 public:
322 namespace_(const char* name)
323 : mName(name)
324 {
325 bindings_internal::register_namespace(name);
326 }
327
328 template<typename FieldType>
329 namespace_& property(const char* name,
330 FieldType (*getter)(),
331 void (*setter)(FieldType) = nullptr)
332 {
333 bindings_internal::register_namespace_property(mName, name, getter,
334 setter);
335 return *this;
336 }
337
338 template<typename ReturnType, typename... Args>
339 namespace_& function(const char* name, ReturnType (*method)(Args...))
340 {
341 bindings_internal::register_namespace_method(mName, name, method);
342 return *this;
343 }
344 };
345
298 void printBindings(); 346 void printBindings();
OLDNEW

Powered by Google App Engine
This is Rietveld