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; }
85 char * i18nModuleName;
86 public void SetI18nModuleName(char * s) { i18nModuleName = s; } public char * GetI18nModuleName() { return i18nModuleName; }
88 public void SetGlobalContext(Context context) { globalContext = context; } public Context GetGlobalContext() { return globalContext; }
89 public void SetTopContext(Context context) { topContext = context; } public Context GetTopContext() { return topContext; }
90 public void SetCurrentContext(Context context) { curContext = context; } public Context GetCurrentContext() { return curContext; }
91 public void SetExcludedSymbols(OldList * list) { excludedSymbols = list; }
92 public void SetImports(OldList * list) { imports = list; }
93 public void SetDefines(OldList * list) { defines = list; }
95 bool outputLineNumbers = true;
96 public void SetOutputLineNumbers(bool value) { outputLineNumbers = value; }
98 public void FixModuleName(char *moduleName)
100 ChangeCh(moduleName, '.', '_');
101 ChangeCh(moduleName, ' ', '_');
102 ChangeCh(moduleName, '-', '_');
103 ChangeCh(moduleName, '&', '_');
106 // todo support %var% variables for windows and $var for linux?
107 public char * PassArg(char * output, const char * input)
110 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
111 const char * escChars = " !\"%&'()+,;=[]^`{}~"; // windowsFileNameCharsNeedEscaping;
112 const char * escCharsQuoted = "\"";
114 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
115 const char * escChars = " !\"$&'()*:;<=>?[\\`{|"; // linuxFileNameCharsNeedEscaping;
116 const char * escCharsQuoted = "\"()$";
118 bool quoting = false;
119 char *o = output, *i = input, *l = input;
121 while(*l && !strchr(escChars, *l)) l++;
122 if(*l) quoting = true;
127 while(*l && !strchr(escChars, *l)) l++;
128 if(*l) quoting = true;
136 if(strchr(quoting ? escCharsQuoted : escChars, *i))
145 /*public Module GetPrivateModule()
147 return privateModule;
150 public class GlobalData : BTNode
154 char * dataTypeString;
160 public class TemplatedType : BTNode
163 TemplateParameter param;
166 class DataRedefinition : struct
168 DataRedefinition prev, next;
170 char type1[1024], type2[1024];
173 public struct CodePosition
176 int line, charPos, pos;
179 void AdjustDelete(BufferLocation start, BufferLocation end)
181 // Location is before, nothing to do
182 if(line - 1 < start.y || (line - 1 == start.y && charPos - 1 < start.x))
184 // Location is inside deleted bytes, point to the start
185 if((line - 1 >= start.y && (line - 1 > start.y || charPos - 1 >= start.x)) &&
186 (line - 1 >= end.y && (line - 1 > end.y || charPos - 1 >= end.x)))
189 if(line - 1 >= end.y)
191 // Location is on another line
193 line -= end.y - start.y;
194 // Location is the last touched line
197 if(charPos - 1 >= end.x)
200 //if(start.line == end.line)
201 charPos -= end.x - start.x;
209 charPos = start.x + 1;
213 // Assuming no carriage return before first character ???? fixed?
214 void AdjustAdd(BufferLocation start, BufferLocation end)
216 int numLines = end.y - start.y;
217 if(line - 1 >= start.y)
219 if(line - 1 > start.y)
223 if(charPos - 1 > start.x || (charPos - 1 == start.x /*&& (numLines ? true : false)*/))
226 //charPos - 1 += numLines ? end.x : (end.x - start.x);
227 charPos += end.x - start.x;
234 public struct Location
237 CodePosition start, end;
239 bool Inside(int line, int charPos)
241 return (start.line < line || (start.line == line && start.charPos <= charPos)) &&
242 (end.line > line || (end.line == line && end.charPos >= charPos));
246 public enum DefinitionType { moduleDefinition, classDefinition, defineDefinition, functionDefinition, dataDefinition };
248 public class Definition : struct
251 Definition prev, next;
256 public class ImportedModule : struct
259 ImportedModule prev, next;
262 ImportType importType;
265 AccessMode importAccess;
268 public class Identifier : struct
271 Identifier prev, next;
273 // TODO: NameSpace * nameSpace;
280 public enum ExpressionType
282 identifierExp, instanceExp, constantExp, stringExp, opExp,
283 bracketsExp, indexExp, callExp, memberExp, pointerExp, typeSizeExp,
284 castExp, conditionExp, newExp, renewExp, classSizeExp,
285 dummyExp, dereferenceErrorExp, symbolErrorExp, classMemberSymbolErrorExp,
286 structMemberSymbolErrorExp, memoryErrorExp, unknownErrorExp,
287 noDebuggerErrorExp, debugStateErrorExp,
288 extensionCompoundExp, classExp, classDataExp, new0Exp, renew0Exp,
289 dbopenExp, dbfieldExp, dbtableExp, dbindexExp, extensionExpressionExp, extensionInitializerExp,
290 vaArgExp, arrayExp, typeAlignExp
293 public enum MemberType
295 unresolvedMember, propertyMember, methodMember, dataMember, reverseConversionMember, classPropertyMember
298 public class ExpUsage
301 bool usageGet:1, usageSet:1, usageArg:1, usageCall:1, usageMember:1, usageDeepGet:1, usageRef:1, usageDelete:1;
304 public class TemplateParameter : struct
307 TemplateParameter prev, next;
310 TemplateParameterType type;
311 Identifier identifier;
314 TemplateDatatype dataType; // For both base datatype (type) and data type (expression)
315 TemplateMemberType memberType; // For identifier
317 TemplateArgument defaultArgument;
319 // For type parameters
320 char * dataTypeString;
324 public class TemplateDatatype : struct
327 OldList * specifiers;
331 public class TemplateArgument : struct
334 TemplateArgument prev, next;
338 TemplateParameterType type;
341 Expression expression;
342 Identifier identifier;
343 TemplateDatatype templateDatatype;
347 public enum SpecifierType
349 baseSpecifier, nameSpecifier, enumSpecifier, structSpecifier, unionSpecifier, /*classSpecifier,*/
350 extendedSpecifier, typeOfSpecifier, subClassSpecifier, templateTypeSpecifier
353 public class Specifier : struct
356 Specifier prev, next;
367 OldList * templateArgs;
374 OldList * definitions;
377 ExtDecl extDeclStruct;
379 Expression expression;
381 TemplateParameter templateParameter;
385 public class Attribute : struct
388 Attribute prev, next;
394 public class Attrib : struct
402 public class ExtDecl : struct
414 public enum ExtDeclType
416 extDeclString, extDeclAttrib
419 public class Expression : struct
422 Expression prev, next;
430 Identifier identifier;
433 Instantiation instance;
442 OldList * specifiers;
465 MemberType memberType;
471 Expression exp1, exp2;
510 Initializer initializer;
526 // *** COMPILING DATA ***
558 public class Enumerator : struct
561 Enumerator prev, next;
567 class Pointer : struct
571 OldList * qualifiers;
575 public enum DeclaratorType
577 structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
578 functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
581 public class Declarator : struct
584 Declarator prev, next;
587 Symbol symbol;//, propSymbol;
588 Declarator declarator;
591 Identifier identifier;
605 OldList * parameters;
618 public enum InitializerType { expInitializer, listInitializer };
620 public class Initializer : struct
623 Initializer prev, next;
625 InitializerType type;
634 public class InitDeclarator : struct
637 InitDeclarator prev, next;
639 Declarator declarator;
640 Initializer initializer;
643 public enum ClassObjectType
651 public class TypeName : struct
656 OldList * qualifiers;
657 Declarator declarator;
658 //bool /*typedObject, */byReference;
660 ClassObjectType classObjectType;
664 class AsmField : struct
669 Expression expression;
673 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
674 expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
675 forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
676 fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
679 public class Statement : struct
682 Statement prev, next;
687 OldList * expressions;
700 OldList * declarations;
701 OldList * statements;
741 OldList * inputFields;
742 OldList * outputFields;
743 OldList * clobberedFields;
747 Expression watcher, object;
748 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
761 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
763 public class Declaration : struct
766 Declaration prev, next;
768 DeclarationType type;
773 OldList * specifiers;
774 OldList * declarators;
783 Specifier extStorage;
788 public class Instantiation : struct
791 Instantiation prev, next;
800 Location nameLoc, insideLoc;
804 public enum MembersInitType { dataMembersInit, methodMembersInit };
806 public class FunctionDefinition : struct
809 FunctionDefinition prev, next;
811 OldList * specifiers;
812 Declarator declarator;
813 OldList * declarations;
816 OldList attached; // For IDE
823 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
826 public class ClassFunction : struct
829 ClassFunction prev, next;
831 OldList * specifiers;
832 Declarator declarator;
833 OldList * declarations;
836 OldList attached; // For IDE
844 bool isConstructor, isDestructor;
849 public class MembersInit : struct
852 MembersInit prev, next;
854 MembersInitType type;
857 OldList * dataMembers;
858 ClassFunction function;
863 public class MemberInit : struct
866 MemberInit prev, next;
869 OldList * identifiers;
871 Initializer initializer;
879 public class ClassDefinition : struct
882 ClassDefinition prev, next;
887 OldList * definitions;
893 bool deleteWatchable;
896 public class PropertyWatch : struct
899 PropertyWatch prev, next;
902 OldList * properties;
906 public enum ClassDefType
908 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
909 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
910 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
911 memberAccessClassDef, accessOverrideClassDef
914 public class PropertyDef : struct
917 PropertyDef prev, next;
919 OldList * specifiers;
920 Declarator declarator;
931 public class ClassDef : struct
940 ClassFunction function;
941 OldList * defProperties;
942 PropertyDef propertyDef;
943 PropertyWatch propertyWatch;
945 Identifier defaultProperty;
949 Initializer initializer;
952 AccessMode memberAccess;
958 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
960 public class External : struct
969 FunctionDefinition function;
970 ClassDefinition _class;
971 Declaration declaration;
976 ImportType importType;
979 public class Context : struct
983 BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
984 BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
985 BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
986 BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
989 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
990 ClassDefinition classDef;
991 bool templateTypesOnly;
995 /*************** Compiling passes symbols ***************/
997 public class Symbol : struct
1001 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
1016 External pointerExternal; // external declaration for the pointer to the Class: e.g. __ecereClass___ecereNameSpace__ecere__com__Class
1017 External structExternal; // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
1021 External externalGet;
1022 External externalSet;
1023 External externalPtr; // Property pointer for watchers
1024 External externalIsSet;
1028 External methodExternal;
1029 External methodCodeExternal;
1032 bool imported, declaredStructSym;
1033 Class _class; // for properties only...
1035 // Only used for classes right now...
1036 bool declaredStruct;
1037 bool needConstructor, needDestructor;
1038 char * constructorName, * structName, * className, * destructorName;
1040 ModuleImport module;
1041 ClassImport _import;
1046 bool fireWatchersDone;
1051 OldList * templateParams; // Review the necessity for this
1052 OldList templatedClasses;
1055 Expression propCategory;
1058 // For the .imp file:
1059 public class ClassImport : struct
1062 ClassImport prev, next;
1070 public class FunctionImport : struct
1073 FunctionImport prev, next;
1077 public class ModuleImport : struct
1080 ModuleImport prev, next;
1084 ImportType importType;
1085 AccessMode importAccess;
1088 public class PropertyImport : struct
1091 PropertyImport prev, next;
1094 bool hasSet, hasGet;
1097 public class MethodImport : struct
1100 MethodImport prev, next;
1105 // For the .sym file:
1106 public enum TypeKind
1108 voidType, charType, shortType, intType, int64Type, longType, floatType,
1109 doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1110 ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1111 subClassType, templateType, thisClassType, intPtrType, intSizeType, _BoolType
1114 public class Type : struct
1134 TemplateParameter thisClassTemplate;
1140 Class methodClass; // Clarify what this is!
1149 Expression arraySizeExp;
1155 TemplateParameter templateParameter;
1162 ClassObjectType classObjectType;
1172 bool extraParam:1; // Clarify this... One thing it is used for is adaptive method with their own type explicitly specified
1173 bool directClassAccess:1; // Need to clarify this if this had the same intended purpose as declaredWithStruct
1176 bool passAsTemplate:1;
1179 bool declaredWithStruct:1;
1180 bool typedByReference:1; // Originally typed by reference, regardless of class type
1181 // TODO: Add _Complex & _Imaginary support
1182 // bool complex:1, imaginary:1;
1184 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1186 Type type = (Type)this;
1187 tempString[0] = '\0';
1189 PrintType(type, tempString, false, true);
1199 public struct Operand
1204 unsigned int ptrSize;
1205 union // Promote to using data value
1215 // unsigned char * p; // Now always storing addresses in ui64
1224 public struct OpTable
1227 // binary arithmetic
1228 bool (* Add)(Expression, Operand, Operand);
1229 bool (* Sub)(Expression, Operand, Operand);
1230 bool (* Mul)(Expression, Operand, Operand);
1231 bool (* Div)(Expression, Operand, Operand);
1232 bool (* Mod)(Expression, Operand, Operand);
1235 bool (* Neg)(Expression, Operand);
1237 // unary arithmetic increment and decrement
1238 bool (* Inc)(Expression, Operand);
1239 bool (* Dec)(Expression, Operand);
1241 // binary arithmetic assignment
1242 bool (* Asign)(Expression, Operand, Operand);
1243 bool (* AddAsign)(Expression, Operand, Operand);
1244 bool (* SubAsign)(Expression, Operand, Operand);
1245 bool (* MulAsign)(Expression, Operand, Operand);
1246 bool (* DivAsign)(Expression, Operand, Operand);
1247 bool (* ModAsign)(Expression, Operand, Operand);
1250 bool (* BitAnd)(Expression, Operand, Operand);
1251 bool (* BitOr)(Expression, Operand, Operand);
1252 bool (* BitXor)(Expression, Operand, Operand);
1253 bool (* LShift)(Expression, Operand, Operand);
1254 bool (* RShift)(Expression, Operand, Operand);
1255 bool (* BitNot)(Expression, Operand);
1257 // binary bitwise assignment
1258 bool (* AndAsign)(Expression, Operand, Operand);
1259 bool (* OrAsign)(Expression, Operand, Operand);
1260 bool (* XorAsign)(Expression, Operand, Operand);
1261 bool (* LShiftAsign)(Expression, Operand, Operand);
1262 bool (* RShiftAsign)(Expression, Operand, Operand);
1264 // unary logical negation
1265 bool (* Not)(Expression, Operand);
1267 // binary logical equality
1268 bool (* Equ)(Expression, Operand, Operand);
1269 bool (* Nqu)(Expression, Operand, Operand);
1272 bool (* And)(Expression, Operand, Operand);
1273 bool (* Or)(Expression, Operand, Operand);
1275 // binary logical relational
1276 bool (* Grt)(Expression, Operand, Operand);
1277 bool (* Sma)(Expression, Operand, Operand);
1278 bool (* GrtEqu)(Expression, Operand, Operand);
1279 bool (* SmaEqu)(Expression, Operand, Operand);
1281 bool (* Cond)(Expression, Operand, Operand, Operand);
1284 define MAX_INCLUDE_DEPTH = 30;
1288 void Compiler_Error(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 yylloc.start.col = yylloc.end.col = 1;
1311 yylloc.start.line = yylloc.end.line = 1;
1312 yylloc.start.pos = yylloc.end.pos = 0;
1315 if(!yylloc.start.line)
1319 //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1320 printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1321 //printf(":%d: error: ", yylloc.start.line);
1322 va_start(args, format);
1323 vsnprintf(string, sizeof(string), format, args);
1324 string[sizeof(string)-1] = 0;
1326 fputs(string, stdout);
1327 __thisModule.application.exitCode = 1;
1331 // Error parsing type
1332 parseTypeError = true;
1338 public int GetNumWarnings() { return numWarnings; }
1340 void Compiler_Warning(char * format, ...)
1346 char fileName[MAX_FILENAME];
1348 if(yylloc.start.included)
1350 String include = GetIncludeFileFromID(yylloc.start.included);
1351 GetWorkingDir(string, sizeof(string));
1352 PathCat(string, include);
1356 GetWorkingDir(string, sizeof(string));
1357 PathCat(string, sourceFile);
1360 // Skip these warnings from MinGW-w64 GCC 4.8 in intrin-impl.h
1361 GetLastDirectory(string, fileName);
1362 if(!strcmp(fileName, "intrin-impl.h")) return;
1366 //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1367 printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1368 //printf(":%d: warning: ", yylloc.start.line);
1369 va_start(args, format);
1370 vsnprintf(string, sizeof(string), format, args);
1371 string[sizeof(string)-1] = 0;
1373 fputs(string, stdout);
1380 int yyerror(char * s)
1385 //printf("\n%*s\n%*s\n", column, "^", column, s);
1387 Compiler_Error($"syntax error\n");
1392 Platform targetPlatform;
1394 public int GetHostBits()
1396 // Default to runtime platform in case we fail to determine host
1397 int hostBits = (sizeof(uintptr) == 8) ? 64 : 32;
1398 String hostType = getenv("HOSTTYPE");
1402 DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1405 if(f.GetLine(host, sizeof(host)))
1412 if(!strcmp(hostType, "x86_64"))
1414 else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1420 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1424 public void SetTargetBits(int bits) { targetBits = bits; };
1425 public int GetTargetBits() { return targetBits; };