Skip to content

Commit 96a5706

Browse files
committed
Add workarounds for IntelliSense parsing
IntelliSense fails to read some header units. Add some workarounds to assist IntelliSense to parse the code correctly.
1 parent eeedcad commit 96a5706

13 files changed

+115
-129
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ indent_style = space
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
1212

13+
# Spell checker configuration
14+
spelling_exclusion_path = spelling.dic
15+
1316
[*.{h,cpp,ixx}]
1417
end_of_line = crlf
1518
indent_size = 4

Directory.Build.props

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
<UseFullPaths>true</UseFullPaths>
4040
<ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel>
4141

42+
<!-- Enables recommended Security Development Lifecycle (SDL) checks.
43+
These checks change security-relevant warnings into errors, and set additional secure code-generation features. -->
44+
<SDLCheck>true</SDLCheck>
45+
4246
<!-- For development purposes, All warnings can be used to discover useful compiler warnings.
4347
This requires also that some warnings need to be disabled from this all warning list. -->
4448
<WarningLevel Condition="'$(NETPBM_WIC_CODEC_ALL_WARNINGS)'!=''">EnableAllWarnings</WarningLevel>

spelling.dic

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+

2+
hkey

src/errors.ixx

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) Victor Derks.
22
// SPDX-License-Identifier: MIT
33

4+
module;
5+
6+
#include "macros.h"
7+
48
export module errors;
59

610
import <win.h>;

src/macros.h

+10
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@
4242
// Use std::format directly to get compile time checking of the string arguments.
4343
#define TRACE(fmt, ...) OutputDebugStringA(std::format(fmt __VA_OPT__(,) __VA_ARGS__).c_str())
4444
#endif
45+
46+
// Include sal.h as workaround that IntelliSense in VS 2020 17.9 fails to parse #import <win.h>
47+
#ifdef __INTELLISENSE__
48+
#define _AMD64_
49+
#include <sal.h>
50+
#include <winreg.h>
51+
#include <libloaderapi.h>
52+
#include <combaseapi.h>
53+
#include <cassert>
54+
#endif

src/netpbm-wic-codec.vcxproj

-6
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
</ItemDefinitionGroup>
114114
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
115115
<ClCompile>
116-
<SDLCheck>true</SDLCheck>
117116
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118117
</ClCompile>
119118
<Link>
@@ -127,7 +126,6 @@
127126
<ClCompile>
128127
<FunctionLevelLinking>true</FunctionLevelLinking>
129128
<IntrinsicFunctions>true</IntrinsicFunctions>
130-
<SDLCheck>true</SDLCheck>
131129
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132130
</ClCompile>
133131
<Link>
@@ -141,7 +139,6 @@
141139
</ItemDefinitionGroup>
142140
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
143141
<ClCompile>
144-
<SDLCheck>true</SDLCheck>
145142
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
146143
<AdditionalOptions>/FS %(AdditionalOptions)</AdditionalOptions>
147144
</ClCompile>
@@ -154,7 +151,6 @@
154151
</ItemDefinitionGroup>
155152
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
156153
<ClCompile>
157-
<SDLCheck>true</SDLCheck>
158154
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
159155
</ClCompile>
160156
<Link>
@@ -168,7 +164,6 @@
168164
<ClCompile>
169165
<FunctionLevelLinking>true</FunctionLevelLinking>
170166
<IntrinsicFunctions>true</IntrinsicFunctions>
171-
<SDLCheck>true</SDLCheck>
172167
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
173168
<AdditionalOptions>/FS %(AdditionalOptions)</AdditionalOptions>
174169
</ClCompile>
@@ -185,7 +180,6 @@
185180
<ClCompile>
186181
<FunctionLevelLinking>true</FunctionLevelLinking>
187182
<IntrinsicFunctions>true</IntrinsicFunctions>
188-
<SDLCheck>true</SDLCheck>
189183
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
190184
</ClCompile>
191185
<Link>

src/netpbm_bitmap_frame_decode.ixx

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) Victor Derks.
22
// SPDX-License-Identifier: MIT
33

4+
module;
5+
6+
#include "macros.h"
7+
48
export module netpbm_bitmap_frame_decode;
59

610
import <std.h>;

src/pnm_header.ixx

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) Victor Derks.
22
// SPDX-License-Identifier: MIT
33

4+
module;
5+
6+
#include "macros.h"
7+
48
export module pnm_header;
59

610
import <std.h>;

src/util.ixx

+80-83
Original file line numberDiff line numberDiff line change
@@ -16,118 +16,115 @@ import errors;
1616
[[nodiscard]] HMODULE get_current_module() noexcept
1717
{
1818
HMODULE module;
19-
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
20-
reinterpret_cast<PCTSTR>(get_current_module), &module);
19+
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
20+
reinterpret_cast<PCWSTR>(get_current_module), &module);
2121

2222
return module;
2323
}
2424

25-
export
25+
export constexpr std::byte operator"" _byte(const unsigned long long int n)
2626
{
27-
constexpr std::byte operator"" _byte(const unsigned long long int n)
28-
{
29-
return static_cast<std::byte>(n);
30-
}
31-
32-
33-
[[nodiscard]] inline const char* pixel_format_to_string(const GUID& guid) noexcept
34-
{
35-
if (guid == GUID_WICPixelFormat2bppGray)
36-
return "GUID_WICPixelFormat2bppGray";
27+
return static_cast<std::byte>(n);
28+
}
3729

38-
if (guid == GUID_WICPixelFormat4bppGray)
39-
return "GUID_WICPixelFormat4bppGray";
4030

41-
if (guid == GUID_WICPixelFormat8bppGray)
42-
return "GUID_WICPixelFormat8bppGray";
31+
export [[nodiscard]] inline const char* pixel_format_to_string(const GUID& guid) noexcept
32+
{
33+
if (guid == GUID_WICPixelFormat2bppGray)
34+
return "GUID_WICPixelFormat2bppGray";
4335

44-
if (guid == GUID_WICPixelFormat16bppGray)
45-
return "GUID_WICPixelFormat16bppGray";
36+
if (guid == GUID_WICPixelFormat4bppGray)
37+
return "GUID_WICPixelFormat4bppGray";
4638

47-
if (guid == GUID_WICPixelFormat24bppRGB)
48-
return "GUID_WICPixelFormat24bppRGB";
39+
if (guid == GUID_WICPixelFormat8bppGray)
40+
return "GUID_WICPixelFormat8bppGray";
4941

50-
if (guid == GUID_WICPixelFormat48bppRGB)
51-
return "GUID_WICPixelFormat48bppRGB";
42+
if (guid == GUID_WICPixelFormat16bppGray)
43+
return "GUID_WICPixelFormat16bppGray";
5244

53-
return "Unknown";
54-
}
55-
56-
[[nodiscard]] inline std::wstring guid_to_string(const GUID& guid)
57-
{
58-
std::wstring guid_text;
45+
if (guid == GUID_WICPixelFormat24bppRGB)
46+
return "GUID_WICPixelFormat24bppRGB";
5947

60-
guid_text.resize(39);
61-
VERIFY(StringFromGUID2(guid, guid_text.data(), static_cast<int>(guid_text.size())) != 0);
48+
if (guid == GUID_WICPixelFormat48bppRGB)
49+
return "GUID_WICPixelFormat48bppRGB";
6250

63-
// Remove the double null terminator.
64-
guid_text.resize(guid_text.size() - 1);
51+
return "Unknown";
52+
}
6553

66-
return guid_text;
67-
}
54+
export [[nodiscard]] inline std::wstring guid_to_string(const GUID& guid)
55+
{
56+
std::wstring guid_text;
6857

69-
[[nodiscard]] inline std::wstring get_module_path()
70-
{
71-
std::wstring path(100, L'?');
72-
size_t path_size;
73-
size_t actual_size;
58+
guid_text.resize(39);
59+
VERIFY(StringFromGUID2(guid, guid_text.data(), static_cast<int>(guid_text.size())) != 0);
7460

75-
do
76-
{
77-
path_size = path.size();
78-
actual_size = ::GetModuleFileName(get_current_module(), path.data(), static_cast<DWORD>(path_size));
61+
// Remove the double null terminator.
62+
guid_text.resize(guid_text.size() - 1);
7963

80-
if (actual_size + 1 > path_size)
81-
{
82-
path.resize(path_size * 2, L'?');
83-
}
84-
} while (actual_size + 1 > path_size);
64+
return guid_text;
65+
}
8566

86-
path.resize(actual_size);
87-
return path;
88-
}
67+
export [[nodiscard]] inline std::wstring get_module_path()
68+
{
69+
std::wstring path(100, L'?');
70+
size_t path_size;
71+
size_t actual_size;
8972

90-
template<>
91-
struct std::formatter<winrt::hresult> : std::formatter<int32_t>
73+
do
9274
{
93-
auto format(const winrt::hresult& result, std::format_context& ctx) const
75+
path_size = path.size();
76+
actual_size = ::GetModuleFileName(get_current_module(), path.data(), static_cast<DWORD>(path_size));
77+
78+
if (actual_size + 1 > path_size)
9479
{
95-
return std::formatter<int32_t>::format(result.value, ctx);
80+
path.resize(path_size * 2, L'?');
9681
}
97-
};
82+
} while (actual_size + 1 > path_size);
9883

99-
inline void check_hresult(const winrt::hresult result, const winrt::hresult result_to_throw)
100-
{
101-
if (result < 0)
102-
throw_hresult(result_to_throw);
103-
}
84+
path.resize(actual_size);
85+
return path;
86+
}
10487

