| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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-present 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 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 case TypeCategory::FLOAT: | 62 case TypeCategory::FLOAT: |
| 63 signature += 'f'; | 63 signature += 'f'; |
| 64 break; | 64 break; |
| 65 case TypeCategory::DOUBLE: | 65 case TypeCategory::DOUBLE: |
| 66 signature += 'd'; | 66 signature += 'd'; |
| 67 break; | 67 break; |
| 68 case TypeCategory::INT: | 68 case TypeCategory::INT: |
| 69 case TypeCategory::INT64: | 69 case TypeCategory::INT64: |
| 70 case TypeCategory::STRING_REF: | 70 case TypeCategory::STRING_REF: |
| 71 case TypeCategory::CLASS_PTR: | 71 case TypeCategory::CLASS_PTR: |
| 72 case TypeCategory::CLASS_REF: | |
| 72 signature += 'i'; | 73 signature += 'i'; |
| 73 break; | 74 break; |
| 74 default: | 75 default: |
| 75 throw std::runtime_error("Unexpected function return type"); | 76 throw std::runtime_error("Unexpected function return type"); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // `this` pointer is an implicit parameter with clang and should be added | 79 // `this` pointer is an implicit parameter with clang and should be added |
| 79 // to the signature. | 80 // to the signature. |
| 80 if (instance_function) | 81 if (instance_function) |
| 81 signature += 'i'; | 82 signature += 'i'; |
| 82 | 83 |
| 83 // Add explicit parameters to the signature, Similar logic in Emscripten: | 84 // Add explicit parameters to the signature, Similar logic in Emscripten: |
| 84 // https://github.com/kripken/emscripten/blob/1.37.3/src/modules.js#L67 | 85 // https://github.com/kripken/emscripten/blob/1.37.3/src/modules.js#L67 |
| 85 for (const auto& type : argTypes) | 86 for (const auto& type : argTypes) |
| 86 { | 87 { |
| 87 switch (type) | 88 switch (type) |
| 88 { | 89 { |
| 89 case TypeCategory::INT: | 90 case TypeCategory::INT: |
| 90 case TypeCategory::STRING_REF: | 91 case TypeCategory::STRING_REF: |
| 91 case TypeCategory::CLASS_PTR: | 92 case TypeCategory::CLASS_PTR: |
| 93 case TypeCategory::CLASS_REF: | |
| 92 signature += 'i'; | 94 signature += 'i'; |
| 93 break; | 95 break; |
| 94 case TypeCategory::INT64: | 96 case TypeCategory::INT64: |
| 95 // See https://github.com/kripken/emscripten/blob/1.37.3/src/modules.j s#L73, | 97 // See https://github.com/kripken/emscripten/blob/1.37.3/src/modules.j s#L73, |
| 96 // numerical types larger than 32-bit are split into multiple | 98 // numerical types larger than 32-bit are split into multiple |
| 97 // 32-bit parameters. | 99 // 32-bit parameters. |
| 98 signature += "ii"; | 100 signature += "ii"; |
| 99 break; | 101 break; |
| 100 case TypeCategory::FLOAT: | 102 case TypeCategory::FLOAT: |
| 101 signature += 'f'; | 103 signature += 'f'; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 std::string result; | 240 std::string result; |
| 239 result += " var string = createOwnedString();\n"; | 241 result += " var string = createOwnedString();\n"; |
| 240 result += " " + call_str + ";\n"; | 242 result += " " + call_str + ";\n"; |
| 241 result += " var result = readString(string);\n"; | 243 result += " var result = readString(string);\n"; |
| 242 result += " Module._DestroyString(string);\n"; | 244 result += " Module._DestroyString(string);\n"; |
| 243 return result; | 245 return result; |
| 244 } | 246 } |
| 245 case TypeCategory::STRING_REF: | 247 case TypeCategory::STRING_REF: |
| 246 return " var result = readString(" + call_str + ");\n"; | 248 return " var result = readString(" + call_str + ");\n"; |
| 247 case TypeCategory::CLASS_PTR: | 249 case TypeCategory::CLASS_PTR: |
| 250 case TypeCategory::CLASS_REF: | |
| 248 { | 251 { |
| 249 std::string result; | 252 std::string result; |
| 250 result += " var result = " + call_str + ";\n"; | 253 result += " var result = " + call_str + ";\n"; |
| 251 result += " if (result)\n"; | 254 result += " if (result)\n"; |
| 252 | 255 |
| 253 const ClassInfo* cls = find_class(call.pointerType); | 256 const ClassInfo* cls = find_class(call.pointerType); |
| 254 if (!cls) | 257 if (!cls) |
| 255 throw std::runtime_error("Function " + call.name + " returns pointer t o unknown class"); | 258 throw std::runtime_error("Function " + call.name + " returns pointer t o unknown class"); |
| 256 | 259 |
| 257 auto offset = cls->subclass_differentiator.offset; | 260 auto offset = cls->subclass_differentiator.offset; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 286 prefix += ", "; | 289 prefix += ", "; |
| 287 prefix += argName; | 290 prefix += argName; |
| 288 | 291 |
| 289 if (call.args[i] == TypeCategory::STRING_REF) | 292 if (call.args[i] == TypeCategory::STRING_REF) |
| 290 { | 293 { |
| 291 hasStringArgs = true; | 294 hasStringArgs = true; |
| 292 params.push_back(std::string("createString(") + argName + ")"); | 295 params.push_back(std::string("createString(") + argName + ")"); |
| 293 } | 296 } |
| 294 else if (call.args[i] == TypeCategory::CLASS_PTR) | 297 else if (call.args[i] == TypeCategory::CLASS_PTR) |
| 295 params.push_back(argName + " ? " + argName + "._pointer : 0"); | 298 params.push_back(argName + " ? " + argName + "._pointer : 0"); |
| 299 else if (call.args[i] == TypeCategory::CLASS_REF) | |
| 300 params.push_back(argName + "._pointer"); | |
|
Wladimir Palant
2017/08/31 12:37:39
This is an implicit null check, should be good eno
sergei
2017/08/31 12:59:20
LGTM, though not tested.
| |
| 296 else if (call.args[i] == TypeCategory::INT64) | 301 else if (call.args[i] == TypeCategory::INT64) |
| 297 { | 302 { |
| 298 // 64-bit integers are passed as two integer parameters | 303 // 64-bit integers are passed as two integer parameters |
| 299 params.push_back(argName + " >>> 0"); | 304 params.push_back(argName + " >>> 0"); |
| 300 params.push_back(argName + " / 0x100000000 >>> 0"); | 305 params.push_back(argName + " / 0x100000000 >>> 0"); |
| 301 } | 306 } |
| 302 else | 307 else |
| 303 params.push_back(argName); | 308 params.push_back(argName); |
| 304 } | 309 } |
| 305 prefix += ")\n{\n"; | 310 prefix += ")\n{\n"; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 | 483 |
| 479 void printBindings() | 484 void printBindings() |
| 480 { | 485 { |
| 481 bindings_internal::printHelpers(); | 486 bindings_internal::printHelpers(); |
| 482 | 487 |
| 483 for (const auto& cls : classes) | 488 for (const auto& cls : classes) |
| 484 bindings_internal::printClass(cls); | 489 bindings_internal::printClass(cls); |
| 485 for (const auto& cls : classes) | 490 for (const auto& cls : classes) |
| 486 bindings_internal::printClassMapping(cls); | 491 bindings_internal::printClassMapping(cls); |
| 487 } | 492 } |
| OLD | NEW |