Ejemplo n.º 1
0
        /// <summary>Pre-Adapt helper for save targets.</summary>
        /// <param name="values">The adaptation-relevant values.</param>
        /// <param name="entry">The relevant entry ID.</param>
        /// <param name="canPreExist">Whether the variable is allowed to already exist.</param>
        /// <param name="tagType">The required type.</param>
        /// <param name="required">Whether a save name *must* be specified by the user.</param>
        /// <param name="defaultName">The default name (or null if none).</param>
        public void PreAdaptSaveMode(CILAdaptationValues values, int entry, bool canPreExist, TagType tagType, bool required, string defaultName = null)
        {
            CommandEntry cent     = values.CommandAt(entry);
            string       saveName = cent.GetSaveNameNoParse(defaultName);

            if (saveName == null)
            {
                if (!required)
                {
                    return;
                }
                throw new ErrorInducedException($"Command '{Meta.Name}' requires a save name, but none was given.");
            }
            int preVarLoc = values.LocalVariableLocation(saveName, out TagReturnType preVarType);

            if (preVarLoc >= 0)
            {
                if (!canPreExist)
                {
                    throw new ErrorInducedException($"Already have a save target var (labeled '{TextStyle.SeparateVal(saveName)}')?!");
                }
                if (preVarType.Type != tagType)
                {
                    throw new ErrorInducedException($"Already have a save target var (labeled '{TextStyle.SeparateVal(saveName)}', with type "
                                                    + $"'{TextStyle.SeparateVal(preVarType.Type.TypeName)}') of wrong type (expected '{TextStyle.SeparateVal(tagType.TypeName)}').");
                }
                cent.SaveLoc = preVarLoc;
            }
            else
            {
                cent.SaveLoc = values.AddVariable(saveName, tagType);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Prepares to adapt a command entry to CIL.</summary>
        /// <param name="values">The adaptation-relevant values.</param>
        /// <param name="entry">The present entry ID.</param>
        public override void PreAdaptToCIL(CILAdaptationValues values, int entry)
        {
            CommandEntry cent = values.Entry.Entries[entry];

            if (cent.IsCallback)
            {
                values.PopVarSet();
                return;
            }
            string arg = cent.Arguments[0].ToString();

            if (arg == "next" || arg == "stop")
            {
                return;
            }
            values.PushVarSet();
            string sn = cent.GetSaveNameNoParse("while_index");

            if (values.LocalVariableLocation(sn) >= 0)
            {
                throw new ErrorInducedException("Already have a while_index var (labeled '" + sn + "')?!");
            }
            TagType type = cent.TagSystem.Types.Type_Integer;

            values.AddVariable(sn, type);
        }
Ejemplo n.º 3
0
        /// <summary>Prepares to adapt a command entry to CIL.</summary>
        /// <param name="values">The adaptation-relevant values.</param>
        /// <param name="entry">The present entry ID.</param>
        public override void PreAdaptToCIL(CILAdaptationValues values, int entry)
        {
            CommandEntry cent = values.Entry.Entries[entry];
            MapTag       mt   = MapTag.For(cent.Arguments[0].ToString());

            if (mt.Internal.Count == 0)
            {
                throw new ErrorInducedException("Empty map input to require!");
            }
            foreach (KeyValuePair <string, TemplateObject> pair in mt.Internal)
            {
                TagType tagType;
                if (pair.Value is TagTypeTag tag)
                {
                    tagType = tag.Internal;
                }
                else if (!cent.System.TagSystem.Types.RegisteredTypes.TryGetValue(pair.Value.ToString(), out tagType))
                {
                    throw new ErrorInducedException("Invalid local variable type: " + pair.Value.ToString() + "!");
                }
                int loc = values.LocalVariableLocation(pair.Key);
                if (loc >= 0)
                {
                    TagReturnType type = values.LocalVariableType(loc);
                    if (type.Type != tagType)
                    {
                        throw new ErrorInducedException("Required local variable '" + pair.Key + "' already exists, but is of type '"
                                                        + type.Type.TypeName + "', when '" + pair.Value.ToString() + "' was required!");
                    }
                }
                values.AddVariable(pair.Key, tagType);
            }
        }
Ejemplo n.º 4
0
        /// <summary>Prepares to adapt a command entry to CIL.</summary>
        /// <param name="values">The adaptation-relevant values.</param>
        /// <param name="entry">The relevant entry ID.</param>
        public override void PreAdaptToCIL(CILAdaptationValues values, int entry)
        {
            CommandEntry cent = values.Entry.Entries[entry];
            string       larg = cent.Arguments[0].ToString().ToLowerFast();

            if (values.LocalVariableLocation(larg) >= 0)
            {
                throw new ErrorInducedException("Duplicate local variable: " + larg + "!");
            }
            if (cent.Arguments[1].ToString().ToLowerFast() != "=")
            {
                throw new ErrorInducedException("Invalid input to var command: second argument must be '='.");
            }
            TagType t;

            if (cent.Arguments.Length >= 5)
            {
                if (cent.Arguments[3].ToString().ToLowerFast() != "as")
                {
                    throw new ErrorInducedException("Invalid input to var command: fourth argument must be 'as'.");
                }
                string tname = cent.Arguments[4].ToString();
                if (!cent.System.TagSystem.Types.RegisteredTypes.TryGetValue(tname, out t))
                {
                    throw new ErrorInducedException("Invalid local variable type: " + larg + "!");
                }
            }
            else
            {
                t = ArgumentCompiler.ReturnType(cent.Arguments[2], values).Type;
            }
            values.AddVariable(larg, t);
        }