Exemplo n.º 1
0
            public void Union(ModifyData other)
            {
                if (other == null)
                {
                    return;
                }

                DataTable.Union(other.DataTable);
                GameData.Union(other.GameData);
                foreach (var pair in other.Fields)
                {
                    if (Fields.ContainsKey(pair.Key))
                    {
                        Fields[pair.Key].Union(pair.Value);
                    }
                    else
                    {
                        Fields[pair.Key] = new Values(pair.Value);
                    }
                }
                foreach (var pair in other.Locals)
                {
                    if (Locals.ContainsKey(pair.Key))
                    {
                        Locals[pair.Key].Union(pair.Value);
                    }
                    else
                    {
                        Locals[pair.Key] = new Values(pair.Value);
                    }
                }
                Waits |= other.Waits;
            }
Exemplo n.º 2
0
            public bool Conflicts(ModifyData other)
            {
                if (Waits || other.Waits)
                {
                    return(true);
                }
                foreach (KeyValuePair <AFieldDecl, Values> pair in other.Fields)
                {
                    if (Fields.ContainsKey(pair.Key))
                    {
                        if (Fields[pair.Key].Conflicts(pair.Value))
                        {
                            return(true);
                        }
                    }
                }

                foreach (KeyValuePair <AALocalDecl, Values> pair in other.Locals)
                {
                    if (Locals.ContainsKey(pair.Key))
                    {
                        if (Locals[pair.Key].Conflicts(pair.Value))
                        {
                            return(true);
                        }
                    }
                }

                return(DataTable.Conflicts(other.DataTable) ||
                       GameData.Conflicts(other.GameData));
            }
Exemplo n.º 3
0
        private static void Update(AMethodDecl method, List <AMethodDecl> parsedMethods, ModifyData modifyData, Dictionary <AMethodDecl, List <AMethodDecl> > usedMethods, Dictionary <AMethodDecl, List <AFieldDecl> > readFields, Dictionary <AMethodDecl, List <AFieldDecl> > writtenFields)
        {
            if (parsedMethods.Contains(method))
            {
                return;
            }

            parsedMethods.Add(method);

            foreach (AFieldDecl fieldDecl in readFields[method])
            {
                modifyData.Add(fieldDecl, true, false);
            }
            foreach (AFieldDecl fieldDecl in writtenFields[method])
            {
                modifyData.Add(fieldDecl, false, true);
            }


            foreach (AMethodDecl usedMethod in usedMethods[method])
            {
                ModifyData data = GetModifyData(usedMethod);
                if (data == null)
                {
                    Update(usedMethod, parsedMethods, modifyData, usedMethods, readFields, writtenFields);
                }
                else
                {
                    modifyData.Union(data);
                }
            }
        }
Exemplo n.º 4
0
        private static ModifyData GetModifyData(AMethodDecl method)
        {
            if (methodData.ContainsKey(method))
            {
                return(methodData[method]);
            }

            if (Util.GetAncestor <AAProgram>(method) == null)
            {
                ModifyData modifyData = new ModifyData();
                string     name       = method.GetName().Text.ToLower();
                if (name.Contains("datatable"))
                {
                    modifyData.DataTable.Reads  |= name.Contains("get");
                    modifyData.DataTable.Writes |= name.Contains("set") || name.Contains("remove") || name.Contains("clear");
                }
                else
                {
                    modifyData.GameData.Writes |= name.Contains("set") || name.Contains("create");
                    modifyData.GameData.Reads   = true;
                }
                if (name == "wait")
                {
                    modifyData.Waits = true;
                }
                methodData[method] = modifyData;
                return(modifyData);
            }
            return(null);
        }
Exemplo n.º 5
0
        public int executeModify(ModifyData data, Transaction tx)
        {
            Plan p = new TablePlan(data.tableName(), tx);

            p = new SelectPlan(p, data.pred());
            UpdateScan us    = (UpdateScan)p.open();
            int        count = 0;

            while (us.next())
            {
                Constant val = data.newValue().evaluate(us); //返回此处的表达式的常量值
                us.setVal(data.targetField(), val);          //设置要更改字段处的值
                count++;
            }
            us.close();
            return(count);
        }
Exemplo n.º 6
0
        public static ModifyData GetLocalData(PExp expression, SharedData data)
        {
            if (expression == null)
            {
                return(new ModifyData());
            }

            AMethodDecl     method       = Util.GetAncestor <AMethodDecl>(expression);
            GetDependancies dependancies = new GetDependancies(data, method);

            expression.Apply(dependancies);
            ModifyData modifyData = new ModifyData();

            foreach (AFieldDecl fieldDecl in dependancies.ReadFields[method])
            {
                modifyData.Add(fieldDecl, true, false);
            }
            foreach (AFieldDecl fieldDecl in dependancies.WrittenFields[method])
            {
                modifyData.Add(fieldDecl, false, true);
            }
            foreach (AALocalDecl localDecl in dependancies.ReadLocals[method])
            {
                modifyData.Add(localDecl, true, false);
            }
            foreach (AALocalDecl localDecl in dependancies.WrittenLocals[method])
            {
                modifyData.Add(localDecl, false, true);
            }

            foreach (AMethodDecl usedMethod in dependancies.UsedMethods[method])
            {
                modifyData.Union(GetModifyData(usedMethod));
            }

            return(modifyData);
        }
