public static int Sum(int a, double b, int c, float d, __arglist)
    {
        ArgIterator args = new ArgIterator(__arglist);
        int         S    = a + (int)b + c + (int)d;

        while (args.GetRemainingCount() > 0)
        {
            if (args.GetNextArgType().Equals(typeof(int).TypeHandle))
            {
                int N = __refvalue(args.GetNextArg(), int);
                Console.WriteLine("int value is " + N);
                S = S + N;
            }
            else if (args.GetNextArgType().Equals(typeof(string).TypeHandle))
            {
                string s = __refvalue(args.GetNextArg(), string);
                Console.WriteLine("string value is " + s);
            }
            else if (args.GetNextArgType().Equals(typeof(MyStruct).TypeHandle))
            {
                MyStruct st = __refvalue(args.GetNextArg(), MyStruct);
                Console.WriteLine("MyStruct value is " + st.x + " " + st.y);
                S = S + 2 * st.x + 3 * st.y;
            }
            else
            {
                return(-1);
            }
        }
        return(S);
    }
Exemple #2
0
        internal static void dummy(string servername, string eventname, __arglist)
        {
            ArgIterator lIterator = new ArgIterator(__arglist);

            object[] args = new object[lIterator.GetRemainingCount()];
            int      i    = 0;

            while (lIterator.GetRemainingCount() > 0)
            {
                TypedReference r = lIterator.GetNextArg();
                args[i++] = TypedReference.ToObject(r);
            }

            foreach (var e in eventinvlist)
            {
                string server_event = servername + "/" + eventname + "/";
                if (e.Contains(server_event))
                {
                    string server    = e.Split('/')[2];
                    var    baseproxy = new SimpleIPC.NamedObject.SIPCProxy(server);
                    if (baseproxy.IsServerAlive())
                    {
                        var proxy = new GenericProxy <IEventCaller>(baseproxy);
                        try
                        {
                            proxy.Proxy.calleventhandlers(eventname, e.Split('/')[3], args);
                        }
                        catch
                        {
                        }
                        proxy.Dispose();
                    }
                }
            }
        }
    public static long EnumTest(__arglist)
    {
        ArgIterator args = new ArgIterator(__arglist);
        long        S    = 0;

        while (args.GetRemainingCount() > 0)
        {
            if (args.GetNextArgType().Equals(typeof(Enum1).TypeHandle))
            {
                Enum1 e = __refvalue(args.GetNextArg(), Enum1);
                Console.WriteLine("Got Enum1, value = " + e + " = " + (long)e);
                S += (long)e;
            }
            if (args.GetNextArgType().Equals(typeof(Enum8).TypeHandle))
            {
                Enum8 e = __refvalue(args.GetNextArg(), Enum8);
                Console.WriteLine("Got Enum8, value = " + e + " = " + (long)e);
                S += (long)e;
            }
            if (args.GetNextArgType().Equals(typeof(Enum16).TypeHandle))
            {
                Enum16 e = __refvalue(args.GetNextArg(), Enum16);
                Console.WriteLine("Got Enum16, value = " + e + " = " + (long)e);
                S += (long)e;
            }
            if (args.GetNextArgType().Equals(typeof(Enuml).TypeHandle))
            {
                Enuml e = __refvalue(args.GetNextArg(), Enuml);
                Console.WriteLine("Got Enuml, value = " + e + " = " + (long)e);
                S += (long)e;
            }
        }
        return(S);
    }
 public static long EnumTest(__arglist)
 {
     ArgIterator args = new ArgIterator(__arglist);
     long S = 0;
     while (args.GetRemainingCount() > 0)
     {
         if (args.GetNextArgType().Equals(typeof(Enum1).TypeHandle))
         {
             Enum1 e = __refvalue(args.GetNextArg(), Enum1);
             Console.WriteLine("Got Enum1, value = " + e + " = " + (long)e);
             S += (long)e;
         }
         if (args.GetNextArgType().Equals(typeof(Enum8).TypeHandle))
         {
             Enum8 e = __refvalue(args.GetNextArg(), Enum8);
             Console.WriteLine("Got Enum8, value = " + e + " = " + (long)e);
             S += (long)e;
         }
         if (args.GetNextArgType().Equals(typeof(Enum16).TypeHandle))
         {
             Enum16 e = __refvalue(args.GetNextArg(), Enum16);
             Console.WriteLine("Got Enum16, value = " + e + " = " + (long)e);
             S += (long)e;
         }
         if (args.GetNextArgType().Equals(typeof(Enuml).TypeHandle))
         {
             Enuml e = __refvalue(args.GetNextArg(), Enuml);
             Console.WriteLine("Got Enuml, value = " + e + " = " + (long)e);
             S += (long)e;
         }
     }
     return S;
 }
Exemple #5
0
    static void X(__arglist) // 仮引数のところに __arglist を書く
    {
        // 中身のとりだしには ArgIterator 構造体を使う
        ArgIterator argumentIterator = new ArgIterator(__arglist);

        while (argumentIterator.GetRemainingCount() > 0)
        {
            object value = null;

            var r = argumentIterator.GetNextArg(); // 可変個引数の1個1個は TypedReference になっている
            var t = __reftype(r);                  // TypedReference から、元の型を取得

            // 型で分岐して、__refvalue で値の取り出し
            if (t == typeof(int))
            {
                value = __refvalue(r, int);
            }
            else if (t == typeof(char))
            {
                value = __refvalue(r, char);
            }
            else if (t == typeof(double))
            {
                value = __refvalue(r, double);
            }
            else
            {
                value = __refvalue(r, string);
            }

            Console.WriteLine(t.Name + ": " + value);
        }
    }
 public static void argit1( __arglist )
   {
   ArgIterator args = new ArgIterator( __arglist );
   int iCount = args.GetRemainingCount();
   for ( int i = 0; i < iCount + 15; i++ ){
   try	{
   try {
   TypedReference trTypRef =  args.GetNextArg();
   }
   catch (InvalidOperationException){}
   if (args.GetRemainingCount()!=0)
     if ( args.GetRemainingCount() != (iCount - i - 1) ){
     throw new Exception( "ExcErr5  ,Should have had remaining count " + (iCount - i - 1) + " but had remaining count " + args.GetRemainingCount() );
     }
   }
   catch(Exception ex){			
   if ( i < iCount )
     Console.WriteLine( "Err_argit4_00: Loop has not gone through only " + i + " arguments" );
   int iRemCount = args.GetRemainingCount();
   if ( iRemCount != 0 ){
   Console.WriteLine( "Err_argit4_01: Should have had remaining count 0 but had remaining count " + iRemCount );
   }
   throw ex;
   }
   }
   if ( args.GetRemainingCount() != 0 ){
   throw new Exception( "ExcErr4  ,Should have had remaining count 0");
   }
   }
Exemple #7
0
        public dynamic TimeThis <T, BigInteger>(String strFuncName, Func <T, BigInteger> work)
        {
            if (work == null)
            {
                throw new ArgumentNullException(nameof(work));
            }

            var                  sw       = Stopwatch.StartNew();
            ArgIterator          b        = new ArgIterator();          // what is this line for?
            Func <T, BigInteger> selector = arg => work(arg);
            var                  result   = selector;

            sw.Stop();
            Write("--- {0} ---\t", strFuncName);
            string strElapsed;

            if (sw.ElapsedMilliseconds <= 1000)
            {
                strElapsed = String.Format("{0} ms", sw.ElapsedMilliseconds);
            }
            else
            {
                strElapsed = String.Format("{0:F1} s", (float)sw.Elapsed.TotalSeconds);
            }
            WriteLine(strElapsed);
            return(result);
        }
Exemple #8
0
            public override object Invoke(__arglist)
            {
                ArgIterator ai = new ArgIterator(__arglist);

                ObjectTypeHandle[] args = new ObjectTypeHandle[ai.GetRemainingCount()];
                while (ai.GetRemainingCount() > 0)
                {
                    int    idx = args.Length - ai.GetRemainingCount();
                    object arg = TypedReference.ToObject(ai.GetNextArg());
                    args[idx] = AdapterTools.Marshal(arg);
                }
                var res = Delegate.InvokeMember("Invoke", ref args, new bool[args.Length]);

                ai = new ArgIterator(__arglist);
                while (ai.GetRemainingCount() > 0)
                {
                    int          idx = args.Length - ai.GetRemainingCount();
                    ObjectHandle arg = args[idx];
                    var          tr  = ai.GetNextArg();
                    if (__reftype(tr).IsByRef)
                    {
                        tr.SetValue(arg.Unwrap());
                    }
                }
                if (res != null)
                {
                    return(res.Unwrap());
                }
                else
                {
                    return(null);
                }
            }
Exemple #9
0
        private static void testArglist(__arglist)
        {
            const int    newint    = 10;
            const double newdouble = 0.1;
            ArgIterator  iter      = new ArgIterator(__arglist);
            int          length    = iter.GetRemainingCount();

            for (int i = 0; i < length; i++)
            {
                Type type = Type.GetTypeFromHandle(iter.GetNextArgType());
                if (type == typeof(int))
                {
                    int v = __refvalue(iter.GetNextArg(), int);
                    Debug.WriteLine("Found int with value:{0}", v);
                    v = newint;
                    continue;
                }
                if (type == typeof(double))
                {
                    double v = __refvalue(iter.GetNextArg(), double);
                    Debug.WriteLine("Found double with value:{0}", v);
                    v = newdouble;
                    continue;
                }
                Debug.WriteLine("Missing object:{0}", TypedReference.ToObject(iter.GetNextArg()));
            }
        }
Exemple #10
0
   public static void argit3( __arglist )
     {
     ArgIterator args = new ArgIterator( __arglist );
     try
       {
       int argCount = args.GetRemainingCount();
       for (int i = 0; i < argCount; i++) 
	 {
	 TypedReference trTypRef = args.GetNextArg();
	 }
       }
     catch(Exception ex)
       {
       throw new Exception( "ExcErr007  ," + ex.ToString() );
       }
     for ( int j = 0; j < 5; j++ )
       {
       try
	 {
	 RuntimeTypeHandle rthRunTypHan = args.GetNextArgType();
	 throw new Exception( "ExcErr006  , Last call should have thrown." );
	 }
       catch (InvalidOperationException)
	 {}
       }
     }
