예제 #1
0
        public void Test1()
        {
            var pcl  = ResolutionTests.CreateCache(@"module modA;

class A(T = int)
{
	static int prop;
	static A statA; // 6
}

A a = new A(); // 9

void main()
{
	A.prop = 3; // 13
	int b = A.prop + 4; // 14
	A.statA.statA = new A!float(); // 15
}
");
            var ctxt = ResolutionContext.Create(pcl, null, pcl[0]["modA"]);

            var refs = ReferencesFinder.Scan(pcl[0]["modA"]["A"].First(), ctxt) as List <ISyntaxRegion>;

            Assert.IsNotNull(refs);
            Assert.AreEqual(8, refs.Count);
        }
예제 #2
0
        protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
        {
            ed   = Editor;
            ctxt = ResolutionContext.Create(Editor, false);

            AbstractType t = null;

            CodeCompletion.DoTimeoutableCompletionTask(CompletionDataGenerator, ctxt, () =>
            {
                ctxt.Push(Editor);
                if (AccessExpression is IExpression)
                {
                    t = ExpressionTypeEvaluation.EvaluateType(AccessExpression as IExpression, ctxt);
                }
                else if (AccessExpression is ITypeDeclaration)
                {
                    t = TypeDeclarationResolver.ResolveSingle(AccessExpression as ITypeDeclaration, ctxt);
                }
            });

            if (t == null)             //TODO: Add after-space list creation when an unbound . (Dot) was entered which means to access the global scope
            {
                return;
            }

            t.Accept(this);
        }
예제 #3
0
        protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
        {
            var dc = begunNode.Parent as DClassLike;

            if (dc == null || dc.ClassType != DTokens.Class)
            {
                return;
            }

            var classType = DResolver.ResolveClassOrInterface(dc, ResolutionContext.Create(Editor), null) as TemplateIntermediateType;

            if (classType == null)
            {
                return;
            }

            var typesToScan = new List <TemplateIntermediateType>();

            IterateThroughBaseClassesInterfaces(typesToScan, classType);

            foreach (var t in typesToScan)
            {
                foreach (var n in t.Definition)
                {
                    var dm = n as DMethod;
                    if (dm == null ||
                        dm.ContainsAttribute(DTokens.Final, DTokens.Private, DTokens.Static))
                    {
                        continue;                         //TODO: Other attributes?
                    }
                    CompletionDataGenerator.AddCodeGeneratingNodeItem(dm, GenerateOverridingMethodStub(dm, begunNode, !(t is InterfaceType)));
                }
            }
        }
예제 #4
0
        public static AbstractType[] ResolveHoveredCode(out ResolutionContext ResolverContext, IEditorData edData)
        {
            ResolverContext = ResolutionContext.Create(edData, false);

            // Resolve the hovered piece of code
            return(AmbiguousType.TryDissolve(DResolver.ResolveType(edData, ctxt: ResolverContext)).ToArray());
        }
예제 #5
0
        protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
        {
            var ctxt             = ResolutionContext.Create(Editor, true);
            var resolvedVariable = TypeDeclarationResolver.HandleNodeMatch(initedVar, ctxt) as DSymbol;

            if (resolvedVariable == null)
            {
                return;
            }

            while (resolvedVariable is TemplateParameterSymbol)
            {
                resolvedVariable = resolvedVariable.Base as DSymbol;
            }

            var structType = resolvedVariable.Base as TemplateIntermediateType;

            if (structType == null)
            {
                return;
            }

            var alreadyTakenNames = new List <int>();

            foreach (var m in init.MemberInitializers)
            {
                alreadyTakenNames.Add(m.MemberNameHash);
            }

            new StructVis(structType, alreadyTakenNames, CompletionDataGenerator, ctxt);
        }
예제 #6
0
        public void TestAccessExpression()
        {
            var pcl = ResolutionTests.CreateCache(@"module modA;

class A
{
	const int someProp=3;
}

A a;");

            var vp = new StandardValueProvider(ResolutionContext.Create(pcl, null, pcl[0]["modA"]));

            /*
             * var v = E("a.someProp", vp);
             * Assert.IsInstanceOfType(v, typeof(PrimitiveValue));
             * Assert.AreEqual(((PrimitiveValue)v).Value,3);
             */
            var v = E("A.someProp", vp);

            Assert.IsInstanceOfType(typeof(VariableValue), v);
            var vv = vp[((VariableValue)v).Variable] as PrimitiveValue;

            Assert.AreEqual(3, vv.Value);
        }
예제 #7
0
        protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
        {
            var ctxt = ResolutionContext.Create(Editor, false);

            foreach (var kv in VersionCompletionItems)
            {
                CompletionDataGenerator.AddTextItem(kv.Key, kv.Value);
            }

            CodeCompletion.DoTimeoutableCompletionTask(CompletionDataGenerator, ctxt, () => {
                ctxt.Push(Editor);
                var cs = ctxt.CurrentContext.DeclarationCondititons;
                foreach (var v in cs.GlobalFlags.Versions)
                {
                    if (!VersionCompletionItems.ContainsKey(v))
                    {
                        CompletionDataGenerator.AddTextItem(v, "");
                    }
                }
                foreach (var v in cs.LocalFlags.Versions)
                {
                    if (!VersionCompletionItems.ContainsKey(v))
                    {
                        CompletionDataGenerator.AddTextItem(v, "");
                    }
                }
            });
        }
예제 #8
0
        public void ClassInheritanceTest()
        {
            var pcl  = ResolutionTests.CreateCache(@"module modA;
				class A{}
				class B:A {}
				class C:A {}
				class D:C {}"                );
            var ctxt = ResolutionContext.Create(pcl, null, pcl[0]["modA"]);

            var A = GetType("A", ctxt);
            var B = GetType("B", ctxt);
            var C = GetType("C", ctxt);
            var D = GetType("D", ctxt);

            Assert.IsTrue(ResultComparer.IsEqual(A, A));
            Assert.IsTrue(ResultComparer.IsEqual(B, B));
            Assert.IsTrue(ResultComparer.IsEqual(C, C));
            Assert.IsTrue(ResultComparer.IsEqual(D, D));

            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(A, B));
            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(A, C));
            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(A, D));

            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(B, C));
            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(C, B));

            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(A, A));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(B, A));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(C, A));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(D, C));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(D, A));
        }
