private int CountClassName(SourceCode aSourceCode)
        {
            int result = 0;

            ClassDefinitionComp classDef = new ClassDefinitionComp();

            int pos = 1;
            foreach(String line in aSourceCode.GetLines())
            {
                if (classDef.Identify(aSourceCode, line, pos))
                    result++;
                pos++;
            }
            return result;
        }
Пример #2
0
        private void RunCompile()
        {
            if (displayProgress)
                Console.WriteLine("Start compiling... File: {0}", this.sourceCode.GetFileName());

            int pos = 1;

            foreach (String currentSourceCodeLine in this.sourceCode.GetLines())
            {
                TargetCodeResult targetCode = new TargetCodeResult(currentSourceCodeLine);

                // TODO: For now we list the commands here, much get a better idea to handle (??) load it from a list (??)

                ICommand usingDirective = new UsingDirectiveComp();
                ICommand namespaceComp = new NamespaceComp();
                ICommand classDef = new ClassDefinitionComp();
                ICommand openStatementBlock = new OpenStatementBlockComp();
                ICommand mainMethod = new MainMethodComp();
                ICommand methodDef = new MethodDefinitionComp();
                ICommand closeStatementBlock = new CloseStatementBlockComp();
                ICommand keywords = new KeywordsComp();
                ICommand autoProperty = new AutoPropertiesComp();

                if (usingDirective.Identify(this.sourceCode, currentSourceCodeLine, pos))
                    targetCode = usingDirective.Compile(this.sourceCode, currentSourceCodeLine, pos);

                if (namespaceComp.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = namespaceComp.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (classDef.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = classDef.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (openStatementBlock.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = openStatementBlock.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (mainMethod.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = mainMethod.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (methodDef.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = methodDef.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (closeStatementBlock.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = closeStatementBlock.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (keywords.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = keywords.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                if (autoProperty.Identify(this.sourceCode, targetCode.GetCurrentCode(), pos))
                    targetCode = autoProperty.Compile(this.sourceCode, targetCode.GetCurrentCode(), pos);

                // TODO: Add additional commands here

                if (!targetCode.Success)
                    this.errors.Add(targetCode.ErrorMessage);

                if (UnitTestMode)
                    this.allCode.Add(targetCode.GetCurrentCode());

                if (writeJavaCode && targetCode.IsValidCode())
                    WriteJavaLine(targetCode);

                pos++;
            }
        }