diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/db.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/hygiene.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 26 |
6 files changed, 29 insertions, 51 deletions
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index c4e62f799..6d116ee75 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -6,8 +6,8 @@ use crate::{ | |||
6 | adt::VariantDef, | 6 | adt::VariantDef, |
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | 7 | db::{AstDatabase, DefDatabase, HirDatabase}, |
8 | ids::AstItemDef, | 8 | ids::AstItemDef, |
9 | Const, Either, Enum, EnumVariant, FieldSource, Function, HasBody, HirFileId, MacroDef, | 9 | Const, Either, Enum, EnumVariant, FieldSource, Function, HasBody, HirFileId, MacroDef, Module, |
10 | MacroDefId, Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | 10 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, |
11 | }; | 11 | }; |
12 | 12 | ||
13 | pub use hir_expand::Source; | 13 | pub use hir_expand::Source; |
@@ -140,15 +140,10 @@ impl HasSource for TypeAlias { | |||
140 | self.id.source(db) | 140 | self.id.source(db) |
141 | } | 141 | } |
142 | } | 142 | } |
143 | |||
144 | impl HasSource for MacroDef { | 143 | impl HasSource for MacroDef { |
145 | type Ast = ast::MacroCall; | 144 | type Ast = ast::MacroCall; |
146 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::MacroCall> { | 145 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::MacroCall> { |
147 | let ast_id = match self.id { | 146 | Source { file_id: self.id.ast_id.file_id(), ast: self.id.ast_id.to_node(db) } |
148 | MacroDefId::DeclarativeMacro(it) => it.ast_id, | ||
149 | MacroDefId::BuiltinMacro(it) => it.ast_id, | ||
150 | }; | ||
151 | Source { file_id: ast_id.file_id(), ast: ast_id.to_node(db) } | ||
152 | } | 147 | } |
153 | } | 148 | } |
154 | 149 | ||
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 5f18e9de3..30664278e 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use hir_expand::{ | 3 | use hir_expand::{ |
4 | builtin_macro::find_builtin_macro, | 4 | builtin_macro::find_builtin_macro, |
5 | name::{self, AsName, Name}, | 5 | name::{self, AsName, Name}, |
6 | DeclarativeMacro, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind, | 6 | HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind, MacroFileKind, |
7 | }; | 7 | }; |
8 | use ra_cfg::CfgOptions; | 8 | use ra_cfg::CfgOptions; |
9 | use ra_db::{CrateId, FileId}; | 9 | use ra_db::{CrateId, FileId}; |
@@ -708,13 +708,12 @@ where | |||
708 | // Case 1: macro rules, define a macro in crate-global mutable scope | 708 | // Case 1: macro rules, define a macro in crate-global mutable scope |
709 | if is_macro_rules(&mac.path) { | 709 | if is_macro_rules(&mac.path) { |
710 | if let Some(name) = &mac.name { | 710 | if let Some(name) = &mac.name { |
711 | let macro_id = DeclarativeMacro { ast_id, krate: self.def_collector.def_map.krate }; | 711 | let macro_id = MacroDefId { |
712 | self.def_collector.define_macro( | 712 | ast_id, |
713 | self.module_id, | 713 | krate: self.def_collector.def_map.krate, |
714 | name.clone(), | 714 | kind: MacroDefKind::Declarative, |
715 | MacroDefId::DeclarativeMacro(macro_id), | 715 | }; |
716 | mac.export, | 716 | self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); |
717 | ); | ||
718 | } | 717 | } |
719 | return; | 718 | return; |
720 | } | 719 | } |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index acb62da27..97fb0cb55 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | use crate::db::AstDatabase; | 2 | use crate::db::AstDatabase; |
3 | use crate::{ | 3 | use crate::{ |
4 | ast::{self, AstNode}, | 4 | ast::{self, AstNode}, |
5 | name, AstId, BuiltinMacro, CrateId, HirFileId, MacroCallId, MacroDefId, MacroFileKind, | 5 | name, AstId, CrateId, HirFileId, MacroCallId, MacroDefId, MacroDefKind, MacroFileKind, |
6 | TextUnit, | 6 | TextUnit, |
7 | }; | 7 | }; |
8 | 8 | ||
@@ -33,11 +33,7 @@ pub fn find_builtin_macro( | |||
33 | ) -> Option<MacroDefId> { | 33 | ) -> Option<MacroDefId> { |
34 | // FIXME: Better registering method | 34 | // FIXME: Better registering method |
35 | if ident == &name::LINE_MACRO { | 35 | if ident == &name::LINE_MACRO { |
36 | Some(MacroDefId::BuiltinMacro(BuiltinMacro { | 36 | Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Line) }) |
37 | expander: BuiltinExpander::Line, | ||
38 | krate, | ||
39 | ast_id, | ||
40 | })) | ||
41 | } else { | 37 | } else { |
42 | None | 38 | None |
43 | } | 39 | } |
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index 009ff5312..5eadee9c2 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{AstNode, Parse, SyntaxNode}; | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | ast_id_map::AstIdMap, BuiltinExpander, HirFileId, HirFileIdRepr, MacroCallId, MacroCallLoc, | 12 | ast_id_map::AstIdMap, BuiltinExpander, HirFileId, HirFileIdRepr, MacroCallId, MacroCallLoc, |
13 | MacroDefId, MacroFile, MacroFileKind, | 13 | MacroDefId, MacroDefKind, MacroFile, MacroFileKind, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | #[derive(Debug, Clone, Eq, PartialEq)] | 16 | #[derive(Debug, Clone, Eq, PartialEq)] |
@@ -69,9 +69,9 @@ pub(crate) fn macro_def( | |||
69 | db: &dyn AstDatabase, | 69 | db: &dyn AstDatabase, |
70 | id: MacroDefId, | 70 | id: MacroDefId, |
71 | ) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> { | 71 | ) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> { |
72 | match id { | 72 | match id.kind { |
73 | MacroDefId::DeclarativeMacro(it) => { | 73 | MacroDefKind::Declarative => { |
74 | let macro_call = it.ast_id.to_node(db); | 74 | let macro_call = id.ast_id.to_node(db); |
75 | let arg = macro_call.token_tree()?; | 75 | let arg = macro_call.token_tree()?; |
76 | let (tt, tmap) = mbe::ast_to_token_tree(&arg).or_else(|| { | 76 | let (tt, tmap) = mbe::ast_to_token_tree(&arg).or_else(|| { |
77 | log::warn!("fail on macro_def to token tree: {:#?}", arg); | 77 | log::warn!("fail on macro_def to token tree: {:#?}", arg); |
@@ -83,8 +83,8 @@ pub(crate) fn macro_def( | |||
83 | })?; | 83 | })?; |
84 | Some(Arc::new((TokenExpander::MacroRules(rules), tmap))) | 84 | Some(Arc::new((TokenExpander::MacroRules(rules), tmap))) |
85 | } | 85 | } |
86 | MacroDefId::BuiltinMacro(it) => { | 86 | MacroDefKind::BuiltIn(expander) => { |
87 | Some(Arc::new((TokenExpander::Builtin(it.expander.clone()), mbe::TokenMap::default()))) | 87 | Some(Arc::new((TokenExpander::Builtin(expander.clone()), mbe::TokenMap::default()))) |
88 | } | 88 | } |
89 | } | 89 | } |
90 | } | 90 | } |
diff --git a/crates/ra_hir_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs index 6b682d3ab..379562a2c 100644 --- a/crates/ra_hir_expand/src/hygiene.rs +++ b/crates/ra_hir_expand/src/hygiene.rs | |||
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | db::AstDatabase, | 9 | db::AstDatabase, |
10 | either::Either, | 10 | either::Either, |
11 | name::{AsName, Name}, | 11 | name::{AsName, Name}, |
12 | HirFileId, HirFileIdRepr, MacroDefId, | 12 | HirFileId, HirFileIdRepr, MacroDefKind, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | #[derive(Debug)] | 15 | #[derive(Debug)] |
@@ -24,9 +24,9 @@ impl Hygiene { | |||
24 | HirFileIdRepr::FileId(_) => None, | 24 | HirFileIdRepr::FileId(_) => None, |
25 | HirFileIdRepr::MacroFile(macro_file) => { | 25 | HirFileIdRepr::MacroFile(macro_file) => { |
26 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | 26 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); |
27 | match loc.def { | 27 | match loc.def.kind { |
28 | MacroDefId::DeclarativeMacro(it) => Some(it.krate), | 28 | MacroDefKind::Declarative => Some(loc.def.krate), |
29 | MacroDefId::BuiltinMacro(_) => None, | 29 | MacroDefKind::BuiltIn(_) => None, |
30 | } | 30 | } |
31 | } | 31 | } |
32 | }; | 32 | }; |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 21d666f13..c6ffa2c6f 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -78,15 +78,9 @@ impl HirFileId { | |||
78 | HirFileIdRepr::MacroFile(macro_file) => { | 78 | HirFileIdRepr::MacroFile(macro_file) => { |
79 | let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id); | 79 | let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id); |
80 | 80 | ||
81 | // FIXME: Do we support expansion information in builtin macro? | ||
82 | let macro_decl = match loc.def { | ||
83 | MacroDefId::DeclarativeMacro(it) => (it), | ||
84 | MacroDefId::BuiltinMacro(_) => return None, | ||
85 | }; | ||
86 | |||
87 | let arg_start = loc.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); | 81 | let arg_start = loc.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); |
88 | let def_start = | 82 | let def_start = |
89 | macro_decl.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); | 83 | loc.def.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); |
90 | 84 | ||
91 | let macro_def = db.macro_def(loc.def)?; | 85 | let macro_def = db.macro_def(loc.def)?; |
92 | let shift = macro_def.0.shift(); | 86 | let shift = macro_def.0.shift(); |
@@ -94,7 +88,7 @@ impl HirFileId { | |||
94 | let macro_arg = db.macro_arg(macro_file.macro_call_id)?; | 88 | let macro_arg = db.macro_arg(macro_file.macro_call_id)?; |
95 | 89 | ||
96 | let arg_start = (loc.ast_id.file_id, arg_start); | 90 | let arg_start = (loc.ast_id.file_id, arg_start); |
97 | let def_start = (macro_decl.ast_id.file_id, def_start); | 91 | let def_start = (loc.def.ast_id.file_id, def_start); |
98 | 92 | ||
99 | Some(ExpansionInfo { arg_start, def_start, macro_arg, macro_def, exp_map, shift }) | 93 | Some(ExpansionInfo { arg_start, def_start, macro_arg, macro_def, exp_map, shift }) |
100 | } | 94 | } |
@@ -128,22 +122,16 @@ impl salsa::InternKey for MacroCallId { | |||
128 | } | 122 | } |
129 | 123 | ||
130 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 124 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
131 | pub enum MacroDefId { | 125 | pub struct MacroDefId { |
132 | DeclarativeMacro(DeclarativeMacro), | ||
133 | BuiltinMacro(BuiltinMacro), | ||
134 | } | ||
135 | |||
136 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
137 | pub struct DeclarativeMacro { | ||
138 | pub krate: CrateId, | 126 | pub krate: CrateId, |
139 | pub ast_id: AstId<ast::MacroCall>, | 127 | pub ast_id: AstId<ast::MacroCall>, |
128 | pub kind: MacroDefKind, | ||
140 | } | 129 | } |
141 | 130 | ||
142 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 131 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
143 | pub struct BuiltinMacro { | 132 | pub enum MacroDefKind { |
144 | pub krate: CrateId, | 133 | Declarative, |
145 | pub ast_id: AstId<ast::MacroCall>, | 134 | BuiltIn(BuiltinExpander), |
146 | pub expander: BuiltinExpander, | ||
147 | } | 135 | } |
148 | 136 | ||
149 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |