Skip to content
Draft
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
31 changes: 31 additions & 0 deletions verible/common/formatting/align.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,52 @@ static const verible::EnumNameMap<AlignmentPolicy> &AlignmentPolicyNameMap() {
return kAlignmentPolicyNameMap;
}

static const verible::EnumNameMap<NamedAlignmentPolicy> &
NamedAlignmentPolicyNameMap() {
static const verible::EnumNameMap<NamedAlignmentPolicy>
kNamedAlignmentPolicyNameMap({
{"align", NamedAlignmentPolicy::kAlign},
{"flush-left", NamedAlignmentPolicy::kFlushLeft},
{"preserve", NamedAlignmentPolicy::kPreserve},
{"infer", NamedAlignmentPolicy::kInferUserIntent},
{"align-both", NamedAlignmentPolicy::kAlignBoth},
{"align-both-separated", NamedAlignmentPolicy::kAlignBothSeparated},
{"align-both-spaced", NamedAlignmentPolicy::kAlignBothSpaced},
});
return kNamedAlignmentPolicyNameMap;
}

std::ostream &operator<<(std::ostream &stream, AlignmentPolicy policy) {
return AlignmentPolicyNameMap().Unparse(policy, stream);
}

std::ostream &operator<<(std::ostream &stream, NamedAlignmentPolicy policy) {
return NamedAlignmentPolicyNameMap().Unparse(policy, stream);
}

bool AbslParseFlag(std::string_view text, AlignmentPolicy *policy,
std::string *error) {
return AlignmentPolicyNameMap().Parse(text, policy, error, "AlignmentPolicy");
}

bool AbslParseFlag(std::string_view text, NamedAlignmentPolicy *policy,
std::string *error) {
return NamedAlignmentPolicyNameMap().Parse(text, policy, error,
"NamedAlignmentPolicy");
}

std::string AbslUnparseFlag(const AlignmentPolicy &policy) {
std::ostringstream stream;
stream << policy;
return stream.str();
}

std::string AbslUnparseFlag(const NamedAlignmentPolicy &policy) {
std::ostringstream stream;
stream << policy;
return stream.str();
}

static int EffectiveCellWidth(const FormatTokenRange &tokens) {
if (tokens.empty()) return 0;
VLOG(2) << __FUNCTION__;
Expand Down
19 changes: 19 additions & 0 deletions verible/common/formatting/align.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,31 @@ enum class AlignmentPolicy {
kInferUserIntent,
};

// Specific enum for named port alignment that combines regular alignment
// options with parenthesis alignment options
enum class NamedAlignmentPolicy {
// Standard alignment options (from AlignmentPolicy)
kPreserve,
kFlushLeft,
kAlign,
kInferUserIntent,

// Parenthesis alignment options
kAlignBoth,
kAlignBothSeparated,
kAlignBothSpaced
};

std::ostream &operator<<(std::ostream &, AlignmentPolicy);
std::ostream &operator<<(std::ostream &, NamedAlignmentPolicy);

bool AbslParseFlag(std::string_view text, AlignmentPolicy *policy,
std::string *error);
bool AbslParseFlag(std::string_view text, NamedAlignmentPolicy *policy,
std::string *error);

std::string AbslUnparseFlag(const AlignmentPolicy &policy);
std::string AbslUnparseFlag(const NamedAlignmentPolicy &policy);

// This represents one unit of alignable work, which is usually a filtered
// subset of partitions within a contiguous range of partitions.
Expand Down
Loading
Loading