Exemplo n.º 7
0
 public abstract List <TViewModel> Read(ModifyData data);
 public override List <CategoryViewModel> Read(ModifyData data)
 {
 }
Exemplo n.º 9
0
        public static void CalculateMethodModify(AAProgram ast, SharedData data, out int methodCount)
        {
            //Calculate what global variables all methods might modify.
            methodData.Clear();


            GetDependancies dependancies = new GetDependancies(data);

            ast.Apply(dependancies);
            methodCount = dependancies.UsedMethods.Count;

            while (dependancies.UsedMethods.Count > 0)
            {
                LinkedList <AMethodDecl> modified = new LinkedList <AMethodDecl>();
                foreach (var pair in dependancies.UsedMethods)
                {
                    AMethodDecl        method      = pair.Key;
                    List <AMethodDecl> usedMethods = pair.Value;


                    ModifyData modifyData = new ModifyData();
                    foreach (AFieldDecl fieldDecl in dependancies.ReadFields[method])
                    {
                        modifyData.Add(fieldDecl, true, false);
                    }
                    foreach (AFieldDecl fieldDecl in dependancies.WrittenFields[method])
                    {
                        modifyData.Add(fieldDecl, false, true);
                    }
                    bool skip = false;
                    foreach (AMethodDecl usedMethod in usedMethods)
                    {
                        ModifyData usedData = GetModifyData(usedMethod);
                        if (usedData == null)
                        {
                            skip = true;
                            break;
                        }
                        modifyData.Union(usedData);
                    }
                    if (skip)
                    {
                        continue;
                    }
                    methodData[method] = modifyData;
                    modified.AddLast(method);
                }
                foreach (AMethodDecl decl in modified)
                {
                    dependancies.UsedMethods.Remove(decl);
                    dependancies.ReadFields.Remove(decl);
                    dependancies.WrittenFields.Remove(decl);
                }
                if (modified.Count == 0)
                {//The rest is in a circular dependancy
                    foreach (var pair in dependancies.UsedMethods)
                    {
                        AMethodDecl method = pair.Key;

                        ModifyData modifyData = new ModifyData();

                        Update(method, new List <AMethodDecl>(), modifyData, dependancies.UsedMethods, dependancies.ReadFields, dependancies.WrittenFields);

                        methodData[method] = modifyData;
                        modified.AddLast(method);
                    }
                    dependancies.UsedMethods.Clear();
                }
            }
        }
Exemplo n.º 10
0
        public static ModifyData GetLocalData(PExp expression, SharedData data)
        {
            if (expression == null)
                return new ModifyData();

            AMethodDecl method = Util.GetAncestor<AMethodDecl>(expression);
            GetDependancies dependancies = new GetDependancies(data, method);
            expression.Apply(dependancies);
            ModifyData modifyData = new ModifyData();

            foreach (AFieldDecl fieldDecl in dependancies.ReadFields[method])
            {
                modifyData.Add(fieldDecl, true, false);
            }
            foreach (AFieldDecl fieldDecl in dependancies.WrittenFields[method])
            {
                modifyData.Add(fieldDecl, false, true);
            }
            foreach (AALocalDecl localDecl in dependancies.ReadLocals[method])
            {
                modifyData.Add(localDecl, true, false);
            }
            foreach (AALocalDecl localDecl in dependancies.WrittenLocals[method])
            {
                modifyData.Add(localDecl, false, true);
            }

            foreach (AMethodDecl usedMethod in dependancies.UsedMethods[method])
            {
                modifyData.Union(GetModifyData(usedMethod));
            }

            return modifyData;
        }
Exemplo n.º 11
0
            public void Union(ModifyData other)
            {
                if (other == null)
                    return;

                DataTable.Union(other.DataTable);
                GameData.Union(other.GameData);
                foreach (var pair in other.Fields)
                {
                    if (Fields.ContainsKey(pair.Key))
                        Fields[pair.Key].Union(pair.Value);
                    else
                        Fields[pair.Key] = new Values(pair.Value);
                }
                foreach (var pair in other.Locals)
                {
                    if (Locals.ContainsKey(pair.Key))
                        Locals[pair.Key].Union(pair.Value);
                    else
                        Locals[pair.Key] = new Values(pair.Value);
                }
                Waits |= other.Waits;
            }
