3 #define YYLTYPE Location
6 extern External curExternal;
8 public void MangleClassName(char * className)
13 for(c = 0; (ch = className[c]); c++)
53 // ChangeCh(className, ' ', '_');
54 // ChangeCh(className, '*', '_');
57 public void FullClassNameCat(char * output, char * className, bool includeTemplateParams)
63 if(!strchr(className, ':'))
69 //if(strchr(className, ':'))
70 for(c = 0; (ch = className[c]) && ch != '<'; c++)
74 strcat(output, "__ecereNameSpace__");
80 for(c = 0; (ch = className[c]); c++)
104 if(!includeTemplateParams) break;
117 output[len++] = '__';
125 static void AddSimpleBaseMembers(OldList list, Class _class, Class topClass)
127 /*if(_class.base && _class.type != CLASS_SYSTEM)
128 AddSimpleBaseMembers(list, _class.base, topClass);*/
129 if(_class.type != systemClass)
130 AddMembers(list, _class, false, null, topClass, null);
133 static bool NameSpaceContained(NameSpace * ns, NameSpace * parent)
138 return NameSpaceContained(ns->parent, parent);
143 static void CheckPublicClass(Symbol classSym, AccessMode access, char * word)
145 Class regClass = classSym ? classSym.registered : null;
148 if(regClass.templateClass)
149 regClass = regClass.templateClass;
150 // TODO: Will need to add checks for template parameter classes
151 if(classSym.isStatic && access != staticAccess)
153 Compiler_Error($"Non-static %s making use of a static class\n", word);
155 else if(access == publicAccess)
157 if(!NameSpaceContained(regClass.nameSpace, regClass.module.application.systemNameSpace))
159 if(NameSpaceContained(regClass.nameSpace, regClass.module.privateNameSpace) || !ModuleAccess(privateModule, regClass.module))
160 Compiler_Error($"Public %s making use of a private class\n", word);
166 static void CheckPublicTypeName(TypeName type, AccessMode access)
171 for(spec = type.qualifiers->first; spec; spec = spec.next)
173 // Only check for classes here...
174 // Skip structs etc. for now
175 if(spec.type == nameSpecifier)
177 Symbol classSym = spec.symbol; // FindClass(spec.name);
178 CheckPublicClass(classSym, access, "define");
184 static void CheckPublicInitializer(Initializer init, AccessMode access)
189 CheckPublicExpression(init.exp, access);
191 case listInitializer:
194 for(i = init.list->first; i; i = i.next)
195 CheckPublicInitializer(i, access);
201 static void CheckPublicExpression(Expression exp, AccessMode access)
215 CheckPublicExpression(exp.op.exp1, access);
217 CheckPublicExpression(exp.op.exp2, access);
222 for(e = exp.list->first; e; e = e.next)
223 CheckPublicExpression(e, access);
229 CheckPublicExpression(exp.index.exp, access);
230 for(e = exp.index.index->first; e; e = e.next)
231 CheckPublicExpression(e, access);
237 CheckPublicExpression(exp.call.exp, access);
238 if(exp.call.arguments)
240 for(e = exp.call.arguments->first; e; e = e.next)
241 CheckPublicExpression(e, access);
247 CheckPublicExpression(exp.member.exp, access);
252 CheckPublicExpression(exp.member.exp, access);
256 CheckPublicTypeName(exp.typeName, access);
260 Type type = exp.expType;
261 CheckPublicTypeName(exp.cast.typeName, access);
263 CheckPublicExpression(exp.cast.exp, access);
269 CheckPublicExpression(exp.cond.cond, access);
270 for(e = exp.cond.exp->first; e; e = e.next)
271 CheckPublicExpression(e, access);
272 CheckPublicExpression(exp.cond.elseExp, access);
277 CheckPublicExpression(exp._new.size, access);
281 CheckPublicExpression(exp._renew.size, access);
282 CheckPublicExpression(exp._renew.exp, access);
287 CheckPublicClass(exp.instance._class.symbol /*FindClass(exp.instance._class.name)*/, access, "define");
288 for(members = exp.instance.members->first; members; members = members.next)
290 if(members.type == dataMembersInit)
293 for(member = members.dataMembers->first; member; member = member.next)
295 CheckPublicInitializer(member.initializer, access);
305 static void CheckPublicDataType(Type type, AccessMode access, char * word)
313 CheckPublicClass(type._class, access, word);
319 // Do we want to overlook these C constructs when doing checks? Most likely... Recursion nightmare.
325 typeSym = FindSymbol(type.enumName, globalContext, globalContext, true, false);
326 if(typeSym) type = typeSym.type;
328 for(member = type.members.first; member; member = member.next)
329 CheckPublicDataType(member, access, word);
336 CheckPublicDataType(type.returnType, access, word);
337 for(param = type.params.first; param; param = param.next)
338 CheckPublicDataType(param, access, word);
339 CheckPublicClass(type.thisClass, access, word);
343 CheckPublicDataType(type.arrayType, access, word);
345 CheckPublicClass(type.enumClass, access, word);
349 CheckPublicDataType(type.type, access, word);
354 // Where is this used? Needed?
359 CheckPublicClass(type._class, access, word);
366 static void CheckMembersDefinitions(Class regClass, DataMember member, OldList definitions, AccessMode access)
368 if(definitions != null)
371 for(def = definitions.first; def; def = def.next)
373 if(def.type == declarationClassDef)
375 Declaration decl = def.decl;
376 DataMember dataMember;
379 if(decl.type == structDeclaration)
384 for(d = decl.declarators->first; d; d = d.next)
386 Identifier declId = GetDeclId(d);
391 BTNamedLink link = (BTNamedLink)member.membersAlpha.FindString(declId.string);
392 dataMember = link ? link.data : null;
395 dataMember = eClass_FindDataMember(regClass, declId.string, privateModule, null, null);
397 CheckPublicDataType(dataMember.dataType, (def.memberAccess == privateAccess) ? privateAccess : access, $"class data member");
401 else if(decl.specifiers)
404 // Unnamed struct/union
405 for(spec = decl.specifiers->first; spec; spec = spec.next)
407 if(spec.type == structSpecifier || spec.type == unionSpecifier)
409 if(spec.definitions && !spec.id)
411 CheckMembersDefinitions(regClass, member, spec.definitions, (def.memberAccess == privateAccess) ? privateAccess : access);
413 else if(spec.definitions && spec.id)
417 BTNamedLink link = (BTNamedLink)member.membersAlpha.FindString(spec.id.string);
418 dataMember = link ? link.data : null;
421 dataMember = eClass_FindDataMember(regClass, spec.id.string, privateModule, null, null);
423 CheckPublicDataType(dataMember.dataType, (def.memberAccess == privateAccess) ? privateAccess : access, $"class data member");
429 else if(decl.type == instDeclaration)
431 CheckPublicClass(decl.inst._class.symbol /*FindClass(decl.inst._class.name)*/, (def.memberAccess == privateAccess) ? privateAccess : access, $"class member instance");
438 static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol, OldList baseSpecs, OldList enumValues, Location loc, OldList defs, void * after, OldList initDeclarators, ExtDecl extDecl)
440 char structName[1024];
441 char className[1024];
442 char constructorName[1024];
443 char destructorName[1024];
445 ClassFunction destructor = null, constructor = null;
446 bool redefinition = false;
447 bool isUnion = classType == unionClass;
449 External external = null;
453 OldList * classDataList;
458 classDataList = MkList();
471 regClass = eSystem_FindClass(privateModule, symbol.string);
473 return; // TODO: Notify of an error?
474 classType = regClass.type;
476 // PUBLISHING CHECK ON BASE CLASS
481 if(!NameSpaceContained(regClass.nameSpace, ®Class.module.privateNameSpace) && regClass.inheritanceAccess == publicAccess)
483 if(!regClass.base.symbol)
484 regClass.base.symbol = FindClass(regClass.base.fullName);
485 CheckPublicClass(regClass.base.symbol, publicAccess, $"class");
487 else if(!symbol.isStatic && regClass.base)
489 if(!regClass.base.symbol)
490 regClass.base.symbol = FindClass(regClass.base.fullName);
491 CheckPublicClass(regClass.base.symbol, privateAccess, $"class");
496 if(NameSpaceContained(regClass.nameSpace, ®Class.module.privateNameSpace))
498 if(regClass.inheritanceAccess == publicAccess &&
499 (regClass.base.nameSpace == ®Class.base.module.privateNameSpace || !ModuleAccess(privateModule, regClass.base.module)))
500 Compiler_Error($"Public class publicly inheriting off private base class\n");
502 else if(!symbol.isStatic)
504 Symbol baseSym = FindClass(regClass.base.fullName);
505 if(baseSym && baseSym.isStatic)
506 Compiler_Error($"Non-static class inheriting off static base class\n");
511 MOVED ENUM VALUES TO PASS1
513 if(classType == enumClass && enumValues)
516 for(e = enumValues.first; e; e = e.next)
525 e.exp.destType = destType;
527 ProcessExpressionType(e.exp);
528 ComputeExpression(e.exp);
529 if(e.exp.isConstant && e.exp.type == ExpConstant)
532 value = strtol(e.exp.string, null, 0);
533 eEnum_AddFixedValue(regClass, e.id.string, value);
537 eEnum_AddValue(regClass, e.id.string);
540 eEnum_AddValue(regClass, e.id.string);
545 // ACCESS OVERRIDING CODE
546 if(definitions != null)
548 for(def = definitions.first; def; def = def.next)
550 if(def.type == accessOverrideClassDef)
555 if((prop = eClass_FindProperty(regClass, def.id.string, privateModule)))
557 eClass_AddProperty(regClass, def.id.string, null, null, null, def.memberAccess);
559 else if((member = eClass_FindDataMember(regClass, def.id.string, privateModule, null, null)))
561 eClass_AddDataMember(regClass, def.id.string, null, 0, 0, def.memberAccess);
563 else if((method = eClass_FindMethod(regClass, def.id.string, privateModule)))
565 eClass_AddMethod(regClass, def.id.string, null, null, def.memberAccess);
570 Compiler_Error($"Couldn't find member %s to override\n", def.id.string);
578 external = MkExternalDeclaration(null);
579 defs.Insert(after, external);
580 curExternal = external;
581 curExternal.symbol = symbol;
584 if((classType == structClass || classType == noHeadClass) && inCompiler)
586 AddSimpleBaseMembers(list, regClass.base, regClass);
589 // First check if there's any declaration or instantiations, we'll need a struct
590 if(definitions != null)
594 if(!NameSpaceContained(regClass.nameSpace, ®Class.module.privateNameSpace))
595 CheckMembersDefinitions(regClass, null, definitions, publicAccess);
596 else if(!symbol.isStatic)
597 CheckMembersDefinitions(regClass, null, definitions, privateAccess);
599 for(def = definitions.first; def; def = def.next)
601 if(def.type == declarationClassDef)
603 Declaration decl = def.decl;
605 if(decl.type == structDeclaration)
607 if(inCompiler && classType != bitClass)
609 ListAdd(list, MkClassDefDeclaration(decl));
611 // Take it out from here...
615 else if(decl.type == instDeclaration)
617 Instantiation inst = decl.inst;
618 Expression exp = inst.exp;
622 // Eventually support multiple instance creations in the same ';'
623 OldList * specifiers = MkList();
626 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(inst._class.name));
627 d = MkDeclaratorIdentifier(MkIdentifier(exp.identifier.string));
631 OldList * declarators = MkList();
632 ListAdd(declarators, d);
634 decl = MkStructDeclaration(specifiers, declarators, null);
635 ListAdd(list, MkClassDefDeclaration(decl));
637 // Add the this pointer to the instance expression
638 exp.type = memberExp;
639 exp.member.member = exp.identifier;
640 exp.member.exp = QMkExpId("this");
641 exp.member.memberType = dataMember;
642 exp.member.thisPtr = true;
647 FreeList(specifiers, FreeSpecifier);
651 // Check if it is a simple class
652 // If it is, we only need a constructor if there is data set,
653 // and we don't need a destructor
654 classSym = inst._class.symbol; // FindClass(inst._class.name);
655 if(classSym && classSym.registered &&
656 (classSym.registered.type == structClass ||
657 classSym.registered.type == bitClass ||
658 classSym.registered.type == unitClass))
660 if(inst.members && inst.members->count)
661 symbol.needConstructor = true;
665 symbol.needConstructor = true;
666 symbol.needDestructor = true;
670 else if(def.type == classDataClassDef)
672 Declaration decl = def.decl;
674 if(decl.type == structDeclaration)
676 if(inCompiler && classType != bitClass)
678 ListAdd(classDataList, MkClassDefDeclaration(decl));
680 // Take it out from here...
685 else if(def.type == defaultPropertiesClassDef)
686 symbol.needConstructor = true;
687 else if(def.type == propertyWatchClassDef)
688 symbol.needConstructor = true;
689 else if(def.type == functionClassDef)
691 ClassFunction func = def.function;
692 if(func.isDestructor)
697 Compiler_Error($"redefinition of destructor for class %s\n", symbol.string);
701 symbol.needDestructor = true;
703 if(!inCompiler && func.body)
705 // Add this to the context
708 string = CopyString("this");
709 type = MkClassType(regClass.fullName);
711 func.body.compound.context.symbols.Add((BTNode)thisSymbol);
715 if(func.isConstructor)
720 Compiler_Error($"redefinition of constructor for class %s\n", symbol.string);
724 symbol.needConstructor = true;
727 if(!inCompiler && func.body)
729 // Add this to the context
732 string = CopyString("this");
733 type = MkClassType(regClass.fullName);
735 func.body.compound.context.symbols.Add((BTNode)thisSymbol);
745 external.symbol = null; // curExternal.symbol = null;
750 OldList * specs = MkList(), * declarators = (initDeclarators != null) ? initDeclarators : MkList();
751 initDeclarators = null;
755 FullClassNameCat(structName, symbol.string, false);
757 // TESTING THIS HERE INSTEAD:
758 strcpy(structName, symbol.string);
759 symbol.structName = CopyString(structName);
762 Specifier spec = MkStructOrUnion(structSpecifier, MkIdentifier(structName),
763 isUnion ? MkListOne(MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkStructOrUnion(unionSpecifier, null, list)), null, null))) : list);
764 spec.extDeclStruct = extDecl;
765 ListAdd(specs, spec);
768 external.symbol = symbol;
769 // TOFIX : Fix this...
770 symbol.structExternal = external;
772 external.declaration = MkDeclaration(specs, declarators);
775 symbol.declaredStruct = true;
779 curExternal = external.prev;
780 defs.Remove(external);
781 FreeExternal(external);
785 // TODO: Deal with declaration id issues...
786 if(classDataList->count)
789 char classDataStructName[1024];
790 OldList * specs = MkList();
793 strcpy(classDataStructName, "__ecereClassData_");
794 FullClassNameCat(classDataStructName, symbol.string, false);
796 declMode = defaultAccess;
797 ListAdd(specs, MkStructOrUnion(structSpecifier, MkIdentifier(classDataStructName), classDataList));
798 external = MkExternalDeclaration(MkDeclaration(specs, null));
799 defs.Insert(after, external);
801 symbol.classData = true;
804 delete classDataList;
811 OldList * specs = MkList(), * declarators = MkList();
812 strcpy(className, "__ecereClass_");
813 FullClassNameCat(className, symbol.string, true);
815 MangleClassName(className);
817 symbol.className = CopyString(className);
819 if(!strstr(sourceFile, ".main.ec"))
820 ListAdd(specs, MkSpecifier(STATIC));
821 ListAdd(specs, MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
822 ListAdd(declarators, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
823 MkDeclaratorIdentifier(MkIdentifier(className))), null));
825 symbol.methodExternal = MkExternalDeclaration(MkDeclaration(specs, declarators));
826 defs.Insert(after, symbol.methodExternal);
827 after = symbol.methodExternal;
830 // Build the destructor
831 if(symbol.needDestructor)
833 ClassFunction function;
834 OldList * specs = MkList();
838 OldList * declarations = null, * statements;
840 strcpy(destructorName, "__ecereDestructor_");
841 FullClassNameCat(destructorName, symbol.string, false);
843 symbol.destructorName = CopyString(destructorName);
845 ListAdd(specs, MkSpecifier(VOID));
847 context = PushContext();
849 statements = MkList();
851 if(definitions != null)
853 for(def = definitions.first; def; def = def.next)
856 if(def.type == declarationClassDef && def.decl && def.decl.type == instDeclaration)
858 Instantiation inst = def.decl.inst;
859 Symbol classSym = inst._class.symbol;
861 classSym = inst._class.symbol = FindClass(inst._class.name);*/
862 if(inst.exp && (!classSym || !classSym.registered || classSym.registered.type == normalClass))
864 /* FIX a DecRef declaration problem...
865 // Decrement counter if it isn't a simple class
867 MkExpressionStmt(MkListOne(MkExpCall(
868 MkExpIdentifier(MkIdentifier("ecere::com::eInstance_DecRef")),
869 MkListOne(CopyExpression(inst.exp))))));
871 Expression exp = MkExpOp(null, DELETE, CopyExpression(inst.exp));
872 ListAdd(statements, MkExpressionStmt(MkListOne(exp)));
874 if(inst.exp && (!classSym || !classSym.registered || classSym.registered.type == noHeadClass))
876 Expression exp = MkExpOp(null, DELETE, CopyExpression(inst.exp));
877 ListAdd(statements, MkExpressionStmt(MkListOne(exp)));
883 if(destructor && destructor.body)
886 declarations = destructor.body.compound.declarations;
887 if(destructor.body.compound.statements)
890 while(stmt = destructor.body.compound.statements.first)
892 destructor.body.compound.statements->Remove(stmt);
893 statements->Add(stmt);
897 // statements->Add(destructor.body);
898 statements->Insert(null, destructor.body);
899 destructor.body.compound.context.parent = context;
900 destructor.body = null;
903 body = MkCompoundStmt(declarations, statements);
905 body.compound.context = context;
907 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(destructorName)), null);
909 // Destructor will have same Symbol ID as class
913 idCode = symbol.idCode;
916 excludedSymbols->Add(decl.symbol);
918 function = MkClassFunction(specs, null, decl, null);
919 ProcessClassFunctionBody(function, body);
920 function.id = symbol.id;
921 function.idCode = symbol.idCode;
922 //function.id = symbol.endid;
923 function.dontMangle = true;
924 definitions.Insert(null, MkClassDefFunction(function));
927 // Build the constructor
929 if(symbol.needConstructor && inCompiler)
931 ClassFunction function;
932 OldList * specs = MkList();
936 OldList * declarations = null, * statements;
938 strcpy(constructorName, "__ecereConstructor_");
939 FullClassNameCat(constructorName, symbol.string, false);
941 symbol.constructorName = CopyString(constructorName);
943 ListAdd(specs, MkSpecifierName/*MkClassName*/("bool"));
945 context = PushContext();
947 statements = MkList();
949 if(definitions != null)
951 for(def = definitions.first; def; def = def.next)
953 if(def.type == declarationClassDef && def.decl && def.decl.type == instDeclaration)
955 Instantiation inst = def.decl.inst;
956 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
958 classSym = inst._class.symbol = FindClass(inst._class.name);*/
960 if(inst.exp && (!classSym || !classSym.registered || classSym.registered.type == normalClass || classSym.registered.type == noHeadClass))
962 Instantiation newInst { };
964 newInst.members = null;
965 newInst.exp = CopyExpression(inst.exp);
966 newInst._class = CopySpecifier(inst._class);
969 MkExpressionStmt(MkListOne(MkExpInstance(newInst))));
973 // Increment counter if it isn't a simple class
974 if(inst.exp && (!classSym || !classSym.registered || classSym.registered.type == normalClass))
977 MkExpressionStmt(MkListOne(MkExpCall(
978 MkExpIdentifier(MkIdentifier("ecere::com::eInstance_IncRef")),
979 MkListOne(CopyExpression(inst.exp))))));
984 for(def = definitions.first; def; def = def.next)
986 // Add the default data properties/members
987 if(def.type == defaultPropertiesClassDef && def.defProperties)
989 MemberInit propertyDef;
990 for(propertyDef = def.defProperties->first; propertyDef; propertyDef = propertyDef.next)
992 Expression memberExp;
993 Identifier id = propertyDef.identifiers->first;
996 memberExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), id);
997 for(id = id.next; id; id = id.next)
998 memberExp = MkExpMember(memberExp, id);
1000 // ASSUME: No list initializers here
1002 MkExpressionStmt(MkListOne(MkExpOp(memberExp, '=',
1003 (propertyDef.initializer && propertyDef.initializer.type == expInitializer ? propertyDef.initializer.exp : null)))));
1006 // Take it out of there...
1007 if(propertyDef.initializer)
1009 if(propertyDef.initializer.type == expInitializer)
1010 propertyDef.initializer.exp = null;
1011 FreeInitializer(propertyDef.initializer);
1013 propertyDef.initializer = null;
1014 propertyDef.identifiers->Clear();
1018 for(def = definitions.first; def; def = def.next)
1020 // Instanciate stuff
1021 if(def.type == declarationClassDef && def.decl && def.decl.type == instDeclaration)
1023 Instantiation inst = def.decl.inst;
1024 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
1026 classSym = inst._class.symbol = FindClass(inst._class.name);*/
1028 if(inst.exp || (!classSym || !classSym.registered || classSym.registered.type == normalClass || classSym.registered.type == noHeadClass))
1030 // Only needed here if members are set...
1031 if(!(inst.exp && (!classSym || !classSym.registered || classSym.registered.type == normalClass || classSym.registered.type == noHeadClass)) || (inst.members && inst.members->count))
1033 // Is it safe to take it out here?
1034 def.decl.inst = null;
1037 MkExpressionStmt(MkListOne(MkExpInstance(inst))));
1044 if(constructor && constructor.body)
1047 declarations = constructor.body.compound.declarations;
1049 if(constructor.body.compound.declarations)
1052 while(decl = constructor.body.compound.declarations.first)
1054 constructor.body.compound.declarations->Remove(decl);
1055 declarations->Add(decl);
1059 // We want to keep the context here...
1060 if(constructor.body.compound.statements)
1063 while(stmt = constructor.body.compound.statements.first)
1065 constructor.body.compound.statements->Remove(stmt);
1066 statements->Add(stmt);
1070 statements->Add(constructor.body);
1071 constructor.body.compound.context.parent = context;
1072 constructor.body = null;
1075 ListAdd(statements, MkReturnStmt(MkListOne(MkExpIdentifier(MkIdentifier("true")))));
1076 body = MkCompoundStmt(declarations, statements);
1077 PopContext(context);
1078 body.compound.context = context;
1080 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(constructorName)), null);
1082 // Constructor will have same Symbol ID as class
1083 decl.symbol = Symbol { };
1084 excludedSymbols->Add(decl.symbol);
1086 //*decl.symbol = *symbol;
1087 decl.symbol.id = symbol.id;
1088 decl.symbol.idCode = symbol.idCode;
1089 //decl.symbol.id = symbol.endid;
1091 function = MkClassFunction(specs, null, decl, null);
1092 ProcessClassFunctionBody(function, body);
1093 function.id = symbol.id;
1094 function.idCode = symbol.idCode;
1095 //function.id = symbol.endid;
1096 function.dontMangle = true;
1097 if(definitions != null)
1098 definitions.Insert(null, MkClassDefFunction(function));
1102 // list = null; // Why was this here?
1105 if(definitions != null)
1107 for(def = definitions.first; def; def = def.next)
1109 if(def.type == propertyClassDef && def.propertyDef)
1111 PropertyDef propertyDef = def.propertyDef;
1112 ClassDef after = def;
1117 yylloc = propertyDef.loc;
1118 if(!NameSpaceContained(regClass.nameSpace, ®Class.module.privateNameSpace) && def.memberAccess == publicAccess)
1119 CheckPublicDataType(propertyDef.symbol.type, publicAccess, "class property");
1120 else if(!symbol.isStatic)
1121 CheckPublicDataType(propertyDef.symbol.type, privateAccess, "class property");
1125 // Commented this out... Why exactly?
1132 if(propertyDef.getStmt && propertyDef.id)
1134 strcpy(name, "__ecereProp_");
1135 FullClassNameCat(name, symbol.string, false);
1136 strcat(name, "_Get_");
1137 // strcat(name, propertyDef.id.string);
1138 FullClassNameCat(name, propertyDef.id.string, true);
1139 MangleClassName(name);
1143 // decl = MkDeclaratorFunction(PlugDeclarator(propertyDef.declarator, MkDeclaratorIdentifier(MkIdentifier(name))), params);
1145 if(propertyDef.symbol.type && propertyDef.symbol.type.kind == TypeKind::classType && propertyDef.symbol.type._class && propertyDef.symbol.type._class.registered &&
1146 propertyDef.symbol.type._class.registered.type == structClass)
1148 ListAdd(params, MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), MkDeclaratorIdentifier(MkIdentifier("value"))));
1149 decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(name)), params));
1151 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, decl, null);
1153 // Take it out here...
1154 //propertyDef.specifiers = null;
1158 decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(name)), params));
1160 func = MkClassFunction(CopyList(propertyDef.specifiers, CopySpecifier),
1164 ProcessClassFunctionBody(func, propertyDef.getStmt);
1165 func.declarator.symbol = propertyDef.symbol;
1166 //func.declarator.propSymbol = propertyDef.symbol;
1167 propertyDef.symbol.externalGet = (External)func;
1169 func.dontMangle = true;
1170 newDef = MkClassDefFunction(func);
1171 definitions.Insert(after, newDef);
1175 propertyDef.getStmt = null;
1179 if(propertyDef.setStmt && propertyDef.id)
1181 OldList * specifiers = MkList();
1183 strcpy(name, "__ecereProp_");
1184 FullClassNameCat(name, symbol.string, false);
1185 strcat(name, "_Set_");
1186 //strcat(name, propertyDef.id.string);
1187 FullClassNameCat(name, propertyDef.id.string, true);
1188 MangleClassName(name);
1192 ListAdd(params, MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier),
1193 PlugDeclarator(propertyDef.declarator,
1194 MkDeclaratorIdentifier(MkIdentifier("value")))));
1196 // Take it out here...
1197 //propertyDef.specifiers = null;
1199 decl = MkDeclaratorFunction(
1200 MkDeclaratorIdentifier(MkIdentifier(name)), params);
1202 // TESTING COMMENTING OUT THESE, ADDED noHeadClass here
1203 if(!propertyDef.symbol._property || !propertyDef.symbol._property.conversion)
1204 ListAdd(specifiers, MkSpecifier(VOID));
1207 // Conversion property
1208 if(regClass.type == structClass)
1209 ListAdd(specifiers, MkSpecifier(VOID));
1211 ListAdd(specifiers, MkSpecifierName(regClass.fullName));
1214 func = MkClassFunction(specifiers, null, decl, null);
1215 ProcessClassFunctionBody(func, propertyDef.setStmt);
1216 func.dontMangle = true;
1217 func.declarator.symbol = propertyDef.symbol;
1218 //func.declarator.propSymbol = propertyDef.symbol;
1219 propertyDef.symbol.externalSet = (External)func;
1220 if(!propertyDef.conversion && regClass.type == normalClass)
1221 func.propSet = propertyDef.symbol;
1225 func.declarator.symbol = Symbol { id = propertyDef.symbol.id + 1 };
1226 //func.declarator.symbol.methodExternal = (External)func;
1229 newDef = MkClassDefFunction(func);
1230 definitions.Insert(after, newDef);
1234 propertyDef.setStmt = null;
1238 if(propertyDef.issetStmt && propertyDef.id)
1240 OldList * specifiers = MkList();
1242 strcpy(name, "__ecereProp_");
1243 FullClassNameCat(name, symbol.string, false);
1244 strcat(name, "_IsSet_");
1245 //strcat(name, propertyDef.id.string);
1246 FullClassNameCat(name, propertyDef.id.string, true);
1247 MangleClassName(name);
1251 decl = MkDeclaratorFunction(
1252 MkDeclaratorIdentifier(MkIdentifier(name)), params);
1254 ListAdd(specifiers, MkSpecifierName("bool"));
1256 func = MkClassFunction(specifiers, null, decl, null);
1257 ProcessClassFunctionBody(func, propertyDef.issetStmt);
1258 func.dontMangle = true;
1259 func.declarator.symbol = propertyDef.symbol;
1260 //func.declarator.propSymbol = propertyDef.symbol;
1261 propertyDef.symbol.externalIsSet = (External)func;
1265 func.declarator.symbol = Symbol { id = propertyDef.symbol,id + 1, external = (External)func };
1268 newDef = MkClassDefFunction(func);
1269 definitions.Insert(after, newDef);
1273 propertyDef.issetStmt = null;
1277 if(propertyDef.id && inCompiler)
1279 // Had to put this here because not all properties go through DeclareProperty
1280 Property prop = eClass_FindProperty(symbol.registered, propertyDef.id.string, privateModule);
1284 OldList * specifiers = MkList();
1285 specifiers->Insert(null, MkSpecifier(STATIC));
1286 ListAdd(specifiers, MkSpecifierName("Property"));
1287 strcpy(name, "__ecereProp_");
1288 FullClassNameCat(name, symbol.string, false);
1290 //strcat(name, propertyDef.id.string);
1291 FullClassNameCat(name, propertyDef.id.string, true);
1292 MangleClassName(name);
1295 OldList * list = MkList();
1296 ListAdd(list, MkInitDeclarator(/*MkDeclaratorPointer(MkPointer(null, null), */
1297 MkDeclaratorIdentifier(MkIdentifier(name))/*)*/, null));
1299 strcpy(name, "__ecerePropM_");
1300 FullClassNameCat(name, symbol.string, false);
1302 //strcat(name, propertyDef.id.string);
1303 FullClassNameCat(name, propertyDef.id.string, true);
1304 MangleClassName(name);
1306 ListAdd(list, MkInitDeclarator(/*MkDeclaratorPointer(MkPointer(null, null), */
1307 MkDeclaratorIdentifier(MkIdentifier(name))/*)*/, null));
1308 decl = MkDeclaration(specifiers, list);
1310 external = MkExternalDeclaration(decl);
1311 ast->Insert(curExternal ? curExternal.prev : null, external);
1312 external.symbol = propertyDef.symbol;
1314 // Setting it in the Property as well here to prevent DeclareProperty to declare it a second time...
1315 propertyDef.symbol.externalPtr = external;
1317 if(inCompiler && prop && prop.symbol)
1318 ((Symbol)prop.symbol).externalPtr = external;
1323 else if(def.type == classPropertyClassDef && def.propertyDef)
1325 PropertyDef propertyDef = def.propertyDef;
1326 ClassDef after = def;
1331 yylloc = propertyDef.loc;
1333 if(!NameSpaceContained(regClass.nameSpace, ®Class.module.privateNameSpace))
1334 CheckPublicDataType(propertyDef.symbol.type, publicAccess, "classwide property");
1335 else if(!symbol.isStatic)
1336 CheckPublicDataType(propertyDef.symbol.type, privateAccess, "classwide property");
1339 // Commented this out... Why exactly?
1346 if(propertyDef.getStmt && propertyDef.id)
1350 sprintf(name, "class::__ecereClassProp_");
1351 FullClassNameCat(name, symbol.string, false);
1352 strcat(name, "_Get_");
1353 strcat(name, propertyDef.id.string);
1354 MangleClassName(name);
1358 declId = MkDeclaratorIdentifier(MkIdentifier(name));
1360 // Class properties returns a uint64 even for struct types
1361 /*if(propertyDef.symbol.type && propertyDef.symbol.type.kind == TypeKind::classType && propertyDef.symbol.type._class && propertyDef.symbol.type._class.registered &&
1362 propertyDef.symbol.type._class.registered.type == structClass)
1364 // ListAdd(params, MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), MkDeclaratorIdentifier(MkIdentifier("value"))));
1365 //decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(declId, params));
1366 decl = MkDeclaratorFunction(declId, params);
1367 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorIdentifier(MkIdentifier("_value"))));
1369 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, decl, null);
1372 Statement body = propertyDef.getStmt;
1373 decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(declId, params));
1374 if(!body.compound.declarations)
1375 body.compound.declarations = MkList();
1376 ListAdd(body.compound.declarations,
1377 MkDeclaration(CopyList(propertyDef.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(
1378 ptrDecl = MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("value"))), MkInitializerAssignment(MkExpCast(MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), CopyDeclarator(propertyDef.declarator)),
1379 MkExpIdentifier(MkIdentifier("_value"))))))));
1381 Symbol sym = ptrDecl.symbol;
1384 sym.type = ProcessType(propertyDef.specifiers, propertyDef.declarator);
1391 //decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(declId, params));
1392 decl = MkDeclaratorFunction(declId, params);
1393 //func = MkClassFunction(CopyList(propertyDef.specifiers, CopySpecifier), null, decl, null);
1394 func = MkClassFunction(MkListOne(MkSpecifierName("uint64")), null, decl, null);
1397 ProcessClassFunctionBody(func, propertyDef.getStmt);
1398 func.declarator.symbol = propertyDef.symbol;
1399 propertyDef.symbol.externalGet = (External)func;
1401 func.dontMangle = true;
1403 newDef = MkClassDefFunction(func);
1404 definitions.Insert(after, newDef);
1407 func.type = ProcessType(propertyDef.specifiers, MkDeclaratorFunction(propertyDef.declarator, null));
1408 if(func.type.returnType.kind == TypeKind::classType && func.type.returnType._class && func.type.returnType._class.registered && func.type.returnType._class.registered.type == structClass)
1409 func.type.returnType.byReference = true;
1412 propertyDef.getStmt = null;
1416 if(propertyDef.setStmt && propertyDef.id)
1418 Context prevCurContext;
1419 OldList * specifiers = MkList();
1420 Statement body = propertyDef.setStmt;
1423 strcpy(name, "class::__ecereClassProp_");
1424 FullClassNameCat(name, symbol.string, false);
1425 strcat(name, "_Set_");
1426 strcat(name, propertyDef.id.string);
1427 MangleClassName(name);
1431 ListAdd(params, MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier),
1432 PlugDeclarator(propertyDef.declarator,
1433 MkDeclaratorIdentifier(MkIdentifier("value")))));
1436 prevCurContext = curContext;
1437 curContext = body.compound.context;
1439 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorIdentifier(MkIdentifier("_value"))));
1441 decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(name)), params);
1442 if(!body.compound.declarations)
1443 body.compound.declarations = MkList();
1445 if(propertyDef.symbol.type && propertyDef.symbol.type.kind == TypeKind::classType && propertyDef.symbol.type._class && propertyDef.symbol.type._class.registered &&
1446 propertyDef.symbol.type._class.registered.type == structClass)
1447 ptrDecl = MkDeclaratorPointer(MkPointer(null, null), PlugDeclarator(propertyDef.declarator, MkDeclaratorIdentifier(MkIdentifier("value"))));
1449 ptrDecl = PlugDeclarator(propertyDef.declarator, MkDeclaratorIdentifier(MkIdentifier("value")));
1451 ListAdd(body.compound.declarations,
1452 MkDeclaration(CopyList(propertyDef.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(ptrDecl,
1453 MkInitializerAssignment(MkExpCast(MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), CopyDeclarator(propertyDef.declarator)),
1454 MkExpIdentifier(MkIdentifier("_value"))))))));
1456 curContext = prevCurContext;
1459 Symbol sym = ptrDecl.symbol;
1462 sym.type = ProcessType(propertyDef.specifiers, propertyDef.declarator);
1464 ListAdd(specifiers, MkSpecifier(VOID));
1466 func = MkClassFunction(specifiers, null, decl, null);
1467 ProcessClassFunctionBody(func, propertyDef.setStmt);
1468 func.dontMangle = true;
1469 func.declarator.symbol = propertyDef.symbol;
1470 propertyDef.symbol.externalSet = (External)func;
1472 newDef = MkClassDefFunction(func);
1473 definitions.Insert(after, newDef);
1477 propertyDef.setStmt = null;
1485 else if(def.type == functionClassDef && def.function.declarator)
1487 ClassFunction func = def.function;
1489 func._class = regClass;
1490 // Add ecereMethod_[class]_ to the declarator
1491 if(!func.dontMangle)
1493 Declarator funcDecl = GetFuncDecl(func.declarator);
1494 Identifier id = GetDeclId(funcDecl);
1497 if(!funcDecl.function.parameters || !funcDecl.function.parameters->first)
1499 if(!funcDecl.function.parameters)
1500 funcDecl.function.parameters = MkList();
1501 ListAdd(funcDecl.function.parameters, MkTypeName(MkListOne(MkSpecifier(VOID)), null));
1504 method = eClass_FindMethod(regClass, id.string, privateModule);
1506 FreeSpecifier(id._class);
1508 if(inCompiler && method)
1510 char * newId = new char[strlen(id.string) + strlen("__ecereMethod___ecereNameSpace__") + strlen(symbol.string) + 2];
1513 ProcessMethodType(method);
1515 if(!NameSpaceContained(regClass.nameSpace, ®Class.module.privateNameSpace) && method.memberAccess == publicAccess)
1516 CheckPublicDataType(method.dataType, publicAccess, "class method");
1517 /* HAVE TO RELAX THIS SINCE static CAN'T QUALIFY METHODS YET... (Conflict with C++ static meaning)
1518 else if(!symbol.isStatic)
1519 CheckPublicDataType(method.dataType, privateAccess, "class method");
1522 strcpy(newId, "__ecereMethod_");
1523 FullClassNameCat(newId, symbol.string, false);
1525 strcat(newId, id.string);
1531 if(method.type != virtualMethod)
1535 delete ((Symbol)method.symbol).string;
1536 ((Symbol)method.symbol).string = CopyString(newId);
1545 if(initDeclarators != null)
1546 FreeList(initDeclarators, FreeInitDeclarator);
1549 public void PreProcessClassDefinitions()
1551 External external, next;
1557 for(external = ast->first; external; external = next)
1559 next = external.next;
1560 curExternal = external;
1561 if(external.type == classExternal)
1563 ClassDefinition _class = external._class;
1564 if(_class.definitions)
1566 ProcessClass(normalClass, _class.definitions, _class.symbol, _class.baseSpecs, null, _class.loc, ast, external.prev, null, null);
1569 else if(external.type == declarationExternal)
1571 Declaration declaration = external.declaration;
1572 if(declaration.type == initDeclaration)
1574 if(declaration.specifiers)
1576 Specifier specifier;
1577 for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
1579 if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
1580 (declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
1582 Symbol symbol = FindClass(specifier.id.string);
1585 OldList * initDeclarators = null;
1586 ExtDecl extDecl = specifier.extDeclStruct;
1587 specifier.extDeclStruct = null;
1590 // Give the declarators away to ProcessClass
1591 // It will include the declarators in the class if appropriate, otherwise free them
1592 initDeclarators = declaration.declarators;
1593 declaration.declarators = null;
1595 ProcessClass((specifier.type == unionSpecifier) ? unionClass : normalClass, specifier.definitions,
1596 symbol, specifier.baseSpecs, specifier.list, specifier.loc, ast, external.prev,
1597 initDeclarators, extDecl);
1603 else if(inCompiler && declaration.type == defineDeclaration)
1605 yylloc = declaration.loc;
1606 if(declaration.declMode == publicAccess)
1607 CheckPublicExpression(declaration.exp, publicAccess);
1608 else if(declaration.declMode != staticAccess)
1609 CheckPublicExpression(declaration.exp, privateAccess);
1612 else if(external.type == importExternal)
1614 //ImportModule(external._import);
1616 else if(inCompiler && external.type == functionExternal)
1618 yylloc = external.function.loc;
1619 if(!external.function.type)
1620 external.function.type = ProcessType(external.function.specifiers, external.function.declarator);
1621 if(external.function.declMode == publicAccess)
1622 CheckPublicDataType(external.function.type, publicAccess, "function");
1623 else if(external.function.declMode != staticAccess)
1624 CheckPublicDataType(external.function.type, privateAccess, "function");