diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -125,7 +125,7 @@ the configuration (without a prefix: ``Auto``). -**BasedOnStyle** (``string``) +**BasedOnStyle** (``String``) The style used for all options not specifically set in the configuration. This option is supported only in the :program:`clang-format` configuration @@ -166,7 +166,7 @@ .. START_FORMAT_STYLE_OPTIONS -**AccessModifierOffset** (``int``) +**AccessModifierOffset** (``Integer``) The extra indent or outdent of access modifiers, e.g. ``public:``. **AlignAfterOpenBracket** (``BracketAlignmentStyle``) @@ -619,7 +619,7 @@ -**AlignTrailingComments** (``bool``) +**AlignTrailingComments** (``Boolean``) If ``true``, aligns trailing comments. .. code-block:: c++ @@ -628,7 +628,7 @@ int a; // My comment a vs. int a; // My comment a int b = 2; // comment b int b = 2; // comment about b -**AllowAllArgumentsOnNextLine** (``bool``) +**AllowAllArgumentsOnNextLine** (``Boolean``) If a function call or braced initializer list doesn't fit on a line, allow putting all arguments onto the next line, even if ``BinPackArguments`` is ``false``. @@ -645,7 +645,7 @@ c, d); -**AllowAllConstructorInitializersOnNextLine** (``bool``) +**AllowAllConstructorInitializersOnNextLine** (``Boolean``) If a constructor definition with a member initializer list doesn't fit on a single line, allow putting all member initializers onto the next line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true. @@ -663,7 +663,7 @@ member0(0), member1(2) {} -**AllowAllParametersOfDeclarationOnNextLine** (``bool``) +**AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) If the function declaration doesn't fit on a line, allow putting all parameters of a function declaration onto the next line even if ``BinPackParameters`` is ``false``. @@ -718,7 +718,7 @@ -**AllowShortCaseLabelsOnASingleLine** (``bool``) +**AllowShortCaseLabelsOnASingleLine** (``Boolean``) If ``true``, short case labels will be contracted to a single line. .. code-block:: c++ @@ -732,7 +732,7 @@ return; } -**AllowShortEnumsOnASingleLine** (``bool``) +**AllowShortEnumsOnASingleLine** (``Boolean``) Allow short enums on a single line. .. code-block:: c++ @@ -923,7 +923,7 @@ -**AllowShortLoopsOnASingleLine** (``bool``) +**AllowShortLoopsOnASingleLine** (``Boolean``) If ``true``, ``while (true) continue;`` can be put on a single line. @@ -1028,7 +1028,7 @@ -**AlwaysBreakBeforeMultilineStrings** (``bool``) +**AlwaysBreakBeforeMultilineStrings** (``Boolean``) If ``true``, always break before multiline string literals. This flag is mean to make cases where there are multiple multiline strings @@ -1088,7 +1088,7 @@ -**AttributeMacros** (``std::vector``) +**AttributeMacros** (``List of Strings``) A vector of strings that should be interpreted as attributes/qualifiers instead of identifiers. This can be useful for language extensions or static analyzer annotations. @@ -1107,7 +1107,7 @@ AttributeMacros: ['__capability', '__output', '__ununsed'] -**BinPackArguments** (``bool``) +**BinPackArguments** (``Boolean``) If ``false``, a function call's arguments will either be all on the same line or will have one line each. @@ -1126,7 +1126,7 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); } -**BinPackParameters** (``bool``) +**BinPackParameters** (``Boolean``) If ``false``, a function declaration's or function definition's parameters will either all be on the same line or will have one line each. @@ -1464,7 +1464,7 @@ } -**BreakAfterJavaFieldAnnotations** (``bool``) +**BreakAfterJavaFieldAnnotations** (``Boolean``) Break after each annotation on a field in Java files. .. code-block:: java @@ -1974,7 +1974,7 @@ -**BreakBeforeConceptDeclarations** (``bool``) +**BreakBeforeConceptDeclarations** (``Boolean``) If ``true``, concept will be placed on a new line. .. code-block:: c++ @@ -1986,7 +1986,7 @@ false: template concept ... -**BreakBeforeTernaryOperators** (``bool``) +**BreakBeforeTernaryOperators** (``Boolean``) If ``true``, ternary operators will be placed after line breaks. .. code-block:: c++ @@ -2083,7 +2083,7 @@ -**BreakStringLiterals** (``bool``) +**BreakStringLiterals** (``Boolean``) Allow breaking string literals when formatting. .. code-block:: c++ @@ -2097,14 +2097,14 @@ const char* x = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; -**ColumnLimit** (``unsigned``) +**ColumnLimit** (``Unsigned``) The column limit. A column limit of ``0`` means that there is no column limit. In this case, clang-format will respect the input's line breaking decisions within statements unless they contradict other rules. -**CommentPragmas** (``std::string``) +**CommentPragmas** (``String``) A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed. @@ -2114,7 +2114,7 @@ // Will leave the following line unaffected #include // FOOBAR pragma: keep -**CompactNamespaces** (``bool``) +**CompactNamespaces** (``Boolean``) If ``true``, consecutive namespace declarations will be on the same line. If ``false``, each namespace is declared on a new line. @@ -2139,7 +2139,7 @@ namespace Extra { }}} -**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) +**ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) If the constructor initializers don't fit on a line, put each initializer on its own line. @@ -2158,11 +2158,11 @@ return 0; } -**ConstructorInitializerIndentWidth** (``unsigned``) +**ConstructorInitializerIndentWidth** (``Unsigned``) The number of characters to use for indentation of constructor initializer lists as well as inheritance lists. -**ContinuationIndentWidth** (``unsigned``) +**ContinuationIndentWidth** (``Unsigned``) Indent width for line continuations. .. code-block:: c++ @@ -2173,7 +2173,7 @@ longFunction( // Again a long comment arg); -**Cpp11BracedListStyle** (``bool``) +**Cpp11BracedListStyle** (``Boolean``) If ``true``, format braced lists as best suited for C++11 braced lists. @@ -2196,18 +2196,18 @@ f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; -**DeriveLineEnding** (``bool``) +**DeriveLineEnding** (``Boolean``) Analyze the formatted file for the most used line ending (``\r\n`` or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived. -**DerivePointerAlignment** (``bool``) +**DerivePointerAlignment** (``Boolean``) If ``true``, analyze the formatted file for the most common alignment of ``&`` and ``*``. Pointer and reference alignment styles are going to be updated according to the preferences found in the file. ``PointerAlignment`` is then used only as fallback. -**DisableFormat** (``bool``) +**DisableFormat** (``Boolean``) Disables formatting completely. **EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) @@ -2332,7 +2332,7 @@ -**ExperimentalAutoDetectBinPacking** (``bool``) +**ExperimentalAutoDetectBinPacking** (``Boolean``) If ``true``, clang-format detects whether function calls and definitions are formatted with one parameter per line. @@ -2344,7 +2344,7 @@ NOTE: This is an experimental flag, that might go away or be renamed. Do not use this in config files, etc. Use at your own risk. -**FixNamespaceComments** (``bool``) +**FixNamespaceComments** (``Boolean``) If ``true``, clang-format adds missing namespace end comments for short namespaces and fixes invalid existing ones. Short ones are controlled by "ShortNamespaceLines". @@ -2357,7 +2357,7 @@ bar(); bar(); } // namespace a } -**ForEachMacros** (``std::vector``) +**ForEachMacros** (``List of Strings``) A vector of macros that should be interpreted as foreach loops instead of as function calls. @@ -2376,7 +2376,7 @@ For example: BOOST_FOREACH. -**IfMacros** (``std::vector``) +**IfMacros** (``List of Strings``) A vector of macros that should be interpreted as conditionals instead of as function calls. @@ -2438,7 +2438,7 @@ -**IncludeCategories** (``std::vector``) +**IncludeCategories** (``List of IncludeCategories``) Regular expressions denoting the different ``#include`` categories used for ordering ``#includes``. @@ -2486,7 +2486,7 @@ Priority: 1 SortPriority: 0 -**IncludeIsMainRegex** (``std::string``) +**IncludeIsMainRegex** (``String``) Specify a regular expression of suffixes that are allowed in the file-to-main-include mapping. @@ -2499,7 +2499,7 @@ For example, if configured to "(_test)?$", then a header a.h would be seen as the "main" include in both a.cc and a_test.cc. -**IncludeIsMainSourceRegex** (``std::string``) +**IncludeIsMainSourceRegex** (``String``) Specify a regular expression for files being formatted that are allowed to be considered "main" in the file-to-main-include mapping. @@ -2519,7 +2519,7 @@ ``ClassImpl.hpp`` would not have the main include file put on top before any other include. -**IndentAccessModifiers** (``bool``) +**IndentAccessModifiers** (``Boolean``) Specify whether access modifiers should have their own indentation level. When ``false``, access modifiers are indented (or outdented) relative to @@ -2546,7 +2546,7 @@ return 1; return 1; } } -**IndentCaseBlocks** (``bool``) +**IndentCaseBlocks** (``Boolean``) Indent case label blocks one level from the case label. When ``false``, the block following the case label uses the same @@ -2569,7 +2569,7 @@ } } -**IndentCaseLabels** (``bool``) +**IndentCaseLabels** (``Boolean``) Indent case labels one level from the switch statement. When ``false``, use the same indentation level as for the switch @@ -2634,7 +2634,7 @@ -**IndentGotoLabels** (``bool``) +**IndentGotoLabels** (``Boolean``) Indent goto labels. When ``false``, goto labels are flushed left. @@ -2691,7 +2691,7 @@ -**IndentRequires** (``bool``) +**IndentRequires** (``Boolean``) Indent the requires clause in a template .. code-block:: c++ @@ -2710,7 +2710,7 @@ //.... } -**IndentWidth** (``unsigned``) +**IndentWidth** (``Unsigned``) The number of columns to use for indentation. .. code-block:: c++ @@ -2724,7 +2724,7 @@ } } -**IndentWrappedFunctionNames** (``bool``) +**IndentWrappedFunctionNames** (``Boolean``) Indent if a function definition or declaration is wrapped after the type. @@ -2770,7 +2770,7 @@ -**JavaImportGroups** (``std::vector``) +**JavaImportGroups** (``List of Strings``) A vector of prefixes ordered by the desired groups for Java imports. One group's prefix can be a subset of another - the longest prefix is @@ -2836,7 +2836,7 @@ -**JavaScriptWrapImports** (``bool``) +**JavaScriptWrapImports** (``Boolean``) Whether to wrap JavaScript import/export statements. .. code-block:: js @@ -2851,7 +2851,7 @@ false: import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" -**KeepEmptyLinesAtTheStartOfBlocks** (``bool``) +**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) If true, the empty line at the start of blocks is kept. .. code-block:: c++ @@ -2937,7 +2937,7 @@ -**MacroBlockBegin** (``std::string``) +**MacroBlockBegin** (``String``) A regular expression matching macros that start a block. .. code-block:: c++ @@ -2966,10 +2966,10 @@ bar(); NS_TABLE_FOO_END -**MacroBlockEnd** (``std::string``) +**MacroBlockEnd** (``String``) A regular expression matching macros that end a block. -**MaxEmptyLinesToKeep** (``unsigned``) +**MaxEmptyLinesToKeep** (``Unsigned``) The maximum number of consecutive empty lines to keep. .. code-block:: c++ @@ -3026,7 +3026,7 @@ -**NamespaceMacros** (``std::vector``) +**NamespaceMacros** (``List of Strings``) A vector of macros which are used to open namespace blocks. These are expected to be macros of the form: @@ -3085,7 +3085,7 @@ -**ObjCBlockIndentWidth** (``unsigned``) +**ObjCBlockIndentWidth** (``Unsigned``) The number of characters to use for indentation of ObjC blocks. .. code-block:: objc @@ -3096,7 +3096,7 @@ [self onOperationDone]; }]; -**ObjCBreakBeforeNestedBlockParam** (``bool``) +**ObjCBreakBeforeNestedBlockParam** (``Boolean``) Break parameters list into lines when there is nested block parameters in a function call. @@ -3120,15 +3120,15 @@ }] } -**ObjCSpaceAfterProperty** (``bool``) +**ObjCSpaceAfterProperty** (``Boolean``) Add a space after ``@property`` in Objective-C, i.e. use ``@property (readonly)`` instead of ``@property(readonly)``. -**ObjCSpaceBeforeProtocolList** (``bool``) +**ObjCSpaceBeforeProtocolList** (``Boolean``) Add a space in front of an Objective-C protocol list, i.e. use ``Foo `` instead of ``Foo``. -**PPIndentWidth** (``int``) +**PPIndentWidth** (``Integer``) The number of columns to use for indentation of preprocessor statements. When set to -1 (default) ``IndentWidth`` is used also for preprocessor statements. @@ -3143,32 +3143,32 @@ # define BAR #endif -**PenaltyBreakAssignment** (``unsigned``) +**PenaltyBreakAssignment** (``Unsigned``) The penalty for breaking around an assignment operator. -**PenaltyBreakBeforeFirstCallParameter** (``unsigned``) +**PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) The penalty for breaking a function call after ``call(``. -**PenaltyBreakComment** (``unsigned``) +**PenaltyBreakComment** (``Unsigned``) The penalty for each line break introduced inside a comment. -**PenaltyBreakFirstLessLess** (``unsigned``) +**PenaltyBreakFirstLessLess** (``Unsigned``) The penalty for breaking before the first ``<<``. -**PenaltyBreakString** (``unsigned``) +**PenaltyBreakString** (``Unsigned``) The penalty for each line break introduced inside a string literal. -**PenaltyBreakTemplateDeclaration** (``unsigned``) +**PenaltyBreakTemplateDeclaration** (``Unsigned``) The penalty for breaking after template declaration. -**PenaltyExcessCharacter** (``unsigned``) +**PenaltyExcessCharacter** (``Unsigned``) The penalty for each character outside of the column limit. -**PenaltyIndentedWhitespace** (``unsigned``) +**PenaltyIndentedWhitespace** (``Unsigned``) Penalty for each character of whitespace indentation (counted relative to leading non-whitespace column). -**PenaltyReturnTypeOnItsOwnLine** (``unsigned``) +**PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) Penalty for putting the return type of a function onto its own line. @@ -3200,7 +3200,7 @@ -**RawStringFormats** (``std::vector``) +**RawStringFormats** (``List of RawStringFormats``) Defines hints for detecting supported languages code blocks in raw strings. @@ -3270,7 +3270,7 @@ -**ReflowComments** (``bool``) +**ReflowComments** (``Boolean``) If ``true``, clang-format will attempt to re-flow comments. .. code-block:: c++ @@ -3285,7 +3285,7 @@ /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of * information */ -**ShortNamespaceLines** (``unsigned``) +**ShortNamespaceLines** (``Unsigned``) The maximal number of unwrapped lines that a short namespace spans. Defaults to 1. @@ -3379,7 +3379,7 @@ -**SortUsingDeclarations** (``bool``) +**SortUsingDeclarations** (``Boolean``) If ``true``, clang-format will sort using declarations. The order of using declarations is defined as follows: @@ -3396,7 +3396,7 @@ using std::cout; vs. using std::cin; using std::cin; using std::cout; -**SpaceAfterCStyleCast** (``bool``) +**SpaceAfterCStyleCast** (``Boolean``) If ``true``, a space is inserted after C style casts. .. code-block:: c++ @@ -3404,7 +3404,7 @@ true: false: (int) i; vs. (int)i; -**SpaceAfterLogicalNot** (``bool``) +**SpaceAfterLogicalNot** (``Boolean``) If ``true``, a space is inserted after the logical not operator (``!``). .. code-block:: c++ @@ -3412,7 +3412,7 @@ true: false: ! someExpression(); vs. !someExpression(); -**SpaceAfterTemplateKeyword** (``bool``) +**SpaceAfterTemplateKeyword** (``Boolean``) If ``true``, a space will be inserted after the 'template' keyword. .. code-block:: c++ @@ -3460,7 +3460,7 @@ -**SpaceBeforeAssignmentOperators** (``bool``) +**SpaceBeforeAssignmentOperators** (``Boolean``) If ``false``, spaces will be removed before assignment operators. .. code-block:: c++ @@ -3469,7 +3469,7 @@ int a = 5; vs. int a= 5; a += 42; a+= 42; -**SpaceBeforeCaseColon** (``bool``) +**SpaceBeforeCaseColon** (``Boolean``) If ``false``, spaces will be removed before case colon. .. code-block:: c++ @@ -3479,7 +3479,7 @@ case 1 : break; case 1: break; } } -**SpaceBeforeCpp11BracedList** (``bool``) +**SpaceBeforeCpp11BracedList** (``Boolean``) If ``true``, a space will be inserted before a C++11 braced list used to initialize an object (after the preceding identifier or type). @@ -3491,7 +3491,7 @@ vector { 1, 2, 3 }; vector{ 1, 2, 3 }; new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; -**SpaceBeforeCtorInitializerColon** (``bool``) +**SpaceBeforeCtorInitializerColon** (``Boolean``) If ``false``, spaces will be removed before constructor initializer colon. @@ -3500,7 +3500,7 @@ true: false: Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} -**SpaceBeforeInheritanceColon** (``bool``) +**SpaceBeforeInheritanceColon** (``Boolean``) If ``false``, spaces will be removed before inheritance colon. .. code-block:: c++ @@ -3580,7 +3580,7 @@ -**SpaceBeforeRangeBasedForLoopColon** (``bool``) +**SpaceBeforeRangeBasedForLoopColon** (``Boolean``) If ``false``, spaces will be removed before range-based for loop colon. @@ -3589,7 +3589,7 @@ true: false: for (auto v : values) {} vs. for(auto v: values) {} -**SpaceBeforeSquareBrackets** (``bool``) +**SpaceBeforeSquareBrackets** (``Boolean``) If ``true``, spaces will be before ``[``. Lambdas will not be affected. Only the first ``[`` will get a space added. @@ -3599,7 +3599,7 @@ int a [5]; vs. int a[5]; int a [5][5]; vs. int a[5][5]; -**SpaceInEmptyBlock** (``bool``) +**SpaceInEmptyBlock** (``Boolean``) If ``true``, spaces will be inserted into ``{}``. .. code-block:: c++ @@ -3608,7 +3608,7 @@ void f() { } vs. void f() {} while (true) { } while (true) {} -**SpaceInEmptyParentheses** (``bool``) +**SpaceInEmptyParentheses** (``Boolean``) If ``true``, spaces may be inserted into ``()``. .. code-block:: c++ @@ -3621,7 +3621,7 @@ } } } } -**SpacesBeforeTrailingComments** (``unsigned``) +**SpacesBeforeTrailingComments** (``Unsigned``) The number of spaces before trailing line comments (``//`` - comments). @@ -3665,7 +3665,7 @@ -**SpacesInCStyleCastParentheses** (``bool``) +**SpacesInCStyleCastParentheses** (``Boolean``) If ``true``, spaces may be inserted into C style casts. .. code-block:: c++ @@ -3673,7 +3673,7 @@ true: false: x = ( int32 )y vs. x = (int32)y -**SpacesInConditionalStatement** (``bool``) +**SpacesInConditionalStatement** (``Boolean``) If ``true``, spaces will be inserted around if/for/switch/while conditions. @@ -3683,7 +3683,7 @@ if ( a ) { ... } vs. if (a) { ... } while ( i < 5 ) { ... } while (i < 5) { ... } -**SpacesInContainerLiterals** (``bool``) +**SpacesInContainerLiterals** (``Boolean``) If ``true``, spaces are inserted inside container literals (e.g. ObjC and Javascript array and dict literals). @@ -3730,7 +3730,7 @@ * ``unsigned Maximum`` The maximum number of spaces at the start of the comment. -**SpacesInParentheses** (``bool``) +**SpacesInParentheses** (``Boolean``) If ``true``, spaces will be inserted after ``(`` and before ``)``. .. code-block:: c++ @@ -3738,7 +3738,7 @@ true: false: t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; -**SpacesInSquareBrackets** (``bool``) +**SpacesInSquareBrackets** (``Boolean``) If ``true``, spaces will be inserted after ``[`` and before ``]``. Lambdas without arguments or unspecified size array declarations will not be affected. @@ -3784,7 +3784,7 @@ -**StatementAttributeLikeMacros** (``std::vector``) +**StatementAttributeLikeMacros** (``List of Strings``) Macros which are ignored in front of a statement, as if they were an attribute. So that they are not parsed as identifier, for example for Qts emit. @@ -3801,7 +3801,7 @@ unsigned char data = 'x'; emit signal(data); // Now it's fine again. -**StatementMacros** (``std::vector``) +**StatementMacros** (``List of Strings``) A vector of macros that should be interpreted as complete statements. @@ -3811,10 +3811,10 @@ For example: Q_UNUSED -**TabWidth** (``unsigned``) +**TabWidth** (``Unsigned``) The number of columns used for tab stops. -**TypenameMacros** (``std::vector``) +**TypenameMacros** (``List of Strings``) A vector of macros that should be interpreted as type declarations instead of as function calls. @@ -3832,7 +3832,7 @@ For example: OpenSSL STACK_OF, BSD LIST_ENTRY. -**UseCRLF** (``bool``) +**UseCRLF** (``Boolean``) Use ``\r\n`` instead of ``\n`` for line breaks. Also used as fallback if ``DeriveLineEnding`` is true. @@ -3861,7 +3861,7 @@ -**WhitespaceSensitiveMacros** (``std::vector``) +**WhitespaceSensitiveMacros** (``List of Strings``) A vector of macros which are whitespace-sensitive and should not be touched. diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py --- a/clang/docs/tools/dump_format_style.py +++ b/clang/docs/tools/dump_format_style.py @@ -1,23 +1,73 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # A tool to parse the FormatStyle struct from Format.h and update the # documentation in ../ClangFormatStyleOptions.rst automatically. # Run from the directory in which this file is located to update the docs. -import collections +import inspect import os import re +from typing import Set CLANG_DIR = os.path.join(os.path.dirname(__file__), '../..') FORMAT_STYLE_FILE = os.path.join(CLANG_DIR, 'include/clang/Format/Format.h') INCLUDE_STYLE_FILE = os.path.join(CLANG_DIR, 'include/clang/Tooling/Inclusions/IncludeStyle.h') DOC_FILE = os.path.join(CLANG_DIR, 'docs/ClangFormatStyleOptions.rst') +PLURALS_FILE = os.path.join(os.path.dirname(__file__), 'plurals.txt') +print(f'generated plurals (for yaml type) are stored in {PLURALS_FILE}') +print('you can use `git checkout -- plurals.txt` to reemit warnings or `git add`\n') +plurals: Set[str] = set() +with open(PLURALS_FILE, 'a+') as f: + f.seek(0) + plurals = set(f.read().splitlines()) def substitute(text, tag, contents): replacement = '\n.. START_%s\n\n%s\n\n.. END_%s\n' % (tag, contents, tag) pattern = r'\n\.\. START_%s\n.*\n\.\. END_%s\n' % (tag, tag) return re.sub(pattern, '%s', text, flags=re.S) % replacement +def register_plural(singular: str, plural: str): + if plural not in plurals: + plurals.add(plural) + with open(PLURALS_FILE, 'a') as f: + f.write(plural + '\n') + cf = inspect.currentframe() + lineno = '' + if cf and cf.f_back: + lineno = ':' + str(cf.f_back.f_lineno) + print(f'{__file__}{lineno} check if plural of {singular} is {plural}', file=os.sys.stderr) + return plural + +def pluralize(word: str): + lword = word.lower() + if len(lword) >= 2 and lword[-1] == 'y' and lword[-2] not in 'aeiou': + return register_plural(word, word[:-1] + 'ies') + elif lword.endswith(('s', 'sh', 'ch', 'x', 'z')): + return register_plural(word, word[:-1] + 'es') + elif lword.endswith('fe'): + return register_plural(word, word[:-2] + 'ves') + elif lword.endswith('f') and not lword.endswith('ff'): + return register_plural(word, word[:-1] + 'ves') + else: + return register_plural(word, word + 's') + + +def to_yaml_type(typestr: str): + if typestr == 'bool': + return 'Boolean' + elif typestr == 'int': + return 'Integer' + elif typestr == 'unsigned': + return 'Unsigned' + elif typestr == 'std::string': + return 'String' + + subtype, napplied = re.subn(r'^std::vector<(.*)>$', r'\1', typestr) + if napplied == 1: + return 'List of ' + pluralize(to_yaml_type(subtype)) + + return typestr + def doxygen2rst(text): text = re.sub(r'\s*(.*?)\s*<\/tt>', r'``\1``', text) text = re.sub(r'\\c ([^ ,;\.]+)', r'``\1``', text) @@ -40,7 +90,7 @@ self.nested_struct = None def __str__(self): - s = '**%s** (``%s``)\n%s' % (self.name, self.type, + s = '**%s** (``%s``)\n%s' % (self.name, to_yaml_type(self.type), doxygen2rst(indent(self.comment, 2))) if self.enum and self.enum.values: s += indent('\n\nPossible values:\n\n%s\n' % self.enum, 2) @@ -85,7 +135,7 @@ self.type = enumtype def __str__(self): - s = '\n* ``%s %s``\n%s' % (self.type, self.name, + s = '\n* ``%s %s``\n%s' % (to_yaml_type(self.type), self.name, doxygen2rst(indent(self.comment, 2))) s += indent('\nPossible values:\n\n', 2) s += indent('\n'.join(map(str, self.values)),2) diff --git a/clang/docs/tools/plurals.txt b/clang/docs/tools/plurals.txt new file mode 100644 --- /dev/null +++ b/clang/docs/tools/plurals.txt @@ -0,0 +1,3 @@ +Strings +IncludeCategories +RawStringFormats diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -3083,7 +3083,7 @@ /// ForEach and If macros. This is useful in projects where ForEach/If /// macros are treated as function calls instead of control statements. /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for - /// backward compatability. + /// backward compatibility. /// \code /// void f() { /// Q_FOREACH(...) {