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;
666 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
667 expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
668 forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
669 fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
672 public class Statement : struct
675 Statement prev, next;
680 OldList * expressions;
693 OldList * declarations;
694 OldList * statements;
734 OldList * inputFields;
735 OldList * outputFields;
736 OldList * clobberedFields;
740 Expression watcher, object;
741 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
754 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
756 public class Declaration : struct
759 Declaration prev, next;
761 DeclarationType type;
766 OldList * specifiers;
767 OldList * declarators;
776 Specifier extStorage;
781 public class Instantiation : struct
784 Instantiation prev, next;
793 Location nameLoc, insideLoc;
797 public enum MembersInitType { dataMembersInit, methodMembersInit };
799 public class FunctionDefinition : struct
802 FunctionDefinition prev, next;
804 OldList * specifiers;
805 Declarator declarator;
806 OldList * declarations;
809 OldList attached; // For IDE
816 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
819 public class ClassFunction : struct
822 ClassFunction prev, next;
824 OldList * specifiers;
825 Declarator declarator;
826 OldList * declarations;
829 OldList attached; // For IDE
837 bool isConstructor, isDestructor;
842 public class MembersInit : struct
845 MembersInit prev, next;
847 MembersInitType type;
850 OldList * dataMembers;
851 ClassFunction function;
856 public class MemberInit : struct
859 MemberInit prev, next;
862 OldList * identifiers;
864 Initializer initializer;
872 public class ClassDefinition : struct
875 ClassDefinition prev, next;
880 OldList * definitions;
886 bool deleteWatchable;
889 public class PropertyWatch : struct
892 PropertyWatch prev, next;
895 OldList * properties;
899 public enum ClassDefType
901 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
902 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
903 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
904 memberAccessClassDef, accessOverrideClassDef
907 public class PropertyDef : struct
910 PropertyDef prev, next;
912 OldList * specifiers;
913 Declarator declarator;
924 public class ClassDef : struct
933 ClassFunction function;
934 OldList * defProperties;
935 PropertyDef propertyDef;
936 PropertyWatch propertyWatch;
938 Identifier defaultProperty;
942 Initializer initializer;
945 AccessMode memberAccess;
951 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
953 public class External : struct
962 FunctionDefinition function;
963 ClassDefinition _class;
964 Declaration declaration;
969 ImportType importType;
972 public class Context : struct
976 BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
977 BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
978 BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
979 BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
982 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
983 ClassDefinition classDef;
984 bool templateTypesOnly;
988 /*************** Compiling passes symbols ***************/
990 public class Symbol : struct
994 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
1009 External pointerExternal; // external declaration for the pointer to the Class: e.g. __ecereClass___ecereNameSpace__ecere__com__Class
1010 External structExternal; // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
1014 External externalGet;
1015 External externalSet;
1016 External externalPtr; // Property pointer for watchers
1017 External externalIsSet;
1021 External methodExternal;
1022 External methodCodeExternal;
1025 bool imported, declaredStructSym;
1026 Class _class; // for properties only...
1028 // Only used for classes right now...
1029 bool declaredStruct;
1030 bool needConstructor, needDestructor;
1031 char * constructorName, * structName, * className, * destructorName;
1033 ModuleImport module;
1034 ClassImport _import;
1039 bool fireWatchersDone;
1044 OldList * templateParams; // Review the necessity for this
1045 OldList templatedClasses;
1048 Expression propCategory;
1051 // For the .imp file:
1052 public class ClassImport : struct
1055 ClassImport prev, next;
1063 public class FunctionImport : struct
1066 FunctionImport prev, next;
1070 public class ModuleImport : struct
1073 ModuleImport prev, next;
1077 ImportType importType;
1078 AccessMode importAccess;
1081 public class PropertyImport : struct
1084 PropertyImport prev, next;
1087 bool hasSet, hasGet;
1090 public class MethodImport : struct
1093 MethodImport prev, next;
1098 // For the .sym file:
1099 public enum TypeKind
1101 voidType, charType, shortType, intType, int64Type, longType, floatType,
1102 doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1103 ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1104 subClassType, templateType, thisClassType, intPtrType, intSizeType
1107 public class Type : struct
1127 TemplateParameter thisClassTemplate;
1133 Class methodClass; // Clarify what this is!
1142 Expression arraySizeExp;
1148 TemplateParameter templateParameter;
1155 ClassObjectType classObjectType;
1165 bool extraParam:1; // Clarify this... One thing it is used for is adaptive method with their own type explicitly specified
1166 bool directClassAccess:1; // Need to clarify this if this had the same intended purpose as declaredWithStruct
1169 bool passAsTemplate:1;
1172 bool declaredWithStruct:1;
1173 bool typedByReference:1; // Originally typed by reference, regardless of class type
1175 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1177 Type type = (Type)this;
1178 tempString[0] = '\0';
1180 PrintType(type, tempString, false, true);
1190 public struct Operand
1195 unsigned int ptrSize;
1196 union // Promote to using data value
1206 // unsigned char * p; // Now always storing addresses in ui64
1215 public struct OpTable
1218 // binary arithmetic
1219 bool (* Add)(Expression, Operand, Operand);
1220 bool (* Sub)(Expression, Operand, Operand);
1221 bool (* Mul)(Expression, Operand, Operand);
1222 bool (* Div)(Expression, Operand, Operand);
1223 bool (* Mod)(Expression, Operand, Operand);
1226 bool (* Neg)(Expression, Operand);
1228 // unary arithmetic increment and decrement
1229 bool (* Inc)(Expression, Operand);
1230 bool (* Dec)(Expression, Operand);
1232 // binary arithmetic assignment
1233 bool (* Asign)(Expression, Operand, Operand);
1234 bool (* AddAsign)(Expression, Operand, Operand);
1235 bool (* SubAsign)(Expression, Operand, Operand);
1236 bool (* MulAsign)(Expression, Operand, Operand);
1237 bool (* DivAsign)(Expression, Operand, Operand);
1238 bool (* ModAsign)(Expression, Operand, Operand);
1241 bool (* BitAnd)(Expression, Operand, Operand);
1242 bool (* BitOr)(Expression, Operand, Operand);
1243 bool (* BitXor)(Expression, Operand, Operand);
1244 bool (* LShift)(Expression, Operand, Operand);
1245 bool (* RShift)(Expression, Operand, Operand);
1246 bool (* BitNot)(Expression, Operand);
1248 // binary bitwise assignment
1249 bool (* AndAsign)(Expression, Operand, Operand);
1250 bool (* OrAsign)(Expression, Operand, Operand);
1251 bool (* XorAsign)(Expression, Operand, Operand);
1252 bool (* LShiftAsign)(Expression, Operand, Operand);
1253 bool (* RShiftAsign)(Expression, Operand, Operand);
1255 // unary logical negation
1256 bool (* Not)(Expression, Operand);
1258 // binary logical equality
1259 bool (* Equ)(Expression, Operand, Operand);
1260 bool (* Nqu)(Expression, Operand, Operand);
1263 bool (* And)(Expression, Operand, Operand);
1264 bool (* Or)(Expression, Operand, Operand);
1266 // binary logical relational
1267 bool (* Grt)(Expression, Operand, Operand);
1268 bool (* Sma)(Expression, Operand, Operand);
1269 bool (* GrtEqu)(Expression, Operand, Operand);
1270 bool (* SmaEqu)(Expression, Operand, Operand);
1272 bool (* Cond)(Expression, Operand, Operand, Operand);
1275 define MAX_INCLUDE_DEPTH = 30;
1279 void Compiler_Error(char * format, ...)
1288 if(yylloc.start.included)
1290 GetWorkingDir(string, sizeof(string));
1291 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1295 GetWorkingDir(string, sizeof(string));
1296 PathCat(string, sourceFile);
1301 yylloc.start.col = yylloc.end.col = 1;
1302 yylloc.start.line = yylloc.end.line = 1;
1303 yylloc.start.pos = yylloc.end.pos = 0;
1306 if(!yylloc.start.line)
1310 //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1311 printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1312 //printf(":%d: error: ", 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);
1318 __thisModule.application.exitCode = 1;
1322 // Error parsing type
1323 parseTypeError = true;
1329 public int GetNumWarnings() { return numWarnings; }
1331 void Compiler_Warning(char * format, ...)
1338 if(yylloc.start.included)
1340 GetWorkingDir(string, sizeof(string));
1341 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1345 GetWorkingDir(string, sizeof(string));
1346 PathCat(string, sourceFile);
1351 //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1352 printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1353 //printf(":%d: warning: ", yylloc.start.line);
1354 va_start(args, format);
1355 vsnprintf(string, sizeof(string), format, args);
1356 string[sizeof(string)-1] = 0;
1358 fputs(string, stdout);
1365 int yyerror(char * s)
1370 //printf("\n%*s\n%*s\n", column, "^", column, s);
1372 Compiler_Error($"syntax error\n");
1377 Platform targetPlatform;
1379 public int GetHostBits()
1381 // Default to runtime platform in case we fail to determine host
1382 int hostBits = (sizeof(uintptr) == 8) ? 64 : 32;
1383 String hostType = getenv("HOSTTYPE");
1387 DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1390 if(f.GetLine(host, sizeof(host)))
1397 if(!strcmp(hostType, "x86_64"))
1399 else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1405 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1409 public void SetTargetBits(int bits) { targetBits = bits; };
1410 public int GetTargetBits() { return targetBits; };