예제 #9
0
        public static AbstractType[] ResolveType(IEditorData editor, AstReparseOptions Options = AstReparseOptions.AlsoParseBeyondCaret, ResolutionContext ctxt = null)
        {
            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor);
            }

            var o = GetScopedCodeObject(editor, Options, ctxt);

            var optionBackup = ctxt.CurrentContext.ContextDependentOptions;

            ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;

            AbstractType[] ret;

            if (o is IExpression)
            {
                ret = Evaluation.EvaluateTypes((IExpression)o, ctxt);
            }
            else if (o is ITypeDeclaration)
            {
                ret = TypeDeclarationResolver.Resolve((ITypeDeclaration)o, ctxt);
            }
            else
            {
                ret = null;
            }

            ctxt.CurrentContext.ContextDependentOptions = optionBackup;

            return(ret);
        }
예제 #10
0
        void FindDerivedClassesThread(object s)
        {
            var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true);

            monitor.BeginStepTask(GettextCatalog.GetString("Find Derived Classes"), lastResults.Length, 1);

            var ctxt = ResolutionContext.Create(ed, true);

            foreach (var t in lastResults)
            {
                var t_ = DResolver.StripMemberSymbols(t);
                if (!(t_ is ClassType || t_ is InterfaceType))
                {
                    monitor.Step(1);
                    continue;
                }

                foreach (var res in ClassInterfaceDerivativeFinder.SearchForClassDerivatives(t_ as TemplateIntermediateType, ctxt))
                {
                    var dc        = res.Definition;
                    var file      = (dc.NodeRoot as DModule).FileName;
                    var targetDoc = TextFileProvider.Instance.GetTextEditorData(new FilePath(file));

                    monitor.ReportResult(new SearchResult(new FileProvider(file, IdeApp.Workspace.GetProjectsContainingFile(file).FirstOrDefault()),
                                                          targetDoc.LocationToOffset(dc.NameLocation.Line, dc.NameLocation.Column), dc.Name.Length));
                }
                monitor.Step(1);
            }

            monitor.EndTask();
            monitor.Dispose();
        }
        protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
        {
            if (Editor.ParseCache == null)
            {
                return;
            }

            var module = Editor.ParseCache.LookupModuleName(import.ModuleIdentifier.ToString(true)).FirstOrDefault();

            if (module == null)
            {
                return;
            }

            var ctxt = ResolutionContext.Create(Editor, true);

            /*
             * Show all members of the imported module
             * + public imports
             * + items of anonymous enums
             */

            MemberCompletionEnumeration.EnumChildren(CompletionDataGenerator, ctxt, module, true, MemberFilter.All, true);

            return;
        }
