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

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

Issue 29431555: Issue 5216 - [emscripten] Use a more reliable way of retrieving mangled function name (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created May 6, 2017, 8:36 a.m.
Right Patch Set: Two minor fixes Created May 8, 2017, 11:41 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/generator.h ('k') | compiled/bindings/library.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 /* 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 for (const auto& method : methods) 50 for (const auto& method : methods)
51 if (!instanceOnly || method.call.instance_function) 51 if (!instanceOnly || method.call.instance_function)
52 printf("%s: %s,\n", method.name.c_str(), wrapCall(method.call).c_str()); 52 printf("%s: %s,\n", method.name.c_str(), wrapCall(method.call).c_str());
53 } 53 }
54 } 54 }
55 55
56 namespace bindings_internal 56 namespace bindings_internal
57 { 57 {
58 FunctionInfo::FunctionInfo() 58 FunctionInfo::FunctionInfo()
59 { 59 {
60 name[0] = '\0';
61 } 60 }
62 61
63 FunctionInfo::FunctionInfo(TypeCategory returnType, TYPEID pointerType, 62 FunctionInfo::FunctionInfo(TypeCategory returnType, TYPEID pointerType,
64 std::initializer_list<TypeCategory> argTypes, bool instance_function, 63 std::initializer_list<TypeCategory> argTypes, bool instance_function,
65 void* function) 64 void* function)
66 : returnType(returnType), pointerType(pointerType), 65 : returnType(returnType), pointerType(pointerType),
67 instance_function(instance_function) 66 instance_function(instance_function)
68 { 67 {
69 name[0] = '\0';
70
71 // The function parameter is a pointer to the function pointer. 68 // The function parameter is a pointer to the function pointer.
72 // Emscripten's "function pointers" are actually integers indicating the 69 // Emscripten's "function pointers" are actually integers indicating the
73 // position in the call table. 0 represents nullptr. 70 // position in the call table. 0 represents nullptr.
74 if (!*reinterpret_cast<int*>(function)) 71 if (!*reinterpret_cast<int*>(function))
75 return; 72 return;
76 73
77 std::string signature; 74 std::string signature;
78 75
79 // Add return type to the signature. Similar logic in Emscripten: 76 // Add return type to the signature. Similar logic in Emscripten:
80 // https://github.com/kripken/emscripten/blob/1.37.3/src/modules.js#L46 77 // https://github.com/kripken/emscripten/blob/1.37.3/src/modules.js#L46
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 break; 130 break;
134 case TypeCategory::DOUBLE: 131 case TypeCategory::DOUBLE:
135 signature += 'd'; 132 signature += 'd';
136 break; 133 break;
137 default: 134 default:
138 throw std::runtime_error("Unexpected function argument type"); 135 throw std::runtime_error("Unexpected function argument type");
139 } 136 }
140 args.push_back(type); 137 args.push_back(type);
141 } 138 }
142 139
143 GetFunctionName(name, function, signature.c_str()); 140 int nameLength = GetFunctionName(nullptr, function, signature.c_str());
141 name.resize(nameLength);
142 GetFunctionName(name.data(), function, signature.c_str());
144 } 143 }
145 144
146 bool FunctionInfo::empty() const 145 bool FunctionInfo::empty() const
147 { 146 {
148 return name[0] == '\0'; 147 return name.empty();
149 } 148 }
150 149
151 ClassInfo* find_class(TYPEID classID) 150 ClassInfo* find_class(TYPEID classID)
152 { 151 {
153 for (auto& classInfo : classes) 152 for (auto& classInfo : classes)
154 if (classInfo.id == classID) 153 if (classInfo.id == classID)
155 return &classInfo; 154 return &classInfo;
156 return nullptr; 155 return nullptr;
157 } 156 }
158 157
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return " var result = readString(" + call_str + ");\n"; 309 return " var result = readString(" + call_str + ");\n";
311 case TypeCategory::CLASS_PTR: 310 case TypeCategory::CLASS_PTR:
312 { 311 {
313 std::string result; 312 std::string result;
314 result += " var result = " + call_str + ";\n"; 313 result += " var result = " + call_str + ";\n";
315 result += " if (result)\n"; 314 result += " if (result)\n";
316 result += " {\n"; 315 result += " {\n";
317 316
318 const ClassInfo* cls = find_class(call.pointerType); 317 const ClassInfo* cls = find_class(call.pointerType);
319 if (!cls) 318 if (!cls)
320 throw std::runtime_error("Function " + std::string(call.name) + " retu rns pointer to unknown class"); 319 throw std::runtime_error("Function " + call.name + " returns pointer t o unknown class");
321 320
322 auto offset = cls->subclass_differentiator.offset; 321 auto offset = cls->subclass_differentiator.offset;
323 if (offset == SIZE_MAX) 322 if (offset == SIZE_MAX)
324 result += " result = exports." + cls->name + "(result);\n"; 323 result += " result = exports." + cls->name + "(result);\n";
325 else 324 else
326 result += " result = exports." + cls->name + ".fromPointer(result); \n"; 325 result += " result = exports." + cls->name + ".fromPointer(result); \n";
327 326
328 result += " }\n"; 327 result += " }\n";
329 result += " else\n"; 328 result += " else\n";
330 result += " result = null;\n"; 329 result += " result = null;\n";
331 return result; 330 return result;
332 } 331 }
333 default: 332 default:
334 throw std::runtime_error("Unexpected return type for " + std::string(cal l.name)); 333 throw std::runtime_error("Unexpected return type for " + call.name);
335 } 334 }
336 } 335 }
337 336
338 std::string wrapCall(const FunctionInfo& call, bool isFunction) 337 std::string wrapCall(const FunctionInfo& call, bool isFunction)
339 { 338 {
340 bool hasStringArgs = false; 339 bool hasStringArgs = false;
341 std::vector<std::string> params; 340 std::vector<std::string> params;
342 std::string prefix; 341 std::string prefix;
343 342
344 if (isFunction) 343 if (isFunction)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 499
501 void printBindings() 500 void printBindings()
502 { 501 {
503 bindings_internal::printHelpers(); 502 bindings_internal::printHelpers();
504 503
505 for (const auto& item : classes) 504 for (const auto& item : classes)
506 bindings_internal::printClass(item); 505 bindings_internal::printClass(item);
507 for (const auto& item : namespaces) 506 for (const auto& item : namespaces)
508 bindings_internal::printNamespace(item); 507 bindings_internal::printNamespace(item);
509 } 508 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld