Exemple #1
0
        private void DefineDefaultConstructor()
        {
            ConstructorBuilder builder = typeBuilder.DefineConstructor(
                MethodAttributes.Public,
                CallingConventions.Standard,
                new Type[0]);

            Block generator = new Block();

            // Call the base constructor

            ConstructorInfo baseConstructor
                = typeBuilder.BaseType.GetConstructor(new Type[0]);

            if (baseConstructor != null)
            {
                generator.LoadArg(0);
                generator.Call(baseConstructor);
            }

            SetMethodsToInitialValues(generator);

            generator.Return();

            generator.Build(new ConstructorBuilderProxy(builder));
        }
Exemple #2
0
        private void DefineConstructor(Method constructor)
        {
            Type[] parameters = new Type[1 + constructor.Parameters.Count];

            parameters[0] = typeof(RuntimeState);

            for (int n = 1; n < parameters.Length; n++)
            {
                parameters[n] = typeof(object);
            }

            ConstructorBuilder builder = typeBuilder.DefineConstructor(
                MethodAttributes.Public,
                CallingConventions.Standard,
                parameters);

            Block generator = new Block();

            SetMethodsToInitialValues(generator);

            if (!constructor.IsInstance)
            {
                throw new Exception();
            }

            MethodInfo callMethod = typeof(Method).GetMethod("Call", new Type[] { typeof(RuntimeState), typeof(object), typeof(object[]) });

            if (callMethod == null)
            {
                throw new Exception();
            }

            generator.Load(constructor);
            generator.LoadArg(1);
            generator.LoadArg(0);

            generator.Load(constructor.Parameters.Count);
            generator.NewArray(typeof(object));

            for (int n = 0; n < constructor.Parameters.Count; n++)
            {
                generator.Dup();
                generator.Load(n);
                generator.LoadArg(n + 1);
                generator.StoreElementRef();
            }

            generator.Call(callMethod);
            generator.Pop();

            generator.Return();

            generator.Build(new ConstructorBuilderProxy(builder));
        }
Exemple #3
0
        private void DefineParserConstructor()
        {
            OrderedSet <string> fields = pattern.Fields;

            Type[] parameterTypes = new Type[1 + fields.Count];

            parameterTypes[0] = typeof(Source);

            for (int n = 1; n < parameterTypes.Length; n++)
            {
                parameterTypes[n] = typeof(object);
            }

            ConstructorBuilder builder = typeBuilder.DefineConstructor(
                MethodAttributes.Public,
                CallingConventions.Standard,
                parameterTypes);

            Block generator = new Block();

            // Call the base constructor

            ConstructorInfo baseConstructor
                = typeBuilder.BaseType.GetConstructor(new Type[] { typeof(Source) });

            if (baseConstructor == null)
            {
                throw new Exception();
            }

            generator.LoadArg(0);
            generator.LoadArg(1);
            generator.Call(baseConstructor);

            SetMethodsToInitialValues(generator);

            // Save the fields

            for (int n = 0; n < fields.Count; n++)
            {
                generator.LoadArg(0);
                generator.LoadArg(n + 2);
                generator.StoreField(typeBuilder.GetField(fields[n]));
            }

            generator.Return();

            generator.Build(new ConstructorBuilderProxy(builder));
        }
Exemple #4
0
        private void DefineParserConstructor()
        {
            OrderedSet<string> fields = pattern.Fields;
            
            Type[] parameterTypes = new Type[1 + fields.Count];
            
            parameterTypes[0] = typeof(Source);
            
            for (int n = 1; n < parameterTypes.Length; n++)
                parameterTypes[n] = typeof(object);

            ConstructorBuilder builder = typeBuilder.DefineConstructor(
                MethodAttributes.Public,
                CallingConventions.Standard,
                parameterTypes);
            
            Block generator = new Block();
            
            // Call the base constructor
            
            ConstructorInfo baseConstructor
                = typeBuilder.BaseType.GetConstructor(new Type[]{typeof(Source)});
            
            if (baseConstructor == null)
                throw new Exception();
            
            generator.LoadArg(0);
            generator.LoadArg(1);
            generator.Call(baseConstructor);
            
            SetMethodsToInitialValues(generator);
            
            // Save the fields
            
            for (int n = 0; n < fields.Count; n++)
            {
                generator.LoadArg(0);
                generator.LoadArg(n + 2);
                generator.StoreField(typeBuilder.GetField(fields[n]));
            }
            
            generator.Return();
            
            generator.Build(new ConstructorBuilderProxy(builder));
        }
Exemple #5
0
 private void DefineConstructor(Method constructor)
 {
     Type[] parameters = new Type[1 + constructor.Parameters.Count];
     
     parameters[0] = typeof(RuntimeState);
     
     for (int n = 1; n < parameters.Length; n++)
         parameters[n] = typeof(object);
     
     ConstructorBuilder builder = typeBuilder.DefineConstructor(
         MethodAttributes.Public,
         CallingConventions.Standard,
         parameters);
     
     Block generator = new Block();
     
     SetMethodsToInitialValues(generator);
     
     if (!constructor.IsInstance)
         throw new Exception();
     
     MethodInfo callMethod = typeof(Method).GetMethod("Call", new Type[]{typeof(RuntimeState), typeof(object), typeof(object[])});
     
     if (callMethod == null)
         throw new Exception();
     
     generator.Load(constructor);
     generator.LoadArg(1);
     generator.LoadArg(0);
     
     generator.Load(constructor.Parameters.Count);
     generator.NewArray(typeof(object));
     
     for (int n = 0; n < constructor.Parameters.Count; n++)
     {
         generator.Dup();
         generator.Load(n);
         generator.LoadArg(n + 1);
         generator.StoreElementRef();
     }
     
     generator.Call(callMethod);
     generator.Pop();
     
     generator.Return();
     
     generator.Build(new ConstructorBuilderProxy(builder));
 }
Exemple #6
0
 private void DefineDefaultConstructor()
 {
     ConstructorBuilder builder = typeBuilder.DefineConstructor(
         MethodAttributes.Public,
         CallingConventions.Standard,
         new Type[0]);
     
     Block generator = new Block();
     
     // Call the base constructor
     
     ConstructorInfo baseConstructor
         = typeBuilder.BaseType.GetConstructor(new Type[0]);
     
     if (baseConstructor != null)
     {
         generator.LoadArg(0);
         generator.Call(baseConstructor);
     }
     
     SetMethodsToInitialValues(generator);
     
     generator.Return();
     
     generator.Build(new ConstructorBuilderProxy(builder));
 }