public void EnteringNode(object sender, XmlTraverseEventArgs e) { XmlNode node = e.Node; TotalNodes++; switch (node.LocalName) { case "Stmt_Echo": EchoStatements++; break; case "#text": StringLiteral(node); break; case AstConstants.Nodes.Stmt_Function: Functions++; break; case AstConstants.Nodes.Stmt_ClassMethod: Methods++; break; case AstConstants.Nodes.Stmt_Class: Classes++; break; case "Expr_Include": IncludeStatements++; break; case AstConstants.Nodes.Stmt_Goto: Gotos++; break; } }
public void EnteringNode(object sender, XmlTraverseEventArgs e) { var node = e.Node; switch (node.LocalName) { case AstConstants.Nodes.Expr_Assign: NodesOfInterest.Add(node); break; case AstConstants.Nodes.Expr_AssignOp_BitwiseAnd: case AstConstants.Nodes.Expr_AssignOp_BitwiseOr: case AstConstants.Nodes.Expr_AssignOp_BitwiseXor: case AstConstants.Nodes.Expr_AssignOp_Concat: case AstConstants.Nodes.Expr_AssignOp_Div: case AstConstants.Nodes.Expr_AssignOp_Minus: case AstConstants.Nodes.Expr_AssignOp_Mod: case AstConstants.Nodes.Expr_AssignOp_Mul: case AstConstants.Nodes.Expr_AssignOp_Plus: case AstConstants.Nodes.Expr_AssignOp_Pow: case AstConstants.Nodes.Expr_AssignOp_ShiftLeft: case AstConstants.Nodes.Expr_AssignOp_ShiftRight: case AstConstants.Nodes.Expr_AssignRef: break; case AstConstants.Nodes.Stmt_Echo: break; case AstConstants.Nodes.Expr_ShellExec: break; case AstConstants.Nodes.Expr_Eval: break; } }
public void EnteringNode(object sender, XmlTraverseEventArgs e) { if (e.Node.LocalName == AstConstants.Nodes.Stmt_Goto) { _gotos++; } }
public void LeavingNode(object sender, XmlTraverseEventArgs e) { var node = e.Node; indentation--; var toPrint = string.Format("{0}{1}:{2}:{3} - {4}", new string(' ', indentation), node.NodeType, node.Prefix, node.LocalName, node.Value); writer.WriteLine(toPrint); }
public void EnteringNode(object sender, XmlTraverseEventArgs e) { var node = e.Node; var toPrint = string.Format("{0}{1}:{2}:{3} - {4}", new string(' ', indentation), node.NodeType, node.Prefix, node.LocalName, node.Value); writer.WriteLine(toPrint); indentation++; }
public void LeavingNode(object sender, XmlTraverseEventArgs e) { }
public void EnteringNode(object sender, XmlTraverseEventArgs e) { var node = e.Node; switch (node.LocalName) { // Nodes case AstConstants.Nodes.Stmt_Interface: currentInterface = new Interface(node) { StartLine = AstNode.GetStartLine(node), EndLine = AstNode.GetEndLine(node) }; break; case AstConstants.Nodes.Stmt_Class: currentClass = new Class(node) { StartLine = AstNode.GetStartLine(node), EndLine = AstNode.GetEndLine(node) }; break; case AstConstants.Nodes.Stmt_ClassMethod: ClassMethodEnter(node); break; case AstConstants.Nodes.Stmt_Property: inPropertyDeclarations = true; break; case AstConstants.Nodes.Stmt_PropertyProperty: currentProperty = new Property(node) { StartLine = AstNode.GetStartLine(node), EndLine = AstNode.GetEndLine(node), VisibilityModifiers = propertyModifiers, }; break; case AstConstants.Nodes.Stmt_Function: currentFunctions.Push(new Function(node) { StartLine = AstNode.GetStartLine(node), EndLine = AstNode.GetEndLine(node) }); functionClosureOrder.Push(FunctionClosure.Function); break; case AstConstants.Nodes.Expr_Closure: currentClosures.Push(new ExtractorClosureInfo() { Closure = new Closure(node) { StartLine = AstNode.GetStartLine(node), EndLine = AstNode.GetEndLine(node) } }); functionClosureOrder.Push(FunctionClosure.Closure); break; case AstConstants.Nodes.Param: currentParameter = new Parameter(node); break; case AstConstants.Nodes.Expr_ClosureUse: currentClosureUse = new ClosureUse(node); break; // Subnodes case AstConstants.Subnodes.Name: Name(node); break; case AstConstants.Subnodes.Params: inParamDeclarations = true; break; case AstConstants.Subnodes.ByRef: Subnode_ByRef_Enter(node); break; case AstConstants.Subnodes.Variadic: if (inParamDeclarations && !parameteVariadicIsSet) { currentParameter.IsVariadic = Convert.ToBoolean(node.FirstChild.LocalName); parameteVariadicIsSet = true; } break; case AstConstants.Subnodes.Default: if (inParamDeclarations && !parameterDefaultIsSet) { currentParameter.IsOptional = node.FirstChild.Prefix != AstConstants.Scalar; parameterDefaultIsSet = true; } break; case AstConstants.Subnodes.Uses: if (currentClosures.Any() && currentClosures.Peek().ClosureUses == null && !currentClosures.Peek().ClosureUsagesIsSet) { currentClosures.Peek().ClosureUses = new Queue<ClosureUse>(); } break; case AstConstants.Subnodes.Var: if (currentClosureUse != null) { currentClosureUse.Name = node.InnerText; } break; case AstConstants.Subnodes.Type: if (inPropertyDeclarations && currentProperty == null) { propertyModifiers = (AstConstants.VisibilityModifiers) Enum.Parse(typeof (AstConstants.VisibilityModifiers), node.InnerText); } break; } }
public void LeavingNode(object sender, XmlTraverseEventArgs e) { var node = e.Node; switch (node.LocalName) { // Nodes case AstConstants.Nodes.Stmt_Interface: _interfaces.Add(currentInterface); currentInterface = null; break; case AstConstants.Nodes.Stmt_Class: _classes.Add(currentClass); currentClass = null; break; case AstConstants.Nodes.Stmt_ClassMethod: ClassMethodExit(); break; case AstConstants.Nodes.Stmt_Property: inPropertyDeclarations = false; propertyModifiers = 0; break; case AstConstants.Nodes.Stmt_PropertyProperty: currentClass.Properties.Add(currentProperty); currentProperty = null; break; case AstConstants.Nodes.Stmt_Function: _functions.Add(currentFunctions.Pop()); functionClosureOrder.Pop(); break; case AstConstants.Nodes.Expr_ClosureUse: currentClosures.Peek().ClosureUses.Enqueue(currentClosureUse); currentClosureUse = null; break; case AstConstants.Nodes.Expr_Closure: _closures.Add(currentClosures.Pop().Closure); functionClosureOrder.Pop(); break; case AstConstants.Nodes.Param: parameters.Enqueue(currentParameter); currentParameter = null; parameteVariadicIsSet = false; parameterByRefIsSet = false; parameterDefaultIsSet = false; break; // Subnodes case AstConstants.Subnodes.Params: ParamsExit(); break; case AstConstants.Subnodes.Uses: if (currentClosures.Any()) { ExtractorClosureInfo closureInfo = currentClosures.Peek(); if (!closureInfo.ClosureUsagesIsSet && closureInfo.ClosureUses != null) { closureInfo.Closure.UseParameters = closureInfo.ClosureUses.ToArray(); closureInfo.ClosureUsagesIsSet = true; } } break; } }
public void EnteringNode(object sender, XmlTraverseEventArgs e) { var node = e.Node; if (!IsNodeOfInterest(node) || IsCurrentlyBlocking) { isFirst = false; return; } if (nodesNotToVisit.Contains(node)) { DoNotVisitChildren(node); nodesNotToVisit.Remove(node); return; } switch (node.LocalName) { case AstConstants.Nodes.Stmt_Class: case AstConstants.Nodes.Stmt_Interface: case AstConstants.Nodes.Stmt_Trait: DoNotVisitChildren(node); break; case AstConstants.Nodes.Expr_Closure: case AstConstants.Nodes.Stmt_Function: case AstConstants.Nodes.Stmt_ClassMethod: if(isFirst) FunctionEnter(node); else DoNotVisitChildren(node); break; case AstConstants.Nodes.Stmt_If: IfStatementEnter(node); break; case AstConstants.Nodes.Stmt_Else: ElseStatementsEnter(node); break; case AstConstants.Nodes.Stmt_ElseIf: ElseIfStatementsEnter(node); break; case AstConstants.Nodes.Stmt_Switch: SwitchStatementEnter(node); break; case AstConstants.Nodes.Stmt_Case: SwitchCaseStatementEnter(node); break; // Loops case AstConstants.Nodes.Stmt_For: ForStatementEnter(node); break; case AstConstants.Nodes.Stmt_While: WhileStatementEnter(node); break; case AstConstants.Nodes.Stmt_Foreach: WhileOrForeachStatementEnter(node); break; case AstConstants.Nodes.Stmt_Do: DoStatementEnter(node); break; case AstConstants.Nodes.Stmt_Continue: ContinueStatementEnter(node); break; case AstConstants.Nodes.Stmt_Break: BreakStatementEnter(node); break; case AstConstants.Nodes.Stmt_Return: ReturnStatementEnter(node); break; default: if (node.Prefix == AstConstants.Node) { NormalStatementEnter(node); } break; } if (isFirst) { isFirst = false; } }
public void LeavingNode(object sender, XmlTraverseEventArgs e) { var node = e.Node; if (traverseBlockingNode == node) { traverseBlockingNode = null; return; } if (!IsNodeOfInterest(node) || IsCurrentlyBlocking) { return; } if (node.Prefix.Equals(AstConstants.Node)) { switch (node.LocalName) { case AstConstants.Nodes.Expr_Closure: case AstConstants.Nodes.Stmt_Function: FunctionExit(node); break; case AstConstants.Nodes.Stmt_If: IfStatementExit(node); break; case AstConstants.Nodes.Stmt_Else: ElseStatementsExit(node); break; case AstConstants.Nodes.Stmt_ElseIf: ElseIfStatementsExit(node); break; case AstConstants.Nodes.Stmt_Switch: SwitchStatementExit(node); break; // Loops case AstConstants.Nodes.Stmt_For: ForStatementExit(node); break; case AstConstants.Nodes.Stmt_Do: case AstConstants.Nodes.Stmt_While: case AstConstants.Nodes.Stmt_Foreach: DoAndWhileAndForeachStatementExit(node); break; case AstConstants.Nodes.Stmt_ClassMethod: ClassMethodExit(node); break; } } if (node.Prefix.Equals(AstConstants.Subnode)) { switch (node.LocalName) { // For loops: case AstConstants.Subnodes.Init: //InitExit(node); break; case AstConstants.Subnodes.Cond: //CondExit(node); break; case AstConstants.Subnodes.Loop: break; } } }