Exemple #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());
        }
Exemple #2
0
        public string getMethodFullName(MethodDeclarationSyntax method)
        {
            string methodName = method.Identifier.ToString();
            string argName    = "";
            var    parList    = method.ParameterList.DescendantNodes().OfType <ParameterSyntax>();

            foreach (var par in parList)
            {
                var nodes = par.DescendantNodes();
                if (nodes.Count() == 0)
                {
                    continue;
                }
                var tokens = nodes.First().DescendantTokens();
                foreach (var token in tokens)
                {
                    if (token.Kind() == SyntaxKind.IdentifierToken)
                    {
                        foreach (var word in SplitWord.getCamelWords(token.ToString()))
                        {
                            argName += word;
                            argName += "\t";
                        }
                    }
                    else
                    {
                        argName += token.Kind().ToString();
                        argName += "\t";
                    }
                }
            }
            return(methodName + argName);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            string curDir = System.IO.Directory.GetCurrentDirectory();

            string rootDir = System.IO.Directory.GetCurrentDirectory() + "\\..\\..\\..\\..\\..";

            Common.initTrainTestFile(rootDir);
            SplitWord.init(rootDir);

            generateExprData ged = new generateExprData(rootDir);

            ged.initPDGs();
            ged.writeJsonResult();
        }
Exemple #4
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());
        }