3 // UNTIL IMPLEMENTED IN GRAMMAR
4 #define ACCESS_CLASSDATA(_class, baseClass) \
5 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
7 #define YYLTYPE Location
10 static Statement registerModuleBody;
11 static External registerModuleExternal;
12 static Statement unregisterModuleBody;
13 static External unregisterModuleExternal;
15 extern int propWatcherID;
17 bool buildingECERECOM = false;
18 public void SetBuildingEcereCom(bool b) { buildingECERECOM = b; } public bool GetBuildingEcereCom() { return buildingECERECOM; }
19 bool buildingECERECOMModule = false;
20 public void SetBuildingEcereComModule(bool b) { buildingECERECOMModule = b; } public bool GetBuildingEcereComModule() { return buildingECERECOMModule; }
22 // This will also be called by the instance processer to make the instance methods... (pass 1.5)
23 External ProcessClassFunction(Class owningClass, ClassFunction func, OldList defs, External after, bool makeStatic)
27 External external = null;
29 if(defs && func.declarator)
31 FunctionDefinition function = null;
33 int symid = func.declarator.symbol.id;
34 int symidCode = func.declarator.symbol.idCode;
39 func.specifiers = MkList();
40 // Add static to the specifiers
42 func.specifiers->Insert(null, MkSpecifier(STATIC));
45 propSymbol = func.declarator.symbol;
47 ReplaceThisClassSpecifiers(func.specifiers, owningClass);
49 if(propSymbol.externalGet == (External)func)
50 func.declarator.symbol = null;
51 else if(propSymbol.externalSet == (External)func)
53 func.declarator.symbol = null;
56 else if(propSymbol.externalIsSet == (External)func)
58 func.declarator.symbol = null;
59 symid += 2; // TOFIX: What should we do with this? Where are 2 IDs allocated for properties? In MkProperty...
64 /*FunctionDefinition*/ function = _MkFunction(func.specifiers, func.declarator, null, false);
65 function.propSet = func.propSet;
66 function.type = func.type;
67 if(func.type) func.type.refCount++;
68 ProcessFunctionBody(function, func.body);
69 external = MkExternalFunction(function);
71 external.symbol = func.declarator.symbol;
72 external.function._class = func._class;
75 symbol = func.declarator.symbol;
76 //symbol.id = func.id; //symid;
78 symbol.idCode = symidCode;
83 Method method = func.declarator.symbol.method;
84 func.declarator.symbol.methodExternal = external;
86 // DANGER: Added this one...
88 if(method && method.symbol)
89 //((Symbol)method.symbol).methodExternal = external;
90 ((Symbol)method.symbol).methodCodeExternal = external;
92 if(method && method.type == virtualMethod)
95 ProcessMethodType(method);
97 methodDataType = method.dataType;
99 // Do type checking here of type against method.dataType
100 // ThisClass must be the owning class for types not specified, static for static, or inherit from method's ThisClass is specified
101 // If not specified, defaults to ThisClass if ThisClass specified in method, otherwise overiding class or static
105 if(!type.staticMethod && !type.thisClass && !type.thisClassTemplate)
107 if(method.dataType.thisClassTemplate)
109 if(owningClass.templateArgs)
111 ClassTemplateArgument * arg = FindTemplateArg(owningClass, method.dataType.thisClassTemplate);
112 type.byReference = method.dataType.byReference;
114 methodDataType = ProcessTypeString(method.dataTypeString, false);
115 type.thisClass = methodDataType.thisClass = arg ? FindClass(arg->dataTypeString) : null;
118 else if(method.dataType.staticMethod)
119 type.staticMethod = true;
120 else if(method.dataType.thisClass)
122 type.thisClass = method.dataType.thisClass;
123 type.byReference = method.dataType.byReference;
127 if(!owningClass.symbol)
128 owningClass.symbol = FindClass(owningClass.fullName);
130 type.thisClass = owningClass.symbol;
131 // WORKING ON THIS TO SUPPORT : pass.NotifyClicked(this, pass, 0, 0, key.modifiers);
132 type.extraParam = true;
137 if(!MatchTypes(type, methodDataType, null, owningClass, method._class /*owningClass*/, true, true, true, false, true))
140 // MatchTypes(type, methodDataType, null, owningClass, owningClass, true, true, true, false);
142 Compiler_Error($"Incompatible virtual function %s\n", method.name);
146 // Mark typed_object/any_object parameters as such according to method type
148 Declarator funcDecl = GetFuncDecl(func.declarator);
149 if(funcDecl.function.parameters && funcDecl.function.parameters->first)
151 TypeName param = funcDecl.function.parameters->first;
153 for(typeParam = methodDataType.params.first; typeParam && param; typeParam = typeParam.next)
155 if(typeParam.classObjectType)
157 param.classObjectType = typeParam.classObjectType;
158 if(param.declarator && param.declarator.symbol)
159 param.declarator.symbol.type.classObjectType = typeParam.classObjectType;
161 param = param ? param.next : null;
165 if(methodDataType != method.dataType)
166 FreeType(methodDataType);
171 if(!type.staticMethod && !type.thisClass)
173 if(owningClass && !owningClass.symbol)
174 owningClass.symbol = FindClass(owningClass.fullName);
176 type.thisClass = owningClass ? FindClass(owningClass.fullName) : null;
182 // TESTING THIS HERE: (Implementing Class Properties)
183 if(symbol.type && !symbol.type.staticMethod && !symbol.type.thisClass)
185 if(!owningClass.symbol)
186 owningClass.symbol = FindClass(owningClass.fullName);
187 symbol.type.thisClass = owningClass.symbol;
190 // Those type of classes don't need a this parameter for Set methods, null thisClass before changing the externals
191 if(propSymbol.externalSet == (External)func && propSymbol._property && propSymbol._property.conversion)
193 if(symbol.type.thisClass && symbol.type.classObjectType != classPointer)
195 // TODO: Perhaps improve this so as to support both "this =" and "return " syntax for all types of classes
196 if(owningClass.type != structClass)
197 //function.propertyNoThis = true;
198 symbol.type.thisClass = null;
203 if(propSymbol.externalGet == (External)func)
205 propSymbol.externalGet = external;
207 else if(propSymbol.externalSet == (External)func)
209 propSymbol.externalSet = external;
211 else if(propSymbol.externalIsSet == (External)func)
213 propSymbol.externalIsSet = external;
217 // Constructor destructor
218 //symbol.type = Type { };
225 func.declarator = null;
226 func.specifiers = null;
229 defs.Insert(after, external);
233 Method method = func.declarator.symbol.method;
234 if(method && method.symbol)
235 ((Symbol)method.symbol).methodCodeExternal = null;
236 if(func.declarator.symbol && func.declarator.symbol.methodExternal == external)
237 func.declarator.symbol.methodExternal = null;
239 //external.function = null;
240 func.declarator = null;
241 func.specifiers = null;
243 FreeExternal(external); // Free external here?
248 globalContext /*curContext*/.symbols.Remove((BTNode)symbol);
249 excludedSymbols->Add(symbol);
252 defs.Insert(after, external);
254 external.function.declarator = CopyDeclarator(external.function.declarator);
255 external.function.specifiers = CopyList(external.function.specifiers, CopySpecifier);
256 external.function.body = null;
262 void CreateRegisterModuleBody()
264 if(!registerModuleBody && inCompiler)
266 char registerName[1024], moduleName[MAX_FILENAME];
267 OldList * specifiers;
268 Declarator declarator;
269 TypeName moduleParam;
271 registerModuleBody = MkCompoundStmt(MkList(), MkList());
272 registerModuleBody.compound.context = Context { parent = globalContext };
275 ListAdd(registerModuleBody.compound.declarations,
276 MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null) /*MkSpecifierName("ecere::com::Class")*/ /*MkStructOrUnion(SpecifierStruct, MkIdentifier("Class"), null)*/),
277 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class"))), null))));
279 ListAdd(registerModuleBody.compound.declarations,
280 MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
281 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("class")), null))));
283 specifiers = MkList();
284 ListAdd(specifiers, MkSpecifier(VOID));
286 moduleParam = MkTypeName(MkListOne(/*MkSpecifier(VOID)*/MkSpecifierName("Module")),
287 //MkDeclaratorPointer(MkPointer(null, null),
288 MkDeclaratorIdentifier(MkIdentifier("module")));
290 GetLastDirectory(outputFile, moduleName);
291 //strcpy(moduleName, argv[2]);
292 StripExtension(moduleName);
293 FixModuleName(moduleName);
294 sprintf(registerName, "__ecereRegisterModule_%s", moduleName);
296 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
297 MkListOne(moduleParam));
300 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
301 ProcessFunctionBody(function, registerModuleBody);
302 function.declMode = defaultAccess;
303 if(!ast) ast = MkList();
304 ListAdd(ast, (registerModuleExternal = MkExternalFunction(function)));
309 if(!unregisterModuleBody && inCompiler)
311 char registerName[1024], moduleName[MAX_FILENAME];
312 OldList * specifiers;
313 Declarator declarator;
314 TypeName moduleParam;
316 unregisterModuleBody = MkCompoundStmt(MkList(), MkList());
317 unregisterModuleBody.compound.context = Context { parent = globalContext };
319 specifiers = MkList();
320 ListAdd(specifiers, MkSpecifier(VOID));
322 moduleParam = MkTypeName(MkListOne(/*MkSpecifier(VOID)*/ MkSpecifierName("Module")),
323 //MkDeclaratorPointer(MkPointer(null, null),
324 MkDeclaratorIdentifier(MkIdentifier("module")));
326 GetLastDirectory(outputFile, moduleName);
327 StripExtension(moduleName);
328 FixModuleName(moduleName);
329 //strcpy(moduleName, argv[2]);
330 sprintf(registerName, "__ecereUnregisterModule_%s", moduleName);
332 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
333 MkListOne(moduleParam));
336 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
337 ProcessFunctionBody(function, unregisterModuleBody);
338 function.declMode = defaultAccess;
339 if(!ast) ast = MkList();
340 ListAdd(ast, (unregisterModuleExternal = MkExternalFunction(function)));
345 void RegisterMembersAndProperties(Class regClass, bool isMember, const char * className, Statement statement)
347 DataMember dataMember = isMember ? (DataMember)regClass : null;
352 char dataMemberSize[16];
356 bool privateMembers = false;
358 sprintf(dataMemberSize, "%d", (int)sizeof(DataMember));
361 for(prop = regClass.conversions.first; prop; prop = prop.next)
363 OldList * args = MkList();
367 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
369 ListAdd(args, MkExpConstant("0"));
373 char * string = QMkString(prop.dataTypeString);
374 ListAdd(args, MkExpString(string));
380 strcpy(name, "__ecereProp_");
381 FullClassNameCat(name, regClass.fullName, false);
382 strcat(name, "_Set_");
383 // strcat(name, prop.name);
384 FullClassNameCat(name, prop.name, true);
385 MangleClassName(name);
386 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
389 ListAdd(args, MkExpConstant("0"));
393 strcpy(name, "__ecereProp_");
394 FullClassNameCat(name, regClass.fullName, false);
395 strcat(name, "_Get_");
396 // strcat(name, prop.name);
397 FullClassNameCat(name, prop.name, true);
398 MangleClassName(name);
400 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
403 ListAdd(args, MkExpConstant("0"));
407 switch(prop.memberAccess)
410 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
413 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
417 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
421 strcpy(name, "__ecereProp_");
422 FullClassNameCat(name, regClass.fullName, false);
424 FullClassNameCat(name, prop.name, true);
425 // strcat(name, prop.name);
426 MangleClassName(name);
428 stmt = MkExpressionStmt(MkListOne(
429 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=',
430 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
431 ListAdd(registerModuleBody.compound.statements, stmt);
435 for(member = isMember ? dataMember.members.first : regClass.membersAndProperties.first; member; member = member.next)
437 if(member.isProperty)
439 prop = (Property) member;
441 OldList * args = MkList();
442 char name[1024], nameM[1024];
443 char * string = QMkString(prop.name);
446 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
449 ListAdd(args, MkExpString(string));
454 char * string = QMkString(prop.dataTypeString);
455 ListAdd(args, MkExpString(string));
461 strcpy(name, "__ecereProp_");
462 FullClassNameCat(name, regClass.fullName, false);
463 strcat(name, "_Set_");
464 FullClassNameCat(name, prop.name, true);
465 // strcat(name, prop.name);
466 MangleClassName(name);
467 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
470 ListAdd(args, MkExpConstant("0"));
474 strcpy(name, "__ecereProp_");
475 FullClassNameCat(name, regClass.fullName, false);
476 strcat(name, "_Get_");
477 FullClassNameCat(name, prop.name, true);
478 // strcat(name, prop.name);
479 MangleClassName(name);
480 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
483 ListAdd(args, MkExpConstant("0"));
486 switch(prop.memberAccess)
489 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
492 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
496 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
500 strcpy(name, "__ecereProp_");
501 FullClassNameCat(name, regClass.fullName, false);
503 FullClassNameCat(name, prop.name, true);
504 // strcat(name, prop.name);
505 MangleClassName(name);
507 strcpy(nameM, "__ecerePropM_");
508 FullClassNameCat(nameM, regClass.fullName, false);
510 FullClassNameCat(nameM, prop.name, true);
511 // strcat(nameM, prop.name);
512 MangleClassName(nameM);
514 if(prop.dataTypeString)
516 stmt = MkExpressionStmt(MkListOne(
517 MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
518 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
522 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args)));
524 ListAdd(registerModuleBody.compound.statements, stmt);
529 strcpy(name, "__ecereProp_");
530 FullClassNameCat(name, regClass.fullName, true);
531 strcat(name, "_IsSet_");
532 FullClassNameCat(name, prop.name, false);
533 // strcat(name, prop.name);
534 MangleClassName(name);
536 stmt = MkExpressionStmt(MkListOne(
537 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("IsSet")), '=',
538 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpIdentifier(MkIdentifier(name))))));
539 ListAdd(registerModuleBody.compound.statements, stmt);
541 if(prop.symbol && ((Symbol)prop.symbol).propCategory)
543 stmt = MkExpressionStmt(MkListOne(
544 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("category")), '=',
545 CopyExpression(((Symbol)prop.symbol).propCategory))));
546 ListAdd(registerModuleBody.compound.statements, stmt);
549 if(prop.dataTypeString)
551 OldList * list = MkList();
552 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', MkExpIdentifier(MkIdentifier(nameM))));
553 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=', MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0"))));
554 // stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(name)))), MkExpressionStmt(list), null);
555 stmt = MkIfStmt(MkListOne(MkExpOp(
556 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
557 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application")))), MkExpressionStmt(list), null);
559 ListAdd(registerModuleBody.compound.statements, stmt);
561 // Unregister 2nd property
562 stmt = MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
563 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0")))));
564 ListAdd(unregisterModuleBody.compound.statements, stmt);
568 else if(member.type == normalMember && !isMember && regClass.type == bitClass)
570 BitMember bitMember = (BitMember) member;
571 OldList * args = MkList();
574 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
578 char * string = QMkString(bitMember.name);
579 ListAdd(args, MkExpString(string));
584 char * string = QMkString(bitMember.dataTypeString);
585 ListAdd(args, MkExpString(string));
591 sprintf(string, "%d", bitMember.size);
592 ListAdd(args, (exp = MkExpConstant(string)));
597 sprintf(string, "%d", bitMember.pos);
598 ListAdd(args, (exp = MkExpConstant(string)));
602 switch(member.memberAccess)
605 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
608 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
612 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
616 stmt = MkExpressionStmt(MkListOne(
617 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddBitMember")), args)));
619 ListAdd(statement.compound.statements, stmt);
621 else if(member.memberAccess == publicAccess || (member.type == normalMember && !member.dataTypeString))
624 // ADD PRIVATE DATA PADDING HERE...
627 uint offset = member.offset - lastOffset;
632 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
637 sprintf(string, "\"__ecerePrivateData%d\"", privateID++);
638 ListAdd(args, MkExpString(string));
643 sprintf(string, "\"byte[%d]\"", offset);
644 ListAdd(args, MkExpString(string));
649 sprintf(string, "%d", offset);
650 ListAdd(args, (exp = MkExpConstant(string)));
654 ListAdd(args, (exp = MkExpConstant("1")));
657 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
659 stmt = MkExpressionStmt(MkListOne(
660 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
662 ListAdd(statement.compound.statements, stmt);
663 privateMembers = false;
666 if(member.type == normalMember)
669 member.dataType = ProcessTypeString(member.dataTypeString, false);
671 ComputeTypeSize(member.dataType);
676 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
680 char * string = QMkString(member.name);
681 ListAdd(args, MkExpString(string));
686 char * string = QMkString(member.dataTypeString);
687 ListAdd(args, MkExpString(string));
693 sprintf(string, "%d", member.dataType.size);
694 ListAdd(args, (exp = MkExpConstant(string)));
700 sprintf(string, "%d", member.dataType.alignment);
701 ListAdd(args, (exp = MkExpConstant(string)));
705 switch(member.memberAccess)
708 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
711 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
715 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
719 stmt = MkExpressionStmt(MkListOne(
720 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
722 ListAdd(statement.compound.statements, stmt);
724 lastOffset = member.offset + member.dataType.size;
728 static int memberCount = 0;
732 char memberName[256];
733 sprintf(memberName, "dataMember%d", memberCount);
736 curContext = statement.compound.context;
737 context = PushContext();
739 args = MkListOne(MkExpIdentifier(MkIdentifier((member.type == unionMember) ? "unionMember" : "structMember")));
742 switch(member.memberAccess)
745 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
748 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
752 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
756 compound = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("DataMember")),
757 MkListOne(MkInitDeclarator(/*MkDeclaratorPointer(MkPointer(null, null), */MkDeclaratorIdentifier(MkIdentifier(memberName))/*)*/,
758 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("eMember_New")), args)))))), MkList());
759 compound.compound.context = context;
763 // Class class / DataMember member
764 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
766 // DataMember dataMember
767 ListAdd(args, MkExpIdentifier(MkIdentifier(memberName)));
769 RegisterMembersAndProperties((Class)member, true, memberName, compound);
772 stmt = MkExpressionStmt(MkListOne(
773 MkExpCall(MkExpIdentifier(MkIdentifier("eMember_AddMember")), args)));
775 stmt = MkExpressionStmt(MkListOne(
776 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMember")), args)));
778 ListAdd(compound.compound.statements, stmt);
782 ListAdd(statement.compound.statements, compound);
786 lastOffset = member.offset + member.memberOffset;
790 privateMembers = true;
795 ClassProperty classProperty;
797 // Watchable properties
798 for(prop = regClass.membersAndProperties.first; prop; prop = prop.next)
800 if(prop.isProperty && prop.isWatchable)
803 char name[1024], nameM[1024];
805 strcpy(name, "__ecereProp_");
806 FullClassNameCat(name, regClass.fullName, true);
808 FullClassNameCat(name, prop.name, false);
809 // strcat(name, prop.name);
810 MangleClassName(name);
812 strcpy(nameM, "__ecerePropM_");
813 FullClassNameCat(nameM, regClass.fullName, true);
815 FullClassNameCat(nameM, prop.name, false);
816 // strcat(nameM, prop.name);
817 MangleClassName(nameM);
819 args = MkListOne(MkExpCondition(MkExpIdentifier(MkIdentifier(nameM)), MkListOne(MkExpIdentifier(MkIdentifier(nameM))), MkExpIdentifier(MkIdentifier(name))));
820 stmt = MkExpressionStmt(MkListOne(
821 MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_Watchable")), args)));
822 ListAdd(registerModuleBody.compound.statements, stmt);
826 // Add Class Properties
827 for(classProperty = (ClassProperty)regClass.classProperties.first; classProperty; classProperty = (ClassProperty)((BTNode)classProperty).next)
829 OldList * args = MkList();
831 char * string = QMkString(classProperty.name);
834 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
837 ListAdd(args, MkExpString(string));
842 char * string = QMkString(classProperty.dataTypeString);
843 ListAdd(args, MkExpString(string));
847 if(classProperty.Set)
849 strcpy(name, "__ecereClassProp_");
850 FullClassNameCat(name, regClass.fullName, true);
851 strcat(name, "_Set_");
852 strcat(name, classProperty.name);
853 MangleClassName(name);
854 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
857 ListAdd(args, MkExpConstant("0"));
859 if(classProperty.Get)
861 strcpy(name, "__ecereClassProp_");
862 FullClassNameCat(name, regClass.fullName, true);
863 strcat(name, "_Get_");
864 strcat(name, classProperty.name);
865 MangleClassName(name);
867 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
870 ListAdd(args, MkExpConstant("0"));
872 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddClassProperty")), args)));
873 ListAdd(registerModuleBody.compound.statements, stmt);
878 extern External curExternal;
880 void GetNameSpaceString(NameSpace ns, char * string)
883 GetNameSpaceString(ns.parent, string);
886 strcat(string, ns.name);
887 strcat(string, "::");
891 // *******************************************************************
892 static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol, OldList baseSpecs, OldList enumValues, OldList defs, External external, AccessMode declMode)
895 Class regClass = symbol.registered;
899 classType = regClass.type;
900 if(classType == enumClass && enumValues && (inCompiler || !buildingECERECOMModule))
903 for(e = enumValues.first; e; e = e.next)
912 e.exp.destType = destType;
914 // Set parsingType to avoid producing errors
916 ProcessExpressionType(e.exp);
921 destType.kind = TypeKind::classType;
922 destType._class = symbol;
923 ProcessExpressionType(e.exp);
925 if(e.exp.type == identifierExp && e.exp.expType && e.exp.identifier && e.exp.identifier.string && e.exp.expType.kind == enumType)
927 // Resolve enums here
929 char * string = e.exp.identifier.string;
930 for(l = e.exp.expType.members.first; l; l = l.next)
932 if(!strcmp(l.name, string))
936 FreeExpContents(e.exp);
937 e.exp.type = constantExp;
938 e.exp.constant = PrintUInt((uint)l.data);
939 FreeType(e.exp.expType);
940 e.exp.expType = ProcessTypeString("uint", false);
947 ComputeExpression(e.exp);
948 if(e.exp.isConstant && /*e.exp.expType.kind == intType*/ e.exp.type == constantExp)
950 Operand op = GetOperand(e.exp);
952 // TODO: 64 BIT ENUM SUPPORT...
955 case charType: value = op.c; break;
956 case shortType: value = op.s; break;
957 default: value = op.i;
960 // value = op.i; //strtol(e.exp.string, null, 0);
961 eEnum_AddFixedValue(regClass, e.id.string, value);
965 eEnum_AddValue(regClass, e.id.string);
968 eEnum_AddValue(regClass, e.id.string);
970 // Fix up derivatives enums largest
972 EnumClassData baseData = regClass.data;
974 for(deriv = regClass.derivatives.first; deriv; deriv = deriv.next)
976 Class c = deriv.data;
977 if(c && c.type == enumClass)
979 EnumClassData data = c.data;
980 data.largest = baseData.largest;
986 // Process all functions
987 if(definitions != null)
991 for(def = definitions.first; def; def = def.next)
993 if(def.type == propertyWatchClassDef && def.propertyWatch)
995 PropertyWatch propWatch = def.propertyWatch;
997 char watcherName[1024];
999 Statement stmt = MkExpressionStmt(MkList());
1002 sprintf(watcherName,"__ecerePropertySelfWatcher_%d", propWatcherID++);
1003 for(propID = propWatch.properties->first; propID; propID = propID.next)
1005 strcat(watcherName, "_");
1006 strcat(watcherName, propID.string);
1009 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
1010 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)), MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null)));
1011 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, decl, null);
1012 ProcessClassFunctionBody(func, propWatch.compound);
1014 // TESTING WITH SAME SYMBOL ID AS CLASS
1015 decl.symbol = Symbol
1018 idCode = symbol.idCode;
1020 excludedSymbols->Add(decl.symbol);
1022 func.id = symbol.id;
1023 func.idCode = symbol.idCode;
1024 func.dontMangle = true;
1026 // Create a declaration above for constructor to see
1028 External externalDecl = MkExternalDeclaration(null);
1030 OldList * specifiers = MkList();
1031 ListAdd(specifiers, MkSpecifier(STATIC));
1032 ListAdd(specifiers, MkSpecifier(VOID));
1034 ast->Insert(curExternal.prev, externalDecl);
1036 decl = MkDeclaration(specifiers,
1037 MkListOne(MkInitDeclarator(MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
1038 MkListOne(MkTypeName(MkListOne(MkSpecifierName(regClass.fullName)), null))), null)));
1039 externalDecl.declaration = decl;
1040 if(decl.symbol && !decl.symbol.methodExternal)
1042 decl.symbol.methodExternal = externalDecl;
1044 // PATCHED THIS, 2 SYMBOLS WERE THERE.. THIS ONE HAD AN ID TOO BIG
1045 decl.symbol.id = symbol.id;
1046 decl.symbol.idCode = symbol.idCode;
1050 propWatch.compound = null;
1051 definitions.Insert(null, MkClassDefFunction(func));
1053 for(propID = propWatch.properties->first; propID; propID = propID.next)
1055 Property prop = eClass_FindProperty(regClass, propID.string, privateModule);
1058 // eProperty_SelfWatch(_class, name, callback);
1059 OldList * args = MkList();
1060 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1062 char * s = QMkString(propID.string);
1063 ListAdd(args, MkExpString(s));
1066 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
1068 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
1071 Compiler_Error($"Property %s not found in class %s\n", propID.string, regClass.fullName);
1073 FreePropertyWatch(def.propertyWatch);
1074 def.propertyWatch = (PropertyWatch)stmt; // Store this here to use it after CreateRegisterModuleBody is done
1076 // ListAdd(statements, stmt);
1081 for(def = definitions.first; def; def = def.next)
1083 if(def.type == functionClassDef)
1085 ProcessClassFunction(regClass, def.function, defs, external.prev, declMode == staticAccess);
1090 // Make the RegisterClass section
1092 if(inCompiler && symbol.id != MAXINT && regClass)
1095 OldList * args = MkList();
1098 const char * registerFunction = null;
1099 AccessMode inheritanceAccess = publicAccess;
1101 CreateRegisterModuleBody();
1103 curExternal = registerModuleExternal;
1106 switch(regClass.type)
1108 case structClass: ListAdd(args, MkExpIdentifier(MkIdentifier("structClass"))); break;
1109 case bitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("bitClass"))); break;
1110 case enumClass: ListAdd(args, MkExpIdentifier(MkIdentifier("enumClass"))); break;
1111 case noHeadClass: ListAdd(args, MkExpIdentifier(MkIdentifier("noHeadClass"))); break;
1112 case unitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("unitClass"))); break;
1113 case normalClass: ListAdd(args, MkExpIdentifier(MkIdentifier("normalClass"))); break;
1117 char nameSpace[1024] = "";
1118 char className[1024] = "";
1120 GetNameSpaceString(regClass.nameSpace, nameSpace);
1122 if(declMode == staticAccess)
1124 GetLastDirectory(sourceFile, className);
1125 ChangeCh(className, '.', '_');
1126 strcat(className, "}");
1128 strcat(className, nameSpace);
1129 strcat(className, regClass.name);
1130 string = QMkString(className);
1131 ListAdd(args, MkExpString(string));
1137 char * string = QMkString(regClass.base.name);
1138 ListAdd(args, regClass.base ? MkExpString(string) :
1139 MkExpConstant("0"));
1144 if(baseSpecs != null)
1146 Type baseType = ProcessType(baseSpecs, null);
1147 if(baseType.kind != structType && baseType.kind != unionType)
1149 char baseName[1024] = "";
1151 if(baseType.kind == TypeKind::classType && baseType._class && baseType._class.isStatic)
1153 // TODO: Handle static classes and complex declarators...
1154 GetLastDirectory(sourceFile, baseName);
1155 ChangeCh(baseName, '.', '_');
1156 strcat(baseName, "}");
1157 strcat(baseName, baseType._class.string);
1160 PrintType(baseType, baseName, false, true);
1162 string = QMkString(baseName);
1163 ListAdd(args, MkExpString(string));
1167 ListAdd(args, MkExpConstant("0"));
1169 if(((Specifier)baseSpecs.first).type == baseSpecifier && ((Specifier)baseSpecs.first).specifier == PRIVATE)
1170 inheritanceAccess = privateAccess;
1173 ListAdd(args, MkExpConstant("0"));
1175 //ListAdd(args, class.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1176 //MkSpecifierName(class.structName)), null)) : MkExpConstant("0"));
1178 if(regClass.type == structClass || regClass.type == normalClass || regClass.type == noHeadClass)
1180 // Check if we have a data member in this class
1181 DataMember member = null;
1184 for(base = regClass.base; base && base.type != systemClass; base = base.next)
1186 for(member = base.membersAndProperties.first; member; member = member.next)
1187 if(!member.isProperty)
1194 if(regClass.type == structClass && symbol.declaredStruct && member)
1196 char baseStructName[1024];
1197 baseStructName[0] = 0;
1198 // TESTING THIS HERE
1199 // FullClassNameCat(baseStructName, regClass.base.fullName, false);
1200 strcpy(baseStructName, (regClass.base.templateClass ? regClass.base.templateClass : regClass.base).fullName);
1202 ListAdd(args, MkExpOp(
1203 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)), '-',
1204 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(baseStructName), null)), null))));
1207 ListAdd(args, symbol.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1208 MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)) : MkExpConstant("0"));
1212 ListAdd(args, MkExpConstant("0"));
1215 //if(regClass.type == normalClass)
1217 char classDataStructName[1024];
1218 strcpy(classDataStructName, "__ecereClassData_");
1219 FullClassNameCat(classDataStructName, symbol.string, false);
1221 ListAdd(args, symbol.classData ? MkExpTypeSize(MkTypeName(MkListOne(
1222 MkStructOrUnion(structSpecifier, MkIdentifier(classDataStructName), null)), null)) : MkExpConstant("0"));
1225 // TODO: Support Class Data for all other types of classes
1226 ListAdd(args, MkExpConstant("0"));
1229 if(regClass.type == normalClass || regClass.type == noHeadClass)
1232 ListAdd(args, symbol.needConstructor ?
1233 MkExpIdentifier(MkIdentifier(symbol.constructorName)) :
1234 MkExpConstant("0"));
1236 ListAdd(args, symbol.needDestructor ?
1237 MkExpIdentifier(MkIdentifier(symbol.destructorName)) :
1238 MkExpConstant("0"));
1242 // TODO: Support Constructors / Destructors for structs
1245 ListAdd(args, MkExpConstant("0"));
1247 ListAdd(args, MkExpConstant("0"));
1251 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1257 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1260 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1264 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1269 switch(inheritanceAccess)
1272 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1276 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1280 registerFunction = "eSystem_RegisterClass";
1282 stmt = MkExpressionStmt(MkListOne(
1283 MkExpOp(MkExpIdentifier(MkIdentifier("class")), '=',
1284 MkExpCall((exp = MkExpIdentifier(MkIdentifier(registerFunction))), args))));
1286 ListAdd(registerModuleBody.compound.statements, stmt);
1289 stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className)))),
1290 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1291 MkExpIdentifier(MkIdentifier("class"))))), null);
1294 stmt = MkIfStmt(MkListOne(
1296 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
1297 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application"))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1298 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1299 MkExpIdentifier(MkIdentifier("class"))))), null);
1301 stmt = MkIfStmt(MkListOne(
1302 MkExpOp(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1303 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1304 MkExpIdentifier(MkIdentifier("class"))))), null);
1307 ListAdd(registerModuleBody.compound.statements, stmt);
1309 if(external && external.type == classExternal && external._class.deleteWatchable)
1311 args = MkListOne(MkExpIdentifier(MkIdentifier("class")));
1312 stmt = MkExpressionStmt(MkListOne(
1313 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DestructionWatchable")), args)));
1314 ListAdd(registerModuleBody.compound.statements, stmt);
1317 // Add Virtual Methods
1320 Class base = regClass.base;
1322 for(c = 0; c<base.vTblSize; c++)
1324 Symbol method = (Symbol)regClass._vTbl[c];
1325 if((void *) method != DummyMethod && base._vTbl[c] != (void *)method && method.methodExternal) // TOLOOKAT: Module check here?
1327 External external = method.methodExternal;
1328 OldList * args = MkList();
1329 Identifier id = external.function ? GetDeclId(external.function.declarator) : null;
1332 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1335 //char * string = QMkString(method.string);
1337 char * string = QMkString(method.method.name);
1338 ListAdd(args, MkExpString(string));
1342 ListAdd(args, MkExpConstant("0"));
1344 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1348 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1350 exp.expType = Type { refCount = 1 };
1351 stmt = MkExpressionStmt(MkListOne(
1352 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1353 ListAdd(registerModuleBody.compound.statements, stmt);
1358 // Add Virtual Methods in order
1361 for(c = regClass.base ? regClass.base.vTblSize : 0; c < regClass.vTblSize; c++)
1363 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1365 if(method.type == virtualMethod && method._class == regClass && method.vid == c)
1370 //External external = method->symbol ? ((Symbol)method.symbol).methodExternal : null;
1371 External external = method.symbol ? ((Symbol)method.symbol).methodCodeExternal : null;
1372 OldList * args = MkList();
1373 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1376 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1379 char * string = QMkString(method.name);
1380 ListAdd(args, MkExpString(string));
1385 char * string = QMkString(method.dataTypeString);
1386 ListAdd(args, MkExpString(string));
1390 if(id && external.function.body)
1392 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(id.string))));
1393 exp.expType = Type { refCount = 1 };
1397 ListAdd(args, (exp = MkExpConstant("0")));
1401 switch(method.memberAccess)
1404 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1407 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1411 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1415 //sprintf(name, "__ecereVMethodID_%s_%s", method._class.fullName, method.name);
1416 strcpy(name, "__ecereVMethodID_");
1417 FullClassNameCat(name, method._class.fullName, false);
1419 strcat(name, method.name);
1421 exp = /*MkExpPointer(*/MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddVirtualMethod")), args)/*, MkIdentifier("vid"))*/;
1423 exp->expType = eSystem_New(sizeof(Type));
1424 exp->expType->refCount++;
1425 exp->expType->isSigned = true;
1426 exp->expType->kind = TypeInt;
1429 stmt = MkExpressionStmt(MkListOne(/*
1430 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', */exp/*)*/));
1432 DeclareMethod(method, name);
1434 ListAdd(registerModuleBody.compound.statements, stmt);
1441 // Add Public Methods (all for now)
1442 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1444 if(method.type == virtualMethod && method._class == regClass);
1445 else if(method.memberAccess == publicAccess || !method.dataTypeString)
1447 //External external = method.symbol ? ((Symbol )method.symbol).methodExternal : null;
1448 External external = method.symbol ? ((Symbol )method.symbol).methodCodeExternal : null;
1449 OldList * args = MkList();
1450 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1453 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1456 char * string = QMkString(method.name);
1457 ListAdd(args, MkExpString(string));
1462 char * string = QMkString(method.dataTypeString);
1463 ListAdd(args, MkExpString(string));
1467 if(id && external.function.body)
1469 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1471 exp.expType = Type { refCount = 1 };
1475 ListAdd(args, (exp = MkExpConstant("0")));
1479 switch(method.memberAccess)
1482 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1485 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1489 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1493 stmt = MkExpressionStmt(MkListOne(
1494 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1495 ListAdd(registerModuleBody.compound.statements, stmt);
1499 RegisterMembersAndProperties(regClass, false, "class", registerModuleBody);
1501 // Add Enumeration Values
1502 if(classType == enumClass)
1505 Class enumClass = eSystem_FindClass(privateModule, "enum");
1506 EnumClassData e = ACCESS_CLASSDATA(regClass, enumClass);
1508 for(value = e.values.first; value; value = value.next)
1510 OldList * args = MkList();
1513 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1516 char * string = QMkString(value.name);
1517 ListAdd(args, MkExpString(string));
1523 // TODO: Support 64 bit enums
1524 sprintf(temp, "%d", (int)value.data);
1525 ListAdd(args, MkExpConstant(temp));
1528 stmt = MkExpressionStmt(MkListOne(
1529 MkExpCall(MkExpIdentifier(MkIdentifier("eEnum_AddFixedValue")), args)));
1530 ListAdd(registerModuleBody.compound.statements, stmt);
1534 // Add Template Parameters
1535 if(symbol.templateParams)
1537 TemplateParameter param;
1538 for(param = symbol.templateParams->first; param; param = param.next)
1540 OldList * args = MkList();
1543 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1547 char * string = QMkString(param.identifier.string);
1548 ListAdd(args, MkExpString(string));
1553 ListAdd(args, MkExpIdentifier(MkIdentifier((param.type == type) ? "type" : ((param.type == identifier) ? "identifier" : "expression"))));
1561 char * typeString = param.dataType ? StringFromSpecDecl(param.dataType.specifiers, param.dataType.decl) : null;
1562 char * string = QMkString(typeString);
1563 ListAdd(args, MkExpString(string));
1570 char memberTypeString[132] = "TemplateMemberType::";
1571 bool needClass = true;
1573 param.memberType.OnGetString(memberTypeString + strlen(memberTypeString), null, &needClass);
1575 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)),
1576 MkExpIdentifier(MkIdentifier(memberTypeString))));
1582 if(param.defaultArgument)
1584 OldList * members = MkList();
1589 char * typeString = param.defaultArgument.templateDatatype ?
1590 StringFromSpecDecl(param.defaultArgument.templateDatatype.specifiers, param.defaultArgument.templateDatatype.decl) : null;
1591 char * string = QMkString(typeString);
1593 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1601 char memberString[1024];
1603 memberString[0] = '\0';
1605 if(param.defaultArgument.identifier._class)
1607 if(param.defaultArgument.identifier._class.type == templateTypeSpecifier)
1608 strcpy(memberString, param.defaultArgument.identifier._class.templateParameter.identifier.string);
1609 else if(param.defaultArgument.identifier._class.name)
1610 strcpy(memberString, param.defaultArgument.identifier._class.name);
1613 strcat(memberString, "::");
1615 strcat(memberString, param.defaultArgument.identifier.string);
1617 string = QMkString(memberString);
1619 // TOFIX: UNIONS ARE BROKEN FOR ASSIGNMENTS, USING dataTypeString INSTEAD
1620 // members->Add(MkMemberInit(MkListOne(MkIdentifier("memberString")), MkInitializerAssignment(MkExpString(string))));
1621 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1629 OldList * ids = MkList();
1631 char * string = null;
1633 //ProcessExpressionType(param.defaultArgument.expression);
1634 //ComputeExpression(param.defaultArgument.expression);
1636 op = GetOperand(param.defaultArgument.expression);
1637 ui64String = PrintUInt64(op.ui64);
1638 ids->Add(MkIdentifier("expression"));
1639 ids->Add(MkIdentifier("ui64"));
1641 //string = QMkString(ui64String);
1642 members->Add(MkMemberInit(ids, MkInitializerAssignment(MkExpConstant(ui64String))));
1649 ListAdd(args, MkExpInstance(MkInstantiation(MkSpecifierName("ClassTemplateArgument"), null,
1650 MkListOne(MkMembersInitList(members)))));
1653 ListAdd(args, MkExpIdentifier(MkIdentifier("null")));
1655 stmt = MkExpressionStmt(MkListOne(
1656 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddTemplateParameter")), args)));
1657 ListAdd(registerModuleBody.compound.statements, stmt);
1659 stmt = MkExpressionStmt(MkListOne(
1660 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DoneAddingTemplateParameters")),
1661 MkListOne(MkExpIdentifier(MkIdentifier("class"))))));
1662 ListAdd(registerModuleBody.compound.statements, stmt);
1665 if(definitions != null)
1667 for(def = definitions.first; def; def = def.next)
1669 if(def.type == propertyWatchClassDef && def.propertyWatch)
1671 ListAdd(registerModuleBody.compound.statements, (Statement)def.propertyWatch);
1672 def.propertyWatch = null;
1674 else if(def.type == classDesignerClassDef)
1677 char className[1024];
1678 sprintf(className, "__ecereClass_%s", def.designer);
1679 MangleClassName(className);
1681 DeclareClass(FindClass(def.designer), className);
1685 char * s = QMkString(def.designer);
1686 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1687 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
1688 MkExpString(s)))), null);
1691 ListAdd(registerModuleBody.compound.statements, stmt);
1693 else if(def.type == classNoExpansionClassDef)
1695 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1696 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("noExpansion")), '=',
1697 MkExpConstant("1")))), null);
1698 ListAdd(registerModuleBody.compound.statements, stmt);
1700 else if(def.type == classFixedClassDef)
1702 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1703 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("fixed")), '=',
1704 MkExpConstant("1")))), null);
1705 ListAdd(registerModuleBody.compound.statements, stmt);
1707 regClass.fixed = true;
1709 else if(def.type == designerDefaultPropertyClassDef)
1711 char * s = QMkString(def.defaultProperty.string);
1712 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1713 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=',
1714 MkExpString(s)))), null);
1715 ListAdd(registerModuleBody.compound.statements, stmt);
1718 else if(def.type == classPropertyValueClassDef)
1720 classPropValues.Add(ClassPropertyValue { regClass = regClass, id = def.id, exp = def.initializer.exp });
1722 def.initializer.exp = null;
1730 class ClassPropertyValue
1736 ~ClassPropertyValue()
1742 static List<ClassPropertyValue> classPropValues { };
1744 public void ProcessClassDefinitions()
1746 External external, next;
1748 CreateRegisterModuleBody();
1751 // (Need to do those things after in case something is not yet defined)
1752 for(external = ast->first; external; external = next)
1754 next = external.next;
1755 curExternal = external;
1756 if(external.type == classExternal)
1758 ClassDefinition _class = external._class;
1759 if(_class.definitions)
1761 ProcessClass(normalClass, _class.definitions, _class.symbol, _class.baseSpecs, null, ast, external, _class.declMode);
1765 ast->Remove(external);
1766 FreeExternal(external);
1769 else if(external.type == functionExternal)
1771 bool setStaticMethod = false;
1773 if(external.symbol && !external.symbol.type.thisClass && !external.symbol.type.staticMethod)
1775 // TOCHECK: Where do we actually need this to be set?
1776 external.symbol.type.staticMethod = true;
1777 setStaticMethod = true;
1782 FunctionDefinition function = external.function;
1786 if(!strcmp(function.declarator.symbol.string, "__on_register_module"))
1788 ListAdd(registerModuleBody.compound.statements, function.body);
1789 function.body.compound.context.parent = registerModuleBody.compound.context;
1790 ast->Remove(external);
1791 function.body = null;
1792 FreeExternal(external);
1796 if(function.declMode != privateAccess && function.declMode != publicAccess) continue;
1800 CreateRegisterModuleBody();
1804 char * string = QMkString(function.declarator.symbol.string);
1805 ListAdd(args, MkExpString(string));
1812 char type[1024] = "";
1813 // We don't want functions to be marked as static methods
1815 function.declarator.symbol.type.staticMethod = false;
1816 PrintType(function.declarator.symbol.type, type, true, true);
1818 function.declarator.symbol.type.staticMethod = true;
1819 string = QMkString(type);
1820 ListAdd(args, MkExpString(string));
1826 ListAdd(args, MkExpIdentifier(MkIdentifier(function.declarator.symbol.string)));
1830 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1833 switch(function.declMode)
1836 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1839 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1843 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1847 stmt = MkExpressionStmt(MkListOne(
1848 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterFunction"))), args)));
1850 ListAdd(registerModuleBody.compound.statements, stmt);
1853 else if(external.type == declarationExternal)
1855 Declaration declaration = external.declaration;
1859 if(external.symbol.type && external.symbol.type.kind == functionType && !external.symbol.type.thisClass)
1860 external.symbol.type.staticMethod = true;
1863 if(external.symbol && declaration.type == initDeclaration)
1865 if(declaration.specifiers)
1867 Specifier specifier;
1868 bool removeExternal = false;
1870 for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
1872 if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
1873 (declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
1875 Symbol symbol = FindClass(specifier.id.string);
1878 ClassType classType;
1879 if(specifier.type == enumSpecifier)
1880 classType = enumClass;
1882 classType = structClass;
1884 removeExternal = true;
1885 // Transfer Context over to Symbol
1886 symbol.ctx = specifier.ctx;
1887 specifier.ctx = null;
1889 ProcessClass(classType, specifier.definitions, symbol, specifier.baseSpecs, specifier.list,ast, external, declaration.declMode);
1893 if(inCompiler && removeExternal)
1895 ast->Remove(external);
1896 FreeExternal(external);
1900 else if(declaration.type == defineDeclaration)
1902 if(inCompiler && declaration.declMode != staticAccess)
1905 OldList * args = MkList();
1907 CreateRegisterModuleBody();
1911 char * string = QMkString(declaration.id.string);
1912 ListAdd(args, MkExpString(string));
1919 char type[1024] = "";
1920 PrintExpression(declaration.exp, type);
1921 string = QMkString(type);
1922 ListAdd(args, MkExpString(string));
1927 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1930 switch(declaration.declMode)
1933 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1936 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1940 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1944 stmt = MkExpressionStmt(MkListOne(
1945 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterDefine"))), args)));
1947 ListAdd(registerModuleBody.compound.statements, stmt);
1953 // Set the class properties at the very end
1954 for(v : classPropValues)
1956 OldList * findClassArgs = MkList();
1957 OldList * args = MkList();
1958 Statement compoundStmt;
1964 ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
1965 s = QMkString(v.regClass.name);
1966 ListAdd(findClassArgs, MkExpString(s));
1969 ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
1970 s = QMkString(v.id.string);
1971 ListAdd(args, MkExpString(s));
1973 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), v.exp));
1974 compoundStmt = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
1975 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("_class")),
1976 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eSystem_FindClass")), findClassArgs)))))),
1977 MkListOne(MkExpressionStmt(MkListOne(
1978 MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eClass_SetProperty")), args)))));
1979 compoundStmt.compound.context = Context { parent = registerModuleBody.compound.context };
1980 ListAdd(registerModuleBody.compound.statements, compoundStmt);
1983 classPropValues.Free();