예제 #12
0
        public void TryPreResolveCommonTypes()
        {
            var obj = GetModule("object");

            if (obj == null)
            {
                return;
            }

            ParseCacheView cache = null;

            foreach (var m in obj)
            {
                if (m.Name == "Object" && m is DClassLike)
                {
                    ObjectClassResult = new ClassType(ObjectClass = (DClassLike)m, new IdentifierDeclaration("Object"), null);
                    break;
                }
                else if (m.Name == "size_t")
                {
                    if (cache == null)
                    {
                        cache = new ParseCacheView(new[] { this });
                    }
                    //TODO: Do a version check, so that only on x64 dmd installations, size_t equals ulong.
                    SizeT = TypeDeclarationResolver.HandleNodeMatch(m,
                                                                    ResolutionContext.Create(cache, null, obj));
                }
            }
        }
예제 #13
0
        protected override string Process(EditorData editorData, bool moduleOnly)
        {
            var sr = DResolver.GetScopedCodeObject(editorData);
            var rr = sr != null?LooseResolution.ResolveTypeLoosely(editorData, sr, out _, true) : null;

            var refs = new StringBuilder();

            if (rr != null)
            {
                var n = ExpressionTypeEvaluation.GetResultMember(rr);

                if (n != null)
                {
                    var ctxt = ResolutionContext.Create(editorData, true);
                    if (moduleOnly || n.ContainsAnyAttribute(DTokens.Private) || (n is DVariable variable && variable.IsLocal))
                    {
                        GetReferencesInModule(editorData.SyntaxTree, refs, n, ctxt);
                    }
                    else
                    {
                        foreach (var rootPackage in editorData.ParseCache.EnumRootPackagesSurroundingModule(editorData.SyntaxTree))
                        {
                            foreach (var module in rootPackage)
                            {
                                GetReferencesInModule(module, refs, n, ctxt);
                            }
                        }
                    }
                }

                //var res = TypeReferenceFinder.Scan(_editorData, System.Threading.CancellationToken.None, null);
            }
예제 #14
0
        public static AbstractType[] ResolveTypeLoosely(IEditorData editor, out NodeResolutionAttempt resolutionAttempt, ResolutionContext ctxt = null)
        {
            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor);
            }

            var o = GetScopedCodeObject(editor, ctxt: ctxt);

            var optionBackup = ctxt.CurrentContext.ContextDependentOptions;

            ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;
            resolutionAttempt = NodeResolutionAttempt.Normal;

            AbstractType[] ret;

            if (o is IExpression)
            {
                ret = Evaluation.EvaluateTypes((IExpression)o, ctxt);
            }
            else if (o is ITypeDeclaration)
            {
                ret = TypeDeclarationResolver.Resolve((ITypeDeclaration)o, ctxt);
            }
            else
            {
                ret = null;
            }

            if (ret == null)
            {
                resolutionAttempt = NodeResolutionAttempt.NoParameterOrTemplateDeduction;

                if (o is PostfixExpression_MethodCall)
                {
                    o = (o as PostfixExpression_MethodCall).PostfixForeExpression;
                }

                if (o is IdentifierExpression)
                {
                    ret = Evaluation.GetOverloads(o as IdentifierExpression, ctxt, false);
                }
                else if (o is ITypeDeclaration)
                {
                    ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.NoTemplateParameterDeduction;
                    ret = TypeDeclarationResolver.Resolve(o as ITypeDeclaration, ctxt);
                }
            }

            if (ret == null)
            {
                resolutionAttempt = NodeResolutionAttempt.RawSymbolLookup;
                ret = TypeDeclarationResolver.HandleNodeMatches(LookupIdRawly(editor, o as ISyntaxRegion), ctxt);
            }

            ctxt.CurrentContext.ContextDependentOptions = optionBackup;
            return(ret);
        }
