CMakePM: Remove comment line lexer addition

This brings the lexer back to vanilla CMake version.

The comment arguments were not needed in the implementation of
source file addition / rename / removal operations.

Change-Id: If28b738b9ce93511b109fe09dcd03f42ee07a431
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Cristian Adam
2023-05-23 14:55:52 +02:00
parent b90600e674
commit 2f04f08611
6 changed files with 17 additions and 42 deletions

View File

@@ -75,8 +75,7 @@ bool cmListFileParser::Parse()
if (token->type == cmListFileLexer_Token_Space) { if (token->type == cmListFileLexer_Token_Space) {
} else if (token->type == cmListFileLexer_Token_Newline) { } else if (token->type == cmListFileLexer_Token_Newline) {
haveNewline = true; haveNewline = true;
} else if (token->type == cmListFileLexer_Token_CommentBracket } else if (token->type == cmListFileLexer_Token_CommentBracket) {
|| token->type == cmListFileLexer_Token_CommentLine) {
haveNewline = false; haveNewline = false;
} else if (token->type == cmListFileLexer_Token_Identifier) { } else if (token->type == cmListFileLexer_Token_Identifier) {
if (haveNewline) { if (haveNewline) {
@@ -187,11 +186,6 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
return false; return false;
} }
this->Separation = SeparationWarning; this->Separation = SeparationWarning;
} else if (token->type == cmListFileLexer_Token_CommentLine) {
if (!this->AddArgument(token, cmListFileArgument::Comment)) {
return false;
}
this->Separation = SeparationWarning;
} else if (token->type == cmListFileLexer_Token_ArgumentBracket) { } else if (token->type == cmListFileLexer_Token_ArgumentBracket) {
if (!this->AddArgument(token, cmListFileArgument::Bracket)) { if (!this->AddArgument(token, cmListFileArgument::Bracket)) {
return false; return false;

View File

@@ -22,8 +22,7 @@ struct cmListFileArgument
{ {
Unquoted, Unquoted,
Quoted, Quoted,
Bracket, Bracket
Comment
}; };
cmListFileArgument() = default; cmListFileArgument() = default;
cmListFileArgument(std::string v, Delimiter d, long line, long column) cmListFileArgument(std::string v, Delimiter d, long line, long column)

View File

@@ -755,7 +755,7 @@ This file must be translated to C and modified to build everywhere.
Run flex >= 2.6 like this: Run flex >= 2.6 like this:
flex --nounistd -DFLEXINT_H --noline -ocmListFileLexer.c cmListFileLexer.in.l flex --nounistd -DFLEXINT_H --noline -ocmListFileLexer.cxx cmListFileLexer.in.l
Modify cmListFileLexer.c: Modify cmListFileLexer.c:
- remove trailing whitespace: sed -i 's/\s*$//' cmListFileLexer.c - remove trailing whitespace: sed -i 's/\s*$//' cmListFileLexer.c
@@ -1172,10 +1172,7 @@ YY_RULE_SETUP
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
{ {
lexer->token.type = cmListFileLexer_Token_CommentLine;
cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1;
} }
YY_BREAK YY_BREAK
case 5: case 5:
@@ -2596,7 +2593,7 @@ static void cmListFileLexerAppend(cmListFileLexer* lexer, const char* text,
} }
/* We need to extend the buffer. */ /* We need to extend the buffer. */
temp = (char *) malloc(newSize); temp = (char *)malloc(newSize);
if (lexer->token.text) { if (lexer->token.text) {
memcpy(temp, lexer->token.text, lexer->token.length); memcpy(temp, lexer->token.text, lexer->token.length);
free(lexer->token.text); free(lexer->token.text);
@@ -2828,8 +2825,7 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
return "unterminated bracket"; return "unterminated bracket";
case cmListFileLexer_Token_BadString: case cmListFileLexer_Token_BadString:
return "unterminated string"; return "unterminated string";
case cmListFileLexer_Token_CommentLine:
return "line comment";
} }
return "unknown token"; return "unknown token";
} }

View File

@@ -21,8 +21,7 @@ typedef enum cmListFileLexer_Type_e
cmListFileLexer_Token_CommentBracket, cmListFileLexer_Token_CommentBracket,
cmListFileLexer_Token_BadCharacter, cmListFileLexer_Token_BadCharacter,
cmListFileLexer_Token_BadBracket, cmListFileLexer_Token_BadBracket,
cmListFileLexer_Token_BadString, cmListFileLexer_Token_BadString
cmListFileLexer_Token_CommentLine
} cmListFileLexer_Type; } cmListFileLexer_Type;
/* NOLINTNEXTLINE(modernize-use-using) */ /* NOLINTNEXTLINE(modernize-use-using) */

