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