Exemple #1
0
        private void ExportClassStatics(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            if (!cls.HaveNewStaticFields)
            {
                writer.Write((uint)0);
                return;
            }

            uint numStaticFields = 0;
            foreach (CppField field in cls.Fields)
                if (field.Field.Static && !field.Field.Literal)
                    numStaticFields++;

            writer.Write(numStaticFields);
            foreach (CppField field in cls.Fields)
            {
                if (field.Field.Static && !field.Field.Literal)
                {
                    writer.Write(fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(field.Type)));
                    writer.Write(fileBuilder.IndexString(field.Name));
                }
            }
        }
Exemple #2
0
        private void ExportEnum(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            CLRTypeSpecClass underlyingType = (CLRTypeSpecClass)cls.GetEnumUnderlyingType();

            bool foundUnderlyingType = false;
            uint numLiterals = 0;
            foreach (CppField fld in cls.Fields)
            {
                CLRFieldRow fieldRow = fld.Field;
                if (fieldRow.Literal)
                    numLiterals++;
            }

            Clarity.Rpa.HighTypeDef.EnumUnderlyingType underlyingTypeSymbol;
            string typeName = underlyingType.TypeDef.TypeName;
            switch (typeName)
            {
                case "Byte":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt8;
                    break;
                case "SByte":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int8;
                    break;
                case "Int16":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int16;
                    break;
                case "UInt16":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt16;
                    break;
                case "Int32":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int32;
                    break;
                case "UInt32":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt32;
                    break;
                case "Int64":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int64;
                    break;
                case "UInt64":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt64;
                    break;
                default:
                    throw new ArgumentException();
            }

            writer.Write((byte)underlyingTypeSymbol);
            writer.Write(numLiterals);
            foreach (CppField fld in cls.Fields)
            {
                CLRFieldRow fieldRow = fld.Field;
                if (fieldRow.Literal)
                {
                    writer.Write(fileBuilder.IndexString(fld.Name));
                    ArraySegment<byte> constantValue = fieldRow.AttachedConstants[0].Value;
                    writer.Write(constantValue.Array, constantValue.Offset, constantValue.Count);
                }
            }
        }
Exemple #3
0
        private void ExportClassDefinitions(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            if (cls.IsDelegate || cls.IsEnum)
                throw new ArgumentException();

            if (cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Interface)
                ExportGenericVariance(cls, writer);

            if (!cls.IsValueType && cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Class)
            {
                writer.Write(cls.TypeDef.IsSealed);
                writer.Write(cls.TypeDef.IsAbstract);
                if (cls.ParentTypeSpec == null)
                    writer.Write((uint)0);
                else
                    writer.Write(1 + fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(cls.ParentTypeSpec)));
            }

            writer.Write((uint)cls.ExplicitInterfaces.Count);
            foreach (CLRTypeSpec typeSpec in cls.ExplicitInterfaces)
                writer.Write(fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(typeSpec)));

            WriteVtableThunks(fileBuilder, writer, cls);

            if (cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Class)
            {
                uint numNonAbstractMethods = 0;

                foreach (CppMethod method in cls.Methods)
                {
                    if (!method.Abstract)
                        numNonAbstractMethods++;
                }

                writer.Write(numNonAbstractMethods);

                foreach (CppMethod method in cls.Methods)
                {
                    if (method.Abstract)
                        continue;

                    writer.Write(method.Static);
                    writer.Write(fileBuilder.IndexMethodSignatureTag(RpaTagFactory.CreateMethodSignature(method.MethodSignature)));
                    writer.Write(fileBuilder.IndexString(method.Name));
                    ExportMethodCode(fileBuilder, writer, cls, method);
                }

                uint numInstanceFields = 0;
                foreach (CppField field in cls.Fields)
                {
                    CLRFieldRow fieldDef = field.Field;
                    if (!fieldDef.Literal && !fieldDef.Static)
                        numInstanceFields++;
                }

                writer.Write(numInstanceFields);
                foreach (CppField field in cls.Fields)
                {
                    CLRFieldRow fieldDef = field.Field;
                    if (!fieldDef.Literal && !fieldDef.Static)
                    {
                        writer.Write(fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(field.Type)));
                        writer.Write(fileBuilder.IndexString(field.Name));
                    }
                }

                WriteInterfaceImplementations(fileBuilder, writer, cls);
            }
        }