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 // todo support %var% variables for windows and $var for linux?
105 public char * PassArg(char * output, const char * input)
108 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
109 const char * escChars = " !\"%&'()+,;=[]^`{}~"; // windowsFileNameCharsNeedEscaping;
110 const char * escCharsQuoted = "\"";
112 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
113 const char * escChars = " !\"$&'()*:;<=>?[\\`{|"; // linuxFileNameCharsNeedEscaping;
114 const char * escCharsQuoted = "\"()$";
116 bool quoting = false;
117 char *o = output, *i = input, *l = input;
119 while(*l && !strchr(escChars, *l)) l++;
120 if(*l) quoting = true;
125 while(*l && !strchr(escChars, *l)) l++;
126 if(*l) quoting = true;
134 if(strchr(quoting ? escCharsQuoted : escChars, *i))
143 /*public Module GetPrivateModule()
145 return privateModule;
148 public class GlobalData : BTNode
152 char * dataTypeString;
158 public class TemplatedType : BTNode
161 TemplateParameter param;
164 class DataRedefinition : struct
166 DataRedefinition prev, next;
168 char type1[1024], type2[1024];
171 public struct CodePosition
174 int line, charPos, pos;
177 void AdjustDelete(BufferLocation start, BufferLocation end)
179 // Location is before, nothing to do
180 if(line - 1 < start.y || (line - 1 == start.y && charPos - 1 < start.x))
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)))
187 if(line - 1 >= end.y)
189 // Location is on another line
191 line -= end.y - start.y;
192 // Location is the last touched line
195 if(charPos - 1 >= end.x)
198 //if(start.line == end.line)
199 charPos -= end.x - start.x;
207 charPos = start.x + 1;
211 // Assuming no carriage return before first character ???? fixed?
212 void AdjustAdd(BufferLocation start, BufferLocation end)
214 int numLines = end.y - start.y;
215 if(line - 1 >= start.y)
217 if(line - 1 > start.y)
221 if(charPos - 1 > start.x || (charPos - 1 == start.x /*&& (numLines ? true : false)*/))
224 //charPos - 1 += numLines ? end.x : (end.x - start.x);
225 charPos += end.x - start.x;
232 public struct Location
235 CodePosition start, end;
237 bool Inside(int line, int charPos)
239 return (start.line < line || (start.line == line && start.charPos <= charPos)) &&
240 (end.line > line || (end.line == line && end.charPos >= charPos));
244 public enum DefinitionType { moduleDefinition, classDefinition, defineDefinition, functionDefinition, dataDefinition };
246 public class Definition : struct
249 Definition prev, next;
254 public class ImportedModule : struct
257 ImportedModule prev, next;
260 ImportType importType;
263 AccessMode importAccess;
266 public class Identifier : struct
269 Identifier prev, next;
271 // TODO: NameSpace * nameSpace;
278 public enum ExpressionType
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
291 public enum MemberType
293 unresolvedMember, propertyMember, methodMember, dataMember, reverseConversionMember, classPropertyMember
296 public class ExpUsage
299 bool usageGet:1, usageSet:1, usageArg:1, usageCall:1, usageMember:1, usageDeepGet:1, usageRef:1, usageDelete:1;
302 public class TemplateParameter : struct
305 TemplateParameter prev, next;
308 TemplateParameterType type;
309 Identifier identifier;
312 TemplateDatatype dataType; // For both base datatype (type) and data type (expression)
313 TemplateMemberType memberType; // For identifier
315 TemplateArgument defaultArgument;
317 // For type parameters
318 char * dataTypeString;
322 public class TemplateDatatype : struct
325 OldList * specifiers;
329 public class TemplateArgument : struct
332 TemplateArgument prev, next;
336 TemplateParameterType type;
339 Expression expression;
340 Identifier identifier;
341 TemplateDatatype templateDatatype;
345 public enum SpecifierType
347 baseSpecifier, nameSpecifier, enumSpecifier, structSpecifier, unionSpecifier, /*classSpecifier,*/
348 extendedSpecifier, typeOfSpecifier, subClassSpecifier, templateTypeSpecifier
351 public class Specifier : struct
354 Specifier prev, next;
365 OldList * templateArgs;
372 OldList * definitions;
375 ExtDecl extDeclStruct;
377 Expression expression;
379 TemplateParameter templateParameter;
383 public class Attribute : struct
386 Attribute prev, next;
392 public class Attrib : struct
400 public class ExtDecl : struct
412 public enum ExtDeclType
414 extDeclString, extDeclAttrib
417 public class Expression : struct
420 Expression prev, next;
428 Identifier identifier;
431 Instantiation instance;
436 OldList * specifiers;
459 MemberType memberType;
465 Expression exp1, exp2;
504 Initializer initializer;
520 // *** COMPILING DATA ***
552 public class Enumerator : struct
555 Enumerator prev, next;
561 class Pointer : struct
565 OldList * qualifiers;
569 public enum DeclaratorType
571 structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
572 functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
575 public class Declarator : struct
578 Declarator prev, next;
581 Symbol symbol;//, propSymbol;
582 Declarator declarator;
585 Identifier identifier;
599 OldList * parameters;
612 public enum InitializerType { expInitializer, listInitializer };
614 public class Initializer : struct
617 Initializer prev, next;
619 InitializerType type;
628 public class InitDeclarator : struct
631 InitDeclarator prev, next;
633 Declarator declarator;
634 Initializer initializer;
637 public enum ClassObjectType
645 public class TypeName : struct
650 OldList * qualifiers;
651 Declarator declarator;
652 //bool /*typedObject, */byReference;
654 ClassObjectType classObjectType;
658 class AsmField : struct
663 Expression expression;
667 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
668 expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
669 forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
670 fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
673 public class Statement : struct
676 Statement prev, next;
681 OldList * expressions;
694 OldList * declarations;
695 OldList * statements;
735 OldList * inputFields;
736 OldList * outputFields;
737 OldList * clobberedFields;
741 Expression watcher, object;
742 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
755 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
757 public class Declaration : struct
760 Declaration prev, next;
762 DeclarationType type;
767 OldList * specifiers;
768 OldList * declarators;
777 Specifier extStorage;
782 public class Instantiation : struct
785 Instantiation prev, next;
794 Location nameLoc, insideLoc;
798 public enum MembersInitType { dataMembersInit, methodMembersInit };
800 public class FunctionDefinition : struct
803 FunctionDefinition prev, next;
805 OldList * specifiers;
806 Declarator declarator;
807 OldList * declarations;
810 OldList attached; // For IDE
817 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
820 public class ClassFunction : struct
823 ClassFunction prev, next;
825 OldList * specifiers;
826 Declarator declarator;
827 OldList * declarations;
830 OldList attached; // For IDE
838 bool isConstructor, isDestructor;
843 public class MembersInit : struct
846 MembersInit prev, next;
848 MembersInitType type;
851 OldList * dataMembers;
852 ClassFunction function;
857 public class MemberInit : struct
860 MemberInit prev, next;
863 OldList * identifiers;
865 Initializer initializer;
873 public class ClassDefinition : struct
876 ClassDefinition prev, next;
881 OldList * definitions;
887 bool deleteWatchable;
890 public class PropertyWatch : struct
893 PropertyWatch prev, next;
896 OldList * properties;
900 public enum ClassDefType
902 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
903 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
904 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
905 memberAccessClassDef, accessOverrideClassDef
908 public class PropertyDef : struct
911 PropertyDef prev, next;
913 OldList * specifiers;
914 Declarator declarator;
925 public class ClassDef : struct
934 ClassFunction function;
935 OldList * defProperties;
936 PropertyDef propertyDef;
937 PropertyWatch propertyWatch;
939 Identifier defaultProperty;
943 Initializer initializer;
946 AccessMode memberAccess;
952 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
954 public class External : struct
963 FunctionDefinition function;
964 ClassDefinition _class;
965 Declaration declaration;
970 ImportType importType;
973 public class Context : struct
977 BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
978 BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
979 BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
980 BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
983 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
984 ClassDefinition classDef;
985 bool templateTypesOnly;
989 /*************** Compiling passes symbols ***************/
991 public class Symbol : struct
995 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
1010 External pointerExternal; // external declaration for the pointer to the Class: e.g. __ecereClass___ecereNameSpace__ecere__com__Class
1011 External structExternal; // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
1015 External externalGet;
1016 External externalSet;
1017 External externalPtr; // Property pointer for watchers
1018 External externalIsSet;
1022 External methodExternal;
1023 External methodCodeExternal;
1026 bool imported, declaredStructSym;
1027 Class _class; // for properties only...
1029 // Only used for classes right now...
1030 bool declaredStruct;
1031 bool needConstructor, needDestructor;
1032 char * constructorName, * structName, * className, * destructorName;
1034 ModuleImport module;
1035 ClassImport _import;
1040 bool fireWatchersDone;
1045 OldList * templateParams; // Review the necessity for this
1046 OldList templatedClasses;
1049 Expression propCategory;
1052 // For the .imp file:
1053 public class ClassImport : struct
1056 ClassImport prev, next;
1064 public class FunctionImport : struct
1067 FunctionImport prev, next;
1071 public class ModuleImport : struct
1074 ModuleImport prev, next;
1078 ImportType importType;
1079 AccessMode importAccess;
1082 public class PropertyImport : struct
1085 PropertyImport prev, next;
1088 bool hasSet, hasGet;
1091 public class MethodImport : struct
1094 MethodImport prev, next;
1099 // For the .sym file:
1100 public enum TypeKind
1102 voidType, charType, shortType, intType, int64Type, longType, floatType,
1103 doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1104 ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1105 subClassType, templateType, thisClassType, intPtrType, intSizeType, _BoolType
1108 public class Type : struct
1128 TemplateParameter thisClassTemplate;
1134 Class methodClass; // Clarify what this is!
1143 Expression arraySizeExp;
1149 TemplateParameter templateParameter;
1156 ClassObjectType classObjectType;
1166 bool extraParam:1; // Clarify this... One thing it is used for is adaptive method with their own type explicitly specified
1167 bool directClassAccess:1; // Need to clarify this if this had the same intended purpose as declaredWithStruct
1170 bool passAsTemplate:1;
1173 bool declaredWithStruct:1;
1174 bool typedByReference:1; // Originally typed by reference, regardless of class type
1175 // TODO: Add _Complex & _Imaginary support
1176 // bool complex:1, imaginary:1;
1178 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1180 Type type = (Type)this;
1181 tempString[0] = '\0';
1183 PrintType(type, tempString, false, true);
1193 public struct Operand
1198 unsigned int ptrSize;
1199 union // Promote to using data value
1209 // unsigned char * p; // Now always storing addresses in ui64
1218 public struct OpTable
1221 // binary arithmetic
1222 bool (* Add)(Expression, Operand, Operand);
1223 bool (* Sub)(Expression, Operand, Operand);
1224 bool (* Mul)(Expression, Operand, Operand);
1225 bool (* Div)(Expression, Operand, Operand);
1226 bool (* Mod)(Expression, Operand, Operand);
1229 bool (* Neg)(Expression, Operand);
1231 // unary arithmetic increment and decrement
1232 bool (* Inc)(Expression, Operand);
1233 bool (* Dec)(Expression, Operand);
1235 // binary arithmetic assignment
1236 bool (* Asign)(Expression, Operand, Operand);
1237 bool (* AddAsign)(Expression, Operand, Operand);
1238 bool (* SubAsign)(Expression, Operand, Operand);
1239 bool (* MulAsign)(Expression, Operand, Operand);
1240 bool (* DivAsign)(Expression, Operand, Operand);
1241 bool (* ModAsign)(Expression, Operand, Operand);
1244 bool (* BitAnd)(Expression, Operand, Operand);
1245 bool (* BitOr)(Expression, Operand, Operand);
1246 bool (* BitXor)(Expression, Operand, Operand);
1247 bool (* LShift)(Expression, Operand, Operand);
1248 bool (* RShift)(Expression, Operand, Operand);
1249 bool (* BitNot)(Expression, Operand);
1251 // binary bitwise assignment
1252 bool (* AndAsign)(Expression, Operand, Operand);
1253 bool (* OrAsign)(Expression, Operand, Operand);
1254 bool (* XorAsign)(Expression, Operand, Operand);
1255 bool (* LShiftAsign)(Expression, Operand, Operand);
1256 bool (* RShiftAsign)(Expression, Operand, Operand);
1258 // unary logical negation
1259 bool (* Not)(Expression, Operand);
1261 // binary logical equality
1262 bool (* Equ)(Expression, Operand, Operand);
1263 bool (* Nqu)(Expression, Operand, Operand);
1266 bool (* And)(Expression, Operand, Operand);
1267 bool (* Or)(Expression, Operand, Operand);
1269 // binary logical relational
1270 bool (* Grt)(Expression, Operand, Operand);
1271 bool (* Sma)(Expression, Operand, Operand);
1272 bool (* GrtEqu)(Expression, Operand, Operand);
1273 bool (* SmaEqu)(Expression, Operand, Operand);
1275 bool (* Cond)(Expression, Operand, Operand, Operand);
1278 define MAX_INCLUDE_DEPTH = 30;
1282 void Compiler_Error(char * format, ...)
1291 if(yylloc.start.included)
1293 GetWorkingDir(string, sizeof(string));
1294 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1298 GetWorkingDir(string, sizeof(string));
1299 PathCat(string, sourceFile);
1304 yylloc.start.col = yylloc.end.col = 1;
1305 yylloc.start.line = yylloc.end.line = 1;
1306 yylloc.start.pos = yylloc.end.pos = 0;
1309 if(!yylloc.start.line)
1313 //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1314 printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1315 //printf(":%d: error: ", yylloc.start.line);
1316 va_start(args, format);
1317 vsnprintf(string, sizeof(string), format, args);
1318 string[sizeof(string)-1] = 0;
1320 fputs(string, stdout);
1321 __thisModule.application.exitCode = 1;
1325 // Error parsing type
1326 parseTypeError = true;
1332 public int GetNumWarnings() { return numWarnings; }
1334 void Compiler_Warning(char * format, ...)
1340 char fileName[MAX_FILENAME];
1342 if(yylloc.start.included)
1344 String include = GetIncludeFileFromID(yylloc.start.included);
1345 GetWorkingDir(string, sizeof(string));
1346 PathCat(string, include);
1350 GetWorkingDir(string, sizeof(string));
1351 PathCat(string, sourceFile);
1354 // Skip these warnings from MinGW-w64 GCC 4.8 in intrin-impl.h
1355 GetLastDirectory(string, fileName);
1356 if(!strcmp(fileName, "intrin-impl.h")) return;
1360 //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1361 printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1362 //printf(":%d: warning: ", yylloc.start.line);
1363 va_start(args, format);
1364 vsnprintf(string, sizeof(string), format, args);
1365 string[sizeof(string)-1] = 0;
1367 fputs(string, stdout);
1374 int yyerror(char * s)
1379 //printf("\n%*s\n%*s\n", column, "^", column, s);
1381 Compiler_Error($"syntax error\n");
1386 Platform targetPlatform;
1388 public int GetHostBits()
1390 // Default to runtime platform in case we fail to determine host
1391 int hostBits = (sizeof(uintptr) == 8) ? 64 : 32;
1392 String hostType = getenv("HOSTTYPE");
1396 DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1399 if(f.GetLine(host, sizeof(host)))
1406 if(!strcmp(hostType, "x86_64"))
1408 else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1414 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1418 public void SetTargetBits(int bits) { targetBits = bits; };
1419 public int GetTargetBits() { return targetBits; };