Exemple #1
0
        public static ZLClassInfo GetLiteralZType(LexTokenLiteral LiteralToken)
        {
            ZLClassInfo RetType      = null;;
            var         LiteralKind  = LiteralToken.Kind;
            var         LiteralValue = LiteralToken.Text;

            if (LiteralKind == TokenKindLiteral.LiteralInt)
            {
                RetType = ZLangBasicTypes.ZINT;
            }
            else if (LiteralKind == TokenKindLiteral.LiteralFloat)
            {
                RetType = ZLangBasicTypes.ZFLOAT;
            }
            else if (LiteralKind == TokenKindLiteral.LiteralString)
            {
                RetType = ZLangBasicTypes.ZSTRING;
            }
            else if (LiteralKind == TokenKindLiteral.True || LiteralKind == TokenKindLiteral.False)
            {
                RetType = ZLangBasicTypes.ZBOOL;
            }
            else if (LiteralKind == TokenKindLiteral.NULL)
            {
                RetType = null; //ZTypeCache.CreateZRealType(typeof(整数));// null;
            }
            return(RetType);
        }
        public void Import(ZLClassInfo zclassype)
        {
            string zname = zclassype.ZTypeName;

            ZLClassDict.Add(zname, zclassype);
            FileSegementer.AddWord(zname);
            ArgSegementer.AddWord(zname);

            foreach (ZLFieldInfo memberItem in zclassype.ZFields)
            {
                string[] itemNames = memberItem.GetZFieldZNames();
                foreach (var name in itemNames)
                {
                    //ZLPropertyDict.Add(name, memberItem);
                    FileSegementer.AddWord(name);
                }
            }

            foreach (ZLPropertyInfo memberItem in zclassype.ZPropertys)
            {
                string[] itemNames = memberItem.GetZPropertyZNames();
                foreach (var name in itemNames)
                {
                    //ZLPropertyDict.Add(name, memberItem);
                    FileSegementer.AddWord(name);
                }
            }

            foreach (ZLMethodInfo item in zclassype.ZMethods)
            {
                ImportMethod(item);
            }
        }
Exemple #3
0
        public override Exp Analy( )
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            SubjectExp = AnalySubExp(SubjectExp);
            ArgExp     = AnalySubExp(ArgExp);
            if (!this.AnalyCorrect)
            {
                return(this);
            }

            var propertyName = ZLangUtil.ZListItemPropertyName;
            var subjType     = SubjectExp.RetType;

            if (subjType is ZLClassInfo)
            {
                ZLClassInfo zclass  = subjType as ZLClassInfo;
                Type        argType = ZTypeUtil.GetTypeOrBuilder(ArgExp.RetType);
                Property = zclass.SharpType.GetProperty(propertyName, new Type[] { argType });
            }

            if (Property == null)
            {
                Errorf(SubjectExp.Position, "不存在索引");
            }
            else
            {
                RetType = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType;
            }
            IsAnalyed = true;
            return(this);
        }
Exemple #4
0
        public static ZLClassInfo MakeGenericType(ZLClassInfo genericType, params ZType[] argZTypes)
        {
            ZLClassInfo newzclass = genericType.MakeGenericType(argZTypes);

            Cache.AddCache(newzclass);
            return(newzclass);
        }
Exemple #5
0
        public override Exp Analy( )
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            if (this.ExpContext == null)
            {
                throw new CCException();
            }
            if (SubjectExp.RetType is ZLEnumInfo)
            {
                Errorf(this.Position, "约定类型没有过程");
            }
            else
            {
                SubjectZType = (SubjectExp.RetType as ZLClassInfo);
                var zmethods = SubjectZType.SearchZMethod(ExpProcDesc);
                if (zmethods.Length == 0)
                {
                    Errorf(this.Position, "没有找到对应的过程");
                }
                else
                {
                    SearchedMethod = zmethods[0];
                    var defArgs = SearchedMethod.ZParams;
                    newExpArgs = AnalyArgLambda(defArgs, ArgExps);

                    this.RetType = SearchedMethod.RetZType;
                }
            }
            IsAnalyed = true;
            return(this);
        }
Exemple #6
0
        private Exp SearchBase()
        {
            if (this.ExpContext.ClassContext.GetSuperZType() == null)
            {
                return(null);
            }
            ZLClassInfo superZType = this.ExpContext.ClassContext.GetSuperZType();

            ZLMethodInfo[] descArray = superZType.SearchDeclaredZMethod(CallDesc);
            if (descArray.Length == 0)
            {
                return(null);
            }
            else if (descArray.Length > 1)
            {
                Errorf(this.Position, "找到多个过程,不能确定是属于哪一个简略使用的类型的过程");
                return(null);
            }
            else
            {
                ZLMethodInfo methodDesc  = descArray[0];
                ExpCallSuper expCallThis = new ExpCallSuper(this.ExpContext, CallDesc, methodDesc, this, ArgExps);
                return(expCallThis);
            }
        }
