/// <summary> /// API.h、COPNewForApp.h、ActivationForApp.hの生成 /// </summary> private void GenerateAPIHeaders(GeneratedCodes result, List <LayerStructure> layerStructures, List <string> baseClassNameList, string includeFilePath) { // API.h StringBuilder stringBuilderForAPI = new StringBuilder(); stringBuilderForAPI.AppendLine(@"#ifndef __RTCOP_GENERATED_API__"); stringBuilderForAPI.AppendLine(@"#define __RTCOP_GENERATED_API__"); stringBuilderForAPI.AppendLine(); stringBuilderForAPI.Append(@"#include """); stringBuilderForAPI.Append(includeFilePath); stringBuilderForAPI.AppendLine(@"COPNewForApp.h"""); stringBuilderForAPI.Append(@"#include """); stringBuilderForAPI.Append(includeFilePath); stringBuilderForAPI.AppendLine(@"ActivationForApp.h"""); stringBuilderForAPI.AppendLine(); stringBuilderForAPI.AppendLine(@"#endif // !__RTCOP_GENERATED_API__"); result.CodeDictionary[@"API.h"] = stringBuilderForAPI.ToString(); // COPNewForApp.h StringBuilder stringBuilderForNew = new StringBuilder(); stringBuilderForNew.AppendLine(@"#ifndef __RTCOP_GENERATED_COPNEWFORAPP__"); stringBuilderForNew.AppendLine(@"#define __RTCOP_GENERATED_COPNEWFORAPP__"); stringBuilderForNew.AppendLine(); stringBuilderForNew.AppendLine(@"#include ""RTCOP/COPNew.h"""); stringBuilderForNew.AppendLine(); foreach (string classname in baseClassNameList) { var nss = classname.Split(new string[] { "::" }, StringSplitOptions.None); string nscheck = ""; for (int i = 0; i < (nss.Length - 1); ++i) { if (nscheck == "") { nscheck = nss[i]; } else { nscheck += ("::" + nss[i]); } if (baseClassNameList.Contains(nscheck)) { stringBuilderForNew.Append(@"class "); } else { stringBuilderForNew.Append(@"namespace "); } stringBuilderForNew.Append(nss[i]); stringBuilderForNew.Append(@" { "); } stringBuilderForNew.Append(@"class "); stringBuilderForNew.Append(nss[nss.Length - 1]); stringBuilderForNew.Append(@";"); for (int i = 0; i < (nss.Length - 1); ++i) { stringBuilderForNew.Append(@" } "); } stringBuilderForNew.AppendLine(); } stringBuilderForNew.AppendLine(@"namespace RTCOP {"); stringBuilderForNew.AppendLine(@"namespace Generated {"); stringBuilderForNew.AppendLine(); stringBuilderForNew.AppendLine(@"template<class Base>"); stringBuilderForNew.AppendLine(@"inline const int GetBaseClassID() { return -1; }"); int classcount = 0; foreach (string classname in baseClassNameList) { stringBuilderForNew.AppendLine(@"template<>"); stringBuilderForNew.Append(@"inline const int GetBaseClassID<"); stringBuilderForNew.Append(classname); stringBuilderForNew.Append(@">() { return "); stringBuilderForNew.Append(classcount); stringBuilderForNew.AppendLine(@"; }"); ++classcount; } stringBuilderForNew.AppendLine(); stringBuilderForNew.AppendLine(@"} // namespace Generated {}"); stringBuilderForNew.AppendLine(); stringBuilderForNew.AppendLine(@"template<class Base, class... ArgTypes>"); stringBuilderForNew.AppendLine(@"inline Core::LayerdObject<Base>* copnew(ArgTypes... args)"); stringBuilderForNew.AppendLine(@"{"); stringBuilderForNew.Append("\t"); stringBuilderForNew.AppendLine(@"const int classId = Generated::GetBaseClassID<Base>();"); stringBuilderForNew.Append("\t"); stringBuilderForNew.AppendLine(@"return COPNew<Base>(classId, args...);"); stringBuilderForNew.AppendLine(@"}"); stringBuilderForNew.AppendLine(); stringBuilderForNew.AppendLine(@"} // namespace RTCOP {}"); stringBuilderForNew.AppendLine(@"#endif // !__RTCOP_GENERATED__COPNEW__"); result.CodeDictionary[@"COPNewForApp.h"] = stringBuilderForNew.ToString(); // ActivationForApp.h StringBuilder stringBuilderForActivation = new StringBuilder(); stringBuilderForActivation.AppendLine(@"#ifndef __RTCOP_GENERATED_ACTIVATIONFORAPP__"); stringBuilderForActivation.AppendLine(@"#define __RTCOP_GENERATED_ACTIVATIONFORAPP__"); stringBuilderForActivation.AppendLine(); stringBuilderForActivation.AppendLine(@"#include ""RTCOP/Activation.h"""); stringBuilderForActivation.AppendLine(); stringBuilderForActivation.AppendLine(@"namespace RTCOP {"); stringBuilderForActivation.AppendLine(@"namespace Generated {"); stringBuilderForActivation.AppendLine(); stringBuilderForActivation.AppendLine(@"enum class LayerID : int"); stringBuilderForActivation.AppendLine(@"{"); stringBuilderForActivation.Append("\t"); stringBuilderForActivation.AppendLine(@"baselayer = 0,"); int layercount = 1; foreach (LayerStructure ls in layerStructures) { stringBuilderForActivation.Append("\t"); stringBuilderForActivation.Append(ls.LayerName); stringBuilderForActivation.Append(@" = "); stringBuilderForActivation.Append(layercount); stringBuilderForActivation.AppendLine(@","); ++layercount; } stringBuilderForActivation.AppendLine(@"};"); stringBuilderForActivation.AppendLine(@"} // namespace Generated {}"); stringBuilderForActivation.AppendLine(); stringBuilderForActivation.AppendLine(@"inline void activate(Generated::LayerID layerid)"); stringBuilderForActivation.AppendLine(@"{"); stringBuilderForActivation.Append("\t"); stringBuilderForActivation.AppendLine(@"Activate((int)layerid);"); stringBuilderForActivation.AppendLine(@"}"); stringBuilderForActivation.AppendLine(); stringBuilderForActivation.AppendLine(@"inline void deactivate(Generated::LayerID layerid)"); stringBuilderForActivation.AppendLine(@"{"); stringBuilderForActivation.Append("\t"); stringBuilderForActivation.AppendLine(@"Deactivate((int)layerid);"); stringBuilderForActivation.AppendLine(@"}"); stringBuilderForActivation.AppendLine(); stringBuilderForActivation.AppendLine(@"} // namespace RTCOP {}"); stringBuilderForActivation.AppendLine(@"#endif // !__RTCOP_GENERATED_ACTIVATION__"); result.CodeDictionary[@"ActivationForApp.h"] = stringBuilderForActivation.ToString(); }
/// <summary> /// 環境依存コード /// </summary> private void GenerateDependentCode(GeneratedCodes result, LayerStructure baseLayerStructure, List <LayerStructure> layerStructures, List <string> baseClassNameList, List <List <LayerdMethodDefinition> > baseMethodLists) { // ヘッダファイル StringBuilder stringBuilderForHeader = new StringBuilder(); stringBuilderForHeader.AppendLine(@"#ifndef __RTCOP_GENERATED_DEPENDENTCODE__"); stringBuilderForHeader.AppendLine(@"#define __RTCOP_GENERATED_DEPENDENTCODE__"); stringBuilderForHeader.AppendLine(); int classCount = 0; foreach (var baseClassName in baseClassNameList) { var nss = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None); string nscheck = ""; for (int i = 0; i < (nss.Length - 1); ++i) { if (nscheck == "") { nscheck = nss[i]; } else { nscheck += ("::" + nss[i]); } if (baseClassNameList.Contains(nscheck)) { stringBuilderForHeader.Append(@"class "); } else { stringBuilderForHeader.Append(@"namespace "); } stringBuilderForHeader.Append(nss[i]); stringBuilderForHeader.Append(@" { "); } stringBuilderForHeader.Append(@"class "); stringBuilderForHeader.Append(nss[nss.Length - 1]); stringBuilderForHeader.Append(@";"); for (int i = 0; i < (nss.Length - 1); ++i) { stringBuilderForHeader.Append(@" } "); } stringBuilderForHeader.AppendLine(); foreach (var layerStructure in layerStructures) { if (layerStructure._FindedPartialClasses[classCount] != null) { stringBuilderForHeader.Append(@"namespace "); stringBuilderForHeader.Append(layerStructure.LayerName); stringBuilderForHeader.Append(@" { "); string cname = baseClassName; if (baseClassName.StartsWith("baselayer::")) { cname = baseClassName.Substring("baselayer::".Length); } var nss2 = cname.Split(new string[] { "::" }, StringSplitOptions.None); nscheck = ""; string nscheck2 = "baselayer"; for (int i = 0; i < (nss2.Length - 1); ++i) { if (nscheck == "") { nscheck = nss2[i]; } else { nscheck += ("::" + nss2[i]); } nscheck2 += ("::" + nss2[i]); if (baseClassNameList.Contains(nscheck) || baseClassNameList.Contains(nscheck2)) { stringBuilderForHeader.Append(@"class "); } else { stringBuilderForHeader.Append(@"namespace "); } stringBuilderForHeader.Append(nss2[i]); stringBuilderForHeader.Append(@" { "); } stringBuilderForHeader.Append(@"class "); stringBuilderForHeader.Append(nss2[nss2.Length - 1]); stringBuilderForHeader.Append(@";"); for (int i = 0; i < nss2.Length; ++i) { stringBuilderForHeader.Append(@" } "); } stringBuilderForHeader.AppendLine(); } } ++classCount; } stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"namespace RTCOP {"); stringBuilderForHeader.AppendLine(@"namespace Generated {"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"class BaseLayer;"); foreach (var layerStructure in layerStructures) { stringBuilderForHeader.Append(@"class "); stringBuilderForHeader.Append(layerStructure.LayerName); stringBuilderForHeader.AppendLine(@";"); } stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"namespace DependentCode {"); stringBuilderForHeader.AppendLine(); foreach (var layerStructure in layerStructures) { classCount = 0; foreach (var baseClassName in baseClassNameList) { if (layerStructure._FindedPartialClasses[classCount] != null) { string cname = baseClassName; if (baseClassName.StartsWith("baselayer::")) { cname = baseClassName.Substring("baselayer::".Length); } stringBuilderForHeader.Append(@"volatile void* GetLayerdObjectFinalizer(::"); stringBuilderForHeader.Append(layerStructure.LayerName); stringBuilderForHeader.Append(@"::"); stringBuilderForHeader.Append(cname); stringBuilderForHeader.AppendLine(@"* obj);"); } ++classCount; } } stringBuilderForHeader.AppendLine(); classCount = 0; foreach (var baseClassName in baseClassNameList) { var nss = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None); for (int i = 0; i < nss.Length; ++i) { stringBuilderForHeader.Append(@"namespace "); stringBuilderForHeader.Append(nss[i]); stringBuilderForHeader.Append(@" { "); } stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"volatile void** GetVirtualFunctionTable(BaseLayer* layer);"); foreach (var layer in layerStructures) { if (layer._FindedPartialClasses[classCount] != null) { stringBuilderForHeader.Append(@"volatile void** GetVirtualFunctionTable("); stringBuilderForHeader.Append(layer.LayerName); stringBuilderForHeader.AppendLine(@"* layer);"); } } stringBuilderForHeader.AppendLine(); var baseMethodList = baseMethodLists[classCount]; foreach (var baseMethod in baseMethodList) { if (baseMethod != null) { stringBuilderForHeader.Append(baseMethod.ReturnType); stringBuilderForHeader.Append(@" ExecuteProceed_"); stringBuilderForHeader.Append(baseMethod.Name); stringBuilderForHeader.Append(@"(void* layerdObject, volatile void* proceed"); foreach (var param in baseMethod.Parameters) { stringBuilderForHeader.Append(@", "); stringBuilderForHeader.Append(param); } stringBuilderForHeader.AppendLine(@");"); } } stringBuilderForHeader.AppendLine(); for (int i = 0; i < nss.Length; ++i) { stringBuilderForHeader.Append(@"}"); } stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(); ++classCount; } stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"} // namespace DependentCode {}"); stringBuilderForHeader.AppendLine(@"} // namespace Generated {}"); stringBuilderForHeader.AppendLine(@"} // namespace RTCOP {}"); stringBuilderForHeader.AppendLine(@"#endif // !__RTCOP_GENERATED_DEPENDENTCODE__"); result.CodeDictionary[@"DependentCode.h"] = stringBuilderForHeader.ToString(); // ソースコード if (Target == DevelopmentTarget.WindowsX64) { if (Environment == DevelopmentEnvironment.VisualStudio) { GenerateDependentCodeForWindowsX64VisualStudio(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } else { GenerateDependentCodeForWindowsX64MinGW(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } } else if (Target == DevelopmentTarget.WindowsX86) { if (Environment == DevelopmentEnvironment.VisualStudio) { GenerateDependentCodeForWindowsX86VisualStudio(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } else { GenerateDependentCodeForWindowsX86MinGW(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } } else if (Target == DevelopmentTarget.LinuxX64) { if (Environment == DevelopmentEnvironment.GCC) { GenerateDependentCodeForLinuxX64(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } else { throw new Exception("ターゲットと開発環境の組み合わせが不正です"); } } else if (Target == DevelopmentTarget.LinuxX86) { if (Environment == DevelopmentEnvironment.GCC) { GenerateDependentCodeForLinuxX86(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } else { throw new Exception("ターゲットと開発環境の組み合わせが不正です"); } } else if (Target == DevelopmentTarget.LinuxARM) { if (Environment == DevelopmentEnvironment.GCC) { GenerateDependentCodeForLinuxARM(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } else { throw new Exception("ターゲットと開発環境の組み合わせが不正です"); } } else if (Target == DevelopmentTarget.LinuxARM64) { if (Environment == DevelopmentEnvironment.GCC) { GenerateDependentCodeForLinuxARM64(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } else { throw new Exception("ターゲットと開発環境の組み合わせが不正です"); } } else if (Target == DevelopmentTarget.macOSX64) { if (Environment == DevelopmentEnvironment.GCC || Environment == DevelopmentEnvironment.Clang) { GenerateDependentCodeForMacOSX64(result, baseLayerStructure, layerStructures, baseClassNameList, baseMethodLists); } else { throw new Exception("ターゲットと開発環境の組み合わせが不正です"); } } }
/// <summary> /// ベースレイヤ /// </summary> private void GenerateBaseLayer(GeneratedCodes result, LayerStructure baseLayerStructure, List <LayerStructure> layerStructures, List <string> baseClassNameList, List <List <LayerdMethodDefinition> > baseMethodLists, List <int> superClassIDs, string includeFilePath) { // 共通処理 var headerIncludeFiles = from item in baseLayerStructure.HeaderFileItems where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include) select(PreprocessDirective) item; var headerImportFiles = from item in baseLayerStructure.HeaderFileItems where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.ImportLayerHeader) select(PreprocessDirective) item; var srcIncludeFiles = from item in baseLayerStructure.SourceFileItems where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include) select(PreprocessDirective) item; var srcImportFiles = from item in baseLayerStructure.SourceFileItems where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.ImportLayerHeader) select(PreprocessDirective) item; // ヘッダファイル StringBuilder stringBuilderForHeader = new StringBuilder(); stringBuilderForHeader.AppendLine(@"#ifndef __RTCOP_GENERATED_BASELAYER__"); stringBuilderForHeader.AppendLine(@"#define __RTCOP_GENERATED_BASELAYER__"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"#include ""RTCOP/Core/Layer.h"""); stringBuilderForHeader.AppendLine(@"#include ""RTCOP/Core/LayerdObject.h"""); stringBuilderForHeader.AppendLine(); var headerIncludeFilesArray = headerIncludeFiles.ToArray(); foreach (var incFile in headerIncludeFilesArray) { stringBuilderForHeader.AppendLine(incFile.ToString()); baseLayerStructure.HeaderFileItems.Remove(incFile); } stringBuilderForHeader.AppendLine(); var headerImportFilesArray = headerImportFiles.ToArray(); List <string> layerNamesH = new List <string>(); foreach (var impFile in headerImportFilesArray) { string filePath = ""; foreach (var incpath in IncludePaths) { string path = incpath + impFile.Param1; string fullPath = Path.GetFullPath(path); if (File.Exists(fullPath)) { filePath = fullPath; break; } } foreach (var ls in layerStructures) { if (ls.LayerName == "baselayer" || layerNamesH.Contains(ls.LayerName)) { continue; } if (ls.ImportedLhInfomation.Exists((obj) => obj.FilePath == filePath)) { layerNamesH.Add(ls.LayerName); } } baseLayerStructure.HeaderFileItems.Remove(impFile); } stringBuilderForHeader.AppendLine(@"#ifdef __RTCOP_GENERAED_CODE_FLAG__"); foreach (string lname in layerNamesH) { stringBuilderForHeader.Append(@"#include """); stringBuilderForHeader.Append(lname); stringBuilderForHeader.AppendLine(@".h"""); } stringBuilderForHeader.AppendLine(@"#else"); foreach (string lname in layerNamesH) { stringBuilderForHeader.Append(@"#include """); stringBuilderForHeader.Append(includeFilePath); stringBuilderForHeader.Append(lname); stringBuilderForHeader.AppendLine(@".h"""); } stringBuilderForHeader.AppendLine(@"#endif"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"namespace RTCOP {"); stringBuilderForHeader.AppendLine(@"namespace Generated {"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"class BaseLayer : public Core::Layer"); stringBuilderForHeader.AppendLine(@"{"); stringBuilderForHeader.AppendLine(@"public:"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"static BaseLayer* GetInstance();"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"explicit BaseLayer(const int id, const char* const name, int numOfBaseClasses, int* numOfBaseMethods);"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual ~BaseLayer() override;"); stringBuilderForHeader.AppendLine(@"protected:"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual void* InitializeLayerdObject(void* obj, int classID) override;"); stringBuilderForHeader.AppendLine(@"};"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"} // namespace Generated {}"); stringBuilderForHeader.AppendLine(@"} // namespace RTCOP {}"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(ItemsToStringForBaseLayer(baseLayerStructure.HeaderFileItems, baseClassNameList, baseMethodLists, superClassIDs, 0, "")); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"#endif //!__RTCOP_GENERATED_JAPANESELAYER__"); result.CodeDictionary[@"BaseLayer.h"] = stringBuilderForHeader.ToString(); // ソースファイル StringBuilder stringBuilderForSource = new StringBuilder(); stringBuilderForSource.AppendLine(@"#include ""COPNewForApp.h"""); stringBuilderForSource.AppendLine(@"#include ""ActivationForApp.h"""); stringBuilderForSource.AppendLine(@"#include ""Layer_Private.h"""); stringBuilderForSource.AppendLine(@"#include ""LayerdObject_Private.h"""); stringBuilderForSource.AppendLine(@"#include ""DependentCode.h"""); stringBuilderForSource.AppendLine(@"#include ""RTCOP/Framework.h"""); stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/RTCOPManager.h"""); stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/PartialClassMembers.h"""); stringBuilderForSource.AppendLine(@"#include <cstring>"); stringBuilderForSource.AppendLine(); var srcIncludeFilesArray = srcIncludeFiles.ToArray(); foreach (var incFile in srcIncludeFilesArray) { stringBuilderForSource.AppendLine(incFile.ToString()); baseLayerStructure.SourceFileItems.Remove(incFile); } stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"#define __RTCOP_GENERAED_CODE_FLAG__"); stringBuilderForSource.AppendLine(@"#include ""BaseLayer.h"""); var srcImportFilesArray = srcImportFiles.ToArray(); List <string> layerNamesS = new List <string>(); foreach (var impFile in srcImportFilesArray) { string filePath = ""; foreach (var incpath in IncludePaths) { string path = incpath + impFile.Param1; string fullPath = Path.GetFullPath(path); if (File.Exists(fullPath)) { filePath = fullPath; break; } } foreach (var ls in layerStructures) { if (layerNamesS.Contains(ls.LayerName)) { continue; } if (ls.ImportedLhInfomation.Exists((obj) => obj.FilePath == filePath)) { stringBuilderForSource.Append(@"#include """); stringBuilderForSource.Append(ls.LayerName); stringBuilderForSource.AppendLine(@".h"""); layerNamesS.Add(ls.LayerName); } } baseLayerStructure.SourceFileItems.Remove(impFile); } stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"namespace RTCOP {"); stringBuilderForSource.AppendLine(@"namespace Generated {"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"BaseLayer* BaseLayer::GetInstance()"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return (BaseLayer*)RTCOP::Framework::Instance->GetRTCOPManager()->GetLayer((int)LayerID::baselayer);"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"BaseLayer::BaseLayer(const int id, const char* const name, int numOfBaseClasses, int* numOfBaseMethods)"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@":Core::Layer(id, name, numOfBaseClasses, numOfBaseMethods)"); stringBuilderForSource.AppendLine(@"{"); int classcount = 0; foreach (string classname in baseClassNameList) { stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"int size"); stringBuilderForSource.Append(classcount); stringBuilderForSource.Append(@" = sizeof(volatile void*) * numOfBaseMethods["); stringBuilderForSource.Append(classcount); stringBuilderForSource.AppendLine(@"];"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"volatile void** virtualFunctionTable"); stringBuilderForSource.Append(classcount); stringBuilderForSource.Append(@" = DependentCode::"); stringBuilderForSource.Append(classname); stringBuilderForSource.AppendLine(@"::GetVirtualFunctionTable(this);"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"std::memcpy(_Private->_VirtualFunctionTables["); stringBuilderForSource.Append(classcount); stringBuilderForSource.Append(@"], virtualFunctionTable"); stringBuilderForSource.Append(classcount); stringBuilderForSource.Append(@", size"); stringBuilderForSource.Append(classcount); stringBuilderForSource.AppendLine(@");"); ++classcount; } stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"BaseLayer::~BaseLayer()"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"void* BaseLayer::InitializeLayerdObject(void* obj, int classID)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return obj;"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"} // namespace Generated {}"); stringBuilderForSource.AppendLine(@"} // namespace RTCOP {}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(ItemsToStringForBaseLayer(baseLayerStructure.SourceFileItems, baseClassNameList, baseMethodLists, superClassIDs, 0, "")); stringBuilderForSource.AppendLine(); result.CodeDictionary[@"BaseLayer.cpp"] = stringBuilderForSource.ToString(); }
/// <summary> /// コード生成 /// </summary> /// <param name="mergedLSFile">マージ済みのレイヤ構造ファイル</param> /// <param name="includeFilePath">インクルードファイルパス</param> /// <returns>生成後のソースコード</returns> public GeneratedCodes GenerateCode(LayerStructureFile mergedLSFile, string includeFilePath) { GeneratedCodes result = new GeneratedCodes(); // ライブラリのヘッダファイルを追加 result.CodeDictionary[@"Layer_Private.h"] = Properties.Resources.Layer_Private_Header; result.CodeDictionary[@"LayerdObject_Private.h"] = Properties.Resources.LayerdObject_Private_Header; // ベースクラスを調べる LayerStructure baselayerStructure = mergedLSFile.BaseLayerStructure; if (baselayerStructure == null) { // ベースレイヤは定義されていなくても、自動的に生成される baselayerStructure = new LayerStructure("baselayer"); mergedLSFile.BaseLayerStructure = baselayerStructure; } List <string> baseClassNameList = new List <string>(); List <List <LayerdMethodDefinition> > baseMethodLists = new List <List <LayerdMethodDefinition> >(); List <List <ConstructorDefinition> > constructorLists = new List <List <ConstructorDefinition> >(); List <int> superClassIDs = new List <int>(); Action <IEnumerable <object>, string, int> createBaseClassAndMethodList = null; createBaseClassAndMethodList = (items, nspace, classId) => { foreach (object item in items) { if (item is LayerDefinition) { var ld = (LayerDefinition)item; string nspace2 = "baselayer"; createBaseClassAndMethodList(ld.Contents, nspace2, -1); } else if (item is NamespaceDefinition) { var nd = (NamespaceDefinition)item; string nspace2 = nd.Name; if (nspace != "") { nspace2 = nspace + "::" + nspace2; } createBaseClassAndMethodList(nd.Contents, nspace2, -1); } else if (item is LayerdClassDefinition) { var lcd = (LayerdClassDefinition)item; string classname = lcd.Name; if (nspace != "") { classname = nspace + "::" + classname; } if (!baseClassNameList.Contains(classname)) { baseClassNameList.Add(classname); baseMethodLists.Add(new List <LayerdMethodDefinition>()); constructorLists.Add(new List <ConstructorDefinition>()); int id = baseClassNameList.IndexOf(classname); if (lcd.SuperClasses.Count >= 1) { string superclassFullname = lcd.SuperClasses[0].ClassName; if (nspace != "") { superclassFullname = nspace + "::" + superclassFullname; } string[] superclassNspaces = superclassFullname.Split(new string[] { "::" }, StringSplitOptions.None); string sname = superclassFullname; int superId = -1; for (int i = 0; i < superclassNspaces.Length; ++i) { int id2 = baseClassNameList.IndexOf(sname); if (id2 != -1) { baseMethodLists[id].AddRange(baseMethodLists[id2]); superId = id2; break; } sname = sname.Remove(0, (superclassNspaces[i].Length + 2)); } superClassIDs.Add(superId); } else { superClassIDs.Add(-1); } createBaseClassAndMethodList(lcd.Contents, classname, id); // デストラクタ無ければ追加 var baseMethodList = baseMethodLists[id]; if (!baseMethodList.Exists((obj) => obj == null)) { baseMethodList.Add(null); } } else { throw new Exception("クラス" + classname + "の定義が重複しています"); } } else if (item is ConstructorDefinition) { var cd = (ConstructorDefinition)item; var list = constructorLists[classId]; list.Add(cd); } else if (item is DestructorDefinition) { var dd = (DestructorDefinition)item; if (dd.IsVirtual || dd.IsPureVirtual) { var methodList = baseMethodLists[classId]; if (!methodList.Exists((obj) => obj == null)) { methodList.Add(null); } } } else if (item is LayerdMethodDefinition) { if (classId == -1) { continue; } var lmd = (LayerdMethodDefinition)item; if (((lmd.IsBase != null) && lmd.IsBase.Value) || lmd.IsVirtual || lmd.IsPureVirtual) { var methodList = baseMethodLists[classId]; if (!methodList.Exists((obj) => (obj != null) && (obj.CompareMethod(lmd)))) { methodList.Add(lmd); } } } } }; createBaseClassAndMethodList(baselayerStructure.HeaderFileItems, "", -1); createBaseClassAndMethodList(baselayerStructure.SourceFileItems, "", -1); createBaseClassAndMethodList(mergedLSFile.BaseClassHeaderItems, "", -1); // レイヤ、クラス、メソッドの数を調べる int numOfLayers = mergedLSFile.LayerStructures.Count + 1; int numOfClasses = baseClassNameList.Count; int[] numOfMethods = new int[numOfClasses]; for (int i = 0; i < numOfClasses; ++i) { numOfMethods[i] = baseMethodLists[i].Count; } //======================================= // ↓これらは別ファイルで定義 //======================================= // RTCOPAppInitializerの生成 GenerateRTCOPAppInitializer(result, numOfLayers, numOfClasses, numOfMethods, mergedLSFile.LayerStructures, includeFilePath); // API.h、COPNewForApp.h、ActivationForApp.hの生成 GenerateAPIHeaders(result, mergedLSFile.LayerStructures, baseClassNameList, includeFilePath); // ベースレイヤの生成 GenerateBaseLayer(result, baselayerStructure, mergedLSFile.LayerStructures, baseClassNameList, baseMethodLists, superClassIDs, includeFilePath); // 各レイヤの生成 GenerateLayers(result, baselayerStructure, mergedLSFile.LayerStructures, baseClassNameList, baseMethodLists, constructorLists, superClassIDs, includeFilePath); // 環境依存コードの生成 GenerateDependentCode(result, baselayerStructure, mergedLSFile.LayerStructures, baseClassNameList, baseMethodLists, includeFilePath); // 結果を返す return(result); }
/// <summary> /// 環境依存コード(macOS) /// </summary> private void GenerateDependentCodeForMacOSX64(GeneratedCodes result, LayerStructure baseLayerStructure, List <LayerStructure> layerStructures, List <string> baseClassNameList, List <List <LayerdMethodDefinition> > baseMethodLists) { // cppファイル StringBuilder stringBuilderForSource = new StringBuilder(); stringBuilderForSource.AppendLine(@"#include ""DependentCode.h"""); stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/LayerdObject.h"""); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"#include ""BaseLayer.h"""); foreach (var layerStructure in layerStructures) { stringBuilderForSource.Append(@"#include """); stringBuilderForSource.Append(layerStructure.LayerName); stringBuilderForSource.AppendLine(@".h"""); } stringBuilderForSource.AppendLine(); foreach (LayerStructure layerStructure in layerStructures) { var headerIncludeFiles = from item in layerStructure.HeaderFileItems where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include) select(PreprocessDirective) item; var srcIncludeFiles = from item in layerStructure.SourceFileItems where (item is PreprocessDirective) && (((PreprocessDirective)item).Kind == DirectiveKind.Include) select(PreprocessDirective) item; foreach (var inc in headerIncludeFiles) { stringBuilderForSource.Append(@"#include """); stringBuilderForSource.Append(inc.Param1); stringBuilderForSource.AppendLine(@""""); } foreach (var inc in srcIncludeFiles) { stringBuilderForSource.Append(@"#include """); stringBuilderForSource.Append(inc.Param1); stringBuilderForSource.AppendLine(@""""); } } stringBuilderForSource.AppendLine(); int classCount = 0; foreach (var baseClassName in baseClassNameList) { stringBuilderForSource.Append(@"asm("".rtcop_vft"); stringBuilderForSource.Append(classCount); stringBuilderForSource.Append(@"0: .quad __ZTVN5RTCOP4Core12LayerdObjectI"); string end = "EE"; string[] nss = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None); if (nss.Length >= 2) { stringBuilderForSource.Append(@"N"); end = "EEE"; } foreach (string ns in nss) { stringBuilderForSource.Append(ns.Length); stringBuilderForSource.Append(ns); } stringBuilderForSource.Append(end); stringBuilderForSource.AppendLine(@"+16"");"); int layerCount = 1; foreach (var layerStructure in layerStructures) { if (layerStructure._FindedPartialClasses[classCount] != null) { stringBuilderForSource.Append(@"asm("".rtcop_vft"); stringBuilderForSource.Append(classCount); stringBuilderForSource.Append(layerCount); stringBuilderForSource.Append(@": .quad __ZTVN"); stringBuilderForSource.Append(layerStructure.LayerName.Length); stringBuilderForSource.Append(layerStructure.LayerName); foreach (string ns in nss) { if (ns != "baselayer") { stringBuilderForSource.Append(ns.Length); stringBuilderForSource.Append(ns); } } stringBuilderForSource.AppendLine(@"E+16"");"); stringBuilderForSource.Append(@"asm("".rtcop_vfaddr"); stringBuilderForSource.Append(classCount); stringBuilderForSource.Append(layerCount); stringBuilderForSource.Append(@": .quad __ZN"); stringBuilderForSource.Append(layerStructure.LayerName.Length); stringBuilderForSource.Append(layerStructure.LayerName); foreach (string ns in nss) { if (ns != "baselayer") { stringBuilderForSource.Append(ns.Length); stringBuilderForSource.Append(ns); } } stringBuilderForSource.AppendLine(@"27_RTCOP_FinalizePartialClassEv"");"); } ++layerCount; } stringBuilderForSource.AppendLine(); ++classCount; } stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"namespace RTCOP {"); stringBuilderForSource.AppendLine(@"namespace Generated {"); stringBuilderForSource.AppendLine(@"namespace DependentCode {"); stringBuilderForSource.AppendLine(); classCount = 0; foreach (var baseClassName in baseClassNameList) { var nss = baseClassName.Split(new string[] { "::" }, StringSplitOptions.None); int layerCount = 1; foreach (var layerStructure in layerStructures) { if (layerStructure._FindedPartialClasses[classCount] != null) { stringBuilderForSource.Append(@"volatile void* GetLayerdObjectFinalizer(::"); stringBuilderForSource.Append(layerStructure.LayerName); stringBuilderForSource.Append(@"::"); for (int i = 0; i < (nss.Length - 1); ++i) { string ns = nss[i]; if (ns != "baselayer") { stringBuilderForSource.Append(ns); stringBuilderForSource.Append(@"::"); } } stringBuilderForSource.Append(nss[nss.Length - 1]); stringBuilderForSource.AppendLine(@"* obj)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"volatile void* vfp = 0;"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"asm volatile(""movq .rtcop_vfaddr"); stringBuilderForSource.Append(classCount); stringBuilderForSource.Append(layerCount); stringBuilderForSource.AppendLine(@"(%%rip), %0"" : ""=r""(vfp) : : ""memory""); "); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return vfp;"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); } ++layerCount; } stringBuilderForSource.AppendLine(); for (int i = 0; i < nss.Length; ++i) { stringBuilderForSource.Append(@"namespace "); stringBuilderForSource.Append(nss[i]); stringBuilderForSource.Append(@" { "); } stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"volatile void** GetVirtualFunctionTable(BaseLayer* layer)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"volatile void** vft = 0;"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"asm volatile(""movq .rtcop_vft"); stringBuilderForSource.Append(classCount); stringBuilderForSource.AppendLine(@"0(%%rip), %0"" : ""=r""(vft) : : ""memory""); "); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return vft;"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); layerCount = 1; foreach (var layerStructure in layerStructures) { if (layerStructure._FindedPartialClasses[classCount] != null) { stringBuilderForSource.Append(@"volatile void** GetVirtualFunctionTable("); stringBuilderForSource.Append(layerStructure.LayerName); stringBuilderForSource.AppendLine(@"* layer)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"volatile void** vft = 0;"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"asm volatile(""movq .rtcop_vft"); stringBuilderForSource.Append(classCount); stringBuilderForSource.Append(layerCount); stringBuilderForSource.AppendLine(@"(%%rip), %0"" : ""=r""(vft) : : ""memory""); "); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return vft;"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); } ++layerCount; } var baseMethodList = baseMethodLists[classCount]; foreach (var baseMethod in baseMethodList) { if (baseMethod != null) { stringBuilderForSource.Append(baseMethod.ReturnType); stringBuilderForSource.Append(@" ExecuteProceed_"); stringBuilderForSource.Append(baseMethod.Name); stringBuilderForSource.Append(@"(void* layerdObject, volatile void* proceed"); foreach (var param in baseMethod.Parameters) { stringBuilderForSource.Append(@", "); stringBuilderForSource.Append(param); } stringBuilderForSource.AppendLine(@")"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(baseMethod.ReturnType); stringBuilderForSource.Append(@"(*pProceed)(void*"); foreach (var param in baseMethod.Parameters) { stringBuilderForSource.Append(@", "); stringBuilderForSource.Append(param.Type); } stringBuilderForSource.Append(@") = ("); stringBuilderForSource.Append(baseMethod.ReturnType); stringBuilderForSource.Append(@"(*)(void*"); foreach (var param in baseMethod.Parameters) { stringBuilderForSource.Append(@", "); stringBuilderForSource.Append(param.Type); } stringBuilderForSource.AppendLine(@"))proceed;"); stringBuilderForSource.Append("\t"); if (!((baseMethod.ReturnType.Type.ToString() == "void") && (baseMethod.ReturnType.Pointers.Count == 0))) { stringBuilderForSource.Append(@"return "); } stringBuilderForSource.Append("pProceed(layerdObject"); foreach (var param in baseMethod.Parameters) { stringBuilderForSource.Append(@", "); stringBuilderForSource.Append(param.Name); } stringBuilderForSource.AppendLine(");"); stringBuilderForSource.AppendLine(@"}"); } } stringBuilderForSource.AppendLine(); for (int i = 0; i < nss.Length; ++i) { stringBuilderForSource.Append(@"}"); } stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(); ++classCount; } stringBuilderForSource.AppendLine(@"} // namespace DependentCode {}"); stringBuilderForSource.AppendLine(@"} // namespace Generated {}"); stringBuilderForSource.AppendLine(@"} // namespace RTCOP {}"); result.CodeDictionary[@"DependentCode.cpp"] = stringBuilderForSource.ToString(); result.CodeDictionary[@"DependentCodeAsm.asm"] = ""; }
/// <summary> /// RTCOPAppInitializerの生成 /// </summary> private void GenerateRTCOPAppInitializer(GeneratedCodes result, int numOfLayers, int numOfClasses, int[] numOfMethods, List <LayerStructure> layerStructures) { // RTCOPAppInitializer.h StringBuilder stringBuilderForHeader = new StringBuilder(); stringBuilderForHeader.AppendLine(@"#ifndef __RTCOP_GENERATED_RTCOPAPPINITIALIZER__"); stringBuilderForHeader.AppendLine(@"#define __RTCOP_GENERATED_RTCOPAPPINITIALIZER__"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"#include ""RTCOP/Core/Initializer.h"""); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"namespace RTCOP {"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"namespace Core {"); stringBuilderForHeader.AppendLine(@"class RTCOPManager;"); stringBuilderForHeader.AppendLine(@"class LayerdObjectInitializer;"); stringBuilderForHeader.AppendLine(@"class LayerActivater;"); stringBuilderForHeader.AppendLine(@"}"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"namespace Generated {"); stringBuilderForHeader.AppendLine(@"class RTCOPAppInitializer : public Core::Initializer"); stringBuilderForHeader.AppendLine(@"{"); stringBuilderForHeader.AppendLine(@"public:"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"explicit RTCOPAppInitializer();"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual ~RTCOPAppInitializer();"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual Core::RTCOPManager* InitializeRTCOPManager() override;"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual Core::LayerdObjectInitializer* InitializeLayerdObjectInitializer(Core::RTCOPManager* manager) override;"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual Core::LayerActivater* InitializeLayerActivater(Core::RTCOPManager* manager) override;"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual void RegisterLayers(Core::RTCOPManager* manager) override;"); stringBuilderForHeader.Append("\t"); stringBuilderForHeader.AppendLine(@"virtual void FirstLayerActivation(Core::LayerActivater* activater) override;"); stringBuilderForHeader.AppendLine(@"};"); stringBuilderForHeader.AppendLine(); stringBuilderForHeader.AppendLine(@"} // namespace Generated {}"); stringBuilderForHeader.AppendLine(@"} // namespace RTCOP {}"); stringBuilderForHeader.AppendLine(@"#endif // !__RTCOP_GENERATED_RTCOPAPPINITIALIZER__"); result.CodeDictionary[@"RTCOPAppInitializer.h"] = stringBuilderForHeader.ToString(); // RTCOPAppInitializer.cpp StringBuilder stringBuilderForSource = new StringBuilder(); stringBuilderForSource.AppendLine(@"#include ""RTCOPAppInitializer.h"""); stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/RTCOPManager.h"""); stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/LayerdObjectInitializer.h"""); stringBuilderForSource.AppendLine(@"#include ""RTCOP/Core/LayerActivater.h"""); stringBuilderForSource.AppendLine(@"#include ""BaseLayer.h"""); foreach (LayerStructure ls in layerStructures) { stringBuilderForSource.Append(@"#include """); stringBuilderForSource.Append(ls.LayerName); stringBuilderForSource.AppendLine(@".h"""); } stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"namespace RTCOP {"); stringBuilderForSource.AppendLine(@"namespace Generated {"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"RTCOPAppInitializer::RTCOPAppInitializer()"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"RTCOPAppInitializer::~RTCOPAppInitializer()"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"Core::RTCOPManager* RTCOPAppInitializer::InitializeRTCOPManager()"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"int numOfLayers = "); stringBuilderForSource.Append(numOfLayers); stringBuilderForSource.AppendLine(@";"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"int numOfClasses = "); stringBuilderForSource.Append(numOfClasses); stringBuilderForSource.AppendLine(@";"); stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"int* numOfMethods = new int[numOfClasses] {"); for (int i = 0; i < numOfMethods.Length; ++i) { int num = numOfMethods[i]; if (Environment != DevelopmentEnvironment.VisualStudio) { num += 1; } stringBuilderForSource.Append(num); if (i < (numOfMethods.Length - 1)) { stringBuilderForSource.Append(@", "); } } stringBuilderForSource.AppendLine(@"};"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return new Core::RTCOPManager(numOfLayers, numOfClasses, numOfMethods);"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"Core::LayerdObjectInitializer* RTCOPAppInitializer::InitializeLayerdObjectInitializer(Core::RTCOPManager* manager)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return new Core::LayerdObjectInitializer(manager);"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"Core::LayerActivater* RTCOPAppInitializer::InitializeLayerActivater(Core::RTCOPManager* manager)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return new Core::LayerActivater(manager);"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"void RTCOPAppInitializer::RegisterLayers(Core::RTCOPManager* manager)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"int numOfBaseClasses = manager->GetNumOfBaseClasses();"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"int* numOfBaseMethods = manager->GetNumOfBaseMethods();"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"manager->RegisterLayer(new BaseLayer(0, ""baselayer"", numOfBaseClasses, numOfBaseMethods));"); int layercount = 1; foreach (LayerStructure ls in layerStructures) { stringBuilderForSource.Append("\t"); stringBuilderForSource.Append(@"manager->RegisterLayer(new "); stringBuilderForSource.Append(ls.LayerName); stringBuilderForSource.Append(@"("); stringBuilderForSource.Append(layercount); stringBuilderForSource.Append(@", """); stringBuilderForSource.Append(ls.LayerName); stringBuilderForSource.AppendLine(@""", numOfBaseClasses, numOfBaseMethods));"); ++layercount; } stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"void RTCOPAppInitializer::FirstLayerActivation(Core::LayerActivater* activater)"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"activater->ActivateLayer(0);"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"Core::Initializer* _GetDefaultInitializer_()"); stringBuilderForSource.AppendLine(@"{"); stringBuilderForSource.Append("\t"); stringBuilderForSource.AppendLine(@"return new RTCOPAppInitializer();"); stringBuilderForSource.AppendLine(@"}"); stringBuilderForSource.AppendLine(); stringBuilderForSource.AppendLine(@"} // namespace Generated {}"); stringBuilderForSource.AppendLine(@"} // namespace RTCOP {}"); result.CodeDictionary[@"RTCOPAppInitializer.cpp"] = stringBuilderForSource.ToString(); }