예제 #1
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
            });
        }
예제 #2
0
 private TypeNamingParser.GenericParamContext[] GetGenericParams()
 {
     if (IsNestedGeneric())
     {
         KaVEList <TypeNamingParser.GenericParamContext> param =
             new KaVEList <TypeNamingParser.GenericParamContext>();
         var genericTypePartContext = RecursiveNested(Ctx.regularType().nestedType().nestedTypeName())
                                      .typeName()
                                      .possiblyGenericTypeName()
                                      .genericTypePart();
         if (genericTypePartContext != null)
         {
             param.AddAll(genericTypePartContext.genericParam());
         }
         if (Ctx.regularType().nestedType().typeName().possiblyGenericTypeName().genericTypePart() != null)
         {
             param.AddAll(
                 Ctx.regularType()
                 .nestedType()
                 .typeName()
                 .possiblyGenericTypeName()
                 .genericTypePart()
                 .genericParam());
         }
         return(param.ToArray());
     }
     return(Ctx.regularType()
            .resolvedType()
            .typeName()
            .possiblyGenericTypeName()
            .genericTypePart()
            .genericParam());
 }
예제 #3
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
            });
        }
        public void ParameterList_MultipleParameters()
        {
            var parameters = new KaVEList <IParameterName> {
                Names.Parameter("[A,P] p1"), Names.Parameter("[B,P] p2")
            };
            var sut = new SSTPrintingContext();

            sut.ParameterList(parameters);
            Assert.AreEqual("(A p1, B p2)", sut.ToString());
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
0
        private String GetWithoutLastTypeName(TypeNamingParser.ResolvedTypeContext resolvedType)
        {
            String typeName = resolvedType.@namespace() != null
                ? resolvedType.@namespace().GetText() + resolvedType.typeName().GetText()
                : resolvedType.typeName().GetText();

            List <TypeNamingParser.TypeNameContext> typeNames = new KaVEList <TypeNamingParser.TypeNameContext>();

            for (int i = 1; i < typeNames.Count - 1; i++)
            {
                typeName += "+" + typeNames[i].GetText();
            }
            return(typeName);
        }
예제 #8
0
        public override void VisitSwitchStatement(ISwitchStatement block, IList <IStatement> body)
        {
            AddIf(block, CompletionCase.EmptyCompletionBefore, body);

            var switchBlock = new SwitchBlock {
                Reference = _exprVisitor.ToVariableRef(block.Condition, body)
            };

            foreach (var section in block.Sections)
            {
                IKaVEList <IStatement> currentSection = null;

                foreach (var label in section.CaseLabels)
                {
                    currentSection = new KaVEList <IStatement>();
                    if (label.IsDefault)
                    {
                        switchBlock.DefaultSection = currentSection;
                    }
                    else
                    {
                        switchBlock.Sections.Add(
                            new CaseBlock
                        {
                            Label = _exprVisitor.ToSimpleExpression(label.ValueExpression, body),
                            Body  = currentSection
                        });
                    }
                    AddIf(label, CompletionCase.InBody, currentSection);
                }

                AddIf(section, CompletionCase.InBody, currentSection);
                foreach (var statement in section.Statements)
                {
                    statement.Accept(this, currentSection);
                }

                switch (1)
                {
                case 1 * 2:
                case 0:
                    break;
                }
            }

            body.Add(switchBlock);

            AddIf(block, CompletionCase.EmptyCompletionAfter, body);
        }
예제 #9
0
        public override IAssignableExpression VisitAnonymousMethodExpression(IAnonymousMethodExpression expr,
                                                                             IList <IStatement> body)
        {
            var lambdaName  = expr.GetName();
            var lambdaBody  = new KaVEList <IStatement>();
            var bodyVisitor = new BodyVisitor(_nameGen, _marker);

            expr.Body.Accept(bodyVisitor, lambdaBody);

            return(new LambdaExpression
            {
                Name = lambdaName,
                Body = lambdaBody
            });
        }
        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);
        }
        public void StatementBlock_NotEmpty_WithoutBrackets()
        {
            var stmts = new KaVEList <IStatement> {
                new ContinueStatement(), new BreakStatement()
            };
            var visitor = new SSTPrintingVisitor();
            var sut     = new SSTPrintingContext();

            var expected = String.Join(
                Environment.NewLine,
                "",
                "    continue;",
                "    break;");

            sut.StatementBlock(stmts, visitor, false);
            Assert.AreEqual(expected, sut.ToString());
        }
예제 #12
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
            });
        }
        public void GeneratesNewConcurrentEventForCommandAndFollowup()
        {
            var expectedCommandEvent  = new CommandEvent();
            var expectedFollowupEvent = TestEventFactory.SomeEvent();
            var eventList             = new KaVEList <IDEEvent>
            {
                TestEventFactory.SomeEvent(),
                expectedCommandEvent,
                expectedFollowupEvent
            };

            ISet <IDEEvent> resultingSet = new HashSet <IDEEvent>();

            eventList.ForEach(ideEvent => resultingSet = _uut.Map(ideEvent));

            Assert.AreEqual(1, resultingSet.Count);

            var resultingConcurrentEvent = (ConcurrentEvent)resultingSet.First();

            Assert.AreEqual(2, resultingConcurrentEvent.ConcurrentEventList.Count);
            CollectionAssert.Contains(resultingConcurrentEvent.ConcurrentEventList, expectedCommandEvent);
            CollectionAssert.Contains(resultingConcurrentEvent.ConcurrentEventList, expectedFollowupEvent);
        }
예제 #14
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");
        }