From 430a2c4dfa2295e4576b77bfde76f5c92be09417 Mon Sep 17 00:00:00 2001 From: Andrew Ferraiuolo Date: Thu, 22 Sep 2022 11:04:06 -0700 Subject: [PATCH] Small improvements to Auth Logic ToString (#727) These were originally made as part of #654, but are split into this separate PR in order to keep PRs more singular in purpose. Tests of ToString will still be added later in a separate PR in order to satisfy #720. Closes #727 COPYBARA_INTEGRATE_REVIEW=https://github.com/google-research/raksha/pull/727 from google-research:tostring-improve@aferr adb85e9fed75473ac714172a811dfc504e31a71b PiperOrigin-RevId: 476146199 --- src/ir/auth_logic/BUILD | 2 +- src/ir/auth_logic/ast.h | 11 +++++++---- src/ir/datalog/program.h | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ir/auth_logic/BUILD b/src/ir/auth_logic/BUILD index 0d3ef13fd..18dfbe339 100644 --- a/src/ir/auth_logic/BUILD +++ b/src/ir/auth_logic/BUILD @@ -35,7 +35,7 @@ cc_library( "//src/common/utils:types", "//src/ir/datalog:program", "@absl//absl/hash", - "@absl//absl/strings:str_format", + "@absl//absl/strings", ], ) diff --git a/src/ir/auth_logic/ast.h b/src/ir/auth_logic/ast.h index b77b21a20..a9ad10a60 100644 --- a/src/ir/auth_logic/ast.h +++ b/src/ir/auth_logic/ast.h @@ -25,6 +25,7 @@ #include #include "absl/hash/hash.h" +#include "absl/strings/str_join.h" #include "src/common/utils/map_iter.h" #include "src/ir/auth_logic/auth_logic_ast_visitor.h" #include "src/ir/datalog/program.h" @@ -452,10 +453,12 @@ class Program { for (const Query& query : queries_) { query_strings.push_back(query.ToString()); } - return absl::StrCat("Program(\n", - absl::StrJoin(relation_decl_strings, "\n"), - absl::StrJoin(says_assertion_strings, "\n"), - absl::StrJoin(query_strings, "\n"), ")"); + return absl::StrJoin( + std::vector({"Program(", + absl::StrJoin(relation_decl_strings, "\n"), + absl::StrJoin(says_assertion_strings, "\n"), + absl::StrJoin(query_strings, "\n")}), + "\n"); } bool operator==(const Program& rhs) const { diff --git a/src/ir/datalog/program.h b/src/ir/datalog/program.h index b46997ae8..569756c9a 100644 --- a/src/ir/datalog/program.h +++ b/src/ir/datalog/program.h @@ -155,8 +155,10 @@ class RelationDeclaration { for (const Argument& arg : arguments_) { arg_strings.push_back(arg.ToString()); } - return absl::StrCat(".decl ", relation_name_, is_attribute_, - absl::StrJoin(arg_strings, ", ")); + return absl::StrCat(".decl ", + is_attribute_ ? " attribute " : "", + relation_name_, "(", + absl::StrJoin(arg_strings, ", "), ")"); } private: