Skip to content

Commit 8a99d2e

Browse files
committed
Add more statement reflection to start looking at assignment statements
And update build and version number. This test case: test: @autodiff @print type = { // A simple first function would be: // func: (a: double, b: double) -> double = { return a + b; } func: (a: double, b: double) -> (r: double) = { r = a + b; } // The generated autodiff forward transformation would be: // func_diff: (a: double, a_d: double, b: double, b_d: double) -> (r: double, r_d: double) = { // r_d = a * b_d + b * a_d; // r = a * b; // } } Now generates this output, recognizing that the statement is an assignment, and that the left-hand side of the assignment is a parameter or return name (but not yet manipulating the right-hand expression): test:/* @autodiff @print */ type = { func:( in a: double, in b: double, ) -> (out r: double, ) = { r = a + b; return; } func_diff:( in a: double, in a_d: double, in b: double, in b_d: double, ) -> ( out r: double = 1, out r_d: double = 1, ) = { r_d = TODO_computed_derivative_expression; r = TODO_changed_original_expression; return; } }
1 parent 62e7cf9 commit 8a99d2e

File tree

5 files changed

+1189
-632
lines changed

5 files changed

+1189
-632
lines changed

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"9B08:1148"
1+
"10202:1808"

source/parse.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,28 @@ struct function_type_node
27522752
return false;
27532753
}
27542754

2755+
auto has_return_named(std::string_view s) const
2756+
-> bool
2757+
{
2758+
auto list = std::get_if<active::list>(&returns);
2759+
if (!list) {
2760+
return false;
2761+
}
2762+
2763+
for (auto& param : (*list)->parameters) {
2764+
if (param->has_name(s)) {
2765+
return true;
2766+
}
2767+
}
2768+
return false;
2769+
}
2770+
2771+
auto has_parameter_or_return_named(std::string_view s) const
2772+
-> bool
2773+
{
2774+
return has_parameter_named(s) || has_return_named(s);
2775+
}
2776+
27552777
auto has_parameter_with_name_and_pass(
27562778
std::string_view s,
27572779
passing_style pass
@@ -3294,6 +3316,24 @@ struct declaration_node
32943316
return std::get<a_function>(type)->has_parameter_named(s);
32953317
}
32963318

3319+
auto has_return_named(std::string_view s) const
3320+
-> bool
3321+
{
3322+
if (!is_function()) {
3323+
return false;
3324+
}
3325+
return std::get<a_function>(type)->has_return_named(s);
3326+
}
3327+
3328+
auto has_parameter_or_return_named(std::string_view s) const
3329+
-> bool
3330+
{
3331+
if (!is_function()) {
3332+
return false;
3333+
}
3334+
return std::get<a_function>(type)->has_parameter_or_return_named(s);
3335+
}
3336+
32973337
auto has_in_parameter_named(std::string_view s) const
32983338
-> bool
32993339
{

0 commit comments

Comments
 (0)