core: Pass stack change user requests on to tools
[valgrind.git] / include / pub_tool_seqmatch.h
blobd3302ddb7ccf58d0e3b306ddb0b9c9b3846aab59
2 /*--------------------------------------------------------------------*/
3 /*--- A simple sequence matching facility. ---*/
4 /*--- pub_tool_seqmatch.h ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2008-2017 OpenWorks Ltd
12 info@open-works.co.uk
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
30 #ifndef __PUB_TOOL_SEQMATCH_H
31 #define __PUB_TOOL_SEQMATCH_H
33 #include "pub_tool_basics.h" // UWord
35 /* Perform totally abstractified sequence matching, of an input
36 sequence against a pattern sequence. The pattern sequence may
37 include '*' elements (matches any number of anything) and '?'
38 elements (matches exactly one element). '*' patterns are matched
39 frugally, meaning that they are "assigned" the minimum amount of
40 input needed to make the match work.
42 This routine is recursive. The recursion depth is equal to the
43 number of '*' elements in the pattern. There is no guard against
44 excessive recursion. This function has no global state and so is
45 thread-safe and re-entrant. (It needs to be, since m_errormgr will
46 effectively construct two simultaneous calls to it, once to match
47 at the frame level, and whilst that is happening, once at the
48 function/object-name level.)
50 When matchAll is True, the entire input sequence must match the
51 pattern, else the match fails. When False, it's ok for some tail
52 of the input sequence to be unused -- so we're only matching a
53 prefix.
55 The pattern array is starts at 'patt' and consists of 'nPatt'
56 elements each of size 'szbPatt'. For the initial call, pass a
57 value of zero to 'ixPatt'.
59 The input sequence can be similarly described using
60 input/nInput/szbInput/ixInput.
61 Alternatively, the input can be lazily constructed using an
62 inputCompleter. When using an inputCompleter, input/nInput/szbInput
63 are unused.
65 pIsStar should return True iff the pointed-to pattern element is
66 conceptually a '*'.
68 pIsQuery should return True iff the pointed-to-pattern element is
69 conceptually a '?'.
71 pattEQinp takes a pointer to a pattern element and a pointer to an
72 input element. It should return True iff they are considered
73 equal. Note that the pattern element is guaranteed to be neither
74 (conceptually) '*' nor '?', so it must be a literal (in the sense
75 that all the input sequence elements are literal).
77 If inputCompleter is not NULL, the input will be lazily constructed
78 when pattEQinp is called.
79 For lazily constructing the input element, the two last arguments
80 of pattEQinp are the inputCompleter and the index of the input
81 element to complete.
82 VG_(generic_match) calls (*haveInputInpC)(inputCompleter,ixInput) to
83 check if there is an element ixInput in the input sequence.
85 Bool VG_(generic_match) (
86 Bool matchAll,
87 const void* patt, SizeT szbPatt, UWord nPatt, UWord ixPatt,
88 const void* input, SizeT szbInput, UWord nInput, UWord ixInput,
89 Bool (*pIsStar)(const void*),
90 Bool (*pIsQuery)(const void*),
91 Bool (*pattEQinp)(const void*,const void*,void*,UWord),
92 void* inputCompleter,
93 Bool (*haveInputInpC)(void*,UWord)
96 /* Mini-regexp function. Searches for 'pat' in 'str'. Supports
97 meta-symbols '*' and '?'. There is no way to escape meta-symbols
98 in the pattern. */
99 Bool VG_(string_match) ( const HChar* pat, const HChar* str );
101 #endif // __PUB_TOOL_SEQMATCH_H
103 /*--------------------------------------------------------------------*/
104 /*--- end pub_tool_seqmatch.h ---*/
105 /*--------------------------------------------------------------------*/