private void MakeSetMemberRule(Type type) { if (MakeOperatorSetMemberBody(type, "SetMember")) { return; } MemberGroup members = Binder.GetMember(Action, type, StringName); // if lookup failed try the strong-box type if available. if (members.Count == 0 && StrongBoxType != null) { type = StrongBoxType; StrongBoxType = null; members = Binder.GetMember(Action, type, StringName); } Expression error; TrackerTypes memberTypes = GetMemberType(members, out error); if (error == null) { switch (memberTypes) { case TrackerTypes.Method: case TrackerTypes.TypeGroup: case TrackerTypes.Type: case TrackerTypes.Constructor: MakeReadOnlyMemberError(type); break; case TrackerTypes.Event: AddToBody(Binder.MakeEventValidation(Rule, members).MakeErrorForRule(Rule, Binder)); break; case TrackerTypes.Field: MakeFieldRule(type, members); break; case TrackerTypes.Property: MakePropertyRule(type, members); break; case TrackerTypes.Custom: MakeGenericBody(type, members[0]); break; case TrackerTypes.All: // no match if (MakeOperatorSetMemberBody(type, "SetMemberAfter")) { return; } MakeMissingMemberError(type); break; default: throw new InvalidOperationException(); } } else { AddToBody(Rule.MakeError(error)); } }
/// <summary> /// Returns a Tracker with the specified type /// </summary> /// <param name="tracker">Tracker type to create</param> public ITracker CreateFactory(TrackerTypes tracker = TrackerTypes.TwoDimensial) { switch (tracker) { case TrackerTypes.TwoDimensial: default: return(new TwoDimensialTracker()); } }
/// <summary> /// Converts input file's string to InputData /// </summary> /// <param name="inputStrings">Collection of string to convert</param> /// <param name="trackerType">Specific Tracker type</param> /// <returns>Specific IInputData implementation for the trackerType</returns> public static IInputData ToInputData(this IEnumerable <string> inputStrings, TrackerTypes trackerType = TrackerTypes.TwoDimensial) { switch (trackerType) { case TrackerTypes.TwoDimensial: return(TwoDimensialConverter(inputStrings)); default: return(null); } }
/// <summary> /// Checks if input data has correct content /// </summary> /// <param name="inputPath">Input data file path</param> /// <param name="trackerType">Which tracker type will work with data</param> public virtual bool ValidateInputFile(string inputPath, TrackerTypes trackerType = TrackerTypes.TwoDimensial) { switch (trackerType) { case TrackerTypes.TwoDimensial: return(ValidateTwoDimensialInputFile(inputPath)); default: return(false); } }
/// <summary> /// Validates does location is presented correctly for the tracker type /// </summary> /// <param name="location">Location presented as string</param> /// <param name="trackerType">TrackerTypes.TwoDimensial be deafault</param> public virtual bool ValidateLocation(string location, TrackerTypes trackerType = TrackerTypes.TwoDimensial) { switch (trackerType) { case TrackerTypes.TwoDimensial: return(ValidateTwoDimensialLocation(location)); default: return(false); } }
private Expression MakeBodyHelper(Type type, MemberGroup members) { if (!_isStatic) { MakeOperatorGetMemberBody(type, "GetCustomMember"); } Expression error; TrackerTypes memberType = GetMemberType(members, out error); if (error != null) { AddToBody(Rule.MakeError(error)); return(Body); } switch (memberType) { case TrackerTypes.TypeGroup: case TrackerTypes.Type: MakeTypeBody(type, members); break; case TrackerTypes.Method: // turn into a MethodGroup MakeGenericBodyWorker(type, ReflectionCache.GetMethodGroup(StringName, members), _instance ?? Rule.Parameters[0]); break; case TrackerTypes.Event: case TrackerTypes.Field: case TrackerTypes.Property: case TrackerTypes.Constructor: case TrackerTypes.Custom: MakeGenericBody(type, members); break; case TrackerTypes.All: // no members were found if (!_isStatic) { MakeOperatorGetMemberBody(type, "GetBoundMember"); } MakeMissingMemberRuleForGet(type); break; default: throw new InvalidOperationException(memberType.ToString()); } return(Body); }
public static ITracker GetTracker(Rectangle rectangle, TrackerTypes type, bool showHandles) { switch (type) { case TrackerTypes.Default: if (defTracker == null) { defTracker = new DefaultTracker(); } defTracker.Transform(rectangle); defTracker.ShowHandles = showHandles; return(defTracker); default: return(null); } }
private void MakeBodyHelper(GetMemberInfo getMemInfo, DynamicMetaObject self, DynamicMetaObject propSelf, Type targetType, MemberGroup members) { if (self != null) { MakeOperatorGetMemberBody(getMemInfo, propSelf, targetType, "GetCustomMember"); } TrackerTypes memberType = GetMemberType(members, out Expression error); if (error == null) { MakeSuccessfulMemberAccess(getMemInfo, self, propSelf, targetType, members, memberType); } else { getMemInfo.Body.FinishError(getMemInfo.ErrorSuggestion?.Expression ?? error); } }
private void MakeBodyHelper(GetMemberInfo getMemInfo, Expression self, Expression propSelf, Type type, MemberGroup members) { if (self != null) { MakeOperatorGetMemberBody(getMemInfo, propSelf, type, "GetCustomMember"); } Expression error; TrackerTypes memberType = GetMemberType(members, out error); if (error == null) { MakeSuccessfulMemberAccess(getMemInfo, self, propSelf, type, members, memberType); } else { getMemInfo.Body.FinishCondition(error); } }
internal static TrackerTypes GetMemberType(MemberGroup members) { TrackerTypes memberType = TrackerTypes.All; for (int i = 0; i < members.Count; i++) { MemberTracker mi = members[i]; if (mi.MemberType != memberType) { if (memberType != TrackerTypes.All) { return(TrackerTypes.All); } memberType = mi.MemberType; } } return(memberType); }
public TrackerTypes GetMemberType(MemberGroup members, out Expression error) { error = null; TrackerTypes memberType = TrackerTypes.All; for (int i = 0; i < members.Count; i++) { MemberTracker mi = members[i]; if (mi.MemberType != memberType) { if (memberType != TrackerTypes.All) { error = MakeAmbiguousMatchError(members); return(TrackerTypes.All); } memberType = mi.MemberType; } } return(memberType); }
/// <summary> /// /// </summary> /// <param name="trackerType"></param> public static Tracker Create(TrackerTypes trackerType) { IntPtr ptr; switch (trackerType) { case TrackerTypes.Boosting: ptr = NativeMethods.tracking_Tracker_create("BOOSTING"); break; case TrackerTypes.GOTURN: ptr = NativeMethods.tracking_Tracker_create("GOTURN"); break; case TrackerTypes.TLD: ptr = NativeMethods.tracking_Tracker_create("TLD"); break; case TrackerTypes.KCF: ptr = NativeMethods.tracking_Tracker_create("KCF"); break; case TrackerTypes.MedianFlow: ptr = NativeMethods.tracking_Tracker_create("MEDIANFLOW"); break; case TrackerTypes.MIL: ptr = NativeMethods.tracking_Tracker_create("MIL"); break; default: throw new ArgumentOutOfRangeException(nameof(trackerType), trackerType, null); } return(new Tracker(ptr)); }
internal static PythonTypeSlot /*!*/ GetSlot(MemberGroup group, string name, bool privateBinding) { if (group.Count == 0) { return(null); } group = FilterNewSlots(group); TrackerTypes tt = GetMemberType(group); switch (tt) { case TrackerTypes.Method: bool checkStatic = false; List <MemberInfo> mems = new List <MemberInfo>(); foreach (MemberTracker mt in group) { MethodTracker metht = (MethodTracker)mt; mems.Add(metht.Method); checkStatic |= metht.IsStatic; } Type declType = group[0].DeclaringType; MemberInfo[] memArray = mems.ToArray(); FunctionType ft = GetMethodFunctionType(declType, memArray, checkStatic); return(GetFinalSlotForFunction(GetBuiltinFunction(declType, group[0].Name, name, ft, memArray))); case TrackerTypes.Field: return(GetReflectedField(((FieldTracker)group[0]).Field)); case TrackerTypes.Property: return(GetReflectedProperty((PropertyTracker)group[0], group, privateBinding)); case TrackerTypes.Event: return(GetReflectedEvent(((EventTracker)group[0]))); case TrackerTypes.Type: TypeTracker type = (TypeTracker)group[0]; for (int i = 1; i < group.Count; i++) { type = TypeGroup.UpdateTypeEntity(type, (TypeTracker)group[i]); } if (type is TypeGroup) { return(new PythonTypeUserDescriptorSlot(type, true)); } return(new PythonTypeUserDescriptorSlot(DynamicHelpers.GetPythonTypeFromType(type.Type), true)); case TrackerTypes.Constructor: return(GetConstructorFunction(group[0].DeclaringType, privateBinding)); case TrackerTypes.Custom: return(((PythonCustomTracker)group[0]).GetSlot()); default: // if we have a new slot in the derived class filter out the // members from the base class. throw new InvalidOperationException(String.Format("Bad member type {0} on {1}.{2}", tt.ToString(), group[0].DeclaringType, name)); } }
private Func <CallSite, TSelfType, CodeContext, object> MakeGetMemberTarget <TSelfType>(string name, object target, CodeContext context) { Type type = CompilerHelpers.GetType(target); // needed for GetMember call until DynamicAction goes away if (typeof(TypeTracker).IsAssignableFrom(type)) { // no fast path for TypeTrackers PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast TypeTracker"); return(null); } MemberGroup members = Context.Binder.GetMember(MemberRequestKind.Get, type, name); if (members.Count == 0 && type.IsInterface()) { // all interfaces have object members type = typeof(object); members = Context.Binder.GetMember(MemberRequestKind.Get, type, name); } if (members.Count == 0 && typeof(IStrongBox).IsAssignableFrom(type)) { // no fast path for strong box access PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast StrongBox"); return(null); } MethodInfo getMem = Context.Binder.GetMethod(type, "GetCustomMember"); if (getMem != null && getMem.IsSpecialName) { // no fast path for custom member access PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast GetCustomMember " + type); return(null); } Expression error; TrackerTypes memberType = Context.Binder.GetMemberType(members, out error); if (error == null) { PythonType argType = DynamicHelpers.GetPythonTypeFromType(type); bool isHidden = argType.IsHiddenMember(name); if (isHidden) { PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast FilteredMember " + memberType); return(null); } switch (memberType) { case TrackerTypes.TypeGroup: case TrackerTypes.Type: object typeObj; if (members.Count == 1) { typeObj = DynamicHelpers.GetPythonTypeFromType(((TypeTracker)members[0]).Type); } else { TypeTracker typeTracker = (TypeTracker)members[0]; for (int i = 1; i < members.Count; i++) { typeTracker = TypeGroup.UpdateTypeEntity(typeTracker, (TypeTracker)members[i]); } typeObj = typeTracker; } return(new FastTypeGet <TSelfType>(type, typeObj).GetTypeObject); case TrackerTypes.Method: PythonTypeSlot slot = PythonTypeOps.GetSlot(members, name, _context.DomainManager.Configuration.PrivateBinding); if (slot is BuiltinMethodDescriptor) { return(new FastMethodGet <TSelfType>(type, (BuiltinMethodDescriptor)slot).GetMethod); } else if (slot is BuiltinFunction) { return(new FastSlotGet <TSelfType>(type, slot, DynamicHelpers.GetPythonTypeFromType(type)).GetRetSlot); } return(new FastSlotGet <TSelfType>(type, slot, DynamicHelpers.GetPythonTypeFromType(type)).GetBindSlot); case TrackerTypes.Event: if (members.Count == 1 && !((EventTracker)members[0]).IsStatic) { slot = PythonTypeOps.GetSlot(members, name, _context.DomainManager.Configuration.PrivateBinding); return(new FastSlotGet <TSelfType>(type, slot, DynamicHelpers.GetPythonTypeFromType(((EventTracker)members[0]).DeclaringType)).GetBindSlot); } PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast Event " + members.Count + " " + ((EventTracker)members[0]).IsStatic); return(null); case TrackerTypes.Property: if (members.Count == 1) { PropertyTracker pt = (PropertyTracker)members[0]; if (!pt.IsStatic && pt.GetIndexParameters().Length == 0) { MethodInfo prop = pt.GetGetMethod(); ParameterInfo[] parameters; if (prop != null && (parameters = prop.GetParameters()).Length == 0) { if (prop.ReturnType == typeof(bool)) { return(new FastPropertyGet <TSelfType>(type, CallInstruction.Create(prop, parameters).Invoke).GetPropertyBool); } else if (prop.ReturnType == typeof(int)) { return(new FastPropertyGet <TSelfType>(type, CallInstruction.Create(prop, parameters).Invoke).GetPropertyInt); } else { return(new FastPropertyGet <TSelfType>(type, CallInstruction.Create(prop, parameters).Invoke).GetProperty); } } } } PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast Property " + members.Count + " " + ((PropertyTracker)members[0]).IsStatic); return(null); case TrackerTypes.All: getMem = Context.Binder.GetMethod(type, "GetBoundMember"); if (getMem != null && getMem.IsSpecialName) { PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast GetBoundMember " + type); return(null); } if (members.Count == 0) { // we don't yet support fast bindings to extension methods members = context.ModuleContext.ExtensionMethods.GetBinder(_context).GetMember(MemberRequestKind.Get, type, name); if (members.Count == 0) { if (IsNoThrow) { return(new FastErrorGet <TSelfType>(type, name, context.ModuleContext.ExtensionMethods).GetErrorNoThrow); } else if (SupportsLightThrow) { return(new FastErrorGet <TSelfType>(type, name, context.ModuleContext.ExtensionMethods).GetErrorLightThrow); } else { return(new FastErrorGet <TSelfType>(type, name, context.ModuleContext.ExtensionMethods).GetError); } } } return(null); default: PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast " + memberType); return(null); } } else { StringBuilder sb = new StringBuilder(); foreach (MemberTracker mi in members) { if (sb.Length != 0) { sb.Append(", "); } sb.Append(mi.MemberType); sb.Append(" : "); sb.Append(mi.ToString()); } return(new FastErrorGet <TSelfType>(type, sb.ToString(), context.ModuleContext.ExtensionMethods).GetAmbiguous); } }
public static ITracker GetTracker(Rectangle rectangle, TrackerTypes type, bool showHandles) { switch(type) { case TrackerTypes.Default: if(defTracker == null) defTracker = new DefaultTracker(); defTracker.Transform(rectangle); defTracker.ShowHandles = showHandles; return defTracker; default: return null; } }
private void MakeSuccessfulMemberAccess(GetMemberInfo getMemInfo, DynamicMetaObject self, DynamicMetaObject propSelf, Type selfType, MemberGroup members, TrackerTypes memberType) { switch (memberType) { case TrackerTypes.TypeGroup: case TrackerTypes.Type: MakeTypeBody(getMemInfo, selfType, members); break; case TrackerTypes.Method: // turn into a MethodGroup MakeGenericBodyWorker(getMemInfo, selfType, ReflectionCache.GetMethodGroup(getMemInfo.Name, members), self); break; case TrackerTypes.Event: case TrackerTypes.Field: case TrackerTypes.Property: case TrackerTypes.Constructor: case TrackerTypes.Custom: MakeGenericBody(getMemInfo, selfType, members, propSelf); break; case TrackerTypes.All: // no members were found if (self != null) { MakeOperatorGetMemberBody(getMemInfo, propSelf, selfType, "GetBoundMember"); } MakeMissingMemberRuleForGet(getMemInfo, self, selfType); break; default: throw new InvalidOperationException(memberType.ToString()); } }
/// <summary> /// Converts string line to the collection of Points /// </summary> /// <param name="firstLine">Points presented as string</param> /// <param name="separator">Char which separate point's positions between themselves at the line</param> /// <param name="trackerType">Specific Tracker type</param> /// <returns>Collection of points</returns> public static IEnumerable <IPoint> ToReceivers(this string firstLine, char separator, TrackerTypes trackerType = TrackerTypes.TwoDimensial) { switch (trackerType) { case TrackerTypes.TwoDimensial: return(TwoDimensialConverter(firstLine, separator)); default: return(null); } }
private void MakeSetMemberRule(SetOrDeleteMemberInfo memInfo, Type type, DynamicMetaObject self, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { if (MakeOperatorSetMemberBody(memInfo, self, value, type, "SetMember")) { return; } MemberGroup members = GetMember(MemberRequestKind.Set, type, memInfo.Name); // if lookup failed try the strong-box type if available. if (self != null && members.Count == 0 && typeof(IStrongBox).IsAssignableFrom(type)) { self = new DynamicMetaObject(Ast.Field(AstUtils.Convert(self.Expression, type), type.GetField("Value")), BindingRestrictions.Empty, ((IStrongBox)self.Value).Value); type = type.GetGenericArguments()[0]; members = GetMember(MemberRequestKind.Set, type, memInfo.Name); } Expression error; TrackerTypes memberTypes = GetMemberType(members, out error); if (error == null) { switch (memberTypes) { case TrackerTypes.Method: case TrackerTypes.TypeGroup: case TrackerTypes.Type: case TrackerTypes.Constructor: memInfo.Body.FinishCondition( errorSuggestion ?? MakeError(MakeReadOnlyMemberError(type, memInfo.Name), BindingRestrictions.Empty, typeof(object)) ); break; case TrackerTypes.Event: memInfo.Body.FinishCondition( errorSuggestion ?? MakeError(MakeEventValidation(members, self, value, memInfo.ResolutionFactory), BindingRestrictions.Empty, typeof(object)) ); break; case TrackerTypes.Field: MakeFieldRule(memInfo, self, value, type, members, errorSuggestion); break; case TrackerTypes.Property: MakePropertyRule(memInfo, self, value, type, members, errorSuggestion); break; case TrackerTypes.Custom: MakeGenericBody(memInfo, self, value, type, members[0], errorSuggestion); break; case TrackerTypes.All: // no match if (MakeOperatorSetMemberBody(memInfo, self, value, type, "SetMemberAfter")) { return; } memInfo.Body.FinishCondition( errorSuggestion ?? MakeError(MakeMissingMemberErrorForAssign(type, self, memInfo.Name), BindingRestrictions.Empty, typeof(object)) ); break; default: throw new InvalidOperationException(); } } else { memInfo.Body.FinishCondition(error); } }
private void MakeSetMemberRule(SetOrDeleteMemberInfo memInfo, Type type, Expression self, MetaObject target) { if (MakeOperatorSetMemberBody(memInfo, self, target, type, "SetMember")) { return; } // needed for GetMember call until DynamicAction goes away OldDynamicAction act = OldSetMemberAction.Make( this, memInfo.Name ); MemberGroup members = GetMember(act, type, memInfo.Name); // if lookup failed try the strong-box type if available. if (members.Count == 0 && typeof(IStrongBox).IsAssignableFrom(type)) { self = Ast.Field(AstUtils.Convert(self, type), type.GetField("Value")); type = type.GetGenericArguments()[0]; members = GetMember(act, type, memInfo.Name); } Expression error; TrackerTypes memberTypes = GetMemberType(members, out error); if (error == null) { switch (memberTypes) { case TrackerTypes.Method: case TrackerTypes.TypeGroup: case TrackerTypes.Type: case TrackerTypes.Constructor: memInfo.Body.FinishCondition( MakeError(MakeReadOnlyMemberError(type, memInfo.Name)) ); break; case TrackerTypes.Event: memInfo.Body.FinishCondition( MakeError(MakeEventValidation(members, self, target.Expression, memInfo.CodeContext)) ); break; case TrackerTypes.Field: MakeFieldRule(memInfo, self, target, type, members); break; case TrackerTypes.Property: MakePropertyRule(memInfo, self, target, type, members); break; case TrackerTypes.Custom: MakeGenericBody(memInfo, self, target, type, members[0]); break; case TrackerTypes.All: // no match if (MakeOperatorSetMemberBody(memInfo, self, target, type, "SetMemberAfter")) { return; } memInfo.Body.FinishCondition( MakeError(MakeMissingMemberError(type, memInfo.Name)) ); break; default: throw new InvalidOperationException(); } } else { memInfo.Body.FinishCondition(error); } }
private void MakeSuccessfulMemberAccess(GetMemberInfo getMemInfo, Expression self, Expression propSelf, Type type, MemberGroup members, TrackerTypes memberType) { switch (memberType) { case TrackerTypes.TypeGroup: case TrackerTypes.Type: MakeTypeBody(getMemInfo, type, members); break; case TrackerTypes.Method: // turn into a MethodGroup MakeGenericBodyWorker(getMemInfo, type, ReflectionCache.GetMethodGroup(getMemInfo.Name, members), self); break; case TrackerTypes.Event: case TrackerTypes.Field: case TrackerTypes.Property: case TrackerTypes.Constructor: case TrackerTypes.Custom: MakeGenericBody(getMemInfo, type, members, propSelf); break; case TrackerTypes.All: // no members were found if (self != null) { MakeOperatorGetMemberBody(getMemInfo, propSelf, type, "GetBoundMember"); } MakeMissingMemberRuleForGet(getMemInfo, type); break; default: throw new InvalidOperationException(memberType.ToString()); } }