Skip to content

Commit

Permalink
Merge pull request #1983 from IEncinas10/dff-name-style
Browse files Browse the repository at this point in the history
Add dff-name-style
  • Loading branch information
hzeller authored Oct 7, 2024
2 parents 14eed6a + a2e4faa commit 32b2456
Show file tree
Hide file tree
Showing 14 changed files with 1,408 additions and 51 deletions.
3 changes: 3 additions & 0 deletions verilog/CST/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ cc_test(
deps = [
":expression",
":match-test-utils",
":verilog-matchers", # fixdeps: keep
":verilog-nonterminals",
"//common/analysis:syntax-tree-search",
"//common/analysis:syntax-tree-search-test-utils",
Expand Down Expand Up @@ -748,13 +749,15 @@ cc_test(
deps = [
":match-test-utils",
":statement",
":verilog-matchers",
":verilog-nonterminals",
"//common/analysis:syntax-tree-search",
"//common/analysis:syntax-tree-search-test-utils",
"//common/analysis/matcher:matcher-builders",
"//common/text:concrete-syntax-tree",
"//common/text:symbol",
"//common/text:text-structure",
"//common/text:tree-utils",
"//common/util:logging",
"//verilog/analysis:verilog-analyzer",
"@com_google_absl//absl/strings:string_view",
Expand Down
29 changes: 29 additions & 0 deletions verilog/CST/expression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,33 @@ const verible::TokenInfo *ReferenceIsSimpleIdentifier(
return ReferenceBaseIsSimple(base_node);
}

const verible::SyntaxTreeLeaf *GetIncrementDecrementOperator(
const verible::Symbol &expr) {
if (expr.Kind() != SymbolKind::kNode) return nullptr;

const SyntaxTreeNode &node = verible::SymbolCastToNode(expr);

if (!node.MatchesTag(NodeEnum::kIncrementDecrementExpression)) return nullptr;

// Structure changes depending on the type of IncrementDecrement
bool is_post = node.front().get()->Kind() == SymbolKind::kNode;

return verible::GetSubtreeAsLeaf(
expr, NodeEnum::kIncrementDecrementExpression, is_post ? 1 : 0);
}

const verible::SyntaxTreeNode *GetIncrementDecrementOperand(
const verible::Symbol &expr) {
if (expr.Kind() != SymbolKind::kNode) return nullptr;

const SyntaxTreeNode &node = verible::SymbolCastToNode(expr);

if (!node.MatchesTag(NodeEnum::kIncrementDecrementExpression)) return nullptr;

// Structure changes depending on the type of IncrementDecrement
bool is_post = node.front().get()->Kind() == SymbolKind::kNode;
return verible::GetSubtreeAsNode(
expr, NodeEnum::kIncrementDecrementExpression, is_post ? 0 : 1);
}

} // namespace verilog
10 changes: 10 additions & 0 deletions verilog/CST/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ std::vector<verible::TreeSearchMatch> FindAllReferenceFullExpressions(
const verible::TokenInfo *ReferenceIsSimpleIdentifier(
const verible::Symbol &reference);

// Return the operator for a kIncrementDecrementExpression
// This function would extract the leaf containing '++' from expression '++a'
const verible::SyntaxTreeLeaf *GetIncrementDecrementOperator(
const verible::Symbol &expr);

// Return the operator for a kIncrementDecrementExpression
// This function would extract the leaf containing 'a' from expression '++a'
const verible::SyntaxTreeNode *GetIncrementDecrementOperand(
const verible::Symbol &expr);

} // namespace verilog

#endif // VERIBLE_VERILOG_CST_EXPRESSION_H_
Loading

0 comments on commit 32b2456

Please sign in to comment.