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 ComputeExpression(e.exp);
927 if(e.exp.isConstant && /*e.exp.expType.kind == intType*/ e.exp.type == constantExp)
929 Operand op = GetOperand(e.exp);
931 // TODO: 64 BIT ENUM SUPPORT...
934 case charType: value = op.c; break;
935 case shortType: value = op.s; break;
936 default: value = op.i;
939 // value = op.i; //strtol(e.exp.string, null, 0);
940 eEnum_AddFixedValue(regClass, e.id.string, value);
944 eEnum_AddValue(regClass, e.id.string);
947 eEnum_AddValue(regClass, e.id.string);
949 // Fix up derivatives enums largest
951 EnumClassData baseData = regClass.data;
953 for(deriv = regClass.derivatives.first; deriv; deriv = deriv.next)
955 Class c = deriv.data;
956 if(c && c.type == enumClass)
958 EnumClassData data = c.data;
959 data.largest = baseData.largest;
965 // Process all functions
966 if(definitions != null)
970 for(def = definitions.first; def; def = def.next)
972 if(def.type == propertyWatchClassDef && def.propertyWatch)
974 PropertyWatch propWatch = def.propertyWatch;
976 char watcherName[1024];
978 Statement stmt = MkExpressionStmt(MkList());
981 sprintf(watcherName,"__ecerePropertySelfWatcher_%d", propWatcherID++);
982 for(propID = propWatch.properties->first; propID; propID = propID.next)
984 strcat(watcherName, "_");
985 strcat(watcherName, propID.string);
988 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
989 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)), MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null)));
990 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, decl, null);
991 ProcessClassFunctionBody(func, propWatch.compound);
993 // TESTING WITH SAME SYMBOL ID AS CLASS
997 idCode = symbol.idCode;
999 excludedSymbols->Add(decl.symbol);
1001 func.id = symbol.id;
1002 func.idCode = symbol.idCode;
1003 func.dontMangle = true;
1005 // Create a declaration above for constructor to see
1007 External externalDecl = MkExternalDeclaration(null);
1009 OldList * specifiers = MkList();
1010 ListAdd(specifiers, MkSpecifier(STATIC));
1011 ListAdd(specifiers, MkSpecifier(VOID));
1013 ast->Insert(curExternal.prev, externalDecl);
1015 decl = MkDeclaration(specifiers,
1016 MkListOne(MkInitDeclarator(MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
1017 MkListOne(MkTypeName(MkListOne(MkSpecifierName(regClass.fullName)), null))), null)));
1018 externalDecl.declaration = decl;
1019 if(decl.symbol && !decl.symbol.methodExternal)
1021 decl.symbol.methodExternal = externalDecl;
1023 // PATCHED THIS, 2 SYMBOLS WERE THERE.. THIS ONE HAD AN ID TOO BIG
1024 decl.symbol.id = symbol.id;
1025 decl.symbol.idCode = symbol.idCode;
1029 propWatch.compound = null;
1030 definitions.Insert(null, MkClassDefFunction(func));
1032 stmt.type = expressionStmt;
1033 stmt.expressions = MkList();
1035 for(propID = propWatch.properties->first; propID; propID = propID.next)
1037 Property prop = eClass_FindProperty(regClass, propID.string, privateModule);
1040 // eProperty_SelfWatch(_class, name, callback);
1041 OldList * args = MkList();
1042 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1043 ListAdd(args, MkExpString(QMkString(propID.string)));
1044 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
1046 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
1049 Compiler_Error($"Property %s not found in class %s\n", propID.string, regClass.fullName);
1051 FreePropertyWatch(def.propertyWatch);
1052 def.propertyWatch = (PropertyWatch)stmt; // Store this here to use it after CreateRegisterModuleBody is done
1054 // ListAdd(statements, stmt);
1059 for(def = definitions.first; def; def = def.next)
1061 if(def.type == functionClassDef)
1063 ProcessClassFunction(regClass, def.function, defs, external.prev, declMode == staticAccess);
1068 // Make the RegisterClass section
1070 if(inCompiler && symbol.id != MAXINT && regClass)
1073 OldList * args = MkList();
1076 char * registerFunction = null;
1077 AccessMode inheritanceAccess = publicAccess;
1079 CreateRegisterModuleBody();
1081 curExternal = registerModuleExternal;
1084 switch(regClass.type)
1086 case structClass: ListAdd(args, MkExpIdentifier(MkIdentifier("structClass"))); break;
1087 case bitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("bitClass"))); break;
1088 case enumClass: ListAdd(args, MkExpIdentifier(MkIdentifier("enumClass"))); break;
1089 case noHeadClass: ListAdd(args, MkExpIdentifier(MkIdentifier("noHeadClass"))); break;
1090 case unitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("unitClass"))); break;
1091 case normalClass: ListAdd(args, MkExpIdentifier(MkIdentifier("normalClass"))); break;
1095 char nameSpace[1024] = "";
1096 char className[1024] = "";
1098 GetNameSpaceString(regClass.nameSpace, nameSpace);
1100 if(declMode == staticAccess)
1102 GetLastDirectory(sourceFile, className);
1103 ChangeCh(className, '.', '_');
1104 strcat(className, "}");
1106 strcat(className, nameSpace);
1107 strcat(className, regClass.name);
1108 string = QMkString(className);
1109 ListAdd(args, MkExpString(string));
1115 char * string = QMkString(regClass.base.name);
1116 ListAdd(args, regClass.base ? MkExpString(string) :
1117 MkExpConstant("0"));
1122 if(baseSpecs != null)
1124 Type baseType = ProcessType(baseSpecs, null);
1125 if(baseType.kind != structType && baseType.kind != unionType)
1127 char baseName[1024] = "";
1129 if(baseType.kind == TypeKind::classType && baseType._class && baseType._class.isStatic)
1131 // TODO: Handle static classes and complex declarators...
1132 GetLastDirectory(sourceFile, baseName);
1133 ChangeCh(baseName, '.', '_');
1134 strcat(baseName, "}");
1135 strcat(baseName, baseType._class.string);
1138 PrintType(baseType, baseName, false, true);
1140 string = QMkString(baseName);
1141 ListAdd(args, MkExpString(string));
1145 ListAdd(args, MkExpConstant("0"));
1147 if(((Specifier)baseSpecs.first).type == baseSpecifier && ((Specifier)baseSpecs.first).specifier == PRIVATE)
1148 inheritanceAccess = privateAccess;
1151 ListAdd(args, MkExpConstant("0"));
1153 //ListAdd(args, class.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1154 //MkSpecifierName(class.structName)), null)) : MkExpConstant("0"));
1156 if(regClass.type == structClass || regClass.type == normalClass || regClass.type == noHeadClass)
1158 // Check if we have a data member in this class
1159 DataMember member = null;
1162 for(base = regClass.base; base && base.type != systemClass; base = base.next)
1164 for(member = base.membersAndProperties.first; member; member = member.next)
1165 if(!member.isProperty)
1172 if(regClass.type == structClass && symbol.declaredStruct && member)
1174 char baseStructName[1024];
1175 baseStructName[0] = 0;
1176 // TESTING THIS HERE
1177 // FullClassNameCat(baseStructName, regClass.base.fullName, false);
1178 strcpy(baseStructName, (regClass.base.templateClass ? regClass.base.templateClass : regClass.base).fullName);
1180 ListAdd(args, MkExpOp(
1181 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)), '-',
1182 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(baseStructName), null)), null))));
1185 ListAdd(args, symbol.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1186 MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)) : MkExpConstant("0"));
1190 ListAdd(args, MkExpConstant("0"));
1193 //if(regClass.type == normalClass)
1195 char classDataStructName[1024];
1196 strcpy(classDataStructName, "__ecereClassData_");
1197 FullClassNameCat(classDataStructName, symbol.string, false);
1199 ListAdd(args, symbol.classData ? MkExpTypeSize(MkTypeName(MkListOne(
1200 MkStructOrUnion(structSpecifier, MkIdentifier(classDataStructName), null)), null)) : MkExpConstant("0"));
1203 // TODO: Support Class Data for all other types of classes
1204 ListAdd(args, MkExpConstant("0"));
1207 if(regClass.type == normalClass || regClass.type == noHeadClass)
1210 ListAdd(args, symbol.needConstructor ?
1211 MkExpIdentifier(MkIdentifier(symbol.constructorName)) :
1212 MkExpConstant("0"));
1214 ListAdd(args, symbol.needDestructor ?
1215 MkExpIdentifier(MkIdentifier(symbol.destructorName)) :
1216 MkExpConstant("0"));
1220 // TODO: Support Constructors / Destructors for structs
1223 ListAdd(args, MkExpConstant("0"));
1225 ListAdd(args, MkExpConstant("0"));
1229 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1235 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1238 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1242 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1247 switch(inheritanceAccess)
1250 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1254 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1258 registerFunction = "eSystem_RegisterClass";
1260 stmt = MkExpressionStmt(MkListOne(
1261 MkExpOp(MkExpIdentifier(MkIdentifier("class")), '=',
1262 MkExpCall((exp = MkExpIdentifier(MkIdentifier(registerFunction))), args))));
1264 ListAdd(registerModuleBody.compound.statements, stmt);
1267 stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className)))),
1268 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1269 MkExpIdentifier(MkIdentifier("class"))))), null);
1272 stmt = MkIfStmt(MkListOne(
1274 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
1275 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application"))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1276 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1277 MkExpIdentifier(MkIdentifier("class"))))), null);
1279 stmt = MkIfStmt(MkListOne(
1280 MkExpOp(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1281 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1282 MkExpIdentifier(MkIdentifier("class"))))), null);
1285 ListAdd(registerModuleBody.compound.statements, stmt);
1287 if(external && external.type == classExternal && external._class.deleteWatchable)
1289 args = MkListOne(MkExpIdentifier(MkIdentifier("class")));
1290 stmt = MkExpressionStmt(MkListOne(
1291 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DestructionWatchable")), args)));
1292 ListAdd(registerModuleBody.compound.statements, stmt);
1295 // Add Virtual Methods
1298 Class base = regClass.base;
1300 for(c = 0; c<base.vTblSize; c++)
1302 Symbol method = (Symbol)regClass._vTbl[c];
1303 if((void *) method != DummyMethod && base._vTbl[c] != (void *)method && method.methodExternal) // TOLOOKAT: Module check here?
1305 External external = method.methodExternal;
1306 OldList * args = MkList();
1307 Identifier id = external.function ? GetDeclId(external.function.declarator) : null;
1310 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1313 //char * string = QMkString(method.string);
1315 char * string = QMkString(method.method.name);
1316 ListAdd(args, MkExpString(string));
1320 ListAdd(args, MkExpConstant("0"));
1322 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1326 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1328 exp.expType = Type { refCount = 1 };
1329 stmt = MkExpressionStmt(MkListOne(
1330 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1331 ListAdd(registerModuleBody.compound.statements, stmt);
1336 // Add Virtual Methods in order
1339 for(c = regClass.base ? regClass.base.vTblSize : 0; c < regClass.vTblSize; c++)
1341 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1343 if(method.type == virtualMethod && method._class == regClass && method.vid == c)
1348 //External external = method->symbol ? ((Symbol)method.symbol).methodExternal : null;
1349 External external = method.symbol ? ((Symbol)method.symbol).methodCodeExternal : null;
1350 OldList * args = MkList();
1351 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1354 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1357 char * string = QMkString(method.name);
1358 ListAdd(args, MkExpString(string));
1363 char * string = QMkString(method.dataTypeString);
1364 ListAdd(args, MkExpString(string));
1368 if(id && external.function.body)
1370 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(id.string))));
1371 exp.expType = Type { refCount = 1 };
1375 ListAdd(args, (exp = MkExpConstant("0")));
1379 switch(method.memberAccess)
1382 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1385 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1389 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1393 //sprintf(name, "__ecereVMethodID_%s_%s", method._class.fullName, method.name);
1394 strcpy(name, "__ecereVMethodID_");
1395 FullClassNameCat(name, method._class.fullName, false);
1397 strcat(name, method.name);
1399 exp = /*MkExpPointer(*/MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddVirtualMethod")), args)/*, MkIdentifier("vid"))*/;
1401 exp->expType = eSystem_New(sizeof(Type));
1402 exp->expType->refCount++;
1403 exp->expType->isSigned = true;
1404 exp->expType->kind = TypeInt;
1407 stmt = MkExpressionStmt(MkListOne(/*
1408 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', */exp/*)*/));
1410 DeclareMethod(method, name);
1412 ListAdd(registerModuleBody.compound.statements, stmt);
1419 // Add Public Methods (all for now)
1420 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1422 if(method.type == virtualMethod && method._class == regClass);
1423 else if(method.memberAccess == publicAccess || !method.dataTypeString)
1425 //External external = method.symbol ? ((Symbol )method.symbol).methodExternal : null;
1426 External external = method.symbol ? ((Symbol )method.symbol).methodCodeExternal : null;
1427 OldList * args = MkList();
1428 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1431 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1434 char * string = QMkString(method.name);
1435 ListAdd(args, MkExpString(string));
1440 char * string = QMkString(method.dataTypeString);
1441 ListAdd(args, MkExpString(string));
1445 if(id && external.function.body)
1447 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1449 exp.expType = Type { refCount = 1 };
1453 ListAdd(args, (exp = MkExpConstant("0")));
1457 switch(method.memberAccess)
1460 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1463 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1467 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1471 stmt = MkExpressionStmt(MkListOne(
1472 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1473 ListAdd(registerModuleBody.compound.statements, stmt);
1477 RegisterMembersAndProperties(regClass, false, "class", registerModuleBody);
1479 // Add Enumeration Values
1480 if(classType == enumClass)
1483 Class enumClass = eSystem_FindClass(privateModule, "enum");
1484 EnumClassData e = ACCESS_CLASSDATA(regClass, enumClass);
1486 for(value = e.values.first; value; value = value.next)
1488 OldList * args = MkList();
1491 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1494 char * string = QMkString(value.name);
1495 ListAdd(args, MkExpString(string));
1501 // TODO: Support 64 bit enums
1502 sprintf(temp, "%d", (int)value.data);
1503 ListAdd(args, MkExpConstant(temp));
1506 stmt = MkExpressionStmt(MkListOne(
1507 MkExpCall(MkExpIdentifier(MkIdentifier("eEnum_AddFixedValue")), args)));
1508 ListAdd(registerModuleBody.compound.statements, stmt);
1512 // Add Template Parameters
1513 if(symbol.templateParams)
1515 TemplateParameter param;
1516 for(param = symbol.templateParams->first; param; param = param.next)
1518 OldList * args = MkList();
1521 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1525 char * string = QMkString(param.identifier.string);
1526 ListAdd(args, MkExpString(string));
1531 ListAdd(args, MkExpIdentifier(MkIdentifier((param.type == type) ? "type" : ((param.type == identifier) ? "identifier" : "expression"))));
1539 char * typeString = param.dataType ? StringFromSpecDecl(param.dataType.specifiers, param.dataType.decl) : null;
1540 char * string = QMkString(typeString);
1541 ListAdd(args, MkExpString(string));
1548 char memberTypeString[132] = "TemplateMemberType::";
1549 bool needClass = true;
1551 param.memberType.OnGetString(memberTypeString + strlen(memberTypeString), null, &needClass);
1553 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)),
1554 MkExpIdentifier(MkIdentifier(memberTypeString))));
1560 if(param.defaultArgument)
1562 OldList * members = MkList();
1567 char * typeString = param.defaultArgument.templateDatatype ?
1568 StringFromSpecDecl(param.defaultArgument.templateDatatype.specifiers, param.defaultArgument.templateDatatype.decl) : null;
1569 char * string = QMkString(typeString);
1571 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1579 char memberString[1024];
1581 memberString[0] = '\0';
1583 if(param.defaultArgument.identifier._class)
1585 if(param.defaultArgument.identifier._class.type == templateTypeSpecifier)
1586 strcpy(memberString, param.defaultArgument.identifier._class.templateParameter.identifier.string);
1587 else if(param.defaultArgument.identifier._class.name)
1588 strcpy(memberString, param.defaultArgument.identifier._class.name);
1591 strcat(memberString, "::");
1593 strcat(memberString, param.defaultArgument.identifier.string);
1595 string = QMkString(memberString);
1597 // TOFIX: UNIONS ARE BROKEN FOR ASSIGNMENTS, USING dataTypeString INSTEAD
1598 // members->Add(MkMemberInit(MkListOne(MkIdentifier("memberString")), MkInitializerAssignment(MkExpString(string))));
1599 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1607 OldList * ids = MkList();
1609 char * string = null;
1611 //ProcessExpressionType(param.defaultArgument.expression);
1612 //ComputeExpression(param.defaultArgument.expression);
1614 op = GetOperand(param.defaultArgument.expression);
1615 ui64String = PrintUInt64(op.ui64);
1616 ids->Add(MkIdentifier("expression"));
1617 ids->Add(MkIdentifier("ui64"));
1619 //string = QMkString(ui64String);
1620 members->Add(MkMemberInit(ids, MkInitializerAssignment(MkExpConstant(ui64String))));
1627 ListAdd(args, MkExpInstance(MkInstantiation(MkSpecifierName("ClassTemplateArgument"), null,
1628 MkListOne(MkMembersInitList(members)))));
1631 ListAdd(args, MkExpIdentifier(MkIdentifier("null")));
1633 stmt = MkExpressionStmt(MkListOne(
1634 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddTemplateParameter")), args)));
1635 ListAdd(registerModuleBody.compound.statements, stmt);
1637 stmt = MkExpressionStmt(MkListOne(
1638 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DoneAddingTemplateParameters")),
1639 MkListOne(MkExpIdentifier(MkIdentifier("class"))))));
1640 ListAdd(registerModuleBody.compound.statements, stmt);
1643 if(definitions != null)
1645 for(def = definitions.first; def; def = def.next)
1647 if(def.type == propertyWatchClassDef && def.propertyWatch)
1649 ListAdd(registerModuleBody.compound.statements, (Statement)def.propertyWatch);
1650 def.propertyWatch = null;
1652 else if(def.type == classDesignerClassDef)
1655 char className[1024];
1656 sprintf(className, "__ecereClass_%s", def.designer);
1657 MangleClassName(className);
1659 DeclareClass(FindClass(def.designer), className);
1662 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1663 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
1664 MkExpString(QMkString(def.designer))))), null);
1665 ListAdd(registerModuleBody.compound.statements, stmt);
1667 else if(def.type == classNoExpansionClassDef)
1669 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1670 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("noExpansion")), '=',
1671 MkExpConstant("1")))), null);
1672 ListAdd(registerModuleBody.compound.statements, stmt);
1674 else if(def.type == classFixedClassDef)
1676 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1677 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("fixed")), '=',
1678 MkExpConstant("1")))), null);
1679 ListAdd(registerModuleBody.compound.statements, stmt);
1681 regClass.fixed = true;
1683 else if(def.type == designerDefaultPropertyClassDef)
1685 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1686 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=',
1687 MkExpString(QMkString(def.defaultProperty.string))))), null);
1688 ListAdd(registerModuleBody.compound.statements, stmt);
1690 else if(def.type == classPropertyValueClassDef)
1692 classPropValues.Add(ClassPropertyValue { regClass = regClass, id = def.id, exp = def.initializer.exp });
1694 def.initializer.exp = null;
1702 class ClassPropertyValue
1708 ~ClassPropertyValue()
1714 static List<ClassPropertyValue> classPropValues { };
1716 public void ProcessClassDefinitions()
1718 External external, next;
1720 CreateRegisterModuleBody();
1723 // (Need to do those things after in case something is not yet defined)
1724 for(external = ast->first; external; external = next)
1726 next = external.next;
1727 curExternal = external;
1728 if(external.type == classExternal)
1730 ClassDefinition _class = external._class;
1731 if(_class.definitions)
1733 ProcessClass(normalClass, _class.definitions, _class.symbol, _class.baseSpecs, null, ast, external, _class.declMode);
1737 ast->Remove(external);
1738 FreeExternal(external);
1741 else if(external.type == functionExternal)
1743 bool setStaticMethod = false;
1745 if(external.symbol && !external.symbol.type.thisClass && !external.symbol.type.staticMethod)
1747 // TOCHECK: Where do we actually need this to be set?
1748 external.symbol.type.staticMethod = true;
1749 setStaticMethod = true;
1754 FunctionDefinition function = external.function;
1758 if(!strcmp(function.declarator.symbol.string, "__on_register_module"))
1760 ListAdd(registerModuleBody.compound.statements, function.body);
1761 function.body.compound.context.parent = registerModuleBody.compound.context;
1762 ast->Remove(external);
1763 function.body = null;
1764 FreeExternal(external);
1768 if(function.declMode != privateAccess && function.declMode != publicAccess) continue;
1772 CreateRegisterModuleBody();
1776 char * string = QMkString(function.declarator.symbol.string);
1777 ListAdd(args, MkExpString(string));
1784 char type[1024] = "";
1785 // We don't want functions to be marked as static methods
1787 function.declarator.symbol.type.staticMethod = false;
1788 PrintType(function.declarator.symbol.type, type, true, true);
1790 function.declarator.symbol.type.staticMethod = true;
1791 string = QMkString(type);
1792 ListAdd(args, MkExpString(string));
1798 ListAdd(args, MkExpIdentifier(MkIdentifier(function.declarator.symbol.string)));
1802 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1805 switch(function.declMode)
1808 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1811 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1815 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1819 stmt = MkExpressionStmt(MkListOne(
1820 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterFunction"))), args)));
1822 ListAdd(registerModuleBody.compound.statements, stmt);
1825 else if(external.type == declarationExternal)
1827 Declaration declaration = external.declaration;
1831 if(external.symbol.type && external.symbol.type.kind == functionType && !external.symbol.type.thisClass)
1832 external.symbol.type.staticMethod = true;
1835 if(external.symbol && declaration.type == initDeclaration)
1837 if(declaration.specifiers)
1839 Specifier specifier;
1840 bool removeExternal = false;
1842 for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
1844 if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
1845 (declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
1847 Symbol symbol = FindClass(specifier.id.string);
1850 ClassType classType;
1851 if(specifier.type == enumSpecifier)
1852 classType = enumClass;
1854 classType = structClass;
1856 removeExternal = true;
1857 // Transfer Context over to Symbol
1858 symbol.ctx = specifier.ctx;
1859 specifier.ctx = null;
1861 ProcessClass(classType, specifier.definitions, symbol, specifier.baseSpecs, specifier.list,ast, external, declaration.declMode);
1865 if(inCompiler && removeExternal)
1867 ast->Remove(external);
1868 FreeExternal(external);
1872 else if(declaration.type == defineDeclaration)
1874 if(inCompiler && declaration.declMode != staticAccess)
1877 OldList * args = MkList();
1879 CreateRegisterModuleBody();
1883 char * string = QMkString(declaration.id.string);
1884 ListAdd(args, MkExpString(string));
1891 char type[1024] = "";
1892 PrintExpression(declaration.exp, type);
1893 string = QMkString(type);
1894 ListAdd(args, MkExpString(string));
1899 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1902 switch(declaration.declMode)
1905 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1908 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1912 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1916 stmt = MkExpressionStmt(MkListOne(
1917 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterDefine"))), args)));
1919 ListAdd(registerModuleBody.compound.statements, stmt);
1925 // Set the class properties at the very end
1926 for(v : classPropValues)
1928 OldList * findClassArgs = MkList();
1929 OldList * args = MkList();
1930 Statement compoundStmt;
1932 ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
1933 ListAdd(findClassArgs, MkExpString(QMkString(v.regClass.name)));
1935 ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
1936 ListAdd(args, MkExpString(QMkString(v.id.string)));
1937 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), v.exp));
1938 compoundStmt = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
1939 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("_class")),
1940 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eSystem_FindClass")), findClassArgs)))))),
1941 MkListOne(MkExpressionStmt(MkListOne(
1942 MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eClass_SetProperty")), args)))));
1943 compoundStmt.compound.context = Context { parent = registerModuleBody.compound.context };
1944 ListAdd(registerModuleBody.compound.statements, compoundStmt);
1947 classPropValues.Free();