type_id: Cell<NodeId>,
}
+fn get<T: Clone>(cell: &RefCell<T>) -> T {
+ cell.borrow().clone()
+}
+
impl ImportResolution {
fn new(id: NodeId, is_public: bool) -> ImportResolution {
ImportResolution {
fn target_for_namespace(&self, namespace: Namespace)
-> Option<Target> {
match namespace {
- TypeNS => return self.type_target.get(),
- ValueNS => return self.value_target.get(),
+ TypeNS => return self.type_target.borrow().clone(),
+ ValueNS => return self.value_target.borrow().clone(),
}
}
// Merges the module with the existing type def or creates a new one.
let module_ = @Module::new(parent_link, def_id, kind, external,
is_public);
- match self.type_def.get() {
+ let type_def = self.type_def.borrow().clone();
+ match type_def {
None => {
- self.type_def.set(Some(TypeNsDef {
+ *self.type_def.borrow_mut() = Some(TypeNsDef {
is_public: is_public,
module_def: Some(module_),
type_def: None,
type_span: Some(sp)
- }));
+ });
}
Some(type_def) => {
- self.type_def.set(Some(TypeNsDef {
+ *self.type_def.borrow_mut() = Some(TypeNsDef {
is_public: is_public,
module_def: Some(module_),
type_span: Some(sp),
type_def: type_def.type_def
- }));
+ });
}
}
}
external: bool,
is_public: bool,
_sp: Span) {
- match self.type_def.get() {
+ let type_def = self.type_def.borrow().clone();
+ match type_def {
None => {
let module = @Module::new(parent_link, def_id, kind,
external, is_public);
- self.type_def.set(Some(TypeNsDef {
+ *self.type_def.borrow_mut() = Some(TypeNsDef {
is_public: is_public,
module_def: Some(module),
type_def: None,
type_span: None,
- }))
+ });
}
Some(type_def) => {
match type_def.module_def {
kind,
external,
is_public);
- self.type_def.set(Some(TypeNsDef {
+ *self.type_def.borrow_mut() = Some(TypeNsDef {
is_public: is_public,
module_def: Some(module),
type_def: type_def.type_def,
type_span: None,
- }))
+ });
}
Some(module_def) => module_def.kind.set(kind),
}
/// Records a type definition.
fn define_type(&self, def: Def, sp: Span, is_public: bool) {
// Merges the type with the existing type def or creates a new one.
- match self.type_def.get() {
+ let type_def = self.type_def.borrow().clone();
+ match type_def {
None => {
- self.type_def.set(Some(TypeNsDef {
+ *self.type_def.borrow_mut() = Some(TypeNsDef {
module_def: None,
type_def: Some(def),
type_span: Some(sp),
is_public: is_public,
- }));
+ });
}
Some(type_def) => {
- self.type_def.set(Some(TypeNsDef {
+ *self.type_def.borrow_mut() = Some(TypeNsDef {
type_def: Some(def),
type_span: Some(sp),
module_def: type_def.module_def,
is_public: is_public,
- }));
+ });
}
}
}
/// Records a value definition.
fn define_value(&self, def: Def, sp: Span, is_public: bool) {
- self.value_def.set(Some(ValueNsDef {
+ *self.value_def.borrow_mut() = Some(ValueNsDef {
def: def,
value_span: Some(sp),
is_public: is_public,
- }));
+ });
}
/// Returns the module node if applicable.
fn defined_in_namespace(&self, namespace: Namespace) -> bool {
match namespace {
- TypeNS => return self.type_def.get().is_some(),
- ValueNS => return self.value_def.get().is_some()
+ TypeNS => return self.type_def.borrow().is_some(),
+ ValueNS => return self.value_def.borrow().is_some()
}
}
fn defined_in_public_namespace(&self, namespace: Namespace) -> bool {
match namespace {
- TypeNS => match self.type_def.get() {
+ TypeNS => match *self.type_def.borrow() {
Some(def) => def.is_public, None => false
},
- ValueNS => match self.value_def.get() {
+ ValueNS => match *self.value_def.borrow() {
Some(def) => def.is_public, None => false
}
}
fn def_for_namespace(&self, namespace: Namespace) -> Option<Def> {
match namespace {
TypeNS => {
- match self.type_def.get() {
+ match *self.type_def.borrow() {
None => None,
Some(type_def) => {
match type_def.type_def {
}
}
ValueNS => {
- match self.value_def.get() {
+ match *self.value_def.borrow() {
None => None,
Some(value_def) => Some(value_def.def)
}
if self.defined_in_namespace(namespace) {
match namespace {
TypeNS => {
- match self.type_def.get() {
+ match *self.type_def.borrow() {
None => None,
Some(type_def) => type_def.type_span
}
}
ValueNS => {
- match self.value_def.get() {
+ match *self.value_def.borrow() {
None => None,
Some(value_def) => value_def.value_span
}
match def {
DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
DefTy(def_id) => {
- match child_name_bindings.type_def.get() {
+ let type_def = child_name_bindings.type_def.borrow().clone();
+ match type_def {
Some(TypeNsDef { module_def: Some(module_def), .. }) => {
debug!("(building reduced graph for external crate) \
already created module");
// Process the static methods. First,
// create the module.
let type_module;
- match child_name_bindings.type_def.get() {
+ let type_def = child_name_bindings.type_def.borrow().clone();
+ match type_def {
Some(TypeNsDef {
module_def: Some(module_def),
..
match value_result {
BoundResult(target_module, name_bindings) => {
debug!("(resolving single import) found value target");
- import_resolution.value_target.set(
- Some(Target::new(target_module, name_bindings)));
+ *import_resolution.value_target.borrow_mut() =
+ Some(Target::new(target_module, name_bindings));
import_resolution.value_id.set(directive.id);
value_used_public = name_bindings.defined_in_public_namespace(ValueNS);
}
match type_result {
BoundResult(target_module, name_bindings) => {
debug!("(resolving single import) found type target: {:?}",
- {name_bindings.type_def.get().unwrap().type_def});
- import_resolution.type_target.set(
- Some(Target::new(target_module, name_bindings)));
+ { name_bindings.type_def.borrow().clone().unwrap().type_def });
+ *import_resolution.type_target.borrow_mut() =
+ Some(Target::new(target_module, name_bindings));
import_resolution.type_id.set(directive.id);
type_used_public = name_bindings.defined_in_public_namespace(TypeNS);
}
}
}
- if import_resolution.value_target.get().is_none() &&
- import_resolution.type_target.get().is_none() {
+ if import_resolution.value_target.borrow().is_none() &&
+ import_resolution.type_target.borrow().is_none() {
let msg = format!("unresolved import: there is no \
`{}` in `{}`",
token::get_ident(source),
// record what this import resolves to for later uses in documentation,
// this may resolve to either a value or a type, but for documentation
// purposes it's good enough to just favor one over the other.
- let value_private = match import_resolution.value_target.get() {
+ let value_private = match *import_resolution.value_target.borrow() {
Some(target) => {
let def = target.bindings.def_for_namespace(ValueNS).unwrap();
self.def_map.borrow_mut().insert(directive.id, def);
// _exists is false.
None => None,
};
- let type_private = match import_resolution.type_target.get() {
+ let type_private = match *import_resolution.type_target.borrow() {
Some(target) => {
let def = target.bindings.def_for_namespace(TypeNS).unwrap();
self.def_map.borrow_mut().insert(directive.id, def);
for (ident, target_import_resolution) in import_resolutions.iter() {
debug!("(resolving glob import) writing module resolution \
{:?} into `{}`",
- target_import_resolution.type_target.get().is_none(),
+ target_import_resolution.type_target.borrow().is_none(),
self.module_to_str(module_));
if !target_import_resolution.is_public.get() {
// Simple: just copy the old import resolution.
let new_import_resolution =
@ImportResolution::new(id, is_public);
- new_import_resolution.value_target.set(
- target_import_resolution.value_target.get());
- new_import_resolution.type_target.set(
- target_import_resolution.type_target.get());
+ *new_import_resolution.value_target.borrow_mut() =
+ get(&target_import_resolution.value_target);
+ *new_import_resolution.type_target.borrow_mut() =
+ get(&target_import_resolution.type_target);
import_resolutions.insert
(*ident, new_import_resolution);
// Merge the two import resolutions at a finer-grained
// level.
- match target_import_resolution.value_target.get() {
+ match *target_import_resolution.value_target.borrow() {
None => {
// Continue.
}
Some(value_target) => {
- dest_import_resolution.value_target.set(
- Some(value_target));
+ *dest_import_resolution.value_target.borrow_mut() = Some(value_target);
}
}
- match target_import_resolution.type_target.get() {
+ match *target_import_resolution.type_target.borrow() {
None => {
// Continue.
}
Some(type_target) => {
- dest_import_resolution.type_target.set(
- Some(type_target));
+ *dest_import_resolution.type_target.borrow_mut() = Some(type_target);
}
}
dest_import_resolution.is_public.set(is_public);
// Merge the child item into the import resolution.
if name_bindings.defined_in_public_namespace(ValueNS) {
debug!("(resolving glob import) ... for value target");
- dest_import_resolution.value_target.set(
- Some(Target::new(containing_module, name_bindings)));
+ *dest_import_resolution.value_target.borrow_mut() =
+ Some(Target::new(containing_module, name_bindings));
dest_import_resolution.value_id.set(id);
}
if name_bindings.defined_in_public_namespace(TypeNS) {
debug!("(resolving glob import) ... for type target");
- dest_import_resolution.type_target.set(
- Some(Target::new(containing_module, name_bindings)));
+ *dest_import_resolution.type_target.borrow_mut() =
+ Some(Target::new(containing_module, name_bindings));
dest_import_resolution.type_id.set(id);
}
dest_import_resolution.is_public.set(is_public);
Success((target, used_proxy)) => {
// Check to see whether there are type bindings, and, if
// so, whether there is a module within.
- match target.bindings.type_def.get() {
+ match *target.bindings.type_def.borrow() {
Some(type_def) => {
match type_def.module_def {
None => {
match resolve_result {
Success((target, _)) => {
let bindings = &*target.bindings;
- match bindings.type_def.get() {
+ match *bindings.type_def.borrow() {
Some(type_def) => {
match type_def.module_def {
None => {
debug!("(resolve bare identifier pattern) succeeded in \
finding {} at {:?}",
token::get_ident(name),
- target.bindings.value_def.get());
- match target.bindings.value_def.get() {
+ target.bindings.value_def.borrow());
+ match *target.bindings.value_def.borrow() {
None => {
fail!("resolved name in the value namespace to a \
set of name bindings with no def?!");