Skip to content

Commit

Permalink
add atom definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
kcking committed Oct 5, 2022
1 parent 2dc75e0 commit f5a124e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
55 changes: 54 additions & 1 deletion generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct Parser {
/// *FlagBits -> *Flags
bitvalues: HashMap<String, String>,
handles: IndexSet<String>,
atoms: IndexSet<String>,
structs: IndexMap<String, Struct>,
struct_aliases: Vec<(String, String)>,
api_constants: Vec<(String, usize)>,
Expand All @@ -69,6 +70,7 @@ impl Parser {
bitmasks: IndexMap::new(),
bitvalues: HashMap::new(),
handles: IndexSet::new(),
atoms: IndexSet::new(),
structs: IndexMap::new(),
struct_aliases: Vec::new(),
api_constants: Vec::new(),
Expand Down Expand Up @@ -480,7 +482,10 @@ impl Parser {
Some("define") => {
self.parse_define();
}
Some("include") | Some("basetype") | Some("funcpointer") | None => {
Some("basetype") => {
self.parse_basetype();
}
Some("include") | Some("funcpointer") | None => {
// Intentionally skipped
self.finish_element();
}
Expand Down Expand Up @@ -829,6 +834,41 @@ impl Parser {
}
}

fn parse_basetype(&mut self) {
let mut is_atom = false;
loop {
use XmlEvent::*;
match self.reader.next().expect("failed to parse XML") {
StartElement { name, .. } => {
match &name.local_name[..] {
"name" => {
if is_atom {
let name = self.parse_characters();
self.atoms.insert(name);
}
}
"type" => {
if self.parse_characters() == "XR_DEFINE_ATOM" {
is_atom = true;
}
}
_ => {
eprintln!("unimplemented basetype element: {}", name.local_name);
}
}
self.finish_element();
}
EndElement { name } => {
if name.local_name == "type" {
break;
}
eprintln!("unexpected end element in basetype, type: {}", name);
}
_ => {}
}
}
}

fn finish_element(&mut self) {
let mut depth: u32 = 0;
loop {
Expand Down Expand Up @@ -1039,6 +1079,18 @@ impl Parser {
}
});

let atoms = self.atoms.iter().map(|name| {
let ident = xr_ty_name(name);
let doc = format!("See {}", self.doc_link(name));
quote! {
#[doc = #doc]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct #ident(u64);
handle!(#ident);
}
});

let structs = self.structs.iter().map(|(name, s)| {
let ident = xr_ty_name(name);
let members = s.members.iter().map(|m| {
Expand Down Expand Up @@ -1209,6 +1261,7 @@ impl Parser {
#(#enums)*
#(#bitmasks)*
#(#handles)*
#(#atoms)*
#(#structs)*

/// Function pointer prototypes
Expand Down
25 changes: 25 additions & 0 deletions sys/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,31 @@ handle!(SpatialAnchorStoreConnectionMSFT);
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct FacialTrackerHTC(u64);
handle!(FacialTrackerHTC);
#[doc = "See [XrPath](https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPath)"]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Path(u64);
handle!(Path);
#[doc = "See [XrSystemId](https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrSystemId)"]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct SystemId(u64);
handle!(SystemId);
#[doc = "See [XrControllerModelKeyMSFT](https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrControllerModelKeyMSFT)"]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct ControllerModelKeyMSFT(u64);
handle!(ControllerModelKeyMSFT);
#[doc = "See [XrAsyncRequestIdFB](https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrAsyncRequestIdFB)"]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct AsyncRequestIdFB(u64);
handle!(AsyncRequestIdFB);
#[doc = "See [XrRenderModelKeyFB](https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrRenderModelKeyFB)"]
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct RenderModelKeyFB(u64);
handle!(RenderModelKeyFB);
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, PartialEq)]
#[doc = "See [XrVector2f](https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrVector2f)"]
Expand Down

0 comments on commit f5a124e

Please sign in to comment.