Skip to content

Commit

Permalink
Updated to latest Rust
Browse files Browse the repository at this point in the history
ozkriff committed May 29, 2014
1 parent 8de1bd6 commit 5db331f
Showing 3 changed files with 35 additions and 35 deletions.
34 changes: 17 additions & 17 deletions src/gen/main.rs
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ fn main() {
optopt("", "xml", "The xml spec file (<namespace>.xml by default)", ""),
];

let os_args = os::args().iter().map(|x| x.to_strbuf()).collect::<Vec<String>>();
let os_args = os::args().iter().map(|x| x.to_string()).collect::<Vec<String>>();
let args = match getopts(os_args.as_slice(), opts) {
Ok(a) => a,
Err(x) => fail!("Error: {}\n{}", x.to_err_msg(), usage("glrsgen", opts)),
@@ -70,25 +70,25 @@ fn main() {
return;
}

let ns = match args.opt_str("namespace").unwrap_or("gl".to_strbuf()).as_slice() {
let ns = match args.opt_str("namespace").unwrap_or("gl".to_string()).as_slice() {
"gl" => Gl,
"glx" => fail!("glx generation unimplemented"),
"wgl" => fail!("wgl generation unimplemented"),
ns => fail!("Unexpected opengl namespace '{}'", ns)
};

let path = Path::new(
args.opt_str("xml").unwrap_or(format_strbuf!("{}.xml", ns))
args.opt_str("xml").unwrap_or(format!("{}.xml", ns))
);

let filter = if args.opt_present("full") {
None
} else {
Some(Filter {
extensions: args.opt_strs("extension"),
profile: args.opt_str("profile").unwrap_or("core".to_strbuf()),
version: args.opt_str("version").unwrap_or("4.3".to_strbuf()),
api: args.opt_str("api").unwrap_or("gl".to_strbuf()),
profile: args.opt_str("profile").unwrap_or("core".to_string()),
version: args.opt_str("version").unwrap_or("4.3".to_string()),
api: args.opt_str("api").unwrap_or("gl".to_string()),
})
};

@@ -116,18 +116,18 @@ fn gen_binding_ident(binding: &Binding, use_idents: bool) -> String {
// fixed
if use_idents {
match binding.ident.as_slice() {
"in" => "in_".to_strbuf(),
"ref" => "ref_".to_strbuf(),
"type" => "type_".to_strbuf(),
ident => ident.to_strbuf(),
"in" => "in_".to_string(),
"ref" => "ref_".to_string(),
"type" => "type_".to_string(),
ident => ident.to_string(),
}
} else {
"_".to_strbuf()
"_".to_string()
}
}

fn gen_binding(binding: &Binding, use_idents: bool) -> String {
format_strbuf!("{}: {}",
format!("{}: {}",
gen_binding_ident(binding, use_idents),
ty::to_rust_ty(binding.ty.as_slice()))
}
@@ -136,21 +136,21 @@ fn gen_param_list(cmd: &Cmd, use_idents: bool) -> String {
cmd.params.iter()
.map(|b| gen_binding(b, use_idents))
.collect::<Vec<String>>()
.connect(", ").to_strbuf()
.connect(", ").to_string()
}

fn gen_param_ident_list(cmd: &Cmd) -> String {
cmd.params.iter()
.map(|b| gen_binding_ident(b, true))
.collect::<Vec<String>>()
.connect(", ").to_strbuf()
.connect(", ").to_string()
}

fn gen_param_ty_list(cmd: &Cmd) -> String {
cmd.params.iter()
.map(|b| ty::to_rust_ty(b.ty.as_slice()))
.collect::<Vec<&str>>()
.connect(", ").to_strbuf()
.connect(", ").to_string()
}

fn gen_return_suffix(cmd: &Cmd) -> String {
@@ -162,7 +162,7 @@ fn gen_symbol_name(ns: &Ns, cmd: &Cmd) -> String {
Gl => "gl",
Glx => "glx",
Wgl => "wgl",
}).to_strbuf().append(cmd.proto.ident.as_slice())
}).to_string().append(cmd.proto.ident.as_slice())
}

