Beispiel #1
0
        public void EmitTypeName()
        {
            if (HasError())
            {
                return;
            }
            else
            {
                ModuleBuilder  moduleBuilder = this.FileContext.ProjectContext.EmitContext.ModuleBuilder;
                var            fullName      = GetTypeFullName();
                bool           IsStatic      = this.ClassContext.IsStatic();
                TypeAttributes typeAttrs     = TypeAttributes.Public;
                if (IsStatic)
                {
                    typeAttrs = TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed;
                }
                var         parentZType  = this.ClassContext.GetSuperZType();
                TypeBuilder classBuilder = null;
                if (parentZType != null)
                {
                    classBuilder = moduleBuilder.DefineType(fullName, typeAttrs, parentZType.SharpType);
                }
                else
                {
                    classBuilder = moduleBuilder.DefineType(fullName, typeAttrs);
                }

                ASTUtil.SetZAttrClass(classBuilder, IsStatic);
                this.ClassContext.SetTypeBuilder(classBuilder);
            }
        }
Beispiel #2
0
        public void EmitName()
        {
            bool isStatic     = this.ParentProperties.ASTClass.ClassContext.IsStatic();
            var  classBuilder = this.ParentProperties.ASTClass.ClassContext.GetTypeBuilder();

            ZPropertyCompiling.IsStatic = isStatic;
            Type propertyType = null;

            if (PropertyZType is ZLType)
            {
                propertyType = ((ZLType)PropertyZType).SharpType;
            }
            else
            {
                propertyType = ((ZCClassInfo)PropertyZType).ClassBuilder;
            }
            MethodAttributes methodAttr = BuilderUtil.GetMethodAttr(isStatic);
            FieldAttributes  fieldAttr  = BuilderUtil.GetFieldAttr(isStatic);

            _fieldBuilder    = classBuilder.DefineField("_" + PropertyName, propertyType, fieldAttr);
            _propertyBuilder = classBuilder.DefineProperty(PropertyName, PropertyAttributes.None, propertyType, null);

            EmitGet(classBuilder, PropertyName, propertyType, isStatic, _fieldBuilder, _propertyBuilder, methodAttr);
            EmitSet(classBuilder, PropertyName, propertyType, isStatic, _fieldBuilder, _propertyBuilder, methodAttr);
            ASTUtil.SetZAttr(_propertyBuilder, PropertyName);
            ZPropertyCompiling.PropertyBuilder = _propertyBuilder;
        }
Beispiel #3
0
        //public ZLEnumInfo Emit()
        //{
        //    if (HasError())
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        //string packageName = this.FileContext.ProjectContext.PackageName;
        //        ModuleBuilder moduleBuilder = this.FileContext.ProjectContext.EmitContext.ModuleBuilder;
        //        var EnumFullName = GetTypeFullName();// packageName + "." + NameSection.TypeName;
        //        EnumTypeBuilder = moduleBuilder.DefineEnum(EnumFullName, TypeAttributes.Public, typeof(int));
        //        ASTUtil.SetZAttrEnum(EnumTypeBuilder);
        //        Properties.Emit(EnumTypeBuilder);
        //        var EmitedType = EnumTypeBuilder.CreateType();
        //        ZLEnumInfo ztype = ZTypeManager.GetByMarkType(EmitedType) as ZLEnumInfo;
        //        return ztype;
        //        //foreach (SectionEnum enumSection in EnumSections)
        //        //{
        //        //    var builder = this.ProjectContext.EmitContext.ModuleBuilder;
        //        //    var packageName = this.ProjectContext.ProjectModel.ProjectPackageName;
        //        //    var fileName = this.FileContext.FileModel.GeneratedClassName;//.GetFileNameNoEx();
        //        //    ZLEnumInfo ztype = enumSection.Compile(builder, packageName, fileName);
        //        //    return ztype;
        //        //}
        //    }
        //}

        public void EmitTypeName()
        {
            ModuleBuilder moduleBuilder = this.FileContext.ProjectContext.EmitContext.ModuleBuilder;
            var           EnumFullName  = GetTypeFullName();

            EnumTypeBuilder = moduleBuilder.DefineEnum(EnumFullName, TypeAttributes.Public, typeof(int));
            ASTUtil.SetZAttrEnum(EnumTypeBuilder);
        }
 public void Emit(EnumBuilder enumBuilder)
 {
     for (int i = 0; i < EnumItems.Count; i++)
     {
         string       name    = EnumItems[i];
         FieldBuilder builder = enumBuilder.DefineLiteral(name, i + 1);
         ASTUtil.SetAttrZCode(builder, name);
     }
 }
        public void EmitNames( )
        {
            EnumBuilder enumBuilder = this.ASTEnum.EnumTypeBuilder;

            for (int i = 0; i < EnumItems.Count; i++)
            {
                string       name    = EnumItems[i];
                FieldBuilder builder = enumBuilder.DefineLiteral(name, i + 1);
                ASTUtil.SetAttrZCode(builder, name);
            }
        }
