3 // UNTIL IMPLEMENTED IN GRAMMAR
4 #define ACCESS_CLASSDATA(_class, baseClass) \
5 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
7 #define YYLTYPE Location
10 static Statement registerModuleBody;
11 static External registerModuleExternal;
12 static Statement unregisterModuleBody;
13 static External unregisterModuleExternal;
15 extern int propWatcherID;
17 bool buildingECERECOM = false;
18 public void SetBuildingEcereCom(bool b) { buildingECERECOM = b; } public bool GetBuildingEcereCom() { return buildingECERECOM; }
19 bool buildingECERECOMModule = false;
20 public void SetBuildingEcereComModule(bool b) { buildingECERECOMModule = b; } public bool GetBuildingEcereComModule() { return buildingECERECOMModule; }
22 // This will also be called by the instance processor to make the instance methods... (pass 1.5)
23 External ProcessClassFunction(Class owningClass, ClassFunction func, OldList defs, External after, bool makeStatic)
27 External external = null;
29 if(defs && func.declarator)
31 FunctionDefinition function = null;
37 func.specifiers = MkList();
38 // Add static to the specifiers
42 for(s = func.specifiers->first; s; s = s.next)
43 if(s.type == baseSpecifier && s.specifier == STATIC)
46 func.specifiers->Insert(null, MkSpecifier(STATIC));
50 propSymbol = func.declarator.symbol;
52 ReplaceThisClassSpecifiers(func.specifiers, owningClass);
54 if(propSymbol.externalGet == (External)func)
55 func.declarator.symbol = null;
56 else if(propSymbol.externalSet == (External)func)
57 func.declarator.symbol = null;
58 else if(propSymbol.externalIsSet == (External)func)
59 func.declarator.symbol = null;
63 /*FunctionDefinition*/ function = _MkFunction(func.specifiers, func.declarator, null, false);
64 function.propSet = func.propSet;
65 function.type = func.type;
66 if(func.type) func.type.refCount++;
67 ProcessFunctionBody(function, func.body);
68 external = MkExternalFunction(function);
73 strcpy(className, "__ecereClass_");
74 FullClassNameCat(className, owningClass.fullName, true);
75 DeclareClass(external, owningClass.symbol, className);
78 external.symbol = func.declarator.symbol;
79 external.function._class = func._class;
82 symbol = func.declarator.symbol;
87 Method method = func.declarator.symbol.method;
88 func.declarator.symbol.methodExternal = external;
90 if(method && method.symbol)
91 ((Symbol)method.symbol).methodCodeExternal = external;
93 if(method && method.type == virtualMethod)
96 ProcessMethodType(method);
98 methodDataType = method.dataType;
100 // Do type checking here of type against method.dataType
101 // ThisClass must be the owning class for types not specified, static for static, or inherit from method's ThisClass is specified
102 // If not specified, defaults to ThisClass if ThisClass specified in method, otherwise overiding class or static
106 if(!type.staticMethod && !type.thisClass && !type.thisClassTemplate)
108 if(method.dataType.thisClassTemplate)
110 if(owningClass.templateArgs)
112 ClassTemplateArgument * arg = FindTemplateArg(owningClass, method.dataType.thisClassTemplate);
113 type.byReference = method.dataType.byReference;
115 methodDataType = ProcessTypeString(method.dataTypeString, false);
116 type.thisClass = methodDataType.thisClass = arg ? FindClass(arg->dataTypeString) : null;
119 else if(method.dataType.staticMethod)
120 type.staticMethod = true;
121 else if(method.dataType.thisClass)
123 type.thisClass = method.dataType.thisClass;
124 type.byReference = method.dataType.byReference;
128 if(!owningClass.symbol)
129 owningClass.symbol = FindClass(owningClass.fullName);
131 type.thisClass = owningClass.symbol;
132 // WORKING ON THIS TO SUPPORT : pass.NotifyClicked(this, pass, 0, 0, key.modifiers);
133 type.extraParam = true;
138 if(!MatchTypes(type, methodDataType, null, owningClass, method._class /*owningClass*/, true, true, true, false, true))
141 // MatchTypes(type, methodDataType, null, owningClass, owningClass, true, true, true, false);
143 Compiler_Error($"Incompatible virtual function %s\n", method.name);
147 // Mark typed_object/any_object parameters as such according to method type
149 Declarator funcDecl = GetFuncDecl(func.declarator);
150 if(funcDecl.function.parameters && funcDecl.function.parameters->first)
152 TypeName param = funcDecl.function.parameters->first;
154 for(typeParam = methodDataType.params.first; typeParam && param; typeParam = typeParam.next)
156 if(typeParam.classObjectType)
158 param.classObjectType = typeParam.classObjectType;
159 if(param.declarator && param.declarator.symbol)
160 param.declarator.symbol.type.classObjectType = typeParam.classObjectType;
162 param = param ? param.next : null;
166 if(methodDataType != method.dataType)
167 FreeType(methodDataType);
172 if(!type.staticMethod && !type.thisClass)
174 if(owningClass && !owningClass.symbol)
175 owningClass.symbol = FindClass(owningClass.fullName);
177 type.thisClass = owningClass ? FindClass(owningClass.fullName) : null;
183 // TESTING THIS HERE: (Implementing Class Properties)
184 if(symbol.type && !symbol.type.staticMethod && !symbol.type.thisClass)
186 if(!owningClass.symbol)
187 owningClass.symbol = FindClass(owningClass.fullName);
188 symbol.type.thisClass = owningClass.symbol;
191 // Those type of classes don't need a this parameter for Set methods, null thisClass before changing the externals
192 if(propSymbol.externalSet == (External)func && propSymbol._property && propSymbol._property.conversion)
194 if(symbol.type.thisClass && symbol.type.classObjectType != classPointer)
196 // TODO: Perhaps improve this so as to support both "this =" and "return " syntax for all types of classes
197 if(owningClass.type != structClass)
198 //function.propertyNoThis = true;
199 symbol.type.thisClass = null;
204 if(propSymbol.externalGet == (External)func)
206 propSymbol.externalGet = external;
208 else if(propSymbol.externalSet == (External)func)
210 propSymbol.externalSet = external;
212 else if(propSymbol.externalIsSet == (External)func)
214 propSymbol.externalIsSet = external;
218 // Constructor destructor
219 //symbol.type = Type { };
226 func.declarator = null;
227 func.specifiers = null;
230 defs.Insert(after, external);
234 Method method = func.declarator.symbol.method;
235 if(method && method.symbol)
236 ((Symbol)method.symbol).methodCodeExternal = null;
237 if(func.declarator.symbol && func.declarator.symbol.methodExternal == external)
238 func.declarator.symbol.methodExternal = null;
240 //external.function = null;
241 func.declarator = null;
242 func.specifiers = null;
244 FreeExternal(external); // Free external here?
249 globalContext /*curContext*/.symbols.Remove((BTNode)symbol);
250 excludedSymbols->Add(symbol);
253 defs.Insert(after, external);
255 external.function.declarator = CopyDeclarator(external.function.declarator);
256 external.function.specifiers = CopyList(external.function.specifiers, CopySpecifier);
257 external.function.body = null;
263 void CreateRegisterModuleBody()
265 if(!registerModuleBody && inCompiler)
267 char registerName[1024], moduleName[MAX_FILENAME];
268 OldList * specifiers;
269 Declarator declarator;
270 TypeName moduleParam;
272 registerModuleBody = MkCompoundStmt(MkList(), MkList());
273 registerModuleBody.compound.context = Context { parent = globalContext };
275 ListAdd(registerModuleBody.compound.declarations,
276 MkDeclaration((specifiers = MkListOne(MkSpecifierName("ecere::com::Class"))),
277 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("class")), null))));
278 // Avoid unused warning here
279 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
281 specifiers = MkList();
282 ListAdd(specifiers, MkSpecifier(VOID));
284 moduleParam = MkTypeName(MkListOne(MkSpecifierName("Module")),
285 MkDeclaratorIdentifier(MkIdentifier("module")));
287 GetLastDirectory(outputFile, moduleName);
288 StripExtension(moduleName);
289 FixModuleName(moduleName);
290 sprintf(registerName, "__ecereRegisterModule_%s", moduleName);
292 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
293 MkListOne(moduleParam));
296 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
297 ProcessFunctionBody(function, registerModuleBody);
298 function.declMode = defaultAccess;
299 if(!ast) ast = MkList();
300 ListAdd(ast, (registerModuleExternal = MkExternalFunction(function)));
301 DeclareStruct(registerModuleExternal, "ecere::com::Instance", false, true);
302 DeclareStruct(registerModuleExternal, "ecere::com::Module", false, true);
307 if(!unregisterModuleBody && inCompiler)
309 char registerName[1024], moduleName[MAX_FILENAME];
310 OldList * specifiers;
311 Declarator declarator;
312 TypeName moduleParam;
314 unregisterModuleBody = MkCompoundStmt(MkList(), MkList());
315 unregisterModuleBody.compound.context = Context { parent = globalContext };
317 specifiers = MkList();
318 ListAdd(specifiers, MkSpecifier(VOID));
320 moduleParam = MkTypeName(MkListOne(MkSpecifierName("Module")),
321 MkDeclaratorIdentifier(MkIdentifier("module")));
323 GetLastDirectory(outputFile, moduleName);
324 StripExtension(moduleName);
325 FixModuleName(moduleName);
326 sprintf(registerName, "__ecereUnregisterModule_%s", moduleName);
328 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
329 MkListOne(moduleParam));
332 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
333 ProcessFunctionBody(function, unregisterModuleBody);
334 function.declMode = defaultAccess;
335 if(!ast) ast = MkList();
336 ListAdd(ast, (unregisterModuleExternal = MkExternalFunction(function)));
337 DeclareStruct(unregisterModuleExternal, "ecere::com::Instance", false, true);
338 DeclareStruct(unregisterModuleExternal, "ecere::com::Module", false, true);
343 void RegisterMembersAndProperties(Class regClass, bool isMember, const char * className, Statement statement)
345 DataMember dataMember = isMember ? (DataMember)regClass : null;
350 char dataMemberSize[16];
354 bool privateMembers = false;
356 sprintf(dataMemberSize, "%d", (int)sizeof(DataMember));
359 for(prop = regClass.conversions.first; prop; prop = prop.next)
361 OldList * args = MkList();
365 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
367 ListAdd(args, MkExpConstant("0"));
371 char * string = QMkString(prop.dataTypeString);
372 ListAdd(args, MkExpString(string));
378 strcpy(name, "__ecereProp_");
379 FullClassNameCat(name, regClass.fullName, false);
380 strcat(name, "_Set_");
381 // strcat(name, prop.name);
382 FullClassNameCat(name, prop.name, true);
383 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
386 ListAdd(args, MkExpConstant("0"));
390 strcpy(name, "__ecereProp_");
391 FullClassNameCat(name, regClass.fullName, false);
392 strcat(name, "_Get_");
393 // strcat(name, prop.name);
394 FullClassNameCat(name, prop.name, true);
396 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
399 ListAdd(args, MkExpConstant("0"));
403 switch(prop.memberAccess)
406 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
409 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
413 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
417 strcpy(name, "__ecereProp_");
418 FullClassNameCat(name, regClass.fullName, false);
420 FullClassNameCat(name, prop.name, true);
421 // strcat(name, prop.name);
422 stmt = MkExpressionStmt(MkListOne(
423 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=',
424 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
425 ListAdd(registerModuleBody.compound.statements, stmt);
429 for(member = isMember ? dataMember.members.first : regClass.membersAndProperties.first; member; member = member.next)
431 if(member.isProperty)
433 prop = (Property) member;
435 OldList * args = MkList();
436 char name[1024], nameM[1024];
437 char * string = QMkString(prop.name);
440 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
443 ListAdd(args, MkExpString(string));
448 char * string = QMkString(prop.dataTypeString);
449 ListAdd(args, MkExpString(string));
455 strcpy(name, "__ecereProp_");
456 FullClassNameCat(name, regClass.fullName, false);
457 strcat(name, "_Set_");
458 FullClassNameCat(name, prop.name, true);
459 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
462 ListAdd(args, MkExpConstant("0"));
466 strcpy(name, "__ecereProp_");
467 FullClassNameCat(name, regClass.fullName, false);
468 strcat(name, "_Get_");
469 FullClassNameCat(name, prop.name, true);
470 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
473 ListAdd(args, MkExpConstant("0"));
476 switch(prop.memberAccess)
479 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
482 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
486 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
490 strcpy(name, "__ecereProp_");
491 FullClassNameCat(name, regClass.fullName, false);
493 FullClassNameCat(name, prop.name, true);
495 strcpy(nameM, "__ecerePropM_");
496 FullClassNameCat(nameM, regClass.fullName, false);
498 FullClassNameCat(nameM, prop.name, true);
500 if(prop.dataTypeString)
502 stmt = MkExpressionStmt(MkListOne(
503 MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
504 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
508 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args)));
510 ListAdd(registerModuleBody.compound.statements, stmt);
515 strcpy(name, "__ecereProp_");
516 FullClassNameCat(name, regClass.fullName, true);
517 strcat(name, "_IsSet_");
518 FullClassNameCat(name, prop.name, false);
519 stmt = MkExpressionStmt(MkListOne(
520 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("IsSet")), '=',
521 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpIdentifier(MkIdentifier(name))))));
522 ListAdd(registerModuleBody.compound.statements, stmt);
524 if(prop.symbol && ((Symbol)prop.symbol).propCategory)
526 stmt = MkExpressionStmt(MkListOne(
527 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("category")), '=',
528 CopyExpression(((Symbol)prop.symbol).propCategory))));
529 ListAdd(registerModuleBody.compound.statements, stmt);
532 if(prop.dataTypeString)
534 OldList * list = MkList();
535 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', MkExpIdentifier(MkIdentifier(nameM))));
536 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=', MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0"))));
537 // stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(name)))), MkExpressionStmt(list), null);
538 stmt = MkIfStmt(MkListOne(MkExpOp(
539 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
540 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application")))), MkExpressionStmt(list), null);
542 ListAdd(registerModuleBody.compound.statements, stmt);
544 // Unregister 2nd property
545 stmt = MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
546 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0")))));
547 ListAdd(unregisterModuleBody.compound.statements, stmt);
551 else if(member.type == normalMember && !isMember && regClass.type == bitClass)
553 BitMember bitMember = (BitMember) member;
554 OldList * args = MkList();
557 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
561 char * string = QMkString(bitMember.name);
562 ListAdd(args, MkExpString(string));
567 char * string = QMkString(bitMember.dataTypeString);
568 ListAdd(args, MkExpString(string));
574 sprintf(string, "%d", bitMember.size);
575 ListAdd(args, (exp = MkExpConstant(string)));
580 sprintf(string, "%d", bitMember.pos);
581 ListAdd(args, (exp = MkExpConstant(string)));
585 switch(member.memberAccess)
588 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
591 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
595 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
599 stmt = MkExpressionStmt(MkListOne(
600 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddBitMember")), args)));
602 ListAdd(statement.compound.statements, stmt);
604 else if(member.memberAccess == publicAccess || (member.type == normalMember && !member.dataTypeString))
607 // ADD PRIVATE DATA PADDING HERE...
610 uint offset = member.offset - lastOffset;
615 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
620 sprintf(string, "\"__ecerePrivateData%d\"", privateID++);
621 ListAdd(args, MkExpString(string));
626 sprintf(string, "\"byte[%d]\"", offset);
627 ListAdd(args, MkExpString(string));
632 sprintf(string, "%d", offset);
633 ListAdd(args, (exp = MkExpConstant(string)));
637 ListAdd(args, (exp = MkExpConstant("1")));
640 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
642 stmt = MkExpressionStmt(MkListOne(
643 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
645 ListAdd(statement.compound.statements, stmt);
646 privateMembers = false;
649 if(member.type == normalMember)
652 member.dataType = ProcessTypeString(member.dataTypeString, false);
654 ComputeTypeSize(member.dataType);
659 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
663 char * string = QMkString(member.name);
664 ListAdd(args, MkExpString(string));
669 char * string = QMkString(member.dataTypeString);
670 ListAdd(args, MkExpString(string));
676 if(member.dataType.isPointerTypeSize)
678 ListAdd(args, (exp = MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)))));
679 ListAdd(args, (exp = MkExpConstant("0xF000F000") /*MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)))*/));
684 if(member.dataType.kind == classType && member.dataType._class && member.dataType._class.registered && member.dataType._class.registered.offset == 0 &&
685 (member.dataType._class.registered.type == structClass || member.dataType._class.registered.type == noHeadClass || member.dataType._class.registered.type == normalClass))
688 DeclareStruct(registerModuleExternal, member.dataType._class.string, false, true);
689 FullClassNameCat(string, member.dataType._class.string, false);
690 exp = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(string), null)), null));
694 sprintf(string, "%d", member.dataType.size);
695 exp = MkExpConstant(string);
699 if(member.dataType.pointerAlignment)
700 exp = MkExpConstant("0xF000F000");
703 sprintf(string, "%d", member.dataType.alignment);
704 exp = MkExpConstant(string);
711 switch(member.memberAccess)
714 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
717 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
721 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
725 stmt = MkExpressionStmt(MkListOne(
726 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
728 ListAdd(statement.compound.statements, stmt);
730 lastOffset = member.offset + member.dataType.size;
734 static int memberCount = 0;
738 char memberName[256];
739 sprintf(memberName, "dataMember%d", memberCount);
742 curContext = statement.compound.context;
743 context = PushContext();
745 args = MkListOne(MkExpIdentifier(MkIdentifier((member.type == unionMember) ? "unionMember" : "structMember")));
748 switch(member.memberAccess)
751 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
754 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
758 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
762 compound = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("DataMember")),
763 MkListOne(MkInitDeclarator(/*MkDeclaratorPointer(MkPointer(null, null), */MkDeclaratorIdentifier(MkIdentifier(memberName))/*)*/,
764 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("eMember_New")), args)))))), MkList());
765 compound.compound.context = context;
769 // Class class / DataMember member
770 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
772 // DataMember dataMember
773 ListAdd(args, MkExpIdentifier(MkIdentifier(memberName)));
775 RegisterMembersAndProperties((Class)member, true, memberName, compound);
778 stmt = MkExpressionStmt(MkListOne(
779 MkExpCall(MkExpIdentifier(MkIdentifier("eMember_AddMember")), args)));
781 stmt = MkExpressionStmt(MkListOne(
782 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMember")), args)));
784 ListAdd(compound.compound.statements, stmt);
788 ListAdd(statement.compound.statements, compound);
792 lastOffset = member.offset + member.memberOffset;
796 privateMembers = true;
801 ClassProperty classProperty;
803 // Watchable properties
804 for(prop = regClass.membersAndProperties.first; prop; prop = prop.next)
806 if(prop.isProperty && prop.isWatchable)
809 char name[1024], nameM[1024];
811 strcpy(name, "__ecereProp_");
812 FullClassNameCat(name, regClass.fullName, true);
814 FullClassNameCat(name, prop.name, false);
816 strcpy(nameM, "__ecerePropM_");
817 FullClassNameCat(nameM, regClass.fullName, true);
819 FullClassNameCat(nameM, prop.name, false);
821 args = MkListOne(MkExpCondition(MkExpIdentifier(MkIdentifier(nameM)), MkListOne(MkExpIdentifier(MkIdentifier(nameM))), MkExpIdentifier(MkIdentifier(name))));
822 stmt = MkExpressionStmt(MkListOne(
823 MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_Watchable")), args)));
824 ListAdd(registerModuleBody.compound.statements, stmt);
828 // Add Class Properties
829 for(classProperty = (ClassProperty)regClass.classProperties.first; classProperty; classProperty = (ClassProperty)((BTNode)classProperty).next)
831 OldList * args = MkList();
833 char * string = QMkString(classProperty.name);
836 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
839 ListAdd(args, MkExpString(string));
844 char * string = QMkString(classProperty.dataTypeString);
845 ListAdd(args, MkExpString(string));
849 if(classProperty.Set)
851 strcpy(name, "__ecereClassProp_");
852 FullClassNameCat(name, regClass.fullName, true);
853 strcat(name, "_Set_");
854 strcat(name, classProperty.name);
855 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
858 ListAdd(args, MkExpConstant("0"));
860 if(classProperty.Get)
862 strcpy(name, "__ecereClassProp_");
863 FullClassNameCat(name, regClass.fullName, true);
864 strcat(name, "_Get_");
865 strcat(name, classProperty.name);
867 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
870 ListAdd(args, MkExpConstant("0"));
872 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddClassProperty")), args)));
873 ListAdd(registerModuleBody.compound.statements, stmt);
878 extern External curExternal;
880 void GetNameSpaceString(NameSpace ns, char * string)
883 GetNameSpaceString(ns.parent, string);
886 strcat(string, ns.name);
887 strcat(string, "::");
891 // *******************************************************************
892 static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol, OldList baseSpecs, OldList enumValues, OldList defs, External external, AccessMode declMode)
895 Class regClass = symbol.registered;
899 classType = regClass.type;
900 if(classType == enumClass && enumValues && (inCompiler || !buildingECERECOMModule))
903 for(e = enumValues.first; e; e = e.next)
912 e.exp.destType = destType;
914 // Set parsingType to avoid producing errors
916 ProcessExpressionType(e.exp);
921 destType.kind = TypeKind::classType;
922 destType._class = symbol;
923 ProcessExpressionType(e.exp);
925 if(e.exp.type == identifierExp && e.exp.expType && e.exp.identifier && e.exp.identifier.string && e.exp.expType.kind == enumType)
927 // Resolve enums here
929 char * string = e.exp.identifier.string;
930 for(l = e.exp.expType.members.first; l; l = l.next)
932 if(!strcmp(l.name, string))
936 FreeExpContents(e.exp);
937 e.exp.type = constantExp;
938 e.exp.constant = PrintInt64(l.data);
939 FreeType(e.exp.expType);
940 e.exp.expType = ProcessTypeString("int64", false);
947 ComputeExpression(e.exp);
948 if(e.exp.isConstant && e.exp.type == constantExp)
950 Operand op = GetOperand(e.exp);
955 value = op.type.isSigned ? (int64)op.c : (int64)op.uc;
958 value = op.type.isSigned ? (int64)op.s : (int64)op.us;
961 value = op.type.isSigned ? (int64)op.i64 : (int64)op.ui64;
965 value = op.type.isSigned ? (int64)op.i : (int)op.ui;
968 eEnum_AddFixedValue(regClass, e.id.string, value);
972 eEnum_AddValue(regClass, e.id.string);
975 eEnum_AddValue(regClass, e.id.string);
977 // Fix up derivatives enums largest
979 EnumClassData baseData = regClass.data;
981 for(deriv = regClass.derivatives.first; deriv; deriv = deriv.next)
983 Class c = deriv.data;
984 if(c && c.type == enumClass)
986 EnumClassData data = c.data;
987 data.largest = baseData.largest;
993 // Process all functions
994 if(definitions != null)
998 for(def = definitions.first; def; def = def.next)
1000 if(def.type == propertyWatchClassDef && def.propertyWatch)
1002 PropertyWatch propWatch = def.propertyWatch;
1004 char watcherName[1024];
1006 Statement stmt = MkExpressionStmt(MkList());
1010 sprintf(watcherName,"__ecerePropertySelfWatcher_%d", propWatcherID++);
1011 for(propID = propWatch.properties->first; propID; propID = propID.next)
1013 strcat(watcherName, "_");
1014 strcat(watcherName, propID.string);
1017 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)), MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null)));
1019 ListAdd(specs, MkSpecifier(STATIC));
1020 ListAdd(specs, MkSpecifier(VOID));
1022 func = MkClassFunction(specs, null, decl, null);
1023 ProcessClassFunctionBody(func, propWatch.compound);
1025 decl.symbol = Symbol { };
1026 excludedSymbols->Add(decl.symbol);
1028 func.dontMangle = true;
1030 propWatch.compound = null;
1031 definitions.Insert(null, MkClassDefFunction(func));
1033 for(propID = propWatch.properties->first; propID; propID = propID.next)
1035 Property prop = eClass_FindProperty(regClass, propID.string, privateModule);
1038 // eProperty_SelfWatch(_class, name, callback);
1039 OldList * args = MkList();
1040 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1042 char * s = QMkString(propID.string);
1043 ListAdd(args, MkExpString(s));
1046 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
1048 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
1051 Compiler_Error($"Property %s not found in class %s\n", propID.string, regClass.fullName);
1053 FreePropertyWatch(def.propertyWatch);
1054 def.propertyWatch = (PropertyWatch)stmt; // Store this here to use it after CreateRegisterModuleBody is done
1056 // ListAdd(statements, stmt);
1061 for(def = definitions.first; def; def = def.next)
1063 if(def.type == functionClassDef)
1065 ProcessClassFunction(regClass, def.function, defs, external.prev, declMode == staticAccess);
1070 // Make the RegisterClass section
1071 if(inCompiler && !symbol.notYetDeclared && regClass)
1074 OldList * args = MkList();
1077 const char * registerFunction = null;
1078 AccessMode inheritanceAccess = publicAccess;
1080 CreateRegisterModuleBody();
1082 curExternal = registerModuleExternal;
1085 switch(regClass.type)
1087 case structClass: ListAdd(args, MkExpIdentifier(MkIdentifier("structClass"))); break;
1088 case bitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("bitClass"))); break;
1089 case enumClass: ListAdd(args, MkExpIdentifier(MkIdentifier("enumClass"))); break;
1090 case noHeadClass: ListAdd(args, MkExpIdentifier(MkIdentifier("noHeadClass"))); break;
1091 case unitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("unitClass"))); break;
1092 case normalClass: ListAdd(args, MkExpIdentifier(MkIdentifier("normalClass"))); break;
1096 char nameSpace[1024] = "";
1097 char className[1024] = "";
1099 GetNameSpaceString(regClass.nameSpace, nameSpace);
1101 if(declMode == staticAccess)
1103 GetLastDirectory(sourceFile, className);
1104 ChangeCh(className, '.', '_');
1105 strcat(className, "}");
1107 strcat(className, nameSpace);
1108 strcat(className, regClass.name);
1109 string = QMkString(className);
1110 ListAdd(args, MkExpString(string));
1116 char * string = QMkString(regClass.base.name);
1117 ListAdd(args, regClass.base ? MkExpString(string) :
1118 MkExpConstant("0"));
1123 if(baseSpecs != null)
1125 Type baseType = ProcessType(baseSpecs, null);
1126 if(baseType.kind != structType && baseType.kind != unionType)
1128 char baseName[1024] = "";
1130 if(baseType.kind == TypeKind::classType && baseType._class && baseType._class.isStatic)
1132 // TODO: Handle static classes and complex declarators...
1133 GetLastDirectory(sourceFile, baseName);
1134 ChangeCh(baseName, '.', '_');
1135 strcat(baseName, "}");
1136 strcat(baseName, baseType._class.string);
1139 PrintType(baseType, baseName, false, true);
1141 string = QMkString(baseName);
1142 ListAdd(args, MkExpString(string));
1146 ListAdd(args, MkExpConstant("0"));
1148 if(((Specifier)baseSpecs.first).type == baseSpecifier && ((Specifier)baseSpecs.first).specifier == PRIVATE)
1149 inheritanceAccess = privateAccess;
1152 ListAdd(args, MkExpConstant("0"));
1154 //ListAdd(args, class.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1155 //MkSpecifierName(class.structName)), null)) : MkExpConstant("0"));
1157 if(regClass.type == structClass || regClass.type == normalClass || regClass.type == noHeadClass)
1159 // Check if we have a data member in this class
1160 DataMember member = null;
1163 for(base = regClass.base; base && base.type != systemClass; base = base.next)
1165 for(member = base.membersAndProperties.first; member; member = member.next)
1166 if(!member.isProperty)
1173 if(regClass.type == structClass && symbol.declaredStruct && member)
1175 char baseStructName[1024];
1176 baseStructName[0] = 0;
1177 // TESTING THIS HERE
1178 // FullClassNameCat(baseStructName, regClass.base.fullName, false);
1179 strcpy(baseStructName, (regClass.base.templateClass ? regClass.base.templateClass : regClass.base).fullName);
1181 ListAdd(args, MkExpOp(
1182 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)), '-',
1183 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(baseStructName), null)), null))));
1186 ListAdd(args, symbol.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1187 MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)) : MkExpConstant("0"));
1191 ListAdd(args, MkExpConstant("0"));
1194 //if(regClass.type == normalClass)
1196 char classDataStructName[1024];
1197 strcpy(classDataStructName, "__ecereClassData_");
1198 FullClassNameCat(classDataStructName, symbol.string, false);
1200 ListAdd(args, symbol.classData ? MkExpTypeSize(MkTypeName(MkListOne(
1201 MkStructOrUnion(structSpecifier, MkIdentifier(classDataStructName), null)), null)) : MkExpConstant("0"));
1204 // TODO: Support Class Data for all other types of classes
1205 ListAdd(args, MkExpConstant("0"));
1208 if(regClass.type == normalClass || regClass.type == noHeadClass)
1211 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), symbol.needConstructor ?
1212 MkExpIdentifier(MkIdentifier(symbol.constructorName)) :
1213 MkExpConstant("0")));
1215 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), symbol.needDestructor ?
1216 MkExpIdentifier(MkIdentifier(symbol.destructorName)) :
1217 MkExpConstant("0")));
1221 // TODO: Support Constructors / Destructors for structs
1224 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpConstant("0")));
1226 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpConstant("0")));
1230 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1236 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1239 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1243 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1248 switch(inheritanceAccess)
1251 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1255 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1259 registerFunction = "eSystem_RegisterClass";
1261 stmt = MkExpressionStmt(MkListOne(
1262 MkExpOp(MkExpIdentifier(MkIdentifier("class")), '=',
1263 MkExpCall((exp = MkExpIdentifier(MkIdentifier(registerFunction))), args))));
1265 ListAdd(registerModuleBody.compound.statements, stmt);
1268 stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className)))),
1269 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1270 MkExpIdentifier(MkIdentifier("class"))))), null);
1273 stmt = MkIfStmt(MkListOne(
1275 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
1276 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application"))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1277 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1278 MkExpIdentifier(MkIdentifier("class"))))), null);
1280 stmt = MkIfStmt(MkListOne(
1281 MkExpOp(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1282 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1283 MkExpIdentifier(MkIdentifier("class"))))), null);
1286 ListAdd(registerModuleBody.compound.statements, stmt);
1288 if(external && external.type == classExternal && external._class.deleteWatchable)
1290 args = MkListOne(MkExpIdentifier(MkIdentifier("class")));
1291 stmt = MkExpressionStmt(MkListOne(
1292 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DestructionWatchable")), args)));
1293 ListAdd(registerModuleBody.compound.statements, stmt);
1296 // Add Virtual Methods
1299 Class base = regClass.base;
1301 for(c = 0; c<base.vTblSize; c++)
1303 Symbol method = (Symbol)regClass._vTbl[c];
1304 if((void *) method != DummyMethod && base._vTbl[c] != (void *)method && method.methodExternal) // TOLOOKAT: Module check here?
1306 External external = method.methodExternal;
1307 OldList * args = MkList();
1308 Identifier id = external.function ? GetDeclId(external.function.declarator) : null;
1311 External e = method.methodExternal ? method.methodExternal : method.methodCodeExternal;
1312 registerModuleExternal.CreateUniqueEdge(e, e.type == functionExternal);
1316 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1319 //char * string = QMkString(method.string);
1321 char * string = QMkString(method.method.name);
1322 ListAdd(args, MkExpString(string));
1326 ListAdd(args, MkExpConstant("0"));
1328 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1332 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1334 exp.expType = Type { refCount = 1 };
1335 stmt = MkExpressionStmt(MkListOne(
1336 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1337 ListAdd(registerModuleBody.compound.statements, stmt);
1342 // Add Virtual Methods in order
1345 for(c = regClass.base ? regClass.base.vTblSize : 0; c < regClass.vTblSize; c++)
1347 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1349 if(method.type == virtualMethod && method._class == regClass && method.vid == c)
1354 External external = method.symbol ? ((Symbol)method.symbol).methodCodeExternal : null;
1355 OldList * args = MkList();
1356 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1359 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1362 char * string = QMkString(method.name);
1363 ListAdd(args, MkExpString(string));
1368 char * string = QMkString(method.dataTypeString);
1369 ListAdd(args, MkExpString(string));
1373 if(id && external.function.body)
1375 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(id.string))));
1376 exp.expType = Type { refCount = 1 };
1380 ListAdd(args, (exp = MkExpConstant("0")));
1384 switch(method.memberAccess)
1387 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1390 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1394 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1398 //sprintf(name, "__ecereVMethodID_%s_%s", method._class.fullName, method.name);
1399 strcpy(name, "__ecereVMethodID_");
1400 FullClassNameCat(name, method._class.fullName, false);
1402 strcat(name, method.name);
1404 exp = /*MkExpPointer(*/MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddVirtualMethod")), args)/*, MkIdentifier("vid"))*/;
1406 exp->expType = eSystem_New(sizeof(Type));
1407 exp->expType->refCount++;
1408 exp->expType->isSigned = true;
1409 exp->expType->kind = TypeInt;
1412 stmt = MkExpressionStmt(MkListOne(/*
1413 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', */exp/*)*/));
1416 registerModuleExternal.CreateUniqueEdge(external, external.type == functionExternal);
1418 DeclareMethod(curExternal, method, name);
1420 ListAdd(registerModuleBody.compound.statements, stmt);
1427 // Add Public Methods (all for now)
1428 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1430 if(method.type == virtualMethod && method._class == regClass);
1431 else if(method.memberAccess == publicAccess || !method.dataTypeString)
1433 External external = method.symbol ? ((Symbol )method.symbol).methodCodeExternal : null;
1434 OldList * args = MkList();
1435 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1438 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1441 char * string = QMkString(method.name);
1442 ListAdd(args, MkExpString(string));
1447 char * string = QMkString(method.dataTypeString);
1448 ListAdd(args, MkExpString(string));
1452 if(id && external.function.body)
1454 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1456 exp.expType = Type { refCount = 1 };
1460 ListAdd(args, (exp = MkExpConstant("0")));
1464 switch(method.memberAccess)
1467 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1470 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1474 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1478 stmt = MkExpressionStmt(MkListOne(
1479 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1480 ListAdd(registerModuleBody.compound.statements, stmt);
1483 registerModuleExternal.CreateUniqueEdge(external, external.type == functionExternal);
1487 RegisterMembersAndProperties(regClass, false, "class", registerModuleBody);
1489 // Add Enumeration Values
1490 if(classType == enumClass)
1493 Class enumClass = eSystem_FindClass(privateModule, "enum");
1494 EnumClassData e = ACCESS_CLASSDATA(regClass, enumClass);
1496 for(value = e.values.first; value; value = value.next)
1498 OldList * args = MkList();
1501 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1504 char * string = QMkString(value.name);
1505 ListAdd(args, MkExpString(string));
1511 if(!strcmp(regClass.dataTypeString, "uint64"))
1512 temp = PrintUInt64(value.data);
1514 temp = PrintInt64(value.data);
1515 ListAdd(args, MkExpConstant(temp));
1519 stmt = MkExpressionStmt(MkListOne(
1520 MkExpCall(MkExpIdentifier(MkIdentifier("eEnum_AddFixedValue")), args)));
1521 ListAdd(registerModuleBody.compound.statements, stmt);
1525 // Add Template Parameters
1526 if(symbol.templateParams)
1528 TemplateParameter param;
1529 for(param = symbol.templateParams->first; param; param = param.next)
1531 OldList * args = MkList();
1534 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1538 char * string = QMkString(param.identifier.string);
1539 ListAdd(args, MkExpString(string));
1544 ListAdd(args, MkExpIdentifier(MkIdentifier((param.type == type) ? "type" : ((param.type == identifier) ? "identifier" : "expression"))));
1552 char * typeString = param.dataType ? StringFromSpecDecl(param.dataType.specifiers, param.dataType.decl) : null;
1553 char * string = QMkString(typeString);
1554 ListAdd(args, MkExpString(string));
1561 char memberTypeString[132] = "TemplateMemberType::";
1562 bool needClass = true;
1564 param.memberType.OnGetString(memberTypeString + strlen(memberTypeString), null, &needClass);
1566 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)),
1567 MkExpIdentifier(MkIdentifier(memberTypeString))));
1573 if(param.defaultArgument)
1575 OldList * members = MkList();
1580 char * typeString = param.defaultArgument.templateDatatype ?
1581 StringFromSpecDecl(param.defaultArgument.templateDatatype.specifiers, param.defaultArgument.templateDatatype.decl) : null;
1582 char * string = QMkString(typeString);
1584 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1592 char memberString[1024];
1594 memberString[0] = '\0';
1596 if(param.defaultArgument.identifier._class)
1598 if(param.defaultArgument.identifier._class.type == templateTypeSpecifier)
1599 strcpy(memberString, param.defaultArgument.identifier._class.templateParameter.identifier.string);
1600 else if(param.defaultArgument.identifier._class.name)
1601 strcpy(memberString, param.defaultArgument.identifier._class.name);
1604 strcat(memberString, "::");
1606 strcat(memberString, param.defaultArgument.identifier.string);
1608 string = QMkString(memberString);
1610 // TOFIX: UNIONS ARE BROKEN FOR ASSIGNMENTS, USING dataTypeString INSTEAD
1611 // members->Add(MkMemberInit(MkListOne(MkIdentifier("memberString")), MkInitializerAssignment(MkExpString(string))));
1612 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1620 OldList * ids = MkList();
1622 char * string = null;
1624 //ProcessExpressionType(param.defaultArgument.expression);
1625 //ComputeExpression(param.defaultArgument.expression);
1627 op = GetOperand(param.defaultArgument.expression);
1628 ui64String = PrintUInt64(op.ui64);
1629 ids->Add(MkIdentifier("expression"));
1630 ids->Add(MkIdentifier("ui64"));
1632 //string = QMkString(ui64String);
1633 members->Add(MkMemberInit(ids, MkInitializerAssignment(MkExpConstant(ui64String))));
1640 ListAdd(args, MkExpInstance(MkInstantiation(MkSpecifierName("ClassTemplateArgument"), null,
1641 MkListOne(MkMembersInitList(members)))));
1644 ListAdd(args, MkExpIdentifier(MkIdentifier("null")));
1646 stmt = MkExpressionStmt(MkListOne(
1647 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddTemplateParameter")), args)));
1648 ListAdd(registerModuleBody.compound.statements, stmt);
1650 stmt = MkExpressionStmt(MkListOne(
1651 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DoneAddingTemplateParameters")),
1652 MkListOne(MkExpIdentifier(MkIdentifier("class"))))));
1653 ListAdd(registerModuleBody.compound.statements, stmt);
1656 if(definitions != null)
1658 for(def = definitions.first; def; def = def.next)
1660 if(def.type == propertyWatchClassDef && def.propertyWatch)
1662 ListAdd(registerModuleBody.compound.statements, (Statement)def.propertyWatch);
1663 def.propertyWatch = null;
1665 else if(def.type == classDesignerClassDef)
1668 char className[1024];
1669 sprintf(className, "__ecereClass_%s", def.designer);
1671 DeclareClass(FindClass(def.designer), className);
1675 char * s = QMkString(def.designer);
1676 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1677 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
1678 MkExpString(s)))), null);
1681 ListAdd(registerModuleBody.compound.statements, stmt);
1683 else if(def.type == classNoExpansionClassDef)
1685 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1686 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("noExpansion")), '=',
1687 MkExpConstant("1")))), null);
1688 ListAdd(registerModuleBody.compound.statements, stmt);
1690 else if(def.type == classFixedClassDef)
1692 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1693 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("fixed")), '=',
1694 MkExpConstant("1")))), null);
1695 ListAdd(registerModuleBody.compound.statements, stmt);
1697 regClass.fixed = true;
1699 else if(def.type == designerDefaultPropertyClassDef)
1701 char * s = QMkString(def.defaultProperty.string);
1702 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1703 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=',
1704 MkExpString(s)))), null);
1705 ListAdd(registerModuleBody.compound.statements, stmt);
1708 else if(def.type == classPropertyValueClassDef)
1710 classPropValues.Add(ClassPropertyValue { regClass = regClass, id = def.id, exp = def.initializer.exp });
1712 def.initializer.exp = null;
1720 class ClassPropertyValue
1726 ~ClassPropertyValue()
1732 static List<ClassPropertyValue> classPropValues { };
1734 public void ProcessClassDefinitions()
1736 External external, next;
1738 CreateRegisterModuleBody();
1741 // (Need to do those things after in case something is not yet defined)
1742 for(external = ast->first; external; external = next)
1744 next = external.next;
1745 curExternal = external;
1746 if(external.type == classExternal)
1748 ClassDefinition _class = external._class;
1749 if(_class.definitions)
1751 ProcessClass(normalClass, _class.definitions, _class.symbol, _class.baseSpecs, null, ast, external, _class.declMode);
1755 ast->Remove(external);
1756 FreeExternal(external);
1759 else if(external.type == functionExternal)
1761 bool setStaticMethod = false;
1763 if(external.symbol && !external.symbol.type.thisClass && !external.symbol.type.staticMethod)
1765 // TOCHECK: Where do we actually need this to be set?
1766 external.symbol.type.staticMethod = true;
1767 setStaticMethod = true;
1772 FunctionDefinition function = external.function;
1776 if(!strcmp(function.declarator.symbol.string, "__on_register_module"))
1778 ListAdd(registerModuleBody.compound.statements, function.body);
1779 function.body.compound.context.parent = registerModuleBody.compound.context;
1780 ast->Remove(external);
1781 function.body = null;
1782 FreeExternal(external);
1786 if(function.declMode != privateAccess && function.declMode != publicAccess) continue;
1790 CreateRegisterModuleBody();
1794 char * string = QMkString(function.declarator.symbol.string);
1795 ListAdd(args, MkExpString(string));
1802 char type[1024] = "";
1803 // We don't want functions to be marked as static methods
1805 function.declarator.symbol.type.staticMethod = false;
1806 PrintType(function.declarator.symbol.type, type, true, true);
1808 function.declarator.symbol.type.staticMethod = true;
1809 string = QMkString(type);
1810 ListAdd(args, MkExpString(string));
1816 ListAdd(args, MkExpIdentifier(MkIdentifier(function.declarator.symbol.string)));
1820 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1823 switch(function.declMode)
1826 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1829 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1833 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1837 stmt = MkExpressionStmt(MkListOne(
1838 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterFunction"))), args)));
1840 ListAdd(registerModuleBody.compound.statements, stmt);
1843 else if(external.type == declarationExternal)
1845 Declaration declaration = external.declaration;
1849 if(external.symbol.type && external.symbol.type.kind == functionType && !external.symbol.type.thisClass)
1850 external.symbol.type.staticMethod = true;
1853 if(external.symbol && declaration && declaration.type == initDeclaration)
1855 if(declaration.specifiers)
1857 Specifier specifier;
1858 bool removeExternal = false;
1860 for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
1862 if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
1863 (declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
1865 Symbol symbol = FindClass(specifier.id.string);
1868 ClassType classType;
1869 if(specifier.type == enumSpecifier)
1870 classType = enumClass;
1872 classType = structClass;
1874 removeExternal = true;
1875 // Transfer Context over to Symbol
1876 symbol.ctx = specifier.ctx;
1877 specifier.ctx = null;
1879 ProcessClass(classType, specifier.definitions, symbol, specifier.baseSpecs, specifier.list,ast, external, declaration.declMode);
1883 if(inCompiler && removeExternal)
1885 ast->Remove(external);
1886 FreeExternal(external);
1890 else if(declaration && declaration.type == defineDeclaration)
1892 if(inCompiler && declaration.declMode != staticAccess)
1895 OldList * args = MkList();
1897 CreateRegisterModuleBody();
1901 char * string = QMkString(declaration.id.string);
1902 ListAdd(args, MkExpString(string));
1909 char type[1024] = "";
1910 PrintExpression(declaration.exp, type);
1911 string = QMkString(type);
1912 ListAdd(args, MkExpString(string));
1917 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1920 switch(declaration.declMode)
1923 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1926 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1930 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1934 stmt = MkExpressionStmt(MkListOne(
1935 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterDefine"))), args)));
1937 ListAdd(registerModuleBody.compound.statements, stmt);
1943 // Set the class properties at the very end
1944 for(v : classPropValues)
1946 OldList * findClassArgs = MkList();
1947 OldList * args = MkList();
1948 Statement compoundStmt;
1955 ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
1956 s = QMkString(v.regClass.name);
1957 ListAdd(findClassArgs, MkExpString(s));
1960 ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
1961 s = QMkString(v.id.string);
1962 ListAdd(args, MkExpString(s));
1966 // TOFIX: We're probably missing a dest type here, and might want to handle through same pathway as in pass2's opExp
1967 ProcessExpressionType(e);
1968 if(e.expType.isPointerType)
1969 e = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("intptr")), null), e);
1971 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), e));
1972 compoundStmt = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
1973 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("_class")),
1974 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eSystem_FindClass")), findClassArgs)))))),
1975 MkListOne(MkExpressionStmt(MkListOne(
1976 MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eClass_SetProperty")), args)))));
1977 compoundStmt.compound.context = Context { parent = registerModuleBody.compound.context };
1978 ListAdd(registerModuleBody.compound.statements, compoundStmt);
1981 classPropValues.Free();