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 processer 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;
33 int symid = func.declarator.symbol.id;
34 int symidCode = func.declarator.symbol.idCode;
39 func.specifiers = MkList();
40 // Add static to the specifiers
42 func.specifiers->Insert(null, MkSpecifier(STATIC));
45 propSymbol = func.declarator.symbol;
47 ReplaceThisClassSpecifiers(func.specifiers, owningClass);
49 if(propSymbol.externalGet == (External)func)
50 func.declarator.symbol = null;
51 else if(propSymbol.externalSet == (External)func)
53 func.declarator.symbol = null;
56 else if(propSymbol.externalIsSet == (External)func)
58 func.declarator.symbol = null;
59 symid += 2; // TOFIX: What should we do with this? Where are 2 IDs allocated for properties? In MkProperty...
64 /*FunctionDefinition*/ function = _MkFunction(func.specifiers, func.declarator, null, false);
65 function.propSet = func.propSet;
66 function.type = func.type;
67 if(func.type) func.type.refCount++;
68 ProcessFunctionBody(function, func.body);
69 external = MkExternalFunction(function);
71 external.symbol = func.declarator.symbol;
72 external.function._class = func._class;
75 symbol = func.declarator.symbol;
76 //symbol.id = func.id; //symid;
78 symbol.idCode = symidCode;
83 Method method = func.declarator.symbol.method;
84 func.declarator.symbol.methodExternal = external;
86 // DANGER: Added this one...
88 if(method && method.symbol)
89 //((Symbol)method.symbol).methodExternal = external;
90 ((Symbol)method.symbol).methodCodeExternal = external;
92 if(method && method.type == virtualMethod)
95 ProcessMethodType(method);
97 methodDataType = method.dataType;
99 // Do type checking here of type against method.dataType
100 // ThisClass must be the owning class for types not specified, static for static, or inherit from method's ThisClass is specified
101 // If not specified, defaults to ThisClass if ThisClass specified in method, otherwise overiding class or static
105 if(!type.staticMethod && !type.thisClass && !type.thisClassTemplate)
107 if(method.dataType.thisClassTemplate)
109 if(owningClass.templateArgs)
111 ClassTemplateArgument * arg = FindTemplateArg(owningClass, method.dataType.thisClassTemplate);
112 type.byReference = method.dataType.byReference;
114 methodDataType = ProcessTypeString(method.dataTypeString, false);
115 type.thisClass = methodDataType.thisClass = arg ? FindClass(arg->dataTypeString) : null;
118 else if(method.dataType.staticMethod)
119 type.staticMethod = true;
120 else if(method.dataType.thisClass)
122 type.thisClass = method.dataType.thisClass;
123 type.byReference = method.dataType.byReference;
127 if(!owningClass.symbol)
128 owningClass.symbol = FindClass(owningClass.fullName);
130 type.thisClass = owningClass.symbol;
131 // WORKING ON THIS TO SUPPORT : pass.NotifyClicked(this, pass, 0, 0, key.modifiers);
132 type.extraParam = true;
137 if(!MatchTypes(type, methodDataType, null, owningClass, method._class /*owningClass*/, true, true, true, false, true))
140 // MatchTypes(type, methodDataType, null, owningClass, owningClass, true, true, true, false);
142 Compiler_Error($"Incompatible virtual function %s\n", method.name);
146 // Mark typed_object/any_object parameters as such according to method type
148 Declarator funcDecl = GetFuncDecl(func.declarator);
149 if(funcDecl.function.parameters && funcDecl.function.parameters->first)
151 TypeName param = funcDecl.function.parameters->first;
153 for(typeParam = methodDataType.params.first; typeParam && param; typeParam = typeParam.next)
155 if(typeParam.classObjectType)
157 param.classObjectType = typeParam.classObjectType;
158 if(param.declarator && param.declarator.symbol)
159 param.declarator.symbol.type.classObjectType = typeParam.classObjectType;
161 param = param ? param.next : null;
165 if(methodDataType != method.dataType)
166 FreeType(methodDataType);
171 if(!type.staticMethod && !type.thisClass)
173 if(owningClass && !owningClass.symbol)
174 owningClass.symbol = FindClass(owningClass.fullName);
176 type.thisClass = owningClass ? FindClass(owningClass.fullName) : null;
182 // TESTING THIS HERE: (Implementing Class Properties)
183 if(symbol.type && !symbol.type.staticMethod && !symbol.type.thisClass)
185 if(!owningClass.symbol)
186 owningClass.symbol = FindClass(owningClass.fullName);
187 symbol.type.thisClass = owningClass.symbol;
190 // Those type of classes don't need a this parameter for Set methods, null thisClass before changing the externals
191 if(propSymbol.externalSet == (External)func && propSymbol._property && propSymbol._property.conversion)
193 if(symbol.type.thisClass && symbol.type.classObjectType != classPointer)
195 // TODO: Perhaps improve this so as to support both "this =" and "return " syntax for all types of classes
196 if(owningClass.type != structClass)
197 //function.propertyNoThis = true;
198 symbol.type.thisClass = null;
203 if(propSymbol.externalGet == (External)func)
205 propSymbol.externalGet = external;
207 else if(propSymbol.externalSet == (External)func)
209 propSymbol.externalSet = external;
211 else if(propSymbol.externalIsSet == (External)func)
213 propSymbol.externalIsSet = external;
217 // Constructor destructor
218 //symbol.type = Type { };
225 func.declarator = null;
226 func.specifiers = null;
229 defs.Insert(after, external);
233 Method method = func.declarator.symbol.method;
234 if(method && method.symbol)
235 ((Symbol)method.symbol).methodCodeExternal = null;
236 if(func.declarator.symbol && func.declarator.symbol.methodExternal == external)
237 func.declarator.symbol.methodExternal = null;
239 //external.function = null;
240 func.declarator = null;
241 func.specifiers = null;
243 FreeExternal(external); // Free external here?
248 globalContext /*curContext*/.symbols.Remove((BTNode)symbol);
249 excludedSymbols->Add(symbol);
252 defs.Insert(after, external);
254 external.function.declarator = CopyDeclarator(external.function.declarator);
255 external.function.specifiers = CopyList(external.function.specifiers, CopySpecifier);
256 external.function.body = null;
262 void CreateRegisterModuleBody()
264 if(!registerModuleBody && inCompiler)
266 char registerName[1024], moduleName[MAX_FILENAME];
267 OldList * specifiers;
268 Declarator declarator;
269 TypeName moduleParam;
271 registerModuleBody = MkCompoundStmt(MkList(), MkList());
272 registerModuleBody.compound.context = Context { parent = globalContext };
275 ListAdd(registerModuleBody.compound.declarations,
276 MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null) /*MkSpecifierName("ecere::com::Class")*/ /*MkStructOrUnion(SpecifierStruct, MkIdentifier("Class"), null)*/),
277 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class"))), null))));
279 ListAdd(registerModuleBody.compound.declarations,
280 MkDeclaration((specifiers = MkListOne(MkSpecifierName("ecere::com::Class"))),
281 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("class")), null))));
282 // Avoid unused warning here
283 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
285 specifiers = MkList();
286 ListAdd(specifiers, MkSpecifier(VOID));
288 moduleParam = MkTypeName(MkListOne(/*MkSpecifier(VOID)*/MkSpecifierName("Module")),
289 //MkDeclaratorPointer(MkPointer(null, null),
290 MkDeclaratorIdentifier(MkIdentifier("module")));
292 GetLastDirectory(outputFile, moduleName);
293 //strcpy(moduleName, argv[2]);
294 StripExtension(moduleName);
295 FixModuleName(moduleName);
296 sprintf(registerName, "__ecereRegisterModule_%s", moduleName);
298 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
299 MkListOne(moduleParam));
302 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
303 ProcessFunctionBody(function, registerModuleBody);
304 function.declMode = defaultAccess;
305 if(!ast) ast = MkList();
306 ListAdd(ast, (registerModuleExternal = MkExternalFunction(function)));
311 if(!unregisterModuleBody && inCompiler)
313 char registerName[1024], moduleName[MAX_FILENAME];
314 OldList * specifiers;
315 Declarator declarator;
316 TypeName moduleParam;
318 unregisterModuleBody = MkCompoundStmt(MkList(), MkList());
319 unregisterModuleBody.compound.context = Context { parent = globalContext };
321 specifiers = MkList();
322 ListAdd(specifiers, MkSpecifier(VOID));
324 moduleParam = MkTypeName(MkListOne(/*MkSpecifier(VOID)*/ MkSpecifierName("Module")),
325 //MkDeclaratorPointer(MkPointer(null, null),
326 MkDeclaratorIdentifier(MkIdentifier("module")));
328 GetLastDirectory(outputFile, moduleName);
329 StripExtension(moduleName);
330 FixModuleName(moduleName);
331 //strcpy(moduleName, argv[2]);
332 sprintf(registerName, "__ecereUnregisterModule_%s", moduleName);
334 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
335 MkListOne(moduleParam));
338 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
339 ProcessFunctionBody(function, unregisterModuleBody);
340 function.declMode = defaultAccess;
341 if(!ast) ast = MkList();
342 ListAdd(ast, (unregisterModuleExternal = MkExternalFunction(function)));
347 void RegisterMembersAndProperties(Class regClass, bool isMember, const char * className, Statement statement)
349 DataMember dataMember = isMember ? (DataMember)regClass : null;
354 char dataMemberSize[16];
358 bool privateMembers = false;
360 sprintf(dataMemberSize, "%d", (int)sizeof(DataMember));
363 for(prop = regClass.conversions.first; prop; prop = prop.next)
365 OldList * args = MkList();
369 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
371 ListAdd(args, MkExpConstant("0"));
375 char * string = QMkString(prop.dataTypeString);
376 ListAdd(args, MkExpString(string));
382 strcpy(name, "__ecereProp_");
383 FullClassNameCat(name, regClass.fullName, false);
384 strcat(name, "_Set_");
385 // strcat(name, prop.name);
386 FullClassNameCat(name, prop.name, true);
387 //MangleClassName(name);
388 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
391 ListAdd(args, MkExpConstant("0"));
395 strcpy(name, "__ecereProp_");
396 FullClassNameCat(name, regClass.fullName, false);
397 strcat(name, "_Get_");
398 // strcat(name, prop.name);
399 FullClassNameCat(name, prop.name, true);
400 //MangleClassName(name);
402 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
405 ListAdd(args, MkExpConstant("0"));
409 switch(prop.memberAccess)
412 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
415 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
419 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
423 strcpy(name, "__ecereProp_");
424 FullClassNameCat(name, regClass.fullName, false);
426 FullClassNameCat(name, prop.name, true);
427 // strcat(name, prop.name);
428 //MangleClassName(name);
430 stmt = MkExpressionStmt(MkListOne(
431 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=',
432 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
433 ListAdd(registerModuleBody.compound.statements, stmt);
437 for(member = isMember ? dataMember.members.first : regClass.membersAndProperties.first; member; member = member.next)
439 if(member.isProperty)
441 prop = (Property) member;
443 OldList * args = MkList();
444 char name[1024], nameM[1024];
445 char * string = QMkString(prop.name);
448 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
451 ListAdd(args, MkExpString(string));
456 char * string = QMkString(prop.dataTypeString);
457 ListAdd(args, MkExpString(string));
463 strcpy(name, "__ecereProp_");
464 FullClassNameCat(name, regClass.fullName, false);
465 strcat(name, "_Set_");
466 FullClassNameCat(name, prop.name, true);
467 // strcat(name, prop.name);
468 //MangleClassName(name);
469 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
472 ListAdd(args, MkExpConstant("0"));
476 strcpy(name, "__ecereProp_");
477 FullClassNameCat(name, regClass.fullName, false);
478 strcat(name, "_Get_");
479 FullClassNameCat(name, prop.name, true);
480 // strcat(name, prop.name);
481 //MangleClassName(name);
482 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
485 ListAdd(args, MkExpConstant("0"));
488 switch(prop.memberAccess)
491 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
494 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
498 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
502 strcpy(name, "__ecereProp_");
503 FullClassNameCat(name, regClass.fullName, false);
505 FullClassNameCat(name, prop.name, true);
506 // strcat(name, prop.name);
507 //MangleClassName(name);
509 strcpy(nameM, "__ecerePropM_");
510 FullClassNameCat(nameM, regClass.fullName, false);
512 FullClassNameCat(nameM, prop.name, true);
513 // strcat(nameM, prop.name);
514 //MangleClassName(nameM);
516 if(prop.dataTypeString)
518 stmt = MkExpressionStmt(MkListOne(
519 MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
520 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
524 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args)));
526 ListAdd(registerModuleBody.compound.statements, stmt);
531 strcpy(name, "__ecereProp_");
532 FullClassNameCat(name, regClass.fullName, true);
533 strcat(name, "_IsSet_");
534 FullClassNameCat(name, prop.name, false);
535 // strcat(name, prop.name);
536 //MangleClassName(name);
538 stmt = MkExpressionStmt(MkListOne(
539 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("IsSet")), '=',
540 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpIdentifier(MkIdentifier(name))))));
541 ListAdd(registerModuleBody.compound.statements, stmt);
543 if(prop.symbol && ((Symbol)prop.symbol).propCategory)
545 stmt = MkExpressionStmt(MkListOne(
546 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("category")), '=',
547 CopyExpression(((Symbol)prop.symbol).propCategory))));
548 ListAdd(registerModuleBody.compound.statements, stmt);
551 if(prop.dataTypeString)
553 OldList * list = MkList();
554 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', MkExpIdentifier(MkIdentifier(nameM))));
555 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=', MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0"))));
556 // stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(name)))), MkExpressionStmt(list), null);
557 stmt = MkIfStmt(MkListOne(MkExpOp(
558 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
559 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application")))), MkExpressionStmt(list), null);
561 ListAdd(registerModuleBody.compound.statements, stmt);
563 // Unregister 2nd property
564 stmt = MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
565 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0")))));
566 ListAdd(unregisterModuleBody.compound.statements, stmt);
570 else if(member.type == normalMember && !isMember && regClass.type == bitClass)
572 BitMember bitMember = (BitMember) member;
573 OldList * args = MkList();
576 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
580 char * string = QMkString(bitMember.name);
581 ListAdd(args, MkExpString(string));
586 char * string = QMkString(bitMember.dataTypeString);
587 ListAdd(args, MkExpString(string));
593 sprintf(string, "%d", bitMember.size);
594 ListAdd(args, (exp = MkExpConstant(string)));
599 sprintf(string, "%d", bitMember.pos);
600 ListAdd(args, (exp = MkExpConstant(string)));
604 switch(member.memberAccess)
607 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
610 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
614 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
618 stmt = MkExpressionStmt(MkListOne(
619 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddBitMember")), args)));
621 ListAdd(statement.compound.statements, stmt);
623 else if(member.memberAccess == publicAccess || (member.type == normalMember && !member.dataTypeString))
626 // ADD PRIVATE DATA PADDING HERE...
629 uint offset = member.offset - lastOffset;
634 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
639 sprintf(string, "\"__ecerePrivateData%d\"", privateID++);
640 ListAdd(args, MkExpString(string));
645 sprintf(string, "\"byte[%d]\"", offset);
646 ListAdd(args, MkExpString(string));
651 sprintf(string, "%d", offset);
652 ListAdd(args, (exp = MkExpConstant(string)));
656 ListAdd(args, (exp = MkExpConstant("1")));
659 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
661 stmt = MkExpressionStmt(MkListOne(
662 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
664 ListAdd(statement.compound.statements, stmt);
665 privateMembers = false;
668 if(member.type == normalMember)
671 member.dataType = ProcessTypeString(member.dataTypeString, false);
673 ComputeTypeSize(member.dataType);
678 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
682 char * string = QMkString(member.name);
683 ListAdd(args, MkExpString(string));
688 char * string = QMkString(member.dataTypeString);
689 ListAdd(args, MkExpString(string));
695 sprintf(string, "%d", member.dataType.size);
696 ListAdd(args, (exp = MkExpConstant(string)));
702 sprintf(string, "%d", member.dataType.alignment);
703 ListAdd(args, (exp = MkExpConstant(string)));
707 switch(member.memberAccess)
710 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
713 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
717 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
721 stmt = MkExpressionStmt(MkListOne(
722 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
724 ListAdd(statement.compound.statements, stmt);
726 lastOffset = member.offset + member.dataType.size;
730 static int memberCount = 0;
734 char memberName[256];
735 sprintf(memberName, "dataMember%d", memberCount);
738 curContext = statement.compound.context;
739 context = PushContext();
741 args = MkListOne(MkExpIdentifier(MkIdentifier((member.type == unionMember) ? "unionMember" : "structMember")));
744 switch(member.memberAccess)
747 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
750 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
754 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
758 compound = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("DataMember")),
759 MkListOne(MkInitDeclarator(/*MkDeclaratorPointer(MkPointer(null, null), */MkDeclaratorIdentifier(MkIdentifier(memberName))/*)*/,
760 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("eMember_New")), args)))))), MkList());
761 compound.compound.context = context;
765 // Class class / DataMember member
766 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
768 // DataMember dataMember
769 ListAdd(args, MkExpIdentifier(MkIdentifier(memberName)));
771 RegisterMembersAndProperties((Class)member, true, memberName, compound);
774 stmt = MkExpressionStmt(MkListOne(
775 MkExpCall(MkExpIdentifier(MkIdentifier("eMember_AddMember")), args)));
777 stmt = MkExpressionStmt(MkListOne(
778 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMember")), args)));
780 ListAdd(compound.compound.statements, stmt);
784 ListAdd(statement.compound.statements, compound);
788 lastOffset = member.offset + member.memberOffset;
792 privateMembers = true;
797 ClassProperty classProperty;
799 // Watchable properties
800 for(prop = regClass.membersAndProperties.first; prop; prop = prop.next)
802 if(prop.isProperty && prop.isWatchable)
805 char name[1024], nameM[1024];
807 strcpy(name, "__ecereProp_");
808 FullClassNameCat(name, regClass.fullName, true);
810 FullClassNameCat(name, prop.name, false);
811 // strcat(name, prop.name);
812 //MangleClassName(name);
814 strcpy(nameM, "__ecerePropM_");
815 FullClassNameCat(nameM, regClass.fullName, true);
817 FullClassNameCat(nameM, prop.name, false);
818 // strcat(nameM, prop.name);
819 //MangleClassName(nameM);
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 //MangleClassName(name);
856 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
859 ListAdd(args, MkExpConstant("0"));
861 if(classProperty.Get)
863 strcpy(name, "__ecereClassProp_");
864 FullClassNameCat(name, regClass.fullName, true);
865 strcat(name, "_Get_");
866 strcat(name, classProperty.name);
867 //MangleClassName(name);
869 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
872 ListAdd(args, MkExpConstant("0"));
874 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddClassProperty")), args)));
875 ListAdd(registerModuleBody.compound.statements, stmt);
880 extern External curExternal;
882 void GetNameSpaceString(NameSpace ns, char * string)
885 GetNameSpaceString(ns.parent, string);
888 strcat(string, ns.name);
889 strcat(string, "::");
893 // *******************************************************************
894 static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol, OldList baseSpecs, OldList enumValues, OldList defs, External external, AccessMode declMode)
897 Class regClass = symbol.registered;
901 classType = regClass.type;
902 if(classType == enumClass && enumValues && (inCompiler || !buildingECERECOMModule))
905 for(e = enumValues.first; e; e = e.next)
914 e.exp.destType = destType;
916 // Set parsingType to avoid producing errors
918 ProcessExpressionType(e.exp);
923 destType.kind = TypeKind::classType;
924 destType._class = symbol;
925 ProcessExpressionType(e.exp);
927 if(e.exp.type == identifierExp && e.exp.expType && e.exp.identifier && e.exp.identifier.string && e.exp.expType.kind == enumType)
929 // Resolve enums here
931 char * string = e.exp.identifier.string;
932 for(l = e.exp.expType.members.first; l; l = l.next)
934 if(!strcmp(l.name, string))
938 FreeExpContents(e.exp);
939 e.exp.type = constantExp;
940 e.exp.constant = PrintUInt((uint)l.data);
941 FreeType(e.exp.expType);
942 e.exp.expType = ProcessTypeString("uint", false);
949 ComputeExpression(e.exp);
950 if(e.exp.isConstant && /*e.exp.expType.kind == intType*/ e.exp.type == constantExp)
952 Operand op = GetOperand(e.exp);
954 // TODO: 64 BIT ENUM SUPPORT...
957 case charType: value = op.c; break;
958 case shortType: value = op.s; break;
959 default: value = op.i;
962 // value = op.i; //strtol(e.exp.string, null, 0);
963 eEnum_AddFixedValue(regClass, e.id.string, value);
967 eEnum_AddValue(regClass, e.id.string);
970 eEnum_AddValue(regClass, e.id.string);
972 // Fix up derivatives enums largest
974 EnumClassData baseData = regClass.data;
976 for(deriv = regClass.derivatives.first; deriv; deriv = deriv.next)
978 Class c = deriv.data;
979 if(c && c.type == enumClass)
981 EnumClassData data = c.data;
982 data.largest = baseData.largest;
988 // Process all functions
989 if(definitions != null)
993 for(def = definitions.first; def; def = def.next)
995 if(def.type == propertyWatchClassDef && def.propertyWatch)
997 PropertyWatch propWatch = def.propertyWatch;
999 char watcherName[1024];
1001 Statement stmt = MkExpressionStmt(MkList());
1004 sprintf(watcherName,"__ecerePropertySelfWatcher_%d", propWatcherID++);
1005 for(propID = propWatch.properties->first; propID; propID = propID.next)
1007 strcat(watcherName, "_");
1008 strcat(watcherName, propID.string);
1011 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
1012 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)), MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null)));
1013 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, decl, null);
1014 ProcessClassFunctionBody(func, propWatch.compound);
1016 // TESTING WITH SAME SYMBOL ID AS CLASS
1017 decl.symbol = Symbol
1020 idCode = symbol.idCode;
1022 excludedSymbols->Add(decl.symbol);
1024 func.id = symbol.id;
1025 func.idCode = symbol.idCode;
1026 func.dontMangle = true;
1028 // Create a declaration above for constructor to see
1030 External externalDecl = MkExternalDeclaration(null);
1032 OldList * specifiers = MkList();
1033 ListAdd(specifiers, MkSpecifier(STATIC));
1034 ListAdd(specifiers, MkSpecifier(VOID));
1036 ast->Insert(curExternal.prev, externalDecl);
1038 decl = MkDeclaration(specifiers,
1039 MkListOne(MkInitDeclarator(MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
1040 MkListOne(MkTypeName(MkListOne(MkSpecifierName(regClass.fullName)), null))), null)));
1041 externalDecl.declaration = decl;
1042 if(decl.symbol && !decl.symbol.methodExternal)
1044 decl.symbol.methodExternal = externalDecl;
1046 // PATCHED THIS, 2 SYMBOLS WERE THERE.. THIS ONE HAD AN ID TOO BIG
1047 decl.symbol.id = symbol.id;
1048 decl.symbol.idCode = symbol.idCode;
1052 propWatch.compound = null;
1053 definitions.Insert(null, MkClassDefFunction(func));
1055 for(propID = propWatch.properties->first; propID; propID = propID.next)
1057 Property prop = eClass_FindProperty(regClass, propID.string, privateModule);
1060 // eProperty_SelfWatch(_class, name, callback);
1061 OldList * args = MkList();
1062 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1064 char * s = QMkString(propID.string);
1065 ListAdd(args, MkExpString(s));
1068 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
1070 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
1073 Compiler_Error($"Property %s not found in class %s\n", propID.string, regClass.fullName);
1075 FreePropertyWatch(def.propertyWatch);
1076 def.propertyWatch = (PropertyWatch)stmt; // Store this here to use it after CreateRegisterModuleBody is done
1078 // ListAdd(statements, stmt);
1083 for(def = definitions.first; def; def = def.next)
1085 if(def.type == functionClassDef)
1087 ProcessClassFunction(regClass, def.function, defs, external.prev, declMode == staticAccess);
1092 // Make the RegisterClass section
1094 if(inCompiler && symbol.id != MAXINT && regClass)
1097 OldList * args = MkList();
1100 const char * registerFunction = null;
1101 AccessMode inheritanceAccess = publicAccess;
1103 CreateRegisterModuleBody();
1105 curExternal = registerModuleExternal;
1108 switch(regClass.type)
1110 case structClass: ListAdd(args, MkExpIdentifier(MkIdentifier("structClass"))); break;
1111 case bitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("bitClass"))); break;
1112 case enumClass: ListAdd(args, MkExpIdentifier(MkIdentifier("enumClass"))); break;
1113 case noHeadClass: ListAdd(args, MkExpIdentifier(MkIdentifier("noHeadClass"))); break;
1114 case unitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("unitClass"))); break;
1115 case normalClass: ListAdd(args, MkExpIdentifier(MkIdentifier("normalClass"))); break;
1119 char nameSpace[1024] = "";
1120 char className[1024] = "";
1122 GetNameSpaceString(regClass.nameSpace, nameSpace);
1124 if(declMode == staticAccess)
1126 GetLastDirectory(sourceFile, className);
1127 ChangeCh(className, '.', '_');
1128 strcat(className, "}");
1130 strcat(className, nameSpace);
1131 strcat(className, regClass.name);
1132 string = QMkString(className);
1133 ListAdd(args, MkExpString(string));
1139 char * string = QMkString(regClass.base.name);
1140 ListAdd(args, regClass.base ? MkExpString(string) :
1141 MkExpConstant("0"));
1146 if(baseSpecs != null)
1148 Type baseType = ProcessType(baseSpecs, null);
1149 if(baseType.kind != structType && baseType.kind != unionType)
1151 char baseName[1024] = "";
1153 if(baseType.kind == TypeKind::classType && baseType._class && baseType._class.isStatic)
1155 // TODO: Handle static classes and complex declarators...
1156 GetLastDirectory(sourceFile, baseName);
1157 ChangeCh(baseName, '.', '_');
1158 strcat(baseName, "}");
1159 strcat(baseName, baseType._class.string);
1162 PrintType(baseType, baseName, false, true);
1164 string = QMkString(baseName);
1165 ListAdd(args, MkExpString(string));
1169 ListAdd(args, MkExpConstant("0"));
1171 if(((Specifier)baseSpecs.first).type == baseSpecifier && ((Specifier)baseSpecs.first).specifier == PRIVATE)
1172 inheritanceAccess = privateAccess;
1175 ListAdd(args, MkExpConstant("0"));
1177 //ListAdd(args, class.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1178 //MkSpecifierName(class.structName)), null)) : MkExpConstant("0"));
1180 if(regClass.type == structClass || regClass.type == normalClass || regClass.type == noHeadClass)
1182 // Check if we have a data member in this class
1183 DataMember member = null;
1186 for(base = regClass.base; base && base.type != systemClass; base = base.next)
1188 for(member = base.membersAndProperties.first; member; member = member.next)
1189 if(!member.isProperty)
1196 if(regClass.type == structClass && symbol.declaredStruct && member)
1198 char baseStructName[1024];
1199 baseStructName[0] = 0;
1200 // TESTING THIS HERE
1201 // FullClassNameCat(baseStructName, regClass.base.fullName, false);
1202 strcpy(baseStructName, (regClass.base.templateClass ? regClass.base.templateClass : regClass.base).fullName);
1204 ListAdd(args, MkExpOp(
1205 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)), '-',
1206 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(baseStructName), null)), null))));
1209 ListAdd(args, symbol.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1210 MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)) : MkExpConstant("0"));
1214 ListAdd(args, MkExpConstant("0"));
1217 //if(regClass.type == normalClass)
1219 char classDataStructName[1024];
1220 strcpy(classDataStructName, "__ecereClassData_");
1221 FullClassNameCat(classDataStructName, symbol.string, false);
1223 ListAdd(args, symbol.classData ? MkExpTypeSize(MkTypeName(MkListOne(
1224 MkStructOrUnion(structSpecifier, MkIdentifier(classDataStructName), null)), null)) : MkExpConstant("0"));
1227 // TODO: Support Class Data for all other types of classes
1228 ListAdd(args, MkExpConstant("0"));
1231 if(regClass.type == normalClass || regClass.type == noHeadClass)
1234 ListAdd(args, symbol.needConstructor ?
1235 MkExpIdentifier(MkIdentifier(symbol.constructorName)) :
1236 MkExpConstant("0"));
1238 ListAdd(args, symbol.needDestructor ?
1239 MkExpIdentifier(MkIdentifier(symbol.destructorName)) :
1240 MkExpConstant("0"));
1244 // TODO: Support Constructors / Destructors for structs
1247 ListAdd(args, MkExpConstant("0"));
1249 ListAdd(args, MkExpConstant("0"));
1253 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1259 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1262 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1266 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1271 switch(inheritanceAccess)
1274 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1278 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1282 registerFunction = "eSystem_RegisterClass";
1284 stmt = MkExpressionStmt(MkListOne(
1285 MkExpOp(MkExpIdentifier(MkIdentifier("class")), '=',
1286 MkExpCall((exp = MkExpIdentifier(MkIdentifier(registerFunction))), args))));
1288 ListAdd(registerModuleBody.compound.statements, stmt);
1291 stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className)))),
1292 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1293 MkExpIdentifier(MkIdentifier("class"))))), null);
1296 stmt = MkIfStmt(MkListOne(
1298 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
1299 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application"))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1300 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1301 MkExpIdentifier(MkIdentifier("class"))))), null);
1303 stmt = MkIfStmt(MkListOne(
1304 MkExpOp(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1305 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1306 MkExpIdentifier(MkIdentifier("class"))))), null);
1309 ListAdd(registerModuleBody.compound.statements, stmt);
1311 if(external && external.type == classExternal && external._class.deleteWatchable)
1313 args = MkListOne(MkExpIdentifier(MkIdentifier("class")));
1314 stmt = MkExpressionStmt(MkListOne(
1315 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DestructionWatchable")), args)));
1316 ListAdd(registerModuleBody.compound.statements, stmt);
1319 // Add Virtual Methods
1322 Class base = regClass.base;
1324 for(c = 0; c<base.vTblSize; c++)
1326 Symbol method = (Symbol)regClass._vTbl[c];
1327 if((void *) method != DummyMethod && base._vTbl[c] != (void *)method && method.methodExternal) // TOLOOKAT: Module check here?
1329 External external = method.methodExternal;
1330 OldList * args = MkList();
1331 Identifier id = external.function ? GetDeclId(external.function.declarator) : null;
1334 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1337 //char * string = QMkString(method.string);
1339 char * string = QMkString(method.method.name);
1340 ListAdd(args, MkExpString(string));
1344 ListAdd(args, MkExpConstant("0"));
1346 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1350 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1352 exp.expType = Type { refCount = 1 };
1353 stmt = MkExpressionStmt(MkListOne(
1354 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1355 ListAdd(registerModuleBody.compound.statements, stmt);
1360 // Add Virtual Methods in order
1363 for(c = regClass.base ? regClass.base.vTblSize : 0; c < regClass.vTblSize; c++)
1365 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1367 if(method.type == virtualMethod && method._class == regClass && method.vid == c)
1372 //External external = method->symbol ? ((Symbol)method.symbol).methodExternal : null;
1373 External external = method.symbol ? ((Symbol)method.symbol).methodCodeExternal : null;
1374 OldList * args = MkList();
1375 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1378 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1381 char * string = QMkString(method.name);
1382 ListAdd(args, MkExpString(string));
1387 char * string = QMkString(method.dataTypeString);
1388 ListAdd(args, MkExpString(string));
1392 if(id && external.function.body)
1394 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(id.string))));
1395 exp.expType = Type { refCount = 1 };
1399 ListAdd(args, (exp = MkExpConstant("0")));
1403 switch(method.memberAccess)
1406 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1409 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1413 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1417 //sprintf(name, "__ecereVMethodID_%s_%s", method._class.fullName, method.name);
1418 strcpy(name, "__ecereVMethodID_");
1419 FullClassNameCat(name, method._class.fullName, false);
1421 strcat(name, method.name);
1423 exp = /*MkExpPointer(*/MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddVirtualMethod")), args)/*, MkIdentifier("vid"))*/;
1425 exp->expType = eSystem_New(sizeof(Type));
1426 exp->expType->refCount++;
1427 exp->expType->isSigned = true;
1428 exp->expType->kind = TypeInt;
1431 stmt = MkExpressionStmt(MkListOne(/*
1432 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', */exp/*)*/));
1434 DeclareMethod(method, name);
1436 ListAdd(registerModuleBody.compound.statements, stmt);
1443 // Add Public Methods (all for now)
1444 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1446 if(method.type == virtualMethod && method._class == regClass);
1447 else if(method.memberAccess == publicAccess || !method.dataTypeString)
1449 //External external = method.symbol ? ((Symbol )method.symbol).methodExternal : null;
1450 External external = method.symbol ? ((Symbol )method.symbol).methodCodeExternal : null;
1451 OldList * args = MkList();
1452 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1455 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1458 char * string = QMkString(method.name);
1459 ListAdd(args, MkExpString(string));
1464 char * string = QMkString(method.dataTypeString);
1465 ListAdd(args, MkExpString(string));
1469 if(id && external.function.body)
1471 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1473 exp.expType = Type { refCount = 1 };
1477 ListAdd(args, (exp = MkExpConstant("0")));
1481 switch(method.memberAccess)
1484 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1487 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1491 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1495 stmt = MkExpressionStmt(MkListOne(
1496 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1497 ListAdd(registerModuleBody.compound.statements, stmt);
1501 RegisterMembersAndProperties(regClass, false, "class", registerModuleBody);
1503 // Add Enumeration Values
1504 if(classType == enumClass)
1507 Class enumClass = eSystem_FindClass(privateModule, "enum");
1508 EnumClassData e = ACCESS_CLASSDATA(regClass, enumClass);
1510 for(value = e.values.first; value; value = value.next)
1512 OldList * args = MkList();
1515 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1518 char * string = QMkString(value.name);
1519 ListAdd(args, MkExpString(string));
1525 // TODO: Support 64 bit enums
1526 sprintf(temp, "%d", (int)value.data);
1527 ListAdd(args, MkExpConstant(temp));
1530 stmt = MkExpressionStmt(MkListOne(
1531 MkExpCall(MkExpIdentifier(MkIdentifier("eEnum_AddFixedValue")), args)));
1532 ListAdd(registerModuleBody.compound.statements, stmt);
1536 // Add Template Parameters
1537 if(symbol.templateParams)
1539 TemplateParameter param;
1540 for(param = symbol.templateParams->first; param; param = param.next)
1542 OldList * args = MkList();
1545 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1549 char * string = QMkString(param.identifier.string);
1550 ListAdd(args, MkExpString(string));
1555 ListAdd(args, MkExpIdentifier(MkIdentifier((param.type == type) ? "type" : ((param.type == identifier) ? "identifier" : "expression"))));
1563 char * typeString = param.dataType ? StringFromSpecDecl(param.dataType.specifiers, param.dataType.decl) : null;
1564 char * string = QMkString(typeString);
1565 ListAdd(args, MkExpString(string));
1572 char memberTypeString[132] = "TemplateMemberType::";
1573 bool needClass = true;
1575 param.memberType.OnGetString(memberTypeString + strlen(memberTypeString), null, &needClass);
1577 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)),
1578 MkExpIdentifier(MkIdentifier(memberTypeString))));
1584 if(param.defaultArgument)
1586 OldList * members = MkList();
1591 char * typeString = param.defaultArgument.templateDatatype ?
1592 StringFromSpecDecl(param.defaultArgument.templateDatatype.specifiers, param.defaultArgument.templateDatatype.decl) : null;
1593 char * string = QMkString(typeString);
1595 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1603 char memberString[1024];
1605 memberString[0] = '\0';
1607 if(param.defaultArgument.identifier._class)
1609 if(param.defaultArgument.identifier._class.type == templateTypeSpecifier)
1610 strcpy(memberString, param.defaultArgument.identifier._class.templateParameter.identifier.string);
1611 else if(param.defaultArgument.identifier._class.name)
1612 strcpy(memberString, param.defaultArgument.identifier._class.name);
1615 strcat(memberString, "::");
1617 strcat(memberString, param.defaultArgument.identifier.string);
1619 string = QMkString(memberString);
1621 // TOFIX: UNIONS ARE BROKEN FOR ASSIGNMENTS, USING dataTypeString INSTEAD
1622 // members->Add(MkMemberInit(MkListOne(MkIdentifier("memberString")), MkInitializerAssignment(MkExpString(string))));
1623 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1631 OldList * ids = MkList();
1633 char * string = null;
1635 //ProcessExpressionType(param.defaultArgument.expression);
1636 //ComputeExpression(param.defaultArgument.expression);
1638 op = GetOperand(param.defaultArgument.expression);
1639 ui64String = PrintUInt64(op.ui64);
1640 ids->Add(MkIdentifier("expression"));
1641 ids->Add(MkIdentifier("ui64"));
1643 //string = QMkString(ui64String);
1644 members->Add(MkMemberInit(ids, MkInitializerAssignment(MkExpConstant(ui64String))));
1651 ListAdd(args, MkExpInstance(MkInstantiation(MkSpecifierName("ClassTemplateArgument"), null,
1652 MkListOne(MkMembersInitList(members)))));
1655 ListAdd(args, MkExpIdentifier(MkIdentifier("null")));
1657 stmt = MkExpressionStmt(MkListOne(
1658 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddTemplateParameter")), args)));
1659 ListAdd(registerModuleBody.compound.statements, stmt);
1661 stmt = MkExpressionStmt(MkListOne(
1662 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DoneAddingTemplateParameters")),
1663 MkListOne(MkExpIdentifier(MkIdentifier("class"))))));
1664 ListAdd(registerModuleBody.compound.statements, stmt);
1667 if(definitions != null)
1669 for(def = definitions.first; def; def = def.next)
1671 if(def.type == propertyWatchClassDef && def.propertyWatch)
1673 ListAdd(registerModuleBody.compound.statements, (Statement)def.propertyWatch);
1674 def.propertyWatch = null;
1676 else if(def.type == classDesignerClassDef)
1679 char className[1024];
1680 sprintf(className, "__ecereClass_%s", def.designer);
1681 MangleClassName(className);
1683 DeclareClass(FindClass(def.designer), className);
1687 char * s = QMkString(def.designer);
1688 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1689 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
1690 MkExpString(s)))), null);
1693 ListAdd(registerModuleBody.compound.statements, stmt);
1695 else if(def.type == classNoExpansionClassDef)
1697 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1698 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("noExpansion")), '=',
1699 MkExpConstant("1")))), null);
1700 ListAdd(registerModuleBody.compound.statements, stmt);
1702 else if(def.type == classFixedClassDef)
1704 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1705 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("fixed")), '=',
1706 MkExpConstant("1")))), null);
1707 ListAdd(registerModuleBody.compound.statements, stmt);
1709 regClass.fixed = true;
1711 else if(def.type == designerDefaultPropertyClassDef)
1713 char * s = QMkString(def.defaultProperty.string);
1714 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1715 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=',
1716 MkExpString(s)))), null);
1717 ListAdd(registerModuleBody.compound.statements, stmt);
1720 else if(def.type == classPropertyValueClassDef)
1722 classPropValues.Add(ClassPropertyValue { regClass = regClass, id = def.id, exp = def.initializer.exp });
1724 def.initializer.exp = null;
1732 class ClassPropertyValue
1738 ~ClassPropertyValue()
1744 static List<ClassPropertyValue> classPropValues { };
1746 public void ProcessClassDefinitions()
1748 External external, next;
1750 CreateRegisterModuleBody();
1753 // (Need to do those things after in case something is not yet defined)
1754 for(external = ast->first; external; external = next)
1756 next = external.next;
1757 curExternal = external;
1758 if(external.type == classExternal)
1760 ClassDefinition _class = external._class;
1761 if(_class.definitions)
1763 ProcessClass(normalClass, _class.definitions, _class.symbol, _class.baseSpecs, null, ast, external, _class.declMode);
1767 ast->Remove(external);
1768 FreeExternal(external);
1771 else if(external.type == functionExternal)
1773 bool setStaticMethod = false;
1775 if(external.symbol && !external.symbol.type.thisClass && !external.symbol.type.staticMethod)
1777 // TOCHECK: Where do we actually need this to be set?
1778 external.symbol.type.staticMethod = true;
1779 setStaticMethod = true;
1784 FunctionDefinition function = external.function;
1788 if(!strcmp(function.declarator.symbol.string, "__on_register_module"))
1790 ListAdd(registerModuleBody.compound.statements, function.body);
1791 function.body.compound.context.parent = registerModuleBody.compound.context;
1792 ast->Remove(external);
1793 function.body = null;
1794 FreeExternal(external);
1798 if(function.declMode != privateAccess && function.declMode != publicAccess) continue;
1802 CreateRegisterModuleBody();
1806 char * string = QMkString(function.declarator.symbol.string);
1807 ListAdd(args, MkExpString(string));
1814 char type[1024] = "";
1815 // We don't want functions to be marked as static methods
1817 function.declarator.symbol.type.staticMethod = false;
1818 PrintType(function.declarator.symbol.type, type, true, true);
1820 function.declarator.symbol.type.staticMethod = true;
1821 string = QMkString(type);
1822 ListAdd(args, MkExpString(string));
1828 ListAdd(args, MkExpIdentifier(MkIdentifier(function.declarator.symbol.string)));
1832 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1835 switch(function.declMode)
1838 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1841 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1845 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1849 stmt = MkExpressionStmt(MkListOne(
1850 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterFunction"))), args)));
1852 ListAdd(registerModuleBody.compound.statements, stmt);
1855 else if(external.type == declarationExternal)
1857 Declaration declaration = external.declaration;
1861 if(external.symbol.type && external.symbol.type.kind == functionType && !external.symbol.type.thisClass)
1862 external.symbol.type.staticMethod = true;
1865 if(external.symbol && declaration.type == initDeclaration)
1867 if(declaration.specifiers)
1869 Specifier specifier;
1870 bool removeExternal = false;
1872 for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
1874 if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
1875 (declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
1877 Symbol symbol = FindClass(specifier.id.string);
1880 ClassType classType;
1881 if(specifier.type == enumSpecifier)
1882 classType = enumClass;
1884 classType = structClass;
1886 removeExternal = true;
1887 // Transfer Context over to Symbol
1888 symbol.ctx = specifier.ctx;
1889 specifier.ctx = null;
1891 ProcessClass(classType, specifier.definitions, symbol, specifier.baseSpecs, specifier.list,ast, external, declaration.declMode);
1895 if(inCompiler && removeExternal)
1897 ast->Remove(external);
1898 FreeExternal(external);
1902 else if(declaration.type == defineDeclaration)
1904 if(inCompiler && declaration.declMode != staticAccess)
1907 OldList * args = MkList();
1909 CreateRegisterModuleBody();
1913 char * string = QMkString(declaration.id.string);
1914 ListAdd(args, MkExpString(string));
1921 char type[1024] = "";
1922 PrintExpression(declaration.exp, type);
1923 string = QMkString(type);
1924 ListAdd(args, MkExpString(string));
1929 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1932 switch(declaration.declMode)
1935 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1938 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1942 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1946 stmt = MkExpressionStmt(MkListOne(
1947 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterDefine"))), args)));
1949 ListAdd(registerModuleBody.compound.statements, stmt);
1955 // Set the class properties at the very end
1956 for(v : classPropValues)
1958 OldList * findClassArgs = MkList();
1959 OldList * args = MkList();
1960 Statement compoundStmt;
1966 ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
1967 s = QMkString(v.regClass.name);
1968 ListAdd(findClassArgs, MkExpString(s));
1971 ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
1972 s = QMkString(v.id.string);
1973 ListAdd(args, MkExpString(s));
1975 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), v.exp));
1976 compoundStmt = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
1977 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("_class")),
1978 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eSystem_FindClass")), findClassArgs)))))),
1979 MkListOne(MkExpressionStmt(MkListOne(
1980 MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eClass_SetProperty")), args)))));
1981 compoundStmt.compound.context = Context { parent = registerModuleBody.compound.context };
1982 ListAdd(registerModuleBody.compound.statements, compoundStmt);
1985 classPropValues.Free();