Exemplo n.º 12
0
            public bool Conflicts(ModifyData other)
            {
                if (Waits || other.Waits)
                    return true;
                foreach (KeyValuePair<AFieldDecl, Values> pair in other.Fields)
                {
                    if (Fields.ContainsKey(pair.Key))
                    {
                        if (Fields[pair.Key].Conflicts(pair.Value))
                            return true;
                    }
                }

                foreach (KeyValuePair<AALocalDecl, Values> pair in other.Locals)
                {
                    if (Locals.ContainsKey(pair.Key))
                    {
                        if (Locals[pair.Key].Conflicts(pair.Value))
                            return true;
                    }
                }

                return DataTable.Conflicts(other.DataTable) ||
                       GameData.Conflicts(other.GameData);
            }
Exemplo n.º 13
0
        public static void CalculateMethodModify(AAProgram ast, SharedData data, out int methodCount)
        {
            //Calculate what global variables all methods might modify.
            methodData.Clear();

            GetDependancies dependancies = new GetDependancies(data);
            ast.Apply(dependancies);
            methodCount = dependancies.UsedMethods.Count;

            while (dependancies.UsedMethods.Count > 0)
            {
                LinkedList<AMethodDecl> modified = new LinkedList<AMethodDecl>();
                foreach (var pair in dependancies.UsedMethods)
                {
                    AMethodDecl method = pair.Key;
                    List<AMethodDecl> usedMethods = pair.Value;

                    ModifyData modifyData = new ModifyData();
                    foreach (AFieldDecl fieldDecl in dependancies.ReadFields[method])
                    {
                        modifyData.Add(fieldDecl, true, false);
                    }
                    foreach (AFieldDecl fieldDecl in dependancies.WrittenFields[method])
                    {
                        modifyData.Add(fieldDecl, false, true);
                    }
                    bool skip = false;
                    foreach (AMethodDecl usedMethod in usedMethods)
                    {
                        ModifyData usedData = GetModifyData(usedMethod);
                        if (usedData == null)
                        {
                            skip = true;
                            break;
                        }
                        modifyData.Union(usedData);
                    }
                    if (skip)
                        continue;
                    methodData[method] = modifyData;
                    modified.AddLast(method);
                }
                foreach (AMethodDecl decl in modified)
                {
                    dependancies.UsedMethods.Remove(decl);
                    dependancies.ReadFields.Remove(decl);
                    dependancies.WrittenFields.Remove(decl);
                }
                if (modified.Count == 0)
                {//The rest is in a circular dependancy
                    foreach (var pair in dependancies.UsedMethods)
                    {
                        AMethodDecl method = pair.Key;

                        ModifyData modifyData = new ModifyData();

                        Update(method, new List<AMethodDecl>(), modifyData, dependancies.UsedMethods, dependancies.ReadFields, dependancies.WrittenFields);

                        methodData[method] = modifyData;
                        modified.AddLast(method);
                    }
                    dependancies.UsedMethods.Clear();
                }
            }
        }
Exemplo n.º 14
0
        private static void Update(AMethodDecl method, List<AMethodDecl> parsedMethods, ModifyData modifyData, Dictionary<AMethodDecl, List<AMethodDecl>> usedMethods, Dictionary<AMethodDecl, List<AFieldDecl>> readFields, Dictionary<AMethodDecl, List<AFieldDecl>> writtenFields)
        {
            if (parsedMethods.Contains(method))
                return;

            parsedMethods.Add(method);

            foreach (AFieldDecl fieldDecl in readFields[method])
            {
                modifyData.Add(fieldDecl, true, false);
            }
            foreach (AFieldDecl fieldDecl in writtenFields[method])
            {
                modifyData.Add(fieldDecl, false, true);
            }

            foreach (AMethodDecl usedMethod in usedMethods[method])
            {
                ModifyData data = GetModifyData(usedMethod);
                if (data == null)
                {
                    Update(usedMethod, parsedMethods, modifyData, usedMethods, readFields, writtenFields);
                }
                else
                {
                    modifyData.Union(data);
                }
            }
        }
Exemplo n.º 15
0
        private static ModifyData GetModifyData(AMethodDecl method)
        {
            if (methodData.ContainsKey(method))
                return methodData[method];

            if (Util.GetAncestor<AAProgram>(method) == null)
            {
                ModifyData modifyData = new ModifyData();
                string name = method.GetName().Text.ToLower();
                if (name.Contains("datatable"))
                {
                    modifyData.DataTable.Reads |= name.Contains("get");
                    modifyData.DataTable.Writes |= name.Contains("set") || name.Contains("remove") || name.Contains("clear");
                }
                else
                {
                    modifyData.GameData.Writes |= name.Contains("set") || name.Contains("create");
                    modifyData.GameData.Reads = true;
                }
                if (name == "wait")
                    modifyData.Waits = true;
                methodData[method] = modifyData;
                return modifyData;
            }
            return null;
        }
 public override List <ViewModel> Read(ModifyData data)
 {
 }