chromium/third_party/skia/src/sksl/analysis/SkSLProgramVisitor.h

/*
 * Copyright 2021 Google LLC
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkSLProgramVisitor_DEFINED
#define SkSLProgramVisitor_DEFINED

#include <memory>

namespace SkSL {

struct Program;
class Expression;
class Statement;
class ProgramElement;

/**
 * Utility class to visit every element, statement, and expression in an SkSL program IR.
 * This is intended for simple analysis and accumulation, where custom visitation behavior is only
 * needed for a limited set of expression kinds.
 *
 * Subclasses should override visitExpression/visitStatement/visitProgramElement as needed and
 * intercept elements of interest. They can then invoke the base class's function to visit all
 * sub expressions. They can also choose not to call the base function to arrest recursion, or
 * implement custom recursion.
 *
 * The visit functions return a bool that determines how the default implementation recurses. Once
 * any visit call returns true, the default behavior stops recursing and propagates true up the
 * stack.
 */
template <typename T>
class TProgramVisitor {};

// ProgramVisitors take const types; ProgramWriters do not.
struct ProgramVisitorTypes {};

extern template class TProgramVisitor<ProgramVisitorTypes>;

class ProgramVisitor : public TProgramVisitor<ProgramVisitorTypes> {};

} // namespace SkSL

#endif