예제 #15
0
        public void GetReferences(string filename, string tok, uint line, uint idx, string expr)
        {
            filename = normalizePath(filename);
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

            _request = Request.References;
            _result  = "__pending__";

            Action dg = () =>
            {
                _setupEditorData();
                CodeLocation loc = new CodeLocation((int)idx + 1, (int)line);
                _editorData.CaretLocation = loc;
                _editorData.SyntaxTree    = ast as DModule;
                _editorData.ModuleCode    = _sources[filename];
                _editorData.CaretOffset   = getCodeOffset(_editorData.ModuleCode, loc);

                ISyntaxRegion sr = DResolver.GetScopedCodeObject(_editorData);
                LooseResolution.NodeResolutionAttempt attempt;
                var rr = sr != null?LooseResolution.ResolveTypeLoosely(_editorData, sr, out attempt, true) : null;

                StringBuilder refs = new StringBuilder();
                if (rr != null)
                {
                    var n = DResolver.GetResultMember(rr, true);

                    if (n != null)
                    {
                        var ctxt = ResolutionContext.Create(_editorData, true);
                        if (n.ContainsAttribute(DTokens.Private) || ((n is DVariable) && (n as DVariable).IsLocal))
                        {
                            GetReferencesInModule(ast, refs, n, ctxt);
                        }
                        else
                        {
                            foreach (var basePath in _imports.Split(nlSeparator, StringSplitOptions.RemoveEmptyEntries))
                            {
                                foreach (var mod in GlobalParseCache.EnumModulesRecursively(basePath))
                                {
                                    GetReferencesInModule(mod, refs, n, ctxt);
                                }
                            }
                        }
                    }
                    //var res = TypeReferenceFinder.Scan(_editorData, System.Threading.CancellationToken.None, null);
                }
                if (!_editorData.CancelToken.IsCancellationRequested && _request == Request.References)
                {
                    _result = refs.ToString();
                }
            };
        }
예제 #16
0
        public void InterfaceInheritanceTest()
        {
            var pcl  = ResolutionTests.CreateCache(@"module modA;
				class A {}
				class B {}

				interface IA {}
				interface IB {}

				interface IC : IA {}
				interface ID : IC {}

				class E : A, IA {}
				class F : B, IA {}

				class G : A, IC {}
				class H : B, ID {}"                );
            var ctxt = ResolutionContext.Create(pcl, null, pcl[0]["modA"]);

            var A  = GetType("A", ctxt);
            var B  = GetType("B", ctxt);
            var IA = GetType("IA", ctxt);
            var IB = GetType("IB", ctxt);
            var IC = GetType("IC", ctxt);
            var ID = GetType("ID", ctxt);
            var E  = GetType("E", ctxt);
            var F  = GetType("F", ctxt);
            var G  = GetType("G", ctxt);
            var H  = GetType("H", ctxt);

            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(IC, IA));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(ID, IC));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(ID, IA));

            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(IA, IC));
            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(IA, ID));
            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(IC, IB));

            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(E, A));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(E, IA));

            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(E, F));
            Assert.IsFalse(ResultComparer.IsImplicitlyConvertible(F, E));

            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(F, B));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(F, IA));

            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(G, A));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(G, IC));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(G, IA));

            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(H, B));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(H, ID));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(H, IC));
            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(H, IA));
        }
