示例#1
0
        private void TestParseFunctionDeclarationInternal(Func <string, NativeXFunctionDeclaration> parser)
        {
            Action <NativeXFunctionDeclaration> vd_common = d =>
            {
                Assert.AreEqual("Sum", d.Name);
                Assert.AreEqual("int", ((NativeXReferenceType)d.ReturnType).ReferencedName);
                Assert.AreEqual(2, d.Parameters.Count);
                Assert.AreEqual("int", ((NativeXReferenceType)((NativeXPointerType)d.Parameters[0].Type).ElementType).ReferencedName);
                Assert.AreEqual("numbers", d.Parameters[0].Name);
                Assert.AreEqual("int", ((NativeXReferenceType)d.Parameters[1].Type).ReferencedName);
                Assert.AreEqual("count", d.Parameters[1].Name);
            };
            Action <NativeXFunctionDeclaration> vd1 = d =>
            {
                Assert.IsFalse(d.Foreign);
                Assert.IsNull(d.Linking);

                NativeXCompositeStatement s = (NativeXCompositeStatement)d.Statement;
                Assert.AreEqual(1, s.Statements.Count);
                NativeXBinaryExpression e = (NativeXBinaryExpression)((NativeXExpressionStatement)s.Statements[0]).Expression;
                Assert.IsNotNull((NativeXFunctionResultExpression)e.LeftOperand);
                Assert.AreEqual("0", ((NativeXPrimitiveExpression)e.RightOperand).Code);
            };
            Action <NativeXFunctionDeclaration> vd2 = d =>
            {
                Assert.IsFalse(d.Foreign);
                Assert.IsNull(d.Statement);
                Assert.AreEqual("Utility", d.Linking.LinkingAssembly);
                Assert.AreEqual("Sum", d.Linking.LinkingSymbol);
            };
            Action <NativeXFunctionDeclaration> vd3 = d =>
            {
                Assert.IsTrue(d.Foreign);
                Assert.IsNull(d.Linking);
                Assert.IsNull(d.Statement);
            };
            string d1 = "function int Sum(int* numbers, int count){result = 0;}";
            string d2 = "function int Sum(int* numbers, int count) alias Utility.Sum;";
            string d3 = "foreign function int Sum(int* numbers, int count);";
            {
                NativeXFunctionDeclaration d = parser(d1);
                vd_common(d);
                vd1(d);
            }
            {
                NativeXFunctionDeclaration d = parser(d2);
                vd_common(d);
                vd2(d);
            }
            {
                NativeXFunctionDeclaration d = parser(d3);
                vd_common(d);
                vd3(d);
            }
            {
                NativeXFunctionDeclaration d = parser(g1 + d1);
                vg1(d);
                vd_common(d);
                vd1(d);
            }
            {
                NativeXFunctionDeclaration d = parser(g2 + d2);
                vg2(d);
                vd_common(d);
                vd2(d);
            }
            {
                NativeXFunctionDeclaration d = parser(g3 + d3);
                vg3(d);
                vd_common(d);
                vd3(d);
            }
        }
        public virtual string OnGetSimpleTooltip(TextPosition pos)
        {
            if (this.EditingObserverExtension.AnalyzingResult == null || this.EditingObserverExtension.AnalyzingResult.Unit == null)
            {
                return(null);
            }
            NativeXNode node = this.EditingObserverExtension.AnalyzingResult.Unit.FindDeepest <NativeXNode>(pos);
            NativeXNode hint = null;

            {
                NativeXReferenceExpression exp = node as NativeXReferenceExpression;
                if (exp != null && exp.Scope != null)
                {
                    hint = (NativeXNode)exp.Scope.Find(exp.ReferencedName);
                    goto SHOW_HINT;
                }
            }
            {
                NativeXReferenceType type = node as NativeXReferenceType;
                if (type != null && type.Scope != null)
                {
                    hint = (NativeXNode)type.Scope.Find(type.ReferencedName);
                    goto SHOW_HINT;
                }
            }
            {
                NativeXConceptReference concept = node as NativeXConceptReference;
                if (concept != null && concept.Scope != null)
                {
                    hint = (NativeXNode)concept.Scope.Find(concept.ReferenceName);
                    goto SHOW_HINT;
                }
            }
            {
                NativeXInstanciatedExpression exp = node as NativeXInstanciatedExpression;
                if (exp != null && exp.Scope != null)
                {
                    hint = (NativeXNode)exp.Scope.Find(exp.ReferencedName);
                    goto SHOW_HINT;
                }
            }
            {
                NativeXInstanceFunctionExpression exp = node as NativeXInstanceFunctionExpression;
                if (exp != null && exp.Scope != null && exp.ConceptName != null)
                {
                    hint = (NativeXNode)exp.Scope.Find(exp.ConceptName.ReferenceName);
                    goto SHOW_HINT;
                }
            }
            {
                NativeXInstanceDeclaration inst = node as NativeXInstanceDeclaration;
                if (inst != null && inst.Scope != null && inst.ConceptName != null)
                {
                    if (this.EditingObserverExtension.AnalyzingResult.IdTokens.ContainsKey(pos.row))
                    {
                        CodeToken token = this.EditingObserverExtension.AnalyzingResult.IdTokens[pos.row].Where(t => t.Start <= pos && pos <= t.End).FirstOrDefault();
                        if (token.Value == inst.ConceptName.ReferenceName)
                        {
                            hint = (NativeXNode)inst.Scope.Find(inst.ConceptName.ReferenceName);
                        }
                    }
                }
            }
            {
                NativeXGenericConstraint genecons = node as NativeXGenericConstraint;
                if (genecons != null && genecons.Scope != null && genecons.ConceptName != null)
                {
                    if (this.EditingObserverExtension.AnalyzingResult.IdTokens.ContainsKey(pos.row))
                    {
                        CodeToken token = this.EditingObserverExtension.AnalyzingResult.IdTokens[pos.row].Where(t => t.Start <= pos && pos <= t.End).FirstOrDefault();
                        if (token.Value == genecons.ConceptName.ReferenceName)
                        {
                            hint = (NativeXNode)genecons.Scope.Find(genecons.ConceptName.ReferenceName);
                        }
                    }
                }
            }
SHOW_HINT:
            if (hint != null)
            {
                NativeXFunctionDeclaration function = hint as NativeXFunctionDeclaration;
                TextPosition start, end;
                if (function == null)
                {
                    start = hint.Start;
                    end   = hint.End;
                }
                else
                {
                    start = hint.Start;
                    end   = function.Statement == null ? function.End : function.Statement.Start;
                }
                if (start < end)
                {
                    start = this.Callback.TextEditorBox.Controller.Normalize(start);
                    end   = this.Callback.TextEditorBox.Controller.Normalize(end);
                    string text = this.Callback.TextEditorBox.TextProvider.GetString(start, end);
                    if (!string.IsNullOrWhiteSpace(text))
                    {
                        return(text);
                    }
                }
            }
            return(null);
        }
示例#3
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);
        }