Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dff-name-style #1983

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 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 @@ -755,6 +756,7 @@ cc_test(
"//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
Loading