public ArgumentNotRecognizedException(
     TypeReference aspectType, 
     MethodReference aspectMethod, 
     ParameterReference param)
     : base(String.Format(Resources.ArgumentNotRecognizedMessageFormat, aspectType.Name, aspectMethod.Name, param.Name))
 {
 }
Ejemplo n.º 2
0
        public Parameter(ParameterReference parameterReference, ComponentCache componentCache) : base(parameterReference.ParameterType, componentCache)
        {
            Contract.Requires<ArgumentNullException>(parameterReference != null);

            parameter = parameterReference.Resolve();
            cache = componentCache;
        }
 public ArgumentTypeMismatchException(
     TypeReference aspectType,
     MethodReference aspectMethod,
     ParameterReference param,
     Type expectedType)
     : base(String.Format(Resources.ArgumentTypeMismatchMessageFormat, aspectType.Name, aspectMethod.Name, param.Name, expectedType.Name))
 {
 }
        internal static TypeReference ResolveParameterTypeIfNeeded(MethodReference method, ParameterReference parameter)
        {
            var genericInstanceMethod = method as GenericInstanceMethod;
            var declaringGenericInstanceType = method.DeclaringType as GenericInstanceType;

            if (genericInstanceMethod == null && declaringGenericInstanceType == null)
                return parameter.ParameterType;

            return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, parameter.ParameterType);
        }
        public LambdaParameterExpression(ParameterReference parameterRef, bool displayType, IEnumerable<Instruction> instructions)
            :base(instructions)
        {
            if (parameterRef == null)
            {
                throw new ArgumentNullException("parameterRef");
            }

            this.Parameter = parameterRef;
            this.DisplayType = displayType;
        }
Ejemplo n.º 6
0
        public ParameterContext(CilWorker worker, TypeReference interfaceType, MethodReference currentMethod, VariableDefinition currentArguments, VariableDefinition currentArgument, TypeReference targetDependency, MethodDefinition adapterConstructor, ParameterReference param)
        {
            CilWorker = worker;
            CurrentArguments = currentArguments;
            CurrentArgument = currentArgument;
            TargetDependency = targetDependency;

            Parameter = param;
            InterfaceType = interfaceType;
            AdapterConstructor = adapterConstructor;
            CurrentMethod = currentMethod;
        }
Ejemplo n.º 7
0
		static bool AreEquivalent (ParameterReference source, ParameterReference target)
		{
			if ((source == null) || (target == null))
				return false;

			int ss = source.GetSequence () - 1;
			int ts = target.GetSequence () - 1;
			if ((ss <= 0) || (ts <= 0))
				return false;

			IList<ParameterDefinition> cp = Current.Parameters;
			IList<ParameterDefinition> tp = Target.Parameters;
			return ((cp.Count > ss) && (tp.Count > ts)) ?
				cp [ss].ParameterType.Equals (tp [ts].ParameterType) : false;
		}
Ejemplo n.º 8
0
 public TypeReference ResolveParameterType(MethodReference method, ParameterReference parameter)
 {
     return this.Resolve(Unity.IL2CPP.GenericParameterResolver.ResolveParameterTypeIfNeeded(method, parameter));
 }
        internal static TypeReference ResolveParameterTypeIfNeeded(MethodReference method, ParameterReference parameter)
        {
            var genericInstanceMethod        = method as GenericInstanceMethod;
            var declaringGenericInstanceType = method.DeclaringType as GenericInstanceType;

            if (genericInstanceMethod == null && declaringGenericInstanceType == null)
            {
                return(parameter.ParameterType);
            }

            return(ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, parameter.ParameterType));
        }
