Exemple #1
0
 internal EventGen(TypeGen owner, string name, Type type, MethodAttributes mthAttr)
 {
     _owner = owner;
     Name   = name;
     _type  = type;
     _attrs = mthAttr;
 }
Exemple #2
0
 public PropertyGen(TypeGen owner, MethodAttributes attrs, Type type, string name)
 {
     this.owner = owner;
     this.attrs = attrs;
     this.type  = type;
     this.name  = name;
 }
Exemple #3
0
 public MethodGen(TypeGen owner, string name, MethodAttributes attributes, Type returnType, MethodImplAttributes implFlags)
     : base(owner, returnType)
 {
     this.name       = name;
     this.attributes = owner.PreprocessAttributes(this, attributes);
     this.implFlags  = implFlags;
 }
Exemple #4
0
 internal MethodGen(TypeGen owner, string name, MethodAttributes attributes, Type returnType, MethodImplAttributes implFlags)
     : base(owner, returnType, owner)
 {
     _name       = name;
     _attributes = owner.PreprocessAttributes(this, attributes);
     _implFlags  = implFlags;
 }
Exemple #5
0
        TypeGen ImplementDelegate()
        {
            TypeGen tg = new TypeGen(owner, name, attrs, typeof(MulticastDelegate), Type.EmptyTypes);

            ConstructorBuilder cb = tg.Public.RuntimeImpl.Constructor()
                                    .Parameter(typeof(object), "object")
                                    .Parameter(typeof(IntPtr), "method")
                                    .GetConstructorBuilder();

            cb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            MethodBuilder mb = tg.Public.Virtual.RuntimeImpl.Method(typeof(IAsyncResult), "BeginInvoke")
                               .CopyParameters(Parameters)
                               .UncheckedParameter(typeof(AsyncCallback), "callback")
                               .UncheckedParameter(typeof(object), "object")
                               .GetMethodBuilder();

            mb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            mb = tg.Public.Virtual.RuntimeImpl.Method(ReturnType, "EndInvoke")
                 .Parameter(typeof(IAsyncResult), "result")
                 .GetMethodBuilder();
            mb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            mb = tg.Public.Virtual.RuntimeImpl.Method(ReturnType, "Invoke")
                 .CopyParameters(Parameters)
                 .GetMethodBuilder();
            mb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            AttributeGen.ApplyList(ref customAttributes, tg.TypeBuilder.SetCustomAttribute);

            return(tg);
        }
Exemple #6
0
 public DelegateGen(TypeGen typeGen, string name, Type returnType, TypeAttributes typeAttributes)
     : base(returnType, typeGen.TypeMapper)
 {
     _owner2 = typeGen;
     _name   = name;
     _attrs  = typeAttributes;
 }
Exemple #7
0
        public TypeGen Interface(string name, params Type[] interfaces)
        {
            TypeGen tg = new TypeGen(this, Qualify(name), (_attrs | TypeAttributes.Interface | TypeAttributes.Abstract) & ~(TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit), null, interfaces, TypeMapper);

            _attrs = 0;
            return(tg);
        }
Exemple #8
0
        public TypeGen Class(string name, Type baseType, params Type[] interfaces)
        {
            TypeGen tg = new TypeGen(this, Qualify(name), (_attrs | TypeAttributes.Class) ^ TypeAttributes.BeforeFieldInit, baseType, interfaces, TypeMapper);

            _attrs = 0;
            return(tg);
        }
Exemple #9
0
        public TypeGen Struct(string name, params Type[] interfaces)
        {
            TypeGen tg = new TypeGen(this, Qualify(name), (_attrs | TypeAttributes.Sealed | TypeAttributes.SequentialLayout) ^ TypeAttributes.BeforeFieldInit, TypeMapper.MapType(typeof(ValueType)), interfaces, TypeMapper);

            _attrs = 0;
            return(tg);
        }
Exemple #10
0
 internal PropertyGen(TypeGen owner, MethodAttributes attrs, Type type, string name)
 {
     _owner           = owner;
     _attrs           = attrs;
     _type            = type;
     Name             = name;
     _indexParameters = new ParameterGenCollection(owner.TypeMapper);
 }
Exemple #11
0
        internal ConstructorGen(TypeGen owner, MethodAttributes attributes, MethodImplAttributes implFlags)
            : base(owner, null, owner)
        {
            _attributes = attributes;
            _implFlags  = implFlags;

            owner.RegisterForCompletion(this);
        }
