Skip to content

Commit

Permalink
Move extra arg into RefCell
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 18, 2024
1 parent 5a7a2c9 commit e543430
Show file tree
Hide file tree
Showing 55 changed files with 135 additions and 528 deletions.
4 changes: 1 addition & 3 deletions src/analyzer/classlike_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::expression_analyzer;
use crate::file_analyzer::FileAnalyzer;
use crate::function_analysis_data::FunctionAnalysisData;
use crate::functionlike_analyzer::{update_analysis_result_with_tast, FunctionLikeAnalyzer};
use crate::scope_analyzer::ScopeAnalyzer;
use crate::scope::BlockContext;
use crate::scope_analyzer::ScopeAnalyzer;
use crate::statements_analyzer::StatementsAnalyzer;
use crate::stmt_analyzer::AnalysisError;
use hakana_reflection_info::codebase_info::symbols::SymbolKind;
Expand Down Expand Up @@ -155,7 +155,6 @@ impl<'a> ClassLikeAnalyzer<'a> {
expr,
&mut analysis_data,
&mut class_context,
&mut None,
)?;

if codebase.enum_exists(&name) {
Expand Down Expand Up @@ -209,7 +208,6 @@ impl<'a> ClassLikeAnalyzer<'a> {
default,
&mut analysis_data,
&mut class_context,
&mut None,
)?;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/analyzer/def_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::custom_hook::AfterDefAnalysisData;
use crate::file_analyzer::InternalError;
use crate::function_analysis_data::FunctionAnalysisData;
use crate::functionlike_analyzer::FunctionLikeAnalyzer;
use crate::scope_analyzer::ScopeAnalyzer;
use crate::scope::loop_scope::LoopScope;
use crate::scope::BlockContext;
use crate::scope_analyzer::ScopeAnalyzer;
use crate::statements_analyzer::StatementsAnalyzer;
use crate::stmt_analyzer::AnalysisError;
use crate::{expression_analyzer, stmt_analyzer};
Expand Down Expand Up @@ -93,7 +93,6 @@ pub(crate) fn analyze(
&boxed.value,
analysis_data,
&mut context,
&mut None,
) {
return Err(InternalError(error, pos));
}
Expand Down
41 changes: 6 additions & 35 deletions src/analyzer/expr/as_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::rc::Rc;

use crate::scope_analyzer::ScopeAnalyzer;
use crate::scope::BlockContext;
use crate::scope_analyzer::ScopeAnalyzer;
use crate::statements_analyzer::StatementsAnalyzer;
use crate::stmt_analyzer::AnalysisError;

Expand All @@ -27,7 +27,6 @@ pub(crate) fn analyze<'expr>(
null_if_false: bool,
analysis_data: &mut FunctionAnalysisData,
context: &mut BlockContext,
if_body_context: &mut Option<BlockContext>,
) -> Result<(), AnalysisError> {
let mut root_expr = left.clone();
let mut has_arrayget_key = false;
Expand Down Expand Up @@ -80,22 +79,10 @@ pub(crate) fn analyze<'expr>(
| aast::Expr_::Await(..)
)
{
replacement_left = get_fake_as_var(
left,
statements_analyzer,
analysis_data,
context,
if_body_context,
);
replacement_left = get_fake_as_var(left, statements_analyzer, analysis_data, context);
} else if let aast::Expr_::Lvar(var) = root_expr.2 {
if var.1 .1 == "$$" {
replacement_left = get_fake_as_var(
left,
statements_analyzer,
analysis_data,
context,
if_body_context,
);
replacement_left = get_fake_as_var(left, statements_analyzer, analysis_data, context);
}
}

Expand Down Expand Up @@ -139,13 +126,7 @@ pub(crate) fn analyze<'expr>(
let old_expr_types = analysis_data.expr_types.clone();
analysis_data.expr_types.clone_from(&old_expr_types);

expression_analyzer::analyze(
statements_analyzer,
&ternary,
analysis_data,
context,
if_body_context,
)?;
expression_analyzer::analyze(statements_analyzer, &ternary, analysis_data, context)?;

