public MemberValue(object instance, string member) { this.instance = instance; this.member = member; bindingFlags = BindingFlags.InvokeMethod; bindingFlags[BindingFlags.Public] = true; bindingFlags[BindingFlags.Instance] = true; }
public ExpressionBuilder(Bits32 <ExpressionFlags> flags) { stack = new SymbolStack(); symbols = new List <Symbol>(); ordered = new List <Symbol>(); this.flags = flags; _lastSymbol = none <Symbol>(); }
public MemberVariable(string member, object instance, bool isField, Type type) : base(member) { this.instance = instance; bindingFlags = BindingFlags.Public; this.isField = isField; this.type = type; arguments = new object[0]; instanceIsNull = instance == null; bindingFlags[BindingFlags.Instance] = !instanceIsNull; bindingFlags[BindingFlags.Static] = instanceIsNull; }
protected DelimitedText(Pattern beginPattern, Maybe <Pattern> _endPattern, Pattern exceptPattern) { this.beginPattern = beginPattern; this._endPattern = _endPattern; this.exceptPattern = exceptPattern; _exceptReplacement = none <string>(); slicer = new LateLazy <Slicer>(true, "You must call Enumerable() before accessing this member"); status = DelimitedTextStatus.Outside; TransformingMap = none <Func <string, string> >(); strings = new List <string>(); }
public static bool Any <TEnum>(this TEnum @enum, params TEnum[] args) where TEnum : struct, Enum { if (typeof(TEnum).IsDefined(typeof(FlagsAttribute))) { Bits32 <TEnum> bits = @enum; return(args.Any(e => bits[e])); } else { return(args.Any(e => e.Equals(@enum))); } }
///<summary>Performs an Atomic modification of bit flags</summary> /// <param name="Value">Value to modify</param> /// <param name="ClearBits">Bits to clear in Value</param> /// <param name="SetBits">Bits to Set in Value</param> /// <returns>previous value</returns> /// <remarks> /// This method performs a thread safe interlocked atomic modification of the /// specified value. /// </remarks> static int InterlockedModifyBits(ref int Value, Bits32 ClearBits, Bits32 SetBits) { int original, newVal; do { newVal = original = Value; Bits.ModifyBits(ref newVal, ClearBits, SetBits); // if the correct bits are already set/cleared then do nothing if (newVal == original) { break; } // use InterlockedCopmareExchange to make a thread safe assignment or try again } while(System.Threading.Interlocked.CompareExchange(ref Value, newVal, original) != original); return(original); }
/// <summary>Tests if any of the bits specified are set in a value</summary> /// <param name="Value">Value to test bits in</param> /// <param name="TestBits">Bit mask of bits to test in Value</param> /// <returns>true if any of the bits specified in TestBits is set in Value</returns> public static bool AnyBitsSet(uint Value, Bits32 TestBits) { return 0 != ((uint)TestBits & Value); }
/// <summary>Tests if all the specified bits are set in a Value</summary> /// <param name="Value">Value to test</param> /// <param name="TestBits">Bit mask of bits to test in Value</param> /// <returns>true, if ALL the bits specified in TestBits are set</returns> public static bool AllBitsSet(uint Value, Bits32 TestBits) { return (uint)TestBits == ((uint)TestBits & Value); }
/// <summary>Tests if any of the bits specified are set in a value</summary> /// <param name="Value">Value to test bits in</param> /// <param name="TestBits">Bit mask of bits to test in Value</param> /// <returns>true if any of the bits specified in TestBits is set in Value</returns> public static bool AnyBitsSet(uint Value, Bits32 TestBits) { return(0 != ((uint)TestBits & Value)); }
/// <summary>Tests if all the specified bits are set in a Value</summary> /// <param name="Value">Value to test</param> /// <param name="TestBits">Bit mask of bits to test in Value</param> /// <returns>true, if ALL the bits specified in TestBits are set</returns> public static bool AllBitsSet(uint Value, Bits32 TestBits) { return((uint)TestBits == ((uint)TestBits & Value)); }
void initialize() { matcher = new Matcher(); matcher.RequiredMatch(source, $"^ ('|' /(-['|']+) '|')? (/({REGEX_VARIABLE}) /(/s* '=' /s*))? /('#'? [/w .]+) " + "/(['.:']) /(/w+) '(' /(-[')']*) ')' /('.'? ['!?'])? $", $"Didn't understand invocation <[{source}]>", true); matcher.Extract(0, out var assemblyName, out var alias, out var sign, out var typeName, out var dot, out member, out var parameterSource, out var invocationMethod); var assemblyPresent = assemblyName.IsNotEmpty(); if (assemblyPresent) { Color(index, 1, Structures); Color(assemblyName.Length, Variables); Color(1, Structures); if (alias.IsNotEmpty()) { Color(alias.Length, Variables); Color(sign.Length, Operators); } Color(typeName.Length, Variables); } else if (alias.IsNotEmpty()) { Color(index, alias.Length, Variables); Color(sign.Length, Operators); Color(typeName.Length, Variables); } else { Color(index, typeName.Length, Variables); } Color(1, Structures); Color(member.Length, Messaging); Color(1, Structures); Color(parameterSource.Length, Variables); Color(1, Structures); Color(invocationMethod.Length, Operators); if (!assemblyPresent) { assemblyName = "mscorlib"; } switch (member) { case "new": invocationType = New; bindingFlags = new Bits32 <BindingFlags>(Public); break; default: invocationType = dot == "." ? InvocationType.Instance : InvocationType.Static; switch (invocationType) { case InvocationType.Instance: bindingFlags = BindingFlags.Instance; break; case InvocationType.Static: bindingFlags = BindingFlags.Static; break; } bindingFlags[Public] = true; switch (invocationMethod) { case "!": bindingFlags[SetProperty] = true; break; case "?": bindingFlags[GetProperty] = true; break; case ".!": bindingFlags[SetField] = true; break; case ".?": bindingFlags[GetField] = true; break; default: bindingFlags[InvokeMethod] = true; break; } break; } if (typeName.StartsWith("#")) { typeName = typeAliases.Find(typeName.Skip(1), t => ""); } if (alias.IsNotEmpty()) { typeAliases[alias] = typeName; } Assert(typeName.IsNotEmpty(), LOCATION, "Couldn't find type"); var fullAssemblyName = typeToAssemblies[typeName]; if (fullAssemblyName != null) { assemblyName = fullAssemblyName; } assembly = assemblies.Find(assemblyName, Assembly.Load); type = assembly.GetType(typeName, false, true); RejectNull(type, LOCATION, $"Didn't understand .NET type {typeName}"); typeToAssemblies[typeName] = assemblyName; parameters = parameterSource.Split("/s* ',' /s*"); }
public Value() { id = CompilerState.ObjectID(); PerformElse = null; options = OptionType.None; }
public Contract(Object obj, string name, Bits32 <ContractType> types) : this(obj, name) { this.types = types; }
public Contract(Object obj, string name) { this.obj = obj; this.name = name; types = ContractType.None; }
/// <summary>Modifies bits in a 32bit value</summary> /// <param name="Value">value to modify</param> /// <param name="ClearBits">Bit mask of bits in value to clear</param> /// <param name="SetBits">Bit mask of bits in value to set</param> public static void ModifyBits(ref int Value, Bits32 ClearBits, Bits32 SetBits) { Value = ( Value & ( int )( ~ClearBits ) ) | ( int )SetBits; }
///<summary>Performs an Atomic modification of bit flags</summary> /// <param name="Value">Value to modify</param> /// <param name="ClearBits">Bits to clear in Value</param> /// <param name="SetBits">Bits to Set in Value</param> /// <returns>previous value</returns> /// <remarks> /// This method performs a thread safe interlocked atomic modification of the /// specified value. /// </remarks> static int InterlockedModifyBits(ref int Value, Bits32 ClearBits, Bits32 SetBits) { int original, newVal; do { newVal = original = Value; Bits.ModifyBits(ref newVal, ClearBits, SetBits); // if the correct bits are already set/cleared then do nothing if(newVal == original) break; // use InterlockedCopmareExchange to make a thread safe assignment or try again } while(System.Threading.Interlocked.CompareExchange(ref Value, newVal, original) != original); return original; }
protected void initialize() { matcher = new Matcher(); matcher.Must().Match(source, regexInvocation, true, false).OrThrow($"Didn't understand invocation <[{source}]>"); var assemblyName = matcher.FirstGroup; var alias = matcher.SecondGroup; var sign = matcher.ThirdGroup; var typeName = matcher.FourthGroup; var dot = matcher.FifthGroup; member = matcher.SixthGroup; var parameterSource = matcher.SeventhGroup; var invocationMethod = matcher.EighthGroup; var assemblyPresent = assemblyName.IsNotEmpty(); if (assemblyPresent) { Color(index, 1, Structures); Color(assemblyName.Length, Variables); Color(1, Structures); if (alias.IsNotEmpty()) { Color(alias.Length, Variables); Color(sign.Length, Operators); } Color(typeName.Length, Variables); } else if (alias.IsNotEmpty()) { Color(index, alias.Length, Variables); Color(sign.Length, Operators); Color(typeName.Length, Variables); } else { Color(index, typeName.Length, Variables); } Color(1, Structures); Color(member.Length, Messaging); Color(1, Structures); Color(parameterSource.Length, Variables); Color(1, Structures); Color(invocationMethod.Length, Operators); if (!assemblyPresent) { assemblyName = "mscorlib"; } switch (member) { case "new": invocationType = New; bindingFlags = new Bits32 <BindingFlags>(Public); break; default: invocationType = dot == "." ? InvocationType.Instance : InvocationType.Static; bindingFlags = invocationType switch { InvocationType.Instance => BindingFlags.Instance, InvocationType.Static => BindingFlags.Static, _ => bindingFlags }; bindingFlags[Public] = true; switch (invocationMethod) { case "!": bindingFlags[SetProperty] = true; break; case "?": bindingFlags[GetProperty] = true; break; case ".!": bindingFlags[SetField] = true; break; case ".?": bindingFlags[GetField] = true; break; default: bindingFlags[InvokeMethod] = true; break; } break; } if (typeName.StartsWith("#")) { typeName = typeAliases.Find(typeName.Drop(1), _ => ""); } if (alias.IsNotEmpty()) { typeAliases[alias] = typeName; } typeName.Must().Not.BeNullOrEmpty().OrThrow(LOCATION, () => "Couldn't find type"); var fullAssemblyName = typeToAssemblies[typeName]; if (fullAssemblyName != null) { assemblyName = fullAssemblyName; } assembly = assemblies.Find(assemblyName, Assembly.Load); type = assembly.GetType(typeName, false, true); type.Must().Not.BeNull().OrThrow(LOCATION, () => $"Didn't understand .NET type {typeName}"); typeToAssemblies[typeName] = assemblyName; parameters = parameterSource.Split("/s* ',' /s*"); }
public ExpressionParser(Bits32 <ExpressionFlags> flags) : base(false) => this.flags = flags;
/// <summary>Modifies bits in a 32bit value</summary> /// <param name="Value">value to modify</param> /// <param name="ClearBits">Bit mask of bits in value to clear</param> /// <param name="SetBits">Bit mask of bits in value to set</param> public static void ModifyBits(ref int Value, Bits32 ClearBits, Bits32 SetBits) { Value = (Value & ( int )(~ClearBits)) | ( int )SetBits; }