[meta] Move the doc() default values in the Operand/OperandKind;
This commit is contained in:
@@ -19,11 +19,21 @@ use crate::cdsl::typevar::TypeVar;
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct Operand {
|
||||
pub name: &'static str,
|
||||
pub doc: Option<String>,
|
||||
doc: Option<String>,
|
||||
pub kind: OperandKind,
|
||||
}
|
||||
|
||||
impl Operand {
|
||||
pub fn doc(&self) -> Option<&str> {
|
||||
match &self.doc {
|
||||
Some(doc) => Some(doc),
|
||||
None => match &self.kind.fields {
|
||||
OperandKindFields::TypeVar(tvar) => Some(&tvar.doc),
|
||||
_ => self.kind.doc(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_value(&self) -> bool {
|
||||
match self.kind.fields {
|
||||
OperandKindFields::TypeVar(_) => true,
|
||||
@@ -95,17 +105,9 @@ impl OperandBuilder {
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> Operand {
|
||||
let doc = match self.doc {
|
||||
Some(doc) => Some(doc),
|
||||
None => match &self.kind.fields {
|
||||
OperandKindFields::TypeVar(tvar) => Some(tvar.doc.clone()),
|
||||
_ => self.kind.doc.clone(),
|
||||
},
|
||||
};
|
||||
|
||||
Operand {
|
||||
name: self.name,
|
||||
doc,
|
||||
doc: self.doc,
|
||||
kind: self.kind,
|
||||
}
|
||||
}
|
||||
@@ -137,6 +139,19 @@ pub(crate) struct OperandKind {
|
||||
}
|
||||
|
||||
impl OperandKind {
|
||||
fn doc(&self) -> Option<&str> {
|
||||
match &self.doc {
|
||||
Some(doc) => Some(&doc),
|
||||
None => match &self.fields {
|
||||
OperandKindFields::TypeVar(type_var) => Some(&type_var.doc),
|
||||
OperandKindFields::ImmEnum(_)
|
||||
| OperandKindFields::ImmValue
|
||||
| OperandKindFields::EntityRef
|
||||
| OperandKindFields::VariableArgs => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn imm_name(&self) -> Option<&str> {
|
||||
match self.fields {
|
||||
OperandKindFields::ImmEnum(_)
|
||||
@@ -230,20 +245,9 @@ impl OperandKindBuilder {
|
||||
},
|
||||
};
|
||||
|
||||
let doc = match self.doc {
|
||||
Some(doc) => Some(doc),
|
||||
None => match &self.fields {
|
||||
OperandKindFields::TypeVar(type_var) => Some(type_var.doc.clone()),
|
||||
OperandKindFields::ImmEnum(_)
|
||||
| OperandKindFields::ImmValue
|
||||
| OperandKindFields::EntityRef
|
||||
| OperandKindFields::VariableArgs => None,
|
||||
},
|
||||
};
|
||||
|
||||
OperandKind {
|
||||
name: self.name,
|
||||
doc,
|
||||
doc: self.doc,
|
||||
default_member,
|
||||
rust_type,
|
||||
fields: self.fields,
|
||||
|
||||
@@ -925,8 +925,7 @@ fn gen_inst_builder(inst: &Instruction, format: &InstructionFormat, fmt: &mut Fo
|
||||
args_doc.push(format!(
|
||||
"- {}: {}",
|
||||
op.name,
|
||||
op.doc
|
||||
.as_ref()
|
||||
op.doc()
|
||||
.expect("every instruction's input operand must be documented")
|
||||
));
|
||||
}
|
||||
@@ -935,8 +934,7 @@ fn gen_inst_builder(inst: &Instruction, format: &InstructionFormat, fmt: &mut Fo
|
||||
rets_doc.push(format!(
|
||||
"- {}: {}",
|
||||
op.name,
|
||||
op.doc
|
||||
.as_ref()
|
||||
op.doc()
|
||||
.expect("every instruction's output operand must be documented")
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user