buildsystem,ecc,ecp,ecs,ide; (#1055) allow cross-compile from 64 bit sdk to Android...
[sdk] / compiler / ecc / ecc.ec
1 #ifdef ECERE_STATIC
2 import static "ecere"
3 import static "ec"
4 #else
5 import "ecere"
6 import "ec"
7 #endif
8
9
10 //#include <stdarg.h>
11
12 static Context globalContext { };
13 static Module privateModule;
14 static ModuleImport mainModule;
15 static OldList _excludedSymbols { offset = (uint)&((Symbol)0).left };
16 static OldList defines, imports;
17 static NameSpace globalData
18 {
19    classes.CompareKey = (void *)BinaryTree::CompareString;
20    defines.CompareKey = (void *)BinaryTree::CompareString;
21    functions.CompareKey = (void *)BinaryTree::CompareString;
22    nameSpaces.CompareKey = (void *)BinaryTree::CompareString;
23 };
24
25 static void OutputImports(char * fileName)
26 {
27    File f = FileOpen(fileName, write);
28    if(f)
29    {
30       if(imports.first)
31       {
32          ModuleImport module;
33          f.Printf("[Imported Modules]\n");
34          for(module = imports.first; module; module = module.next)
35          {
36             ClassImport _class;
37             FunctionImport function;
38
39             if(module.name)
40                f.Printf("   %s\n", module.name);
41             else
42                f.Printf("   [This]\n");
43             if(module.importType == staticImport)
44                f.Printf("      [Static]\n");
45             else if(module.importType == remoteImport)
46                f.Printf("      [Remote]\n");
47
48             if(module.importAccess == privateAccess)
49                f.Printf("      [Private]\n");
50             else
51                f.Printf("      [Public]\n");
52
53             if(module.classes.first)
54             {
55                f.Printf("      [Imported Classes]\n");
56                for(_class = module.classes.first; _class; _class = _class.next)
57                {
58                   f.Printf("         %s\n", _class.name);
59                   if(_class.itself)
60                   {
61                      f.Printf("            [Instantiated]\n");
62                   }
63                   if(_class.isRemote)
64                   {
65                      f.Printf("            [Remote]\n");
66                   }
67
68                   if(_class.methods.first)
69                   {
70                      MethodImport method;
71                      f.Printf("            [Imported Methods]\n");
72                      for(method = _class.methods.first; method; method = method.next)
73                      {
74                         f.Printf("               %s\n", method.name);
75                         if(method.isVirtual)
76                            f.Printf("                  [Virtual]\n");
77
78                      }
79                      f.Printf("               .\n");
80                   }
81
82                   if(_class.properties.first)
83                   {
84                      PropertyImport prop;
85                      f.Printf("            [Imported Properties]\n");
86                      for(prop = _class.properties.first; prop; prop = prop.next)
87                      {
88                         f.Printf("               %s\n", prop.name);
89                         if(prop.isVirtual)
90                            f.Printf("                  [Virtual]\n");
91                         if(prop.hasSet)
92                            f.Printf("                  [Set]\n");
93                         if(prop.hasGet)
94                            f.Printf("                  [Get]\n");
95                      }
96                      f.Printf("               .\n");
97                   }
98                }
99                f.Printf("        .\n");
100             }
101             if(module.functions.first)
102             {
103                f.Printf("      [Imported Functions]\n");
104                for(function = module.functions.first; function; function = function.next)
105                {
106                   f.Printf("         %s\n", function.name);
107                }
108                f.Printf("        .\n");
109             }
110          }
111          f.Printf("   .\n");
112       }
113    }
114    delete f;
115 }
116
117 #ifdef _DEBUG
118 static bool TestType(String string, String expected)
119 {
120    bool result = true;
121    char typeString[1024] = { 0 };
122    Type type = ProcessTypeString(string, false);
123    PrintType(type, typeString, true, false);//true);
124    if(strcmp(typeString, expected ? expected : string))
125    {
126       PrintLn("FAILED: ", string, " -> ", typeString);
127       result = false;
128    }
129    return result;
130 }
131
132 static void TestTypes()
133 {
134    int succeeded = 0, count = 0;
135
136    count++, succeeded += TestType("dllexport void (dllexport * Module::signal(int, void (*)(int)))(int)", null);
137    count++, succeeded += TestType("int (* f[8])[10]", null);
138    count++, succeeded += TestType("void (* signal(int, void (*)(int)))(int)", null);
139    count++, succeeded += TestType("void (* signal(double))()", null);
140    count++, succeeded += TestType("void (* bla)(int)", null);
141    count++, succeeded += TestType("int f(void (*[10])())", null);
142    count++, succeeded += TestType("void (*[10])()", null);
143    count++, succeeded += TestType("void (* converters_table[10])()", null);
144    count++, succeeded += TestType("int (* f[8])[10]", null);
145
146    count++, succeeded += TestType("int f[8][10]", null);
147    count++, succeeded += TestType("int f[10]", null);
148    count++, succeeded += TestType("void *", null);
149    count++, succeeded += TestType("char * x", "char * x");
150    count++, succeeded += TestType("char * x", null);
151    count++, succeeded += TestType("char (* x[3])()", null);
152    count++, succeeded += TestType("char (*(* x[3])())", "char * (* x[3])()");
153    count++, succeeded += TestType("char (* x())", "char * x()");
154    count++, succeeded += TestType("char (* (* x[3])())[5]", null);
155    count++, succeeded += TestType("char (* f())[5]", null);
156    count++, succeeded += TestType("char * (* f())[5]", null);
157    count++, succeeded += TestType("char * (* * f())[5][2][3]", null);
158    count++, succeeded += TestType("char * (* * (* f)())[5][2][3]", null);
159    count++, succeeded += TestType("char * (* (* * (* f)())[5][2])[3]", null);
160    count++, succeeded += TestType("void (* (* bar)[5])()", null);
161    count++, succeeded += TestType("const int * (* const f)(char[10])", null);
162    count++, succeeded += TestType("const int", null);
163    count++, succeeded += TestType("int * const *", null);
164    count++, succeeded += TestType("int * const", null);
165    count++, succeeded += TestType("const int *", null);
166
167    count++, succeeded += TestType("char * const (* (* const bar)[5])(int)", null);
168    count++, succeeded += TestType("char * const (* (* (* const bar)[5][6])(int))[2]", null);
169    count++, succeeded += TestType("int * * a", null);
170
171    count++, succeeded += TestType("char * const (* bar)()", null);
172
173    count++, succeeded += TestType("char * const (* const (* const bar)[5])(int)", null);
174
175    count++, succeeded += TestType("char * (* const (* bar)[5])(int)", null);
176    count++, succeeded += TestType("void (* * const bar[5])()", null);
177    count++, succeeded += TestType("void (* * const bar)()", null);
178    count++, succeeded += TestType("void (* const * bar)()", null);
179    count++, succeeded += TestType("const int * * foo", null); // this prevents you from doing: **foo = 0;
180    count++, succeeded += TestType("int * const * bar", null); // this prevents you from doing: *bar = 0;
181    count++, succeeded += TestType("int * * const two", null); // this prevents you from doing: two = 0;
182    count++, succeeded += TestType("dllexport int TestFunction()", null);
183    count++, succeeded += TestType("dllexport int (* TestFunction())[3]", null);
184
185
186    count++, succeeded += TestType("int dllexport TestFunction()", "dllexport int TestFunction()");
187    count++, succeeded += TestType("bool (stdcall * Load)(Module module)", null);
188
189    count++, succeeded += TestType("bool (__attribute__((stdcall)) * Load)(Module module)", "bool (stdcall * Load)(Module module)");
190    count++, succeeded += TestType("int (dllexport * Load)()", null);
191    count++, succeeded += TestType("int (* Load)(Module module)", null);
192    count++, succeeded += TestType("bool (__declspec(dllexport) * Load)(Module module)", "bool (dllexport * Load)(Module module)");
193    count++, succeeded += TestType("__declspec(dllexport) int TestFunction()", "dllexport int TestFunction()");
194    count++, succeeded += TestType("int __declspec(dllexport) TestFunction()", "dllexport int TestFunction()");
195    count++, succeeded += TestType("int __attribute__((dllexport)) TestFunction()", "dllexport int TestFunction()");
196    count++, succeeded += TestType("bool (__attribute__((dllexport)) * Load)(Module module)", "bool (dllexport * Load)(Module module)");
197    count++, succeeded += TestType("any_object TestFunction(any_object, typed_object param)", null);
198    count++, succeeded += TestType("void typed_object::OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)", null);
199    count++, succeeded += TestType("int typed_object::OnCompare(any_object object)", null);
200    count++, succeeded += TestType("char * typed_object::OnGetString(char * tempString, void * fieldData, bool * needClass)", null);
201    count++, succeeded += TestType("void typed_object&::OnCopy(any_object newData)", null);
202    count++, succeeded += TestType("void typed_object::OnFree(void)", null);
203    count++, succeeded += TestType("bool typed_object&::OnGetDataFromString(char * string)", null);
204    count++, succeeded += TestType("Window typed_object::OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)", null);
205    count++, succeeded += TestType("void typed_object::OnSerialize(IOChannel channel)", null);
206    count++, succeeded += TestType("void typed_object&::OnUnserialize(IOChannel channel)", null);
207    count++, succeeded += TestType("bool typed_object&::OnSaveEdit(Window window, void * object)", null);
208    count++, succeeded += TestType("void ::StaticMethod(IOChannel channel)", null);
209
210    count++, succeeded += TestType("void PrintLn(typed_object object, ...)", null);
211    count++, succeeded += TestType("void PrintLn(typed_object object, ...)", null);
212
213    count++, succeeded += TestType("thisclass RemoveSwapRight()", null);
214    count++, succeeded += TestType("struct { thisclass prev; thisclass next; }", null);
215
216    count++, succeeded += TestType("LinkElement<thisclass>", null);
217
218    count++, succeeded += TestType("void (dllexport * converters_table[10])()", null);
219
220    count++, succeeded += TestType("bool (stdcall * * Load)(Module module)", null);
221
222    count++, succeeded += TestType("int stdcall TestFunction()", "stdcall int TestFunction()");
223    count++, succeeded += TestType("dllexport stdcall void test()", null);
224
225    count++, succeeded += TestType("bool (* Module::notifySelect)(MenuItem selection, Modifiers mods)", null);
226
227    count++, succeeded += TestType("typed_object &", null);
228
229    PrintLn("\n", succeeded, " / ", count, " tests succeeded.");
230 }
231 #endif
232
233 class CompilerApp : Application
234 {
235    void Main()
236    {
237       char * cppCommand = null;
238       char * cppOptions = null;
239       int cppOptionsLen = 0;
240       /*char ** argv = null;
241       int argc = 0;*/
242       int c;
243       bool valid = true;
244       char defaultOutputFile[MAX_LOCATION];
245       bool buildingBootStrap = false;
246
247       Platform targetPlatform = GetRuntimePlatform();
248       int targetBits = GetHostBits();
249
250 #ifdef _DEBUG
251       // buildingBootStrap = true;
252 #endif
253
254       SetSymbolsDir("");
255
256       /*for(c = 0; c<this.argc; c++)
257       {
258          char * arg = this.argv[c];
259          int argLen = strlen(arg);
260
261          argv = renew argv char *[argc + 1];
262          argv[argc] = new char[argLen+1];
263          strcpy(argv[argc], arg);
264
265          while(argv[argc][argLen-1] == '\\' && c < this.argc-1)
266          {
267             int len;
268
269             c++;
270             arg = this.argv[c];
271             len = strlen(arg);
272             argv[argc] = renew argv[argc] char[argLen + len + 1];
273
274             argv[argc][argLen-1] = ' ';
275             strcpy(argv[argc] + argLen, arg);
276             argLen += len;
277          }
278          argc++;
279       }*/
280
281 #ifdef _DEBUG
282       printf("\nArguments given:\n");
283       for(c=1; c<argc; c++)
284          printf(" %s", argv[c]);
285       printf("\n\n");
286       for(c=1; c<argc; c++)
287          PrintLn("Arg", c, ": ", argv[c]);
288       printf("\n");
289       //getch();
290 #endif
291
292       for(c = 1; c<argc; c++)
293       {
294          char * arg = argv[c];
295          if(arg[0] == '-')
296          {
297             if(!strcmp(arg + 1, "m32") || !strcmp(arg + 1, "m64"))
298             {
299                int newLen = cppOptionsLen + 1 + strlen(arg);
300                cppOptions = renew cppOptions char[newLen + 1];
301                cppOptions[cppOptionsLen] = ' ';
302                strcpy(cppOptions + cppOptionsLen + 1, arg);
303                cppOptionsLen = newLen;
304                targetBits = !strcmp(arg + 1, "m32") ? 32 : 64;
305             }
306             else if(!strcmp(arg + 1, "t32") || !strcmp(arg + 1, "t64"))
307             {
308                targetBits = !strcmp(arg + 1, "t32") ? 32 : 64;
309             }
310             else if(arg[1] == 'D' || arg[1] == 'I')
311             {
312                char * buf;
313                int size = cppOptionsLen + 1 + strlen(arg) * 2 + 1;
314                cppOptions = renew cppOptions char[size];
315                buf = cppOptions + cppOptionsLen;
316                *buf++ = ' ';
317                PassArg(buf, arg);
318                cppOptionsLen = cppOptionsLen + 1 + strlen(buf);
319                if(arg[1] == 'D')
320                {
321                   if(!strcmp(arg, "-DBUILDING_ECERE_COM"))
322                      SetBuildingEcereCom(true);
323                   else if(!strcmp(arg, "-DECERE_COM_MODULE"))
324                      SetBuildingEcereComModule(true);
325                   else if(!strcmp(arg, "-DECERE_BOOTSTRAP"))
326                      buildingBootStrap = true;
327                }
328             }
329             else if(!strcmp(arg+1, "t"))
330             {
331                if(++c < argc)
332                   targetPlatform = argv[c];
333                else
334                   valid = false;
335             }
336             else if(!strcmp(arg+1, "cpp"))
337             {
338                if(++c < argc)
339                   cppCommand = CopyString(argv[c]);
340                else
341                   valid = false;
342             }
343             else if(!strcmp(arg+1, "o"))
344             {
345                if(!GetOutputFile() && c + 1 < argc)
346                {
347                   SetOutputFile(argv[c+1]);
348                   c++;
349                }
350                else
351                   valid = false;
352             }
353             else if(!strcmp(arg+1, "c"))
354             {
355                if(!GetSourceFile() && c + 1 < argc)
356                {
357                   SetSourceFile(argv[c+1]);
358                   c++;
359                }
360                else
361                   valid = false;
362             }
363             else if(!strcmp(arg+1, "isystem") || !strcmp(arg+1, "isysroot"))
364             {
365                if(c + 1 < argc)
366                {
367                   char * buf;
368                   char * arg1 = argv[++c];
369                   int size = cppOptionsLen + 1 + strlen(arg) * 2 + strlen(arg1) * 2 + 1;
370                   cppOptions = renew cppOptions char[size];
371                   buf = cppOptions + cppOptionsLen;
372                   *buf++ = ' ';
373                   buf = PassArg(buf, arg);
374                   *buf++ = ' ';
375                   buf = PassArg(buf, arg1);
376                   cppOptionsLen = buf - cppOptions;
377                }
378                else
379                   valid = false;
380             }
381             else if(!strcmp(arg+1, "fno-diagnostics-show-caret"))
382             {
383                char * buf;
384                int size = cppOptionsLen + 1 + strlen(arg) * 2 + 1;
385                cppOptions = renew cppOptions char[size];
386                buf = cppOptions + cppOptionsLen;
387                *buf++ = ' ';
388                PassArg(buf, arg);
389                cppOptionsLen = cppOptionsLen + 1 + strlen(buf);
390             }
391             else if(!strcmp(arg+1, "symbols"))
392             {
393                if(c + 1 < argc)
394                {
395                   SetSymbolsDir(argv[c+1]);
396                   c++;
397                }
398                else
399                   valid = false;
400             }
401             else if(!strcmp(arg+1, "memguard"))
402             {
403                SetMemoryGuard(true);
404             }
405             else if(!strcmp(arg+1, "defaultns"))
406             {
407                if(c + 1 < argc)
408                {
409                   SetDefaultNameSpace(argv[c+1]);
410                   //defaultNameSpaceLen = strlen(defaultNameSpace);
411                   c++;
412                }
413                else
414                   valid = false;
415             }
416             else if(!strcmp(arg+1, "strictns"))
417             {
418                SetStrictNameSpaces(true);
419             }
420             else if(!strcmp(arg+1, "nolinenumbers"))
421             {
422                SetOutputLineNumbers(false);
423             }
424          }
425          else
426             valid = false;
427       }
428       if(valid)
429       {
430          if(!cppCommand)
431             cppCommand = CopyString("gcc");
432          if(!GetSourceFile())
433             valid = false;
434          else if(!GetOutputFile())
435          {
436             strcpy(defaultOutputFile, "");
437             PathCat(defaultOutputFile, GetSourceFile());
438             ChangeExtension(defaultOutputFile, "c", defaultOutputFile);
439             SetOutputFile(defaultOutputFile);
440          }
441       }
442
443       if(!valid)
444       {
445          printf($"Syntax:\n   ecc [-t <target platform>] [-cpp <c preprocessor>] [-o <output>] [-symbols <outputdir>] [-I<includedir>]* [-isystem <sysincludedir>]* [-D<definition>]* -c <input>\n");
446       }
447       else
448       {
449          DualPipe cppOutput;
450          // TODO: Improve this
451          char command[MAX_F_STRING*3];
452          SetGlobalData(&globalData);
453          SetExcludedSymbols(&_excludedSymbols);
454          SetGlobalContext(globalContext);
455          SetCurrentContext(globalContext);
456          SetTopContext(globalContext);
457          SetDefines(&::defines);
458          SetImports(&imports);
459          SetInCompiler(true);
460          SetTargetPlatform(targetPlatform);
461          SetTargetBits(targetBits);
462          SetEchoOn(false);
463
464          privateModule = (Module)__ecere_COM_Initialize(true | (targetBits == sizeof(uintptr)*8 ? 0 : targetBits == 64 ? 2 : targetBits==32 ? 4 : 0) | 8, 1, null);
465          SetPrivateModule(privateModule);
466
467          globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
468          globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
469          globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
470          globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
471          globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
472          if(buildingBootStrap)
473          {
474             // Do not define this when we pre-include stdint.h or the eC compiler will be confused when parsing these types (External prioritization in pass15.ec will fail)
475             globalContext.types.Add((BTNode)Symbol { string = CopyString("intptr_t"), type = ProcessTypeString("intptr", false) });
476             globalContext.types.Add((BTNode)Symbol { string = CopyString("uintptr_t"), type = ProcessTypeString("uintptr", false) });
477             globalContext.types.Add((BTNode)Symbol { string = CopyString("ssize_t"), type = ProcessTypeString("intsize", false) });
478             globalContext.types.Add((BTNode)Symbol { string = CopyString("size_t"), type = ProcessTypeString("uintsize", false) });
479          }
480
481 #ifdef _DEBUG
482          // TestTypes();
483 #endif
484
485          {
486             GlobalData data { fullName = CopyString("__thisModule"), dataTypeString = CopyString("Module"), module = privateModule };
487             data.key = (uintptr)data.fullName;
488             globalData.functions.Add((BTNode)data);
489          }
490
491          snprintf(command, sizeof(command), "%s%s -x c -E %s\"%s\"", cppCommand, cppOptions ? cppOptions : "", buildingBootStrap ? "" : "-include stdint.h -include sys/types.h ", GetSourceFile());
492          command[sizeof(command)-1] = 0;
493 #ifdef _DEBUG
494          PrintLn("ECC Executing:");
495          PrintLn(command);
496 #endif
497          if((cppOutput = DualPipeOpen({ output = true }, command)))
498          {
499             char impFile[MAX_LOCATION];
500             ImportedModule module;
501             char sourceFileName[MAX_FILENAME];
502             char mainModuleName[MAX_FILENAME];
503             int exitCode;
504             OldList * ast;
505
506             TempFile fileInput { };
507             SetFileInput(fileInput);
508
509             imports.Add((mainModule = ModuleImport { }));
510             SetMainModule(mainModule);
511
512             GetLastDirectory(GetSourceFile(), sourceFileName);
513             strcpy(mainModuleName, sourceFileName);
514
515 #if 0
516             // TEMP: UNTIL WE CAN HAVE PER SOURCE FILE PREPROCESSOR DEFINITIONS...
517             if(GetBuildingEcereCom() &&
518                !(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
519                strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
520                strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
521                strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
522                strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
523                strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
524                strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
525                strcmpi(mainModuleName, "Mutex.ec")))
526                SetBuildingEcereComModule(true);
527             if(GetBuildingEcereCom() &&
528                !(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
529                /*strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&*/
530                /*strcmpi(mainModuleName, "String.ec") && */strcmpi(mainModuleName, "BTNode.ec") &&
531                strcmpi(mainModuleName, "Mutex.ec") && strcmpi(mainModuleName, "Thread.ec")))
532             //if(GetBuildingEcereCom() && !strcmpi(mainModuleName, "instance.ec"))
533                SetMemoryGuard(false);
534 #endif
535
536             StripExtension(mainModuleName);
537             module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
538             ::defines.AddName(module);
539
540             resetScanner();
541             while(!cppOutput.Eof())
542             {
543                char junk[4096];
544                int count = cppOutput.Read(junk, 1, 4096);
545                fileInput.Write(junk, 1, count);
546             }
547             exitCode = cppOutput.GetExitCode();
548             delete cppOutput;
549
550             fileInput.Seek(0, start);
551
552    #ifdef _DEBUG
553             // SetYydebug(true);
554    #endif
555
556             // Predeclare all classes
557             {
558                char symFile[MAX_FILENAME];
559                char symLocation[MAX_LOCATION];
560                ImportedModule module, next;
561
562                strcpy(symFile, sourceFileName);
563                ChangeExtension(symFile, "sym", symFile);
564
565                strcpy(symLocation, GetSymbolsDir());
566                PathCat(symLocation, symFile);
567
568                // LoadSymbols(symLocation, normalImport, true);
569                LoadSymbols(symLocation, preDeclImport, false);
570
571                for(module = ::defines.first; module; module = next)
572                {
573                   next = module.next;
574                   if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
575                   {
576                      delete module.name;
577                      ::defines.Delete(module);
578                   }
579                }
580
581                if(!GetEcereImported() && !GetBuildingEcereCom())
582                   eModule_LoadStrict(privateModule, "ecereCOM", publicAccess /*privateAccess*/);
583             }
584
585             ParseEc();
586
587             CheckDataRedefinitions();
588
589             SetYydebug(false);
590             SetCurrentNameSpace(null);
591             SetDefaultNameSpace(null);
592             SetDeclMode(privateAccess);
593
594             delete fileInput;
595             SetFileInput(null);
596
597             ast = GetAST();
598
599             if(/*ast /*&& !parseError*/ /*&& */!exitCode)
600             {
601                ProcessDBTableDefinitions();
602
603                // *** PASS 0 - Register all classes, methods, properties and members ***
604                // ***          Build the constructors, destructors, properties as    ***
605                // ***          class functions                                       ***
606                PrePreProcessClassDefinitions();
607                ComputeModuleClasses(privateModule);
608                PreProcessClassDefinitions();
609
610                // For classes defined in this module...
611                ComputeModuleClasses(privateModule);
612
613
614                // *** PASS 1 - Turn the class functions into functions               ***
615                // *** Write the RegisterModule (Register classes)                    ***
616                ProcessClassDefinitions();
617
618                // *** PASS 1.5 - Replace members by this.member, figure out types, do type checking / conversions
619                ComputeDataTypes();
620
621                // *** PASS 1.6 - Replace instantiations
622                ProcessInstantiations();
623
624                // *** PASS 2 - Replace Member Access ***
625                ProcessMemberAccess();
626
627                // *** PASS 3 - Replace pointers to objects by "Instance *" ***
628                ProcessInstanceDeclarations();
629
630                strcpy(impFile, GetSymbolsDir());
631                PathCat(impFile, sourceFileName);
632                ChangeExtension(impFile, "imp", impFile);
633                if(imports.first)
634                   OutputImports(impFile);
635                // For now use precomp to generate sym file only...
636
637                if(/*!strcmp(targetExt, "c") && */!this.exitCode)
638                {
639                   File output = FileOpen(GetOutputFile(), write);
640                   if(output)
641                   {
642                      output.Printf("/* Code generated from eC source file: %s */\n", sourceFileName);
643                      output.Printf("#if defined(__GNUC__)\n");
644                         output.Printf("typedef long long int64;\n");
645                         output.Printf("typedef unsigned long long uint64;\n");
646                         output.Printf("#ifndef _WIN32\n");
647                            output.Printf("#define __declspec(x)\n");
648                         output.Printf("#endif\n");
649                      output.Printf("#elif defined(__TINYC__)\n");
650                         output.Printf("#include <stdarg.h>\n");
651                         output.Printf("#define __builtin_va_list va_list\n");
652                         output.Printf("#define __builtin_va_start va_start\n");
653                         output.Printf("#define __builtin_va_end va_end\n");
654                         output.Printf("#ifdef _WIN32\n");
655                            output.Printf("#define strcasecmp stricmp\n");
656                            output.Printf("#define strncasecmp strnicmp\n");
657                            output.Printf("#define __declspec(x) __attribute__((x))\n");
658                         output.Printf("#else\n");
659                            output.Printf("#define __declspec(x)\n");
660                         output.Printf("#endif\n");
661                         output.Printf("typedef long long int64;\n");
662                         output.Printf("typedef unsigned long long uint64;\n");
663                      output.Printf("#else\n");
664                         output.Printf("typedef __int64 int64;\n");
665                         output.Printf("typedef unsigned __int64 uint64;\n");
666                      output.Printf("#endif\n");
667                      output.Printf("#ifdef __BIG_ENDIAN__\n");
668                         output.Printf("#define __ENDIAN_PAD(x) (8 - (x))\n");
669                      output.Printf("#else\n");
670                         output.Printf("#define __ENDIAN_PAD(x) 0\n");
671                      output.Printf("#endif\n");
672                      if(buildingBootStrap)
673                      {
674                         //output.Printf("#ifdef __MINGW32__\n");
675                         //output.Printf("#ifdef _WIN64\n");
676                         /*
677                         output.Printf("#if defined(_WIN64) || WORDSIZE == 64\n");
678                         output.Printf("typedef unsigned long long int uintptr_t;\n");
679                         output.Printf("typedef long long int intptr_t;\n");
680                         output.Printf("#else\n");
681                         output.Printf("typedef unsigned int uintptr_t;\n");
682                         output.Printf("typedef int intptr_t;\n");
683                         output.Printf("#endif\n");
684                         */
685                         //output.Printf("#else\n");
686                         output.Printf("#include <stdint.h>\n");
687                         output.Printf("#include <sys/types.h>\n");
688                         //output.Printf("#endif\n");
689                      }
690
691                      // NOTE: If anything is changed up there, the start outputLine must be updated in libec's output.c or Debugging lines will be wrong
692
693                      if(ast)
694                         OutputTree(ast, output);
695                      delete output;
696                   }
697                }
698                /*
699                else if(!strcmp(targetExt, "o"))
700                {
701                   // Compile right away
702                   File output = FileOpen(GetOutputFile(), Write);
703                   output.Printf("#include <ecereCOM.h>\n\n");
704                   OutputTree(ast, output);
705                   delete output;
706                }*/
707             }
708             else
709                this.exitCode = exitCode;
710
711             if(ast)
712             {
713                FreeASTTree(ast);
714             }
715          }
716
717          FreeContext(globalContext);
718          FreeExcludedSymbols(_excludedSymbols);
719
720          ::defines.Free(FreeModuleDefine);
721          imports.Free(FreeModuleImport);
722
723          FreeTypeData(privateModule);
724          FreeIncludeFiles();
725          FreeGlobalData(globalData);
726
727          delete privateModule;
728       }
729
730       delete cppCommand;
731       delete cppOptions;
732
733       /*for(c = 0; c<argc; c++)
734          delete argv[c];
735       delete argv;
736       */
737       SetSymbolsDir(null); // Free symbols dir
738
739       OutputIntlStrings();
740
741 #if defined(_DEBUG) && defined(__WIN32__)
742       PrintLn("Done.");
743       if(exitCode || GetNumWarnings())
744          getch();
745 #endif
746    }
747 }