Skip to content

Commit 400653c

Browse files
Copilotwravery
andauthored
Adapt nullable input fix to next
Co-authored-by: wravery <6502881+wravery@users.noreply.github.com>
1 parent e55df33 commit 400653c

7 files changed

Lines changed: 33 additions & 31 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎.github/workflows/linux.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-24.04
1414

1515
steps:
16-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16+
- uses: actions/checkout@v4.1.3
1717
with:
1818
submodules: true
1919

‎.github/workflows/macos.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
runs-on: macos-latest
1313

1414
steps:
15-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
15+
- uses: actions/checkout@v4.1.3
1616
with:
1717
submodules: true
1818
fetch-depth: 0
1919

2020
- name: Cache vcpkg
21-
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
21+
uses: actions/cache@v4.0.2
2222
id: cache-vcpkg
2323
with:
2424
path: build/vcpkg_cache/

‎.github/workflows/windows.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
libs: ['shared', 'static']
1212
config: ['Debug', 'Release']
1313

14-
runs-on: windows-2022
14+
runs-on: windows-latest
1515

1616
steps:
17-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
17+
- uses: actions/checkout@v4.1.3
1818
with:
1919
submodules: true
2020
fetch-depth: 0
@@ -25,7 +25,7 @@ jobs:
2525
run: echo "vcpkg_triplet=${{ matrix.arch }}-windows$(if ('${{ matrix.libs }}' -eq 'static') { '-static' })" >> $env:GITHUB_OUTPUT
2626

2727
- name: Cache vcpkg
28-
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
28+
uses: actions/cache@v4.0.2
2929
id: cache-vcpkg
3030
with:
3131
path: build/vcpkg_cache/

‎include/SchemaGenerator.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class [[nodiscard("unnecessary construction")]] Generator
8181
std::size_t level, const response::Value& defaultValue) const noexcept;
8282
[[nodiscard("unnecessary memory copy")]] std::string getArgumentDeclaration(
8383
const InputField& argument, const char* prefixToken, const char* argumentsToken,
84-
const char* defaultToken) const noexcept;
84+
const char* defaultToken, bool useOptional) const noexcept;
8585
[[nodiscard("unnecessary memory copy")]] std::string getArgumentAccessType(
86-
const InputField& argument) const noexcept;
86+
const InputField& argument, bool useOptional) const noexcept;
8787
[[nodiscard("unnecessary memory copy")]] std::string getResultAccessType(
8888
const OutputField& result) const noexcept;
8989
[[nodiscard("unnecessary memory copy")]] std::string getTypeModifiers(

‎include/SchemaLoader.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ class [[nodiscard("unnecessary construction")]] SchemaLoader
264264
std::string_view type) const noexcept;
265265
[[nodiscard("unnecessary memory copy")]] std::string getInputCppType(
266266
const InputField& field) const noexcept;
267+
[[nodiscard("unnecessary memory copy")]] std::string getArgumentCppType(
268+
const InputField& field) const noexcept;
267269
[[nodiscard("unnecessary memory copy")]] std::string getOutputCppType(
268270
const OutputField& field) const noexcept;
269271

@@ -276,6 +278,9 @@ class [[nodiscard("unnecessary construction")]] SchemaLoader
276278
const InputField& field) noexcept;
277279

278280
private:
281+
[[nodiscard("unnecessary memory copy")]] std::string getArgumentCppType(
282+
const InputField& field, bool useOptional) const noexcept;
283+
279284
[[nodiscard("unnecessary call")]] static bool isExtension(
280285
const peg::ast_node& definition) noexcept;
281286

‎src/SchemaGenerator.cpp‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ concept )cpp" << accessorName
11601160
<< R"cpp(WithParams = requires (TImpl impl, service::FieldParams params)cpp";
11611161
for (const auto& argument : outputField.arguments)
11621162
{
1163-
headerFile << R"cpp(, )cpp" << _loader.getInputCppType(argument) << R"cpp( )cpp"
1163+
headerFile << R"cpp(, )cpp" << _loader.getArgumentCppType(argument) << R"cpp( )cpp"
11641164
<< argument.cppName << R"cpp(Arg)cpp";
11651165
}
11661166

@@ -1182,7 +1182,7 @@ concept )cpp" << accessorName
11821182
<< R"cpp( = requires (TImpl impl)cpp";
11831183
for (const auto& argument : outputField.arguments)
11841184
{
1185-
headerFile << R"cpp(, )cpp" << _loader.getInputCppType(argument) << R"cpp( )cpp"
1185+
headerFile << R"cpp(, )cpp" << _loader.getArgumentCppType(argument) << R"cpp( )cpp"
11861186
<< argument.cppName << R"cpp(Arg)cpp";
11871187
}
11881188

@@ -1332,7 +1332,7 @@ void Generator::outputObjectDeclaration(std::ostream& headerFile, const ObjectTy
13321332
headerFile << R"cpp(, )cpp";
13331333
}
13341334

