public override void LoadRules(IniFile.IniSection rules) { base.LoadRules(rules); WeaponType = rules.ReadEnum<WeaponType>("WeaponType", null); Action = rules.ReadEnum<Action>("Action", Action.MultiMissile); IsPowered = rules.ReadBool("IsPowered", true); DisableableFromShell = rules.ReadBool("DisableableFromShell"); SidebarFlashTabFrames = rules.ReadInt("SidebarFlashTabFrames", -1); AIDefendAgainst = rules.ReadBool("AIDefendAgainst"); PreClick = rules.ReadBool("PreClick"); PostClick = rules.ReadBool("PostClick"); ShowTimer = rules.ReadBool("ShowTimer"); SpecialSound = Get<Sound>(rules.ReadString("SpecialSound")); StartSound = Get<Sound>(rules.ReadString("StartSound")); Range = rules.ReadFloat("Range", 0); LineMultiplier = rules.ReadInt("LineMultiplier", 0); Type = rules.ReadEnum<AbstractType>("Type", null); PreDependent = rules.ReadEnum<WeaponType>("PreDependent", null); AuxBuilding = Get<BuildingType>(rules.ReadString("AuxBuilding")); UseChargeDrain = rules.ReadBool("UseChargeDrain"); ManualControl = rules.ReadBool("ManualControl"); RechargeTime = rules.ReadFloat("RechargeTime", 5.0f); SidebarImage = rules.ReadString("SidebarImage", ""); }
bool IsMoreSpecialized(AbstractType r1, AbstractType r2) { // Probably an issue: Assume a type to be more specialized if it's a symbol if (r1 is DSymbol && !(r2 is DSymbol)) return true; else if (r2 is DSymbol && !(r1 is DSymbol)) return false; else if (!(r1 is DSymbol && r2 is DSymbol)) return false; var dn1 = ((DSymbol)r1).Definition; var dn2 = ((DSymbol)r2).Definition; if (dn1 == null || dn1.TemplateParameters == null || dn2 == null || dn2.TemplateParameters == null) return false; var dummyList = new Dictionary<TemplateParameter, ISemantic>(); foreach (var t in dn1.TemplateParameters) dummyList.Add(t, null); var tp1_enum = dn1.TemplateParameters.GetEnumerator(); var tp2_enum = dn2.TemplateParameters.GetEnumerator(); while (tp1_enum.MoveNext() && tp2_enum.MoveNext()) if (!IsMoreSpecialized((TemplateParameter)tp1_enum.Current, (TemplateParameter)tp2_enum.Current, dummyList)) return false; return true; }
static bool HandleDecl(DTokenDeclaration tk, AbstractType r) { if (r is PrimitiveType) return tk.Token == ((PrimitiveType)r).TypeToken; return false; }
static bool HandleDecl(DTokenDeclaration tk, AbstractType r) { if (r is PrimitiveType) return ResultComparer.IsPrimitiveTypeImplicitlyConvertible(((PrimitiveType)r).TypeToken, tk.Token); return false; }
protected override void HandleItem (INode n, AbstractType resolvedCurrentScope) { var res = TypeDeclarationResolver.HandleNodeMatch (n, ctxt, resolvedCurrentScope, idObject); if (res != null) matches_types.Add (res); stopEnumeration = true; }
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; }
private bool evalIsExpression_WithAliases(IsExpression isExpression, AbstractType typeToCheck) { /* * Note: It's needed to let the abstract ast scanner also scan through IsExpressions etc. * in order to find aliases and/or specified template parameters! */ var expectedTemplateParams = new TemplateParameter[isExpression.TemplateParameterList == null ? 1 : (isExpression.TemplateParameterList.Length + 1)]; expectedTemplateParams [0] = isExpression.ArtificialFirstSpecParam; if(expectedTemplateParams.Length > 1) isExpression.TemplateParameterList.CopyTo (expectedTemplateParams, 1); var tpl_params = new DeducedTypeDictionary(expectedTemplateParams); var tpd = new TemplateParameterDeduction(tpl_params, ctxt); bool retTrue = false; if (isExpression.EqualityTest) // 6. { // a) if (isExpression.TypeSpecialization != null) { tpd.EnforceTypeEqualityWhenDeducing = true; retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck); tpd.EnforceTypeEqualityWhenDeducing = false; } else // b) { var r = evalIsExpression_EvalSpecToken(isExpression, typeToCheck, true); retTrue = r.Item1; tpl_params[isExpression.ArtificialFirstSpecParam] = new TemplateParameterSymbol(isExpression.ArtificialFirstSpecParam, r.Item2); } } else // 5. retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck); if (retTrue && isExpression.TemplateParameterList != null) foreach (var p in isExpression.TemplateParameterList) if (!tpd.Handle(p, tpl_params[p] != null ? tpl_params[p].Base : null)) return false; if (retTrue) { foreach (var kv in tpl_params) ctxt.CurrentContext.DeducedTemplateParameters[kv.Key] = kv.Value; } return retTrue; }
public ObjectCacheNode(string n, AbstractType t, ulong address) { if (string.IsNullOrEmpty(n)) { throw new ArgumentNullException("name", "Child name must not be empty!"); } if (t == null) { throw new ArgumentNullException("t", "Abstract type of '" + n + "' must not be null!"); } Name = n; NodeType = t; this.address = address; }
/// <summary> /// Used when evaluating traits. /// Evaluates the first argument to <param name="t">t</param>, /// takes the second traits argument, tries to evaluate it to a string, and puts it + the first arg into an postfix_access expression /// </summary> PostfixExpression_Access prepareMemberTraitExpression(TraitsExpression te, out AbstractType t) { if (te.Arguments != null && te.Arguments.Length == 2) { var tEx = te.Arguments[0]; t = DResolver.StripMemberSymbols(E(tEx, te)); if (t == null) { EvalError(te, "First argument didn't resolve to a type"); } else if (te.Arguments[1].AssignExpression != null) { var litEx = te.Arguments[1].AssignExpression; var eval_Backup = eval; eval = true; var v = E(litEx); eval = eval_Backup; if (v is ArrayValue && (v as ArrayValue).IsString) { var av = v as ArrayValue; // Mock up a postfix_access expression to ensure static properties & ufcs methods are checked either return(new PostfixExpression_Access { PostfixForeExpression = tEx.AssignExpression ?? new TypeDeclarationExpression(tEx.Type), AccessExpression = new IdentifierExpression(av.StringValue) { Location = litEx.Location, EndLocation = litEx.EndLocation }, EndLocation = litEx.EndLocation }); } else { EvalError(te.Arguments[1].AssignExpression, "Second traits argument must evaluate to a string literal", v); } } else { EvalError(te, "Second traits argument must be an expression"); } } t = null; return(null); }
bool HandleDecl(TemplateTypeParameter p, MemberFunctionAttributeDecl m, AbstractType r) { if (r == null || r.Modifier == 0) { return(false); } // Modifiers must be equal on both sides if (m.Modifier != r.Modifier) { return(false); } // Now compare the type inside the parentheses with the given type 'r' return(m.InnerType != null && HandleDecl(p, m.InnerType, r)); }
public static AbstractType EvaluateType(IExpression x, ResolutionContext ctxt) { var ev = new Evaluation(ctxt); ISemantic t = null; if (!Debugger.IsAttached) { try { t = ev.E(x); } catch { } } else { t = ev.E(x); } return(AbstractType.Get(t)); }
/// <summary> /// Processes the field. /// Determines the type of field, before passing it onto the more specific parsing functions. /// </summary> /// <param name="item">The item.</param> /// <param name="fieldDescription">The field description.</param> /// <param name="fieldCount">The field count.</param> /// <param name="parentNode">The parent node.</param> private static void ProcessField(IType item, string fieldDescription, string fieldCount, FieldGroup parentNode) { if (item.GetType().IsSubclassOf(typeof(AbstractPrimitive))) { ProcessPrimitiveField((AbstractPrimitive)item, fieldDescription, fieldCount, parentNode); } else if (item.GetType() == typeof(Varies)) { ProcessVaries((Varies)item, fieldDescription, fieldCount, parentNode); } else if (item.GetType().GetInterfaces().Contains(typeof(IComposite))) { AbstractType dataType = (AbstractType)item; string desc = string.IsNullOrEmpty(dataType.Description) ? fieldDescription : dataType.Description; ProcessCompositeField((IComposite)item, desc, fieldCount, parentNode); } }
private bool evalIsExpression_WithAliases(IsExpression isExpression, AbstractType typeToCheck) { /* * Note: It's needed to let the abstract ast scanner also scan through IsExpressions etc. * in order to find aliases and/or specified template parameters! */ var expectedTemplateParams = new TemplateParameter[isExpression.TemplateParameterList.Length + 1]; expectedTemplateParams [0] = isExpression.ArtificialFirstSpecParam; if(expectedTemplateParams.Length > 1) isExpression.TemplateParameterList.CopyTo (expectedTemplateParams, 1); var tpl_params = new DeducedTypeDictionary(expectedTemplateParams); var tpd = new TemplateParameterDeduction(tpl_params, ctxt); bool retTrue = false; if (isExpression.EqualityTest) // 6. { // a) if (isExpression.TypeSpecialization != null) { tpd.EnforceTypeEqualityWhenDeducing = true; retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck); tpd.EnforceTypeEqualityWhenDeducing = false; } else // b) { var r = evalIsExpression_EvalSpecToken(isExpression, typeToCheck, true); retTrue = r.Item1; tpl_params[isExpression.TypeAliasIdentifierHash] = new TemplateParameterSymbol(null, r.Item2); } } else // 5. retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck); if (retTrue && isExpression.TemplateParameterList != null) foreach (var p in isExpression.TemplateParameterList) if (!tpd.Handle(p, tpl_params[p.NameHash] != null ? tpl_params[p.NameHash].Base : null)) return false; //TODO: Put all tpl_params results into the resolver context or make a new scope or something! return retTrue; }
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, at as AssocArrayType)); } else if (td is DTokenDeclaration) { return(HandleDecl((DTokenDeclaration)td, at)); } else if (td is DelegateDeclaration) { return(HandleDecl(p, (DelegateDeclaration)td, at as DelegateType)); } else if (td is PointerDecl) { return(HandleDecl(p, (PointerDecl)td, 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); }
public static AbstractType Resolve(ArrayDecl ad, ResolutionContext ctxt) { var valueTypes = Resolve(ad.ValueType, ctxt); ctxt.CheckForSingleResult(valueTypes, ad); AbstractType valueType = null; AbstractType keyType = null; int fixedArrayLength = -1; if (valueTypes != null && valueTypes.Length != 0) { valueType = valueTypes[0]; } ISymbolValue val; keyType = ResolveKey(ad, out fixedArrayLength, out val, ctxt); if (keyType == null || (keyType is PrimitiveType && ((PrimitiveType)keyType).TypeToken == DTokens.Int)) { if (fixedArrayLength >= 0) { // D Magic: One might access tuple items directly in the pseudo array declaration - so stuff like Tup[0] i; becomes e.g. int i; var dtup = DResolver.StripMemberSymbols(valueType) as DTuple; if (dtup == null) { return(new ArrayType(valueType, fixedArrayLength, ad)); } if (dtup.Items != null && fixedArrayLength < dtup.Items.Length) { return(AbstractType.Get(dtup.Items [fixedArrayLength])); } else { ctxt.LogError(ad, "TypeTuple only consists of " + (dtup.Items != null ? dtup.Items.Length : 0) + " items. Can't access item at index " + fixedArrayLength); return(null); } } return(new ArrayType(valueType, ad)); } return(new AssocArrayType(valueType, keyType, ad)); }
//TODO: Für semantisches Highlighting den TypeRefFinder benutzen und einfach pauschal alle Ids entsprechend highlighten public static TooltipInformation Create(AbstractType t, ColorScheme st, bool templateParamCompletion = false, int currentMethodParam = -1) { var markupGen = new TooltipMarkupGen(st); var tti = new TooltipInformation { SignatureMarkup = markupGen.GenTooltipSignature(t, templateParamCompletion, currentMethodParam) }; var ds = t as DSymbol; DNode n; if (ds != null && (n = ds.Definition) != null) { CreateTooltipBody(markupGen, n, tti); } return(tti); }
bool HandleDecl(VectorDeclaration v, AbstractType r) { if (r.DeclarationOrExpressionBase is VectorDeclaration) { var v_res = ExpressionTypeEvaluation.EvaluateType(v.Id, ctxt); var r_res = ExpressionTypeEvaluation.EvaluateType(((VectorDeclaration)r.DeclarationOrExpressionBase).Id, ctxt); if (v_res == null || r_res == null) { return(false); } else { return(ResultComparer.IsImplicitlyConvertible(r_res, v_res)); } } return(false); }
bool IsMoreSpecialized(AbstractType r1, AbstractType r2) { // Probably an issue: Assume a type to be more specialized if it's a symbol if (r1 is DSymbol && !(r2 is DSymbol)) { return(true); } else if (r2 is DSymbol && !(r1 is DSymbol)) { return(false); } else if (!(r1 is DSymbol && r2 is DSymbol)) { return(false); } var dn1 = ((DSymbol)r1).Definition; var dn2 = ((DSymbol)r2).Definition; if (dn1 == null || dn1.TemplateParameters == null || dn2 == null || dn2.TemplateParameters == null) { return(false); } var dummyList = new Dictionary <TemplateParameter, ISemantic>(); foreach (var t in dn1.TemplateParameters) { dummyList.Add(t, null); } var tp1_enum = dn1.TemplateParameters.GetEnumerator(); var tp2_enum = dn2.TemplateParameters.GetEnumerator(); while (tp1_enum.MoveNext() && tp2_enum.MoveNext()) { if (!IsMoreSpecialized((TemplateParameter)tp1_enum.Current, (TemplateParameter)tp2_enum.Current, dummyList)) { return(false); } } return(true); }
/// <summary> /// Returns affected AbstractType /// </summary> /// <param name="bu"></param> /// <param name="agency"></param> /// <param name="preloadedAbstractTypes"></param> /// <returns></returns> public async Task <AbstractType> CreateOrUpdatePseudoAgency( AbstractType bu, Agency agency, Dictionary <Tuple <Guid, Guid>, AbstractType> preloadedAbstractTypes) { var key = new Tuple <Guid, Guid>(bu.Id, agency.Id); AbstractType agencyAbstractType; if (!preloadedAbstractTypes.ContainsKey(key)) { agencyAbstractType = await AddAgencyAbstractType(agency, bu); preloadedAbstractTypes.Add(key, agencyAbstractType); } else { agencyAbstractType = preloadedAbstractTypes[key]; } return(agencyAbstractType); }
public async Task <AbstractType> AddAgencyAbstractType(Agency agency, AbstractType abstractType) { var newAbstractType = new AbstractType { Id = Guid.NewGuid(), Agency = agency, ParentId = abstractType.Id, Type = AbstractObjectType.Agency.ToString() }; _efContext.AbstractType.Add(newAbstractType); newAbstractType.UserGroups = await _permissionService.CreateDomainNode( typeof(AbstractType).Name.ToSnakeCase(), newAbstractType.ParentId, newAbstractType.Id ); return(newAbstractType); }
public TechnoPair(INIEntity ent, string index, AbstractType abstractType = AbstractType.RegName, IndexType indexType = IndexType.Index) { Index = index; Name = ent["Name"]; RegName = ent.Name; UIName = ent["UIName"]; switch (indexType) { default: case IndexType.Index: abst = Index; break; case IndexType.Name: abst = Name; Index = Name; break; case IndexType.RegName: abst = RegName; Index = RegName; break; } switch (abstractType) { default: case AbstractType.RegName: abst += " " + RegName; break; case AbstractType.Name: abst += " " + Name; break; case AbstractType.UIName: abst += " " + UIName; break; case AbstractType.IndexOnly: abst += ""; break; } }
AbstractType GetTheMoreSpecialized(AbstractType r1, AbstractType r2) { if (r1 == null || r2 == null) return null; if (IsMoreSpecialized(r1, r2)) { if (IsMoreSpecialized(r2, r1)) return null; else return r1; } else { if (IsMoreSpecialized(r2, r1)) return r2; else return null; } }
bool HandleDecl(TemplateTypeParameter p, MemberFunctionAttributeDecl m, AbstractType r) { if (r == null || r.Modifier == 0) { return(false); } // Modifiers must be equal on both sides if (m.Modifier != r.Modifier) { return(false); } // Strip modifier, but: immutable(int[]) becomes immutable(int)[] ?! AbstractType newR; if (r is AssocArrayType) { var aa = r as AssocArrayType; var clonedValueType = aa.Modifier != r.Modifier ? aa.ValueType.Clone(false) : aa.ValueType; clonedValueType.Modifier = r.Modifier; var at = aa as ArrayType; if (at != null) { newR = at.IsStaticArray ? new ArrayType(clonedValueType, at.FixedLength, r.DeclarationOrExpressionBase) : new ArrayType(clonedValueType, r.DeclarationOrExpressionBase); } else { newR = new AssocArrayType(clonedValueType, aa.KeyType, r.DeclarationOrExpressionBase); } } else { newR = r.Clone(false); newR.Modifier = 0; } // Now compare the type inside the parentheses with the given type 'r' return(m.InnerType != null && HandleDecl(p, m.InnerType, newR)); }
protected async Task <Guid> CreateAgencyIfNotExists(string gdamId = null, string agencyName = null) { gdamId = gdamId ?? "Test gdam agency id"; agencyName = agencyName ?? "Test Agency"; var existing = await EFContext.Agency.FirstOrDefaultAsync(a => a.GdamAgencyId == gdamId && a.Name == agencyName); if (existing != null) { return(existing.Id); } var abstractType = EFContext.AbstractType.FirstOrDefault(a => a.Type == core.Constants.AccessObjectType.Agency && a.Parent.Type == core.Constants.AccessObjectType.Module); var country = new Country { Name = "Test coutry name", Iso = "USA" }; EFContext.Country.Add(country); var agency = new Agency { Name = agencyName, CountryId = country.Id, GdamAgencyId = gdamId, Labels = new[] { "costPG", "CM_Prime_P&G", $"{plugins.Constants.PurchaseOrder.VendorSapIdLabelPrefix}TestSAPVendorCode" } }; var agencyAbstractType = new AbstractType { Agency = agency, Type = AbstractObjectType.Agency.ToString(), ObjectId = agency.Id, ParentId = abstractType.Id }; EFContext.Add(agencyAbstractType); await EFContext.SaveChangesAsync(); return(agency.Id); }
public static AbstractType[] HandleNodeMatches( IEnumerable <INode> matches, ResolutionContext ctxt, AbstractType resultBase = null, ISyntaxRegion typeDeclaration = null) { // Abbreviate a foreach-loop + List alloc var ll = matches as IList <INode>; if (ll != null && ll.Count == 1) { return new[] { ll[0] == null ? null : HandleNodeMatch(ll[0], ctxt, resultBase, typeDeclaration) } } ; if (matches == null) { return(new AbstractType[0]); } var vis = new NodeMatchHandleVisitor { ctxt = ctxt, resultBase = resultBase, typeBase = typeDeclaration }; var rl = new List <AbstractType>(); foreach (var m in matches) { if (m == null) { continue; } var res = HandleNodeMatch(m, ctxt, resultBase, typeDeclaration, vis); if (res != null) { rl.Add(res); } } return(rl.ToArray()); }
static AbstractType DeduceEponymousTemplate(EponymousTemplateType ept, ResolutionContext ctxt) { if (ept.Definition.Initializer == null) { ctxt.LogError(ept.Definition, "Can't deduce type from empty initializer!"); return(null); } // Introduce the deduced params to the current resolution context ctxt.CurrentContext.IntroduceTemplateParameterTypes(ept); // Get actual overloads AbstractType deducedType = null; deducedType = new MemberSymbol(ept.Definition, Evaluation.EvaluateType(ept.Definition.Initializer, ctxt), null, ept.DeducedTypes); //ept; //Evaluation.EvaluateType (ept.Definition.Initializer, ctxt); // Undo context-related changes ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals(ept); return(deducedType); }
protected async Task <A5Agency> PrepareTestData(params string[] labels) { var gdamAgencyId = "gdamAgencyId1"; var a5Agency = await GetA5Agency(); a5Agency._id = gdamAgencyId; if (labels != null) { var labelz = a5Agency._cm.Common.Labels.ToList(); labelz.AddRange(labels); a5Agency._cm.Common.Labels = labelz.ToArray(); } var costAgency = new Agency { Id = Guid.NewGuid(), GdamAgencyId = gdamAgencyId, Labels = a5Agency._cm.Common.Labels }; var countryIso = a5Agency._cm.Common.Address.Country.FirstOrDefault(); var agencyAbstractType = new AbstractType { ObjectId = costAgency.Id }; var defaultCurrecny = new Currency { DefaultCurrency = true, Code = "USD" }; var country = new Country { Iso = countryIso }; EFContext.AbstractType.Add(agencyAbstractType); EFContext.Agency.Add(costAgency); EFContext.Currency.Add(defaultCurrecny); EFContext.Country.Add(country); EFContext.SaveChanges(); return(a5Agency); }
public static bool IsPrimitive(this AbstractType abstractType) { switch (abstractType) { case null: return(true); case BooleanType booleanType: case NumberType numberType: case StringType stringType: case FileType fileType: case EnumType enumType: return(true); case DateTimeType dateTimeType: case ModelType modelType: return(false); case ArrayType arrayType: return(arrayType.Inner.IsPrimitive()); case DictionaryType dictionaryType: return(dictionaryType.Key.IsPrimitive() && dictionaryType.Value.IsPrimitive()); default: throw new NotImplementedException($"Type {abstractType.GetType()} is not implemented."); } }
public void ResetAbst(AbstractType abstractType = AbstractType.RegName, IndexType indexType = IndexType.Index) { switch (indexType) { default: case IndexType.Index: abst = Index; break; case IndexType.Name: abst = Name; Index = Name; break; case IndexType.RegName: abst = RegName; Index = RegName; break; } switch (abstractType) { default: case AbstractType.RegName: abst += " " + RegName; break; case AbstractType.Name: abst += " " + Name; break; case AbstractType.UIName: abst += " " + UIName; break; case AbstractType.IndexOnly: abst += ""; break; } }
/// <summary> /// Since most expressions should return a single type only, it's not needed to use this function unless you might /// want to pay attention on (illegal) multiple overloads. /// </summary> public static AbstractType[] EvaluateTypes(IExpression x, ResolutionContext ctxt) { var ev = new Evaluation(ctxt); ISemantic t = null; if (!Debugger.IsAttached) { try { t = ev.E(x); } catch { } } else { t = ev.E(x); } if (t is InternalOverloadValue) { return(((InternalOverloadValue)t).Overloads); } return(t == null ? null : new[] { AbstractType.Get(t) }); }
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.Resolve(id, ctxt); ctxt.CheckForSingleResult(_r, id); return(_r != null && _r.Length != 0 && (EnforceTypeEqualityWhenDeducing ? ResultComparer.IsEqual(r, _r[0]) : ResultComparer.IsImplicitlyConvertible(r, _r[0]))); }
public static AbstractType ResolveType(IEditorData editor, ResolutionContext ctxt = null) { var o = GetScopedCodeObject(editor); if (ctxt == null) { ctxt = ResolutionContext.Create(editor, false); } AbstractType ret = null; CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () => { ctxt.Push(editor); var optionBackup = ctxt.CurrentContext.ContextDependentOptions; ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly; if (o is IExpression) { ret = ExpressionTypeEvaluation.EvaluateType((IExpression)o, ctxt, false); } else if (o is ITypeDeclaration) { ret = TypeDeclarationResolver.ResolveSingle((ITypeDeclaration)o, ctxt); } else if (o is INode) { ret = TypeDeclarationResolver.HandleNodeMatch(o as INode, ctxt); } ctxt.CurrentContext.ContextDependentOptions = optionBackup; }); return(ret); }
bool HandleDecl(TemplateTypeParameter parameter, TemplateInstanceExpression tix, AbstractType r) { /* * TODO: Scan down r for having at least one templateinstanceexpression as declaration base. * If a tix was found, check if the definition of the respective result base level * and the un-aliased identifier of the 'tix' parameter match. * Attention: if the alias represents an undeduced type (i.e. a type bundle of equally named type nodes), * it is only important that the definition is inside this bundle. * Therefore, it's needed to manually resolve the identifier, and look out for aliases or such unprecise aliases..confusing as s**t! * * If the param tix id is part of the template param list, the behaviour is currently undefined! - so instantly return false, I'll leave it as TODO/FIXME */ var paramTix_TemplateMatchPossibilities = ResolveTemplateInstanceId(tix); TemplateIntermediateType tixBasedArgumentType = null; var r_ = r as DSymbol; while (r_ != null) { if (r_.DeclarationOrExpressionBase is TemplateInstanceExpression) { var tit = r_ as TemplateIntermediateType; if (tit != null && CheckForTixIdentifierEquality(paramTix_TemplateMatchPossibilities, tit.Definition)) { tixBasedArgumentType = tit; break; } } r_ = r_.Base as DSymbol; } /* * This part is very tricky: * I still dunno what is allowed over here-- * * class Foo(T:Bar!E[],E) {} * ... * Foo!(Bar!string[]) f; -- E will be 'string' then * * class DerivateBar : Bar!string[] {} -- new Foo!DerivateBar() is also allowed, but now DerivateBar * obviously is not a template instance expression - it's a normal identifier only. */ if (tixBasedArgumentType != null) { var argEnum_given = ((TemplateInstanceExpression)tixBasedArgumentType.DeclarationOrExpressionBase).Arguments.GetEnumerator(); foreach (var p in tix.Arguments) { if (!argEnum_given.MoveNext() || argEnum_given.Current == null) return false; // Convert p to type declaration var param_Expected = ConvertToTypeDeclarationRoughly(p); if (param_Expected == null) return false; var result_Given = ExpressionTypeEvaluation.EvaluateType(argEnum_given.Current as IExpression, ctxt); if (result_Given == null || !HandleDecl(parameter, param_Expected, result_Given)) return false; } // Too many params passed.. if (argEnum_given.MoveNext()) return false; return true; } return false; }
/// <summary> /// Evaluates the identifier/template instance as usual. /// If the id points to a variable, the initializer/dynamic value will be evaluated using its initializer. /// /// If ImplicitlyExecute is false but value evaluation is switched on, an InternalOverloadValue-object will be returned /// that keeps all overloads passed via 'overloads' /// </summary> ISemantic TryDoCTFEOrGetValueRefs(AbstractType[] overloads, IExpression idOrTemplateInstance, bool ImplicitlyExecute = true, ISymbolValue[] executionArguments=null) { if (overloads == null || overloads.Length == 0){ EvalError(idOrTemplateInstance, "No symbols found"); return null; } var r = overloads[0]; const string ambigousExprMsg = "Ambiguous expression"; if(r is TemplateParameterSymbol) { var tps = (TemplateParameterSymbol)r; if((tps.Parameter is TemplateTypeParameter || tps.Parameter is TemplateAliasParameter)) return new TypeValue(tps.Base ?? tps); if(tps.Parameter is TemplateValueParameter) return tps.ParameterValue; if(tps.Parameter is TemplateTupleParameter) return new TypeValue(tps.Base); //TODO: Are there other evaluable template parameters? } else if (r is UserDefinedType || r is PackageSymbol || r is ModuleSymbol || r is AliasedType) { if (overloads.Length > 1) { EvalError(idOrTemplateInstance, ambigousExprMsg, overloads); return null; } return new TypeValue(r); } else if (r is MemberSymbol) { var mr = (MemberSymbol)r; // If we've got a function here, execute it if (mr.Definition is DMethod) { if (ImplicitlyExecute) { if (overloads.Length > 1){ EvalError(idOrTemplateInstance, ambigousExprMsg, overloads); return null; } return FunctionEvaluation.Execute(mr, executionArguments, ValueProvider); } return new InternalOverloadValue(overloads); } else if (mr.Definition is DVariable) { if (overloads.Length > 1) { EvalError(idOrTemplateInstance, ambigousExprMsg, overloads); return null; } return new VariableValue(mr); } } EvalError(idOrTemplateInstance, "Could neither execute nor evaluate symbol value", overloads); return null; }
/// <summary> /// Used when evaluating traits. /// Evaluates the first argument to <param name="t">t</param>, /// takes the second traits argument, tries to evaluate it to a string, and puts it + the first arg into an postfix_access expression /// </summary> PostfixExpression_Access prepareMemberTraitExpression(TraitsExpression te,out AbstractType t) { if(te.Arguments != null && te.Arguments.Length == 2) { var tEx = te.Arguments[0]; t = DResolver.StripMemberSymbols(E(tEx,te)); if(t == null) EvalError(te, "First argument didn't resolve to a type"); else if(te.Arguments[1].AssignExpression != null) { var litEx = te.Arguments[1].AssignExpression; var eval_Backup = eval; eval = true; var v = E(litEx); eval = eval_Backup; if(v is ArrayValue && (v as ArrayValue).IsString) { var av = v as ArrayValue; // Mock up a postfix_access expression to ensure static properties & ufcs methods are checked either return new PostfixExpression_Access{ PostfixForeExpression = tEx.AssignExpression ?? new TypeDeclarationExpression(tEx.Type), AccessExpression = new IdentifierExpression(av.StringValue) { Location = litEx.Location, EndLocation = litEx.EndLocation}, EndLocation = litEx.EndLocation }; } else EvalError(te.Arguments[1].AssignExpression, "Second traits argument must evaluate to a string literal", v); } else EvalError(te, "Second traits argument must be an expression"); } t = null; return null; }
public static string GetReferenceUrl(AbstractType result, ResolutionContext ctxt, CodeLocation caret) { if (result != null) { var n = DResolver.GetResultMember(result); if (n != null && n.NodeRoot is IAbstractSyntaxTree) { if (IsPhobosModule(n.NodeRoot as IAbstractSyntaxTree)) { var phobos_url = "phobos/" + (n.NodeRoot as IAbstractSyntaxTree).ModuleName.Replace('.', '_') + ".html"; if (!(n is IAbstractSyntaxTree)) { phobos_url += "#" + n.Name; } return(phobos_url); } } else if (result is PrimitiveType || result is DelegateType || result is AssocArrayType) { if (result.DeclarationOrExpressionBase is ITypeDeclaration) { return(GetRefUrlFor((ITypeDeclaration)result.DeclarationOrExpressionBase)); } else if (result.DeclarationOrExpressionBase is IExpression) { return(GetRefUrlFor((IExpression)result.DeclarationOrExpressionBase)); } } } if (ctxt.ScopedStatement != null) { return(GetRefUrlFor(ctxt.ScopedStatement, caret)); } else if (ctxt.ScopedBlock is DClassLike) { var dc = ctxt.ScopedBlock as DClassLike; if (dc.ClassType == DTokens.Class) { return("class.html"); } else if (dc.ClassType == DTokens.Interface) { return("interface.html"); } else if (dc.ClassType == DTokens.Struct || dc.ClassType == DTokens.Union) { return("struct.html"); } else if (dc.ClassType == DTokens.Template) { return("template.html"); } } else if (ctxt.ScopedBlock is DEnum) { return("enum.html"); } return(null); }
private bool evalIsExpression_NoAlias(IsExpression isExpression, AbstractType typeToCheck) { if (isExpression.TypeSpecialization != null) { var spec = DResolver.StripAliasSymbols(TypeDeclarationResolver.Resolve(isExpression.TypeSpecialization, ctxt)); return spec != null && spec.Length != 0 && (isExpression.EqualityTest ? ResultComparer.IsEqual(typeToCheck, spec[0]) : ResultComparer.IsImplicitlyConvertible(typeToCheck, spec[0], ctxt)); } return isExpression.EqualityTest && evalIsExpression_EvalSpecToken(isExpression, typeToCheck, false).Item1; }
bool HandleDecl(VectorDeclaration v, AbstractType r) { if (r.DeclarationOrExpressionBase is VectorDeclaration) { var v_res = ExpressionTypeEvaluation.EvaluateType(v.Id, ctxt); var r_res = ExpressionTypeEvaluation.EvaluateType(((VectorDeclaration)r.DeclarationOrExpressionBase).Id, ctxt); if (v_res == null || r_res == null) return false; else return ResultComparer.IsImplicitlyConvertible(r_res, v_res); } return false; }
public LValue(AbstractType nodeType) : base(nodeType) { }
void GetRawCallOverloads(PostfixExpression_MethodCall call, out AbstractType[] baseExpression, out ISymbolValue baseValue, out TemplateInstanceExpression tix) { baseExpression = null; baseValue = null; tix = null; if (call.PostfixForeExpression is PostfixExpression_Access) { var pac = (PostfixExpression_Access)call.PostfixForeExpression; tix = pac.AccessExpression as TemplateInstanceExpression; var vs = E(pac, null, false, false); if (vs != null && vs.Length != 0) { if (vs[0] is ISymbolValue) { baseValue = (ISymbolValue)vs[0]; baseExpression = new[] { baseValue.RepresentedType }; } else if (vs[0] is InternalOverloadValue) baseExpression = ((InternalOverloadValue)vs[0]).Overloads; else baseExpression = TypeDeclarationResolver.Convert(vs); } } else { // Explicitly don't resolve the methods' return types - it'll be done after filtering to e.g. resolve template types to the deduced one var optBackup = ctxt.CurrentContext.ContextDependentOptions; ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.DontResolveBaseTypes; if (call.PostfixForeExpression is TokenExpression) baseExpression = GetResolvedConstructorOverloads((TokenExpression)call.PostfixForeExpression, ctxt); else if (eval) { if (call.PostfixForeExpression is TemplateInstanceExpression) baseValue = E(tix = call.PostfixForeExpression as TemplateInstanceExpression, false) as ISymbolValue; else if (call.PostfixForeExpression is IdentifierExpression) baseValue = E((IdentifierExpression)call.PostfixForeExpression, false) as ISymbolValue; else baseValue = E(call.PostfixForeExpression) as ISymbolValue; if (baseValue is InternalOverloadValue) baseExpression = ((InternalOverloadValue)baseValue).Overloads; else if (baseValue != null) baseExpression = new[] { baseValue.RepresentedType }; else baseExpression = null; } else { if (call.PostfixForeExpression is TemplateInstanceExpression) baseExpression = GetOverloads(tix = (TemplateInstanceExpression)call.PostfixForeExpression, null, false); else if (call.PostfixForeExpression is IdentifierExpression) baseExpression = GetOverloads(call.PostfixForeExpression as IdentifierExpression, deduceParameters:false); else baseExpression = new[] { AbstractType.Get(E(call.PostfixForeExpression)) }; } ctxt.CurrentContext.ContextDependentOptions = optBackup; } }
public void FreezeFirstParameterByDirectBaseTypeShouldAssignSameInstanceToSecondParameter( [Frozen(Matching.DirectBaseType)] ConcreteType p1, AbstractType p2) { Assert.Equal(p1, p2); }
public StaticVariableValue(DVariable artificialVariable, AbstractType propType, IExpression baseExpression) : base(artificialVariable, propType, baseExpression) { }
public LValue(AbstractType nodeType, IExpression baseExpression) : base(ExpressionValueType.None, nodeType, baseExpression) { }
public VariableValue(DVariable variable, AbstractType variableType, IExpression baseExpression) : base(variableType, baseExpression) { this.Variable = variable; }
protected LValue(AbstractType nodeType) : base(nodeType) { }
public StaticVariableValue(DVariable artificialVariable, AbstractType propType) : base(new MemberSymbol(artificialVariable, propType, null)) { }
bool HandleDecl(TemplateTypeParameter p, MemberFunctionAttributeDecl m, AbstractType r) { if (r == null || r.Modifier == 0) return false; // Modifiers must be equal on both sides if (m.Modifier != r.Modifier) return false; // Strip modifier, but: immutable(int[]) becomes immutable(int)[] ?! AbstractType newR; if (r is AssocArrayType) { var aa = r as AssocArrayType; var clonedValueType = aa.Modifier != r.Modifier ? aa.ValueType.Clone(false) : aa.ValueType; clonedValueType.Modifier = r.Modifier; var at = aa as ArrayType; if (at != null) newR = at.IsStaticArray ? new ArrayType(clonedValueType, at.FixedLength, r.DeclarationOrExpressionBase) : new ArrayType(clonedValueType, r.DeclarationOrExpressionBase); else newR = new AssocArrayType(clonedValueType, aa.KeyType, r.DeclarationOrExpressionBase); } else { newR = r.Clone(false); newR.Modifier = 0; } // Now compare the type inside the parentheses with the given type 'r' return m.InnerType != null && HandleDecl(p, m.InnerType, newR); }
public ComponentWiseStaticFunction(IEnumerable <string> fields, AbstractType returnType, string name, AbstractType para0, string paraName0, string compString) { Fields = fields; ReturnType = returnType; Name = name; ParameterTypes = new[] { para0 }; ParameterNames = new[] { paraName0 }; CompString = compString; Static = true; Comment = "DUMMY << >> &&"; }
bool HandleDecl(TypeOfDeclaration t, AbstractType r) { // Can I enter some template parameter referencing id into a typeof specialization!? // class Foo(T:typeof(1)) {} ? var t_res = TypeDeclarationResolver.Resolve(t,ctxt); if (t_res == null) return false; return ResultComparer.IsImplicitlyConvertible(r,t_res); }
public static IEnumerable <string> LhsRhs(this AbstractType type) { yield return(type.NameThat + " lhs"); yield return(type.NameThat + " rhs"); }
/// <summary> /// See <see cref="Resolve"/> /// </summary> public static AbstractType ResolveSingle(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true) { var r = Resolve(id, ctxt, resultBases, filterForTemplateArgs); ctxt.CheckForSingleResult(r, id); return r != null && r.Length != 0 ? r[0] : null; }
/// <summary> /// Returns either all unfiltered and undeduced overloads of a member of a base type/value (like b from type a if the expression is a.b). /// if <param name="EvalAndFilterOverloads"></param> is false. /// If true, all overloads will be deduced, filtered and evaluated, so that (in most cases,) a one-item large array gets returned /// which stores the return value of the property function b that is executed without arguments. /// Also handles UFCS - so if filtering is wanted, the function becom /// </summary> ISemantic[] E(PostfixExpression_Access acc, ISemantic resultBase = null, bool EvalAndFilterOverloads = true, bool ResolveImmediateBaseType = true) { if (acc == null) return null; var baseExpression = resultBase ?? E(acc.PostfixForeExpression); if (acc.AccessExpression is NewExpression) { /* * This can be both a normal new-Expression as well as an anonymous class declaration! */ //TODO! return null; } AbstractType[] overloads; var optBackup = ctxt.CurrentContext.ContextDependentOptions; if (acc.AccessExpression is TemplateInstanceExpression) { if (!ResolveImmediateBaseType) ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.DontResolveBaseTypes; var tix = (TemplateInstanceExpression)acc.AccessExpression; // Do not deduce and filter if superior expression is a method call since call arguments' types also count as template arguments! overloads = GetOverloads(tix, new[] { AbstractType.Get(baseExpression) }, EvalAndFilterOverloads); if (!ResolveImmediateBaseType) ctxt.CurrentContext.ContextDependentOptions = optBackup; } else if (acc.AccessExpression is IdentifierExpression) { var id = acc.AccessExpression as IdentifierExpression; if (eval && EvalAndFilterOverloads && resultBase != null) { var staticPropResult = StaticProperties.TryEvalPropertyValue(ValueProvider, resultBase, id.ValueStringHash); if (staticPropResult != null) return new[]{staticPropResult}; } if (!ResolveImmediateBaseType) ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.DontResolveBaseTypes; overloads = GetOverloads(id, new[] { AbstractType.Get(baseExpression) }, EvalAndFilterOverloads); if (!ResolveImmediateBaseType) ctxt.CurrentContext.ContextDependentOptions = optBackup; } else { if (eval){ EvalError(acc, "Invalid access expression"); return null; } ctxt.LogError(acc, "Invalid post-dot expression"); return null; } /* * Try to get ufcs functions at first! * * void foo(int i) {} * * class A * { * void foo(int i, int a) {} * * void bar(){ * 123.foo(23); // Not allowed! * // Anyway, if we tried to search ufcs functions AFTER searching from child to parent scope levels, * // it would return the local foo() only, not the global one..which would be an error then! * } * * Probably also worth to notice is the property syntax..are property functions rather preferred than ufcs ones? * } */ if(overloads == null || EvalAndFilterOverloads) { var oo = UFCSResolver.TryResolveUFCS(baseExpression, acc, ctxt) as AbstractType[]; if(oo != null) { int overloadsLength = overloads == null ? 0 : overloads.Length; var newArr = new AbstractType[overloadsLength + oo.Length]; if(overloadsLength != 0) overloads.CopyTo(newArr,0); oo.CopyTo(newArr, overloadsLength); overloads = newArr; } } // If evaluation active and the access expression is stand-alone, return a single item only. if (EvalAndFilterOverloads && eval) return new[] { TryDoCTFEOrGetValueRefs(overloads, acc.AccessExpression) }; return overloads; }
public static AbstractType[] HandleNodeMatches( IEnumerable<INode> matches, ResolutionContext ctxt, AbstractType resultBase = null, object typeDeclaration = null) { // Abbreviate a foreach-loop + List alloc var ll = matches as IList<INode>; if (ll != null && ll.Count == 1) return new[] { ll[0] == null ? null : HandleNodeMatch(ll[0], ctxt, resultBase, typeDeclaration) }; var rl = new List<AbstractType>(); if (matches != null) foreach (var m in matches) { if (m == null) continue; var res = HandleNodeMatch(m, ctxt, resultBase, typeDeclaration); if (res != null) rl.Add(res); } return rl.ToArray(); }
/// <summary> /// The variable's or method's base type will be resolved (if auto type, the intializer's type will be taken). /// A class' base class will be searched. /// etc.. /// </summary> public static AbstractType HandleNodeMatch( INode m, ResolutionContext ctxt, AbstractType resultBase = null, object typeBase = null) { AbstractType ret = null; // See https://github.com/aBothe/Mono-D/issues/161 int stkC; if (stackCalls == null) { stackCalls = new Dictionary<INode, int>(); stackCalls[m] = stkC = 1; } else if (stackCalls.TryGetValue(m, out stkC)) stackCalls[m] = ++stkC; else stackCalls[m] = stkC = 1; /* * Pushing a new scope is only required if current scope cannot be found in the handled node's hierarchy. * Edit: No, it is required nearly every time because of nested type declarations - then, we do need the * current block scope. */ bool popAfterwards; { var newScope = m is IBlockNode ? (IBlockNode)m : m.Parent as IBlockNode; popAfterwards = ctxt.ScopedBlock != newScope && newScope != null; if (popAfterwards) { var options = ctxt.CurrentContext.ContextDependentOptions; var applyOptions = ctxt.ScopedBlockIsInNodeHierarchy (m); ctxt.PushNewScope (newScope); if (applyOptions) ctxt.CurrentContext.ContextDependentOptions = options; } } var canResolveBase = ((ctxt.Options & ResolutionOptions.DontResolveBaseTypes) != ResolutionOptions.DontResolveBaseTypes) && stkC < 10 && (m.Type == null || m.Type.ToString(false) != m.Name); // To support resolving type parameters to concrete types if the context allows this, introduce all deduced parameters to the current context if (resultBase is DSymbol) ctxt.CurrentContext.IntroduceTemplateParameterTypes((DSymbol)resultBase); var importSymbolNode = m as ImportSymbolNode; var variable = m as DVariable; // Only import symbol aliases are allowed to search in the parse cache if (importSymbolNode != null) ret = HandleImportSymbolMatch (importSymbolNode,ctxt); else if (variable != null) { AbstractType bt = null; if (!(variable is EponymousTemplate)) { if (canResolveBase) { var bts = TypeDeclarationResolver.Resolve (variable.Type, ctxt); ctxt.CheckForSingleResult (bts, variable.Type); if (bts != null && bts.Length != 0) bt = bts [0]; // For auto variables, use the initializer to get its type else if (variable.Initializer != null) { bt = DResolver.StripMemberSymbols (Evaluation.EvaluateType (variable.Initializer, ctxt)); } // Check if inside an foreach statement header if (bt == null && ctxt.ScopedStatement != null) bt = GetForeachIteratorType (variable, ctxt); } // Note: Also works for aliases! In this case, we simply try to resolve the aliased type, otherwise the variable's base type ret = variable.IsAlias ? new AliasedType (variable, bt, typeBase as ISyntaxRegion) as MemberSymbol : new MemberSymbol (variable, bt, typeBase as ISyntaxRegion); } else ret = new EponymousTemplateType (variable as EponymousTemplate, GetInvisibleTypeParameters(variable, ctxt).AsReadOnly(), typeBase as ISyntaxRegion); } else if (m is DMethod) { ret = new MemberSymbol(m as DNode,canResolveBase ? GetMethodReturnType(m as DMethod, ctxt) : null, typeBase as ISyntaxRegion); } else if (m is DClassLike) ret = HandleClassLikeMatch (m as DClassLike, ctxt, typeBase, canResolveBase); else if (m is DModule) { var mod = (DModule)m; if (typeBase != null && typeBase.ToString() != mod.ModuleName) { var pack = ctxt.ParseCache.LookupPackage(typeBase.ToString()).FirstOrDefault(); if (pack != null) ret = new PackageSymbol(pack, typeBase as ISyntaxRegion); } else ret = new ModuleSymbol(m as DModule, typeBase as ISyntaxRegion); } else if (m is DEnum) ret = new EnumType((DEnum)m, typeBase as ISyntaxRegion); else if (m is TemplateParameter.Node) { //ResolveResult[] templateParameterType = null; //TODO: Resolve the specialization type //var templateParameterType = TemplateInstanceHandler.ResolveTypeSpecialization(tmp, ctxt); ret = new TemplateParameterSymbol((m as TemplateParameter.Node).TemplateParameter, null, typeBase as ISyntaxRegion); } else if(m is NamedTemplateMixinNode) { var tmxNode = m as NamedTemplateMixinNode; ret = new MemberSymbol(tmxNode, canResolveBase ? ResolveSingle(tmxNode.Type, ctxt) : null, typeBase as ISyntaxRegion); } if (popAfterwards) ctxt.Pop(); else if (resultBase is DSymbol) ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals((DSymbol)resultBase); if (stkC == 1) stackCalls.Remove(m); else stackCalls[m] = stkC-1; return ret; }
public static IEnumerable <string> TypedArgs(this IEnumerable <string> ss, AbstractType type) { return(ss.Select(s => type.Name + " " + s)); }
public static AbstractType[] Resolve(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true) { AbstractType[] res; if (id.InnerDeclaration == null && resultBases == null) res = ResolveIdentifier(id.IdHash, ctxt, id, id.ModuleScoped); else { var rbases = resultBases ?? Resolve(id.InnerDeclaration, ctxt); if (rbases == null || rbases.Length == 0) return null; res = ResolveFurtherTypeIdentifier(id.IdHash, rbases, ctxt, id); } if (filterForTemplateArgs && (ctxt.Options & ResolutionOptions.NoTemplateParameterDeduction) == 0) { var l_ = new List<AbstractType>(); if (res != null) foreach (var s in res) l_.Add(s); return TemplateInstanceHandler.DeduceParamsAndFilterOverloads(l_, null, false, ctxt); } else return res; }
public static IEnumerable <string> TypedArgs(this AbstractType type, params string[] args) { return(args.Select(a => type.NameThat + " " + a)); }
bool HandleDecl(VectorDeclaration v, AbstractType r) { throw new System.NotImplementedException (); //TODO: Reimplement typedeclarationresolver as proper Visitor. /*if (r.DeclarationOrExpressionBase is VectorDeclaration) { var v_res = ExpressionTypeEvaluation.EvaluateType(v.Id, ctxt); var r_res = ExpressionTypeEvaluation.EvaluateType(((VectorDeclaration)r.DeclarationOrExpressionBase).Id, ctxt); if (v_res == null || r_res == null) return false; else return ResultComparer.IsImplicitlyConvertible(r_res, v_res); }*/ return false; }
public Operator(AbstractType type, string op) : base(type, "operator" + op) { Static = true; }
/// <summary> /// Item1 - True, if isExpression returns true /// Item2 - If Item1 is true, it contains the type of the alias that is defined in the isExpression /// </summary> private Tuple<bool, AbstractType> evalIsExpression_EvalSpecToken(IsExpression isExpression, AbstractType typeToCheck, bool DoAliasHandling = false) { bool r = false; AbstractType res = null; switch (isExpression.TypeSpecializationToken) { /* * To handle semantic tokens like "return" or "super" it's just needed to * look into the current resolver context - * then, we'll be able to gather either the parent method or the currently scoped class definition. */ case DTokens.Struct: case DTokens.Union: case DTokens.Class: case DTokens.Interface: if (r = typeToCheck is UserDefinedType && ((TemplateIntermediateType)typeToCheck).Definition.ClassType == isExpression.TypeSpecializationToken) res = typeToCheck; break; case DTokens.Enum: if (!(typeToCheck is EnumType)) break; { var tr = (UserDefinedType)typeToCheck; r = true; res = tr.Base; } break; case DTokens.Function: case DTokens.Delegate: if (typeToCheck is DelegateType) { var isFun = false; var dgr = (DelegateType)typeToCheck; if (!dgr.IsFunctionLiteral) r = isExpression.TypeSpecializationToken == ( (isFun = ((DelegateDeclaration)dgr.DeclarationOrExpressionBase).IsFunction) ? DTokens.Function : DTokens.Delegate); // Must be a delegate otherwise else isFun = !(r = isExpression.TypeSpecializationToken == DTokens.Delegate); if (r) { //TODO if (isFun) { // TypeTuple of the function parameter types. For C- and D-style variadic functions, only the non-variadic parameters are included. // For typesafe variadic functions, the ... is ignored. } else { // the function type of the delegate } } } else // Normal functions are also accepted as delegates { r = isExpression.TypeSpecializationToken == DTokens.Delegate && typeToCheck is MemberSymbol && ((DSymbol)typeToCheck).Definition is DMethod; //TODO: Alias handling, same as couple of lines above } break; case DTokens.Super: //TODO: Test this var dc = DResolver.SearchClassLikeAt(ctxt.ScopedBlock, isExpression.Location) as DClassLike; if (dc != null) { var udt = DResolver.ResolveBaseClasses(new ClassType(dc, dc, null), ctxt, true) as ClassType; if (r = udt.Base != null && ResultComparer.IsEqual(typeToCheck, udt.Base)) { var l = new List<AbstractType>(); if (udt.Base != null) l.Add(udt.Base); if (udt.BaseInterfaces != null && udt.BaseInterfaces.Length != 0) l.AddRange(udt.BaseInterfaces); res = new DTuple(isExpression, l); } } break; case DTokens.Const: case DTokens.Immutable: case DTokens.InOut: // TODO? case DTokens.Shared: if (r = typeToCheck.Modifier == isExpression.TypeSpecializationToken) res = typeToCheck; break; case DTokens.Return: // TODO: Test IStatement _u = null; var dm = DResolver.SearchBlockAt(ctxt.ScopedBlock, isExpression.Location, out _u) as DMethod; if (dm != null) { var retType_ = TypeDeclarationResolver.GetMethodReturnType(dm, ctxt); if (r = retType_ != null && ResultComparer.IsEqual(typeToCheck, retType_)) res = retType_; } break; } return new Tuple<bool, AbstractType>(r, res); }