Пример #1
0
        private void RegisterTypeCasts(XContainer root, OpcodeLookup lookup)
        {
            List <TempTypeCast>           info  = new List <TempTypeCast>();
            Dictionary <string, string[]> casts = new Dictionary <string, string[]>();

            // Load type casting information.
            foreach (XElement element in root.Element("typecasting").Elements("to"))
            {
                TempTypeCast temp = new TempTypeCast()
                {
                    Name     = XMLUtil.GetStringAttribute(element, "name"),
                    CastOnly = XMLUtil.GetBoolAttribute(element, "castOnly", false),
                    Types    = element.Elements("from").Select(e => e.Value)
                };
                info.Add(temp);
                casts[temp.Name] = temp.Types.ToArray();
            }

            bool itemsAdded = true;

            while (itemsAdded)
            {
                itemsAdded = false;
                // Iterate over all casts.
                foreach (var i in info)
                {
                    string[] newPredecessors = casts[i.Name];
                    // Iterate over all predecessors of the cast.
                    foreach (string type in casts[i.Name])
                    {
                        // Check if the predecessor supports casting.
                        if (casts.TryGetValue(type, out string[] predecessors))
Пример #2
0
 private void RegisterValueTypes(XContainer root, OpcodeLookup lookup)
 {
     foreach (XElement element in root.Element("valueTypes").Descendants("type"))
     {
         string name      = XMLUtil.GetStringAttribute(element, "name");
         var    opcode    = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
         int    size      = XMLUtil.GetNumericAttribute(element, "size");
         bool   quoted    = XMLUtil.GetBoolAttribute(element, "quoted", false);
         string tag       = XMLUtil.GetStringAttribute(element, "tag", null);
         var    valueType = new ScriptValueType(name, opcode, size, quoted, tag);
         lookup.RegisterValueType(valueType);
     }
 }
Пример #3
0
        private void RegisterGlobals(XContainer root, OpcodeLookup lookup)
        {
            foreach (XElement element in root.Element("globals").Descendants("global"))
            {
                string name = XMLUtil.GetStringAttribute(element, "name");
                if (name == "")
                {
                    continue;
                }

                ushort opcode     = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
                string returnType = XMLUtil.GetStringAttribute(element, "type");
                bool   isNull     = XMLUtil.GetBoolAttribute(element, "null", false);

                var info = new GlobalInfo(name, opcode, returnType, !isNull);
                lookup.RegisterGlobal(info);
            }
        }
Пример #4
0
        private void RegisterFunctions(XContainer root, OpcodeLookup lookup)
        {
            foreach (XElement element in root.Element("functions").Descendants("function"))
            {
                string name = XMLUtil.GetStringAttribute(element, "name");
                if (name == "")
                {
                    continue;
                }

                var      opcode         = (ushort)XMLUtil.GetNumericAttribute(element, "opcode");
                string   returnType     = XMLUtil.GetStringAttribute(element, "returnType", "void");
                var      flags          = (uint)XMLUtil.GetNumericAttribute(element, "flags", 0);
                string   group          = XMLUtil.GetStringAttribute(element, "group", null);
                bool     isNull         = XMLUtil.GetBoolAttribute(element, "null", false);
                string[] parameterTypes = element.Descendants("arg").Select(e => XMLUtil.GetStringAttribute(e, "type")).ToArray();

                var info = new FunctionInfo(name, opcode, returnType, flags, group, parameterTypes, !isNull);
                lookup.RegisterFunction(info);
            }
        }
Пример #5
0
        private void HandleTagReferenceElement(StructureLayout layout, XElement element, string name, int offset)
        {
            bool withGroup = XMLUtil.GetBoolAttribute(element, "withGroup");

            layout.AddTagReferenceField(name, offset, withGroup);
        }