예제 #17
0
        public static AbstractType[] ResolveHoveredCode(
            out ResolutionContext ResolverContext,
            MonoDevelop.Ide.Gui.Document doc = null)
        {
            var edData = CreateEditorData(doc);

            ResolverContext = ResolutionContext.Create(edData);

            // Resolve the hovered piece of code
            return(DResolver.ResolveType(edData, ResolverContext, DResolver.AstReparseOptions.AlsoParseBeyondCaret));
        }
예제 #18
0
        void _th(object pcl_shared)
        {
            var ctxt = ResolutionContext.Create((ParseCacheView)pcl_shared, gFlags_shared, ast);

            // Make it as most performing as possible by avoiding unnecessary base types.
            // Aliases should be analyzed deeper though.
            ctxt.CurrentContext.ContextDependentOptions |=
                ResolutionOptions.DontResolveBaseTypes |                 //TODO: Exactly find out which option can be enabled here. Resolving variables' types is needed sometimes - but only, when highlighting a variable reference is wanted explicitly.
                ResolutionOptions.NoTemplateParameterDeduction |
                ResolutionOptions.ReturnMethodReferencesOnly;

            ISyntaxRegion sr = null;
            int           i  = 0;

            while (curQueueOffset < queueCount)
            {
                // Avoid race condition runtime errors
                lock (_lockObject)
                {
                    i = curQueueOffset;
                    curQueueOffset++;
                }

                // Resolve gotten syntax object
                sr = q[i];
                var        sb = ctxt.CurrentContext.ScopedBlock;
                IStatement tStmt;
                ctxt.CurrentContext.Set(DResolver.SearchBlockAt(
                                            sb == null || sr.Location <sb.BlockStartLocation || sr.EndLocation> sb.EndLocation ? ast : sb,
                                            sr.Location,
                                            out tStmt), tStmt);

                if (sr is PostfixExpression_Access)
                {
                    HandleAccessExpressions((PostfixExpression_Access)sr, ctxt);
                }
                else
                {
                    AbstractType t = null;
                    if (sr is IExpression)
                    {
                        t = DResolver.StripAliasSymbol(Evaluation.EvaluateType((IExpression)sr, ctxt));
                    }
                    else if (sr is ITypeDeclaration)
                    {
                        t = DResolver.StripAliasSymbol(TypeDeclarationResolver.ResolveSingle((ITypeDeclaration)sr, ctxt));
                    }

                    // Enter into the result list
                    HandleResult(sr, t);
                }
            }
        }
예제 #19
0
        public static AbstractType[] ResolveHoveredCode(
            out ResolutionContext ResolverContext,
            MonoDevelop.Ide.Gui.Document doc = null)
        {
            var edData = GetEditorData(doc);

            ResolverContext = ResolutionContext.Create(edData);
            ResolverContext.ContextIndependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;

            // Resolve the hovered piece of code
            return(DResolver.ResolveType(edData, ResolverContext, DResolver.AstReparseOptions.AlsoParseBeyondCaret | DResolver.AstReparseOptions.OnlyAssumeIdentifierList));
        }
