Пример #1
0
        public static List <SpeciesDefinition> LoadSpecies(string xmlfile)
        {
            List <SpeciesDefinition> species = new List <SpeciesDefinition>();
            XPathDocument            doc     = new XPathDocument(xmlfile);
            XPathNavigator           nav     = doc.CreateNavigator();

            foreach (XPathNavigator n in nav.Select("/battle/speciess/species"))
            {
                string            name  = n.GetAttribute("name", "");
                string            descr = n.GetAttribute("description", "");
                SpeciesDefinition d     = new SpeciesDefinition();
                d.Name        = name;
                d.Description = descr;

                /*
                 * foreach (XPathNavigator n1 in n.Select("origin"))
                 * {
                 *      string oriname = n.GetAttribute("name", "");
                 *
                 *      //d.AddOrigin(n.GetAttribute("name",""));
                 * }
                 */
                foreach (XPathNavigator n2 in n.Select("provides"))
                {
                    d.Provide(n2.GetAttribute("value", ""));
                }
                foreach (XPathNavigator n3 in n.Select("requires"))
                {
                    d.Require(n3.GetAttribute("value", ""));
                }
                foreach (XPathNavigator n4 in n.Select("modifier"))
                {
                    string             modname     = n4.GetAttribute("name", "");
                    string             description = n4.GetAttribute("description", "");
                    string             val         = n4.GetAttribute("value", "");
                    string             target      = n4.GetAttribute("target", "");
                    string             type        = n4.GetAttribute("type", "");
                    ModifierDefinition mod         = new ModifierDefinition();
                    mod.Name        = modname;
                    mod.Description = description;
                    mod.ModValue    = double.Parse(val);
                    mod.EntityType  = BattleEntity.ParseEntity(type);
                    mod.TargetName  = target;
                    d.AddModifier(mod);
                }
                species.Add(d);
            }

            return(species);
        }
Пример #2
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            LanguageDefinition language = ((LanguageExecutionContext)context).Language;

            ModifierDefinition @static = language.StaticModifier;

            snippet.PrefixTitle($"{@static.Keyword} ");

            snippet.PrefixShortcut(@static.Shortcut);

            snippet.PrefixDescription($"{@static.Keyword} ");

            snippet.ReplacePlaceholders(LiteralIdentifiers.Modifiers, $"${LiteralIdentifiers.Modifiers}$ {@static.Keyword}");

            snippet.PrefixFileName(@static.Name);
        }
Пример #3
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            LanguageDefinition language = ((LanguageExecutionContext)context).Language;

            ModifierDefinition modifier = GetModifier(language);

            snippet.PrefixTitle($"{modifier.Keyword} ");

            snippet.PrefixShortcut(modifier.Shortcut);

            snippet.PrefixDescription($"{modifier.Keyword} ");

            if (ShouldRemoveLiteral)
            {
                snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.Modifiers, modifier.Keyword);
            }
            else
            {
                snippet.ReplacePlaceholders(LiteralIdentifiers.Modifiers, $"${LiteralIdentifiers.Modifiers}$ {modifier.Keyword}");
            }

            snippet.PrefixFileName(modifier.Name);
        }
