예제 #1
0
 private static void ValidateCodeDirectives(CodeDirectiveCollection e)
 {
     for (int i = 0; i < e.Count; i++)
     {
         ValidateCodeDirective(e[i]);
     }
 }
        static CodeDirective[] _ToArray(CodeDirectiveCollection dirs)
        {
            var result = new CodeDirective[dirs.Count];

            dirs.CopyTo(result, 0);
            return(result);
        }
예제 #3
0
        public void AddRange()
        {
            CodeDirective cd1 = new CodeDirective();
            CodeDirective cd2 = new CodeDirective();
            CodeDirective cd3 = new CodeDirective();

            CodeDirectiveCollection coll1 = new CodeDirectiveCollection();

            coll1.Add(cd1);
            coll1.Add(cd2);

            CodeDirectiveCollection coll2 = new CodeDirectiveCollection();

            coll2.Add(cd3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(cd1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(cd2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(cd3), "#4");

            CodeDirectiveCollection coll3 = new CodeDirectiveCollection();

            coll3.Add(cd3);
            coll3.AddRange(new CodeDirective[] { cd1, cd2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(cd1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(cd2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(cd3), "#8");
        }
예제 #4
0
        public void Constructor0()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            Assert.IsFalse(((IList)coll).IsFixedSize, "#1");
            Assert.IsFalse(((IList)coll).IsReadOnly, "#2");
            Assert.AreEqual(0, coll.Count, "#3");
            Assert.IsFalse(((ICollection)coll).IsSynchronized, "#4");
        }
예제 #5
0
        public void Constructor1_NullItem()
        {
            CodeDirective[] directives = new CodeDirective[] {
                new CodeDirective(), null
            };

            CodeDirectiveCollection coll = new CodeDirectiveCollection(
                directives);
        }
예제 #6
0
        public void AddRange_Self()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            coll.Add(new CodeDirective());
            Assert.AreEqual(1, coll.Count, "#1");
            coll.AddRange(coll);
            Assert.AreEqual(2, coll.Count, "#2");
        }
예제 #7
0
 protected override void GenerateDirectives(CodeDirectiveCollection directives)
 {
     foreach (CodeDirective directive in directives)
     {
         var cdr = directive as CodeRegionDirective;
         if (cdr != null)
         {
             Output.WriteLine(cdr.RegionText);
         }
     }
 }
예제 #8
0
        public void Constructor1()
        {
            CodeDirective cd1 = new CodeDirective();
            CodeDirective cd2 = new CodeDirective();

            CodeDirective[]         directives = new CodeDirective[] { cd1, cd2 };
            CodeDirectiveCollection coll       = new CodeDirectiveCollection(
                directives);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cd1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cd2), "#3");
        }
예제 #9
0
        public void Constructor1_Deny_Unrestricted()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(cd), "Add");
            Assert.AreSame(cd, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(cd), "Contains");
            Assert.AreEqual(0, coll.IndexOf(cd), "IndexOf");
            coll.Insert(0, cd);
            coll.Remove(cd);
        }
예제 #10
0
        public void Insert()
        {
            CodeDirective cd1 = new CodeDirective();
            CodeDirective cd2 = new CodeDirective();

            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            coll.Add(cd1);
            Assert.AreEqual(1, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cd1), "#2");
            coll.Insert(0, cd2);
            Assert.AreEqual(2, coll.Count, "#3");
            Assert.AreEqual(1, coll.IndexOf(cd1), "#4");
            Assert.AreEqual(0, coll.IndexOf(cd2), "#5");
        }
예제 #11
0
        public void Constructor2()
        {
            CodeDirective cd1 = new CodeDirective();
            CodeDirective cd2 = new CodeDirective();

            CodeDirectiveCollection c = new CodeDirectiveCollection();

            c.Add(cd1);
            c.Add(cd2);

            CodeDirectiveCollection coll = new CodeDirectiveCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cd1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cd2), "#3");
        }
예제 #12
0
 protected override void GenerateDirectives(CodeDirectiveCollection directives)
 {
     foreach (CodeDirective d in directives)
     {
         var r = d as CodeRegionDirective;
         if (r != null)
         {
             if (r.RegionMode == CodeRegionMode.Start)
             {
                 Output.WriteLine();
                 Output.Write("(region ");
                 Output.Write(r.RegionText);
                 ++Indent;
             }
             else if (r.RegionMode == CodeRegionMode.End)
             {
                 Output.Write(")");
                 --Indent;
             }
         }
     }
 }
	public void AddRange(CodeDirectiveCollection value) {}