Beispiel #6
0
        //public ZLDimInfo Emit()
        //{
        //    if (HasError())
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        string packageName = this.FileContext.ProjectContext.PackageName;
        //        ModuleBuilder moduleBuilder = this.FileContext.ProjectContext.EmitContext.ModuleBuilder;
        //        var fullName = packageName + "." + NameSection.TypeName;

        //        TypeAttributes typeAttrs = TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit;
        //        DimBuilder = moduleBuilder.DefineType(fullName, typeAttrs);
        //        ASTUtil.SetZAttrDim(DimBuilder);
        //        Properties.Emit(DimBuilder);
        //        Type type = DimBuilder.CreateType();
        //        var EmitedZType = ZTypeManager.CreateZLDimImp(type);
        //        return EmitedZType;
        //    }
        //}

        public void EmitTypeName()
        {
            if (HasError())
            {
                return;
            }
            else
            {
                ModuleBuilder  moduleBuilder = this.FileContext.ProjectContext.EmitContext.ModuleBuilder;
                var            fullName      = GetTypeFullName();
                TypeAttributes typeAttrs     = TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit;
                DimBuilder = moduleBuilder.DefineType(fullName, typeAttrs);
                ASTUtil.SetZAttrDim(DimBuilder);
                return;
            }
        }
Beispiel #7
0
        public void EmitName()
        {
            var          classBuilder = this.MethodContext.ClassContext.GetTypeBuilder();
            bool         isStatic     = this.MethodContext.ClassContext.IsStatic();
            ZCMethodDesc ProcDesc     = NamePart.GetZDesc();
            List <Type>  argTypes     = new List <Type>();
            var          parameters   = MethodContext.ZMethodInfo.ZParams;

            foreach (var zparam in parameters)
            {
                argTypes.Add(ZTypeUtil.GetTypeOrBuilder(zparam.ZParamType));
            }
            var MethodName = NamePart.GetMethodName();
            MethodAttributes methodAttributes;

            if (isStatic)
            {
                methodAttributes = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig;
            }
            else
            {
                methodAttributes = MethodAttributes.Public | MethodAttributes.Virtual;
            }
            MethodBuilder methodBuilder = classBuilder.DefineMethod(MethodName, methodAttributes,
                                                                    ZTypeUtil.GetTypeOrBuilder(RetZType), argTypes.ToArray());

            if (MethodName == "启动")
            {
                Type                   myType           = typeof(STAThreadAttribute);
                ConstructorInfo        infoConstructor  = myType.GetConstructor(new Type[] { });
                CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(infoConstructor, new object[] { });
                methodBuilder.SetCustomAttribute(attributeBuilder);
            }
            else
            {
                string code = this.NamePart.GetZDesc().ToZCode();
                ASTUtil.SetAttrZCode(methodBuilder, code);
            }
            this.MethodContext.SetBuilder(methodBuilder);
            this.NamePart.EmitName();
        }
Beispiel #8
0
 protected void Errorf(CodePosition postion, string msgFormat, params string[] msgParams)
 {
     ASTUtil.Errorf(this.ProcContext.ClassContext.FileContext, postion, msgFormat, msgParams);
 }