pub struct Semantics {
pub source: Source,
pub program: Program,
pub parse_error: Option<ParseError>,
pub names: Names,
pub issues: IssueCollection,
}
Expand description
The Semantics
struct encapsulates all the information obtained after performing semantic analysis
on a PHP source code file. It includes the original source code, the parsed abstract syntax tree (AST),
any parse errors encountered, resolved names, the symbol table, and a collection of semantic issues.
Fields§
§source: Source
The original PHP source code, including its name and content.
program: Program
The abstract syntax tree (AST) resulting from parsing the source code.
parse_error: Option<ParseError>
An optional parse error, if one occurred during parsing.
names: Names
The resolved names within the source code, used for identifier resolution.
issues: IssueCollection
A collection of semantic issues found during analysis, such as invalid inheritance, improper returns, duplicate names, etc.
Implementations§
Source§impl Semantics
impl Semantics
Sourcepub fn build(
interner: &ThreadedInterner,
version: PHPVersion,
source: Source,
) -> Self
pub fn build( interner: &ThreadedInterner, version: PHPVersion, source: Source, ) -> Self
Builds the Semantics
object by performing parsing, name resolution, symbol table construction,
and semantic analysis on the provided PHP source code.
§Parameters
interner
: A reference to aThreadedInterner
used for string interning, which helps in efficiently handling string comparisons and memory usage.version
: The PHP version to use for semantic analysis.source
: TheSource
object representing the PHP source code to be analyzed.
§Returns
A Semantics
object containing the results of the semantic analysis, including the AST,
any parse errors, resolved names, the symbol table, and any semantic issues found.
§Steps
- Parsing: The source code is parsed into an abstract syntax tree (AST).
If there are syntax errors, they are captured in
parse_error
. - Name Resolution: Resolves all the names in the AST, linking identifiers to their declarations.
- Symbol Table Construction: Builds a symbol table containing all the symbols (classes, functions, constants, etc.) defined in the source code.
- Semantic Analysis: Checks the AST for semantic correctness, such as type checking, scope rules, etc., and collects any issues.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Determines whether the semantic analysis was successful, i.e., no parse errors or semantic issues were found.
Sourcepub fn has_parse_error(&self) -> bool
pub fn has_parse_error(&self) -> bool
Determines whether the source code contains any parse errors.
Sourcepub fn has_issues(&self) -> bool
pub fn has_issues(&self) -> bool
Determines whether the source code contains any semantic issues.
Sourcepub fn category(&self) -> SourceCategory
pub fn category(&self) -> SourceCategory
Retrieves the category of the source code.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Semantics
impl<'de> Deserialize<'de> for Semantics
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Semantics
impl StructuralPartialEq for Semantics
Auto Trait Implementations§
impl Freeze for Semantics
impl RefUnwindSafe for Semantics
impl Send for Semantics
impl Sync for Semantics
impl Unpin for Semantics
impl UnwindSafe for Semantics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more