Normalize whole tree with cargo fmt under rustfmt.toml
One-time mechanical pass; no behavior change (full test suite green before and after). From here on, cargo fmt --check is the standard. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
8effef9b6b
commit
d2cd44c428
8 files changed
+191
-149
No files matched your search
+108
-25
@@ -31,7 +31,12 @@ pub struct Item {
|
||||
#[derive(Debug)]
|
||||
pub enum ItemKind {
|
||||
Module(Module),
|
||||
Package { kw: String, name: String, items: Vec<Item>, dangling: Vec<Comment> },
|
||||
Package {
|
||||
kw: String,
|
||||
name: String,
|
||||
items: Vec<Item>,
|
||||
dangling: Vec<Comment>,
|
||||
},
|
||||
Directive(String),
|
||||
Import(Vec<String>),
|
||||
Timeunit(String),
|
||||
@@ -42,13 +47,19 @@ pub enum ItemKind {
|
||||
PortDecl(PortDecl),
|
||||
ContAssign(ContAssign),
|
||||
/// The body statement carries any `@(...)`/`#delay` timing control.
|
||||
Always { kw: String, stmt: Stmt },
|
||||
Always {
|
||||
kw: String,
|
||||
stmt: Stmt,
|
||||
},
|
||||
Initial(Stmt),
|
||||
Final(Stmt),
|
||||
Instantiation(Instantiation),
|
||||
GateInstantiation(GateInstantiation),
|
||||
Genvar(Vec<String>),
|
||||
GenerateRegion { items: Vec<Item>, dangling: Vec<Comment> },
|
||||
GenerateRegion {
|
||||
items: Vec<Item>,
|
||||
dangling: Vec<Comment>,
|
||||
},
|
||||
GenIf(GenIf),
|
||||
GenFor(GenFor),
|
||||
GenCase(GenCase),
|
||||
@@ -412,11 +423,26 @@ pub enum StmtKind {
|
||||
step: Vec<ForStep>,
|
||||
body: Box<Stmt>,
|
||||
},
|
||||
While { cond: Expr, body: Box<Stmt> },
|
||||
DoWhile { body: Box<Stmt>, cond: Expr },
|
||||
Repeat { count: Expr, body: Box<Stmt> },
|
||||
Forever { body: Box<Stmt> },
|
||||
Foreach { target: Expr, vars: Vec<String>, body: Box<Stmt> },
|
||||
While {
|
||||
cond: Expr,
|
||||
body: Box<Stmt>,
|
||||
},
|
||||
DoWhile {
|
||||
body: Box<Stmt>,
|
||||
cond: Expr,
|
||||
},
|
||||
Repeat {
|
||||
count: Expr,
|
||||
body: Box<Stmt>,
|
||||
},
|
||||
Forever {
|
||||
body: Box<Stmt>,
|
||||
},
|
||||
Foreach {
|
||||
target: Expr,
|
||||
vars: Vec<String>,
|
||||
body: Box<Stmt>,
|
||||
},
|
||||
/// Blocking/nonblocking/compound assignment.
|
||||
Assign {
|
||||
lhs: Expr,
|
||||
@@ -426,11 +452,21 @@ pub enum StmtKind {
|
||||
rhs: Expr,
|
||||
},
|
||||
/// `force`/`release`/`deassign` statements, raw pieces.
|
||||
ForceRelease { kw: String, lhs: Expr, rhs: Option<Expr> },
|
||||
ForceRelease {
|
||||
kw: String,
|
||||
lhs: Expr,
|
||||
rhs: Option<Expr>,
|
||||
},
|
||||
/// Procedural timing control: `#10 stmt;`, `@(posedge clk) stmt;`,
|
||||
/// `#10;`, `@(ev);`
|
||||
Timing { control: TimingControl, stmt: Option<Box<Stmt>> },
|
||||
Wait { cond: Expr, stmt: Option<Box<Stmt>> },
|
||||
Timing {
|
||||
control: TimingControl,
|
||||
stmt: Option<Box<Stmt>>,
|
||||
},
|
||||
Wait {
|
||||
cond: Expr,
|
||||
stmt: Option<Box<Stmt>>,
|
||||
},
|
||||
ExprStmt(Expr),
|
||||
/// `-> event_name;`
|
||||
EventTrigger(Expr),
|
||||
@@ -496,29 +532,76 @@ pub enum Expr {
|
||||
Str(String),
|
||||
/// Explicitly empty (used for `.port()` connections).
|
||||
Empty,
|
||||
Unary { op: String, expr: Box<Expr> },
|
||||
Binary { lhs: Box<Expr>, op: String, rhs: Box<Expr> },
|
||||
Ternary { cond: Box<Expr>, then: Box<Expr>, els: Box<Expr> },
|
||||
Call { callee: Box<Expr>, args: Vec<Expr> },
|
||||
Index { base: Box<Expr>, index: Box<Expr> },
|
||||
Range { base: Box<Expr>, op: String, msb: Box<Expr>, lsb: Box<Expr> },
|
||||
Member { base: Box<Expr>, name: String },
|
||||
Scope { base: Box<Expr>, name: String },
|
||||
Unary {
|
||||
op: String,
|
||||
expr: Box<Expr>,
|
||||
},
|
||||
Binary {
|
||||
lhs: Box<Expr>,
|
||||
op: String,
|
||||
rhs: Box<Expr>,
|
||||
},
|
||||
Ternary {
|
||||
cond: Box<Expr>,
|
||||
then: Box<Expr>,
|
||||
els: Box<Expr>,
|
||||
},
|
||||
Call {
|
||||
callee: Box<Expr>,
|
||||
args: Vec<Expr>,
|
||||
},
|
||||
Index {
|
||||
base: Box<Expr>,
|
||||
index: Box<Expr>,
|
||||
},
|
||||
Range {
|
||||
base: Box<Expr>,
|
||||
op: String,
|
||||
msb: Box<Expr>,
|
||||
lsb: Box<Expr>,
|
||||
},
|
||||
Member {
|
||||
base: Box<Expr>,
|
||||
name: String,
|
||||
},
|
||||
Scope {
|
||||
base: Box<Expr>,
|
||||
name: String,
|
||||
},
|
||||
Concat(Vec<Expr>),
|
||||
Repl { count: Box<Expr>, inner: Vec<Expr> },
|
||||
Repl {
|
||||
count: Box<Expr>,
|
||||
inner: Vec<Expr>,
|
||||
},
|
||||
Paren(Box<Expr>),
|
||||
/// `ty'(expr)` cast; `ty` kept as raw text.
|
||||
Cast { ty: String, expr: Box<Expr> },
|
||||
Cast {
|
||||
ty: String,
|
||||
expr: Box<Expr>,
|
||||
},
|
||||
/// `'{...}` assignment pattern.
|
||||
AssignPattern(Vec<PatternItem>),
|
||||
Postfix { expr: Box<Expr>, op: String },
|
||||
Inside { lhs: Box<Expr>, ranges: Vec<Expr> },
|
||||
Postfix {
|
||||
expr: Box<Expr>,
|
||||
op: String,
|
||||
},
|
||||
Inside {
|
||||
lhs: Box<Expr>,
|
||||
ranges: Vec<Expr>,
|
||||
},
|
||||
/// `[a:b]` inside an `inside` range list or value range.
|
||||
ValueRange { lo: Box<Expr>, hi: Box<Expr> },
|
||||
ValueRange {
|
||||
lo: Box<Expr>,
|
||||
hi: Box<Expr>,
|
||||
},
|
||||
/// A type used in expression position (`parameter type T = logic [7:0]`).
|
||||
Type(DataType),
|
||||
/// `(min : typ : max)` delay expression.
|
||||
MinTypMax { min: Box<Expr>, typ: Box<Expr>, max: Box<Expr> },
|
||||
MinTypMax {
|
||||
min: Box<Expr>,
|
||||
typ: Box<Expr>,
|
||||
max: Box<Expr>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -49,9 +49,9 @@ struct RawLexer<'a> {
|
||||
|
||||
/// Multi-character operators, longest first so greedy matching works.
|
||||
const OPERATORS: &[&str] = &[
|
||||
"<<<=", ">>>=", "===", "!==", "==?", "!=?", "<<<", ">>>", "<<=", ">>=", "**", "==", "!=",
|
||||
"<=", ">=", "&&", "||", "<<", ">>", "->", "=>", "::", "+:", "-:", "+=", "-=", "*=", "/=",
|
||||
"%=", "&=", "|=", "^=", "++", "--", "~&", "~|", "~^", "^~", "##", "'{",
|
||||
"<<<=", ">>>=", "===", "!==", "==?", "!=?", "<<<", ">>>", "<<=", ">>=", "**", "==", "!=", "<=",
|
||||
">=", "&&", "||", "<<", ">>", "->", "=>", "::", "+:", "-:", "+=", "-=", "*=", "/=", "%=", "&=",
|
||||
"|=", "^=", "++", "--", "~&", "~|", "~^", "^~", "##", "'{",
|
||||
];
|
||||
|
||||
const SINGLE_OPS: &[u8] = b"+-*/%&|^~!<>=?:;,.#@()[]{}'$";
|
||||
@@ -456,8 +456,7 @@ impl<'a> RawLexer<'a> {
|
||||
let start = self.pos;
|
||||
self.bump(); // '
|
||||
let c = self.peek();
|
||||
if matches!(c, b'0' | b'1' | b'x' | b'X' | b'z' | b'Z') && !is_ident_char(self.peek_at(1))
|
||||
{
|
||||
if matches!(c, b'0' | b'1' | b'x' | b'X' | b'z' | b'Z') && !is_ident_char(self.peek_at(1)) {
|
||||
// Unbased unsized literal: '0 '1 'x 'z
|
||||
self.bump();
|
||||
return Ok(self.text_from(start));
|
||||
@@ -493,8 +492,21 @@ fn is_ident_char(c: u8) -> bool {
|
||||
fn is_base_intro(c: u8) -> bool {
|
||||
matches!(
|
||||
c,
|
||||
b's' | b'S' | b'd' | b'D' | b'b' | b'B' | b'o' | b'O' | b'h' | b'H' | b'0' | b'1' | b'x'
|
||||
| b'X' | b'z' | b'Z'
|
||||
b's' | b'S'
|
||||
| b'd'
|
||||
| b'D'
|
||||
| b'b'
|
||||
| b'B'
|
||||
| b'o'
|
||||
| b'O'
|
||||
| b'h'
|
||||
| b'H'
|
||||
| b'0'
|
||||
| b'1'
|
||||
| b'x'
|
||||
| b'X'
|
||||
| b'z'
|
||||
| b'Z'
|
||||
)
|
||||
}
|
||||
|
||||
@@ -547,8 +559,8 @@ pub fn tokenize(source: &str) -> Result<Vec<Token>, LexError> {
|
||||
for raw in raws {
|
||||
match raw.kind {
|
||||
RawKind::LineComment | RawKind::BlockComment => {
|
||||
let same_line_as_prev = raw.newlines_before == 0 && !tokens.is_empty()
|
||||
&& pending.is_empty();
|
||||
let same_line_as_prev =
|
||||
raw.newlines_before == 0 && !tokens.is_empty() && pending.is_empty();
|
||||
if same_line_as_prev {
|
||||
// Trailing comment for the previous real token.
|
||||
let prev = tokens.last_mut().unwrap();
|
||||
@@ -596,11 +608,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
fn kinds(src: &str) -> Vec<(TokenKind, String)> {
|
||||
tokenize(src)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|t| (t.kind, t.text))
|
||||
.collect()
|
||||
tokenize(src).unwrap().into_iter().map(|t| (t.kind, t.text)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -27,13 +27,26 @@ impl std::error::Error for ParseError {}
|
||||
type PResult<T> = Result<T, ParseError>;
|
||||
|
||||
const TYPE_KEYWORDS: &[&str] = &[
|
||||
"logic", "reg", "bit", "byte", "shortint", "int", "longint", "integer", "time", "realtime",
|
||||
"real", "shortreal", "string", "chandle", "event", "void",
|
||||
"logic",
|
||||
"reg",
|
||||
"bit",
|
||||
"byte",
|
||||
"shortint",
|
||||
"int",
|
||||
"longint",
|
||||
"integer",
|
||||
"time",
|
||||
"realtime",
|
||||
"real",
|
||||
"shortreal",
|
||||
"string",
|
||||
"chandle",
|
||||
"event",
|
||||
"void",
|
||||
];
|
||||
|
||||
const NET_KEYWORDS: &[&str] = &[
|
||||
"wire", "tri", "tri0", "tri1", "wand", "wor", "trireg", "supply0", "supply1", "uwire",
|
||||
];
|
||||
const NET_KEYWORDS: &[&str] =
|
||||
&["wire", "tri", "tri0", "tri1", "wand", "wor", "trireg", "supply0", "supply1", "uwire"];
|
||||
|
||||
const GATE_KEYWORDS: &[&str] = &[
|
||||
"and", "or", "nand", "nor", "xor", "xnor", "not", "buf", "bufif0", "bufif1", "notif0",
|
||||
@@ -41,9 +54,8 @@ const GATE_KEYWORDS: &[&str] = &[
|
||||
"rtran", "tranif0", "tranif1", "rtranif0", "rtranif1",
|
||||
];
|
||||
|
||||
const ASSIGN_OPS: &[&str] = &[
|
||||
"=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", "<<<=", ">>>=",
|
||||
];
|
||||
const ASSIGN_OPS: &[&str] =
|
||||
&["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", "<<<=", ">>>="];
|
||||
|
||||
pub struct Parser {
|
||||
tokens: Vec<Token>,
|
||||
@@ -53,7 +65,8 @@ pub struct Parser {
|
||||
}
|
||||
|
||||
pub fn parse(tokens: Vec<Token>) -> PResult<SourceFile> {
|
||||
let mut p = Parser { tokens, pos: 0, pending_leading: Vec::new(), pending_trailing: Vec::new() };
|
||||
let mut p =
|
||||
Parser { tokens, pos: 0, pending_leading: Vec::new(), pending_trailing: Vec::new() };
|
||||
p.parse_source_file()
|
||||
}
|
||||
|
||||
@@ -319,8 +332,10 @@ impl Parser {
|
||||
}
|
||||
_ if NET_KEYWORDS.contains(&kw.as_str())
|
||||
|| TYPE_KEYWORDS.contains(&kw.as_str())
|
||||
|| matches!(kw.as_str(), "var" | "automatic" | "static" | "const" | "signed"
|
||||
| "unsigned") =>
|
||||
|| matches!(
|
||||
kw.as_str(),
|
||||
"var" | "automatic" | "static" | "const" | "signed" | "unsigned"
|
||||
) =>
|
||||
{
|
||||
let d = self.parse_data_decl()?;
|
||||
Ok(ItemKind::DataDecl(d))
|
||||
@@ -647,7 +662,9 @@ impl Parser {
|
||||
let t = self.cur();
|
||||
if t.kind == TokenKind::Keyword && NET_KEYWORDS.contains(&t.text.as_str()) {
|
||||
net = Some(self.bump().text);
|
||||
} else if t.is_kw("var") || t.is_kw("automatic") || t.is_kw("static")
|
||||
} else if t.is_kw("var")
|
||||
|| t.is_kw("automatic")
|
||||
|| t.is_kw("static")
|
||||
|| t.is_kw("const")
|
||||
{
|
||||
qualifiers.push(self.bump().text);
|
||||
@@ -1398,11 +1415,8 @@ impl Parser {
|
||||
(None, Some(Box::new(self.parse_stmt()?)))
|
||||
} else {
|
||||
let then = Box::new(self.parse_stmt()?);
|
||||
let els = if self.eat_kw("else") {
|
||||
Some(Box::new(self.parse_stmt()?))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let els =
|
||||
if self.eat_kw("else") { Some(Box::new(self.parse_stmt()?)) } else { None };
|
||||
(Some(then), els)
|
||||
};
|
||||
Ok(StmtKind::Assert { kw, cond, then, els })
|
||||
@@ -1495,8 +1509,7 @@ impl Parser {
|
||||
fn parse_for_step(&mut self) -> PResult<ForStep> {
|
||||
let lhs = self.parse_unary()?;
|
||||
let op = self.cur().text.clone();
|
||||
if self.cur().kind == TokenKind::Symbol
|
||||
&& (ASSIGN_OPS.contains(&op.as_str()) || op == "<=")
|
||||
if self.cur().kind == TokenKind::Symbol && (ASSIGN_OPS.contains(&op.as_str()) || op == "<=")
|
||||
{
|
||||
self.bump();
|
||||
let rhs = self.parse_expr()?;
|
||||
|
||||
Reference in new issue
Block a user