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