예제 #1
0
        /// <summary></summary>
        protected virtual void CompileRoot(IRoot root)
        {
            Debug.Assert(root != null);

            IRoot LanguageRoot = LoadLanguageRoot();

            Debug.Assert(LanguageRoot != null);
            Debug.Assert(NodeTreeDiagnostic.IsValid(LanguageRoot));

            MergeLanguageRoot(root, LanguageRoot);

            if (IsRootValid(root))
            {
                ReplacePhase1Macroes(root);

                if (ReplicateAllBlocks(root))
                {
                    ReplacePhase2Macroes(root);
                    InitializeSources(root);

                    if (CheckClassAndLibraryNames(root))
                    {
                        if (ResolveIdentifiers(root) && ResolveTypes(root))
                        {
                            SealScope(root);

                            if (ResolveContract(root) && ResolveBody(root))
                            {
                                CheckNumberType(root);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadOnlyRootNodeIndex"/> class.
        /// </summary>
        /// <param name="node">The indexed root node.</param>
        public ReadOnlyRootNodeIndex(INode node)
        {
            if (!NodeTreeDiagnostic.IsValid(node, assertValid: false))
            {
                Debug.WriteLine($"Invalid node {node}");
                Exception InnerException = null;
                throw new ArgumentException(nameof(node), InnerException);
            }

            Debug.Assert(node != null);

            Node = node;
        }
예제 #3
0
        /// <summary></summary>
        protected virtual bool IsRootValid(IRoot root)
        {
            bool Success = true;

            if (!NodeTreeDiagnostic.IsValid(root, assertValid: false))
            {
                ErrorList.AddError(new ErrorInputRootInvalid());
                Success = false;
            }

            Debug.Assert(Success || !ErrorList.IsEmpty);
            return(Success);
        }
예제 #4
0
        public static void TestCompileFile()
        {
            if (TestOff)
            {
                return;
            }

            Compiler Compiler = new Compiler();

            Assert.That(Compiler != null, "Sanity Check #0");

            string TestFileName = $"{RootPath}coverage/coverage.easly";

            Exception ex;
            string    NullString = null;

            ex = Assert.Throws <ArgumentNullException>(() => Compiler.Compile(NullString));
            Assert.That(ex.Message == $"Value cannot be null.{NL}Parameter name: fileName", ex.Message);

            Compiler.Compile("notfound.easly");
            Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputFileNotFound AsInputFileNotFound && AsInputFileNotFound.Message == "File not found: 'notfound.easly'.", ErrorListToString(Compiler));

            using (FileStream fs = new FileStream(TestFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
            {
                Compiler.Compile(TestFileName);
                Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputFileInvalid, ErrorListToString(Compiler));
            }

            Stream NullStream = null;

            ex = Assert.Throws <ArgumentNullException>(() => Compiler.Compile(NullStream));
            Assert.That(ex.Message == $"Value cannot be null.{NL}Parameter name: stream", ex.Message);

            Compiler.Compile(TestFileName);
            Assert.That(Compiler.ErrorList.IsEmpty, ErrorListToString(Compiler));

            string InvalidFile = File.Exists($"{RootPath}Test-Easly-Compiler.dll") ? $"{RootPath}Test-Easly-Compiler.dll" : $"{RootPath}Test-Easly-Compiler.csproj";

            using (FileStream fs = new FileStream(InvalidFile, FileMode.Open, FileAccess.Read))
            {
                Compiler.Compile(fs);
                Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputFileInvalid, ErrorListToString(Compiler));
            }

            IRoot NullRoot = null;

            ex = Assert.Throws <ArgumentNullException>(() => Compiler.Compile(NullRoot));
            Assert.That(ex.Message == $"Value cannot be null.{NL}Parameter name: root", ex.Message);

            using (FileStream fs = new FileStream(TestFileName, FileMode.Open, FileAccess.Read))
            {
                Compiler.Compile(fs);
                Assert.That(Compiler.ErrorList.IsEmpty, ErrorListToString(Compiler));
            }

            IRoot ClonedRoot = NodeHelper.DeepCloneNode(CoverageNode, cloneCommentGuid: true) as IRoot;

            NodeTreeHelper.SetGuidProperty(ClonedRoot.ClassBlocks.NodeBlockList[0].NodeList[0], nameof(IClass.ClassGuid), Guid.Empty);
            Assert.That(!NodeTreeDiagnostic.IsValid(ClonedRoot, assertValid: false));

            Compiler.Compile(ClonedRoot);
            Assert.That(!Compiler.ErrorList.IsEmpty && Compiler.ErrorList.At(0) is IErrorInputRootInvalid, ErrorListToString(Compiler));
        }