Skip to content

Commit

Permalink
Small improvements to Auth Logic ToString (#727)
Browse files Browse the repository at this point in the history
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=#727 from google-research:tostring-improve@aferr adb85e9
PiperOrigin-RevId: 476146199
  • Loading branch information
Andrew Ferraiuolo authored and arcs-c3po committed Sep 22, 2022
1 parent 544151f commit 430a2c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ir/auth_logic/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
11 changes: 7 additions & 4 deletions src/ir/auth_logic/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#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"
Expand Down Expand Up @@ -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<std::string>({"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 {
Expand Down
6 changes: 4 additions & 2 deletions src/ir/datalog/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 430a2c4

Please sign in to comment.