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

Unified 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: Created March 30, 2017, 7:59 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« compiled/bindings.ipp ('K') | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/filter/RegExpFilter.cpp
===================================================================
--- a/compiled/filter/RegExpFilter.cpp
+++ b/compiled/filter/RegExpFilter.cpp
@@ -10,17 +10,19 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <cctype>
#include <climits>
+#include <cstdio>
#include <emscripten.h>
#include "RegExpFilter.h"
#include "../StringScanner.h"
#include "../StringMap.h"
namespace
@@ -337,21 +339,36 @@ void RegExpFilter::ParseSitekeys(const S
{
if (scanner.position() > start)
AddSitekey(DependentString(sitekeys, start, scanner.position() - start));
start = scanner.position() + 1;
}
}
}
-void RegExpFilter::InitJSTypes()
+void RegExpFilter::GenerateCustomBindings()
{
sergei 2017/03/30 11:09:18 BTW, what about having of this method under `#ifde
Wladimir Palant 2017/03/30 12:58:58 Why? The compiler will remove it if not needed.
sergei 2017/04/04 14:49:30 Generally yes, but I'm not sure that compiler can
Wladimir Palant 2017/04/04 15:41:48 I sincerely disagee - we are adding EMSCRIPTEN_KEE
sergei 2017/04/11 16:29:20 I'm pretty sure that compiler is not removing this
Wladimir Palant 2017/04/11 18:22:44 That's actually me doing something stupid - this f
- EM_ASM(exports.RegExpFilter.typeMap = {};);
+ printf("exports.RegExpFilter.typeMap = {\n");
+
+ OwnedString type;
+ char type_cstr[256];
for (auto it = typeMap.begin(); it != typeMap.end(); ++it)
- EM_ASM_ARGS(exports.RegExpFilter.typeMap[readString($0).replace("-", "_").toUpperCase()] = $1, &(it->first), it->second);
+ {
+ type = it->first;
+ for (int i = 0; i < type.length(); i++)
+ {
+ if (type[i] == '-')
+ type_cstr[i] = '_';
+ else
+ type_cstr[i] = toupper(type[i]);
sergei 2017/03/30 11:09:17 Just wonder, does compiler generate a warning here
Wladimir Palant 2017/03/30 12:58:58 Nope, for me it doesn't.
+ }
+ type_cstr[type.length()] = 0;
+ printf(" %s: %i,\n", type_cstr, it->second);
+ }
+ printf("};\n");
}
sergei 2017/03/30 11:09:17 This implementation smells but since it's only to
Wladimir Palant 2017/03/30 12:58:58 Yes, this isn't runtime code.
RegExpFilter::DomainMap* RegExpFilter::GetDomains() const
{
if (!mData.DomainsParsingDone())
{
ParseDomains(mData.GetDomainsSource(mText), u'|');
mData.SetDomainsParsingDone();
« compiled/bindings.ipp ('K') | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld