Esempio n. 1
0
        public override IAssignableExpression VisitAnonymousMethodExpression(IAnonymousMethodExpression expr,
                                                                             IList <IStatement> body)
        {
            var lambdaName = expr.GetName();
            var lambdaBody = new KaVEList <IStatement>();

            var isCompletionTarget = expr == _marker.HandlingNode && CompletionCase.InBody == _marker.Case;

            if (isCompletionTarget)
            {
                var stmt = new ExpressionStatement {
                    Expression = new CompletionExpression()
                };
                lambdaBody.Add(stmt);
            }

            var bodyVisitor = new StatementVisitor(_nameGen, _marker);

            expr.Body.Accept(bodyVisitor, lambdaBody);

            return(new LambdaExpression
            {
                Name = lambdaName,
                Body = lambdaBody
            });
        }
Esempio n. 2
0
        public override IAssignableExpression VisitLambdaExpression(ILambdaExpression expr, IList <IStatement> body)
        {
            if (expr.DeclaredElement == null)
            {
                return(new UnknownExpression());
            }

            var lambdaName  = expr.GetName();
            var lambdaBody  = new KaVEList <IStatement>();
            var bodyVisitor = new BodyVisitor(_nameGen, _marker);

            if (expr.BodyBlock != null)
            {
                expr.BodyBlock.Accept(bodyVisitor, lambdaBody);
            }
            else if (expr.BodyExpression != null)
            {
                var varRef = ToVariableRef(expr.BodyExpression, lambdaBody);
                lambdaBody.Add(
                    new ReturnStatement {
                    IsVoid = false, Expression = new ReferenceExpression {
                        Reference = varRef
                    }
                });
            }

            return(new LambdaExpression
            {
                Name = lambdaName,
                Body = lambdaBody
            });
        }
Esempio n. 3
0
        public override IAssignableExpression VisitLambdaExpression(ILambdaExpression expr, IList <IStatement> body)
        {
            if (expr.DeclaredElement == null)
            {
                return(new UnknownExpression());
            }

            var lambdaName = expr.GetName();
            var lambdaBody = new KaVEList <IStatement>();

            var isCompletionTarget = expr == _marker.HandlingNode && CompletionCase.InBody == _marker.Case;

            if (isCompletionTarget)
            {
                var stmt = new ExpressionStatement {
                    Expression = new CompletionExpression()
                };
                lambdaBody.Add(stmt);
            }

            var bodyVisitor = new StatementVisitor(_nameGen, _marker);

            if (expr.BodyBlock != null)
            {
                expr.BodyBlock.Accept(bodyVisitor, lambdaBody);
            }
            else if (expr.BodyExpression != null)
            {
                var varRef = ToVariableRef(expr.BodyExpression, lambdaBody);
                lambdaBody.Add(
                    new ReturnStatement {
                    IsVoid = false, Expression = new ReferenceExpression {
                        Reference = varRef
                    }
                });
            }

            return(new LambdaExpression
            {
                Name = lambdaName,
                Body = lambdaBody
            });
        }
Esempio n. 4
0
        public static IKaVEList <T> LoadTestCase <T>(string path) where T : ITestCase
        {
            var testcases = new KaVEList <T>();
            var lines     = LoadTestFile(path);

            foreach (var line in lines)
            {
                var fields = line.Split('\t');
                var t      = (T)CreateTestCase(fields, typeof(T));
                testcases.Add(t);
            }
            return(testcases);
        }
Esempio n. 5
0
        private void writeToFile(List <Tuple <string, string> > list, string filePath)
        {
            List <string> s = new KaVEList <string>();

            for (var i = 0; i < list.Count; i++)
            {
                if (i == _numMaxInvalidNames)
                {
                    break;
                }
                s.Add(list[i].Item1);
            }
            File.WriteAllLines(filePath, s);
        }
        public void ShouldStoreZipGroups()
        {
            Init("a", "b", "c");

            _sut.StoreZipGroups(Sets.NewHashSet(ToSet("a", "b"), ToSet("c")));

            var actuals = new KaVEList <IKaVESet <string> >(); // allow duplicates
            IKaVESet <string> zipGroup;

            while (_sut.AcquireNextUnmergedZipGroup(out zipGroup))
            {
                actuals.Add(zipGroup);
            }
            var expecteds = Sets.NewHashSet(ToSet("a", "b"), ToSet("c"));

            CollectionAssert.AreEquivalent(expecteds, actuals);
        }
Esempio n. 7
0
        public void Run()
        {
            Console.WriteLine("Grab Names from Contexts");
            var ctx = FindInputFiles();

            var numZips    = ctx.Count();
            var currentZip = 1;

            var numTotalCtxs   = 0;
            var numTotalUsages = 0;
            List <Tuple <string, List <string> > > ssts = new KaVEList <Tuple <string, List <string> > >();

            foreach (var fileName in ctx)
            {
                Log("### processing zip {0}/{1}: {2}", currentZip++, numZips, fileName);

                var fullFileIn = _dirIn + fileName;

                using (var ra = new ReadingArchive(fullFileIn))
                {
                    Log("reading contexts...");
                    var numCtxs = 0;
                    while (ra.HasNext())
                    {
                        var context = ra.GetNext <Context>();
                        var list    = new KaVEList <string>();
                        // TODO: grab names in a NameToJsonConverter
                        numCtxs++;
                    }
                    Log("found {0} contexts\n\n", numCtxs);
                    if (_numMaxZips != -1 && currentZip == _numMaxZips + 1)
                    {
                        break;
                    }
                }
            }
            var typeNameNullCount   = 0;
            var typeNameCount       = 0;
            var methodNameNullCount = 0;
            var methodNameCount     = 0;
            List <Tuple <string, string> > wrongSyntaxTypeName = new KaVEList <Tuple <string, string> >();

            foreach (var t in ssts)
            {
                foreach (var s in t.Item2)
                {
                    var type = s.Split(':');
                    if (type[0].Equals("CSharp.PropertyName"))
                    {
                        typeNameCount++;
                        var name = s.Deserialize <IName>();
                        if (name.Identifier == "?")
                        {
                            wrongSyntaxTypeName.Add(new Tuple <string, string>(s, t.Item1));
                            typeNameNullCount++;
                        }
                    }
                }
            }
            Log("{0} of {1} names are null", typeNameNullCount, typeNameCount);
            Log("{0} of {1} names are null", methodNameNullCount, methodNameCount);
            double percentageTypeNames   = typeNameNullCount / (double)typeNameCount;
            double percentageMethodNames = methodNameNullCount / (double)methodNameCount;

            Log("TypeNames not parseable: {0}%\n", percentageTypeNames);
            Log("PropertyName not parseable: {0}%\n\n", percentageMethodNames);

            //showInvalidNames(wrongSyntaxTypeName);

            Log("\n\n");

            //showInvalidNames(wrongSyntaxMethodName);

            if (_writeToFile)
            {
                Log("File with invalid names written to {0}", _dirOut);
                writeToFile(wrongSyntaxTypeName, _dirOut + "/typename.txt");
            }
            //Log(wrongSyntax[0].Item1 + "\n\n");
            //Log(wrongSyntax[0].Item2 + "\n\n");
        }