This is an archive of the discontinued LLVM Phabricator instance.

[clang][lex] Expose findBeginningOfLine()
AcceptedPublic

Authored by KyleFromKitware on Feb 1 2023, 12:10 PM.

Details

Reviewers
cor3ntin
tahonermann
Group Reviewers
Restricted Project
Summary

And fix a few corner cases in which it returns the wrong answer.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 12:10 PM
KyleFromKitware requested review of this revision.Feb 1 2023, 12:10 PM

Fixed formatting.

cor3ntin accepted this revision.Feb 1 2023, 11:47 PM

LGTM except the duplicated comment

clang/lib/Lex/Lexer.cpp
493–494

Should we remove the comment here?

This revision is now accepted and ready to land.Feb 1 2023, 11:47 PM
KyleFromKitware added inline comments.Feb 2 2023, 5:37 AM
clang/lib/Lex/Lexer.cpp
493–494

Other Lexer methods follow a similar pattern of having doc comments both in the header and in the implementation. I think we can leave it.

@KyleFromKitware oups, this fell under the cracks. I think I'm happy with is as-is, do you need help landing it?

@KyleFromKitware oups, this fell under the cracks. I think I'm happy with is as-is, do you need help landing it?

Yes, please.

@KyleFromKitware oups, this fell under the cracks. I think I'm happy with is as-is, do you need help landing it?

Yes, please.

Sure. Let me know what name and email address you would like used for the patch attribution! Thanks

Sure. Let me know what name and email address you would like used for the patch attribution! Thanks

Kyle Edwards <kyle.edwards@kitware.com>

Is there some way I can set this in my profile settings so that this name and address is always used?

Sorry for the delayed response. I managed to miss seeing this review request.

clang/include/clang/Lex/Lexer.h
598–599
clang/lib/Lex/Lexer.cpp
493–494
clang/unittests/Lex/LexerTest.cpp
673

I find this case interesting. I'm assuming it is intentional that an offset that corresponds to an EOL character indicates that the offset of the character following it be returned. That suggests some additional cases to test:

EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n\n", 12), 13);
EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n", 12), 13);  // 13? Or perhaps invalid?

My intuition is that an offset corresponding to an EOL character would result in the offset of the line containing the EOL character being returned.

clang/unittests/Lex/LexerTest.cpp
673

I did my best to preserve the existing behavior of the function while fixing a corner case that was obviously wrong. Should this be fixed as well?

KyleFromKitware marked an inline comment as not done.Mar 30 2023, 10:19 AM
cor3ntin added inline comments.Mar 30 2023, 10:42 AM
clang/unittests/Lex/LexerTest.cpp
673

@KyleFromKitware Try to fix it. If it doesn't cause test failures, i think we can do it as part of this PR. It it has wider ramifications we'll see.
But I agree with Tom that logically new lines should be part of the line they appear in rather than the next.