105-
[[nodiscard]] constexpr bool failed(const winrt::hresult result) noexcept
88+
export template<>
89+
struct std::formatter<winrt::hresult> : std::formatter<int32_t>
90+
{
91+
auto format(const winrt::hresult& result, std::format_context& ctx) const
10692
{
107-
return result < 0;
93+
return std::formatter<int32_t>::format(result.value, ctx);
10894
}
95+
};
10996

110-
template<typename T>
111-
T* check_in_pointer(_In_ T * pointer)
112-
{
113-
if (!pointer)
114-
winrt::throw_hresult(error_invalid_argument);
97+
export inline void check_hresult(const winrt::hresult result, const winrt::hresult result_to_throw)
98+
{
99+
if (result < 0)
100+
throw_hresult(result_to_throw);
101+
}
115102

116-
return pointer;
117-
}
103+
export [[nodiscard]] constexpr bool failed(const winrt::hresult result) noexcept
104+
{
105+
return result < 0;
106+
}
118107

119-
template<typename T>
120-
T* check_out_pointer(T * pointer)
121-
{
122-
if (!pointer)
123-
winrt::throw_hresult(error_pointer);
108+
export template<typename T>
109+
T* check_in_pointer(_In_ T* pointer)
110+
{
111+
if (!pointer)
112+
winrt::throw_hresult(error_invalid_argument);
124113

125-
return pointer;
126-
}
114+
return pointer;
115+
}
127116

128-
inline void check_condition(const bool condition, const winrt::hresult result_to_throw)
129-
{
130-
if (!condition)
131-
throw_hresult(result_to_throw);
132-
}
117+
export template<typename T>
118+
T* check_out_pointer(T* pointer)
119+
{
120+
if (!pointer)
121+
winrt::throw_hresult(error_pointer);
122+
123+
return pointer;
124+
}
125+
126+
export inline void check_condition(const bool condition, const winrt::hresult result_to_throw)
127+
{
128+
if (!condition)
129+
throw_hresult(result_to_throw);
133130
}

std-header-units/generate_header_units.cpp

-28
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,3 @@
33

44
import "std.h";
55
import "win.h";
6-
7-
import <vector>;
8-
import <fstream>;
9-
import <ios>;
10-
import <sstream>;
11-
import <string>;
12-
import <array>;
13-
import <algorithm>;
14-
import <bit>;
15-
import <mutex>;
16-
import <span>;
17-
import <cstdint>;
18-
import <cstdio>;
19-
import <cstddef>;
20-
import <cassert>;
21-
import <utility>;
22-
import <chrono>;
23-
import <format>;
24-
25-
import <Shlwapi.h>;
26-
import <Unknwn.h>;
27-
import <objidl.h>;
28-
import <winerror.h>;
29-
import <wincodec.h>;
30-
import <Windows.h>;
31-
import <olectl.h>;
32-
import <ShlObj.h>;
33-
import <guiddef.h>;

std-header-units/std-header-units.vcxproj

-6
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
</PropertyGroup>
103103
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
104104
<ClCompile>
105-
<SDLCheck>true</SDLCheck>
106105
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107106
<ScanSourceForModuleDependencies>true</ScanSourceForModuleDependencies>
108107
</ClCompile>
@@ -114,7 +113,6 @@
114113
<ClCompile>
115114
<FunctionLevelLinking>true</FunctionLevelLinking>
116115
<IntrinsicFunctions>true</IntrinsicFunctions>
117-
<SDLCheck>true</SDLCheck>
118116
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
119117
<ScanSourceForModuleDependencies>true</ScanSourceForModuleDependencies>
120118
</ClCompile>
@@ -126,7 +124,6 @@
126124
</ItemDefinitionGroup>
127125
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
128126
<ClCompile>
129-
<SDLCheck>true</SDLCheck>
130127
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
131128
<ScanSourceForModuleDependencies>true</ScanSourceForModuleDependencies>
132129
</ClCompile>
@@ -136,7 +133,6 @@
136133
</ItemDefinitionGroup>
137134
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
138135
<ClCompile>
139-
<SDLCheck>true</SDLCheck>
140136
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
141137
<ScanSourceForModuleDependencies>true</ScanSourceForModuleDependencies>
142138
</ClCompile>
@@ -148,7 +144,6 @@
148144
<ClCompile>
149145
<FunctionLevelLinking>true</FunctionLevelLinking>
150146
<IntrinsicFunctions>true</IntrinsicFunctions>
151-
<SDLCheck>true</SDLCheck>
152147
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
153148
<ScanSourceForModuleDependencies>true</ScanSourceForModuleDependencies>
154149
</ClCompile>
@@ -162,7 +157,6 @@
162157
<ClCompile>
163158
<FunctionLevelLinking>true</FunctionLevelLinking>
164159
<IntrinsicFunctions>true</IntrinsicFunctions>
165-
<SDLCheck>true</SDLCheck>
166160
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
167161
<ScanSourceForModuleDependencies>true</ScanSourceForModuleDependencies>
168162
</ClCompile>

0 commit comments

Comments
 (0)