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

Delta Between Two Patch Sets: compiled/bindings.ipp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Properly determine ref_counted offset instead of assuming that it is zero Created March 14, 2017, 10:18 a.m.
Right Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.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/bindings.cpp ('k') | compiled/debug.h » ('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 #pragma once 1 #pragma once
2 2
3 #include <cstddef>
3 #include <cstdint> 4 #include <cstdint>
4 #include <cstdio> 5 #include <cstdio>
5 #include <cstdlib> 6 #include <cstdlib>
6 #include <exception> 7 #include <exception>
7 #include <map> 8 #include <map>
8 #include <string> 9 #include <string>
9 #include <type_traits> 10 #include <type_traits>
10 #include <utility> 11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 }; 271 };
271 272
272 struct ClassInfo 273 struct ClassInfo
273 { 274 {
274 ClassInfo* baseClass; 275 ClassInfo* baseClass;
275 std::string name; 276 std::string name;
276 std::vector<PropertyInfo> properties; 277 std::vector<PropertyInfo> properties;
277 std::vector<MethodInfo> methods; 278 std::vector<MethodInfo> methods;
278 std::vector<FunctionInfo> initializers; 279 std::vector<FunctionInfo> initializers;
279 DifferentiatorInfo subclass_differentiator; 280 DifferentiatorInfo subclass_differentiator;
280 int ref_counted_offset; 281 ptrdiff_t ref_counted_offset;
sergei 2017/03/20 17:07:18 Can we use ptrdiff_t for ref_counted_offset?
Wladimir Palant 2017/03/21 10:10:15 Done.
281 }; 282 };
282 283
283 std::map<TYPEID, ClassInfo> classes; 284 std::map<TYPEID, ClassInfo> classes;
284 285
285 void register_class(const char* name, TYPEID classID, TYPEID baseClassID, 286 void register_class(const char* name, TYPEID classID, TYPEID baseClassID,
286 int ref_counted_offset) 287 ptrdiff_t ref_counted_offset)
287 { 288 {
288 auto it = classes.find(classID); 289 auto it = classes.find(classID);
289 if (it != classes.end()) 290 if (it != classes.end())
290 throw std::runtime_error(std::string("Duplicate definition for class ") + name); 291 throw std::runtime_error(std::string("Duplicate definition for class ") + name);
291 292
292 ClassInfo* baseClass = nullptr; 293 ClassInfo* baseClass = nullptr;
293 if (baseClassID != TypeInfo<NoBaseClass>()) 294 if (baseClassID != TypeInfo<NoBaseClass>())
294 { 295 {
295 it = classes.find(baseClassID); 296 it = classes.find(baseClassID);
296 if (it == classes.end()) 297 if (it == classes.end())
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 640
640 template<typename ClassType, 641 template<typename ClassType,
641 typename BaseClass = bindings_internal::NoBaseClass, 642 typename BaseClass = bindings_internal::NoBaseClass,
642 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr> 643 typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::typ e* = nullptr>
643 class class_ 644 class class_
644 { 645 {
645 public: 646 public:
646 class_(const char* name) 647 class_(const char* name)
647 { 648 {
648 ClassType* ptr = reinterpret_cast<ClassType*>(0x10000000); 649 ClassType* ptr = reinterpret_cast<ClassType*>(0x10000000);
649 int ref_counted_offset = 650 ptrdiff_t ref_counted_offset =
650 reinterpret_cast<int>(dynamic_cast<ref_counted*>(ptr)) - 651 reinterpret_cast<char*>(static_cast<ref_counted*>(ptr)) -
sergei 2017/03/20 17:07:15 Could we please use static_cast instead of dynamic
Wladimir Palant 2017/03/21 10:10:12 Done.
651 reinterpret_cast<int>(ptr); 652 reinterpret_cast<char*>(ptr);
652 bindings_internal::register_class(name, 653 bindings_internal::register_class(name,
653 bindings_internal::TypeInfo<ClassType>(), 654 bindings_internal::TypeInfo<ClassType>(),
654 bindings_internal::TypeInfo<BaseClass>(), 655 bindings_internal::TypeInfo<BaseClass>(),
655 ref_counted_offset 656 ref_counted_offset
656 ); 657 );
657 } 658 }
658 659
659 template<typename FieldType> 660 template<typename FieldType>
660 const class_& property(const char* name, 661 const class_& property(const char* name,
661 FieldType (ClassType::*getter)() const, 662 FieldType (ClassType::*getter)() const,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 718
718 std::vector<std::pair<int, std::string>> mapping; 719 std::vector<std::pair<int, std::string>> mapping;
719 for (const auto& item : list) 720 for (const auto& item : list)
720 mapping.emplace_back(item.first, item.second); 721 mapping.emplace_back(item.first, item.second);
721 722
722 bindings_internal::register_differentiator( 723 bindings_internal::register_differentiator(
723 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 724 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
724 return *this; 725 return *this;
725 } 726 }
726 }; 727 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld