Skip to main content

mir_analyzer/
lib.rs

1pub mod cache;
2pub mod call;
3pub mod class;
4pub mod collector;
5pub mod context;
6pub mod db;
7pub mod dead_code;
8pub mod diagnostics;
9pub mod expr;
10pub mod file_analyzer;
11pub mod generic;
12pub mod narrowing;
13pub mod parser;
14pub mod pass2;
15pub mod php_version;
16pub mod project;
17pub mod session;
18pub mod stmt;
19pub mod stubs;
20pub mod taint;
21
22pub use file_analyzer::{FileAnalysis, FileAnalyzer};
23pub use parser::type_from_hint::type_from_hint;
24pub use parser::{DocblockParser, ParsedDocblock};
25pub use php_version::{ParsePhpVersionError, PhpVersion};
26pub use project::{AnalysisResult, ProjectAnalyzer};
27pub use session::AnalysisSession;
28pub use stubs::{is_builtin_function, stub_files, StubVfs};
29
30pub mod symbol;
31pub mod type_env;
32pub use mir_issues::{Issue, IssueKind, Location, Severity};
33
34/// Convert a parser [`php_ast::Span`] (byte-offset range) into a
35/// [`mir_codebase::storage::Location`] (file path + 1-based line range +
36/// 0-based codepoint columns) using `source` and the parser's `source_map`.
37///
38/// This is the canonical way for consumers to translate Pass-2 result spans
39/// (e.g. [`crate::symbol::ResolvedSymbol::span`]) into source locations they
40/// can hand to their own protocol layer. Consumers that need different
41/// position semantics (LSP UTF-16 code units, byte offsets, etc.) translate
42/// from this `Location` rather than re-implementing the column math.
43pub fn location_from_span(
44    span: php_ast::Span,
45    file: std::sync::Arc<str>,
46    source: &str,
47    source_map: &php_rs_parser::source_map::SourceMap,
48) -> mir_codebase::storage::Location {
49    let (line, col_start) = diagnostics::offset_to_line_col(source, span.start, source_map);
50    let (line_end, col_end) = if span.start < span.end {
51        diagnostics::offset_to_line_col(source, span.end, source_map)
52    } else {
53        (line, col_start)
54    };
55    mir_codebase::storage::Location {
56        file,
57        line,
58        line_end,
59        col_start,
60        col_end: col_end.max(col_start.saturating_add(1)),
61    }
62}
63pub use symbol::{DocumentSymbol, DocumentSymbolKind, ResolvedSymbol, SymbolKind};
64pub use type_env::{ScopeId, TypeEnv};
65
66pub mod composer;
67pub use composer::Psr4Map;
68
69pub mod test_utils;