Beispiel #1
0
        private void GenerateMetadata(CodePrinter prtDecl, CodePrinter prtImpl)
        {
            if (CurrType.GenMetadata)
            {
                string strMDataName = GenContext.GetMetaName(CurrType, true);
                string strDecl      = string.Format("il2cppTypeInfo {0}",
                                                    GenContext.GetMetaName(CurrType));
                prtDecl.AppendFormatLine("extern {0};", strDecl);

                string varName      = GenMetaStringLiteral(prtImpl, "Name", CurrType.Def.Name, strMDataName);
                string varNamespace = GenMetaStringLiteral(prtImpl, "Namespace", CurrType.Def.Namespace, strMDataName);

                prtImpl.AppendFormatLine("{0} =", strDecl);
                prtImpl.AppendLine("{");
                ++prtImpl.Indents;
                prtImpl.AppendFormatLine("(uint16_t*){0},", varName);
                prtImpl.AppendFormatLine("(uint16_t*){0},", varNamespace);
                --prtImpl.Indents;
                prtImpl.AppendLine("};");
            }

            foreach (var metX in CurrType.Methods)
            {
                if (metX.GenMetadata)
                {
                    string strMDataName = GenContext.GetMetaName(metX, true);
                    string strDecl      = string.Format("il2cppMethodInfo {0}",
                                                        GenContext.GetMetaName(metX));
                    prtDecl.AppendFormatLine("extern {0};", strDecl);

                    string varName = GenMetaStringLiteral(prtImpl, "Name", metX.Def.Name, strMDataName);

                    prtImpl.AppendFormatLine("{0} =", strDecl);
                    prtImpl.AppendLine("{");
                    ++prtImpl.Indents;
                    prtImpl.AppendFormatLine("(uint16_t*){0},", varName);
                    --prtImpl.Indents;
                    prtImpl.AppendLine("};");
                }
            }

            foreach (var fldX in CurrType.Fields)
            {
                if (fldX.GenMetadata)
                {
                    string strMDataName = GenContext.GetMetaName(fldX, true);
                    string strDecl      = string.Format("il2cppFieldInfo {0}",
                                                        GenContext.GetMetaName(fldX));
                    prtDecl.AppendFormatLine("extern {0};", strDecl);

                    string varName = GenMetaStringLiteral(prtImpl, "Name", fldX.Def.Name, strMDataName);

                    var  initValue    = fldX.Def.InitialValue;
                    bool hasInitValue = initValue != null && initValue.Length > 0;

                    string varInitData = null;
                    if (hasInitValue)
                    {
                        varInitData = GenMetaBytesLiteral(prtImpl, "InitData", initValue, strMDataName);
                    }

                    prtImpl.AppendFormatLine("{0} =", strDecl);
                    prtImpl.AppendLine("{");
                    ++prtImpl.Indents;
                    prtImpl.AppendFormatLine("(uint16_t*){0},", varName);
                    prtImpl.AppendLine("nullptr,");
                    prtImpl.AppendLine("nullptr,");
                    prtImpl.AppendLine("nullptr,");

                    prtImpl.AppendLine("{");
                    ++prtImpl.Indents;
                    if (hasInitValue)
                    {
                        prtImpl.AppendFormatLine("{0},\n{1}",
                                                 varInitData,
                                                 initValue.Length);
                    }
                    else
                    {
                        prtImpl.AppendLine("nullptr,\n0");
                    }
                    --prtImpl.Indents;
                    prtImpl.AppendLine("},");

                    prtImpl.AppendFormatLine("{0},",
                                             (uint)fldX.Def.Attributes);

                    if (fldX.IsInstance && !CurrType.IsEnumType)
                    {
                        prtImpl.AppendFormatLine("IL2CPP_OFFSETOF(&{0}::{1})",
                                                 GenContext.GetTypeName(CurrType),
                                                 GenContext.GetFieldName(fldX));
                    }
                    else
                    {
                        prtImpl.AppendLine("0");
                    }

                    --prtImpl.Indents;
                    prtImpl.AppendLine("};");
                }
            }
        }