Exemple #12
0
        public ConstructorGen(TypeGen owner, MethodAttributes attributes, MethodImplAttributes implFlags)
            : base(owner, null)
        {
            this.attributes = attributes;
            this.implFlags  = implFlags;

            owner.RegisterForCompletion(this);
        }
Exemple #13
0
        // this routine runs at parser-runtime (not parser-compiletime nor program-runtime)
        public string GetMangledContextual(TypeGen currentFrameBuilder, FrameScope currentScope, FrameScope topLevelScope, string varname)
        {
            string mangledName;

            if (!MangledContextuals.TryGetValue(varname, out mangledName))
            {
                throw new InvalidOperationException("you must declare the contextual " + varname + ", including its type annotation");
            }
            return(GetMangledContextual(currentFrameBuilder, currentScope, topLevelScope, topLevelScope[varname].Type, varname));
        }
Exemple #14
0
        protected RoutineGen(TypeGen owner, Type returnType)
            : base(returnType)
        {
            this.ownerType = this.owner = owner;

            if (owner != null)
            {
                owner.RegisterForCompletion(this);
            }
        }
Exemple #15
0
        TypeGen GetDelegateType()
        {
            if (delegateType == null)
            {
                LockSignature();
                delegateType = ImplementDelegate();
            }

            return(delegateType);
        }
Exemple #16
0
        internal EventGen(TypeGen owner, string name, Type type, MethodAttributes mthAttr)
        {
            this.owner = owner;
            this.name  = name;
            this.type  = type;
            this.attrs = mthAttr;

            eb = owner.TypeBuilder.DefineEvent(name, EventAttributes.None, type);
            owner.RegisterForCompletion(this);
        }
Exemple #17
0
        internal FieldGen(TypeGen owner, string name, Type type, FieldAttributes attrs)
        {
            _owner = owner;
            _attrs = attrs;
            Name   = name;
            _type  = type;

            _fb = owner.TypeBuilder.DefineField(name, type, attrs);
            owner.RegisterForCompletion(this);
        }
Exemple #18
0
        public FieldGen(TypeGen owner, string name, Type type, FieldAttributes attrs)
        {
            this.owner = owner;
            this.attrs = attrs;
            this.name  = name;
            this.type  = type;

            fb = owner.TypeBuilder.DefineField(name, type, attrs);
            owner.RegisterForCompletion(this);
        }
Exemple #19
0
        protected RoutineGen(TypeGen owner, Type returnType, ICodeGenBasicContext context)
            : base(returnType, owner.TypeMapper)
        {
            _context  = context;
            OwnerType = Owner = owner;

            if (owner != null)
            {
                owner.RegisterForCompletion(this);
            }
        }
Exemple #20
0
 public static void RunMethodTest(MethodGenerator method, string name = null)
 {
     ExecutableTestHelper.Generator gen = ag =>
     {
         TypeGen t = ag.Class("Test");
         {
             method(t.Public.Static.Method(typeof(void), "Main"));
         }
     };
     RunTest(gen, ExecutableTestHelper.GetTestName(method.Method));
 }
Exemple #21
0
        internal TypeGen(TypeGen owner, string name, TypeAttributes attrs, Type baseType, Type[] interfaces)
        {
            this.owner      = owner.owner;
            this.name       = name;
            this.baseType   = baseType;
            this.interfaces = interfaces;

            tb = owner.TypeBuilder.DefineNestedType(name, attrs, baseType, interfaces);
            owner.nestedTypes.Add(this);
            ScanMethodsToImplement(interfaces);

            TypeInfo.RegisterProvider(tb, this);
        }
Exemple #22
0
        public TypeGen Class(string name, Type baseType, params Type[] interfaces)
        {
            if (tb.IsInterface)
            {
                throw new InvalidOperationException(Properties.Messages.ErrInterfaceNoNested);
            }

            if (typeVis == 0)
            {
                typeVis |= TypeAttributes.NestedPrivate;
            }

            TypeGen tg = new TypeGen(this, name, (typeVis | typeVirt | typeFlags | TypeAttributes.Class) ^ TypeAttributes.BeforeFieldInit, baseType, interfaces);

            ResetAttrs();
            return(tg);
        }
Exemple #23
0
        public TypeGen Struct(string name, params Type[] interfaces)
        {
            if (tb.IsInterface)
            {
                throw new InvalidOperationException(Properties.Messages.ErrInterfaceNoNested);
            }

            if (typeVis == 0)
            {
                typeVis |= TypeAttributes.NestedPrivate;
            }

            TypeGen tg = new TypeGen(this, name, (typeVis | typeVirt | typeFlags | TypeAttributes.Sealed | TypeAttributes.SequentialLayout) ^ TypeAttributes.BeforeFieldInit, typeof(ValueType), interfaces);

            ResetAttrs();
            return(tg);
        }
