コード例 #1
0
        /// <summary>
        /// Create new Variable
        /// </summary>
        public static CodeBlock AddReturnStatement(this CodeBlock inParentBlock, string inReturnVariableName)
        {
            var tmpData = new ReturnCodeEntry()
            {
                CodeEntries = new List <ICodeEntry> {
                    new ConstantValue()
                    {
                        Value = inReturnVariableName
                    }
                }
            };

            inParentBlock.CodeEntries.Add(tmpData);
            return(inParentBlock);
        }
コード例 #2
0
        /// <summary>
        /// Handling an Array Inizializer block
        /// I'm unsure why this is not an ExpressionCOntext, but whatever
        /// </summary>
        /// <param name="inCodeBlock"></param>
        /// <param name="inBlockStatement"></param>
        private void HandleBlockStatementStatement(CodeBlock inParentCodeBlock, StatementContext inStatement)
        {
            if (inStatement.expression().Length > 1)
            {
                throw new NotImplementedException("Not done yet");
            }
            var tmpStatement = new StatementCode();

            if (inStatement.IF() != null)
            {
                if (inStatement.statement().Length > 2)
                {
                    throw new NotImplementedException("statement.statement length bigger than 1");
                }
                tmpStatement.StatementType       = StatementTypeEnum.If;
                tmpStatement.StatementCodeBlocks = new List <CodeBlock>()
                {
                    new CodeBlock()
                };
                HandleExpressionContext(tmpStatement.StatementCodeBlocks[0], inStatement.parExpression().expression(), null);
                tmpStatement.InnerContent = new CodeBlock();
                HandleBlockStatementStatement(tmpStatement.InnerContent, inStatement.statement()[0]);

                if (inStatement.ELSE() != null)
                {
                    inParentCodeBlock.CodeEntries.Add(tmpStatement);
                    tmpStatement = new StatementCode();

                    tmpStatement.StatementType       = StatementTypeEnum.Else;
                    tmpStatement.StatementCodeBlocks = new List <CodeBlock>()
                    {
                        new CodeBlock()
                    };
                    HandleExpressionContext(tmpStatement.StatementCodeBlocks[0], inStatement.parExpression().expression(), null);
                    tmpStatement.InnerContent = new CodeBlock();
                    HandleBlockStatementStatement(tmpStatement.InnerContent, inStatement.statement().Last());
                }
            }
            else if (inStatement.ASSERT() != null)
            {
                tmpStatement.StatementType       = StatementTypeEnum.Assert;
                tmpStatement.StatementCodeBlocks = new List <CodeBlock>()
                {
                };
                foreach (var tmpStatementExpression in inStatement.expression())
                {
                    var tmpBlock = new CodeBlock();
                    HandleExpressionContext(tmpBlock, tmpStatementExpression);
                    tmpStatement.StatementCodeBlocks.Add(tmpBlock);
                }
            }
            else if (inStatement.IDENTIFIER() != null)
            {
                throw new NotImplementedException("Not done yet");
            }
            else if (inStatement.RETURN() != null)
            {
                var tmpReturnCodeEntry = new ReturnCodeEntry();
                HandleExpressionContext(tmpReturnCodeEntry, inStatement.expression()[0], null);
                inParentCodeBlock.CodeEntries.Add(tmpReturnCodeEntry);
                return;
            }
            else if (inStatement.THROW() != null)
            {
                tmpStatement.StatementType       = StatementTypeEnum.Throw;
                tmpStatement.StatementCodeBlocks = new List <CodeBlock>()
                {
                };
                var tmpBlock = new CodeBlock();
                HandleExpressionContext(tmpBlock, inStatement.expression()[0]);
                tmpStatement.StatementCodeBlocks.Add(tmpBlock);
                return;
            }
            else if (inStatement.SEMI() != null)
            {
                //Semicolon, so it is a simple Statement
                //tmpStatement.StatementCodeBlocks = new List<CodeBlock>() { new CodeBlock() };
                if (inStatement.expression()[0].GetText() + ";" != inStatement.GetText())
                {
                    throw new NotImplementedException("Unhandlet Statement in Semi");
                }

                HandleExpressionContext(inParentCodeBlock, inStatement.expression()[0], null);
                return;
            }
            else if (inStatement.block() != null)
            {
                foreach (var tmpCode in inStatement.block().blockStatement())
                {
                    HandloBlockStatementContent(inParentCodeBlock, tmpCode);
                }
                return;
            }
            else if (inStatement.forControl() != null)
            {
                var tmpForControl = inStatement.forControl();
                tmpStatement.StatementType       = StatementTypeEnum.For;
                tmpStatement.StatementCodeBlocks = new List <CodeBlock>()
                {
                    new CodeBlock(), new CodeBlock(), new CodeBlock()
                };
                tmpStatement.InnerContent = new CodeBlock();
                HandleBlockStatementStatement(tmpStatement.InnerContent, inStatement.statement()[0]);

                if (tmpForControl.forInit() != null)
                {
                    if (tmpForControl.forInit().localVariableDeclaration() != null)
                    {
                        HandleLocalVariableDeclarationContext(tmpStatement.StatementCodeBlocks[0], tmpForControl.forInit().localVariableDeclaration());
                    }
                    if (tmpForControl.forInit().expressionList() != null)
                    {
                        foreach (var tmpExpr in tmpForControl.forInit().expressionList().expression())
                        {
                            HandleExpressionContext(tmpStatement.StatementCodeBlocks[0], tmpExpr);
                        }
                    }
                }
                if (tmpForControl.expression() != null)
                {
                    HandleExpressionContext(tmpStatement.StatementCodeBlocks[1], tmpForControl.expression());
                }
                if (tmpForControl.expressionList() != null)
                {
                    foreach (var tmpExpr in tmpForControl.expressionList().expression())
                    {
                        HandleExpressionContext(tmpStatement.StatementCodeBlocks[2], tmpExpr);
                    }
                }
                if (tmpForControl.enhancedForControl() != null)
                {
                    throw new NotImplementedException("for Inline Variable Declaration missing yet");
                    HandleExpressionContext(tmpStatement.StatementCodeBlocks[1], tmpForControl.expression());
                }
            }
            else if (inStatement.WHILE() != null)
            {
                if (inStatement.statement().Length > 2)
                {
                    throw new NotImplementedException("statement.statement length bigger than 1");
                }
                tmpStatement.StatementType       = StatementTypeEnum.While;
                tmpStatement.StatementCodeBlocks = new List <CodeBlock>()
                {
                    new CodeBlock()
                };
                HandleExpressionContext(tmpStatement.StatementCodeBlocks[0], inStatement.parExpression().expression(), null);
                tmpStatement.InnerContent = new CodeBlock();
                HandleBlockStatementStatement(tmpStatement.InnerContent, inStatement.statement()[0]);
            }
            else
            {
                throw new NotImplementedException("Not done yet");
            }

            if (inStatement.statement().Length > 0)
            {
                var tmpinnercount = (inStatement.ELSE() != null ? 1 : 0)
                                    + (inStatement.IF() != null ? 1 : 0)
                                    + (inStatement.FOR() != null ? 1 : 0)
                                    + (inStatement.WHILE() != null ? 1 : 0);

                if (inStatement.statement().Length != tmpinnercount)
                {
                    throw new NotImplementedException("Statement inner Statement length not matching");
                }
            }

            inParentCodeBlock.CodeEntries.Add(tmpStatement);
        }
コード例 #3
0
        public void PropertysThis_FullName_ToLower()
        {
            var tmpProject = new ProjectInformation();

            var tmpClassString     = Create.AddClass("String");
            var tmpGetFullName     = "getFullName";
            var tmpFullNameMethode = tmpClassString.AddMethode(tmpGetFullName, new TypeContainer {
                Name = "String"
            });

            var tmpClass1      = Create.AddClass("Class1");
            var tmpMethodeName = "getChildResources";

            tmpClass1.AddMethode(tmpMethodeName, new TypeContainer {
                Name = "void"
            });
            var tmpMethode = tmpClass1.MethodeList[0];

            Create.AddField(tmpClass1, "Text", new BaseType("String"));

            tmpMethode.Code = new CodeBlock();

            var tmpReturn = new ReturnCodeEntry
            {
                CodeEntries = new List <CodeConverterCore.Interface.ICodeEntry>
                {
                    new VariableAccess
                    {
                        Access = new VariableAccess
                        {
                            Child = new VariableAccess
                            {
                                Access = new ConstantValue
                                {
                                    Value = "Text",
                                }
                            },
                            Access = new ConstantValue
                            {
                                Value = "this"
                            }
                        },
                        Child = new VariableAccess
                        {
                            Access = new MethodeCall
                            {
                                Name = tmpGetFullName
                            }
                        }
                    }
                }
            };

            tmpMethode.Code.CodeEntries.Add(tmpReturn);

            var tmpText = tmpReturn.ToString();

            Assert.AreEqual("return this  Text     getFullName ()  ", tmpText);

            tmpProject.FillClasses(new List <ClassContainer> {
                tmpClass1, tmpClassString
            });

            new AnalyzerCore().LinkProjectInformation(tmpProject);

            tmpFullNameMethode.IsProperty = true;
            tmpFullNameMethode.Name       = "FullName";

            Assert.AreEqual(tmpFullNameMethode.Name, (((tmpReturn.CodeEntries[0] as VariableAccess).Child as VariableAccess).Access as MethodeCall).Name);
        }