#include "src/trace_processor/perfetto_sql/engine/perfetto_sql_preprocessor.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/ext/base/flat_hash_map.h"
#include "perfetto/ext/base/status_or.h"
#include "perfetto/ext/base/string_utils.h"
#include "src/trace_processor/sqlite/sql_source.h"
#include "src/trace_processor/sqlite/sqlite_tokenizer.h"
#include "src/trace_processor/util/status_macros.h"
namespace perfetto::trace_processor {
namespace {
enum IntrinsicMacro { … };
IntrinsicMacro MacroNameToEnum(const std::string& macro_name) { … }
base::Status ErrorAtToken(const SqliteTokenizer& tokenizer,
const SqliteTokenizer::Token& token,
const char* error) { … }
struct InvocationArg { … };
base::StatusOr<InvocationArg> ParseMacroInvocationArg(
SqliteTokenizer& tokenizer,
SqliteTokenizer::Token& tok,
bool has_prev_args) { … }
base::StatusOr<std::optional<SqlSource>> ExecuteStringify(
const SqliteTokenizer& tokenizer,
const SqliteTokenizer::Token& name_token,
const std::vector<SqlSource>& args) { … }
void RewriteIntrinsicMacro(const std::string& macro_name,
std::optional<SqlSource>& res,
std::vector<SqlSource>& token_list,
SqliteTokenizer& tokenizer,
SqlSource::Rewriter& rewriter,
SqliteTokenizer::Token prev,
SqliteTokenizer::Token tok) { … }
}
PerfettoSqlPreprocessor::PerfettoSqlPreprocessor(
SqlSource source,
const base::FlatHashMap<std::string, Macro>& macros)
: … { … }
bool PerfettoSqlPreprocessor::NextStatement() { … }
base::StatusOr<SqlSource> PerfettoSqlPreprocessor::RewriteInternal(
const SqlSource& source,
const std::unordered_map<std::string, SqlSource>& arg_bindings) { … }
base::StatusOr<std::vector<SqlSource>> PerfettoSqlPreprocessor::ParseTokenList(
SqliteTokenizer& tokenizer,
SqliteTokenizer::Token& tok,
const std::unordered_map<std::string, SqlSource>& bindings) { … }
base::StatusOr<SqlSource> PerfettoSqlPreprocessor::ExecuteMacroInvocation(
const SqliteTokenizer& tokenizer,
const SqliteTokenizer::Token& name_token,
const std::string& macro_name,
std::vector<SqlSource> token_list) { … }
base::StatusOr<std::optional<SqlSource>>
PerfettoSqlPreprocessor::ExecuteTokenZipJoin(
const SqliteTokenizer& tokenizer,
const SqliteTokenizer::Token& name_token,
std::vector<SqlSource> token_list,
bool prefixed) { … }
base::StatusOr<std::optional<SqlSource>>
PerfettoSqlPreprocessor::ExecuteTokenApply(
const SqliteTokenizer& tokenizer,
const SqliteTokenizer::Token& name_token,
std::vector<SqlSource> token_list) { … }
base::StatusOr<std::optional<SqlSource>>
PerfettoSqlPreprocessor::ExecuteTokenMapJoin(
const SqliteTokenizer& tokenizer,
const SqliteTokenizer::Token& name_token,
std::vector<SqlSource> token_list) { … }
base::StatusOr<std::optional<SqlSource>>
PerfettoSqlPreprocessor::ExecuteTokenMapJoinWithCapture(
const SqliteTokenizer& tokenizer,
const SqliteTokenizer::Token& name_token,
std::vector<SqlSource> token_list) { … }
}