View File

@@ -110,10 +110,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
} }
<COMMENT>[^\0\n]* { <COMMENT>[^\0\n]* {
lexer->token.type = cmListFileLexer_Token_CommentLine;
cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1;
} }
\( { \( {
@@ -541,8 +538,6 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
return "unterminated bracket"; return "unterminated bracket";
case cmListFileLexer_Token_BadString: case cmListFileLexer_Token_BadString:
return "unterminated string"; return "unterminated string";
case cmListFileLexer_Token_CommentLine:
return "line comment";
} }
return "unknown token"; return "unknown token";
} }

View File

@@ -432,12 +432,11 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
for (const auto &func : {function, targetSourcesFunc, addQmlModuleFunc}) { for (const auto &func : {function, targetSourcesFunc, addQmlModuleFunc}) {
if (func == cmakeListFile.Functions.end()) if (func == cmakeListFile.Functions.end())
continue; continue;
auto filePathArgument auto filePathArgument = Utils::findOrDefault(func->Arguments(),
= Utils::findOrDefault(func->Arguments(), [file_name = fileName.toStdString()](
[file_name = fileName.toStdString()](const auto &arg) { const auto &arg) {
return arg.Delim != cmListFileArgument::Comment return arg.Value == file_name;
&& arg.Value == file_name; });
});
if (!filePathArgument.Value.empty()) { if (!filePathArgument.Value.empty()) {
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName}; return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
@@ -456,9 +455,7 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
const auto haveGlobbing = Utils::anyOf(func->Arguments(), const auto haveGlobbing = Utils::anyOf(func->Arguments(),
[globVariables](const auto &arg) { [globVariables](const auto &arg) {
return globVariables.contains(arg.Value) return globVariables.contains(arg.Value);
&& arg.Delim
!= cmListFileArgument::Comment;
}); });
if (haveGlobbing) { if (haveGlobbing) {
@@ -475,21 +472,16 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
})); }));
for (const auto &arg : func->Arguments()) { for (const auto &arg : func->Arguments()) {
if (arg.Delim == cmListFileArgument::Comment)
continue;
auto matchedFunctions = Utils::filtered(setFunctions, [arg](const auto &f) { auto matchedFunctions = Utils::filtered(setFunctions, [arg](const auto &f) {
return arg.Value == std::string("${") + f.Arguments()[0].Value + "}"; return arg.Value == std::string("${") + f.Arguments()[0].Value + "}";
}); });
for (const auto &f : matchedFunctions) { for (const auto &f : matchedFunctions) {
filePathArgument filePathArgument = Utils::findOrDefault(f.Arguments(),
= Utils::findOrDefault(f.Arguments(), [file_name = fileName.toStdString()](
[file_name = fileName.toStdString()]( const auto &arg) {
const auto &arg) { return arg.Value == file_name;
return arg.Delim != cmListFileArgument::Comment });
&& arg.Value == file_name;
});
if (!filePathArgument.Value.empty()) { if (!filePathArgument.Value.empty()) {
return ProjectFileArgumentPosition{filePathArgument, return ProjectFileArgumentPosition{filePathArgument,