Beispiel #1
0
 internal Method(MethodDeclarationInfo type, Class parent, AccessFlag flag, int index)
 {
     Parent            = parent;
     AccessFlag        = flag;
     Declaration       = type;
     ConstantPoolIndex = index;
 }
Beispiel #2
0
        /// <summary>
        /// Method for creating a new topic.
        /// </summary>
        /// <param name="forum">The parent forum of the topic.</param>
        /// <param name="subject">The subject of the topic.</param>
        /// <param name="message">The content/message of the topic.</param>
        /// <param name="type">The type of the topic </param>
        /// <param name="customPropties"></param>
        /// <returns>The newly created topic.</returns>
        public Topic Create(Forum forum, String subject, String message, TopicType type, IDictionary <String, Object> customPropties = null)
        {
            if (forum == null)
            {
                throw new ArgumentNullException("forum");
            }
            if (String.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException("subject");
            }
            if (String.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException("message");
            }
            forum = this.forumRepo.Read(f => f.Id == forum.Id);
            if (forum == null)
            {
                throw new ArgumentException("forum does not exist");
            }

            this.logger.WriteFormat("Create called on TopicService, subject: {0}, forum id: {1}", subject, forum.Id);
            AccessFlag flag = this.permService.GetAccessFlag(this.userProvider.CurrentUser, forum);

            if ((flag & AccessFlag.Create) != AccessFlag.Create)
            {
                this.logger.WriteFormat("User does not have permissions to create a new topic in forum {1}, subject: {0}", subject, forum.Id);
                throw new PermissionException("topic, create");
            }
            if (type != TopicType.Regular && (flag & AccessFlag.Priority) != AccessFlag.Priority)
            {
                this.logger.WriteFormat("User does not have permissions to set topic type on new topic in forum {1}, subject: {0}", subject, forum.Id);
                throw new PermissionException("topic, type");
            }

            Topic t = new Topic {
                Author   = this.userProvider.CurrentUser,
                AuthorId = this.userProvider.CurrentUser.Id,
                Changed  = DateTime.UtcNow,
                Created  = DateTime.UtcNow,
                Editor   = this.userProvider.CurrentUser,
                EditorId = this.userProvider.CurrentUser.Id,
                Forum    = forum,
                ForumId  = forum.Id,
                Message  = message,
                State    = TopicState.None,
                Subject  = subject,
                Type     = type
            };

            t.SetCustomProperties(customPropties);

            this.topicRepo.Create(t);
            this.logger.WriteFormat("Topic created in TopicService, Id: {0}", t.Id);
            this.eventPublisher.Publish <TopicCreated>(new TopicCreated {
                Topic = t
            });
            this.logger.WriteFormat("Create events in TopicService fired, Id: {0}", t.Id);

            return(t);
        }
Beispiel #3
0
 internal Account(AccountDatabase db, long id, string name, AccessFlag permissions)
 {
     mDB            = db;
     CharacterId    = id;
     mCharacterName = name;
     Permissions    = permissions;
 }
Beispiel #4
0
 internal Field(AccessFlag flag, Class parent, VariableType type, int index)
     : base(type)
 {
     Parent            = parent;
     AccessFlag        = flag;
     ConstantPoolIndex = index;
 }
Beispiel #5
0
 public Class(string internalName, string fqn, AccessFlag accessFlags)
     : this()
 {
     this.internalName = internalName;
     this.fqn = fqn;
     this.accessFlags = accessFlags;
 }
Beispiel #6
0
 public void UpdateAuthInfo(TokenInfo tokens, AccessFlag permissions)
 {
     AccessToken  = tokens.AccessToken;
     RefreshToken = tokens.RefreshToken;
     Expires      = tokens.Expires;
     Permissions  = permissions;
 }
