blob: 760aecbdf23dee5a0ac879345fb9a13ea0db4b79 [file] [log] [blame]
sewardjd7a02db2008-12-12 08:07:49 +00001
2/*--------------------------------------------------------------------*/
3/*--- A simple sequence matching facility. ---*/
4/*--- pub_tool_seqmatch.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
10
Elliott Hughesed398002017-06-21 14:41:24 -070011 Copyright (C) 2008-2017 OpenWorks Ltd
sewardjd7a02db2008-12-12 08:07:49 +000012 info@open-works.co.uk
13
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.
18
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.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
32#ifndef __PUB_TOOL_SEQMATCH_H
33#define __PUB_TOOL_SEQMATCH_H
34
florian535fb1b2013-09-15 13:54:34 +000035#include "pub_tool_basics.h" // UWord
36
sewardjd7a02db2008-12-12 08:07:49 +000037/* Perform totally abstractified sequence matching, of an input
38 sequence against a pattern sequence. The pattern sequence may
39 include '*' elements (matches any number of anything) and '?'
40 elements (matches exactly one element). '*' patterns are matched
41 frugally, meaning that they are "assigned" the minimum amount of
42 input needed to make the match work.
43
44 This routine is recursive. The recursion depth is equal to the
45 number of '*' elements in the pattern. There is no guard against
46 excessive recursion. This function has no global state and so is
47 thread-safe and re-entrant. (It needs to be, since m_errormgr will
48 effectively construct two simultaneous calls to it, once to match
49 at the frame level, and whilst that is happening, once at the
50 function/object-name level.)
51
52 When matchAll is True, the entire input sequence must match the
53 pattern, else the match fails. When False, it's ok for some tail
54 of the input sequence to be unused -- so we're only matching a
55 prefix.
56
57 The pattern array is starts at 'patt' and consists of 'nPatt'
58 elements each of size 'szbPatt'. For the initial call, pass a
59 value of zero to 'ixPatt'.
60
philippea0a73932014-06-15 15:42:20 +000061 The input sequence can be similarly described using
62 input/nInput/szbInput/ixInput.
63 Alternatively, the input can be lazily constructed using an
64 inputCompleter. When using an inputCompleter, input/nInput/szbInput
65 are unused.
sewardjd7a02db2008-12-12 08:07:49 +000066
67 pIsStar should return True iff the pointed-to pattern element is
68 conceptually a '*'.
69
70 pIsQuery should return True iff the pointed-to-pattern element is
71 conceptually a '?'.
72
73 pattEQinp takes a pointer to a pattern element and a pointer to an
74 input element. It should return True iff they are considered
75 equal. Note that the pattern element is guaranteed to be neither
76 (conceptually) '*' nor '?', so it must be a literal (in the sense
77 that all the input sequence elements are literal).
philippe13a59522012-08-03 23:11:39 +000078
philippea0a73932014-06-15 15:42:20 +000079 If inputCompleter is not NULL, the input will be lazily constructed
80 when pattEQinp is called.
philippe13a59522012-08-03 23:11:39 +000081 For lazily constructing the input element, the two last arguments
82 of pattEQinp are the inputCompleter and the index of the input
83 element to complete.
philippea0a73932014-06-15 15:42:20 +000084 VG_(generic_match) calls (*haveInputInpC)(inputCompleter,ixInput) to
85 check if there is an element ixInput in the input sequence.
sewardjd7a02db2008-12-12 08:07:49 +000086*/
87Bool VG_(generic_match) (
88 Bool matchAll,
florian3e798632012-11-24 19:41:54 +000089 const void* patt, SizeT szbPatt, UWord nPatt, UWord ixPatt,
90 const void* input, SizeT szbInput, UWord nInput, UWord ixInput,
91 Bool (*pIsStar)(const void*),
92 Bool (*pIsQuery)(const void*),
93 Bool (*pattEQinp)(const void*,const void*,void*,UWord),
philippea0a73932014-06-15 15:42:20 +000094 void* inputCompleter,
95 Bool (*haveInputInpC)(void*,UWord)
sewardjd7a02db2008-12-12 08:07:49 +000096 );
97
98/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
99 meta-symbols '*' and '?'. There is no way to escape meta-symbols
100 in the pattern. */
florian19f91bb2012-11-10 22:29:54 +0000101Bool VG_(string_match) ( const HChar* pat, const HChar* str );
sewardjd7a02db2008-12-12 08:07:49 +0000102
103#endif // __PUB_TOOL_SEQMATCH_H
104
105/*--------------------------------------------------------------------*/
106/*--- end pub_tool_seqmatch.h ---*/
107/*--------------------------------------------------------------------*/