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, ' ', '_');
268 f.Puts("#include <libintl.h>\n\n");
269 if(targetPlatform == win32 && !isConsole && !isStaticLibrary && !isDynamicLibrary)
271 //f.Puts("#include <windows.h>\n\n");
273 f.Puts("typedef void * HINSTANCE;\n");
274 f.Puts("#define WINAPI __stdcall\n");
277 for(importedModule = ::_defines.first; importedModule; importedModule = importedModule.next)
279 if(importedModule.type == moduleDefinition)
282 if(importedModule.importType == staticImport)
283 f.Printf("static ", importedModule.name);
284 f.Printf("\"%s\"\n", importedModule.name);
288 f.Puts("default:\n");
289 f.Puts("static Module __currentModule;\n\n");
292 f.Puts("Module __thisModule;\n\n");
294 // TOCHECK: Problem compiling Scrabble.main.ec when binding Client first
299 f.Printf("void __ecereRegisterModule_%s(Module module);\n\n", mainModuleName);
301 for(module = _imports.first; module; module = module.next)
304 FunctionImport function;
305 if(module.importType == staticImport)
307 /*if(targetPlatform == win32)
309 f.Printf("bool __stdcall __ecereDll_Load_%s(Module module);\n", module.name);
310 f.Printf("bool __stdcall __ecereDll_Unload_%s(Module module);\n", module.name);
314 f.Printf("bool __ecereDll_Load_%s(Module module);\n", module.name);
315 f.Printf("bool __ecereDll_Unload_%s(Module module);\n", module.name);
318 for(_class = module.classes.first; _class; _class = _class.next)
322 char className[1024] = "";
323 Class regClass = eSystem_FindClass(privateModule, _class.name);
325 FullClassNameCat(className, _class.name, true);
326 MangleClassName(className);
329 f.Printf("Class __ecereClass_%s;\n", className);
332 //if(!_class.isRemote)
334 //if(strcmp(_class.name, "SerialBuffer"))
336 for(method = _class.methods.first; method; method = method.next)
338 Method meth = eClass_FindMethod(regClass, method.name, privateModule);
339 if(meth && !meth.dataType)
341 Context context = SetupTemplatesContext(regClass);
342 meth.dataType = ProcessTypeString(meth.dataTypeString, false);
343 FinishTemplatesContext(context);
347 f.Printf("int __ecereVMethodID_%s_%s;\n", className, method.name);
348 else if(module.name && module.importType != staticImport && (!meth || !meth.dataType.dllExport))
358 sprintf(name, "__ecereMethod_%s_%s", className, method.name);
359 PrintType(type, name, true);
360 f.Printf("%s;\n", name);
363 //f.Printf("void * __ecereMethod_%s_%s;\n", className, method.name);
365 f.Printf("int (*__ecereMethod_%s_%s)();\n", className, method.name);
372 for(prop = _class.properties.first; prop; prop = prop.next)
376 FullClassNameCat(propName, prop.name, true);
377 // strcpy(propName, prop.name);
378 MangleClassName(propName);
380 if(module.name && module.importType != staticImport)
383 f.Printf("void * __ecereProp_%s_Set_%s;\n", className, propName);
385 f.Printf("void * __ecereProp_%s_Get_%s;\n", className, propName);
387 f.Printf("Property __ecereProp_%s_%s;\n", className, propName);
392 for(function = module.functions.first; function; function = function.next)
394 GlobalFunction func = eSystem_FindFunction(privateModule, function.name);
395 if(func && !func.dataType)
396 func.dataType = ProcessTypeString(func.dataTypeString, false);
398 if(module.name && module.importType != staticImport && (!func || !func.dataType || !func.dataType.dllExport))
400 char functionName[1024];
402 FullClassNameCat(functionName, function.name, false);
403 f.Printf("void * __ecereFunction_%s;\n", functionName);
409 for(defModule = ::modules.first; defModule; defModule = defModule.next)
411 char moduleName[1024];
412 strcpy(moduleName, defModule.name);
413 ChangeCh(moduleName, ' ', '_');
414 ChangeCh(moduleName, '-', '_');
415 ChangeCh(moduleName, '.', '_');
417 f.Printf("void __ecereRegisterModule_%s(Module module);\n", moduleName);
418 f.Printf("void __ecereUnregisterModule_%s(Module module);\n", moduleName);
419 if(defModule.globalInstance)
421 f.Printf("void __ecereCreateModuleInstances_%s();\n", moduleName);
422 f.Printf("void __ecereDestroyModuleInstances_%s();\n", moduleName);
431 // Insert DCOM bindings here
432 dcomSymbols.Seek(0, start);
433 while(!dcomSymbols.Eof())
436 int read = dcomSymbols.Read(buffer, 1, sizeof(buffer));
438 f.Write(buffer, 1, read);
447 /*if(targetPlatform == win32)
448 f.Printf("\nbool __stdcall __ecereDll_Load_%s(Module module)\n{\n", projectName);
450 f.Printf("\nbool __ecereDll_Load_%s(Module module)\n{\n", projectName);
452 else if(isDynamicLibrary)
454 if(targetPlatform == win32)
455 f.Puts("\ndllexport bool __stdcall __ecereDll_Load(Module module)\n{\n");
457 f.Puts("\ndllexport bool __ecereDll_Load(Module module)\n{\n");
459 else if(targetPlatform == win32 && !isConsole)
461 f.Puts("\nint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, char * cmdLine, int show)\n{\n");
464 f.Puts("\nint main(int _argc, char * _argv[])\n{\n");
466 if(!isDynamicLibrary)
468 f.Puts(" int exitCode;\n");
469 f.Puts(" Module module;\n");
472 //if(nonInst || thisAppClass) // We use it all the time to get "Application" for the exit code now...
473 f.Puts(" Class _class;\n");
476 f.Puts(" Method method;\n");
478 f.Puts(" Property _property;\n");
480 f.Puts(" GlobalFunction function;\n");
486 f.Puts(" if(!__currentModule)\n");
488 f.Puts(" __currentModule = module;\n");
490 f.Puts(" __thisModule = module;\n");
493 else if(targetPlatform == win32 && !isConsole)
494 f.Puts(" __thisModule = __currentModule = module = __ecere_COM_Initialize(1, 0, null);\n\n");
496 f.Puts(" __thisModule = __currentModule = module = __ecere_COM_Initialize(1, _argc, (void *)_argv);\n\n");
500 f.Printf(" bindtextdomain(\"%s\", \"%s\");\n", projectName, localeDir);
501 f.Printf(" textdomain(\"%s\");\n", projectName);
502 f.Printf(" bind_textdomain_codeset (\"%s\", \"utf-8\");\n", projectName);
505 // First load all modules
508 for(module = _imports.first; module; module = module.next)
512 //if(strcmp(module.name, "ecereCOM") && strcmp(module.name, "ecere") )
514 if(module.importType == staticImport)
515 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);
517 f.Printf(" eModule_Load(module, \"%s\", %s);\n", module.name, (module.importAccess == privateAccess) ? "privateAccess" : "publicAccess");
524 // Then define the classes
527 for(defModule = ::modules.first; defModule; defModule = defModule.next)
529 char moduleName[1024];
530 strcpy(moduleName, defModule.name);
531 ChangeCh(moduleName, ' ', '_');
532 ChangeCh(moduleName, '-', '_');
533 ChangeCh(moduleName, '.', '_');
535 f.Printf(" __ecereRegisterModule_%s(module);\n", moduleName);
540 // Register Remote Modules
543 f.Printf(" __ecereRegisterModule_%s(module);\n\n", mainModuleName);
549 f.Puts(" if(__currentModule == module)\n");
552 // Then load the imports
553 for(module = _imports.first; module; module = module.next)
556 FunctionImport function;
557 if(module.classes.count)
559 for(_class = module.classes.first; _class; _class = _class.next)
561 Class regClass = eSystem_FindClass(privateModule, _class.name);
563 //if(!_class.isRemote)
568 char className[1024] = "";
569 FullClassNameCat(className, _class.name, true);
570 MangleClassName(className);
573 sprintf(classID, "__ecereClass_%s", className);
575 strcpy(classID, "_class");
577 if(isDynamicLibrary && !isStaticLibrary)
578 f.Printf(" %s = eSystem_FindClass(__currentModule, \"%s\");\n", classID, _class.name);
580 f.Printf(" %s = eSystem_FindClass(module, \"%s\");\n", classID, _class.name);
582 for(method = _class.methods.first; method; method = method.next)
584 Method meth = eClass_FindMethod(regClass, method.name, privateModule);
585 if(!meth || !meth.dataType.dllExport)
587 if(method.isVirtual || (module.name && module.importType != staticImport))
589 f.Printf(" method = eClass_FindMethod(%s, \"%s\", module);\n",
590 classID, method.name);
592 f.Printf(" if(method) __ecereVMethodID_%s_%s = method.vid;\n", className, method.name);
594 f.Printf(" if(method) __ecereMethod_%s_%s = method.function;\n", className, method.name);
599 for(prop = _class.properties.first; prop; prop = prop.next)
603 FullClassNameCat(propName, prop.name, true);
604 // strcpy(propName, prop.name);
605 MangleClassName(propName);
607 f.Printf(" __ecereProp_%s_%s = _property = eClass_FindProperty(%s, \"%s\", module);\n",
608 className, propName, classID, prop.name);
610 if(module.name && module.importType != staticImport)
613 f.Printf(" __ecereProp_%s_Set_%s = _property.Set;\n", className, propName);
615 f.Printf(" __ecereProp_%s_Get_%s = _property.Get;\n", className, propName);
622 if(module.functions.count)
624 for(function = module.functions.first; function; function = function.next)
626 GlobalFunction func = eSystem_FindFunction(privateModule, function.name);
627 if(module.name && module.importType != staticImport && (!func || !func.dataType || !func.dataType.dllExport))
629 char functionName[1024];
631 FullClassNameCat(functionName, function.name, false);
633 if(isDynamicLibrary && !isStaticLibrary)
634 f.Printf(" function = eSystem_FindFunction(__currentModule, \"%s\");\n", function.name);
636 f.Printf(" function = eSystem_FindFunction(module, \"%s\");\n", function.name);
638 f.Printf(" if(function) __ecereFunction_%s = function.function;\n", functionName);
648 //f.Printf(" module._vTbl[10](module);\n");
652 if(!isDynamicLibrary && thisAppClass)
654 f.Printf(" _class = eSystem_FindClass(__currentModule, \"%s\");\n", thisAppClass.name);
655 f.Printf(" eInstance_Evolve((Instance *)&__currentModule, _class);\n");
656 f.Printf(" __thisModule = __currentModule;\n");
661 f.Puts(" if(__currentModule == module)\n");
665 // Then check if there's any global instances to create
668 for(defModule = ::modules.first; defModule; defModule = defModule.next)
669 if(defModule.globalInstance)
671 char moduleName[1024];
672 strcpy(moduleName, defModule.name);
673 ChangeCh(moduleName, ' ', '_');
674 ChangeCh(moduleName, '-', '_');
675 ChangeCh(moduleName, '.', '_');
677 f.Printf(" __ecereCreateModuleInstances_%s();\n", moduleName);
687 if(!isDynamicLibrary && thisAppClass)
689 f.Printf(" __currentModule._vTbl[12](__currentModule);\n");
694 f.Puts(" return true;\n");
698 /*if(targetPlatform == win32)
699 f.Printf("\nbool __stdcall __ecereDll_Unload_%s(Module module)\n{\n", projectName);
701 f.Printf("\nbool __ecereDll_Unload_%s(Module module)\n{\n", projectName);
705 if(targetPlatform == win32)
706 f.Puts("\ndllexport bool __stdcall __ecereDll_Unload(Module module)\n{\n");
708 f.Puts("\ndllexport bool __ecereDll_Unload(Module module)\n{\n");
714 f.Puts(" if(__currentModule == module)\n");
717 // Then check if there's any global instances to destroy
720 for(defModule = ::modules.first; defModule; defModule = defModule.next)
721 if(defModule.globalInstance)
723 char moduleName[1024];
724 strcpy(moduleName, defModule.name);
725 ChangeCh(moduleName, ' ', '_');
726 ChangeCh(moduleName, '-', '_');
727 ChangeCh(moduleName, '.', '_');
728 f.Printf(" __ecereDestroyModuleInstances_%s();\n", moduleName);
739 //f.Printf(" module._vTbl[11](module);\n");
744 for(defModule = ::modules.first; defModule; defModule = defModule.next)
746 char moduleName[1024];
747 strcpy(moduleName, defModule.name);
748 ChangeCh(moduleName, ' ', '_');
749 ChangeCh(moduleName, '-', '_');
750 ChangeCh(moduleName, '.', '_');
751 f.Printf(" __ecereUnregisterModule_%s(module);\n", moduleName);
755 f.Puts(" if(__currentModule == module)\n");
756 f.Puts(" __currentModule = (void *)0;\n");
759 f.Puts(" if(__thisModule == module)\n");
760 f.Puts(" __thisModule = (void *)0;\n");
764 if(!isDynamicLibrary)
768 " _class = eSystem_FindClass(__currentModule, \"ecere::com::Application\");\n"
769 " exitCode = ((ecere::com::Application)__currentModule).exitCode;\n"
770 " delete __currentModule;\n"
771 " return exitCode;\n");
774 f.Puts(" return true;\n");
780 static Class FindAppClass(NameSpace * nameSpace, bool thisModule)
784 for(link = (BTNamedLink)nameSpace->classes.first; link; link = (BTNamedLink)((BTNode)link).next)
786 Class _class = link.data;
788 applicationClass = eSystem_FindClass(_class.module, "Application");
789 if(_class != applicationClass && eClass_IsDerived(_class, applicationClass) && (!thisModule || _class.module == privateModule))
792 if(strcmp(_class.fullName, "ecere::com::Application") && (!thisModule || _class.module == privateModule))
795 for(base = _class.base; base && base.type != systemClass; base = base.base)
796 if(!strcmp(base.fullName, "ecere::com::Application"))
801 for(ns = (NameSpace *)nameSpace->nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
803 Class _class = FindAppClass(ns, thisModule);
804 if(_class) // && _class != applicationClass)
807 return null; //applicationClass;
810 static Class SearchAppClass_Module(Module module)
815 appClass = FindAppClass(module.publicNameSpace, false);
816 if(appClass) return appClass;
817 appClass = FindAppClass(module.privateNameSpace, false);
818 if(appClass) return appClass;
820 for(subModule = module.modules.first; subModule; subModule = subModule.next)
822 appClass = SearchAppClass_Module(subModule.module);
823 if(appClass) return appClass;
828 static void BindDCOMClient()
830 Class dcomClientObjectClass = eSystem_FindClass(privateModule, "ecere::net::DCOMClientObject");
833 if(dcomClientObjectClass && dcomClientObjectClass.derivatives.first)
836 if(!dcomSymbols) dcomSymbols = TempFile { };
840 for(deriv = dcomClientObjectClass.derivatives.first; deriv; deriv = deriv.next)
842 Class _class = deriv.data;
848 DeclareClass(FindClass("ecere::net::DCOMClientObject"), "__ecereClass___ecereNameSpace__ecere__net__DCOMClientObject");
849 f.Printf("class %s : ecere::net::DCOMClientObject\n", _class.fullName);
852 // CLIENT VIRTUAL METHODS BINDINGS
853 if(_class.vTblSize > _class.base.vTblSize)
856 f.Printf(" virtual void CallVirtualMethod(uint __ecereMethodID, SerialBuffer __ecereBuffer)\n");
858 f.Printf(" switch(__ecereMethodID)\n");
861 for(vid = _class.base.vTblSize; vid < _class.vTblSize; vid++)
864 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
866 if(method.type == virtualMethod && method._class == _class && method.vid == vid)
872 method.dataType = ProcessTypeString(method.dataTypeString, false);
873 if(method.dataType && method.dataType.name)
875 f.Printf(" case %d:\n", vid - _class.base.vTblSize);
878 if(method.dataType.returnType.kind != voidType)
881 OldList * specs = MkList();
883 char type[1024] = "";
884 char className[1024];
887 if(method.dataType.returnType.kind == classType)
888 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
891 PrintType(method.dataType.returnType, type, false, true);
892 classSym = FindClass(type);
895 strcpy(className, "__ecereClass_");
896 FullClassNameCat(className, classSym.string, true);
897 MangleClassName(className);
898 DeclareClass(classSym, className);
900 PrintType(method.dataType.returnType, type, true, true);
902 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
903 resultType = MkTypeName(specs, decl);
906 OutputTypeName(resultType, f);
910 for(param = method.dataType.params.first; param; param = param.next)
912 if(param.kind == classType && !strcmp(param._class.string, "String"))
914 // Hardcode 1024 chars max string for now
915 f.Printf(" char %s[1024];\n", param.name);
916 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
917 DeclareClass(FindClass("String"), "__ecereClass_String");
921 TypeName paramTypeName;
922 OldList * specs = MkList();
924 char type[1024] = "";
925 char className[1024];
928 if(param.kind == classType)
929 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
932 PrintType(param, type, false, true);
933 classSym = FindClass(type);
937 strcpy(className, "__ecereClass_");
938 FullClassNameCat(className, classSym.string, true);
939 MangleClassName(className);
940 DeclareClass(classSym, className);
942 PrintType(param, type, true, true);
944 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier(param.name /*"__ecereResult"*/)));
945 paramTypeName = MkTypeName(specs, decl);
948 OutputTypeName(paramTypeName, f);
955 for(param = method.dataType.params.first; param; param = param.next)
957 f.Printf(" __ecereBuffer.Unserialize(");
958 if(param.kind == classType && !strcmp(param._class.string, "String"))
960 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
961 f.Printf("(StaticString)");
968 if(method.dataType.returnType.kind != voidType)
969 f.Printf("__ecereResult = ");
971 // f.Printf("this.instance.%s(", method.name);
972 f.Printf("%s(", method.name);
974 for(param = method.dataType.params.first; param; param = param.next)
978 f.Printf("%s", param.name);
983 for(param = method.dataType.params.first; param; param = param.next)
985 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
987 if(!strcmp(param._class.string, "String"))
989 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
990 f.Printf(" __ecereBuffer.Serialize((StaticString)%s);\n", param.name);
993 f.Printf(" __ecereBuffer.Serialize(%s);\n", param.name);
996 if(method.dataType.returnType.kind != voidType)
998 f.Printf(" __ecereBuffer.Serialize(__ecereResult);\n");
1001 for(param = method.dataType.params.first; param; param = param.next)
1003 if(param.kind == classType && strcmp(param._class.string, "String") && param._class.registered &&
1004 (param._class.registered.type == normalClass || param._class.registered.type == noHeadClass))
1006 f.Printf(" delete %s;\n", param.name);
1009 if(method.dataType.returnType.kind == classType && strcmp(method.dataType.returnType._class.string, "String") && method.dataType.returnType._class.registered &&
1010 (method.dataType.returnType._class.registered.type == normalClass || method.dataType.returnType._class.registered.type == noHeadClass))
1012 f.Printf(" delete __ecereResult;\n");
1016 f.Printf(" break;\n");
1028 vid = _class.base.vTblSize;
1030 next = (Method)_class.methods.first;
1031 while(next && ((next.type == virtualMethod) != doVirtual || (doVirtual && next.vid != vid)))
1034 next = (Method)((BTNode)next).next;
1035 if(!next && doVirtual)
1037 if(vid == _class.vTblSize)
1042 next = (Method)_class.methods.first;
1045 for(method = next; method; method = next)
1049 if(!method.dataType)
1050 method.dataType = ProcessTypeString(method.dataTypeString, false);
1052 if(method.dataType.name)
1058 strcpy(name, "__ecereVMethodID_");
1059 FullClassNameCat(name, method._class.fullName, true);
1061 strcat(name, method.name);
1062 DeclareMethod(method, name);
1064 f.Printf("virtual ");
1066 f.Printf("%s\n", method.dataTypeString);
1071 if(method.dataType.returnType.kind != voidType)
1073 TypeName resultType;
1074 OldList * specs = MkList();
1076 char type[1024] = "";
1077 char className[1024];
1080 if(method.dataType.returnType.kind == classType)
1081 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
1084 PrintType(method.dataType.returnType, type, false, true);
1085 classSym = FindClass(type);
1089 strcpy(className, "__ecereClass_");
1090 FullClassNameCat(className, classSym.string, true);
1091 MangleClassName(className);
1092 DeclareClass(classSym, className);
1094 PrintType(method.dataType.returnType, type, true, true);
1096 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
1097 resultType = MkTypeName(specs, decl);
1100 OutputTypeName(resultType, f);
1101 if(method.dataType.returnType.kind == structType)
1102 f.Printf(" = { 0 }");
1103 else if(method.dataType.returnType.kind == classType && method.dataType.returnType._class.registered && method.dataType.returnType._class.registered.type == structClass)
1109 //f.Printf(" incref this;\n");
1110 for(param = method.dataType.params.first; param; param = param.next)
1112 char type[1024] = "";
1113 char className[1024];
1116 if(param.kind == classType)
1117 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
1120 PrintType(param, type, false, true);
1121 classSym = FindClass(type);
1124 strcpy(className, "__ecereClass_");
1125 FullClassNameCat(className, classSym.string, true);
1127 MangleClassName(className);
1128 DeclareClass(classSym, className);
1130 if(param.kind == classType && !strcmp(param._class.string, "String"))
1132 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1133 f.Printf(" __ecereBuffer.Serialize((StaticString)%s);\n", param.name);
1136 f.Printf(" __ecereBuffer.Serialize(%s);\n", param.name);
1140 eSystem_FindClass(privateModule, "ecere::net::DCOMClientObject"), "CallMethod", privateModule),
1141 "__ecereMethod___ecereNameSpace__ecere__net__DCOMClientObject_CallMethod");
1143 f.Printf(" if(DCOMClientObject::CallMethod(%d))\n", id++);
1145 for(param = method.dataType.params.first; param; param = param.next)
1147 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
1149 if(!strcmp(param._class.string, "String"))
1151 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1152 f.Printf(" __ecereBuffer.Unserialize((StaticString)%s);\n", param.name);
1155 f.Printf(" __ecereBuffer.Unserialize(%s);\n", param.name);
1158 if(method.dataType.returnType.kind != voidType)
1160 if(method.dataType.returnType.kind == classType && !strcmp(method.dataType.returnType._class.string, "String"))
1162 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1163 f.Printf(" __ecereBuffer.Unserialize((StaticString)__ecereResult);\n");
1166 f.Printf(" __ecereBuffer.Unserialize(__ecereResult);\n");
1169 f.Printf(" __ecereBuffer.Free();\n");
1170 //f.Printf(" delete this;\n");
1171 if(method.dataType.returnType.kind != voidType)
1173 f.Printf(" return __ecereResult;\n");
1179 next = (Method)((BTNode)method).next;
1180 while(next && ((next.type == virtualMethod) != doVirtual || (doVirtual && next.vid != vid)))
1183 next = (Method)((BTNode)next).next;
1184 if(!next && doVirtual)
1186 if(vid == _class.vTblSize)
1191 next = (Method)_class.methods.first;
1206 static void BindDCOMServer()
1209 for(_class = privateModule.classes.first; _class; _class = _class.next)
1211 if(_class.isRemote == 3) //)
1218 if(!dcomSymbols) dcomSymbols = TempFile { };
1221 DeclareClass(FindClass("ecere::net::DCOMServerObject"), "__ecereClass___ecereNameSpace__ecere__net__DCOMServerObject");
1224 for(_class = privateModule.classes.first; _class; _class = _class.next)
1226 if(_class.isRemote == 3) //2 && !strncmp(_class.fullName, "DCOMServer_", strlen("DCOMServer_")))
1232 f.Printf("class DCOM%s : ecere::net::DCOMServerObject\n", _class.fullName);
1233 // f.Printf("class DCOM%s\n", _class.fullName);
1236 f.Printf(" %s instance;\n", _class.fullName);
1237 f.Printf(" unsigned int id;\n");
1238 f.Printf(" SerialBuffer buffer { };\n");
1242 f.Printf(" DCOM%s()\n", _class.fullName);
1244 f.Printf(" instance = eInstance_New(class(%s));\n", _class.fullName);
1248 f.Printf(" virtual void CallMethod(uint __ecereMethodID, SerialBuffer __ecereBuffer)\n");
1250 f.Printf(" switch(__ecereMethodID)\n");
1253 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
1256 method.dataType = ProcessTypeString(method.dataTypeString, false);
1257 if(method.dataType && method.dataType.name)
1259 f.Printf(" case %d:\n", id++);
1263 if(method.dataType.returnType.kind != voidType)
1265 TypeName resultType;
1266 OldList * specs = MkList();
1268 char type[1024] = "";
1269 char className[1024];
1272 if(method.dataType.returnType.kind == classType)
1273 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
1276 PrintType(method.dataType.returnType, type, false, true);
1277 classSym = FindClass(type);
1280 strcpy(className, "__ecereClass_");
1281 FullClassNameCat(className, classSym.string, true);
1282 MangleClassName(className);
1283 DeclareClass(classSym, className);
1285 PrintType(method.dataType.returnType, type, true, true);
1287 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
1288 resultType = MkTypeName(specs, decl);
1291 OutputTypeName(resultType, f);
1295 for(param = method.dataType.params.first; param; param = param.next)
1297 if(param.kind == classType && !strcmp(param._class.string, "String"))
1299 // Hardcode 1024 chars max string for now
1300 f.Printf(" char %s[1024];\n", param.name);
1301 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1302 DeclareClass(FindClass("String"), "__ecereClass_String");
1306 TypeName paramTypeName;
1307 OldList * specs = MkList();
1309 char type[1024] = "";
1310 char className[1024];
1313 if(param.kind == classType)
1314 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
1317 PrintType(param, type, false, true);
1318 classSym = FindClass(type);
1322 strcpy(className, "__ecereClass_");
1323 FullClassNameCat(className, classSym.string, true);
1324 MangleClassName(className);
1325 DeclareClass(classSym, className);
1327 PrintType(param, type, true, true);
1329 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier(param.name /*"__ecereResult"*/)));
1330 paramTypeName = MkTypeName(specs, decl);
1333 OutputTypeName(paramTypeName, f);
1340 for(param = method.dataType.params.first; param; param = param.next)
1342 f.Printf(" __ecereBuffer.Unserialize(");
1343 if(param.kind == classType && !strcmp(param._class.string, "String"))
1345 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1346 f.Printf("(StaticString)");
1353 if(method.dataType.returnType.kind != voidType)
1354 f.Printf("__ecereResult = ");
1356 // f.Printf("this.instance.%s(", method.name);
1357 f.Printf("((%s)instance).%s(", _class.fullName, method.name);
1359 for(param = method.dataType.params.first; param; param = param.next)
1363 f.Printf("%s", param.name);
1368 for(param = method.dataType.params.first; param; param = param.next)
1370 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
1372 if(!strcmp(param._class.string, "String"))
1374 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1375 f.Printf(" __ecereBuffer.Serialize((StaticString)%s);\n", param.name);
1378 f.Printf(" __ecereBuffer.Serialize(%s);\n", param.name);
1381 if(method.dataType.returnType.kind != voidType)
1383 f.Printf(" __ecereBuffer.Serialize(__ecereResult);\n");
1386 for(param = method.dataType.params.first; param; param = param.next)
1388 if(param.kind == classType && strcmp(param._class.string, "String") && param._class.registered &&
1389 (param._class.registered.type == normalClass || param._class.registered.type == noHeadClass))
1391 f.Printf(" delete %s;\n", param.name);
1394 if(method.dataType.returnType.kind == classType && strcmp(method.dataType.returnType._class.string, "String") && method.dataType.returnType._class.registered &&
1395 (method.dataType.returnType._class.registered.type == normalClass || method.dataType.returnType._class.registered.type == noHeadClass))
1397 f.Printf(" delete __ecereResult;\n");
1401 f.Printf(" break;\n");
1408 // *** VIRTUAL FUNCTIONS BINDINGS ***
1409 for(vid = _class.base.vTblSize; vid < _class.vTblSize; vid++)
1414 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
1415 if(method.type == virtualMethod && method._class == _class && method.vid == vid)
1420 if(!method.dataType)
1421 method.dataType = ProcessTypeString(method.dataTypeString, false);
1423 if(method.dataType.name)
1425 f.Printf(" virtual %s\n", method.dataTypeString);
1430 f.Printf(" DCOM%s __ecereObject = (void *)_vTbl[-1];\n", _class.fullName);
1431 if(method.dataType.returnType.kind != voidType)
1433 TypeName resultType;
1434 OldList * specs = MkList();
1436 char type[1024] = "";
1437 char className[1024];
1440 if(method.dataType.returnType.kind == classType)
1441 classSym = method.dataType.returnType._class; // VERIFY THIS FindClass(method.dataType.returnType._class.string);
1444 PrintType(method.dataType.returnType, type, false, true);
1445 classSym = FindClass(type);
1449 strcpy(className, "__ecereClass_");
1450 FullClassNameCat(className, classSym.string, true);
1451 MangleClassName(className);
1452 DeclareClass(classSym, className);
1454 PrintType(method.dataType.returnType, type, true, true);
1456 decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult")));
1457 resultType = MkTypeName(specs, decl);
1460 OutputTypeName(resultType, f);
1461 if(method.dataType.returnType.kind == structType)
1462 f.Printf(" = { 0 }");
1463 else if(method.dataType.returnType.kind == classType && method.dataType.returnType._class.registered && method.dataType.returnType._class.registered.type == structClass)
1469 //f.Printf(" incref this;\n");
1470 for(param = method.dataType.params.first; param; param = param.next)
1472 char type[1024] = "";
1473 char className[1024];
1476 if(param.kind == classType)
1477 classSym = param._class; // VERIFY THIS FindClass(param._class.string);
1480 PrintType(param, type, false, true);
1481 classSym = FindClass(type);
1484 strcpy(className, "__ecereClass_");
1485 FullClassNameCat(className, classSym.string, true);
1486 MangleClassName(className);
1487 DeclareClass(classSym, className);
1489 if(param.kind == classType && !strcmp(param._class.string, "String"))
1491 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1492 f.Printf(" __ecereObject.virtualsBuffer.Serialize((StaticString)%s);\n", param.name);
1495 f.Printf(" __ecereObject.virtualsBuffer.Serialize(%s);\n", param.name);
1500 eSystem_FindClass(privateModule, "ecere::net::DCOMServerObject"), "CallVirtualMethod", privateModule),
1501 "__ecereMethod___ecereNameSpace__ecere__net__DCOMServerObject_CallVirutalMethod");
1503 f.Printf(" if(__ecereObject.CallVirtualMethod(%d))\n", vid - _class.base.vTblSize);
1505 for(param = method.dataType.params.first; param; param = param.next)
1507 if(param.kind == classType && ((param._class && param._class.registered && param._class.registered.type == structClass) || !strcmp(param._class.string, "String")) && !param.constant)
1509 if(!strcmp(param._class.string, "String"))
1511 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1512 f.Printf(" __ecereObject.virtualsBuffer.Unserialize((StaticString)%s);\n", param.name);
1515 f.Printf(" __ecereObject.virtualsBuffer.Unserialize(%s);\n", param.name);
1518 if(method.dataType.returnType.kind != voidType)
1520 if(method.dataType.returnType.kind == classType && !strcmp(method.dataType.returnType._class.string, "String"))
1522 DeclareClass(FindClass("StaticString"), "__ecereClass_StaticString");
1523 f.Printf(" __ecereObject.virtualsBuffer.Unserialize((StaticString)__ecereResult);\n");
1526 f.Printf(" __ecereObject.virtualsBuffer.Unserialize(__ecereResult);\n");
1529 f.Printf(" else\n");
1530 f.Printf(" ((%s)this).%s::%s(", _class.fullName, _class.fullName, method.name);
1531 for(param = method.dataType.params.first; param; param = param.next)
1533 f.Printf("%s", param.name);
1534 if(param.next) f.Printf(", ");
1538 f.Printf(" __ecereObject.virtualsBuffer.Free();\n");
1539 //f.Printf(" delete this;\n");
1540 if(method.dataType.returnType.kind != voidType)
1542 f.Printf(" return __ecereResult;\n");
1547 /*if(vid < _class.vTblSize)
1558 class SymbolgenApp : Application
1563 char ** argv = null;
1568 char * output = null;
1570 targetPlatform = GetRuntimePlatform();
1573 for(c = 0; c<this.argc; c++)
1575 char * arg = this.argv[c];
1576 int argLen = strlen(arg);
1578 argv = renew argv char *[argc + 1];
1579 argv[argc] = new char[argLen+1];
1580 strcpy(argv[argc], arg);
1582 while(argv[argc][argLen-1] == '\\' && c < this.argc-1)
1589 argv[argc] = renew argv[argc] char[argLen + len + 1];
1591 argv[argc][argLen-1] = ' ';
1592 strcpy(argv[argc] + argLen, arg);
1599 for(c = 1; c<argc; c++)
1601 char * arg = argv[c];
1604 if(!strcmp(arg+1, "o"))
1606 if(!output && c + 1 < argc)
1614 else if(!strcmp(arg, "-name"))
1618 strcpy(projectName, argv[c+1]);
1624 else if(!strcmp(arg, "-t"))
1627 targetPlatform = argv[c];
1631 else if(!strcmp(arg, "-console"))
1633 else if(!strcmp(arg, "-dynamiclib"))
1634 isDynamicLibrary = true;
1635 else if(!strcmp(arg, "-staticlib"))
1637 isDynamicLibrary = true; // TOFIX: unmixup
1638 isStaticLibrary = true;
1640 else if(!strcmp(arg, "-symbols"))
1644 SetSymbolsDir(argv[c+1]);
1656 printf("Syntax:\n ecs [-t <target platform>] <input>[, <input>]* -o <output>\n");
1660 char ext[MAX_EXTENSION];
1661 char symbolModule[MAX_FILENAME];
1662 GetExtension(output, ext);
1663 GetLastDirectory(output, symbolModule);
1665 SetDefines(&::_defines);
1666 SetImports(&_imports);
1667 SetGlobalData(&globalData);
1668 SetExcludedSymbols(&_excludedSymbols);
1669 SetGlobalContext(theGlobalContext);
1670 SetTopContext(theGlobalContext);
1671 SetCurrentContext(theGlobalContext);
1672 SetTargetPlatform(targetPlatform);
1674 privateModule = __ecere_COM_Initialize(true, 1, null);
1675 SetPrivateModule(privateModule);
1676 mainModule = ModuleImport { };
1677 SetMainModule(mainModule);
1678 _imports.Add(mainModule);
1680 //if(!strcmp(ext, "c"))
1682 File potFile = null;
1683 Map<String, String> intlStrings { };
1684 MapIterator<String, String> it { map = intlStrings };
1686 for(c = 1; c<argc; c++)
1688 char * file = argv[c];
1691 if(!strcmp(file, "-c"))
1696 char ext[MAX_EXTENSION];
1697 GetExtension(file,ext);
1698 if(!strcmp(ext, "imp"))
1703 // What is this supposed to do?
1704 for(c = 1; c<argc; c++)
1706 char * file = argv[c];
1709 if(!strcmp(file, "-c"))
1714 for(c = 1; c<argc; c++)
1716 char * file = argv[c];
1719 // Don't even know what it does here?
1720 if(!strcmp(file, "-c"))
1725 char ext[MAX_EXTENSION];
1726 char moduleName[MAX_LOCATION];
1728 GetExtension(file,ext);
1730 GetLastDirectory(file, moduleName);
1731 StripExtension(moduleName);
1732 strcat(moduleName, ".ec");
1734 if(fstrcmp(moduleName, symbolModule) && (!strcmp(ext, "sym") || !strcmp(ext, "ec")))
1736 ImportedModule importedModule;
1737 ModuleInfo module { };
1738 char fileName[MAX_FILENAME];
1739 ::modules.Add(module);
1741 GetLastDirectory(file, fileName);
1743 module.name = CopyString(fileName);
1745 StripExtension(module.name);
1747 for(importedModule = ::_defines.first; importedModule; importedModule = importedModule.next)
1749 if(importedModule.type == moduleDefinition && !strcmpi(importedModule.name, module.name) && !(importedModule.importType == remoteImport))
1754 module.globalInstance = importedModule.globalInstance;
1757 importedModule = ImportedModule
1759 name = CopyString(module.name),
1760 type = moduleDefinition,
1761 importType = normalImport
1763 ::_defines.AddName(importedModule);
1765 module.globalInstance = LoadSymbols(file, normalImport, false);
1766 CheckDataRedefinitions();
1772 ChangeExtension(file, "bowl", fileName);
1773 f = FileOpen(fileName, read);
1778 char potFileName[MAX_LOCATION];
1779 strcpy(potFileName, output);
1780 StripExtension(potFileName);
1781 ChangeExtension(potFileName, "pot", potFileName);
1782 potFile = FileOpen(potFileName, write);
1784 potFile.Printf("# %s\n", moduleName);
1787 String comment = null, msgid = null, msgstr = null;
1789 for(c = 0; c < 4; c++)
1791 static char line[65536];
1792 if(f.GetLine(line, sizeof(line)))
1794 if(c == 0) comment = CopyString(line);
1795 else if(c == 1) msgid = CopyString(line);
1796 else if(c == 2) msgstr = CopyString(line);
1799 if(msgid && !it.Index(msgid, false))
1802 intlStrings[msgid] = comment;
1803 potFile.Puts(comment); potFile.Puts("\n");
1804 potFile.Puts(msgid); potFile.Puts("\n");
1805 potFile.Puts(msgstr); potFile.Puts("\n");
1819 ComputeModuleClasses(privateModule);
1821 if(!isDynamicLibrary)
1823 // applicationClass = eSystem_FindClass(privateModule, "Application");
1825 thisAppClass = FindAppClass(&privateModule.application.publicNameSpace, true);
1827 thisAppClass = FindAppClass(&privateModule.application.privateNameSpace, true);
1829 thisAppClass = FindAppClass(&privateModule.application.publicNameSpace, false);
1831 thisAppClass = FindAppClass(&privateModule.application.privateNameSpace, false);
1833 thisAppClass = SearchAppClass_Module(privateModule);
1843 FreeContext(theGlobalContext);
1844 FreeExcludedSymbols(_excludedSymbols);
1846 ::_defines.Free(FreeModuleDefine);
1847 _imports.Free(FreeModuleImport);
1849 //precompDefines.Free(FreeDefinition);
1851 FreeTypeData(privateModule);
1853 FreeGlobalData(globalData);
1855 delete privateModule;
1858 SetSymbolsDir(null); // Free symbols dir
1861 for(c = 0; c<argc; c++)