Beispiel #7
0
        /// <summary>
        /// Method for updating a post.
        /// </summary>
        /// <param name="post">The properties from this post will be update in the data storage.</param>
        /// <returns>The updated post.</returns>
        /// <remarks>Please note, only some properties are taken from the give post, others are automatically updated (changed, editor, etc.) and others can not be updated by this method (state, etc.).</remarks>
        public Post Update(Post post)
        {
            if (post == null)
            {
                throw new ArgumentNullException("post");
            }
            this.logger.WriteFormat("Update called on PostService, Id: {0}", post.Id);
            // Let's get the topic from the data-storage!
            Post oldPost = this.Read(post.Id);

            if (oldPost == null)
            {
                this.logger.WriteFormat("Update post failed, no post with the given id was found, Id: {0}", post.Id);
                throw new ArgumentException("psot does not exist");
            }
            Post originalPost = oldPost.Clone() as Post;

            // Author with "update" access or moderator?
            AccessFlag flag = this.permService.GetAccessFlag(this.userProvider.CurrentUser, oldPost.Topic.Forum);

            if ((flag & AccessFlag.Priority) != AccessFlag.Update)
            {
                this.logger.WriteFormat("User does not have permissions to update a post, id: {1}, subject: {0}", post.Subject, post.Id);
                throw new PermissionException("topic, update");
            }

            Boolean changed = false;

            if (oldPost.Subject != post.Subject)
            {
                oldPost.Subject = post.Subject;
                changed         = true;
            }
            if (oldPost.Message != post.Message)
            {
                oldPost.Message = post.Message;
                changed         = true;
            }
            if (oldPost.CustomProperties != post.CustomProperties)
            {
                oldPost.CustomProperties = post.CustomProperties;
                changed = true;
            }

            if (changed)
            {
                oldPost.Editor   = this.userProvider.CurrentUser;
                oldPost.EditorId = this.userProvider.CurrentUser.Id;
                oldPost.Changed  = DateTime.UtcNow;
                oldPost          = this.postRepo.Update(oldPost);
                this.logger.WriteFormat("Post updated in postService, Id: {0}", oldPost.Id);
                this.eventPublisher.Publish <PostUpdated>(new PostUpdated(originalPost)
                {
                    UpdatedPost = oldPost
                });
                this.logger.WriteFormat("Update events in PostService fired, Id: {0}", oldPost.Id);
            }
            return(oldPost);
        }
Beispiel #8
0
 internal VMField(uint flag, VariableType type, int classIndex, int offset)
     : base(type)
 {
     Offset     = offset;
     AccessFlag = new AccessFlag()
     {
         Flag = flag
     };
     ClassIndex = classIndex;
 }
Beispiel #9
0
        public Field AddClassField(Class classType, string name, VariableType type, AccessFlag flag)
        {
            int index = FieldPool.Add(new FieldConstantInfo(
                                          classType.ConstantPoolIndex,
                                          StringPool.TryAdd(name),
                                          StringPool.TryAdd(type.GetDescriptor()),
                                          flag.Flag));

            return(classType.AddField(name, type, flag, index));
        }
Beispiel #10
0
        /// <summary>
        /// 请使用这个函数添加field
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="flag"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        internal Field AddField(string name, VariableType type, AccessFlag flag, int index)
        {
            if (Methods.ContainsKey(name))
            {
                throw new XiVMError($"Dupilcate Name {name} in class {Name}");
            }

            Field field = new Field(flag, this, type, index);

            Fields.Add(name, field);
            return(field);
        }
Beispiel #11
0
        public static Uri GetUrl(AccessFlag flags, int local_port, string private_data, out string challenge_code)
        {
            challenge_code = GenerateCode(32);

            string scopes = GetScopes(flags);

            StringBuilder url = new StringBuilder("/api/hyperwave/login?");

            url.Append($"&port={local_port}");
            url.AppendFormat("&scope={0}", Uri.EscapeUriString(scopes));
            url.AppendFormat("&code_challenge={0}", HashCode(challenge_code));
            url.AppendFormat("&state={0}", Uri.EscapeUriString(private_data));

            return(new Uri(SSOConfiguration.LoginPortalUrl, url.ToString()));
        }
Beispiel #12
0
        private static string GetScopes(AccessFlag flags)
        {
            List <string> access = new List <string>(8)
            {
                "esi-mail.read_mail.v1"
            };

            if (flags.HasFlag(AccessFlag.MailWrite))
            {
                access.Add("esi-mail.organize_mail.v1");
            }

            if (flags.HasFlag(AccessFlag.MailSend))
            {
                access.Add("esi-mail.send_mail.v1");
            }

            if (flags.HasFlag(AccessFlag.ContactsRead))
            {
                access.Add("characterContactsRead");
            }

            if (flags.HasFlag(AccessFlag.ContactsWrite))
            {
                access.Add("characterContactsWrite");
            }

            if (flags.HasFlag(AccessFlag.CalendarRead))
            {
                access.Add("characterCalendarRead");
            }

            if (flags.HasFlag(AccessFlag.CalendarWrite))
            {
                access.Add("esi-calendar.respond_calendar_events.v1");
            }

            if (flags.HasFlag(AccessFlag.WalletRead))
            {
                access.Add("esi-wallet.read_character_wallet.v1");
            }

            string scopes = string.Join(" ", access);

            return(scopes);
        }
