void MyChecker::check(const MatchFinder::MatchResult &Result) { const auto *Call = Result.Nodes.getNodeAs("myCall"); CheckerContext &Context = *Result.Context; // Get the current state. MyState currentState = Context.getState (); // Use the current state to update our analysis. // ... }
void PrintChecker::check(const MatchFinder::MatchResult &Result) { const auto *Call = Result.Nodes.getNodeAsThis code example shows how `CheckerContext.getState` can be used to get the current state of analysis. In this case, the `MyState` class is used to represent the current state of analysis, and it determines whether we should emit a warning message or not. Package library: Clang Static Analyzer("printfCall"); CheckerContext &Context = *Result.Context; // Check if warnings are enabled. if (!Context.getLangOpts().Warnings) return; // Get the current state. MyState currentState = Context.getState (); // Use the current state to determine if we should print a warning. if (currentState.shouldPrintWarning()) { Context.emitWarning("Print statement found"); } }