示例#1
0
        public FieldInfo SetVariable(DataPortor scop, Tree tree, bool asParameter = false)
        {
            if (tree.Membre != null && scop.GetField(tree.Membre.Name, SearcheMode.Flaten) == tree.Membre)
            {
                return(tree.Membre);
            }
            string type      = tree.Children[0].Content;
            string varName   = tree.Children[1].Content;
            Class  @class    = GetClass(scop, type);
            var    fieldInfo = new FieldInfo(varName, @class, scop is MethodInfo);

            if (scop is MethodInfo && asParameter)
            {
                fieldInfo = ((MethodInfo)scop).AddParam(fieldInfo);
            }
            else if (scop is MethodInfo || scop is Class)
            {
                fieldInfo = scop.Add(fieldInfo);
            }
            else
            {
                throw new BadImageFormatException();
            }
            return(fieldInfo);
        }
示例#2
0
 internal void DownloadClass(Class scop, Tree tree)
 {
     _byteCodeMapper.CurrentScop.SetCurrent(scop);
     if (scop.IsClass)
     {
         if (scop == scop.Base)
         {
             throw new BadImageFormatException();
         }
         else if (!scop.Base.Finalized)
         {
             DownloadClass(scop.Base, _summary[scop.Base]);
             _byteCodeMapper.CurrentScop.SetCurrent(scop);
         }
     }
     scop.Base = scop.Base;
     foreach (Tree field in tree.Children.Where(field => field.Kind == Kind.TypeAssigne))
     {
         SetVariable(scop, field);
     }
     foreach (
         Tree method in
         tree.Children.Where(method => method.Kind == Kind.Function || method.Kind == Kind.Constructor))
     {
         SetMethodTo(scop, method);
     }
     scop.Finalized = true;
 }
示例#3
0
        public MethodCallHiretachy GetMethod(Tree val, IList <Tree> Params)
        {
            var @params = new Class[Params.Count];

            for (int j = 0; j < @params.Length; j++)
            {
                if (Params[j].Type == null)
                {
                    if (!_typeCalc.CalcTypes(Params[j]))
                    {
                        throw new TypeLoadException();
                    }
                }
                @params[j] = Params[j].Type;
            }
            return(ByteCodeMapper.CurrentScop.Finder.GetMethod(ByteCodeMapper.Split(val.Content), @params));
        }
示例#4
0
        private static void DeclareMethod <T>(string opers, Class leftOperand, Class rightOperand, Class @retrn) where T : MethodInfo, new()
        {
            var m = new T {
                Name = opers, Return = Bool, IsBasic = true
            };

            m.AddParam(new FieldInfo("a", leftOperand, true));
            m.AddParam(new FieldInfo("b", rightOperand, true));
            leftOperand.Scops.Add(m);

            if (leftOperand != rightOperand)
            {
                var n = new T {
                    Name = opers, Return = @retrn, IsBasic = true
                };
                n.AddParam(new FieldInfo("b", rightOperand, true));
                n.AddParam(new FieldInfo("a", leftOperand, true));
                leftOperand.Scops.Add(n);
            }
        }
示例#5
0
        private Class GetClass(DataPortor scop, string type)
        {
            Class @class = _byteCodeMapper.Finder.GetClass(_byteCodeMapper.CurrentScop.Root, type);

            if (@class == null)
            {
                LogIn(scop, null, this, "Class Name :" + type + " doesn't declared");
                return(null);
            }
            if ([email protected] && [email protected] && @class.IsFromAssembly(_byteCodeMapper.CurrentScop))
            {
                if (Prevent.Contains(@class))
                {
                    throw new StrongTypingException();
                }
                Prevent.Add((Class)scop);
                DownloadClass(@class, _summary[@class]);
                Prevent.RemoveAt(Prevent.Count - 1);
            }
            return(@class);
        }
示例#6
0
        private void SetMethodTo(Class @class, Tree _method)
        {
            int        inc        = _method.Kind == Kind.Constructor ? 1 : 0;
            string     returnType = _method[0].Content;
            Class      @return    = GetClass(@class, returnType);
            MethodInfo method     = _method.Method = new MethodInfo
            {
                Return = @return,
                Parent = @class,
                Name   = _method[1 - inc].Content
            };

            @class.Scops.Add(method);
            foreach (Tree child in _method[2 - inc].Children)
            {
                child.Membre   = SetVariable(method, child, true);
                child.BaseCall = method;
                child.Type     = child.Membre.Return;
                child.Compiled = true;
            }
        }
示例#7
0
        static Assembly()
        {
            if (Initialized)
            {
                return;
            }
            Initialized = true;
            var ns = (Namespace)CurrentScop.Initialize("System").Current;

            BaseClasses = new[]
            {
                Object = Class.LoadAsClass(ns, null, "object", 4),
                Void   = Class.LoadAsClass(ns, Object, "void", 0),

                Bool = Class.LoadAsStruct(ns, "bool", 1, true),
                Char = Class.LoadAsStruct(ns, "char", 2),
                Byte = Class.LoadAsStruct(ns, "byte", 1, true),

                Short  = Class.LoadAsStruct(ns, "short", 2, true),
                UShort = Class.LoadAsStruct(ns, "short", 2, true),

                Int  = Class.LoadAsStruct(ns, "int", 4, true),
                UInt = Class.LoadAsStruct(ns, "uint", 4, true),

                Long  = Class.LoadAsStruct(ns, "long", 8, true),
                ULong = Class.LoadAsStruct(ns, "ulong", 8, true),

                Float  = Class.LoadAsStruct(ns, "float", 4, true),
                Double = Class.LoadAsStruct(ns, "double", 8, true),

                Class.LoadAsStruct(ns, "complex", 16),
                String = Class.LoadAsClass(ns, Object, "string", 4),
                Class.LoadAsClass(ns, Object, "array", 4)
            };
            CPUClasses = new[] { Void, Bool, Char, Byte, Short, Int, Long, UShort, UInt, ULong, Float, Double };
            _shareProTypes(ns);
        }
示例#8
0
文件: Constants.cs 项目: QsCompany/Qs
        private static byte[] getBytes(double s, Class type)
        {
            var l = type.SizeOf();

            switch (l)
            {
            case 1:
                return(new[] { (byte)s });

            case 2:
                return(BitConverter.GetBytes((short)s));

            case 3:
                var bytes = BitConverter.GetBytes((int)s);
                return(new[] { bytes[0], bytes[1], bytes[2] });

            case 4:
                return(BitConverter.GetBytes((int)s));

            case 8:
                return(BitConverter.GetBytes(s));
            }
            return(new byte[l]);
        }
示例#9
0
文件: Constants.cs 项目: QsCompany/Qs
 public ConstInfo DeclareConst(Class type, string name = null, byte[] value = null)
 {
     return(DeclareConst(new ConstInfo(type, value, name)));
 }