8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 16:43:03 +01:00

Changes post review to #8358 - thanks Artyom.

This commit is contained in:
Adriano dos Santos Fernandes 2025-01-12 14:37:54 -03:00
parent c20f37a6f1
commit d1b61224ee
3 changed files with 190 additions and 189 deletions

View File

@ -46,7 +46,7 @@ public:
std::string rawText; std::string rawText;
std::string processedText; std::string processedText;
std::string getProcessedString() const const std::string& getProcessedString() const
{ {
return type == FrontendLexer::Token::TYPE_STRING || type == FrontendLexer::Token::TYPE_META_STRING ? return type == FrontendLexer::Token::TYPE_STRING || type == FrontendLexer::Token::TYPE_META_STRING ?
processedText : rawText; processedText : rawText;

View File

@ -48,13 +48,14 @@ FrontendParser::AnyNode FrontendParser::internalParse()
const auto commandToken = lexer.getToken(); const auto commandToken = lexer.getToken();
if (commandToken.type == Token::TYPE_OTHER) if (commandToken.type != Token::TYPE_OTHER)
{ return InvalidNode();
const auto& command = commandToken.processedText; const auto& command = commandToken.processedText;
if (command == TOKEN_ADD) if (command == TOKEN_ADD)
{ {
if (const auto tableName = parseName()) if (auto tableName = parseName())
{ {
AddNode node; AddNode node;
node.tableName = std::move(tableName.value()); node.tableName = std::move(tableName.value());
@ -78,7 +79,7 @@ FrontendParser::AnyNode FrontendParser::internalParse()
if (command == TOKEN_BLOBDUMP) if (command == TOKEN_BLOBDUMP)
{ {
if (const auto file = parseFileName()) if (auto file = parseFileName())
{ {
node.file = std::move(file.value()); node.file = std::move(file.value());
@ -99,7 +100,7 @@ FrontendParser::AnyNode FrontendParser::internalParse()
do do
{ {
const auto token = lexer.getToken(); auto token = lexer.getToken();
if (token.type == Token::TYPE_EOF) if (token.type == Token::TYPE_EOF)
{ {
@ -122,17 +123,17 @@ FrontendParser::AnyNode FrontendParser::internalParse()
{ {
CopyNode node; CopyNode node;
if (const auto source = parseName()) if (auto source = parseName())
node.source = std::move(source.value()); node.source = std::move(source.value());
else else
return InvalidNode(); return InvalidNode();
if (const auto destination = parseName()) if (auto destination = parseName())
node.destination = std::move(destination.value()); node.destination = std::move(destination.value());
else else
return InvalidNode(); return InvalidNode();
if (const auto database = parseFileName()) if (auto database = parseFileName())
node.database = std::move(database.value()); node.database = std::move(database.value());
else else
return InvalidNode(); return InvalidNode();
@ -151,7 +152,7 @@ FrontendParser::AnyNode FrontendParser::internalParse()
do do
{ {
const auto token = lexer.getToken(); auto token = lexer.getToken();
if (token.type == Token::TYPE_EOF) if (token.type == Token::TYPE_EOF)
{ {
@ -199,7 +200,7 @@ FrontendParser::AnyNode FrontendParser::internalParse()
{ {
ExplainNode node; ExplainNode node;
if (const auto query = parseUtilEof()) if (auto query = parseUtilEof())
{ {
node.query = std::move(query.value()); node.query = std::move(query.value());
return node; return node;
@ -221,7 +222,7 @@ FrontendParser::AnyNode FrontendParser::internalParse()
} }
else if (command.length() >= 2 && TOKEN_INPUT.find(command) == 0) else if (command.length() >= 2 && TOKEN_INPUT.find(command) == 0)
{ {
if (const auto file = parseFileName()) if (auto file = parseFileName())
{ {
InputNode node; InputNode node;
node.file = std::move(file.value()); node.file = std::move(file.value());
@ -259,7 +260,6 @@ FrontendParser::AnyNode FrontendParser::internalParse()
if (const auto showNode = parseShow(); !std::holds_alternative<InvalidNode>(showNode)) if (const auto showNode = parseShow(); !std::holds_alternative<InvalidNode>(showNode))
return showNode; return showNode;
} }
}
return InvalidNode(); return InvalidNode();
} }
@ -389,7 +389,7 @@ FrontendParser::AnySetNode FrontendParser::parseSet()
return parsed.value(); return parsed.value();
} }
else if (text.length() >= 5 && std::string(TOKEN_TRANSACTION).find(text) == 0) else if (text.length() >= 5 && TOKEN_TRANSACTION.find(text) == 0)
{ {
SetTransactionNode node; SetTransactionNode node;
node.statement = lexer.getBuffer(); node.statement = lexer.getBuffer();
@ -434,7 +434,7 @@ std::optional<FrontendParser::AnySetNode> FrontendParser::parseSet(std::string_v
{ {
if (setCommand == testCommand || if (setCommand == testCommand ||
(testCommandMinLen && setCommand.length() >= testCommandMinLen && (testCommandMinLen && setCommand.length() >= testCommandMinLen &&
std::string(testCommand).find(setCommand) == 0)) testCommand.find(setCommand) == 0))
{ {
Node node; Node node;
@ -502,7 +502,7 @@ FrontendParser::AnyShowNode FrontendParser::parseShow()
return parsed.value(); return parsed.value();
else if (const auto parsed = parseShowOptName<ShowCollationsNode>(text, TOKEN_COLLATIONS, 9)) else if (const auto parsed = parseShowOptName<ShowCollationsNode>(text, TOKEN_COLLATIONS, 9))
return parsed.value(); return parsed.value();
else if (text.length() >= 7 && std::string(TOKEN_COMMENTS).find(text) == 0) else if (text.length() >= 7 && TOKEN_COMMENTS.find(text) == 0)
{ {
if (parseEof()) if (parseEof())
return ShowCommentsNode(); return ShowCommentsNode();
@ -522,7 +522,7 @@ FrontendParser::AnyShowNode FrontendParser::parseShow()
return parsed.value(); return parsed.value();
else if (const auto parsed = parseShowOptName<ShowFiltersNode>(text, TOKEN_FILTERS, 6)) else if (const auto parsed = parseShowOptName<ShowFiltersNode>(text, TOKEN_FILTERS, 6))
return parsed.value(); return parsed.value();
else if (text.length() >= 4 && std::string(TOKEN_FUNCTIONS).find(text) == 0) else if (text.length() >= 4 && TOKEN_FUNCTIONS.find(text) == 0)
{ {
ShowFunctionsNode node; ShowFunctionsNode node;
node.name = parseName(); node.name = parseName();
@ -558,7 +558,7 @@ FrontendParser::AnyShowNode FrontendParser::parseShow()
return parsed.value(); return parsed.value();
else if (const auto parsed = parseShowOptName<ShowPackagesNode>(text, TOKEN_PACKAGES, 4)) else if (const auto parsed = parseShowOptName<ShowPackagesNode>(text, TOKEN_PACKAGES, 4))
return parsed.value(); return parsed.value();
else if (text.length() >= 4 && std::string(TOKEN_PROCEDURES).find(text) == 0) else if (text.length() >= 4 && TOKEN_PROCEDURES.find(text) == 0)
{ {
ShowProceduresNode node; ShowProceduresNode node;
node.name = parseName(); node.name = parseName();
@ -586,7 +586,7 @@ FrontendParser::AnyShowNode FrontendParser::parseShow()
return parsed.value(); return parsed.value();
else if (const auto parsed = parseShowOptName<ShowRolesNode>(text, TOKEN_ROLES, 4)) else if (const auto parsed = parseShowOptName<ShowRolesNode>(text, TOKEN_ROLES, 4))
return parsed.value(); return parsed.value();
else if (text.length() >= 6 && std::string(TOKEN_SECCLASSES).find(text) == 0) else if (text.length() >= 6 && TOKEN_SECCLASSES.find(text) == 0)
{ {
const auto lexerPos = lexer.getPos(); const auto lexerPos = lexer.getPos();
const auto token = lexer.getNameToken(); const auto token = lexer.getNameToken();
@ -622,7 +622,7 @@ FrontendParser::AnyShowNode FrontendParser::parseShow()
return ShowSqlDialectNode(); return ShowSqlDialectNode();
} }
} }
else if (text.length() >= 3 && std::string(TOKEN_SYSTEM).find(text) == 0) else if (text.length() >= 3 && TOKEN_SYSTEM.find(text) == 0)
{ {
ShowSystemNode node; ShowSystemNode node;
@ -630,22 +630,22 @@ FrontendParser::AnyShowNode FrontendParser::parseShow()
{ {
const auto objectTypeText = std::string(objectType->c_str()); const auto objectTypeText = std::string(objectType->c_str());
if ((objectTypeText.length() >= 7 && std::string(TOKEN_COLLATES).find(objectTypeText) == 0) || if ((objectTypeText.length() >= 7 && TOKEN_COLLATES.find(objectTypeText) == 0) ||
(objectTypeText.length() >= 9 && std::string(TOKEN_COLLATIONS).find(objectTypeText) == 0)) (objectTypeText.length() >= 9 && TOKEN_COLLATIONS.find(objectTypeText) == 0))
{ {
node.objType = obj_collation; node.objType = obj_collation;
} }
else if (objectTypeText.length() >= 4 && std::string(TOKEN_FUNCTIONS).find(objectTypeText) == 0) else if (objectTypeText.length() >= 4 && TOKEN_FUNCTIONS.find(objectTypeText) == 0)
node.objType = obj_udf; node.objType = obj_udf;
else if (objectTypeText.length() >= 5 && std::string(TOKEN_TABLES).find(objectTypeText) == 0) else if (objectTypeText.length() >= 5 && TOKEN_TABLES.find(objectTypeText) == 0)
node.objType = obj_relation; node.objType = obj_relation;
else if (objectTypeText.length() >= 4 && std::string(TOKEN_ROLES).find(objectTypeText) == 0) else if (objectTypeText.length() >= 4 && TOKEN_ROLES.find(objectTypeText) == 0)
node.objType = obj_sql_role; node.objType = obj_sql_role;
else if (objectTypeText.length() >= 4 && std::string(TOKEN_PROCEDURES).find(objectTypeText) == 0) else if (objectTypeText.length() >= 4 && TOKEN_PROCEDURES.find(objectTypeText) == 0)
node.objType = obj_procedure; node.objType = obj_procedure;
else if (objectTypeText.length() >= 4 && std::string(TOKEN_PACKAGES).find(objectTypeText) == 0) else if (objectTypeText.length() >= 4 && TOKEN_PACKAGES.find(objectTypeText) == 0)
node.objType = obj_package_header; node.objType = obj_package_header;
else if (objectTypeText.length() >= 3 && std::string(TOKEN_PUBLICATIONS).find(objectTypeText) == 0) else if (objectTypeText.length() >= 3 && TOKEN_PUBLICATIONS.find(objectTypeText) == 0)
node.objType = obj_publication; node.objType = obj_publication;
else else
return InvalidNode(); return InvalidNode();
@ -672,7 +672,7 @@ FrontendParser::AnyShowNode FrontendParser::parseShow()
} }
else if (const auto parsed = parseShowOptName<ShowViewsNode>(text, TOKEN_VIEWS, 4)) else if (const auto parsed = parseShowOptName<ShowViewsNode>(text, TOKEN_VIEWS, 4))
return parsed.value(); return parsed.value();
else if (text.length() >= 9 && std::string(TOKEN_WIRE_STATISTICS).find(text) == 0 || else if (text.length() >= 9 && TOKEN_WIRE_STATISTICS.find(text) == 0 ||
text == TOKEN_WIRE_STATS) text == TOKEN_WIRE_STATS)
{ {
if (parseEof()) if (parseEof())
@ -692,7 +692,7 @@ std::optional<FrontendParser::AnyShowNode> FrontendParser::parseShowOptName(std:
{ {
if (showCommand == testCommand || if (showCommand == testCommand ||
(testCommandMinLen && showCommand.length() >= testCommandMinLen && (testCommandMinLen && showCommand.length() >= testCommandMinLen &&
std::string(testCommand).find(showCommand) == 0)) testCommand.find(showCommand) == 0))
{ {
Node node; Node node;
node.name = parseName(); node.name = parseName();
@ -708,8 +708,8 @@ std::optional<FrontendParser::AnyShowNode> FrontendParser::parseShowOptName(std:
std::optional<std::string> FrontendParser::parseUtilEof() std::optional<std::string> FrontendParser::parseUtilEof()
{ {
const auto startPos = lexer.getPos(); const auto startIt = lexer.getPos();
auto lastPos = startPos; auto lastPosIt = startIt;
bool first = true; bool first = true;
do do
@ -721,10 +721,10 @@ std::optional<std::string> FrontendParser::parseUtilEof()
if (first) if (first)
return std::nullopt; return std::nullopt;
return FrontendLexer::trim(std::string(startPos, lastPos)); return FrontendLexer::trim(std::string(startIt, lastPosIt));
} }
lastPos = lexer.getPos(); lastPosIt = lexer.getPos();
first = false; first = false;
} while (true); } while (true);

View File

@ -210,13 +210,14 @@ public:
template <typename> template <typename>
static inline constexpr bool AlwaysFalseV = false; static inline constexpr bool AlwaysFalseV = false;
public: private:
FrontendParser(std::string_view statement, const Options& aOptions) FrontendParser(std::string_view statement, const Options& aOptions)
: lexer(statement), : lexer(statement),
options(aOptions) options(aOptions)
{ {
} }
public:
FrontendParser(const FrontendParser&) = delete; FrontendParser(const FrontendParser&) = delete;
FrontendParser& operator=(const FrontendParser&) = delete; FrontendParser& operator=(const FrontendParser&) = delete;