[PATCH] Allow predefined styles to define different options for different languages.

Alexander Kornienko alexfh at google.com
Tue Dec 10 03:32:00 PST 2013



================
Comment at: lib/Format/Format.cpp:87
@@ +86,3 @@
+    // When reading, read the language first, we need it for getPredefinedStyle.
+    IO.mapOptional("Language", Style.Language);
+
----------------
Daniel Jasper wrote:
> So, I don't understand the full flow of how the YAML parsing now works. Does this work correctly if "Language" is not the first field in a config file?
When writing, the order of IO.map* calls actually determines the order of the keys in the output file, but when in reading mode, this code works on a YAML document tree, so there's no dependency on the order of the keys. We need to read this first, as we use the value of Style.Language further on.

I've added a test, so this is actually verified.

================
Comment at: include/clang/Format/Format.h:356
@@ -350,2 +355,3 @@
 /// Returns \c true if the Style has been set.
-bool getPredefinedStyle(StringRef Name, FormatStyle *Style);
+bool getPredefinedStyle(FormatStyle::LanguageKind Language, StringRef Name,
+                        FormatStyle *Style);
----------------
Daniel Jasper wrote:
> I'd reverse the order of the first two parameters. Intuitively, I would always think that I want "this specific style for this specific language".
I hesitated whether to put the language first or second, so with your opinion in place, it's clear, which order is better ;)


http://llvm-reviews.chandlerc.com/D2364

BRANCH
  svn

ARCANIST PROJECT
  clang



More information about the cfe-commits mailing list