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

Delta Between Two Patch Sets: compiled/filter/RegExpFilter.cpp

Issue 29398655: Issue 5062 - [emscripten] Allow generation of custom bindings code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Improved initialization code Created March 30, 2017, 12:58 p.m.
Right Patch Set: Rebased Created April 13, 2017, 1:06 p.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/filter/RegExpFilter.h ('k') | no next file » | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <cctype> 18 #include <cctype>
19 #include <climits> 19 #include <climits>
20 #include <cstdio> 20 #include <cstdio>
21 #include <string>
21 22
22 #include <emscripten.h> 23 #include <emscripten.h>
23 24
24 #include "RegExpFilter.h" 25 #include "RegExpFilter.h"
25 #include "../StringScanner.h" 26 #include "../StringScanner.h"
26 #include "../StringMap.h" 27 #include "../StringMap.h"
27 28
28 namespace 29 namespace
29 { 30 {
30 enum 31 enum
31 { 32 {
32 TYPE_OTHER = 0x1, 33 TYPE_OTHER = 0x1,
33 TYPE_SCRIPT = 0x2, 34 TYPE_SCRIPT = 0x2,
34 TYPE_IMAGE = 0x4, 35 TYPE_IMAGE = 0x4,
35 TYPE_STYLESHEET = 0x8, 36 TYPE_STYLESHEET = 0x8,
36 TYPE_OBJECT = 0x10, 37 TYPE_OBJECT = 0x10,
37 TYPE_SUBDOCUMENT = 0x20, 38 TYPE_SUBDOCUMENT = 0x20,
38 TYPE_DOCUMENT = 0x40, 39 TYPE_DOCUMENT = 0x40,
40 TYPE_WEBSOCKET = 0x80,
41 TYPE_WEBRTC = 0x100,
39 TYPE_PING = 0x400, 42 TYPE_PING = 0x400,
40 TYPE_XMLHTTPREQUEST = 0x800, 43 TYPE_XMLHTTPREQUEST = 0x800,
41 TYPE_OBJECT_SUBREQUEST = 0x1000, 44 TYPE_OBJECT_SUBREQUEST = 0x1000,
42 TYPE_MEDIA = 0x4000, 45 TYPE_MEDIA = 0x4000,
43 TYPE_FONT = 0x8000, 46 TYPE_FONT = 0x8000,
44 TYPE_POPUP = 0x8000000, 47 TYPE_POPUP = 0x8000000,
45 TYPE_GENERICBLOCK = 0x10000000, 48 TYPE_GENERICBLOCK = 0x10000000,
46 TYPE_GENERICHIDE = 0x20000000, 49 TYPE_GENERICHIDE = 0x20000000,
47 TYPE_ELEMHIDE = 0x40000000, 50 TYPE_ELEMHIDE = 0x40000000,
48 }; 51 };
49 52
50 StringMap<int> typeMap { 53 const StringMap<int> typeMap {
51 {u"other"_str, TYPE_OTHER}, 54 {u"other"_str, TYPE_OTHER},
52 {u"script"_str, TYPE_SCRIPT}, 55 {u"script"_str, TYPE_SCRIPT},
53 {u"image"_str, TYPE_IMAGE}, 56 {u"image"_str, TYPE_IMAGE},
54 {u"stylesheet"_str, TYPE_STYLESHEET}, 57 {u"stylesheet"_str, TYPE_STYLESHEET},
55 {u"object"_str, TYPE_OBJECT}, 58 {u"object"_str, TYPE_OBJECT},
56 {u"subdocument"_str, TYPE_SUBDOCUMENT}, 59 {u"subdocument"_str, TYPE_SUBDOCUMENT},
57 {u"document"_str, TYPE_DOCUMENT}, 60 {u"document"_str, TYPE_DOCUMENT},
61 {u"websocket"_str, TYPE_WEBSOCKET},
62 {u"webrtc"_str, TYPE_WEBRTC},
58 {u"xbl"_str, TYPE_OTHER}, // Backwards compat 63 {u"xbl"_str, TYPE_OTHER}, // Backwards compat
59 {u"ping"_str, TYPE_PING}, 64 {u"ping"_str, TYPE_PING},
60 {u"xmlhttprequest"_str, TYPE_XMLHTTPREQUEST}, 65 {u"xmlhttprequest"_str, TYPE_XMLHTTPREQUEST},
61 {u"object-subrequest"_str, TYPE_OBJECT_SUBREQUEST}, 66 {u"object-subrequest"_str, TYPE_OBJECT_SUBREQUEST},
62 {u"dtd"_str, TYPE_OTHER}, // Backwards compat 67 {u"dtd"_str, TYPE_OTHER}, // Backwards compat
63 {u"media"_str, TYPE_MEDIA}, 68 {u"media"_str, TYPE_MEDIA},
64 {u"font"_str, TYPE_FONT}, 69 {u"font"_str, TYPE_FONT},
65 {u"background"_str, TYPE_IMAGE}, // Backwards compat 70 {u"background"_str, TYPE_IMAGE}, // Backwards compat
66 71
67 {u"popup"_str, TYPE_POPUP}, 72 {u"popup"_str, TYPE_POPUP},
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ; 346 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ;
342 start = scanner.position() + 1; 347 start = scanner.position() + 1;
343 } 348 }
344 } 349 }
345 } 350 }
346 351
347 void RegExpFilter::GenerateCustomBindings() 352 void RegExpFilter::GenerateCustomBindings()
348 { 353 {
349 printf("exports.RegExpFilter.typeMap = {\n"); 354 printf("exports.RegExpFilter.typeMap = {\n");
350 355
351 OwnedString type; 356 for (const auto& item : typeMap)
352 char type_cstr[256]; 357 {
353 for (auto it = typeMap.begin(); it != typeMap.end(); ++it) 358 std::string type(item.first.length(), '\0');
hub 2017/03/31 02:57:22 Shouldn't we use a range iterator here (with const
Wladimir Palant 2017/04/04 14:26:01 Done.
354 { 359 for (int i = 0; i < item.first.length(); i++)
355 type = it->first; 360 type[i] = (item.first[i] == '-' ? '_' : toupper(item.first[i]));
356 for (int i = 0; i < type.length(); i++) 361 printf(" %s: %i,\n", type.c_str(), item.second);
357 {
358 if (type[i] == '-')
359 type_cstr[i] = '_';
360 else
361 type_cstr[i] = toupper(type[i]);
362 }
hub 2017/03/31 02:57:22 Also we don't check that i or type.length() is < 2
Wladimir Palant 2017/04/04 14:26:01 I didn't really want to bother but let's do a prop
363 type_cstr[type.length()] = 0;
364 printf(" %s: %i,\n", type_cstr, it->second);
365 } 362 }
366 printf("};\n"); 363 printf("};\n");
367 } 364 }
368 365
369 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const 366 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const
370 { 367 {
371 if (!mData.DomainsParsingDone()) 368 if (!mData.DomainsParsingDone())
372 { 369 {
373 ParseDomains(mData.GetDomainsSource(mText), u'|'); 370 ParseDomains(mData.GetDomainsSource(mText), u'|');
374 mData.SetDomainsParsingDone(); 371 mData.SetDomainsParsingDone();
(...skipping 22 matching lines...) Expand all
397 return false; 394 return false;
398 } 395 }
399 396
400 if (!mData.RegExpParsingDone()) 397 if (!mData.RegExpParsingDone())
401 { 398 {
402 const OwnedString pattern(mData.GetRegExpSource(mText)); 399 const OwnedString pattern(mData.GetRegExpSource(mText));
403 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; 400 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ;
404 } 401 }
405 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); 402 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location);
406 } 403 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld