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 Module GetPrivateModule()
101 public class GlobalData : BTNode
105 char * dataTypeString;
111 public class TemplatedType : BTNode
114 TemplateParameter param;
117 class DataRedefinition : struct
119 DataRedefinition prev, next;
121 char type1[1024], type2[1024];
124 public struct CodePosition
127 int line, charPos, pos;
130 void AdjustDelete(BufferLocation start, BufferLocation end)
132 // Location is before, nothing to do
133 if(line - 1 < start.y || (line - 1 == start.y && charPos - 1 < start.x))
135 // Location is inside deleted bytes, point to the start
136 if((line - 1 >= start.y && (line - 1 > start.y || charPos - 1 >= start.x)) &&
137 (line - 1 >= end.y && (line - 1 > end.y || charPos - 1 >= end.x)))
140 if(line - 1 >= end.y)
142 // Location is on another line
144 line -= end.y - start.y;
145 // Location is the last touched line
148 if(charPos - 1 >= end.x)
151 //if(start.line == end.line)
152 charPos -= end.x - start.x;
160 charPos = start.x + 1;
164 // Assuming no carriage return before first character ???? fixed?
165 void AdjustAdd(BufferLocation start, BufferLocation end)
167 int numLines = end.y - start.y;
168 if(line - 1 >= start.y)
170 if(line - 1 > start.y)
174 if(charPos - 1 > start.x || (charPos - 1 == start.x /*&& (numLines ? true : false)*/))
177 //charPos - 1 += numLines ? end.x : (end.x - start.x);
178 charPos += end.x - start.x;
185 public struct Location
188 CodePosition start, end;
190 bool Inside(int line, int charPos)
192 return (start.line < line || (start.line == line && start.charPos <= charPos)) &&
193 (end.line > line || (end.line == line && end.charPos >= charPos));
197 public enum DefinitionType { moduleDefinition, classDefinition, defineDefinition, functionDefinition, dataDefinition };
199 public class Definition : struct
202 Definition prev, next;
207 public class ImportedModule : struct
210 ImportedModule prev, next;
213 ImportType importType;
216 AccessMode importAccess;
219 public class Identifier : struct
222 Identifier prev, next;
224 // TODO: NameSpace * nameSpace;
231 public enum ExpressionType
233 identifierExp, instanceExp, constantExp, stringExp, opExp,
234 bracketsExp, indexExp, callExp, memberExp, pointerExp, typeSizeExp,
235 castExp, conditionExp, newExp, renewExp, classSizeExp,
236 dummyExp, dereferenceErrorExp, symbolErrorExp, classMemberSymbolErrorExp,
237 structMemberSymbolErrorExp, memoryErrorExp, unknownErrorExp,
238 noDebuggerErrorExp, debugStateErrorExp,
239 extensionCompoundExp, classExp, classDataExp, new0Exp, renew0Exp,
240 dbopenExp, dbfieldExp, dbtableExp, dbindexExp, extensionExpressionExp, extensionInitializerExp,
241 vaArgExp, arrayExp, typeAlignExp
244 public enum MemberType
246 unresolvedMember, propertyMember, methodMember, dataMember, reverseConversionMember, classPropertyMember
249 public class ExpUsage
252 bool usageGet:1, usageSet:1, usageArg:1, usageCall:1, usageMember:1, usageDeepGet:1, usageRef:1, usageDelete:1;
255 public class TemplateParameter : struct
258 TemplateParameter prev, next;
261 TemplateParameterType type;
262 Identifier identifier;
265 TemplateDatatype dataType; // For both base datatype (type) and data type (expression)
266 TemplateMemberType memberType; // For identifier
268 TemplateArgument defaultArgument;
270 // For type parameters
271 char * dataTypeString;
275 public class TemplateDatatype : struct
278 OldList * specifiers;
282 public class TemplateArgument : struct
285 TemplateArgument prev, next;
289 TemplateParameterType type;
292 Expression expression;
293 Identifier identifier;
294 TemplateDatatype templateDatatype;
298 public enum SpecifierType
300 baseSpecifier, nameSpecifier, enumSpecifier, structSpecifier, unionSpecifier, /*classSpecifier,*/
301 extendedSpecifier, typeOfSpecifier, subClassSpecifier, templateTypeSpecifier
304 public class Specifier : struct
307 Specifier prev, next;
318 OldList * templateArgs;
325 OldList * definitions;
328 ExtDecl extDeclStruct;
330 Expression expression;
332 TemplateParameter templateParameter;
336 public class Attribute : struct
339 Attribute prev, next;
345 public class Attrib : struct
353 public class ExtDecl : struct
365 public enum ExtDeclType
367 extDeclString, extDeclAttrib
370 public class Expression : struct
373 Expression prev, next;
381 Identifier identifier;
384 Instantiation instance;
389 OldList * specifiers;
412 MemberType memberType;
418 Expression exp1, exp2;
457 Initializer initializer;
473 // *** COMPILING DATA ***
505 public class Enumerator : struct
508 Enumerator prev, next;
514 class Pointer : struct
518 OldList * qualifiers;
522 public enum DeclaratorType
524 structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
525 functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
528 public class Declarator : struct
531 Declarator prev, next;
534 Symbol symbol;//, propSymbol;
535 Declarator declarator;
538 Identifier identifier;
552 OldList * parameters;
565 public enum InitializerType { expInitializer, listInitializer };
567 public class Initializer : struct
570 Initializer prev, next;
572 InitializerType type;
581 public class InitDeclarator : struct
584 InitDeclarator prev, next;
586 Declarator declarator;
587 Initializer initializer;
590 public enum ClassObjectType
598 public class TypeName : struct
603 OldList * qualifiers;
604 Declarator declarator;
605 //bool /*typedObject, */byReference;
607 ClassObjectType classObjectType;
611 class AsmField : struct
616 Expression expression;
619 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
620 expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
621 forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
622 fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
625 public class Statement : struct
628 Statement prev, next;
633 OldList * expressions;
646 OldList * declarations;
647 OldList * statements;
687 OldList * inputFields;
688 OldList * outputFields;
689 OldList * clobberedFields;
693 Expression watcher, object;
694 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
707 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
709 public class Declaration : struct
712 Declaration prev, next;
714 DeclarationType type;
719 OldList * specifiers;
720 OldList * declarators;
729 Specifier extStorage;
734 public class Instantiation : struct
737 Instantiation prev, next;
746 Location nameLoc, insideLoc;
750 public enum MembersInitType { dataMembersInit, methodMembersInit };
752 public class FunctionDefinition : struct
755 FunctionDefinition prev, next;
757 OldList * specifiers;
758 Declarator declarator;
759 OldList * declarations;
762 OldList attached; // For IDE
769 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
772 public class ClassFunction : struct
775 ClassFunction prev, next;
777 OldList * specifiers;
778 Declarator declarator;
779 OldList * declarations;
782 OldList attached; // For IDE
790 bool isConstructor, isDestructor;
795 public class MembersInit : struct
798 MembersInit prev, next;
800 MembersInitType type;
803 OldList * dataMembers;
804 ClassFunction function;
809 public class MemberInit : struct
812 MemberInit prev, next;
815 OldList * identifiers;
817 Initializer initializer;
825 public class ClassDefinition : struct
828 ClassDefinition prev, next;
833 OldList * definitions;
839 bool deleteWatchable;
842 public class PropertyWatch : struct
845 PropertyWatch prev, next;
848 OldList * properties;
852 public enum ClassDefType
854 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
855 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
856 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
857 memberAccessClassDef, accessOverrideClassDef
860 public class PropertyDef : struct
863 PropertyDef prev, next;
865 OldList * specifiers;
866 Declarator declarator;
877 public class ClassDef : struct
886 ClassFunction function;
887 OldList * defProperties;
888 PropertyDef propertyDef;
889 PropertyWatch propertyWatch;
891 Identifier defaultProperty;
895 Initializer initializer;
898 AccessMode memberAccess;
904 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
906 public class External : struct
915 FunctionDefinition function;
916 ClassDefinition _class;
917 Declaration declaration;
922 ImportType importType;
925 public class Context : struct
929 BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
930 BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
931 BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
932 BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
935 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
936 ClassDefinition classDef;
937 bool templateTypesOnly;
941 /*************** Compiling passes symbols ***************/
943 public class Symbol : struct
947 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
962 External pointerExternal; // external declaration for the pointer to the Class: e.g. __ecereClass___ecereNameSpace__ecere__com__Class
963 External structExternal; // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
967 External externalGet;
968 External externalSet;
969 External externalPtr; // Property pointer for watchers
970 External externalIsSet;
974 External methodExternal;
975 External methodCodeExternal;
978 bool imported, declaredStructSym;
979 Class _class; // for properties only...
981 // Only used for classes right now...
983 bool needConstructor, needDestructor;
984 char * constructorName, * structName, * className, * destructorName;
992 bool fireWatchersDone;
997 OldList * templateParams; // Review the necessity for this
998 OldList templatedClasses;
1001 Expression propCategory;
1004 // For the .imp file:
1005 public class ClassImport : struct
1008 ClassImport prev, next;
1016 public class FunctionImport : struct
1019 FunctionImport prev, next;
1023 public class ModuleImport : struct
1026 ModuleImport prev, next;
1030 ImportType importType;
1031 AccessMode importAccess;
1034 public class PropertyImport : struct
1037 PropertyImport prev, next;
1040 bool hasSet, hasGet;
1043 public class MethodImport : struct
1046 MethodImport prev, next;
1051 // For the .sym file:
1052 public enum TypeKind
1054 voidType, charType, shortType, intType, int64Type, longType, floatType,
1055 doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1056 ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1057 subClassType, templateType, thisClassType, intPtrType
1060 public class Type : struct
1080 TemplateParameter thisClassTemplate;
1095 Expression arraySizeExp;
1101 TemplateParameter templateParameter;
1112 ClassObjectType classObjectType;
1117 bool directClassAccess;
1122 bool passAsTemplate;
1125 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1127 Type type = (Type)this;
1128 tempString[0] = '\0';
1130 PrintType(type, tempString, false, true);
1140 public struct Operand
1145 unsigned int ptrSize;
1146 union // Promote to using data value
1165 public struct OpTable
1168 // binary arithmetic
1169 bool (* Add)(Expression, Operand, Operand);
1170 bool (* Sub)(Expression, Operand, Operand);
1171 bool (* Mul)(Expression, Operand, Operand);
1172 bool (* Div)(Expression, Operand, Operand);
1173 bool (* Mod)(Expression, Operand, Operand);
1176 bool (* Neg)(Expression, Operand);
1178 // unary arithmetic increment and decrement
1179 bool (* Inc)(Expression, Operand);
1180 bool (* Dec)(Expression, Operand);
1182 // binary arithmetic assignment
1183 bool (* Asign)(Expression, Operand, Operand);
1184 bool (* AddAsign)(Expression, Operand, Operand);
1185 bool (* SubAsign)(Expression, Operand, Operand);
1186 bool (* MulAsign)(Expression, Operand, Operand);
1187 bool (* DivAsign)(Expression, Operand, Operand);
1188 bool (* ModAsign)(Expression, Operand, Operand);
1191 bool (* BitAnd)(Expression, Operand, Operand);
1192 bool (* BitOr)(Expression, Operand, Operand);
1193 bool (* BitXor)(Expression, Operand, Operand);
1194 bool (* LShift)(Expression, Operand, Operand);
1195 bool (* RShift)(Expression, Operand, Operand);
1196 bool (* BitNot)(Expression, Operand);
1198 // binary bitwise assignment
1199 bool (* AndAsign)(Expression, Operand, Operand);
1200 bool (* OrAsign)(Expression, Operand, Operand);
1201 bool (* XorAsign)(Expression, Operand, Operand);
1202 bool (* LShiftAsign)(Expression, Operand, Operand);
1203 bool (* RShiftAsign)(Expression, Operand, Operand);
1205 // unary logical negation
1206 bool (* Not)(Expression, Operand);
1208 // binary logical equality
1209 bool (* Equ)(Expression, Operand, Operand);
1210 bool (* Nqu)(Expression, Operand, Operand);
1213 bool (* And)(Expression, Operand, Operand);
1214 bool (* Or)(Expression, Operand, Operand);
1216 // binary logical relational
1217 bool (* Grt)(Expression, Operand, Operand);
1218 bool (* Sma)(Expression, Operand, Operand);
1219 bool (* GrtEqu)(Expression, Operand, Operand);
1220 bool (* SmaEqu)(Expression, Operand, Operand);
1222 bool (* Cond)(Expression, Operand, Operand, Operand);
1225 define MAX_INCLUDE_DEPTH = 10;
1229 void Compiler_Error(char * format, ...)
1238 if(yylloc.start.included)
1240 GetWorkingDir(string, sizeof(string));
1241 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1245 GetWorkingDir(string, sizeof(string));
1246 PathCat(string, sourceFile);
1251 yylloc.start.col = yylloc.end.col = 1;
1252 yylloc.start.line = yylloc.end.line = 1;
1253 yylloc.start.pos = yylloc.end.pos = 0;
1256 if(!yylloc.start.line)
1260 //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1261 printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1262 //printf(":%d: error: ", yylloc.start.line);
1263 va_start(args, format);
1264 vsnprintf(string, sizeof(string), format, args);
1265 string[sizeof(string)-1] = 0;
1267 fputs(string, stdout);
1268 __thisModule.application.exitCode = 1;
1272 // Error parsing type
1273 parseTypeError = true;
1279 public int GetNumWarnings() { return numWarnings; }
1281 void Compiler_Warning(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 //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1302 printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1303 //printf(":%d: warning: ", yylloc.start.line);
1304 va_start(args, format);
1305 vsnprintf(string, sizeof(string), format, args);
1306 string[sizeof(string)-1] = 0;
1308 fputs(string, stdout);
1315 int yyerror(char * s)
1320 //printf("\n%*s\n%*s\n", column, "^", column, s);
1322 Compiler_Error($"syntax error\n");
1327 Platform targetPlatform;
1329 public int GetHostBits()
1331 // Default to runtime platform in case we fail to determine host
1332 int hostBits = (sizeof(uintptr) == 8) ? 64 : 32;
1333 String hostType = getenv("HOSTTYPE");
1337 DualPipe f = DualPipeOpen({ output = true }, "uname -m");
1340 if(f.GetLine(host, sizeof(host)))
1347 if(!strcmp(hostType, "x86_64"))
1349 else if(!strcmp(hostType, "i386") || !strcmp(hostType, "i686"))
1355 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };
1359 public void SetTargetBits(int bits) { targetBits = bits; };