示例#1
0
        public static SourceObject Compute(
            Compiler compiler,
            Source src,
            AmbientParser.IUnoCodeReader codeReader,
            AmbientParser.ParseResult parseResult,
            out int rangeStart,
            out int rangeLength,
            out string memberExp)
        {
            var cc = new CodeCompleter.CodeCompleter(compiler, src, codeReader, codeReader.Offset, parseResult);

            return(Compute(src, codeReader, cc, out rangeStart, out rangeLength, out memberExp));
        }
示例#2
0
        public static void Suggest(Uno.Compiler.Core.Compiler compiler, AmbientParser.ParseResult parseResult, IUnoCodeReader codeReader, Source src, List <Function> pinfo, out int highlightArgument, out int range, out IEnumerable <string> usings)
        {
            highlightArgument = 0;
            range             = 0;

            usings = new List <string>();

            try
            {
                // Scan backwards to find function argument list start
                var caret = codeReader.Offset;
                FindArgListStart(codeReader, out highlightArgument);
                range = caret - codeReader.Offset;


                TokenType tt;
                var       cc = new CodeCompleter.CodeCompleter(compiler, src, codeReader, caret, parseResult);

                var memberExp = cc.FindMemberExpression(out tt, false, false);

                if (tt == TokenType.Import)
                {
                    memberExp += "Importer";
                }
                else if (memberExp == "sample")
                {
                    pinfo.Add(new Method(src, null, null, 0, "sample", compiler.ILFactory.Essentials.Float4, new[]
                    {
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Texture2D, "texture", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Float2, "texCoord", null),
                    }, null));

                    pinfo.Add(new Method(src, null, null, 0, "sample", compiler.ILFactory.Essentials.Float4, new[]
                    {
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Texture2D, "texture", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Float2, "texCoord", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.SamplerState, "samplerState", null),
                    }, null));

                    pinfo.Add(new Method(src, null, null, 0, "sample", compiler.ILFactory.Essentials.Float4, new[]
                    {
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.TextureCube, "texture", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Float3, "texCoord", null),
                    }, null));

                    pinfo.Add(new Method(src, null, null, 0, "sample", compiler.ILFactory.Essentials.Float4, new[]
                    {
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.TextureCube, "texture", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Float3, "texCoord", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.SamplerState, "samplerState", null),
                    }, null));
                }
                else if (memberExp == "vertex_attrib")
                {
                    var gpt         = new GenericParameterType(src, compiler.ILFactory.Essentials.Object, "T");
                    var gptarray    = compiler.TypeBuilder.GetArray(gpt);
                    var ushortArray = compiler.TypeBuilder.GetArray(compiler.ILFactory.Essentials.UShort);

                    pinfo.Add(new Method(src, null, null, 0, "vertex_attrib", gpt, new[]
                    {
                        new Parameter(src, null, 0, gptarray, "vertexArray", null)
                    }, null));

                    pinfo.Add(new Method(src, null, null, 0, "vertex_attrib", gpt, new[]
                    {
                        new Parameter(src, null, 0, gptarray, "vertexArray", null),
                        new Parameter(src, null, 0, ushortArray, "indexArray", null),
                    }, null));

                    pinfo.Add(new Method(src, null, null, 0, "vertex_attrib<T>", gpt, new[]
                    {
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.VertexAttributeType, "vertexAttributeType", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.VertexBuffer, "vertexBuffer", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Int, "stride", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Int, "offset", null),
                    }, null));

                    pinfo.Add(new Method(src, null, null, 0, "vertex_attrib<T>", gpt, new[]
                    {
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.VertexAttributeType, "vertexAttributeType", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.VertexBuffer, "vertexBuffer", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Int, "stride", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.Int, "offset", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.IndexType, "indexType", null),
                        new Parameter(src, null, 0, compiler.ILFactory.Essentials.IndexBuffer, "indexBuffer", null),
                    }, null));
                }

                usings = cc.Context.Usings;

                if (cc.Context.NodePath == null || cc.Context.NodePath.Count == 0)
                {
                    return;
                }

                var pe = cc.ResolveStringInFunctionContext(cc.Context.NodePath.LastOrDefault(x => AmbientParser.NodeTypeHelpers.IsMethodNode(x.Type)), memberExp, src);



                if (pe != null)
                {
                    DataType dt         = null;
                    string   methodName = null;

                    if (pe.ExpressionType == PartialExpressionType.MethodGroup)
                    {
                        var mg = pe as PartialMethodGroup;

                        if (mg.Object != null)
                        {
                            dt = mg.Object.ReturnType;
                        }
                        else
                        {
                            dt = mg.Methods[0].DeclaringType;
                        }

                        methodName = mg.Methods[0].Name;
                    }
                    else if (pe.ExpressionType == PartialExpressionType.Type)
                    {
                        var pdt = pe as PartialType;

                        foreach (var c in pdt.Type.Constructors)
                        {
                            pinfo.Add(c);
                        }
                        return;
                    }

                    var hidden = new HashSet <Method>();

                    while (dt != null)
                    {
                        foreach (var m in dt.Methods)
                        {
                            if (!hidden.Contains(m))
                            {
                                if (m.Name == methodName)
                                {
                                    pinfo.Add(m);
                                }
                            }
                            if (m.OverriddenMethod != null)
                            {
                                hidden.Add(m.OverriddenMethod);
                            }
                        }

                        dt = dt.Base;
                    }
                }
            }
            catch (Exception) {  }
        }
示例#3
0
 public static SourceObject TryGetSourceObject(Compiler compiler, Source src, AmbientParser.IUnoCodeReader codeReader, AmbientParser.ParseResult parseResult)
 {
     try
     {
         int    start, length;
         string memberExp;
         return(Compute(compiler, src, codeReader, parseResult, out start, out length, out memberExp));
     }
     catch (MaxErrorException)
     {
         return(null);
     }
 }