Skip to content

Commit 119e695

Browse files
committed
---
yaml --- r: 79247 b: refs/heads/auto c: 9d33001 h: refs/heads/master i: 79245: c803287 79243: 5af95dc 79239: 4403aac 79231: 4054729 v: v3
1 parent 1d31b9e commit 119e695

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: cd4e637ae4113d4c49a2e5c533b5bf48fbf7cc6e
16+
refs/heads/auto: 9d33001a90319fc242dcf43ec3c7e1fa1c11d847
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libsyntax/parse/token.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::cmp::Equiv;
2020
use std::local_data;
2121
use std::rand;
2222
use std::rand::RngUtil;
23+
use std::ptr::to_unsafe_ptr;
2324

2425
#[deriving(Clone, Encodable, Decodable, Eq, IterBytes)]
2526
pub enum binop {
@@ -544,15 +545,31 @@ pub fn gensym_ident(str : &str) -> ast::Ident {
544545
}
545546

546547
// create a fresh name that maps to the same string as the old one.
548+
// note that this guarantees that ptr_eq(ident_to_str(src),interner_get(fresh_name(src)));
549+
// that is, that the new name and the old one are connected to ptr_eq strings.
547550
pub fn fresh_name(src : &ast::Ident) -> Name {
548551
gensym(ident_to_str(src))
549552
// following: debug version. Could work in final except that it's incompatible with
550553
// good error messages and uses of struct names in ambiguous could-be-binding
551-
// locations.
554+
// locations. Also definitely destroys the guarantee given above about ptr_eq.
552555
/*let num = rand::rng().gen_uint_range(0,0xffff);
553556
gensym(fmt!("%s_%u",ident_to_str(src),num))*/
554557
}
555558

559+
// it looks like there oughta be a str_ptr_eq fn, but no one bothered to implement it?
560+
pub fn str_ptr_eq<T>(a: @str, b: @str) -> bool {
561+
// doesn't compile! ...because of rebase mangling. this should be fixed
562+
// in the commit that follows this.
563+
let (a_ptr, b_ptr): (*uint, *uint) = (to_unsafe_ptr(a), to_unsafe_ptr(b));
564+
a_ptr == b_ptr
565+
}
566+
567+
568+
569+
// return true when two identifiers refer (through the intern table) to the same ptr_eq
570+
// string. This is used to compare identifiers in places where hygienic comparison is
571+
// not wanted (i.e. not lexical vars).
572+
556573
// create a fresh mark.
557574
pub fn fresh_mark() -> Mrk {
558575
gensym("mark")
@@ -698,5 +715,19 @@ pub fn is_reserved_keyword(tok: &Token) -> bool {
698715
#[cfg(test)]
699716
mod test {
700717
use super::*;
718+
use std::io;
719+
use std::managed;
720+
use ast;
721+
use ast_util;
722+
723+
724+
#[test] fn t1() {
725+
let ghi = str_to_ident("ghi");
726+
assert_eq!(ident_to_str(&ghi),@"ghi");
727+
let fresh = ast::Ident::new(fresh_name(&ghi));
728+
assert_eq!(ident_to_str(&fresh),@"ghi");
729+
assert!(str_ptr_eq(ident_to_str(&ghi),ident_to_str(&fresh)));
730+
assert_eq!(3,4);
731+
}
701732

702733
}

0 commit comments

Comments
 (0)