コード例 #1
0
ファイル: Program.cs プロジェクト: obfuscators-2019/shwing
        public ShwingBuilder(string path)
        {
            var filePath     = path;
            var fileContents = File.ReadAllText(filePath);

            if (fileContents.Length <= 0)
            {
                return;
            }

            var tree = CSharpSyntaxTree.ParseText(fileContents);

            if (OracleNode == null)
            {
                OracleNode = new ShwingNode(tree.GetRoot(), -1, 0, 1);
            }
            else
            {
                OracleNode.Add(tree.GetRoot(), -1, 0, 1);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: obfuscators-2019/shwing
        public void Add(SyntaxNodeOrToken newNode, int precedingId, int currentDepth, int maxDepth = int.MaxValue)
        {
            Counter += 1;
            _parentIds.Add(precedingId);

            if (currentDepth >= maxDepth)
            {
                return;
            }
            // TODO: Throw, or error check or something.
            Debug.Assert(newNode.Kind() == Kind, "Uh oh. Kinds must be the same at ShwingNodes.");

            var        newChildren     = newNode.ChildNodesAndTokens();
            ShwingNode lastTouchedNode = null;

            for (int i = 0; i < newChildren.Count; i++)
            {
                var newKid = newChildren[i];

                if (i == Children.Count)
                {
                    Children.Add(new List <ShwingNode>());
                }

                var j = Children[i].FindIndex(x => x.Kind == newKid.Kind());

                var lastId = lastTouchedNode?.Id ?? -2;

                if (j != -1)
                {
                    Children[i][j].Add(newKid, lastId, currentDepth + 1, maxDepth);
                    lastTouchedNode = Children[i][j];
                }
                else
                {
                    lastTouchedNode = new ShwingNode(newKid, lastId, currentDepth + 1, maxDepth);
                    Children[i].Add(lastTouchedNode);
                }
            }
        }