Beispiel #13
0
        /// <summary>
        /// 这里用了LookAhead
        /// 此外不允许不带定义的声明
        /// DeclarationStmt
        ///     ACCESS_FLAG* TypeExpr FuncDeclarator BlockStmt
        ///     ACCESS_FLAG* TypeExpr VarDeclarator SEMICOLON
        /// </summary>
        /// <returns></returns>
        private DeclarationStmt ParseDeclOrDefStmt()
        {
            AccessFlag flag = ParserAccessFlag();
            TypeExpr   type = ParseTypeExpr();

            if (Check(TokenType.LPAREN) || CheckAt(1, TokenType.LPAREN))
            {
                FuncStmt ret = ParseFuncDeclarator(type, flag);
                ret.Body = ParseBlockStmt();
                return(ret);
            }
            else
            {
                VarStmt ret = ParseVarDeclarator(type, flag);
                Consume(TokenType.SEMICOLON);
                return(ret);
            }
        }
Beispiel #14
0
            bool SetOption(AccessFlag flag, bool enabled)
            {
                if (Flags.HasFlag(flag) == enabled)
                {
                    return(false);
                }

                if (enabled)
                {
                    Flags |= flag;
                }
                else
                {
                    Flags &= ~flag;
                }

                return(true);
            }
Beispiel #15
0
        /// <summary>
        /// 参数中不能出现void,构造函数没有ID
        /// FuncDeclarator
        ///     ID? LPAREN ParamsAST RPAREN
        /// </summary>
        /// <param name="retType"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        private FuncStmt ParseFuncDeclarator(TypeExpr retType, AccessFlag flag)
        {
            string id;

            if (Check(TokenType.LPAREN))
            {
                id = "(init)";
            }
            else
            {
                id = Consume(TokenType.ID).Literal;
            }
            Consume(TokenType.LPAREN);
            ParamsAst ps = null;

            ps = ParseParamsAST();

            Consume(TokenType.RPAREN);
            return(new FuncStmt(flag, retType, id, ps));
        }
Beispiel #16
0
        /// <summary>
        /// VarDeclarator
        ///     Id (ASSIGN Expr)? (COMMA VarDeclarator)?
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private VarStmt ParseVarDeclarator(TypeExpr type, AccessFlag flag)
        {
            Expr    declarator = ParseExpr(true);
            VarStmt vars;

            if (declarator is IdExpr idExpr)
            {
                vars = new VarStmt(flag, type, idExpr.Id, null);
            }
            else
            {
                vars = new VarStmt(flag, type, ((IdExpr)declarator.Expr1).Id, declarator.Expr2);
            }
            if (Check(TokenType.COMMA))
            {
                Consume(TokenType.COMMA);
                vars.SiblingAST = ParseVarDeclarator(type, flag);
            }
            return(vars);
        }
Beispiel #17
0
 /// <summary>
 /// 因为在生成raw的时候并不知道要访问函数还是域(函数和域允许同名)
 /// 所以生成raw的时候仅作信息检索不生成字节码
 /// 在这里做决定,生成field的相关字节码
 /// </summary>
 /// <param name="pass"></param>
 /// <param name="raw"></param>
 /// <returns></returns>
 private static VariableType ExpectLocalOrField(CodeGenPass pass, VariableType raw)
 {
     if (raw is MemberType memberType)
     {
         if (memberType.IsField)
         {
             FieldConstantInfo fieldConstantInfo = pass.Constructor.FieldPool.Get(memberType.FieldPoolIndex);
             AccessFlag        flag = new AccessFlag()
             {
                 Flag = fieldConstantInfo.Flag
             };
             if (flag.IsStatic)
             {
                 if (memberType.FromObject)
                 {
                     // 多余的object地址要pop
                     pass.Constructor.AddPop(new ObjectType(memberType.ClassType));
                 }
                 pass.Constructor.AddLoadStatic(memberType.FieldPoolIndex);
             }
             else
             {
                 if (memberType.FromThis)
                 {
                     // 隐式的this.bar
                     pass.Constructor.AddLocal(pass.Constructor.CurrentMethod.Params[0].Offset);
                     pass.Constructor.AddLoadT(pass.Constructor.CurrentMethod.Params[0].Type);
                 }
                 pass.Constructor.AddLoadNonStatic(memberType.FieldPoolIndex);
             }
             VariableType ret = VariableType.GetType(
                 pass.Constructor.StringPool.Get(fieldConstantInfo.Descriptor));
             return(ret);
         }
         else
         {
             throw new XiLangError($"{memberType} is not a variable");
         }
     }
     return(raw);
 }
