Skip to content

Commit

Permalink
VS2017 support, VS2017 & clang warnings, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Mar 8, 2017
1 parent 3e09a92 commit 45eb228
Show file tree
Hide file tree
Showing 30 changed files with 381 additions and 339 deletions.
15 changes: 7 additions & 8 deletions far/FarDlgBuilder.hpp
Expand Up @@ -108,9 +108,8 @@ struct ListControlBinding: public DialogItemBinding<T>
Поддерживает automation (изменение флагов одного элемента в зависимости от состояния
другого). Реализуется при помощи метода LinkFlags().
*/
class DialogBuilder: noncopyable, public DialogBuilderBase<DialogItemEx>
class DialogBuilder: noncopyable, public base<DialogBuilderBase<DialogItemEx>>
{
using base = DialogBuilderBase<DialogItemEx>;
public:
DialogBuilder(lng TitleMessageId, const wchar_t *HelpTopic = nullptr, Dialog::dialog_handler handler = nullptr);
DialogBuilder();
Expand Down Expand Up @@ -154,30 +153,30 @@ class DialogBuilder: noncopyable, public DialogBuilderBase<DialogItemEx>

void AddRadioButtons(IntOption& Value, int OptionCount, const lng MessageIDs[], bool FocusOnSelected=false);

using base::AddText;
using base_type::AddText;

decltype(auto) AddText(lng LabelId)
{
return base::AddText(static_cast<int>(LabelId));
return base_type::AddText(static_cast<int>(LabelId));
}

decltype(auto) AddTextBefore(DialogItemEx* RelativeTo, lng LabelId)
{
return base::AddTextBefore(RelativeTo, static_cast<int>(LabelId));
return base_type::AddTextBefore(RelativeTo, static_cast<int>(LabelId));
}

using base::AddTextAfter;
using base_type::AddTextAfter;

decltype(auto) AddTextAfter(DialogItemEx* RelativeTo, lng LabelId, int skip = 1)
{
return base::AddTextAfter(RelativeTo, static_cast<int>(LabelId), skip);
return base_type::AddTextAfter(RelativeTo, static_cast<int>(LabelId), skip);
}

using base::AddSeparator;

decltype(auto) AddSeparator(lng LabelId)
{
return base::AddSeparator(static_cast<int>(LabelId));
return base_type::AddSeparator(static_cast<int>(LabelId));
}

// Связывает состояние элементов Parent и Target. Когда Parent->Selected равно
Expand Down
8 changes: 8 additions & 0 deletions far/changelog
@@ -1,3 +1,11 @@
drkns 08.03.2017 17:34:21 +0000 - build 4909

1. VS2017 support.

2. VS2017 & clang warnings.

3. Рефакторинг.

zg 07.03.2017 03:02:10 +0200 - build 4908

1. убрана глобальная переменная WaitInMainLoop.
Expand Down
4 changes: 2 additions & 2 deletions far/cmdline.cpp
Expand Up @@ -82,7 +82,7 @@ CommandLine::CommandLine(window_ptr Owner):
CmdStr(
Owner,
this,
[this](const Manager::Key& Key){ return Global->CtrlObject->Cp()->ProcessKey(Key); },
[](const Manager::Key& Key){ return Global->CtrlObject->Cp()->ProcessKey(Key); },
nullptr,
Global->CtrlObject->CmdHistory.get(),
nullptr,
Expand Down Expand Up @@ -478,7 +478,7 @@ int CommandLine::ProcessKey(const Manager::Key& Key)
// Сбрасываем выделение на некоторых клавишах
if (!Global->Opt->CmdLine.EditBlock)
{
static int UnmarkKeys[]=
static const unsigned int UnmarkKeys[]=
{
KEY_LEFT, KEY_NUMPAD4,
KEY_CTRLS, KEY_RCTRLS,
Expand Down
25 changes: 21 additions & 4 deletions far/common.hpp
Expand Up @@ -199,13 +199,30 @@ constexpr size_t aligned_size(size_t Size, size_t Alignment = MEMORY_ALLOCATION_
return (Size + (Alignment - 1)) & ~(Alignment - 1);
}

template<class T, int Alignment = MEMORY_ALLOCATION_ALIGNMENT>
struct aligned_sizeof
namespace detail
{
enum
template<class T, int Alignment>
struct aligned_sizeof_t
{
value = aligned_size(sizeof(T), Alignment)
enum
{
value = aligned_size(sizeof(T), Alignment)
};
};
}

template<typename T, int Alignment = MEMORY_ALLOCATION_ALIGNMENT>
constexpr auto aligned_sizeof()
{
return detail::aligned_sizeof_t<T, Alignment>::value;
}

template<typename T>
class base: public T
{
protected:
using T::T;
using base_type = base;
};

#endif // COMMON_HPP_1BD5AB87_3379_4AFE_9F63_DB850DCF72B4
1 change: 1 addition & 0 deletions far/common/zip_view.hpp
Expand Up @@ -94,6 +94,7 @@ class zip_iterator:
auto operator==(const zip_iterator& rhs) const { return m_Tuple == rhs.m_Tuple; }
auto operator<(const zip_iterator& rhs) const { return m_Tuple < rhs.m_Tuple; }
auto operator*() const { return detail::traits<args...>::dereference(m_Tuple); }
auto operator-(const zip_iterator& rhs) const { return std::get<0>(m_Tuple) - std::get<0>(rhs.m_Tuple); }

private:
typename zip_iterator::pointer m_Tuple;
Expand Down
21 changes: 6 additions & 15 deletions far/components.cpp
Expand Up @@ -50,14 +50,6 @@ namespace components
GetComponentsList().add(this);
}

components_list::components_list():
list(),
ptr(),
enum_ptr(),
m_size()
{
}

void components_list::add(component* item)
{
if (!list)
Expand All @@ -78,13 +70,12 @@ namespace components
if (!index)
enum_ptr = list;

if (enum_ptr)
{
value = enum_ptr->m_getInfo;
enum_ptr = enum_ptr->m_next;
return true;
}
return false;
if (!enum_ptr)
return false;

value = enum_ptr->m_getInfo;
enum_ptr = enum_ptr->m_next;
return true;
}

std::map<string, string>& GetComponentsInfo()
Expand Down
10 changes: 5 additions & 5 deletions far/components.hpp
Expand Up @@ -65,12 +65,12 @@ namespace components

bool get(size_t index, value_type& value) const;

components_list();
components_list() = default;

component* list;
component* ptr;
mutable component* enum_ptr;
size_t m_size;
component* list{};
component* ptr{};
mutable component* enum_ptr{};
size_t m_size{};
};

std::map<string, string>& GetComponentsInfo();
Expand Down
40 changes: 21 additions & 19 deletions far/configdb.cpp
Expand Up @@ -2149,7 +2149,7 @@ void config_provider::CheckDatabase(SQLiteDb *pDb)
}
}

