move macro id to ids

This commit is contained in:
Aleksey Kladov 2019-01-02 00:37:36 +03:00
parent 42cc77703b
commit db8d293208
5 changed files with 40 additions and 40 deletions

View File

@ -4,11 +4,11 @@ use ra_syntax::{SyntaxNode, SourceFileNode};
use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable};
use crate::{
DefLoc, DefId, Name, HirFileId,
DefLoc, DefId, MacroCallLoc, MacroCallId, Name, HirFileId,
SourceFileItems, SourceItemId,
query_definitions,
FnScopes,
macros::{MacroCallLoc, MacroCallId, MacroExpansion},
macros::MacroExpansion,
module::{ModuleId, ModuleTree, ModuleSource,
nameres::{ItemMap, InputModuleItems}},
ty::{InferenceResult, Ty},

View File

@ -2,7 +2,7 @@ use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId};
use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast};
use crate::{
MacroCallId, HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum,
HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum,
arena::{Arena, Id},
};
@ -77,6 +77,38 @@ impl From<MacroCallId> for HirFileId {
}
}
/// `MacroCallId` identifies a particular macro invocation, like
/// `println!("Hello, {}", world)`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MacroCallId(u32);
ra_db::impl_numeric_id!(MacroCallId);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MacroCallLoc {
pub(crate) source_root_id: SourceRootId,
pub(crate) module_id: ModuleId,
pub(crate) source_item_id: SourceItemId,
}
impl MacroCallId {
pub(crate) fn loc(
self,
db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>,
) -> MacroCallLoc {
db.as_ref().id2loc(self)
}
}
impl MacroCallLoc {
#[allow(unused)]
pub(crate) fn id(
&self,
db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>,
) -> MacroCallId {
db.as_ref().loc2id(&self)
}
}
/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
/// in a specific module.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

View File

@ -42,8 +42,8 @@ pub use self::{
path::{Path, PathKind},
name::Name,
krate::Crate,
ids::{HirFileId, DefId, DefLoc},
macros::{MacroDef, MacroInput, MacroExpansion, MacroCallId, MacroCallLoc},
ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc},
macros::{MacroDef, MacroInput, MacroExpansion},
module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution},
function::{Function, FnScopes},
adt::{Struct, Enum},

View File

@ -1,44 +1,12 @@
use std::sync::Arc;
use ra_db::{SourceRootId, LocalSyntaxPtr, LocationIntener};
use ra_db::LocalSyntaxPtr;
use ra_syntax::{
TextRange, TextUnit, SourceFileNode, AstNode, SyntaxNode,
ast::{self, NameOwner},
};
use crate::{module::ModuleId, SourceItemId, HirDatabase};
/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
/// in a specific module.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MacroCallId(u32);
ra_db::impl_numeric_id!(MacroCallId);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MacroCallLoc {
pub(crate) source_root_id: SourceRootId,
pub(crate) module_id: ModuleId,
pub(crate) source_item_id: SourceItemId,
}
impl MacroCallId {
pub(crate) fn loc(
self,
db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>,
) -> MacroCallLoc {
db.as_ref().id2loc(self)
}
}
impl MacroCallLoc {
#[allow(unused)]
pub(crate) fn id(
&self,
db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>,
) -> MacroCallId {
db.as_ref().loc2id(&self)
}
}
use crate::{HirDatabase, MacroCallId};
// Hard-coded defs for now :-(
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

View File

@ -12,7 +12,7 @@ use ra_db::{SourceRootId, Cancelable,};
use crate::{
SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, HirFileId,
macros::MacroCallLoc,
MacroCallLoc,
db::HirDatabase,
function::FnScopes,
module::{