Beispiel #18
0
        /// <summary>
        /// ACCESS_FLAG*
        /// 目前仅支持static,只允许出现一次
        /// </summary>
        /// <returns></returns>
        private AccessFlag ParserAccessFlag()
        {
            AccessFlag accessFlag = new AccessFlag();

            while (Check(LexicalRules.AccessFlagTokens))
            {
                Token t = Consume(LexicalRules.AccessFlagTokens);
                switch (t.Type)
                {
                case TokenType.STATIC:
                    if (accessFlag.IsStatic)
                    {
                        throw new SyntaxError("Duplicated static modifier", t);
                    }
                    accessFlag.IsStatic = true;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            return(accessFlag);
        }
Beispiel #19
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name='dex'>
        /// Pointer to the DEX file this class was loaded from
        /// </param>
        internal Class(Dex dex, BinaryReader reader)
        {
            Dex = dex;

            ClassIndex      = reader.ReadUInt32();
            AccessFlags     = (AccessFlag)reader.ReadUInt32();
            SuperClassIndex = reader.ReadUInt32();
            var interfacesOffset = reader.ReadUInt32();

            SourceFileIndex = reader.ReadUInt32();
            var annotationsOffset  = reader.ReadUInt32();
            var classDataOffset    = reader.ReadUInt32();
            var staticValuesOffset = reader.ReadUInt32();

            Interfaces = dex.ReadTypeList(interfacesOffset);

            var fieldAnnotations     = new Dictionary <uint, List <Annotation> >();
            var methodAnnotations    = new Dictionary <uint, List <Annotation> >();
            var parameterAnnotations = new Dictionary <uint, List <Annotation> >();

            if (annotationsOffset != 0)
            {
                reader.BaseStream.Position = annotationsOffset;

                // annotations_directory_item
                var classAnnotationsOffset   = reader.ReadUInt32();
                var annotatedFieldsCount     = reader.ReadUInt32();
                var annotatedMethodsCount    = reader.ReadUInt32();
                var annotatedParametersCount = reader.ReadUInt32();

                for (int i = 0; i < annotatedFieldsCount; i++)
                {
                    // field_annotation
                    var fieldIndex  = reader.ReadUInt32();
                    var annotations = Annotation.ReadAnnotations(reader);
                    fieldAnnotations.Add(fieldIndex, annotations);
                }

                for (int i = 0; i < annotatedMethodsCount; i++)
                {
                    // method_annotation
                    var methodIndex = reader.ReadUInt32();
                    var annotations = Annotation.ReadAnnotations(reader);
                    methodAnnotations.Add(methodIndex, annotations);
                }

                for (int i = 0; i < annotatedParametersCount; i++)
                {
                    // parameter_annotation
                    var methodIndex = reader.ReadUInt32();
                    var annotations = Annotation.ReadAnnotations(reader);
                    parameterAnnotations.Add(methodIndex, annotations);
                }

                if (classAnnotationsOffset > 0)
                {
                    reader.BaseStream.Position = classAnnotationsOffset;
                    Annotations = Annotation.ReadAnnotationSetItem(reader);
                }
            }

            if (classDataOffset != 0)
            {
                reader.BaseStream.Position = classDataOffset;

                var staticFieldsCount   = Leb128.ReadUleb(reader);
                var instanceFieldsCount = Leb128.ReadUleb(reader);
                var directMethodsCount  = Leb128.ReadUleb(reader);
                var virtualMethodsCount = Leb128.ReadUleb(reader);

                StaticFields   = ReadFields(staticFieldsCount, reader, fieldAnnotations);
                InstanceFields = ReadFields(instanceFieldsCount, reader, fieldAnnotations);
                DirectMethods  = ReadMethods(directMethodsCount, reader, methodAnnotations, parameterAnnotations);
                VirtualMethods = ReadMethods(virtualMethodsCount, reader, methodAnnotations, parameterAnnotations);
            }
            else
            {
                StaticFields   = new Field[0];
                InstanceFields = new Field[0];
                DirectMethods  = new Method[0];
                VirtualMethods = new Method[0];
            }

            if (staticValuesOffset != 0)
            {
                reader.BaseStream.Position = staticValuesOffset;

                var size   = Leb128.ReadUleb(reader);
                var values = new EncodedValue[size];

                for (int i = 0; i < (int)size; i++)
                {
                    values[i] = EncodedValue.parse(reader);
                }

                StaticFieldsValues = values;
            }
            else
            {
                StaticFieldsValues = new EncodedValue[0];
            }
        }
Beispiel #20
0
        protected Post Create(Topic topic, Post post, String subject, String message, IDictionary <String, Object> customProperties)
        {
            if (topic == null)
            {
                throw new ArgumentNullException("topic");
            }
            if (String.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException("subject");
            }
            if (String.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException("message");
            }
            // Let's get the topic from the data-storage!
            topic = this.topicRepo.Read(t => t.Id == topic.Id);
            if (topic == null)
            {
                throw new ArgumentException("topic does not exist");
            }
            if (post != null)
            {
                // Let's get the topic from the data-storage!
                post = this.postRepo.Read(po => po.Id == post.Id);
                if (post == null)
                {
                    throw new ArgumentException("post does not exist");
                }
            }

            this.logger.WriteFormat("Create called on PostService, subject: {0}, topic id: {1}", subject, topic.Id);
            AccessFlag flag = this.permService.GetAccessFlag(this.userProvider.CurrentUser, topic.Forum);

            if ((flag & AccessFlag.Reply) != AccessFlag.Reply)
            {
                this.logger.WriteFormat("User does not have permissions to create a new post in topic {1}, subject: {0}", subject, topic.Id);
                throw new PermissionException("post, create");
            }

            Post p = new Post {
                Author   = this.userProvider.CurrentUser,
                AuthorId = this.userProvider.CurrentUser.Id,
                Changed  = DateTime.UtcNow,
                Created  = DateTime.UtcNow,
                Editor   = this.userProvider.CurrentUser,
                EditorId = this.userProvider.CurrentUser.Id,
                Topic    = topic,
                TopicId  = topic.Id,
                Forum    = topic.Forum,
                ForumId  = topic.ForumId,
                Message  = message,
                State    = PostState.None,
                Subject  = subject
            };

            p.SetCustomProperties(customProperties);

            // Was a parent post given?
            if (post != null)
            {
                // Let's store that then, for the "tree" view (and other features)
                p.ParentPost   = post;
                p.ParentPostId = post.Id;
            }

            this.postRepo.Create(p);
            this.logger.WriteFormat("Post created in PostService, Id: {0}", p.Id);
            this.eventPublisher.Publish <PostCreated>(new PostCreated {
                Post = p
            });
            this.logger.WriteFormat("Create events in PostService fired, Id: {0}", p.Id);

            return(p);
        }
Beispiel #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="accessFlag">局部变量传null</param>
 /// <param name="type"></param>
 /// <param name="id"></param>
 /// <param name="init"></param>
 public VarStmt(AccessFlag accessFlag, TypeExpr type, string id, Expr init)
     : base(accessFlag, type, id)
 {
     Init = init;
 }
Beispiel #22
0
 public FuncStmt(AccessFlag flag, TypeExpr type, string id, ParamsAst ps)
     : base(flag, type, id)
 {
     Params = ps;
 }
Beispiel #23
0
        public Method AddMethod(Class classType, string name, VariableType retType, List <VariableType> ps, AccessFlag flag)
        {
            MethodDeclarationInfo declarationInfo = new MethodDeclarationInfo(retType, ps,
                                                                              StringPool.TryAdd(MethodDeclarationInfo.GetDescriptor(retType, ps)));
            int index = MethodPool.Add(new MethodConstantInfo(
                                           classType.ConstantPoolIndex,
                                           StringPool.TryAdd(name),
                                           StringPool.TryAdd(declarationInfo.GetDescriptor()),
                                           flag.Flag));
            Method method = classType.AddMethod(name, declarationInfo, flag, index);

            Methods.Add(method);
            return(method);
        }
Beispiel #24
0
        /// <summary>
        /// 加载模块
        /// </summary>
        /// <param name="binaryModule"></param>
        /// <param name="isDependency">是执行模块还是依赖模块</param>
        /// <returns></returns>
        public static VMModule AddModule(BinaryModule binaryModule, bool isDependency)
        {
            if (!isDependency)
            {
                LoadWatch.Start();
            }

            VMModule module = new VMModule()
            {
                StringPoolLink = new List <uint>(),
                Classes        = new Dictionary <uint, VMClass>(),
                ClassPool      = binaryModule.ClassPool,
                ClassPoolLink  = new List <VMClass>(),
                FieldPool      = binaryModule.FieldPool,
                FieldPoolLink  = new List <VMField>(),
                MethodPool     = binaryModule.MethodPool,
                MethodPoolLink = new List <VMMethod>()
            };
            HashSet <int> externalModuleNameIndexes = new HashSet <int>();

            // 字符串常量
            foreach (string stringConstant in binaryModule.StringPool)
            {
                // 建立映射
                module.StringPoolLink.Add(MethodArea.Singleton.AddConstantString(stringConstant));
            }
            Modules.Add(module.StringPoolLink[binaryModule.ModuleNameIndex - 1], module);

            // 类
            foreach (ClassConstantInfo classInfo in module.ClassPool)
            {
                int moduleNameIndex = classInfo.Module;
                if (moduleNameIndex != binaryModule.ModuleNameIndex)
                {
                    // 外部域
                    externalModuleNameIndexes.Add(moduleNameIndex);
                    // 占位
                    module.ClassPoolLink.Add(null);
                }
                else
                {
                    VMClass vmClass = new VMClass()
                    {
                        Parent          = module,
                        Methods         = new Dictionary <uint, List <VMMethod> >(),
                        StaticFields    = new List <VMField>(),
                        StaticFieldSize = HeapData.MiscDataSize,    // 头部信息
                        Fields          = new List <VMField>(),
                        FieldSize       = HeapData.MiscDataSize     // 头部信息
                    };
                    module.Classes.Add(module.StringPoolLink[classInfo.Name - 1], vmClass);
                    module.ClassPoolLink.Add(vmClass);
                }
            }

            // Field
            AccessFlag accessFlag = new AccessFlag();

            foreach (FieldConstantInfo fieldInfo in module.FieldPool)
            {
                int moduleNameIndex = module.ClassPool[fieldInfo.Class - 1].Module;
                if (moduleNameIndex != binaryModule.ModuleNameIndex)
                {
                    // 外部域
                    externalModuleNameIndexes.Add(moduleNameIndex);
                    // 占位
                    module.FieldPoolLink.Add(null);
                }
                else
                {
                    module.Classes.TryGetValue(module.StringPoolLink[module.ClassPool[fieldInfo.Class - 1].Name - 1],
                                               out VMClass vmClass);
                    // 分配方法区空间并且链接地址
                    accessFlag.Flag = fieldInfo.Flag;
                    VariableType fieldType = VariableType.GetType(binaryModule.StringPool[fieldInfo.Descriptor - 1]);
                    VMField      vmField;
                    if (accessFlag.IsStatic)
                    {
                        vmField = new VMField(fieldInfo.Flag, fieldType, fieldInfo.Class, vmClass.StaticFieldSize);
                        module.FieldPoolLink.Add(vmField);
                        vmClass.StaticFields.Add(vmField);
                        vmClass.StaticFieldSize += fieldType.Size;
                    }
                    else
                    {
                        vmField = new VMField(fieldInfo.Flag, fieldType, fieldInfo.Class, vmClass.FieldSize);
                        module.FieldPoolLink.Add(vmField);
                        vmClass.Fields.Add(vmField);
                        vmClass.FieldSize += fieldType.Size;
                    }
                }
            }

            // 完成静态空间分配
            foreach (var vmClass in module.ClassPoolLink)
            {
                if (vmClass != null)
                {
                    vmClass.StaticFieldAddress = StaticArea.Singleton.MallocClassStaticArea(vmClass);
                    Classes.Add(vmClass.StaticFieldAddress, vmClass);
                }
            }

            // Method
            foreach ((MethodConstantInfo methodInfo, BinaryMethod binaryMethod) in module.MethodPool.Zip(binaryModule.Methods))
            {
                int moduleNameIndex = module.ClassPool[methodInfo.Class - 1].Module;
                if (moduleNameIndex != binaryModule.ModuleNameIndex)
                {
                    // 外部方法
                    externalModuleNameIndexes.Add(moduleNameIndex);
                    // 占位
                    module.MethodPoolLink.Add(null);
                }
                else
                {
                    module.Classes.TryGetValue(module.StringPoolLink[module.ClassPool[methodInfo.Class - 1].Name - 1],
                                               out VMClass vmClass);

                    // 构造VMMethod
                    VMMethod vmMethod = new VMMethod()
                    {
                        Parent = vmClass,
                        Flag   = new AccessFlag()
                        {
                            Flag = methodInfo.Flag
                        },
                        DescriptorAddress      = module.StringPoolLink[methodInfo.Descriptor - 1],
                        LocalDescriptorAddress = binaryMethod.LocalDescriptorIndex.Select(i => module.StringPoolLink[i - 1]).ToList(),
                        CodeBlock = MethodArea.Singleton.Malloc(binaryMethod.Instructions)
                    };

                    Methods.Add(vmMethod.CodeAddress, vmMethod);

                    // 将VMMethod添加到Class中
                    uint methodNameAddr = module.StringPoolLink[methodInfo.Name - 1];
                    if (vmClass.Methods.TryGetValue(methodNameAddr, out List <VMMethod> methodGroup))
                    {
                        methodGroup.Add(vmMethod);
                    }
                    else
                    {
                        vmClass.Methods.Add(methodNameAddr, new List <VMMethod>()
                        {
                            vmMethod
                        });
                    }

                    // 建立Link
                    module.MethodPoolLink.Add(vmMethod);
                }
            }

            if (!isDependency)
            {
                DependencyLoadWatch.Start();
            }

            // 导入外部模块
            foreach (int externalModuleNameIndex in externalModuleNameIndexes)
            {
                if (!Modules.ContainsKey(module.StringPoolLink[externalModuleNameIndex - 1]))
                {
                    // 导入未导入的模块,图的广度优先遍历
                    AddModule(Program.LoadModule(binaryModule.StringPool[externalModuleNameIndex - 1]), true);
                }
            }

            if (!isDependency)
            {
                DependencyLoadWatch.Stop();
            }

            // 链接外部符号
            ExternalSymbolResolution(module);

            if (!isDependency)
            {
                LoadWatch.Stop();
            }

            return(module);
        }
Beispiel #25
0
        protected Topic Update(Topic topic, Boolean updateType)
        {
            if (topic == null)
            {
                throw new ArgumentNullException("topic");
            }
            this.logger.WriteFormat("Update called on TopicService, Id: {0}", topic.Id);
            // Let's get the topic from the data-storage!
            Topic oldTopic = this.Read(topic.Id);

            if (oldTopic == null)
            {
                this.logger.WriteFormat("Update topic failed, no topic with the given id was found, Id: {0}", topic.Id);
                throw new ArgumentException("topic does not exist");
            }
            Topic originalTopic = oldTopic.Clone() as Topic;

            // Author with "update" access or moderator?
            AccessFlag flag = this.permService.GetAccessFlag(this.userProvider.CurrentUser, oldTopic.Forum);

            if ((flag & AccessFlag.Update) != AccessFlag.Update)
            {
                this.logger.WriteFormat("User does not have permissions to update a topic, id: {1}, subject: {0}", topic.Subject, topic.Id);
                throw new PermissionException("topic, update");
            }

            Boolean changed = false;

            if (updateType && ((flag & AccessFlag.Priority) != AccessFlag.Priority))
            {
                this.logger.WriteFormat("User does not have permissions to change type on a topic, id: {1}, subject: {0}", topic.Subject, topic.Id);
                throw new PermissionException("topic, update");
            }
            else
            {
                oldTopic.Type = topic.Type;
                changed       = true;
            }
            if (oldTopic.Subject != topic.Subject)
            {
                oldTopic.Subject = topic.Subject;
                changed          = true;
            }
            if (oldTopic.Message != topic.Message)
            {
                oldTopic.Message = topic.Message;
                changed          = true;
            }
            if (oldTopic.CustomProperties != topic.CustomProperties)
            {
                oldTopic.CustomProperties = topic.CustomProperties;
                changed = true;
            }

            if (changed)
            {
                oldTopic.Editor   = this.userProvider.CurrentUser;
                oldTopic.EditorId = this.userProvider.CurrentUser.Id;
                oldTopic.Changed  = DateTime.UtcNow;
                oldTopic          = this.topicRepo.Update(oldTopic);
                this.logger.WriteFormat("Topic updated in TopicService, Id: {0}", oldTopic.Id);
                this.eventPublisher.Publish <TopicUpdated>(new TopicUpdated(originalTopic)
                {
                    UpdatedTopic = oldTopic
                });
                this.logger.WriteFormat("Update events in TopicService fired, Id: {0}", oldTopic.Id);
            }
            return(oldTopic);
        }
Beispiel #26
0
 public DeclarationStmt(AccessFlag flag, TypeExpr type, string id)
 {
     AccessFlag = flag;
     Type       = type;
     Id         = id;
 }
Beispiel #27
0
        public string AccessFlagsToString(AccessFlag flag)
        {
            var access = new List <string>();

            if ((flag & AccessFlag.ACC_PUBLIC) != 0)
            {
                access.Add("public");
            }

            if ((flag & AccessFlag.ACC_PRIVATE) != 0)
            {
                access.Add("private");
            }

            if ((flag & AccessFlag.ACC_PROTECTED) != 0)
            {
                access.Add("protected");
            }

            if ((flag & AccessFlag.ACC_STATIC) != 0)
            {
                access.Add("static");
            }

            if ((flag & AccessFlag.ACC_FINAL) != 0)
            {
                access.Add("final");
            }

            if ((flag & AccessFlag.ACC_SYNCHRONIZED) != 0)
            {
                access.Add("synchronized");
            }

            if ((flag & AccessFlag.ACC_VOLATILE) != 0)
            {
                access.Add("volatile");
            }

            if ((flag & AccessFlag.ACC_BRIDGE) != 0)
            {
                access.Add("bridge");
            }

            if ((flag & AccessFlag.ACC_TRANSIENT) != 0)
            {
                access.Add("transient");
            }

            if ((flag & AccessFlag.ACC_VARARGS) != 0)
            {
                access.Add("varargs");
            }

            if ((flag & AccessFlag.ACC_NATIVE) != 0)
            {
                access.Add("native");
            }

            if ((flag & AccessFlag.ACC_INTERFACE) != 0)
            {
                access.Add("interface");
            }
            else if ((flag & AccessFlag.ACC_ABSTRACT) != 0)
            {
                access.Add("abstract");
            }

            if ((flag & AccessFlag.ACC_STRICT) != 0)
            {
                access.Add("strictfp");
            }

            if ((flag & AccessFlag.ACC_SYNTHETIC) != 0)
            {
                access.Add("synthetic");
            }

            if ((flag & AccessFlag.ACC_ANNOTATION) != 0)
            {
                access.Add("annotation");
            }

            if ((flag & AccessFlag.ACC_ENUM) != 0)
            {
                access.Add("enum");
            }

            if ((flag & AccessFlag.ACC_CONSTRUCTOR) != 0)
            {
                access.Add("constructor");
            }

            if ((flag & AccessFlag.ACC_DECLARED_SYNCHRONIZED) != 0)
            {
                access.Add("synchronized");
            }

            return(string.Join(" ", access));
        }
Beispiel #28
0
        /// <summary>
        /// API使用这个函数添加method
        /// </summary>
        /// <param name="name"></param>
        /// <param name="decl"></param>
        /// <param name="flag"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        internal Method AddMethod(string name, MethodDeclarationInfo decl, AccessFlag flag, int index)
        {
            if (Fields.ContainsKey(name))
            {
                throw new XiVMError($"Dupilcate Name {name} in class {Name}");
            }

            Method function = new Method(decl, this, flag, index);

            if (Methods.TryGetValue(name, out List <Method> value))
            {
                foreach (Method m in value)
                {
                    if (m.Declaration.Equivalent(decl))
                    {
                        // 重复定义
                        throw new XiVMError($"Duplicate definition for {Name}.{name}");
                    }
                }
                value.Add(function);
            }
            else
            {
                Methods.Add(name, new List <Method>()
                {
                    function
                });
            }

            // 添加参数
            int offset = 0;

            if (flag.IsStatic)
            {
                function.Params = new Variable[function.Declaration.Params.Count];
                for (int i = function.Declaration.Params.Count - 1; i >= 0; --i)
                {
                    offset            -= function.Declaration.Params[i].SlotSize;
                    function.Params[i] = new Variable(function.Declaration.Params[i])
                    {
                        Offset = offset
                    };
                }
            }
            else
            {
                function.Params = new Variable[function.Declaration.Params.Count + 1];
                for (int i = function.Declaration.Params.Count - 1; i >= 0; --i)
                {
                    offset -= function.Declaration.Params[i].SlotSize;
                    function.Params[i + 1] = new Variable(function.Declaration.Params[i])
                    {
                        Offset = offset
                    };
                }
                // 成员方法默认参数this
                offset            -= VariableType.AddressType.SlotSize;
                function.Params[0] = new Variable(ObjectType)
                {
                    Offset = offset
                };
            }

            return(function);
        }