{"action":"created","comment":{"url":"https://api.github.com/repos/peterschrammel/cbmc/pulls/comments/88807417","pull_request_review_id":9368325,"id":88807417,"diff_hunk":"@@ -0,0 +1,203 @@\n+#include \"function_return_builder.h\"\n+\n+#include <test-c-gen/expr2cleanc.h>\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::function_return_buildert\n+Inputs:\n+ all_inputs - All the inputs from the interpreter\n+ function_id - The ID of the function being called\n+ e2c_converter - The expr2c converter being used to generate C code\n+Purpose: A builder class for dealing with function returns\n+ \\*******************************************************************/\n+function_return_buildert::function_return_buildert(const inputst &all_inputs,\n+                                                   const irep_idt &function_id,\n+                                                   expr2cleanct &e2c_converter)\n+  :e2c(e2c_converter)\n+{\n+  has_return = false;\n+\n+  for(const input_entryt &input : all_inputs)\n+  {\n+    // TODO: this isn't a great way to find returns\n+    if(input.first == \"return'\")\n+    {\n+      has_return = true;\n+      return_entry = input;\n+      set_return_variable_name(function_id);\n+      return;\n+    }\n+  }\n+\n+  has_return = false;\n+}\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::set_return_variable_name\n+Inputs:\n+ function_id - The name of the function\n+Purpose: Store the variable named used to store the result of the function\n+ \\*******************************************************************/\n+void function_return_buildert::set_return_variable_name(\n+    const irep_idt &function_id)\n+{\n+  std::ostringstream ret_name_builder;\n+  ret_name_builder << \"ret_\";\n+  ret_name_builder << function_id;\n+  return_var_name = ret_name_builder.str();\n+}\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::add_assertions_for_expression\n+Inputs:\n+ correct_expression - The expression representing the value expected\n+ ret_value_var - The name of the variable (including relevant nesting)\n+Pupose: Add assertions to the assertions list for the return value\n+ \\*******************************************************************/\n+void function_return_buildert::add_assertions_for_expression(const exprt &correct_expression,\n+                                                             std::string ret_value_var)\n+{\n+  assert(has_return);\n+\n+  const typet &type = correct_expression.type();\n+\n+  if(type.id() == ID_struct)\n+  {\n+    add_assertions_for_struct_expression(correct_expression, ret_value_var);\n+  }\n+  else if(type.id() == ID_pointer)\n+  {\n+    // TODO - this should check pointers dereferenced == something sensible?\n+    add_assertions_for_simple_expression(correct_expression, ret_value_var);\n+  }\n+  else\n+  {\n+    add_assertions_for_simple_expression(correct_expression, ret_value_var);\n+  }\n+}\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::add_assertions_for_struct_expression\n+Inputs:\n+ correct_expression - The expression representing the value expected\n+ ret_value_var - The name of the variable (including relevant nesting)\n+Purpose: Look through all the components of the struct and add assertions for\n+         each of them.\n+ \\*******************************************************************/\n+void function_return_buildert::add_assertions_for_struct_expression(\n+    const exprt &correct_expression, std::string ret_value_var)\n+{\n+  const struct_typet &struct_type=to_struct_type(correct_expression.type());\n+\n+  exprt::operandst::const_iterator o_it=correct_expression.operands().begin();\n+  for(struct_typet::componentst::const_iterator\n+      it=struct_type.components().begin();\n+      it!=struct_type.components().end();\n+      it++)\n+  {\n+    // Skip padding parameters\n+    if(it->get_is_padding())\n+    {\n+      ++o_it;\n+      continue;\n+    }\n+\n+    const irep_idt &component_name = it->get_name();\n+\n+    std::ostringstream struct_component_name_builder;\n+    struct_component_name_builder << ret_value_var << \".\" << component_name;\n+\n+\n+    add_assertions_for_expression(*o_it, struct_component_name_builder.str());\n+    ++o_it;\n+  }\n+}\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::add_assertions_for_simple_expression\n+Inputs:\n+ correct_expression - The expression representing the value expected\n+ return_value_var - The name of the variable (including relevant nesting)\n+Purpose: Add an assertion for a simple expression\n+ \\*******************************************************************/\n+void function_return_buildert::add_assertions_for_simple_expression(\n+    const exprt &correct_expression, std::string return_value_var)\n+{\n+  std::ostringstream assert_builder;\n+\n+  assert_builder << \"assert(\";\n+  assert_builder << return_value_var;\n+  assert_builder << \" == \";\n+\n+  std::string expected_return_value = e2c.convert(correct_expression);\n+\n+  assert_builder << expected_return_value;\n+  assert_builder << \");\";\n+\n+  assertions.push_back(assert_builder.str());\n+}\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::get_function_has_return\n+Outputs: Returns true if the function has a return value\n+Purpose: We only store and validate function returns if the\n+         function actually returns something.\n+ \\*******************************************************************/\n+bool function_return_buildert::get_function_has_return() const\n+{\n+  return has_return;\n+}\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::get_return_variable_name\n+Outputs: The variable used to store the function return\n+Purpose: For getting the name used to store the function return\n+ \\*******************************************************************/\n+std::string function_return_buildert::get_return_variable_name() const\n+{\n+  // if the function doesn't return anything, these other methods shouldn't\n+  // be called\n+  assert(has_return);\n+  return return_var_name;\n+}\n+\n+/*******************************************************************\\\n+Function: function_return_buildert::get_return_decleration\n+Outputs: The decleration line\n+Purpose: Get the decleration line for the return variable\n+ \\*******************************************************************/\n+std::string function_return_buildert::get_return_decleration() const\n+{\n+  // if the function doesn't return anything, these other methods shouldn't\n+  // be called\n+  assert(has_return);\n+\n+  std::ostringstream ret_var_decleartion_builder;","path":"src/test-c-gen/function_return_builder.cpp","position":175,"original_position":175,"commit_id":"28a991247011d3446b774452d74f4f29ff3228f2","original_commit_id":"28a991247011d3446b774452d74f4f29ff3228f2","user":{"login":"peterschrammel","id":4222448,"avatar_url":"https://avatars.githubusercontent.com/u/4222448?v=3","gravatar_id":"","url":"https://api.github.com/users/peterschrammel","html_url":"https://github.com/peterschrammel","followers_url":"https://api.github.com/users/peterschrammel/followers","following_url":"https://api.github.com/users/peterschrammel/following{/other_user}","gists_url":"https://api.github.com/users/peterschrammel/gists{/gist_id}","starred_url":"https://api.github.com/users/peterschrammel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterschrammel/subscriptions","organizations_url":"https://api.github.com/users/peterschrammel/orgs","repos_url":"https://api.github.com/users/peterschrammel/repos","events_url":"https://api.github.com/users/peterschrammel/events{/privacy}","received_events_url":"https://api.github.com/users/peterschrammel/received_events","type":"User","site_admin":false},"body":"-> declaration","created_at":"2016-11-20T18:07:09Z","updated_at":"2016-11-20T18:11:57Z","html_url":"https://github.com/peterschrammel/cbmc/pull/5#discussion_r88807417","pull_request_url":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/peterschrammel/cbmc/pulls/comments/88807417"},"html":{"href":"https://github.com/peterschrammel/cbmc/pull/5#discussion_r88807417"},"pull_request":{"href":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5","id":94411795,"html_url":"https://github.com/peterschrammel/cbmc/pull/5","diff_url":"https://github.com/peterschrammel/cbmc/pull/5.diff","patch_url":"https://github.com/peterschrammel/cbmc/pull/5.patch","issue_url":"https://api.github.com/repos/peterschrammel/cbmc/issues/5","number":5,"state":"open","locked":false,"title":"First pass on the C Test Generation","user":{"login":"thk123","id":638608,"avatar_url":"https://avatars.githubusercontent.com/u/638608?v=3","gravatar_id":"","url":"https://api.github.com/users/thk123","html_url":"https://github.com/thk123","followers_url":"https://api.github.com/users/thk123/followers","following_url":"https://api.github.com/users/thk123/following{/other_user}","gists_url":"https://api.github.com/users/thk123/gists{/gist_id}","starred_url":"https://api.github.com/users/thk123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thk123/subscriptions","organizations_url":"https://api.github.com/users/thk123/orgs","repos_url":"https://api.github.com/users/thk123/repos","events_url":"https://api.github.com/users/thk123/events{/privacy}","received_events_url":"https://api.github.com/users/thk123/received_events","type":"User","site_admin":false},"body":"Includes support for generating tests for:\r\n\r\n- non main methods\r\n- normal parameters being passed in\r\n- struct (and nested struct) parameters and returns\r\n- asserting results on returns\r\n\r\n","created_at":"2016-11-18T18:22:42Z","updated_at":"2016-11-20T18:11:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1581d44aed159889594d2dcaca120b0cfd9b7661","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5/commits","review_comments_url":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5/comments","review_comment_url":"https://api.github.com/repos/peterschrammel/cbmc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/peterschrammel/cbmc/issues/5/comments","statuses_url":"https://api.github.com/repos/peterschrammel/cbmc/statuses/28a991247011d3446b774452d74f4f29ff3228f2","head":{"label":"thk123:c-test-gen-no-prune","ref":"c-test-gen-no-prune","sha":"28a991247011d3446b774452d74f4f29ff3228f2","user":{"login":"thk123","id":638608,"avatar_url":"https://avatars.githubusercontent.com/u/638608?v=3","gravatar_id":"","url":"https://api.github.com/users/thk123","html_url":"https://github.com/thk123","followers_url":"https://api.github.com/users/thk123/followers","following_url":"https://api.github.com/users/thk123/following{/other_user}","gists_url":"https://api.github.com/users/thk123/gists{/gist_id}","starred_url":"https://api.github.com/users/thk123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thk123/subscriptions","organizations_url":"https://api.github.com/users/thk123/orgs","repos_url":"https://api.github.com/users/thk123/repos","events_url":"https://api.github.com/users/thk123/events{/privacy}","received_events_url":"https://api.github.com/users/thk123/received_events","type":"User","site_admin":false},"repo":{"id":72552124,"name":"cbmc","full_name":"thk123/cbmc","owner":{"login":"thk123","id":638608,"avatar_url":"https://avatars.githubusercontent.com/u/638608?v=3","gravatar_id":"","url":"https://api.github.com/users/thk123","html_url":"https://github.com/thk123","followers_url":"https://api.github.com/users/thk123/followers","following_url":"https://api.github.com/users/thk123/following{/other_user}","gists_url":"https://api.github.com/users/thk123/gists{/gist_id}","starred_url":"https://api.github.com/users/thk123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thk123/subscriptions","organizations_url":"https://api.github.com/users/thk123/orgs","repos_url":"https://api.github.com/users/thk123/repos","events_url":"https://api.github.com/users/thk123/events{/privacy}","received_events_url":"https://api.github.com/users/thk123/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/thk123/cbmc","description":"C Bounded Model Checker","fork":true,"url":"https://api.github.com/repos/thk123/cbmc","forks_url":"https://api.github.com/repos/thk123/cbmc/forks","keys_url":"https://api.github.com/repos/thk123/cbmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thk123/cbmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thk123/cbmc/teams","hooks_url":"https://api.github.com/repos/thk123/cbmc/hooks","issue_events_url":"https://api.github.com/repos/thk123/cbmc/issues/events{/number}","events_url":"https://api.github.com/repos/thk123/cbmc/events","assignees_url":"https://api.github.com/repos/thk123/cbmc/assignees{/user}","branches_url":"https://api.github.com/repos/thk123/cbmc/branches{/branch}","tags_url":"https://api.github.com/repos/thk123/cbmc/tags","blobs_url":"https://api.github.com/repos/thk123/cbmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thk123/cbmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thk123/cbmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/thk123/cbmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thk123/cbmc/statuses/{sha}","languages_url":"https://api.github.com/repos/thk123/cbmc/languages","stargazers_url":"https://api.github.com/repos/thk123/cbmc/stargazers","contributors_url":"https://api.github.com/repos/thk123/cbmc/contributors","subscribers_url":"https://api.github.com/repos/thk123/cbmc/subscribers","subscription_url":"https://api.github.com/repos/thk123/cbmc/subscription","commits_url":"https://api.github.com/repos/thk123/cbmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/thk123/cbmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/thk123/cbmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/thk123/cbmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/thk123/cbmc/contents/{+path}","compare_url":"https://api.github.com/repos/thk123/cbmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thk123/cbmc/merges","archive_url":"https://api.github.com/repos/thk123/cbmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thk123/cbmc/downloads","issues_url":"https://api.github.com/repos/thk123/cbmc/issues{/number}","pulls_url":"https://api.github.com/repos/thk123/cbmc/pulls{/number}","milestones_url":"https://api.github.com/repos/thk123/cbmc/milestones{/number}","notifications_url":"https://api.github.com/repos/thk123/cbmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thk123/cbmc/labels{/name}","releases_url":"https://api.github.com/repos/thk123/cbmc/releases{/id}","deployments_url":"https://api.github.com/repos/thk123/cbmc/deployments","created_at":"2016-11-01T15:58:09Z","updated_at":"2016-11-01T15:58:18Z","pushed_at":"2016-11-18T17:12:06Z","git_url":"git://github.com/thk123/cbmc.git","ssh_url":"git@github.com:thk123/cbmc.git","clone_url":"https://github.com/thk123/cbmc.git","svn_url":"https://github.com/thk123/cbmc","homepage":"http://www.cprover.org/cbmc","size":14839,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"peterschrammel:develop","ref":"develop","sha":"4a883d0ccb744050bb5868930ce2fce92005ac1e","user":{"login":"peterschrammel","id":4222448,"avatar_url":"https://avatars.githubusercontent.com/u/4222448?v=3","gravatar_id":"","url":"https://api.github.com/users/peterschrammel","html_url":"https://github.com/peterschrammel","followers_url":"https://api.github.com/users/peterschrammel/followers","following_url":"https://api.github.com/users/peterschrammel/following{/other_user}","gists_url":"https://api.github.com/users/peterschrammel/gists{/gist_id}","starred_url":"https://api.github.com/users/peterschrammel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterschrammel/subscriptions","organizations_url":"https://api.github.com/users/peterschrammel/orgs","repos_url":"https://api.github.com/users/peterschrammel/repos","events_url":"https://api.github.com/users/peterschrammel/events{/privacy}","received_events_url":"https://api.github.com/users/peterschrammel/received_events","type":"User","site_admin":false},"repo":{"id":55680594,"name":"cbmc","full_name":"peterschrammel/cbmc","owner":{"login":"peterschrammel","id":4222448,"avatar_url":"https://avatars.githubusercontent.com/u/4222448?v=3","gravatar_id":"","url":"https://api.github.com/users/peterschrammel","html_url":"https://github.com/peterschrammel","followers_url":"https://api.github.com/users/peterschrammel/followers","following_url":"https://api.github.com/users/peterschrammel/following{/other_user}","gists_url":"https://api.github.com/users/peterschrammel/gists{/gist_id}","starred_url":"https://api.github.com/users/peterschrammel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterschrammel/subscriptions","organizations_url":"https://api.github.com/users/peterschrammel/orgs","repos_url":"https://api.github.com/users/peterschrammel/repos","events_url":"https://api.github.com/users/peterschrammel/events{/privacy}","received_events_url":"https://api.github.com/users/peterschrammel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peterschrammel/cbmc","description":"C Bounded Model Checker","fork":true,"url":"https://api.github.com/repos/peterschrammel/cbmc","forks_url":"https://api.github.com/repos/peterschrammel/cbmc/forks","keys_url":"https://api.github.com/repos/peterschrammel/cbmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peterschrammel/cbmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peterschrammel/cbmc/teams","hooks_url":"https://api.github.com/repos/peterschrammel/cbmc/hooks","issue_events_url":"https://api.github.com/repos/peterschrammel/cbmc/issues/events{/number}","events_url":"https://api.github.com/repos/peterschrammel/cbmc/events","assignees_url":"https://api.github.com/repos/peterschrammel/cbmc/assignees{/user}","branches_url":"https://api.github.com/repos/peterschrammel/cbmc/branches{/branch}","tags_url":"https://api.github.com/repos/peterschrammel/cbmc/tags","blobs_url":"https://api.github.com/repos/peterschrammel/cbmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peterschrammel/cbmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peterschrammel/cbmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/peterschrammel/cbmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peterschrammel/cbmc/statuses/{sha}","languages_url":"https://api.github.com/repos/peterschrammel/cbmc/languages","stargazers_url":"https://api.github.com/repos/peterschrammel/cbmc/stargazers","contributors_url":"https://api.github.com/repos/peterschrammel/cbmc/contributors","subscribers_url":"https://api.github.com/repos/peterschrammel/cbmc/subscribers","subscription_url":"https://api.github.com/repos/peterschrammel/cbmc/subscription","commits_url":"https://api.github.com/repos/peterschrammel/cbmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/peterschrammel/cbmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/peterschrammel/cbmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/peterschrammel/cbmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/peterschrammel/cbmc/contents/{+path}","compare_url":"https://api.github.com/repos/peterschrammel/cbmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peterschrammel/cbmc/merges","archive_url":"https://api.github.com/repos/peterschrammel/cbmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peterschrammel/cbmc/downloads","issues_url":"https://api.github.com/repos/peterschrammel/cbmc/issues{/number}","pulls_url":"https://api.github.com/repos/peterschrammel/cbmc/pulls{/number}","milestones_url":"https://api.github.com/repos/peterschrammel/cbmc/milestones{/number}","notifications_url":"https://api.github.com/repos/peterschrammel/cbmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peterschrammel/cbmc/labels{/name}","releases_url":"https://api.github.com/repos/peterschrammel/cbmc/releases{/id}","deployments_url":"https://api.github.com/repos/peterschrammel/cbmc/deployments","created_at":"2016-04-07T09:12:29Z","updated_at":"2016-04-07T09:12:36Z","pushed_at":"2016-11-20T16:55:54Z","git_url":"git://github.com/peterschrammel/cbmc.git","ssh_url":"git@github.com:peterschrammel/cbmc.git","clone_url":"https://github.com/peterschrammel/cbmc.git","svn_url":"https://github.com/peterschrammel/cbmc","homepage":"http://www.cprover.org/cbmc","size":16194,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5"},"html":{"href":"https://github.com/peterschrammel/cbmc/pull/5"},"issue":{"href":"https://api.github.com/repos/peterschrammel/cbmc/issues/5"},"comments":{"href":"https://api.github.com/repos/peterschrammel/cbmc/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/peterschrammel/cbmc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/peterschrammel/cbmc/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/peterschrammel/cbmc/statuses/28a991247011d3446b774452d74f4f29ff3228f2"}}}}
{"actor":{"display_login":"peterschrammel"}}