예제 #20
0
파일: VDServer.cs 프로젝트: Dzugaru/visuald
        public void GetReferences(string filename, string tok, uint line, uint idx, string expr)
        {
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

            _setupEditorData();
            CodeLocation loc = new CodeLocation((int)idx + 1, (int)line);

            _editorData.CaretLocation = loc;
            _editorData.SyntaxTree    = ast as DModule;
            _editorData.ModuleCode    = _sources[filename];
            _editorData.CaretOffset   = getCodeOffset(_editorData.ModuleCode, loc);

            _references = null;

            ISyntaxRegion sr;

            DResolver.NodeResolutionAttempt attempt;
            var rr = DResolver.ResolveTypeLoosely(_editorData, out attempt, out sr);

            StringBuilder refs = new StringBuilder();

            if (rr != null)
            {
                var n = DResolver.GetResultMember(rr, true);

                if (n != null)
                {
                    var ctxt = ResolutionContext.Create(_editorData, true);
                    if (n.ContainsAttribute(DTokens.Private) || ((n is DVariable) && (n as DVariable).IsLocal))
                    {
                        GetReferencesInModule(ast, refs, n, ctxt);
                    }
                    else
                    {
                        foreach (var basePath in _imports.Split('\n'))
                        {
                            foreach (var mod in GlobalParseCache.EnumModulesRecursively(basePath))
                            {
                                GetReferencesInModule(mod, refs, n, ctxt);
                            }
                        }
                    }
                }
                //var res = TypeReferenceFinder.Scan(_editorData, System.Threading.CancellationToken.None, null);
            }
            _references = refs;
        }
예제 #21
0
        public void Parse()
        {
            Clear();

            var editor  = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument;
            var project = ((editor != null && editor.HasProject) ? editor.Project : MonoDevelop.Ide.IdeApp.ProjectOperations.CurrentSelectedProject) as AbstractDProject;
            var file    = FindTraceLogFileName(project);

            if (file == null)
            {
                profilerPadWidget.AddTracedFunction(0, 0, 0, 0, new DVariable {
                    Name = trace_log + " not found.."
                });
                return;
            }

            var ctxt = ResolutionContext.Create(DResolverWrapper.CreateParseCacheView(editor), null, null);

            StreamReader reader = File.OpenText(file);
            string       line;

            while ((line = reader.ReadLine()) != null)
            {
                var m = traceFuncRegex.Match(line);

                if (m.Success)
                {
                    var symName = m.Groups["name"].Value;

                    if (symName.StartsWith("="))
                    {
                        continue;
                    }

                    bool mightBeLegalUnresolvableSymbol;
                    var  dn = ExamTraceSymbol(symName, ctxt, out mightBeLegalUnresolvableSymbol);

                    long v;
                    if (dn != null || mightBeLegalUnresolvableSymbol)
                    {
                        profilerPadWidget.AddTracedFunction(
                            long.TryParse(m.Groups["numcalls"].Value, out v) ? v : 0,
                            long.TryParse(m.Groups["treetime"].Value, out v) ? v : 0,
                            long.TryParse(m.Groups["functime"].Value, out v) ? v : 0,
                            long.TryParse(m.Groups["percall"].Value, out v) ? v : 0,
                            dn ?? new DVariable {
                            Name = symName
                        });
                    }
                }
            }
        }
예제 #22
0
        public static AbstractType[] ResolveHoveredCodeLoosely(out ResolutionContext ctxt, out IEditorData ed, out DResolver.NodeResolutionAttempt resolutionAttempt, Document doc = null)
        {
            ed = CreateEditorData(doc);
            if (ed == null)
            {
                resolutionAttempt = DResolver.NodeResolutionAttempt.Normal;
                ctxt = null;
                return(null);
            }
            ctxt = ResolutionContext.Create(ed, false);

            //return DResolver.ResolveTypeLoosely(ed, out resolutionAttempt, ctxt);
            return(AmbiguousType.TryDissolve(DResolver.ResolveTypeLoosely(ed, out resolutionAttempt, ctxt)).ToArray());
        }
예제 #23
0
        public static AbstractType[] ResolveHoveredCode(
            out ResolutionContext ResolverContext, out IEditorData edData,
            Document doc = null)
        {
            edData = CreateEditorData(doc);
            if (edData == null)
            {
                ResolverContext = null;
                return(null);
            }
            ResolverContext = ResolutionContext.Create(edData, false);

            // Resolve the hovered piece of code
            return(AmbiguousType.TryDissolve(DResolver.ResolveType(edData, ctxt: ResolverContext)).ToArray());
        }
