3 // UNTIL IMPLEMENTED IN GRAMMAR
4 #define ACCESS_CLASSDATA(_class, baseClass) \
5 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
7 #define YYLTYPE Location
10 static Statement registerModuleBody;
11 static External registerModuleExternal;
12 static Statement unregisterModuleBody;
13 static External unregisterModuleExternal;
15 extern int propWatcherID;
17 bool buildingECERECOM = false;
18 public void SetBuildingEcereCom(bool b) { buildingECERECOM = b; } public bool GetBuildingEcereCom() { return buildingECERECOM; }
19 bool buildingECERECOMModule = false;
20 public void SetBuildingEcereComModule(bool b) { buildingECERECOMModule = b; } public bool GetBuildingEcereComModule() { return buildingECERECOMModule; }
22 // This will also be called by the instance processor to make the instance methods... (pass 1.5)
23 External ProcessClassFunction(Class owningClass, ClassFunction func, OldList defs, External after, bool makeStatic)
27 External external = null;
29 if(defs && func.declarator)
31 FunctionDefinition function = null;
37 func.specifiers = MkList();
38 // Add static to the specifiers
42 for(s = func.specifiers->first; s; s = s.next)
43 if(s.type == baseSpecifier && s.specifier == STATIC)
46 func.specifiers->Insert(null, MkSpecifier(STATIC));
50 propSymbol = func.declarator.symbol;
52 ReplaceThisClassSpecifiers(func.specifiers, owningClass);
54 if(propSymbol.externalGet == (External)func)
55 func.declarator.symbol = null;
56 else if(propSymbol.externalSet == (External)func)
57 func.declarator.symbol = null;
58 else if(propSymbol.externalIsSet == (External)func)
59 func.declarator.symbol = null;
63 /*FunctionDefinition*/ function = _MkFunction(func.specifiers, func.declarator, null, false);
64 function.propSet = func.propSet;
65 function.type = func.type;
66 if(func.type) func.type.refCount++;
67 ProcessFunctionBody(function, func.body);
68 external = MkExternalFunction(function);
74 strcpy(className, "__ecereClass_");
75 FullClassNameCat(className, owningClass.fullName, true);
76 DeclareClass(external, owningClass.symbol, className);
80 external.symbol = func.declarator.symbol;
81 external.function._class = func._class;
84 symbol = func.declarator.symbol;
89 Method method = func.declarator.symbol.method;
90 func.declarator.symbol.methodExternal = external;
92 if(method && method.symbol)
93 ((Symbol)method.symbol).methodCodeExternal = external;
95 if(method && method.type == virtualMethod)
98 ProcessMethodType(method);
100 methodDataType = method.dataType;
102 // Do type checking here of type against method.dataType
103 // ThisClass must be the owning class for types not specified, static for static, or inherit from method's ThisClass is specified
104 // If not specified, defaults to ThisClass if ThisClass specified in method, otherwise overiding class or static
108 if(!type.staticMethod && !type.thisClass && !type.thisClassTemplate)
110 if(method.dataType.thisClassTemplate)
112 if(owningClass.templateArgs)
114 ClassTemplateArgument * arg = FindTemplateArg(owningClass, method.dataType.thisClassTemplate);
115 type.byReference = method.dataType.byReference;
117 methodDataType = ProcessTypeString(method.dataTypeString, false);
118 type.thisClass = methodDataType.thisClass = arg ? FindClass(arg->dataTypeString) : null;
121 else if(method.dataType.staticMethod)
122 type.staticMethod = true;
123 else if(method.dataType.thisClass)
125 type.thisClass = method.dataType.thisClass;
126 type.byReference = method.dataType.byReference;
130 if(!owningClass.symbol)
131 owningClass.symbol = FindClass(owningClass.fullName);
133 type.thisClass = owningClass.symbol;
134 // WORKING ON THIS TO SUPPORT : pass.NotifyClicked(this, pass, 0, 0, key.modifiers);
135 type.extraParam = true;
140 if(!MatchTypes(type, methodDataType, null, owningClass, method._class /*owningClass*/, true, true, true, false, true))
143 // MatchTypes(type, methodDataType, null, owningClass, owningClass, true, true, true, false);
145 Compiler_Error($"Incompatible virtual function %s\n", method.name);
149 // Mark typed_object/any_object parameters as such according to method type
151 Declarator funcDecl = GetFuncDecl(func.declarator);
152 if(funcDecl.function.parameters && funcDecl.function.parameters->first)
154 TypeName param = funcDecl.function.parameters->first;
156 for(typeParam = methodDataType.params.first; typeParam && param; typeParam = typeParam.next)
158 if(typeParam.classObjectType)
160 param.classObjectType = typeParam.classObjectType;
161 if(param.declarator && param.declarator.symbol)
162 param.declarator.symbol.type.classObjectType = typeParam.classObjectType;
164 param = param ? param.next : null;
168 if(methodDataType != method.dataType)
169 FreeType(methodDataType);
174 if(!type.staticMethod && !type.thisClass)
176 if(owningClass && !owningClass.symbol)
177 owningClass.symbol = FindClass(owningClass.fullName);
179 type.thisClass = owningClass ? FindClass(owningClass.fullName) : null;
185 // TESTING THIS HERE: (Implementing Class Properties)
186 if(symbol.type && !symbol.type.staticMethod && !symbol.type.thisClass)
188 if(!owningClass.symbol)
189 owningClass.symbol = FindClass(owningClass.fullName);
190 symbol.type.thisClass = owningClass.symbol;
193 // Those type of classes don't need a this parameter for Set methods, null thisClass before changing the externals
194 if(propSymbol.externalSet == (External)func && propSymbol._property && propSymbol._property.conversion)
196 if(symbol.type.thisClass && symbol.type.classObjectType != classPointer)
198 // TODO: Perhaps improve this so as to support both "this =" and "return " syntax for all types of classes
199 if(owningClass.type != structClass)
200 //function.propertyNoThis = true;
201 symbol.type.thisClass = null;
206 if(propSymbol.externalGet == (External)func)
208 propSymbol.externalGet = external;
210 else if(propSymbol.externalSet == (External)func)
212 propSymbol.externalSet = external;
214 else if(propSymbol.externalIsSet == (External)func)
216 propSymbol.externalIsSet = external;
220 // Constructor destructor
221 //symbol.type = Type { };
228 func.declarator = null;
229 func.specifiers = null;
232 defs.Insert(after, external);
236 Method method = func.declarator.symbol.method;
237 if(method && method.symbol)
238 ((Symbol)method.symbol).methodCodeExternal = null;
239 if(func.declarator.symbol && func.declarator.symbol.methodExternal == external)
240 func.declarator.symbol.methodExternal = null;
242 //external.function = null;
243 func.declarator = null;
244 func.specifiers = null;
246 FreeExternal(external); // Free external here?
251 globalContext /*curContext*/.symbols.Remove((BTNode)symbol);
252 excludedSymbols->Add(symbol);
255 defs.Insert(after, external);
257 external.function.declarator = CopyDeclarator(external.function.declarator);
258 external.function.specifiers = CopyList(external.function.specifiers, CopySpecifier);
259 external.function.body = null;
265 void CreateRegisterModuleBody()
267 if(!registerModuleBody && inCompiler)
269 char registerName[1024], moduleName[MAX_FILENAME];
270 OldList * specifiers;
271 Declarator declarator;
272 TypeName moduleParam;
274 registerModuleBody = MkCompoundStmt(MkList(), MkList());
275 registerModuleBody.compound.context = Context { parent = globalContext };
277 ListAdd(registerModuleBody.compound.declarations,
278 MkDeclaration((specifiers = MkListOne(MkSpecifierName("ecere::com::Class"))),
279 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("class")), null))));
280 // Avoid unused warning here
281 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
283 specifiers = MkList();
284 ListAdd(specifiers, MkSpecifier(VOID));
286 moduleParam = MkTypeName(MkListOne(MkSpecifierName("Module")),
287 MkDeclaratorIdentifier(MkIdentifier("module")));
289 GetLastDirectory(outputFile, moduleName);
290 StripExtension(moduleName);
291 FixModuleName(moduleName);
292 sprintf(registerName, "__ecereRegisterModule_%s", moduleName);
294 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
295 MkListOne(moduleParam));
298 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
299 ProcessFunctionBody(function, registerModuleBody);
300 function.declMode = defaultAccess;
301 if(!ast) ast = MkList();
302 ListAdd(ast, (registerModuleExternal = MkExternalFunction(function)));
303 DeclareStruct(registerModuleExternal, "ecere::com::Instance", false, true);
304 DeclareStruct(registerModuleExternal, "ecere::com::Module", false, true);
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(MkSpecifierName("Module")),
323 MkDeclaratorIdentifier(MkIdentifier("module")));
325 GetLastDirectory(outputFile, moduleName);
326 StripExtension(moduleName);
327 FixModuleName(moduleName);
328 sprintf(registerName, "__ecereUnregisterModule_%s", moduleName);
330 declarator = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(registerName)),
331 MkListOne(moduleParam));
334 FunctionDefinition function = _MkFunction(specifiers, declarator, null, false);
335 ProcessFunctionBody(function, unregisterModuleBody);
336 function.declMode = defaultAccess;
337 if(!ast) ast = MkList();
338 ListAdd(ast, (unregisterModuleExternal = MkExternalFunction(function)));
339 DeclareStruct(unregisterModuleExternal, "ecere::com::Instance", false, true);
340 DeclareStruct(unregisterModuleExternal, "ecere::com::Module", false, true);
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 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
388 ListAdd(args, MkExpConstant("0"));
392 strcpy(name, "__ecereProp_");
393 FullClassNameCat(name, regClass.fullName, false);
394 strcat(name, "_Get_");
395 // strcat(name, prop.name);
396 FullClassNameCat(name, prop.name, true);
398 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
401 ListAdd(args, MkExpConstant("0"));
405 switch(prop.memberAccess)
408 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
411 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
415 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
419 strcpy(name, "__ecereProp_");
420 FullClassNameCat(name, regClass.fullName, false);
422 FullClassNameCat(name, prop.name, true);
423 // strcat(name, prop.name);
424 stmt = MkExpressionStmt(MkListOne(
425 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=',
426 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
427 ListAdd(registerModuleBody.compound.statements, stmt);
431 for(member = isMember ? dataMember.members.first : regClass.membersAndProperties.first; member; member = member.next)
433 if(member.isProperty)
435 prop = (Property) member;
437 OldList * args = MkList();
438 char name[1024], nameM[1024];
439 char * string = QMkString(prop.name);
442 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
445 ListAdd(args, MkExpString(string));
450 char * string = QMkString(prop.dataTypeString);
451 ListAdd(args, MkExpString(string));
457 strcpy(name, "__ecereProp_");
458 FullClassNameCat(name, regClass.fullName, false);
459 strcat(name, "_Set_");
460 FullClassNameCat(name, prop.name, true);
461 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
464 ListAdd(args, MkExpConstant("0"));
468 strcpy(name, "__ecereProp_");
469 FullClassNameCat(name, regClass.fullName, false);
470 strcat(name, "_Get_");
471 FullClassNameCat(name, prop.name, true);
472 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
475 ListAdd(args, MkExpConstant("0"));
478 switch(prop.memberAccess)
481 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
484 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
488 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
492 strcpy(name, "__ecereProp_");
493 FullClassNameCat(name, regClass.fullName, false);
495 FullClassNameCat(name, prop.name, true);
497 strcpy(nameM, "__ecerePropM_");
498 FullClassNameCat(nameM, regClass.fullName, false);
500 FullClassNameCat(nameM, prop.name, true);
502 if(prop.dataTypeString)
504 stmt = MkExpressionStmt(MkListOne(
505 MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
506 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args))));
510 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddProperty")), args)));
512 ListAdd(registerModuleBody.compound.statements, stmt);
517 strcpy(name, "__ecereProp_");
518 FullClassNameCat(name, regClass.fullName, true);
519 strcat(name, "_IsSet_");
520 FullClassNameCat(name, prop.name, false);
521 stmt = MkExpressionStmt(MkListOne(
522 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("IsSet")), '=',
523 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpIdentifier(MkIdentifier(name))))));
524 ListAdd(registerModuleBody.compound.statements, stmt);
526 if(prop.symbol && ((Symbol)prop.symbol).propCategory)
528 stmt = MkExpressionStmt(MkListOne(
529 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier(nameM)), MkIdentifier("category")), '=',
530 CopyExpression(((Symbol)prop.symbol).propCategory))));
531 ListAdd(registerModuleBody.compound.statements, stmt);
534 if(prop.dataTypeString)
536 OldList * list = MkList();
537 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', MkExpIdentifier(MkIdentifier(nameM))));
538 ListAdd(list, MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=', MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0"))));
539 // stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(name)))), MkExpressionStmt(list), null);
540 stmt = MkIfStmt(MkListOne(MkExpOp(
541 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
542 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application")))), MkExpressionStmt(list), null);
544 ListAdd(registerModuleBody.compound.statements, stmt);
546 // Unregister 2nd property
547 stmt = MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(nameM)), '=',
548 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null,null), null)), MkExpConstant("0")))));
549 ListAdd(unregisterModuleBody.compound.statements, stmt);
553 else if(member.type == normalMember && !isMember && regClass.type == bitClass)
555 BitMember bitMember = (BitMember) member;
556 OldList * args = MkList();
559 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
563 char * string = QMkString(bitMember.name);
564 ListAdd(args, MkExpString(string));
569 char * string = QMkString(bitMember.dataTypeString);
570 ListAdd(args, MkExpString(string));
576 sprintf(string, "%d", bitMember.size);
577 ListAdd(args, (exp = MkExpConstant(string)));
582 sprintf(string, "%d", bitMember.pos);
583 ListAdd(args, (exp = MkExpConstant(string)));
587 switch(member.memberAccess)
590 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
593 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
597 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
601 stmt = MkExpressionStmt(MkListOne(
602 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddBitMember")), args)));
604 ListAdd(statement.compound.statements, stmt);
606 else if(member.memberAccess == publicAccess || (member.type == normalMember && !member.dataTypeString))
609 // ADD PRIVATE DATA PADDING HERE...
612 uint offset = member.offset - lastOffset;
617 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
622 sprintf(string, "\"__ecerePrivateData%d\"", privateID++);
623 ListAdd(args, MkExpString(string));
628 sprintf(string, "\"byte[%d]\"", offset);
629 ListAdd(args, MkExpString(string));
634 sprintf(string, "%d", offset);
635 ListAdd(args, (exp = MkExpConstant(string)));
639 ListAdd(args, (exp = MkExpConstant("1")));
642 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
644 stmt = MkExpressionStmt(MkListOne(
645 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
647 ListAdd(statement.compound.statements, stmt);
648 privateMembers = false;
651 if(member.type == normalMember)
654 member.dataType = ProcessTypeString(member.dataTypeString, false);
656 ComputeTypeSize(member.dataType);
661 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
665 char * string = QMkString(member.name);
666 ListAdd(args, MkExpString(string));
671 char * string = QMkString(member.dataTypeString);
672 ListAdd(args, MkExpString(string));
678 if(member.dataType.isPointerTypeSize)
680 ListAdd(args, (exp = MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)))));
681 ListAdd(args, (exp = MkExpConstant("0xF000F000") /*MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)))*/));
686 if(member.dataType.kind == classType && member.dataType._class && member.dataType._class.registered && member.dataType._class.registered.offset == 0 &&
687 (member.dataType._class.registered.type == structClass || member.dataType._class.registered.type == noHeadClass || member.dataType._class.registered.type == normalClass))
690 DeclareStruct(registerModuleExternal, member.dataType._class.string, false, true);
691 FullClassNameCat(string, member.dataType._class.string, false);
692 exp = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(string), null)), null));
696 sprintf(string, "%d", member.dataType.size);
697 exp = MkExpConstant(string);
701 if(member.dataType.pointerAlignment)
702 exp = MkExpConstant("0xF000F000");
705 sprintf(string, "%d", member.dataType.alignment);
706 exp = MkExpConstant(string);
713 switch(member.memberAccess)
716 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
719 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
723 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
727 stmt = MkExpressionStmt(MkListOne(
728 MkExpCall(MkExpIdentifier(MkIdentifier(isMember ? "eMember_AddDataMember" : "eClass_AddDataMember")), args)));
730 ListAdd(statement.compound.statements, stmt);
732 lastOffset = member.offset + member.dataType.size;
736 static int memberCount = 0;
740 char memberName[256];
741 sprintf(memberName, "dataMember%d", memberCount);
744 curContext = statement.compound.context;
745 context = PushContext();
747 args = MkListOne(MkExpIdentifier(MkIdentifier((member.type == unionMember) ? "unionMember" : "structMember")));
750 switch(member.memberAccess)
753 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
756 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
760 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
764 compound = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("DataMember")),
765 MkListOne(MkInitDeclarator(/*MkDeclaratorPointer(MkPointer(null, null), */MkDeclaratorIdentifier(MkIdentifier(memberName))/*)*/,
766 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("eMember_New")), args)))))), MkList());
767 compound.compound.context = context;
771 // Class class / DataMember member
772 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
774 // DataMember dataMember
775 ListAdd(args, MkExpIdentifier(MkIdentifier(memberName)));
777 RegisterMembersAndProperties((Class)member, true, memberName, compound);
780 stmt = MkExpressionStmt(MkListOne(
781 MkExpCall(MkExpIdentifier(MkIdentifier("eMember_AddMember")), args)));
783 stmt = MkExpressionStmt(MkListOne(
784 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMember")), args)));
786 ListAdd(compound.compound.statements, stmt);
790 ListAdd(statement.compound.statements, compound);
794 lastOffset = member.offset + member.memberOffset;
798 privateMembers = true;
803 ClassProperty classProperty;
805 // Watchable properties
806 for(prop = regClass.membersAndProperties.first; prop; prop = prop.next)
808 if(prop.isProperty && prop.isWatchable)
811 char name[1024], nameM[1024];
813 strcpy(name, "__ecereProp_");
814 FullClassNameCat(name, regClass.fullName, true);
816 FullClassNameCat(name, prop.name, false);
818 strcpy(nameM, "__ecerePropM_");
819 FullClassNameCat(nameM, regClass.fullName, true);
821 FullClassNameCat(nameM, prop.name, false);
823 args = MkListOne(MkExpCondition(MkExpIdentifier(MkIdentifier(nameM)), MkListOne(MkExpIdentifier(MkIdentifier(nameM))), MkExpIdentifier(MkIdentifier(name))));
824 stmt = MkExpressionStmt(MkListOne(
825 MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_Watchable")), args)));
826 ListAdd(registerModuleBody.compound.statements, stmt);
830 // Add Class Properties
831 for(classProperty = (ClassProperty)regClass.classProperties.first; classProperty; classProperty = (ClassProperty)((BTNode)classProperty).next)
833 OldList * args = MkList();
835 char * string = QMkString(classProperty.name);
838 ListAdd(args, MkExpIdentifier(MkIdentifier(className)));
841 ListAdd(args, MkExpString(string));
846 char * string = QMkString(classProperty.dataTypeString);
847 ListAdd(args, MkExpString(string));
851 if(classProperty.Set)
853 strcpy(name, "__ecereClassProp_");
854 FullClassNameCat(name, regClass.fullName, true);
855 strcat(name, "_Set_");
856 strcat(name, classProperty.name);
857 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
860 ListAdd(args, MkExpConstant("0"));
862 if(classProperty.Get)
864 strcpy(name, "__ecereClassProp_");
865 FullClassNameCat(name, regClass.fullName, true);
866 strcat(name, "_Get_");
867 strcat(name, classProperty.name);
869 ListAdd(args, MkExpIdentifier(MkIdentifier(name)));
872 ListAdd(args, MkExpConstant("0"));
874 stmt = MkExpressionStmt(MkListOne(MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddClassProperty")), args)));
875 ListAdd(registerModuleBody.compound.statements, stmt);
880 extern External curExternal;
882 void GetNameSpaceString(NameSpace ns, char * string)
885 GetNameSpaceString(ns.parent, string);
888 strcat(string, ns.name);
889 strcat(string, "::");
893 // *******************************************************************
894 static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol, OldList baseSpecs, OldList enumValues, OldList defs, External external, AccessMode declMode)
897 Class regClass = symbol.registered;
901 classType = regClass.type;
902 if(classType == enumClass && enumValues && (inCompiler || !buildingECERECOMModule))
905 for(e = enumValues.first; e; e = e.next)
914 e.exp.destType = destType;
916 // Set parsingType to avoid producing errors
918 ProcessExpressionType(e.exp);
923 destType.kind = TypeKind::classType;
924 destType._class = symbol;
925 ProcessExpressionType(e.exp);
927 if(e.exp.type == identifierExp && e.exp.expType && e.exp.identifier && e.exp.identifier.string && e.exp.expType.kind == enumType)
929 // Resolve enums here
931 char * string = e.exp.identifier.string;
932 for(l = e.exp.expType.members.first; l; l = l.next)
934 if(!strcmp(l.name, string))
938 FreeExpContents(e.exp);
939 e.exp.type = constantExp;
940 e.exp.constant = PrintInt64(l.data);
941 FreeType(e.exp.expType);
942 e.exp.expType = ProcessTypeString("int64", false);
949 ComputeExpression(e.exp);
950 if(e.exp.isConstant && e.exp.type == constantExp)
952 Operand op = GetOperand(e.exp);
957 value = op.type.isSigned ? (int64)op.c : (int64)op.uc;
960 value = op.type.isSigned ? (int64)op.s : (int64)op.us;
963 value = op.type.isSigned ? (int64)op.i64 : (int64)op.ui64;
967 value = op.type.isSigned ? (int64)op.i : (int)op.ui;
970 eEnum_AddFixedValue(regClass, e.id.string, value);
974 eEnum_AddValue(regClass, e.id.string);
977 eEnum_AddValue(regClass, e.id.string);
979 // Fix up derivatives enums largest
981 EnumClassData baseData = regClass.data;
983 for(deriv = regClass.derivatives.first; deriv; deriv = deriv.next)
985 Class c = deriv.data;
986 if(c && c.type == enumClass)
988 EnumClassData data = c.data;
989 data.largest = baseData.largest;
995 // Process all functions
996 if(definitions != null)
1000 for(def = definitions.first; def; def = def.next)
1002 if(def.type == propertyWatchClassDef && def.propertyWatch)
1004 PropertyWatch propWatch = def.propertyWatch;
1006 char watcherName[1024];
1008 Statement stmt = MkExpressionStmt(MkList());
1012 sprintf(watcherName,"__ecerePropertySelfWatcher_%d", propWatcherID++);
1013 for(propID = propWatch.properties->first; propID; propID = propID.next)
1015 strcat(watcherName, "_");
1016 strcat(watcherName, propID.string);
1019 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)), MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null)));
1021 ListAdd(specs, MkSpecifier(STATIC));
1022 ListAdd(specs, MkSpecifier(VOID));
1024 func = MkClassFunction(specs, null, decl, null);
1025 ProcessClassFunctionBody(func, propWatch.compound);
1027 decl.symbol = Symbol { };
1028 excludedSymbols->Add(decl.symbol);
1030 func.dontMangle = true;
1032 propWatch.compound = null;
1033 definitions.Insert(null, MkClassDefFunction(func));
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")));
1044 char * s = QMkString(propID.string);
1045 ListAdd(args, MkExpString(s));
1048 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
1050 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
1053 Compiler_Error($"Property %s not found in class %s\n", propID.string, regClass.fullName);
1055 FreePropertyWatch(def.propertyWatch);
1056 def.propertyWatch = (PropertyWatch)stmt; // Store this here to use it after CreateRegisterModuleBody is done
1058 // ListAdd(statements, stmt);
1063 for(def = definitions.first; def; def = def.next)
1065 if(def.type == functionClassDef)
1067 ProcessClassFunction(regClass, def.function, defs, external.prev, declMode == staticAccess);
1072 // Make the RegisterClass section
1073 if(inCompiler && symbol.mustRegister && regClass)
1076 OldList * args = MkList();
1079 const char * registerFunction = null;
1080 AccessMode inheritanceAccess = publicAccess;
1082 CreateRegisterModuleBody();
1084 curExternal = registerModuleExternal;
1087 switch(regClass.type)
1089 case structClass: ListAdd(args, MkExpIdentifier(MkIdentifier("structClass"))); break;
1090 case bitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("bitClass"))); break;
1091 case enumClass: ListAdd(args, MkExpIdentifier(MkIdentifier("enumClass"))); break;
1092 case noHeadClass: ListAdd(args, MkExpIdentifier(MkIdentifier("noHeadClass"))); break;
1093 case unitClass: ListAdd(args, MkExpIdentifier(MkIdentifier("unitClass"))); break;
1094 case normalClass: ListAdd(args, MkExpIdentifier(MkIdentifier("normalClass"))); break;
1098 char nameSpace[1024] = "";
1099 char className[1024] = "";
1101 GetNameSpaceString(regClass.nameSpace, nameSpace);
1103 if(declMode == staticAccess)
1105 GetLastDirectory(sourceFile, className);
1106 ChangeCh(className, '.', '_');
1107 strcat(className, "}");
1109 strcat(className, nameSpace);
1110 strcat(className, regClass.name);
1111 string = QMkString(className);
1112 ListAdd(args, MkExpString(string));
1118 char * string = QMkString(regClass.base.name);
1119 ListAdd(args, regClass.base ? MkExpString(string) :
1120 MkExpConstant("0"));
1125 if(baseSpecs != null)
1127 Type baseType = ProcessType(baseSpecs, null);
1128 if(baseType.kind != structType && baseType.kind != unionType)
1130 char baseName[1024] = "";
1132 if(baseType.kind == TypeKind::classType && baseType._class && baseType._class.isStatic)
1134 // TODO: Handle static classes and complex declarators...
1135 GetLastDirectory(sourceFile, baseName);
1136 ChangeCh(baseName, '.', '_');
1137 strcat(baseName, "}");
1138 strcat(baseName, baseType._class.string);
1141 PrintType(baseType, baseName, false, true);
1143 string = QMkString(baseName);
1144 ListAdd(args, MkExpString(string));
1148 ListAdd(args, MkExpConstant("0"));
1150 if(((Specifier)baseSpecs.first).type == baseSpecifier && ((Specifier)baseSpecs.first).specifier == PRIVATE)
1151 inheritanceAccess = privateAccess;
1154 ListAdd(args, MkExpConstant("0"));
1156 //ListAdd(args, class.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1157 //MkSpecifierName(class.structName)), null)) : MkExpConstant("0"));
1159 if(regClass.type == structClass || regClass.type == normalClass || regClass.type == noHeadClass)
1161 // Check if we have a data member in this class
1162 DataMember member = null;
1165 for(base = regClass.base; base && base.type != systemClass; base = base.next)
1167 for(member = base.membersAndProperties.first; member; member = member.next)
1168 if(!member.isProperty)
1175 if(regClass.type == structClass && symbol.declaredStruct && member)
1177 char baseStructName[1024];
1178 baseStructName[0] = 0;
1179 // TESTING THIS HERE
1180 // FullClassNameCat(baseStructName, regClass.base.fullName, false);
1181 strcpy(baseStructName, (regClass.base.templateClass ? regClass.base.templateClass : regClass.base).fullName);
1183 ListAdd(args, MkExpOp(
1184 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)), '-',
1185 MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(baseStructName), null)), null))));
1188 ListAdd(args, symbol.declaredStruct ? MkExpTypeSize(MkTypeName(MkListOne(
1189 MkStructOrUnion(structSpecifier, MkIdentifier(symbol.structName), null)), null)) : MkExpConstant("0"));
1193 ListAdd(args, MkExpConstant("0"));
1196 //if(regClass.type == normalClass)
1198 char classDataStructName[1024];
1199 strcpy(classDataStructName, "__ecereClassData_");
1200 FullClassNameCat(classDataStructName, symbol.string, false);
1202 ListAdd(args, symbol.classData ? MkExpTypeSize(MkTypeName(MkListOne(
1203 MkStructOrUnion(structSpecifier, MkIdentifier(classDataStructName), null)), null)) : MkExpConstant("0"));
1206 // TODO: Support Class Data for all other types of classes
1207 ListAdd(args, MkExpConstant("0"));
1210 if(regClass.type == normalClass || regClass.type == noHeadClass)
1213 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), symbol.needConstructor ?
1214 MkExpIdentifier(MkIdentifier(symbol.constructorName)) :
1215 MkExpConstant("0")));
1217 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), symbol.needDestructor ?
1218 MkExpIdentifier(MkIdentifier(symbol.destructorName)) :
1219 MkExpConstant("0")));
1223 // TODO: Support Constructors / Destructors for structs
1226 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpConstant("0")));
1228 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpConstant("0")));
1232 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1238 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1241 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1245 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1250 switch(inheritanceAccess)
1253 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1257 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1261 registerFunction = "eSystem_RegisterClass";
1263 stmt = MkExpressionStmt(MkListOne(
1264 MkExpOp(MkExpIdentifier(MkIdentifier("class")), '=',
1265 MkExpCall((exp = MkExpIdentifier(MkIdentifier(registerFunction))), args))));
1267 ListAdd(registerModuleBody.compound.statements, stmt);
1270 stmt = MkIfStmt(MkListOne(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className)))),
1271 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1272 MkExpIdentifier(MkIdentifier("class"))))), null);
1275 stmt = MkIfStmt(MkListOne(
1277 MkExpMember(MkExpIdentifier(MkIdentifier("module")), MkIdentifier("application")), EQ_OP,
1278 MkExpMember(MkExpIdentifier(MkIdentifier("__thisModule")), MkIdentifier("application"))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1279 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1280 MkExpIdentifier(MkIdentifier("class"))))), null);
1282 stmt = MkIfStmt(MkListOne(
1283 MkExpOp(MkExpOp(null, '!', MkExpIdentifier(MkIdentifier(symbol.className))), AND_OP, MkExpIdentifier(MkIdentifier("class")))),
1284 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(symbol.className)), '=',
1285 MkExpIdentifier(MkIdentifier("class"))))), null);
1288 ListAdd(registerModuleBody.compound.statements, stmt);
1290 if(external && external.type == classExternal && external._class.deleteWatchable)
1292 args = MkListOne(MkExpIdentifier(MkIdentifier("class")));
1293 stmt = MkExpressionStmt(MkListOne(
1294 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DestructionWatchable")), args)));
1295 ListAdd(registerModuleBody.compound.statements, stmt);
1298 // Add Virtual Methods
1301 Class base = regClass.base;
1303 for(c = 0; c<base.vTblSize; c++)
1305 Symbol method = (Symbol)regClass._vTbl[c];
1306 if((void *) method != DummyMethod && base._vTbl[c] != (void *)method && method.methodExternal) // TOLOOKAT: Module check here?
1308 External external = method.methodExternal;
1309 OldList * args = MkList();
1310 Identifier id = external.function ? GetDeclId(external.function.declarator) : null;
1313 External e = method.methodExternal ? method.methodExternal : method.methodCodeExternal;
1314 registerModuleExternal.CreateUniqueEdge(e, e.type == functionExternal);
1318 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1321 //char * string = QMkString(method.string);
1323 char * string = QMkString(method.method.name);
1324 ListAdd(args, MkExpString(string));
1328 ListAdd(args, MkExpConstant("0"));
1330 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1334 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1336 exp.expType = Type { refCount = 1 };
1337 stmt = MkExpressionStmt(MkListOne(
1338 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1339 ListAdd(registerModuleBody.compound.statements, stmt);
1344 // Add Virtual Methods in order
1347 for(c = regClass.base ? regClass.base.vTblSize : 0; c < regClass.vTblSize; c++)
1349 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1351 if(method.type == virtualMethod && method._class == regClass && method.vid == c)
1356 External external = method.symbol ? ((Symbol)method.symbol).methodCodeExternal : null;
1357 OldList * args = MkList();
1358 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1361 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1364 char * string = QMkString(method.name);
1365 ListAdd(args, MkExpString(string));
1370 char * string = QMkString(method.dataTypeString);
1371 ListAdd(args, MkExpString(string));
1375 if(id && external.function.body)
1377 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(id.string))));
1378 exp.expType = Type { refCount = 1 };
1382 ListAdd(args, (exp = MkExpConstant("0")));
1386 switch(method.memberAccess)
1389 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1392 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1396 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1400 //sprintf(name, "__ecereVMethodID_%s_%s", method._class.fullName, method.name);
1401 strcpy(name, "__ecereVMethodID_");
1402 FullClassNameCat(name, method._class.fullName, false);
1404 strcat(name, method.name);
1406 exp = /*MkExpPointer(*/MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddVirtualMethod")), args)/*, MkIdentifier("vid"))*/;
1408 exp->expType = eSystem_New(sizeof(Type));
1409 exp->expType->refCount++;
1410 exp->expType->isSigned = true;
1411 exp->expType->kind = TypeInt;
1414 stmt = MkExpressionStmt(MkListOne(/*
1415 MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', */exp/*)*/));
1418 registerModuleExternal.CreateUniqueEdge(external, external.type == functionExternal);
1420 DeclareMethod(curExternal, method, name);
1422 ListAdd(registerModuleBody.compound.statements, stmt);
1429 // Add Public Methods (all for now)
1430 for(method = (Method)regClass.methods.first; method; method = (Method)((BTNode)method).next)
1432 if(method.type == virtualMethod && method._class == regClass);
1433 else if(method.memberAccess == publicAccess || !method.dataTypeString)
1435 External external = method.symbol ? ((Symbol )method.symbol).methodCodeExternal : null;
1436 OldList * args = MkList();
1437 Identifier id = (external && external.function) ? GetDeclId(external.function.declarator) : null;
1440 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1443 char * string = QMkString(method.name);
1444 ListAdd(args, MkExpString(string));
1449 char * string = QMkString(method.dataTypeString);
1450 ListAdd(args, MkExpString(string));
1454 if(id && external.function.body)
1456 ListAdd(args, (exp = MkExpIdentifier(MkIdentifier(
1458 exp.expType = Type { refCount = 1 };
1462 ListAdd(args, (exp = MkExpConstant("0")));
1466 switch(method.memberAccess)
1469 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1472 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1476 ListAdd(args, MkExpIdentifier(MkIdentifier("publicAccess")));
1480 stmt = MkExpressionStmt(MkListOne(
1481 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddMethod")), args)));
1482 ListAdd(registerModuleBody.compound.statements, stmt);
1485 registerModuleExternal.CreateUniqueEdge(external, external.type == functionExternal);
1489 RegisterMembersAndProperties(regClass, false, "class", registerModuleBody);
1491 // Add Enumeration Values
1492 if(classType == enumClass)
1495 Class enumClass = eSystem_FindClass(privateModule, "enum");
1496 EnumClassData e = ACCESS_CLASSDATA(regClass, enumClass);
1498 for(value = e.values.first; value; value = value.next)
1500 OldList * args = MkList();
1503 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1506 char * string = QMkString(value.name);
1507 ListAdd(args, MkExpString(string));
1513 if(!strcmp(regClass.dataTypeString, "uint64"))
1514 temp = PrintUInt64(value.data);
1516 temp = PrintInt64(value.data);
1517 ListAdd(args, MkExpConstant(temp));
1521 stmt = MkExpressionStmt(MkListOne(
1522 MkExpCall(MkExpIdentifier(MkIdentifier("eEnum_AddFixedValue")), args)));
1523 ListAdd(registerModuleBody.compound.statements, stmt);
1527 // Add Template Parameters
1528 if(symbol.templateParams)
1530 TemplateParameter param;
1531 for(param = symbol.templateParams->first; param; param = param.next)
1533 OldList * args = MkList();
1536 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
1540 char * string = QMkString(param.identifier.string);
1541 ListAdd(args, MkExpString(string));
1546 ListAdd(args, MkExpIdentifier(MkIdentifier((param.type == type) ? "type" : ((param.type == identifier) ? "identifier" : "expression"))));
1554 char * typeString = param.dataType ? StringFromSpecDecl(param.dataType.specifiers, param.dataType.decl) : null;
1555 char * string = QMkString(typeString);
1556 ListAdd(args, MkExpString(string));
1563 char memberTypeString[132] = "TemplateMemberType::";
1564 bool needClass = true;
1566 param.memberType.OnGetString(memberTypeString + strlen(memberTypeString), null, &needClass);
1568 MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)),
1569 MkExpIdentifier(MkIdentifier(memberTypeString))));
1575 if(param.defaultArgument)
1577 OldList * members = MkList();
1582 char * typeString = param.defaultArgument.templateDatatype ?
1583 StringFromSpecDecl(param.defaultArgument.templateDatatype.specifiers, param.defaultArgument.templateDatatype.decl) : null;
1584 char * string = QMkString(typeString);
1586 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1594 char memberString[1024];
1596 memberString[0] = '\0';
1598 if(param.defaultArgument.identifier._class)
1600 if(param.defaultArgument.identifier._class.type == templateTypeSpecifier)
1601 strcpy(memberString, param.defaultArgument.identifier._class.templateParameter.identifier.string);
1602 else if(param.defaultArgument.identifier._class.name)
1603 strcpy(memberString, param.defaultArgument.identifier._class.name);
1606 strcat(memberString, "::");
1608 strcat(memberString, param.defaultArgument.identifier.string);
1610 string = QMkString(memberString);
1612 // TOFIX: UNIONS ARE BROKEN FOR ASSIGNMENTS, USING dataTypeString INSTEAD
1613 // members->Add(MkMemberInit(MkListOne(MkIdentifier("memberString")), MkInitializerAssignment(MkExpString(string))));
1614 members->Add(MkMemberInit(MkListOne(MkIdentifier("dataTypeString")), MkInitializerAssignment(MkExpString(string))));
1622 OldList * ids = MkList();
1624 char * string = null;
1626 //ProcessExpressionType(param.defaultArgument.expression);
1627 //ComputeExpression(param.defaultArgument.expression);
1629 op = GetOperand(param.defaultArgument.expression);
1630 ui64String = PrintUInt64(op.ui64);
1631 ids->Add(MkIdentifier("expression"));
1632 ids->Add(MkIdentifier("ui64"));
1634 //string = QMkString(ui64String);
1635 members->Add(MkMemberInit(ids, MkInitializerAssignment(MkExpConstant(ui64String))));
1642 ListAdd(args, MkExpInstance(MkInstantiation(MkSpecifierName("ClassTemplateArgument"), null,
1643 MkListOne(MkMembersInitList(members)))));
1646 ListAdd(args, MkExpIdentifier(MkIdentifier("null")));
1648 stmt = MkExpressionStmt(MkListOne(
1649 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_AddTemplateParameter")), args)));
1650 ListAdd(registerModuleBody.compound.statements, stmt);
1652 stmt = MkExpressionStmt(MkListOne(
1653 MkExpCall(MkExpIdentifier(MkIdentifier("eClass_DoneAddingTemplateParameters")),
1654 MkListOne(MkExpIdentifier(MkIdentifier("class"))))));
1655 ListAdd(registerModuleBody.compound.statements, stmt);
1658 if(definitions != null)
1660 for(def = definitions.first; def; def = def.next)
1662 if(def.type == propertyWatchClassDef && def.propertyWatch)
1664 ListAdd(registerModuleBody.compound.statements, (Statement)def.propertyWatch);
1665 def.propertyWatch = null;
1667 else if(def.type == classDesignerClassDef)
1670 char className[1024];
1671 sprintf(className, "__ecereClass_%s", def.designer);
1673 DeclareClass(FindClass(def.designer), className);
1677 char * s = QMkString(def.designer);
1678 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1679 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
1680 MkExpString(s)))), null);
1683 ListAdd(registerModuleBody.compound.statements, stmt);
1685 else if(def.type == classNoExpansionClassDef)
1687 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1688 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("noExpansion")), '=',
1689 MkExpConstant("1")))), null);
1690 ListAdd(registerModuleBody.compound.statements, stmt);
1692 else if(def.type == classFixedClassDef)
1694 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1695 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("fixed")), '=',
1696 MkExpConstant("1")))), null);
1697 ListAdd(registerModuleBody.compound.statements, stmt);
1699 regClass.fixed = true;
1701 else if(def.type == designerDefaultPropertyClassDef)
1703 char * s = QMkString(def.defaultProperty.string);
1704 stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
1705 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=',
1706 MkExpString(s)))), null);
1707 ListAdd(registerModuleBody.compound.statements, stmt);
1710 else if(def.type == classPropertyValueClassDef)
1712 classPropValues.Add(ClassPropertyValue { regClass = regClass, staticClass = (declMode == staticAccess), id = def.id, exp = def.initializer.exp });
1714 def.initializer.exp = null;
1722 class ClassPropertyValue
1729 ~ClassPropertyValue()
1735 static List<ClassPropertyValue> classPropValues { };
1737 public void ProcessClassDefinitions()
1739 External external, next;
1741 CreateRegisterModuleBody();
1744 // (Need to do those things after in case something is not yet defined)
1745 for(external = ast->first; external; external = next)
1747 next = external.next;
1748 curExternal = external;
1749 if(external.type == classExternal)
1751 ClassDefinition _class = external._class;
1752 if(_class.definitions)
1754 ProcessClass(normalClass, _class.definitions, _class.symbol, _class.baseSpecs, null, ast, external, _class.declMode);
1758 ast->Remove(external);
1759 FreeExternal(external);
1762 else if(external.type == functionExternal)
1764 bool setStaticMethod = false;
1766 if(external.symbol && !external.symbol.type.thisClass && !external.symbol.type.staticMethod)
1768 // TOCHECK: Where do we actually need this to be set?
1769 external.symbol.type.staticMethod = true;
1770 setStaticMethod = true;
1775 FunctionDefinition function = external.function;
1779 if(!strcmp(function.declarator.symbol.string, "__on_register_module"))
1781 ListAdd(registerModuleBody.compound.statements, function.body);
1782 function.body.compound.context.parent = registerModuleBody.compound.context;
1783 ast->Remove(external);
1784 function.body = null;
1785 FreeExternal(external);
1789 if(function.declMode != privateAccess && function.declMode != publicAccess) continue;
1793 CreateRegisterModuleBody();
1797 char * string = QMkString(function.declarator.symbol.string);
1798 ListAdd(args, MkExpString(string));
1805 char type[1024] = "";
1806 // We don't want functions to be marked as static methods
1808 function.declarator.symbol.type.staticMethod = false;
1809 PrintType(function.declarator.symbol.type, type, true, true);
1811 function.declarator.symbol.type.staticMethod = true;
1812 string = QMkString(type);
1813 ListAdd(args, MkExpString(string));
1819 ListAdd(args, MkExpIdentifier(MkIdentifier(function.declarator.symbol.string)));
1823 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1826 switch(function.declMode)
1829 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1832 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1836 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1840 stmt = MkExpressionStmt(MkListOne(
1841 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterFunction"))), args)));
1843 ListAdd(registerModuleBody.compound.statements, stmt);
1846 else if(external.type == declarationExternal)
1848 Declaration declaration = external.declaration;
1852 if(external.symbol.type && external.symbol.type.kind == functionType && !external.symbol.type.thisClass)
1853 external.symbol.type.staticMethod = true;
1856 if(external.symbol && declaration && declaration.type == initDeclaration)
1858 if(declaration.specifiers)
1860 Specifier specifier;
1861 bool removeExternal = false;
1863 for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
1865 if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
1866 (declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
1868 Symbol symbol = FindClass(specifier.id.string);
1871 ClassType classType;
1872 if(specifier.type == enumSpecifier)
1873 classType = enumClass;
1875 classType = structClass;
1877 removeExternal = true;
1878 // Transfer Context over to Symbol
1879 symbol.ctx = specifier.ctx;
1880 specifier.ctx = null;
1882 ProcessClass(classType, specifier.definitions, symbol, specifier.baseSpecs, specifier.list,ast, external, declaration.declMode);
1886 if(inCompiler && removeExternal)
1888 ast->Remove(external);
1889 FreeExternal(external);
1893 else if(declaration && declaration.type == defineDeclaration)
1895 if(inCompiler && declaration.declMode != staticAccess)
1898 OldList * args = MkList();
1900 CreateRegisterModuleBody();
1904 char * string = QMkString(declaration.id.string);
1905 ListAdd(args, MkExpString(string));
1912 char type[1024] = "";
1913 PrintExpression(declaration.exp, type);
1914 string = QMkString(type);
1915 ListAdd(args, MkExpString(string));
1920 ListAdd(args, MkExpIdentifier(MkIdentifier("module")));
1923 switch(declaration.declMode)
1926 ListAdd(args, MkExpIdentifier(MkIdentifier("staticAccess")));
1929 ListAdd(args, MkExpIdentifier(MkIdentifier("privateAccess")));
1933 ListAdd(args, MkExpIdentifier(MkIdentifier(buildingECERECOMModule ? "baseSystemAccess" : "publicAccess")));
1937 stmt = MkExpressionStmt(MkListOne(
1938 MkExpCall((MkExpIdentifier(MkIdentifier("eSystem_RegisterDefine"))), args)));
1940 ListAdd(registerModuleBody.compound.statements, stmt);
1946 // Set the class properties at the very end
1947 for(v : classPropValues)
1949 OldList * findClassArgs = MkList();
1950 OldList * args = MkList();
1951 Statement compoundStmt;
1958 ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
1960 char nameSpace[1024] = "";
1961 char className[1024] = "";
1962 Class regClass = v.regClass;
1963 GetNameSpaceString(regClass.nameSpace, nameSpace);
1966 GetLastDirectory(sourceFile, className);
1967 ChangeCh(className, '.', '_');
1968 strcat(className, "}");
1970 strcat(className, nameSpace);
1971 strcat(className, regClass.name);
1972 s = QMkString(className);
1974 ListAdd(findClassArgs, MkExpString(s));
1977 ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
1978 s = QMkString(v.id.string);
1979 ListAdd(args, MkExpString(s));
1983 // TOFIX: We're probably missing a dest type here, and might want to handle through same pathway as in pass2's opExp
1984 ProcessExpressionType(e);
1985 if(e.expType.isPointerType)
1986 e = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("intptr")), null), e);
1988 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), e));
1989 compoundStmt = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
1990 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("_class")),
1991 MkInitializerAssignment(MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eSystem_FindClass")), findClassArgs)))))),
1992 MkListOne(MkExpressionStmt(MkListOne(
1993 MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eClass_SetProperty")), args)))));
1994 compoundStmt.compound.context = Context { parent = registerModuleBody.compound.context };
1995 ListAdd(registerModuleBody.compound.statements, compoundStmt);
1998 classPropValues.Free();