mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
asm! parsing and lowering fixes
This commit is contained in:
parent
c075a9980e
commit
f74a0c8801
10 changed files with 106 additions and 18 deletions
|
@ -572,9 +572,11 @@ impl<'db> SemanticsImpl<'db> {
|
|||
} else {
|
||||
let asm = ast::AsmExpr::cast(parent)?;
|
||||
let source_analyzer = self.analyze_no_infer(asm.syntax())?;
|
||||
let line = asm.template().position(|it| *it.syntax() == literal)?;
|
||||
let asm = self.wrap_node_infile(asm);
|
||||
let (owner, (expr, asm_parts)) = source_analyzer.as_asm_parts(asm.as_ref())?;
|
||||
let res = asm_parts
|
||||
.get(line)?
|
||||
.iter()
|
||||
.map(|&(range, index)| {
|
||||
(
|
||||
|
@ -629,8 +631,9 @@ impl<'db> SemanticsImpl<'db> {
|
|||
} else {
|
||||
let asm = ast::AsmExpr::cast(parent)?;
|
||||
let source_analyzer = &self.analyze_no_infer(asm.syntax())?;
|
||||
let line = asm.template().position(|it| *it.syntax() == literal)?;
|
||||
let asm = self.wrap_node_infile(asm);
|
||||
source_analyzer.resolve_offset_in_asm_template(asm.as_ref(), offset).map(
|
||||
source_analyzer.resolve_offset_in_asm_template(asm.as_ref(), line, offset).map(
|
||||
|(owner, (expr, range, index))| {
|
||||
(range, Some(Either::Right(InlineAsmOperand { owner, expr, index })))
|
||||
},
|
||||
|
|
|
@ -907,12 +907,14 @@ impl SourceAnalyzer {
|
|||
pub(crate) fn resolve_offset_in_asm_template(
|
||||
&self,
|
||||
asm: InFile<&ast::AsmExpr>,
|
||||
line: usize,
|
||||
offset: TextSize,
|
||||
) -> Option<(DefWithBodyId, (ExprId, TextRange, usize))> {
|
||||
let (def, _, body_source_map) = self.def.as_ref()?;
|
||||
let (expr, args) = body_source_map.asm_template_args(asm)?;
|
||||
Some(*def).zip(
|
||||
args.iter()
|
||||
args.get(line)?
|
||||
.iter()
|
||||
.find(|(range, _)| range.contains_inclusive(offset))
|
||||
.map(|(range, idx)| (expr, *range, *idx)),
|
||||
)
|
||||
|
@ -944,7 +946,7 @@ impl SourceAnalyzer {
|
|||
pub(crate) fn as_asm_parts(
|
||||
&self,
|
||||
asm: InFile<&ast::AsmExpr>,
|
||||
) -> Option<(DefWithBodyId, (ExprId, &[(TextRange, usize)]))> {
|
||||
) -> Option<(DefWithBodyId, (ExprId, &[Vec<(TextRange, usize)>]))> {
|
||||
let (def, _, body_source_map) = self.def.as_ref()?;
|
||||
Some(*def).zip(body_source_map.asm_template_args(asm))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue