Skip to content

Commit

Permalink
Move syntax::ext::hygiene to syntax_pos::hygiene.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Mar 29, 2017
1 parent 07a3429 commit 1979f96
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/map/def_collector.rs
Expand Up @@ -92,7 +92,7 @@ impl<'a> DefCollector<'a> {
fn visit_macro_invoc(&mut self, id: NodeId, const_expr: bool) {
if let Some(ref mut visit) = self.visit_macro_invoc {
visit(MacroInvocationData {
mark: Mark::from_placeholder_id(id),
mark: id.placeholder_to_mark(),
const_expr: const_expr,
def_index: self.parent_def.unwrap(),
})
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -680,7 +680,7 @@ pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {

impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
let mark = Mark::from_placeholder_id(id);
let mark = id.placeholder_to_mark();
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
let invocation = self.resolver.invocations[&mark];
invocation.module.set(self.resolver.current_module);
Expand Down
10 changes: 9 additions & 1 deletion src/libsyntax/ast.rs
Expand Up @@ -20,7 +20,7 @@ pub use util::ThinVec;
use syntax_pos::{mk_sp, BytePos, Span, DUMMY_SP, ExpnId};
use codemap::{respan, Spanned};
use abi::Abi;
use ext::hygiene::SyntaxContext;
use ext::hygiene::{Mark, SyntaxContext};
use print::pprust;
use ptr::P;
use rustc_data_structures::indexed_vec;
Expand Down Expand Up @@ -256,6 +256,14 @@ impl NodeId {
pub fn as_u32(&self) -> u32 {
self.0
}

pub fn placeholder_from_mark(mark: Mark) -> Self {
NodeId(mark.as_u32())
}

pub fn placeholder_to_mark(self) -> Mark {
Mark::from_u32(self.0)
}
}

impl fmt::Display for NodeId {
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use ast::{self, Block, Ident, PatKind, Path};
use ast::{self, Block, Ident, NodeId, PatKind, Path};
use ast::{MacStmtStyle, StmtKind, ItemKind};
use attr::{self, HasAttrs};
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
while let Some(expansions) = expansions.pop() {
for (mark, expansion) in expansions.into_iter().rev() {
let derives = derives.remove(&mark).unwrap_or_else(Vec::new);
placeholder_expander.add(mark.as_placeholder_id(), expansion, derives);
placeholder_expander.add(NodeId::placeholder_from_mark(mark), expansion, derives);
}
}

Expand Down Expand Up @@ -703,7 +703,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
..self.cx.current_expansion.clone()
},
});
placeholder(expansion_kind, mark.as_placeholder_id())
placeholder(expansion_kind, NodeId::placeholder_from_mark(mark))
}

fn collect_bang(&mut self, mac: ast::Mac, span: Span, kind: ExpansionKind) -> Expansion {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/placeholders.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use ast;
use ast::{self, NodeId};
use codemap::{DUMMY_SP, dummy_spanned};
use ext::base::ExtCtxt;
use ext::expand::{Expansion, ExpansionKind};
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
let mut expansion = expansion.fold_with(self);
if let Expansion::Items(mut items) = expansion {
for derive in derives {
match self.remove(derive.as_placeholder_id()) {
match self.remove(NodeId::placeholder_from_mark(derive)) {
Expansion::Items(derived_items) => items.extend(derived_items),
_ => unreachable!(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/lib.rs
Expand Up @@ -136,12 +136,12 @@ pub mod print {
}

pub mod ext {
pub use syntax_pos::hygiene;
pub mod base;
pub mod build;
pub mod derive;
pub mod expand;
pub mod placeholders;
pub mod hygiene;
pub mod quote;
pub mod source_util;

Expand Down
13 changes: 4 additions & 9 deletions src/libsyntax/ext/hygiene.rs → src/libsyntax_pos/hygiene.rs
Expand Up @@ -15,7 +15,6 @@
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
//! DOI=10.1017/S0956796812000093 http://dx.doi.org/10.1017/S0956796812000093

use ast::NodeId;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -47,17 +46,13 @@ impl Mark {
Mark(0)
}

pub fn from_placeholder_id(id: NodeId) -> Self {
Mark(id.as_u32())
}

pub fn as_placeholder_id(self) -> NodeId {
NodeId::from_u32(self.0)
}

pub fn as_u32(self) -> u32 {
self.0
}

pub fn from_u32(raw: u32) -> Mark {
Mark(raw)
}
}

struct HygieneData {
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax_pos/lib.rs
Expand Up @@ -23,6 +23,7 @@
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![deny(warnings)]

#![feature(const_fn)]
#![feature(custom_attribute)]
#![allow(unused_attributes)]
#![feature(rustc_private)]
Expand All @@ -41,6 +42,8 @@ use serialize::{Encodable, Decodable, Encoder, Decoder};
extern crate serialize;
extern crate serialize as rustc_serialize; // used by deriving

pub mod hygiene;

pub type FileName = String;

/// Spans represent a region of code, used for error reporting. Positions in spans
Expand Down

0 comments on commit 1979f96

Please sign in to comment.