Exemple #7
0
 private void AddClassMethodNamePart(ZLClassInfo zclass)
 {
     foreach (ZLMethodInfo zmethodInfo in zclass.ZMethods)
     {
         ZLMethodDesc[] itemNames = zmethodInfo.ZDescs;
         foreach (var desc in itemNames)
         {
             ImportMethodDesc(desc);
         }
     }
 }
        public void Analy()
        {
            string      fileName  = this.ASTClass.FileContext.FileModel.GeneratedClassName;
            bool        IsStatic  = false;
            ZLClassInfo BaseZType = null;

            if (Raw == null)
            {
                IsStatic  = false;
                BaseZType = ZLangBasicTypes.ZOBJECT;
            }
            else if (Raw.BaseTypeToken == null)
            {
                ExtendsTypeName = null;
                IsStatic        = false;
                BaseZType       = ZLangBasicTypes.ZOBJECT;
            }
            else
            {
                ExtendsTypeName = Raw.BaseTypeToken.Text;
                if (ExtendsTypeName == "唯一类型")
                {
                    IsStatic = true;
                }
                else if (ExtendsTypeName == "普通类型" || ExtendsTypeName == "一般类型")
                {
                    IsStatic  = false;
                    BaseZType = ZLangBasicTypes.ZOBJECT;
                }
                else
                {
                    IsStatic = false;
                    var ztypes = ZTypeManager.GetByMarkName(ExtendsTypeName);
                    if (ztypes.Length == 0)
                    {
                        this.ASTClass.FileContext.Errorf(Raw.BaseTypeToken.Position, "类型'{0}'不存在", ExtendsTypeName);
                    }
                    else if (ztypes.Length == 1)
                    {
                        BaseZType = ztypes[0] as ZLClassInfo;
                    }
                    else if (ztypes.Length == 0)
                    {
                        this.ASTClass.FileContext.Errorf(Raw.BaseTypeToken.Position, "'{0}'存在{1}个同名类型", ExtendsTypeName, ztypes.Length.ToString());
                    }
                }
                //if (ClassName != fileName)
                //{
                //    this.FileContext.Errorf(BaseTypeToken.Position, "类名称 '" + ClassName + "'和文件名称'" + fileName + "'不一致");
                //}
            }
            this.ASTClass.ClassContext.SetIsStatic(IsStatic);
            this.ASTClass.ClassContext.SetSuperClass(BaseZType);
        }
Exemple #9
0
        public bool IsSuperField(string name)
        {
            ZLClassInfo zbase = this.ClassContext.GetSuperZType();

            if (zbase == null)
            {
                return(false);
            }
            var zmember = zbase.SearchField(name);

            return(zmember != null);
        }
Exemple #10
0
        public bool CheckRunZLogo(ProjectCompileResult result)
        {
            if (result.MessageCollection.Errors.Count > 0)
            {
                return(false);
            }
            //if (result.CompiledTypes.Count == 0) return false;
            ZLClassInfo zclass = result.CompiledTypes.ZClasses[0] as ZLClassInfo;
            MethodInfo  method = zclass.SharpType.GetMethod("RunZLogo");

            return(method != null);
        }
Exemple #11
0
        //public void EmitBody()
        //{
        //    if (Properties != null)
        //    {
        //        Properties.EmitBodys();
        //    }
        //    foreach (ProcConstructorBase item in Constructors)
        //    {
        //        item.EmitBody();
        //    }
        //    foreach (ProcMethod item in Methods)
        //    {
        //        item.EmitBody();
        //    }
        //}

        public ZLClassInfo CreateZType()
        {
            if (!HasError())
            {
                Type        type       = this.ClassContext.GetTypeBuilder().CreateType();
                var         ztype      = ZTypeManager.GetByMarkType(type);
                ZLClassInfo zclasstype = (ZLClassInfo)ztype;
                this.FileContext.EmitedIZDescType = zclasstype;
                return(zclasstype);
            }
            return(null);
        }
Exemple #12
0
        public bool IsSuperProperty(string name)
        {
            ZLClassInfo zbase = this.ClassContext.GetSuperZType();

            if (zbase == null)
            {
                return(false);
            }
            ZLPropertyInfo zmember = zbase.SearchProperty(name);

            return(zmember != null);
        }
Exemple #13
0
        private void AnalyMember(ZLClassInfo zclass)
        {
            memberSymbol = zclass.SearchProperty(propertyName);
            if (memberSymbol != null)
            {
                RetType = ((ZLPropertyInfo)memberSymbol).GetZPropertyType();
                return;
            }

            memberSymbol = zclass.SearchField(propertyName);
            if (memberSymbol != null)
            {
                RetType = ((ZLFieldInfo)memberSymbol).GetZFieldType();
            }
        }
