示例#1
0
        public void writeFuncIntrinsicJson(List <PDG> pdgs, string path)
        {
            var        sw1     = new StringWriter();
            JsonWriter writer1 = new JsonTextWriter(sw1);

            writer1.Formatting = (Formatting.Indented);

            writer1.WriteStartArray();
            foreach (var pdg in pdgs)
            {
                writer1.WriteStartObject();
                writer1.WritePropertyName("name");
                writer1.WriteStartArray();

                foreach (var n in SplitWord.getIntrinsicWords(pdg.funcName))
                {
                    writer1.WriteValue(n);
                }

                writer1.WriteEndArray();

                writer1.WritePropertyName("tokens");
                writer1.WriteStartArray();
                var method = pdg.getNode(0).info.GetSyntax();
                foreach (var token in method.ChildNodes().Last().DescendantTokens())
                {
                    if (token.Kind() == SyntaxKind.IdentifierToken)
                    {
                        writer1.WriteValue("<id>");
                        foreach (var word in SplitWord.getIntrinsicWords(token.ToString()))
                        {
                            writer1.WriteValue(word);
                        }
                        writer1.WriteValue("</id>");
                    }
                    else
                    {
                        writer1.WriteValue(token.Kind().ToString());
                    }
                }
                writer1.WriteEndArray();


                string funcBody = method.ToString();
                writer1.WritePropertyName("body");
                writer1.WriteStartArray();
                foreach (var stmt in funcBody.Split('\n'))
                {
                    writer1.WriteValue(stmt);
                }
                writer1.WriteEndArray();
                writer1.WriteEndObject();
            }

            writer1.WriteEndArray();

            writer1.Flush();

            File.WriteAllText(path, sw1.ToString());
        }
示例#2
0
        public void writePDGIntrinsicJson(List <PDG> pdgs, string path)
        {
            var        sw     = new StringWriter();
            JsonWriter writer = new JsonTextWriter(sw);

            writer.Formatting = (Formatting.Indented);

            writer.WriteStartArray();
            foreach (var pdg in pdgs)
            {
                writer.WriteStartObject();

                writer.WritePropertyName("name");

                writer.WriteStartArray();

                foreach (var n in SplitWord.getIntrinsicWords(pdg.funcName))
                {
                    writer.WriteValue(n);
                }
                writer.WriteEndArray();

                writer.WritePropertyName("tokens");
                writer.WriteStartArray();

                var dicSort = from objeDic in pdg.PDNodes orderby objeDic.Key ascending select objeDic;
                foreach (var node in dicSort)
                {
                    if (node.Value.type > PDGNodeType.predicate && node.Value.type != PDGNodeType.loop_break &&
                        node.Value.type != PDGNodeType.loop_continue && node.Value.type != PDGNodeType.return_statement)
                    {
                        continue;
                    }
                    if (node.Value.info == null)
                    {
                        continue;
                    }
                    if (node.Value.info.GetSyntax().Kind() == SyntaxKind.TryStatement)
                    {
                        continue;
                    }
                    writer.WriteStartArray();
                    writer.WriteValue(node.Key);  //statemtent ID
                    var tokens = node.Value.parse2();

                    foreach (var token in tokens)
                    {
                        writer.WriteValue(token);
                    }
                    writer.WriteEndArray();
                }
                writer.WriteEndArray();

                writer.WritePropertyName("cdedges");
                writer.WriteStartArray();
                foreach (var node in dicSort)
                {
                    var nodeType = node.Value.type;
                    if (nodeType > PDGNodeType.predicate && nodeType != PDGNodeType.loop_break && nodeType != PDGNodeType.loop_continue)
                    {
                        continue;
                    }

                    foreach (var e in pdg.getCDSuccWithoutRegion(node.Key))
                    {
                        writer.WriteValue(node.Key + "->" + e);
                    }
                }
                writer.WriteEndArray();
                writer.WritePropertyName("cfedges");
                writer.WriteStartArray();
                foreach (var node in dicSort)
                {
                    var nodeType = node.Value.type;
                    if (nodeType > PDGNodeType.predicate && nodeType != PDGNodeType.loop_break && nodeType != PDGNodeType.loop_continue)
                    {
                        continue;
                    }
                    //writer.WriteStartArray();
                    foreach (var e in pdg.getCFSuccWithoutRegion(node.Key))
                    {
                        writer.WriteValue(node.Key + "->" + e);
                    }
                    //writer.WriteEndArray();
                }
                writer.WriteEndArray();
                writer.WritePropertyName("ddedges");
                writer.WriteStartArray();
                foreach (var node in dicSort)
                {
                    var nodeType = node.Value.type;
                    if (nodeType > PDGNodeType.predicate && nodeType != PDGNodeType.loop_break && nodeType != PDGNodeType.loop_continue)
                    {
                        continue;
                    }
                    //writer.WriteStartArray();
                    if (pdg.getDDSuccs(node.Key) == null)
                    {
                        continue;
                    }
                    foreach (var e in pdg.getDDSuccs(node.Key))
                    {
                        writer.WriteValue(node.Key + "->" + e);
                    }
                    //writer.WriteEndArray();
                }
                writer.WriteEndArray();

                writer.WritePropertyName("body");

                var    method   = pdg.getNode(0).info.GetSyntax();
                string funcBody = method.ToString();
                writer.WriteStartArray();
                foreach (var stmt in funcBody.Split('\n'))
                {
                    writer.WriteValue(stmt);
                }
                writer.WriteEndArray();

                writer.WriteEndObject();
            }
            writer.WriteEndArray();

            writer.Flush();

            File.WriteAllText(path, sw.ToString());
        }