Ejemplo n.º 10
0
 public SsaVariable GetOriginalVariable(ParameterReference parameter)
 {
     if (methodHasThis)
         return parameters[parameter.Index + 1];
     else
         return parameters[parameter.Index];
 }
		private void UpdateParameterLeastType (ParameterReference parameter, IEnumerable<StackEntryUsageResult> usageResults)
		{
			int pIndex = parameter.GetSequence () - 1;
			int parameterDepth = GetActualTypeDepth (parameter.ParameterType);

			int currentLeastDepth = 0;
			TypeReference currentLeastType = null;
			List<MethodSignature> signatures = null;

			//update the result array as in if (needUpdate) block below
			foreach (var usage in usageResults) {
				bool needUpdate = false;

				switch (usage.Instruction.OpCode.Code) {
				case Code.Newobj :
				case Code.Call :
				case Code.Callvirt :
					MethodReference method = (MethodReference) usage.Instruction.Operand;

					//potential generalization to object does not really make sense
					//from a readability/maintainability point of view
					if (IsSystemObjectMethod (method))
						continue;
					//we cannot really know if suggestion would work since the collection
					//is non-generic thus we ignore it
					TypeReference type = method.DeclaringType;
					if (IsFromNonGenericCollectionNamespace (type.Namespace))
						continue;

					int pcount = method.HasParameters ? method.Parameters.Count : 0;
					if (usage.StackOffset == pcount) {
						//argument is used as `this` in the call
						if (signatures == null)
							signatures = GetSignatures (usageResults);
						currentLeastType = GetBaseImplementor (GetActualType (type), signatures);
					} else {
						//argument is also used as an argument in the call
						currentLeastType = method.Parameters [pcount - usage.StackOffset - 1].ParameterType;

						//if parameter type is a generic, find the 'real' constructed type
						GenericParameter gp = (currentLeastType as GenericParameter);
						if (gp != null)
							currentLeastType = GetConstructedGenericType (method, gp);
					}

					//if the best we could find is object or non-generic collection, ignore this round
					if (currentLeastType == null || IsIgnoredSuggestionType (currentLeastType))
						continue;

					needUpdate = true;
					break;

				case Code.Stfld :
				case Code.Stsfld :
					FieldReference field = (FieldReference) usage.Instruction.Operand;
					currentLeastType = field.FieldType;

					needUpdate = true;
					break;
				}

				if (needUpdate) {
					currentLeastDepth = GetActualTypeDepth (currentLeastType);
					if (null == types_least [pIndex] || currentLeastDepth > depths_least [pIndex]) {
						types_least [pIndex] = currentLeastType;
						depths_least [pIndex] = currentLeastDepth;
					}
					if (currentLeastDepth == parameterDepth) //no need to check further
						return;
				}
			}
		}
		private static bool IsBooMacroParameter (ParameterReference p)
		{
			return p.Name == "macro" && p.ParameterType.FullName == BooMacroStatement;
		}
Ejemplo n.º 13
0
        public static void EnsureWellName(ParameterReference r)
        {
            if (r.mWellName != null) return;
            if (IGNORE_WELLNAMING)
            {
                r.mWellName = r.Name;
                return;
            }

            var name = r.Name;
            if (name == "")
            {
                name = r.Index == 0 ? "e" : "e" + r.Index.ToString();
            }
            else
            {
                var start = name.IndexOf(NONWELLFLAG);
                if (start >= 0)
                {
                    name = Replace(name, start, 1, "e");
                }
                else if (char.IsUpper(name, 0))
                {
                    name = name.Substring(0, 1).ToLower() + name.Substring(1);
                }

                name = Regex.Replace(name, @"\W", "_");
            }
            r.mWellName = name;
        }
Ejemplo n.º 14
0
 public static bool ParameterReferenceEquals(ParameterReference a, ParameterReference b)
 {
     // TODO: Should we check names?  Generic methods make up parameter names
     // TODO: Sequence? They seem to be off by one sometimes..
     return TypeReferenceEquals(a.ParameterType, b.ParameterType);
 }
		protected override string GetArgumentName(ParameterReference parameter)
		{
			return parameter.Name;
		}
		private bool CheckParameterName (IMetadataTokenProvider eventType, ParameterReference invokeParameter, string expectedName)
		{
			if (invokeParameter.Name == expectedName)
				return true;

			string msg = String.Format (CultureInfo.InvariantCulture, "The expected name is {0}, not {1}", 
				expectedName, invokeParameter.Name);
			Runner.Report (eventType, Severity.Low, Confidence.High, msg);
			return false;
		}
Ejemplo n.º 17
0
 public TypeReference ResolveParameterType(MethodReference method, ParameterReference parameter)
 {
     return(Resolve(GenericParameterResolver.ResolveParameterTypeIfNeeded(method, parameter)));
 }
