syntax: Merge keywords and remaining special idents in one list
Simplify the macro used for generation of keywords Make `Keyword::ident` private
This commit is contained in:
parent
923001ebb7
commit
b32d7b5923
24 changed files with 143 additions and 198 deletions
|
@ -18,7 +18,7 @@ use syntax::attr::ThinAttributesExt;
|
|||
use hir;
|
||||
use syntax::codemap::{respan, Span, Spanned};
|
||||
use syntax::ptr::P;
|
||||
use syntax::parse::token;
|
||||
use syntax::parse::token::keywords;
|
||||
use syntax::util::move_map::MoveMap;
|
||||
|
||||
pub trait Folder : Sized {
|
||||
|
@ -867,7 +867,7 @@ pub fn noop_fold_crate<T: Folder>(Crate { module, attrs, config, span,
|
|||
let config = folder.fold_meta_items(config);
|
||||
|
||||
let crate_mod = folder.fold_item(hir::Item {
|
||||
name: token::special_idents::Invalid.name,
|
||||
name: keywords::Invalid.name(),
|
||||
attrs: attrs,
|
||||
id: DUMMY_NODE_ID,
|
||||
vis: hir::Public,
|
||||
|
|
|
@ -14,9 +14,8 @@ use syntax::abi::Abi;
|
|||
use syntax::ast;
|
||||
use syntax::codemap::{self, CodeMap, BytePos, Spanned};
|
||||
use syntax::errors;
|
||||
use syntax::parse::token::{self, BinOpToken};
|
||||
use syntax::parse::token::{self, keywords, BinOpToken};
|
||||
use syntax::parse::lexer::comments;
|
||||
use syntax::parse;
|
||||
use syntax::print::pp::{self, break_offset, word, space, hardbreak};
|
||||
use syntax::print::pp::{Breaks, eof};
|
||||
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
|
||||
|
@ -2209,9 +2208,8 @@ impl<'a> State<'a> {
|
|||
hir::TyInfer if is_closure => self.print_pat(&input.pat)?,
|
||||
_ => {
|
||||
match input.pat.node {
|
||||
PatKind::Ident(_, ref path1, _) if
|
||||
path1.node.name ==
|
||||
parse::token::special_idents::Invalid.name => {
|
||||
PatKind::Ident(_, ref path1, _)
|
||||
if path1.node.name == keywords::Invalid.name() => {
|
||||
// Do nothing.
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -1578,7 +1578,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
let var = self.variable(p_id, sp);
|
||||
// Ignore unused self.
|
||||
let name = path1.node;
|
||||
if name != keywords::SelfValue.ident.name {
|
||||
if name != keywords::SelfValue.name() {
|
||||
if !self.warn_about_unused(sp, p_id, entry_ln, var) {
|
||||
if self.live_on_entry(entry_ln, var).is_none() {
|
||||
self.report_dead_assign(p_id, sp, var, true);
|
||||
|
|
|
@ -29,7 +29,7 @@ use std::fmt;
|
|||
use std::mem::replace;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::special_idents;
|
||||
use syntax::parse::token::keywords;
|
||||
use util::nodemap::NodeMap;
|
||||
|
||||
use hir;
|
||||
|
@ -245,7 +245,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
|
|||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
|
||||
if lifetime_ref.name == special_idents::StaticLifetime.name {
|
||||
if lifetime_ref.name == keywords::StaticLifetime.name() {
|
||||
self.insert_lifetime(lifetime_ref, DefStaticRegion);
|
||||
return;
|
||||
}
|
||||
|
@ -673,7 +673,7 @@ impl<'a> LifetimeContext<'a> {
|
|||
let lifetime_i = &lifetimes[i];
|
||||
|
||||
for lifetime in lifetimes {
|
||||
if lifetime.lifetime.name == special_idents::StaticLifetime.name {
|
||||
if lifetime.lifetime.name == keywords::StaticLifetime.name() {
|
||||
span_err!(self.sess, lifetime.lifetime.span, E0262,
|
||||
"invalid lifetime parameter name: `{}`", lifetime.lifetime.name);
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ pub struct ArgDecl<'tcx> {
|
|||
/// and has to be collected from multiple actual arguments.
|
||||
pub spread: bool,
|
||||
|
||||
/// Either special_idents::invalid or the name of a single-binding
|
||||
/// Either keywords::Invalid or the name of a single-binding
|
||||
/// pattern associated with this argument. Useful for debuginfo.
|
||||
pub debug_name: Name
|
||||
}
|
||||
|
|
|
@ -1069,7 +1069,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
pub fn mk_self_type(&self) -> Ty<'tcx> {
|
||||
self.mk_param(subst::SelfSpace, 0, keywords::SelfType.ident.name)
|
||||
self.mk_param(subst::SelfSpace, 0, keywords::SelfType.name())
|
||||
}
|
||||
|
||||
pub fn mk_param_from_def(&self, def: &ty::TypeParameterDef) -> Ty<'tcx> {
|
||||
|
|
|
@ -533,7 +533,7 @@ impl ParamTy {
|
|||
}
|
||||
|
||||
pub fn for_self() -> ParamTy {
|
||||
ParamTy::new(subst::SelfSpace, 0, keywords::SelfType.ident.name)
|
||||
ParamTy::new(subst::SelfSpace, 0, keywords::SelfType.name())
|
||||
}
|
||||
|
||||
pub fn for_def(def: &ty::TypeParameterDef) -> ParamTy {
|
||||
|
|
|
@ -18,7 +18,7 @@ use rustc::hir::pat_util::pat_is_binding;
|
|||
use std::ops::{Index, IndexMut};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use syntax::parse::token::keywords;
|
||||
|
||||
pub struct Builder<'a, 'tcx: 'a> {
|
||||
hir: Cx<'a, 'tcx>,
|
||||
|
@ -238,7 +238,7 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
|
|||
ty::UpvarCapture::ByRef(..) => true
|
||||
});
|
||||
let mut decl = UpvarDecl {
|
||||
debug_name: token::special_idents::invalid.name,
|
||||
debug_name: keywords::Invalid.name(),
|
||||
by_ref: by_ref
|
||||
};
|
||||
if let Some(hir::map::NodeLocal(pat)) = tcx.map.find(fv.def.var_id()) {
|
||||
|
@ -296,7 +296,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
|||
self.schedule_drop(pattern.as_ref().map_or(ast_block.span, |pat| pat.span),
|
||||
argument_extent, &lvalue, ty);
|
||||
|
||||
let mut name = token::special_idents::invalid.name;
|
||||
let mut name = keywords::Invalid.name();
|
||||
if let Some(pat) = pattern {
|
||||
if let hir::PatKind::Ident(_, ref ident, _) = pat.node {
|
||||
if pat_is_binding(&self.hir.tcx().def_map.borrow(), pat) {
|
||||
|
|
|
@ -22,7 +22,7 @@ use machine;
|
|||
use type_of;
|
||||
|
||||
use syntax::codemap::DUMMY_SP;
|
||||
use syntax::parse::token;
|
||||
use syntax::parse::token::keywords;
|
||||
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
|
@ -286,7 +286,7 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
|
|||
alloca: lltemp,
|
||||
address_operations: &ops
|
||||
};
|
||||
declare_local(bcx, token::special_idents::Invalid.name,
|
||||
declare_local(bcx, keywords::Invalid.name(),
|
||||
tupled_arg_ty, scope, variable_access,
|
||||
VariableKind::ArgumentVariable(arg_index + i + 1),
|
||||
bcx.fcx().span.unwrap_or(DUMMY_SP));
|
||||
|
|
|
@ -73,7 +73,7 @@ use syntax::{abi, ast};
|
|||
use syntax::codemap::{Span, Pos};
|
||||
use syntax::errors::DiagnosticBuilder;
|
||||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
||||
use syntax::parse::token;
|
||||
use syntax::parse::token::{self, keywords};
|
||||
|
||||
use rustc::hir::print as pprust;
|
||||
use rustc::hir;
|
||||
|
@ -1313,7 +1313,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
let trait_node_id = tcx.map.as_local_node_id(trait_did).unwrap();
|
||||
match find_bound_for_assoc_item(this,
|
||||
trait_node_id,
|
||||
token::keywords::SelfType.ident.name,
|
||||
keywords::SelfType.name(),
|
||||
assoc_name,
|
||||
span) {
|
||||
Ok(bound) => bound,
|
||||
|
|
|
@ -120,7 +120,7 @@ use syntax::attr;
|
|||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::codemap::{self, Span, Spanned};
|
||||
use syntax::errors::DiagnosticBuilder;
|
||||
use syntax::parse::token::{self, InternedString, special_idents};
|
||||
use syntax::parse::token::{self, InternedString, keywords};
|
||||
use syntax::ptr::P;
|
||||
use syntax::util::lev_distance::find_best_match_for_name;
|
||||
|
||||
|
@ -2851,7 +2851,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
method_ty
|
||||
}
|
||||
Err(error) => {
|
||||
if method_name.node != special_idents::Invalid.name {
|
||||
if method_name.node != keywords::Invalid.name() {
|
||||
method::report_error(fcx, method_name.span, expr_t,
|
||||
method_name.node, Some(rcvr), error);
|
||||
}
|
||||
|
@ -2990,7 +2990,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
let msg = format!("field `{}` of struct `{}` is private", field.node, struct_path);
|
||||
fcx.tcx().sess.span_err(expr.span, &msg);
|
||||
fcx.write_ty(expr.id, field_ty);
|
||||
} else if field.node == special_idents::Invalid.name {
|
||||
} else if field.node == keywords::Invalid.name() {
|
||||
fcx.write_error(expr.id);
|
||||
} else if method::exists(fcx, field.span, field.node, expr_t, expr.id) {
|
||||
fcx.type_error_struct(field.span,
|
||||
|
@ -3780,7 +3780,7 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
|
|||
method::MethodError::PrivateMatch(def) => Some(def),
|
||||
_ => None,
|
||||
};
|
||||
if item_name != special_idents::Invalid.name {
|
||||
if item_name != keywords::Invalid.name() {
|
||||
method::report_error(fcx, span, ty, item_name, None, error);
|
||||
}
|
||||
def
|
||||
|
|
|
@ -472,7 +472,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
|||
{
|
||||
let name = match space {
|
||||
TypeSpace => ast_generics.ty_params[index].name,
|
||||
SelfSpace => keywords::SelfType.ident.name,
|
||||
SelfSpace => keywords::SelfType.name(),
|
||||
FnSpace => bug!("Fn space occupied?"),
|
||||
};
|
||||
|
||||
|
|
|
@ -1655,7 +1655,7 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
let def = ty::TypeParameterDef {
|
||||
space: SelfSpace,
|
||||
index: 0,
|
||||
name: keywords::SelfType.ident.name,
|
||||
name: keywords::SelfType.name(),
|
||||
def_id: ccx.tcx.map.local_def_id(param_id),
|
||||
default_def_id: ccx.tcx.map.local_def_id(parent),
|
||||
default: None,
|
||||
|
|
|
@ -2666,7 +2666,7 @@ fn resolve_type(cx: &DocContext,
|
|||
hir::TyFloat(ast::FloatTy::F64) => return Primitive(F64),
|
||||
},
|
||||
Def::SelfTy(..) if path.segments.len() == 1 => {
|
||||
return Generic(keywords::SelfType.ident.to_string());
|
||||
return Generic(keywords::SelfType.name().to_string());
|
||||
}
|
||||
Def::SelfTy(..) | Def::TyParam(..) => true,
|
||||
_ => false,
|
||||
|
|
|
@ -13,9 +13,7 @@ use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind};
|
|||
use attr;
|
||||
use codemap::{Span, respan, Spanned, DUMMY_SP, Pos};
|
||||
use ext::base::ExtCtxt;
|
||||
use parse::token::{keywords, special_idents};
|
||||
use parse::token::InternedString;
|
||||
use parse::token;
|
||||
use parse::token::{self, keywords, InternedString};
|
||||
use ptr::P;
|
||||
|
||||
// Transitional reexports so qquote can find the paths it is looking for
|
||||
|
@ -602,7 +600,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
self.expr_path(self.path_ident(span, id))
|
||||
}
|
||||
fn expr_self(&self, span: Span) -> P<ast::Expr> {
|
||||
self.expr_ident(span, keywords::SelfValue.ident)
|
||||
self.expr_ident(span, keywords::SelfValue.ident())
|
||||
}
|
||||
|
||||
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
|
||||
|
@ -1132,7 +1130,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> {
|
||||
P(ast::Item {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ident: special_idents::Invalid,
|
||||
ident: keywords::Invalid.ident(),
|
||||
attrs: vec![],
|
||||
node: ast::ItemKind::Use(vp),
|
||||
vis: vis,
|
||||
|
|
|
@ -25,7 +25,7 @@ use fold;
|
|||
use fold::*;
|
||||
use util::move_map::MoveMap;
|
||||
use parse;
|
||||
use parse::token::{fresh_mark, fresh_name, intern};
|
||||
use parse::token::{fresh_mark, fresh_name, intern, keywords};
|
||||
use ptr::P;
|
||||
use util::small_vector::SmallVector;
|
||||
use visit;
|
||||
|
@ -380,7 +380,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
|
|||
|
||||
Some(rc) => match *rc {
|
||||
NormalTT(ref expander, tt_span, allow_internal_unstable) => {
|
||||
if ident.name != parse::token::special_idents::Invalid.name {
|
||||
if ident.name != keywords::Invalid.name() {
|
||||
fld.cx
|
||||
.span_err(path_span,
|
||||
&format!("macro {}! expects no ident argument, given '{}'",
|
||||
|
@ -401,7 +401,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
|
|||
expander.expand(fld.cx, span, &marked_before[..])
|
||||
}
|
||||
IdentTT(ref expander, tt_span, allow_internal_unstable) => {
|
||||
if ident.name == parse::token::special_idents::Invalid.name {
|
||||
if ident.name == keywords::Invalid.name() {
|
||||
fld.cx.span_err(path_span,
|
||||
&format!("macro {}! expects an ident argument",
|
||||
extname));
|
||||
|
@ -420,7 +420,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
|
|||
expander.expand(fld.cx, span, ident, marked_tts)
|
||||
}
|
||||
MacroRulesTT => {
|
||||
if ident.name == parse::token::special_idents::Invalid.name {
|
||||
if ident.name == keywords::Invalid.name() {
|
||||
fld.cx.span_err(path_span, "macro_rules! expects an ident argument");
|
||||
return SmallVector::zero();
|
||||
}
|
||||
|
@ -893,7 +893,7 @@ fn expand_annotatable(a: Annotatable,
|
|||
}
|
||||
ast::ItemKind::Mod(_) | ast::ItemKind::ForeignMod(_) => {
|
||||
let valid_ident =
|
||||
it.ident.name != parse::token::special_idents::Invalid.name;
|
||||
it.ident.name != keywords::Invalid.name();
|
||||
|
||||
if valid_ident {
|
||||
fld.cx.mod_push(it.ident);
|
||||
|
@ -1807,7 +1807,7 @@ mod tests {
|
|||
|
||||
// run one of the renaming tests
|
||||
fn run_renaming_test(t: &RenamingTest, test_idx: usize) {
|
||||
let invalid_name = token::special_idents::Invalid.name;
|
||||
let invalid_name = keywords::Invalid.name();
|
||||
let (teststr, bound_connections, bound_ident_check) = match *t {
|
||||
(ref str,ref conns, bic) => (str.to_string(), conns.clone(), bic)
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ use ast::*;
|
|||
use ast;
|
||||
use attr::{ThinAttributes, ThinAttributesExt};
|
||||
use codemap::{respan, Span, Spanned};
|
||||
use parse::token;
|
||||
use parse::token::{self, keywords};
|
||||
use ptr::P;
|
||||
use util::small_vector::SmallVector;
|
||||
use util::move_map::MoveMap;
|
||||
|
@ -1015,7 +1015,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_mac
|
|||
let config = folder.fold_meta_items(config);
|
||||
|
||||
let mut items = folder.fold_item(P(ast::Item {
|
||||
ident: token::special_idents::Invalid,
|
||||
ident: keywords::Invalid.ident(),
|
||||
attrs: attrs,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
vis: ast::Visibility::Public,
|
||||
|
|
|
@ -141,7 +141,7 @@ pub enum Token {
|
|||
/// Doc comment
|
||||
DocComment(ast::Name),
|
||||
// In left-hand-sides of MBE macros:
|
||||
/// Parse a nonterminal (name to bind, name of NT, styles of their idents)
|
||||
/// Parse a nonterminal (name to bind, name of NT)
|
||||
MatchNt(ast::Ident, ast::Ident),
|
||||
// In right-hand-sides of MBE macros:
|
||||
/// A syntactic variable that will be filled in by macro expansion.
|
||||
|
@ -271,34 +271,30 @@ impl Token {
|
|||
/// Returns `true` if the token is a given keyword, `kw`.
|
||||
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
|
||||
match *self {
|
||||
Ident(id) => id.name == kw.ident.name,
|
||||
Ident(id) => id.name == kw.name(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_path_segment_keyword(&self) -> bool {
|
||||
match *self {
|
||||
Ident(id) => id.name == keywords::Super.ident.name ||
|
||||
id.name == keywords::SelfValue.ident.name ||
|
||||
id.name == keywords::SelfType.ident.name,
|
||||
Ident(id) => id.name == keywords::Super.name() ||
|
||||
id.name == keywords::SelfValue.name() ||
|
||||
id.name == keywords::SelfType.name(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is either a used or reserved keyword.
|
||||
/// Returns `true` if the token is either a strict or reserved keyword.
|
||||
pub fn is_any_keyword(&self) -> bool {
|
||||
match *self {
|
||||
Ident(id) => id.name >= USED_KEYWORD_START &&
|
||||
id.name <= RESERVED_KEYWORD_FINAL,
|
||||
_ => false
|
||||
}
|
||||
self.is_strict_keyword() || self.is_reserved_keyword()
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is a used keyword.
|
||||
pub fn is_used_keyword(&self) -> bool {
|
||||
/// Returns `true` if the token is a strict keyword.
|
||||
pub fn is_strict_keyword(&self) -> bool {
|
||||
match *self {
|
||||
Ident(id) => id.name >= USED_KEYWORD_START &&
|
||||
id.name <= USED_KEYWORD_FINAL,
|
||||
Ident(id) => id.name >= keywords::As.name() &&
|
||||
id.name <= keywords::While.name(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -306,8 +302,8 @@ impl Token {
|
|||
/// Returns `true` if the token is a keyword reserved for possible future use.
|
||||
pub fn is_reserved_keyword(&self) -> bool {
|
||||
match *self {
|
||||
Ident(id) => id.name >= RESERVED_KEYWORD_START &&
|
||||
id.name <= RESERVED_KEYWORD_FINAL,
|
||||
Ident(id) => id.name >= keywords::Abstract.name() &&
|
||||
id.name <= keywords::Yield.name(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -370,148 +366,104 @@ impl fmt::Debug for Nonterminal {
|
|||
}
|
||||
}
|
||||
|
||||
// Get the first "argument"
|
||||
macro_rules! first {
|
||||
( $first:expr, $( $remainder:expr, )* ) => ( $first )
|
||||
}
|
||||
|
||||
// Get the last "argument" (has to be done recursively to avoid phoney local ambiguity error)
|
||||
macro_rules! last {
|
||||
( $first:expr, $( $remainder:expr, )+ ) => ( last!( $( $remainder, )+ ) );
|
||||
( $first:expr, ) => ( $first )
|
||||
}
|
||||
|
||||
// In this macro, there is the requirement that the name (the number) must be monotonically
|
||||
// increasing by one in the special identifiers, starting at 0; the same holds for the keywords,
|
||||
// except starting from the next number instead of zero.
|
||||
macro_rules! declare_special_idents_and_keywords {(
|
||||
// So now, in these rules, why is each definition parenthesised?
|
||||
// Answer: otherwise we get a spurious local ambiguity bug on the "}"
|
||||
pub mod special_idents {
|
||||
$( ($si_index: expr, $si_const: ident, $si_str: expr); )*
|
||||
}
|
||||
|
||||
pub mod keywords {
|
||||
'used:
|
||||
$( ($ukw_index: expr, $ukw_const: ident, $ukw_str: expr); )*
|
||||
'reserved:
|
||||
$( ($rkw_index: expr, $rkw_const: ident, $rkw_str: expr); )*
|
||||
}
|
||||
macro_rules! declare_keywords {(
|
||||
$( ($index: expr, $konst: ident, $string: expr) )*
|
||||
) => {
|
||||
const USED_KEYWORD_START: ast::Name = first!($( ast::Name($ukw_index), )*);
|
||||
const USED_KEYWORD_FINAL: ast::Name = last!($( ast::Name($ukw_index), )*);
|
||||
const RESERVED_KEYWORD_START: ast::Name = first!($( ast::Name($rkw_index), )*);
|
||||
const RESERVED_KEYWORD_FINAL: ast::Name = last!($( ast::Name($rkw_index), )*);
|
||||
|
||||
pub mod special_idents {
|
||||
use ast;
|
||||
$(
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $si_const: ast::Ident = ast::Ident::with_empty_ctxt(ast::Name($si_index));
|
||||
)*
|
||||
}
|
||||
|
||||
/// Rust keywords are either 'used' in the language or 'reserved' for future use.
|
||||
pub mod keywords {
|
||||
use ast;
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Keyword {
|
||||
pub ident: ast::Ident,
|
||||
ident: ast::Ident,
|
||||
}
|
||||
impl Keyword {
|
||||
#[inline] pub fn ident(self) -> ast::Ident { self.ident }
|
||||
#[inline] pub fn name(self) -> ast::Name { self.ident.name }
|
||||
}
|
||||
$(
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $ukw_const: Keyword = Keyword {
|
||||
ident: ast::Ident::with_empty_ctxt(ast::Name($ukw_index))
|
||||
};
|
||||
)*
|
||||
$(
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $rkw_const: Keyword = Keyword {
|
||||
ident: ast::Ident::with_empty_ctxt(ast::Name($rkw_index))
|
||||
pub const $konst: Keyword = Keyword {
|
||||
ident: ast::Ident::with_empty_ctxt(ast::Name($index))
|
||||
};
|
||||
)*
|
||||
}
|
||||
|
||||
fn mk_fresh_ident_interner() -> IdentInterner {
|
||||
interner::StrInterner::prefill(&[$($si_str,)* $($ukw_str,)* $($rkw_str,)*])
|
||||
interner::StrInterner::prefill(&[$($string,)*])
|
||||
}
|
||||
}}
|
||||
|
||||
// NB: leaving holes in the ident table is bad! a different ident will get
|
||||
// interned with the id from the hole, but it will be between the min and max
|
||||
// of the reserved words, and thus tagged as "reserved".
|
||||
// After modifying this list adjust `is_strict_keyword`/`is_reserved_keyword`,
|
||||
// this should be rarely necessary though if the keywords are kept in alphabetic order.
|
||||
declare_keywords! {
|
||||
// Invalid identifier
|
||||
(0, Invalid, "")
|
||||
|
||||
declare_special_idents_and_keywords! {
|
||||
pub mod special_idents {
|
||||
// Special identifiers
|
||||
(0, Invalid, "");
|
||||
(1, __Unused1, "<__unused1>");
|
||||
(2, __Unused2, "<__unused2>");
|
||||
(3, __Unused3, "<__unused3>");
|
||||
(4, __Unused4, "<__unused4>");
|
||||
(5, __Unused5, "<__unused5>");
|
||||
(6, Union, "union");
|
||||
(7, Default, "default");
|
||||
(8, StaticLifetime, "'static");
|
||||
}
|
||||
// Strict keywords used in the language.
|
||||
(1, As, "as")
|
||||
(2, Box, "box")
|
||||
(3, Break, "break")
|
||||
(4, Const, "const")
|
||||
(5, Continue, "continue")
|
||||
(6, Crate, "crate")
|
||||
(7, Else, "else")
|
||||
(8, Enum, "enum")
|
||||
(9, Extern, "extern")
|
||||
(10, False, "false")
|
||||
(11, Fn, "fn")
|
||||
(12, For, "for")
|
||||
(13, If, "if")
|
||||
(14, Impl, "impl")
|
||||
(15, In, "in")
|
||||
(16, Let, "let")
|
||||
(17, Loop, "loop")
|
||||
(18, Match, "match")
|
||||
(19, Mod, "mod")
|
||||
(20, Move, "move")
|
||||
(21, Mut, "mut")
|
||||
(22, Pub, "pub")
|
||||
(23, Ref, "ref")
|
||||
(24, Return, "return")
|
||||
(25, SelfValue, "self")
|
||||
(26, SelfType, "Self")
|
||||
(27, Static, "static")
|
||||
(28, Struct, "struct")
|
||||
(29, Super, "super")
|
||||
(30, Trait, "trait")
|
||||
(31, True, "true")
|
||||
(32, Type, "type")
|
||||
(33, Unsafe, "unsafe")
|
||||
(34, Use, "use")
|
||||
(35, Where, "where")
|
||||
(36, While, "while")
|
||||
|
||||
pub mod keywords {
|
||||
// Keywords
|
||||
'used:
|
||||
(9, Static, "static");
|
||||
(10, Super, "super");
|
||||
(11, SelfValue, "self");
|
||||
(12, SelfType, "Self");
|
||||
(13, As, "as");
|
||||
(14, Break, "break");
|
||||
(15, Crate, "crate");
|
||||
(16, Else, "else");
|
||||
(17, Enum, "enum");
|
||||
(18, Extern, "extern");
|
||||
(19, False, "false");
|
||||
(20, Fn, "fn");
|
||||
(21, For, "for");
|
||||
(22, If, "if");
|
||||
(23, Impl, "impl");
|
||||
(24, In, "in");
|
||||
(25, Let, "let");
|
||||
(26, Loop, "loop");
|
||||
(27, Match, "match");
|
||||
(28, Mod, "mod");
|
||||
(29, Move, "move");
|
||||
(30, Mut, "mut");
|
||||
(31, Pub, "pub");
|
||||
(32, Ref, "ref");
|
||||
(33, Return, "return");
|
||||
(34, Struct, "struct");
|
||||
(35, True, "true");
|
||||
(36, Trait, "trait");
|
||||
(37, Type, "type");
|
||||
(38, Unsafe, "unsafe");
|
||||
(39, Use, "use");
|
||||
(40, While, "while");
|
||||
(41, Continue, "continue");
|
||||
(42, Box, "box");
|
||||
(43, Const, "const");
|
||||
(44, Where, "where");
|
||||
'reserved:
|
||||
(45, Virtual, "virtual");
|
||||
(46, Proc, "proc");
|
||||
(47, Alignof, "alignof");
|
||||
(48, Become, "become");
|
||||
(49, Offsetof, "offsetof");
|
||||
(50, Priv, "priv");
|
||||
(51, Pure, "pure");
|
||||
(52, Sizeof, "sizeof");
|
||||
(53, Typeof, "typeof");
|
||||
(54, Unsized, "unsized");
|
||||
(55, Yield, "yield");
|
||||
(56, Do, "do");
|
||||
(57, Abstract, "abstract");
|
||||
(58, Final, "final");
|
||||
(59, Override, "override");
|
||||
(60, Macro, "macro");
|
||||
}
|
||||
// Keywords reserved for future use.
|
||||
(37, Abstract, "abstract")
|
||||
(38, Alignof, "alignof")
|
||||
(39, Become, "become")
|
||||
(40, Do, "do")
|
||||
(41, Final, "final")
|
||||
(42, Macro, "macro")
|
||||
(43, Offsetof, "offsetof")
|
||||
(44, Override, "override")
|
||||
(45, Priv, "priv")
|
||||
(46, Proc, "proc")
|
||||
(47, Pure, "pure")
|
||||
(48, Sizeof, "sizeof")
|
||||
(49, Typeof, "typeof")
|
||||
(50, Unsized, "unsized")
|
||||
(51, Virtual, "virtual")
|
||||
(52, Yield, "yield")
|
||||
|
||||
// Weak keywords, have special meaning only in specific contexts.
|
||||
(53, Default, "default")
|
||||
(54, StaticLifetime, "'static")
|
||||
(55, Union, "union")
|
||||
}
|
||||
|
||||
// looks like we can get rid of this completely...
|
||||
|
|
|
@ -20,7 +20,7 @@ use attr;
|
|||
use attr::{AttrMetaMethods, AttributeMethods};
|
||||
use codemap::{self, CodeMap, BytePos};
|
||||
use errors;
|
||||
use parse::token::{self, BinOpToken, Token, InternedString};
|
||||
use parse::token::{self, keywords, BinOpToken, Token, InternedString};
|
||||
use parse::lexer::comments;
|
||||
use parse;
|
||||
use print::pp::{self, break_offset, word, space, zerobreak, hardbreak};
|
||||
|
@ -2957,9 +2957,8 @@ impl<'a> State<'a> {
|
|||
ast::TyKind::Infer if is_closure => self.print_pat(&input.pat)?,
|
||||
_ => {
|
||||
match input.pat.node {
|
||||
PatKind::Ident(_, ref path1, _) if
|
||||
path1.node.name ==
|
||||
parse::token::special_idents::Invalid.name => {
|
||||
PatKind::Ident(_, ref path1, _)
|
||||
if path1.node.name == keywords::Invalid.name() => {
|
||||
// Do nothing.
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -14,7 +14,7 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
|
|||
use codemap;
|
||||
use fold::Folder;
|
||||
use fold;
|
||||
use parse::token::{intern, InternedString, special_idents};
|
||||
use parse::token::{intern, InternedString, keywords};
|
||||
use parse::{token, ParseSess};
|
||||
use ptr::P;
|
||||
use util::small_vector::SmallVector;
|
||||
|
@ -148,7 +148,7 @@ impl fold::Folder for PreludeInjector {
|
|||
let vp = P(codemap::dummy_spanned(ast::ViewPathGlob(prelude_path)));
|
||||
mod_.items.insert(0, P(ast::Item {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ident: special_idents::Invalid,
|
||||
ident: keywords::Invalid.ident(),
|
||||
node: ast::ItemKind::Use(vp),
|
||||
attrs: vec![ast::Attribute {
|
||||
span: self.span,
|
||||
|
|
|
@ -31,7 +31,7 @@ use ext::expand::ExpansionConfig;
|
|||
use fold::Folder;
|
||||
use util::move_map::MoveMap;
|
||||
use fold;
|
||||
use parse::token::{intern, InternedString};
|
||||
use parse::token::{intern, keywords, InternedString};
|
||||
use parse::{token, ParseSess};
|
||||
use print::pprust;
|
||||
use ast;
|
||||
|
@ -116,7 +116,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
|
|||
|
||||
fn fold_item(&mut self, i: P<ast::Item>) -> SmallVector<P<ast::Item>> {
|
||||
let ident = i.ident;
|
||||
if ident.name != token::special_idents::Invalid.name {
|
||||
if ident.name != keywords::Invalid.name() {
|
||||
self.cx.path.push(ident);
|
||||
}
|
||||
debug!("current path: {}", path_name_i(&self.cx.path));
|
||||
|
@ -160,7 +160,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
|
|||
ast::ItemKind::Mod(..) => fold::noop_fold_item(i, self),
|
||||
_ => SmallVector::one(i),
|
||||
};
|
||||
if ident.name != token::special_idents::Invalid.name {
|
||||
if ident.name != keywords::Invalid.name() {
|
||||
self.cx.path.pop();
|
||||
}
|
||||
res
|
||||
|
@ -453,7 +453,7 @@ fn mk_std(cx: &TestCtxt) -> P<ast::Item> {
|
|||
(ast::ItemKind::Use(
|
||||
P(nospan(ast::ViewPathSimple(id_test,
|
||||
path_node(vec!(id_test)))))),
|
||||
ast::Visibility::Public, token::special_idents::Invalid)
|
||||
ast::Visibility::Public, keywords::Invalid.ident())
|
||||
} else {
|
||||
(ast::ItemKind::ExternCrate(None), ast::Visibility::Inherited, id_test)
|
||||
};
|
||||
|
@ -545,7 +545,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) {
|
|||
|
||||
P(ast::Item {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ident: token::special_idents::Invalid,
|
||||
ident: keywords::Invalid.ident(),
|
||||
attrs: vec![],
|
||||
node: ast::ItemKind::Use(P(use_path)),
|
||||
vis: ast::Visibility::Inherited,
|
||||
|
@ -590,7 +590,7 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
|
|||
let struct_type = ecx.ty_path(ecx.path(sp, vec![ecx.ident_of("self"),
|
||||
ecx.ident_of("test"),
|
||||
ecx.ident_of("TestDescAndFn")]));
|
||||
let static_lt = ecx.lifetime(sp, token::special_idents::StaticLifetime.name);
|
||||
let static_lt = ecx.lifetime(sp, keywords::StaticLifetime.name());
|
||||
// &'static [self::test::TestDescAndFn]
|
||||
let static_type = ecx.ty_rptr(sp,
|
||||
ecx.ty(sp, ast::TyKind::Vec(struct_type)),
|
||||
|
|
|
@ -201,8 +201,7 @@ use syntax::codemap::{self, DUMMY_SP};
|
|||
use syntax::codemap::Span;
|
||||
use syntax::errors::Handler;
|
||||
use syntax::util::move_map::MoveMap;
|
||||
use syntax::parse::token::{intern, InternedString};
|
||||
use syntax::parse::token::{keywords, special_idents};
|
||||
use syntax::parse::token::{intern, keywords, InternedString};
|
||||
use syntax::ptr::P;
|
||||
|
||||
use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
|
||||
|
@ -635,7 +634,7 @@ impl<'a> TraitDef<'a> {
|
|||
|
||||
cx.item(
|
||||
self.span,
|
||||
special_idents::Invalid,
|
||||
keywords::Invalid.ident(),
|
||||
a,
|
||||
ast::ItemKind::Impl(unsafety,
|
||||
ast::ImplPolarity::Positive,
|
||||
|
@ -866,7 +865,7 @@ impl<'a> MethodDef<'a> {
|
|||
// creating fresh self id
|
||||
_ => Some(ast::Arg::new_self(trait_.span,
|
||||
ast::Mutability::Immutable,
|
||||
keywords::SelfValue.ident))
|
||||
keywords::SelfValue.ident()))
|
||||
};
|
||||
let args = {
|
||||
let args = arg_types.into_iter().map(|(name, ty)| {
|
||||
|
|
|
@ -264,7 +264,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
|
|||
let self_path = cx.expr_self(span);
|
||||
match *self_ptr {
|
||||
None => {
|
||||
(self_path, respan(span, ast::SelfKind::Value(keywords::SelfValue.ident)))
|
||||
(self_path, respan(span, ast::SelfKind::Value(keywords::SelfValue.ident())))
|
||||
}
|
||||
Some(ref ptr) => {
|
||||
let self_ty = respan(
|
||||
|
@ -272,7 +272,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
|
|||
match *ptr {
|
||||
Borrowed(ref lt, mutbl) => {
|
||||
let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name));
|
||||
ast::SelfKind::Region(lt, mutbl, keywords::SelfValue.ident)
|
||||
ast::SelfKind::Region(lt, mutbl, keywords::SelfValue.ident())
|
||||
}
|
||||
Raw(_) => cx.span_bug(span, "attempted to use *self in deriving definition")
|
||||
});
|
||||
|
|
|
@ -19,8 +19,7 @@ use syntax::ext::base::*;
|
|||
use syntax::ext::base;
|
||||
use syntax::ext::build::AstBuilder;
|
||||
use syntax::fold::Folder;
|
||||
use syntax::parse::token::special_idents;
|
||||
use syntax::parse::token;
|
||||
use syntax::parse::token::{self, keywords};
|
||||
use syntax::ptr::P;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
@ -449,7 +448,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
|||
let sp = piece_ty.span;
|
||||
let ty = ecx.ty_rptr(sp,
|
||||
ecx.ty(sp, ast::TyKind::Vec(piece_ty)),
|
||||
Some(ecx.lifetime(sp, special_idents::StaticLifetime.name)),
|
||||
Some(ecx.lifetime(sp, keywords::StaticLifetime.name())),
|
||||
ast::Mutability::Immutable);
|
||||
let slice = ecx.expr_vec_slice(sp, pieces);
|
||||
// static instead of const to speed up codegen by not requiring this to be inlined
|
||||
|
@ -475,7 +474,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
|||
|
||||
// First, build up the static array which will become our precompiled
|
||||
// format "string"
|
||||
let static_lifetime = self.ecx.lifetime(self.fmtsp, special_idents::StaticLifetime.name);
|
||||
let static_lifetime = self.ecx.lifetime(self.fmtsp, keywords::StaticLifetime.name());
|
||||
let piece_ty = self.ecx.ty_rptr(
|
||||
self.fmtsp,
|
||||
self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue