public IEnumerable<DMethod> FindFitting(ResolverContextStack ctxt, CodeLocation currentLocation, ISemantic firstArgument, string nameFilter = null) { if (IsProcessing) return null; var preMatchList = new List<DMethod>(); bool dontUseNameFilter = nameFilter == null; lock(CachedMethods) foreach (var kv in CachedMethods) { // First test if arg is matching the parameter if ((dontUseNameFilter || kv.Key.Name == nameFilter) && ResultComparer.IsImplicitlyConvertible(firstArgument, kv.Value, ctxt)) preMatchList.Add(kv.Key); } // Then filter out methods which cannot be accessed in the current context // (like when the method is defined in a module that has not been imported) var mv = new MatchFilterVisitor<DMethod>(ctxt, preMatchList); mv.IterateThroughScopeLayers(currentLocation); return mv.filteredList; }
internal static IOpenView SelectFromSemantic(ISemantic query) { var subject = ((ISemantic)query).Subject; var context = new SemqContext(subject, subject.QueryRoot); return(((ISelect)query.Translate(context, null)).Select()); }
/// <summary> /// Handles mathemathical operation. /// If l and r are both primitive values, the MathOp delegate is executed. /// /// TODO: Operator overloading. /// </summary> ISemantic HandleSingleMathOp(IExpression x, ISemantic l, ISemantic r, MathOp m) { if (l == null || r == null) { return(null); } var pl = l as PrimitiveValue; var pr = r as PrimitiveValue; //TODO: imaginary/complex parts if (pl != null && pr != null) { // If one if (pl.IsNaN || pr.IsNaN) { return(PrimitiveValue.CreateNaNValue(x, pl.IsNaN ? pl.BaseTypeToken : pr.BaseTypeToken)); } return(new PrimitiveValue(pl.BaseTypeToken, m(pl, pr), x)); } throw new NotImplementedException("Operator overloading not implemented yet."); }
static ISymbolValue HandleSingleMathOp(OperatorBasedExpression x, ISemantic l, ISemantic r, MathOp2 m, bool UnorderedCheck = true) { if (l == null || r == null) { return(null); } var pl = l as PrimitiveValue; var pr = r as PrimitiveValue; //TODO: imaginary/complex parts if (pl != null && pr != null) { if (UnorderedCheck && (pl.IsNaN || pr.IsNaN)) { return(PrimitiveValue.CreateNaNValue(x, pl.IsNaN ? pl.BaseTypeToken : pr.BaseTypeToken)); } return(m(pl, pr, x)); } return(null); //throw new NotImplementedException("Operator overloading not implemented yet."); }
UFCSResolver(ResolutionContext ctxt, ISemantic firstArg, int nameHash = 0, ISyntaxRegion sr = null) : base(ctxt) { this.firstArgument = firstArg; this.nameFilterHash = nameHash; this.sr = sr; }
bool Handle(TemplateTypeParameter p, ISemantic arg) { // if no argument given, try to handle default arguments if (arg == null) { return(TryAssignDefaultType(p)); } // If no spezialization given, assign argument immediately if (p.Specialization == null) { return(Set(p, arg, 0)); } bool handleResult = HandleDecl(null, p.Specialization, arg); if (!handleResult) { return(false); } // Apply the entire argument to parameter p if there hasn't been no explicit association yet TemplateParameterSymbol tps; if (!TargetDictionary.TryGetValue(p, out tps) || tps == null) { TargetDictionary[p] = new TemplateParameterSymbol(p, arg); } return(true); }
public static DNode GetResultMember(ISemantic res, bool keepAliases = false) { var t = AbstractType.Get(res); if (t == null) { return(null); } if (keepAliases) { var aliasTag = t.Tag as TypeResolution.TypeDeclarationResolver.AliasTag; if (aliasTag != null && (!(aliasTag.aliasDefinition is ImportSymbolAlias) || // Only if the import symbol alias definition was selected, go to its base (aliasTag.typeBase != null && aliasTag.aliasDefinition.NameLocation != aliasTag.typeBase.Location))) { return(aliasTag.aliasDefinition); } } if (t is DSymbol) { return(((DSymbol)res).Definition); } return(null); }
public static void AddFloatingTypeProperties(int TypeToken, ISemantic rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { var intType = new DTokenDeclaration(TypeToken); if (!DontAddInitProperty) { var prop_Init = new DVariable() { Type = intType, Initializer = new PostfixExpression_Access() { PostfixForeExpression = new TokenExpression(TypeToken), AccessExpression = new IdentifierExpression("nan") } }; if (relatedNode != null) { prop_Init.AssignFrom(relatedNode); } // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(FloatingTypeProps, cdg, intType); }
ISemantic E(OperatorBasedExpression x, ISemantic lValue=null) { if (x is AssignExpression) return E((AssignExpression)x,lValue); // TODO: Implement operator precedence (see http://forum.dlang.org/thread/[email protected] ) if (x is XorExpression || // a ^ b x is OrExpression || // a | b x is AndExpression || // a & b x is ShiftExpression || // a << 8 x is AddExpression || // a += b; a -= b; x is MulExpression || // a *= b; a /= b; a %= b; x is CatExpression || // a ~= b; x is PowExpression) // a ^^ b; return E_MathOp(x, lValue); else if (x is EqualExpression) // a==b return E((EqualExpression)x, lValue); else if (x is OrOrExpression || // a || b x is AndAndExpression || // a && b x is IdendityExpression || // a is T x is RelExpression) // a <= b return E_BoolOp(x, lValue as ISymbolValue); else if (x is InExpression) // a in b return E((InExpression)x, lValue); throw new WrongEvaluationArgException(); }
static bool CheckAndDeduceTypeAgainstTplParameter(TemplateParameter handledParameter, ISemantic argumentToCheck, DeducedTypeDictionary deducedTypes, ResolutionContext ctxt) { return(new Templates.TemplateParameterDeduction(deducedTypes, ctxt).Handle(handledParameter, argumentToCheck)); }
bool HandleDecl(TemplateTypeParameter p, IdentifierDeclaration id, ISemantic r) { // Bottom-level reached if (id.InnerDeclaration == null && Contains(id.IdHash) && !id.ModuleScoped) { // Associate template param with r return(Set((p != null && id.IdHash == p.NameHash) ? p : null, r, id.IdHash)); } var deducee = DResolver.StripMemberSymbols(AbstractType.Get(r)) as DSymbol; if (id.InnerDeclaration != null && deducee != null && deducee.Definition.NameHash == id.IdHash) { var physicalParentType = TypeDeclarationResolver.HandleNodeMatch(deducee.Definition.Parent, ctxt, null, id.InnerDeclaration); if (HandleDecl(p, id.InnerDeclaration, physicalParentType)) { if (Contains(id.IdHash)) { Set((p != null && id.IdHash == p.NameHash) ? p : null, deducee, id.IdHash); } return(true); } } /* * If not stand-alone identifier or is not required as template param, resolve the id and compare it against r */ var _r = TypeDeclarationResolver.ResolveSingle(id, ctxt); return(_r != null && (EnforceTypeEqualityWhenDeducing ? ResultComparer.IsEqual(r, _r) : ResultComparer.IsImplicitlyConvertible(r, _r))); }
static AbstractTooltipContent BuildTooltipContent(ISemantic res) { if (res is ISymbolValue) { var sv = res as ISymbolValue; if (sv is TypeValue) { return new AbstractTooltipContent { ResolveResult = res, Title = sv.RepresentedType.ToString() } } ; return(new AbstractTooltipContent { ResolveResult = res, Title = "(" + sv.RepresentedType + ") " + sv.ToCode() }); } // Only show one description for items sharing descriptions string description = res is DSymbol ? ((DSymbol)res).Definition.Description : ""; return(new AbstractTooltipContent { ResolveResult = res, Title = (res is ModuleSymbol ? ((ModuleSymbol)res).Definition.FileName : res.ToString()), Description = description }); } }
public TemplateParameterSymbol(TemplateParameter tpn, ISemantic typeOrValue, ISyntaxRegion paramIdentifier = null) : base(tpn != null ? tpn.Representation : null, AbstractType.Get(typeOrValue), paramIdentifier) { IsKnowinglyUndetermined = TemplateInstanceHandler.IsNonFinalArgument(typeOrValue); this.Parameter = tpn; this.ParameterValue = typeOrValue as ISymbolValue; }
/// <summary> /// Returns false if the item has already been set before and if the already set item is not equal to 'r'. /// Inserts 'r' into the target dictionary and returns true otherwise. /// </summary> bool Set(ITemplateParameter p, ISemantic r, string name = null) { if (string.IsNullOrEmpty(name)) { name = p.Name; } TemplateParameterSymbol rl = null; if (!TargetDictionary.TryGetValue(name, out rl) || rl == null) { TargetDictionary[name] = new TemplateParameterSymbol(p, r, null, TargetDictionary.ParameterOwner); return(true); } else { if (rl != null) { if (ResultComparer.IsEqual(rl.Base, r)) { return(true); } else { // Error: Ambiguous assignment } } TargetDictionary[name] = new TemplateParameterSymbol(p, r, null, TargetDictionary.ParameterOwner); return(false); } }
public bool HandleDecl(TemplateTypeParameter p ,ITypeDeclaration td, ISemantic rr) { if (td is IdentifierDeclaration) return HandleDecl(p,(IdentifierDeclaration)td, rr); //HACK Ensure that no information gets lost by using this function // -- getting a value but requiring an abstract type and just extract it from the value - is this correct behaviour? var at = AbstractType.Get(rr); if (td is ArrayDecl) return HandleDecl(p,(ArrayDecl)td, DResolver.StripMemberSymbols(at) as AssocArrayType); else if (td is DTokenDeclaration) return HandleDecl((DTokenDeclaration)td, at); else if (td is DelegateDeclaration) return HandleDecl(p, (DelegateDeclaration)td, DResolver.StripMemberSymbols(at) as DelegateType); else if (td is PointerDecl) return HandleDecl(p, (PointerDecl)td, DResolver.StripMemberSymbols(at) as PointerType); else if (td is MemberFunctionAttributeDecl) return HandleDecl(p,(MemberFunctionAttributeDecl)td, at); else if (td is TypeOfDeclaration) return HandleDecl((TypeOfDeclaration)td, at); else if (td is VectorDeclaration) return HandleDecl((VectorDeclaration)td, at); else if (td is TemplateInstanceExpression) return HandleDecl(p,(TemplateInstanceExpression)td, at); return false; }
/// <summary> /// Adds init, max, min to the completion list /// </summary> public static void AddIntegralTypeProperties(int TypeToken, ISemantic rr, ICompletionDataGenerator cdg, INode relatedNode = null, bool DontAddInitProperty = false) { var intType = new DTokenDeclaration(TypeToken); if (!DontAddInitProperty) { var prop_Init = new DVariable() { Type = intType, Initializer = new IdentifierExpression(0, LiteralFormat.Scalar) }; if (relatedNode != null) { prop_Init.AssignFrom(relatedNode); } // Override the initializer variable's name and description prop_Init.Name = "init"; prop_Init.Description = "A type's or variable's static initializer expression"; cdg.Add(prop_Init); } CreateArtificialProperties(IntegralProps, cdg, intType); }
/// <summary> /// Checks given results for type equality /// </summary> public static bool IsEqual(ISemantic r1, ISemantic r2) { if (r1 is ISymbolValue && r2 is ISymbolValue) return SymbolValueComparer.IsEqual((ISymbolValue)r1, (ISymbolValue)r2); else if (r1 is TemplateIntermediateType && r2 is TemplateIntermediateType) { var tr1 = (TemplateIntermediateType)r1; var tr2 = (TemplateIntermediateType)r2; if (tr1.Definition != tr2.Definition) return false; //TODO: Compare deduced types return true; } else if (r1 is PrimitiveType && r2 is PrimitiveType) return ((PrimitiveType)r1).TypeToken == ((PrimitiveType)r2).TypeToken; else if (r1 is ArrayType && r2 is ArrayType) { var ar1 = (ArrayType)r1; var ar2 = (ArrayType)r2; if (!IsEqual(ar1.KeyType, ar2.KeyType)) return false; return IsEqual(ar1.Base, ar2.Base); } //TODO: Handle other types return false; }
/// <summary> /// Joins the nodes in a graph instructing the builder to use the specified synonym for the join query in the relational code. /// </summary> /// <typeparam name="T">The type of a synonym node.</typeparam> /// <param name="graph">A graph.</param> /// <param name="synonym">A synonym of a graph.</param> public static DbTable <T> JoinAs <T>(this ISemantic graph, DbTable <T> synonym) where T : DbRow { graph.CheckNullAndThrow(Text.Free.Graph, Text.Method.Join); synonym.CheckNullAndThrow("synonym", Text.Method.Join); CheckSynonymAndThrow(synonym); var node = graph.Subject; bool found = false; do { if (((DbNode)(object)synonym).Equals(node)) { found = true; break; } } while ((node = node.Next) != null); if (!found) { throw new QueryTalkException(".JoinAs<T>", QueryTalkExceptionType.InvalidSynonym, String.Format("synonym = {0}", synonym), Text.Method.JoinSynonym); } return(((IEndView)((ISemqToSql)graph).Join() .Select("1.*")) .UseAs(synonym)); }
internal void EvalError(IExpression x, string msg, ISemantic lastResult) { if (!ignoreErrors) { Errors.Add(new EvaluationException(x, msg, new[] { lastResult })); } }
ISemantic E(InExpression x, ISemantic l = null) { // The return value of the InExpression is null if the element is not in the array; // if it is in the array it is a pointer to the element. return(E(x.RightOperand)); }
bool HandleDecl(TemplateTypeParameter p, IdentifierDeclaration id, ISemantic r) { // Bottom-level reached if (id.InnerDeclaration == null && Contains(id.IdHash) && !id.ModuleScoped) { // Associate template param with r return Set((p != null && id.IdHash == p.NameHash) ? p : null, r, id.IdHash); } var deducee = DResolver.StripMemberSymbols(AbstractType.Get(r)) as DSymbol; if (id.InnerDeclaration != null && deducee != null && deducee.Definition.NameHash == id.IdHash) { var physicalParentType = TypeDeclarationResolver.HandleNodeMatch(deducee.Definition.Parent, ctxt, null, id.InnerDeclaration); if (HandleDecl(p, id.InnerDeclaration, physicalParentType)) { if (Contains(id.IdHash)) Set((p != null && id.IdHash == p.NameHash) ? p : null, deducee, id.IdHash); return true; } } /* * If not stand-alone identifier or is not required as template param, resolve the id and compare it against r */ var _r = TypeDeclarationResolver.ResolveSingle(id, ctxt); return _r != null && (EnforceTypeEqualityWhenDeducing ? ResultComparer.IsEqual(r,_r) : ResultComparer.IsImplicitlyConvertible(r,_r)); }
public static List <AbstractType> TryResolveUFCS( ISemantic firstArgument, PostfixExpression_Access acc, ResolutionContext ctxt) { if (firstArgument == null || acc == null || ctxt == null) { return(new List <AbstractType>()); } int name; if (acc.AccessExpression is IdentifierExpression) { name = ((IdentifierExpression)acc.AccessExpression).ValueStringHash; } else if (acc.AccessExpression is TemplateInstanceExpression) { name = ((TemplateInstanceExpression)acc.AccessExpression).TemplateIdHash; } else { return(new List <AbstractType> ()); } return(TryResolveUFCS(firstArgument, name, acc.PostfixForeExpression.Location, ctxt, acc)); }
public bool HandleDecl(TemplateTypeParameter p, ITypeDeclaration td, ISemantic rr) { if (td is IdentifierDeclaration) { return(HandleDecl(p, (IdentifierDeclaration)td, rr)); } if (TemplateInstanceHandler.IsNonFinalArgument(rr)) { foreach (var tp in this.TargetDictionary.Keys.ToList()) { if (TargetDictionary[tp] == null) { TargetDictionary[tp] = new TemplateParameterSymbol(tp, null); } } return(true); } //HACK Ensure that no information gets lost by using this function // -- getting a value but requiring an abstract type and just extract it from the value - is this correct behaviour? var at = AbstractType.Get(rr); if (td is ArrayDecl) { return(HandleDecl(p, (ArrayDecl)td, DResolver.StripMemberSymbols(at) as AssocArrayType)); } else if (td is DTokenDeclaration) { return(HandleDecl((DTokenDeclaration)td, at)); } else if (td is DelegateDeclaration) { return(HandleDecl(p, (DelegateDeclaration)td, DResolver.StripMemberSymbols(at) as DelegateType)); } else if (td is PointerDecl) { return(HandleDecl(p, (PointerDecl)td, DResolver.StripMemberSymbols(at) as PointerType)); } else if (td is MemberFunctionAttributeDecl) { return(HandleDecl(p, (MemberFunctionAttributeDecl)td, at)); } else if (td is TypeOfDeclaration) { return(HandleDecl((TypeOfDeclaration)td, at)); } else if (td is VectorDeclaration) { return(HandleDecl((VectorDeclaration)td, at)); } else if (td is TemplateInstanceExpression) { return(HandleDecl(p, (TemplateInstanceExpression)td, at)); } return(false); }
/// <summary> /// Checks given results for type equality /// </summary> public static bool IsEqual(ISemantic r1, ISemantic r2) { if(r1 is TemplateParameterSymbol) r1 = ((TemplateParameterSymbol)r1).Base; if(r2 is TemplateParameterSymbol) r2 = ((TemplateParameterSymbol)r2).Base; if (r1 is ISymbolValue && r2 is ISymbolValue) return SymbolValueComparer.IsEqual((ISymbolValue)r1, (ISymbolValue)r2); else if (r1 is TemplateIntermediateType && r2 is TemplateIntermediateType) { var tr1 = (TemplateIntermediateType)r1; var tr2 = (TemplateIntermediateType)r2; if (tr1.Definition != tr2.Definition) return false; //TODO: Compare deduced types return true; } else if (r1 is PrimitiveType && r2 is PrimitiveType) return ((PrimitiveType)r1).TypeToken == ((PrimitiveType)r2).TypeToken; else if (r1 is ArrayType && r2 is ArrayType) { var ar1 = (ArrayType)r1; var ar2 = (ArrayType)r2; if (!IsEqual(ar1.KeyType, ar2.KeyType)) return false; return IsEqual(ar1.Base, ar2.Base); } else if(r1 is DelegateType && r2 is DelegateType) { var dg1 = r1 as DelegateType; var dg2 = r2 as DelegateType; if(dg1.IsFunctionLiteral != dg2.IsFunctionLiteral || !IsEqual(dg1.ReturnType, dg2.ReturnType)) return false; if(dg1.Parameters == null || dg1.Parameters.Length == 0) return dg2.Parameters == null || dg2.Parameters.Length==0; else if(dg2.Parameters == null) return dg1.Parameters == null || dg1.Parameters.Length==0; else if(dg1.Parameters.Length == dg2.Parameters.Length) { for(int i = dg1.Parameters.Length-1; i != 0; i--) if(!IsEqual(dg1.Parameters[i], dg2.Parameters[i])) return false; return true; } } //TODO: Handle other types return false; }
/// <summary> /// Ends the semantic sentence creating the Procedure object. /// </summary> /// <param name="sentence">A semantic sentence.</param> public static Procedure EndProc(this ISemantic sentence) { var query = _Translate((DbNode)sentence); var proc = ((IEndProc)query).EndProcInternal(); ((IConnectable)sentence).ResetConnectionKey(); return(proc); }
public static AbstractType Get(ISemantic s) { if (s is ISymbolValue) { return(((ISymbolValue)s).RepresentedType); } return(s as AbstractType); }
public static AbstractType Convert(ISemantic s) { if (s is AbstractType) return (AbstractType)s; else if(s is ISymbolValue) return ((ISymbolValue)s).RepresentedType; return null; }
/// <summary> /// Returns false if the item has already been set before and if the already set item is not equal to 'r'. /// Inserts 'r' into the target dictionary and returns true otherwise. /// </summary> bool Set(TemplateParameter p, ISemantic r, int nameHash) { if (p == null) { if (nameHash != 0 && TargetDictionary.ExpectedParameters != null) { foreach (var tpar in TargetDictionary.ExpectedParameters) { if (tpar.NameHash == nameHash) { p = tpar; break; } } } } if (p == null) { ctxt.LogError(null, "no fitting template parameter found!"); return(false); } // void call(T)(T t) {} // call(myA) -- T is *not* myA but A, so only assign myA's type to T. if (p is TemplateTypeParameter) { var newR = Resolver.TypeResolution.DResolver.StripMemberSymbols(AbstractType.Get(r)); if (newR != null) { r = newR; } } TemplateParameterSymbol rl; if (!TargetDictionary.TryGetValue(p, out rl) || rl == null) { TargetDictionary[p] = new TemplateParameterSymbol(p, r); return(true); } else { if (ResultComparer.IsEqual(rl.Base, r)) { TargetDictionary[p] = new TemplateParameterSymbol(p, r); return(true); } else if (rl == null) { TargetDictionary[p] = new TemplateParameterSymbol(p, r); } // Error: Ambiguous assignment return(false); } }
bool Handle(TemplateAliasParameter p, ISemantic arg) { #region Handle parameter defaults if (arg == null) { if (p.DefaultExpression != null) { var eval = Evaluation.EvaluateValue(p.DefaultExpression, ctxt); if (eval == null) return false; return Set(p, eval, 0); } else if (p.DefaultType != null) { var res = TypeDeclarationResolver.ResolveSingle(p.DefaultType, ctxt); return res != null && Set(p, res, 0); } return false; } #endregion #region Given argument must be a symbol - so no built-in type but a reference to a node or an expression var t=AbstractType.Get(arg); if (t == null) return false; if(!(t is DSymbol)) while (t != null) { if (t is PrimitiveType) // arg must not base on a primitive type. return false; if (t is DerivedDataType) t = ((DerivedDataType)t).Base; else break; } #endregion #region Specialization check if (p.SpecializationExpression != null) { // LANGUAGE ISSUE: Can't do anything here - dmd won't let you use MyClass!(2) though you have class MyClass(alias X:2) return false; } else if (p.SpecializationType != null) { // ditto return false; } #endregion return Set(p,arg,0); }
ISymbolValue TryGetValue(ISemantic s) { if (s is VariableValue) { return(ValueProvider[((VariableValue)s).Variable]); } return(s as ISymbolValue); }
public static DNode GetResultMember(ISemantic res) { if (res is DSymbol) { return(((DSymbol)res).Definition); } return(null); }
bool Handle(TemplateValueParameter p, ISemantic arg) { // Handle default arg case if (arg == null) { if (p.DefaultExpression != null) { var eval = Evaluation.EvaluateValue(p.DefaultExpression, ctxt); if (eval == null) { return(false); } return(Set(p, eval)); } else { return(false); } } var valueArgument = arg as ISymbolValue; // There must be a constant expression given! if (valueArgument == null) { return(false); } // Check for param type <-> arg expression type match var paramType = TypeDeclarationResolver.Resolve(p.Type, ctxt); if (paramType == null || paramType.Length == 0) { return(false); } if (valueArgument.RepresentedType == null || !ResultComparer.IsImplicitlyConvertible(paramType[0], valueArgument.RepresentedType)) { return(false); } // If spec given, test for equality (only ?) if (p.SpecializationExpression != null) { var specVal = Evaluation.EvaluateValue(p.SpecializationExpression, ctxt); if (specVal == null || !SymbolValueComparer.IsEqual(specVal, valueArgument)) { return(false); } } return(Set(p, arg)); }
ISemantic E(EqualExpression x, ISemantic lValue = null, ISemantic rValue = null) { var l = TryGetValue(lValue ?? E(x.LeftOperand)); var r = TryGetValue(rValue ?? E(x.RightOperand)); var isEq = SymbolValueComparer.IsEqual(l, r); return(new PrimitiveValue(x.OperatorToken == DTokens.Equal ? isEq : !isEq, x)); }
ISymbolValue TryGetValue(ISemantic s) { if (s is VariableValue) { return(EvaluateValue(s as VariableValue, ValueProvider)); } return(s as ISymbolValue); }
public static List <ISemantic> PreResolveTemplateArgs(TemplateInstanceExpression tix, ResolverContextStack ctxt) { // Resolve given argument expressions var templateArguments = new List <ISemantic>(); if (tix != null && tix.Arguments != null) { foreach (var arg in tix.Arguments) { if (arg is TypeDeclarationExpression) { var tde = (TypeDeclarationExpression)arg; var res = TypeDeclarationResolver.Resolve(tde.Declaration, ctxt); if (ctxt.CheckForSingleResult(res, tde.Declaration) || res != null) { var mr = res[0] as MemberSymbol; if (mr != null && mr.Definition is DVariable) { var dv = (DVariable)mr.Definition; if (dv.IsAlias || dv.Initializer == null) { templateArguments.Add(mr); continue; } ISemantic eval = null; try { eval = new StandardValueProvider(ctxt)[dv]; } catch (System.Exception ee) // Should be a non-const-expression error here only { ctxt.LogError(dv.Initializer, ee.Message); } templateArguments.Add(eval == null ? (ISemantic)mr : eval); } else { templateArguments.Add(res[0]); } } } else { templateArguments.Add(Evaluation.EvaluateValue(arg, ctxt)); } } } return(templateArguments); }
public UfcsMatchScanner(ResolutionContext ctxt, ConcurrentDictionary <DMethod, AbstractType> CachedMethods, ISemantic firstArgument, int nameFilterHash = 0) : base(ctxt) { this.firstArgument = firstArgument; this.nameFilterHash = nameFilterHash; this.cache = CachedMethods; }
public TemplateParameterSymbol(ITemplateParameter tp, ISemantic representedTypeOrValue, ISyntaxRegion originalParameterIdentifier = null, DNode parentNode = null) : base(new TemplateParameterNode(tp) { Parent = parentNode }, AbstractType.Get(representedTypeOrValue), originalParameterIdentifier ?? tp) { this.Parameter = tp; this.ParameterValue = representedTypeOrValue as ISymbolValue; }
public static MemberSymbol[] TryResolveUFCS( ISemantic firstArgument, PostfixExpression_Access acc, ResolutionContext ctxt) { if (ctxt == null) return null; int name=0; if (acc.AccessExpression is IdentifierExpression) name = ((IdentifierExpression)acc.AccessExpression).ValueStringHash; else if (acc.AccessExpression is TemplateInstanceExpression) name = ((TemplateInstanceExpression)acc.AccessExpression).TemplateIdHash; else return null; var methodMatches = new List<MemberSymbol>(); if(ctxt.ParseCache!=null) foreach (var pc in ctxt.ParseCache) { var tempResults=pc.UfcsCache.FindFitting(ctxt, acc.Location, firstArgument, name); if (tempResults != null) foreach (var m in tempResults) { ctxt.PushNewScope(m); if (m.TemplateParameters != null && m.TemplateParameters.Length != 0) { var ov = TemplateInstanceHandler.DeduceParamsAndFilterOverloads( new[] { new MemberSymbol(m, null, acc) }, new[] { firstArgument }, true, ctxt); if (ov == null || ov.Length == 0) continue; var ms = (DSymbol)ov[0]; ctxt.CurrentContext.IntroduceTemplateParameterTypes(ms); } var mr = TypeDeclarationResolver.HandleNodeMatch(m, ctxt, null, acc) as MemberSymbol; if (mr!=null) { mr.FirstArgument = firstArgument; mr.DeducedTypes = ctxt.CurrentContext.DeducedTemplateParameters.ToReadonly(); mr.IsUFCSResult = true; methodMatches.Add(mr); } ctxt.Pop(); } } return methodMatches.Count == 0 ? null : methodMatches.ToArray(); }
public static void AddArrayProperties(ISemantic rr, ICompletionDataGenerator cdg, ArrayDecl ArrayDecl = null) { CreateArtificialProperties(ArrayProps, cdg, ArrayDecl); cdg.Add(new DVariable { Name = "ptr", Description = "Returns pointer to the array", Type = new PointerDecl(ArrayDecl == null ? new DTokenDeclaration(DTokens.Void) : ArrayDecl.ValueType) }); }
ISemantic E(AssignExpression x, ISemantic lValue=null) { if (!eval) return E(x.LeftOperand); var l = TryGetValue(lValue ?? E(x.LeftOperand)); //TODO return null; }
public static void AddArrayProperties(ISemantic rr, ICompletionDataGenerator cdg, ArrayDecl ArrayDecl = null) { CreateArtificialProperties(ArrayProps, cdg, ArrayDecl); cdg.Add(new DVariable { Name = "ptr", Description = "Returns pointer to the array", Type = new PointerDecl(ArrayDecl == null ? new DTokenDeclaration(DTokens.Void) : ArrayDecl.ValueType) }); }
public static List<AbstractType> TryResolveUFCS( ISemantic firstArgument,int nameHash,CodeLocation nameLoc, ResolutionContext ctxt, ISyntaxRegion nameSr = null) { if (firstArgument == null || ctxt == null) return new List<AbstractType>(); var us = new UFCSResolver (ctxt, firstArgument, nameHash, nameSr); us.IterateThroughScopeLayers (nameLoc, MemberFilter.Methods | MemberFilter.Templates); return us.matches; }
internal TopChainer(ISemantic prev, Nullable <long> top, bool isWithTies, int overloader) : base(((ISelect)prev.Translate(new SemqContext(((DbNode)prev).Root), null)).Select()) { if (top != null) { Prev.SetTop((long)top, isWithTies); } else { SkipBuild = true; } }
static AbstractTooltipContent BuildTooltipContent(ISemantic res) { // Only show one description for items sharing descriptions string description = res is DSymbol ? ((DSymbol)res).Definition.Description : ""; return new AbstractTooltipContent { ResolveResult = res, Title = (res is ModuleSymbol ? ((ModuleSymbol)res).Definition.FileName : res.ToString()), Description = description }; }
public static void Generate(ISemantic rr, ResolutionContext ctxt, IEditorData ed, ICompletionDataGenerator gen) { if(ed.ParseCache!=null) foreach (var pc in ed.ParseCache) if (pc != null && pc.UfcsCache != null && pc.UfcsCache.CachedMethods != null) { var r=pc.UfcsCache.FindFitting(ctxt, ed.CaretLocation, rr); if(r!=null) foreach (var m in r) gen.Add(m); } }
public static bool IsUfcsResult(AbstractType t, out ISemantic firstArgument) { var o = t.Tag as UfcsTag; if (o == null) { firstArgument = null; return false; } firstArgument = o.firstArgument; return true; }
public static AbstractType Get(ISemantic s) { //FIXME: What to do with the other overloads? if (s is InternalOverloadValue) return (s as InternalOverloadValue).Overloads[0]; if (s is VariableValue) return (s as VariableValue).Member; if (s is ISymbolValue) return (s as ISymbolValue).RepresentedType; return s as AbstractType; }
static AbstractTooltipContent BuildTooltipContent(ISemantic res) { // Only show one description for items sharing descriptions var ds = res as DSymbol; var description = ds != null ? ds.Definition.Description : ""; return new AbstractTooltipContent { ResolveResult = res, Title = BuildTooltipTitle(res), Description = description }; }
public bool Handle(TemplateParameter parameter, ISemantic argumentToAnalyze) { // Packages aren't allowed at all if (argumentToAnalyze is PackageSymbol) return false; // Module symbols can be used as alias only if (argumentToAnalyze is ModuleSymbol && !(parameter is TemplateAliasParameter)) return false; //TODO: Handle __FILE__ and __LINE__ correctly - so don't evaluate them at the template declaration but at the point of instantiation /* * Introduce previously deduced parameters into current resolution context * to allow value parameter to be of e.g. type T whereas T is already set somewhere before */ DeducedTypeDictionary _prefLocalsBackup = null; if (ctxt != null && ctxt.CurrentContext != null) { _prefLocalsBackup = ctxt.CurrentContext.DeducedTemplateParameters; var d = new DeducedTypeDictionary(); foreach (var kv in TargetDictionary) if (kv.Value != null) d[kv.Key] = kv.Value; ctxt.CurrentContext.DeducedTemplateParameters = d; } bool res = false; if (parameter is TemplateAliasParameter) res = Handle((TemplateAliasParameter)parameter, argumentToAnalyze); else if (parameter is TemplateThisParameter) res = Handle((TemplateThisParameter)parameter, argumentToAnalyze); else if (parameter is TemplateTypeParameter) res = Handle((TemplateTypeParameter)parameter, argumentToAnalyze); else if (parameter is TemplateValueParameter) res = Handle((TemplateValueParameter)parameter, argumentToAnalyze); else if (parameter is TemplateTupleParameter) res = Handle((TemplateTupleParameter)parameter, new[] { argumentToAnalyze }); if (ctxt != null && ctxt.CurrentContext != null) ctxt.CurrentContext.DeducedTemplateParameters = _prefLocalsBackup; return res; }
bool Handle(TemplateValueParameter p, ISemantic arg) { // Handle default arg case if (arg == null) { if (p.DefaultExpression != null) { var eval = Evaluation.EvaluateValue(p.DefaultExpression, ctxt); if (eval == null) return false; return Set(p, eval, 0); } else return false; } var valueArgument = arg as ISymbolValue; // There must be a constant expression given! if (valueArgument == null) return false; // Check for param type <-> arg expression type match var paramType = TypeDeclarationResolver.Resolve(p.Type, ctxt); if (paramType == null || paramType.Length == 0) return false; if (valueArgument.RepresentedType == null || !ResultComparer.IsImplicitlyConvertible(paramType[0], valueArgument.RepresentedType)) return false; // If spec given, test for equality (only ?) if (p.SpecializationExpression != null) { var specVal = Evaluation.EvaluateValue(p.SpecializationExpression, ctxt); if (specVal == null || !SymbolValueComparer.IsEqual(specVal, valueArgument)) return false; } return Set(p, arg, 0); }
public static List<AbstractType> TryResolveUFCS( ISemantic firstArgument, PostfixExpression_Access acc, ResolutionContext ctxt) { if (firstArgument == null || acc == null || ctxt == null) return new List<AbstractType>(); int name; if (acc.AccessExpression is IdentifierExpression) name = ((IdentifierExpression)acc.AccessExpression).ValueStringHash; else if (acc.AccessExpression is TemplateInstanceExpression) name = ((TemplateInstanceExpression)acc.AccessExpression).TemplateIdHash; else return new List<AbstractType> (); return TryResolveUFCS (firstArgument, name, acc.PostfixForeExpression.Location, ctxt, acc); }
bool Handle(TemplateTypeParameter p, ISemantic arg) { // if no argument given, try to handle default arguments if (arg == null) return TryAssignDefaultType(p); // If no spezialization given, assign argument immediately if (p.Specialization == null) return Set(p, arg, 0); bool handleResult= HandleDecl(null,p.Specialization,arg); if (!handleResult) return false; // Apply the entire argument to parameter p if there hasn't been no explicit association yet if (TargetDictionary[p.NameHash] == null) TargetDictionary[p.NameHash] = new TemplateParameterSymbol(p, arg); return true; }
public static MemberSymbol[] TryResolveUFCS( ISemantic firstArgument, PostfixExpression_Access acc, ResolverContextStack ctxt) { if (ctxt == null) return null; var name=""; if (acc.AccessExpression is IdentifierExpression) name = ((IdentifierExpression)acc.AccessExpression).Value as string; else if (acc.AccessExpression is TemplateInstanceExpression) name = ((TemplateInstanceExpression)acc.AccessExpression).TemplateIdentifier.Id; else return null; var methodMatches = new List<MemberSymbol>(); if(ctxt.ParseCache!=null) foreach (var pc in ctxt.ParseCache) { var tempResults=pc.UfcsCache.FindFitting(ctxt, acc.Location, firstArgument, name); if (tempResults != null) foreach (var m in tempResults) { var mr = TypeDeclarationResolver.HandleNodeMatch(m, ctxt, TypeDeclarationResolver.Convert(firstArgument), acc) as MemberSymbol; if (mr!=null) { mr.IsUFCSResult = true; methodMatches.Add(mr); } } } return methodMatches.Count == 0 ? null : methodMatches.ToArray(); }
public bool HandleDecl(TemplateTypeParameter p ,ITypeDeclaration td, ISemantic rr) { if (td is IdentifierDeclaration) return HandleDecl(p,(IdentifierDeclaration)td, rr); if (TemplateInstanceHandler.IsNonFinalArgument(rr)) { foreach (var tp in this.TargetDictionary.Keys.ToList()) if (TargetDictionary[tp] == null) TargetDictionary[tp] = new TemplateParameterSymbol(tp, null); return true; } //HACK Ensure that no information gets lost by using this function // -- getting a value but requiring an abstract type and just extract it from the value - is this correct behaviour? var at = AbstractType.Get(rr); if (td is ArrayDecl) return HandleDecl(p,(ArrayDecl)td, DResolver.StripMemberSymbols(at) as AssocArrayType); else if (td is DTokenDeclaration) return HandleDecl((DTokenDeclaration)td, at); else if (td is DelegateDeclaration) return HandleDecl(p, (DelegateDeclaration)td, DResolver.StripMemberSymbols(at) as DelegateType); else if (td is PointerDecl) return HandleDecl(p, (PointerDecl)td, DResolver.StripMemberSymbols(at) as PointerType); else if (td is MemberFunctionAttributeDecl) return HandleDecl(p,(MemberFunctionAttributeDecl)td, at); else if (td is TypeOfDeclaration) return HandleDecl((TypeOfDeclaration)td, at); else if (td is VectorDeclaration) return HandleDecl((VectorDeclaration)td, at); else if (td is TemplateInstanceExpression) return HandleDecl(p,(TemplateInstanceExpression)td, at); return false; }
/// <summary> /// /// </summary> /// <param name="dm"></param> /// <param name="args"></param> /// <param name="baseValueProvider">Required for evaluating missing default parameters.</param> public static bool AssignCallArgumentsToIC(DMethod dm, ISymbolValue[] args, AbstractSymbolValueProvider baseValueProvider, out Dictionary<DVariable,ISymbolValue> targetArgs) { targetArgs = new Dictionary<DVariable, ISymbolValue>(); var argsRemaining = args != null ? args.Length : 0; int argu = 0; for (int para = 0; para < dm.Parameters.Count; para++) { var par = dm.Parameters[para] as DVariable; if (par.Type is VarArgDecl && argsRemaining > 0) { var va_args = new ISemantic[argsRemaining]; args.CopyTo(va_args, argu); argsRemaining=0; //TODO: Assign a value tuple to par if (++para < dm.Parameters.Count) return false; } if (argsRemaining > 0) { targetArgs[par] = args[argu++]; argsRemaining--; } else if (par.Initializer != null) { targetArgs[par] = Evaluation.EvaluateValue(par.Initializer, baseValueProvider); } else return false; } return argsRemaining == 0; }
static AbstractTooltipContent BuildTooltipContent(ISemantic res) { if (res is ISymbolValue) { var sv = res as ISymbolValue; if (sv is TypeValue) return new AbstractTooltipContent { ResolveResult = res, Title = sv.RepresentedType.ToString() }; return new AbstractTooltipContent { ResolveResult = res, Title = "(" + sv.RepresentedType + ") "+sv.ToCode() }; } // Only show one description for items sharing descriptions string description = res is DSymbol ? ((DSymbol)res).Definition.Description : ""; return new AbstractTooltipContent { ResolveResult = res, Title = (res is ModuleSymbol ? ((ModuleSymbol)res).Definition.FileName : res.ToString()), Description = description }; }
bool Handle(TemplateTypeParameter p, ISemantic arg) { // if no argument given, try to handle default arguments if (arg == null) { if (p.Default == null) return false; else { IStatement stmt = null; ctxt.PushNewScope(DResolver.SearchBlockAt(ctxt.ScopedBlock.NodeRoot as IBlockNode, p.Default.Location, out stmt)); ctxt.ScopedStatement = stmt; var defaultTypeRes = TypeDeclarationResolver.Resolve(p.Default, ctxt); bool b = false; if (defaultTypeRes != null) b = Set(p, defaultTypeRes.First()); ctxt.Pop(); return b; } } // If no spezialization given, assign argument immediately if (p.Specialization == null) return Set(p, arg); bool handleResult= HandleDecl(p,p.Specialization,arg); if (!handleResult) return false; // Apply the entire argument to parameter p if there hasn't been no explicit association yet if (!TargetDictionary.ContainsKey(p.Name) || TargetDictionary[p.Name] == null) TargetDictionary[p.Name] = new TemplateParameterSymbol(p, arg); return true; }
static string BuildTooltipTitle(ISemantic res) { if (res is TypeValue) res = (res as TypeValue).RepresentedType; else if (res is ISymbolValue) { var sv = res as ISymbolValue; return "(" + BuildTooltipTitle(sv.RepresentedType) + ") " + sv.ToCode (); } else if (res is PackageSymbol) return "(Package) " + (res as PackageSymbol).Package.ToString (); var ds = res as DSymbol; if (ds == null) return string.Empty; if (ds is ModuleSymbol) return "(Module) " + (ds as ModuleSymbol).Definition.FileName; var bt = DResolver.StripMemberSymbols (ds.Base); if ((ds is MemberSymbol || ds is TemplateParameterSymbol) && bt != null) { return string.Format("{1}\r\n(Deduced Type: {0})", bt.ToString(), ds.Definition.ToString()); } else return ds.ToCode (); }
/// <summary> /// Returns false if the item has already been set before and if the already set item is not equal to 'r'. /// Inserts 'r' into the target dictionary and returns true otherwise. /// </summary> bool Set(TemplateParameter p, ISemantic r, int nameHash) { if (p == null) { if (nameHash != 0 && TargetDictionary.ExpectedParameters != null) { foreach (var tpar in TargetDictionary.ExpectedParameters) if (tpar.NameHash == nameHash) { p = tpar; break; } } } if (p == null) { ctxt.LogError (null, "no fitting template parameter found!"); return false; } // void call(T)(T t) {} // call(myA) -- T is *not* myA but A, so only assign myA's type to T. if (p is TemplateTypeParameter) { var newR = Resolver.TypeResolution.DResolver.StripMemberSymbols(AbstractType.Get(r)); if (newR != null) r = newR; } TemplateParameterSymbol rl; if (!TargetDictionary.TryGetValue(p, out rl) || rl == null) { TargetDictionary[p] = new TemplateParameterSymbol(p, r); return true; } else { if (ResultComparer.IsEqual(rl.Base, r)) { return true; } else { // Error: Ambiguous assignment } TargetDictionary[p] = new TemplateParameterSymbol(p, r); return false; } }
bool Handle(TemplateThisParameter p, ISemantic arg) { // Only special handling required for method calls return Handle(p.FollowParameter,arg); }