Upgrade to Pro — share decks privately, control downloads, hide ads and more …

clangのtoolを直接叩いてiOSアプリ開発をパワーアップ!

tokorom
March 12, 2014

 clangのtoolを直接叩いてiOSアプリ開発をパワーアップ!

clang-formatとかclang-checkをiOSアプリ開発(Objective-C)でも使ってみようという話。

tokorom

March 12, 2014
Tweet

More Decks by tokorom

Other Decks in Technology

Transcript

  1. clangͷtoolΛ௚઀ୟ͍ͯ iOSΞϓϦ։ൃΛύϫʔΞοϓʂ ॴ ༑ଠ @tokorom iOS App Programer These are

    “not” confidential sessions—please diffuse by your blogging and twitter potatotips #5
  2. clangͱ͸ʁ • γʔϥϯά͡Όͳͯ͘ Ϋϥϯ (ˈklæŋ) •ϓϩάϥϛϯάݴޠ CɺC++ɺObjective-Cɺ Objective-C++ ޲͚ͷίϯύΠϥϑϩϯτΤϯυ ྆ํͱ΋WikipediaΑΓ

  3. ࠓ೔঺հ͢Δͷ͸ • ίʔυϑΥʔϚολʔʢclang-formatʣ • γϯλοΫενΣοΫʢclang-checkͱ͔ʣ • ͕࣌ؒ͋Ε͹ ιʔείʔυิ׬ʢclang -code- completion-atʣ΋΍Γ͔͚ͨͬͨͲ·ͨࠓ౓

  4. ίʔυϑΥʔϚολʔʢclang-format)

  5. clang-format

  6. Uncrustifyͱͷൺֱ clang-format Uncrustify Πϯετʔϧ × େม ˕ ௒؆୯ ઃఆ߲໨ ˚

    ͬ͘͟Γ ◦ ࡉ͔͍ ߦࢦఆ ˕ Ͱ͖Δ × Ͱ͖ͳ͍ʢͨͿΜʣ ެࣜ౓ ˕ clangͦͷ·· -
  7. ΫοΫύουͰ͸clang-formatΛ࠾༻ • ͲͪΒ΋ࡉ͔͘ઃఆͨ͠ͱ͜ΖͰ100%ࢥ͍௨Γ ʹ͸ͳΒͳ͍ʢͲΜ͙Γͷഎൺ΂ʣ • clangͷtoolͰ͋Δͱ͍͏҆৺ײ • ಛఆͷߦ͚ͩͷϑΥʔϚοτ͕Ͱ͖Δ

  8. Πϯετʔϧ •http://blog.hardcodes.de/articles/63/building- clang-format-and-friends-on-osx-mountain-lion •ͱʹ͔͘makeʹ͕͔͔࣌ؒΓ·͢

  9. Xcodeͳਓ͸ • ClangFormat-Xcode ͱ͍͏plugin͕࢖͑·͢ https://github.com/travisjeffery/ClangFormat-Xcode

  10. Vimͳਓ͸ • vim-clang-format ͱ͍͏plugin͕࢖͑·͢ https://github.com/rhysd/vim-clang-format •prefixΩʔΛࣗ༝ʹઃఆͰ͖ΔͷͰVimͷඪ४ͷ ϑΥʔϚοτ༻Ωʔʮ=ʯͰϑΥʔϚοτ΋Մೳ •ʮ==ʯͰݱࡏߦ͚ͩϑΥʔϚοτͱ͔ɺϏϡ δϡΞϧϞʔυͰબ୒ͨ͠ߦ͚ͩʮ=ʯͰϑΥʔ Ϛοτͱ͔

  11. γϯλοΫενΣοΫ

  12. clang-check $ clang-check hello.m -- ! hello.m:12:5: error: unknown type

    name 'MSString'; did you mean 'NSString'? MSString *string1 = nil; ^~~~~~~~ NSString /System/Library/Frameworks/Foundation.framework/Headers/ NSXPCConnection.h:13:29: note: 'NSString' declared here @class NSMutableDictionary, NSString, NSOperationQueue, NSSet, …; ^ 1 error generated. Error while processing /Users/ytokoro/develop/objc/hello.m.
  13. XcodeͷϓϩδΣΫτ಺ͷϑΝΠϧͷ৔߹… $ clang -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics- show-note-include-stack

    -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=/Users/ytokoro/Library/Developer/Xcode/ DerivedData/ModuleCache -Wno-trigraphs -fpascal-strings -O0 -Wno- missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage - Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of- weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses - Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter - Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno- unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion - Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum- conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno- selector -Wno-strict-selector-match -Wundeclared-selector -Wno- deprecated-implementations -DDEBUG=1 -isysroot /Applications/Xcode.app/ Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/ iPhoneSimulator7.0.sdk -fexceptions -fasm-blocks -fstrict-aliasing - Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi- version=2 -fobjc-legacy-dispatch -mios-simulator-version-min=7.0 - iquote /Users/ytokoro/Library/Developer/Xcode/DerivedData/
  14. XcodeͷϓϩδΣΫτ಺ͷϑΝΠϧͷ৔߹… •ݱ࣮తͳܗͰclang-checkʹ౉͢ΦϓγϣϯΛಋ ग़͢Δज़͕·ͩΘ͔͍ͬͯͳ͍ •clang-check࢖͍͍ͨͷʹͩΕ͔ϔϧϓʂ

  15. clang-check͕͏·͘࢖͑ΔΑ͏ʹͳͬͨΒ •Vim΍EmacsͰ΋XcodeόϦͷγϯλοΫε νΣοΫ/੩తղੳ͕؆୯ʹͰ͖ΔΑ͏ʹͳΔ •ίʔυΛॻ͍͍ͯΔ࠷தʹඇಉظʹγϯλοΫ ενΣοΫͯ͠هड़ϛεΛഁઢͰ໌ࣔͱ͔ • Vimͳਓ͸ vim-watchdogs ͱ͍͏plugin͔Βݺͼ ग़͢ͱ͍͍͔Μ͡ʹͳΓͦ͏

    https://github.com/osyo-manga/vim-watchdogs
  16. ࠓ͸ xcodebuild Ͱ୅༻͍ͯ͠·͢

  17. ݱࡏͷ΅͘ͷνΣοΫ؀ڥ •vim-watchdogs ܦ༝Ͱ xcodebuild Λఆظతʹୟ ͍ͯɺίϯύΠϧΤϥʔ͕͋Ε͹Τϥʔ಺༰Λ QuickFixͰදࣔ • .vimrc ͷઃఆ͸͜ͷ͋ͨΓ

    https://github.com/tokorom/dotfiles/blob/ master/.vimrc#L592-L604
  18. More Information Yuta ToKoRo! iOS App Programer! @tokorom! ! http://www.tokoro.me/