예제 #24
0
        public static void EnumAllAvailableMembers(ICompletionDataGenerator cdgen, IBlockNode ScopedBlock
                                                   , IStatement ScopedStatement,
                                                   CodeLocation Caret,
                                                   ParseCacheView CodeCache,
                                                   MemberFilter VisibleMembers,
                                                   ConditionalCompilationFlags compilationEnvironment = null)
        {
            var ctxt = ResolutionContext.Create(CodeCache, compilationEnvironment, ScopedBlock, ScopedStatement);

            var en = new MemberCompletionEnumeration(ctxt, cdgen)
            {
                isVarInst = true
            };

            en.IterateThroughScopeLayers(Caret, VisibleMembers);
        }
예제 #25
0
        public static INode GetNode(EditorData ed, string id, ref ResolutionContext ctxt)
        {
            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(ed, true);
            }

            DToken tk;
            var    bt = DParser.ParseBasicType(id, out tk);
            var    t  = TypeDeclarationResolver.ResolveSingle(bt, ctxt);

            var n = (t as DSymbol).Definition;

            Assert.That(n, Is.Not.Null);
            return(n);
        }
예제 #26
0
        public void TestPrimitives()
        {
            TestPrimitive("1", DTokens.Int, 1M);
            TestPrimitive("1.0", DTokens.Double, 1.0M);
            TestPrimitive("1f", DTokens.Float, 1M);
            TestPrimitive("1e+3", DTokens.Int, 1000M);
            TestPrimitive("1.0e+2", DTokens.Double, 100M);
            TestPrimitive("'c'", DTokens.Char, (decimal)(int)'c');

            TestString("\"asdf\"", "asdf", true);
            TestString("\"asdf\"c", "asdf", true);
            TestString("\"asdf\"w", "asdf", true);
            TestString("\"asdf\"d", "asdf", true);

            TestString("\"asdf\"", "asdf", false);
            TestString("\"asdf\"c", "asdf", false);
            TestString("\"asdf\"w", "asdf", false);
            TestString("\"asdf\"d", "asdf", false);

            var ex = DParser.ParseExpression("['a','s','d','f']");
            var v  = Evaluation.EvaluateValue(ex, (ResolutionContext)null);

            Assert.IsInstanceOfType(typeof(ArrayValue), v);
            var ar = (ArrayValue)v;

            Assert.AreEqual(ar.Elements.Length, 4);

            foreach (var ev in ar.Elements)
            {
                Assert.IsInstanceOfType(typeof(PrimitiveValue), ev);
            }


            ex = DParser.ParseExpression("[\"KeyA\":12, \"KeyB\":33, \"KeyC\":44]");
            v  = Evaluation.EvaluateValue(ex, (ResolutionContext)null);

            Assert.IsInstanceOfType(typeof(AssociativeArrayValue), v);
            var aa = (AssociativeArrayValue)v;

            Assert.AreEqual(aa.Elements.Count, 3);

            ex = DParser.ParseExpression("(a,b) => a+b");
            var pcl = new ParseCacheView(new[] { new MutableRootPackage() });

            v = Evaluation.EvaluateValue(ex, ResolutionContext.Create(pcl, null, null));
            Assert.IsInstanceOfType(typeof(DelegateValue), v);
        }
