refactoring c++ with clang

65
Refactoring C++ with Clang Or how to make C++ more fun than Java Manuel Klimek - Google

Upload: doantram

Post on 04-Jan-2017

247 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Refactoring C++ with Clang

Refactoring C++ with Clang Or how to make C++ more fun than Java

Manuel Klimek - Google

Page 2: Refactoring C++ with Clang

We care about...

Page 3: Refactoring C++ with Clang

We care about...

● Performance

Page 4: Refactoring C++ with Clang

We care about...

● Performance

● Productivity

Page 5: Refactoring C++ with Clang

● Performance

● Productivity

● Fun

We care about...

Page 6: Refactoring C++ with Clang

● Performance

● Productivity

● Fun

C++ gives us...

Page 7: Refactoring C++ with Clang

● Performance ✓

● Productivity

● Fun

C++ gives us...

Page 8: Refactoring C++ with Clang

● Performance ✓

● Productivity ✓

● Fun

C++ gives us...

Page 9: Refactoring C++ with Clang

● Performance ✓

● Productivity ✓

● Fun ?

C++ gives us...

Page 10: Refactoring C++ with Clang

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

C++ could be more fun...

Page 12: Refactoring C++ with Clang

Tooling!

Page 13: Refactoring C++ with Clang

Tooling!

Page 14: Refactoring C++ with Clang

Tooling!

● Correct indentation

Page 15: Refactoring C++ with Clang

Tooling!

● Correct indentation

● Fixing style violations

Page 16: Refactoring C++ with Clang

Tooling!

● Correct indentation

● Fixing style violations

● Renaming variables

Page 17: Refactoring C++ with Clang

Tooling!

● Correct indentation

● Fixing style violations

● Renaming variables

● Creating code structure

Page 18: Refactoring C++ with Clang

Challenges...

Page 19: Refactoring C++ with Clang

Challenges...

● X-TU

Page 20: Refactoring C++ with Clang

Challenges...

● X-TU

● Workflow Integration

Page 21: Refactoring C++ with Clang

Challenges...

● X-TU

● Workflow Integration ● Build Systems

Page 22: Refactoring C++ with Clang

Challenges...

● X-TU

● Workflow Integration ● Build Systems

● Speed

Page 23: Refactoring C++ with Clang

Tomorrowland

Clang

Page 24: Refactoring C++ with Clang

Libraries

Tomorrowland

Clang

Page 25: Refactoring C++ with Clang

Libraries

Tomorrowland

Clang

Tools

Page 26: Refactoring C++ with Clang

Libraries

Tomorrowland

Clang

IDE'ish Services

Tools

Page 27: Refactoring C++ with Clang

Libraries

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 28: Refactoring C++ with Clang

Libraries

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 29: Refactoring C++ with Clang

Libraries● Tooling

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 30: Refactoring C++ with Clang

Clang tooling layers

Page 31: Refactoring C++ with Clang

Clang tooling layers

● Clang Plugins

Page 32: Refactoring C++ with Clang

Clang tooling layers

● Clang Plugins

● libClang

Page 33: Refactoring C++ with Clang

Clang tooling layers

● Clang Plugins

● libClang ● libTooling

Page 34: Refactoring C++ with Clang

libTooling

● Run over a string

● Run over multiple files in a project

Page 35: Refactoring C++ with Clang

bool RunToolOnCode( FrontendAction *ToolAction, Twine Code, Twine FileName);

Page 36: Refactoring C++ with Clang

Libraries● Tooling

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 37: Refactoring C++ with Clang

Libraries● Tooling● Refactoring

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 38: Refactoring C++ with Clang

Hide ALL the complexity!

● Apply

● Deduplicated

● Edits

Page 39: Refactoring C++ with Clang

Libraries● Tooling● Refactoring

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 40: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 41: Refactoring C++ with Clang

RAV Considered Complicated

Call(Callee(Method(HasName( "eat"))) eat();honey.eat();(*eat)();

Page 42: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 43: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools

Page 44: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools● clang-format

Page 45: Refactoring C++ with Clang

The Whitespace Cure

● configurable

● boxable

● context sensitive

● correct

Page 46: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools● clang-format

Page 47: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools● clang-format● clang-lint

Page 48: Refactoring C++ with Clang

Phoenix rising

● interactive automatic fixes

● configure patterns

● minimize false positives

Page 49: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools● clang-format● clang-lint

Page 50: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools● clang-format● clang-lint● clang-rename

Page 51: Refactoring C++ with Clang

Common Code Transformations

● autonomous and integrated

● fast and correct

Page 52: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools● clang-format● clang-lint● clang-rename

Page 53: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish Services

Editor Integration

Tools● clang-format● clang-lint● clang-rename

Page 54: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish ServicesClangD

Editor Integration

Tools● clang-format● clang-lint● clang-rename

Page 55: Refactoring C++ with Clang

ClangD manages...

● dirty buffers

● caches parsing

● open RPC interface

● build system integration

Page 56: Refactoring C++ with Clang

ClangD provides...

● fast context information

● complete code

● run actions

Page 57: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish ServicesClangD

Editor Integration

Tools● clang-format● clang-lint● clang-rename

Page 58: Refactoring C++ with Clang

Libraries● Tooling● Refactoring● ASTMatchers

Tomorrowland

Clang

IDE'ish ServicesClangD

Editor Integration

Tools● clang-format● clang-lint● clang-rename

Page 59: Refactoring C++ with Clang

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

IDE everywhere

● command line

● emacs, vi

● integrate other IDEs

Page 61: Refactoring C++ with Clang

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

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

Where are we?

● Libraries... in progress.

● Tools... early spikes.

● ClangD... entering design phase.

● Editor integration...

Page 64: Refactoring C++ with Clang

What's next?

You!

Page 65: Refactoring C++ with Clang

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