Exemple #24
0
        TypeGen ImplementDelegate()
        {
            TypeGen tg;

            if (_owner == null)
            {
                tg = new TypeGen(_owner2, _name, _attrs, _owner2.TypeMapper.MapType(typeof(MulticastDelegate)), Type.EmptyTypes, TypeMapper);
            }
            else
            {
                tg = new TypeGen(_owner, _name, _attrs, _owner.TypeMapper.MapType(typeof(MulticastDelegate)), Type.EmptyTypes, TypeMapper);
            }

            ConstructorBuilder cb = tg.Public.RuntimeImpl.Constructor()
                                    .Parameter(Helpers.TypeOf <object>(TypeMapper), "object")
                                    .Parameter(Helpers.TypeOf <IntPtr>(TypeMapper), "method")
                                    .GetConstructorBuilder();

            cb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            MethodBuilder mb = tg.Public.Virtual.RuntimeImpl.Method(Helpers.TypeOf <IAsyncResult>(TypeMapper), "BeginInvoke")
                               .CopyParameters(Parameters)
                               .UncheckedParameter(Helpers.TypeOf <AsyncCallback>(TypeMapper), "callback")
                               .UncheckedParameter(Helpers.TypeOf <object>(TypeMapper), "object")
                               .GetMethodBuilder();

            mb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            mb = tg.Public.Virtual.RuntimeImpl.Method(ReturnType, "EndInvoke")
                 .Parameter(Helpers.TypeOf <IAsyncResult>(TypeMapper), "result")
                 .GetMethodBuilder();
            mb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            mb = tg.Public.Virtual.RuntimeImpl.Method(ReturnType, "Invoke")
                 .CopyParameters(Parameters)
                 .GetMethodBuilder();
            mb.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            AttributeGen.ApplyList(ref _customAttributes, tg.TypeBuilder.SetCustomAttribute);

            return(tg);
        }
Exemple #25
0
        // this routine runs at parser-runtime (not parser-compiletime nor program-runtime)
        public string GetMangledContextual(TypeGen currentFrameBuilder, FrameScope currentScope, FrameScope topLevelScope, Type type, string varname)
        {
            string mangledName;

            if (!MangledContextuals.TryGetValue(varname, out mangledName))
            {
                var frameLocal = new FrameLocal(varname, type, topLevelScope);
                topLevelScope.AddHere(varname, frameLocal);
                currentFrameBuilder.FrameGen.MangledContextuals.Add(varname, mangledName = frameLocal.MangledName);
                // create a field in the toplevel frame class for the current contextual value
                Public.Field(type, "_ctxl_" + mangledName);
                // and create a runtime type representing the type of the Stack<TypeOfThisContextual>
                var stack_type = typeof(Stack <>).MakeGenericType(type);
                // create a field in the toplevel frame class for the stack of previously assigned dynamic
                //   values of the contextual variable.
                Public.Field(stack_type, "_stack_" + mangledName);
                // push a closure that will run (parser-runtime) at the end of the toplevel routine declaration
                //   (but at program-runtime will run as a prologue to the program) that initializes this stack
                PrologueEvents.Add((CodeGen cg) => {
                    if (cg.This().Type.Name == "TopLevelFrame")
                    {
                        cg.Assign(cg.This().Field("_stack_" + mangledName), Exp.New(stack_type));
                    }
                    else
                    {
                        cg.Assign(cg.This().Field("TopLevelFrame").Field("_stack_" + mangledName), Exp.New(stack_type));
                    }
                });
            }
            // if we haven't already added a flag assigned slot for this contextual-scope tuple in this frame,
            if (!currentScope.AssignedContextuals.Contains(mangledName))
            {
                // record that we've done so,
                currentScope.AssignedContextuals.Add(mangledName);
                // and create a field in the current frame class for a flag representing whether to pop the
                //   contextual stack upon leaving this scope,
                currentFrameBuilder.FrameGen.Public.Field(typeof(int), "_assigned_" + currentScope.ID + "_" + mangledName);
            }
            return(mangledName);
        }
Exemple #26
0
 internal void AddType(TypeGen tg)
 {
     _types.Add(tg);
 }
Exemple #27
0
 public void AddType(TypeGen tg)
 {
     types.Add(tg);
 }