2 public import static "ecere"
24 enum Order { ascending, descending };
26 public class DBTableDef : struct
31 OldList * definitions;
35 enum DBTableEntryType { fieldEntry, indexEntry };
37 class DBTableEntry : struct
39 DBTableEntry prev, next;
40 DBTableEntryType type;
53 class DBIndexItem : struct
55 DBIndexItem prev, next;
60 bool inCompiler = false;
61 public void SetInCompiler(bool b) { inCompiler = b; }
64 Context globalContext;
65 OldList * excludedSymbols;
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; }
75 public void SetFileInput(File file) { fileInput = file; }
76 char * symbolsDir = null;
77 public void SetSymbolsDir(char * s) {
79 symbolsDir = CopyString(s);
80 } public char * GetSymbolsDir() { return symbolsDir ? symbolsDir : ""; }
82 public void SetOutputFile(char * s) { outputFile = s; } public char * GetOutputFile() { return outputFile; }
84 public void SetSourceFile(char * s) { sourceFile = s; } public char * GetSourceFile() { return sourceFile; }
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; }
93 bool outputLineNumbers = true;
94 public void SetOutputLineNumbers(bool value) { outputLineNumbers = value; }
96 public void FixModuleName(char *moduleName)
98 ChangeCh(moduleName, '.', '_');
99 ChangeCh(moduleName, ' ', '_');
100 ChangeCh(moduleName, '-', '_');
101 ChangeCh(moduleName, '&', '_');
104 /*public Module GetPrivateModule()
106 return privateModule;
109 public class GlobalData : BTNode
113 char * dataTypeString;
119 public class TemplatedType : BTNode
122 TemplateParameter param;
125 class DataRedefinition : struct
127 DataRedefinition prev, next;
129 char type1[1024], type2[1024];
132 public struct CodePosition
135 int line, charPos, pos;
138 void AdjustDelete(BufferLocation start, BufferLocation end)
140 // Location is before, nothing to do
141 if(line - 1 < start.y || (line - 1 == start.y && charPos - 1 < start.x))
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)))
148 if(line - 1 >= end.y)
150 // Location is on another line
152 line -= end.y - start.y;
153 // Location is the last touched line
156 if(charPos - 1 >= end.x)
159 //if(start.line == end.line)
160 charPos -= end.x - start.x;
168 charPos = start.x + 1;
172 // Assuming no carriage return before first character ???? fixed?
173 void AdjustAdd(BufferLocation start, BufferLocation end)
175 int numLines = end.y - start.y;
176 if(line - 1 >= start.y)
178 if(line - 1 > start.y)
182 if(charPos - 1 > start.x || (charPos - 1 == start.x /*&& (numLines ? true : false)*/))
185 //charPos - 1 += numLines ? end.x : (end.x - start.x);
186 charPos += end.x - start.x;
193 public struct Location
196 CodePosition start, end;
198 bool Inside(int line, int charPos)
200 return (start.line < line || (start.line == line && start.charPos <= charPos)) &&
201 (end.line > line || (end.line == line && end.charPos >= charPos));
205 public enum DefinitionType { moduleDefinition, classDefinition, defineDefinition, functionDefinition, dataDefinition };
207 public class Definition : struct
210 Definition prev, next;
215 public class ImportedModule : struct
218 ImportedModule prev, next;
221 ImportType importType;
224 AccessMode importAccess;
227 public class Identifier : struct
230 Identifier prev, next;
232 // TODO: NameSpace * nameSpace;
239 public enum ExpressionType
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
252 public enum MemberType
254 unresolvedMember, propertyMember, methodMember, dataMember, reverseConversionMember, classPropertyMember
257 public class ExpUsage
260 bool usageGet:1, usageSet:1, usageArg:1, usageCall:1, usageMember:1, usageDeepGet:1, usageRef:1, usageDelete:1;
263 public class TemplateParameter : struct
266 TemplateParameter prev, next;
269 TemplateParameterType type;
270 Identifier identifier;
273 TemplateDatatype dataType; // For both base datatype (type) and data type (expression)
274 TemplateMemberType memberType; // For identifier
276 TemplateArgument defaultArgument;
278 // For type parameters
279 char * dataTypeString;
283 public class TemplateDatatype : struct
286 OldList * specifiers;
290 public class TemplateArgument : struct
293 TemplateArgument prev, next;
297 TemplateParameterType type;
300 Expression expression;
301 Identifier identifier;
302 TemplateDatatype templateDatatype;
306 public enum SpecifierType
308 baseSpecifier, nameSpecifier, enumSpecifier, structSpecifier, unionSpecifier, /*classSpecifier,*/
309 extendedSpecifier, typeOfSpecifier, subClassSpecifier, templateTypeSpecifier
312 public class Specifier : struct
315 Specifier prev, next;
326 OldList * templateArgs;
333 OldList * definitions;
336 ExtDecl extDeclStruct;
338 Expression expression;
340 TemplateParameter templateParameter;
344 public class Attribute : struct
347 Attribute prev, next;
353 public class Attrib : struct
361 public class ExtDecl : struct
373 public enum ExtDeclType
375 extDeclString, extDeclAttrib
378 public class Expression : struct
381 Expression prev, next;
389 Identifier identifier;
392 Instantiation instance;
397 OldList * specifiers;
420 MemberType memberType;
426 Expression exp1, exp2;
465 Initializer initializer;
481 // *** COMPILING DATA ***
513 public class Enumerator : struct
516 Enumerator prev, next;
522 class Pointer : struct
526 OldList * qualifiers;
530 public enum DeclaratorType
532 structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
533 functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
536 public class Declarator : struct
539 Declarator prev, next;
542 Symbol symbol;//, propSymbol;
543 Declarator declarator;
546 Identifier identifier;
560 OldList * parameters;
573 public enum InitializerType { expInitializer, listInitializer };
575 public class Initializer : struct
578 Initializer prev, next;
580 InitializerType type;
589 public class InitDeclarator : struct
592 InitDeclarator prev, next;
594 Declarator declarator;
595 Initializer initializer;
598 public enum ClassObjectType
606 public class TypeName : struct
611 OldList * qualifiers;
612 Declarator declarator;
613 //bool /*typedObject, */byReference;
615 ClassObjectType classObjectType;
619 class AsmField : struct
624 Expression expression;
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
633 public class Statement : struct
636 Statement prev, next;
641 OldList * expressions;
654 OldList * declarations;
655 OldList * statements;
695 OldList * inputFields;
696 OldList * outputFields;
697 OldList * clobberedFields;
701 Expression watcher, object;
702 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
715 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
717 public class Declaration : struct
720 Declaration prev, next;
722 DeclarationType type;
727 OldList * specifiers;
728 OldList * declarators;
737 Specifier extStorage;
742 public class Instantiation : struct
745 Instantiation prev, next;
754 Location nameLoc, insideLoc;
758 public enum MembersInitType { dataMembersInit, methodMembersInit };
760 public class FunctionDefinition : struct
763 FunctionDefinition prev, next;
765 OldList * specifiers;
766 Declarator declarator;
767 OldList * declarations;
770 OldList attached; // For IDE
777 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
780 public class ClassFunction : struct
783 ClassFunction prev, next;
785 OldList * specifiers;
786 Declarator declarator;
787 OldList * declarations;
790 OldList attached; // For IDE
798 bool isConstructor, isDestructor;
803 public class MembersInit : struct
806 MembersInit prev, next;
808 MembersInitType type;
811 OldList * dataMembers;
812 ClassFunction function;
817 public class MemberInit : struct
820 MemberInit prev, next;
823 OldList * identifiers;
825 Initializer initializer;
833 public class ClassDefinition : struct
836 ClassDefinition prev, next;
841 OldList * definitions;
847 bool deleteWatchable;
850 public class PropertyWatch : struct
853 PropertyWatch prev, next;
856 OldList * properties;
860 public enum ClassDefType
862 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
863 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
864 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
865 memberAccessClassDef, accessOverrideClassDef
868 public class PropertyDef : struct
871 PropertyDef prev, next;
873 OldList * specifiers;
874 Declarator declarator;
885 public class ClassDef : struct
894 ClassFunction function;
895 OldList * defProperties;
896 PropertyDef propertyDef;
897 PropertyWatch propertyWatch;
899 Identifier defaultProperty;
903 Initializer initializer;
906 AccessMode memberAccess;
912 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
914 public class External : struct
923 FunctionDefinition function;
924 ClassDefinition _class;
925 Declaration declaration;
930 ImportType importType;
933 public class Context : struct
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 };
943 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
944 ClassDefinition classDef;
945 bool templateTypesOnly;
949 /*************** Compiling passes symbols ***************/
951 public class Symbol : struct
955 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
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
975 External externalGet;
976 External externalSet;
977 External externalPtr; // Property pointer for watchers
978 External externalIsSet;
982 External methodExternal;
983 External methodCodeExternal;
986 bool imported, declaredStructSym;
987 Class _class; // for properties only...
989 // Only used for classes right now...
991 bool needConstructor, needDestructor;
992 char * constructorName, * structName, * className, * destructorName;
1000 bool fireWatchersDone;
1005 OldList * templateParams; // Review the necessity for this
1006 OldList templatedClasses;
1009 Expression propCategory;
1012 // For the .imp file:
1013 public class ClassImport : struct
1016 ClassImport prev, next;
1024 public class FunctionImport : struct
1027 FunctionImport prev, next;
1031 public class ModuleImport : struct
1034 ModuleImport prev, next;
1038 ImportType importType;
1039 AccessMode importAccess;
1042 public class PropertyImport : struct
1045 PropertyImport prev, next;
1048 bool hasSet, hasGet;
1051 public class MethodImport : struct
1054 MethodImport prev, next;
1059 // For the .sym file:
1060 public enum TypeKind
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
1068 public class Type : struct
1088 TemplateParameter thisClassTemplate;
1103 Expression arraySizeExp;
1109 TemplateParameter templateParameter;
1116 ClassObjectType classObjectType;
1127 bool directClassAccess:1;
1130 bool passAsTemplate:1;
1134 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1136 Type type = (Type)this;
1137 tempString[0] = '\0';
1139 PrintType(type, tempString, false, true);
1149 public struct Operand
1154 unsigned int ptrSize;
1155 union // Promote to using data value
1165 // unsigned char * p; // Now always storing addresses in ui64
1174 public struct OpTable
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);
1185 bool (* Neg)(Expression, Operand);
1187 // unary arithmetic increment and decrement
1188 bool (* Inc)(Expression, Operand);
1189 bool (* Dec)(Expression, Operand);
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);
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);
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);
1214 // unary logical negation
1215 bool (* Not)(Expression, Operand);
1217 // binary logical equality
1218 bool (* Equ)(Expression, Operand, Operand);
1219 bool (* Nqu)(Expression, Operand, Operand);
1222 bool (* And)(Expression, Operand, Operand);
1223 bool (* Or)(Expression, Operand, Operand);
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);
1231 bool (* Cond)(Expression, Operand, Operand, Operand);
1234 define MAX_INCLUDE_DEPTH = 30;
1238 void Compiler_Error(char * format, ...)
1247 if(yylloc.start.included)
1249 GetWorkingDir(string, sizeof(string));
1250 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1254 GetWorkingDir(string, sizeof(string));
1255 PathCat(string, sourceFile);
1260 yylloc.start.col = yylloc.end.col = 1;
1261 yylloc.start.line = yylloc.end.line = 1;
1262 yylloc.start.pos = yylloc.end.pos = 0;
1265 if(!yylloc.start.line)
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;
1276 fputs(string, stdout);
1277 __thisModule.application.exitCode = 1;
1281 // Error parsing type
1282 parseTypeError = true;
1288 public int GetNumWarnings() { return numWarnings; }
1290 void Compiler_Warning(char * format, ...)
1297 if(yylloc.start.included)
1299 GetWorkingDir(string, sizeof(string));
1300 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1304 GetWorkingDir(string, sizeof(string));
1305 PathCat(string, sourceFile);
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;
1317 fputs(string, stdout);
1324 int yyerror(char * s)
1329 //printf("\n%*s\n%*s\n", column, "^", column, s);
1331 Compiler_Error($"syntax error\n");
1336 Platform targetPlatform;
1338 public int GetHostBits()
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");
1346 DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1349 if(f.GetLine(host, sizeof(host)))
1356 if(!strcmp(hostType, "x86_64"))
1358 else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1364 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1368 public void SetTargetBits(int bits) { targetBits = bits; };
1369 public int GetTargetBits() { return targetBits; };