[PATCH] D58404: [clang-format] Add basic support for formatting C# files

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 21 03:06:11 PDT 2019


MyDeveloperDay updated this revision to Diff 191649.
MyDeveloperDay added a comment.

Addressing Review Comments

- Remove all non Format only code (i.e. changes to clang/Basic and clang/Lexer to support verbatim interpolated strings C# 6)
- For the most part the need to for them is removed by merging of tokens during the FormatLexer phase
- There is one obscure failure scenario, but for a first pass I think it can be ignored (tests commented out) where a `\` is used unescaped just before a `"` (because of paths can be more common than you think)
  - `string s = @"ABC\" + ToString("B");";`

    In this case, the string `@"ABC\"` is seen as `@"ABC\" + ToString("`, clang-format then gets confused about where it should put spaces and we end up with
  - `string s = @"ABC\" + ToString(" B ");";`

  AnnotatedTokens(L=0):
   M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=6 PPK=2 FakeLParens=2/ FakeRParens=0 II=0x252fbe52028 Text='string'
   M=0 C=1 T=StartOfName S=1 B=0 BK=0 P=220 Name=identifier L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x252fbe522d0 Text='s'
   M=0 C=0 T=BinaryOperator S=1 B=0 BK=0 P=22 Name=equal L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='='
   M=0 C=1 T=Unknown S=1 B=0 BK=0 P=22 Name=string_literal L=31 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='@"ABC\" + ToString("'
   M=0 C=0 T=Unknown S=1 B=0 BK=0 P=23 Name=identifier L=33 PPK=2 FakeLParens= FakeRParens=0 II=0x252fbe52300 Text='B'
   M=0 C=1 T=Unknown S=1 B=0 BK=0 P=23 Name=string_literal L=38 PPK=2 FakeLParens= FakeRParens=1 II=0x0 Text='");"'
   M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=39 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'



     


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58404/new/

https://reviews.llvm.org/D58404

Files:
  clang/docs/ClangFormat.rst
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTestCSharp.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58404.191649.patch
Type: text/x-patch
Size: 34076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190321/40da4289/attachment-0001.bin>


More information about the cfe-commits mailing list