예제 #14
0
        public void Remove_NotInCollection()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            coll.Remove(new CodeDirective());
        }
예제 #15
0
        static CodeCompileUnit _ParseCompileUnit(_PC pc)
        {
            var l      = pc.Line;
            var c      = pc.Column;
            var p      = pc.Position;
            var result = new CodeCompileUnit().Mark(l, c, p);
            var ns     = new CodeNamespace().Mark(l, c, p);

            result.Namespaces.Add(ns);
            while (ST.directive == pc.SymbolId || ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)
            {
                switch (pc.SymbolId)
                {
                case ST.directive:
                    var d = _ParseDirective(pc) as CodeDirective;
                    if (null != d)
                    {
                        result.StartDirectives.Add(d);
                    }
                    break;

                case ST.blockComment:
                    ns.Comments.Add(_ParseCommentStatement(pc));
                    break;

                case ST.lineComment:
                    ns.Comments.Add(_ParseCommentStatement(pc, true));
                    break;
                }
            }
            while (ST.usingKeyword == pc.SymbolId)
            {
                while (ST.directive == pc.SymbolId || ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)
                {
                    pc.Advance(false);
                }
                var l2 = pc.Line;
                var c2 = pc.Column;
                var p2 = pc.Position;
                pc.Advance();
                var nsi = new CodeNamespaceImport(_ParseNamespaceName(pc)).SetLoc(l2, c2, p2);
                if (ST.semi != pc.SymbolId)
                {
                    pc.Error("Expecting ; in using declaration");
                }
                pc.Advance(false);
                ns.Imports.Add(nsi);
            }
            while (ST.lbracket == pc.SymbolId)
            {
                var pc2 = pc.GetLookAhead(true);
                pc2.Advance();
                if (ST.assemblyKeyword != pc2.SymbolId)
                {
                    break;
                }
                result.AssemblyCustomAttributes.AddRange(_ParseAttributeGroup(pc, false).Value);
            }
            while (!pc.IsEnded)
            {
                var            startDirs = new CodeDirectiveCollection();
                var            comments  = new CodeCommentStatementCollection();
                CodeLinePragma lp        = null;
                while (ST.directive == pc.SymbolId || ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)
                {
                    switch (pc.SymbolId)
                    {
                    case ST.directive:
                        var d   = _ParseDirective(pc);
                        var llp = d as CodeLinePragma;
                        if (null != llp)
                        {
                            lp = llp;
                        }
                        else if (null != d)
                        {
                            startDirs.Add(d as CodeDirective);
                        }
                        break;

                    case ST.blockComment:
                        comments.Add(_ParseCommentStatement(pc));
                        break;

                    case ST.lineComment:
                        comments.Add(_ParseCommentStatement(pc, true));
                        break;
                    }
                }
                if (ST.namespaceKeyword == pc.SymbolId)
                {
                    var nns = _ParseNamespace(pc);
                    nns.Comments.AddRange(comments);
                    result.Namespaces.Add(nns);
                }
                else
                {
                    var t = _ParseTypeDecl(pc, false, pc.Line, pc.Column, pc.Position, null);
                    t.Comments.AddRange(comments);
                    t.StartDirectives.AddRange(startDirs);
                    t.LinePragma = lp;
                    ns.Types.Add(t);
                }
            }
            return(result);
        }
