2 public import static "ecere"
24 #define yylloc _yylloc
30 identifier = IDENTIFIER,
32 stringLiteral = STRING_LITERAL,
45 mulAssign = MUL_ASSIGN,
46 divAssign = DIV_ASSIGN,
47 modAssign = MOD_ASSIGN,
48 addAssign = ADD_ASSIGN,
49 subAssign = SUB_ASSIGN,
50 leftAssign = LEFT_ASSIGN,
51 rightAssign = RIGHT_ASSIGN,
52 andAssign = AND_ASSIGN,
53 xorAssign = XOR_ASSIGN,
93 thisClass = THISCLASS,
94 className = CLASS_NAME,
102 _extStorage = EXT_STORAGE,
109 typedObject = TYPED_OBJECT,
110 anyObject = ANY_OBJECT,
112 extension = EXTENSION,
116 stopWatching = STOPWATCHING,
117 fireWatchers = FIREWATCHERS,
118 _watchable = WATCHABLE,
119 classDesigner = CLASS_DESIGNER,
120 classNoExpansion = CLASS_NO_EXPANSION,
121 classFixed = CLASS_FIXED,
122 isPropSet = ISPROPSET,
123 classDefaultProperty = CLASS_DEFAULT_PROPERTY,
124 propertyCategory = PROPERTY_CATEGORY,
125 classData = CLASS_DATA,
126 classProperty = CLASS_PROPERTY,
128 nameSpace = NAMESPACE,
135 databaseOpen = DATABASE_OPEN,
137 attribDep = ATTRIB_DEP,
142 imaginary = _IMAGINARY,
143 _restrict = RESTRICT,
147 enum Order { ascending, descending };
149 public class DBTableDef : struct
154 OldList * definitions;
158 enum DBTableEntryType { fieldEntry, indexEntry };
160 class DBTableEntry : struct
162 DBTableEntry prev, next;
163 DBTableEntryType type;
176 class DBIndexItem : struct
178 DBIndexItem prev, next;
183 bool inCompiler = false;
184 public void SetInCompiler(bool b) { inCompiler = b; }
187 Context globalContext;
188 OldList * excludedSymbols;
193 Module privateModule;
194 public void SetPrivateModule(Module module) { privateModule = module; }public Module GetPrivateModule() { return privateModule; }
195 ModuleImport mainModule;
196 public void SetMainModule(ModuleImport moduleImport) { mainModule = moduleImport; } public ModuleImport GetMainModule() { return mainModule; }
198 public void SetFileInput(File file) { fileInput = file; }
199 char * symbolsDir = null;
200 public void SetSymbolsDir(const char * s) {
202 symbolsDir = CopyString(s);
203 } public const char * GetSymbolsDir() { return symbolsDir ? symbolsDir : ""; }
204 const char * outputFile;
205 public void SetOutputFile(const char * s) { outputFile = s; } public const char * GetOutputFile() { return outputFile; }
206 const char * sourceFile;
207 public void SetSourceFile(const char * s) { sourceFile = s; } public const char * GetSourceFile() { return sourceFile; }
208 const char * i18nModuleName;
209 public void SetI18nModuleName(const char * s) { i18nModuleName = s; } public const char * GetI18nModuleName() { return i18nModuleName; }
211 public void SetGlobalContext(Context context) { globalContext = context; } public Context GetGlobalContext() { return globalContext; }
212 public void SetTopContext(Context context) { topContext = context; } public Context GetTopContext() { return topContext; }
213 public void SetCurrentContext(Context context) { curContext = context; } public Context GetCurrentContext() { return curContext; }
214 public void SetExcludedSymbols(OldList * list) { excludedSymbols = list; }
215 public void SetImports(OldList * list) { imports = list; }
216 public void SetDefines(OldList * list) { defines = list; }
218 bool outputLineNumbers = true;
219 public void SetOutputLineNumbers(bool value) { outputLineNumbers = value; }
221 public void FixModuleName(char *moduleName)
223 ChangeCh(moduleName, '.', '_');
224 ChangeCh(moduleName, ' ', '_');
225 ChangeCh(moduleName, '-', '_');
226 ChangeCh(moduleName, '&', '_');
229 // todo support %var% variables for windows and $var for linux?
230 public char * PassArg(char * output, const char * input)
233 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
234 const char * escChars = " !\"%&'()+,;=[]^`{}~"; // windowsFileNameCharsNeedEscaping;
235 const char * escCharsQuoted = "\"";
237 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
238 const char * escChars = " !\"$&'()*:;<=>?[\\`{|"; // linuxFileNameCharsNeedEscaping;
239 const char * escCharsQuoted = "\"()$";
241 bool quoting = false;
243 const char *i = input, *l = input;
245 while(*l && !strchr(escChars, *l)) l++;
246 if(*l) quoting = true;
251 while(*l && !strchr(escChars, *l)) l++;
252 if(*l) quoting = true;
260 if(strchr(quoting ? escCharsQuoted : escChars, *i))
269 /*public Module GetPrivateModule()
271 return privateModule;
274 public class GlobalData : BTNode
278 char * dataTypeString;
284 public class TemplatedType : BTNode
287 TemplateParameter param;
290 class DataRedefinition : struct
292 DataRedefinition prev, next;
294 char type1[1024], type2[1024];
297 public struct CodePosition
300 int line, charPos, pos;
303 void AdjustDelete(BufferLocation start, BufferLocation end)
305 // Location is before, nothing to do
306 if(line - 1 < start.y || (line - 1 == start.y && charPos - 1 < start.x))
308 // Location is inside deleted bytes, point to the start
309 if((line - 1 >= start.y && (line - 1 > start.y || charPos - 1 >= start.x)) &&
310 (line - 1 >= end.y && (line - 1 > end.y || charPos - 1 >= end.x)))
313 if(line - 1 >= end.y)
315 // Location is on another line
317 line -= end.y - start.y;
318 // Location is the last touched line
321 if(charPos - 1 >= end.x)
324 //if(start.line == end.line)
325 charPos -= end.x - start.x;
333 charPos = start.x + 1;
337 // Assuming no carriage return before first character ???? fixed?
338 void AdjustAdd(BufferLocation start, BufferLocation end)
340 int numLines = end.y - start.y;
341 if(line - 1 >= start.y)
343 if(line - 1 > start.y)
347 if(charPos - 1 > start.x || (charPos - 1 == start.x /*&& (numLines ? true : false)*/))
350 //charPos - 1 += numLines ? end.x : (end.x - start.x);
351 charPos += end.x - start.x;
358 public struct Location
361 CodePosition start, end;
363 bool Inside(int line, int charPos)
365 return (start.line < line || (start.line == line && start.charPos <= charPos)) &&
366 (end.line > line || (end.line == line && end.charPos >= charPos));
370 public enum DefinitionType { moduleDefinition, classDefinition, defineDefinition, functionDefinition, dataDefinition };
372 public class Definition : struct
375 Definition prev, next;
380 public class ImportedModule : struct
383 ImportedModule prev, next;
386 ImportType importType;
389 AccessMode importAccess;
392 public class Identifier : struct
395 Identifier prev, next;
397 // TODO: NameSpace * nameSpace;
404 public enum ExpressionType
406 identifierExp, instanceExp, constantExp, stringExp, opExp,
407 bracketsExp, indexExp, callExp, memberExp, pointerExp, typeSizeExp,
408 castExp, conditionExp, newExp, renewExp, classSizeExp,
409 dummyExp, dereferenceErrorExp, symbolErrorExp,
410 memberSymbolErrorExp, memoryErrorExp, unknownErrorExp,
412 extensionCompoundExp, classExp, classDataExp, new0Exp, renew0Exp,
413 dbopenExp, dbfieldExp, dbtableExp, dbindexExp, extensionExpressionExp, extensionInitializerExp,
414 vaArgExp, arrayExp, typeAlignExp,
415 memberPropertyErrorExp, functionCallErrorExp, divideBy0ErrorExp
418 public enum MemberType
420 unresolvedMember, propertyMember, methodMember, dataMember, reverseConversionMember, classPropertyMember
423 public class ExpUsage
426 bool usageGet:1, usageSet:1, usageArg:1, usageCall:1, usageMember:1, usageDeepGet:1, usageRef:1, usageDelete:1;
429 public class TemplateParameter : struct
432 TemplateParameter prev, next;
435 TemplateParameterType type;
436 Identifier identifier;
439 TemplateDatatype dataType; // For both base datatype (type) and data type (expression)
440 TemplateMemberType memberType; // For identifier
442 TemplateArgument defaultArgument;
444 // For type parameters
445 const char * dataTypeString;
449 public class TemplateDatatype : struct
452 OldList * specifiers;
456 public class TemplateArgument : struct
459 TemplateArgument prev, next;
463 TemplateParameterType type;
466 Expression expression;
467 Identifier identifier;
468 TemplateDatatype templateDatatype;
472 public enum SpecifierType
474 baseSpecifier, nameSpecifier, enumSpecifier, structSpecifier, unionSpecifier, /*classSpecifier,*/
475 extendedSpecifier, typeOfSpecifier, subClassSpecifier, templateTypeSpecifier
478 public class Specifier : struct
481 Specifier prev, next;
492 OldList/*<TemplateArgument>*/ * templateArgs;
497 OldList/*<Enumerator>*/ * list;
498 OldList/*<Specifier>*/ * baseSpecs;
499 OldList/*<ClassDef>*/ * definitions;
502 ExtDecl extDeclStruct;
504 Expression expression;
506 TemplateParameter templateParameter;
510 public class Attribute : struct
513 Attribute prev, next;
519 public class Attrib : struct
527 public class ExtDecl : struct
539 public enum ExtDeclType
541 extDeclString, extDeclAttrib
544 public class Expression : struct
547 Expression prev, next;
555 Identifier identifier;
558 Instantiation instance;
567 OldList * specifiers;
590 MemberType memberType;
596 Expression exp1, exp2;
635 Initializer initializer;
651 // *** COMPILING DATA ***
663 uint needTemplateCast;
683 needTemplateCast = 0;
687 public class Enumerator : struct
690 Enumerator prev, next;
696 class Pointer : struct
700 OldList * qualifiers;
704 public enum DeclaratorType
706 structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
707 functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
710 public class Declarator : struct
713 Declarator prev, next;
716 Symbol symbol;//, propSymbol;
717 Declarator declarator;
720 Identifier identifier;
734 OldList * parameters;
747 public enum InitializerType { expInitializer, listInitializer };
749 public class Initializer : struct
752 Initializer prev, next;
754 InitializerType type;
764 public class InitDeclarator : struct
767 InitDeclarator prev, next;
769 Declarator declarator;
770 Initializer initializer;
773 public enum ClassObjectType
781 public class TypeName : struct
786 OldList * qualifiers;
787 Declarator declarator;
788 //bool /*typedObject, */byReference;
790 ClassObjectType classObjectType;
794 class AsmField : struct
799 Expression expression;
803 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
804 expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
805 forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
806 fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
809 public class Statement : struct
812 Statement prev, next;
817 OldList * expressions;
830 OldList * declarations;
831 OldList * statements;
871 OldList * inputFields;
872 OldList * outputFields;
873 OldList * clobberedFields;
877 Expression watcher, object;
878 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
891 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
893 public class Declaration : struct
896 Declaration prev, next;
898 DeclarationType type;
903 OldList * specifiers;
904 OldList * declarators;
913 Specifier extStorage;
918 public class Instantiation : struct
921 Instantiation prev, next;
930 Location nameLoc, insideLoc;
934 public enum MembersInitType { dataMembersInit, methodMembersInit };
936 public class FunctionDefinition : struct
939 FunctionDefinition prev, next;
941 OldList * specifiers;
942 Declarator declarator;
943 OldList * declarations;
946 OldList attached; // For IDE
953 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
956 public class ClassFunction : struct
959 ClassFunction prev, next;
961 OldList * specifiers;
962 Declarator declarator;
963 OldList * declarations;
966 OldList attached; // For IDE
974 bool isConstructor, isDestructor;
979 public class MembersInit : struct
982 MembersInit prev, next;
984 MembersInitType type;
987 OldList * dataMembers;
988 ClassFunction function;
993 public class MemberInit : struct
996 MemberInit prev, next;
999 OldList * identifiers;
1001 Initializer initializer;
1009 public class ClassDefinition : struct
1012 ClassDefinition prev, next;
1016 OldList * baseSpecs;
1017 OldList * definitions;
1019 Location blockStart;
1022 AccessMode declMode;
1023 bool deleteWatchable;
1026 public class PropertyWatch : struct
1029 PropertyWatch prev, next;
1032 OldList * properties;
1036 public enum ClassDefType
1038 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
1039 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
1040 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
1041 memberAccessClassDef, accessOverrideClassDef
1044 public class PropertyDef : struct
1047 PropertyDef prev, next;
1049 OldList * specifiers;
1050 Declarator declarator;
1054 Statement issetStmt;
1056 Expression category;
1065 public class ClassDef : struct
1068 ClassDef prev, next;
1074 ClassFunction function;
1075 OldList * defProperties;
1076 PropertyDef propertyDef;
1077 PropertyWatch propertyWatch;
1079 Identifier defaultProperty;
1083 Initializer initializer;
1086 AccessMode memberAccess;
1092 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
1094 public class External : struct
1097 External prev, next;
1103 FunctionDefinition function;
1104 ClassDefinition _class;
1105 Declaration declaration;
1106 char * importString;
1110 ImportType importType;
1113 public class Context : struct
1117 BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
1118 BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
1119 BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
1120 BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
1123 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
1124 ClassDefinition classDef;
1125 bool templateTypesOnly;
1129 /*************** Compiling passes symbols ***************/
1131 public class Symbol : struct
1135 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
1150 External pointerExternal; // external declaration for the pointer to the Class: e.g. __ecereClass___ecereNameSpace__ecere__com__Class
1151 External structExternal; // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
1155 External externalGet;
1156 External externalSet;
1157 External externalPtr; // Property pointer for watchers
1158 External externalIsSet;
1162 External methodExternal;
1163 External methodCodeExternal;
1166 bool imported, declaredStructSym;
1167 Class _class; // for properties only...
1169 // Only used for classes right now...
1170 bool declaredStruct;
1171 bool needConstructor, needDestructor;
1172 char * constructorName, * structName, * className, * destructorName;
1174 ModuleImport module;
1175 ClassImport _import;
1180 bool fireWatchersDone;
1185 OldList * templateParams; // Review the necessity for this
1186 OldList templatedClasses;
1189 Expression propCategory;
1192 // For the .imp file:
1193 public class ClassImport : struct
1196 ClassImport prev, next;
1204 public class FunctionImport : struct
1207 FunctionImport prev, next;
1211 public class ModuleImport : struct
1214 ModuleImport prev, next;
1218 ImportType importType;
1219 AccessMode importAccess;
1222 public class PropertyImport : struct
1225 PropertyImport prev, next;
1228 bool hasSet, hasGet;
1231 public class MethodImport : struct
1234 MethodImport prev, next;
1239 // For the .sym file:
1240 public enum TypeKind
1242 voidType, charType, shortType, intType, int64Type, longType, floatType,
1243 doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1244 ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1245 subClassType, templateType, thisClassType, intPtrType, intSizeType, _BoolType
1248 public class Type : struct
1268 TemplateParameter thisClassTemplate;
1274 Class methodClass; // Clarify what this is!
1283 Expression arraySizeExp;
1289 TemplateParameter templateParameter;
1296 ClassObjectType classObjectType;
1306 bool extraParam:1; // Clarify this... One thing it is used for is adaptive method with their own type explicitly specified
1307 bool directClassAccess:1; // Need to clarify this if this had the same intended purpose as declaredWithStruct
1310 bool passAsTemplate:1;
1313 bool declaredWithStruct:1;
1314 bool typedByReference:1; // Originally typed by reference, regardless of class type
1316 // bool wasThisClass:1;
1317 // TODO: Add _Complex & _Imaginary support
1318 // bool complex:1, imaginary:1;
1320 const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1322 Type type = (Type)this;
1323 tempString[0] = '\0';
1325 PrintType(type, tempString, false, true);
1334 property bool specConst
1339 while((t.kind == pointerType || t.kind == arrayType) && t.type) t = t.type;
1345 public struct Operand
1350 unsigned int ptrSize;
1351 union // Promote to using data value
1361 // unsigned char * p; // Now always storing addresses in ui64
1370 public struct OpTable
1373 // binary arithmetic
1374 bool (* Add)(Expression, Operand, Operand);
1375 bool (* Sub)(Expression, Operand, Operand);
1376 bool (* Mul)(Expression, Operand, Operand);
1377 bool (* Div)(Expression, Operand, Operand);
1378 bool (* Mod)(Expression, Operand, Operand);
1381 bool (* Neg)(Expression, Operand);
1383 // unary arithmetic increment and decrement
1384 bool (* Inc)(Expression, Operand);
1385 bool (* Dec)(Expression, Operand);
1387 // binary arithmetic assignment
1388 bool (* Asign)(Expression, Operand, Operand);
1389 bool (* AddAsign)(Expression, Operand, Operand);
1390 bool (* SubAsign)(Expression, Operand, Operand);
1391 bool (* MulAsign)(Expression, Operand, Operand);
1392 bool (* DivAsign)(Expression, Operand, Operand);
1393 bool (* ModAsign)(Expression, Operand, Operand);
1396 bool (* BitAnd)(Expression, Operand, Operand);
1397 bool (* BitOr)(Expression, Operand, Operand);
1398 bool (* BitXor)(Expression, Operand, Operand);
1399 bool (* LShift)(Expression, Operand, Operand);
1400 bool (* RShift)(Expression, Operand, Operand);
1401 bool (* BitNot)(Expression, Operand);
1403 // binary bitwise assignment
1404 bool (* AndAsign)(Expression, Operand, Operand);
1405 bool (* OrAsign)(Expression, Operand, Operand);
1406 bool (* XorAsign)(Expression, Operand, Operand);
1407 bool (* LShiftAsign)(Expression, Operand, Operand);
1408 bool (* RShiftAsign)(Expression, Operand, Operand);
1410 // unary logical negation
1411 bool (* Not)(Expression, Operand);
1413 // binary logical equality
1414 bool (* Equ)(Expression, Operand, Operand);
1415 bool (* Nqu)(Expression, Operand, Operand);
1418 bool (* And)(Expression, Operand, Operand);
1419 bool (* Or)(Expression, Operand, Operand);
1421 // binary logical relational
1422 bool (* Grt)(Expression, Operand, Operand);
1423 bool (* Sma)(Expression, Operand, Operand);
1424 bool (* GrtEqu)(Expression, Operand, Operand);
1425 bool (* SmaEqu)(Expression, Operand, Operand);
1427 bool (* Cond)(Expression, Operand, Operand, Operand);
1430 define MAX_INCLUDE_DEPTH = 30;
1434 void Compiler_Error(const char * format, ...)
1443 if(yylloc.start.included)
1445 GetWorkingDir(string, sizeof(string));
1446 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1450 GetWorkingDir(string, sizeof(string));
1451 PathCat(string, sourceFile);
1453 printf("%s", string);
1456 yylloc.start.col = yylloc.end.col = 1;
1457 yylloc.start.line = yylloc.end.line = 1;
1458 yylloc.start.pos = yylloc.end.pos = 0;
1461 if(!yylloc.start.line)
1465 //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1466 printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1467 //printf(":%d: error: ", yylloc.start.line);
1468 va_start(args, format);
1469 vsnprintf(string, sizeof(string), format, args);
1470 string[sizeof(string)-1] = 0;
1472 fputs(string, stdout);
1473 __thisModule.application.exitCode = 1;
1477 // Error parsing type
1478 parseTypeError = true;
1484 public int GetNumWarnings() { return numWarnings; }
1486 void Compiler_Warning(const char * format, ...)
1492 char fileName[MAX_FILENAME];
1494 if(yylloc.start.included)
1496 String include = GetIncludeFileFromID(yylloc.start.included);
1497 GetWorkingDir(string, sizeof(string));
1498 PathCat(string, include);
1502 GetWorkingDir(string, sizeof(string));
1503 PathCat(string, sourceFile);
1506 // Skip these warnings from MinGW-w64 GCC 4.8 in intrin-impl.h
1507 GetLastDirectory(string, fileName);
1508 if(!strcmp(fileName, "intrin-impl.h")) return;
1510 printf("%s", string);
1512 //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1513 printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1514 //printf(":%d: warning: ", yylloc.start.line);
1515 va_start(args, format);
1516 vsnprintf(string, sizeof(string), format, args);
1517 string[sizeof(string)-1] = 0;
1519 fputs(string, stdout);
1531 //printf("\n%*s\n%*s\n", column, "^", column, s);
1533 Compiler_Error($"syntax error\n");
1538 Platform targetPlatform;
1540 public int GetHostBits()
1542 // Default to runtime platform in case we fail to determine host
1543 int hostBits = (sizeof(uintptr) == 8) ? 64 : 32;
1544 String hostType = getenv("HOSTTYPE");
1548 DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1551 if(f.GetLine(host, sizeof(host)))
1558 if(!strcmp(hostType, "x86_64"))
1560 else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1566 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1570 public void SetTargetBits(int bits) { targetBits = bits; };
1571 public int GetTargetBits() { return targetBits; };