let mut ternary_type = analysis_data
.get_expr_type(stmt_pos)
Expand Down Expand Up @@ -207,27 +188,17 @@ fn get_fake_as_var(
statements_analyzer: &StatementsAnalyzer,
analysis_data: &mut FunctionAnalysisData,
context: &mut BlockContext,
if_body_context: &mut Option<BlockContext>,
) -> Option<aast::Expr<(), ()>> {
let left_var_id = format!("$<tmp coalesce var>{}", left.pos().start_offset());

expression_analyzer::analyze(
statements_analyzer,
left,
analysis_data,
context,
if_body_context,
)
.ok();
expression_analyzer::analyze(statements_analyzer, left, analysis_data, context).ok();

let condition_type = analysis_data
.get_rc_expr_type(left.pos())
.cloned()
.unwrap_or(Rc::new(get_mixed_any()));

context
.locals
.insert(left_var_id.clone(), condition_type);
context.locals.insert(left_var_id.clone(), condition_type);

return Some(aast::Expr(
(),
Expand Down
32 changes: 4 additions & 28 deletions src/analyzer/expr/assignment/array_assignment_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,18 @@ pub(crate) fn analyze(
array_exprs.push(root_array_expr);
let root_array_expr = root_array_expr.0;

expression_analyzer::analyze(
statements_analyzer,
root_array_expr,
analysis_data,
context,
&mut None,
)?;
expression_analyzer::analyze(statements_analyzer, root_array_expr, analysis_data, context)?;

let mut root_type = analysis_data
.get_expr_type(root_array_expr.pos())
.cloned()
.unwrap_or(get_mixed_any());

if root_type.is_mixed() {
expression_analyzer::analyze(
statements_analyzer,
expr.0,
analysis_data,
context,
&mut None,
)?;
expression_analyzer::analyze(statements_analyzer, expr.0, analysis_data, context)?;

if let Some(dim_expr) = expr.1 {
expression_analyzer::analyze(
statements_analyzer,
dim_expr,
analysis_data,
context,
&mut None,
)?;
expression_analyzer::analyze(statements_analyzer, dim_expr, analysis_data, context)?;
}
}

Expand Down Expand Up @@ -684,13 +666,7 @@ pub(crate) fn analyze_nested_array_assignment<'a>(
let was_inside_general_use = context.inside_general_use;
context.inside_general_use = true;

expression_analyzer::analyze(
statements_analyzer,
dim,
analysis_data,
context,
&mut None,
)?;
expression_analyzer::analyze(statements_analyzer, dim, analysis_data, context)?;

context.inside_general_use = was_inside_general_use;
let dim_type = analysis_data.get_rc_expr_type(dim.pos()).cloned();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,7 @@ pub(crate) fn analyze_regular_assignment(
let was_inside_general_use = context.inside_general_use;
context.inside_general_use = true;

expression_analyzer::analyze(
statements_analyzer,
stmt_var,
analysis_data,
context,
&mut None,
)?;
expression_analyzer::analyze(statements_analyzer, stmt_var, analysis_data, context)?;

context.inside_general_use = was_inside_general_use;

Expand Down Expand Up @@ -360,9 +354,7 @@ pub(crate) fn analyze_regular_assignment(
if let Some(var_id) = var_id {
let context_type = Rc::new(context_type.unwrap_or(get_mixed_any()).clone());

context
.locals
.insert(var_id.to_owned(), context_type);
context.locals.insert(var_id.to_owned(), context_type);
}

Ok(assigned_properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@ pub(crate) fn analyze(
// eg. $class::$foo
let was_inside_general_use = context.inside_general_use;
context.inside_general_use = true;
expression_analyzer::analyze(
statements_analyzer,
expr,
analysis_data,
context,
&mut None,
)?;
expression_analyzer::analyze(statements_analyzer, expr, analysis_data, context)?;
context.inside_general_use = was_inside_general_use;

let lhs_type = analysis_data.get_expr_type(&expr.1.clone());
Expand Down
30 changes: 10 additions & 20 deletions src/analyzer/expr/binop/and_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub(crate) fn analyze<'expr>(
right: &'expr aast::Expr<(), ()>,
analysis_data: &mut FunctionAnalysisData,
context: &mut BlockContext,
if_body_context: &mut Option<BlockContext>,
) -> Result<(), AnalysisError> {
let mut left_context = context.clone();

Expand All @@ -32,13 +31,7 @@ pub(crate) fn analyze<'expr>(

analysis_data.set_expr_type(stmt_pos, get_bool());

expression_analyzer::analyze(
statements_analyzer,
left,
analysis_data,
&mut left_context,
if_body_context,
)?;
expression_analyzer::analyze(statements_analyzer, left, analysis_data, &mut left_context)?;

if let Some(cond_type) = analysis_data.get_rc_expr_type(left.pos()).cloned() {
handle_paradoxical_condition(
Expand Down Expand Up @@ -73,9 +66,7 @@ pub(crate) fn analyze<'expr>(

for (var_id, var_type) in &left_context.locals {
if left_context.assigned_var_ids.contains_key(var_id) {
context
.locals
.insert(var_id.clone(), var_type.clone());
context.locals.insert(var_id.clone(), var_type.clone());
}
}

Expand Down Expand Up @@ -160,7 +151,6 @@ pub(crate) fn analyze<'expr>(
right,
analysis_data,
&mut right_context,
if_body_context,
)?;

if let Some(cond_type) = analysis_data.get_rc_expr_type(right.pos()).cloned() {
Expand All @@ -185,26 +175,26 @@ pub(crate) fn analyze<'expr>(
.extend(right_context.assigned_var_ids);
}

if let Some(ref mut if_body_context) = if_body_context {
if let Some(if_body_context) = &context.if_body_context {
let mut if_body_context_inner = if_body_context.borrow_mut();

if !context.inside_negation {
context.locals = right_context.locals;

if_body_context
.locals
.extend(context.locals.clone());
if_body_context_inner.locals.extend(context.locals.clone());

if_body_context
if_body_context_inner
.cond_referenced_var_ids
.extend(context.cond_referenced_var_ids.clone());
if_body_context
if_body_context_inner
.assigned_var_ids
.extend(context.assigned_var_ids.clone());

if_body_context
if_body_context_inner
.reconciled_expression_clauses
.extend(partitioned_clauses.1);

if_body_context.allow_taints = right_context.allow_taints;
if_body_context_inner.allow_taints = right_context.allow_taints;
} else {
context.locals = left_context.locals;
}
Expand Down
22 changes: 12 additions & 10 deletions src/analyzer/expr/binop/arithmetic_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ pub(crate) fn analyze<'expr: 'tast, 'tast>(
analysis_data: &'tast mut FunctionAnalysisData,
context: &mut BlockContext,
) -> Result<(), AnalysisError> {
expression_analyzer::analyze(statements_analyzer, left, analysis_data, context, &mut None)?;
expression_analyzer::analyze(
statements_analyzer,
right,
analysis_data,
context,
&mut None,
)?;
expression_analyzer::analyze(statements_analyzer, left, analysis_data, context)?;
expression_analyzer::analyze(statements_analyzer, right, analysis_data, context)?;

let fallback = get_mixed_any();
let e1_type = match analysis_data.get_rc_expr_type(&left.1).cloned() {
Expand Down Expand Up @@ -106,7 +100,11 @@ pub(crate) fn analyze<'expr: 'tast, 'tast>(
continue;
}

if let TAtomic::TEnumLiteralCase { constraint_type: Some(constraint), .. } = &e1_type_atomic {
if let TAtomic::TEnumLiteralCase {
constraint_type: Some(constraint),
..
} = &e1_type_atomic
{
e1_type_atomic = e1_type_atomic.clone();
}

Expand Down Expand Up @@ -142,7 +140,11 @@ pub(crate) fn analyze<'expr: 'tast, 'tast>(
continue;
}

if let TAtomic::TEnumLiteralCase { constraint_type: Some(constraint), .. } = &e2_type_atomic {
if let TAtomic::TEnumLiteralCase {
constraint_type: Some(constraint),
..
} = &e2_type_atomic
{
e2_type_atomic = e2_type_atomic.clone();
}

Expand Down
2 changes: 0 additions & 2 deletions src/analyzer/expr/binop/assignment_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ pub(crate) fn analyze(
),
analysis_data,
context,
&mut None,
)?;

context.inside_assignment_op = false;
Expand Down Expand Up @@ -155,7 +154,6 @@ pub(crate) fn analyze(
assign_value,
analysis_data,
context,
&mut None,
)?;
}
};
Expand Down
Loading

0 comments on commit e543430

Please sign in to comment.