void config_provider::TryImportDatabase(representable *p, const char *son, bool plugin)
void config_provider::TryImportDatabase(representable* p, const char* NodeName, bool IsPlugin)
{
if (!m_TemplateSource && !Global->Opt->TemplateProfilePath.empty())
{
Expand All @@ -2160,21 +2160,21 @@ void config_provider::TryImportDatabase(representable *p, const char *son, bool
{
auto root = m_TemplateSource->GetRoot();

if (!son)
if (!NodeName)
{
p->Import(*m_TemplateSource);
}
else if (!plugin)
else if (!IsPlugin)
{
m_TemplateSource->SetRoot(root.FirstChildElement(son));
m_TemplateSource->SetRoot(root.FirstChildElement(NodeName));
p->Import(*m_TemplateSource);
}
else
{
for (const auto& i: xml_enum(root.FirstChildElement("pluginsconfig"), "plugin"))
{
const auto guid = i->Attribute("guid");
if (guid && 0 == strcmp(guid, son))
if (guid && 0 == strcmp(guid, NodeName))
{
m_TemplateSource->SetRoot(&const_cast<tinyxml::XMLElement&>(*i));
p->Import(*m_TemplateSource);
Expand All @@ -2187,31 +2187,33 @@ void config_provider::TryImportDatabase(representable *p, const char *son, bool
}

template<class T>
std::unique_ptr<T> config_provider::CreateDatabase(const char *son)
void config_provider::CheckAndImportDatabase(T* Database, const char* ImportNodeName, bool IsPlugin)
{
auto cfg = std::make_unique<T>();
CheckDatabase(cfg.get());
if (m_Mode != mode::m_import && cfg->IsNew())
CheckDatabase(Database);
if (m_Mode != mode::m_import && Database->IsNew())
{
TryImportDatabase(cfg.get(), son);
TryImportDatabase(Database, ImportNodeName, IsPlugin);
}
return cfg;
}

template<class T>
HierarchicalConfigUniquePtr config_provider::CreateHierarchicalConfig(dbcheck DbId, const string& dbn, const char *xmln, bool Local, bool plugin)
std::unique_ptr<T> config_provider::CreateDatabase()
{
auto cfg = std::make_unique<T>(dbn, Local);
auto Database = std::make_unique<T>();
CheckAndImportDatabase(Database.get(), nullptr, false);
return Database;
}

template<class T>
HierarchicalConfigUniquePtr config_provider::CreateHierarchicalConfig(dbcheck DbId, const string& DbName, const char* ImportNodeName, bool IsLocal, bool IsPlugin)
{
auto Database = std::make_unique<T>(DbName, IsLocal);
if (!m_CheckedDb.Check(DbId))
{
CheckDatabase(cfg.get());
if (m_Mode != mode::m_import && cfg->IsNew())
{
TryImportDatabase(cfg.get(), xmln, plugin);
}
CheckAndImportDatabase(Database.get(), ImportNodeName, IsPlugin);
m_CheckedDb.Set(DbId);
}
return HierarchicalConfigUniquePtr(cfg.release());
return HierarchicalConfigUniquePtr(Database.release());
}

enum dbcheck: int
Expand Down
7 changes: 4 additions & 3 deletions far/configdb.hpp
Expand Up @@ -385,11 +385,12 @@ class config_provider: noncopyable
HierarchicalConfigUniquePtr CreatePanelModeConfig();

private:
template<class T> HierarchicalConfigUniquePtr CreateHierarchicalConfig(dbcheck DbId, const string& dbn, const char *xmln, bool Local = false, bool plugin = false);
template<class T> std::unique_ptr<T> CreateDatabase(const char *son = nullptr);
template<class T> void CheckAndImportDatabase(T* Database, const char* ImportNodeName, bool IsPlugin);
template<class T> std::unique_ptr<T> CreateDatabase();
template<class T> HierarchicalConfigUniquePtr CreateHierarchicalConfig(dbcheck DbId, const string& DbName, const char* ImportNodeName, bool IsLocal = false, bool IsPlugin = false);
bool Import(const string& File);
bool Export(const string& File);
void TryImportDatabase(representable *p, const char *son = nullptr, bool plugin=false);
void TryImportDatabase(representable* p, const char* NodeName = nullptr, bool IsPlugin = false);
void CheckDatabase(class SQLiteDb *pDb);

int m_LoadResult;
Expand Down
14 changes: 4 additions & 10 deletions far/copy.cpp
Expand Up @@ -1200,12 +1200,9 @@ ShellCopy::ShellCopy(panel_ptr SrcPanel, // исходная панель (
// Позаботимся о дизах.
if (!(Flags&FCOPY_COPYTONUL) && !strDestDizPath.empty())
{
const auto Attr = os::GetFileAttributes(DestDiz.GetDizName());
int DestReadOnly=(Attr!=INVALID_FILE_ATTRIBUTES && (Attr & FILE_ATTRIBUTE_READONLY));

if (LastIteration) // Скидываем только во время последней Op.
if (Move && !DestReadOnly)
SrcPanel->FlushDiz();
// Скидываем только во время последней Op.
if (LastIteration && Move && !os::fs::file_status(DestDiz.GetDizName()).check(FILE_ATTRIBUTE_READONLY))
SrcPanel->FlushDiz();

DestDiz.Flush(strDestDizPath);
}
Expand All @@ -1222,10 +1219,7 @@ ShellCopy::ShellCopy(panel_ptr SrcPanel, // исходная панель (
{ // равно нужно апдейтить дизы!
if (!(Flags&FCOPY_COPYTONUL) && !strDestDizPath.empty())
{
const auto Attr = os::GetFileAttributes(DestDiz.GetDizName());
int DestReadOnly=(Attr!=INVALID_FILE_ATTRIBUTES && (Attr & FILE_ATTRIBUTE_READONLY));

if (Move && !DestReadOnly)
if (Move && !os::fs::file_status(DestDiz.GetDizName()).check(FILE_ATTRIBUTE_READONLY))
SrcPanel->FlushDiz();

DestDiz.Flush(strDestDizPath);
Expand Down
4 changes: 2 additions & 2 deletions far/dialog.cpp
Expand Up @@ -194,15 +194,15 @@ size_t ItemStringAndSize(const DialogItemEx *Data,string& ItemString)

static size_t ConvertItemEx2(const DialogItemEx *ItemEx, FarGetDialogItem *Item)
{
size_t size = aligned_sizeof<FarDialogItem>::value, offsetList = size, offsetListItems = size;
size_t size = aligned_sizeof<FarDialogItem>(), offsetList = size, offsetListItems = size;
vmenu_ptr ListBox;
size_t ListBoxSize = 0;
if (ItemEx->Type==DI_LISTBOX || ItemEx->Type==DI_COMBOBOX)
{
ListBox=ItemEx->ListPtr;
if (ListBox)
{
size += aligned_sizeof<FarList>::value;
size += aligned_sizeof<FarList>();
offsetListItems=size;
ListBoxSize=ListBox->size();
size+=ListBoxSize*sizeof(FarListItem);
Expand Down
2 changes: 2 additions & 0 deletions far/disabled_warnings.hpp
Expand Up @@ -39,7 +39,9 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma warning(disable: 4091) // https://msdn.microsoft.com/en-us/library/eehkcz60.aspx 'typedef ': ignored on left of 'type' when no variable is declared
#pragma warning(disable: 4265) // https://msdn.microsoft.com/en-us/library/wzxffy8c.aspx 'class' : class has virtual functions, but destructor is not virtual
#pragma warning(disable: 4668) // https://msdn.microsoft.com/en-us/library/4dt9kyhy.aspx 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
#pragma warning(disable: 4774) // no page 'function' : format string expected in argument 'number' is not a string literal
#pragma warning(disable: 4917) // https://msdn.microsoft.com/en-us/library/3w98z1xh.aspx 'declarator' : a GUID can only be associated with a class, interface or namespace
#pragma warning(disable: 4987) // no page nonstandard extension used: 'throw (...)'
#pragma warning(disable: 4996) // https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx The compiler encountered a deprecated declaration
#else
// these in the rest of the code as well
Expand Down
4 changes: 2 additions & 2 deletions far/editor.cpp
Expand Up @@ -816,7 +816,7 @@ bool Editor::ProcessKeyInternal(const Manager::Key& Key, bool& Refresh)

if (!EdOpt.PersistentBlocks)
{
static int UnmarkKeys[]=
static const unsigned int UnmarkKeys[]=
{
KEY_LEFT, KEY_NUMPAD4,
KEY_RIGHT, KEY_NUMPAD6,
Expand Down Expand Up @@ -6801,7 +6801,7 @@ Editor::numbered_iterator Editor::InsertString(const wchar_t* Str, int nLength,
const auto NewLine = numbered_iterator(Lines.emplace(Where, GetOwner()), Where.Number());
m_LinesCount++;

const auto& UpdateIterator = [&NewLine, &Where](numbered_iterator& What)
const auto& UpdateIterator = [&Where](numbered_iterator& What)
{
if (What.Number() >= Where.Number())
{
Expand Down
2 changes: 1 addition & 1 deletion far/encoding.cpp
Expand Up @@ -41,7 +41,7 @@ class installed_codepages
{
public:
installed_codepages();
const cp_map& get() const { return m_InstalledCp; }
const auto& get() const { return m_InstalledCp; }

private:
void insert(UINT Codepage, UINT MaxCharSize, const string& Name)
Expand Down
2 changes: 1 addition & 1 deletion far/execute.cpp
Expand Up @@ -854,7 +854,7 @@ void Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
seInfo.lpParameters = strNewCmdPar.data();
}

const auto& GetVerb = [&Verb](const string& Str)
const auto& GetVerb = [](const string& Str)
{
DWORD DummyError;
string DummyString;
Expand Down
1 change: 1 addition & 0 deletions far/far.vcxproj
Expand Up @@ -30,6 +30,7 @@
</PropertyGroup>
<PropertyGroup>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
8 changes: 8 additions & 0 deletions far/farexcpt.hpp
Expand Up @@ -55,6 +55,11 @@ auto seh_invoke(function&& Callable, filter&& Filter, handler&& Handler)
// GCC doesn't support these currently
return Callable();
#else
#if COMPILER == C_CLANG
// Workaround for clang "filter expression type should be an integral value" error
std::function<DWORD(DWORD, EXCEPTION_POINTERS*)> FilterWrapper = Filter;
#define Filter FilterWrapper
#endif
__try
{
return Callable();
Expand All @@ -66,6 +71,9 @@ auto seh_invoke(function&& Callable, filter&& Filter, handler&& Handler)
ResetStackOverflowIfNeeded();
return Handler();
}
#if COMPILER == C_CLANG
#undef Filter
#endif
#endif
}

Expand Down

0 comments on commit 45eb228

Please sign in to comment.