Ejemplo n.º 18
0
 public ArgumentReferenceExpression(ParameterReference parameter)
 {
     _parameter = parameter;
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Fixes a parameter reference 
        /// </summary>
        /// <param name="targetMethod"></param>
        /// <param name="yourParamRef"></param>
        /// <returns></returns>
        /// 
        private ParameterDefinition FixParamReference(MethodDefinition targetMethod,
			ParameterReference yourParamRef)
        {
            var targetParam = targetMethod.Parameters[yourParamRef.Index];
            return targetParam;
        }
		public ArgumentReferenceExpression(ParameterReference parameter, IEnumerable<Instruction> instructions)
            :base(instructions)
		{
			this.Parameter = parameter;
		}
Ejemplo n.º 21
0
        public Unit VisitInlineArg(Instruction instruction, ParameterReference operand)
        {
            MarkLabel(instruction);
            var opCode = _opCodeMapper.Map(instruction.OpCode);

            if (instruction.OpCode.OperandType == OperandType.InlineArg)
            {
                _generator.Emit(opCode, (ushort)operand.Index);
            }
            else
            {
                _generator.Emit(opCode, (byte)operand.Index);
            }

            return Unit.Value;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Mark all reachable items in argument as such.
        /// </summary>
        private static void Walk(ReachableContext context, ParameterReference param)
        {
            param.ParameterType.MarkReachable(context);

            var paramDef = param as ParameterDefinition;
            if (paramDef != null)
            {
                var method = paramDef.Method as MemberReference;
                if (method != null)
                {
                    method.MarkReachable(context);
                }
                Walk(context, (ICustomAttributeProvider)paramDef);
            }
        }
Ejemplo n.º 23
0
 public static JSVariable New(ParameterReference parameter, MethodReference function)
 {
     return new JSParameter(parameter.Name, parameter.ParameterType, function);
 }
 internal Type ResolveParameterType(ParameterReference parameterReference)
 {
     return ResolveType(parameterReference.ParameterType);
 }
		private string GetSuggestionMessage (ParameterReference parameter)
		{
			StringBuilder sb = new StringBuilder ();
			sb.Append ("Parameter '");
			sb.Append (parameter.Name);
			if (parameter.ParameterType is GenericParameter)
				sb.Append ("' could be constrained to type '");
			else
				sb.Append ("' could be of type '");

			TypeReference type = types_least [parameter.Index];
			AppendPrettyTypeName (sb, type);
			sb.Append ("'.");
			return sb.ToString ();
		}
Ejemplo n.º 26
0
 void addParameterReference(ParameterReference param)
 {
     if (param == null)
         return;
     pushMember(param.ParameterType);
 }
		private bool CheckParameterName (IMetadataTokenProvider eventType, ParameterReference invokeParameter, string expectedName)
		{
			if (String.Compare (invokeParameter.Name, expectedName) == 0)
				return true;

			Runner.Report (eventType, Severity.Low, Confidence.High, String.Format ("The expected name is {0}, not {1}", expectedName, invokeParameter.Name));
			return false;
		}
Ejemplo n.º 28
0
 /// <summary>
 /// Builds a name for a parameter type that can be used for comparing parameters.  See 
 /// <see cref="GetTypeName"/> for details.
 /// </summary>
 public static string GetParameterTypeName( ParameterReference param )
 {
     return TypeNameCache.GetTypeName( param.ParameterType );
 }
		protected virtual string GetArgumentName(ParameterReference parameter)
		{
			ParameterDefinition parameterDefinition = parameter.Resolve();

			MethodSpecificContext referingMethodContext = GetCurrentMethodContext();

			string result;
			if (!referingMethodContext.ParameterDefinitionToNameMap.TryGetValue(parameterDefinition, out result))
			{
				result = parameterDefinition.Name;
			}

			if (!Language.IsValidIdentifier(result))
			{
				result = Language.ReplaceInvalidCharactersInIdentifier(result);
			}

			if (Language.IsGlobalKeyword(result))
			{
				result = Utilities.EscapeName(result, this.Language);
			}

			return result;
		}
Ejemplo n.º 30
0
 /// <summary>
 /// A cecil parameter reference will be directed to this method.
 /// </summary>
 /// <param name="item">Cecil reference.</param>
 /// <param name="resolvedItem">Output parameter that will be populated with the resolved cecil definition.</param>
 /// <returns><c>true</c></returns>
 private static bool TryResolve(ParameterReference item, out object resolvedItem)
 {
     resolvedItem = item.Resolve();
     return true;
 }
 private static bool IsBooMacroParameter(ParameterReference p)
 {
     return p.Name == "macro" && p.ParameterType.IsNamed ("Boo.Lang.Compiler.Ast", "MacroStatement");
 }
 internal static TypeReference ResolveParameterTypeIfNeeded(MethodReference method, ParameterReference parameter)
 {
     GenericInstanceMethod genericInstanceMethod = method as GenericInstanceMethod;
     GenericInstanceType declaringType = method.DeclaringType as GenericInstanceType;
     if ((genericInstanceMethod == null) && (declaringType == null))
     {
         return parameter.ParameterType;
     }
     return ResolveIfNeeded(genericInstanceMethod, declaringType, parameter.ParameterType);
 }