Пример #1
0
 private void TestParseVariableDeclarationInternal(Func <string, NativeXVariableDeclaration> parser)
 {
     Action <NativeXVariableDeclaration> vd_common = d =>
     {
         Assert.AreEqual("a", d.Name);
         NativeXInstanciatedType t = (NativeXInstanciatedType)d.Type;
         Assert.AreEqual("List", t.ElementType.ReferencedName);
         Assert.AreEqual(1, t.GenericArguments.Count);
         Assert.AreEqual("int", ((NativeXReferenceType)t.GenericArguments[0]).ReferencedName);
     };
     Action <NativeXVariableDeclaration> vd1 = d =>
     {
         Assert.IsNull(d.Initializer);
         Assert.IsNull(d.Linking);
     };
     Action <NativeXVariableDeclaration> vd2 = d =>
     {
         Assert.IsNull(d.Initializer);
         Assert.AreEqual("Utility", d.Linking.LinkingAssembly);
         Assert.AreEqual("Sum", d.Linking.LinkingSymbol);
     };
     Action <NativeXVariableDeclaration> vd3 = d =>
     {
         Assert.IsNull(d.Linking);
         NativeXBinaryExpression e = (NativeXBinaryExpression)d.Initializer;
         Assert.AreEqual("1", ((NativeXPrimitiveExpression)e.LeftOperand).Code);
         Assert.AreEqual("2", ((NativeXPrimitiveExpression)e.RightOperand).Code);
     };
     string d1 = "variable List<int> a;";
     string d2 = "variable List<int> a alias Utility.Sum;";
     string d3 = "variable List<int> a = 1+2;";
     {
         NativeXVariableDeclaration d = parser(d1);
         vd_common(d);
         vd1(d);
     }
     {
         NativeXVariableDeclaration d = parser(d2);
         vd_common(d);
         vd2(d);
     }
     {
         NativeXVariableDeclaration d = parser(d3);
         vd_common(d);
         vd3(d);
     }
     {
         NativeXVariableDeclaration d = parser(g1 + d1);
         vg1(d);
         vd_common(d);
         vd1(d);
     }
     {
         NativeXVariableDeclaration d = parser(g2 + d2);
         vg2(d);
         vd_common(d);
         vd2(d);
     }
     {
         NativeXVariableDeclaration d = parser(g3 + d3);
         vg3(d);
         vd_common(d);
         vd3(d);
     }
 }
Пример #2
0
        protected IEnumerable <TextEditorPopupItem> CreatePopupExpressions(CodeScope scope)
        {
            Bitmap functionImage             = null;
            Bitmap memberImage               = null;
            Bitmap templateImage             = null;
            Bitmap parameterImage            = null;
            List <TextEditorPopupItem> items = new List <TextEditorPopupItem>();

            foreach (CodeNode node in scope.FindAllDistinct())
            {
                {
                    NativeXNameTypePair parameter = node as NativeXNameTypePair;
                    if (parameter != null && parameter.Name != null)
                    {
                        items.Add(new TextEditorPopupItem()
                        {
                            Text  = parameter.Name,
                            Image = (parameterImage ?? (parameterImage = Images.Parameter))
                        });
                    }
                }
                {
                    NativeXVariableStatement varstat = node as NativeXVariableStatement;
                    if (varstat != null && varstat.Name != null)
                    {
                        items.Add(new TextEditorPopupItem()
                        {
                            Text  = varstat.Name,
                            Image = (memberImage ?? (memberImage = Images.Member))
                        });
                    }
                }
                {
                    NativeXVariableDeclaration vardecl = node as NativeXVariableDeclaration;
                    if (vardecl != null && vardecl.Name != null)
                    {
                        items.Add(new TextEditorPopupItem()
                        {
                            Text  = vardecl.Name,
                            Image = (memberImage ?? (memberImage = Images.Member))
                        });
                    }
                }
                {
                    NativeXFunctionDeclaration funcdecl = node as NativeXFunctionDeclaration;
                    if (funcdecl != null && funcdecl.Name != null)
                    {
                        items.Add(new TextEditorPopupItem()
                        {
                            Text  = funcdecl.Name,
                            Image = (functionImage ?? (functionImage = Images.Function))
                        });
                    }
                }
                {
                    NativeXConceptDeclaration conceptdecl = node as NativeXConceptDeclaration;
                    if (conceptdecl != null && conceptdecl.Name != null)
                    {
                        items.Add(new TextEditorPopupItem()
                        {
                            Text  = conceptdecl.Name,
                            Image = (templateImage ?? (templateImage = Images.Template))
                        });
                    }
                }
            }

            Bitmap keywordImage = Images.Keyword;

            string[] keywords = new string[] { "result", "cast", "exception", "true", "false", "null", "sizeof", "offsetof" };
            items.AddRange(
                keywords.Select(k => new TextEditorPopupItem()
            {
                Text  = k,
                Image = keywordImage
            }));
            return(items);
        }