public void SetParameterValue(string parameterName, string value, ParameterType parameterType, ISequenceStep sequence) { IParameterData data = ModuleUtils.FindParameterByName(parameterName, sequence); data.Value = value; data.ParameterType = parameterType; }
// // Imports SRE parameters // public static AParametersCollection Create(ParameterInfo [] pi, MethodBase method) { if (pi.Length == 0) { if (method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0) { return(new ParametersCollection(new IParameterData [0], Type.EmptyTypes, method, false)); } return(Parameters.EmptyReadOnlyParameters); } Type [] types = new Type [pi.Length]; IParameterData [] par = new IParameterData [pi.Length]; bool is_params = false; for (int i = 0; i < types.Length; i++) { types [i] = TypeManager.TypeToCoreType(pi [i].ParameterType); ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; if (types [i].IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) { mod = Parameter.Modifier.OUT; } else { mod = Parameter.Modifier.REF; } // // Strip reference wrapping // types [i] = TypeManager.GetElementType(types [i]); } else if (i == 0 && TypeManager.extension_attribute_type != null && method != null && method.IsStatic && (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute && method.IsDefined(TypeManager.extension_attribute_type, false)) { mod = Parameter.Modifier.This; } else if (i >= pi.Length - 2 && types [i].IsArray) { if (p.IsDefined(TypeManager.param_array_type, false)) { mod = Parameter.Modifier.PARAMS; is_params = true; } } par [i] = new ParameterData(p.Name, mod); } return(method != null ? new ParametersCollection(par, types, method, is_params) : new ParametersCollection(par, types)); }
private bool VerifyVariableInSequenceStep(ISequenceStep sequenceStep, IVariable variable, TypeDataCollection typeDatas) { if ((null != sequenceStep.LoopCounter && variable.Name.Equals(sequenceStep.LoopCounter.CounterVariable)) || (null != sequenceStep.RetryCounter) && variable.Name.Equals(sequenceStep.RetryCounter.CounterVariable)) { Type varType = typeof(int); ITypeData typeData = typeDatas.GetTypeData(varType.Name); if (null == typeData) { variable.Type = _comInterfaceManager.GetTypeByName(varType.Name, varType.Namespace); } return(true); } if (null != sequenceStep.Function) { IFunctionData functionData = sequenceStep.Function; if (variable.Name.Equals(functionData.Instance)) { variable.Type = functionData.ClassType; return(true); } if (variable.Name.Equals(functionData.Return)) { variable.Type = functionData.ReturnType.Type; return(true); } IParameterData parameter = functionData.Parameters.FirstOrDefault (item => item.ParameterType == ParameterType.Variable && variable.Name.Equals(item.Value)); if (null != parameter) { variable.Type = functionData.ParameterType[parameter.Index].Type; return(true); } } if (sequenceStep.HasSubSteps) { foreach (ISequenceStep subStep in sequenceStep.SubSteps) { bool verified = VerifyVariableInSequenceStep(subStep, variable, typeDatas); if (verified) { return(true); } } } return(false); }
protected void CheckReservedNameConflict (string prefix, MethodSpec accessor) { string name; AParametersCollection parameters; if (accessor != null) { name = accessor.Name; parameters = accessor.Parameters; } else { name = prefix + ShortName; if (IsExplicitImpl) name = MemberName.Left + "." + name; if (this is Indexer) { parameters = ((Indexer) this).ParameterInfo; if (prefix[0] == 's') { var data = new IParameterData[parameters.Count + 1]; Array.Copy (parameters.FixedParameters, data, data.Length - 1); data[data.Length - 1] = new ParameterData ("value", Parameter.Modifier.NONE); var types = new TypeSpec[data.Length]; Array.Copy (parameters.Types, types, data.Length - 1); types[data.Length - 1] = member_type; parameters = new ParametersImported (data, types, false); } } else { if (prefix[0] == 's') parameters = ParametersCompiled.CreateFullyResolved (new[] { member_type }); else parameters = ParametersCompiled.EmptyReadOnlyParameters; } } var conflict = MemberCache.FindMember (Parent.Definition, new MemberFilter (name, 0, MemberKind.Method, parameters, null), BindingRestriction.DeclaredOnly | BindingRestriction.NoAccessors); if (conflict != null) { Report.SymbolRelatedToPreviousError (conflict); Report.Error (82, Location, "A member `{0}' is already reserved", conflict.GetSignatureForError ()); } }
// 更新所有被ref或out修饰的参数值。如果变量的LogRecordLevel为Trace,则将更新的值写入日志。 private void UpdateParamVariableValue() { for (int i = 0; i < Params.Length; i++) { IArgument argument = Function.ParameterType[i]; IParameterData parameter = Function.Parameters[i]; // 如果参数值是直接传递值,或者参数没有使用ref或out修饰,则返回 if (parameter.ParameterType == ParameterType.Value || argument.Modifier == ArgumentModifier.None) { continue; } object value = Params[i]; // variableName已经是运行时名称 string runtimeVariableName = ModuleUtils.GetVariableNameFromParamValue(parameter.Value); Context.VariableMapper.SetParamValue(runtimeVariableName, parameter.Value, value); IVariable variable = CoreUtils.GetVariable(Context.Sequence, runtimeVariableName); if (variable.LogRecordLevel == RecordLevel.Trace) { LogTraceVariable(variable, value); } } }
ParametersCollection (IParameterData [] parameters, Type [] types, MethodBase method, bool hasParams) { this.parameters = parameters; this.types = types; has_arglist = (method.CallingConvention & CallingConventions.VarArgs) != 0; if (has_arglist) { this.parameters = new IParameterData [parameters.Length + 1]; parameters.CopyTo (this.parameters, 0); this.parameters [parameters.Length] = new ArglistParameter (Location.Null); this.types = new Type [types.Length + 1]; types.CopyTo (this.types, 0); this.types [types.Length] = TypeManager.arg_iterator_type; } has_params = hasParams; }
public int IndexOf(IParameterData item) { return(_innerCollection.IndexOf(item)); }
public ParametersImported (IParameterData[] param, TypeSpec[] types, bool hasParams) { this.parameters = param; this.types = types; this.has_params = hasParams; }
// // Imports System.Reflection parameters // AParametersCollection CreateParameters (TypeSpec parent, ParameterInfo[] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) return ParametersCompiled.EmptyReadOnlyParameters; TypeSpec[] types = new TypeSpec[pi.Length + varargs]; IParameterData[] par = new IParameterData[pi.Length + varargs]; bool is_params = false; for (int i = 0; i < pi.Length; i++) { ParameterInfo p = pi[i]; Parameter.Modifier mod = 0; Expression default_value = null; if (p.ParameterType.IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // var el = p.ParameterType.GetElementType (); types[i] = ImportType (el, new DynamicTypeReader (p)); // TODO: 1-based positio to be csc compatible } else if (i == 0 && method.IsStatic && parent.IsStatic && parent.MemberDefinition.DeclaringAssembly.HasExtensionMethod && HasAttribute (CustomAttributeData.GetCustomAttributes (method), "ExtensionAttribute", CompilerServicesNamespace)) { mod = Parameter.Modifier.This; types[i] = ImportType (p.ParameterType); } else { types[i] = ImportType (p.ParameterType, new DynamicTypeReader (p)); if (i >= pi.Length - 2 && types[i] is ArrayContainer) { if (HasAttribute (CustomAttributeData.GetCustomAttributes (p), "ParamArrayAttribute", "System")) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.RawDefaultValue; var ptype = types[i]; if ((p.Attributes & ParameterAttributes.HasDefault) != 0 && ptype.Kind != MemberKind.TypeParameter && (value != null || TypeSpec.IsReferenceType (ptype))) { if (value == null) { default_value = Constant.CreateConstant (ptype, null, Location.Null); } else { default_value = ImportParameterConstant (value); if (ptype.IsEnum) { default_value = new EnumConstant ((Constant) default_value, ptype); } } } else if (value == Missing.Value) { default_value = EmptyExpression.MissingValue; } else if (value == null) { default_value = new DefaultValueExpression (new TypeExpression (ptype, Location.Null), Location.Null); } else if (ptype.BuiltinType == BuiltinTypeSpec.Type.Decimal) { default_value = ImportParameterConstant (value); } } } par[i] = new ParameterData (p.Name, mod, default_value); } if (varargs != 0) { par[par.Length - 1] = new ArglistParameter (Location.Null); types[types.Length - 1] = InternalType.Arglist; } return method != null ? new ParametersImported (par, types, varargs != 0, is_params) : new ParametersImported (par, types, is_params); }
public static ParametersCompiled CreateFullyResolved (IParameterData[] parameters, TypeSpec[] types) { return new ParametersCompiled (parameters, types); }
private string FormatFailedParameterMatchingMessage(Type beingCreated, IParameterData missingParameter, ICachedMethod constructor) { return(string.IsNullOrWhiteSpace(missingParameter.Name) ? $"Failed to find a matching parameter of type {missingParameter.Value.GetType().Name} named {missingParameter.Name} in constructor {FormatConstructor(constructor)} while creating {beingCreated.FullName}." : $"Failed to find a matching parameter of type {missingParameter.Value.GetType().Name} in constructor {FormatConstructor(constructor)} while creating {beingCreated.FullName}."); }
// // Imports SRE parameters // public static AParametersCollection Create (ParameterInfo [] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) return ParametersCompiled.EmptyReadOnlyParameters; Type [] types = new Type [pi.Length + varargs]; IParameterData [] par = new IParameterData [pi.Length + varargs]; bool is_params = false; PredefinedAttribute extension_attr = PredefinedAttributes.Get.Extension; PredefinedAttribute param_attr = PredefinedAttributes.Get.ParamArray; for (int i = 0; i < pi.Length; i++) { types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType); ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; Expression default_value = null; if (types [i].IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // types [i] = TypeManager.GetElementType (types [i]); } else if (i == 0 && extension_attr.IsDefined && method != null && method.IsStatic && (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute && method.IsDefined (extension_attr.Type, false)) { mod = Parameter.Modifier.This; } else { if (i >= pi.Length - 2 && types[i].IsArray) { if (p.IsDefined (param_attr.Type, false)) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.DefaultValue; if (value == Missing.Value) { default_value = EmptyExpression.Null; } else if (value == null) { default_value = new NullLiteral (Location.Null); } else { default_value = Constant.CreateConstant (value.GetType (), value, Location.Null); } } } par [i] = new ParameterData (p.Name, mod, default_value); } if (varargs != 0) { par [par.Length - 1] = new ArglistParameter (Location.Null); types [types.Length - 1] = InternalType.Arglist; } return method != null ? new ParametersImported (par, types, varargs != 0, is_params) : new ParametersImported (par, types); }
public override bool Define () { if (IsGeneric) { foreach (TypeParameter type_param in TypeParameters) { if (!type_param.Resolve (this)) return false; } foreach (TypeParameter type_param in TypeParameters) { if (!type_param.DefineType (this)) return false; } } member_cache = new MemberCache (TypeManager.multicast_delegate_type, this); // FIXME: POSSIBLY make this static, as it is always constant // Type [] const_arg_types = new Type [2]; const_arg_types [0] = TypeManager.object_type; const_arg_types [1] = TypeManager.intptr_type; const MethodAttributes ctor_mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public; ConstructorBuilder = TypeBuilder.DefineConstructor (ctor_mattr, CallingConventions.Standard, const_arg_types); ConstructorBuilder.DefineParameter (1, ParameterAttributes.None, "object"); ConstructorBuilder.DefineParameter (2, ParameterAttributes.None, "method"); // // HACK because System.Reflection.Emit is lame // IParameterData [] fixed_pars = new IParameterData [] { new ParameterData ("object", Parameter.Modifier.NONE), new ParameterData ("method", Parameter.Modifier.NONE) }; AParametersCollection const_parameters = new ParametersImported ( fixed_pars, new Type[] { TypeManager.object_type, TypeManager.intptr_type }); TypeManager.RegisterMethod (ConstructorBuilder, const_parameters); member_cache.AddMember (ConstructorBuilder, this); ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.Runtime); // // Here the various methods like Invoke, BeginInvoke etc are defined // // First, call the `out of band' special method for // defining recursively any types we need: if (!Parameters.Resolve (this)) return false; // // Invoke method // // Check accessibility foreach (Type partype in Parameters.Types){ if (!IsAccessibleAs (partype)) { Report.SymbolRelatedToPreviousError (partype); Report.Error (59, Location, "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'", TypeManager.CSharpName (partype), GetSignatureForError ()); return false; } } ReturnType = ReturnType.ResolveAsTypeTerminal (this, false); if (ReturnType == null) return false; ret_type = ReturnType.Type; if (!IsAccessibleAs (ret_type)) { Report.SymbolRelatedToPreviousError (ret_type); Report.Error (58, Location, "Inconsistent accessibility: return type `" + TypeManager.CSharpName (ret_type) + "' is less " + "accessible than delegate `" + GetSignatureForError () + "'"); return false; } CheckProtectedModifier (); if (RootContext.StdLib && TypeManager.IsSpecialType (ret_type)) { Method.Error1599 (Location, ret_type, Report); return false; } TypeManager.CheckTypeVariance (ret_type, Variance.Covariant, this); // // We don't have to check any others because they are all // guaranteed to be accessible - they are standard types. // CallingConventions cc = Parameters.CallingConvention; InvokeBuilder = TypeBuilder.DefineMethod ("Invoke", mattr, cc, ret_type, Parameters.GetEmitTypes ()); InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime); TypeManager.RegisterMethod (InvokeBuilder, Parameters); member_cache.AddMember (InvokeBuilder, this); // // Don't emit async method for compiler generated delegates (e.g. dynamic site containers) // if (TypeManager.iasyncresult_type != null && TypeManager.asynccallback_type != null && !IsCompilerGenerated) { DefineAsyncMethods (cc); } return true; }
public ParametersImported (IParameterData [] param, Type[] types) { this.parameters = param; this.types = types; }
// // Imports System.Reflection parameters // AParametersCollection CreateParameters (TypeSpec parent, ParameterInfo[] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) return ParametersCompiled.EmptyReadOnlyParameters; TypeSpec[] types = new TypeSpec[pi.Length + varargs]; IParameterData[] par = new IParameterData[pi.Length + varargs]; bool is_params = false; for (int i = 0; i < pi.Length; i++) { ParameterInfo p = pi[i]; Parameter.Modifier mod = 0; Expression default_value = null; if (p.ParameterType.IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // var el = p.ParameterType.GetElementType (); types[i] = ImportType (el, p, 0); // TODO: 1 to be csc compatible } else if (i == 0 && method.IsStatic && parent.IsStatic && parent.MemberDefinition.DeclaringAssembly.HasExtensionMethod && HasExtensionAttribute (CustomAttributeData.GetCustomAttributes (method)) != null) { mod = Parameter.Modifier.This; types[i] = ImportType (p.ParameterType); } else { types[i] = ImportType (p.ParameterType, p, 0); if (i >= pi.Length - 2 && types[i] is ArrayContainer) { if (HasAttribute (CustomAttributeData.GetCustomAttributes (p), typeof (ParamArrayAttribute))) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.RawDefaultValue; var ptype = types[i]; if (((p.Attributes & ParameterAttributes.HasDefault) != 0 && ptype.Kind != MemberKind.TypeParameter)) { // // Use value type as int constant can be used for object parameter type // var dtype = value == null ? ptype : ImportType (value.GetType ()); default_value = Constant.CreateConstant (null, dtype, value, Location.Null); } else if (value == Missing.Value) { default_value = EmptyExpression.MissingValue; } else { if (ptype == TypeManager.decimal_type) default_value = ReadDecimalConstant (CustomAttributeData.GetCustomAttributes (p)); if (default_value == null) default_value = new DefaultValueExpression (new TypeExpression (ptype, Location.Null), Location.Null); } } } par[i] = new ParameterData (p.Name, mod, default_value); } if (varargs != 0) { par[par.Length - 1] = new ArglistParameter (Location.Null); types[types.Length - 1] = InternalType.Arglist; } return method != null ? new ParametersImported (par, types, varargs != 0, is_params) : new ParametersImported (par, types, is_params); }
public void Insert(int index, IParameterData item) { throw new System.NotImplementedException(); }
public ParametersCollection (IParameterData [] param, Type[] types) { this.parameters = param; this.types = types; }
public bool Contains(IParameterData item) { return(_innerCollection.Contains(item)); }
// // Imports SRE parameters // public static AParametersCollection Create (ParameterInfo [] pi, MethodBase method) { if (pi.Length == 0) { if (method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0) return new ParametersCollection (new IParameterData [0], Type.EmptyTypes, method, false); return Parameters.EmptyReadOnlyParameters; } Type [] types = new Type [pi.Length]; IParameterData [] par = new IParameterData [pi.Length]; bool is_params = false; for (int i = 0; i < types.Length; i++) { types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType); ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; if (types [i].IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // types [i] = TypeManager.GetElementType (types [i]); } else if (i == 0 && TypeManager.extension_attribute_type != null && method != null && method.IsStatic && (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute && method.IsDefined (TypeManager.extension_attribute_type, false)) { mod = Parameter.Modifier.This; } else if (i >= pi.Length - 2 && types [i].IsArray) { if (p.IsDefined (TypeManager.param_array_type, false)) { mod = Parameter.Modifier.PARAMS; is_params = true; } } par [i] = new ParameterData (p.Name, mod); } return method != null ? new ParametersCollection (par, types, method, is_params) : new ParametersCollection (par, types); }
public IWarningInfo CheckParameterData(IFunctionData function, int index, ISequenceFlowContainer[] arr, bool overwriteType) { IParameterData parameterData = function.Parameters[index]; IArgument parameterType = function.ParameterType[index]; switch (parameterData.ParameterType) { //还没输入参数值 //todo这里好像不对? case ParameterType.NotAvailable: if (function.Type != FunctionType.InstancePropertySetter && function.Type != FunctionType.StaticPropertySetter) { return(new WarningInfo() { WarnCode = WarnCode.ParameterDataNotAvailable, Infomation = $"Parameter \"{parameterType.Name}\" not available" }); } return(null); break; //输入参数值 //检查参数类型是不是值类型 case ParameterType.Value: //不判断VariableType.Undefined //如果为类类型,则报错 if (parameterType.VariableType == VariableType.Class || parameterType.VariableType == VariableType.Struct) { return(new WarningInfo() { WarnCode = WarnCode.TypeInvalid, Infomation = $"Parameter \"{parameterType.Name}\" data type invalid: parameter type is of class, but input is value" }); } else if (parameterType.VariableType == VariableType.Enumeration) { //获取assembly信息里的enumeration字典 //字典键:namespace.class //字典值:string array含有枚举项 IComInterfaceDescription description = _comInterfaceManager.GetComInterfaceByName(parameterType.Type.AssemblyName); if (description == null) { return(new WarningInfo() { WarnCode = WarnCode.ParameterTypeAssemblyInvalid, Infomation = $"Could not find assembly {parameterType.Type.AssemblyName} for parameterType {parameterType.Name}" }); } IDictionary <string, string[]> eCollection = description.Enumerations; string[] e = null; if (!eCollection.TryGetValue($"{parameterType.Type.Namespace}.{parameterType.Type.Name}", out e)) { return(new WarningInfo() { WarnCode = WarnCode.EnumClassFault, Infomation = $"Could not find enumeration class {parameterType.Type.Namespace}.{parameterType.Type.Name}" }); } if (!e.Contains(parameterData.Value)) { return(new WarningInfo() { WarnCode = WarnCode.EnumDNE, Infomation = $"Could not find enumeration {parameterData.Value} in class {parameterType.Type.Namespace}.{parameterType.Type.Name}" }); } } else //parameterType.VariableType == VariableType.Value { //判断值类型是符合的值类型吗 if (!ValueConvertor.CheckValue(parameterType.Type.Name, parameterData.Value)) { return(new WarningInfo() { WarnCode = WarnCode.TypeInvalid, Infomation = $"Parameter \"{parameterType.Name}\" data type invalid: failed to parse input into parameter type" }); } } return(null); break; case ParameterType.Variable: return(FindVariablesCheckPropertyType(arr, parameterData.Value, parameterType.Type, overwriteType)); break; case ParameterType.Expression: return(null); break; default: throw new ArgumentOutOfRangeException("Invalid parameter value type."); break; } }
protected override bool DoDefineMembers() { if (IsGeneric) { foreach (TypeParameter type_param in TypeParameters) { if (!type_param.Resolve(this)) { return(false); } } foreach (TypeParameter type_param in TypeParameters) { if (!type_param.DefineType(this)) { return(false); } } } member_cache = new MemberCache(TypeManager.multicast_delegate_type, this); // FIXME: POSSIBLY make this static, as it is always constant // Type [] const_arg_types = new Type [2]; const_arg_types [0] = TypeManager.object_type; const_arg_types [1] = TypeManager.intptr_type; const MethodAttributes ctor_mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public; ConstructorBuilder = TypeBuilder.DefineConstructor(ctor_mattr, CallingConventions.Standard, const_arg_types); ConstructorBuilder.DefineParameter(1, ParameterAttributes.None, "object"); ConstructorBuilder.DefineParameter(2, ParameterAttributes.None, "method"); // // HACK because System.Reflection.Emit is lame // IParameterData [] fixed_pars = new IParameterData [] { new ParameterData("object", Parameter.Modifier.NONE), new ParameterData("method", Parameter.Modifier.NONE) }; AParametersCollection const_parameters = new ParametersImported( fixed_pars, new Type[] { TypeManager.object_type, TypeManager.intptr_type }); TypeManager.RegisterMethod(ConstructorBuilder, const_parameters); member_cache.AddMember(ConstructorBuilder, this); ConstructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); // // Here the various methods like Invoke, BeginInvoke etc are defined // // First, call the `out of band' special method for // defining recursively any types we need: if (!Parameters.Resolve(this)) { return(false); } // // Invoke method // // Check accessibility foreach (Type partype in Parameters.Types) { if (!IsAccessibleAs(partype)) { Report.SymbolRelatedToPreviousError(partype); Report.Error(59, Location, "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'", TypeManager.CSharpName(partype), GetSignatureForError()); return(false); } } ReturnType = ReturnType.ResolveAsTypeTerminal(this, false); if (ReturnType == null) { return(false); } ret_type = ReturnType.Type; if (!IsAccessibleAs(ret_type)) { Report.SymbolRelatedToPreviousError(ret_type); Report.Error(58, Location, "Inconsistent accessibility: return type `" + TypeManager.CSharpName(ret_type) + "' is less " + "accessible than delegate `" + GetSignatureForError() + "'"); return(false); } CheckProtectedModifier(); if (RootContext.StdLib && TypeManager.IsSpecialType(ret_type)) { Method.Error1599(Location, ret_type, Report); return(false); } TypeManager.CheckTypeVariance(ret_type, Variance.Covariant, this); // // We don't have to check any others because they are all // guaranteed to be accessible - they are standard types. // CallingConventions cc = Parameters.CallingConvention; InvokeBuilder = TypeBuilder.DefineMethod("Invoke", mattr, cc, ret_type, Parameters.GetEmitTypes()); InvokeBuilder.SetImplementationFlags(MethodImplAttributes.Runtime); TypeManager.RegisterMethod(InvokeBuilder, Parameters); member_cache.AddMember(InvokeBuilder, this); // // Don't emit async method for compiler generated delegates (e.g. dynamic site containers) // if (TypeManager.iasyncresult_type != null && TypeManager.asynccallback_type != null && !IsCompilerGenerated) { DefineAsyncMethods(cc); } return(true); }
// // Imports SRE parameters // public static AParametersCollection Create(ParameterInfo [] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) { return(ParametersCompiled.EmptyReadOnlyParameters); } Type [] types = new Type [pi.Length + varargs]; IParameterData [] par = new IParameterData [pi.Length + varargs]; bool is_params = false; PredefinedAttribute extension_attr = PredefinedAttributes.Get.Extension; PredefinedAttribute param_attr = PredefinedAttributes.Get.ParamArray; for (int i = 0; i < pi.Length; i++) { types [i] = TypeManager.TypeToCoreType(pi [i].ParameterType); ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; Expression default_value = null; if (types [i].IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) { mod = Parameter.Modifier.OUT; } else { mod = Parameter.Modifier.REF; } // // Strip reference wrapping // types [i] = TypeManager.GetElementType(types [i]); } else if (i == 0 && extension_attr.IsDefined && method != null && method.IsStatic && (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute && method.IsDefined(extension_attr.Type, false)) { mod = Parameter.Modifier.This; } else { if (i >= pi.Length - 2 && types[i].IsArray) { if (p.IsDefined(param_attr.Type, false)) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.DefaultValue; if (value == Missing.Value) { default_value = EmptyExpression.Null; } else if (value == null) { default_value = new NullLiteral(Location.Null); } else { default_value = Constant.CreateConstant(value.GetType(), value, Location.Null); } } } par [i] = new ParameterData(p.Name, mod, default_value); } if (varargs != 0) { par [par.Length - 1] = new ArglistParameter(Location.Null); types [types.Length - 1] = InternalType.Arglist; } return(method != null ? new ParametersImported(par, types, varargs != 0, is_params) : new ParametersImported(par, types)); }
// // Imports System.Reflection parameters // public static AParametersCollection Create (TypeSpec parent, ParameterInfo [] pi, MethodBase method) { int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) return ParametersCompiled.EmptyReadOnlyParameters; TypeSpec [] types = new TypeSpec [pi.Length + varargs]; IParameterData [] par = new IParameterData [pi.Length + varargs]; bool is_params = false; for (int i = 0; i < pi.Length; i++) { ParameterInfo p = pi [i]; Parameter.Modifier mod = 0; Expression default_value = null; if (p.ParameterType.IsByRef) { if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) mod = Parameter.Modifier.OUT; else mod = Parameter.Modifier.REF; // // Strip reference wrapping // types [i] = Import.ImportType (p.ParameterType.GetElementType ()); } else if (i == 0 && method.IsStatic && parent.IsStatic && // TODO: parent.Assembly.IsExtension && HasExtensionAttribute (method)) { mod = Parameter.Modifier.This; types[i] = Import.ImportType (p.ParameterType); } else { types[i] = Import.ImportType (p.ParameterType); if (i >= pi.Length - 2 && types[i] is ArrayContainer) { var cattrs = CustomAttributeData.GetCustomAttributes (p); if (cattrs != null && cattrs.Any (l => l.Constructor.DeclaringType == typeof (ParamArrayAttribute))) { mod = Parameter.Modifier.PARAMS; is_params = true; } } if (!is_params && p.IsOptional) { object value = p.DefaultValue; if (value == Missing.Value) { default_value = EmptyExpression.Null; } else if (value == null) { default_value = new NullLiteral (Location.Null); } else { default_value = Constant.CreateConstant (null, Import.ImportType (value.GetType ()), value, Location.Null); } } } par [i] = new ParameterData (p.Name, mod, default_value); } if (varargs != 0) { par [par.Length - 1] = new ArglistParameter (Location.Null); types [types.Length - 1] = InternalType.Arglist; } return method != null ? new ParametersImported (par, types, varargs != 0, is_params) : new ParametersImported (par, types, is_params); }
// // Imports SRE parameters // public static ParametersCollection Create(ParameterInfo[] pi, MethodBase method) { const TypeAttributes staticClassAttribute = TypeAttributes.Abstract | TypeAttributes.Sealed; int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0; if (pi.Length == 0 && varargs == 0) { return(ParametersCompiled.EmptyReadOnlyParameters); } var types = new Type[pi.Length + varargs]; var par = new IParameterData[pi.Length + varargs]; var isParams = false; var extensionAttribute = TypeManager.PredefinedAttributes.Extension; var paramAttributre = TypeManager.PredefinedAttributes.ParamArray; for (int i = 0; i < pi.Length; i++) { types[i] = pi[i].ParameterType; ParameterInfo p = pi[i]; Parameter.Modifier mod = 0; Expression defaultValue = null; if (types[i].IsByRef) { //if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out) // mod = Parameter.Modifier.OUT; //else // mod = Parameter.Modifier.REF; // // Strip reference wrapping // types[i] = types[i].GetElementType(); } else if (i == 0 && method != null && method.IsStatic && (method.DeclaringType.Attributes & staticClassAttribute) == staticClassAttribute && method.IsDefined(extensionAttribute, false)) { mod = Parameter.Modifier.This; } else { if (i >= pi.Length - 2 && types[i].IsArray) { if (p.IsDefined(paramAttributre, false)) { mod = Parameter.Modifier.Params; isParams = true; } } if (!isParams && p.IsOptional) { var value = p.DefaultValue; if (value == Missing.Value) { defaultValue = EmptyExpression.Null; } else if (value == null) { defaultValue = new LiteralExpression { Kind = LiteralKind.Null, Span = SourceSpan.None }; } else { Activator.CreateInstance( typeof(ConstantExpression <>).MakeGenericType(value.GetType()), value); } } } par[i] = new ParameterData(p.Name, mod, defaultValue) { ModifierFlags = mod }; } if (varargs != 0) { //par[par.Length - 1] = new ArglistParameter(Location.Null); //types[types.Length - 1] = InternalType.Arglist; throw new NotSupportedException("__arglist parameters are not supported."); } return(method != null ? new ParametersImported(par, types, varargs != 0, isParams) : new ParametersImported(par, types)); }
// // Returns null when the property is not valid C# property // public PropertySpec CreateProperty (PropertyInfo pi, TypeSpec declaringType, MethodSpec get, MethodSpec set) { Modifiers mod = 0; AParametersCollection param = null; TypeSpec type = null; if (get != null) { mod = get.Modifiers; param = get.Parameters; type = get.ReturnType; } bool is_valid_property = true; if (set != null) { if (set.ReturnType.Kind != MemberKind.Void) is_valid_property = false; var set_param_count = set.Parameters.Count - 1; if (set_param_count < 0) { set_param_count = 0; is_valid_property = false; } var set_type = set.Parameters.Types[set_param_count]; if (mod == 0) { AParametersCollection set_based_param; if (set_param_count == 0) { set_based_param = ParametersCompiled.EmptyReadOnlyParameters; } else { // // Create indexer parameters based on setter method parameters (the last parameter has to be removed) // var data = new IParameterData[set_param_count]; var types = new TypeSpec[set_param_count]; Array.Copy (set.Parameters.FixedParameters, data, set_param_count); Array.Copy (set.Parameters.Types, types, set_param_count); set_based_param = new ParametersImported (data, types, set.Parameters.HasParams); } mod = set.Modifiers; param = set_based_param; type = set_type; } else { if (set_param_count != get.Parameters.Count) is_valid_property = false; if (get.ReturnType != set_type) is_valid_property = false; // Possible custom accessor modifiers if ((mod & Modifiers.AccessibilityMask) != (set.Modifiers & Modifiers.AccessibilityMask)) { var get_acc = mod & Modifiers.AccessibilityMask; if (get_acc != Modifiers.PUBLIC) { var set_acc = set.Modifiers & Modifiers.AccessibilityMask; // If the accessor modifiers are not same, do extra restriction checks if (get_acc != set_acc) { var get_restr = ModifiersExtensions.IsRestrictedModifier (get_acc, set_acc); var set_restr = ModifiersExtensions.IsRestrictedModifier (set_acc, get_acc); if (get_restr && set_restr) { is_valid_property = false; // Neither is more restrictive } if (get_restr) { mod &= ~Modifiers.AccessibilityMask; mod |= set_acc; } } } } } } PropertySpec spec = null; if (!param.IsEmpty) { var index_name = declaringType.MemberDefinition.GetAttributeDefaultMember (); if (index_name == null) { is_valid_property = false; } else { if (get != null) { if (get.IsStatic) is_valid_property = false; if (get.Name.IndexOf (index_name, StringComparison.Ordinal) != 4) is_valid_property = false; } if (set != null) { if (set.IsStatic) is_valid_property = false; if (set.Name.IndexOf (index_name, StringComparison.Ordinal) != 4) is_valid_property = false; } } if (is_valid_property) spec = new IndexerSpec (declaringType, new ImportedParameterMemberDefinition (pi, type, param, this), type, param, pi, mod); } if (spec == null) spec = new PropertySpec (MemberKind.Property, declaringType, new ImportedMemberDefinition (pi, type, this), type, pi, mod); if (!is_valid_property) { spec.IsNotCSharpCompatible = true; return spec; } if (set != null) spec.Set = set; if (get != null) spec.Get = get; return spec; }
public void Add(IParameterData item) { ModuleUtils.AddAndRefreshIndex(this._innerCollection, item); }
public ParametersImported (IParameterData [] parameters, TypeSpec [] types, bool hasArglist, bool hasParams) { this.parameters = parameters; this.types = types; this.has_arglist = hasArglist; this.has_params = hasParams; }
private void VerifyVariableTypes(ISequenceStep sequenceStep, VariableTreeTable variableTree) { if (!string.IsNullOrWhiteSpace(sequenceStep.LoopCounter?.CounterVariable)) { string variableName = ModuleUtils.GetVarNameByParamValue(sequenceStep.LoopCounter.CounterVariable); IVariable variable = variableTree.GetVariable(variableName); Type varType = typeof(int); // Argument不能作为遍历变量 if (null == variable) { ThrowIfVariableNotFound(variableName, sequenceStep); } else if (!ModuleUtils.IsPropertyParam(sequenceStep.LoopCounter.CounterVariable) && (variable.Type == null || !variable.Type.Name.Equals(varType.Name))) { variable.Type = _comInterfaceManager.GetTypeByName(varType.Name, varType.Namespace); } } if (!string.IsNullOrWhiteSpace(sequenceStep.RetryCounter?.CounterVariable)) { string variableName = ModuleUtils.GetVarNameByParamValue(sequenceStep.RetryCounter.CounterVariable); IVariable variable = variableTree.GetVariable(variableName); // Argument不能作为遍历变量 if (null == variable) { ThrowIfVariableNotFound(variableName, sequenceStep); } else if (!ModuleUtils.IsPropertyParam(sequenceStep.RetryCounter.CounterVariable)) { Type varType = typeof(int); ITypeData typeData = _comInterfaceManager.GetTypeByName(varType.Name, varType.Namespace); variable.Type = typeData; } } if (null != sequenceStep.Function) { IFunctionData functionData = sequenceStep.Function; if (!string.IsNullOrWhiteSpace(functionData.Instance)) { SetVariableAndArgumentType(functionData.Instance, functionData.ClassType, variableTree, sequenceStep); } if (!string.IsNullOrWhiteSpace(functionData.Return)) { SetVariableAndArgumentType(functionData.Return, functionData.ReturnType.Type, variableTree, sequenceStep); } for (int i = 0; i < functionData.ParameterType.Count; i++) { IParameterData parameterValue = functionData.Parameters[i]; if (parameterValue.ParameterType == ParameterType.Variable && !string.IsNullOrWhiteSpace(parameterValue.Value)) { SetVariableAndArgumentType(parameterValue.Value, functionData.ParameterType[i].Type, variableTree, sequenceStep); } } } if (sequenceStep.HasSubSteps) { foreach (ISequenceStep subStep in sequenceStep.SubSteps) { VerifyVariableTypes(subStep, variableTree); } } }
private ParametersCompiled (IParameterData[] parameters, TypeSpec[] types) { this.parameters = parameters; this.types = types; }
public bool Remove(IParameterData item) { throw new System.NotImplementedException(); }