/// <summary> /// Creates a new instance of the CheatPrefixButton class /// </summary> /// <param name="i">The Prefix of the CheatPrefixButton</param> public CheatPrefixContainer(Prefix i) : base("") { Size = new Vector2(80f, 30f); Prefix = i; }
public string Get(Prefix prefix) { var suffixes = chain[prefix]; var index = rnd.Next(suffixes.Count); return suffixes[index]; }
/// <summary> /// Initializes a new instance of the <see cref="DerivedUnit" /> class. /// </summary> /// <param name="prefix">The prefix.</param> /// <param name="notation">The notation.</param> /// <param name="expression">The expression.</param> public DerivedUnit(Prefix prefix, string notation, Expression expression) { this.prefix = prefix ?? Prefix.None; this.notation = notation; this.expression = expression; this.derivedBaseUnit = new DerivedBaseUnit(expression); }
private static void Main() { const int MAXGEN = 1000; var corpus = Resources.english; var suffixChain = new WordChain(); var prefix = new Prefix(); var words = corpus .Split(new[] {Environment.NewLine, " "}, StringSplitOptions.RemoveEmptyEntries) .ToList(); foreach (var word in words) { suffixChain.Add(prefix, word); prefix.Add(word); } suffixChain.Add(prefix, NONWORD); var wordChain = Generate(suffixChain, MAXGEN); var text = string.Join(" ", wordChain); Console.WriteLine(text); }
public FileSize(decimal plainValue, Prefix prefix) { PlainValue = plainValue; Prefix = prefix; InternalRepresentation = ToInternalRepresentation(plainValue, prefix); }
public override int GetHashCode() { unchecked { return(((Prefix != null ? Prefix.GetHashCode() : 0) * 397) ^ (Registry.GetType() != null ? Registry.GetType().GetHashCode() : 0)); } }
public static dynamic GetTSObject(Prefix dynObject) { if (dynObject is null) { return(null); } return(dynObject.teklaObject); }
public void Add(Prefix prefix, string word) { prefix = prefix.Copy(); if (!chain.ContainsKey(prefix)) chain.Add(prefix, new List<string>()); chain[prefix].Add(word); }
public ActionResult DeleteConfirmed(int id) { Prefix prefix = db.Prefixes.Find(id); db.Prefixes.Remove(prefix); db.SaveChanges(); return(RedirectToAction("Index")); }
public Unit(double quantity, Prefix prefix, BaseUnit baseUnit, sbyte power = 1) : this(quantity, baseUnit, power) { var prefixes = new sbyte[Length]; prefixes[(sbyte)baseUnit - 1] = (sbyte)prefix; this.Prefixes = new Vector <sbyte>(prefixes); }
/// <summary> /// [進入屏障] 在這之後透過 PutMethods 方法組放入的數據將被計算長度 /// </summary> /// <param name="prefixFlag"></param> /// <param name="endian"></param> protected void EnterBarrier(Prefix prefixFlag, Endian endian, uint extend = 0) { barExtLen = extend; barPos = bufferLength; prefix = prefixFlag; barLenEndian = endian; PutEmpty((int)prefixFlag); }
public void TestPrefixDefaultConstructor() { Prefix prefix = new Prefix(); Assert.AreEqual(string.Empty, prefix.Nick); Assert.AreEqual(string.Empty, prefix.UserName); Assert.AreEqual(string.Empty, prefix.HostName); Assert.IsFalse(prefix.Exists); }
public async Task <RuntimeResult> SetDefaultPrefix(string newPrefix) { string currentPrefix = Guild.Prefix; Prefix.Set(Context.Guild.Id, newPrefix); return(new InfoResult($"Prefix was **{currentPrefix}**, now changed to **{newPrefix}**")); }
public static Unit kat(this int number, Prefix prefix, sbyte power = 1) { if (power == 1) { return(number * Unit.Create(prefix, "kat")); } return(number * Unit.Create(prefix, "kat").Pow(power)); }
public static Unit ohm(this double number, Prefix prefix, sbyte power = 1) { if (power == 1) { return(number * Unit.Create(prefix, "Ω")); } return(number * Unit.Create(prefix, "Ω").Pow(power)); }
/// <summary> /// Returns true if Name instances are equal /// </summary> /// <param name="other">Instance of Name to be compared</param> /// <returns>Boolean</returns> public bool Equals(Name other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Uuid == other.Uuid || Uuid != null && Uuid.Equals(other.Uuid) ) && ( Alias == other.Alias || Alias != null && Alias.Equals(other.Alias) ) && ( First == other.First || First != null && First.Equals(other.First) ) && ( Family == other.Family || Family != null && Family.Equals(other.Family) ) && ( Given == other.Given || Given != null && Given.SequenceEqual(other.Given) ) && ( Prefix == other.Prefix || Prefix != null && Prefix.SequenceEqual(other.Prefix) ) && ( Suffix == other.Suffix || Suffix != null && Suffix.SequenceEqual(other.Suffix) ) && ( Creation == other.Creation || Creation != null && Creation.Equals(other.Creation) ) && ( LastUpdated == other.LastUpdated || LastUpdated != null && LastUpdated.Equals(other.LastUpdated) )); }
public Prefix ConvertData() { Prefix data = new Prefix() { Id = this.Id }; return(data); }
public object Visit(Prefix obj) { string codeString = ""; //<Prefix> ::= '-' codeString += obj.PrefixSymbol; return(codeString); }
public ActionResult Create(Prefix prefix) { if (ModelState.IsValid) { db.Prefixes.Add(prefix); db.SaveChanges(); return RedirectToAction("Index"); } return View(prefix); }
public Ping(string server, Prefix prefix, string message) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (String.IsNullOrWhiteSpace(message)) throw new ArgumentException("Null or whitespace string", "message"); this.server = server; this.prefix = prefix; this.message = message; this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, Ping.CanonicalCommand, ":{0}", this.Message); }
public Pass(string server, Prefix prefix, string password) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (String.IsNullOrWhiteSpace(password)) throw new ArgumentException("Null or whitespace string", "password"); this.server = server; this.prefix = prefix; this.password = password; this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, Pass.CanonicalCommand, "{0}", this.Password); }
public List(string server, Prefix prefix, IImmutableList<string> channels) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (channels == null) throw new ArgumentNullException("channels"); if (channels.Count == 0 || channels.Any(c => String.IsNullOrWhiteSpace(c))) throw new ArgumentException("Empty channel list or list contains an empty element.", "channels"); this.server = server; this.prefix = prefix; this.channels = channels; this.ircMessage = Common.CreateIrcMessageFormat(prefix, List.CanonicalCommand, "{0}", String.Join(",", this.Channels)); }
public Part(string server, Prefix prefix, IImmutableList<string> destinations) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (destinations == null) throw new ArgumentNullException("destinations"); if (destinations.Count == 0 || destinations.Any(c => String.IsNullOrWhiteSpace(c))) throw new ArgumentException("Empty destination list or list contains an empty element.", "destinations"); this.server = server; this.prefix = prefix; this.destinations = destinations; this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, Part.CanonicalCommand, "{0}", this.Destinations); }
/// <summary> /// Parses strings like: /// PFX A 0 re . /// </summary> /// <param name="data"></param> /// <returns>null if parsing failes</returns> public static Prefix Parse(string[] data) { if (data.Length != 5) return null; if (data[0] != "PFX") return null; Prefix pfx = new Prefix (); if (!pfx.ParseData (data)) return null; return pfx; }
public Message(string server, Prefix prefix, string command, IImmutableList<string> parameters) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("String null or empty", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (String.IsNullOrWhiteSpace(command)) throw new ArgumentException("String null or empty", "command"); if (parameters == null) throw new ArgumentNullException("parameters"); if (parameters.Any(s => String.IsNullOrWhiteSpace(s))) throw new ArgumentException("Empty or null parameter", "parameters"); this.server = server; this.prefix = prefix; this.command = command; this.parameters = parameters; }
public void EqualityTest() { var p1 = new Prefix(_prefixConfig, "DEV", "iphone"); var p2 = new Prefix(_prefixConfig, "DEV"); var p3 = new Prefix(_prefixConfig, "stageB"); var p4 = new Prefix(_prefixConfig, "DEV", "iphone"); Assert.IsTrue(p1.CompareTo(p2) > 0); Assert.IsTrue(p1.CompareTo(p3) > 0); Assert.IsTrue(p2.CompareTo(p3) > 0); Assert.AreNotEqual(p1, p2); Assert.AreEqual(p1, p4); }
public User(string server, Prefix prefix, string userName, string realName, UserModes userMode) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (String.IsNullOrWhiteSpace(userName)) throw new ArgumentException("Null or whitespace string", "userName"); if (String.IsNullOrWhiteSpace(realName)) throw new ArgumentException("Null or whitespace string", "realName"); this.server = server; this.prefix = prefix; this.userName = userName; this.realName = realName; this.userModes = userMode; this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, User.CanonicalCommand, "{0} {1} * :{2}", this.UserName, (int)this.UserMode, this.RealName); }
public PrefixDef(int prefixID, Prefix prefix) { this.prefixID = prefixID; this.prefix = prefix; Item item = new Item(); item.SetDefaults("Unloaded Item"); item.value = 100000; prefix.Apply(item); categories["Positive"] = item.value >= 100000; categories["Negative"] = item.value < 100000; showcaseItem = GetShowcaseItem(prefix); }
private static IEnumerable<string> Generate(WordChain suffixChain, int count) { var prefix = new Prefix(); var words = Enumerable .Range(1, count) .Select(_ => suffixChain.Get(prefix)) .TakeWhile(next => next != NONWORD); foreach (var next in words) { yield return next; prefix.Add(next); } }
public Join(string server, Prefix prefix, IImmutableList<string> channels, Maybe<IImmutableList<string>> keys) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (channels == null) throw new ArgumentNullException("channels"); if (channels.Count == 0 || channels.Any(c => String.IsNullOrWhiteSpace(c))) throw new ArgumentException("Empty channel list or list contains an empty element.", "channels"); if (keys.HasValue && keys.Value.Count != 0 && (keys.Value.Count != channels.Count || keys.Value.Any(k => String.IsNullOrWhiteSpace(k)))) throw new ArgumentException("Non-empty key list contains an empty element or doesn't have the same number of elements as the channel list.", "keys"); this.server = server; this.prefix = prefix; this.channels = channels; this.keys = keys.DefaultIfEmpty(ImmutableList<string>.Empty).Single(); this.ircMessage = Common.CreateIrcMessageFormat(prefix, Join.CanonicalCommand, "{0} {1}", String.Join(",", this.Channels), String.Join(",", this.Keys)); }
/// <summary> /// Initializes a new instance of the <see cref="MethodUnit" /> class. /// </summary> /// <param name="prefix">The prefix.</param> /// <param name="toBase">To base.</param> /// <param name="fromBase">From base.</param> /// <param name="notation">The notation.</param> /// <param name="expression">The expression.</param> public MethodUnit( Prefix prefix, Func<double, double> toBase, Func<double, double> fromBase, string notation, Expression expression) { this.prefix = prefix ?? Prefix.None; this.toBase = toBase; this.fromBase = fromBase; this.notation = notation; this.expression = expression; this.BaseUnit = new DerivedBaseUnit(expression); this.unitExpression = new UnitExpression(this); }
public void CompareTest() { var p1 = new Prefix(_prefixConfig, "DEV", "iphone"); var p2 = new Prefix(_prefixConfig, "DEV"); var p3 = new Prefix(_prefixConfig, "stageB"); var p4 = new Prefix(_prefixConfig, "DEV", "iphone"); var p5 = new Prefix(_prefixConfig, "ios", "iphone"); var prefixes = new [] {p1, p2, p3, p4, p5}; var max = prefixes.Max(); var min = prefixes.Min(); Assert.AreEqual(max, p1); Assert.AreEqual(min, p3); Assert.IsTrue(p2.CompareTo(p5) < 0); }
public Quit(string server, Prefix prefix, Maybe<string> message) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); this.server = server; this.prefix = prefix; this.message = message.DefaultIfEmpty(String.Empty).Single(); if (this.Message != String.Empty) { this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, Quit.CanonicalCommand, ":{0}", this.Message); } else { this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, Quit.CanonicalCommand, ""); } }
public void TestPrefixIrcMessage() { // Empty Prefix prefix = new Prefix(); Assert.AreEqual(string.Empty, prefix.IrcMessage); // Nick only prefix = new Prefix("nickname", string.Empty, string.Empty); Assert.AreEqual("nickname", prefix.IrcMessage); // Nick with user prefix = new Prefix("nickname", "username", string.Empty); Assert.AreEqual("nickname", prefix.IrcMessage); // Nick with user and host prefix = new Prefix("nickname", "username", "hostname"); Assert.AreEqual("nickname!username@hostname", prefix.IrcMessage); }
internal static string UnitToString(Prefix prefix, string unit, int power, bool fancy = true) { StringBuilder s = new StringBuilder(); if (power != 0) { if (prefix != 0) s.Append(prefix); s.Append(unit); if (power != 1) { if (fancy) s.Append(SS(power)); else s.Append("^").Append(power); } return s.ToString(); } else return ""; }
public Kick(string server, Prefix prefix, string channel, string nick, Maybe<string> reason) { if (String.IsNullOrWhiteSpace(server)) throw new ArgumentException("Null or whitespace string", "server"); if (prefix == null) throw new ArgumentNullException("prefix"); if (String.IsNullOrWhiteSpace(channel)) throw new ArgumentException("Null or whitespace string", "channel"); this.server = server; this.prefix = prefix; this.channel = channel; this.nick = nick; this.reason = reason.DefaultIfEmpty(String.Empty).Single(); if (this.Reason != String.Empty) { this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, Kick.CanonicalCommand, "{0} {1} :{2}", this.Channel, this.Nick, this.Reason); } else { this.ircMessage = Common.CreateIrcMessageFormat(this.Prefix, Kick.CanonicalCommand, "{0} {1}", this.Channel, this.Nick); } }
public void TestPrefixAlternateConstructor() { // Empty parameters Prefix prefix = new Prefix(string.Empty, string.Empty, string.Empty); Assert.AreEqual(string.Empty, prefix.Nick); Assert.AreEqual(string.Empty, prefix.UserName); Assert.AreEqual(string.Empty, prefix.HostName); Assert.IsFalse(prefix.Exists); // Nick only prefix = new Prefix("nickname", string.Empty, string.Empty); Assert.AreEqual("nickname", prefix.Nick); Assert.AreEqual(string.Empty, prefix.UserName); Assert.AreEqual(string.Empty, prefix.HostName); Assert.IsTrue(prefix.Exists); // Nick with user prefix = new Prefix("nickname", "username", string.Empty); Assert.AreEqual("nickname", prefix.Nick); Assert.AreEqual(string.Empty, prefix.UserName); Assert.AreEqual(string.Empty, prefix.HostName); Assert.IsTrue(prefix.Exists); // Nick with host prefix = new Prefix("nickname", string.Empty, "hostname"); Assert.AreEqual("nickname", prefix.Nick); Assert.AreEqual(string.Empty, prefix.UserName); Assert.AreEqual(string.Empty, prefix.HostName); Assert.IsTrue(prefix.Exists); // Nick with user and host prefix = new Prefix("nickname", "username", "hostname"); Assert.AreEqual("nickname", prefix.Nick); Assert.AreEqual("username", prefix.UserName); Assert.AreEqual("hostname", prefix.HostName); Assert.IsTrue(prefix.Exists); }
private void ImportCall(ILOpcode opcode, int token) { bool callViaSlot = false; bool delegateInvoke = false; DelegateCreationInfo delegateInfo = null; bool mdArrayCreate = false; MethodDesc method = (MethodDesc)_methodIL.GetObject(token); if (method.IsIntrinsic) { if (ImportIntrinsicCall(method)) return; } TypeDesc constrained = null; if (opcode != ILOpcode.newobj) { if ((_pendingPrefix & Prefix.Constrained) != 0 && opcode == ILOpcode.callvirt) { _pendingPrefix &= ~Prefix.Constrained; constrained = _constrained; bool forceUseRuntimeLookup; MethodDesc directMethod = constrained.GetClosestMetadataType().TryResolveConstraintMethodApprox(method.OwningType, method, out forceUseRuntimeLookup); if (directMethod == null || forceUseRuntimeLookup) throw new NotImplementedException(); method = directMethod; opcode = ILOpcode.call; } } TypeDesc owningType = method.OwningType; TypeDesc retType = null; { if (opcode == ILOpcode.newobj) retType = owningType; if (opcode == ILOpcode.newobj) { if (owningType.IsString) { // String constructors actually look like regular method calls method = method.GetStringInitializer(); opcode = ILOpcode.call; // WORKAROUND: the static method expects an extra arg // Annoyingly, it needs to be before all the others _stack.InsertAt(new ExpressionEntry(StackValueKind.ObjRef, "0"), _stack.Top - method.Signature.Length + 1); } else if (owningType.IsArray) { mdArrayCreate = true; } else if (owningType.IsDelegate) { delegateInfo = _compilation.GetDelegateCtor(owningType, ((LdTokenEntry<MethodDesc>)_stack.Peek()).LdToken); method = delegateInfo.Constructor.Method; } } else if (owningType.IsDelegate) { if (method.Name == "Invoke") { opcode = ILOpcode.call; delegateInvoke = true; } } } if (opcode == ILOpcode.callvirt) { // TODO: Null checks if (method.IsVirtual) { // TODO: Full resolution of virtual methods if (!method.IsNewSlot) throw new NotImplementedException(); // TODO: Interface calls if (method.OwningType.IsInterface) throw new NotImplementedException(); _dependencies.Add(_nodeFactory.VirtualMethodUse(method)); callViaSlot = true; } } if (!callViaSlot && !delegateInvoke && !mdArrayCreate) AddMethodReference(method); if (opcode == ILOpcode.newobj) AddTypeReference(retType, true); var methodSignature = method.Signature; if (retType == null) retType = methodSignature.ReturnType; string temp = null; StackValueKind retKind = StackValueKind.Unknown; var needNewLine = false; if (!retType.IsVoid) { retKind = GetStackValueKind(retType); temp = NewTempName(); AppendLine(); Append(GetStackValueKindCPPTypeName(retKind, retType)); Append(" "); Append(temp); if (retType.IsValueType && opcode == ILOpcode.newobj) { Append(";"); needNewLine = true; } else { Append(" = "); if (retType.IsPointer) { Append("(intptr_t)"); } } } else { needNewLine = true; } if (opcode == ILOpcode.newobj && !mdArrayCreate) { if (!retType.IsValueType) { // We do not reset needNewLine since we still need for the next statement. if (needNewLine) AppendLine(); Append("__allocate_object("); Append(_writer.GetCppTypeName(retType)); Append("::__getMethodTable())"); AppendSemicolon(); needNewLine = true; if (delegateInfo != null && delegateInfo.Thunk != null) { MethodDesc thunkMethod = delegateInfo.Thunk.Method; AddMethodReference(thunkMethod); // Update stack with new name. ((ExpressionEntry) _stack[_stack.Top - 2]).Name = temp; var sb = new CppGenerationBuffer(); AppendLine(); sb.Append("(intptr_t)&"); sb.Append(_writer.GetCppTypeName(thunkMethod.OwningType)); sb.Append("::"); sb.Append(_writer.GetCppMethodName(thunkMethod)); PushExpression(StackValueKind.NativeInt, sb.ToString()); } } } if (needNewLine) AppendLine(); if (callViaSlot || delegateInvoke) { // While waiting for C# return by ref, get this reference and insert it back // if it is a delegate invoke. ExpressionEntry v = (ExpressionEntry) _stack[_stack.Top - (methodSignature.Length + 1)]; Append("(*"); Append(_writer.GetCppTypeName(method.OwningType)); Append("::"); Append(delegateInvoke ? "__invoke__" : "__getslot__"); Append(_writer.GetCppMethodName(method)); Append("("); Append(v); Append("))"); if (delegateInvoke) { v.Name = "((" + _writer.GetCppSignatureTypeName(GetWellKnownType(WellKnownType.MulticastDelegate)) + ")" + v.Name + ")->m_firstParameter"; } } else if (mdArrayCreate) { Append("RhNewMDArray"); } else { Append(_writer.GetCppTypeName(method.OwningType)); Append("::"); Append(_writer.GetCppMethodName(method)); } TypeDesc thisArgument = null; Append("("); if (mdArrayCreate) { Append(_writer.GetCppTypeName(method.OwningType)); Append("::__getMethodTable(), "); Append(((ArrayType)method.OwningType).Rank.ToStringInvariant()); Append(", "); } else if (opcode == ILOpcode.newobj) { Append("("); if (retType.IsValueType) { Append(_writer.GetCppSignatureTypeName(retType.MakeByRefType())); Append(")"); Append("&" + temp); } else { Append(_writer.GetCppSignatureTypeName(retType)); Append(")"); Append(temp); } if (methodSignature.Length > 0) Append(", "); } else { if (!methodSignature.IsStatic) { thisArgument = owningType; if (thisArgument.IsValueType) thisArgument = thisArgument.MakeByRefType(); } } PassCallArguments(methodSignature, thisArgument); Append(")"); if (temp != null) { Debug.Assert(retKind != StackValueKind.Unknown, "Valid return type"); PushExpression(retKind, temp, retType); } AppendSemicolon(); }
private void ImportConstrainedPrefix(int token) { _pendingPrefix |= Prefix.Constrained; _constrained = ResolveTypeToken(token); }
private void ImportCall(ILOpcode opcode, int token) { bool callViaSlot = false; bool delegateInvoke = false; DelegateInfo delegateInfo = null; bool mdArrayCreate = false; MethodDesc method = (MethodDesc)_methodIL.GetObject(token); var intrinsicClassification = IntrinsicMethods.GetIntrinsicMethodClassification(method); if (intrinsicClassification != IntrinsicMethodKind.None) { ImportIntrinsicCall(intrinsicClassification); return; } if (opcode == ILOpcode.calli) throw new NotImplementedException(); TypeDesc constrained = null; if (opcode != ILOpcode.newobj) { if ((_pendingPrefix & Prefix.Constrained) != 0 && opcode == ILOpcode.callvirt) { _pendingPrefix &= ~Prefix.Constrained; constrained = _constrained; // TODO: throw new NotImplementedException(); } } TypeDesc retType = null; { TypeDesc owningType = method.OwningType; if (opcode == ILOpcode.newobj) retType = owningType; if (opcode == ILOpcode.newobj) { if (owningType.IsString) { // String constructors actually look like regular method calls method = IntrinsicMethods.GetStringInitializer(method); opcode = ILOpcode.call; // WORKAROUND: the static method expects an extra arg // Annoyingly, it needs to be before all the others if (_stackTop >= _stack.Length) Array.Resize(ref _stack, 2 * _stackTop + 3); for (int i = _stackTop - 1; i > _stackTop - method.Signature.Length; i--) _stack[i + 1] = _stack[i]; _stackTop++; _stack[_stackTop - method.Signature.Length] = new StackValue { Kind = StackValueKind.ObjRef, Value = new Value("0") }; } else if (owningType.IsArray) { mdArrayCreate = true; } else if (owningType.IsDelegate) { delegateInfo = _compilation.GetDelegateCtor((MethodDesc)_stack[_stackTop - 1].Value.Aux); method = delegateInfo.Ctor; } } else if (owningType.IsDelegate) { if (method.Name == "Invoke") { opcode = ILOpcode.call; delegateInvoke = true; } } } if (opcode == ILOpcode.callvirt) { // TODO: Null checks if (method.IsVirtual) { // TODO: Full resolution of virtual methods if (!method.IsNewSlot) throw new NotImplementedException(); // TODO: Interface calls if (method.OwningType.IsInterface) throw new NotImplementedException(); _compilation.AddVirtualSlot(method); callViaSlot = true; } } if (!callViaSlot && !delegateInvoke && !mdArrayCreate) _compilation.AddMethod(method); if (opcode == ILOpcode.newobj) _compilation.MarkAsConstructed(retType); var methodSignature = method.Signature; if (retType == null) retType = methodSignature.ReturnType; string temp = null; StackValueKind retKind = StackValueKind.Unknown; if (!retType.IsVoid) { retKind = GetStackValueKind(retType); temp = NewTempName(); Append(GetStackValueKindCPPTypeName(retKind, retType)); Append(" "); Append(temp); if (retType.IsValueType && opcode == ILOpcode.newobj) { Append(";"); } else { Append("="); if (retType.IsPointer) { Append("(intptr_t)"); } } } if (opcode == ILOpcode.newobj && !mdArrayCreate) { if (!retType.IsValueType) { _compilation.AddType(retType); Append("__allocate_object("); Append(_writer.GetCppTypeName(retType)); Append("::__getMethodTable())"); Finish(); if (delegateInfo != null && delegateInfo.ShuffleThunk != null) { _stack[_stackTop - 2].Value.Name = temp; StringBuilder sb = new StringBuilder(); sb.Append("(intptr_t)&"); sb.Append(_writer.GetCppTypeName(delegateInfo.ShuffleThunk.OwningType)); sb.Append("::"); sb.Append(_writer.GetCppMethodName(delegateInfo.ShuffleThunk)); Push(StackValueKind.NativeInt, new Value(sb.ToString()), null); } } } if (callViaSlot || delegateInvoke) { Append("(*"); Append(_writer.GetCppTypeName(method.OwningType)); Append("::"); Append(delegateInvoke ? "__invoke__" : "__getslot__"); Append(_writer.GetCppMethodName(method)); Append("("); Append(_stack[_stackTop - (methodSignature.Length + 1)].Value.Name); Append("))"); if (delegateInvoke) { _stack[_stackTop - (methodSignature.Length + 1)].Value.Name = "((" + _writer.GetCppSignatureTypeName(GetWellKnownType(WellKnownType.MulticastDelegate)) + ")" + _stack[_stackTop - (methodSignature.Length + 1)].Value.Name + ")->m_firstParameter"; } } else if (mdArrayCreate) { _compilation.AddType(method.OwningType); Append("RhNewMDArray"); } else { Append(_writer.GetCppTypeName(method.OwningType)); Append("::"); Append(_writer.GetCppMethodName(method)); } Append("("); int count = methodSignature.Length; bool hasThis = !methodSignature.IsStatic; if (hasThis) count++; if (mdArrayCreate) { Append(_writer.GetCppTypeName(method.OwningType)); Append("::__getMethodTable(), "); Append(((ArrayType)method.OwningType).Rank.ToString()); Append(", "); count--; } else if (opcode == ILOpcode.newobj) { Append("("); if (retType.IsValueType) { Append(_writer.GetCppSignatureTypeName(retType.MakeByRefType())); Append(")"); Append("&" + temp); } else { Append(_writer.GetCppSignatureTypeName(retType)); Append(")"); Append(temp); } count--; if (count > 0) Append(", "); } for (int i = 0; i < count; i++) { var op = _stack[_stackTop - count + i]; int argIndex = methodSignature.Length - (count - i); TypeDesc argType; if (argIndex == -1) { argType = method.OwningType; if (argType.IsValueType) argType = argType.MakeByRefType(); } else { argType = methodSignature[argIndex]; } AppendCastIfNecessary(argType, op.Kind); Append(op.Value.Name); if (i != count - 1) Append(", "); } _stackTop -= count; Append(")"); if (temp != null) Push(retKind, new Value(temp), retType); Finish(); }
private void ImportCall(ILOpcode opcode, int token) { bool callViaSlot = false; bool delegateInvoke = false; bool callViaInterfaceDispatch = false; DelegateCreationInfo delegateInfo = null; MethodDesc method = (MethodDesc)_methodIL.GetObject(token); if (method.IsIntrinsic) { if (ImportIntrinsicCall(method)) return; } TypeDesc constrained = null; if (opcode != ILOpcode.newobj) { if ((_pendingPrefix & Prefix.Constrained) != 0 && opcode == ILOpcode.callvirt) { _pendingPrefix &= ~Prefix.Constrained; constrained = _constrained; bool forceUseRuntimeLookup; MethodDesc directMethod = constrained.GetClosestDefType().TryResolveConstraintMethodApprox(method.OwningType, method, out forceUseRuntimeLookup); if (forceUseRuntimeLookup) throw new NotImplementedException(); if (directMethod != null) { method = directMethod; opcode = ILOpcode.call; } else { // Dereference "this" int thisPosition = _stack.Top - (method.Signature.Length + 1); string tempName = NewTempName(); Append(GetStackValueKindCPPTypeName(StackValueKind.ObjRef)); Append(" "); Append(tempName); Append(" = *("); Append(GetStackValueKindCPPTypeName(StackValueKind.ObjRef)); Append("*)"); Append(_stack[thisPosition]); AppendSemicolon(); _stack[thisPosition] = new ExpressionEntry(StackValueKind.ObjRef, tempName); } } } TypeDesc owningType = method.OwningType; TypeDesc retType = null; { if (opcode == ILOpcode.newobj) { retType = owningType; if (owningType.IsString) { // String constructors actually look like regular method calls method = method.GetStringInitializer(); opcode = ILOpcode.call; } else if (owningType.IsArray) { ImportNewObjArray(owningType, method); return; } else if (owningType.IsDelegate) { delegateInfo = _compilation.GetDelegateCtor(owningType, ((LdTokenEntry<MethodDesc>)_stack.Peek()).LdToken); method = delegateInfo.Constructor.Method; } } else if (owningType.IsDelegate) { if (method.Name == "Invoke") { opcode = ILOpcode.call; delegateInvoke = true; } } } if (opcode == ILOpcode.callvirt) { // TODO: Null checks if (method.IsVirtual) { // TODO: Full resolution of virtual methods if (!method.IsNewSlot) throw new NotImplementedException(); if (method.OwningType.IsInterface) callViaInterfaceDispatch = true; else callViaSlot = true; _dependencies.Add(_nodeFactory.VirtualMethodUse(method)); } } if (!callViaSlot && !delegateInvoke && !callViaInterfaceDispatch) AddMethodReference(method); if (opcode == ILOpcode.newobj) AddTypeReference(retType, true); var methodSignature = method.Signature; if (retType == null) retType = methodSignature.ReturnType; string temp = null; StackValueKind retKind = StackValueKind.Unknown; var needNewLine = false; if (callViaInterfaceDispatch) { _dependencies.Add(_nodeFactory.ReadyToRunHelper(ReadyToRunHelperId.VirtualCall, method)); ExpressionEntry v = (ExpressionEntry)_stack[_stack.Top - (methodSignature.Length + 1)]; string typeDefName = _writer.GetCppMethodName(method); _writer.AppendSignatureTypeDef(_builder, typeDefName, method.Signature, method.OwningType); string functionPtr = NewTempName(); AppendEmptyLine(); Append("void*"); Append(functionPtr); Append(" = (void*) (("); Append(typeDefName); // Call method to find implementation address Append(") System_Private_CoreLib::System::Runtime::DispatchResolve::FindInterfaceMethodImplementationTarget("); // Get EEType of current object (interface implementation) Append("::System_Private_CoreLib::System::Object::get_EEType((::System_Private_CoreLib::System::Object*)"); Append(v.Name); Append(")"); Append(", "); // Get EEType of interface Append("((::System_Private_CoreLib::Internal::Runtime::EEType *)("); Append(_writer.GetCppTypeName(method.OwningType)); Append("::__getMethodTable()))"); Append(", "); // Get slot of implementation Append("(uint16_t)"); Append("("); Append(_writer.GetCppTypeName(method.OwningType)); Append("::"); Append("__getslot__"); Append(_writer.GetCppMethodName(method)); Append("("); Append(v.Name); Append("))"); Append("));"); PushExpression(StackValueKind.ByRef, functionPtr); } if (!retType.IsVoid) { retKind = GetStackValueKind(retType); temp = NewTempName(); AppendLine(); Append(GetStackValueKindCPPTypeName(retKind, retType)); Append(" "); Append(temp); if (retType.IsValueType && opcode == ILOpcode.newobj) { Append(";"); needNewLine = true; } else { Append(" = "); if (retType.IsPointer) { Append("(intptr_t)"); } } } else { needNewLine = true; } AddTypeReference(method.OwningType, true); if (opcode == ILOpcode.newobj) { if (!retType.IsValueType) { // We do not reset needNewLine since we still need for the next statement. if (needNewLine) AppendLine(); Append("__allocate_object("); Append(_writer.GetCppTypeName(retType)); Append("::__getMethodTable())"); AppendSemicolon(); needNewLine = true; if (delegateInfo != null && delegateInfo.Thunk != null) { MethodDesc thunkMethod = delegateInfo.Thunk.Method; AddMethodReference(thunkMethod); // Update stack with new name. ((ExpressionEntry)_stack[_stack.Top - 2]).Name = temp; var sb = new CppGenerationBuffer(); AppendLine(); sb.Append("(intptr_t)&"); sb.Append(_writer.GetCppTypeName(thunkMethod.OwningType)); sb.Append("::"); sb.Append(_writer.GetCppMethodName(thunkMethod)); PushExpression(StackValueKind.NativeInt, sb.ToString()); } } } if (needNewLine) AppendLine(); if (callViaSlot || delegateInvoke) { ExpressionEntry v = (ExpressionEntry)_stack[_stack.Top - (methodSignature.Length + 1)]; Append("(*"); Append(_writer.GetCppTypeName(method.OwningType)); Append("::"); Append(delegateInvoke ? "__invoke__" : "__getslot__"); Append(_writer.GetCppMethodName(method)); Append("("); Append(v); Append("))"); if (delegateInvoke) { v.Name = "((" + _writer.GetCppSignatureTypeName(GetWellKnownType(WellKnownType.MulticastDelegate)) + ")" + v.Name + ")->m_firstParameter"; } } else if (callViaInterfaceDispatch) { Append("(("); Append(_writer.GetCppMethodName(method)); Append(")"); ExpressionEntry v = (ExpressionEntry)_stack.Pop(); Append(v); Append(")"); } else { Append(_writer.GetCppTypeName(method.OwningType)); Append("::"); Append(_writer.GetCppMethodName(method)); } TypeDesc thisArgument = null; Append("("); if (opcode == ILOpcode.newobj) { Append("("); if (retType.IsValueType) { Append(_writer.GetCppSignatureTypeName(retType.MakeByRefType())); Append(")"); Append("&" + temp); } else { Append(_writer.GetCppSignatureTypeName(retType)); Append(")"); Append(temp); } if (methodSignature.Length > 0) Append(", "); } else { if (!methodSignature.IsStatic) { thisArgument = owningType; if (thisArgument.IsValueType) thisArgument = thisArgument.MakeByRefType(); } } PassCallArguments(methodSignature, thisArgument); Append(")"); if (temp != null) { Debug.Assert(retKind != StackValueKind.Unknown, "Valid return type"); PushExpression(retKind, temp, retType); } AppendSemicolon(); }