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)
25 Identifier id = GetDeclId(func.declarator);
28 External external = null;
30 if(defs && func.declarator)
32 FunctionDefinition function = null;
34 int symid = func.declarator.symbol.id;
35 int symidCode = func.declarator.symbol.idCode;
40 func.specifiers = MkList();
41 // Add static to the specifiers
43 func.specifiers->Insert(null, MkSpecifier(STATIC));
46 propSymbol = func.declarator.symbol;
48 ReplaceThisClassSpecifiers(func.specifiers, owningClass);
50 if(propSymbol.externalGet == (External)func)
51 func.declarator.symbol = null;
52 else if(propSymbol.externalSet == (External)func)
54 func.declarator.symbol = null;
57 else if(propSymbol.externalIsSet == (External)func)
59 func.declarator.symbol = null;
60 symid += 2; // TOFIX: What should we do with this? Where are 2 IDs allocated for properties? In MkProperty...
65 /*FunctionDefinition*/ function = _MkFunction(func.specifiers, func.declarator, null, false);
66 function.propSet = func.propSet;
67 function.type = func.type;
68 if(func.type) func.type.refCount++;
69 ProcessFunctionBody(function, func.body);
70 external = MkExternalFunction(function);
72 external.symbol = func.declarator.symbol;
73 external.function._class = func._class;
76 symbol = func.declarator.symbol;
77 //symbol.id = func.id; //symid;
79 symbol.idCode = symidCode;
84 Method method = func.declarator.symbol.method;
85 func.declarator.symbol.methodExternal = external;
87 // DANGER: Added this one...
89 if(method && method.symbol)
90 //((Symbol)method.symbol).methodExternal = external;
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))
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 };
276 ListAdd(registerModuleBody.compound.declarations,
277 MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null) /*MkSpecifierName("ecere::com::Class")*/ /*MkStructOrUnion(SpecifierStruct, MkIdentifier("Class"), null)*/),
278 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class"))), null))));
280 ListAdd(registerModuleBody.compound.declarations,
281 MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
282 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("class")), null))));
284 specifiers = MkList();
285 ListAdd(specifiers, MkSpecifier(VOID));
287 moduleParam = MkTypeName(MkListOne(/*MkSpecifier(VOID)*/MkSpecifierName("Module")),
288 //MkDeclaratorPointer(MkPointer(null, null),
289 MkDeclaratorIdentifier(MkIdentifier("module")));
291 GetLastDirectory(outputFile, moduleName);
292 //strcpy(moduleName, argv[2]);
293 StripExtension(moduleName);
294 FixModuleName(moduleName);
295 sprintf(registerName, "__ecereRegisterModule_%s", moduleName);
297 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
298 MkListOne(moduleParam));
301 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
302 ProcessFunctionBody(function, registerModuleBody);
303 function.declMode = defaultAccess;
304 if(!ast) ast = MkList();
305 ListAdd(ast, (registerModuleExternal = MkExternalFunction(function)));
310 if(!unregisterModuleBody && inCompiler)
312 char registerName[1024], moduleName[MAX_FILENAME];
313 OldList * specifiers;
314 Declarator declarator;
315 TypeName moduleParam;
317 unregisterModuleBody = MkCompoundStmt(MkList(), MkList());
318 unregisterModuleBody.compound.context = Context { parent = globalContext };
320 specifiers = MkList();
321 ListAdd(specifiers, MkSpecifier(VOID));
323 moduleParam = MkTypeName(MkListOne(/*MkSpecifier(VOID)*/ MkSpecifierName("Module")),
324 //MkDeclaratorPointer(MkPointer(null, null),
325 MkDeclaratorIdentifier(MkIdentifier("module")));
327 GetLastDirectory(outputFile, moduleName);
328 StripExtension(moduleName);
329 FixModuleName(moduleName);
330 //strcpy(moduleName, argv[2]);
331 sprintf(registerName, "__ecereUnregisterModule_%s", moduleName);
333 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
334 MkListOne(moduleParam));
337 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
338 ProcessFunctionBody(function, unregisterModuleBody);
339 function.declMode = defaultAccess;
340 if(!ast) ast = MkList();
341 ListAdd(ast, (unregisterModuleExternal = MkExternalFunction(function)));
346 void RegisterMembersAndProperties(Class regClass, bool isMember, char * className, Statement statement)
348 DataMember dataMember = isMember ? (DataMember)regClass : null;
353 char dataMemberSize[16];
357 bool privateMembers = false;
359 sprintf(dataMemberSize, "%d", (int)sizeof(DataMember));
362 for(prop = regClass.conversions.first; prop; prop = prop.next)
364 OldList * args = MkList();
368 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
370 ListAdd(args, MkExpConstant("0"));
374 char * string = QMkString(prop.dataTypeString);
375 ListAdd(args, MkExpString(string));
381 strcpy(name, "__ecereProp_");
382 FullClassNameCat(name, regClass.fullName, false);
383 strcat(name, "_Set_");
384 // strcat(name, prop.name);
385 FullClassNameCat(name, prop.name, true);
386 MangleClassName(name);
387 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
390 ListAdd(args, MkExpConstant("0"));
394 strcpy(name, "__ecereProp_");
395 FullClassNameCat(name, regClass.fullName, false);
396 strcat(name, "_Get_");
397 // strcat(name, prop.name);
398 FullClassNameCat(name, prop.name, true);
399 MangleClassName(name);
401 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
404 ListAdd(args, MkExpConstant("0"));
408 switch(prop.memberAccess)
411 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
414 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
418 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
422 strcpy(name, "__ecereProp_");
423 FullClassNameCat(name, regClass.fullName, false);
425 FullClassNameCat(name, prop.name, true);
426 // strcat(name, prop.name);
427 MangleClassName(name);
429 stmt = MkExpressionStmt(MkListOne(
430 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=',
431 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
432 ListAdd(registerModuleBody.compound.statements, stmt);
436 for(member = isMember ? dataMember.members.first : regClass.membersAndProperties.first; member; member = member.next)
438 if(member.isProperty)
440 prop = (Property) member;
442 OldList * args = MkList();
443 char name[1024], nameM[1024];
444 char * string = QMkString(prop.name);
447 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
450 ListAdd(args, MkExpString(string));
455 char * string = QMkString(prop.dataTypeString);
456 ListAdd(args, MkExpString(string));
462 strcpy(name, "__ecereProp_");
463 FullClassNameCat(name, regClass.fullName, false);
464 strcat(name, "_Set_");
465 FullClassNameCat(name, prop.name, true);
466 // strcat(name, prop.name);
467 MangleClassName(name);
468 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
471 ListAdd(args, MkExpConstant("0"));
475 strcpy(name, "__ecereProp_");
476 FullClassNameCat(name, regClass.fullName, false);
477 strcat(name, "_Get_");
478 FullClassNameCat(name, prop.name, true);
479 // strcat(name, prop.name);
480 MangleClassName(name);
481 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
484 ListAdd(args, MkExpConstant("0"));
487 switch(prop.memberAccess)
490 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
493 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
497 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
501 strcpy(name, "__ecereProp_");
502 FullClassNameCat(name, regClass.fullName, false);
504 FullClassNameCat(name, prop.name, true);
505 // strcat(name, prop.name);
506 MangleClassName(name);
508 strcpy(nameM, "__ecerePropM_");
509 FullClassNameCat(nameM, regClass.fullName, false);
511 FullClassNameCat(nameM, prop.name, true);
512 // strcat(nameM, prop.name);
513 MangleClassName(nameM);
515 if(prop.dataTypeString)
517 stmt = MkExpressionStmt(MkListOne(
518 MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
519 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
523 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args)));
525 ListAdd(registerModuleBody.compound.statements, stmt);
530 strcpy(name, "__ecereProp_");
531 FullClassNameCat(name, regClass.fullName, true);
532 strcat(name, "_IsSet_");
533 FullClassNameCat(name, prop.name, false);
534 // strcat(name, prop.name);
535 MangleClassName(name);
537 stmt = MkExpressionStmt(MkListOne(
538 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("IsSet")), '=',
539 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpIdentifier(MkIdentifier(name))))));
540 ListAdd(registerModuleBody.compound.statements, stmt);
542 if(prop.symbol && ((Symbol)prop.symbol).propCategory)
544 stmt = MkExpressionStmt(MkListOne(
545 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("category")), '=',
546 CopyExpression(((Symbol)prop.symbol).propCategory))));
547 ListAdd(registerModuleBody.compound.statements, stmt);
550 if(prop.dataTypeString)
552 OldList * list = MkList();
553 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', MkExpIdentifier(MkIdentifier(nameM))));
554 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=', MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0"))));
555 // stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(name)))), MkExpressionStmt(list), null);
556 stmt = MkIfStmt(MkListOne(MkExpOp(
557 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
558 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application")))), MkExpressionStmt(list), null);
560 ListAdd(registerModuleBody.compound.statements, stmt);
562 // Unregister 2nd property
563 stmt = MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
564 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0")))));
565 ListAdd(unregisterModuleBody.compound.statements, stmt);
569 else if(member.type == normalMember && !isMember && regClass.type == bitClass)
571 BitMember bitMember = (BitMember) member;
572 OldList * args = MkList();
575 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
579 char * string = QMkString(bitMember.name);
580 ListAdd(args, MkExpString(string));
585 char * string = QMkString(bitMember.dataTypeString);
586 ListAdd(args, MkExpString(string));
592 sprintf(string, "%d", bitMember.size);
593 ListAdd(args, (exp = MkExpConstant(string)));
598 sprintf(string, "%d", bitMember.pos);
599 ListAdd(args, (exp = MkExpConstant(string)));
603 switch(member.memberAccess)
606 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
609 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
613 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
617 stmt = MkExpressionStmt(MkListOne(
618 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddBitMember")), args)));
620 ListAdd(statement.compound.statements, stmt);
622 else if(member.memberAccess == publicAccess || (member.type == normalMember && !member.dataTypeString))
625 // ADD PRIVATE DATA PADDING HERE...
628 uint offset = member.offset - lastOffset;
633 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
638 sprintf(string, "\"__ecerePrivateData%d\"", privateID++);
639 ListAdd(args, MkExpString(string));
644 sprintf(string, "\"byte[%d]\"", offset);
645 ListAdd(args, MkExpString(string));
650 sprintf(string, "%d", offset);
651 ListAdd(args, (exp = MkExpConstant(string)));
655 ListAdd(args, (exp = MkExpConstant("1")));
658 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
660 stmt = MkExpressionStmt(MkListOne(
661 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
663 ListAdd(statement.compound.statements, stmt);
664 privateMembers = false;
667 if(member.type == normalMember)
670 member.dataType = ProcessTypeString(member.dataTypeString, false);
672 ComputeTypeSize(member.dataType);
677 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
681 char * string = QMkString(member.name);
682 ListAdd(args, MkExpString(string));
687 char * string = QMkString(member.dataTypeString);
688 ListAdd(args, MkExpString(string));
694 sprintf(string, "%d", member.dataType.size);
695 ListAdd(args, (exp = MkExpConstant(string)));
701 sprintf(string, "%d", member.dataType.alignment);
702 ListAdd(args, (exp = MkExpConstant(string)));
706 switch(member.memberAccess)
709 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
712 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
716 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
720 stmt = MkExpressionStmt(MkListOne(
721 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
723 ListAdd(statement.compound.statements, stmt);
725 lastOffset = member.offset + member.dataType.size;
729 static int memberCount = 0;
733 char memberName[256];
734 sprintf(memberName, "dataMember%d", memberCount);
737 curContext = statement.compound.context;
738 context = PushContext();
740 args = MkListOne(MkExpIdentifier(MkIdentifier((member.type == unionMember) ? "unionMember" : "structMember")));
743 switch(member.memberAccess)
746 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
749 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
753 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
757 compound = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("DataMember")),
758 MkListOne(MkInitDeclarator(/*MkDeclaratorPointer(MkPointer(null, null), */MkDeclaratorIdentifier(MkIdentifier(memberName))/*)*/,
759 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("eMember_New")), args)))))), MkList());
760 compound.compound.context = context;
764 // Class class / DataMember member
765 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
767 // DataMember dataMember
768 ListAdd(args, MkExpIdentifier(MkIdentifier(memberName)));
770 RegisterMembersAndProperties((Class)member, true, memberName, compound);
773 stmt = MkExpressionStmt(MkListOne(
774 MkExpCall(MkExpIdentifier(MkIdentifier("eMember_AddMember")), args)));
776 stmt = MkExpressionStmt(MkListOne(
777 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMember")), args)));
779 ListAdd(compound.compound.statements, stmt);
783 ListAdd(statement.compound.statements, compound);
787 lastOffset = member.offset + member.memberOffset;
791 privateMembers = true;
796 ClassProperty classProperty;
798 // Watchable properties
799 for(prop = regClass.membersAndProperties.first; prop; prop = prop.next)
801 if(prop.isProperty && prop.isWatchable)
804 char name[1024], nameM[1024];
806 strcpy(name, "__ecereProp_");
807 FullClassNameCat(name, regClass.fullName, true);
809 FullClassNameCat(name, prop.name, false);
810 // strcat(name, prop.name);
811 MangleClassName(name);
813 strcpy(nameM, "__ecerePropM_");
814 FullClassNameCat(nameM, regClass.fullName, true);
816 FullClassNameCat(nameM, prop.name, false);
817 // strcat(nameM, prop.name);
818 MangleClassName(nameM);
820 args = MkListOne(MkExpCondition(MkExpIdentifier(MkIdentifier(nameM)), MkListOne(MkExpIdentifier(MkIdentifier(nameM))), MkExpIdentifier(MkIdentifier(name))));
821 stmt = MkExpressionStmt(MkListOne(
822 MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_Watchable")), args)));
823 ListAdd(registerModuleBody.compound.statements, stmt);
827 // Add Class Properties
828 for(classProperty = (ClassProperty)regClass.classProperties.first; classProperty; classProperty = (ClassProperty)((BTNode)classProperty).next)
830 OldList * args = MkList();
832 char * string = QMkString(classProperty.name);
835 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
838 ListAdd(args, MkExpString(string));
843 char * string = QMkString(classProperty.dataTypeString);
844 ListAdd(args, MkExpString(string));
848 if(classProperty.Set)
850 strcpy(name, "__ecereClassProp_");
851 FullClassNameCat(name, regClass.fullName, true);
852 strcat(name, "_Set_");
853 strcat(name, classProperty.name);
854 MangleClassName(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);
866 MangleClassName(name);
868 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
871 ListAdd(args, MkExpConstant("0"));
873 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddClassProperty")), args)));
874 ListAdd(registerModuleBody.compound.statements, stmt);
879 extern External curExternal;
881 void GetNameSpaceString(NameSpace ns, char * string)
884 GetNameSpaceString(ns.parent, string);
887 strcat(string, ns.name);
888 strcat(string, "::");
892 // *******************************************************************
893 static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol, OldList baseSpecs, OldList enumValues, OldList defs, External external, AccessMode declMode)
896 Class regClass = symbol.registered;
900 classType = regClass.type;
901 if(classType == enumClass && enumValues && (inCompiler || !buildingECERECOMModule))
904 for(e = enumValues.first; e; e = e.next)
913 e.exp.destType = destType;
915 // Set parsingType to avoid producing errors
917 ProcessExpressionType(e.exp);
922 destType.kind = TypeKind::classType;
923 destType._class = symbol;
924 ProcessExpressionType(e.exp);
926 if(e.exp.type == identifierExp && e.exp.expType && e.exp.identifier && e.exp.identifier.string && e.exp.expType.kind == enumType)
928 // Resolve enums here
930 char * string = e.exp.identifier.string;
931 for(l = e.exp.expType.members.first; l; l = l.next)
933 if(!strcmp(l.name, string))
937 FreeExpContents(e.exp);
938 e.exp.type = constantExp;
939 e.exp.constant = PrintUInt((uint)l.data);
940 FreeType(e.exp.expType);
941 e.exp.expType = ProcessTypeString("uint", false);
948 ComputeExpression(e.exp);
949 if(e.exp.isConstant && /*e.exp.expType.kind == intType*/ e.exp.type == constantExp)
951 Operand op = GetOperand(e.exp);
953 // TODO: 64 BIT ENUM SUPPORT...
956 case charType: value = op.c; break;
957 case shortType: value = op.s; break;
958 default: value = op.i;
961 // value = op.i; //strtol(e.exp.string, null, 0);
962 eEnum_AddFixedValue(regClass, e.id.string, value);
966 eEnum_AddValue(regClass, e.id.string);
969 eEnum_AddValue(regClass, e.id.string);
971 // Fix up derivatives enums largest
973 EnumClassData baseData = regClass.data;
975 for(deriv = regClass.derivatives.first; deriv; deriv = deriv.next)
977 Class c = deriv.data;
978 if(c && c.type == enumClass)
980 EnumClassData data = c.data;
981 data.largest = baseData.largest;
987 // Process all functions
988 if(definitions != null)
992 for(def = definitions.first; def; def = def.next)
994 if(def.type == propertyWatchClassDef && def.propertyWatch)
996 PropertyWatch propWatch = def.propertyWatch;
998 char watcherName[1024];
1000 Statement stmt = MkExpressionStmt(MkList());
1003 sprintf(watcherName,"__ecerePropertySelfWatcher_%d", propWatcherID++);
1004 for(propID = propWatch.properties->first; propID; propID = propID.next)
1006 strcat(watcherName, "_");
1007 strcat(watcherName, propID.string);
1010 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
1011 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)), MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null)));
1012 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, decl, null);
1013 ProcessClassFunctionBody(func, propWatch.compound);
1015 // TESTING WITH SAME SYMBOL ID AS CLASS
1016 decl.symbol = Symbol
1019 idCode = symbol.idCode;
1021 excludedSymbols->Add(decl.symbol);
1023 func.id = symbol.id;
1024 func.idCode = symbol.idCode;
1025 func.dontMangle = true;
1027 // Create a declaration above for constructor to see
1029 External externalDecl = MkExternalDeclaration(null);
1031 OldList * specifiers = MkList();
1032 ListAdd(specifiers, MkSpecifier(STATIC));
1033 ListAdd(specifiers, MkSpecifier(VOID));
1035 ast->Insert(curExternal.prev, externalDecl);
1037 decl = MkDeclaration(specifiers,
1038 MkListOne(MkInitDeclarator(MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
1039 MkListOne(MkTypeName(MkListOne(MkSpecifierName(regClass.fullName)), null))), null)));
1040 externalDecl.declaration = decl;
1041 if(decl.symbol && !decl.symbol.methodExternal)
1043 decl.symbol.methodExternal = externalDecl;
1045 // PATCHED THIS, 2 SYMBOLS WERE THERE.. THIS ONE HAD AN ID TOO BIG
1046 decl.symbol.id = symbol.id;
1047 decl.symbol.idCode = symbol.idCode;
1051 propWatch.compound = null;
1052 definitions.Insert(null, MkClassDefFunction(func));
1054 for(propID = propWatch.properties->first; propID; propID = propID.next)
1056 Property prop = eClass_FindProperty(regClass, propID.string, privateModule);
1059 // eProperty_SelfWatch(_class, name, callback);
1060 OldList * args = MkList();
1061 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1063 char * s = QMkString(propID.string);
1064 ListAdd(args, MkExpString(s));
1067 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
1069 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
1072 Compiler_Error($"Property %s not found in class %s\n", propID.string, regClass.fullName);
1074 FreePropertyWatch(def.propertyWatch);
1075 def.propertyWatch = (PropertyWatch)stmt; // Store this here to use it after CreateRegisterModuleBody is done
1077 // ListAdd(statements, stmt);
1082 for(def = definitions.first; def; def = def.next)
1084 if(def.type == functionClassDef)
1086 ProcessClassFunction(regClass, def.function, defs, external.prev, declMode == staticAccess);
1091 // Make the RegisterClass section
1093 if(inCompiler && symbol.id != MAXINT && regClass)
1096 OldList * args = MkList();
1099 char * registerFunction = null;
1100 AccessMode inheritanceAccess = publicAccess;
1102 CreateRegisterModuleBody();
1104 curExternal = registerModuleExternal;
1107 switch(regClass.type)
1109 case structClass: ListAdd(args, MkExpIdentifier(MkIdentifier("structClass"))); break;
1110 case bitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("bitClass"))); break;
1111 case enumClass: ListAdd(args, MkExpIdentifier(MkIdentifier("enumClass"))); break;
1112 case noHeadClass: ListAdd(args, MkExpIdentifier(MkIdentifier("noHeadClass"))); break;
1113 case unitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("unitClass"))); break;
1114 case normalClass: ListAdd(args, MkExpIdentifier(MkIdentifier("normalClass"))); break;
1118 char nameSpace[1024] = "";
1119 char className[1024] = "";
1121 GetNameSpaceString(regClass.nameSpace, nameSpace);
1123 if(declMode == staticAccess)
1125 GetLastDirectory(sourceFile, className);
1126 ChangeCh(className, '.', '_');
1127 strcat(className, "}");
1129 strcat(className, nameSpace);
1130 strcat(className, regClass.name);
1131 string = QMkString(className);
1132 ListAdd(args, MkExpString(string));
1138 char * string = QMkString(regClass.base.name);
1139 ListAdd(args, regClass.base ? MkExpString(string) :
1140 MkExpConstant("0"));
1145 if(baseSpecs != null)
1147 Type baseType = ProcessType(baseSpecs, null);
1148 if(baseType.kind != structType && baseType.kind != unionType)
1150 char baseName[1024] = "";
1152 if(baseType.kind == TypeKind::classType && baseType._class && baseType._class.isStatic)
1154 // TODO: Handle static classes and complex declarators...
1155 GetLastDirectory(sourceFile, baseName);
1156 ChangeCh(baseName, '.', '_');
1157 strcat(baseName, "}");
1158 strcat(baseName, baseType._class.string);
1161 PrintType(baseType, baseName, false, true);
1163 string = QMkString(baseName);
1164 ListAdd(args, MkExpString(string));
1168 ListAdd(args, MkExpConstant("0"));
1170 if(((Specifier)baseSpecs.first).type == baseSpecifier && ((Specifier)baseSpecs.first).specifier == PRIVATE)
1171 inheritanceAccess = privateAccess;
1174 ListAdd(args, MkExpConstant("0"));
1176 //ListAdd(args, class.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1177 //MkSpecifierName(class.structName)), null)) : MkExpConstant("0"));
1179 if(regClass.type == structClass || regClass.type == normalClass || regClass.type == noHeadClass)
1181 // Check if we have a data member in this class
1182 DataMember member = null;
1185 for(base = regClass.base; base && base.type != systemClass; base = base.next)
1187 for(member = base.membersAndProperties.first; member; member = member.next)
1188 if(!member.isProperty)
1195 if(regClass.type == structClass && symbol.declaredStruct && member)
1197 char baseStructName[1024];
1198 baseStructName[0] = 0;
1199 // TESTING THIS HERE
1200 // FullClassNameCat(baseStructName, regClass.base.fullName, false);
1201 strcpy(baseStructName, (regClass.base.templateClass ? regClass.base.templateClass : regClass.base).fullName);
1203 ListAdd(args, MkExpOp(
1204 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)), '-',
1205 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(baseStructName), null)), null))));
1208 ListAdd(args, symbol.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1209 MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)) : MkExpConstant("0"));
1213 ListAdd(args, MkExpConstant("0"));
1216 //if(regClass.type == normalClass)
1218 char classDataStructName[1024];
1219 strcpy(classDataStructName, "__ecereClassData_");
1220 FullClassNameCat(classDataStructName, symbol.string, false);
1222 ListAdd(args, symbol.classData ? MkExpTypeSize(MkTypeName(MkListOne(
1223 MkStructOrUnion(structSpecifier, MkIdentifier(classDataStructName), null)), null)) : MkExpConstant("0"));
1226 // TODO: Support Class Data for all other types of classes
1227 ListAdd(args, MkExpConstant("0"));
1230 if(regClass.type == normalClass || regClass.type == noHeadClass)
1233 ListAdd(args, symbol.needConstructor ?
1234 MkExpIdentifier(MkIdentifier(symbol.constructorName)) :
1235 MkExpConstant("0"));
1237 ListAdd(args, symbol.needDestructor ?
1238 MkExpIdentifier(MkIdentifier(symbol.destructorName)) :
1239 MkExpConstant("0"));
1243 // TODO: Support Constructors / Destructors for structs
1246 ListAdd(args, MkExpConstant("0"));
1248 ListAdd(args, MkExpConstant("0"));
1252 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1258 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1261 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1265 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1270 switch(inheritanceAccess)
1273 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1277 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1281 registerFunction = "eSystem_RegisterClass";
1283 stmt = MkExpressionStmt(MkListOne(
1284 MkExpOp(MkExpIdentifier(MkIdentifier("class")), '=',
1285 MkExpCall((exp = MkExpIdentifier(MkIdentifier(registerFunction))), args))));
1287 ListAdd(registerModuleBody.compound.statements, stmt);
1290 stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className)))),
1291 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1292 MkExpIdentifier(MkIdentifier("class"))))), null);
1295 stmt = MkIfStmt(MkListOne(
1297 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
1298 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application"))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1299 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1300 MkExpIdentifier(MkIdentifier("class"))))), null);
1302 stmt = MkIfStmt(MkListOne(
1303 MkExpOp(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1304 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1305 MkExpIdentifier(MkIdentifier("class"))))), null);
1308 ListAdd(registerModuleBody.compound.statements, stmt);
1310 if(external && external.type == classExternal && external._class.deleteWatchable)
1312 args = MkListOne(MkExpIdentifier(MkIdentifier("class")));
1313 stmt = MkExpressionStmt(MkListOne(
1314 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DestructionWatchable")), args)));
1315 ListAdd(registerModuleBody.compound.statements, stmt);
1318 // Add Virtual Methods
1321 Class base = regClass.base;
1323 for(c = 0; c<base.vTblSize; c++)
1325 Symbol method = (Symbol)regClass._vTbl[c];
1326 if((void *) method != DummyMethod && base._vTbl[c] != (void *)method && method.methodExternal) // TOLOOKAT: Module check here?
1328 External external = method.methodExternal;
1329 OldList * args = MkList();
1330 Identifier id = external.function ? GetDeclId(external.function.declarator) : null;
1333 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1336 //char * string = QMkString(method.string);
1338 char * string = QMkString(method.method.name);
1339 ListAdd(args, MkExpString(string));
1343 ListAdd(args, MkExpConstant("0"));
1345 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1349 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1351 exp.expType = Type { refCount = 1 };
1352 stmt = MkExpressionStmt(MkListOne(
1353 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1354 ListAdd(registerModuleBody.compound.statements, stmt);
1359 // Add Virtual Methods in order
1362 for(c = regClass.base ? regClass.base.vTblSize : 0; c < regClass.vTblSize; c++)
1364 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1366 if(method.type == virtualMethod && method._class == regClass && method.vid == c)
1371 //External external = method->symbol ? ((Symbol)method.symbol).methodExternal : null;
1372 External external = method.symbol ? ((Symbol)method.symbol).methodCodeExternal : null;
1373 OldList * args = MkList();
1374 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1377 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1380 char * string = QMkString(method.name);
1381 ListAdd(args, MkExpString(string));
1386 char * string = QMkString(method.dataTypeString);
1387 ListAdd(args, MkExpString(string));
1391 if(id && external.function.body)
1393 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(id.string))));
1394 exp.expType = Type { refCount = 1 };
1398 ListAdd(args, (exp = MkExpConstant("0")));
1402 switch(method.memberAccess)
1405 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1408 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1412 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1416 //sprintf(name, "__ecereVMethodID_%s_%s", method._class.fullName, method.name);
1417 strcpy(name, "__ecereVMethodID_");
1418 FullClassNameCat(name, method._class.fullName, false);
1420 strcat(name, method.name);
1422 exp = /*MkExpPointer(*/MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddVirtualMethod")), args)/*, MkIdentifier("vid"))*/;
1424 exp->expType = eSystem_New(sizeof(Type));
1425 exp->expType->refCount++;
1426 exp->expType->isSigned = true;
1427 exp->expType->kind = TypeInt;
1430 stmt = MkExpressionStmt(MkListOne(/*
1431 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', */exp/*)*/));
1433 DeclareMethod(method, name);
1435 ListAdd(registerModuleBody.compound.statements, stmt);
1442 // Add Public Methods (all for now)
1443 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1445 if(method.type == virtualMethod && method._class == regClass);
1446 else if(method.memberAccess == publicAccess || !method.dataTypeString)
1448 //External external = method.symbol ? ((Symbol )method.symbol).methodExternal : null;
1449 External external = method.symbol ? ((Symbol )method.symbol).methodCodeExternal : null;
1450 OldList * args = MkList();
1451 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1454 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1457 char * string = QMkString(method.name);
1458 ListAdd(args, MkExpString(string));
1463 char * string = QMkString(method.dataTypeString);
1464 ListAdd(args, MkExpString(string));
1468 if(id && external.function.body)
1470 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1472 exp.expType = Type { refCount = 1 };
1476 ListAdd(args, (exp = MkExpConstant("0")));
1480 switch(method.memberAccess)
1483 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1486 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1490 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1494 stmt = MkExpressionStmt(MkListOne(
1495 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1496 ListAdd(registerModuleBody.compound.statements, stmt);
1500 RegisterMembersAndProperties(regClass, false, "class", registerModuleBody);
1502 // Add Enumeration Values
1503 if(classType == enumClass)
1506 Class enumClass = eSystem_FindClass(privateModule, "enum");
1507 EnumClassData e = ACCESS_CLASSDATA(regClass, enumClass);
1509 for(value = e.values.first; value; value = value.next)
1511 OldList * args = MkList();
1514 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1517 char * string = QMkString(value.name);
1518 ListAdd(args, MkExpString(string));
1524 // TODO: Support 64 bit enums
1525 sprintf(temp, "%d", (int)value.data);
1526 ListAdd(args, MkExpConstant(temp));
1529 stmt = MkExpressionStmt(MkListOne(
1530 MkExpCall(MkExpIdentifier(MkIdentifier("eEnum_AddFixedValue")), args)));
1531 ListAdd(registerModuleBody.compound.statements, stmt);
1535 // Add Template Parameters
1536 if(symbol.templateParams)
1538 TemplateParameter param;
1539 for(param = symbol.templateParams->first; param; param = param.next)
1541 OldList * args = MkList();
1544 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1548 char * string = QMkString(param.identifier.string);
1549 ListAdd(args, MkExpString(string));
1554 ListAdd(args, MkExpIdentifier(MkIdentifier((param.type == type) ? "type" : ((param.type == identifier) ? "identifier" : "expression"))));
1562 char * typeString = param.dataType ? StringFromSpecDecl(param.dataType.specifiers, param.dataType.decl) : null;
1563 char * string = QMkString(typeString);
1564 ListAdd(args, MkExpString(string));
1571 char memberTypeString[132] = "TemplateMemberType::";
1572 bool needClass = true;
1574 param.memberType.OnGetString(memberTypeString + strlen(memberTypeString), null, &needClass);
1576 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)),
1577 MkExpIdentifier(MkIdentifier(memberTypeString))));
1583 if(param.defaultArgument)
1585 OldList * members = MkList();
1590 char * typeString = param.defaultArgument.templateDatatype ?
1591 StringFromSpecDecl(param.defaultArgument.templateDatatype.specifiers, param.defaultArgument.templateDatatype.decl) : null;
1592 char * string = QMkString(typeString);
1594 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1602 char memberString[1024];
1604 memberString[0] = '\0';
1606 if(param.defaultArgument.identifier._class)
1608 if(param.defaultArgument.identifier._class.type == templateTypeSpecifier)
1609 strcpy(memberString, param.defaultArgument.identifier._class.templateParameter.identifier.string);
1610 else if(param.defaultArgument.identifier._class.name)
1611 strcpy(memberString, param.defaultArgument.identifier._class.name);
1614 strcat(memberString, "::");
1616 strcat(memberString, param.defaultArgument.identifier.string);
1618 string = QMkString(memberString);
1620 // TOFIX: UNIONS ARE BROKEN FOR ASSIGNMENTS, USING dataTypeString INSTEAD
1621 // members->Add(MkMemberInit(MkListOne(MkIdentifier("memberString")), MkInitializerAssignment(MkExpString(string))));
1622 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1630 OldList * ids = MkList();
1632 char * string = null;
1634 //ProcessExpressionType(param.defaultArgument.expression);
1635 //ComputeExpression(param.defaultArgument.expression);
1637 op = GetOperand(param.defaultArgument.expression);
1638 ui64String = PrintUInt64(op.ui64);
1639 ids->Add(MkIdentifier("expression"));
1640 ids->Add(MkIdentifier("ui64"));
1642 //string = QMkString(ui64String);
1643 members->Add(MkMemberInit(ids, MkInitializerAssignment(MkExpConstant(ui64String))));
1650 ListAdd(args, MkExpInstance(MkInstantiation(MkSpecifierName("ClassTemplateArgument"), null,
1651 MkListOne(MkMembersInitList(members)))));
1654 ListAdd(args, MkExpIdentifier(MkIdentifier("null")));
1656 stmt = MkExpressionStmt(MkListOne(
1657 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddTemplateParameter")), args)));
1658 ListAdd(registerModuleBody.compound.statements, stmt);
1660 stmt = MkExpressionStmt(MkListOne(
1661 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DoneAddingTemplateParameters")),
1662 MkListOne(MkExpIdentifier(MkIdentifier("class"))))));
1663 ListAdd(registerModuleBody.compound.statements, stmt);
1666 if(definitions != null)
1668 for(def = definitions.first; def; def = def.next)
1670 if(def.type == propertyWatchClassDef && def.propertyWatch)
1672 ListAdd(registerModuleBody.compound.statements, (Statement)def.propertyWatch);
1673 def.propertyWatch = null;
1675 else if(def.type == classDesignerClassDef)
1678 char className[1024];
1679 sprintf(className, "__ecereClass_%s", def.designer);
1680 MangleClassName(className);
1682 DeclareClass(FindClass(def.designer), className);
1686 char * s = QMkString(def.designer);
1687 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1688 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
1689 MkExpString(s)))), null);
1692 ListAdd(registerModuleBody.compound.statements, stmt);
1694 else if(def.type == classNoExpansionClassDef)
1696 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1697 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("noExpansion")), '=',
1698 MkExpConstant("1")))), null);
1699 ListAdd(registerModuleBody.compound.statements, stmt);
1701 else if(def.type == classFixedClassDef)
1703 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1704 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("fixed")), '=',
1705 MkExpConstant("1")))), null);
1706 ListAdd(registerModuleBody.compound.statements, stmt);
1708 regClass.fixed = true;
1710 else if(def.type == designerDefaultPropertyClassDef)
1712 char * s = QMkString(def.defaultProperty.string);
1713 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1714 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=',
1715 MkExpString(s)))), null);
1716 ListAdd(registerModuleBody.compound.statements, stmt);
1719 else if(def.type == classPropertyValueClassDef)
1721 classPropValues.Add(ClassPropertyValue { regClass = regClass, id = def.id, exp = def.initializer.exp });
1723 def.initializer.exp = null;
1731 class ClassPropertyValue
1737 ~ClassPropertyValue()
1743 static List<ClassPropertyValue> classPropValues { };
1745 public void ProcessClassDefinitions()
1747 External external, next;
1749 CreateRegisterModuleBody();
1752 // (Need to do those things after in case something is not yet defined)
1753 for(external = ast->first; external; external = next)
1755 next = external.next;
1756 curExternal = external;
1757 if(external.type == classExternal)
1759 ClassDefinition _class = external._class;
1760 if(_class.definitions)
1762 ProcessClass(normalClass, _class.definitions, _class.symbol, _class.baseSpecs, null, ast, external, _class.declMode);
1766 ast->Remove(external);
1767 FreeExternal(external);
1770 else if(external.type == functionExternal)
1772 bool setStaticMethod = false;
1774 if(external.symbol && !external.symbol.type.thisClass && !external.symbol.type.staticMethod)
1776 // TOCHECK: Where do we actually need this to be set?
1777 external.symbol.type.staticMethod = true;
1778 setStaticMethod = true;
1783 FunctionDefinition function = external.function;
1787 if(!strcmp(function.declarator.symbol.string, "__on_register_module"))
1789 ListAdd(registerModuleBody.compound.statements, function.body);
1790 function.body.compound.context.parent = registerModuleBody.compound.context;
1791 ast->Remove(external);
1792 function.body = null;
1793 FreeExternal(external);
1797 if(function.declMode != privateAccess && function.declMode != publicAccess) continue;
1801 CreateRegisterModuleBody();
1805 char * string = QMkString(function.declarator.symbol.string);
1806 ListAdd(args, MkExpString(string));
1813 char type[1024] = "";
1814 // We don't want functions to be marked as static methods
1816 function.declarator.symbol.type.staticMethod = false;
1817 PrintType(function.declarator.symbol.type, type, true, true);
1819 function.declarator.symbol.type.staticMethod = true;
1820 string = QMkString(type);
1821 ListAdd(args, MkExpString(string));
1827 ListAdd(args, MkExpIdentifier(MkIdentifier(function.declarator.symbol.string)));
1831 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1834 switch(function.declMode)
1837 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1840 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1844 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1848 stmt = MkExpressionStmt(MkListOne(
1849 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterFunction"))), args)));
1851 ListAdd(registerModuleBody.compound.statements, stmt);
1854 else if(external.type == declarationExternal)
1856 Declaration declaration = external.declaration;
1860 if(external.symbol.type && external.symbol.type.kind == functionType && !external.symbol.type.thisClass)
1861 external.symbol.type.staticMethod = true;
1864 if(external.symbol && declaration.type == initDeclaration)
1866 if(declaration.specifiers)
1868 Specifier specifier;
1869 bool removeExternal = false;
1871 for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
1873 if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
1874 (declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
1876 Symbol symbol = FindClass(specifier.id.string);
1879 ClassType classType;
1880 if(specifier.type == enumSpecifier)
1881 classType = enumClass;
1883 classType = structClass;
1885 removeExternal = true;
1886 // Transfer Context over to Symbol
1887 symbol.ctx = specifier.ctx;
1888 specifier.ctx = null;
1890 ProcessClass(classType, specifier.definitions, symbol, specifier.baseSpecs, specifier.list,ast, external, declaration.declMode);
1894 if(inCompiler && removeExternal)
1896 ast->Remove(external);
1897 FreeExternal(external);
1901 else if(declaration.type == defineDeclaration)
1903 if(inCompiler && declaration.declMode != staticAccess)
1906 OldList * args = MkList();
1908 CreateRegisterModuleBody();
1912 char * string = QMkString(declaration.id.string);
1913 ListAdd(args, MkExpString(string));
1920 char type[1024] = "";
1921 PrintExpression(declaration.exp, type);
1922 string = QMkString(type);
1923 ListAdd(args, MkExpString(string));
1928 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1931 switch(declaration.declMode)
1934 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1937 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1941 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1945 stmt = MkExpressionStmt(MkListOne(
1946 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterDefine"))), args)));
1948 ListAdd(registerModuleBody.compound.statements, stmt);
1954 // Set the class properties at the very end
1955 for(v : classPropValues)
1957 OldList * findClassArgs = MkList();
1958 OldList * args = MkList();
1959 Statement compoundStmt;
1962 ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
1963 s = QMkString(v.regClass.name);
1964 ListAdd(findClassArgs, MkExpString(s));
1967 ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
1968 s = QMkString(v.id.string);
1969 ListAdd(args, MkExpString(s));
1971 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), v.exp));
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();