Exemple #14
0
        public override Exp Analy( )
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            var subjType = ListSymbol.GetZType();

            ZLClassInfo zclass = subjType as ZLClassInfo;

            Property  = zclass.SharpType.GetProperty(ZLangUtil.ZListItemPropertyName);
            RetType   = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType;
            IsAnalyed = true;
            return(this);
        }
Exemple #15
0
        private Exp AnalyGeneric_1()
        {
            LexToken genericArgTypeToken = TypeTokens[0];
            ZType    genericArgZType     = SearchZType(genericArgTypeToken);

            if (genericArgZType != null)
            {
                //Type newType = MakeGenericType(mainZType, genericArgZType);
                //ZType newZtype = ZTypeManager.RegNewGenericType(newType);
                ZLClassInfo newZClass = ZTypeManager.MakeGenericType((ZLClassInfo)mainZType, genericArgZType);
                ExpTypeTwo  twoExp    = new ExpTypeTwo(this.ExpContext, TypeTokens[0], TypeTokens[1], genericArgZType, mainZType, newZClass);
                return(twoExp.Analy());
            }
            return(noneType);
        }
Exemple #16
0
        public string GetMethodName()
        {
            ZLClassInfo baseZType = this.MethodAST.MethodContext.ClassContext.GetSuperZType();
            var         procDesc  = GetZDesc();

            if (baseZType != null)
            {
                var zmethods = baseZType.SearchZMethod(procDesc);
                if (zmethods.Length > 0)
                {
                    return(zmethods[0].SharpMethod.Name);
                }
            }
            string mname = this.CreateMethodName(procDesc);

            return(mname);
        }
Exemple #17
0
        private static ZTypeCompareEnum Compare(ZLClassInfo z1, ZCClassInfo z2)
        {
            ZTypeCompareEnum result = Compare(z1, z2.BaseZClass);

            if (result == ZTypeCompareEnum.EQ)
            {
                return(ZTypeCompareEnum.SuperOf);
            }
            else if (result == ZTypeCompareEnum.SuperOf)
            {
                return(ZTypeCompareEnum.SuperOf);
            }
            else
            {
                return(ZTypeCompareEnum.NEQ);
            }
        }
Exemple #18
0
        private Exp AnalyGeneric_2()
        {
            LexToken genericArgTypeToken1 = TypeTokens[0];
            LexToken genericArgTypeToken2 = TypeTokens[1];
            ZType    genericArgZType1     = SearchZType(genericArgTypeToken1);
            ZType    genericArgZType2     = SearchZType(genericArgTypeToken2);

            if (genericArgZType1 != null && genericArgZType2 != null)
            {
                //Type newType = MakeGenericType(mainZType, genericArgZType1, genericArgZType2);
                //ZType newZtype = ZTypeManager.RegNewGenericType(newType);
                //RetType = newZtype;
                ZLClassInfo  newZClass = ZTypeManager.MakeGenericType((ZLClassInfo)mainZType, genericArgZType1, genericArgZType2);
                ExpTypeThree twoExp    = new ExpTypeThree(this.ExpContext, TypeTokens[0], TypeTokens[1], TypeTokens[2], genericArgZType1, genericArgZType2, mainZType, newZClass);
                return(twoExp.Analy());
            }
            return(noneType);
        }
Exemple #19
0
        private List <IZObj> EmitTypes()
        {
            if (FileContext.HasError())
            {
                return(new List <IZObj>());
            }
            List <IZObj> list = new List <IZObj>();

            foreach (EnumAST item in EnumASTList)
            {
                item.EmitPropertiesBody();
                ZLEnumInfo ze = item.CreateZType();
                if (ze != null)
                {
                    list.Add(ze);
                    this.FileContext.ProjectContext.CompiledTypes.Add(ze);
                }
            }

            foreach (DimAST item in DimASTList)
            {
                item.EmitPropertiesBody();
                ZLDimInfo zd = item.CreateZType();
                if (zd != null)
                {
                    list.Add(zd);
                    this.FileContext.ProjectContext.CompiledTypes.Add(zd);
                }
            }

            foreach (ClassAST item in ClassASTList)
            {
                item.EmitMemberBody();
                ZLClassInfo zc = item.CreateZType();
                if (zc != null)
                {
                    list.Add(zc);
                    this.FileContext.ProjectContext.CompiledTypes.Add(zc);
                    //this.FileContext.ImportUseContext.ContextFileManager.Import(zc);
                }
            }

            return(list);
        }