Пример #4
0
        public override bool Visit(ModifierDefinition modifier)
        {
            //if (modifier.Parameters.Length() > 0)
            //{
            //    throw new System.Exception("modifiers with parameters not implemented");
            //}
            var modifierInParams = TransUtils.GetDefaultInParams();

            foreach (var parameter in modifier.Parameters.Parameters)
            {
                string name = null;
                name = TransUtils.GetCanonicalLocalVariableName(parameter, context);
                BoogieType type = TransUtils.GetBoogieTypeFromSolidityTypeName(parameter.TypeName);
                modifierInParams.Add(new BoogieFormalParam(new BoogieTypedIdent(name, type)));
            }

            Block            body     = modifier.Body;
            bool             hasPre   = false;
            bool             hasPost  = false;
            List <Statement> postlude = new List <Statement>();

            // this list does not include locals introduced during translation
            List <BoogieLocalVariable> localVarsDeclared = new List <BoogieLocalVariable>();

            bool translatingPre = true;

            foreach (Statement statement in body.Statements)
            {
                if (statement is VariableDeclarationStatement varDecls)
                {
                    foreach (VariableDeclaration varDecl in varDecls.Declarations)
                    {
                        string     name = TransUtils.GetCanonicalLocalVariableName(varDecl, context);
                        BoogieType type = TransUtils.GetBoogieTypeFromSolidityTypeName(varDecl.TypeName);
                        // Issue a warning for intXX variables in case /useModularArithemtic option is used:
                        if (context.TranslateFlags.UseModularArithmetic && varDecl.TypeDescriptions.IsInt())
                        {
                            Console.WriteLine($"Warning: signed integer arithmetic is not handled with /useModularArithmetic option");
                        }
                        var boogieVariable = new BoogieLocalVariable(new BoogieTypedIdent(name, type));
                        if (translatingPre)
                        {
                            localVarsDeclared.Add(boogieVariable); // don't add locals after placeholder
                        }
                    }

                    // throw new System.Exception("locals within modifiers not supported");
                }
                if (statement is PlaceholderStatement)
                {
                    translatingPre = false;
                    // only capture those locals declared in the prefix, these are visible to postlude
                    context.AddPreludeLocalsToModifier(modifier.Name, localVarsDeclared);

                    continue;
                }
                if (translatingPre)
                {
                    hasPre = true;
                }
                else
                {
                    hasPost = true;
                }
            }

            var attributes = new List <BoogieAttribute>();

            attributes.Add(new BoogieAttribute("inline", 1));

            if (hasPre)
            {
                List <BoogieVariable> inParams  = new List <BoogieVariable>(modifierInParams);
                List <BoogieVariable> outParams = new List <BoogieVariable>();
                outParams.AddRange(localVarsDeclared.Select(x => new BoogieFormalParam(new BoogieTypedIdent("__out_mod_" + x.Name, x.TypedIdent.Type))));
                BoogieProcedure preludeProc = new BoogieProcedure(modifier.Name + "_pre", inParams, outParams, attributes);
                context.AddModiferToPreProc(modifier.Name, preludeProc);

                BoogieImplementation preludeImpl = new BoogieImplementation(modifier.Name + "_pre",
                                                                            inParams, outParams, new List <BoogieVariable>(), new BoogieStmtList());
                context.AddModiferToPreImpl(modifier.Name, preludeImpl);
            }

            if (hasPost)
            {
                List <BoogieVariable> inParams = new List <BoogieVariable>(modifierInParams);
                inParams.AddRange(localVarsDeclared);
                List <BoogieVariable> outParams    = new List <BoogieVariable>();
                BoogieProcedure       postludeProc = new BoogieProcedure(modifier.Name + "_post", inParams, outParams, attributes);
                context.AddModiferToPostProc(modifier.Name, postludeProc);

                BoogieImplementation postludeImpl = new BoogieImplementation(modifier.Name + "_post",
                                                                             inParams, outParams, new List <BoogieVariable>(), new BoogieStmtList());
                context.AddModiferToPostImpl(modifier.Name, postludeImpl);
            }

            return(false);
        }
Пример #5
0
 public AccessModifierCommand(ModifierDefinition modifier)
 {
     Modifier = modifier;
 }
Пример #6
0
 public override bool Visit(ModifierDefinition node)
 {
     return(false);
 }
Пример #7
0
 public virtual bool Visit(ModifierDefinition node)
 {
     return(CommonVisit(node));
 }
Пример #8
0
 public virtual void EndVisit(ModifierDefinition node)
 {
     CommonEndVisit(node);
 }
