10d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// Copyright 2009 The RE2 Authors. All Rights Reserved. 20d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// Use of this source code is governed by a BSD-style 30d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// license that can be found in the LICENSE file. 40d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 50d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin#include "util/test.h" 60d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin#include "re2/regexp.h" 70d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin#include "re2/walker-inl.h" 80d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 90d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkinnamespace re2 { 100d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 110d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// Null walker. For benchmarking the walker itself. 120d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 130d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkinclass NullWalker : public Regexp::Walker<bool> { 140d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin public: 150d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin NullWalker() { } 160d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin bool PostVisit(Regexp* re, bool parent_arg, bool pre_arg, 170d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin bool* child_args, int nchild_args); 180d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 190d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin bool ShortVisit(Regexp* re, bool a) { 200d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin // Should never be called: we use Walk not WalkExponential. 210d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin LOG(DFATAL) << "NullWalker::ShortVisit called"; 220d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin return a; 230d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin } 240d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 250d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin private: 260d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin DISALLOW_EVIL_CONSTRUCTORS(NullWalker); 270d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin}; 280d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 290d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// Called after visiting re's children. child_args contains the return 300d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// value from each of the children's PostVisits (i.e., whether each child 310d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// can match an empty string). Returns whether this clause can match an 320d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// empty string. 330d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkinbool NullWalker::PostVisit(Regexp* re, bool parent_arg, bool pre_arg, 340d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin bool* child_args, int nchild_args) { 350d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin return false; 360d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin} 370d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 380d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin// Returns whether re can match an empty string. 390d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkinvoid Regexp::NullWalk() { 400d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin NullWalker w; 410d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin w.Walk(this, false); 420d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin} 430d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin 440d4c52358a1af421705c54bd8a9fdd8a30558a2eAlexander Gutkin} // namespace re2 45