chromium/third_party/perfetto/src/trace_processor/sqlite/sqlite_tokenizer.cc

/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "src/trace_processor/sqlite/sqlite_tokenizer.h"

#include <ctype.h>
#include <sqlite3.h>
#include <cstdint>
#include <optional>
#include <string_view>

#include "perfetto/base/compiler.h"
#include "perfetto/base/logging.h"

namespace perfetto {
namespace trace_processor {

// The contents of this file are ~copied from SQLite with some modifications to
// minimize the amount copied: i.e. if we can call a libc function/public SQLite
// API instead of a private one.
//
// The changes are as follows:
// 1. Remove all ifdefs to only keep branches we actually use
// 2. Change handling of |CC_KYWD0| to remove distinction between different
//    SQLite kewords, reducing how many things we need to copy over.
// 3. Constants are changed from be macro defines to be values in
//    |SqliteTokenType|.

namespace {

const unsigned char sqlite3CtypeMap[256] =;

#define CC_X
#define CC_KYWD0
#define CC_KYWD
#define CC_DIGIT
#define CC_DOLLAR
#define CC_VARALPHA
#define CC_VARNUM
#define CC_SPACE
#define CC_QUOTE
#define CC_QUOTE2
#define CC_PIPE
#define CC_MINUS
#define CC_LT
#define CC_GT
#define CC_EQ
#define CC_BANG
#define CC_SLASH
#define CC_LP
#define CC_RP
#define CC_SEMI
#define CC_PLUS
#define CC_STAR
#define CC_PERCENT
#define CC_COMMA
#define CC_AND
#define CC_TILDA
#define CC_DOT
#define CC_ID
#define CC_NUL
#define CC_BOM

// clang-format off
static const unsigned char aiClass[] =;
// clang-format on

#define IdChar(C)

// Copy of |sqlite3GetToken| for use by the PerfettoSql transpiler.
//
// We copy this function because |sqlite3GetToken| is static to sqlite3.c
// in most distributions of SQLite so we cannot call it from our code.
//
// While we could redefine SQLITE_PRIVATE, pragmatically that will not fly in
// all the places we build trace processor so we need to resort to making a
// copy.
int GetSqliteToken(const unsigned char* z, SqliteTokenType* tokenType) {}

}  // namespace

SqliteTokenizer::SqliteTokenizer(SqlSource sql) :{}

SqliteTokenizer::Token SqliteTokenizer::Next() {}

SqliteTokenizer::Token SqliteTokenizer::NextNonWhitespace() {}

SqliteTokenizer::Token SqliteTokenizer::NextTerminal() {}

SqlSource SqliteTokenizer::Substr(const Token& start, const Token& end) const {}

SqlSource SqliteTokenizer::SubstrToken(const Token& token) const {}

std::string SqliteTokenizer::AsTraceback(const Token& token) const {}

void SqliteTokenizer::Rewrite(SqlSource::Rewriter& rewriter,
                              const Token& start,
                              const Token& end,
                              SqlSource rewrite,
                              EndToken end_token) const {}

void SqliteTokenizer::RewriteToken(SqlSource::Rewriter& rewriter,
                                   const Token& token,
                                   SqlSource rewrite) const {}

}  // namespace trace_processor
}  // namespace perfetto