/// <summary> /// Visit variable expression ast /// </summary> /// <param name="variableExpressionAst"></param> /// <returns></returns> public override object VisitVariableExpression(VariableExpressionAst variableExpressionAst) { if (variableExpressionAst == null) { return(null); } var varPath = variableExpressionAst.VariablePath; if (_variables.ContainsKey(AssignmentTarget.GetUnaliasedVariableName(varPath))) { var details = _variables[AssignmentTarget.GetUnaliasedVariableName(varPath)]; Current.AddAst(new VariableTarget(variableExpressionAst)); details.AssociatedAsts.Add(variableExpressionAst); } return(base.VisitVariableExpression(variableExpressionAst)); }
/// <summary> /// Visit assignment statement /// </summary> /// <param name="assignmentStatementAst"></param> /// <returns></returns> public override object VisitAssignmentStatement(AssignmentStatementAst assignmentStatementAst) { if (assignmentStatementAst == null) { return(null); } base.VisitAssignmentStatement(assignmentStatementAst); foreach (var assignTarget in GetAssignmentTargets(assignmentStatementAst.Left)) { var leftAst = assignTarget; while (leftAst is AttributedExpressionAst) { leftAst = ((AttributedExpressionAst)leftAst).Child; } if (leftAst is VariableExpressionAst) { var varPath = ((VariableExpressionAst)leftAst).VariablePath; if (_variables.ContainsKey(AssignmentTarget.GetUnaliasedVariableName(varPath))) { var details = _variables[AssignmentTarget.GetUnaliasedVariableName(varPath)]; details.AssignedBlocks.Add(Current); } Current.AddAst(new AssignmentTarget(assignmentStatementAst)); } else { // We skip things like $a.test = 3. In this case we will just test // for variable $a assignTarget.Visit(this.Decorator); } } return(null); }