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