Exemple #11
0
 public static int Sum(int a, double b, int c, float d, __arglist)
 {
    ArgIterator args = new ArgIterator(__arglist);
    int S = a + (int)b + c + (int)d;
    while(args.GetRemainingCount() > 0)
      {
        if (args.GetNextArgType().Equals(typeof(int).TypeHandle))
        {
            int N = __refvalue(args.GetNextArg(), int);
            Console.WriteLine("int value is "+N);
            S = S + N;
        }
        else if (args.GetNextArgType().Equals(typeof(string).TypeHandle))
        {
            string s = __refvalue(args.GetNextArg(), string);
            Console.WriteLine("string value is "+s);
        }
        else if (args.GetNextArgType().Equals(typeof(MyStruct).TypeHandle))
        {
            MyStruct st = __refvalue(args.GetNextArg(), MyStruct);
            Console.WriteLine("MyStruct value is "+st.x+" "+st.y);
            S = S + 2*st.x + 3*st.y;
        }
        else
           return -1;
      }
    return S;
 }
        public static void Write(string format, object arg0, object arg1, object arg2, object arg3, __arglist)
        {
            ArgIterator iter     = new ArgIterator(__arglist);
            int         argCount = iter.GetRemainingCount();
#endif

            object[] args = new object[argCount + 4];
            args[0] = arg0;
            args[1] = arg1;
            args[2] = arg2;
            args[3] = arg3;
#if NETCF
            for (int i = 0; i < argCount; i++)
            {
                args[i + 4] = arglist[i];
#else
            for (int i = 0; i < argCount; i++)
            {
                TypedReference typedRef = iter.GetNextArg();
                args[i + 4] = TypedReference.ToObject(typedRef);
#endif
            }

            stdout.Write(String.Format(format, args));
        }
Exemple #13
0
    // Helper method for "TestArgIteratorGetType".
    private void TestTypes(String testNum, Type[] types, __arglist)
    {
        ArgIterator iter  = new ArgIterator(__arglist);
        int         count = iter.GetRemainingCount();

        AssertEquals("Length " + testNum, types.Length, count);
        while (count > 0)
        {
            Type type = Type.GetTypeFromHandle
                            (iter.GetNextArgType());
            AssertEquals("TypeCheck " + testNum,
                         types[types.Length - count], type);
            AssertEquals("Remaining " + testNum,
                         count, iter.GetRemainingCount());
            iter.GetNextArg();
            --count;
        }
        try
        {
            iter.GetNextArgType();
            Fail("EndCheck " + testNum);
        }
        catch (InvalidOperationException)
        {
            // We expect this exception at the end of the list.
        }
        AssertEquals("Remaining " + testNum, 0,
                     iter.GetRemainingCount());
    }
        public static void argit0(__arglist)
        {
            ArgIterator args   = new ArgIterator(__arglist);
            int         iCount = args.GetRemainingCount();

            for (int i = 0; i < iCount + 15; i++)
            {
                try
                {
                    TypedReference trTypRef = args.GetNextArg();
                    if (args.GetRemainingCount() != (iCount - i - 1))
                    {
                        throw new Exception("ExcErr5  ,Should have had remaining count " + (iCount - i - 1) + " but had remaining count " + args.GetRemainingCount());
                    }
                }
                catch (Exception ex)
                {
                    if (i < iCount)
                    {
                        Console.WriteLine(i);
                        throw ex;
                    }
                    int iRemCount = args.GetRemainingCount();
                    if (iRemCount != 0)
                    {
                        throw new Exception("ExcErr3  ,Should have had remaining count 0 but had remaining count " + iRemCount);
                    }
                }
            }
            if (args.GetRemainingCount() != 0)
            {
                throw new Exception("ExcErr4  ,Should have had remaining count 0");
            }
        }
	// Helper method for "TestArgIteratorGetType".
	private void TestTypes(String testNum, Type[] types, __arglist)
			{
				ArgIterator iter = new ArgIterator(__arglist);
				int count = iter.GetRemainingCount();
				AssertEquals("Length " + testNum, types.Length, count);
				while(count > 0)
				{
					Type type = Type.GetTypeFromHandle
						(iter.GetNextArgType());
					AssertEquals("TypeCheck " + testNum,
								 types[types.Length - count], type);
					AssertEquals("Remaining " + testNum,
								 count, iter.GetRemainingCount());
					iter.GetNextArg();
					--count;
				}
				try
				{
					iter.GetNextArgType();
					Fail("EndCheck " + testNum);
				}
				catch(InvalidOperationException)
				{
					// We expect this exception at the end of the list.
				}
				AssertEquals("Remaining " + testNum, 0,
							 iter.GetRemainingCount());
			}
        public static void argit3(__arglist)
        {
            ArgIterator args = new ArgIterator(__arglist);

            try
            {
                int argCount = args.GetRemainingCount();
                for (int i = 0; i < argCount; i++)
                {
                    TypedReference trTypRef = args.GetNextArg();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("ExcErr007  ," + ex.ToString());
            }
            for (int j = 0; j < 5; j++)
            {
                try
                {
                    RuntimeTypeHandle rthRunTypHan = args.GetNextArgType();
                    throw new Exception("ExcErr006  , Last call should have thrown.");
                }
                catch (InvalidOperationException)
                {}
            }
        }
Exemple #17
0
	static void TestRefValue (__arglist)
	{
		ArgIterator args = new ArgIterator (__arglist);

		var o = __refvalue ( args.GetNextArg (),int);
		for (int i = 0; i < args.GetRemainingCount (); i++) {
			Console.WriteLine (__refvalue (args.GetNextArg (), int));
		}
	}
Exemple #18
0
        private static void ArglistMethod(__arglist)
        {
            var iter = new ArgIterator(__arglist);

            for (int n = iter.GetRemainingCount(); n > 0; n--)
            {
                Console.WriteLine(TypedReference.ToObject(iter.GetNextArg()));
            }
        }
Exemple #19
0
        public void VariableArguments(__arglist)
        {
            ArgIterator argumentIterator = new ArgIterator(__arglist);

            for (int i = 0; i < argumentIterator.GetRemainingCount(); i++)
            {
                Console.WriteLine(
                    __refvalue(argumentIterator.GetNextArg(), string));
            }
        }
Exemple #20
0
        public static unsafe ValueType Box(ArgIterator arg)
        {
            ValueType empty = (ValueType)FormatterServices.GetUninitializedObject(typeof(ArgIterator));

            TypedReference innerRef;

            TypedReferenceTools.MakeTypedReference(&innerRef, empty);
            __refvalue(innerRef, ArgIterator) = arg;
            return(empty);
        }
Exemple #21
0
            public void Bar4(__arglist) // Compliant - private method
            {
                ArgIterator argumentIterator = new ArgIterator(__arglist);

                for (int i = 0; i < argumentIterator.GetRemainingCount(); i++)
                {
                    Console.WriteLine(
                        __refvalue(argumentIterator.GetNextArg(), string));
                }
            }
Exemple #22
0
        public static void DisplayNumbersOnConsole(__arglist)
        {
            ArgIterator ai = new ArgIterator(__arglist);

            while (ai.GetRemainingCount() > 0)
            {
                TypedReference tr = ai.GetNextArg();
                Console.WriteLine(TypedReference.ToObject(tr));
            }
        }
Exemple #23
0
        public void Bar3(int val, string name, __arglist) // Noncompliant
        {
            ArgIterator argumentIterator = new ArgIterator(__arglist);

            for (int i = 0; i < argumentIterator.GetRemainingCount(); i++)
            {
                Console.WriteLine(
                    __refvalue(argumentIterator.GetNextArg(), string));
            }
        }
Exemple #24
0
        /// <summary>
        /// Fill in the GC-relevant stack frame locations.
        /// </summary>
        private void FakeGcScanRoots(MethodDesc method, ArgIterator argit, CORCOMPILE_GCREFMAP_TOKENS[] frame)
        {
            // Encode generic instantiation arg
            if (argit.HasParamType)
            {
                if (method.RequiresInstMethodDescArg())
                {
                    frame[argit.GetParamTypeArgOffset()] = CORCOMPILE_GCREFMAP_TOKENS.GCREFMAP_METHOD_PARAM;
                }
                else if (method.RequiresInstMethodTableArg())
                {
                    frame[argit.GetParamTypeArgOffset()] = CORCOMPILE_GCREFMAP_TOKENS.GCREFMAP_TYPE_PARAM;
                }
            }

            // If the function has a this pointer, add it to the mask
            if (argit.HasThis)
            {
                bool isUnboxingStub = false; // TODO: is this correct?
                bool interior       = method.OwningType.IsValueType && !isUnboxingStub;

                frame[_transitionBlock.ThisOffset] = (interior ? CORCOMPILE_GCREFMAP_TOKENS.GCREFMAP_INTERIOR : CORCOMPILE_GCREFMAP_TOKENS.GCREFMAP_REF);
            }

            if (argit.IsVarArg)
            {
                frame[argit.GetVASigCookieOffset()] = CORCOMPILE_GCREFMAP_TOKENS.GCREFMAP_VASIG_COOKIE;

                // We are done for varargs - the remaining arguments are reported via vasig cookie
                return;
            }

            // Also if the method has a return buffer, then it is the first argument, and could be an interior ref,
            // so always promote it.
            if (argit.HasRetBuffArg())
            {
                frame[_transitionBlock.GetRetBuffArgOffset(argit.HasThis)] = CORCOMPILE_GCREFMAP_TOKENS.GCREFMAP_INTERIOR;
            }

            //
            // Now iterate the arguments
            //

            // Cycle through the arguments, and call GcScanRoots for each
            int argIndex = 0;
            int argOffset;

            while ((argOffset = argit.GetNextOffset()) != TransitionBlock.InvalidOffset)
            {
                ArgLocDesc?    argLocDescForStructInRegs = argit.GetArgLoc(argOffset);
                ArgDestination argDest = new ArgDestination(_transitionBlock, argOffset, argLocDescForStructInRegs);
                GcScanRoots(method.Signature[argIndex], in argDest, delta: 0, frame);
                argIndex++;
            }
        }
Exemple #25
0
        private static void Foo(__arglist)
        {
            var iterator = new ArgIterator(__arglist);

            while (iterator.GetRemainingCount() > 0)
            {
                var typedReference = iterator.GetNextArg();
                Console.WriteLine($"{TypedReference.ToObject(typedReference)} " +
                                  $"/ {TypedReference.GetTargetType(typedReference)}");
            }
        }
Exemple #26
0
 public static void argit2b (__arglist)
   {
   ArgIterator args = new ArgIterator( __arglist );
   int hashcode = args.GetHashCode();
   TypedReference trTypRef = args.GetNextArg();
   int hashcodecompare= args.GetHashCode();
   if (! hashcode.Equals(hashcodecompare))
     {
     throw new Exception( "argit2b - 1, hashcode changed" );
     }
   }
Exemple #27
0
    static void TestRefValue(__arglist)
    {
        ArgIterator args = new ArgIterator(__arglist);

        var o = __refvalue(args.GetNextArg(), int);

        for (int i = 0; i < args.GetRemainingCount(); i++)
        {
            Console.WriteLine(__refvalue(args.GetNextArg(), int));
        }
    }
Exemple #28
0
        public object[] ArgTest(__arglist)
        {
            var args   = new ArgIterator(__arglist);
            var result = new object[] { args.GetRemainingCount() };

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = TypedReference.ToObject(args.GetNextArg());
            }
            return(result);
        }
Exemple #29
0
        private static double getFloat(ArgIterator ai)
        {
            TypedReference tr = ai.GetNextArg();
            Type           t  = __reftype(tr);

            if (t == typeof(double))
            {
                return(__refvalue(tr, double));
            }
            throw new FormatException("expecting a double");
        }
Exemple #30
0
        private unsafe static string getString(ArgIterator ai)
        {
            TypedReference tr = ai.GetNextArg();
            Type           t  = __reftype(tr);

            if (t == typeof(sbyte *))
            {
                return(new String(__refvalue(tr, sbyte *)));
            }
            throw new FormatException("expecting a string");
        }
Exemple #31
0
        public void Bar(__arglist) // Noncompliant {{Use the 'params' keyword instead of '__arglist'.}}
//                  ^^^
        {
            ArgIterator argumentIterator = new ArgIterator(__arglist);

            for (int i = 0; i < argumentIterator.GetRemainingCount(); i++)
            {
                Console.WriteLine(
                    __refvalue(argumentIterator.GetNextArg(), string));
            }
        }
Exemple #32
0
        private static char getChar(ArgIterator ai)
        {
            TypedReference tr = ai.GetNextArg();
            Type           t  = __reftype(tr);

            if (t == typeof(sbyte))
            {
                return((char)(__refvalue(tr, sbyte)));
            }
            throw new FormatException("expecting a char");
        }
Exemple #33
0
	    public void Foo(__arglist)
	    {
		    var iterator = new ArgIterator(__arglist);
		    while (iterator.GetRemainingCount() > 0)
		    {
			    TypedReference typedReference = iterator.GetNextArg();
			    Console.WriteLine("{0} / {1}",
				    TypedReference.ToObject(typedReference),
				    TypedReference.GetTargetType(typedReference));
		    }
	    }
Exemple #34
0
        private static int getInt(ArgIterator ai)
        {
            TypedReference tr = ai.GetNextArg();
            Type           t  = __reftype(tr);

            if (t == typeof(int))
            {
                return((int)(__refvalue(tr, int)));
            }
            throw new FormatException("expecting an integer");
        }
Exemple #35
0
        /*
         * static public TType Cast<TType>(object Value)
         * {
         *      if (typeof(TType) == typeof(int)) return (TType)(dynamic)Convert.ToInt32(Value);
         *      if (typeof(TType) == typeof(uint)) return (TType)(dynamic)Convert.ToUInt32(Value);
         *
         *      if (Value.GetType() == typeof(int)) return (TType)(dynamic)(int)Value;
         *      if (Value.GetType() == typeof(uint)) return (TType)(dynamic)(uint)Value;
         *      return (TType)(dynamic)Value;
         * }
         */

        static public object[] GetObjectsFromArgsIterator(ArgIterator ArgIterator)
        {
            var Params = new object[ArgIterator.GetRemainingCount()];

            for (int n = 0; n < Params.Length; n++)
            {
                Params[n] = TypedReference.ToObject(ArgIterator.GetNextArg());
            }
            ArgIterator.End();
            return(Params);
        }
Exemple #36
0
        public static void VarargMethod(string headline, __arglist)
        {
            ArgIterator ai = new ArgIterator(__arglist);

            Console.Write(headline);
            while (ai.GetRemainingCount() > 0)
            {
                Console.Write(TypedReference.ToObject(ai.GetNextArg()));
            }
            Console.WriteLine();
        }
Exemple #37
0
        // special case, this return false for HasParameters
        private void ShowItems_NoParameter(__arglist)
        {
            ArgIterator args = new ArgIterator(__arglist);

            for (int i = 0; i < args.GetRemainingCount(); i++)
            {
// gmcs cannot compile __refvalue correctly - bnc 569539
#if !__MonoCS__
                Console.WriteLine(__refvalue(args.GetNextArg(), string));
#endif
            }
        }
Exemple #38
0
//Test 1
	// check whether GetHashCode returns the same value
	// check to see if we can use ArgIterators on any class
	// check ArgIterators on Arrays
	// test arg iterators with instance methods on normal classes
	public TestStruct argit1( Object[] objExpectedArr, __arglist )
	{
		ArgIterator args = new ArgIterator( __arglist );
		int hashcode = args.GetHashCode();
		
		int iCount = args.GetRemainingCount();
                Console.WriteLine( "Found  "+ iCount +" arguments. " );  
		Object[] objArr = new Object[iCount];

		for ( int i = 0; i < iCount; i++ ){
			objArr[i] = TypedReference.ToObject(args.GetNextArg());
                        Console.WriteLine( "Object  " + i + ": " + objArr[i] + " Expected: " + objExpectedArr[i] );  
			if ( objExpectedArr[i] == null ){
				if ( objArr[i] != null ){
					throw new Exception( "argit1 - 1, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
				}
			}
			
			else if ( ! objArr[i].Equals( objExpectedArr[i] ) ) {
				throw new Exception( "argit1 - 2, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
			}
		}		

		//repeating the code above __arglist should be valid in method scope
		ArgIterator args2 = new ArgIterator( __arglist );
		int iCount2 = args2.GetRemainingCount();
		Object[] objArr2 = new Object[iCount];

		for ( int i = 0; i < iCount2; i++ ){
			objArr2[i] = TypedReference.ToObject(args2.GetNextArg());
                        Console.WriteLine( "Object  " + i + ": " + objArr2[i] + " Expected: " + objExpectedArr[i] );
			if ( objExpectedArr[i] == null ){
				if ( objArr2[i] != null ){
					throw new Exception( "argit1 - 3, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
				}
			}
			
			else if ( ! objArr2[i].Equals( objExpectedArr[i] ) ) {
				throw new Exception( "argit1 - 4, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
			}
		}				
		int hashcodecompare= args.GetHashCode();
		if (! hashcode.Equals(hashcodecompare))
			{
				throw new Exception( "argit1 - 5, hashcode changed" );
			}
                TestStruct Bar = new TestStruct();
                Bar.foo1 = 1;
                Bar.foo2 = 2;
                return Bar;
	}
Exemple #39
0
 public static void argit2 (__arglist)
   {
   ArgIterator args = new ArgIterator( __arglist );	
   int hashcode = args.GetHashCode();
   try{
   NormClass.argit2b( __arglist(   ) );
   }
   catch (InvalidOperationException) {}
   int hashcodecompare= args.GetHashCode();
   if (! hashcode.Equals(hashcodecompare))
     {
     throw new Exception( "argit2 - 1, hashcode changed" );
     }
   }
Exemple #40
0
    static void X(__arglist) // 仮引数のところに __arglist を書く
    {
        // 中身のとりだしには ArgIterator 構造体を使う
        ArgIterator argumentIterator = new ArgIterator(__arglist);
        while (argumentIterator.GetRemainingCount() > 0)
        {
            object value = null;

            var r = argumentIterator.GetNextArg(); // 可変個引数の1個1個は TypedReference になっている
            var t = __reftype(r); // TypedReference から、元の型を取得

            // 型で分岐して、__refvalue で値の取り出し
            if (t == typeof(int)) value = __refvalue(r, int);
            else if (t == typeof(char)) value = __refvalue(r, char);
            else if (t == typeof(double)) value = __refvalue(r, double);
            else value = __refvalue(r, string);

            Console.WriteLine(t.Name + ": " + value);
        }
    }
Exemple #41
0
 public void argit1( Object[] objExpectedArr, __arglist )
   {
   ArgIterator args = new ArgIterator( __arglist );
   int hashcode = args.GetHashCode();
   int iCount = args.GetRemainingCount();
   Object[] objArr = new Object[iCount];
   for ( int i = 0; i < iCount; i++ ){
   objArr[i] = TypedReference.ToObject(args.GetNextArg());
   if ( objExpectedArr[i] == null ){
   if ( objArr[i] != null ){
   throw new Exception( "argit1 - 1, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
   }
   }
   else if ( ! objArr[i].Equals( objExpectedArr[i] ) ) {
   throw new Exception( "argit1 - 2, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
   }
   }		
   ArgIterator args2 = new ArgIterator( __arglist );
   int iCount2 = args2.GetRemainingCount();
   Object[] objArr2 = new Object[iCount];
   for ( int i = 0; i < iCount2; i++ ){
   objArr2[i] = TypedReference.ToObject(args2.GetNextArg());
   if ( objExpectedArr[i] == null ){
   if ( objArr2[i] != null ){
   throw new Exception( "argit1 - 3, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
   }
   }
   else if ( ! objArr2[i].Equals( objExpectedArr[i] ) ) {
   throw new Exception( "argit1 - 4, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
   }
   }				
   int hashcodecompare= args.GetHashCode();
   if (! hashcode.Equals(hashcodecompare))
     {
     throw new Exception( "argit1 - 5, hashcode changed" );
     }
   }
Exemple #42
0
 public static void argit1 (__arglist)
   {
   ArgIterator args = new ArgIterator( __arglist );
   Boolean b= args.Equals(new Object());
   }
	public static int GetArgCount(__arglist)
	{
		ArgIterator argIterator = new ArgIterator(__arglist);
		return argIterator.GetRemainingCount();
	}
	// Helper method for "TestArgIteratorGetValue".
	private void TestValues(String testNum, Object[] values, __arglist)
			{
				Object expected, actual;
				ArgIterator iter = new ArgIterator(__arglist);
				int count = iter.GetRemainingCount();
				AssertEquals("Length " + testNum, values.Length, count);
				while(count > 0)
				{
					expected = values[values.Length - count];
					actual = TypedReference.ToObject(iter.GetNextArg());
					if(expected == null)
					{
						AssertNull("ValueCheck " + testNum, actual);
					}
					else
					{
						Assert("ValueCheck " + testNum,
							   expected.Equals(actual));
					}
					--count;
					AssertEquals("Remaining " + testNum,
								 count, iter.GetRemainingCount());
				}
				try
				{
					iter.GetNextArg();
					Fail("EndCheck " + testNum);
				}
				catch(InvalidOperationException)
				{
					// We expect this exception at the end of the list.
				}
				AssertEquals("Remaining " + testNum, 0,
							 iter.GetRemainingCount());

				// Restart and run the test again to make sure that
				// the first iteration did not modify the vararg values.
				iter = new ArgIterator(__arglist);
				count = iter.GetRemainingCount();
				AssertEquals("Length " + testNum, values.Length, count);
				while(count > 0)
				{
					expected = values[values.Length - count];
					actual = TypedReference.ToObject(iter.GetNextArg());
					if(expected == null)
					{
						AssertNull("ValueCheck " + testNum, actual);
					}
					else
					{
						Assert("ValueCheck " + testNum,
							   expected.Equals(actual));
					}
					--count;
					AssertEquals("Remaining " + testNum,
								 count, iter.GetRemainingCount());
				}
				try
				{
					iter.GetNextArg();
					Fail("EndCheck " + testNum);
				}
				catch(InvalidOperationException)
				{
					// We expect this exception at the end of the list.
				}
				AssertEquals("Remaining " + testNum, 0,
							 iter.GetRemainingCount());
			}
	// Helper method for "TestArgIteratorEnd".
	private void TestEnd(String testNum, __arglist)
			{
				ArgIterator iter = new ArgIterator(__arglist);
				iter.End();
				AssertEquals("Remaining " + testNum, 0,
							 iter.GetRemainingCount());
				try
				{
					iter.GetNextArg();
					Fail("EndCheck " + testNum);
				}
				catch(InvalidOperationException)
				{
					// We expect this exception at the end of the list.
				}
			}
Exemple #46
0
        private static unsafe void SetupCallerPopArgument(byte* callerTransitionBlock, ArgIterator callerArgs)
        {
            int argStackPopSize = callerArgs.CbStackPop();

#if _TARGET_X86_
            // In a callee pops architecture, we must specify how much stack space to pop to reset the frame
            // to the ReturnValue thunk.
            ((TransitionBlock*)callerTransitionBlock)->m_argumentRegisters.ecx = new IntPtr(argStackPopSize);
#else
#error handling of how callee pop is handled is not yet implemented for this platform
#endif
        }
Exemple #47
0
 public Type[] argit7( __arglist )
   {
   Console.WriteLine( 1 );
   ArgIterator args = new ArgIterator( __arglist );
   int iCount = args.GetRemainingCount();
   Type[] typArr = new Type[iCount];
   for ( int i = 0; i < iCount; i++ )
     {
     Console.WriteLine( "       -> " + typeof( System.TypedReference ).TypeHandle.Value );
     Console.WriteLine( "       => " + args.GetNextArgType() );
     }
   return typArr;
   }
 public static void argit1( __arglist ) {
 ArgIterator args = new ArgIterator( __arglist );
 TypedReference trTypRef = args.GetNextArg();
 }
   public MyStruct SumAndCount(int a, int b, __arglist)
   {
     Console.WriteLine("This type: " + this.GetType().ToString());
     MyStruct t = new MyStruct();
     
    ArgIterator args = new ArgIterator(__arglist);     
    t.x += (a + b);
    t.y += args.GetRemainingCount();

    while(args.GetRemainingCount() > 0)
    {
        if (args.GetNextArgType().Equals(typeof(int).TypeHandle))
        {
            int N = __refvalue(args.GetNextArg(), int);
            Console.WriteLine("int value is "+N);
            t.x = t.x + N;
        }
        else
        if (args.GetNextArgType().Equals(typeof(byte).TypeHandle))
        {
            byte N = __refvalue(args.GetNextArg(), byte);
            Console.WriteLine("byte value is "+N);
            t.x = t.x + N;
        }
        else
        if (args.GetNextArgType().Equals(typeof(short).TypeHandle))
        {
            short N = __refvalue(args.GetNextArg(), short);
            Console.WriteLine("short value is "+N);
            t.x = t.x + N;
        }
        else
        if (args.GetNextArgType().Equals(typeof(long).TypeHandle))
        {
            TypedReference tr = args.GetNextArg();
            Interlocked.Increment(ref __refvalue(tr, long));
            long N = __refvalue(tr, long);
            Console.WriteLine("long value is "+N);
            t.x = t.x + (int)(N % 57);
        }
        else
        if (args.GetNextArgType().Equals(typeof(float).TypeHandle))
        {
            float N = __refvalue(args.GetNextArg(), float);
            Console.WriteLine("float value is "+N);
            t.x = t.x + (int)N;
        }
        else
        if (args.GetNextArgType().Equals(typeof(double).TypeHandle))
        {
            double N = __refvalue(args.GetNextArg(), double);
            Console.WriteLine("double value is "+N);
            t.x = t.x + (int)N;
        }                            
        else
        if (args.GetNextArgType().Equals(typeof(Struct1).TypeHandle))
        {
            Struct1 N = __refvalue(args.GetNextArg(), Struct1);
            Console.WriteLine("Struct1 value is "+N.x);
            t.x = t.x + N.x;
        }                            
        else
            throw new Exception();
     }
     
     return t;
   }
Exemple #50
0
   public static void argit0( __arglist )
     {
     ArgIterator args = new ArgIterator( __arglist );
     int iCount = args.GetRemainingCount();
     for ( int i = 0; i < iCount + 15; i++ )
       {
       try
	 {
	 TypedReference trTypRef =  args.GetNextArg();
	 if ( args.GetRemainingCount() != (iCount - i - 1) )
	   {
	   throw new Exception( "ExcErr5  ,Should have had remaining count " + (iCount - i - 1) + " but had remaining count " + args.GetRemainingCount() );
	   }
	 }
       catch(Exception ex)
	 {			
	 if ( i < iCount )
	   {
	   Console.WriteLine( i );
	   throw ex;
	   }
	 int iRemCount = args.GetRemainingCount();
	 if ( iRemCount != 0 )
	   {
	   throw new Exception( "ExcErr3  ,Should have had remaining count 0 but had remaining count " + iRemCount );
	   }
	 }
       }
     if ( args.GetRemainingCount() != 0 )
       {
       throw new Exception( "ExcErr4  ,Should have had remaining count 0");
       }
     }
Exemple #51
0
   public Object[] argit6( Object[] objExpectedArr, __arglist )
     {
     ArgIterator args = new ArgIterator( __arglist );
     int iCount = args.GetRemainingCount();
     Object[] objArr = new Object[iCount];
     for ( int i = 0; i < iCount; i++ )
       {
       objArr[i] = TypedReference.ToObject(args.GetNextArg());
       if ( objExpectedArr[i] == null )
	 {
	 if ( objArr[i] != null )
	   {
	   throw new Exception( "argit6 - 1, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
	   }
	 }
       else if ( ! objExpectedArr[i].Equals( objExpectedArr[i] ) )
	 {
	 throw new Exception( "argit6 - 2, __arglist[i] was null but it did not equal to objExpectedArr[i]" );
	 }
       }
     return objArr;
     }
Exemple #52
0
 public static void argit2( __arglist )
   {
   ArgIterator args = new ArgIterator( __arglist );
   Object o = args.GetNextArgType();
   }
	static void M (ref ArgIterator a)
	{
	}
        internal CallConversionParameters(CallConversionInfo conversionInfo, IntPtr callerTransitionBlockParam)
        {
            // Make sure the thred static variable has been initialized for this thread
            s_pinnedGCHandles = s_pinnedGCHandles ?? new GCHandleContainer();

            _conversionInfo = conversionInfo;
            _callerTransitionBlock = (byte*)callerTransitionBlockParam.ToPointer();
            _functionPointerToCall = conversionInfo.TargetFunctionPointer;
            _instantiatingStubArgument = conversionInfo.InstantiatingStubArgument;
            _delegateData = default(DelegateData);
            _calleeArgs = default(ArgIterator);
            _invokeReturnValue = IntPtr.Zero;
            _copyReturnValue = true;
            _dynamicInvokeParams = null;
            _dynamicInvokeByRefObjectArgs = null;

            // 
            // Setup input argument iterator for the caller
            //
            ArgIteratorData callerIteratorData;

            if (conversionInfo.IsDelegateDynamicInvokeThunk)
                callerIteratorData = s_delegateDynamicInvokeImplArgIteratorData;
            else if (conversionInfo.IsReflectionDynamicInvokerThunk)
                callerIteratorData = s_reflectionDynamicInvokeImplArgIteratorData;
            else
                callerIteratorData = conversionInfo.ArgIteratorData;

            _callerArgs = new ArgIterator(callerIteratorData,
                                              callerIteratorData.HasThis() ?
                                                CallingConvention.ManagedInstance :
                                                CallingConvention.ManagedStatic,
                                              conversionInfo.CallerHasParamType,
                                              conversionInfo.CallerHasExtraParameterWhichIsFunctionTarget,
                                              conversionInfo.CallerForcedByRefData,
                                              false, false); // Setup input

            bool forceCalleeHasParamType = false;

            // If the callee MAY have a param type, we need to know before we create the callee arg iterator
            // To do this we need to actually load the target address and see if it has the generic method pointer
            // bit set.
            if (conversionInfo.CalleeMayHaveParamType)
            {
                ArgIterator callerArgsLookupTargetFunctionPointer = new ArgIterator(conversionInfo.ArgIteratorData,
                                                                                        conversionInfo.ArgIteratorData.HasThis() ?
                                                                                            CallingConvention.ManagedInstance :
                                                                                            CallingConvention.ManagedStatic,
                                                                                        conversionInfo.CallerHasParamType,
                                                                                        conversionInfo.CallerHasExtraParameterWhichIsFunctionTarget,
                                                                                        conversionInfo.CallerForcedByRefData,
                                                                                        false, false);

                // Find the last valid caller offset. That's the offset of the target function pointer.
                int ofsCallerValid = TransitionBlock.InvalidOffset;
                while (true)
                {
                    // Setup argument offsets.
                    int ofsCallerTemp = callerArgsLookupTargetFunctionPointer.GetNextOffset();

                    // Check to see if we've handled all the arguments that we are to pass to the callee. 
                    if (TransitionBlock.InvalidOffset == ofsCallerTemp)
                        break;

                    ofsCallerValid = ofsCallerTemp;
                }

                if (ofsCallerValid == TransitionBlock.InvalidOffset)
                    throw new InvalidProgramException();

                int stackSizeCaller = callerArgsLookupTargetFunctionPointer.GetArgSize();
                Debug.Assert(stackSizeCaller == IntPtr.Size);
                void* pSrc = _callerTransitionBlock + ofsCallerValid;
                IntPtr tempFunctionPointer = *((IntPtr*)pSrc);

                forceCalleeHasParamType = UpdateCalleeFunctionPointer(tempFunctionPointer);
            }

            // Retrieve target function pointer and instantiation argument for delegate thunks
            if (conversionInfo.IsDelegateThunk)
            {
                Debug.Assert(_callerArgs.HasThis() && !_conversionInfo.IsUnboxingThunk);

                IntPtr locationOfThisPointer = (IntPtr)(_callerTransitionBlock + ArgIterator.GetThisOffset());
                _delegateData._delegateObject = (Delegate)Unsafe.As<IntPtr, Object>(ref *(IntPtr*)locationOfThisPointer);
                Debug.Assert(_delegateData._delegateObject != null);

                RuntimeAugments.GetDelegateData(
                    _delegateData._delegateObject,
                    out _delegateData._firstParameter,
                    out _delegateData._helperObject,
                    out _delegateData._extraFunctionPointerOrData,
                    out _delegateData._functionPointer);

                if (conversionInfo.TargetDelegateFunctionIsExtraFunctionPointerOrDataField)
                {
                    if (conversionInfo.IsOpenInstanceDelegateThunk)
                    {
                        _delegateData._boxedFirstParameter = BoxedCallerFirstArgument;
                        Debug.Assert(_delegateData._boxedFirstParameter != null);
                        _callerArgs.Reset();

                        IntPtr resolvedTargetFunctionPointer = OpenMethodResolver.ResolveMethod(_delegateData._extraFunctionPointerOrData, _delegateData._boxedFirstParameter);
                        forceCalleeHasParamType = UpdateCalleeFunctionPointer(resolvedTargetFunctionPointer);
                    }
                    else
                    {
                        forceCalleeHasParamType = UpdateCalleeFunctionPointer(_delegateData._extraFunctionPointerOrData);
                    }
                }
                else if (conversionInfo.IsMulticastDelegate)
                {
                    _delegateData._multicastTargetCount = (int)_delegateData._extraFunctionPointerOrData;
                }
            }

            // 
            // Setup output argument iterator for the callee
            //
            _calleeArgs = new ArgIterator(conversionInfo.ArgIteratorData,
                                                (conversionInfo.ArgIteratorData.HasThis() && !conversionInfo.IsStaticDelegateThunk) ?
                                                    CallingConvention.ManagedInstance :
                                                    CallingConvention.ManagedStatic,
                                                forceCalleeHasParamType || conversionInfo.CalleeHasParamType,
                                                false,
                                                conversionInfo.CalleeForcedByRefData,
                                                conversionInfo.IsOpenInstanceDelegateThunk,
                                                conversionInfo.IsClosedStaticDelegate);

            // The function pointer, 'hasParamType', and 'hasThis' flags for the callee arg iterator need to be computed/read from the caller's 
            // input arguments in the case of a reflection invoker thunk (the target method pointer and 'hasThis' flags are
            // passed in as parameters from the caller, not loaded from a static method signature in native layout)
            if (conversionInfo.IsReflectionDynamicInvokerThunk)
                ComputeCalleeFlagsAndFunctionPointerForReflectionInvokeThunk();

#if CALLINGCONVENTION_CALLEE_POPS
            // Ensure that the count of bytes in the stack is available
            _callerArgs.CbStackPop();
#endif
        }
	// Helper method for "TestArgIteratorGetValueByType".
	private void TestByType(String testNum, Type[] types, __arglist)
			{
				ArgIterator iter = new ArgIterator(__arglist);
				int count = iter.GetRemainingCount();
				AssertEquals("Length " + testNum, types.Length, count);
				while(count > 0)
				{
					Type type = types[types.Length - count];
					Object value = TypedReference.ToObject
						(iter.GetNextArg(type.TypeHandle));
					Type valueType = value.GetType();
					AssertEquals("TypeCheck " + testNum, type, valueType);
					--count;
					AssertEquals("Remaining " + testNum,
								 count, iter.GetRemainingCount());
				}
				try
				{
					iter.GetNextArg(typeof(double).TypeHandle);
					Fail("EndCheck " + testNum);
				}
				catch(InvalidOperationException)
				{
					// We expect this exception at the end of the list.
				}
				AssertEquals("Remaining " + testNum, 0,
							 iter.GetRemainingCount());

				// Reset the list and check for the wrong type.
				iter = new ArgIterator(__arglist);
				try
				{
					iter.GetNextArg(typeof(long).TypeHandle);
					Fail("TypeCheck 2 " + testNum);
				}
				catch(InvalidOperationException)
				{
					// This is what we expected.
				}
			}