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

Side by Side Diff: compiled/filter/RegExpFilter.cpp

Issue 29398655: Issue 5062 - [emscripten] Allow generation of custom bindings code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
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:
View unified diff | Download patch
« no previous file with comments | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <climits> 19 #include <climits>
20 #include <cstdio>
21 #include <string>
19 22
20 #include <emscripten.h> 23 #include <emscripten.h>
21 24
22 #include "RegExpFilter.h" 25 #include "RegExpFilter.h"
23 #include "../StringScanner.h" 26 #include "../StringScanner.h"
24 #include "../StringMap.h" 27 #include "../StringMap.h"
25 28
26 namespace 29 namespace
27 { 30 {
28 enum 31 enum
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 done = scanner.done(); 342 done = scanner.done();
340 if (scanner.next() == u'|') 343 if (scanner.next() == u'|')
341 { 344 {
342 if (scanner.position() > start) 345 if (scanner.position() > start)
343 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ; 346 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ;
344 start = scanner.position() + 1; 347 start = scanner.position() + 1;
345 } 348 }
346 } 349 }
347 } 350 }
348 351
349 void RegExpFilter::InitJSTypes() 352 void RegExpFilter::GenerateCustomBindings()
350 { 353 {
351 EM_ASM(exports.RegExpFilter.typeMap = {};); 354 printf("exports.RegExpFilter.typeMap = {\n");
352 for (auto it = typeMap.begin(); it != typeMap.end(); ++it) 355
353 EM_ASM_ARGS(exports.RegExpFilter.typeMap[readString($0).replace("-", "_").to UpperCase()] = $1, &(it->first), it->second); 356 for (const auto& item : typeMap)
357 {
358 std::string type(item.first.length(), '\0');
359 for (int i = 0; i < item.first.length(); i++)
360 type[i] = (item.first[i] == '-' ? '_' : toupper(item.first[i]));
361 printf(" %s: %i,\n", type.c_str(), item.second);
362 }
363 printf("};\n");
354 } 364 }
355 365
356 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const 366 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const
357 { 367 {
358 if (!mData.DomainsParsingDone()) 368 if (!mData.DomainsParsingDone())
359 { 369 {
360 ParseDomains(mData.GetDomainsSource(mText), u'|'); 370 ParseDomains(mData.GetDomainsSource(mText), u'|');
361 mData.SetDomainsParsingDone(); 371 mData.SetDomainsParsingDone();
362 } 372 }
363 return ActiveFilter::GetDomains(); 373 return ActiveFilter::GetDomains();
(...skipping 20 matching lines...) Expand all
384 return false; 394 return false;
385 } 395 }
386 396
387 if (!mData.RegExpParsingDone()) 397 if (!mData.RegExpParsingDone())
388 { 398 {
389 const OwnedString pattern(mData.GetRegExpSource(mText)); 399 const OwnedString pattern(mData.GetRegExpSource(mText));
390 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; 400 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ;
391 } 401 }
392 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);
393 } 403 }
OLDNEW
« no previous file with comments | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld