public override bool VisitAssignmentExpression(AssignmentExpression assignExp) { if (assignExp.Target.NodeType == NodeType.VariableRefExpression) { // Convert to declaration if not found on the scope VariableReferenceExpression varRef = (VariableReferenceExpression)assignExp.Target; ISymbolTable scope = varRef.SymbolTable; System.Diagnostics.Debug.Assert(scope != null); String name = varRef.Identifier.Name; if (!scope.IsDefined(name)) // TODO: The rules are slighly more complicated than that. { errorReport.Disable(); SingleVariableDeclarationStatement varDecl = new SingleVariableDeclarationStatement(varRef.Identifier); IStatement stmt = ASTUtils.GetParentStatement(varRef); System.Diagnostics.Debug.Assert(stmt != null); IStatementContainer stmts = stmt.Parent as IStatementContainer; int index = stmts.Statements.IndexOf(stmt); varDecl.InitExp = assignExp.Value; // stmts.Statements.Insert(index, varDecl); stmts.Statements.Replace(stmt, varDecl); if (!ApplyDeclarationRules(varRef.Identifier, scope, varDecl, stmt)) { stmts.Statements.Remove(varDecl); } errorReport.Enable(); } } return(base.VisitAssignmentExpression(assignExp)); }