diff options
author | Ivan Blinkov <ivan@blinkov.ru> | 2022-02-10 16:47:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:10 +0300 |
commit | 1aeb9a455974457866f78722ad98114bafc84e8a (patch) | |
tree | e4340eaf1668684d83a0a58c36947c5def5350ad /contrib/libs/hyperscan/src/compiler | |
parent | bd5ef432f5cfb1e18851381329d94665a4c22470 (diff) | |
download | ydb-1aeb9a455974457866f78722ad98114bafc84e8a.tar.gz |
Restoring authorship annotation for Ivan Blinkov <ivan@blinkov.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/hyperscan/src/compiler')
-rw-r--r-- | contrib/libs/hyperscan/src/compiler/asserts.cpp | 54 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/compiler/asserts.h | 10 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/compiler/compiler.cpp | 240 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/compiler/compiler.h | 48 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/compiler/error.cpp | 34 | ||||
-rw-r--r-- | contrib/libs/hyperscan/src/compiler/expression_info.h | 204 |
6 files changed, 295 insertions, 295 deletions
diff --git a/contrib/libs/hyperscan/src/compiler/asserts.cpp b/contrib/libs/hyperscan/src/compiler/asserts.cpp index 444422260c..12f5dbc5ba 100644 --- a/contrib/libs/hyperscan/src/compiler/asserts.cpp +++ b/contrib/libs/hyperscan/src/compiler/asserts.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017, Intel Corporation + * Copyright (c) 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -42,8 +42,8 @@ * word-to-word and word-to-nonword) are dropped. */ #include "asserts.h" - -#include "compiler/compiler.h" + +#include "compiler/compiler.h" #include "nfagraph/ng.h" #include "nfagraph/ng_prune.h" #include "nfagraph/ng_redundancy.h" @@ -117,13 +117,13 @@ u32 conjunct(u32 flags1, u32 flags2) { typedef map<pair<NFAVertex, NFAVertex>, NFAEdge> edge_cache_t; static -void replaceAssertVertex(NGHolder &g, NFAVertex t, const ExpressionInfo &expr, - edge_cache_t &edge_cache, u32 &assert_edge_count) { - DEBUG_PRINTF("replacing assert vertex %zu\n", g[t].index); +void replaceAssertVertex(NGHolder &g, NFAVertex t, const ExpressionInfo &expr, + edge_cache_t &edge_cache, u32 &assert_edge_count) { + DEBUG_PRINTF("replacing assert vertex %zu\n", g[t].index); const u32 flags = g[t].assert_flags; - DEBUG_PRINTF("consider assert vertex %zu with flags %u\n", g[t].index, - flags); + DEBUG_PRINTF("consider assert vertex %zu with flags %u\n", g[t].index, + flags); // Wire up all the predecessors to all the successors. @@ -144,7 +144,7 @@ void replaceAssertVertex(NGHolder &g, NFAVertex t, const ExpressionInfo &expr, for (const auto &outEdge : out_edges_range(t, g)) { NFAVertex v = target(outEdge, g); - DEBUG_PRINTF("consider path [%zu,%zu,%zu]\n", g[u].index, + DEBUG_PRINTF("consider path [%zu,%zu,%zu]\n", g[u].index, g[t].index, g[v].index); if (v == t) { @@ -175,16 +175,16 @@ void replaceAssertVertex(NGHolder &g, NFAVertex t, const ExpressionInfo &expr, auto cache_key = make_pair(u, v); auto ecit = edge_cache.find(cache_key); if (ecit == edge_cache.end()) { - DEBUG_PRINTF("adding edge %zu %zu\n", g[u].index, g[v].index); - NFAEdge e = add_edge(u, v, g); + DEBUG_PRINTF("adding edge %zu %zu\n", g[u].index, g[v].index); + NFAEdge e = add_edge(u, v, g); edge_cache.emplace(cache_key, e); g[e].assert_flags = flags; if (++assert_edge_count > MAX_ASSERT_EDGES) { - throw CompileError(expr.index, "Pattern is too large."); + throw CompileError(expr.index, "Pattern is too large."); } } else { NFAEdge e = ecit->second; - DEBUG_PRINTF("updating edge %zu %zu [a %zu]\n", g[u].index, + DEBUG_PRINTF("updating edge %zu %zu [a %zu]\n", g[u].index, g[v].index, g[t].index); // Edge already exists. u32 &e_flags = g[e].assert_flags; @@ -201,29 +201,29 @@ void replaceAssertVertex(NGHolder &g, NFAVertex t, const ExpressionInfo &expr, } static -void setReportId(ReportManager &rm, NGHolder &g, const ExpressionInfo &expr, - NFAVertex v, s32 adj) { +void setReportId(ReportManager &rm, NGHolder &g, const ExpressionInfo &expr, + NFAVertex v, s32 adj) { // Don't try and set the report ID of a special vertex. assert(!is_special(v, g)); // There should be no reports set already. assert(g[v].reports.empty()); - Report r = rm.getBasicInternalReport(expr, adj); + Report r = rm.getBasicInternalReport(expr, adj); g[v].reports.insert(rm.getInternalId(r)); - DEBUG_PRINTF("set report id for vertex %zu, adj %d\n", g[v].index, adj); + DEBUG_PRINTF("set report id for vertex %zu, adj %d\n", g[v].index, adj); } static -void checkForMultilineStart(ReportManager &rm, NGHolder &g, - const ExpressionInfo &expr) { +void checkForMultilineStart(ReportManager &rm, NGHolder &g, + const ExpressionInfo &expr) { vector<NFAEdge> dead; for (auto v : adjacent_vertices_range(g.start, g)) { if (!(g[v].assert_flags & POS_FLAG_MULTILINE_START)) { continue; } - DEBUG_PRINTF("mls %zu %08x\n", g[v].index, g[v].assert_flags); + DEBUG_PRINTF("mls %zu %08x\n", g[v].index, g[v].assert_flags); /* we have found a multi-line start (maybe more than one) */ @@ -241,7 +241,7 @@ void checkForMultilineStart(ReportManager &rm, NGHolder &g, for (const auto &e : dead) { NFAVertex dummy = add_vertex(g); g[dummy].char_reach.setall(); - setReportId(rm, g, expr, dummy, -1); + setReportId(rm, g, expr, dummy, -1); add_edge(source(e, g), dummy, g[e], g); add_edge(dummy, g.accept, g); } @@ -266,8 +266,8 @@ bool hasAssertVertices(const NGHolder &g) { * Remove the horrors that are the temporary assert vertices which arise from * our construction method. Allows the rest of our code base to live in * blissful ignorance of their existence. */ -void removeAssertVertices(ReportManager &rm, NGHolder &g, - const ExpressionInfo &expr) { +void removeAssertVertices(ReportManager &rm, NGHolder &g, + const ExpressionInfo &expr) { size_t num = 0; DEBUG_PRINTF("before: graph has %zu vertices\n", num_vertices(g)); @@ -289,19 +289,19 @@ void removeAssertVertices(ReportManager &rm, NGHolder &g, for (auto v : vertices_range(g)) { if (g[v].assert_flags & WORDBOUNDARY_FLAGS) { - replaceAssertVertex(g, v, expr, edge_cache, assert_edge_count); + replaceAssertVertex(g, v, expr, edge_cache, assert_edge_count); num++; } } - checkForMultilineStart(rm, g, expr); + checkForMultilineStart(rm, g, expr); if (num) { DEBUG_PRINTF("resolved %zu assert vertices\n", num); pruneUseless(g); pruneEmptyVertices(g); - renumber_vertices(g); - renumber_edges(g); + renumber_vertices(g); + renumber_edges(g); } DEBUG_PRINTF("after: graph has %zu vertices\n", num_vertices(g)); diff --git a/contrib/libs/hyperscan/src/compiler/asserts.h b/contrib/libs/hyperscan/src/compiler/asserts.h index b4d64c6c9a..45f2534240 100644 --- a/contrib/libs/hyperscan/src/compiler/asserts.h +++ b/contrib/libs/hyperscan/src/compiler/asserts.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017, Intel Corporation + * Copyright (c) 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,9 +35,9 @@ namespace ue2 { -class ExpressionInfo; +class ExpressionInfo; class ReportManager; -class NGHolder; +class NGHolder; /** \brief Convert temporary assert vertices (from construction method) to * edge-based flags. @@ -45,8 +45,8 @@ class NGHolder; * Remove the horrors that are the temporary assert vertices which arise from * our construction method. Allows the rest of our code base to live in * blissful ignorance of their existence. */ -void removeAssertVertices(ReportManager &rm, NGHolder &g, - const ExpressionInfo &expr); +void removeAssertVertices(ReportManager &rm, NGHolder &g, + const ExpressionInfo &expr); } // namespace ue2 diff --git a/contrib/libs/hyperscan/src/compiler/compiler.cpp b/contrib/libs/hyperscan/src/compiler/compiler.cpp index 5751bd64f4..86974f9281 100644 --- a/contrib/libs/hyperscan/src/compiler/compiler.cpp +++ b/contrib/libs/hyperscan/src/compiler/compiler.cpp @@ -29,10 +29,10 @@ /** \file * \brief Compiler front-end interface. */ -#include "allocator.h" +#include "allocator.h" #include "asserts.h" #include "compiler.h" -#include "crc32.h" +#include "crc32.h" #include "database.h" #include "grey.h" #include "hs_internal.h" @@ -58,7 +58,7 @@ #include "rose/rose_build.h" #include "rose/rose_internal.h" #include "som/slot_manager_dump.h" -#include "util/bytecode_ptr.h" +#include "util/bytecode_ptr.h" #include "util/compile_error.h" #include "util/target_info.h" #include "util/verify_types.h" @@ -80,9 +80,9 @@ static void validateExt(const hs_expr_ext &ext) { static const unsigned long long ALL_EXT_FLAGS = HS_EXT_FLAG_MIN_OFFSET | HS_EXT_FLAG_MAX_OFFSET | - HS_EXT_FLAG_MIN_LENGTH | - HS_EXT_FLAG_EDIT_DISTANCE | - HS_EXT_FLAG_HAMMING_DISTANCE; + HS_EXT_FLAG_MIN_LENGTH | + HS_EXT_FLAG_EDIT_DISTANCE | + HS_EXT_FLAG_HAMMING_DISTANCE; if (ext.flags & ~ALL_EXT_FLAGS) { throw CompileError("Invalid hs_expr_ext flag set."); } @@ -100,13 +100,13 @@ void validateExt(const hs_expr_ext &ext) { throw CompileError("In hs_expr_ext, min_length must be less than or " "equal to max_offset."); } - - if ((ext.flags & HS_EXT_FLAG_EDIT_DISTANCE) && - (ext.flags & HS_EXT_FLAG_HAMMING_DISTANCE)) { - throw CompileError("In hs_expr_ext, cannot have both edit distance and " - "Hamming distance."); - } - + + if ((ext.flags & HS_EXT_FLAG_EDIT_DISTANCE) && + (ext.flags & HS_EXT_FLAG_HAMMING_DISTANCE)) { + throw CompileError("In hs_expr_ext, cannot have both edit distance and " + "Hamming distance."); + } + } void ParsedLitExpression::parseLiteral(const char *expression, size_t len, @@ -150,10 +150,10 @@ ParsedLitExpression::ParsedLitExpression(unsigned index_in, } ParsedExpression::ParsedExpression(unsigned index_in, const char *expression, - unsigned flags, ReportID report, + unsigned flags, ReportID report, const hs_expr_ext *ext) - : expr(index_in, flags & HS_FLAG_ALLOWEMPTY, flags & HS_FLAG_SINGLEMATCH, - false, flags & HS_FLAG_PREFILTER, SOM_NONE, report, 0, MAX_OFFSET, + : expr(index_in, flags & HS_FLAG_ALLOWEMPTY, flags & HS_FLAG_SINGLEMATCH, + false, flags & HS_FLAG_PREFILTER, SOM_NONE, report, 0, MAX_OFFSET, 0, 0, 0, flags & HS_FLAG_QUIET) { // We disallow SOM + Quiet. if ((flags & HS_FLAG_QUIET) && (flags & HS_FLAG_SOM_LEFTMOST)) { @@ -165,7 +165,7 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression, component = parse(expression, mode); - expr.utf8 = mode.utf8; /* utf8 may be set by parse() */ + expr.utf8 = mode.utf8; /* utf8 may be set by parse() */ const size_t len = strlen(expression); if (expr.utf8 && !isValidUtf8(expression, len)) { @@ -196,7 +196,7 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression, // Set SOM type. if (flags & HS_FLAG_SOM_LEFTMOST) { - expr.som = SOM_LEFT; + expr.som = SOM_LEFT; } // Set extended parameters, if we have them. @@ -205,32 +205,32 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression, validateExt(*ext); if (ext->flags & HS_EXT_FLAG_MIN_OFFSET) { - expr.min_offset = ext->min_offset; + expr.min_offset = ext->min_offset; } if (ext->flags & HS_EXT_FLAG_MAX_OFFSET) { - expr.max_offset = ext->max_offset; + expr.max_offset = ext->max_offset; } if (ext->flags & HS_EXT_FLAG_MIN_LENGTH) { - expr.min_length = ext->min_length; - } - if (ext->flags & HS_EXT_FLAG_EDIT_DISTANCE) { - expr.edit_distance = ext->edit_distance; - } - if (ext->flags & HS_EXT_FLAG_HAMMING_DISTANCE) { - expr.hamm_distance = ext->hamming_distance; + expr.min_length = ext->min_length; } + if (ext->flags & HS_EXT_FLAG_EDIT_DISTANCE) { + expr.edit_distance = ext->edit_distance; + } + if (ext->flags & HS_EXT_FLAG_HAMMING_DISTANCE) { + expr.hamm_distance = ext->hamming_distance; + } } // These are validated in validateExt, so an error will already have been // thrown if these conditions don't hold. - assert(expr.max_offset >= expr.min_offset); - assert(expr.max_offset >= expr.min_length); + assert(expr.max_offset >= expr.min_offset); + assert(expr.max_offset >= expr.min_length); // Since prefiltering and SOM aren't supported together, we must squash any // min_length constraint as well. - if (flags & HS_FLAG_PREFILTER && expr.min_length) { + if (flags & HS_FLAG_PREFILTER && expr.min_length) { DEBUG_PRINTF("prefiltering mode: squashing min_length constraint\n"); - expr.min_length = 0; + expr.min_length = 0; } } @@ -239,25 +239,25 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression, * \brief Dumps the parse tree to screen in debug mode and to disk in dump * mode. */ -void dumpExpression(UNUSED const ParsedExpression &pe, +void dumpExpression(UNUSED const ParsedExpression &pe, UNUSED const char *stage, UNUSED const Grey &grey) { #if defined(DEBUG) - DEBUG_PRINTF("===== Rule ID: %u (expression index: %u) =====\n", - pe.expr.report, pe.expr.index); + DEBUG_PRINTF("===== Rule ID: %u (expression index: %u) =====\n", + pe.expr.report, pe.expr.index); ostringstream debug_tree; - dumpTree(debug_tree, pe.component.get()); + dumpTree(debug_tree, pe.component.get()); printf("%s\n", debug_tree.str().c_str()); #endif // DEBUG #if defined(DUMP_SUPPORT) if (grey.dumpFlags & Grey::DUMP_PARSE) { stringstream ss; - ss << grey.dumpPath << "Expr_" << pe.expr.index << "_componenttree_" + ss << grey.dumpPath << "Expr_" << pe.expr.index << "_componenttree_" << stage << ".txt"; ofstream out(ss.str().c_str()); - out << "Component Tree for " << pe.expr.report << endl; - dumpTree(out, pe.component.get()); - if (pe.expr.utf8) { + out << "Component Tree for " << pe.expr.report << endl; + dumpTree(out, pe.component.get()); + if (pe.expr.utf8) { out << "UTF8 mode" << endl; } } @@ -267,13 +267,13 @@ void dumpExpression(UNUSED const ParsedExpression &pe, /** \brief Run Component tree optimisations on \a expr. */ static -void optimise(ParsedExpression &pe) { - if (pe.expr.min_length || pe.expr.som) { +void optimise(ParsedExpression &pe) { + if (pe.expr.min_length || pe.expr.som) { return; } DEBUG_PRINTF("optimising\n"); - pe.component->optimise(true /* root is connected to sds */); + pe.component->optimise(true /* root is connected to sds */); } void addExpression(NG &ng, unsigned index, const char *expression, @@ -329,34 +329,34 @@ void addExpression(NG &ng, unsigned index, const char *expression, // Do per-expression processing: errors here will result in an exception // being thrown up to our caller - ParsedExpression pe(index, expression, flags, id, ext); - dumpExpression(pe, "orig", cc.grey); + ParsedExpression pe(index, expression, flags, id, ext); + dumpExpression(pe, "orig", cc.grey); // Apply prefiltering transformations if desired. - if (pe.expr.prefilter) { - prefilterTree(pe.component, ParseMode(flags)); - dumpExpression(pe, "prefiltered", cc.grey); + if (pe.expr.prefilter) { + prefilterTree(pe.component, ParseMode(flags)); + dumpExpression(pe, "prefiltered", cc.grey); } // Expressions containing zero-width assertions and other extended pcre // types aren't supported yet. This call will throw a ParseError exception // if the component tree contains such a construct. - checkUnsupported(*pe.component); + checkUnsupported(*pe.component); - pe.component->checkEmbeddedStartAnchor(true); - pe.component->checkEmbeddedEndAnchor(true); + pe.component->checkEmbeddedStartAnchor(true); + pe.component->checkEmbeddedEndAnchor(true); if (cc.grey.optimiseComponentTree) { - optimise(pe); - dumpExpression(pe, "opt", cc.grey); + optimise(pe); + dumpExpression(pe, "opt", cc.grey); } DEBUG_PRINTF("component=%p, nfaId=%u, reportId=%u\n", - pe.component.get(), pe.expr.index, pe.expr.report); + pe.component.get(), pe.expr.index, pe.expr.report); // You can only use the SOM flags if you've also specified an SOM // precision mode. - if (pe.expr.som != SOM_NONE && cc.streaming && !ng.ssm.somPrecision()) { + if (pe.expr.som != SOM_NONE && cc.streaming && !ng.ssm.somPrecision()) { throw CompileError("To use a SOM expression flag in streaming mode, " "an SOM precision mode (e.g. " "HS_MODE_SOM_HORIZON_LARGE) must be specified."); @@ -364,25 +364,25 @@ void addExpression(NG &ng, unsigned index, const char *expression, // If this expression is a literal, we can feed it directly to Rose rather // than building the NFA graph. - if (shortcutLiteral(ng, pe)) { + if (shortcutLiteral(ng, pe)) { DEBUG_PRINTF("took literal short cut\n"); return; } - auto built_expr = buildGraph(ng.rm, cc, pe); - if (!built_expr.g) { + auto built_expr = buildGraph(ng.rm, cc, pe); + if (!built_expr.g) { DEBUG_PRINTF("NFA build failed on ID %u, but no exception was " - "thrown.\n", pe.expr.report); + "thrown.\n", pe.expr.report); throw CompileError("Internal error."); } - if (!pe.expr.allow_vacuous && matches_everywhere(*built_expr.g)) { + if (!pe.expr.allow_vacuous && matches_everywhere(*built_expr.g)) { throw CompileError("Pattern matches empty buffer; use " "HS_FLAG_ALLOWEMPTY to enable support."); } - if (!ng.addGraph(built_expr.expr, std::move(built_expr.g))) { - DEBUG_PRINTF("NFA addGraph failed on ID %u.\n", pe.expr.report); + if (!ng.addGraph(built_expr.expr, std::move(built_expr.g))) { + DEBUG_PRINTF("NFA addGraph failed on ID %u.\n", pe.expr.report); throw CompileError("Error compiling expression."); } } @@ -430,7 +430,7 @@ void addLitExpression(NG &ng, unsigned index, const char *expression, } static -bytecode_ptr<RoseEngine> generateRoseEngine(NG &ng) { +bytecode_ptr<RoseEngine> generateRoseEngine(NG &ng) { const u32 minWidth = ng.minWidth.is_finite() ? verify_u32(ng.minWidth) : ROSE_BOUND_INF; auto rose = ng.rose->buildRose(minWidth); @@ -455,54 +455,54 @@ platform_t target_to_platform(const target_t &target_info) { if (!target_info.has_avx2()) { p |= HS_PLATFORM_NOAVX2; } - if (!target_info.has_avx512()) { - p |= HS_PLATFORM_NOAVX512; - } + if (!target_info.has_avx512()) { + p |= HS_PLATFORM_NOAVX512; + } if (!target_info.has_avx512vbmi()) { p |= HS_PLATFORM_NOAVX512VBMI; } return p; } -/** \brief Encapsulate the given bytecode (RoseEngine) in a newly-allocated - * \ref hs_database, ensuring that it is padded correctly to give cacheline - * alignment. */ -static -hs_database_t *dbCreate(const char *in_bytecode, size_t len, u64a platform) { - size_t db_len = sizeof(struct hs_database) + len; - DEBUG_PRINTF("db size %zu\n", db_len); - DEBUG_PRINTF("db platform %llx\n", platform); - - struct hs_database *db = (struct hs_database *)hs_database_alloc(db_len); - if (hs_check_alloc(db) != HS_SUCCESS) { - hs_database_free(db); - return nullptr; - } - - // So that none of our database is uninitialized - memset(db, 0, db_len); - - // we need to align things manually - size_t shift = (uintptr_t)db->bytes & 0x3f; - DEBUG_PRINTF("shift is %zu\n", shift); - - db->bytecode = offsetof(struct hs_database, bytes) - shift; - char *bytecode = (char *)db + db->bytecode; - assert(ISALIGNED_CL(bytecode)); - - db->magic = HS_DB_MAGIC; - db->version = HS_DB_VERSION; - db->length = len; - db->platform = platform; - - // Copy bytecode - memcpy(bytecode, in_bytecode, len); - - db->crc32 = Crc32c_ComputeBuf(0, bytecode, db->length); - return db; -} - - +/** \brief Encapsulate the given bytecode (RoseEngine) in a newly-allocated + * \ref hs_database, ensuring that it is padded correctly to give cacheline + * alignment. */ +static +hs_database_t *dbCreate(const char *in_bytecode, size_t len, u64a platform) { + size_t db_len = sizeof(struct hs_database) + len; + DEBUG_PRINTF("db size %zu\n", db_len); + DEBUG_PRINTF("db platform %llx\n", platform); + + struct hs_database *db = (struct hs_database *)hs_database_alloc(db_len); + if (hs_check_alloc(db) != HS_SUCCESS) { + hs_database_free(db); + return nullptr; + } + + // So that none of our database is uninitialized + memset(db, 0, db_len); + + // we need to align things manually + size_t shift = (uintptr_t)db->bytes & 0x3f; + DEBUG_PRINTF("shift is %zu\n", shift); + + db->bytecode = offsetof(struct hs_database, bytes) - shift; + char *bytecode = (char *)db + db->bytecode; + assert(ISALIGNED_CL(bytecode)); + + db->magic = HS_DB_MAGIC; + db->version = HS_DB_VERSION; + db->length = len; + db->platform = platform; + + // Copy bytecode + memcpy(bytecode, in_bytecode, len); + + db->crc32 = Crc32c_ComputeBuf(0, bytecode, db->length); + return db; +} + + struct hs_database *build(NG &ng, unsigned int *length, u8 pureFlag) { assert(length); @@ -513,7 +513,7 @@ struct hs_database *build(NG &ng, unsigned int *length, u8 pureFlag) { if (!rose) { throw CompileError("Unable to generate bytecode."); } - *length = rose.size(); + *length = rose.size(); if (!*length) { DEBUG_PRINTF("RoseEngine has zero length\n"); assert(0); @@ -594,42 +594,42 @@ bool isSupported(const Component &c) { } #endif -BuiltExpression buildGraph(ReportManager &rm, const CompileContext &cc, - const ParsedExpression &pe) { - assert(isSupported(*pe.component)); +BuiltExpression buildGraph(ReportManager &rm, const CompileContext &cc, + const ParsedExpression &pe) { + assert(isSupported(*pe.component)); - const auto builder = makeNFABuilder(rm, cc, pe); + const auto builder = makeNFABuilder(rm, cc, pe); assert(builder); // Set up START and ACCEPT states; retrieve the special states - const auto bs = makeGlushkovBuildState(*builder, pe.expr.prefilter); + const auto bs = makeGlushkovBuildState(*builder, pe.expr.prefilter); // Map position IDs to characters/components - pe.component->notePositions(*bs); + pe.component->notePositions(*bs); // Wire the start dotstar state to the firsts - connectInitialStates(*bs, pe); + connectInitialStates(*bs, pe); DEBUG_PRINTF("wire up body of expr\n"); // Build the rest of the FOLLOW set vector<PositionInfo> initials = {builder->getStartDotStar(), builder->getStart()}; - pe.component->buildFollowSet(*bs, initials); + pe.component->buildFollowSet(*bs, initials); // Wire the lasts to the accept state - connectFinalStates(*bs, pe); + connectFinalStates(*bs, pe); // Create our edges bs->buildEdges(); - BuiltExpression built_expr = builder->getGraph(); - assert(built_expr.g); + BuiltExpression built_expr = builder->getGraph(); + assert(built_expr.g); - dumpDotWrapper(*built_expr.g, built_expr.expr, "00_before_asserts", - cc.grey); - removeAssertVertices(rm, *built_expr.g, built_expr.expr); + dumpDotWrapper(*built_expr.g, built_expr.expr, "00_before_asserts", + cc.grey); + removeAssertVertices(rm, *built_expr.g, built_expr.expr); - return built_expr; + return built_expr; } } // namespace ue2 diff --git a/contrib/libs/hyperscan/src/compiler/compiler.h b/contrib/libs/hyperscan/src/compiler/compiler.h index b42cb1425b..36986faaae 100644 --- a/contrib/libs/hyperscan/src/compiler/compiler.h +++ b/contrib/libs/hyperscan/src/compiler/compiler.h @@ -35,9 +35,9 @@ #include "ue2common.h" #include "database.h" -#include "compiler/expression_info.h" +#include "compiler/expression_info.h" #include "parser/Component.h" -#include "util/noncopyable.h" +#include "util/noncopyable.h" #include "util/ue2string.h" #include <memory> @@ -51,21 +51,21 @@ struct CompileContext; struct Grey; struct target_t; class NG; -class NGHolder; +class NGHolder; class ReportManager; -/** \brief Class gathering together the pieces of a parsed expression. */ -class ParsedExpression : noncopyable { +/** \brief Class gathering together the pieces of a parsed expression. */ +class ParsedExpression : noncopyable { public: ParsedExpression(unsigned index, const char *expression, unsigned flags, - ReportID report, const hs_expr_ext *ext = nullptr); + ReportID report, const hs_expr_ext *ext = nullptr); - /** \brief Expression information (from flags, extparam etc) */ - ExpressionInfo expr; + /** \brief Expression information (from flags, extparam etc) */ + ExpressionInfo expr; - /** \brief Root node of parsed component tree. */ - std::unique_ptr<Component> component; -}; + /** \brief Root node of parsed component tree. */ + std::unique_ptr<Component> component; +}; /** \brief Class gathering together the pieces of a parsed lit-expression. */ @@ -83,16 +83,16 @@ public: ue2_literal lit; }; -/** - * \brief Class gathering together the pieces of an expression that has been - * built into an NFA graph. - */ -struct BuiltExpression { - /** \brief Expression information (from flags, extparam etc) */ - ExpressionInfo expr; +/** + * \brief Class gathering together the pieces of an expression that has been + * built into an NFA graph. + */ +struct BuiltExpression { + /** \brief Expression information (from flags, extparam etc) */ + ExpressionInfo expr; - /** \brief Built Glushkov NFA graph. */ - std::unique_ptr<NGHolder> g; + /** \brief Built Glushkov NFA graph. */ + std::unique_ptr<NGHolder> g; }; /** @@ -109,12 +109,12 @@ struct BuiltExpression { * @param ext * Struct containing extra parameters for this expression, or NULL if * none. - * @param report + * @param report * The identifier to associate with the expression; returned by engine on * match. */ void addExpression(NG &ng, unsigned index, const char *expression, - unsigned flags, const hs_expr_ext *ext, ReportID report); + unsigned flags, const hs_expr_ext *ext, ReportID report); void addLitExpression(NG &ng, unsigned index, const char *expression, unsigned flags, const hs_expr_ext *ext, ReportID id, @@ -148,8 +148,8 @@ struct hs_database *build(NG &ng, unsigned int *length, u8 pureFlag); * @return * nullptr on error. */ -BuiltExpression buildGraph(ReportManager &rm, const CompileContext &cc, - const ParsedExpression &expr); +BuiltExpression buildGraph(ReportManager &rm, const CompileContext &cc, + const ParsedExpression &expr); /** * Build a platform_t out of a target_t. diff --git a/contrib/libs/hyperscan/src/compiler/error.cpp b/contrib/libs/hyperscan/src/compiler/error.cpp index 07db98192d..23ab45c655 100644 --- a/contrib/libs/hyperscan/src/compiler/error.cpp +++ b/contrib/libs/hyperscan/src/compiler/error.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016, Intel Corporation + * Copyright (c) 2015-2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -42,7 +42,7 @@ using std::string; static const char failureNoMemory[] = "Unable to allocate memory."; static const char failureInternal[] = "Internal error."; -static const char failureBadAlloc[] = "Allocator returned misaligned memory."; +static const char failureBadAlloc[] = "Allocator returned misaligned memory."; extern const hs_compile_error_t hs_enomem = { const_cast<char *>(failureNoMemory), 0 @@ -50,9 +50,9 @@ extern const hs_compile_error_t hs_enomem = { extern const hs_compile_error_t hs_einternal = { const_cast<char *>(failureInternal), 0 }; -extern const hs_compile_error_t hs_badalloc = { - const_cast<char *>(failureBadAlloc), 0 -}; +extern const hs_compile_error_t hs_badalloc = { + const_cast<char *>(failureBadAlloc), 0 +}; namespace ue2 { @@ -60,18 +60,18 @@ hs_compile_error_t *generateCompileError(const string &err, int expression) { hs_compile_error_t *ret = (struct hs_compile_error *)hs_misc_alloc(sizeof(hs_compile_error_t)); if (ret) { - hs_error_t e = hs_check_alloc(ret); - if (e != HS_SUCCESS) { - hs_misc_free(ret); - return const_cast<hs_compile_error_t *>(&hs_badalloc); - } + hs_error_t e = hs_check_alloc(ret); + if (e != HS_SUCCESS) { + hs_misc_free(ret); + return const_cast<hs_compile_error_t *>(&hs_badalloc); + } char *msg = (char *)hs_misc_alloc(err.size() + 1); if (msg) { - e = hs_check_alloc(msg); - if (e != HS_SUCCESS) { - hs_misc_free(msg); - return const_cast<hs_compile_error_t *>(&hs_badalloc); - } + e = hs_check_alloc(msg); + if (e != HS_SUCCESS) { + hs_misc_free(msg); + return const_cast<hs_compile_error_t *>(&hs_badalloc); + } memcpy(msg, err.c_str(), err.size() + 1); ret->message = msg; } else { @@ -97,8 +97,8 @@ void freeCompileError(hs_compile_error_t *error) { if (!error) { return; } - if (error == &hs_enomem || error == &hs_einternal || - error == &hs_badalloc) { + if (error == &hs_enomem || error == &hs_einternal || + error == &hs_badalloc) { // These are not allocated. return; } diff --git a/contrib/libs/hyperscan/src/compiler/expression_info.h b/contrib/libs/hyperscan/src/compiler/expression_info.h index fefb3b58af..99ee740322 100644 --- a/contrib/libs/hyperscan/src/compiler/expression_info.h +++ b/contrib/libs/hyperscan/src/compiler/expression_info.h @@ -1,108 +1,108 @@ -/* +/* * Copyright (c) 2017-2018, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * \file - * \brief ExpressionInfo class for storing the properties of an expression. - */ - -#ifndef COMPILER_EXPRESSION_INFO_H -#define COMPILER_EXPRESSION_INFO_H - -#include "ue2common.h" -#include "som/som.h" - -namespace ue2 { - -/** \brief Properties of an expression. */ -class ExpressionInfo { -public: - ExpressionInfo(unsigned int index_in, bool allow_vacuous_in, - bool highlander_in, bool utf8_in, bool prefilter_in, - som_type som_in, ReportID report_in, u64a min_offset_in, - u64a max_offset_in, u64a min_length_in, u32 edit_distance_in, + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * \brief ExpressionInfo class for storing the properties of an expression. + */ + +#ifndef COMPILER_EXPRESSION_INFO_H +#define COMPILER_EXPRESSION_INFO_H + +#include "ue2common.h" +#include "som/som.h" + +namespace ue2 { + +/** \brief Properties of an expression. */ +class ExpressionInfo { +public: + ExpressionInfo(unsigned int index_in, bool allow_vacuous_in, + bool highlander_in, bool utf8_in, bool prefilter_in, + som_type som_in, ReportID report_in, u64a min_offset_in, + u64a max_offset_in, u64a min_length_in, u32 edit_distance_in, u32 hamm_distance_in, bool quiet_in) - : index(index_in), report(report_in), allow_vacuous(allow_vacuous_in), - highlander(highlander_in), utf8(utf8_in), prefilter(prefilter_in), - som(som_in), min_offset(min_offset_in), max_offset(max_offset_in), - min_length(min_length_in), edit_distance(edit_distance_in), + : index(index_in), report(report_in), allow_vacuous(allow_vacuous_in), + highlander(highlander_in), utf8(utf8_in), prefilter(prefilter_in), + som(som_in), min_offset(min_offset_in), max_offset(max_offset_in), + min_length(min_length_in), edit_distance(edit_distance_in), hamm_distance(hamm_distance_in), quiet(quiet_in) {} - - /** - * \brief Index of the expression represented by this graph. - * - * Used: - * - down the track in error handling; - * - for identifying parts of an expression in highlander mode. - */ - unsigned int index; - - /** \brief Report ID specified by the user. */ - ReportID report; - - /** \brief Vacuous pattern is allowed. (HS_FLAG_ALLOWEMPTY) */ - bool allow_vacuous; - - /** \brief "Highlander" (single match) pattern. (HS_FLAG_SINGLEMATCH) */ - bool highlander; - - /** \brief UTF-8 pattern. (HS_FLAG_UTF8) */ - bool utf8; - - /** \brief Prefiltering pattern. (HS_FLAG_PREFILTER) */ - bool prefilter; - - /** \brief Start-of-match type requested, or SOM_NONE. */ - som_type som; - - /** \brief Minimum match offset extended parameter. 0 if not used. */ - u64a min_offset; - - /** - * \brief Maximum match offset extended parameter. - * MAX_OFFSET if not used. - */ - u64a max_offset; - - /** \brief Minimum match length extended parameter. 0 if not used. */ - u64a min_length; - - /** - * \brief Approximate matching edit distance extended parameter. - * 0 if not used. - */ - u32 edit_distance; - u32 hamm_distance; + + /** + * \brief Index of the expression represented by this graph. + * + * Used: + * - down the track in error handling; + * - for identifying parts of an expression in highlander mode. + */ + unsigned int index; + + /** \brief Report ID specified by the user. */ + ReportID report; + + /** \brief Vacuous pattern is allowed. (HS_FLAG_ALLOWEMPTY) */ + bool allow_vacuous; + + /** \brief "Highlander" (single match) pattern. (HS_FLAG_SINGLEMATCH) */ + bool highlander; + + /** \brief UTF-8 pattern. (HS_FLAG_UTF8) */ + bool utf8; + + /** \brief Prefiltering pattern. (HS_FLAG_PREFILTER) */ + bool prefilter; + + /** \brief Start-of-match type requested, or SOM_NONE. */ + som_type som; + + /** \brief Minimum match offset extended parameter. 0 if not used. */ + u64a min_offset; + + /** + * \brief Maximum match offset extended parameter. + * MAX_OFFSET if not used. + */ + u64a max_offset; + + /** \brief Minimum match length extended parameter. 0 if not used. */ + u64a min_length; + + /** + * \brief Approximate matching edit distance extended parameter. + * 0 if not used. + */ + u32 edit_distance; + u32 hamm_distance; /** \brief Quiet on match. */ bool quiet; -}; - -} - -#endif // COMPILER_EXPRESSION_INFO_H +}; + +} + +#endif // COMPILER_EXPRESSION_INFO_H |