public ArgumentNotRecognizedException(
     TypeReference aspectType, 
     MethodReference aspectMethod, 
     ParameterReference param)
     : base(String.Format(Resources.ArgumentNotRecognizedMessageFormat, aspectType.Name, aspectMethod.Name, param.Name))
 {
 }
예제 #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;
        }
예제 #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;
        }
예제 #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;
		}
예제 #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));
        }
예제 #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;
		}
예제 #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;
        }
예제 #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;
		}
예제 #17
0
 public TypeReference ResolveParameterType(MethodReference method, ParameterReference parameter)
 {
     return(Resolve(GenericParameterResolver.ResolveParameterTypeIfNeeded(method, parameter)));
 }
예제 #18
0
 public ArgumentReferenceExpression(ParameterReference parameter)
 {
     _parameter = parameter;
 }
예제 #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;
		}
예제 #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;
        }
예제 #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);
            }
        }
예제 #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 ();
		}
예제 #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;
		}
예제 #28
0
파일: Helper.cs 프로젝트: chinshou/Obfuscar
 /// <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;
		}
예제 #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);
 }