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: Slight code improvements Created May 8, 2017, 8:52 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 signature += 'd'; 132 signature += 'd';
133 break; 133 break;
134 default: 134 default:
135 throw std::runtime_error("Unexpected function argument type"); 135 throw std::runtime_error("Unexpected function argument type");
136 } 136 }
137 args.push_back(type); 137 args.push_back(type);
138 } 138 }
139 139
140 int nameLength = GetFunctionName(nullptr, function, signature.c_str()); 140 int nameLength = GetFunctionName(nullptr, function, signature.c_str());
141 name.resize(nameLength); 141 name.resize(nameLength);
142 GetFunctionName(name.data(), function, signature.c_str()); 142 GetFunctionName(name.data(), function, signature.c_str());
sergei 2017/05/08 09:16:29 if std::string::data() returns only a const pointe
Wladimir Palant 2017/05/08 10:17:18 Oh, so the C++ standard in its most recent iterati
143 } 143 }
144 144
145 bool FunctionInfo::empty() const 145 bool FunctionInfo::empty() const
146 { 146 {
147 return name.size() == 0; 147 return name.empty();
148 } 148 }
149 149
150 ClassInfo* find_class(TYPEID classID) 150 ClassInfo* find_class(TYPEID classID)
151 { 151 {
152 for (auto& classInfo : classes) 152 for (auto& classInfo : classes)
153 if (classInfo.id == classID) 153 if (classInfo.id == classID)
154 return &classInfo; 154 return &classInfo;
155 return nullptr; 155 return nullptr;
156 } 156 }
157 157
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 std::string generateCall(const FunctionInfo& call, 266 std::string generateCall(const FunctionInfo& call,
267 std::vector<std::string>& params) 267 std::vector<std::string>& params)
268 { 268 {
269 if (call.returnType == TypeCategory::DEPENDENT_STRING || 269 if (call.returnType == TypeCategory::DEPENDENT_STRING ||
270 call.returnType == TypeCategory::OWNED_STRING) 270 call.returnType == TypeCategory::OWNED_STRING)
271 { 271 {
272 params.insert(params.begin(), "string"); 272 params.insert(params.begin(), "string");
273 } 273 }
274 274
275 std::string call_str(call.name.data()); 275 std::string call_str(call.name);
276 call_str += "("; 276 call_str += "(";
277 for (int i = 0; i < params.size(); i++) 277 for (int i = 0; i < params.size(); i++)
278 { 278 {
279 if (i > 0) 279 if (i > 0)
280 call_str += ", "; 280 call_str += ", ";
281 call_str += params[i]; 281 call_str += params[i];
282 } 282 }
283 call_str += ")"; 283 call_str += ")";
284 284
285 switch (call.returnType) 285 switch (call.returnType)
(...skipping 23 matching lines...) Expand all
309 return " var result = readString(" + call_str + ");\n"; 309 return " var result = readString(" + call_str + ");\n";
310 case TypeCategory::CLASS_PTR: 310 case TypeCategory::CLASS_PTR:
311 { 311 {
312 std::string result; 312 std::string result;
313 result += " var result = " + call_str + ";\n"; 313 result += " var result = " + call_str + ";\n";
314 result += " if (result)\n"; 314 result += " if (result)\n";
315 result += " {\n"; 315 result += " {\n";
316 316
317 const ClassInfo* cls = find_class(call.pointerType); 317 const ClassInfo* cls = find_class(call.pointerType);
318 if (!cls) 318 if (!cls)
319 throw std::runtime_error("Function " + std::string(call.name.data()) + " returns pointer to unknown class"); 319 throw std::runtime_error("Function " + call.name + " returns pointer t o unknown class");
320 320
321 auto offset = cls->subclass_differentiator.offset; 321 auto offset = cls->subclass_differentiator.offset;
322 if (offset == SIZE_MAX) 322 if (offset == SIZE_MAX)
323 result += " result = exports." + cls->name + "(result);\n"; 323 result += " result = exports." + cls->name + "(result);\n";
324 else 324 else
325 result += " result = exports." + cls->name + ".fromPointer(result); \n"; 325 result += " result = exports." + cls->name + ".fromPointer(result); \n";
326 326
327 result += " }\n"; 327 result += " }\n";
328 result += " else\n"; 328 result += " else\n";
329 result += " result = null;\n"; 329 result += " result = null;\n";
330 return result; 330 return result;
331 } 331 }
332 default: 332 default:
333 throw std::runtime_error("Unexpected return type for " + std::string(cal l.name.data())); 333 throw std::runtime_error("Unexpected return type for " + call.name);
334 } 334 }
335 } 335 }
336 336
337 std::string wrapCall(const FunctionInfo& call, bool isFunction) 337 std::string wrapCall(const FunctionInfo& call, bool isFunction)
338 { 338 {
339 bool hasStringArgs = false; 339 bool hasStringArgs = false;
340 std::vector<std::string> params; 340 std::vector<std::string> params;
341 std::string prefix; 341 std::string prefix;
342 342
343 if (isFunction) 343 if (isFunction)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 499
500 void printBindings() 500 void printBindings()
501 { 501 {
502 bindings_internal::printHelpers(); 502 bindings_internal::printHelpers();
503 503
504 for (const auto& item : classes) 504 for (const auto& item : classes)
505 bindings_internal::printClass(item); 505 bindings_internal::printClass(item);
506 for (const auto& item : namespaces) 506 for (const auto& item : namespaces)
507 bindings_internal::printNamespace(item); 507 bindings_internal::printNamespace(item);
508 } 508 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld