-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PerfettoSqlPreprocessor is currently responsible for tokenizing SQL statements and returning them to the parser. In a followup, it will also be reponsible for expanding macros which is why we bother making it a standalone component. Change-Id: Ib9aede77b8e410c87f085813a4a4bd56237d5fca
- Loading branch information
1 parent
a0e3185
commit 671c628
Showing
12 changed files
with
398 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/trace_processor/perfetto_sql/engine/perfetto_sql_preprocessor.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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/perfetto_sql/engine/perfetto_sql_preprocessor.h" | ||
#include <unordered_set> | ||
|
||
#include "perfetto/base/status.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 { | ||
namespace trace_processor { | ||
|
||
PerfettoSqlPreprocessor::PerfettoSqlPreprocessor(SqlSource source) | ||
: global_tokenizer_(std::move(source)) {} | ||
|
||
bool PerfettoSqlPreprocessor::NextStatement() { | ||
PERFETTO_CHECK(status_.ok()); | ||
|
||
// Skip through any number of semi-colons (representing empty statements). | ||
SqliteTokenizer::Token tok = global_tokenizer_.NextNonWhitespace(); | ||
while (tok.token_type == SqliteTokenType::TK_SEMI) { | ||
tok = global_tokenizer_.NextNonWhitespace(); | ||
} | ||
|
||
// If we still see a terminal token at this point, we must have hit EOF. | ||
if (tok.IsTerminal()) { | ||
PERFETTO_DCHECK(tok.token_type != SqliteTokenType::TK_SEMI); | ||
return false; | ||
} | ||
|
||
SqlSource stmt = | ||
global_tokenizer_.Substr(tok, global_tokenizer_.NextTerminal()); | ||
statement_ = std::move(stmt); | ||
return true; | ||
} | ||
|
||
base::Status PerfettoSqlPreprocessor::ErrorAtToken( | ||
const SqliteTokenizer& tokenizer, | ||
const SqliteTokenizer::Token& token, | ||
const char* error) { | ||
std::string traceback = tokenizer.AsTraceback(token); | ||
return base::ErrStatus("%s%s", traceback.c_str(), error); | ||
} | ||
|
||
} // namespace trace_processor | ||
} // namespace perfetto |
Oops, something went wrong.