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(char * s) {
202 symbolsDir = CopyString(s);
203 } public char * GetSymbolsDir() { return symbolsDir ? symbolsDir : ""; }
205 public void SetOutputFile(char * s) { outputFile = s; } public char * GetOutputFile() { return outputFile; }
207 public void SetSourceFile(char * s) { sourceFile = s; } public char * GetSourceFile() { return sourceFile; }
208 char * i18nModuleName;
209 public void SetI18nModuleName(char * s) { i18nModuleName = s; } public 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;
242 char *o = output, *i = input, *l = input;
244 while(*l && !strchr(escChars, *l)) l++;
245 if(*l) quoting = true;
250 while(*l && !strchr(escChars, *l)) l++;
251 if(*l) quoting = true;
259 if(strchr(quoting ? escCharsQuoted : escChars, *i))
268 /*public Module GetPrivateModule()
270 return privateModule;
273 public class GlobalData : BTNode
277 char * dataTypeString;
283 public class TemplatedType : BTNode
286 TemplateParameter param;
289 class DataRedefinition : struct
291 DataRedefinition prev, next;
293 char type1[1024], type2[1024];
296 public struct CodePosition
299 int line, charPos, pos;
302 void AdjustDelete(BufferLocation start, BufferLocation end)
304 // Location is before, nothing to do
305 if(line - 1 < start.y || (line - 1 == start.y && charPos - 1 < start.x))
307 // Location is inside deleted bytes, point to the start
308 if((line - 1 >= start.y && (line - 1 > start.y || charPos - 1 >= start.x)) &&
309 (line - 1 >= end.y && (line - 1 > end.y || charPos - 1 >= end.x)))
312 if(line - 1 >= end.y)
314 // Location is on another line
316 line -= end.y - start.y;
317 // Location is the last touched line
320 if(charPos - 1 >= end.x)
323 //if(start.line == end.line)
324 charPos -= end.x - start.x;
332 charPos = start.x + 1;
336 // Assuming no carriage return before first character ???? fixed?
337 void AdjustAdd(BufferLocation start, BufferLocation end)
339 int numLines = end.y - start.y;
340 if(line - 1 >= start.y)
342 if(line - 1 > start.y)
346 if(charPos - 1 > start.x || (charPos - 1 == start.x /*&& (numLines ? true : false)*/))
349 //charPos - 1 += numLines ? end.x : (end.x - start.x);
350 charPos += end.x - start.x;
357 public struct Location
360 CodePosition start, end;
362 bool Inside(int line, int charPos)
364 return (start.line < line || (start.line == line && start.charPos <= charPos)) &&
365 (end.line > line || (end.line == line && end.charPos >= charPos));
369 public enum DefinitionType { moduleDefinition, classDefinition, defineDefinition, functionDefinition, dataDefinition };
371 public class Definition : struct
374 Definition prev, next;
379 public class ImportedModule : struct
382 ImportedModule prev, next;
385 ImportType importType;
388 AccessMode importAccess;
391 public class Identifier : struct
394 Identifier prev, next;
396 // TODO: NameSpace * nameSpace;
403 public enum ExpressionType
405 identifierExp, instanceExp, constantExp, stringExp, opExp,
406 bracketsExp, indexExp, callExp, memberExp, pointerExp, typeSizeExp,
407 castExp, conditionExp, newExp, renewExp, classSizeExp,
408 dummyExp, dereferenceErrorExp, symbolErrorExp,
409 memberSymbolErrorExp, memoryErrorExp, unknownErrorExp,
411 extensionCompoundExp, classExp, classDataExp, new0Exp, renew0Exp,
412 dbopenExp, dbfieldExp, dbtableExp, dbindexExp, extensionExpressionExp, extensionInitializerExp,
413 vaArgExp, arrayExp, typeAlignExp,
414 memberPropertyErrorExp, functionCallErrorExp, divideBy0ErrorExp
417 public enum MemberType
419 unresolvedMember, propertyMember, methodMember, dataMember, reverseConversionMember, classPropertyMember
422 public class ExpUsage
425 bool usageGet:1, usageSet:1, usageArg:1, usageCall:1, usageMember:1, usageDeepGet:1, usageRef:1, usageDelete:1;
428 public class TemplateParameter : struct
431 TemplateParameter prev, next;
434 TemplateParameterType type;
435 Identifier identifier;
438 TemplateDatatype dataType; // For both base datatype (type) and data type (expression)
439 TemplateMemberType memberType; // For identifier
441 TemplateArgument defaultArgument;
443 // For type parameters
444 char * dataTypeString;
448 public class TemplateDatatype : struct
451 OldList * specifiers;
455 public class TemplateArgument : struct
458 TemplateArgument prev, next;
462 TemplateParameterType type;
465 Expression expression;
466 Identifier identifier;
467 TemplateDatatype templateDatatype;
471 public enum SpecifierType
473 baseSpecifier, nameSpecifier, enumSpecifier, structSpecifier, unionSpecifier, /*classSpecifier,*/
474 extendedSpecifier, typeOfSpecifier, subClassSpecifier, templateTypeSpecifier
477 public class Specifier : struct
480 Specifier prev, next;
491 OldList * templateArgs;
498 OldList/*<ClassDef>*/ * definitions;
501 ExtDecl extDeclStruct;
503 Expression expression;
505 TemplateParameter templateParameter;
509 public class Attribute : struct
512 Attribute prev, next;
518 public class Attrib : struct
526 public class ExtDecl : struct
538 public enum ExtDeclType
540 extDeclString, extDeclAttrib
543 public class Expression : struct
546 Expression prev, next;
554 Identifier identifier;
557 Instantiation instance;
566 OldList * specifiers;
589 MemberType memberType;
595 Expression exp1, exp2;
634 Initializer initializer;
650 // *** COMPILING DATA ***
684 public class Enumerator : struct
687 Enumerator prev, next;
693 class Pointer : struct
697 OldList * qualifiers;
701 public enum DeclaratorType
703 structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
704 functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
707 public class Declarator : struct
710 Declarator prev, next;
713 Symbol symbol;//, propSymbol;
714 Declarator declarator;
717 Identifier identifier;
731 OldList * parameters;
744 public enum InitializerType { expInitializer, listInitializer };
746 public class Initializer : struct
749 Initializer prev, next;
751 InitializerType type;
761 public class InitDeclarator : struct
764 InitDeclarator prev, next;
766 Declarator declarator;
767 Initializer initializer;
770 public enum ClassObjectType
778 public class TypeName : struct
783 OldList * qualifiers;
784 Declarator declarator;
785 //bool /*typedObject, */byReference;
787 ClassObjectType classObjectType;
791 class AsmField : struct
796 Expression expression;
800 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
801 expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
802 forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
803 fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
806 public class Statement : struct
809 Statement prev, next;
814 OldList * expressions;
827 OldList * declarations;
828 OldList * statements;
868 OldList * inputFields;
869 OldList * outputFields;
870 OldList * clobberedFields;
874 Expression watcher, object;
875 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
888 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
890 public class Declaration : struct
893 Declaration prev, next;
895 DeclarationType type;
900 OldList * specifiers;
901 OldList * declarators;
910 Specifier extStorage;
915 public class Instantiation : struct
918 Instantiation prev, next;
927 Location nameLoc, insideLoc;
931 public enum MembersInitType { dataMembersInit, methodMembersInit };
933 public class FunctionDefinition : struct
936 FunctionDefinition prev, next;
938 OldList * specifiers;
939 Declarator declarator;
940 OldList * declarations;
943 OldList attached; // For IDE
950 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
953 public class ClassFunction : struct
956 ClassFunction prev, next;
958 OldList * specifiers;
959 Declarator declarator;
960 OldList * declarations;
963 OldList attached; // For IDE
971 bool isConstructor, isDestructor;
976 public class MembersInit : struct
979 MembersInit prev, next;
981 MembersInitType type;
984 OldList * dataMembers;
985 ClassFunction function;
990 public class MemberInit : struct
993 MemberInit prev, next;
996 OldList * identifiers;
998 Initializer initializer;
1006 public class ClassDefinition : struct
1009 ClassDefinition prev, next;
1013 OldList * baseSpecs;
1014 OldList * definitions;
1016 Location blockStart;
1019 AccessMode declMode;
1020 bool deleteWatchable;
1023 public class PropertyWatch : struct
1026 PropertyWatch prev, next;
1029 OldList * properties;
1033 public enum ClassDefType
1035 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
1036 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
1037 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
1038 memberAccessClassDef, accessOverrideClassDef
1041 public class PropertyDef : struct
1044 PropertyDef prev, next;
1046 OldList * specifiers;
1047 Declarator declarator;
1051 Statement issetStmt;
1053 Expression category;
1062 public class ClassDef : struct
1065 ClassDef prev, next;
1071 ClassFunction function;
1072 OldList * defProperties;
1073 PropertyDef propertyDef;
1074 PropertyWatch propertyWatch;
1076 Identifier defaultProperty;
1080 Initializer initializer;
1083 AccessMode memberAccess;
1089 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
1091 public class External : struct
1094 External prev, next;
1100 FunctionDefinition function;
1101 ClassDefinition _class;
1102 Declaration declaration;
1103 char * importString;
1107 ImportType importType;
1110 public class Context : struct
1114 BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
1115 BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
1116 BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
1117 BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
1120 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
1121 ClassDefinition classDef;
1122 bool templateTypesOnly;
1126 /*************** Compiling passes symbols ***************/
1128 public class Symbol : struct
1132 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
1147 External pointerExternal; // external declaration for the pointer to the Class: e.g. __ecereClass___ecereNameSpace__ecere__com__Class
1148 External structExternal; // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
1152 External externalGet;
1153 External externalSet;
1154 External externalPtr; // Property pointer for watchers
1155 External externalIsSet;
1159 External methodExternal;
1160 External methodCodeExternal;
1163 bool imported, declaredStructSym;
1164 Class _class; // for properties only...
1166 // Only used for classes right now...
1167 bool declaredStruct;
1168 bool needConstructor, needDestructor;
1169 char * constructorName, * structName, * className, * destructorName;
1171 ModuleImport module;
1172 ClassImport _import;
1177 bool fireWatchersDone;
1182 OldList * templateParams; // Review the necessity for this
1183 OldList templatedClasses;
1186 Expression propCategory;
1189 // For the .imp file:
1190 public class ClassImport : struct
1193 ClassImport prev, next;
1201 public class FunctionImport : struct
1204 FunctionImport prev, next;
1208 public class ModuleImport : struct
1211 ModuleImport prev, next;
1215 ImportType importType;
1216 AccessMode importAccess;
1219 public class PropertyImport : struct
1222 PropertyImport prev, next;
1225 bool hasSet, hasGet;
1228 public class MethodImport : struct
1231 MethodImport prev, next;
1236 // For the .sym file:
1237 public enum TypeKind
1239 voidType, charType, shortType, intType, int64Type, longType, floatType,
1240 doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1241 ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1242 subClassType, templateType, thisClassType, intPtrType, intSizeType, _BoolType
1245 public class Type : struct
1265 TemplateParameter thisClassTemplate;
1271 Class methodClass; // Clarify what this is!
1280 Expression arraySizeExp;
1286 TemplateParameter templateParameter;
1293 ClassObjectType classObjectType;
1303 bool extraParam:1; // Clarify this... One thing it is used for is adaptive method with their own type explicitly specified
1304 bool directClassAccess:1; // Need to clarify this if this had the same intended purpose as declaredWithStruct
1307 bool passAsTemplate:1;
1310 bool declaredWithStruct:1;
1311 bool typedByReference:1; // Originally typed by reference, regardless of class type
1312 // TODO: Add _Complex & _Imaginary support
1313 // bool complex:1, imaginary:1;
1315 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1317 Type type = (Type)this;
1318 tempString[0] = '\0';
1320 PrintType(type, tempString, false, true);
1330 public struct Operand
1335 unsigned int ptrSize;
1336 union // Promote to using data value
1346 // unsigned char * p; // Now always storing addresses in ui64
1355 public struct OpTable
1358 // binary arithmetic
1359 bool (* Add)(Expression, Operand, Operand);
1360 bool (* Sub)(Expression, Operand, Operand);
1361 bool (* Mul)(Expression, Operand, Operand);
1362 bool (* Div)(Expression, Operand, Operand);
1363 bool (* Mod)(Expression, Operand, Operand);
1366 bool (* Neg)(Expression, Operand);
1368 // unary arithmetic increment and decrement
1369 bool (* Inc)(Expression, Operand);
1370 bool (* Dec)(Expression, Operand);
1372 // binary arithmetic assignment
1373 bool (* Asign)(Expression, Operand, Operand);
1374 bool (* AddAsign)(Expression, Operand, Operand);
1375 bool (* SubAsign)(Expression, Operand, Operand);
1376 bool (* MulAsign)(Expression, Operand, Operand);
1377 bool (* DivAsign)(Expression, Operand, Operand);
1378 bool (* ModAsign)(Expression, Operand, Operand);
1381 bool (* BitAnd)(Expression, Operand, Operand);
1382 bool (* BitOr)(Expression, Operand, Operand);
1383 bool (* BitXor)(Expression, Operand, Operand);
1384 bool (* LShift)(Expression, Operand, Operand);
1385 bool (* RShift)(Expression, Operand, Operand);
1386 bool (* BitNot)(Expression, Operand);
1388 // binary bitwise assignment
1389 bool (* AndAsign)(Expression, Operand, Operand);
1390 bool (* OrAsign)(Expression, Operand, Operand);
1391 bool (* XorAsign)(Expression, Operand, Operand);
1392 bool (* LShiftAsign)(Expression, Operand, Operand);
1393 bool (* RShiftAsign)(Expression, Operand, Operand);
1395 // unary logical negation
1396 bool (* Not)(Expression, Operand);
1398 // binary logical equality
1399 bool (* Equ)(Expression, Operand, Operand);
1400 bool (* Nqu)(Expression, Operand, Operand);
1403 bool (* And)(Expression, Operand, Operand);
1404 bool (* Or)(Expression, Operand, Operand);
1406 // binary logical relational
1407 bool (* Grt)(Expression, Operand, Operand);
1408 bool (* Sma)(Expression, Operand, Operand);
1409 bool (* GrtEqu)(Expression, Operand, Operand);
1410 bool (* SmaEqu)(Expression, Operand, Operand);
1412 bool (* Cond)(Expression, Operand, Operand, Operand);
1415 define MAX_INCLUDE_DEPTH = 30;
1419 void Compiler_Error(char * format, ...)
1428 if(yylloc.start.included)
1430 GetWorkingDir(string, sizeof(string));
1431 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1435 GetWorkingDir(string, sizeof(string));
1436 PathCat(string, sourceFile);
1441 yylloc.start.col = yylloc.end.col = 1;
1442 yylloc.start.line = yylloc.end.line = 1;
1443 yylloc.start.pos = yylloc.end.pos = 0;
1446 if(!yylloc.start.line)
1450 //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1451 printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1452 //printf(":%d: error: ", yylloc.start.line);
1453 va_start(args, format);
1454 vsnprintf(string, sizeof(string), format, args);
1455 string[sizeof(string)-1] = 0;
1457 fputs(string, stdout);
1458 __thisModule.application.exitCode = 1;
1462 // Error parsing type
1463 parseTypeError = true;
1469 public int GetNumWarnings() { return numWarnings; }
1471 void Compiler_Warning(char * format, ...)
1477 char fileName[MAX_FILENAME];
1479 if(yylloc.start.included)
1481 String include = GetIncludeFileFromID(yylloc.start.included);
1482 GetWorkingDir(string, sizeof(string));
1483 PathCat(string, include);
1487 GetWorkingDir(string, sizeof(string));
1488 PathCat(string, sourceFile);
1491 // Skip these warnings from MinGW-w64 GCC 4.8 in intrin-impl.h
1492 GetLastDirectory(string, fileName);
1493 if(!strcmp(fileName, "intrin-impl.h")) return;
1497 //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1498 printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1499 //printf(":%d: warning: ", yylloc.start.line);
1500 va_start(args, format);
1501 vsnprintf(string, sizeof(string), format, args);
1502 string[sizeof(string)-1] = 0;
1504 fputs(string, stdout);
1516 //printf("\n%*s\n%*s\n", column, "^", column, s);
1518 Compiler_Error($"syntax error\n");
1523 Platform targetPlatform;
1525 public int GetHostBits()
1527 // Default to runtime platform in case we fail to determine host
1528 int hostBits = (sizeof(uintptr) == 8) ? 64 : 32;
1529 String hostType = getenv("HOSTTYPE");
1533 DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1536 if(f.GetLine(host, sizeof(host)))
1543 if(!strcmp(hostType, "x86_64"))
1545 else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1551 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1555 public void SetTargetBits(int bits) { targetBits = bits; };
1556 public int GetTargetBits() { return targetBits; };