diff --git a/src/gl_generator/generators/struct_gen.rs b/src/gl_generator/generators/struct_gen.rs index a9b5e1f1..5fd296df 100644 --- a/src/gl_generator/generators/struct_gen.rs +++ b/src/gl_generator/generators/struct_gen.rs @@ -154,11 +154,11 @@ fn write_struct(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P { #[allow(non_snake_case)] #[allow(dead_code)] #[stable] - pub struct {ns:c} {{ + pub struct {ns} {{ {ptrs} }}", - ns = *ns, + ns = ns.fmt_struct_name(), ptrs = registry.cmd_iter().map(|c| { let fallbacks = match registry.aliases.get(&c.proto.ident) { Some(v) => v.clone(), @@ -176,7 +176,7 @@ fn write_struct(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P { /// Creates the `impl` of the structure created by `write_struct`. fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P { ecx.parse_item(format!(" - impl {ns:c} {{ + impl {ns} {{ /// Load each OpenGL symbol using a custom load function. This allows for the /// use of functions like `glfwGetProcAddress` or `SDL_GL_GetProcAddress`. /// @@ -186,7 +186,7 @@ fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P { #[unstable] #[allow(dead_code)] #[allow(unused_variables)] - pub fn load_with(loadfn: |symbol: &str| -> *const __gl_imports::libc::c_void) -> {ns:c} {{ + pub fn load_with(loadfn: |symbol: &str| -> *const __gl_imports::libc::c_void) -> {ns} {{ let metaloadfn: |&str, &[&str]| -> *const __gl_imports::libc::c_void = |symbol, symbols| {{ let mut ptr = loadfn(symbol); if ptr.is_null() {{ @@ -197,7 +197,7 @@ fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P { }} ptr }}; - {ns:c} {{ + {ns} {{ {loadings} }} }} @@ -210,14 +210,14 @@ fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P { #[unstable] #[allow(dead_code)] #[allow(unused_variables)] - pub fn load(loader: &T) -> {ns:c} {{ - {ns:c}::load_with(|name| loader.get_proc_addr(name)) + pub fn load(loader: &T) -> {ns} {{ + {ns}::load_with(|name| loader.get_proc_addr(name)) }} {modules} }}", - ns = *ns, + ns = ns.fmt_struct_name(), loadings = registry.cmd_iter().map(|c| { let fallbacks = registry.aliases.get(&c.proto.ident); diff --git a/src/gl_generator/lib.rs b/src/gl_generator/lib.rs index 09ed7f7a..8a915974 100644 --- a/src/gl_generator/lib.rs +++ b/src/gl_generator/lib.rs @@ -181,19 +181,19 @@ pub fn generate_bindings(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree], return DummyResult::any(span); } api = Some(match tts { - [&TtToken(_, token::LitStr(api))] if api.as_str() == "gl" + [&TtToken(_, token::Literal(token::Str_(api), None))] if api.as_str() == "gl" => (registry::Ns::Gl, khronos_api::GL_XML), - [&TtToken(_, token::LitStr(api))] if api.as_str() == "glx" + [&TtToken(_, token::Literal(token::Str_(api), None))] if api.as_str() == "glx" => (registry::Ns::Glx, khronos_api::GLX_XML), - [&TtToken(_, token::LitStr(api))] if api.as_str() == "wgl" + [&TtToken(_, token::Literal(token::Str_(api), None))] if api.as_str() == "wgl" => (registry::Ns::Wgl, khronos_api::WGL_XML), - [&TtToken(_, token::LitStr(api))] if api.as_str() == "egl" + [&TtToken(_, token::Literal(token::Str_(api), None))] if api.as_str() == "egl" => (registry::Ns::Egl, khronos_api::EGL_XML), - [&TtToken(_, token::LitStr(api))] if api.as_str() == "gles1" + [&TtToken(_, token::Literal(token::Str_(api), None))] if api.as_str() == "gles1" => (registry::Ns::Gles1, khronos_api::GL_XML), - [&TtToken(_, token::LitStr(api))] if api.as_str() == "gles2" + [&TtToken(_, token::Literal(token::Str_(api), None))] if api.as_str() == "gles2" => (registry::Ns::Gles2, khronos_api::GL_XML), - [&TtToken(span, token::LitStr(api))] => { + [&TtToken(span, token::Literal(token::Str_(api), None))] => { ecx.span_err(span, format!("Unknown API \"{}\"", api.as_str()).as_slice()); return DummyResult::any(span); }, @@ -211,11 +211,11 @@ pub fn generate_bindings(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree], return DummyResult::any(span); } profile = Some(match tts { - [&TtToken(_, token::LitStr(profile))] if profile.as_str() == "core" + [&TtToken(_, token::Literal(token::Str_(profile), None))] if profile.as_str() == "core" => "core".to_string(), - [&TtToken(_, token::LitStr(profile))] if profile.as_str() == "compatibility" + [&TtToken(_, token::Literal(token::Str_(profile), None))] if profile.as_str() == "compatibility" => "compatibility".to_string(), - [&TtToken(_, token::LitStr(profile))] => { + [&TtToken(_, token::Literal(token::Str_(profile), None))] => { let span = tts.head().map_or(span, |tt| tt.get_span()); ecx.span_err(span, format!("Unknown profile \"{}\"", profile.as_str()).as_slice()); @@ -236,7 +236,7 @@ pub fn generate_bindings(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree], return DummyResult::any(span); } version = Some(match tts { - [&TtToken(_, token::LitStr(version))] => { + [&TtToken(_, token::Literal(token::Str_(version), None))] => { version.as_str().to_string() }, _ => { @@ -254,7 +254,7 @@ pub fn generate_bindings(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree], return DummyResult::any(span); } match tts { - [&TtToken(span, token::LitStr(gen))] => { + [&TtToken(span, token::Literal(token::Str_(gen), None))] => { if generators.is_none() { continue; } for (name, generator_) in generators.take().unwrap().into_iter() { if name == gen.as_str() { @@ -294,7 +294,7 @@ pub fn generate_bindings(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree], let mut failed = false; let exts = tts.split(is_comma).scan((), |_, tts| { match tts { - [TtToken(_, token::LitStr(ext))] => { + [TtToken(_, token::Literal(token::Str_(ext), None))] => { Some(ext.as_str().to_string()) }, _ => { diff --git a/src/gl_generator/registry.rs b/src/gl_generator/registry.rs index 76441fc6..e6901bf4 100644 --- a/src/gl_generator/registry.rs +++ b/src/gl_generator/registry.rs @@ -33,6 +33,19 @@ use self::Ns::{Gl, Glx, Wgl, Egl, Gles1, Gles2}; pub enum Ns { Gl, Glx, Wgl, Egl, Gles1, Gles2 } +impl Ns { + pub fn fmt_struct_name(&self) -> &str { + match *self { + Gl => "Gl", + Glx => "Glx", + Wgl => "Wgl", + Egl => "Egl", + Gles1 => "Gles1", + Gles2 => "Gles2", + } + } +} + impl FromStr for Ns { fn from_str(s: &str) -> Option { match s { @@ -60,19 +73,6 @@ impl fmt::Show for Ns { } } -impl fmt::Char for Ns { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - match *self { - Gl => write!(fmt, "Gl"), - Glx => write!(fmt, "Glx"), - Wgl => write!(fmt, "Wgl"), - Egl => write!(fmt, "Egl"), - Gles1 => write!(fmt, "Gles1"), - Gles2 => write!(fmt, "Gles2"), - } - } -} - fn trim_str<'a>(s: &'a str, trim: &str) -> &'a str { if s.starts_with(trim) { s.slice_from(trim.len()) } else { s } } @@ -501,7 +501,7 @@ impl<'a, R: Buffer> RegistryBuilder { } fn consume_two<'a, T: FromXML, U: FromXML>(&self, one: &'a str, two: &'a str, end: &'a str) -> (Vec, Vec) { - debug!("consume_two: looking for {:s} and {:s} until {:s}", one, two, end); + debug!("consume_two: looking for {} and {} until {}", one, two, end); let mut ones = Vec::new(); let mut twos = Vec::new(); @@ -755,7 +755,7 @@ impl FromXML for Feature { let name = get_attribute(a, "name").unwrap(); let number = get_attribute(a, "number").unwrap(); - debug!("Found api = {:s}, name = {:s}, number = {:s}", api, name, number); + debug!("Found api = {}, name = {}, number = {}", api, name, number); let (require, remove) = r.consume_two("require", "remove", "feature");