refactoring c++ with clang
TRANSCRIPT
![Page 1: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/1.jpg)
Refactoring C++ with Clang Or how to make C++ more fun than Java
Manuel Klimek - Google
![Page 2: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/2.jpg)
We care about...
![Page 3: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/3.jpg)
We care about...
● Performance
![Page 4: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/4.jpg)
We care about...
● Performance
● Productivity
![Page 5: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/5.jpg)
● Performance
● Productivity
● Fun
We care about...
![Page 6: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/6.jpg)
● Performance
● Productivity
● Fun
C++ gives us...
![Page 7: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/7.jpg)
● Performance ✓
● Productivity
● Fun
C++ gives us...
![Page 8: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/8.jpg)
● Performance ✓
● Productivity ✓
● Fun
C++ gives us...
![Page 9: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/9.jpg)
● Performance ✓
● Productivity ✓
● Fun ?
C++ gives us...
![Page 10: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/10.jpg)
Subject: [PATCH] Awesome new feature On Thu, March 8, 2011 PedanticGuy wrote:> On Wed, March 7, 2011 NewContributor wrote:> + void DoSomethingAwesome(Cats cats); ALL your methods are capitalized incorrectly...Please fix. Thx.
![Page 11: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/11.jpg)
C++ could be more fun...
![Page 12: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/12.jpg)
Tooling!
![Page 13: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/13.jpg)
Tooling!
![Page 14: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/14.jpg)
Tooling!
● Correct indentation
![Page 15: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/15.jpg)
Tooling!
● Correct indentation
● Fixing style violations
![Page 16: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/16.jpg)
Tooling!
● Correct indentation
● Fixing style violations
● Renaming variables
![Page 17: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/17.jpg)
Tooling!
● Correct indentation
● Fixing style violations
● Renaming variables
● Creating code structure
![Page 18: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/18.jpg)
Challenges...
![Page 19: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/19.jpg)
Challenges...
● X-TU
![Page 20: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/20.jpg)
Challenges...
● X-TU
● Workflow Integration
![Page 21: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/21.jpg)
Challenges...
● X-TU
● Workflow Integration ● Build Systems
![Page 22: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/22.jpg)
Challenges...
● X-TU
● Workflow Integration ● Build Systems
● Speed
![Page 23: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/23.jpg)
Tomorrowland
Clang
![Page 24: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/24.jpg)
Libraries
Tomorrowland
Clang
![Page 25: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/25.jpg)
Libraries
Tomorrowland
Clang
Tools
![Page 26: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/26.jpg)
Libraries
Tomorrowland
Clang
IDE'ish Services
Tools
![Page 27: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/27.jpg)
Libraries
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 28: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/28.jpg)
Libraries
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 29: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/29.jpg)
Libraries● Tooling
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 30: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/30.jpg)
Clang tooling layers
![Page 31: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/31.jpg)
Clang tooling layers
● Clang Plugins
![Page 32: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/32.jpg)
Clang tooling layers
● Clang Plugins
● libClang
![Page 33: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/33.jpg)
Clang tooling layers
● Clang Plugins
● libClang ● libTooling
![Page 34: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/34.jpg)
libTooling
● Run over a string
● Run over multiple files in a project
![Page 35: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/35.jpg)
bool RunToolOnCode( FrontendAction *ToolAction, Twine Code, Twine FileName);
![Page 36: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/36.jpg)
Libraries● Tooling
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 37: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/37.jpg)
Libraries● Tooling● Refactoring
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 38: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/38.jpg)
Hide ALL the complexity!
● Apply
● Deduplicated
● Edits
![Page 39: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/39.jpg)
Libraries● Tooling● Refactoring
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 40: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/40.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 41: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/41.jpg)
RAV Considered Complicated
Call(Callee(Method(HasName( "eat"))) eat();honey.eat();(*eat)();
![Page 42: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/42.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 43: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/43.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools
![Page 44: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/44.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools● clang-format
![Page 45: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/45.jpg)
The Whitespace Cure
● configurable
● boxable
● context sensitive
● correct
![Page 46: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/46.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools● clang-format
![Page 47: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/47.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools● clang-format● clang-lint
![Page 48: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/48.jpg)
Phoenix rising
● interactive automatic fixes
● configure patterns
● minimize false positives
![Page 49: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/49.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools● clang-format● clang-lint
![Page 50: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/50.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools● clang-format● clang-lint● clang-rename
![Page 51: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/51.jpg)
Common Code Transformations
● autonomous and integrated
● fast and correct
![Page 52: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/52.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools● clang-format● clang-lint● clang-rename
![Page 53: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/53.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish Services
Editor Integration
Tools● clang-format● clang-lint● clang-rename
![Page 54: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/54.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish ServicesClangD
Editor Integration
Tools● clang-format● clang-lint● clang-rename
![Page 55: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/55.jpg)
ClangD manages...
● dirty buffers
● caches parsing
● open RPC interface
● build system integration
![Page 56: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/56.jpg)
ClangD provides...
● fast context information
● complete code
● run actions
![Page 57: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/57.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish ServicesClangD
Editor Integration
Tools● clang-format● clang-lint● clang-rename
![Page 58: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/58.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish ServicesClangD
Editor Integration
Tools● clang-format● clang-lint● clang-rename
![Page 59: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/59.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish ServicesClangD
Editor Integration● Emacs● Vim● Eclipse
Tools● clang-format● clang-lint● clang-rename
![Page 60: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/60.jpg)
IDE everywhere
● command line
● emacs, vi
● integrate other IDEs
![Page 61: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/61.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish ServicesClangD
Editor Integration● Emacs● Vim● Eclipse
Tools● clang-format● clang-lint● clang-rename
![Page 62: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/62.jpg)
Libraries● Tooling● Refactoring● ASTMatchers
Tomorrowland
Clang
IDE'ish ServicesClangD
Editor Integration● Emacs● Vim● Eclipse
Tools● clang-format● clang-lint● clang-rename
![Page 63: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/63.jpg)
Where are we?
● Libraries... in progress.
● Tools... early spikes.
● ClangD... entering design phase.
● Editor integration...
![Page 64: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/64.jpg)
What's next?
You!
![Page 65: Refactoring C++ with Clang](https://reader033.vdocuments.mx/reader033/viewer/2022052300/586cae801a28ab3f528b4c09/html5/thumbnails/65.jpg)
ReferencesDiscussions, ideas:Bring them up on [email protected] Tooling Branch (beware, spiky)cfe/branches/tooling Clang MapReduce -- Automatic C++ Refactoring at Google Scalehttp://llvm.org/devmtg/2011-11/#talk2