예제 #16
0
        // CodeDirectiveCollection
        public void CodeDirectiveCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeDirectiveCollection.
            CodeDirectiveCollection collection = new CodeDirectiveCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeDirective to the collection.
            collection.Add(new CodeRegionDirective(CodeRegionMode.Start, "Region1"));
            //</Snippet3>

            //<Snippet4>
            // Adds an array of CodeDirective objects to the collection.
            CodeDirective[] directives =
            {
                new CodeRegionDirective(CodeRegionMode.Start, "Region1"),
                new CodeRegionDirective(CodeRegionMode.End,   "Region1")
            };
            collection.AddRange(directives);

            // Adds a collection of CodeDirective objects to the collection.
            CodeDirectiveCollection directivesCollection = new CodeDirectiveCollection();

            directivesCollection.Add(new CodeRegionDirective(CodeRegionMode.Start, "Region2"));
            directivesCollection.Add(new CodeRegionDirective(CodeRegionMode.End, "Region2"));
            collection.AddRange(directivesCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeDirective in the
            // collection, and retrieves its index if it is found.
            CodeDirective testDirective = new CodeRegionDirective(CodeRegionMode.Start, "Region1");
            int           itemIndex     = -1;

            if (collection.Contains(testDirective))
            {
                itemIndex = collection.IndexOf(testDirective);
            }
            //</Snippet5>

            //<Snippet6>
            // Copies the contents of the collection beginning at index 0 to the specified CodeDirective array.
            // 'directives' is a CodeDirective array.
            collection.CopyTo(directives, 0);
            //</Snippet6>

            //<Snippet7>
            // Retrieves the count of the items in the collection.
            int collectionCount = collection.Count;

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeDirective at index 0 of the collection.
            collection.Insert(0, new CodeRegionDirective(CodeRegionMode.Start, "Region1"));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeDirective from the collection.
            CodeDirective directive = new CodeRegionDirective(CodeRegionMode.Start, "Region1");

            collection.Remove(directive);
            //</Snippet9>

            //<Snippet10>
            // Removes the CodeDirective at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }
예제 #17
0
 protected virtual void GenerateDirectives(CodeDirectiveCollection directives)
 {
 }
	public CodeDirectiveCollection(CodeDirectiveCollection value) {}
예제 #19
0
 public void Constructor1_Null()
 {
     CodeDirectiveCollection coll = new CodeDirectiveCollection(
         (CodeDirective[])null);
 }
예제 #20
0
 protected virtual void GenerateDirectives(CodeDirectiveCollection directives)
 {
 }
예제 #21
0
        public void Add_Null()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            coll.Add((CodeDirective)null);
        }
