//! Code to traverse the AST and drive the rest of scope analysis. //! //! This module is responsible for walking the AST. Other modules do the actual //! analysis. //! //! Scope analysis is currently a second pass, after parsing, using the AST, //! but the goal is to do this analysis as part of the parse phase, even when //! no AST is built. So we try to keep AST use separate from the analysis code.
usecrate::builder::{ScopeBuildError, ScopeDataMapAndScriptStencilList, ScopeDataMapBuilder}; usecrate::data::FunctionDeclarationPropertyMap; use ast::arena; use ast::associated_data::AssociatedData; use ast::source_atom_set::CommonSourceAtomSetIndices; use ast::{types::*, visit::Pass}; use std::collections::HashMap; use stencil::scope::ScopeDataMap; use stencil::script::{ScriptStencilIndex, ScriptStencilList};
/// The result of scope analysis. pubstruct ScopePassResult<'alloc> { pub scope_data_map: ScopeDataMap, pub function_declarations: HashMap<ScriptStencilIndex, &'alloc Function<'alloc>>, pub function_stencil_indices: AssociatedData<ScriptStencilIndex>, pub function_declaration_properties: FunctionDeclarationPropertyMap, pub scripts: ScriptStencilList, pub error: Option<ScopeBuildError>,
}
/// The top-level struct responsible for extracting the necessary information /// from the AST. The analysis itself is done mainly by the `ScopeDataMapBuilder`, /// which has very limited interaction with the AST. /// /// FIXME: This should be rewritten as a grammar extension. #[derive(Debug)] pubstruct ScopePass<'alloc> {
builder: ScopeDataMapBuilder,
function_declarations: HashMap<ScriptStencilIndex, &'alloc Function<'alloc>>,
}
// Given we override `visit_binding_identifier` above, // visit_identifier is not called for Identifier inside BindingIdentifier, // and this is called only for references, either // IdentifierExpression or AssignmentTargetIdentifier. fn visit_identifier(&mutself, ast: &'alloc Identifier) { self.builder.on_non_binding_identifier(ast.value);
}
/// Setter doesn't have FormalParameters, but single Parameter. /// Call builder methods around it. fn visit_setter(&mutself, ast: &'alloc Setter<'alloc>) { self.builder.before_setter(ast); // FIXME: Call self.builder.on_function_name
// FIXME: Pass something that points `(param)` part of setter, // including `(` and `)`. self.builder.before_setter_parameter(&ast.param); self.visit_parameter(&ast.param); self.builder.after_setter_parameter();
/// Arrow function with expression body. /// Use the expression as the node for function body. fn enter_enum_arrow_expression_body_variant_expression(
&mutself,
ast: &'alloc arena::Box<'alloc, Expression<'alloc>>,
) { let expr: &Expression = ast; self.builder.before_function_body(expr);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.