/// <summary> /// Get the Type that is supposed to define the member we are about to invoke. /// </summary> /// <param name="node">Parse node describing the primitive call.</param> /// <returns>Type that is supposed to define the member we are about to invoke.</returns> private Type GetDefiningType(Compiler.SemanticNodes.PrimitiveCallNode node) { String definingTypeName = node.ApiParameters[0].Value; // Get the type that is expected to implement the member we are looking for. Type definingType = NativeTypeClassMap.GetType(definingTypeName); if (definingType == null) { throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongTypeName, definingTypeName)).SetErrorLocation(node); } return(definingType); }
protected Expression UnaryOperation(Conversion conversion, Func <Expression, Type, Expression> func) { if (this.Parameters == null) { return(null); } if (this.Parameters.Count != 1) { return(null); } Type type = (this.Parameters[0] == "self") ? null : NativeTypeClassMap.GetType(this.Parameters[0]); Type[] types = new Type[] { type }; IList <Expression> args = this.GetArguments(types, conversion); return(func(args[0], type)); }
protected Type[] GetArgumentTypes(IEnumerable <string> parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } // Then get type definitions for each parameter we are to pass to the member. bool first = true; List <Type> argumentTypes = new List <Type>(); foreach (string typeName in parameters) { // Special case, for lazy people, the first parameter type can be "this", meaning the same as the defining type. if (first && (typeName == "this")) { if (this.DefiningType == null) { throw new ArgumentNullException("this.DefiningType"); } argumentTypes.Add(this.DefiningType); } else { // Get the parameter type, if we fail to find one, throw an exception now! Type type = NativeTypeClassMap.GetType(typeName); if (type == null) { throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongTypeName, typeName)); } argumentTypes.Add(type); } first = false; } return(argumentTypes.ToArray()); }
private Expression Shift() { if (this.Parameters == null) { return(null); } if (this.Parameters.Count != 2) { return(null); } // We don't support if the shift parameter is other than int if (NativeTypeClassMap.GetType(this.Parameters[1]) != typeof(int)) { throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongShiftTypeName, this.Parameters[1])); } Type type = NativeTypeClassMap.GetType(this.Parameters[0]); int bits; if (type == typeof(System.Numerics.BigInteger)) { bits = 0; } else if (type == typeof(Int64)) { bits = -63; } else if (type == typeof(Int32)) { bits = -31; } else if (type == typeof(Int16)) { bits = -15; } else if (type == typeof(SByte)) { bits = -7; } else if (type == typeof(UInt64)) { bits = 64; } else if (type == typeof(UInt32)) { bits = 32; } else if (type == typeof(UInt16)) { bits = 16; } else if (type == typeof(Byte)) { bits = 8; } else { throw new PrimitiveInvalidTypeException(String.Format(CodeGenerationErrors.WrongShiftTypeName, this.Parameters[0])); } IList <Expression> args = this.GetArguments(new Type[] { type, typeof(int) }, Conversion.Checked); Expression value = args[0]; Expression shift = args[1]; Expression zero = this.GetZero(type); return(this.Shift(value, shift, type, bits, zero)); }