impl<'a, W: Writer> Generator<'a, W> {
@@ -202,7 +202,7 @@ impl<'a, W: Writer> Generator<'a, W> {

fn write_enum(&mut self, enm: &Enum) {
let ident = if (enm.ident.as_slice()[0] as char).is_digit() {
format_strbuf!("_{}", enm.ident)
format!("_{}", enm.ident)
} else {
enm.ident.clone()
};
32 changes: 16 additions & 16 deletions src/gen/registry.rs
Original file line number Diff line number Diff line change
@@ -314,8 +314,8 @@ impl<'a> RegistryBuilder {
match self.recv() {
// ignores
Characters(_) | Comment(_) => (),
StartElement(ref s, _) if s.as_slice() == "comment" => self.skip_until(EndElement("comment".to_strbuf())),
StartElement(ref s, _) if s.as_slice() == "types" => self.skip_until(EndElement("types".to_strbuf())),
StartElement(ref s, _) if s.as_slice() == "comment" => self.skip_until(EndElement("comment".to_string())),
StartElement(ref s, _) if s.as_slice() == "types" => self.skip_until(EndElement("types".to_string())),

// add groups
StartElement(ref s, _) if s.as_slice() == "groups" => {
@@ -343,7 +343,7 @@ impl<'a> RegistryBuilder {
}

StartElement(ref s, ref atts) if s.as_slice() == "feature" => {
debug!("Parsing feature: {:?}", atts);
debug!("Parsing feature: {}", atts);
registry.features.push(FromXML::convert(self, atts));
}

@@ -398,11 +398,11 @@ impl<'a> RegistryBuilder {
for rem in f.removes.iter() {
if rem.profile == filter.profile {
for enm in rem.enums.iter() {
debug!("Removing {:?}", enm);
debug!("Removing {}", enm);
desired_enums.remove(enm);
}
for cmd in rem.commands.iter() {
debug!("Removing {:?}", cmd);
debug!("Removing {}", cmd);
desired_cmds.remove(cmd);
}
}
@@ -428,8 +428,8 @@ impl<'a> RegistryBuilder {

Registry {
groups: groups,
enums: enums.move_iter().filter(|e| desired_enums.contains(&("GL_".to_strbuf().append(e.ident.as_slice())))).collect::<Vec<Enum>>(),
cmds: cmds.move_iter().filter(|c| desired_cmds.contains(&("gl".to_strbuf().append(c.proto.ident.as_slice())))).collect::<Vec<Cmd>>(),
enums: enums.move_iter().filter(|e| desired_enums.contains(&("GL_".to_string().append(e.ident.as_slice())))).collect::<Vec<Enum>>(),
cmds: cmds.move_iter().filter(|c| desired_cmds.contains(&("gl".to_string().append(c.proto.ident.as_slice())))).collect::<Vec<Cmd>>(),
// these aren't important after this step
features: Vec::new(),
extensions: Vec::new(),
@@ -448,8 +448,8 @@ impl<'a> RegistryBuilder {
loop {
match self.recv() {
StartElement(ref name, ref atts) => {
debug!("Found start element <{:?} {:?}>", name, atts);
debug!("one and two are {:?} and {:?}", one, two);
debug!("Found start element <{} {}>", name, atts);
debug!("one and two are {} and {}", one, two);

let n = name.clone();

@@ -464,11 +464,11 @@ impl<'a> RegistryBuilder {
} else if two == n.as_slice() {
twos.push(FromXML::convert(self, atts));
} else {
fail!("Unexpected element: <{:?} {:?}>", n, atts);
fail!("Unexpected element: <{} {}>", n, atts);
}
},
EndElement(ref name) => {
debug!("Found end element </{:?}>", name);
debug!("Found end element </{}>", name);

if (&[one, two]).iter().any(|&x| x == name.as_slice()) {
continue;
@@ -512,13 +512,13 @@ impl<'a> RegistryBuilder {
match self.recv() {
// ignores
Characters(_) | Comment(_) => (),
StartElement(ref s, _) if s.as_slice() == "unused" => self.skip_until(EndElement("unused".to_strbuf())),
StartElement(ref s, _) if s.as_slice() == "unused" => self.skip_until(EndElement("unused".to_string())),

// add enum definition
StartElement(ref s, ref atts) if s.as_slice() == "enum" => {
enums.push(
Enum {
ident: trim_enum_prefix(atts.get("name"), self.ns).to_strbuf(),
ident: trim_enum_prefix(atts.get("name"), self.ns).to_string(),
value: atts.get_clone("value"),
alias: atts.find_clone("alias"),
ty: atts.find_clone("type"),
@@ -557,7 +557,7 @@ impl<'a> RegistryBuilder {
// consume command prototype
let proto_atts = self.expect_start_element("proto");
let mut proto = self.consume_binding(proto_atts.find_clone("group"));
proto.ident = trim_cmd_prefix(proto.ident.as_slice(), self.ns).to_strbuf();
proto.ident = trim_cmd_prefix(proto.ident.as_slice(), self.ns).to_string();
self.expect_end_element("proto");

let mut params = Vec::new();
@@ -622,7 +622,7 @@ impl<'a> RegistryBuilder {
self.expect_end_element("name");
Binding {
ident: ident,
ty: ty.into_strbuf(),
ty: ty.into_string(),
group: group,
}
}
@@ -686,7 +686,7 @@ impl FromXML for Extension {
fn convert(r: &RegistryBuilder, a: &sax::Attributes) -> Extension {
debug!("Doing a FromXML on Extension");
let name = a.get_clone("name");
let supported = a.get("supported").split('|').map(|x| x.to_strbuf()).collect::<Vec<String>>();
let supported = a.get("supported").split('|').map(|x| x.to_string()).collect::<Vec<String>>();
let mut require = Vec::new();
loop {
match r.recv() {
4 changes: 2 additions & 2 deletions src/gen/ty.rs
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@

pub fn to_return_suffix(ty: &str) -> String {
match ty {
"c_void" | "VOID" | "GLvoid" => "".to_strbuf(),
ty_str => format_strbuf!(" -> {}", ty_str.replace("*mut ", "*")),
"c_void" | "VOID" | "GLvoid" => "".to_string(),
ty_str => format!(" -> {}", ty_str.replace("*mut ", "*")),
}
}

0 comments on commit 5db331f

Please sign in to comment.