Lines Matching refs:Style
183 static void mapping(IO &IO, FormatStyle &Style) {
185 IO.mapOptional("Language", Style.Language);
194 if (getPredefinedStyle(StyleName, Style.Language, &PredefinedStyle) &&
195 Style == PredefinedStyle) {
204 FormatStyle::LanguageKind OldLanguage = Style.Language;
207 if (!getPredefinedStyle(BasedOnStyle, Language, &Style)) {
211 Style.Language = OldLanguage;
217 IO.mapOptional("DerivePointerBinding", Style.DerivePointerAlignment);
219 Style.IndentWrappedFunctionNames);
220 IO.mapOptional("PointerBindsToType", Style.PointerAlignment);
222 Style.SpaceBeforeParens);
225 IO.mapOptional("AccessModifierOffset", Style.AccessModifierOffset);
226 IO.mapOptional("AlignAfterOpenBracket", Style.AlignAfterOpenBracket);
228 Style.AlignConsecutiveAssignments);
230 Style.AlignConsecutiveDeclarations);
231 IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlinesLeft);
232 IO.mapOptional("AlignOperands", Style.AlignOperands);
233 IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
235 Style.AllowAllParametersOfDeclarationOnNextLine);
237 Style.AllowShortBlocksOnASingleLine);
239 Style.AllowShortCaseLabelsOnASingleLine);
241 Style.AllowShortFunctionsOnASingleLine);
243 Style.AllowShortIfStatementsOnASingleLine);
245 Style.AllowShortLoopsOnASingleLine);
247 Style.AlwaysBreakAfterDefinitionReturnType);
249 Style.AlwaysBreakAfterReturnType);
253 if (Style.AlwaysBreakAfterDefinitionReturnType != FormatStyle::DRTBS_None &&
254 Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None) {
255 if (Style.AlwaysBreakAfterDefinitionReturnType == FormatStyle::DRTBS_All)
256 Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
257 else if (Style.AlwaysBreakAfterDefinitionReturnType ==
259 Style.AlwaysBreakAfterReturnType =
264 Style.AlwaysBreakBeforeMultilineStrings);
266 Style.AlwaysBreakTemplateDeclarations);
267 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
268 IO.mapOptional("BinPackParameters", Style.BinPackParameters);
269 IO.mapOptional("BraceWrapping", Style.BraceWrapping);
271 Style.BreakBeforeBinaryOperators);
272 IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);
274 Style.BreakBeforeTernaryOperators);
276 Style.BreakConstructorInitializersBeforeComma);
277 IO.mapOptional("ColumnLimit", Style.ColumnLimit);
278 IO.mapOptional("CommentPragmas", Style.CommentPragmas);
280 Style.ConstructorInitializerAllOnOneLineOrOnePerLine);
282 Style.ConstructorInitializerIndentWidth);
283 IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
284 IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
285 IO.mapOptional("DerivePointerAlignment", Style.DerivePointerAlignment);
286 IO.mapOptional("DisableFormat", Style.DisableFormat);
288 Style.ExperimentalAutoDetectBinPacking);
289 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
290 IO.mapOptional("IncludeCategories", Style.IncludeCategories);
291 IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
292 IO.mapOptional("IndentWidth", Style.IndentWidth);
294 Style.IndentWrappedFunctionNames);
296 Style.KeepEmptyLinesAtTheStartOfBlocks);
297 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
298 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
299 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
300 IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
301 IO.mapOptional("ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth);
302 IO.mapOptional("ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty);
304 Style.ObjCSpaceBeforeProtocolList);
306 Style.PenaltyBreakBeforeFirstCallParameter);
307 IO.mapOptional("PenaltyBreakComment", Style.PenaltyBreakComment);
309 Style.PenaltyBreakFirstLessLess);
310 IO.mapOptional("PenaltyBreakString", Style.PenaltyBreakString);
311 IO.mapOptional("PenaltyExcessCharacter", Style.PenaltyExcessCharacter);
313 Style.PenaltyReturnTypeOnItsOwnLine);
314 IO.mapOptional("PointerAlignment", Style.PointerAlignment);
315 IO.mapOptional("ReflowComments", Style.ReflowComments);
316 IO.mapOptional("SortIncludes", Style.SortIncludes);
317 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
319 Style.SpaceBeforeAssignmentOperators);
320 IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens);
321 IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
323 Style.SpacesBeforeTrailingComments);
324 IO.mapOptional("SpacesInAngles", Style.SpacesInAngles);
326 Style.SpacesInContainerLiterals);
328 Style.SpacesInCStyleCastParentheses);
329 IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
330 IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
331 IO.mapOptional("Standard", Style.Standard);
332 IO.mapOptional("TabWidth", Style.TabWidth);
333 IO.mapOptional("UseTab", Style.UseTab);
415 static FormatStyle expandPresets(const FormatStyle &Style) {
416 if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
417 return Style;
418 FormatStyle Expanded = Style;
421 switch (Style.BreakBeforeBraces) {
636 FormatStyle Style = getLLVMStyle();
637 Style.AccessModifierOffset = -4;
638 Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
639 Style.AlignOperands = false;
640 Style.AlignTrailingComments = false;
641 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
642 Style.BreakBeforeBraces = FormatStyle::BS_WebKit;
643 Style.BreakConstructorInitializersBeforeComma = true;
644 Style.Cpp11BracedListStyle = false;
645 Style.ColumnLimit = 0;
646 Style.IndentWidth = 4;
647 Style.NamespaceIndentation = FormatStyle::NI_Inner;
648 Style.ObjCBlockIndentWidth = 4;
649 Style.ObjCSpaceAfterProperty = true;
650 Style.PointerAlignment = FormatStyle::PAS_Left;
651 Style.Standard = FormatStyle::LS_Cpp03;
652 return Style;
656 FormatStyle Style = getLLVMStyle();
657 Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
658 Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
659 Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
660 Style.BreakBeforeBraces = FormatStyle::BS_GNU;
661 Style.BreakBeforeTernaryOperators = true;
662 Style.Cpp11BracedListStyle = false;
663 Style.ColumnLimit = 79;
664 Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
665 Style.Standard = FormatStyle::LS_Cpp03;
666 return Style;
677 FormatStyle *Style) {
679 *Style = getLLVMStyle();
681 *Style = getChromiumStyle(Language);
683 *Style = getMozillaStyle();
685 *Style = getGoogleStyle(Language);
687 *Style = getWebKitStyle();
689 *Style = getGNUStyle();
691 *Style = getNoStyle();
696 Style->Language = Language;
700 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style) {
701 assert(Style);
702 FormatStyle::LanguageKind Language = Style->Language;
712 // base style.
713 Input.setContext(Style);
738 *Style = Styles[i];
739 Style->Language = Language;
746 std::string configurationAsText(const FormatStyle &Style) {
752 FormatStyle NonConstStyle = expandPresets(Style);
761 FormatTokenLexer(SourceManager &SourceMgr, FileID ID, FormatStyle &Style,
765 SourceMgr(SourceMgr), ID(ID), Style(Style),
766 IdentTable(getFormattingLangOpts(Style)), Keywords(IdentTable),
768 MacroBlockBeginRegex(Style.MacroBlockBegin),
769 MacroBlockEndRegex(Style.MacroBlockEnd) {
771 getFormattingLangOpts(Style)));
774 for (const std::string &ForEachMacro : Style.ForEachMacros)
784 if (Style.Language == FormatStyle::LK_JavaScript)
804 if (Style.Language == FormatStyle::LK_JavaScript) {
1083 String->TokenText, String->OriginalColumn, Style.TabWidth, Encoding);
1229 Column += Style.TabWidth - Column % Style.TabWidth;
1276 if (Style.Language == FormatStyle::LK_Java &&
1280 } else if (Style.Language == FormatStyle::LK_JavaScript &&
1303 encoding::columnWidthWithTabs(Text, Column, Style.TabWidth, Encoding);
1310 Text.substr(0, FirstNewlinePos), Column, Style.TabWidth, Encoding);
1315 Text.substr(Text.find_last_of('\n') + 1), 0, Style.TabWidth,
1320 if (Style.Language == FormatStyle::LK_Cpp) {
1347 FormatStyle &Style;
1372 } else if (Style.Language == FormatStyle::LK_JavaScript &&
1394 getFormattingLangOpts(Style), Buffer.begin(),
1418 Formatter(const FormatStyle &Style, SourceManager &SourceMgr, FileID ID,
1420 : Style(Style), ID(ID), SourceMgr(SourceMgr),
1421 Whitespaces(SourceMgr, Style,
1429 DEBUG(llvm::dbgs() << "Language: " << getLanguageName(Style.Language)
1435 FormatTokenLexer Tokens(SourceMgr, ID, Style, Encoding);
1437 UnwrappedLineParser Parser(Style, Tokens.getKeywords(), Tokens.lex(),
1470 TokenAnnotator Annotator(Style, Tokens.getKeywords());
1481 ContinuationIndenter Indenter(Style, Tokens.getKeywords(), SourceMgr,
1484 UnwrappedLineFormatter(&Indenter, &Whitespaces, Style, Tokens.getKeywords(),
1683 if (Style.DerivePointerAlignment)
1684 Style.PointerAlignment = countVariableAlignments(AnnotatedLines) <= 0
1687 if (Style.Standard == FormatStyle::LS_Auto)
1688 Style.Standard = hasCpp03IncompatibleFormat(AnnotatedLines)
1704 FormatStyle Style;
1738 static void sortIncludes(const FormatStyle &Style,
1792 tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
1796 if (!Style.SortIncludes)
1809 // (http://llvm.org/docs/CodingStandards.html#include-style).
1823 for (const auto &Category : Style.IncludeCategories)
1845 Category = Style.IncludeCategories[i].Priority;
1860 sortIncludes(Style, IncludesInBlock, Ranges, FileName, Replaces,
1872 sortIncludes(Style, IncludesInBlock, Ranges, FileName, Replaces, Cursor);
1876 tooling::Replacements reformat(const FormatStyle &Style,
1880 FormatStyle Expanded = expandPresets(Style);
1887 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
1890 if (Style.DisableFormat)
1911 return reformat(Style, SourceMgr, ID, CharRanges, IncompleteFormat);
1914 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
1917 LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
1918 LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
1920 bool AlternativeOperators = Style.Language == FormatStyle::LK_Cpp;
1931 "Coding style, currently supports:\n"
1933 "Use -style=file to load style configuration from\n"
1937 "Use -style=\"{key: value, ...}\" to set specific\n"
1939 " -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
1956 FormatStyle Style = getLLVMStyle();
1957 Style.Language = getLanguageByFileName(FileName);
1958 if (!getPredefinedStyle(FallbackStyle, Style.Language, &Style)) {
1959 llvm::errs() << "Invalid fallback style \"" << FallbackStyle
1960 << "\" using LLVM style\n";
1961 return Style;
1965 // Parse YAML/JSON style from the command line.
1966 if (std::error_code ec = parseConfiguration(StyleName, &Style)) {
1967 llvm::errs() << "Error parsing -style: " << ec.message() << ", using "
1968 << FallbackStyle << " style\n";
1970 return Style;
1974 if (!getPredefinedStyle(StyleName, Style.Language, &Style))
1975 llvm::errs() << "Invalid value for -style, using " << FallbackStyle
1976 << " style\n";
1977 return Style;
2013 parseConfiguration(Text.get()->getBuffer(), &Style)) {
2025 return Style;
2030 << getLanguageName(Style.Language) << ": "
2033 return Style;