Пример #9
0
        public override bool Visit(ModifierDefinition modifier)
        {
            //if (modifier.Parameters.Length() > 0)
            //{
            //    throw new System.Exception("modifiers with parameters not implemented");
            //}
            var modifierInParams = TransUtils.GetDefaultInParams();

            foreach (var parameter in modifier.Parameters.Parameters)
            {
                string name = null;
                name = TransUtils.GetCanonicalLocalVariableName(parameter);
                BoogieType type = TransUtils.GetBoogieTypeFromSolidityTypeName(parameter.TypeName);
                modifierInParams.Add(new BoogieFormalParam(new BoogieTypedIdent(name, type)));
            }

            Block            body     = modifier.Body;
            bool             hasPre   = false;
            bool             hasPost  = false;
            List <Statement> postlude = new List <Statement>();

            bool translatingPre = true;

            foreach (Statement statement in body.Statements)
            {
                if (statement is VariableDeclarationStatement)
                {
                    throw new System.Exception("locals within modifiers not supported");
                }
                if (statement is PlaceholderStatement)
                {
                    translatingPre = false;
                    continue;
                }
                if (translatingPre)
                {
                    hasPre = true;
                }
                else
                {
                    hasPost = true;
                }
            }

            if (hasPre)
            {
                List <BoogieVariable> inParams    = modifierInParams;
                List <BoogieVariable> outParams   = new List <BoogieVariable>();
                BoogieProcedure       preludeProc = new BoogieProcedure(modifier.Name + "_pre", inParams, outParams);
                context.AddModiferToPreProc(modifier.Name, preludeProc);

                BoogieImplementation preludeImpl = new BoogieImplementation(modifier.Name + "_pre",
                                                                            inParams, outParams, new List <BoogieVariable>(), new BoogieStmtList());
                context.AddModiferToPreImpl(modifier.Name, preludeImpl);
            }

            if (hasPost)
            {
                List <BoogieVariable> inParams     = modifierInParams;
                List <BoogieVariable> outParams    = new List <BoogieVariable>();
                BoogieProcedure       postludeProc = new BoogieProcedure(modifier.Name + "_post", inParams, outParams);
                context.AddModiferToPostProc(modifier.Name, postludeProc);

                BoogieImplementation postludeImpl = new BoogieImplementation(modifier.Name + "_post",
                                                                             inParams, outParams, new List <BoogieVariable>(), new BoogieStmtList());
                context.AddModiferToPostImpl(modifier.Name, postludeImpl);
            }

            return(false);
        }
Пример #10
0
        private NightfallManifestGroupModel CreateD2NightFall(DateTime date, bool createNew)
        {
            var nightfallDefinition = new NightfallManifestGroupModel();

            var mileStones = DestinyDailyApiManager.BungieApi.GetMilestones();

            if (mileStones.ErrorCode > 1)
            {
                return(null);
            }

            var activityManifest  = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, ActivityDefinition> >("DestinyActivityDefinition");
            var modifierManifest  = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, ModifierDefinition> >("DestinyActivityModifierDefinition");
            var objectiveManifest = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, ModifierDefinition> >("DestinyObjectiveDefinition");
            var vendorManifest    = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, VendorDefinition> >("DestinyVendorDefinition");

            foreach (var milestone in mileStones.Response)
            {
                var milestoneDetails = activityManifest[milestone.Value.availableQuests[0].activity.activityHash];
                if (milestoneDetails.displayProperties.name.Contains("Nightfall"))
                {
                    if (createNew)
                    {
                        var newEntry = new D2Nightfall()
                        {
                            missionid = milestoneDetails.hash,
                            day       = date.Day,
                            month     = date.Month,
                            year      = date.Year
                        };
                        db2.D2Nightfalls.Add(newEntry);
                        db2.SaveChanges();
                    }

                    nightfallDefinition.Activity = milestoneDetails;

                    foreach (var modifier in milestone.Value.availableQuests[0].activity.modifierHashes)
                    {
                        if (createNew)
                        {
                            var modifierEntry = new D2NightfallModifier()
                            {
                                modfierid = modifier,
                                day       = date.Day,
                                month     = date.Month,
                                year      = date.Year
                            };
                            db2.D2NightfallModifiers.Add(modifierEntry);
                            db2.SaveChanges();
                        }

                        var classifiedOverride = db2.ClassifiedOverrides.FirstOrDefault(c => c.id == modifier);
                        if (classifiedOverride != null)
                        {
                            var overrideManifest = new ModifierDefinition()
                            {
                                hash = modifier,
                                displayProperties = new DisplayProperties()
                                {
                                    name        = classifiedOverride.name,
                                    description = classifiedOverride.desc
                                }
                            };
                            nightfallDefinition.Modifiers.Add(overrideManifest);
                        }
                        else
                        {
                            nightfallDefinition.Modifiers.Add(modifierManifest[modifier]);
                        }
                    }

                    var tiers = milestone.Value.availableQuests[0].challenges.Select(c => c.activityHash).First();
                    foreach (var challenge in milestone.Value.availableQuests[0].challenges.Where(c => c.activityHash == tiers))
                    {
                        if (createNew)
                        {
                            var challengeEntry = new D2NightfallChallenge()
                            {
                                objectiveid = challenge.objectiveHash,
                                day         = date.Day,
                                month       = date.Month,
                                year        = date.Year
                            };
                            db2.D2NightfallChallenges.Add(challengeEntry);
                            db2.SaveChanges();
                        }

                        nightfallDefinition.Challenges.Add(objectiveManifest[challenge.objectiveHash]);
                    }

                    return(nightfallDefinition);
                }
            }
            return(null);
        }