This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add a Lexer util to get the source text of a statement
AbandonedPublic

Authored by tbourvon on Jan 28 2018, 10:49 AM.

Details

Summary

This is a simple Lexer util to get the source text of a statement given as parameter. This is needed for D37014.

Diff Detail

Event Timeline

tbourvon created this revision.Jan 28 2018, 10:49 AM
lebedev.ri set the repository for this revision to rCTE Clang Tools Extra.
aaron.ballman added inline comments.Jan 29 2018, 5:11 AM
clang-tidy/utils/LexerUtils.cpp
39

You should elide the curly braces here.

44

Please don't use auto here, as the type is not spelled out in the initialization.

clang-tidy/utils/LexerUtils.h
26

Formatting (elsewhere as well).

You should run the patch under clang-format to handle this sort of thing.

unittests/clang-tidy/LexerUtilsTest.cpp
31

Don't use auto unless the type is spelled out in the init, such as with dyn_cast

34–35

Can FooLookup.front() actually be null? I think this should use cast<> and assert if given null or something other than a FunctionDecl.

37–38

I think you can use cast<> here instead of dyn_cast_or_null<>, and it will assert for you if the body isn't valid.

43

Spurious newline.

alexfh requested changes to this revision.Jan 31 2018, 1:42 PM
alexfh added inline comments.
clang-tidy/utils/LexerUtils.h
26

Have you seen clang::tooling::fixit::getText? It should cover this use case.

This revision now requires changes to proceed.Jan 31 2018, 1:42 PM
tbourvon abandoned this revision.Feb 13 2018, 6:26 AM
tbourvon added inline comments.
clang-tidy/utils/LexerUtils.h
26

Hadn't seen that! Seems to be making this whole patch obsolete, I'm closing it