Skip to content

Commit

Permalink
feat: qemu 8.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arcnmx committed May 7, 2024
1 parent 479752d commit fa360b8
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qapi-codegen"
version = "0.11.1" # keep in sync with html_root_url
version = "0.11.2" # keep in sync with html_root_url
authors = ["arcnmx"]
edition = "2018"

Expand All @@ -17,4 +17,4 @@ travis-ci = { repository = "arcnmx/qapi-rs" }
maintenance = { status = "passively-maintained" }

[dependencies]
qapi-parser = { version = "0.10", path = "../parser" }
qapi-parser = { version = "0.11", path = "../parser" }
36 changes: 27 additions & 9 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/qapi-codegen/0.11.1")]
#![doc(html_root_url = "https://docs.rs/qapi-codegen/0.11.2")]

//! Generates Rust types for the [QAPI schema language](https://qemu-project.gitlab.io/qemu/devel/qapi-code-gen.html#the-qapi-schema-language)
Expand Down Expand Up @@ -127,7 +127,7 @@ struct Context<W> {
includes: Vec<String>,
included: HashSet<PathBuf>,
events: Vec<spec::Event>,
unions: Vec<spec::CombinedUnion>,
unions: BTreeMap<String, spec::CombinedUnion>,
enums: BTreeMap<String, spec::Enum>,
types: BTreeMap<String, spec::Struct>,
struct_discriminators: BTreeMap<String, String>,
Expand Down Expand Up @@ -274,10 +274,24 @@ unsafe impl ::qapi_spec::Enum for {} {{
Spec::Event(v) => {
write!(self.out, "
#[derive(Debug, Clone, Serialize, Deserialize{})]
pub struct {} {{
", if v.data.is_empty() { ", Default" } else { "" }, event_identifier(&v.id))?;
for item in &v.data.fields {
writeln!(self.out, "{},", valuety(item, true, &v.id))?;
", if v.data.is_empty() { ", Default" } else { "" })?;
if let spec::DataOrType::Type(..) = v.data {
writeln!(self.out, "#[serde(transparent)]")?;
writeln!(self.out, "#[repr(transparent)]")?;
}
writeln!(self.out, "pub struct {} {{", event_identifier(&v.id))?;
match v.data {
spec::DataOrType::Type(ref ty) => {
let data = spec::Value {
name: "data".into(),
ty: ty.clone(),
optional: false,
};
writeln!(self.out, "{},", valuety(&data, true, &v.id))?
},
spec::DataOrType::Data(ref data) => for item in &data.fields {
writeln!(self.out, "{},", valuety(item, true, &v.id))?;
},
}
writeln!(self.out, "}}")?;
writeln!(self.out, "
Expand All @@ -298,7 +312,7 @@ pub enum {} {{
writeln!(self.out, "}}")?;
},
Spec::CombinedUnion(v) => {
self.unions.push(v);
self.unions.insert(v.id.clone(), v);
},
Spec::PragmaWhitelist { .. } => (),
Spec::PragmaExceptions { .. } => (),
Expand Down Expand Up @@ -400,7 +414,7 @@ impl {} {{
}

fn process_unions(&mut self) -> io::Result<()> {
for u in &self.unions {
for u in self.unions.values() {
let discrim = u.discriminator.as_ref().map(|s| &s[..]).unwrap_or("type");
let type_id = type_identifier(&u.id);
write!(self.out, "
Expand Down Expand Up @@ -540,8 +554,12 @@ impl From<{}> for {} {{
}}
", variant_ty, type_id, variant_ty, variant_name)?;
let ty = self.types.get(&variant.ty.name)
.map(|ty| ty.wrapper_type())
.or_else(|| self.unions.get(&variant.ty.name)
.map(|_e| None)
)
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, format!("could not find qapi type {}, needed by {}", variant.ty.name, u.id)))?;
if let Some(newtype) = ty.wrapper_type() {
if let Some(newtype) = ty {
let newtype_ty = typename(&newtype.ty);
write!(self.out, "
impl From<{}> for {} {{
Expand Down
2 changes: 1 addition & 1 deletion parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qapi-parser"
version = "0.10.0" # keep in sync with html_root_url
version = "0.11.0" # keep in sync with html_root_url
authors = ["arcnmx"]
edition = "2018"

Expand Down
46 changes: 40 additions & 6 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/qapi-parser/0.10.0")]
#![doc(html_root_url = "https://docs.rs/qapi-parser/0.11.0")]

pub mod spec {
use std::fmt;
Expand Down Expand Up @@ -235,6 +235,9 @@ pub mod spec {
#[serde(untagged, rename_all = "kebab-case")]
pub enum Conditional {
Define(ConditionalDefinition),
Not {
not: ConditionalDefinition,
},
All {
all: Vec<ConditionalDefinition>,
},
Expand Down Expand Up @@ -263,12 +266,21 @@ pub mod spec {
#[serde(default)]
pub allow_oob: bool,
#[serde(default)]
pub coroutine: bool,
#[serde(default)]
pub boxed: bool,
#[serde(default = "Command::success_response_default")]
pub success_response: bool,
#[serde(default)]
pub allow_preconfig: bool,
#[serde(default)]
pub features: Features,
#[serde(default = "Command::gen_default")]
pub gen: bool,
}

impl Command {
fn success_response_default() -> bool { true }
fn gen_default() -> bool { true }
}

Expand Down Expand Up @@ -326,6 +338,8 @@ pub mod spec {
pub id: String,
#[serde(default)]
pub data: Vec<SpecName>,
#[serde(default)]
pub prefix: Option<String>,
#[serde(default, rename = "if")]
pub conditional: Option<Conditional>,
}
Expand Down Expand Up @@ -390,9 +404,11 @@ pub mod spec {
#[serde(rename = "event")]
pub id: String,
#[serde(default)]
pub data: Data,
pub data: DataOrType,
#[serde(default, rename = "if")]
pub conditional: Option<Conditional>,
#[serde(default)]
pub features: Features,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -425,23 +441,41 @@ pub mod spec {
name: String,
#[serde(rename = "if")]
conditional: Conditional,
#[serde(default)]
features: Features,
},
Explicit {
name: String,
#[serde(default)]
features: Features,
},
}

impl SpecName {
pub fn name(&self) -> &String {
match self {
SpecName::Name(name) | SpecName::Explicit { name, .. } => name,
SpecName::Conditional { name, .. } => name,
}
}

pub fn features(&self) -> Option<&Features> {
match self {
SpecName::Name(..) => None,
SpecName::Explicit { features, .. } => Some(features),
SpecName::Conditional { features, .. } => Some(features),
}
}
}

impl fmt::Display for SpecName {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self.as_ref(), fmt)
}
}
impl AsRef<str> for SpecName {
fn as_ref(&self) -> &str {
match self {
SpecName::Name(name) | SpecName::Explicit { name } => &name[..],
SpecName::Conditional { name, .. } => &name[..],
}
&self.name()[..]
}
}
}
Expand Down
1 change: 1 addition & 0 deletions qmp/schema/qapi/machine-common.json

0 comments on commit fa360b8

Please sign in to comment.