Exemple #20
0
 public override Exp Analy()
 {
     if (this.IsAnalyed)
     {
         return(this);
     }
     SubjectExp = SubjectExp.Analy();
     if (SubjectExp.RetType == null)
     {
         //Type newType =typeof(列表<>).MakeGenericType(typeof(object));
         //ZType newZtype = ZTypeManager.RegNewGenericType(newType);
         ZLClassInfo newZClass = ZTypeManager.MakeGenericType(ZLangBasicTypes.ZLIST, ZLangBasicTypes.ZOBJECT);
         SubjectExp.RetType = newZClass;
     }
     CreateEachSymbols();
     AnalyCountMethod();
     ItemExp      = new ExpEachItem(this.ExpContext, this.ListSymbol, this.IndexSymbol);
     this.RetType = ZLangBasicTypes.ZVOID;
     IsAnalyed    = true;
     return(this);
 }
Exemple #21
0
        public void AnalyNameItemType(LexTokenText nameToken)
        {
            ContextImportUse importUseContext = this.ASTFile.FileContext.ImportUseContext;
            string           typeName         = nameToken.Text;
            var ztypes = importUseContext.SearchByTypeName(typeName);

            if (ztypes.Length == 0)
            {
                this.ASTFile.FileContext.Errorf(nameToken.Position, "没有搜索到'{0}'", typeName);
                return;
            }
            var descType = ztypes[0];

            if (descType is ZLClassInfo)
            {
                ZLClassInfo zclass = descType as ZLClassInfo;
                if (zclass.IsStatic)
                {
                    importUseContext.AddUseType(zclass);
                }
                else
                {
                    this.ASTFile.FileContext.Errorf(nameToken.Position, "'{0}'不是唯一类型,不能被导入类", typeName);
                }
            }
            else if (descType is ZLEnumInfo)
            {
                ZLEnumInfo zenum = descType as ZLEnumInfo;
                importUseContext.AddUseType(zenum);
            }
            else if (descType is ZLDimInfo)
            {
                ZLDimInfo zdim = descType as ZLDimInfo;
                importUseContext.AddDimType(zdim);
            }
            else
            {
                throw new CCException();
            }
        }
Exemple #22
0
        public override Exp Analy()
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            if (this.ExpContext == null)
            {
                throw new CCException();
            }
            VarName = VarToken.Text;
            ZLClassInfo zbase = this.ClassContext.GetSuperZType();

            ZMember = zbase.SearchProperty(VarName);
            if (ZMember == null)
            {
                throw new CCException();
            }
            RetType   = ZMember.ZPropertyType;
            IsAnalyed = true;
            return(this);
        }
Exemple #23
0
        private ExpStaticClassName ParseExpStaticClass(LexToken tok)
        {
            string name   = tok.Text;
            var    ztypes = this.ExpContext.FileContext.ImportUseContext.SearchImportType(name);

            if (ztypes.Length == 0)
            {
                return(null);
            }
            ZLClassInfo ztype = ztypes[0] as ZLClassInfo;

            if (ztype == null)
            {
                return(null);
            }
            if (!ztype.IsStatic)
            {
                return(null);
            }
            ExpStaticClassName expStatic = new ExpStaticClassName(this.ExpContext, tok, ztype);

            //expStatic.SetContextExp(this.ExpContext);
            return(expStatic);
        }
Exemple #24
0
        private static ZLType CreateZTypeImp(Type type)
        {
            if (AttributeUtil.HasAttribute <ZInstanceAttribute>(type))
            {
                ZInstanceAttribute zAttr = AttributeUtil.GetAttribute <ZInstanceAttribute>(type);
                Type        sharpType    = (zAttr.SharpType == null ? type : zAttr.SharpType);
                ZLClassInfo zclass       = new ZLClassInfo(type, sharpType, false);
                return(zclass);
            }
            else if (AttributeUtil.HasAttribute <ZEnumAttribute>(type))
            {
                ZLEnumInfo zenum = new ZLEnumInfo(type);
                return(zenum);
            }
            else if (AttributeUtil.HasAttribute <ZStaticAttribute>(type))
            {
                ZStaticAttribute zAttr     = AttributeUtil.GetAttribute <ZStaticAttribute>(type);
                Type             sharpType = (zAttr.SharpType == null ? type : zAttr.SharpType);
                ZLClassInfo      zclass    = new ZLClassInfo(type, sharpType, true);
                return(zclass);
            }

            return(null);
        }
Exemple #25
0
 public void SetSuperClass(ZLClassInfo baseType)
 {
     SelfCompilingType.BaseZClass = baseType;
 }
Exemple #26
0
 public ExpStaticClassName(ContextExp expContext, LexToken nameToken, ZLClassInfo classType)
     : base(expContext)
 {
     this.VarToken  = nameToken;
     this.classType = classType;
 }
Exemple #27
0
 private static ZTypeCompareEnum Compare(ZLClassInfo z1, ZLClassInfo z2)
 {
     return(Compare(z1.SharpType, z2.SharpType));
 }