From ecc8ff9199118b88e98c903c9117fa2f0cddf8ab Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 28 Apr 2017 09:40:48 -0400 Subject: [PATCH] rework macro to prepare for more modifiers than just `[pub]` --- src/librustc/ty/maps.rs | 45 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 09bdca4915a1..e653392e3fb5 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -353,11 +353,11 @@ impl<'tcx> QueryDescription for queries::mir_pass<'tcx> { macro_rules! define_maps { (<$tcx:tt> $($(#[$attr:meta])* - [$($pub:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => { - pub struct Maps<$tcx> { - providers: IndexVec>, - query_stack: RefCell)>>, - $($(#[$attr])* $($pub)* $name: RefCell>>),* + [$($modifiers:tt)*] $name:ident: $node:ident($K:ty) -> $V:ty,)*) => { + define_map_struct! { + tcx: $tcx, + input: ($(([$($attr)*] [$($modifiers)*] $name))*), + output: () } impl<$tcx> Maps<$tcx> { @@ -519,6 +519,41 @@ macro_rules! define_maps { } } +macro_rules! define_map_struct { + (tcx: $tcx:tt, + input: (), + output: ($($output:tt)*)) => { + pub struct Maps<$tcx> { + providers: IndexVec>, + query_stack: RefCell)>>, + $($output)* + } + }; + + // Detect things with the `pub` modifier + (tcx: $tcx:tt, + input: (([$($attr:meta)*] [pub] $name:ident) $($input:tt)*), + output: ($($output:tt)*)) => { + define_map_struct! { + tcx: $tcx, + input: ($($input)*), + output: ($($output)* + $(#[$attr])* pub $name: RefCell>>,) + } + }; + + (tcx: $tcx:tt, + input: (([$($attr:meta)*] [$($modifiers:tt)*] $name:ident) $($input:tt)*), + output: ($($output:tt)*)) => { + define_map_struct! { + tcx: $tcx, + input: ($($input)*), + output: ($($output)* + $(#[$attr])* $name: RefCell>>,) + } + }; +} + // Each of these maps also corresponds to a method on a // `Provider` trait for requesting a value of that type, // and a method on `Maps` itself for doing that in a