예제 #27
0
        public void Parse(DProject project)
        {
            string file = TraceLogFile(project);

            if (file == null)
            {
                profilerPadWidget.AddTracedFunction(0, 0, 0, 0, new DVariable {
                    Name = "trace.log not found.."
                });
                return;
            }

            lastProfiledProject = project;
            profilerPadWidget.ClearTracedFunctions();

            var ctxt = ResolutionContext.Create(Resolver.DResolverWrapper.CreateCacheList(lastProfiledProject), null, null);

            StreamReader reader = File.OpenText(file);
            string       line;

            while ((line = reader.ReadLine()) != null)
            {
                var m = traceFuncRegex.Match(line);

                if (m.Success)
                {
                    var symName = m.Groups[5].Value;

                    if (symName.StartsWith("="))
                    {
                        continue;
                    }

                    bool mightBeLegalUnresolvableSymbol;
                    var  dn = ExamTraceSymbol(symName, ctxt, out mightBeLegalUnresolvableSymbol);

                    if (dn != null || mightBeLegalUnresolvableSymbol)
                    {
                        profilerPadWidget.AddTracedFunction(long.Parse(m.Groups[1].Value), long.Parse(m.Groups[2].Value),
                                                            long.Parse(m.Groups[3].Value), long.Parse(m.Groups[4].Value), dn ?? new DVariable {
                            Name = symName
                        });
                    }
                }
            }
        }
예제 #28
0
        public static Dictionary <int, Dictionary <ISyntaxRegion, byte> > Scan(IEditorData ed, List <ISyntaxRegion> invalidConditionalCodeRegions = null, int timeout = int.MinValue)
        {
            if (ed == null || ed.SyntaxTree == null)
            {
                return(new Dictionary <int, Dictionary <ISyntaxRegion, byte> >());
            }

            var ctxt = ResolutionContext.Create(ed, false);

            // Since it's just about enumerating, not checking types, ignore any conditions
            ctxt.ContextIndependentOptions |= ResolutionOptions.IgnoreDeclarationConditions;

            var typeRefFinder = new TypeReferenceFinder(ctxt, invalidConditionalCodeRegions);

            CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () => ed.SyntaxTree.Accept(typeRefFinder), timeout);

            return(typeRefFinder.Matches);
        }
예제 #29
0
        public void TestTemplateDeductionAsConversion()
        {
            var pcl  = ResolutionTests.CreateCache(@"module modA;
void foo(T:T)(T[] t) {}

int[] p=[1,2,3,4,5];
");
            var ctxt = ResolutionContext.Create(pcl, null, pcl[0]["modA"]);

            var foo = pcl[0]["modA"]["foo"].First() as DMethod;

            ctxt.PushNewScope(foo);
            var foo_firstArg = TypeDeclarationResolver.Resolve(foo.Parameters[0].Type, ctxt);

            var p = TypeDeclarationResolver.ResolveIdentifier("p", ctxt, null)[0] as MemberSymbol;

            Assert.IsTrue(ResultComparer.IsImplicitlyConvertible(p, foo_firstArg[0], ctxt));
            ctxt.Pop();
        }
예제 #30
0
        public void TestConstEval()
        {
            var pcl = ResolutionTests.CreateCache(@"module modA;
const a= 234;
enum b=123;
const int c=125;
enum int d=126;
");
            var vp  = new StandardValueProvider(ResolutionContext.Create(pcl, null, pcl[0]["modA"]));

            var v = E("a", vp);

            Assert.IsInstanceOfType(typeof(VariableValue), v);
            var val = vp[((VariableValue)v).Variable];

            Assert.IsInstanceOfType(typeof(PrimitiveValue), val);
            var pv = (PrimitiveValue)val;

            Assert.AreEqual(pv.Value, 234M);

            v   = E("b", vp);
            val = vp[((VariableValue)v).Variable];
            pv  = (PrimitiveValue)val;
            Assert.AreEqual(pv.Value, 123M);

            v   = E("c", vp);
            val = vp[((VariableValue)v).Variable];
            pv  = (PrimitiveValue)val;
            Assert.AreEqual(pv.Value, 125M);

            v   = E("d", vp);
            val = vp[((VariableValue)v).Variable];
            pv  = (PrimitiveValue)val;
            Assert.AreEqual(pv.Value, 126M);

            pv = E("d + 4", vp) as PrimitiveValue;
            Assert.IsNotNull(pv);
            Assert.AreEqual(130M, pv.Value);

            pv = E("d + a", vp) as PrimitiveValue;
            Assert.IsNotNull(pv);
            Assert.AreEqual(360M, pv.Value);
        }