Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/gl_generator/generators/struct_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ fn write_struct(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P<ast::Item> {
#[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(),
Expand All @@ -176,7 +176,7 @@ fn write_struct(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P<ast::Item> {
/// Creates the `impl` of the structure created by `write_struct`.
fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P<ast::Item> {
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`.
///
Expand All @@ -186,7 +186,7 @@ fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P<ast::Item> {
#[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() {{
Expand All @@ -197,7 +197,7 @@ fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P<ast::Item> {
}}
ptr
}};
{ns:c} {{
{ns} {{
{loadings}
}}
}}
Expand All @@ -210,14 +210,14 @@ fn write_impl(ecx: &ExtCtxt, registry: &Registry, ns: &Ns) -> P<ast::Item> {
#[unstable]
#[allow(dead_code)]
#[allow(unused_variables)]
pub fn load<T: __gl_imports::gl_common::GlFunctionsSource>(loader: &T) -> {ns:c} {{
{ns:c}::load_with(|name| loader.get_proc_addr(name))
pub fn load<T: __gl_imports::gl_common::GlFunctionsSource>(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);
Expand Down
26 changes: 13 additions & 13 deletions src/gl_generator/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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());
Expand All @@ -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()
},
_ => {
Expand All @@ -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() {
Expand Down Expand Up @@ -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())
},
_ => {
Expand Down
30 changes: 15 additions & 15 deletions src/gl_generator/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ns> {
match s {
Expand Down Expand Up @@ -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 }
}
Expand Down Expand Up @@ -501,7 +501,7 @@ impl<'a, R: Buffer> RegistryBuilder<R> {
}

fn consume_two<'a, T: FromXML, U: FromXML>(&self, one: &'a str, two: &'a str, end: &'a str) -> (Vec<T>, Vec<U>) {
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();
Expand Down Expand Up @@ -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");

Expand Down