9 static define localeDir = "locale";
12 static Platform targetPlatform;
14 static bool isConsole;
15 static bool isDynamicLibrary;
16 static bool isStaticLibrary;
17 static OldList modules;
18 static File dcomSymbols;
20 static OldList _defines { };
21 static OldList _imports { };
22 static OldList _excludedSymbols { offset = (uint)&((Symbol)0).left };
23 static NameSpace globalData
25 classes.CompareKey = (void *)BinaryTree::CompareString;
26 defines.CompareKey = (void *)BinaryTree::CompareString;
27 functions.CompareKey = (void *)BinaryTree::CompareString;
28 nameSpaces.CompareKey = (void *)BinaryTree::CompareString;
30 static Context theGlobalContext { };
31 static ModuleImport mainModule;
32 static Module privateModule;
34 static char mainModuleName[MAX_LOCATION];
35 static char projectName[MAX_LOCATION];
36 static void LoadImports(char * fileName)
38 File f = FileOpen(fileName, read);
44 if(!f.GetLine(line, sizeof(line))) break;
45 TrimLSpaces(line, line);
49 if(!strcmp(line, "[Imported Modules]"))
51 ModuleImport module = null;
54 if(!f.GetLine(line, sizeof(line))) break;
55 TrimLSpaces(line, line);
56 if(!strcmp(line, ".")) break;
60 ClassImport _class = null;
61 FunctionImport function = null;
63 if(!strcmp(line, "[This]"))
65 if((mainModule = GetMainModule()))
69 mainModule = ModuleImport { };
70 SetMainModule(mainModule);
72 _imports.AddName(module);
75 else if(!strcmp(line, "[Static]"))
77 module.importType = staticImport;
79 else if(!strcmp(line, "[Remote]"))
81 module.importType = remoteImport;
83 else if(!strcmp(line, "[Private]"))
85 if(module.importAccess != publicAccess)
86 module.importAccess = privateAccess;
88 else if(!strcmp(line, "[Public]"))
90 module.importAccess = publicAccess;
92 else if(!strcmp(line, "[Imported Classes]"))
96 if(!f.GetLine(line, sizeof(line))) break;
97 TrimLSpaces(line, line);
98 if(!strcmp(line, ".")) break;
102 if(!strcmp(line, "[Instantiated]"))
104 _class.itself = true;
106 else if(!strcmp(line, "[Remote]"))
110 else if(!strcmp(line, "[Imported Methods]"))
112 MethodImport method = null;
115 if(!f.GetLine(line, sizeof(line))) break;
116 TrimLSpaces(line, line);
117 if(!strcmp(line, ".")) break;
120 if(!(method = _class.methods.FindName(line, false)))
122 method = MethodImport { name = CopyString(line) };
123 _class.methods.AddName(method);
126 else if(!strcmp(line, "[Virtual]"))
127 method.isVirtual = true;
131 else if(!strcmp(line, "[Imported Properties]"))
133 PropertyImport prop = null;
136 if(!f.GetLine(line, sizeof(line))) break;
137 TrimLSpaces(line, line);
138 if(!strcmp(line, ".")) break;
141 if(!(prop = _class.properties.FindName(line, false)))
143 prop = PropertyImport { name = CopyString(line) };
144 _class.properties.AddName(prop);
147 else if(!strcmp(line, "[Set]"))
149 else if(!strcmp(line, "[Get]"))
151 else if(!strcmp(line, "[Virtual]"))
152 prop.isVirtual = true;
158 if(!(_class = module.classes.FindName(line, false)))
160 _class = ClassImport { name = CopyString(line) };
161 module.classes.AddName(_class);
166 else if(!strcmp(line, "[Imported Functions]"))
170 if(!f.GetLine(line, sizeof(line))) break;
171 TrimLSpaces(line, line);
172 if(!strcmp(line, ".")) break;
179 if(!(function = module.functions.FindName(line, false)))
181 function = FunctionImport { name = CopyString(line) };
182 module.functions.AddName(function);
190 if(!(module = _imports.FindName(line, false)))
192 if(!strcmp(line, "ecereCOM"))
194 module = _imports.FindName("ecere", false);
196 else if(!strcmp(line, "ecere"))
198 module = _imports.FindName("ecereCOM", false);
202 module.name = CopyString("ecere");
207 module = ModuleImport { name = CopyString(line) };
208 _imports.AddName(module);
220 // static Class applicationClass;
221 static Class thisAppClass;
223 class ModuleInfo : struct
225 ModuleInfo prev, next;
231 static bool SeardchModuleName(Module searchIn, char * name)
235 if(searchIn.name && !strcmp(searchIn.name, name))
238 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
240 if(SearchModuleName(subModule.module, name))
246 static void WriteMain(char * fileName)
248 File f = FileOpen(fileName, write);
252 ModuleInfo defModule;
253 bool nonInst = false, anyMethod = false, anyProp = false, anyFunction = false;
254 ImportedModule importedModule;
256 GetLastDirectory(fileName, mainModuleName);
257 StripExtension(mainModuleName);
260 strcpy(projectName, mainModuleName);
261 StripExtension(projectName);
263 ChangeCh(mainModuleName, '.', '_');
264 ChangeCh(mainModuleName, '-', '_');
265 ChangeCh(mainModuleName, ' ', '_');
267 if(targetPlatform == win32 && !isConsole && !isStaticLibrary && !isDynamicLibrary)
269 //f.Puts("#include <windows.h>\n\n");
271 f.Puts("typedef void * HINSTANCE;\n");
272 f.Puts("#define WINAPI __stdcall\n");
275 for(importedModule = ::_defines.first; importedModule; importedModule = importedModule.next)
277 if(importedModule.type == moduleDefinition)
280 if(importedModule.importType == staticImport)
281 f.Printf("static ", importedModule.name);
282 f.Printf("\"%s\"\n", importedModule.name);
286 f.Puts("default:\n");
287 f.Puts("static Module __currentModule;\n\n");
290 f.Puts("Module __thisModule;\n\n");
292 // TOCHECK: Problem compiling Scrabble.main.ec when binding Client first
297 f.Printf("void __ecereRegisterModule_%s(Module module);\n\n", mainModuleName);
299 for(module = _imports.first; module; module = module.next)
302 FunctionImport function;
303 if(module.importType == staticImport)
305 /*if(targetPlatform == win32)
307 f.Printf("bool __stdcall __ecereDll_Load_%s(Module module);\n", module.name);
308 f.Printf("bool __stdcall __ecereDll_Unload_%s(Module module);\n", module.name);
312 f.Printf("bool __ecereDll_Load_%s(Module module);\n", module.name);
313 f.Printf("bool __ecereDll_Unload_%s(Module module);\n", module.name);
316 for(_class = module.classes.first; _class; _class = _class.next)
320 char className[1024] = "";
321 Class regClass = eSystem_FindClass(privateModule, _class.name);
323 FullClassNameCat(className, _class.name, true);
324 MangleClassName(className);
327 f.Printf("Class __ecereClass_%s;\n", className);
330 //if(!_class.isRemote)
332 //if(strcmp(_class.name, "SerialBuffer"))
334 for(method = _class.methods.first; method; method = method.next)
336 Method meth = eClass_FindMethod(regClass, method.name, privateModule);
337 if(meth && !meth.dataType)
339 Context context = SetupTemplatesContext(regClass);
340 meth.dataType = ProcessTypeString(meth.dataTypeString, false);
341 FinishTemplatesContext(context);
345 f.Printf("int __ecereVMethodID_%s_%s;\n", className, method.name);
346 else if(module.name && module.importType != staticImport && (!meth || !meth.dataType.dllExport))
356 sprintf(name, "__ecereMethod_%s_%s", className, method.name);
357 PrintType(type, name, true);
358 f.Printf("%s;\n", name);
361 //f.Printf("void * __ecereMethod_%s_%s;\n", className, method.name);
363 f.Printf("int (*__ecereMethod_%s_%s)();\n", className, method.name);
370 for(prop = _class.properties.first; prop; prop = prop.next)
374 FullClassNameCat(propName, prop.name, true);
375 // strcpy(propName, prop.name);
376 MangleClassName(propName);
378 if(module.name && module.importType != staticImport)
381 f.Printf("void * __ecereProp_%s_Set_%s;\n", className, propName);
383 f.Printf("void * __ecereProp_%s_Get_%s;\n", className, propName);
385 f.Printf("Property __ecereProp_%s_%s;\n", className, propName);
390 for(function = module.functions.first; function; function = function.next)
392 GlobalFunction func = eSystem_FindFunction(privateModule, function.name);
393 if(func && !func.dataType)
394 func.dataType = ProcessTypeString(func.dataTypeString, false);
396 if(module.name && module.importType != staticImport && (!func || !func.dataType || !func.dataType.dllExport))
398 char functionName[1024];
400 FullClassNameCat(functionName, function.name, false);
401 f.Printf("void * __ecereFunction_%s;\n", functionName);
407 for(defModule = ::modules.first; defModule; defModule = defModule.next)
409 char moduleName[1024];
410 strcpy(moduleName, defModule.name);
411 ChangeCh(moduleName, ' ', '_');
412 ChangeCh(moduleName, '-', '_');
413 ChangeCh(moduleName, '.', '_');
415 f.Printf("void __ecereRegisterModule_%s(Module module);\n", moduleName);
416 f.Printf("void __ecereUnregisterModule_%s(Module module);\n", moduleName);
417 if(defModule.globalInstance)
419 f.Printf("void __ecereCreateModuleInstances_%s();\n", moduleName);
420 f.Printf("void __ecereDestroyModuleInstances_%s();\n", moduleName);
429 // Insert DCOM bindings here
430 dcomSymbols.Seek(0, start);
431 while(!dcomSymbols.Eof())
434 int read = dcomSymbols.Read(buffer, 1, sizeof(buffer));
436 f.Write(buffer, 1, read);
445 /*if(targetPlatform == win32)
446 f.Printf("\nbool __stdcall __ecereDll_Load_%s(Module module)\n{\n", projectName);
448 f.Printf("\nbool __ecereDll_Load_%s(Module module)\n{\n", projectName);
450 else if(isDynamicLibrary)
452 if(targetPlatform == win32)
453 f.Puts("\ndllexport bool __stdcall __ecereDll_Load(Module module)\n{\n");
455 f.Puts("\ndllexport bool __ecereDll_Load(Module module)\n{\n");
457 else if(targetPlatform == win32 && !isConsole)
459 f.Puts("\nint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, char * cmdLine, int show)\n{\n");
462 f.Puts("\nint main(int _argc, char * _argv[])\n{\n");
464 if(!isDynamicLibrary)
466 f.Puts(" int exitCode;\n");
467 f.Puts(" Module module;\n");
470 //if(nonInst || thisAppClass) // We use it all the time to get "Application" for the exit code now...
471 f.Puts(" Class _class;\n");
474 f.Puts(" Method method;\n");
476 f.Puts(" Property _property;\n");
478 f.Puts(" GlobalFunction function;\n");
484 f.Puts(" if(!__currentModule)\n");
486 f.Puts(" __currentModule = module;\n");
488 f.Puts(" __thisModule = module;\n");
491 else if(targetPlatform == win32 && !isConsole)
492 f.Puts(" __thisModule = __currentModule = module = __ecere_COM_Initialize(1, 0, null);\n\n");
494 f.Puts(" __thisModule = __currentModule = module = __ecere_COM_Initialize(1, _argc, (void *)_argv);\n\n");
496 // First load all modules
499 for(module = _imports.first; module; module = module.next)
503 //if(strcmp(module.name, "ecereCOM") && strcmp(module.name, "ecere") )
505 if(module.importType == staticImport)
506 f.Printf(" eModule_LoadStatic(module, \"%s\", %s, __ecereDll_Load_%s, __ecereDll_Unload_%s);\n", module.name, (module.importAccess == privateAccess) ? "privateAccess" : "publicAccess", module.name,module.name);
508 f.Printf(" eModule_Load(module, \"%s\", %s);\n", module.name, (module.importAccess == privateAccess) ? "privateAccess" : "publicAccess");
515 // Then define the classes
518 for(defModule = ::modules.first; defModule; defModule = defModule.next)
520 char moduleName[1024];
521 strcpy(moduleName, defModule.name);
522 ChangeCh(moduleName, ' ', '_');
523 ChangeCh(moduleName, '-', '_');
524 ChangeCh(moduleName, '.', '_');
526 f.Printf(" __ecereRegisterModule_%s(module);\n", moduleName);
531 // Register Remote Modules
534 f.Printf(" __ecereRegisterModule_%s(module);\n\n", mainModuleName);
540 f.Puts(" if(__currentModule == module)\n");
543 // Then load the imports
544 for(module = _imports.first; module; module = module.next)
547 FunctionImport function;
548 if(module.classes.count)
550 for(_class = module.classes.first; _class; _class = _class.next)
552 Class regClass = eSystem_FindClass(privateModule, _class.name);
554 //if(!_class.isRemote)
559 char className[1024] = "";
560 FullClassNameCat(className, _class.name, true);
561 MangleClassName(className);
564 sprintf(classID, "__ecereClass_%s", className);
566 strcpy(classID, "_class");
568 if(isDynamicLibrary && !isStaticLibrary)
569 f.Printf(" %s = eSystem_FindClass(__currentModule, \"%s\");\n", classID, _class.name);
571 f.Printf(" %s = eSystem_FindClass(module, \"%s\");\n", classID, _class.name);
573 for(method = _class.methods.first; method; method = method.next)
575 Method meth = eClass_FindMethod(regClass, method.name, privateModule);
576 if(!meth || !meth.dataType.dllExport)
578 if(method.isVirtual || (module.name && module.importType != staticImport))
580 f.Printf(" method = eClass_FindMethod(%s, \"%s\", module);\n",
581 classID, method.name);
583 f.Printf(" if(method) __ecereVMethodID_%s_%s = method.vid;\n", className, method.name);
585 f.Printf(" if(method) __ecereMethod_%s_%s = method.function;\n", className, method.name);
590 for(prop = _class.properties.first; prop; prop = prop.next)
594 FullClassNameCat(propName, prop.name, true);
595 // strcpy(propName, prop.name);
596 MangleClassName(propName);
598 f.Printf(" __ecereProp_%s_%s = _property = eClass_FindProperty(%s, \"%s\", module);\n",
599 className, propName, classID, prop.name);
601 if(module.name && module.importType != staticImport)
604 f.Printf(" __ecereProp_%s_Set_%s = _property.Set;\n", className, propName);
606 f.Printf(" __ecereProp_%s_Get_%s = _property.Get;\n", className, propName);
613 if(module.functions.count)
615 for(function = module.functions.first; function; function = function.next)
617 GlobalFunction func = eSystem_FindFunction(privateModule, function.name);
618 if(module.name && module.importType != staticImport && (!func || !func.dataType || !func.dataType.dllExport))
620 char functionName[1024];
622 FullClassNameCat(functionName, function.name, false);
624 if(isDynamicLibrary && !isStaticLibrary)
625 f.Printf(" function = eSystem_FindFunction(__currentModule, \"%s\");\n", function.name);
627 f.Printf(" function = eSystem_FindFunction(module, \"%s\");\n", function.name);
629 f.Printf(" if(function) __ecereFunction_%s = function.function;\n", functionName);
639 //f.Printf(" module._vTbl[10](module);\n");
644 f.Printf(" LoadTranslatedStrings(module, \"%s\");\n", projectName);
646 if(!isDynamicLibrary && thisAppClass)
648 f.Printf(" _class = eSystem_FindClass(__currentModule, \"%s\");\n", thisAppClass.name);
649 f.Printf(" eInstance_Evolve((Instance *)&__currentModule, _class);\n");
650 f.Printf(" __thisModule = __currentModule;\n");
655 f.Puts(" if(__currentModule == module)\n");
659 // Then check if there's any global instances to create
662 for(defModule = ::modules.first; defModule; defModule = defModule.next)
663 if(defModule.globalInstance)
665 char moduleName[1024];
666 strcpy(moduleName, defModule.name);
667 ChangeCh(moduleName, ' ', '_');
668 ChangeCh(moduleName, '-', '_');
669 ChangeCh(moduleName, '.', '_');
671 f.Printf(" __ecereCreateModuleInstances_%s();\n", moduleName);
681 if(!isDynamicLibrary && thisAppClass)
683 f.Printf(" __currentModule._vTbl[12](__currentModule);\n");
688 f.Puts(" return true;\n");
692 /*if(targetPlatform == win32)
693 f.Printf("\nbool __stdcall __ecereDll_Unload_%s(Module module)\n{\n", projectName);
695 f.Printf("\nbool __ecereDll_Unload_%s(Module module)\n{\n", projectName);
699 if(targetPlatform == win32)
700 f.Puts("\ndllexport bool __stdcall __ecereDll_Unload(Module module)\n{\n");
702 f.Puts("\ndllexport bool __ecereDll_Unload(Module module)\n{\n");
708 f.Puts(" if(__currentModule == module)\n");
711 // Then check if there's any global instances to destroy
714 for(defModule = ::modules.first; defModule; defModule = defModule.next)
715 if(defModule.globalInstance)
717 char moduleName[1024];
718 strcpy(moduleName, defModule.name);
719 ChangeCh(moduleName, ' ', '_');
720 ChangeCh(moduleName, '-', '_');
721 ChangeCh(moduleName, '.', '_');
722 f.Printf(" __ecereDestroyModuleInstances_%s();\n", moduleName);
728 f.Printf(" UnloadTranslatedStrings(__currentModule);\n");
735 //f.Printf(" module._vTbl[11](module);\n");
740 for(defModule = ::modules.first; defModule; defModule = defModule.next)
742 char moduleName[1024];
743 strcpy(moduleName, defModule.name);
744 ChangeCh(moduleName, ' ', '_');
745 ChangeCh(moduleName, '-', '_');
746 ChangeCh(moduleName, '.', '_');
747 f.Printf(" __ecereUnregisterModule_%s(module);\n", moduleName);
751 f.Puts(" if(__currentModule == module)\n");
752 f.Puts(" __currentModule = (void *)0;\n");
755 f.Puts(" if(__thisModule == module)\n");
756 f.Puts(" __thisModule = (void *)0;\n");
760 if(!isDynamicLibrary)
764 " _class = eSystem_FindClass(__currentModule, \"ecere::com::Application\");\n"
765 " exitCode = ((ecere::com::Application)__currentModule).exitCode;\n"
766 " delete __currentModule;\n"
767 " return exitCode;\n");
770 f.Puts(" return true;\n");
776 static Class FindAppClass(NameSpace * nameSpace, bool thisModule)
780 for(link = (BTNamedLink)nameSpace->classes.first; link; link = (BTNamedLink)((BTNode)link).next)
782 Class _class = link.data;
784 applicationClass = eSystem_FindClass(_class.module, "Application");
785 if(_class != applicationClass && eClass_IsDerived(_class, applicationClass) && (!thisModule || _class.module == privateModule))
788 if(strcmp(_class.fullName, "ecere::com::Application") && (!thisModule || _class.module == privateModule))
791 for(base = _class.base; base && base.type != systemClass; base = base.base)
792 if(!strcmp(base.fullName, "ecere::com::Application"))
797 for(ns = (NameSpace *)nameSpace->nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
799 Class _class = FindAppClass(ns, thisModule);
800 if(_class) // && _class != applicationClass)
803 return null; //applicationClass;
806 static Class SearchAppClass_Module(Module module)
811 appClass = FindAppClass(module.publicNameSpace, false);
812 if(appClass) return appClass;
813 appClass = FindAppClass(module.privateNameSpace, false);
814 if(appClass) return appClass;
816 for(subModule = module.modules.first; subModule; subModule = subModule.next)
818 appClass = SearchAppClass_Module(subModule.module);
819 if(appClass) return appClass;
824 static void BindDCOMClient()
826 Class dcomClientObjectClass = eSystem_FindClass(privateModule, "ecere::net::DCOMClientObject");
829 if(dcomClientObjectClass && dcomClientObjectClass.derivatives.first)
832 if(!dcomSymbols) dcomSymbols = TempFile { };
836 for(deriv = dcomClientObjectClass.derivatives.first; deriv; deriv = deriv.next)
838 Class _class = deriv.data;
844 DeclareClass(FindClass("ecere::net::DCOMClientObject"), "__ecereClass___ecereNameSpace__ecere__net__DCOMClientObject");
845 f.Printf("class %s : ecere::net::DCOMClientObject\n", _class.fullName);
848 // CLIENT VIRTUAL METHODS BINDINGS
849 if(_class.vTblSize > _class.base.vTblSize)
852 f.Printf(" virtual void CallVirtualMethod(uint __ecereMethodID, SerialBuffer __ecereBuffer)\n");
854 f.Printf(" switch(__ecereMethodID)\n");
857 for(vid = _class.base.vTblSize; vid < _class.vTblSize; vid++)
860 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
862 if(method.type == virtualMethod && method._class == _class && method.vid == vid)
868 method.dataType = ProcessTypeString(method.dataTypeString, false);
869 if(method.dataType && method.dataType.name)
871 f.Printf(" case %d:\n", vid - _class.base.vTblSize);
874 if(method.dataType.returnType.kind != voidType)
877 OldList * specs = MkList();
879 char type[1024] = "";
880 char className[1024];
883 if(method.dataType.returnType.kind == classType)
884 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
887 PrintType(method.dataType.returnType, type, false, true);
888 classSym = FindClass(type);
891 strcpy(className, "__ecereClass_");
892 FullClassNameCat(className, classSym.string, true);
893 MangleClassName(className);
894 DeclareClass(classSym, className);
896 PrintType(method.dataType.returnType, type, true, true);
898 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
899 resultType = MkTypeName(specs, decl);
902 OutputTypeName(resultType, f);
906 for(param = method.dataType.params.first; param; param = param.next)
908 if(param.kind == classType && !strcmp(param._class.string, "String"))
910 // Hardcode 1024 chars max string for now
911 f.Printf(" char %s[1024];\n", param.name);
912 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
913 DeclareClass(FindClass("String"), "__ecereClass_String");
917 TypeName paramTypeName;
918 OldList * specs = MkList();
920 char type[1024] = "";
921 char className[1024];
924 if(param.kind == classType)
925 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
928 PrintType(param, type, false, true);
929 classSym = FindClass(type);
933 strcpy(className, "__ecereClass_");
934 FullClassNameCat(className, classSym.string, true);
935 MangleClassName(className);
936 DeclareClass(classSym, className);
938 PrintType(param, type, true, true);
940 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier(param.name /*"__ecereResult"*/)));
941 paramTypeName = MkTypeName(specs, decl);
944 OutputTypeName(paramTypeName, f);
951 for(param = method.dataType.params.first; param; param = param.next)
953 f.Printf(" __ecereBuffer.Unserialize(");
954 if(param.kind == classType && !strcmp(param._class.string, "String"))
956 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
957 f.Printf("(StaticString)");
964 if(method.dataType.returnType.kind != voidType)
965 f.Printf("__ecereResult = ");
967 // f.Printf("this.instance.%s(", method.name);
968 f.Printf("%s(", method.name);
970 for(param = method.dataType.params.first; param; param = param.next)
974 f.Printf("%s", param.name);
979 for(param = method.dataType.params.first; param; param = param.next)
981 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
983 if(!strcmp(param._class.string, "String"))
985 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
986 f.Printf(" __ecereBuffer.Serialize((StaticString)%s);\n", param.name);
989 f.Printf(" __ecereBuffer.Serialize(%s);\n", param.name);
992 if(method.dataType.returnType.kind != voidType)
994 f.Printf(" __ecereBuffer.Serialize(__ecereResult);\n");
997 for(param = method.dataType.params.first; param; param = param.next)
999 if(param.kind == classType && strcmp(param._class.string, "String") && param._class.registered &&
1000 (param._class.registered.type == normalClass || param._class.registered.type == noHeadClass))
1002 f.Printf(" delete %s;\n", param.name);
1005 if(method.dataType.returnType.kind == classType && strcmp(method.dataType.returnType._class.string, "String") && method.dataType.returnType._class.registered &&
1006 (method.dataType.returnType._class.registered.type == normalClass || method.dataType.returnType._class.registered.type == noHeadClass))
1008 f.Printf(" delete __ecereResult;\n");
1012 f.Printf(" break;\n");
1024 vid = _class.base.vTblSize;
1026 next = (Method)_class.methods.first;
1027 while(next && ((next.type == virtualMethod) != doVirtual || (doVirtual && next.vid != vid)))
1030 next = (Method)((BTNode)next).next;
1031 if(!next && doVirtual)
1033 if(vid == _class.vTblSize)
1038 next = (Method)_class.methods.first;
1041 for(method = next; method; method = next)
1045 if(!method.dataType)
1046 method.dataType = ProcessTypeString(method.dataTypeString, false);
1048 if(method.dataType.name)
1054 strcpy(name, "__ecereVMethodID_");
1055 FullClassNameCat(name, method._class.fullName, true);
1057 strcat(name, method.name);
1058 DeclareMethod(method, name);
1060 f.Printf("virtual ");
1062 f.Printf("%s\n", method.dataTypeString);
1067 if(method.dataType.returnType.kind != voidType)
1069 TypeName resultType;
1070 OldList * specs = MkList();
1072 char type[1024] = "";
1073 char className[1024];
1076 if(method.dataType.returnType.kind == classType)
1077 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
1080 PrintType(method.dataType.returnType, type, false, true);
1081 classSym = FindClass(type);
1085 strcpy(className, "__ecereClass_");
1086 FullClassNameCat(className, classSym.string, true);
1087 MangleClassName(className);
1088 DeclareClass(classSym, className);
1090 PrintType(method.dataType.returnType, type, true, true);
1092 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
1093 resultType = MkTypeName(specs, decl);
1096 OutputTypeName(resultType, f);
1097 if(method.dataType.returnType.kind == structType)
1098 f.Printf(" = { 0 }");
1099 else if(method.dataType.returnType.kind == classType && method.dataType.returnType._class.registered && method.dataType.returnType._class.registered.type == structClass)
1105 //f.Printf(" incref this;\n");
1106 for(param = method.dataType.params.first; param; param = param.next)
1108 char type[1024] = "";
1109 char className[1024];
1112 if(param.kind == classType)
1113 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
1116 PrintType(param, type, false, true);
1117 classSym = FindClass(type);
1120 strcpy(className, "__ecereClass_");
1121 FullClassNameCat(className, classSym.string, true);
1123 MangleClassName(className);
1124 DeclareClass(classSym, className);
1126 if(param.kind == classType && !strcmp(param._class.string, "String"))
1128 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1129 f.Printf(" __ecereBuffer.Serialize((StaticString)%s);\n", param.name);
1132 f.Printf(" __ecereBuffer.Serialize(%s);\n", param.name);
1136 eSystem_FindClass(privateModule, "ecere::net::DCOMClientObject"), "CallMethod", privateModule),
1137 "__ecereMethod___ecereNameSpace__ecere__net__DCOMClientObject_CallMethod");
1139 f.Printf(" if(DCOMClientObject::CallMethod(%d))\n", id++);
1141 for(param = method.dataType.params.first; param; param = param.next)
1143 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
1145 if(!strcmp(param._class.string, "String"))
1147 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1148 f.Printf(" __ecereBuffer.Unserialize((StaticString)%s);\n", param.name);
1151 f.Printf(" __ecereBuffer.Unserialize(%s);\n", param.name);
1154 if(method.dataType.returnType.kind != voidType)
1156 if(method.dataType.returnType.kind == classType && !strcmp(method.dataType.returnType._class.string, "String"))
1158 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1159 f.Printf(" __ecereBuffer.Unserialize((StaticString)__ecereResult);\n");
1162 f.Printf(" __ecereBuffer.Unserialize(__ecereResult);\n");
1165 f.Printf(" __ecereBuffer.Free();\n");
1166 //f.Printf(" delete this;\n");
1167 if(method.dataType.returnType.kind != voidType)
1169 f.Printf(" return __ecereResult;\n");
1175 next = (Method)((BTNode)method).next;
1176 while(next && ((next.type == virtualMethod) != doVirtual || (doVirtual && next.vid != vid)))
1179 next = (Method)((BTNode)next).next;
1180 if(!next && doVirtual)
1182 if(vid == _class.vTblSize)
1187 next = (Method)_class.methods.first;
1202 static void BindDCOMServer()
1205 for(_class = privateModule.classes.first; _class; _class = _class.next)
1207 if(_class.isRemote == 3) //)
1214 if(!dcomSymbols) dcomSymbols = TempFile { };
1217 DeclareClass(FindClass("ecere::net::DCOMServerObject"), "__ecereClass___ecereNameSpace__ecere__net__DCOMServerObject");
1220 for(_class = privateModule.classes.first; _class; _class = _class.next)
1222 if(_class.isRemote == 3) //2 && !strncmp(_class.fullName, "DCOMServer_", strlen("DCOMServer_")))
1228 f.Printf("class DCOM%s : ecere::net::DCOMServerObject\n", _class.fullName);
1229 // f.Printf("class DCOM%s\n", _class.fullName);
1232 f.Printf(" %s instance;\n", _class.fullName);
1233 f.Printf(" unsigned int id;\n");
1234 f.Printf(" SerialBuffer buffer { };\n");
1238 f.Printf(" DCOM%s()\n", _class.fullName);
1240 f.Printf(" instance = eInstance_New(class(%s));\n", _class.fullName);
1244 f.Printf(" virtual void CallMethod(uint __ecereMethodID, SerialBuffer __ecereBuffer)\n");
1246 f.Printf(" switch(__ecereMethodID)\n");
1249 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
1252 method.dataType = ProcessTypeString(method.dataTypeString, false);
1253 if(method.dataType && method.dataType.name)
1255 f.Printf(" case %d:\n", id++);
1259 if(method.dataType.returnType.kind != voidType)
1261 TypeName resultType;
1262 OldList * specs = MkList();
1264 char type[1024] = "";
1265 char className[1024];
1268 if(method.dataType.returnType.kind == classType)
1269 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
1272 PrintType(method.dataType.returnType, type, false, true);
1273 classSym = FindClass(type);
1276 strcpy(className, "__ecereClass_");
1277 FullClassNameCat(className, classSym.string, true);
1278 MangleClassName(className);
1279 DeclareClass(classSym, className);
1281 PrintType(method.dataType.returnType, type, true, true);
1283 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
1284 resultType = MkTypeName(specs, decl);
1287 OutputTypeName(resultType, f);
1291 for(param = method.dataType.params.first; param; param = param.next)
1293 if(param.kind == classType && !strcmp(param._class.string, "String"))
1295 // Hardcode 1024 chars max string for now
1296 f.Printf(" char %s[1024];\n", param.name);
1297 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1298 DeclareClass(FindClass("String"), "__ecereClass_String");
1302 TypeName paramTypeName;
1303 OldList * specs = MkList();
1305 char type[1024] = "";
1306 char className[1024];
1309 if(param.kind == classType)
1310 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
1313 PrintType(param, type, false, true);
1314 classSym = FindClass(type);
1318 strcpy(className, "__ecereClass_");
1319 FullClassNameCat(className, classSym.string, true);
1320 MangleClassName(className);
1321 DeclareClass(classSym, className);
1323 PrintType(param, type, true, true);
1325 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier(param.name /*"__ecereResult"*/)));
1326 paramTypeName = MkTypeName(specs, decl);
1329 OutputTypeName(paramTypeName, f);
1336 for(param = method.dataType.params.first; param; param = param.next)
1338 f.Printf(" __ecereBuffer.Unserialize(");
1339 if(param.kind == classType && !strcmp(param._class.string, "String"))
1341 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1342 f.Printf("(StaticString)");
1349 if(method.dataType.returnType.kind != voidType)
1350 f.Printf("__ecereResult = ");
1352 // f.Printf("this.instance.%s(", method.name);
1353 f.Printf("((%s)instance).%s(", _class.fullName, method.name);
1355 for(param = method.dataType.params.first; param; param = param.next)
1359 f.Printf("%s", param.name);
1364 for(param = method.dataType.params.first; param; param = param.next)
1366 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
1368 if(!strcmp(param._class.string, "String"))
1370 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1371 f.Printf(" __ecereBuffer.Serialize((StaticString)%s);\n", param.name);
1374 f.Printf(" __ecereBuffer.Serialize(%s);\n", param.name);
1377 if(method.dataType.returnType.kind != voidType)
1379 f.Printf(" __ecereBuffer.Serialize(__ecereResult);\n");
1382 for(param = method.dataType.params.first; param; param = param.next)
1384 if(param.kind == classType && strcmp(param._class.string, "String") && param._class.registered &&
1385 (param._class.registered.type == normalClass || param._class.registered.type == noHeadClass))
1387 f.Printf(" delete %s;\n", param.name);
1390 if(method.dataType.returnType.kind == classType && strcmp(method.dataType.returnType._class.string, "String") && method.dataType.returnType._class.registered &&
1391 (method.dataType.returnType._class.registered.type == normalClass || method.dataType.returnType._class.registered.type == noHeadClass))
1393 f.Printf(" delete __ecereResult;\n");
1397 f.Printf(" break;\n");
1404 // *** VIRTUAL FUNCTIONS BINDINGS ***
1405 for(vid = _class.base.vTblSize; vid < _class.vTblSize; vid++)
1410 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
1411 if(method.type == virtualMethod && method._class == _class && method.vid == vid)
1416 if(!method.dataType)
1417 method.dataType = ProcessTypeString(method.dataTypeString, false);
1419 if(method.dataType.name)
1421 f.Printf(" virtual %s\n", method.dataTypeString);
1426 f.Printf(" DCOM%s __ecereObject = (void *)_vTbl[-1];\n", _class.fullName);
1427 if(method.dataType.returnType.kind != voidType)
1429 TypeName resultType;
1430 OldList * specs = MkList();
1432 char type[1024] = "";
1433 char className[1024];
1436 if(method.dataType.returnType.kind == classType)
1437 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
1440 PrintType(method.dataType.returnType, type, false, true);
1441 classSym = FindClass(type);
1445 strcpy(className, "__ecereClass_");
1446 FullClassNameCat(className, classSym.string, true);
1447 MangleClassName(className);
1448 DeclareClass(classSym, className);
1450 PrintType(method.dataType.returnType, type, true, true);
1452 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
1453 resultType = MkTypeName(specs, decl);
1456 OutputTypeName(resultType, f);
1457 if(method.dataType.returnType.kind == structType)
1458 f.Printf(" = { 0 }");
1459 else if(method.dataType.returnType.kind == classType && method.dataType.returnType._class.registered && method.dataType.returnType._class.registered.type == structClass)
1465 //f.Printf(" incref this;\n");
1466 for(param = method.dataType.params.first; param; param = param.next)
1468 char type[1024] = "";
1469 char className[1024];
1472 if(param.kind == classType)
1473 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
1476 PrintType(param, type, false, true);
1477 classSym = FindClass(type);
1480 strcpy(className, "__ecereClass_");
1481 FullClassNameCat(className, classSym.string, true);
1482 MangleClassName(className);
1483 DeclareClass(classSym, className);
1485 if(param.kind == classType && !strcmp(param._class.string, "String"))
1487 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1488 f.Printf(" __ecereObject.virtualsBuffer.Serialize((StaticString)%s);\n", param.name);
1491 f.Printf(" __ecereObject.virtualsBuffer.Serialize(%s);\n", param.name);
1496 eSystem_FindClass(privateModule, "ecere::net::DCOMServerObject"), "CallVirtualMethod", privateModule),
1497 "__ecereMethod___ecereNameSpace__ecere__net__DCOMServerObject_CallVirutalMethod");
1499 f.Printf(" if(__ecereObject.CallVirtualMethod(%d))\n", vid - _class.base.vTblSize);
1501 for(param = method.dataType.params.first; param; param = param.next)
1503 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
1505 if(!strcmp(param._class.string, "String"))
1507 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1508 f.Printf(" __ecereObject.virtualsBuffer.Unserialize((StaticString)%s);\n", param.name);
1511 f.Printf(" __ecereObject.virtualsBuffer.Unserialize(%s);\n", param.name);
1514 if(method.dataType.returnType.kind != voidType)
1516 if(method.dataType.returnType.kind == classType && !strcmp(method.dataType.returnType._class.string, "String"))
1518 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1519 f.Printf(" __ecereObject.virtualsBuffer.Unserialize((StaticString)__ecereResult);\n");
1522 f.Printf(" __ecereObject.virtualsBuffer.Unserialize(__ecereResult);\n");
1525 f.Printf(" else\n");
1526 f.Printf(" ((%s)this).%s::%s(", _class.fullName, _class.fullName, method.name);
1527 for(param = method.dataType.params.first; param; param = param.next)
1529 f.Printf("%s", param.name);
1530 if(param.next) f.Printf(", ");
1534 f.Printf(" __ecereObject.virtualsBuffer.Free();\n");
1535 //f.Printf(" delete this;\n");
1536 if(method.dataType.returnType.kind != voidType)
1538 f.Printf(" return __ecereResult;\n");
1543 /*if(vid < _class.vTblSize)
1554 class SymbolgenApp : Application
1559 char ** argv = null;
1564 char * output = null;
1566 targetPlatform = GetRuntimePlatform();
1569 for(c = 0; c<this.argc; c++)
1571 char * arg = this.argv[c];
1572 int argLen = strlen(arg);
1574 argv = renew argv char *[argc + 1];
1575 argv[argc] = new char[argLen+1];
1576 strcpy(argv[argc], arg);
1578 while(argv[argc][argLen-1] == '\\' && c < this.argc-1)
1585 argv[argc] = renew argv[argc] char[argLen + len + 1];
1587 argv[argc][argLen-1] = ' ';
1588 strcpy(argv[argc] + argLen, arg);
1595 for(c = 1; c<argc; c++)
1597 char * arg = argv[c];
1600 if(!strcmp(arg+1, "o"))
1602 if(!output && c + 1 < argc)
1610 else if(!strcmp(arg, "-name"))
1614 strcpy(projectName, argv[c+1]);
1620 else if(!strcmp(arg, "-t"))
1623 targetPlatform = argv[c];
1627 else if(!strcmp(arg, "-console"))
1629 else if(!strcmp(arg, "-dynamiclib"))
1630 isDynamicLibrary = true;
1631 else if(!strcmp(arg, "-staticlib"))
1633 isDynamicLibrary = true; // TOFIX: unmixup
1634 isStaticLibrary = true;
1636 else if(!strcmp(arg, "-symbols"))
1640 SetSymbolsDir(argv[c+1]);
1652 printf("Syntax:\n ecs [-t <target platform>] <input>[, <input>]* -o <output>\n");
1656 char ext[MAX_EXTENSION];
1657 char symbolModule[MAX_FILENAME];
1658 GetExtension(output, ext);
1659 GetLastDirectory(output, symbolModule);
1661 SetDefines(&::_defines);
1662 SetImports(&_imports);
1663 SetGlobalData(&globalData);
1664 SetExcludedSymbols(&_excludedSymbols);
1665 SetGlobalContext(theGlobalContext);
1666 SetTopContext(theGlobalContext);
1667 SetCurrentContext(theGlobalContext);
1668 SetTargetPlatform(targetPlatform);
1670 privateModule = __ecere_COM_Initialize(true, 1, null);
1671 SetPrivateModule(privateModule);
1672 mainModule = ModuleImport { };
1673 SetMainModule(mainModule);
1674 _imports.Add(mainModule);
1676 //if(!strcmp(ext, "c"))
1678 File potFile = null;
1679 Map<String, String> intlStrings { };
1680 MapIterator<String, String> it { map = intlStrings };
1682 for(c = 1; c<argc; c++)
1684 char * file = argv[c];
1687 if(!strcmp(file, "-c"))
1692 char ext[MAX_EXTENSION];
1693 GetExtension(file,ext);
1694 if(!strcmp(ext, "imp"))
1699 // What is this supposed to do?
1700 for(c = 1; c<argc; c++)
1702 char * file = argv[c];
1705 if(!strcmp(file, "-c"))
1710 for(c = 1; c<argc; c++)
1712 char * file = argv[c];
1715 // Don't even know what it does here?
1716 if(!strcmp(file, "-c"))
1721 char ext[MAX_EXTENSION];
1722 char moduleName[MAX_LOCATION];
1724 GetExtension(file,ext);
1726 GetLastDirectory(file, moduleName);
1727 StripExtension(moduleName);
1728 strcat(moduleName, ".ec");
1730 if(fstrcmp(moduleName, symbolModule) && (!strcmp(ext, "sym") || !strcmp(ext, "ec")))
1732 ImportedModule importedModule;
1733 ModuleInfo module { };
1734 char fileName[MAX_FILENAME];
1735 ::modules.Add(module);
1737 GetLastDirectory(file, fileName);
1739 module.name = CopyString(fileName);
1741 StripExtension(module.name);
1743 for(importedModule = ::_defines.first; importedModule; importedModule = importedModule.next)
1745 if(importedModule.type == moduleDefinition && !strcmpi(importedModule.name, module.name) && !(importedModule.importType == remoteImport))
1750 module.globalInstance = importedModule.globalInstance;
1753 importedModule = ImportedModule
1755 name = CopyString(module.name),
1756 type = moduleDefinition,
1757 importType = normalImport
1759 ::_defines.AddName(importedModule);
1761 module.globalInstance = LoadSymbols(file, normalImport, false);
1762 CheckDataRedefinitions();
1768 ChangeExtension(file, "bowl", fileName);
1769 f = FileOpen(fileName, read);
1774 char potFileName[MAX_LOCATION];
1775 strcpy(potFileName, output);
1776 StripExtension(potFileName);
1777 ChangeExtension(potFileName, "pot", potFileName);
1778 potFile = FileOpen(potFileName, write);
1780 potFile.Printf("# %s\n", moduleName);
1783 String comment = null, msgid = null, msgstr = null;
1785 for(c = 0; c < 4; c++)
1787 static char line[65536];
1788 if(f.GetLine(line, sizeof(line)))
1790 if(c == 0) comment = CopyString(line);
1791 else if(c == 1) msgid = CopyString(line);
1792 else if(c == 2) msgstr = CopyString(line);
1795 if(msgid && !it.Index(msgid, false))
1798 intlStrings[msgid] = comment;
1799 potFile.Puts(comment); potFile.Puts("\n");
1800 potFile.Puts(msgid); potFile.Puts("\n");
1801 potFile.Puts(msgstr); potFile.Puts("\n");
1815 ComputeModuleClasses(privateModule);
1817 if(!isDynamicLibrary)
1819 // applicationClass = eSystem_FindClass(privateModule, "Application");
1821 thisAppClass = FindAppClass(&privateModule.application.publicNameSpace, true);
1823 thisAppClass = FindAppClass(&privateModule.application.privateNameSpace, true);
1825 thisAppClass = FindAppClass(&privateModule.application.publicNameSpace, false);
1827 thisAppClass = FindAppClass(&privateModule.application.privateNameSpace, false);
1829 thisAppClass = SearchAppClass_Module(privateModule);
1839 FreeContext(theGlobalContext);
1840 FreeExcludedSymbols(_excludedSymbols);
1842 ::_defines.Free(FreeModuleDefine);
1843 _imports.Free(FreeModuleImport);
1845 //precompDefines.Free(FreeDefinition);
1847 FreeTypeData(privateModule);
1849 FreeGlobalData(globalData);
1851 delete privateModule;
1854 SetSymbolsDir(null); // Free symbols dir
1857 for(c = 0; c<argc; c++)