Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed clang warnings in generated C++ code #2201

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class CppAssembleMethodGenerator(private val reactor: Reactor) {

private fun Connection.getConnectionLambda(portType: String): String {
return """
[this]($portType left, $portType right) {
[&]($portType left, $portType right) {
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
left->environment()->draw_connection(left, right, $properties);
}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ class CppParameterGenerator(private val reactor: Reactor) {
* This is required for some code bodies (e.g. target code in parameter initializers) to have access to the local parameters.
*/
fun generateOuterAliasDeclarations() =
reactor.parameters.joinToString(separator = "") { "const typename Parameters::${it.typeAlias}& ${it.name} = __lf_inner.${it.name};\n" }
reactor.parameters.joinToString(prefix = "// parameter aliases for use in the outer scope\n", separator = "") {
"[[maybe_unused]] const typename Parameters::${it.typeAlias}& ${it.name} = __lf_inner.${it.name};\n"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi
${" | "..reactions.generateReactionViewForwardDeclarations()}
|
| class Inner: public lfutil::LFScope {
| const Inner& __lf_inner = *this;
| const Parameters __lf_parameters;
| [[maybe_unused]] const Inner& __lf_inner = *this;
| [[maybe_unused]] const Parameters __lf_parameters;
${" | "..parameters.generateInnerAliasDeclarations()}
${" | "..state.generateDeclarations()}
${" | "..methods.generateDeclarations()}
Expand Down
42 changes: 42 additions & 0 deletions test/Cpp/src/multiport/MultiportToMultiportAfterParameterized.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Test multiport to multiport connections. See also MultiportToMultiport.
target Cpp

reactor Source(width: size_t = 2) {
output[width] out: size_t

reaction(startup) -> out {=
for (size_t i = 0; i < out.size(); i++) {
out[i].set(i);
}
=}
}

reactor Destination(width: size_t = 2) {
input[width] in: size_t

reaction(in) {=
for (size_t i = 0; i < in.size(); i++) {
if (in[i].is_present()) {
size_t value = *in[i].get();
std::cout << "Received on channel " << i << ": " << value << '\n';
// NOTE: For testing purposes, this assumes the specific
// widths instantiated below.
if (value != i % 3) {
std::cerr << "ERROR: expected " << i % 3 << '\n';
exit(1);
}
}
}
if (get_elapsed_logical_time() != 1s) {
std::cerr << "ERROR: Expected to receive input after one second.\n";
exit(2);
}
=}
}

main reactor(delay: time = 1 sec) {
a1 = new Source(width=3)
a2 = new Source(width=2)
b = new Destination(width=5)
a1.out, a2.out -> b.in after delay
}
Loading