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;
329 Expression expression;
331 TemplateParameter templateParameter;
335 public class Attribute : struct
338 Attribute prev, next;
344 public class Attrib : struct
352 public class ExtDecl : struct
364 public enum ExtDeclType
366 extDeclString, extDeclAttrib
369 public class Expression : struct
372 Expression prev, next;
380 Identifier identifier;
383 Instantiation instance;
388 OldList * specifiers;
411 MemberType memberType;
417 Expression exp1, exp2;
456 Initializer initializer;
472 // *** COMPILING DATA ***
504 public class Enumerator : struct
507 Enumerator prev, next;
513 class Pointer : struct
517 OldList * qualifiers;
521 public enum DeclaratorType
523 structDeclarator, identifierDeclarator, bracketsDeclarator, arrayDeclarator,
524 functionDeclarator, pointerDeclarator, extendedDeclarator, extendedDeclaratorEnd
527 public class Declarator : struct
530 Declarator prev, next;
533 Symbol symbol;//, propSymbol;
534 Declarator declarator;
537 Identifier identifier;
551 OldList * parameters;
564 public enum InitializerType { expInitializer, listInitializer };
566 public class Initializer : struct
569 Initializer prev, next;
571 InitializerType type;
580 public class InitDeclarator : struct
583 InitDeclarator prev, next;
585 Declarator declarator;
586 Initializer initializer;
589 public enum ClassObjectType
597 public class TypeName : struct
602 OldList * qualifiers;
603 Declarator declarator;
604 //bool /*typedObject, */byReference;
606 ClassObjectType classObjectType;
610 class AsmField : struct
615 Expression expression;
618 public enum StmtType { labeledStmt, caseStmt, compoundStmt,
619 expressionStmt, ifStmt, switchStmt, whileStmt, doWhileStmt,
620 forStmt, gotoStmt, continueStmt, breakStmt, returnStmt, asmStmt, badDeclarationStmt,
621 fireWatchersStmt, stopWatchingStmt, watchStmt, forEachStmt
624 public class Statement : struct
627 Statement prev, next;
632 OldList * expressions;
645 OldList * declarations;
646 OldList * statements;
686 OldList * inputFields;
687 OldList * outputFields;
688 OldList * clobberedFields;
692 Expression watcher, object;
693 OldList * watches; // OldList of PropertyWatch for a StmtWatch, list of property identifiers for firewatches, stopwatching
706 public enum DeclarationType { structDeclaration, initDeclaration, instDeclaration, defineDeclaration };
708 public class Declaration : struct
711 Declaration prev, next;
713 DeclarationType type;
718 OldList * specifiers;
719 OldList * declarators;
728 Specifier extStorage;
733 public class Instantiation : struct
736 Instantiation prev, next;
745 Location nameLoc, insideLoc;
749 public enum MembersInitType { dataMembersInit, methodMembersInit };
751 public class FunctionDefinition : struct
754 FunctionDefinition prev, next;
756 OldList * specifiers;
757 Declarator declarator;
758 OldList * declarations;
761 OldList attached; // For IDE
768 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
771 public class ClassFunction : struct
774 ClassFunction prev, next;
776 OldList * specifiers;
777 Declarator declarator;
778 OldList * declarations;
781 OldList attached; // For IDE
789 bool isConstructor, isDestructor;
794 public class MembersInit : struct
797 MembersInit prev, next;
799 MembersInitType type;
802 OldList * dataMembers;
803 ClassFunction function;
808 public class MemberInit : struct
811 MemberInit prev, next;
814 OldList * identifiers;
816 Initializer initializer;
824 public class ClassDefinition : struct
827 ClassDefinition prev, next;
832 OldList * definitions;
838 bool deleteWatchable;
841 public class PropertyWatch : struct
844 PropertyWatch prev, next;
847 OldList * properties;
851 public enum ClassDefType
853 functionClassDef, defaultPropertiesClassDef, declarationClassDef, propertyClassDef,
854 propertyWatchClassDef, classDesignerClassDef, classNoExpansionClassDef, classFixedClassDef,
855 designerDefaultPropertyClassDef, classDataClassDef, classPropertyClassDef, classPropertyValueClassDef,
856 memberAccessClassDef, accessOverrideClassDef
859 public class PropertyDef : struct
862 PropertyDef prev, next;
864 OldList * specifiers;
865 Declarator declarator;
876 public class ClassDef : struct
885 ClassFunction function;
886 OldList * defProperties;
887 PropertyDef propertyDef;
888 PropertyWatch propertyWatch;
890 Identifier defaultProperty;
894 Initializer initializer;
897 AccessMode memberAccess;
903 public enum ExternalType { functionExternal, declarationExternal, classExternal, importExternal, nameSpaceExternal, dbtableExternal };
905 public class External : struct
914 FunctionDefinition function;
915 ClassDefinition _class;
916 Declaration declaration;
921 ImportType importType;
924 public class Context : struct
928 BinaryTree types { CompareKey = (void *)BinaryTree::CompareString };
929 BinaryTree classes { CompareKey = (void *)BinaryTree::CompareString };
930 BinaryTree symbols { CompareKey = (void *)BinaryTree::CompareString };
931 BinaryTree structSymbols { CompareKey = (void *)BinaryTree::CompareString };
934 BinaryTree templateTypes { CompareKey = (void *)BinaryTree::CompareString };
935 ClassDefinition classDef;
936 bool templateTypesOnly;
940 /*************** Compiling passes symbols ***************/
942 public class Symbol : struct
946 Symbol parent, left, right; // Reusing left, right as prev, next when in excludedSymbols
961 External pointerExternal; // external declaration for the pointer to the Class: e.g. __ecereClass___ecereNameSpace__ecere__com__Class
962 External structExternal; // external declaration for the actual class members structure: e.g. __ecereNameSpace__ecere__com__Class
966 External externalGet;
967 External externalSet;
968 External externalPtr; // Property pointer for watchers
969 External externalIsSet;
973 External methodExternal;
974 External methodCodeExternal;
977 bool imported, declaredStructSym;
978 Class _class; // for properties only...
980 // Only used for classes right now...
982 bool needConstructor, needDestructor;
983 char * constructorName, * structName, * className, * destructorName;
991 bool fireWatchersDone;
996 OldList * templateParams; // Review the necessity for this
997 OldList templatedClasses;
1000 Expression propCategory;
1003 // For the .imp file:
1004 public class ClassImport : struct
1007 ClassImport prev, next;
1015 public class FunctionImport : struct
1018 FunctionImport prev, next;
1022 public class ModuleImport : struct
1025 ModuleImport prev, next;
1029 ImportType importType;
1030 AccessMode importAccess;
1033 public class PropertyImport : struct
1036 PropertyImport prev, next;
1039 bool hasSet, hasGet;
1042 public class MethodImport : struct
1045 MethodImport prev, next;
1050 // For the .sym file:
1051 public enum TypeKind
1053 voidType, charType, shortType, intType, int64Type, longType, floatType,
1054 doubleType, classType, structType, unionType, functionType, arrayType, pointerType,
1055 ellipsisType, enumType, methodType, vaListType, /*typedObjectType, anyObjectType, classPointerType, */ dummyType,
1056 subClassType, templateType, thisClassType
1059 public class Type : struct
1079 TemplateParameter thisClassTemplate;
1094 Expression arraySizeExp;
1100 TemplateParameter templateParameter;
1111 ClassObjectType classObjectType;
1116 bool directClassAccess;
1121 bool passAsTemplate;
1124 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
1126 Type type = (Type)this;
1127 tempString[0] = '\0';
1129 PrintType(type, tempString, false, true);
1139 public struct Operand
1144 unsigned int ptrSize;
1145 union // Promote to using data value
1162 public struct OpTable
1165 // binary arithmetic
1166 bool (* Add)(Expression, Operand, Operand);
1167 bool (* Sub)(Expression, Operand, Operand);
1168 bool (* Mul)(Expression, Operand, Operand);
1169 bool (* Div)(Expression, Operand, Operand);
1170 bool (* Mod)(Expression, Operand, Operand);
1173 bool (* Neg)(Expression, Operand);
1175 // unary arithmetic increment and decrement
1176 bool (* Inc)(Expression, Operand);
1177 bool (* Dec)(Expression, Operand);
1179 // binary arithmetic assignment
1180 bool (* Asign)(Expression, Operand, Operand);
1181 bool (* AddAsign)(Expression, Operand, Operand);
1182 bool (* SubAsign)(Expression, Operand, Operand);
1183 bool (* MulAsign)(Expression, Operand, Operand);
1184 bool (* DivAsign)(Expression, Operand, Operand);
1185 bool (* ModAsign)(Expression, Operand, Operand);
1188 bool (* BitAnd)(Expression, Operand, Operand);
1189 bool (* BitOr)(Expression, Operand, Operand);
1190 bool (* BitXor)(Expression, Operand, Operand);
1191 bool (* LShift)(Expression, Operand, Operand);
1192 bool (* RShift)(Expression, Operand, Operand);
1193 bool (* BitNot)(Expression, Operand);
1195 // binary bitwise assignment
1196 bool (* AndAsign)(Expression, Operand, Operand);
1197 bool (* OrAsign)(Expression, Operand, Operand);
1198 bool (* XorAsign)(Expression, Operand, Operand);
1199 bool (* LShiftAsign)(Expression, Operand, Operand);
1200 bool (* RShiftAsign)(Expression, Operand, Operand);
1202 // unary logical negation
1203 bool (* Not)(Expression, Operand);
1205 // binary logical equality
1206 bool (* Equ)(Expression, Operand, Operand);
1207 bool (* Nqu)(Expression, Operand, Operand);
1210 bool (* And)(Expression, Operand, Operand);
1211 bool (* Or)(Expression, Operand, Operand);
1213 // binary logical relational
1214 bool (* Grt)(Expression, Operand, Operand);
1215 bool (* Sma)(Expression, Operand, Operand);
1216 bool (* GrtEqu)(Expression, Operand, Operand);
1217 bool (* SmaEqu)(Expression, Operand, Operand);
1219 bool (* Cond)(Expression, Operand, Operand, Operand);
1222 define MAX_INCLUDE_DEPTH = 10;
1226 void Compiler_Error(char * format, ...)
1234 string[sizeof(string)-1] = 0;
1236 if(yylloc.start.included)
1238 GetWorkingDir(string, sizeof(string));
1239 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1243 GetWorkingDir(string, sizeof(string));
1244 PathCat(string, sourceFile);
1249 yylloc.start.col = yylloc.end.col = 1;
1250 yylloc.start.line = yylloc.end.line = 1;
1251 yylloc.start.pos = yylloc.end.pos = 0;
1254 if(!yylloc.start.line)
1258 //printf("(%d, %d) : error: ", yylloc.start.line, yylloc.start.charPos);
1259 printf($":%d:%d: error: ", yylloc.start.line, yylloc.start.charPos);
1260 //printf(":%d: error: ", yylloc.start.line);
1261 va_start(args, format);
1262 vsnprintf(string, sizeof(string), format, args);
1264 fputs(string, stdout);
1265 __thisModule.application.exitCode = 1;
1269 // Error parsing type
1270 parseTypeError = true;
1276 public int GetNumWarnings() { return numWarnings; }
1278 void Compiler_Warning(char * format, ...)
1284 string[sizeof(string)-1] = 0;
1286 if(yylloc.start.included)
1288 GetWorkingDir(string, sizeof(string));
1289 PathCat(string, GetIncludeFileFromID(yylloc.start.included));
1293 GetWorkingDir(string, sizeof(string));
1294 PathCat(string, sourceFile);
1299 //printf("(%d, %d) : warning: ", yylloc.start.line, yylloc.start.charPos);
1300 printf($":%d:%d: warning: ", yylloc.start.line, yylloc.start.charPos);
1301 //printf(":%d: warning: ", yylloc.start.line);
1302 va_start(args, format);
1303 vsnprintf(string, sizeof(string), format, args);
1305 fputs(string, stdout);
1312 int yyerror(char * s)
1317 //printf("\n%*s\n%*s\n", column, "^", column, s);
1319 Compiler_Error($"syntax error\n");
1324 Platform targetPlatform;
1326 public void SetTargetPlatform(Platform platform) { targetPlatform = platform; };