ide/designer: Support for editing internationalizable strings
[sdk] / compiler / libec / src / ecdefs.ec
1 #ifdef ECERE_STATIC
2 public import static "ecere"
3 #else
4 public import "ecere"
5 #endif
6
7 import "ast"
8 import "freeAst"
9 import "firstPass"
10 import "pass0"
11 import "pass1"
12 import "pass15"
13 import "pass16"
14 import "pass2"
15 import "pass3"
16 import "loadSymbols"
17 import "copy"
18 import "shortcuts"
19 import "output"
20 import "dbpass"
21
22 #include <stdio.h>
23
24 enum Order { ascending, descending };
25
26 public class DBTableDef : struct
27 {
28 public:
29    char * name;
30    Symbol symbol;
31    OldList * definitions;
32    AccessMode declMode;
33 }
34
35 enum DBTableEntryType { fieldEntry, indexEntry };
36
37 class DBTableEntry : struct
38 {
39    DBTableEntry prev, next;
40    DBTableEntryType type;
41    Identifier id;
42    union
43    {
44       struct
45       {
46          TypeName dataType;
47          char * name;
48       };
49       OldList * items;
50    };
51 };
52
53 class DBIndexItem : struct
54 {
55    DBIndexItem prev, next;
56    Identifier id;
57    Order order;
58 };
59
60 bool inCompiler = false;
61 public void SetInCompiler(bool b) { inCompiler = b; }
62
63 Context curContext;
64 Context globalContext;
65 OldList * excludedSymbols;
66
67 Context topContext;
68 OldList * imports;
69 OldList * defines;
70 Module privateModule;
71 public void SetPrivateModule(Module module) { privateModule = module; }public Module GetPrivateModule() { return privateModule; }
72 ModuleImport mainModule;
73 public void SetMainModule(ModuleImport moduleImport) { mainModule = moduleImport; } public ModuleImport GetMainModule() { return mainModule; }
74 File fileInput;
75 public void SetFileInput(File file) { fileInput = file; }
76 char * symbolsDir = null;
77 public void SetSymbolsDir(char * s) {
78    delete symbolsDir;
79    symbolsDir = CopyString(s);
80 } public char * GetSymbolsDir() { return symbolsDir ? symbolsDir : ""; }
81 char * outputFile;
82 public void SetOutputFile(char * s) { outputFile = s; } public char * GetOutputFile() { return outputFile; }
83 char * sourceFile;
84 public void SetSourceFile(char * s) { sourceFile = s; } public char * GetSourceFile() { return sourceFile; }
85 char * i18nModuleName;
86 public void SetI18nModuleName(char * s) { i18nModuleName = s; } public char * GetI18nModuleName() { return i18nModuleName; }
87
88 public void SetGlobalContext(Context context) { globalContext = context; } public Context GetGlobalContext() { return globalContext; }
89 public void SetTopContext(Context context) { topContext = context; } public Context GetTopContext() { return topContext; }
90 public void SetCurrentContext(Context context) { curContext = context; } public Context GetCurrentContext() { return curContext; }
91 public void SetExcludedSymbols(OldList * list) { excludedSymbols = list; }
92 public void SetImports(OldList * list) { imports = list; }
93 public void SetDefines(OldList * list) { defines = list; }
94
95 bool outputLineNumbers = true;
96 public void SetOutputLineNumbers(bool value) { outputLineNumbers = value; }
97
98 public void FixModuleName(char *moduleName)
99 {
100    ChangeCh(moduleName, '.', '_');
101    ChangeCh(moduleName, ' ', '_');
102    ChangeCh(moduleName, '-', '_');
103    ChangeCh(moduleName, '&', '_');
104 }
105
106 // todo support %var% variables for windows and $var for linux?
107 public char * PassArg(char * output, const char * input)
108 {
109 #ifdef __WIN32__
110 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
111    const char * escChars = " !\"%&'()+,;=[]^`{}~"; // windowsFileNameCharsNeedEscaping;
112    const char * escCharsQuoted = "\"";
113 #else
114 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
115    const char * escChars = " !\"$&'()*:;<=>?[\\`{|"; // linuxFileNameCharsNeedEscaping;
116    const char * escCharsQuoted = "\"()$";
117 #endif
118    bool quoting = false;
119    char *o = output, *i = input, *l = input;
120 #ifdef __WIN32__
121    while(*l && !strchr(escChars, *l)) l++;
122    if(*l) quoting = true;
123 #else
124    if(*i == '-')
125    {
126       l++;
127       while(*l && !strchr(escChars, *l)) l++;
128       if(*l) quoting = true;
129       *o++ = *i++;
130    }
131 #endif
132    if(quoting)
133       *o++ = '\"';
134    while(*i)
135    {
136       if(strchr(quoting ? escCharsQuoted : escChars, *i))
137          *o++ = '\\';
138       *o++ = *i++;
139    }
140    if(quoting)
141       *o++ = '\"';
142    *o = '\0';
143    return o;
144 }
145 /*public Module GetPrivateModule()
146 {
147    return privateModule;
148 }*/
149
150 public class GlobalData : BTNode
151 {
152 public:
153    Module module;
154    char * dataTypeString;
155    Type dataType;
156    void * symbol;
157    char * fullName;
158 };
159
160 public class TemplatedType : BTNode
161 {
162 public:
163    TemplateParameter param;
164 };
165
166 class DataRedefinition : struct
167 {
168    DataRedefinition prev, next;
169    char name[1024];
170    char type1[1024], type2[1024];
171 };
172
173 public struct CodePosition
174 {
175 public:
176    int line, charPos, pos;
177    int included;
178
179    void AdjustDelete(BufferLocation start, BufferLocation end)
180    {
181       // Location is before, nothing to do
182       if(line - 1 < start.y || (line - 1 == start.y && charPos - 1 < start.x))
183          return;
184       // Location is inside deleted bytes, point to the start
185       if((line - 1 >= start.y && (line - 1 > start.y || charPos - 1 >= start.x)) &&
186          (line - 1 >= end.y && (line - 1 > end.y || charPos - 1 >= end.x)))
187       {
188          // Location is after
189          if(line - 1 >= end.y)
190          {
191             // Location is on another line
192             if(line - 1 > end.y)
193                line -= end.y - start.y;
194             // Location is the last touched line
195             else
196             {
197                if(charPos - 1 >= end.x)
198                {
199                   line = start.y + 1;
200                   //if(start.line == end.line)
201                      charPos -= end.x - start.x;
202                }
203             }
204          }
205       }
206       else
207       {
208          line = start.y + 1;
209          charPos = start.x + 1;
210       }
211    }
212
213    // Assuming no carriage return before first character ???? fixed?
214    void AdjustAdd(BufferLocation start, BufferLocation end)
215    {
216       int numLines = end.y - start.y;
217       if(line - 1 >= start.y)
218       {
219          if(line - 1 > start.y)
220             line += numLines;
221          else
222          {
223             if(charPos - 1 > start.x || (charPos - 1 == start.x /*&& (numLines ? true : false)*/))
224             {
225                line += numLines;
226                //charPos - 1 += numLines ? end.x : (end.x - start.x);
227                charPos += end.x - start.x;
228             }
229          }
230       }
231    }
232 };
233
234 public struct Location
235 {
236 public:
237    CodePosition start, end;
238
239    bool Inside(int line, int charPos)
240    {
241       return (start.line < line || (start.line == line && start.charPos <= charPos)) &&
242              (end.line > line || (end.line == line && end.charPos >= charPos));
243    }
244 };
245
246 public enum DefinitionType { moduleDefinition, classDefinition, defineDefinition, functionDefinition, dataDefinition };
247
248 public class Definition : struct
249 {
250 public:
251    Definition prev, next;
252    char * name;
253    DefinitionType type;
254 };
255
256 public class ImportedModule : struct
257 {
258 public:
259    ImportedModule prev, next;
260    char * name;
261    DefinitionType type;
262    ImportType importType;
263    bool globalInstance;
264    bool dllOnly;
265    AccessMode importAccess;
266 };
267
268 public class Identifier : struct
269 {
270 public:
271    Identifier prev, next;
272    Location loc;
273    // TODO: NameSpace * nameSpace;
274    Symbol classSym;
275    Specifier _class;
276    char * string;
277    Identifier badID;
278 };
279
280 public enum ExpressionType
281 {
282    identifierExp, instanceExp, constantExp, stringExp, opExp,
283    bracketsExp, indexExp, callExp, memberExp, pointerExp, typeSizeExp,
284    castExp, conditionExp, newExp, renewExp, classSizeExp,
285    dummyExp, dereferenceErrorExp, symbolErrorExp, classMemberSymbolErrorExp,
286    structMemberSymbolErrorExp, memoryErrorExp, unknownErrorExp,
287    noDebuggerErrorExp, debugStateErrorExp,
288    extensionCompoundExp, classExp, classDataExp, new0Exp, renew0Exp,
289    dbopenExp, dbfieldExp, dbtableExp, dbindexExp, extensionExpressionExp, extensionInitializerExp,
290    vaArgExp, arrayExp, typeAlignExp
291 };
292
293 public enum MemberType
294 {
295    unresolvedMember, propertyMember, methodMember, dataMember, reverseConversionMember, classPropertyMember
296 };
297
298 public class ExpUsage
299 {
300 public:
301    bool usageGet:1, usageSet:1, usageArg:1, usageCall:1, usageMember:1, usageDeepGet:1, usageRef:1, usageDelete:1;
302 };
303
304 public class TemplateParameter : struct
305 {
306 public:
307    TemplateParameter prev, next;
308    Location loc;
309
310    TemplateParameterType type;
311    Identifier identifier;
312    union
313    {
314       TemplateDatatype dataType; // For both base datatype (type) and data type (expression)
315       TemplateMemberType memberType;   // For identifier
316    };
317    TemplateArgument defaultArgument;
318
319    // For type parameters
320    char * dataTypeString;
321    Type baseType;
322 }
323
324 public class TemplateDatatype : struct
325 {
326 public:
327    OldList * specifiers;
328    Declarator decl;
329 }
330
331 public class TemplateArgument : struct
332 {
333 public:
334    TemplateArgument prev, next;
335    Location loc;
336
337    Identifier name;
338    TemplateParameterType type;
339    union
340    {
341       Expression expression;
342       Identifier identifier;
343       TemplateDatatype templateDatatype;
344    };
345 }
346
347 public enum SpecifierType
348 {
349    baseSpecifier, nameSpecifier, enumSpecifier, structSpecifier, unionSpecifier, /*classSpecifier,*/
350    extendedSpecifier, typeOfSpecifier, subClassSpecifier, templateTypeSpecifier
351 };
352
353 public class Specifier : struct
354 {
355 public:
356    Specifier prev, next;
357    Location loc;
358    SpecifierType type;
359    union
360    {
361       int specifier;
362       struct
363       {
364          ExtDecl extDecl;
365          char * name;
366          Symbol symbol;
367          OldList * templateArgs;
368       };
369       struct
370       {
371          Identifier id;
372          OldList * list;
373          OldList * baseSpecs;
374          OldList * definitions;
375          bool addNameSpace;
376          Context ctx;
377          ExtDecl extDeclStruct;
378       };
379       Expression expression;
380       Specifier _class;
381       TemplateParameter templateParameter;
382    };
383 };
384
385 public class Attribute : struct
386 {
387 public:
388    Attribute prev, next;
389    Location loc;
390    String attr;
391    Expression exp;
392 }
393
394 public class Attrib : struct
395 {
396 public:
397    Location loc;
398    int type;
399    OldList * attribs;
400 }
401
402 public class ExtDecl : struct
403 {
404 public:
405    Location loc;
406    ExtDeclType type;
407    union
408    {
409       String s;
410       Attrib attr;
411    };
412 }
413
414 public enum ExtDeclType
415 {
416    extDeclString, extDeclAttrib
417 };
418
419 public class Expression : struct
420 {
421 public:
422    Expression prev, next;
423    Location loc;
424    ExpressionType type;
425    union
426    {
427       struct
428       {
429          char * constant;
430          Identifier identifier;
431       };
432       Statement compound;
433       Instantiation instance;
434       struct
435       {
436          char * string;
437          bool intlString;
438       };
439       OldList * list;
440       struct
441       {
442          OldList * specifiers;
443          Declarator decl;
444       } _classExp;
445       struct
446       {
447          Identifier id;
448       } classData;
449       struct
450       {
451          Expression exp;
452          OldList * arguments;
453          Location argLoc;
454       } call;
455       struct
456       {
457          Expression exp;
458          OldList * index;
459       } index;
460       struct
461       {
462          Expression exp;
463          Identifier member;
464
465          MemberType memberType;
466          bool thisPtr;
467       } member;
468       struct
469       {
470          int op;
471          Expression exp1, exp2;
472       } op;
473       TypeName typeName;
474       Specifier _class;
475       struct
476       {
477          TypeName typeName;
478          Expression exp;
479       } cast;
480       struct
481       {
482          Expression cond;
483          OldList * exp;
484          Expression elseExp;
485       } cond;
486       struct
487       {
488          TypeName typeName;
489          Expression size;
490       } _new;
491       struct
492       {
493          TypeName typeName;
494          Expression size;
495          Expression exp;
496       } _renew;
497       struct
498       {
499          char * table;
500          Identifier id;
501       } db;
502       struct
503       {
504          Expression ds;
505          Expression name;
506       } dbopen;
507       struct
508       {
509          TypeName typeName;
510          Initializer initializer;
511       } initializer;
512       struct
513       {
514          Expression exp;
515          TypeName typeName;
516       } vaArg;
517    };
518
519    bool debugValue;
520
521    DataValue val;
522
523    uint64 address;
524    bool hasAddress;
525
526    // *** COMPILING DATA ***
527    Type expType;
528    Type destType;
529
530    ExpUsage usage;
531    int tempCount;
532    bool byReference;
533    bool isConstant;
534    bool addedThis;
535    bool needCast;
536    bool thisPtr;
537
538    void Clear()
539    {
540       debugValue = false;
541       val = { 0 };
542       address = 0;
543       hasAddress = false;
544
545       expType = null;
546       destType = null;
547
548       usage = 0;
549       tempCount = 0;
550       byReference = false;
551       isConstant = false;
552       addedThis = false;
553       needCast = false;
554       thisPtr = false;
555    }
556 };
557
558 public class Enumerator : struct
559 {
560 public:
561    Enumerator prev, next;
562    Location loc;
563    Identifier id;
564    Expression exp;
565 };
566
567 class Pointer : struct
568 {
569    Pointer prev, next;
570    Location loc;
571    OldList * qualifiers;
572    Pointer pointer;
573 };
574
575 public enum DeclaratorType
576 {
577    structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
578    functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
579 };
580
581 public class Declarator : struct
582 {
583 public:
584    Declarator prev, next;
585    Location loc;
586    DeclaratorType type;
587    Symbol symbol;//, propSymbol;
588    Declarator declarator;
589    union
590    {
591       Identifier identifier;
592       struct
593       {
594          Expression exp;
595          Expression posExp;
596          Attrib attrib;
597       } structDecl;
598       struct
599       {
600          Expression exp;
601          Specifier enumClass;
602       } array;
603       struct
604       {
605          OldList * parameters;
606       } function;
607       struct
608       {
609          Pointer pointer;
610       } pointer;
611       struct
612       {
613          ExtDecl extended;
614       } extended;
615    };
616 };
617
618 public enum InitializerType { expInitializer, listInitializer };
619
620 public class Initializer : struct
621 {
622 public:
623    Initializer prev, next;
624    Location loc;
625    InitializerType type;
626    union
627    {
628       Expression exp;
629       OldList * list;
630    };
631    bool isConstant;
632 };
633
634 public class InitDeclarator : struct
635 {
636 public:
637    InitDeclarator prev, next;
638    Location loc;
639    Declarator declarator;
640    Initializer initializer;
641 };
642
643 public enum ClassObjectType
644 {
645    none,
646    classPointer,
647    typedObject,
648    anyObject
649 };
650
651 public class TypeName : struct
652 {
653 public:
654    TypeName prev, next;
655    Location loc;
656    OldList * qualifiers;
657    Declarator declarator;
658    //bool /*typedObject, */byReference;
659    //bool anyObject;
660    ClassObjectType classObjectType;
661    Expression bitCount;
662 };
663
664 class AsmField : struct
665 {
666    AsmField prev, next;
667    Location loc;
668    char * command;
669    Expression expression;
670    Identifier symbolic;
671 };
672
673 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
674                expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
675                forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
676                fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
677              };
678
679 public class Statement : struct
680 {
681 public:
682    Statement prev, next;
683    Location loc;
684    StmtType type;
685    union
686    {
687       OldList * expressions;
688       struct
689       {
690          Identifier id;
691          Statement stmt;
692       } labeled;
693       struct
694       {
695          Expression exp;
696          Statement stmt;
697       } caseStmt;
698       struct
699       {
700          OldList * declarations;
701          OldList * statements;
702          Context context;
703          bool isSwitch;
704       } compound;
705       struct
706       {
707          OldList * exp;
708          Statement stmt;
709          Statement elseStmt;
710       } ifStmt;
711       struct
712       {
713          OldList * exp;
714          Statement stmt;
715       } switchStmt;
716       struct
717       {
718          OldList * exp;
719          Statement stmt;
720       } whileStmt;
721       struct
722       {
723          OldList * exp;
724          Statement stmt;
725       } doWhile;
726       struct
727       {
728          Statement init;
729          Statement check;
730          OldList * increment;
731          Statement stmt;
732       } forStmt;
733       struct
734       {
735          Identifier id;
736       } gotoStmt;
737       struct
738       {
739          Specifier spec;
740          char * statements;
741          OldList * inputFields;
742          OldList * outputFields;
743          OldList * clobberedFields;
744       } asmStmt;
745       struct
746       {
747          Expression watcher, object;
748          OldList * watches;   // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
749       } _watch;
750       struct
751       {
752          Identifier id;
753          OldList * exp;
754          OldList * filter;
755          Statement stmt;
756       } forEachStmt;
757       Declaration decl;
758    };
759 };
760
761 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
762
763 public class Declaration : struct
764 {
765 public:
766    Declaration prev, next;
767    Location loc;
768    DeclarationType type;
769    union
770    {
771       struct
772       {
773          OldList * specifiers;
774          OldList * declarators;
775       };
776       Instantiation inst;
777       struct
778       {
779          Identifier id;
780          Expression exp;
781       };
782    };
783    Specifier extStorage;
784    Symbol symbol;
785    AccessMode declMode;
786 };
787
788 public class Instantiation : struct
789 {
790 public:
791    Instantiation prev, next;
792    Location loc;
793    Specifier _class;
794    Expression exp;
795    OldList * members;
796    Symbol symbol;
797    bool fullSet;
798    bool isConstant;
799    byte * data;
800    Location nameLoc, insideLoc;
801    bool built;
802 };
803
804 public enum MembersInitType { dataMembersInit, methodMembersInit };
805
806 public class FunctionDefinition : struct
807 {
808 public:
809    FunctionDefinition prev, next;
810    Location loc;
811    OldList * specifiers;
812    Declarator declarator;
813    OldList * declarations;
814    Statement body;
815    Class _class;
816    OldList attached;    // For IDE
817    AccessMode declMode;
818
819    Type type;
820    Symbol propSet;
821
822    int tempCount;
823    bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
824 };
825
826 public class ClassFunction : struct
827 {
828 public:
829    ClassFunction prev, next;
830    Location loc;
831    OldList * specifiers;
832    Declarator declarator;
833    OldList * declarations;
834    Statement body;
835    Class _class;
836    OldList attached;    // For IDE
837    AccessMode declMode;
838
839    // COMPILING DATA
840    Type type;
841    Symbol propSet;
842
843    bool isVirtual;
844    bool isConstructor, isDestructor;
845    bool dontMangle;
846    int id, idCode;
847 };
848
849 public class MembersInit : struct
850 {
851 public:
852    MembersInit prev, next;
853    Location loc;
854    MembersInitType type;
855    union
856    {
857       OldList * dataMembers;
858       ClassFunction function;
859    };
860    //bool coloned;
861 };
862
863 public class MemberInit : struct
864 {
865 public:
866    MemberInit prev, next;
867    Location loc;
868    Location realLoc;
869    OldList * identifiers;
870    // Expression exp;
871    Initializer initializer;
872
873    // COMPILE DATA
874    bool used;
875    bool variable;
876    bool takeOutExp;
877 };
878
879 public class ClassDefinition : struct
880 {
881 public:
882    ClassDefinition prev, next;
883    Location loc;
884    Specifier _class;
885    // Specifier base;
886    OldList * baseSpecs;
887    OldList * definitions;
888    Symbol symbol;
889    Location blockStart;
890    Location nameLoc;
891    int endid;
892    AccessMode declMode;
893    bool deleteWatchable;
894 };
895
896 public class PropertyWatch : struct
897 {
898 public:
899    PropertyWatch prev, next;
900    Location loc;
901    Statement compound;
902    OldList * properties;
903    bool deleteWatch;
904 };
905
906 public enum ClassDefType
907 {
908    functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
909    propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
910    designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
911    memberAccessClassDef, accessOverrideClassDef
912 };
913
914 public class PropertyDef : struct
915 {
916 public:
917    PropertyDef prev, next;
918    Location loc;
919    OldList * specifiers;
920    Declarator declarator;
921    Identifier id;
922    Statement getStmt;
923    Statement setStmt;
924    Statement issetStmt;
925    Symbol symbol;
926    bool conversion;
927    bool isWatchable;
928    Expression category;
929 };
930
931 public class ClassDef : struct
932 {
933 public:
934    ClassDef prev, next;
935    Location loc;
936    ClassDefType type;
937    union
938    {
939       Declaration decl;
940       ClassFunction function;
941       OldList * defProperties;
942       PropertyDef propertyDef;
943       PropertyWatch propertyWatch;
944       char * designer;
945       Identifier defaultProperty;
946       struct
947       {
948          Identifier id;
949          Initializer initializer;
950       };
951    };
952    AccessMode memberAccess;
953
954    // IDE
955    void * object;
956 };
957
958 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
959
960 public class External : struct
961 {
962 public:
963    External prev, next;
964    Location loc;
965    ExternalType type;
966    Symbol symbol;
967    union
968    {
969       FunctionDefinition function;
970       ClassDefinition _class;
971       Declaration declaration;
972       char * importString;
973       Identifier id;
974       DBTableDef table;
975    };
976    ImportType importType;
977 };
978
979 public class Context : struct
980 {
981 public:
982    Context parent;
983    BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
984    BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
985    BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
986    BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
987    int nextID;
988    int simpleID;
989    BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
990    ClassDefinition classDef;
991    bool templateTypesOnly;
992    bool hasNameSpace;
993 };
994
995 /*************** Compiling passes symbols ***************/
996
997 public class Symbol : struct
998 {
999 public:
1000    char * string;
1001    Symbol parent, left, right;   // Reusing left, right as prev, next when in excludedSymbols
1002    int depth;
1003
1004    Type type;
1005    union
1006    {
1007       Method method;
1008       Property _property;
1009       Class registered;
1010    };
1011    int id, idCode;
1012    union
1013    {
1014       struct
1015       {
1016          External pointerExternal;  // external declaration for the pointer to the Class:    e.g. __ecereClass___ecereNameSpace__ecere__com__Class
1017          External structExternal;   // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
1018       };
1019       struct
1020       {
1021          External externalGet;
1022          External externalSet;
1023          External externalPtr;    // Property pointer for watchers
1024          External externalIsSet;
1025       };
1026       struct
1027       {
1028          External methodExternal;
1029          External methodCodeExternal;
1030       };
1031    };
1032    bool imported, declaredStructSym;
1033    Class _class; // for properties only...
1034
1035    // Only used for classes right now...
1036    bool declaredStruct;
1037    bool needConstructor, needDestructor;
1038    char * constructorName, * structName, * className, * destructorName;
1039
1040    ModuleImport module;
1041    ClassImport _import;
1042    Location nameLoc;
1043    bool isParam;
1044    bool isRemote;
1045    bool isStruct;
1046    bool fireWatchersDone;
1047    int declaring;
1048    bool classData;
1049    bool isStatic;
1050    char * shortName;
1051    OldList * templateParams;     // Review the necessity for this
1052    OldList templatedClasses;
1053    Context ctx;
1054    int isIterator;
1055    Expression propCategory;
1056 };
1057
1058 // For the .imp file:
1059 public class ClassImport : struct
1060 {
1061 public:
1062    ClassImport prev, next;
1063    char * name;
1064    OldList methods;
1065    OldList properties;
1066    bool itself;
1067    bool isRemote;
1068 };
1069
1070 public class FunctionImport : struct
1071 {
1072 public:
1073    FunctionImport prev, next;
1074    char * name;
1075 };
1076
1077 public class ModuleImport : struct
1078 {
1079 public:
1080    ModuleImport prev, next;
1081    char * name;
1082    OldList classes;
1083    OldList functions;
1084    ImportType importType;
1085    AccessMode importAccess;
1086 };
1087
1088 public class PropertyImport : struct
1089 {
1090 public:
1091    PropertyImport prev, next;
1092    char * name;
1093    bool isVirtual;
1094    bool hasSet, hasGet;
1095 };
1096
1097 public class MethodImport : struct
1098 {
1099 public:
1100    MethodImport prev, next;
1101    char * name;
1102    bool isVirtual;
1103 };
1104
1105 // For the .sym file:
1106 public enum TypeKind
1107 {
1108    voidType, charType, shortType, intType, int64Type, longType, floatType,
1109    doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1110    ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1111    subClassType, templateType, thisClassType, intPtrType, intSizeType, _BoolType
1112 };
1113
1114 public class Type : struct
1115 {
1116 public:
1117    Type prev, next;
1118    int refCount;
1119    union
1120    {
1121       Symbol _class;
1122       struct
1123       {
1124          OldList members;
1125          char * enumName;
1126       };
1127       // For a function:
1128       struct
1129       {
1130          Type returnType;
1131          OldList params;
1132          Symbol thisClass;
1133          bool staticMethod;
1134          TemplateParameter thisClassTemplate;
1135       };
1136       // For a method
1137       struct
1138       {
1139          Method method;
1140          Class methodClass;      // Clarify what this is!
1141          Class usedClass;
1142       };
1143
1144       // For an array:
1145       struct
1146       {
1147          Type arrayType;
1148          int arraySize;
1149          Expression arraySizeExp;
1150          bool freeExp;
1151          Symbol enumClass;
1152       };
1153       // For a pointer:
1154       Type type;
1155       TemplateParameter templateParameter;
1156    };
1157    TypeKind kind;
1158    uint size;
1159    char * name;
1160    char * typeName;
1161
1162    ClassObjectType classObjectType;
1163    int alignment;
1164    uint offset;
1165    int bitFieldCount;
1166    int count;
1167
1168    bool isSigned:1;
1169    bool constant:1;
1170    bool truth:1;
1171    bool byReference:1;
1172    bool extraParam:1;      // Clarify this... One thing it is used for is adaptive method with their own type explicitly specified
1173    bool directClassAccess:1;     // Need to clarify this if this had the same intended purpose as declaredWithStruct
1174    bool computing:1;
1175    bool keepCast:1;
1176    bool passAsTemplate:1;
1177    bool dllExport:1;
1178    bool attrStdcall:1;
1179    bool declaredWithStruct:1;
1180    bool typedByReference:1;      // Originally typed by reference, regardless of class type
1181    // TODO: Add _Complex & _Imaginary support
1182    // bool complex:1, imaginary:1;
1183
1184    char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1185    {
1186       Type type = (Type)this;
1187       tempString[0] = '\0';
1188       if(type)
1189          PrintType(type, tempString, false, true);
1190       return tempString;
1191    }
1192
1193    void OnFree()
1194    {
1195
1196    }
1197 };
1198
1199 public struct Operand
1200 {
1201 public:
1202    TypeKind kind;
1203    Type type;
1204    unsigned int ptrSize;
1205    union    // Promote to using data value
1206    {
1207       char c;
1208       unsigned char uc;
1209       short s;
1210       unsigned short us;
1211       int i;
1212       unsigned int ui;
1213       float f;
1214       double d;
1215       // unsigned char * p; // Now always storing addresses in ui64
1216       int64 i64;
1217       uint64 ui64;
1218       // intptr iptr;
1219       // uintptr uiptr;
1220    };
1221    OpTable ops;
1222 };
1223
1224 public struct OpTable
1225 {
1226 public:
1227    // binary arithmetic
1228    bool (* Add)(Expression, Operand, Operand);
1229    bool (* Sub)(Expression, Operand, Operand);
1230    bool (* Mul)(Expression, Operand, Operand);
1231    bool (* Div)(Expression, Operand, Operand);
1232    bool (* Mod)(Expression, Operand, Operand);
1233
1234    // unary arithmetic
1235    bool (* Neg)(Expression, Operand);
1236
1237    // unary arithmetic increment and decrement
1238    bool (* Inc)(Expression, Operand);
1239    bool (* Dec)(Expression, Operand);
1240
1241    // binary arithmetic assignment
1242    bool (* Asign)(Expression, Operand, Operand);
1243    bool (* AddAsign)(Expression, Operand, Operand);
1244    bool (* SubAsign)(Expression, Operand, Operand);
1245    bool (* MulAsign)(Expression, Operand, Operand);
1246    bool (* DivAsign)(Expression, Operand, Operand);
1247    bool (* ModAsign)(Expression, Operand, Operand);
1248
1249    // binary bitwise
1250    bool (* BitAnd)(Expression, Operand, Operand);
1251    bool (* BitOr)(Expression, Operand, Operand);
1252    bool (* BitXor)(Expression, Operand, Operand);
1253    bool (* LShift)(Expression, Operand, Operand);
1254    bool (* RShift)(Expression, Operand, Operand);
1255    bool (* BitNot)(Expression, Operand);
1256
1257    // binary bitwise assignment
1258    bool (* AndAsign)(Expression, Operand, Operand);
1259    bool (* OrAsign)(Expression, Operand, Operand);
1260    bool (* XorAsign)(Expression, Operand, Operand);
1261    bool (* LShiftAsign)(Expression, Operand, Operand);
1262    bool (* RShiftAsign)(Expression, Operand, Operand);
1263
1264    // unary logical negation
1265    bool (* Not)(Expression, Operand);
1266
1267    // binary logical equality
1268    bool (* Equ)(Expression, Operand, Operand);
1269    bool (* Nqu)(Expression, Operand, Operand);
1270
1271    // binary logical
1272    bool (* And)(Expression, Operand, Operand);
1273    bool (* Or)(Expression, Operand, Operand);
1274
1275    // binary logical relational
1276    bool (* Grt)(Expression, Operand, Operand);
1277    bool (* Sma)(Expression, Operand, Operand);
1278    bool (* GrtEqu)(Expression, Operand, Operand);
1279    bool (* SmaEqu)(Expression, Operand, Operand);
1280
1281    bool (* Cond)(Expression, Operand, Operand, Operand);
1282 };
1283
1284 define MAX_INCLUDE_DEPTH = 30;
1285
1286 #include <stdarg.h>
1287
1288 void Compiler_Error(char * format, ...)
1289 {
1290    if(inCompiler)
1291    {
1292       if(!parsingType)
1293       {
1294          va_list args;
1295          char string[10000];
1296
1297          if(yylloc.start.included)
1298          {
1299             GetWorkingDir(string, sizeof(string));
1300             PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1301          }
1302          else
1303          {
1304             GetWorkingDir(string, sizeof(string));
1305             PathCat(string, sourceFile);
1306          }
1307          printf(string);
1308
1309          /*
1310          yylloc.start.col = yylloc.end.col = 1;
1311          yylloc.start.line = yylloc.end.line = 1;
1312          yylloc.start.pos = yylloc.end.pos = 0;
1313          */
1314 #ifdef _DEBUG
1315          if(!yylloc.start.line)
1316             printf("");
1317 #endif
1318
1319          //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1320          printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1321          //printf(":%d: error: ", yylloc.start.line);
1322          va_start(args, format);
1323          vsnprintf(string, sizeof(string), format, args);
1324          string[sizeof(string)-1] = 0;
1325          va_end(args);
1326          fputs(string, stdout);
1327          __thisModule.application.exitCode = 1;
1328       }
1329       else
1330       {
1331          // Error parsing type
1332          parseTypeError = true;
1333       }
1334    }
1335 }
1336
1337 int numWarnings;
1338 public int GetNumWarnings() { return numWarnings; }
1339
1340 void Compiler_Warning(char * format, ...)
1341 {
1342    if(inCompiler)
1343    {
1344       va_list args;
1345       char string[10000];
1346       char fileName[MAX_FILENAME];
1347
1348       if(yylloc.start.included)
1349       {
1350          String include = GetIncludeFileFromID(yylloc.start.included);
1351          GetWorkingDir(string, sizeof(string));
1352          PathCat(string, include);
1353       }
1354       else
1355       {
1356          GetWorkingDir(string, sizeof(string));
1357          PathCat(string, sourceFile);
1358       }
1359
1360       // Skip these warnings from MinGW-w64 GCC 4.8 in intrin-impl.h
1361       GetLastDirectory(string, fileName);
1362       if(!strcmp(fileName, "intrin-impl.h")) return;
1363
1364       printf(string);
1365
1366       //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1367       printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1368       //printf(":%d: warning: ", yylloc.start.line);
1369       va_start(args, format);
1370       vsnprintf(string, sizeof(string), format, args);
1371       string[sizeof(string)-1] = 0;
1372       va_end(args);
1373       fputs(string, stdout);
1374       numWarnings++;
1375    }
1376 }
1377 bool parseError;
1378 bool skipErrors;
1379
1380 int yyerror(char * s)
1381 {
1382    if(!skipErrors)
1383    {
1384         //fflush(stdout);
1385         //printf("\n%*s\n%*s\n", column, "^", column, s);
1386       parseError = true;
1387       Compiler_Error($"syntax error\n");
1388    }
1389    return 0;
1390 }
1391
1392 Platform targetPlatform;
1393
1394 public int GetHostBits()
1395 {
1396    // Default to runtime platform in case we fail to determine host
1397    int hostBits = (sizeof(uintptr) == 8) ? 64 : 32;
1398    String hostType = getenv("HOSTTYPE");
1399    char host[256];
1400    if(!hostType)
1401    {
1402       DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1403       if(f)
1404       {
1405          if(f.GetLine(host, sizeof(host)))
1406             hostType = host;
1407          delete f;
1408       }
1409    }
1410    if(hostType)
1411    {
1412       if(!strcmp(hostType, "x86_64"))
1413          hostBits = 64;
1414       else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1415          hostBits = 32;
1416    }
1417    return hostBits;
1418 }
1419
1420 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1421
1422 int targetBits;
1423
1424 public void SetTargetBits(int bits) { targetBits = bits; };
1425 public int GetTargetBits() { return targetBits; };