1335-
headerFile << _loader.getInputCppType(argument) << R"cpp(&& )cpp" << argument.cppName
1335+
headerFile << _loader.getArgumentCppType(argument) << R"cpp(&& )cpp" << argument.cppName
13361336
<< R"cpp(Arg)cpp";
13371337
firstArgument = false;
13381338
}
@@ -1585,7 +1585,7 @@ std::string Generator::getFieldDeclaration(const OutputField& outputField) const
15851585
output << R"cpp(, )cpp";
15861586
}
15871587

1588-
output << _loader.getInputCppType(argument) << R"cpp(&& )cpp" << argument.cppName << "Arg";
1588+
output << _loader.getArgumentCppType(argument) << R"cpp(&& )cpp" << argument.cppName << "Arg";
15891589
firstArgument = false;
15901590
}
15911591

@@ -1778,7 +1778,8 @@ void Result<)cpp" << _loader.getSchemaNamespace()
17781778

17791779
for (const auto& inputField : inputType.fields)
17801780
{
1781-
sourceFile << getArgumentDeclaration(inputField, "value", "value", "defaultValue");
1781+
sourceFile
1782+
<< getArgumentDeclaration(inputField, "value", "value", "defaultValue", false);
17821783
}
17831784

17841785
if (!inputType.fields.empty())
@@ -2841,7 +2842,8 @@ service::AwaitableResolver )cpp"
28412842
sourceFile << getArgumentDeclaration(argument,
28422843
"arg",
28432844
"params.arguments",
2844-
"defaultArguments");
2845+
"defaultArguments",
2846+
true);
28452847
}
28462848
}
28472849

@@ -3208,7 +3210,7 @@ std::string Generator::getArgumentDefaultValue(
32083210
}
32093211

32103212
std::string Generator::getArgumentDeclaration(const InputField& argument, const char* prefixToken,
3211-
const char* argumentsToken, const char* defaultToken) const noexcept
3213+
const char* argumentsToken, const char* defaultToken, bool useOptional) const noexcept
32123214
{
32133215
std::ostringstream argumentDeclaration;
32143216
std::string argumentName(argument.cppName);
@@ -3217,15 +3219,15 @@ std::string Generator::getArgumentDeclaration(const InputField& argument, const
32173219
if (argument.defaultValue.type() == response::Type::Null)
32183220
{
32193221
argumentDeclaration << R"cpp( auto )cpp" << prefixToken << argumentName << R"cpp( = )cpp"
3220-
<< getArgumentAccessType(argument) << R"cpp(::require)cpp"
3222+
<< getArgumentAccessType(argument, useOptional) << R"cpp(::require)cpp"
32213223
<< getTypeModifiers(argument.modifiers) << R"cpp((")cpp"
32223224
<< argument.name << R"cpp(", )cpp" << argumentsToken << R"cpp();
32233225
)cpp";
32243226
}
32253227
else
32263228
{
32273229
argumentDeclaration << R"cpp( auto pair)cpp" << argumentName << R"cpp( = )cpp"
3228-
<< getArgumentAccessType(argument) << R"cpp(::find)cpp"
3230+
<< getArgumentAccessType(argument, useOptional) << R"cpp(::find)cpp"
32293231
<< getTypeModifiers(argument.modifiers) << R"cpp((")cpp"
32303232
<< argument.name << R"cpp(", )cpp" << argumentsToken << R"cpp();
32313233
auto )cpp" << prefixToken
@@ -3247,7 +3249,7 @@ std::string Generator::getArgumentDeclaration(const InputField& argument, const
32473249
}
32483250

32493251
argumentDeclaration << R"cpp(
3250-
: )cpp" << getArgumentAccessType(argument)
3252+
: )cpp" << getArgumentAccessType(argument, useOptional)
32513253
<< R"cpp(::require)cpp" << getTypeModifiers(argument.modifiers)
32523254
<< R"cpp((")cpp" << argument.name << R"cpp(", )cpp" << defaultToken
32533255
<< R"cpp());
@@ -3257,9 +3259,15 @@ std::string Generator::getArgumentDeclaration(const InputField& argument, const
32573259
return argumentDeclaration.str();
32583260
}
32593261

3260-
std::string Generator::getArgumentAccessType(const InputField& argument) const noexcept
3262+
std::string Generator::getArgumentAccessType(
3263+
const InputField& argument, bool useOptional) const noexcept
32613264
{
32623265
std::ostringstream argumentType;
3266+
const bool optionalInput = useOptional && argument.fieldType == InputFieldType::Input
3267+
&& std::find(argument.modifiers.cbegin(),
3268+
argument.modifiers.cend(),
3269+
service::TypeModifier::Nullable)
3270+
!= argument.modifiers.cend();
32633271

32643272
argumentType << R"cpp(service::ModifiedArgument<)cpp";
32653273

@@ -3280,7 +3288,7 @@ std::string Generator::getArgumentAccessType(const InputField& argument) const n
32803288
break;
32813289
}
32823290

3283-
argumentType << R"cpp(>)cpp";
3291+
argumentType << (optionalInput ? R"cpp(, true>)cpp" : R"cpp(>)cpp");
32843292

32853293
return argumentType.str();
32863294
}

0 commit comments

Comments
 (0)