/// <summary> /// Resolves an identifier and returns the definition + its base type. /// Does not deduce any template parameters or nor filters out unfitting template specifications! /// </summary> public static AbstractType[] ResolveIdentifier(int idHash, ResolutionContext ctxt, object idObject, bool ModuleScope = false) { var loc = idObject is ISyntaxRegion ? ((ISyntaxRegion)idObject).Location : CodeLocation.Empty; if (ModuleScope) { ctxt.PushNewScope(ctxt.ScopedBlock.NodeRoot as DModule); } // If there are symbols that must be preferred, take them instead of scanning the ast else { TemplateParameterSymbol dedTemplateParam; if (ctxt.GetTemplateParam(idHash, out dedTemplateParam)) { return new[] { dedTemplateParam } } ; } var res = NameScan.SearchAndResolve(ctxt, loc, idHash, idObject); if (ModuleScope) { ctxt.Pop(); } return /*res.Count == 0 ? null :*/ (res.ToArray()); }
public static AbstractType[] ResolveIdentifier(string id, ResolverContextStack ctxt, object idObject, bool ModuleScope = false) { var loc = idObject is ISyntaxRegion ? ((ISyntaxRegion)idObject).Location:CodeLocation.Empty; if (ModuleScope) { ctxt.PushNewScope(ctxt.ScopedBlock.NodeRoot as IAbstractSyntaxTree); } // If there are symbols that must be preferred, take them instead of scanning the ast else { var tstk = new Stack <ResolverContext>(); D_Parser.Resolver.Templates.TemplateParameterSymbol dedTemplateParam = null; while (!ctxt.CurrentContext.DeducedTemplateParameters.TryGetValue(id, out dedTemplateParam)) { if (ctxt.PrevContextIsInSameHierarchy) { tstk.Push(ctxt.Pop()); } else { break; } } while (tstk.Count > 0) { ctxt.Push(tstk.Pop()); } if (dedTemplateParam != null) { return new[] { dedTemplateParam } } ; } var matches = NameScan.SearchMatchesAlongNodeHierarchy(ctxt, loc, id); var res = HandleNodeMatches(matches, ctxt, null, idObject); if (ModuleScope) { ctxt.Pop(); } return(res); }
/// <summary> /// Resolves an identifier and returns the definition + its base type. /// Does not deduce any template parameters or nor filters out unfitting template specifications! /// </summary> public static AbstractType[] ResolveIdentifier(int idHash, ResolutionContext ctxt, ISyntaxRegion idObject, bool ModuleScope = false) { var loc = idObject is ISyntaxRegion ? ((ISyntaxRegion)idObject).Location : CodeLocation.Empty; if (ModuleScope) { ctxt.PushNewScope(ctxt.ScopedBlock.NodeRoot as DModule); } // If there are symbols that must be preferred, take them instead of scanning the ast else { TemplateParameterSymbol dedTemplateParam; if (ctxt.GetTemplateParam(idHash, out dedTemplateParam)) { return new[] { dedTemplateParam } } ; } var res = NameScan.SearchAndResolve(ctxt, loc, idHash, idObject); if (ModuleScope) { ctxt.Pop(); } if (res.Count != 0) { return /*res.Count == 0 ? null :*/ (res.ToArray()); } // Support some very basic static typing if no phobos is given atm if (idHash == Evaluation.stringTypeHash) { res.Add(Evaluation.GetStringType(ctxt)); } else if (idHash == Evaluation.wstringTypeHash) { res.Add(Evaluation.GetStringType(ctxt, LiteralSubformat.Utf16)); } else if (idHash == Evaluation.dstringTypeHash) { res.Add(Evaluation.GetStringType(ctxt, LiteralSubformat.Utf32)); } return(res.ToArray()); }
/// <summary> /// Used for searching further identifier list parts. /// /// a.b -- nextIdentifier would be 'b' whereas <param name="resultBases">resultBases</param> contained the resolution result for 'a' /// </summary> public static AbstractType[] ResolveFurtherTypeIdentifier(string nextIdentifier, IEnumerable <AbstractType> resultBases, ResolverContextStack ctxt, object typeIdObject = null) { if ((resultBases = DResolver.StripAliasSymbols(resultBases)) == null) { return(null); } var r = new List <AbstractType>(); var nextResults = new List <AbstractType>(); foreach (var b in resultBases) { IEnumerable <AbstractType> scanResults = new[] { b }; do { foreach (var scanResult in scanResults) { // First filter out all alias and member results..so that there will be only (Static-)Type or Module results left.. if (scanResult is MemberSymbol) { var mr = (MemberSymbol)scanResult; if (mr.Base != null) { nextResults.Add(mr.Base); } } else if (scanResult is UserDefinedType) { var udt = (UserDefinedType)scanResult; var bn = udt.Definition as IBlockNode; var nodeMatches = NameScan.ScanNodeForIdentifier(bn, nextIdentifier, ctxt); ctxt.PushNewScope(bn); ctxt.CurrentContext.IntroduceTemplateParameterTypes(udt); var results = HandleNodeMatches(nodeMatches, ctxt, b, typeIdObject); if (results != null) { foreach (var res in results) { r.Add(AbstractType.Get(res)); } } ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals(udt); ctxt.Pop(); } else if (scanResult is PackageSymbol) { var pack = ((PackageSymbol)scanResult).Package; IAbstractSyntaxTree accessedModule = null; if (pack.Modules.TryGetValue(nextIdentifier, out accessedModule)) { r.Add(new ModuleSymbol(accessedModule as DModule, typeIdObject as ISyntaxRegion, (PackageSymbol)scanResult)); } else if (pack.Packages.TryGetValue(nextIdentifier, out pack)) { r.Add(new PackageSymbol(pack, typeIdObject as ISyntaxRegion)); } } else if (scanResult is ModuleSymbol) { var modRes = (ModuleSymbol)scanResult; var matches = NameScan.ScanNodeForIdentifier(modRes.Definition, nextIdentifier, ctxt); var results = HandleNodeMatches(matches, ctxt, b, typeIdObject); if (results != null) { foreach (var res in results) { r.Add(AbstractType.Get(res)); } } } } scanResults = DResolver.FilterOutByResultPriority(ctxt, nextResults); nextResults = new List <AbstractType>(); }while (scanResults != null); } return(r.Count == 0 ? null : r.ToArray()); }