Skip to content

Commit

Permalink
add clang-format conf to the project, format the c++ code (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
adiviness authored Jun 11, 2019
1 parent 6fc0978 commit 9b92986
Show file tree
Hide file tree
Showing 523 changed files with 11,569 additions and 12,674 deletions.
93 changes: 93 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

AccessModifierOffset: -4
AlignAfterOpenBracket: Align
#AllowAllArgumentsOnNextLine: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
#AllowAllConstructorInitializersOnNextLine: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
#AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
ColumnLimit: 0
CommentPragmas: "suppress"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
FixNamespaceComments: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^.*(precomp|pch|stdafx)'
Priority: -1
- Regex: '^".*"'
Priority: 1
- Regex: '^<.*>'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: "BEGIN_TEST_METHOD_PROPERTIES|BEGIN_MODULE|BEGIN_TEST_CLASS|BEGIN_TEST_METHOD"
MacroBlockEnd: "END_TEST_METHOD_PROPERTIES|END_MODULE|END_TEST_CLASS|END_TEST_METHOD"
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
#SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
4 changes: 4 additions & 0 deletions doc/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Openconsole can be built with Visual Studio or from the command line. There are build scripts for both cmd and powershell in /tools.

When using Visual Studio, be sure to set up the path for code formatting. This can be done in Visual Studio by going to Tools > Options > Text Editor > C++ > Formatting and checking "Use custom clang-format.exe file" and choosing the clang-format.exe in the repository at /dep/llvm/clang-format.exe by clicking "browse" right under the check box.

## Building with cmd

The cmd scripts are set up to emulate a portion of the OS razzle build environment. razzle.cmd is the first script that should be run. bcz.cmd will build clean and bz.cmd should build incrementally.
Expand All @@ -11,6 +13,7 @@ There are also scripts for running the tests:
- `runut.cmd` - run the unit tests
- `runft.cmd` - run the feature tests
- `runuia.cmd` - run the UIA tests
- `runformat` - uses clang-format to format all c++ files to match our coding style.

## Build with Powershell

Expand All @@ -20,6 +23,7 @@ Openconsole.psm1 should be loaded with `Import-Module`. From there `Set-MsbuildD
- `Invoke-OpenConsoleTests` - runs the various tests. Will run the unit tests by default.
- `Start-OpenConsole` - starts Openconsole.exe from the output directory. x64 is run by default.
- `Debug-OpenConsole` - starts Openconsole.exe and attaches it to the default debugger. x64 is run by default.
- `Invoke-CodeFormat` - uses clang-format to format all c++ files to match our coding style.

## Configuration Types

Expand Down
27 changes: 12 additions & 15 deletions src/buffer/out/AttrRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "precomp.h"
#include "AttrRow.hpp"

// Routine Description:
// - constructor
// Arguments:
// - cchRowWidth - the length of the default text attribute
// - attr - the default text attribute
// Return Value:
// - constructed object
// Note: will throw exception if unable to allocate memory for text attribute storage
// Routine Description:
// - constructor
// Arguments:
// - cchRowWidth - the length of the default text attribute
// - attr - the default text attribute
// Return Value:
// - constructed object
// Note: will throw exception if unable to allocate memory for text attribute storage
ATTR_ROW::ATTR_ROW(const UINT cchRowWidth, const TextAttribute attr)
{
_list.push_back(TextAttributeRun(cchRowWidth, attr));
Expand Down Expand Up @@ -210,7 +210,6 @@ void ATTR_ROW::ReplaceLegacyAttrs(_In_ WORD wToBeReplacedAttr, _In_ WORD wReplac
ReplaceAttrs(ToBeReplaced, ReplaceWith);
}


// Method Description:
// - Replaces all runs in the row with the given toBeReplacedAttr with the new
// attribute replaceWith.
Expand All @@ -230,7 +229,6 @@ void ATTR_ROW::ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAtt
}
}


// Routine Description:
// - Takes a array of attribute runs, and inserts them into this row from startIndex to endIndex.
// - For example, if the current row was was [{4, BLUE}], the merge string
Expand All @@ -245,11 +243,10 @@ void ATTR_ROW::ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAtt
// Return Value:
// - STATUS_NO_MEMORY if there wasn't enough memory to insert the runs
// otherwise STATUS_SUCCESS if we were successful.
[[nodiscard]]
HRESULT ATTR_ROW::InsertAttrRuns(const std::basic_string_view<TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth)
[[nodiscard]] HRESULT ATTR_ROW::InsertAttrRuns(const std::basic_string_view<TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth)
{
// Definitions:
// Existing Run = The run length encoded color array we're already storing in memory before this was called.
Expand Down
11 changes: 4 additions & 7 deletions src/buffer/out/AttrRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ class ATTR_ROW final

void Resize(const size_t newWidth);

[[nodiscard]]
HRESULT InsertAttrRuns(const std::basic_string_view<TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth);
[[nodiscard]] HRESULT InsertAttrRuns(const std::basic_string_view<TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth);

static std::vector<TextAttributeRun> PackAttrs(const std::vector<TextAttribute>& attrs);

Expand All @@ -65,12 +64,10 @@ class ATTR_ROW final
friend class AttrRowIterator;

private:

std::vector<TextAttributeRun> _list;
size_t _cchRowWidth;

#ifdef UNIT_TESTING
friend class AttrRowTests;
#endif

};
3 changes: 1 addition & 2 deletions src/buffer/out/AttrRowIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Author(s):
- Austin Diviness (AustDi) 04-Jun-2018
--*/


#pragma once

#include "TextAttribute.hpp"
Expand Down Expand Up @@ -55,7 +54,7 @@ class AttrRowIterator final
std::vector<TextAttributeRun>::const_iterator _run;
const ATTR_ROW* _pAttrRow;
size_t _currentAttributeIndex; // index of TextAttribute within the current TextAttributeRun

void _increment(size_t count);
void _decrement(size_t count);
void _setToEnd();
Expand Down
7 changes: 3 additions & 4 deletions src/buffer/out/CharRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ void CharRow::Reset()
// - newSize - the new width of the character and attributes rows
// Return Value:
// - S_OK on success, otherwise relevant error code
[[nodiscard]]
HRESULT CharRow::Resize(const size_t newSize) noexcept
[[nodiscard]] HRESULT CharRow::Resize(const size_t newSize) noexcept
{
try
{
Expand Down Expand Up @@ -263,7 +262,7 @@ std::wstring CharRow::GetTextRaw() const
{
std::wstring wstr;
wstr.reserve(_data.size());
for (size_t i = 0; i < _data.size(); ++i)
for (size_t i = 0; i < _data.size(); ++i)
{
auto glyph = GlyphAt(i);
for (auto it = glyph.begin(); it != glyph.end(); ++it)
Expand All @@ -279,7 +278,7 @@ std::wstring CharRow::GetText() const
std::wstring wstr;
wstr.reserve(_data.size());

for (size_t i = 0; i < _data.size(); ++i)
for (size_t i = 0; i < _data.size(); ++i)
{
auto glyph = GlyphAt(i);
if (!DbcsAttrAt(i).IsTrailing())
Expand Down
10 changes: 4 additions & 6 deletions src/buffer/out/CharRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class CharRow final
bool WasDoubleBytePadded() const noexcept;
size_t size() const noexcept;
void Reset();
[[nodiscard]]
HRESULT Resize(const size_t newSize) noexcept;
[[nodiscard]] HRESULT Resize(const size_t newSize) noexcept;
size_t MeasureLeft() const;
size_t MeasureRight() const noexcept;
void ClearCell(const size_t column);
Expand Down Expand Up @@ -116,8 +115,7 @@ void OverwriteColumns(InputIt1 startChars, InputIt1 endChars, InputIt2 startAttr
endChars,
startAttrs,
outIt,
[](const wchar_t wch, const DbcsAttribute attr)
{
return CharRow::value_type{ wch, attr };
});
[](const wchar_t wch, const DbcsAttribute attr) {
return CharRow::value_type{ wch, attr };
});
}
1 change: 0 additions & 1 deletion src/buffer/out/CharRowCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "CharRowCell.hpp"
#include "unicode.hpp"


// default glyph value, used for reseting the character data portion of a cell
static constexpr wchar_t DefaultValue = UNICODE_SPACE;

Expand Down
3 changes: 1 addition & 2 deletions src/buffer/out/CharRowCell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ Author(s):

#include "DbcsAttribute.hpp"


#if (defined(_M_IX86) || defined(_M_AMD64))
// currently CharRowCell's fields use 3 bytes of memory, leaving the 4th byte in unused. this leads
// to a rather large amount of useless memory allocated. so instead, pack CharRowCell by bytes instead of words.
#pragma pack(push, 1)
#endif


class CharRowCell final
{
public:
Expand All @@ -44,6 +42,7 @@ class CharRowCell final
const wchar_t& Char() const noexcept;

friend constexpr bool operator==(const CharRowCell& a, const CharRowCell& b) noexcept;

private:
wchar_t _wch;
DbcsAttribute _attr;
Expand Down
2 changes: 0 additions & 2 deletions src/buffer/out/CharRowCellReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "UnicodeStorage.hpp"
#include "CharRow.hpp"


// Routine Description:
// - assignment operator. will store extended glyph data in a separate storage location
// Arguments:
Expand Down Expand Up @@ -96,7 +95,6 @@ CharRowCellReference::const_iterator CharRowCellReference::end() const
{
if (_cellData().DbcsAttr().IsGlyphStored())
{

const auto& chars = _parent.GetUnicodeStorage().GetText(_parent.GetStorageKey(_index));
return chars.data() + chars.size();
}
Expand Down
2 changes: 0 additions & 2 deletions src/buffer/out/CharRowCellReference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class CharRow;
class CharRowCellReference final
{
public:

using const_iterator = const wchar_t*;

CharRowCellReference(CharRow& parent, const size_t index) :
Expand All @@ -45,7 +44,6 @@ class CharRowCellReference final
const_iterator begin() const;
const_iterator end() const;


friend bool operator==(const CharRowCellReference& ref, const std::vector<wchar_t>& glyph);
friend bool operator==(const std::vector<wchar_t>& glyph, const CharRowCellReference& ref);

Expand Down
5 changes: 3 additions & 2 deletions src/buffer/out/DbcsAttribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ constexpr bool operator==(const DbcsAttribute& a, const DbcsAttribute& b) noexce
return a._attribute == b._attribute;
}

static_assert(sizeof(DbcsAttribute) == sizeof(BYTE), "DbcsAttribute should be one byte big. if this changes then it needs"
" either an implicit conversion to a BYTE or an update to all places that assume it's a byte big");
static_assert(sizeof(DbcsAttribute) == sizeof(BYTE), "DbcsAttribute should be one byte big. if this changes then it needs "
"either an implicit conversion to a BYTE or an update to all places "
"that assume it's a byte big");
1 change: 0 additions & 1 deletion src/buffer/out/OutputCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ OutputCell::OutputCell() :
_textAttribute{ InvalidTextAttribute },
_behavior{ TextAttributeBehavior::Stored }
{

}

OutputCell::OutputCell(const std::wstring_view charData,
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/out/OutputCell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class OutputCell final
}

private:
// basic_string contains a small storage internally so we don't need
// basic_string contains a small storage internally so we don't need
// to worry about heap allocation for short strings.
std::wstring _text;
std::wstring _text;
DbcsAttribute _dbcsAttribute;
TextAttribute _textAttribute;
TextAttributeBehavior _behavior;
Expand Down
Loading

0 comments on commit 9b92986

Please sign in to comment.