예제 #22
0
        static CodeStatement _ParseStatement(_PC pc, bool includeComments = false)
        {
            #region Preamble
            CodeLinePragma lp        = null;
            var            startDirs = new CodeDirectiveCollection();
            while (ST.directive == pc.SymbolId)
            {
                var d = _ParseDirective(pc);
                if (null != d)
                {
                    var clp = d as CodeLinePragma;
                    if (null != clp)
                    {
                        lp = clp;
                    }
                    else
                    {
                        startDirs.Add(d as CodeDirective);
                    }
                }
                while (!includeComments && ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)
                {
                    pc.Advance(false);
                }
            }
            CodeStatement stmt = null;
            if (includeComments && (ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId))
            {
                stmt = _ParseCommentStatement(pc);
                stmt.StartDirectives.AddRange(startDirs);
                if (null != lp)
                {
                    stmt.LinePragma = lp;
                }
            }
            else
            {
                while (ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)
                {
                    pc.Advance(false);
                }
            }
            #endregion Preamble
            var l = pc.Line;
            var c = pc.Column;
            var p = pc.Position;
            // if we got here we've parsed our start directives and this isn't a comment statement
            if (null == stmt)
            {
                _PC pc2 = null;
                switch (pc.SymbolId)
                {
                case ST.semi:
                    // can't do much with empty statements
                    pc.Advance();
                    stmt = new CodeSnippetStatement().SetLoc(l, c, p);
                    break;

                case ST.gotoKeyword:
                    pc.Advance();
                    if (ST.identifier != pc.SymbolId)
                    {
                        pc.Error("Expecting label identifier in goto statement");
                    }
                    stmt = new CodeGotoStatement(pc.Value).SetLoc(l, c, p);
                    if (ST.semi != pc.SymbolId)
                    {
                        pc.Error("Expecting ; in goto statement");
                    }
                    pc.Advance();
                    break;

                case ST.returnKeyword:
                    pc.Advance();
                    if (ST.semi != pc.SymbolId)
                    {
                        stmt = new CodeMethodReturnStatement(_ParseExpression(pc)).Mark(l, c, p);
                    }
                    else
                    {
                        stmt = new CodeMethodReturnStatement().SetLoc(l, c, p);
                    }
                    if (ST.semi != pc.SymbolId)
                    {
                        pc.Error("Expecting ; in return statement");
                    }
                    pc.Advance();
                    break;

                case ST.throwKeyword:
                    pc.Advance();
                    var expr = _ParseExpression(pc);
                    stmt = new CodeThrowExceptionStatement(expr).Mark(l, c, p);
                    if (ST.semi != pc.SymbolId)
                    {
                        pc.Error("Expecting ; in throw statement");
                    }
                    pc.Advance();
                    break;

                case ST.ifKeyword:
                    stmt = _ParseIfStatement(pc);
                    break;

                case ST.whileKeyword:
                    stmt = _ParseWhileStatement(pc);
                    break;

                case ST.forKeyword:
                    stmt = _ParseForStatement(pc);
                    break;

                case ST.tryKeyword:
                    stmt = _ParseTryCatchFinallyStatement(pc);
                    break;

                case ST.varType:
                    stmt = _ParseVariableDeclarationStatement(pc);
                    break;

                default:
                    // possibly a var decl, a label statement, or an expression statement
                    if (ST.identifier == pc.SymbolId)
                    {
                        pc2 = pc.GetLookAhead(true);
                        pc2.Advance();
                        if (ST.colon == pc2.SymbolId)                                 // label
                        {
                            var lbl = pc2.Value;
                            pc.Advance();
                            stmt = new CodeLabeledStatement(lbl, new CodeSnippetStatement().SetLoc(l, c, p)).SetLoc(l, c, p);
                            pc2  = null;
                            break;
                        }
                    }
                    pc2 = null;
                    pc2 = pc.GetLookAhead(true);
                    pc2.ResetAdvanceCount();
                    var advc = 0;
                    try
                    {
                        // possibly a var decl
                        stmt = _ParseVariableDeclarationStatement(pc2);
                        advc = pc2.AdvanceCount;
                        while (advc > 0)
                        {
                            pc.Advance(false);
                            --advc;
                        }
                        break;
                    }
                    catch (SlangSyntaxException sx)
                    {
                        try
                        {
                            pc.ResetAdvanceCount();
                            expr = _ParseExpression(pc);
                            if (ST.semi != pc.SymbolId)
                            {
                                pc.Error("Expecting ; in expression statement");
                            }
                            pc.Advance();
                            var bo = expr as CodeBinaryOperatorExpression;
                            if (null != bo && CodeBinaryOperatorType.Assign == bo.Operator)
                            {
                                var ur = bo.UserData.Contains("slang:unresolved");
                                stmt = new CodeAssignStatement(bo.Left, bo.Right).Mark(l, c, p, ur);
                            }
                            else
                            {
                                stmt = new CodeExpressionStatement(expr).Mark(l, c, p);
                            }
                            break;
                        }
                        catch (SlangSyntaxException sx2)
                        {
                            if (pc.AdvanceCount > advc)
                            {
                                throw sx2;
                            }
                            throw sx;
                        }
                    }
                }
            }
            #region Post
            stmt.StartDirectives.AddRange(startDirs);
            if (null != lp)
            {
                stmt.LinePragma = lp;
            }

            while (!includeComments && ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)
            {
                pc.Advance(false);
            }
            while (ST.directive == pc.SymbolId && pc.Value.StartsWith("#end", StringComparison.InvariantCulture))
            {
                stmt.EndDirectives.Add(_ParseDirective(pc) as CodeDirective);
                while (!includeComments && ST.lineComment == pc.SymbolId || ST.blockComment == pc.SymbolId)
                {
                    pc.Advance(false);
                }
            }
            #endregion Post
            return(stmt);
        }
예제 #23
0
        public void Insert_Null()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            coll.Insert(0, (CodeDirective)null);
        }
예제 #24
0
        public void Remove_Null()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            coll.Remove((CodeDirective)null);
        }
예제 #25
0
 private static void ValidateCodeDirectives(CodeDirectiveCollection e)
 {
     for (int i = 0; i < e.Count; i++)
         ValidateCodeDirective(e[i]);
 }
예제 #26
0
 public void AddRange(CodeDirectiveCollection value)
 {
 }
예제 #27
0
        public void AddRange_Null_Collection()
        {
            CodeDirectiveCollection coll = new CodeDirectiveCollection();

            coll.AddRange((CodeDirectiveCollection)null);
        }
예제 #28
0
 public CodeDirectiveCollection(CodeDirectiveCollection value)
 {
 }
예제 #29
0
 protected virtual void GenerateDirectives(CodeDirectiveCollection directives)
 {
     throw new NotImplementedException();
 }