Skip to content

Commit f5c7d9c

Browse files
committed
---
yaml --- r: 79344 b: refs/heads/try c: 358d521 h: refs/heads/master v: v3
1 parent e3e4e46 commit f5c7d9c

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e6de6b7da8ee88bf84b0e217900051334be08da
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
5-
refs/heads/try: 41a939aa5f0ae8d2864bff0bd17ffc2b8760688d
5+
refs/heads/try: 358d5213ffcd1c2f8514da9ca24572ecf81bac5e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/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)