4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
52 OutputExpression(exp, f);
54 count = strlen(string);
55 count += f.Read(string + count, 1, 1023);
61 int64 _strtoi64(char * string, char ** endString, int base)
67 for(c = 0; (ch = string[c]) && isspace(ch); c++);
69 else if(ch == '-') { sign = -1; c++; };
72 if(ch == 0 && string[c+1] == 'x')
85 for( ;(ch = string[c]); c++)
89 else if(ch >= '1' && ch <= '9')
91 else if(ch >= 'a' && ch <= 'z')
93 else if(ch >= 'A' && ch <= 'Z')
98 *endString = string + c;
110 *endString = string + c;
118 uint64 _strtoui64(char * string, char ** endString, int base)
124 for(c = 0; (ch = string[c]) && isspace(ch); c++);
126 else if(ch == '-') { sign = -1; c++; };
129 if(ch == 0 && string[c+1] == 'x')
142 for( ;(ch = string[c]); c++)
146 else if(ch >= '1' && ch <= '9')
148 else if(ch >= 'a' && ch <= 'z')
150 else if(ch >= 'A' && ch <= 'Z')
154 if(endString) *endString = string + c;
166 *endString = string + c;
174 Type ProcessTemplateParameterType(TemplateParameter param)
176 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
178 // TOFIX: Will need to free this Type
181 if(param.dataTypeString)
182 param.baseType = ProcessTypeString(param.dataTypeString, false);
184 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
186 return param.baseType;
191 bool NeedCast(Type type1, Type type2)
193 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
195 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
200 if(type1.kind == type2.kind)
208 if(type1.passAsTemplate && !type2.passAsTemplate)
210 return type1.isSigned != type2.isSigned;
212 return type1._class != type2._class;
214 return NeedCast(type1.type, type2.type);
216 return true; //false; ????
222 static void ReplaceClassMembers(Expression exp, Class _class)
224 if(exp.type == identifierExp && exp.identifier)
226 Identifier id = exp.identifier;
228 Symbol symbol = null;
229 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
231 // First, check if the identifier is declared inside the function
232 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
234 symbol = (Symbol)ctx.symbols.FindString(id.string);
239 // If it is not, check if it is a member of the _class
240 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
242 Property prop = eClass_FindProperty(_class, id.string, privateModule);
243 Method method = null;
244 DataMember member = null;
245 ClassProperty classProp;
248 method = eClass_FindMethod(_class, id.string, privateModule);
251 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
252 if(!prop && !method && !member)
254 classProp = eClass_FindClassProperty(_class, id.string);
256 if(prop || method || member || classProp)
258 // Replace by this.[member]
259 exp.type = memberExp;
260 exp.member.member = id;
261 exp.member.memberType = unresolvedMember;
262 exp.member.exp = QMkExpId("this");
263 //exp.member.exp.loc = exp.loc;
264 exp.addedThis = true;
266 else if(_class && _class.templateParams.first)
269 for(sClass = _class; sClass; sClass = sClass.base)
271 if(sClass.templateParams.first)
273 ClassTemplateParameter param;
274 for(param = sClass.templateParams.first; param; param = param.next)
276 if(param.type == expression && !strcmp(param.name, id.string))
278 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
283 OldList * specs = MkList();
285 FreeIdentifier(exp.member.member);
287 ProcessExpressionType(argExp);
289 decl = SpecDeclFromString(param.dataTypeString, specs, null);
291 exp.expType = ProcessType(specs, decl);
293 // *[expType] *[argExp]
294 exp.type = bracketsExp;
295 exp.list = MkListOne(MkExpOp(null, '*',
296 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
307 ////////////////////////////////////////////////////////////////////////
308 // PRINTING ////////////////////////////////////////////////////////////
309 ////////////////////////////////////////////////////////////////////////
311 public char * PrintInt(int64 result)
314 if(result > MAXINT64)
315 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
317 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
318 return CopyString(temp);
321 public char * PrintUInt(uint64 result)
324 if(result > MAXDWORD)
325 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
326 else if(result > MAXINT)
327 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
329 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
330 return CopyString(temp);
333 public char * PrintInt64(int64 result)
336 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
337 return CopyString(temp);
340 public char * PrintUInt64(uint64 result)
343 if(result > MAXINT64)
344 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
346 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
347 return CopyString(temp);
350 public char * PrintHexUInt(uint64 result)
353 if(result > MAXDWORD)
354 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
356 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
357 return CopyString(temp);
360 public char * PrintHexUInt64(uint64 result)
363 if(result > MAXDWORD)
364 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
366 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
367 return CopyString(temp);
370 public char * PrintShort(short result)
373 sprintf(temp, "%d", (unsigned short)result);
374 return CopyString(temp);
377 public char * PrintUShort(unsigned short result)
381 sprintf(temp, "0x%X", (int)result);
383 sprintf(temp, "%d", result);
384 return CopyString(temp);
387 public char * PrintChar(char result)
390 if(result > 0 && isprint(result))
391 sprintf(temp, "'%c'", result);
393 sprintf(temp, "%d", result);
395 //sprintf(temp, "%#X", result);
396 sprintf(temp, "0x%X", (unsigned char)result);
397 return CopyString(temp);
400 public char * PrintUChar(unsigned char result)
403 sprintf(temp, "0x%X", result);
404 return CopyString(temp);
407 public char * PrintFloat(float result)
410 sprintf(temp, "%.16ff", result);
411 return CopyString(temp);
414 public char * PrintDouble(double result)
417 sprintf(temp, "%.16f", result);
418 return CopyString(temp);
421 ////////////////////////////////////////////////////////////////////////
422 ////////////////////////////////////////////////////////////////////////
424 //public Operand GetOperand(Expression exp);
426 #define GETVALUE(name, t) \
427 public bool Get##name(Expression exp, t * value2) \
429 Operand op2 = GetOperand(exp); \
430 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
431 else if(op2.kind == intType) *value2 = (t) op2.ui; \
432 if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
433 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
434 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
435 else if(op2.kind == shortType) *value2 = (t) op2.us; \
436 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
437 else if(op2.kind == charType) *value2 = (t) op2.uc; \
438 else if(op2.kind == floatType) *value2 = (t) op2.f; \
439 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
440 else if(op2.kind == pointerType) *value2 = (t) op2.ui; \
447 GETVALUE(UInt, unsigned int);
448 GETVALUE(Int64, int64);
449 GETVALUE(UInt64, uint64);
450 GETVALUE(Short, short);
451 GETVALUE(UShort, unsigned short);
452 GETVALUE(Char, char);
453 GETVALUE(UChar, unsigned char);
454 GETVALUE(Float, float);
455 GETVALUE(Double, double);
457 void ComputeExpression(Expression exp);
459 void ComputeClassMembers(Class _class, bool isMember)
461 DataMember member = isMember ? (DataMember) _class : null;
462 Context context = isMember ? null : SetupTemplatesContext(_class);
463 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
464 (_class.type == bitClass || _class.structSize == _class.offset) && _class.computeSize))
467 int unionMemberOffset = 0;
470 if(!member && _class.destructionWatchOffset)
471 _class.memberOffset += sizeof(OldList);
473 // To avoid reentrancy...
474 //_class.structSize = -1;
477 DataMember dataMember;
478 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
480 if(!dataMember.isProperty)
482 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
484 /*if(dataMember.dataType)
486 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
487 /*if(!dataMember.dataType)
488 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
496 DataMember dataMember;
497 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
499 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
501 if(!isMember && _class.type == bitClass && dataMember.dataType)
503 BitMember bitMember = (BitMember) dataMember;
507 ComputeTypeSize(dataMember.dataType);
509 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
510 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
512 _class.memberOffset = bitMember.pos + bitMember.size;
513 for(d = 0; d<bitMember.size; d++)
519 bitMember.mask = mask << bitMember.pos;
521 else if(dataMember.type == normalMember && dataMember.dataType)
526 // Prevent infinite recursion
527 if(dataMember.dataType.kind != classType ||
528 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
529 _class.type != structClass)))
530 ComputeTypeSize(dataMember.dataType);
532 if(dataMember.dataType.bitFieldCount)
534 bitFields += dataMember.dataType.bitFieldCount;
541 int size = (bitFields + 7) / 8;
545 // TESTING THIS PADDING CODE
548 member.structAlignment = Max(member.structAlignment, alignment);
550 if(member.memberOffset % alignment)
551 member.memberOffset += alignment - (member.memberOffset % alignment);
554 dataMember.offset = member.memberOffset;
555 if(member.type == unionMember)
556 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
559 member.memberOffset += size;
564 // TESTING THIS PADDING CODE
567 _class.structAlignment = Max(_class.structAlignment, alignment);
569 if(_class.memberOffset % alignment)
570 _class.memberOffset += alignment - (_class.memberOffset % alignment);
573 dataMember.offset = _class.memberOffset;
574 _class.memberOffset += size;
578 size = dataMember.dataType.size;
579 alignment = dataMember.dataType.alignment;
590 // TESTING THIS PADDING CODE
593 member.structAlignment = Max(member.structAlignment, alignment);
595 if(member.memberOffset % alignment)
596 member.memberOffset += alignment - (member.memberOffset % alignment);
599 dataMember.offset = member.memberOffset;
600 if(member.type == unionMember)
601 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
604 member.memberOffset += size;
609 // TESTING THIS PADDING CODE
612 _class.structAlignment = Max(_class.structAlignment, alignment);
614 if(_class.memberOffset % alignment)
615 _class.memberOffset += alignment - (_class.memberOffset % alignment);
618 dataMember.offset = _class.memberOffset;
619 _class.memberOffset += size;
624 ComputeClassMembers((Class)dataMember, true);
628 // THERE WASN'T A MAX HERE ? member.structAlignment = dataMember.structAlignment;
629 member.structAlignment = Max(member.structAlignment, dataMember.structAlignment);
630 dataMember.offset = member.memberOffset;
631 if(member.type == unionMember)
632 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
634 member.memberOffset += dataMember.memberOffset;
638 _class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
639 dataMember.offset = _class.memberOffset;
640 _class.memberOffset += dataMember.memberOffset;
648 int size = (bitFields + 7) / 8;
652 // TESTING THIS PADDING CODE
655 member.structAlignment = Max(member.structAlignment, alignment);
657 if(member.memberOffset % alignment)
658 member.memberOffset += alignment - (member.memberOffset % alignment);
661 if(member.type == unionMember)
662 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
665 member.memberOffset += size;
670 // TESTING THIS PADDING CODE
673 _class.structAlignment = Max(_class.structAlignment, alignment);
675 if(_class.memberOffset % alignment)
676 _class.memberOffset += alignment - (_class.memberOffset % alignment);
678 _class.memberOffset += size;
683 if(member && member.type == unionMember)
685 member.memberOffset = unionMemberOffset;
690 /*if(_class.type == structClass)
691 _class.size = _class.memberOffset;
695 if(_class.type != bitClass)
697 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset;
701 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
703 if(prop.isProperty && prop.isWatchable)
705 prop.watcherOffset = _class.structSize;
706 _class.structSize += sizeof(OldList);
714 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
716 Class deriv = derivative.data;
718 if(deriv.computeSize)
720 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
721 deriv.offset = /*_class.offset + */_class.structSize;
722 deriv.memberOffset = 0;
723 // ----------------------
725 deriv.structSize = deriv.offset;
727 ComputeClassMembers(deriv, false);
735 FinishTemplatesContext(context);
738 public void ComputeModuleClasses(Module module)
743 for(subModule = module.modules.first; subModule; subModule = subModule.next)
744 ComputeModuleClasses(subModule.data);
745 for(_class = module.classes.first; _class; _class = _class.next)
746 ComputeClassMembers(_class, false);
750 public int ComputeTypeSize(Type type)
752 uint size = type ? type.size : 0;
753 if(!size && type && !type.computing)
755 type.computing = true;
758 case charType: type.alignment = size = sizeof(char); break;
759 case intType: type.alignment = size = sizeof(int); break;
760 case int64Type: type.alignment = size = sizeof(int64); break;
761 case longType: type.alignment = size = sizeof(long); break;
762 case shortType: type.alignment = size = sizeof(short); break;
763 case floatType: type.alignment = size = sizeof(float); break;
764 case doubleType: type.alignment = size = sizeof(double); break;
767 Class _class = type._class ? type._class.registered : null;
769 if(_class && _class.type == structClass)
771 // Ensure all members are properly registered
772 ComputeClassMembers(_class, false);
773 type.alignment = _class.structAlignment;
774 size = _class.structSize;
775 if(type.alignment && size % type.alignment)
776 size += type.alignment - (size % type.alignment);
779 else if(_class && (_class.type == unitClass ||
780 _class.type == enumClass ||
781 _class.type == bitClass))
784 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
785 size = type.alignment = ComputeTypeSize(_class.dataType);
788 size = type.alignment = sizeof(Instance *);
791 case pointerType: case subClassType: size = type.alignment = sizeof(void *); break;
793 if(type.arraySizeExp)
795 ProcessExpressionType(type.arraySizeExp);
796 ComputeExpression(type.arraySizeExp);
797 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
798 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
800 Location oldLoc = yylloc;
801 // bool isConstant = type.arraySizeExp.isConstant;
802 char expression[10240];
803 expression[0] = '\0';
804 type.arraySizeExp.expType = null;
805 yylloc = type.arraySizeExp.loc;
807 PrintExpression(type.arraySizeExp, expression);
808 Compiler_Error($"Array size not constant int (%s)\n", expression);
811 GetInt(type.arraySizeExp, &type.arraySize);
819 else if(type.enumClass)
821 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
823 type.arraySize = eClass_GetProperty(type.enumClass.registered, "enumSize");
830 // Unimplemented auto size
834 size = ComputeTypeSize(type.type) * type.arraySize;
835 type.alignment = type.type.alignment;
841 for(member = type.members.first; member; member = member.next)
843 uint addSize = ComputeTypeSize(member);
845 member.offset = size;
846 if(member.alignment && size % member.alignment)
847 member.offset += member.alignment - (size % member.alignment);
848 size = member.offset;
850 type.alignment = Max(type.alignment, member.alignment);
853 if(type.alignment && size % type.alignment)
854 size += type.alignment - (size % type.alignment);
860 for(member = type.members.first; member; member = member.next)
862 uint addSize = ComputeTypeSize(member);
864 member.offset = size;
865 if(member.alignment && size % member.alignment)
866 member.offset += member.alignment - (size % member.alignment);
867 size = member.offset;
869 type.alignment = Max(type.alignment, member.alignment);
870 size = Max(size, addSize);
872 if(type.alignment && size % type.alignment)
873 size += type.alignment - (size % type.alignment);
878 TemplateParameter param = type.templateParameter;
879 Type baseType = ProcessTemplateParameterType(param);
881 size = ComputeTypeSize(baseType);
883 size = sizeof(uint64);
888 size = sizeof(enum { test });
893 size = sizeof(void *);
898 type.computing = false;
904 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass)
906 // This function is in need of a major review when implementing private members etc.
907 DataMember topMember = isMember ? (DataMember) _class : null;
912 Context context = isMember ? null : SetupTemplatesContext(_class);
914 if(!isMember && _class.base)
916 maxSize = _class.structSize;
917 //if(_class.base.type != systemClass) // Commented out with new Instance _class
919 // DANGER: Testing this noHeadClass here...
920 if(_class.type == structClass || _class.type == noHeadClass)
921 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass);
923 maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
927 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
929 if(!member.isProperty)
935 if(member.dataTypeString)
937 OldList * specs = MkList(), * decls = MkList();
940 decl = SpecDeclFromString(member.dataTypeString, specs,
941 MkDeclaratorIdentifier(MkIdentifier(member.name)));
942 ListAdd(decls, MkStructDeclarator(decl, null));
943 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
946 member.dataType = ProcessType(specs, decl);
948 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
951 Type type = ProcessType(specs, decl);
952 DeclareType(member.dataType, false, false);
956 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
957 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
958 DeclareStruct(member.dataType._class.string, false);
961 ComputeTypeSize(member.dataType);
962 size = member.dataType.size;
963 alignment = member.dataType.alignment;
967 if(totalSize % alignment)
968 totalSize += alignment - (totalSize % alignment);
977 OldList * specs = MkList(), * list = MkList();
980 AddMembers(list, (Class)member, true, &size, topClass);
982 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
983 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
984 alignment = member.structAlignment;
988 if(totalSize % alignment)
989 totalSize += alignment - (totalSize % alignment);
999 if(topMember && topMember.type == unionMember)
1000 *retSize = Max(*retSize, totalSize);
1002 *retSize += totalSize;
1004 else if(totalSize < maxSize && _class.type != systemClass)
1006 char sizeString[50];
1007 sprintf(sizeString, "%d", maxSize - totalSize);
1008 ListAdd(declarations,
1009 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1010 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1013 FinishTemplatesContext(context);
1014 return topMember ? topMember.memberID : _class.memberID;
1017 static int DeclareMembers(Class _class, bool isMember)
1019 DataMember topMember = isMember ? (DataMember) _class : null;
1022 Context context = isMember ? null : SetupTemplatesContext(_class);
1024 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1025 DeclareMembers(_class.base, false);
1027 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1029 if(!member.isProperty)
1036 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1037 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1038 DeclareStruct(member.dataType._class.string, false);
1040 if(!member.dataType && member.dataTypeString)
1041 member.dataType = ProcessTypeString(member.dataTypeString, false);
1043 DeclareType(member.dataType, false, false);
1049 DeclareMembers((Class)member, true);
1056 FinishTemplatesContext(context);
1058 return topMember ? topMember.memberID : _class.memberID;
1061 void DeclareStruct(char * name, bool skipNoHead)
1063 External external = null;
1064 Symbol classSym = FindClass(name);
1066 if(!inCompiler || !classSym) return null;
1068 // We don't need any declaration for bit classes...
1069 if(classSym.registered &&
1070 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1073 /*if(classSym.registered.templateClass)
1074 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1077 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1079 // Add typedef struct
1081 OldList * specifiers, * declarators;
1082 OldList * declarations = null;
1083 char structName[1024];
1084 external = (classSym.registered && classSym.registered.type == structClass) ?
1085 classSym.pointerExternal : classSym.structExternal;
1087 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1088 // Moved this one up because DeclareClass done later will need it
1090 classSym.declaring++;
1092 if(strchr(classSym.string, '<'))
1094 if(classSym.registered.templateClass)
1096 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1097 classSym.declaring--;
1103 DeclareMembers(classSym.registered, false);
1106 FullClassNameCat(structName, name, false);
1109 external = MkExternalDeclaration(null);*/
1113 classSym.declaredStructSym = true;
1115 declarations = MkList();
1117 AddMembers(declarations, classSym.registered, false, null, classSym.registered);
1119 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1120 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1122 if(!declarations->count)
1124 FreeList(declarations, null);
1125 declarations = null;
1128 if(skipNoHead || declarations)
1130 if(external && external.declaration)
1132 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1134 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1137 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1140 if(classSym.structExternal)
1141 ast->Move(classSym.structExternal, curExternal.prev);
1142 ast->Move(classSym.pointerExternal, curExternal.prev);
1144 classSym.id = curExternal.symbol.idCode;
1145 classSym.idCode = curExternal.symbol.idCode;
1146 // external = classSym.pointerExternal;
1147 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1153 external = MkExternalDeclaration(null);
1155 specifiers = MkList();
1156 declarators = MkList();
1157 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1160 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1161 ListAdd(declarators, MkInitDeclarator(d, null));
1163 external.declaration = decl = MkDeclaration(specifiers, declarators);
1164 if(decl.symbol && !decl.symbol.pointerExternal)
1165 decl.symbol.pointerExternal = external;
1167 // For simple classes, keep the declaration as the external to move around
1168 if(classSym.registered && classSym.registered.type == structClass)
1170 char className[1024];
1171 strcpy(className, "__ecereClass_");
1172 FullClassNameCat(className, classSym.string, true);
1173 MangleClassName(className);
1176 DeclareClass(classSym, className);
1178 external.symbol = classSym;
1179 classSym.pointerExternal = external;
1180 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1181 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1185 char className[1024];
1186 strcpy(className, "__ecereClass_");
1187 FullClassNameCat(className, classSym.string, true);
1188 MangleClassName(className);
1190 // TOFIX: TESTING THIS...
1191 classSym.structExternal = external;
1192 DeclareClass(classSym, className);
1193 external.symbol = classSym;
1197 ast->Insert(curExternal ? curExternal.prev : null, external);
1201 classSym.declaring--;
1203 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1205 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1206 // Moved this one up because DeclareClass done later will need it
1209 classSym.declaring++;
1213 if(classSym.registered)
1214 DeclareMembers(classSym.registered, false);
1217 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1220 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1223 if(classSym.structExternal)
1224 ast->Move(classSym.structExternal, curExternal.prev);
1225 ast->Move(classSym.pointerExternal, curExternal.prev);
1227 classSym.id = curExternal.symbol.idCode;
1228 classSym.idCode = curExternal.symbol.idCode;
1229 // external = classSym.pointerExternal;
1230 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1233 classSym.declaring--;
1238 void DeclareProperty(Property prop, char * setName, char * getName)
1240 Symbol symbol = prop.symbol;
1241 char propName[1024];
1243 strcpy(setName, "__ecereProp_");
1244 FullClassNameCat(setName, prop._class.fullName, false);
1245 strcat(setName, "_Set_");
1246 // strcat(setName, prop.name);
1247 FullClassNameCat(setName, prop.name, true);
1249 strcpy(getName, "__ecereProp_");
1250 FullClassNameCat(getName, prop._class.fullName, false);
1251 strcat(getName, "_Get_");
1252 FullClassNameCat(getName, prop.name, true);
1253 // strcat(getName, prop.name);
1255 strcpy(propName, "__ecereProp_");
1256 FullClassNameCat(propName, prop._class.fullName, false);
1257 strcat(propName, "_");
1258 FullClassNameCat(propName, prop.name, true);
1259 // strcat(propName, prop.name);
1261 // To support "char *" property
1262 MangleClassName(getName);
1263 MangleClassName(setName);
1264 MangleClassName(propName);
1266 if(prop._class.type == structClass)
1267 DeclareStruct(prop._class.fullName, false);
1269 if(!symbol || curExternal.symbol.idCode < symbol.id)
1271 bool imported = false;
1272 bool dllImport = false;
1273 if(!symbol || symbol._import)
1278 if(!prop._class.symbol)
1279 prop._class.symbol = FindClass(prop._class.fullName);
1280 classSym = prop._class.symbol;
1281 if(classSym && !classSym._import)
1283 ModuleImport module;
1285 if(prop._class.module)
1286 module = FindModule(prop._class.module);
1288 module = mainModule;
1290 classSym._import = ClassImport
1292 name = CopyString(prop._class.fullName);
1293 isRemote = prop._class.isRemote;
1295 module.classes.Add(classSym._import);
1297 symbol = prop.symbol = Symbol { };
1298 symbol._import = (ClassImport)PropertyImport
1300 name = CopyString(prop.name);
1301 isVirtual = false; //prop.isVirtual;
1302 hasSet = prop.Set ? true : false;
1303 hasGet = prop.Get ? true : false;
1306 classSym._import.properties.Add(symbol._import);
1309 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1315 Context context = SetupTemplatesContext(prop._class);
1316 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1317 FinishTemplatesContext(context);
1323 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1326 OldList * specifiers, * declarators;
1331 Declarator typeDecl;
1332 bool simple = false;
1334 specifiers = MkList();
1335 declarators = MkList();
1338 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1339 MkDeclaratorIdentifier(MkIdentifier("this"))));
1341 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1344 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1347 Context context = SetupTemplatesContext(prop._class);
1348 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1349 FinishTemplatesContext(context);
1352 // Make sure the simple _class's type is declared
1353 for(spec = specifiers->first; spec; spec = spec.next)
1355 if(spec.type == nameSpecifier /*SpecifierClass*/)
1357 if((!typeDecl || typeDecl.type == identifierDeclarator))
1359 Symbol classSym = spec.symbol; // FindClass(spec.name);
1360 symbol._class = classSym.registered;
1361 if(classSym.registered && classSym.registered.type == structClass)
1363 DeclareStruct(spec.name, false);
1371 d = PlugDeclarator(typeDecl, d);
1374 ListAdd(params, MkTypeName(specifiers,
1375 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1376 specifiers = MkList();
1379 d = MkDeclaratorFunction(d, params);
1383 specifiers->Insert(null, MkSpecifier(EXTERN));
1384 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1385 specifiers->Insert(null, MkSpecifier(STATIC));
1387 ListAdd(specifiers, MkSpecifier(VOID));
1389 ListAdd(declarators, MkInitDeclarator(d, null));
1391 decl = MkDeclaration(specifiers, declarators);
1393 external = MkExternalDeclaration(decl);
1394 ast->Insert(curExternal.prev, external);
1395 external.symbol = symbol;
1396 symbol.externalGet = external;
1398 ReplaceThisClassSpecifiers(specifiers, prop._class);
1401 FreeDeclarator(typeDecl);
1405 // Move declaration higher...
1406 ast->Move(symbol.externalGet, curExternal.prev);
1413 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1416 OldList * specifiers, * declarators;
1421 Declarator typeDecl;
1423 declarators = MkList();
1426 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1427 if(!prop.conversion || prop._class.type == structClass)
1429 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1430 MkDeclaratorIdentifier(MkIdentifier("this"))));
1433 specifiers = MkList();
1436 Context context = SetupTemplatesContext(prop._class);
1437 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1438 MkDeclaratorIdentifier(MkIdentifier("value")));
1439 FinishTemplatesContext(context);
1441 ListAdd(params, MkTypeName(specifiers, d));
1443 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1446 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1447 d = MkDeclaratorFunction(d, params);
1449 // Make sure the simple _class's type is declared
1450 for(spec = specifiers->first; spec; spec = spec.next)
1452 if(spec.type == nameSpecifier /*SpecifierClass*/)
1454 if((!typeDecl || typeDecl.type == identifierDeclarator))
1456 Symbol classSym = spec.symbol; // FindClass(spec.name);
1457 symbol._class = classSym.registered;
1458 if(classSym.registered && classSym.registered.type == structClass)
1459 DeclareStruct(spec.name, false);
1464 ListAdd(declarators, MkInitDeclarator(d, null));
1466 specifiers = MkList();
1469 specifiers->Insert(null, MkSpecifier(EXTERN));
1470 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1471 specifiers->Insert(null, MkSpecifier(STATIC));
1473 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1474 if(!prop.conversion || prop._class.type == structClass)
1475 ListAdd(specifiers, MkSpecifier(VOID));
1477 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1479 decl = MkDeclaration(specifiers, declarators);
1481 external = MkExternalDeclaration(decl);
1482 ast->Insert(curExternal.prev, external);
1483 external.symbol = symbol;
1484 symbol.externalSet = external;
1486 ReplaceThisClassSpecifiers(specifiers, prop._class);
1490 // Move declaration higher...
1491 ast->Move(symbol.externalSet, curExternal.prev);
1495 // Property (for Watchers)
1496 if(!symbol.externalPtr)
1500 OldList * specifiers = MkList();
1503 specifiers->Insert(null, MkSpecifier(EXTERN));
1505 specifiers->Insert(null, MkSpecifier(STATIC));
1507 ListAdd(specifiers, MkSpecifierName("Property"));
1510 OldList * list = MkList();
1511 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1512 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1516 strcpy(propName, "__ecerePropM_");
1517 FullClassNameCat(propName, prop._class.fullName, false);
1518 strcat(propName, "_");
1519 // strcat(propName, prop.name);
1520 FullClassNameCat(propName, prop.name, true);
1522 MangleClassName(propName);
1524 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1525 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1527 decl = MkDeclaration(specifiers, list);
1530 external = MkExternalDeclaration(decl);
1531 ast->Insert(curExternal.prev, external);
1532 external.symbol = symbol;
1533 symbol.externalPtr = external;
1537 // Move declaration higher...
1538 ast->Move(symbol.externalPtr, curExternal.prev);
1541 symbol.id = curExternal.symbol.idCode;
1545 // ***************** EXPRESSION PROCESSING ***************************
1546 public Type Dereference(Type source)
1551 if(source.kind == pointerType || source.kind == arrayType)
1554 source.type.refCount++;
1556 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1564 // Support dereferencing of no head classes for now...
1565 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1571 Compiler_Error($"cannot dereference type\n");
1576 static Type Reference(Type source)
1592 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1594 Identifier ident = member.identifiers ? member.identifiers->first : null;
1596 DataMember dataMember = null;
1597 Method method = null;
1598 bool freeType = false;
1600 yylloc = member.loc;
1606 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1610 dataMember = *curMember;
1616 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1617 DataMember _subMemberStack[256];
1618 int _subMemberStackPos = 0;
1620 // FILL MEMBER STACK
1622 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1625 dataMember = thisMember;
1626 if(curMember && thisMember.memberAccess == publicAccess)
1628 *curMember = thisMember;
1629 *curClass = thisMember._class;
1630 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
1631 *subMemberStackPos = _subMemberStackPos;
1638 method = eClass_FindMethod(_class, ident.string, privateModule);
1639 if(method && method.type == virtualMethod)
1651 if(!dataMember.dataType && dataMember.dataTypeString)
1653 //Context context = SetupTemplatesContext(dataMember._class);
1654 Context context = SetupTemplatesContext(_class);
1655 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1656 FinishTemplatesContext(context);
1658 type = dataMember.dataType;
1662 // This is for destination type...
1663 if(!method.dataType)
1664 ProcessMethodType(method);
1665 //DeclareMethod(method);
1666 // method.dataType = ((Symbol)method.symbol)->type;
1667 type = method.dataType;
1670 if(ident && ident.next)
1672 for(ident = ident.next; ident && type; ident = ident.next)
1674 if(type.kind == classType)
1676 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1678 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1680 type = dataMember.dataType;
1682 else if(type.kind == structType || type.kind == unionType)
1685 for(memberType = type.members.first; memberType; memberType = memberType.next)
1687 if(!strcmp(memberType.name, ident.string))
1697 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1698 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1701 ClassTemplateParameter curParam = null;
1703 for(sClass = _class; sClass; sClass = sClass.base)
1706 if(sClass.templateClass) sClass = sClass.templateClass;
1707 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1709 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1711 for(sClass = sClass.base; sClass; sClass = sClass.base)
1713 if(sClass.templateClass) sClass = sClass.templateClass;
1714 id += sClass.templateParams.count;
1725 ClassTemplateArgument arg = _class.templateArgs[id];
1726 if(arg.dataTypeString)
1729 type = ProcessTypeString(arg.dataTypeString, false);
1731 if(type && _class.templateClass)
1732 type.passAsTemplate = true;
1738 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1739 exp.destType.refCount++;
1745 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1747 Class expClass = type._class.registered;
1748 Class cClass = null;
1753 char templateString[1024];
1754 ClassTemplateParameter param;
1755 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1756 for(cClass = expClass; cClass; cClass = cClass.base)
1759 if(cClass.templateClass) cClass = cClass.templateClass;
1760 for(param = cClass.templateParams.first; param; param = param.next)
1764 ClassTemplateArgument arg;
1765 for(sClass = cClass.base; sClass; sClass = sClass.base)
1767 if(sClass.templateClass) sClass = sClass.templateClass;
1768 id += sClass.templateParams.count;
1770 arg = expClass.templateArgs[id];
1772 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1774 ClassTemplateParameter cParam;
1775 //int p = numParams - sClass.templateParams.count;
1778 if(sClass.templateClass) sClass = sClass.templateClass;
1780 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1782 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1783 p += nextClass.templateParams.count;
1786 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1788 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1790 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1792 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1793 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1805 strcat(argument, arg.name.string);
1806 strcat(argument, " = ");
1812 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1813 char expString[1024];
1814 OldList * specs = MkList();
1815 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1817 char * string = PrintHexUInt64(arg.expression.ui64);
1818 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1820 ProcessExpressionType(exp);
1821 ComputeExpression(exp);
1822 expString[0] = '\0';
1823 PrintExpression(exp, expString);
1824 strcat(argument, expString);
1826 FreeExpression(exp);
1831 strcat(argument, arg.member.name);
1834 case TemplateParameterType::type:
1836 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1837 strcat(argument, arg.dataTypeString);
1843 if(paramCount) strcat(templateString, ", ");
1844 if(lastParam != p - 1)
1846 strcat(templateString, param.name);
1847 strcat(templateString, " = ");
1849 strcat(templateString, argument);
1858 int len = strlen(templateString);
1859 if(templateString[len-1] == '<')
1863 if(templateString[len-1] == '>')
1864 templateString[len++] = ' ';
1865 templateString[len++] = '>';
1867 templateString[len++] = '\0';
1870 Context context = SetupTemplatesContext(_class);
1871 if(freeType) FreeType(type);
1872 type = ProcessTypeString(templateString, false);
1874 FinishTemplatesContext(context);
1878 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1880 ProcessExpressionType(member.initializer.exp);
1881 if(!member.initializer.exp.expType)
1885 char expString[10240];
1886 expString[0] = '\0';
1887 PrintExpression(member.initializer.exp, expString);
1888 ChangeCh(expString, '\n', ' ');
1889 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1892 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1893 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1895 Compiler_Error($"incompatible instance method %s\n", ident.string);
1898 else if(member.initializer)
1901 FreeType(member.exp.destType);
1902 member.exp.destType = type;
1903 if(member.exp.destType)
1904 member.exp.destType.refCount++;
1905 ProcessExpressionType(member.exp);
1908 ProcessInitializer(member.initializer, type);
1910 if(freeType) FreeType(type);
1914 if(_class && _class.type == unitClass)
1916 if(member.initializer)
1919 FreeType(member.exp.destType);
1920 member.exp.destType = MkClassType(_class.fullName);
1921 ProcessExpressionType(member.initializer, type);
1923 Type type = MkClassType(_class.fullName);
1924 ProcessInitializer(member.initializer, type);
1930 if(member.initializer)
1932 //ProcessExpressionType(member.exp);
1933 ProcessInitializer(member.initializer, null);
1939 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1943 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1945 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1949 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1954 void ProcessInstantiationType(Instantiation inst)
1959 MembersInit members;
1960 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1963 /*if(!inst._class.symbol)
1964 inst._class.symbol = FindClass(inst._class.name);*/
1965 classSym = inst._class.symbol;
1966 _class = classSym ? classSym.registered : null;
1968 // DANGER: Patch for mutex not declaring its struct when not needed
1969 if(!_class || _class.type != noHeadClass)
1970 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1972 afterExternal = afterExternal ? afterExternal : curExternal;
1975 ProcessExpressionType(inst.exp);
1977 inst.isConstant = true;
1980 DataMember curMember = null;
1981 Class curClass = null;
1982 DataMember subMemberStack[256];
1983 int subMemberStackPos = 0;
1985 for(members = inst.members->first; members; members = members.next)
1987 switch(members.type)
1989 case methodMembersInit:
1992 static uint instMethodID = 0;
1993 External external = curExternal;
1994 Context context = curContext;
1995 Declarator declarator = members.function.declarator;
1996 Identifier nameID = GetDeclId(declarator);
1997 char * unmangled = nameID ? nameID.string : null;
1999 External createdExternal = null;
2004 //members.function.dontMangle = true;
2005 strcpy(name, "__ecereInstMeth_");
2006 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2008 strcat(name, nameID.string);
2010 sprintf(number, "_%08d", instMethodID++);
2011 strcat(name, number);
2012 nameID.string = CopyString(name);
2015 // Do modifications here...
2018 Symbol symbol = declarator.symbol;
2019 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2021 if(method && method.type == virtualMethod)
2023 symbol.method = method;
2024 ProcessMethodType(method);
2026 if(!symbol.type.thisClass)
2028 if(method.dataType.thisClass && currentClass &&
2029 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2031 if(!currentClass.symbol)
2032 currentClass.symbol = FindClass(currentClass.fullName);
2033 symbol.type.thisClass = currentClass.symbol;
2038 _class.symbol = FindClass(_class.fullName);
2039 symbol.type.thisClass = _class.symbol;
2042 // TESTING THIS HERE:
2043 DeclareType(symbol.type, true, true);
2048 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2049 unmangled, classSym.string);
2053 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2054 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2058 FreeSpecifier(nameID._class);
2059 nameID._class = null;
2065 Type type = declarator.symbol.type;
2066 External oldExternal = curExternal;
2068 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2069 // *** It was commented out for problems such as
2071 class VirtualDesktop : Window
2073 clientSize = Size { };
2084 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2086 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2089 if(strcmp(declarator.symbol.string, name))
2091 printf("TOCHECK: Look out for this\n");
2092 delete declarator.symbol.string;
2093 declarator.symbol.string = CopyString(name);
2096 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2098 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2099 excludedSymbols->Remove(declarator.symbol);
2100 globalContext.symbols.Add((BTNode)declarator.symbol);
2101 if(strstr(declarator.symbol.string), "::")
2102 globalContext.hasNameSpace = true;
2107 //curExternal = curExternal.prev;
2108 //afterExternal = afterExternal->next;
2110 //ProcessFunction(afterExternal->function);
2112 //curExternal = afterExternal;
2114 External externalDecl;
2115 externalDecl = MkExternalDeclaration(null);
2116 ast->Insert(oldExternal.prev, externalDecl);
2118 // Which function does this process?
2119 if(createdExternal.function)
2121 ProcessFunction(createdExternal.function);
2123 //curExternal = oldExternal;
2126 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2128 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2129 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2131 //externalDecl = MkExternalDeclaration(decl);
2133 //***** ast->Insert(external.prev, externalDecl);
2134 //ast->Insert(curExternal.prev, externalDecl);
2135 externalDecl.declaration = decl;
2136 if(decl.symbol && !decl.symbol.pointerExternal)
2137 decl.symbol.pointerExternal = externalDecl;
2139 // Trying this out...
2140 declarator.symbol.pointerExternal = externalDecl;
2147 curExternal = declarator.symbol.pointerExternal;
2148 ProcessFunction((FunctionDefinition)members.function);
2150 curExternal = external;
2151 curContext = context;
2155 FreeClassFunction(members.function);
2157 // In this pass, turn this into a MemberInitData
2158 exp = QMkExpId(name);
2159 members.type = dataMembersInit;
2160 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2166 case dataMembersInit:
2168 if(members.dataMembers && classSym)
2171 Location oldyyloc = yylloc;
2172 for(member = members.dataMembers->first; member; member = member.next)
2174 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2175 if(member.initializer && !member.initializer.isConstant)
2176 inst.isConstant = false;
2188 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2190 // OPTIMIZATIONS: TESTING THIS...
2193 if(type.kind == functionType)
2198 for(param = type.params.first; param; param = param.next)
2199 DeclareType(param, declarePointers, true);
2201 DeclareType(type.returnType, declarePointers, true);
2203 else if(type.kind == pointerType && declarePointers)
2204 DeclareType(type.type, declarePointers, false);
2205 else if(type.kind == classType)
2207 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2208 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2210 else if(type.kind == structType || type.kind == unionType)
2213 for(member = type.members.first; member; member = member.next)
2214 DeclareType(member, false, false);
2216 else if(type.kind == arrayType)
2217 DeclareType(type.arrayType, declarePointers, false);
2221 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2223 ClassTemplateArgument * arg = null;
2225 ClassTemplateParameter curParam = null;
2227 for(sClass = _class; sClass; sClass = sClass.base)
2230 if(sClass.templateClass) sClass = sClass.templateClass;
2231 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2233 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2235 for(sClass = sClass.base; sClass; sClass = sClass.base)
2237 if(sClass.templateClass) sClass = sClass.templateClass;
2238 id += sClass.templateParams.count;
2248 arg = &_class.templateArgs[id];
2249 if(arg && param.type == type)
2250 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2255 public Context SetupTemplatesContext(Class _class)
2257 Context context = PushContext();
2258 context.templateTypesOnly = true;
2259 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2261 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2262 for(; param; param = param.next)
2264 if(param.type == type && param.identifier)
2266 TemplatedType type { key = (uint)param.identifier.string, param = param };
2267 curContext.templateTypes.Add((BTNode)type);
2274 for(sClass = _class; sClass; sClass = sClass.base)
2276 ClassTemplateParameter p;
2277 for(p = sClass.templateParams.first; p; p = p.next)
2279 //OldList * specs = MkList();
2280 //Declarator decl = null;
2281 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2284 TemplateParameter param = p.param;
2288 // ADD DATA TYPE HERE...
2289 p.param = param = TemplateParameter
2291 identifier = MkIdentifier(p.name), type = p.type,
2292 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2295 type = TemplatedType { key = (uint)p.name, param = param };
2296 curContext.templateTypes.Add((BTNode)type);
2304 public void FinishTemplatesContext(Context context)
2306 PopContext(context);
2307 FreeContext(context);
2311 public void ProcessMethodType(Method method)
2313 if(!method.dataType)
2315 Context context = SetupTemplatesContext(method._class);
2317 method.dataType = ProcessTypeString(method.dataTypeString, false);
2319 FinishTemplatesContext(context);
2321 if(method.type != virtualMethod && method.dataType)
2323 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2325 if(!method._class.symbol)
2326 method._class.symbol = FindClass(method._class.fullName);
2327 method.dataType.thisClass = method._class.symbol;
2331 // Why was this commented out? Working fine without now...
2334 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2335 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2342 char * par = strstr(type, "(");
2343 char * classOp = null;
2348 for(c = par-type-1; c >= 0; c++)
2350 if(type[c] == ':' && type[c+1] == ':')
2352 classOp = type + c - 1;
2353 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2360 else if(!isspace(type[c]))
2367 int typeLen = strlen(type);
2368 memcpy(temp, classOp, classOpLen);
2369 temp[classOpLen] = '\0';
2371 _class = eSystem_FindClass(module, temp);
2374 method.dataTypeString = new char[typeLen - classOpLen + 1];
2375 memcpy(method.dataTypeString, type, classOp - type);
2376 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2379 method.dataTypeString = type;
2385 public void ProcessPropertyType(Property prop)
2389 Context context = SetupTemplatesContext(prop._class);
2390 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2391 FinishTemplatesContext(context);
2395 public void DeclareMethod(Method method, char * name)
2397 Symbol symbol = method.symbol;
2398 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2400 bool imported = false;
2401 bool dllImport = false;
2403 if(!method.dataType)
2404 method.dataType = ProcessTypeString(method.dataTypeString, false);
2406 if(!symbol || symbol._import || method.type == virtualMethod)
2408 if(!symbol || method.type == virtualMethod)
2411 if(!method._class.symbol)
2412 method._class.symbol = FindClass(method._class.fullName);
2413 classSym = method._class.symbol;
2414 if(!classSym._import)
2416 ModuleImport module;
2418 if(method._class.module && method._class.module.name)
2419 module = FindModule(method._class.module);
2421 module = mainModule;
2422 classSym._import = ClassImport
2424 name = CopyString(method._class.fullName);
2425 isRemote = method._class.isRemote;
2427 module.classes.Add(classSym._import);
2431 symbol = method.symbol = Symbol { };
2435 symbol._import = (ClassImport)MethodImport
2437 name = CopyString(method.name);
2438 isVirtual = method.type == virtualMethod;
2440 classSym._import.methods.Add(symbol._import);
2444 // Set the symbol type
2448 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2450 else if(type.thisClass == (void *)-1)
2452 type.thisClass = null;
2455 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2456 symbol.type = method.dataType;
2457 if(symbol.type) symbol.type.refCount++;
2460 if(!method.thisClass || strcmp(method.thisClass, "void"))
2461 symbol.type.params.Insert(null,
2462 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2465 if(!method.dataType.dllExport)
2468 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2474 if(!method.dataType)
2475 method.dataType = ((Symbol)method.symbol).type;
2476 //ProcessMethodType(method);
2479 if(method.type != virtualMethod && method.dataType)
2480 DeclareType(method.dataType, true, true);
2482 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2484 // We need a declaration here :)
2486 OldList * specifiers, * declarators;
2488 Declarator funcDecl;
2491 specifiers = MkList();
2492 declarators = MkList();
2496 ListAdd(specifiers, MkSpecifier(EXTERN));
2497 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2498 ListAdd(specifiers, MkSpecifier(STATIC));
2500 if(method.type == virtualMethod)
2502 ListAdd(specifiers, MkSpecifier(INT));
2503 d = MkDeclaratorIdentifier(MkIdentifier(name));
2507 d = MkDeclaratorIdentifier(MkIdentifier(name));
2510 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2512 Context context = SetupTemplatesContext(method._class);
2513 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2514 FinishTemplatesContext(context);
2516 funcDecl = GetFuncDecl(d);
2520 Specifier spec, next;
2521 for(spec = specifiers->first; spec; spec = next)
2524 if(spec.type == extendedSpecifier)
2526 specifiers->Remove(spec);
2527 FreeSpecifier(spec);
2532 // Add this parameter if not a static method
2533 if(method.dataType && !method.dataType.staticMethod)
2535 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2537 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2538 TypeName thisParam = MkTypeName(MkListOne(
2539 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2540 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2541 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2542 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2544 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2546 TypeName param = funcDecl.function.parameters->first;
2547 funcDecl.function.parameters->Remove(param);
2548 FreeTypeName(param);
2551 if(!funcDecl.function.parameters)
2552 funcDecl.function.parameters = MkList();
2553 funcDecl.function.parameters->Insert(null, thisParam);
2556 // Make sure we don't have empty parameter declarations for static methods...
2558 else if(!funcDecl.function.parameters)
2560 funcDecl.function.parameters = MkList();
2561 funcDecl.function.parameters->Insert(null,
2562 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2566 ProcessDeclarator(d);
2568 ListAdd(declarators, MkInitDeclarator(d, null));
2570 decl = MkDeclaration(specifiers, declarators);
2572 ReplaceThisClassSpecifiers(specifiers, method._class);
2574 // Keep a different symbol for the function definition than the declaration...
2575 if(symbol.pointerExternal)
2577 Symbol functionSymbol { };
2581 *functionSymbol = *symbol;
2582 functionSymbol.string = CopyString(symbol.string);
2583 if(functionSymbol.type)
2584 functionSymbol.type.refCount++;
2587 excludedSymbols->Add(functionSymbol);
2588 symbol.pointerExternal.symbol = functionSymbol;
2590 external = MkExternalDeclaration(decl);
2592 ast->Insert(curExternal ? curExternal.prev : null, external);
2593 external.symbol = symbol;
2594 symbol.pointerExternal = external;
2598 // Move declaration higher...
2599 ast->Move(symbol.pointerExternal, curExternal.prev);
2602 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2606 char * ReplaceThisClass(Class _class)
2608 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2612 ClassTemplateParameter param;
2615 char className[1024];
2616 strcpy(className, _class.fullName);
2617 for(param = _class.templateParams.first; param; param = param.next)
2619 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2621 if(first) strcat(className, "<");
2622 if(!first) strcat(className, ", ");
2623 if(lastParam + 1 != p)
2625 strcat(className, param.name);
2626 strcat(className, " = ");
2628 strcat(className, param.name);
2636 int len = strlen(className);
2637 if(className[len-1] == '>') className[len++] = ' ';
2638 className[len++] = '>';
2639 className[len++] = '\0';
2641 return CopyString(className);
2644 return CopyString(_class.fullName);
2647 Type ReplaceThisClassType(Class _class)
2649 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2653 ClassTemplateParameter param;
2655 char className[1024];
2656 strcpy(className, _class.fullName);
2658 for(param = _class.templateParams.first; param; param = param.next)
2660 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2662 if(first) strcat(className, "<");
2663 if(!first) strcat(className, ", ");
2664 if(lastParam + 1 != p)
2666 strcat(className, param.name);
2667 strcat(className, " = ");
2669 strcat(className, param.name);
2677 int len = strlen(className);
2678 if(className[len-1] == '>') className[len++] = ' ';
2679 className[len++] = '>';
2680 className[len++] = '\0';
2682 return MkClassType(className);
2683 //return ProcessTypeString(className, false);
2687 return MkClassType(_class.fullName);
2688 //return ProcessTypeString(_class.fullName, false);
2692 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2694 if(specs != null && _class)
2697 for(spec = specs.first; spec; spec = spec.next)
2699 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2701 spec.type = nameSpecifier;
2702 spec.name = ReplaceThisClass(_class);
2703 spec.symbol = FindClass(spec.name); //_class.symbol;
2709 // Returns imported or not
2710 bool DeclareFunction(GlobalFunction function, char * name)
2712 Symbol symbol = function.symbol;
2713 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2715 bool imported = false;
2716 bool dllImport = false;
2718 if(!function.dataType)
2720 function.dataType = ProcessTypeString(function.dataTypeString, false);
2721 if(!function.dataType.thisClass)
2722 function.dataType.staticMethod = true;
2729 ModuleImport module = FindModule(function.module);
2730 // WARNING: This is not added anywhere...
2731 symbol = function.symbol = Symbol { };
2735 if(!function.dataType.dllExport)
2737 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2738 module.functions.Add(symbol._import);
2741 // Set the symbol type
2743 symbol.type = ProcessTypeString(function.dataTypeString, false);
2744 if(!symbol.type.thisClass)
2745 symbol.type.staticMethod = true;
2748 imported = symbol._import ? true : false;
2749 if(imported && function.module != privateModule && function.module.importType != staticImport)
2753 DeclareType(function.dataType, true, true);
2757 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2759 // We need a declaration here :)
2761 OldList * specifiers, * declarators;
2763 Declarator funcDecl;
2766 specifiers = MkList();
2767 declarators = MkList();
2770 ListAdd(specifiers, MkSpecifier(EXTERN));
2773 ListAdd(specifiers, MkSpecifier(STATIC));
2776 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2779 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2781 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2782 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2783 if(function.module.importType == staticImport)
2786 for(spec = specifiers->first; spec; spec = spec.next)
2787 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2789 specifiers->Remove(spec);
2790 FreeSpecifier(spec);
2795 funcDecl = GetFuncDecl(d);
2797 // Make sure we don't have empty parameter declarations for static methods...
2798 if(funcDecl && !funcDecl.function.parameters)
2800 funcDecl.function.parameters = MkList();
2801 funcDecl.function.parameters->Insert(null,
2802 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2805 ListAdd(declarators, MkInitDeclarator(d, null));
2808 Context oldCtx = curContext;
2809 curContext = globalContext;
2810 decl = MkDeclaration(specifiers, declarators);
2811 curContext = oldCtx;
2814 // Keep a different symbol for the function definition than the declaration...
2815 if(symbol.pointerExternal)
2817 Symbol functionSymbol { };
2820 *functionSymbol = *symbol;
2821 functionSymbol.string = CopyString(symbol.string);
2822 if(functionSymbol.type)
2823 functionSymbol.type.refCount++;
2826 excludedSymbols->Add(functionSymbol);
2828 symbol.pointerExternal.symbol = functionSymbol;
2830 external = MkExternalDeclaration(decl);
2832 ast->Insert(curExternal.prev, external);
2833 external.symbol = symbol;
2834 symbol.pointerExternal = external;
2838 // Move declaration higher...
2839 ast->Move(symbol.pointerExternal, curExternal.prev);
2843 symbol.id = curExternal.symbol.idCode;
2846 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2849 void DeclareGlobalData(GlobalData data)
2851 Symbol symbol = data.symbol;
2852 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2857 symbol = data.symbol = Symbol { };
2860 data.dataType = ProcessTypeString(data.dataTypeString, false);
2861 DeclareType(data.dataType, true, true);
2864 if(!symbol.pointerExternal)
2866 // We need a declaration here :)
2868 OldList * specifiers, * declarators;
2872 specifiers = MkList();
2873 declarators = MkList();
2875 ListAdd(specifiers, MkSpecifier(EXTERN));
2876 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2877 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2879 ListAdd(declarators, MkInitDeclarator(d, null));
2881 decl = MkDeclaration(specifiers, declarators);
2882 external = MkExternalDeclaration(decl);
2884 ast->Insert(curExternal.prev, external);
2885 external.symbol = symbol;
2886 symbol.pointerExternal = external;
2890 // Move declaration higher...
2891 ast->Move(symbol.pointerExternal, curExternal.prev);
2895 symbol.id = curExternal.symbol.idCode;
2900 class Conversion : struct
2902 Conversion prev, next;
2908 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2912 // Property convert;
2914 if(source.kind == templateType && dest.kind != templateType)
2916 Type type = ProcessTemplateParameterType(source.templateParameter);
2917 if(type) source = type;
2920 if(dest.kind == templateType && source.kind != templateType)
2922 Type type = ProcessTemplateParameterType(dest.templateParameter);
2923 if(type) dest = type;
2926 if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
2931 if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
2936 if((dest.kind == structType && source.kind == structType) ||
2937 (dest.kind == unionType && source.kind == unionType))
2939 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2940 (source.members.first && source.members.first == dest.members.first))
2944 if(dest.kind == ellipsisType && source.kind != voidType)
2947 if(dest.kind == pointerType && dest.type.kind == voidType &&
2948 ((source.kind == classType && (!source._class || !source._class.registered || source._class.registered.type == structClass || source._class.registered.type == normalClass || source._class.registered.type == noHeadClass || source._class.registered.type == systemClass))
2949 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2951 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2953 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2955 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2956 ((dest.kind == classType && (!dest._class || !dest._class.registered || dest._class.registered.type == structClass || dest._class.registered.type == normalClass || dest._class.registered.type == noHeadClass || dest._class.registered.type == systemClass))
2957 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2959 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2961 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2964 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2966 if(source._class.registered && source._class.registered.type == unitClass)
2968 if(conversions != null)
2970 if(source._class.registered == dest._class.registered)
2975 Class sourceBase, destBase;
2976 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2977 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2978 if(sourceBase == destBase)
2982 // Don't match enum inheriting from other enum if resolving enumeration values
2983 // TESTING: !dest.classObjectType
2984 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2986 (!source._class.registered || source._class.registered.type != enumClass) ||
2987 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2991 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2993 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2994 source._class && source._class.registered && source._class.registered.type != enumClass)
2996 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3004 // JUST ADDED THIS...
3005 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3010 // Just added this for Straight conversion of ColorAlpha => Color
3011 if(source.kind == classType)
3014 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3017 for(convert = _class.conversions.first; convert; convert = convert.next)
3019 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3021 Conversion after = (conversions != null) ? conversions.last : null;
3023 if(!convert.dataType)
3024 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3025 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
3027 if(!conversions && !convert.Get)
3029 else if(conversions != null)
3031 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3032 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3033 (dest.kind != classType || dest._class.registered != _class.base))
3037 Conversion conv { convert = convert, isGet = true };
3038 // conversions.Add(conv);
3039 conversions.Insert(after, conv);
3051 if(dest.kind == classType)
3054 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3057 for(convert = _class.conversions.first; convert; convert = convert.next)
3059 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3061 // Conversion after = (conversions != null) ? conversions.last : null;
3063 if(!convert.dataType)
3064 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3065 // Just added this equality check to prevent recursion.... Make it safer?
3066 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3067 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3069 if(!conversions && !convert.Set)
3071 else if(conversions != null)
3073 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3074 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3075 (source.kind != classType || source._class.registered != _class.base))
3079 // *** Testing this! ***
3080 Conversion conv { convert = convert };
3081 conversions.Add(conv);
3082 //conversions.Insert(after, conv);
3090 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3092 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3093 (source.kind != classType || source._class.registered.type != structClass))
3097 // TESTING THIS... IS THIS OK??
3098 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3100 if(!dest._class.registered.dataType)
3101 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3102 // Only support this for classes...
3103 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3104 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3106 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3115 if(source.kind == classType)
3118 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3121 for(convert = _class.conversions.first; convert; convert = convert.next)
3123 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3125 Conversion after = (conversions != null) ? conversions.last : null;
3127 if(!convert.dataType)
3128 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3129 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3131 if(!conversions && !convert.Get)
3133 else if(conversions != null)
3135 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3136 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3137 (dest.kind != classType || dest._class.registered != _class.base))
3141 Conversion conv { convert = convert, isGet = true };
3143 // conversions.Add(conv);
3144 conversions.Insert(after, conv);
3153 // TESTING THIS... IS THIS OK??
3154 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3156 if(!source._class.registered.dataType)
3157 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3158 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3166 if(source.kind == classType || source.kind == subClassType)
3168 else if(dest.kind == source.kind &&
3169 (dest.kind != structType && dest.kind != unionType &&
3170 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3172 // RECENTLY ADDED THESE
3173 else if(dest.kind == doubleType && source.kind == floatType)
3175 else if(dest.kind == shortType && source.kind == charType)
3177 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType))
3179 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType))
3181 else if(source.kind == enumType &&
3182 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type))
3184 else if(dest.kind == enumType &&
3185 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || dest.kind == int64Type))
3187 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3188 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3190 Type paramSource, paramDest;
3192 if(dest.kind == methodType)
3193 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3194 if(source.kind == methodType)
3195 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3197 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3198 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3199 if(dest.kind == methodType)
3200 dest = dest.method.dataType;
3201 if(source.kind == methodType)
3202 source = source.method.dataType;
3204 paramSource = source.params.first;
3205 if(paramSource && paramSource.kind == voidType) paramSource = null;
3206 paramDest = dest.params.first;
3207 if(paramDest && paramDest.kind == voidType) paramDest = null;
3210 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3211 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3213 // Source thisClass must be derived from destination thisClass
3214 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3215 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3217 if(paramDest && paramDest.kind == classType)
3218 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3220 Compiler_Error($"method class should not take an object\n");
3223 paramDest = paramDest.next;
3225 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3227 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3231 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3233 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3239 // THIS WAS BACKWARDS:
3240 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3241 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3244 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3246 Compiler_Error($"overriding class expected to be derived from method class\n");
3250 paramSource = paramSource.next;
3256 // Source thisClass must be derived from destination thisClass
3257 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3259 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3265 // THIS WAS BACKWARDS TOO??
3266 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3267 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3270 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3272 //Compiler_Error($"overriding class expected to be derived from method class\n");
3280 // Source return type must be derived from destination return type
3281 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3283 Compiler_Warning($"incompatible return type for function\n");
3289 for(; paramDest; paramDest = paramDest.next)
3293 //Compiler_Warning($"not enough parameters\n");
3294 Compiler_Error($"not enough parameters\n");
3298 Type paramDestType = paramDest;
3299 Type paramSourceType = paramSource;
3300 Type type = paramDestType;
3302 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3303 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3304 paramSource.kind != templateType)
3307 ClassTemplateParameter curParam = null;
3309 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3312 if(sClass.templateClass) sClass = sClass.templateClass;
3313 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3315 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3317 for(sClass = sClass.base; sClass; sClass = sClass.base)
3319 if(sClass.templateClass) sClass = sClass.templateClass;
3320 id += sClass.templateParams.count;
3331 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3332 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3336 // paramDest must be derived from paramSource
3337 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3338 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3342 PrintType(paramDest, type, false, true);
3343 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3345 if(paramDestType != paramDest)
3346 FreeType(paramDestType);
3349 if(paramDestType != paramDest)
3350 FreeType(paramDestType);
3353 paramSource = paramSource.next;
3357 Compiler_Error($"too many parameters\n");
3362 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3366 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3367 (source.kind == arrayType || source.kind == pointerType))
3369 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3376 static void FreeConvert(Conversion convert)
3378 if(convert.resultType)
3379 FreeType(convert.resultType);
3382 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3383 char * string, OldList conversions)
3387 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3389 Class _class = link.data;
3390 if(_class.type == enumClass)
3392 OldList converts { };
3394 type.kind = classType;
3397 _class.symbol = FindClass(_class.fullName);
3398 type._class = _class.symbol;
3400 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3403 Class enumClass = eSystem_FindClass(privateModule, "enum");
3407 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3409 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3410 for(value = e.values.first; value; value = value.next)
3412 if(!strcmp(value.name, string))
3417 FreeExpContents(sourceExp);
3418 FreeType(sourceExp.expType);
3420 sourceExp.isConstant = true;
3421 sourceExp.expType = MkClassType(baseClass.fullName);
3425 sourceExp.type = constantExp;
3426 if(!strcmp(baseClass.dataTypeString, "int"))
3427 sprintf(constant, "%d",value.data);
3429 sprintf(constant, "0x%X",value.data);
3430 sourceExp.constant = CopyString(constant);
3431 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3434 while(converts.first)
3436 Conversion convert = converts.first;
3437 converts.Remove(convert);
3438 conversions.Add(convert);
3447 converts.Free(FreeConvert);
3451 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3452 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3457 public bool ModuleVisibility(Module searchIn, Module searchFor)
3459 SubModule subModule;
3461 if(searchFor == searchIn)
3464 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3466 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3468 if(ModuleVisibility(subModule.module, searchFor))
3475 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3479 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3481 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3483 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3486 for(module = mainModule.application.allModules.first; module; module = module.next)
3488 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3494 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3496 Type source = sourceExp.expType;
3497 Type realDest = dest;
3499 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3502 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3504 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3506 Class sourceBase, destBase;
3507 for(sourceBase = source._class.registered;
3508 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3509 sourceBase = sourceBase.base);
3510 for(destBase = dest._class.registered;
3511 destBase && destBase.base && destBase.base.type != systemClass;
3512 destBase = destBase.base);
3513 //if(source._class.registered == dest._class.registered)
3514 if(sourceBase == destBase)
3523 int64 value = MAXINT;
3528 if(sourceExp.type == constantExp)
3531 value = strtoll(sourceExp.constant, null, 0);
3533 value = strtoull(sourceExp.constant, null, 0);
3535 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3538 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3540 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3543 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3544 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3547 source = Type { kind = intType, isSigned = false, refCount = 1 };
3550 if(dest.kind == classType)
3552 Class _class = dest._class ? dest._class.registered : null;
3554 if(_class && _class.type == unitClass)
3556 if(source.kind != classType)
3559 Type tempDest, tempSource;
3561 for(; _class.base.type != systemClass; _class = _class.base);
3563 tempDest = tempType;
3565 tempType.kind = classType;
3567 _class.symbol = FindClass(_class.fullName);
3569 tempType._class = _class.symbol;
3570 tempType.truth = dest.truth;
3572 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3574 FreeType(sourceExp.expType);
3575 sourceExp.expType = dest; dest.refCount++;
3577 //sourceExp.expType = MkClassType(_class.fullName);
3585 // Why wasn't there something like this?
3586 if(_class && _class.type == bitClass && source.kind != classType)
3588 if(!dest._class.registered.dataType)
3589 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3590 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3593 FreeType(sourceExp.expType);
3594 source = sourceExp.expType = MkClassType(dest._class.string);
3597 //source.kind = classType;
3598 //source._class = dest._class;
3602 // Adding two enumerations
3604 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3606 if(!source._class.registered.dataType)
3607 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3608 if(!dest._class.registered.dataType)
3609 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3611 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3614 source = sourceExp.expType = MkClassType(dest._class.string);
3617 //source.kind = classType;
3618 //source._class = dest._class;
3622 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3624 OldList * specs = MkList();
3628 ReadString(string, sourceExp.string);
3629 decl = SpecDeclFromString(string, specs, null);
3631 FreeExpContents(sourceExp);
3632 FreeType(sourceExp.expType);
3634 sourceExp.type = classExp;
3635 sourceExp._classExp.specifiers = specs;
3636 sourceExp._classExp.decl = decl;
3637 sourceExp.expType = dest;
3645 else if(source.kind == classType)
3647 Class _class = source._class ? source._class.registered : null;
3649 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3652 if(dest.kind != classType)
3654 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3655 if(!source._class.registered.dataType)
3656 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3659 dest = MkClassType(source._class.string);
3660 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3661 // dest = MkClassType(source._class.string);
3665 if(dest.kind != classType)
3668 Type tempDest, tempSource;
3670 if(!source._class.registered.dataType)
3671 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3673 for(; _class.base.type != systemClass; _class = _class.base);
3675 tempSource = tempType;
3676 tempType.kind = classType;
3677 tempType._class = FindClass(_class.fullName);
3678 tempType.truth = source.truth;
3679 tempType.classObjectType = source.classObjectType;
3682 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3684 // PUT THIS BACK TESTING UNITS?
3685 if(conversions.last)
3687 ((Conversion)(conversions.last)).resultType = dest;
3691 FreeType(sourceExp.expType);
3692 sourceExp.expType = MkClassType(_class.fullName);
3693 sourceExp.expType.truth = source.truth;
3694 sourceExp.expType.classObjectType = source.classObjectType;
3696 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3698 if(!sourceExp.destType)
3700 FreeType(sourceExp.destType);
3701 sourceExp.destType = sourceExp.expType;
3702 if(sourceExp.expType)
3703 sourceExp.expType.refCount++;
3706 //source = _class.dataType;
3709 // TOCHECK: TESTING THIS NEW CODE
3710 if(!_class.dataType)
3711 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3713 dest = MkClassType(source._class.string);
3714 dest.truth = source.truth;
3715 dest.classObjectType = source.classObjectType;
3718 source = _class.dataType;
3728 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3738 if(source.kind == classType)
3740 Class _class = source._class.registered;
3741 if(_class.type == unitClass)
3743 if(!_class.dataType)
3744 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3745 source = _class.dataType;
3749 if(dest.kind == classType)
3751 Class _class = dest._class ? dest._class.registered : null;
3752 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3753 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3755 if(_class.type == normalClass || _class.type == noHeadClass)
3757 Expression newExp { };
3758 *newExp = *sourceExp;
3759 if(sourceExp.destType) sourceExp.destType.refCount++;
3760 if(sourceExp.expType) sourceExp.expType.refCount++;
3761 sourceExp.type = castExp;
3762 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3763 sourceExp.cast.exp = newExp;
3764 FreeType(sourceExp.expType);
3765 sourceExp.expType = null;
3766 ProcessExpressionType(sourceExp);
3768 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3771 FreeType(sourceExp.expType);
3772 sourceExp.expType = dest;
3776 if(inCompiler) FreeType(dest);
3781 if(!_class.dataType)
3782 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3784 dest = _class.dataType;
3788 // Accept lower precision types for units, since we want to keep the unit type
3789 if(dest.kind == doubleType &&
3790 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3791 source.kind == charType))
3793 specs = MkListOne(MkSpecifier(DOUBLE));
3795 else if(dest.kind == floatType &&
3796 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3797 source.kind == doubleType))
3799 specs = MkListOne(MkSpecifier(FLOAT));
3801 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3802 source.kind == floatType || source.kind == doubleType))
3805 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3806 ListAdd(specs, MkSpecifier(INT64));
3808 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3809 source.kind == floatType || source.kind == doubleType))
3812 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3813 ListAdd(specs, MkSpecifier(INT));
3815 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3816 source.kind == floatType || source.kind == doubleType))
3819 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3820 ListAdd(specs, MkSpecifier(SHORT));
3822 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3823 source.kind == floatType || source.kind == doubleType))
3826 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3827 ListAdd(specs, MkSpecifier(CHAR));
3836 else if(dest.kind == doubleType &&
3837 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3838 source.kind == charType))
3840 specs = MkListOne(MkSpecifier(DOUBLE));
3842 else if(dest.kind == floatType &&
3843 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3845 specs = MkListOne(MkSpecifier(FLOAT));
3847 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3848 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3851 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3852 ListAdd(specs, MkSpecifier(CHAR));
3854 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3855 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3858 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3859 ListAdd(specs, MkSpecifier(SHORT));
3861 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3864 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3865 ListAdd(specs, MkSpecifier(INT));
3867 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3870 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3871 ListAdd(specs, MkSpecifier(INT64));
3873 else if(dest.kind == enumType &&
3874 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3876 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3887 Expression newExp { };
3888 *newExp = *sourceExp;
3891 if(sourceExp.destType) sourceExp.destType.refCount++;
3892 if(sourceExp.expType) sourceExp.expType.refCount++;
3894 sourceExp.type = castExp;
3895 if(realDest.kind == classType)
3897 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3898 FreeList(specs, FreeSpecifier);
3901 sourceExp.cast.typeName = MkTypeName(specs, null);
3902 if(newExp.type == opExp)
3904 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3907 sourceExp.cast.exp = newExp;
3909 FreeType(sourceExp.expType);
3910 sourceExp.expType = null;
3911 ProcessExpressionType(sourceExp);
3914 FreeList(specs, FreeSpecifier);
3922 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3923 if(sourceExp.type == identifierExp)
3925 Identifier id = sourceExp.identifier;
3926 if(dest.kind == classType)
3928 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3930 Class _class = dest._class.registered;
3931 Class enumClass = eSystem_FindClass(privateModule, "enum");
3934 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3937 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3938 for(value = e.values.first; value; value = value.next)
3940 if(!strcmp(value.name, id.string))
3945 FreeExpContents(sourceExp);
3946 FreeType(sourceExp.expType);
3948 sourceExp.isConstant = true;
3949 sourceExp.expType = MkClassType(_class.fullName);
3953 sourceExp.type = constantExp;
3954 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3955 sprintf(constant, "%d",value.data);
3957 sprintf(constant, "0x%X",value.data);
3958 sourceExp.constant = CopyString(constant);
3959 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3968 // Loop through all enum classes
3969 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3976 #define TERTIARY(o, name, m, t, p) \
3977 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3979 exp.type = constantExp; \
3980 exp.string = p(op1.m ? op2.m : op3.m); \
3982 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3986 #define BINARY(o, name, m, t, p) \
3987 static bool name(Expression exp, Operand op1, Operand op2) \
3990 exp.type = constantExp; \
3991 exp.string = p(op1.m o value2); \
3993 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3997 #define BINARY_DIVIDE(o, name, m, t, p) \
3998 static bool name(Expression exp, Operand op1, Operand op2) \
4001 exp.type = constantExp; \
4002 exp.string = p(value2 ? (op1.m o value2) : 0); \
4004 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4008 #define UNARY(o, name, m, t, p) \
4009 static bool name(Expression exp, Operand op1) \
4011 exp.type = constantExp; \
4012 exp.string = p(o op1.m); \
4014 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4018 #define OPERATOR_ALL(macro, o, name) \
4019 macro(o, Int##name, i, int, PrintInt) \
4020 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4021 macro(o, Short##name, s, short, PrintShort) \
4022 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4023 macro(o, Char##name, c, char, PrintChar) \
4024 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4025 macro(o, Float##name, f, float, PrintFloat) \
4026 macro(o, Double##name, d, double, PrintDouble)
4028 #define OPERATOR_INTTYPES(macro, o, name) \
4029 macro(o, Int##name, i, int, PrintInt) \
4030 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4031 macro(o, Short##name, s, short, PrintShort) \
4032 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4033 macro(o, Char##name, c, char, PrintChar) \
4034 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4037 // binary arithmetic
4038 OPERATOR_ALL(BINARY, +, Add)
4039 OPERATOR_ALL(BINARY, -, Sub)
4040 OPERATOR_ALL(BINARY, *, Mul)
4041 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4042 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4045 OPERATOR_ALL(UNARY, -, Neg)
4047 // unary arithmetic increment and decrement
4048 OPERATOR_ALL(UNARY, ++, Inc)
4049 OPERATOR_ALL(UNARY, --, Dec)
4051 // binary arithmetic assignment
4052 OPERATOR_ALL(BINARY, =, Asign)
4053 OPERATOR_ALL(BINARY, +=, AddAsign)
4054 OPERATOR_ALL(BINARY, -=, SubAsign)
4055 OPERATOR_ALL(BINARY, *=, MulAsign)
4056 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4057 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4060 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4061 OPERATOR_INTTYPES(BINARY, |, BitOr)
4062 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4063 OPERATOR_INTTYPES(BINARY, <<, LShift)
4064 OPERATOR_INTTYPES(BINARY, >>, RShift)
4067 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4069 // binary bitwise assignment
4070 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4071 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4072 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4073 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4074 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4076 // unary logical negation
4077 OPERATOR_INTTYPES(UNARY, !, Not)
4079 // binary logical equality
4080 OPERATOR_ALL(BINARY, ==, Equ)
4081 OPERATOR_ALL(BINARY, !=, Nqu)
4084 OPERATOR_ALL(BINARY, &&, And)
4085 OPERATOR_ALL(BINARY, ||, Or)
4087 // binary logical relational
4088 OPERATOR_ALL(BINARY, >, Grt)
4089 OPERATOR_ALL(BINARY, <, Sma)
4090 OPERATOR_ALL(BINARY, >=, GrtEqu)
4091 OPERATOR_ALL(BINARY, <=, SmaEqu)
4093 // tertiary condition operator
4094 OPERATOR_ALL(TERTIARY, ?, Cond)
4096 //Add, Sub, Mul, Div, Mod, , Neg, Inc, Dec, Asign, AddAsign, SubAsign, MulAsign, DivAsign, ModAsign, BitAnd, BitOr, BitXor, LShift, RShift, BitNot, AndAsign, OrAsign, XorAsign, LShiftAsign, RShiftAsign, Not, Equ, Nqu, And, Or, Grt, Sma, GrtEqu, SmaEqu
4097 #define OPERATOR_TABLE_ALL(name, type) \
4098 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4100 type##Inc, type##Dec, \
4101 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4102 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4104 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4106 type##Equ, type##Nqu, \
4107 type##And, type##Or, \
4108 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4111 #define OPERATOR_TABLE_INTTYPES(name, type) \
4112 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4114 type##Inc, type##Dec, \
4115 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4116 null, null, null, null, null, \
4118 null, null, null, null, null, \
4120 type##Equ, type##Nqu, \
4121 type##And, type##Or, \
4122 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4125 OPERATOR_TABLE_ALL(int, Int)
4126 OPERATOR_TABLE_ALL(uint, UInt)
4127 OPERATOR_TABLE_ALL(short, Short)
4128 OPERATOR_TABLE_ALL(ushort, UShort)
4129 OPERATOR_TABLE_INTTYPES(float, Float)
4130 OPERATOR_TABLE_INTTYPES(double, Double)
4131 OPERATOR_TABLE_ALL(char, Char)
4132 OPERATOR_TABLE_ALL(uchar, UChar)
4134 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4135 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4136 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4137 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4138 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4139 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4140 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4141 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4143 public void ReadString(char * output, char * string)
4145 int len = strlen(string);
4147 bool quoted = false, escaped = false;
4148 for(c = 0; c<len; c++)
4150 char ch = string[c];
4155 case 'n': output[d] = '\n'; break;
4156 case 't': output[d] = '\t'; break;
4157 case 'a': output[d] = '\a'; break;
4158 case 'b': output[d] = '\b'; break;
4159 case 'f': output[d] = '\f'; break;
4160 case 'r': output[d] = '\r'; break;
4161 case 'v': output[d] = '\v'; break;
4162 case '\\': output[d] = '\\'; break;
4163 case '\"': output[d] = '\"'; break;
4164 default: output[d++] = '\\'; output[d] = ch;
4165 //default: output[d] = ch;
4186 public Operand GetOperand(Expression exp)
4189 Type type = exp.expType;
4192 while(type.kind == classType &&
4193 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4195 if(!type._class.registered.dataType)
4196 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4197 type = type._class.registered.dataType;
4200 op.kind = type.kind;
4201 op.type = exp.expType;
4202 if(exp.isConstant && exp.type == constantExp)
4208 if(exp.constant[0] == '\'')
4209 op.c = exp.constant[1];
4210 else if(type.isSigned)
4212 op.c = (char)strtol(exp.constant, null, 0);
4217 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4225 op.s = (short)strtol(exp.constant, null, 0);
4230 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4238 op.i = (int)strtol(exp.constant, null, 0);
4243 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4251 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4256 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4262 op.f = (float)strtod(exp.constant, null);
4266 op.d = (double)strtod(exp.constant, null);
4269 //case classType: For when we have operator overloading...
4270 // Pointer additions
4271 //case functionType:
4275 op.p = (unsigned char *)strtoul(exp.constant, null, 0);
4276 op.kind = pointerType;
4286 static void UnusedFunction()
4289 a.OnGetString(0,0,0);
4292 extern int __ecereVMethodID_class_OnGetString;
4295 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4297 DataMember dataMember;
4298 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4300 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4301 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4305 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4307 void * ptr = inst.data + dataMember.offset + offset;
4308 char * result = null;
4309 exp.loc = member.loc = inst.loc;
4310 ((Identifier)member.identifiers->first).loc = inst.loc;
4312 if(!dataMember.dataType)
4313 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4314 type = dataMember.dataType;
4315 if(type.kind == classType)
4317 Class _class = type._class.registered;
4318 if(_class.type == enumClass)
4320 Class enumClass = eSystem_FindClass(privateModule, "enum");
4323 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4325 for(item = e.values.first; item; item = item.next)
4327 if((int)item.data == *(int *)ptr)
4335 exp.identifier = MkIdentifier(result);
4336 exp.type = identifierExp;
4337 exp.destType = MkClassType(_class.fullName);
4338 ProcessExpressionType(exp);
4342 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4344 if(!_class.dataType)
4345 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4346 type = _class.dataType;
4355 FreeExpContents(exp);
4357 exp.constant = PrintFloat(*(float*)ptr);
4358 exp.type = constantExp;
4363 FreeExpContents(exp);
4365 exp.constant = PrintDouble(*(double*)ptr);
4366 exp.type = constantExp;
4371 FreeExpContents(exp);
4373 exp.constant = PrintInt(*(int*)ptr);
4374 exp.type = constantExp;
4379 FreeExpContents(exp);
4381 exp.constant = PrintInt64(*(int64*)ptr);
4382 exp.type = constantExp;
4386 Compiler_Error($"Unhandled type populating instance\n");
4389 ListAdd(memberList, member);
4392 if(parentDataMember.type == unionMember)
4397 void PopulateInstance(Instantiation inst)
4399 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4400 Class _class = classSym.registered;
4401 DataMember dataMember;
4402 OldList * memberList = MkList();
4403 inst.members = MkListOne(MkMembersInitList(memberList));
4404 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4406 if(!dataMember.isProperty)
4408 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4409 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4413 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4415 void * ptr = inst.data + dataMember.offset;
4416 char * result = null;
4418 exp.loc = member.loc = inst.loc;
4419 ((Identifier)member.identifiers->first).loc = inst.loc;
4421 if(!dataMember.dataType)
4422 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4423 type = dataMember.dataType;
4424 if(type.kind == classType)
4426 Class _class = type._class.registered;
4427 if(_class.type == enumClass)
4429 Class enumClass = eSystem_FindClass(privateModule, "enum");
4432 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4434 for(item = e.values.first; item; item = item.next)
4436 if((int)item.data == *(int *)ptr)
4445 exp.identifier = MkIdentifier(result);
4446 exp.type = identifierExp;
4447 exp.destType = MkClassType(_class.fullName);
4448 ProcessExpressionType(exp);
4451 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4453 if(!_class.dataType)
4454 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4455 type = _class.dataType;
4464 exp.constant = PrintFloat(*(float*)ptr);
4465 exp.type = constantExp;
4470 exp.constant = PrintDouble(*(double*)ptr);
4471 exp.type = constantExp;
4476 exp.constant = PrintInt(*(int*)ptr);
4477 exp.type = constantExp;
4482 exp.constant = PrintInt64(*(int64*)ptr);
4483 exp.type = constantExp;
4487 Compiler_Error($"Unhandled type populating instance\n");
4490 ListAdd(memberList, member);
4496 void ComputeInstantiation(Expression exp)
4498 Instantiation inst = exp.instance;
4499 MembersInit members;
4500 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4501 Class _class = classSym ? classSym.registered : null;
4502 DataMember curMember = null;
4503 Class curClass = null;
4504 DataMember subMemberStack[256];
4505 int subMemberStackPos = 0;
4508 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4510 // Don't recompute the instantiation...
4511 // Non Simple classes will have become constants by now
4515 if(_class.type == normalClass || _class.type == noHeadClass)
4516 inst.data = (byte *)eInstance_New(_class);
4518 inst.data = new0 byte[_class.structSize];
4523 for(members = inst.members->first; members; members = members.next)
4525 switch(members.type)
4527 case dataMembersInit:
4529 if(members.dataMembers)
4532 for(member = members.dataMembers->first; member; member = member.next)
4534 Identifier ident = member.identifiers ? member.identifiers->first : null;
4537 Property prop = null;
4538 DataMember dataMember = null;
4539 Method method = null;
4540 uint dataMemberOffset;
4544 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4547 if(curMember.isProperty)
4548 prop = (Property)curMember;
4551 dataMember = curMember;
4553 // CHANGED THIS HERE
4554 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4555 // dataMemberOffset = dataMember.offset;
4562 prop = eClass_FindProperty(_class, ident.string, privateModule);
4566 if(prop.memberAccess == publicAccess)
4568 curMember = (DataMember)prop;
4569 curClass = prop._class;
4574 DataMember _subMemberStack[256];
4575 int _subMemberStackPos = 0;
4577 // FILL MEMBER STACK
4578 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4583 if(dataMember.memberAccess == publicAccess)
4585 curMember = dataMember;
4586 curClass = dataMember._class;
4587 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4588 subMemberStackPos = _subMemberStackPos;
4594 if(found && member.initializer && member.initializer.type == expInitializer)
4596 Expression value = member.initializer.exp;
4600 type = prop.dataType;
4604 if(!dataMember.dataType)
4605 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4607 type = dataMember.dataType;
4610 if(ident && ident.next)
4612 // for(; ident && type; ident = ident.next)
4613 for(ident = ident.next; ident && type; ident = ident.next)
4615 if(type.kind == classType)
4617 prop = eClass_FindProperty(type._class.registered,
4618 ident.string, privateModule);
4620 type = prop.dataType;
4623 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4624 ident.string, &dataMemberOffset, privateModule, null, null);
4626 type = dataMember.dataType;
4629 else if(type.kind == structType || type.kind == unionType)
4632 for(memberType = type.members.first; memberType; memberType = memberType.next)
4634 if(!strcmp(memberType.name, ident.string))
4645 FreeType(value.destType);
4646 value.destType = type;
4647 if(type) type.refCount++;
4648 ComputeExpression(value);
4650 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4652 if(type.kind == classType)
4654 Class _class = type._class.registered;
4655 if(_class.type == bitClass || _class.type == unitClass ||
4656 _class.type == enumClass)
4658 if(!_class.dataType)
4659 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4660 type = _class.dataType;
4666 void * ptr = inst.data + dataMemberOffset;
4668 if(value.type == constantExp)
4674 GetInt(value, (int*)ptr);
4679 GetInt64(value, (int64*)ptr);
4684 GetFloat(value, (float*)ptr);
4689 GetDouble(value, (double *)ptr);
4694 else if(value.type == instanceExp)
4696 if(type.kind == classType)
4698 Class _class = type._class.registered;
4699 if(_class.type == structClass)
4701 ComputeTypeSize(type);
4702 if(value.instance.data)
4703 memcpy(ptr, value.instance.data, type.size);
4710 if(value.type == instanceExp && value.instance.data)
4712 void (*Set)(void *, void *) = (void *)prop.Set;
4713 Set(inst.data, value.instance.data);
4714 PopulateInstance(inst);
4716 else if(value.type == constantExp)
4722 void (*Set)(void *, double) = (void *)prop.Set;
4723 Set(inst.data, strtod(value.constant, null) );
4728 void (*Set)(void *, float) = (void *)prop.Set;
4729 Set(inst.data, (float)(strtod(value.constant, null)));
4734 void (*Set)(void *, int) = (void *)prop.Set;
4735 Set(inst.data, strtol(value.constant, null, 0));
4740 void (*Set)(void *, int64) = (void *)prop.Set;
4741 Set(inst.data, _strtoi64(value.constant, null, 0));
4746 else if(value.type == stringExp)
4749 ReadString(temp, value.string);
4750 prop.Set(inst.data, temp);
4754 else if(_class.type == unitClass)
4758 // Only support converting units to units for now...
4759 if(value.type == constantExp)
4761 if(type.kind == classType)
4763 Class _class = type._class.registered;
4764 if(_class.type == unitClass)
4766 if(!_class.dataType)
4767 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4768 type = _class.dataType;
4771 // TODO: Assuming same base type for units...
4777 float (*Set)(float) = (void *)prop.Set;
4778 GetFloat(member.initializer.exp, &fValue);
4779 exp.constant = PrintFloat(Set(fValue));
4780 exp.type = constantExp;
4786 double (*Set)(double) = (void *)prop.Set;
4787 GetDouble(member.initializer.exp, &dValue);
4788 exp.constant = PrintDouble(Set(dValue));
4789 exp.type = constantExp;
4796 else if(_class.type == bitClass)
4800 if(value.type == instanceExp && value.instance.data)
4802 unsigned int (*Set)(void *) = (void *)prop.Set;
4803 bits = Set(value.instance.data);
4805 else if(value.type == constantExp)
4811 BitMember bitMember = (BitMember) dataMember;
4814 GetInt(value, &part);
4815 bits = (bits & ~bitMember.mask);
4816 if(!bitMember.dataType)
4817 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4819 type = bitMember.dataType;
4821 if(type.kind == classType && type._class && type._class.registered)
4823 if(!type._class.registered.dataType)
4824 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4825 type = type._class.registered.dataType;
4832 bits |= ((char)part << bitMember.pos);
4834 bits |= ((unsigned char)part << bitMember.pos);
4838 bits |= ((short)part << bitMember.pos);
4840 bits |= ((unsigned short)part << bitMember.pos);
4845 bits |= ((int)part << bitMember.pos);
4847 bits |= ((unsigned int)part << bitMember.pos);
4851 bits |= ((int64)part << bitMember.pos);
4853 bits |= ((uint64)part << bitMember.pos);
4861 if(_class && _class.type == unitClass)
4863 ComputeExpression(member.initializer.exp);
4864 exp.constant = member.initializer.exp.constant;
4865 exp.type = constantExp;
4867 member.initializer.exp.constant = null;
4877 if(_class && _class.type == bitClass)
4879 exp.constant = PrintHexUInt(bits);
4880 exp.type = constantExp;
4882 if(exp.type != instanceExp)
4888 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4890 if(exp.op.op == SIZEOF)
4892 FreeExpContents(exp);
4893 exp.type = constantExp;
4894 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4905 // Provide default unary +
4906 Expression exp2 = exp.op.exp2;
4908 FreeExpContents(exp);
4909 FreeType(exp.expType);
4910 FreeType(exp.destType);
4916 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4918 // unary arithmetic increment and decrement
4919 //OPERATOR_ALL(UNARY, ++, Inc)
4920 //OPERATOR_ALL(UNARY, --, Dec)
4923 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4925 // unary logical negation
4927 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4935 // binary arithmetic
4937 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4940 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
4943 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
4946 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
4949 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
4951 // binary arithmetic assignment
4952 //OPERATOR_ALL(BINARY, =, Asign)
4953 //OPERATOR_ALL(BINARY, +=, AddAsign)
4954 //OPERATOR_ALL(BINARY, -=, SubAsign)
4955 //OPERATOR_ALL(BINARY, *=, MulAsign)
4956 //OPERATOR_ALL(BINARY, /=, DivAsign)
4957 //OPERATOR_ALL(BINARY, %=, ModAsign)
4962 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
4966 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
4969 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
4972 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
4975 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
4977 // binary bitwise assignment
4978 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4979 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4980 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4981 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4982 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4983 // binary logical equality
4985 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
4988 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
4992 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
4995 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
4997 // binary logical relational
4999 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5002 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5005 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5008 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5015 void ComputeExpression(Expression exp)
5017 char expString[10240];
5018 expString[0] = '\0';
5020 PrintExpression(exp, expString);
5027 ComputeInstantiation(exp);
5036 Expression exp1, exp2 = null;
5040 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5042 ComputeExpression(exp.op.exp2);
5045 ComputeExpression(exp.op.exp1);
5048 op1 = GetOperand(exp1);
5049 if(op1.type) op1.type.refCount++;
5052 op2 = GetOperand(exp2);
5053 if(op2.type) op2.type.refCount++;
5059 op1 = GetOperand(exp1);
5060 if(op1.type) op1.type.refCount++;
5063 CallOperator(exp, exp1, exp2, op1, op2);
5070 if(exp.op.exp1 && exp.op.exp2)
5075 FreeExpContents(exp);
5076 op1.ops.BitAnd(exp, op1, op2);
5085 FreeExpContents(exp);
5086 op1.ops.Mul(exp, op1, op2);
5095 FreeExpContents(exp);
5096 op1.ops.Add(exp, op1, op2);
5101 // Provide default unary +
5102 Expression exp2 = exp.op.exp2;
5104 FreeExpContents(exp);
5105 FreeType(exp.expType);
5106 FreeType(exp.destType);
5117 FreeExpContents(exp);
5118 op1.ops.Sub(exp, op1, op2);
5125 FreeExpContents(exp);
5126 op1.ops.Neg(exp, op1);
5133 FreeExpContents(exp);
5134 op1.ops.BitNot(exp, op1);
5140 FreeExpContents(exp);
5141 op1.ops.Not(exp, op1);
5144 // Binary only operators
5148 FreeExpContents(exp);
5149 op1.ops.Div(exp, op1, op2);
5155 FreeExpContents(exp);
5156 op1.ops.Mod(exp, op1, op2);
5168 FreeExpContents(exp);
5169 op1.ops.Sma(exp, op1, op2);
5178 FreeExpContents(exp);
5179 op1.ops.Grt(exp, op1, op2);
5188 FreeExpContents(exp);
5189 op1.ops.SmaEqu(exp, op1, op2);
5198 FreeExpContents(exp);
5199 op1.ops.GrtEqu(exp, op1, op2);
5208 FreeExpContents(exp);
5209 op1.ops.Equ(exp, op1, op2);
5218 FreeExpContents(exp);
5219 op1.ops.Nqu(exp, op1, op2);
5226 FreeExpContents(exp);
5227 op1.ops.BitOr(exp, op1, op2);
5233 FreeExpContents(exp);
5234 op1.ops.BitXor(exp, op1, op2);
5242 FreeExpContents(exp);
5243 exp.type = constantExp;
5244 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5248 if(op1.type) FreeType(op1.type);
5249 if(op2.type) FreeType(op2.type);
5253 case extensionExpressionExp:
5256 for(e = exp.list->first; e; e = n)
5261 OldList * list = exp.list;
5262 ComputeExpression(e);
5263 //FreeExpContents(exp);
5264 FreeType(exp.expType);
5265 FreeType(exp.destType);
5282 exp.isConstant = true;
5284 ComputeExpression(exp.index.exp);
5285 if(!exp.index.exp.isConstant)
5286 exp.isConstant = false;
5288 for(e = exp.index.index->first; e; e = e.next)
5290 ComputeExpression(e);
5293 // Check if this type is int
5296 exp.isConstant = false;
5298 exp.expType = Dereference(exp.index.exp.expType);
5304 Expression memberExp = exp.member.exp;
5305 Identifier memberID = exp.member.member;
5308 ComputeExpression(exp.member.exp);
5309 type = exp.member.exp.expType;
5312 Class _class = (exp.member.member && exp.member.member.classSym) ? exp.member.member.classSym.registered : (((type.kind == classType || type.kind == subClassType) && type._class) ? type._class.registered : null);
5313 Property prop = null;
5314 DataMember member = null;
5315 Class convertTo = null;
5316 if(type.kind == subClassType && exp.member.exp.type == classExp)
5317 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5324 PrintType(type, string, false, true);
5325 classSym = FindClass(string);
5326 _class = classSym ? classSym.registered : null;
5329 if(exp.member.member)
5331 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5333 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5335 if(!prop && !member && _class && exp.member.member)
5337 Symbol classSym = FindClass(exp.member.member.string);
5339 _class = classSym ? classSym.registered : null;
5340 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5347 Type type = prop.dataType;
5348 // TODO: Assuming same base type for units...
5349 if(_class.type == unitClass)
5351 if(type.kind == classType)
5353 Class _class = type._class.registered;
5354 if(_class.type == unitClass)
5356 if(!_class.dataType)
5357 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5358 type = _class.dataType;
5366 float (*Get)(float) = (void *)prop.Get;
5367 GetFloat(exp.member.exp, &value);
5368 exp.constant = PrintFloat(Get ? Get(value) : value);
5369 exp.type = constantExp;
5375 double (*Get)(double);
5376 GetDouble(exp.member.exp, &value);
5379 Get = (void *)prop.Set;
5381 Get = (void *)prop.Get;
5382 exp.constant = PrintDouble(Get ? Get(value) : value);
5383 exp.type = constantExp;
5392 Expression value = exp.member.exp;
5395 ProcessPropertyType(prop);
5397 type = prop.dataType;
5400 // printf("Investigate this\n");
5402 else if(_class.type == structClass)
5408 Class propertyClass = type._class.registered;
5409 if(propertyClass.type == structClass && value.type == instanceExp)
5411 void (*Set)(void *, void *) = (void *)prop.Set;
5412 exp.instance = Instantiation { };
5413 exp.instance.data = new0 byte[_class.structSize];
5414 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5415 exp.instance.loc = exp.loc;
5416 exp.type = instanceExp;
5417 Set(exp.instance.data, value.instance.data);
5418 PopulateInstance(exp.instance);
5425 void (*Set)(void *, int) = (void *)prop.Set;
5427 exp.instance = Instantiation { };
5428 exp.instance.data = new0 byte[_class.structSize];
5429 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5430 exp.instance.loc = exp.loc;
5431 exp.type = instanceExp;
5433 GetInt(value, &intValue);
5435 Set(exp.instance.data, intValue);
5436 PopulateInstance(exp.instance);
5442 void (*Set)(void *, int64) = (void *)prop.Set;
5444 exp.instance = Instantiation { };
5445 exp.instance.data = new0 byte[_class.structSize];
5446 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5447 exp.instance.loc = exp.loc;
5448 exp.type = instanceExp;
5450 GetInt64(value, &intValue);
5452 Set(exp.instance.data, intValue);
5453 PopulateInstance(exp.instance);
5459 void (*Set)(void *, double) = (void *)prop.Set;
5461 exp.instance = Instantiation { };
5462 exp.instance.data = new0 byte[_class.structSize];
5463 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5464 exp.instance.loc = exp.loc;
5465 exp.type = instanceExp;
5467 GetDouble(value, &doubleValue);
5469 Set(exp.instance.data, doubleValue);
5470 PopulateInstance(exp.instance);
5475 else if(_class.type == bitClass)
5481 Class propertyClass = type._class.registered;
5482 if(propertyClass.type == structClass && value.instance.data)
5484 unsigned int (*Set)(void *) = (void *)prop.Set;
5485 unsigned int bits = Set(value.instance.data);
5486 exp.constant = PrintHexUInt(bits);
5487 exp.type = constantExp;
5490 else if(_class.type == bitClass)
5493 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5496 GetUInt(exp.member.exp, &value);
5498 exp.constant = PrintHexUInt(bits);
5499 exp.type = constantExp;
5507 if(_class.type == bitClass)
5510 GetUInt(exp.member.exp, &value);
5516 Class _class = type._class.registered;
5517 if(_class.type == structClass)
5519 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5521 exp.instance = Instantiation { };
5522 exp.instance.data = new0 byte[_class.structSize];
5523 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5524 exp.instance.loc = exp.loc;
5525 //exp.instance.fullSet = true;
5526 exp.type = instanceExp;
5527 Get(value, exp.instance.data);
5528 PopulateInstance(exp.instance);
5530 else if(_class.type == bitClass)
5532 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5533 uint64 bits = Get(value);
5534 exp.constant = PrintHexUInt64(bits);
5535 exp.type = constantExp;
5541 else if(_class.type == structClass)
5543 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5548 Class _class = type._class.registered;
5549 if(_class.type == structClass && value)
5551 void (*Get)(void *, void *) = (void *)prop.Get;
5553 exp.instance = Instantiation { };
5554 exp.instance.data = new0 byte[_class.structSize];
5555 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5556 exp.instance.loc = exp.loc;
5557 //exp.instance.fullSet = true;
5558 exp.type = instanceExp;
5559 Get(value, exp.instance.data);
5560 PopulateInstance(exp.instance);
5568 char * value = exp.member.exp.instance.data;
5573 Class _class = type._class.registered;
5574 if(_class.type == normalClass)
5576 void *(*Get)(void *) = (void *)prop.Get;
5578 exp.instance = Instantiation { };
5579 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5580 exp.type = instanceExp;
5581 exp.instance.data = Get(value, exp.instance.data);
5593 exp.isConstant = false;
5601 if(exp.type != ExpressionType::memberExp)
5603 FreeExpression(memberExp);
5604 FreeIdentifier(memberID);
5610 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5611 FreeExpContents(exp);
5612 exp.constant = PrintUInt(ComputeTypeSize(type));
5613 exp.type = constantExp;
5619 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5620 if(classSym && classSym.registered)
5622 if(classSym.registered.fixed)
5624 FreeSpecifier(exp._class);
5625 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5626 exp.type = constantExp;
5630 char className[1024];
5631 strcpy(className, "__ecereClass_");
5632 FullClassNameCat(className, classSym.string, true);
5633 MangleClassName(className);
5635 FreeExpContents(exp);
5636 exp.type = pointerExp;
5637 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5638 exp.member.member = MkIdentifier("structSize");
5648 if(exp.type == castExp)
5651 ComputeExpression(exp.cast.exp);
5654 if(e && exp.expType)
5657 type = exp.destType;
5660 if(type.kind == classType)
5662 Class _class = type._class.registered;
5663 if(_class && (_class.type == unitClass || _class.type == bitClass))
5665 if(!_class.dataType)
5666 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5667 type = _class.dataType;
5678 FreeExpContents(exp);
5679 exp.constant = PrintChar(value);
5680 exp.type = constantExp;
5684 unsigned char value;
5685 GetUChar(e, &value);
5686 FreeExpContents(exp);
5687 exp.constant = PrintUChar(value);
5688 exp.type = constantExp;
5695 GetShort(e, &value);
5696 FreeExpContents(exp);
5697 exp.constant = PrintShort(value);
5698 exp.type = constantExp;
5702 unsigned short value;
5703 GetUShort(e, &value);
5704 FreeExpContents(exp);
5705 exp.constant = PrintUShort(value);
5706 exp.type = constantExp;
5714 FreeExpContents(exp);
5715 exp.constant = PrintInt(value);
5716 exp.type = constantExp;
5722 FreeExpContents(exp);
5723 exp.constant = PrintUInt(value);
5724 exp.type = constantExp;
5731 GetInt64(e, &value);
5732 FreeExpContents(exp);
5733 exp.constant = PrintInt64(value);
5734 exp.type = constantExp;
5739 GetUInt64(e, &value);
5740 FreeExpContents(exp);
5741 exp.constant = PrintUInt64(value);
5742 exp.type = constantExp;
5748 GetFloat(e, &value);
5749 FreeExpContents(exp);
5750 exp.constant = PrintFloat(value);
5751 exp.type = constantExp;
5757 GetDouble(e, &value);
5758 FreeExpContents(exp);
5759 exp.constant = PrintDouble(value);
5760 exp.type = constantExp;
5774 // Caring only about last expression for now...
5775 ComputeExpression(exp.cond.exp->last);
5776 if(exp.cond.elseExp)
5777 ComputeExpression(exp.cond.elseExp);
5779 ComputeExpression(exp.cond.cond);
5781 op1 = GetOperand(exp.cond.cond);
5782 if(op1.type) op1.type.refCount++;
5783 op2 = GetOperand(exp.cond.exp->last);
5784 if(op2.type) op2.type.refCount++;
5785 op3 = GetOperand(exp.cond.elseExp);
5786 if(op3.type) op3.type.refCount++;
5788 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5789 if(op1.type) FreeType(op1.type);
5790 if(op2.type) FreeType(op2.type);
5791 if(op3.type) FreeType(op3.type);
5797 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5802 OldList converts { };
5805 if(destType.kind == voidType)
5808 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5812 // for(convert = converts.last; convert; convert = convert.prev)
5813 for(convert = converts.first; convert; convert = convert.next)
5815 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5818 Expression newExp { };
5819 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5821 // TODO: Check this...
5823 newExp.destType = null;
5828 exp.type = memberExp;
5829 exp.addedThis = true;
5830 exp.member.exp = newExp;
5831 FreeType(exp.member.exp.expType);
5833 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5834 exp.member.exp.expType.classObjectType = objectType;
5835 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5836 exp.member.memberType = propertyMember;
5837 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5838 // TESTING THIS... for (int)degrees
5839 exp.needCast = true;
5840 if(exp.expType) exp.expType.refCount++;
5841 ApplyAnyObjectLogic(exp.member.exp);
5846 /*if(exp.isConstant)
5848 // Color { ColorRGB = [exp] };
5849 exp.type = instanceExp;
5850 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5851 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5852 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5856 // If not constant, don't turn it yet into an instantiation
5857 // (Go through the deep members system first)
5858 exp.type = memberExp;
5859 exp.addedThis = true;
5860 exp.member.exp = newExp;
5862 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5863 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5864 newExp.expType._class.registered.type == noHeadClass)
5866 newExp.byReference = true;
5869 FreeType(exp.member.exp.expType);
5870 /*exp.member.exp.expType = convert.convert.dataType;
5871 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
5872 exp.member.exp.expType = null;
5873 if(convert.convert.dataType)
5875 exp.member.exp.expType = { };
5876 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
5877 exp.member.exp.expType.refCount = 1;
5878 exp.member.exp.expType.classObjectType = objectType;
5879 ApplyAnyObjectLogic(exp.member.exp);
5882 exp.member.member = MkIdentifier(convert.convert._class.fullName);
5883 exp.member.memberType = reverseConversionMember;
5884 exp.expType = convert.resultType ? convert.resultType :
5885 MkClassType(convert.convert._class.fullName);
5886 exp.needCast = true;
5887 if(convert.resultType) convert.resultType.refCount++;
5893 FreeType(exp.expType);
5896 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5897 exp.needCast = true;
5898 if(exp.expType) exp.expType.refCount++;
5902 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
5903 exp.needCast = true;
5904 if(convert.resultType)
5905 convert.resultType.refCount++;
5909 if(exp.isConstant && inCompiler)
5910 ComputeExpression(exp);
5912 converts.Free(FreeConvert);
5915 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
5917 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
5919 if(!result && exp.expType && exp.destType)
5921 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
5922 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
5923 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
5924 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
5928 // if(result) CheckTemplateTypes(exp);
5932 void CheckTemplateTypes(Expression exp)
5934 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
5936 Expression newExp { };
5940 if(exp.destType) exp.destType.refCount++;
5941 if(exp.expType) exp.expType.refCount++;
5945 switch(exp.expType.kind)
5948 if(exp.destType.classObjectType)
5950 // We need to pass the address, just pass it along (Undo what was done above)
5951 if(exp.destType) exp.destType.refCount--;
5952 if(exp.expType) exp.expType.refCount--;
5957 // If we're looking for value:
5958 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
5960 OldList * unionDefs = MkList();
5961 OldList * statements = MkList();
5962 context = PushContext();
5963 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
5964 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
5965 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
5966 exp.type = extensionCompoundExp;
5967 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
5968 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
5969 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
5970 exp.compound.compound.context = context;
5971 PopContext(context);
5976 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
5977 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
5981 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
5983 Expression newExp { };
5987 if(exp.destType) exp.destType.refCount++;
5988 if(exp.expType) exp.expType.refCount++;
5992 switch(exp.expType.kind)
5995 if(exp.destType.classObjectType)
5997 // We need to pass the address, just pass it along (Undo what was done above)
5998 if(exp.destType) exp.destType.refCount--;
5999 if(exp.expType) exp.expType.refCount--;
6004 // If we're looking for value:
6005 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6007 OldList * unionDefs = MkList();
6008 OldList * statements = MkList();
6009 context = PushContext();
6010 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6011 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6012 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6013 exp.type = extensionCompoundExp;
6014 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6015 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6016 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6017 exp.compound.compound.context = context;
6018 PopContext(context);
6023 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6025 exp.type = bracketsExp;
6026 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6027 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6028 ProcessExpressionType(exp.list->first);
6033 exp.type = bracketsExp;
6034 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6035 newExp.needCast = true;
6036 ProcessExpressionType(exp.list->first);
6042 if(exp.expType.kind == templateType)
6044 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6047 FreeType(exp.destType);
6048 FreeType(exp.expType);
6053 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6058 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6059 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6063 char typeString[1024];
6065 OldList * specs = MkList();
6066 typeString[0] = '\0';
6067 PrintType(exp.expType, typeString, false, false);
6068 decl = SpecDeclFromString(typeString, specs, null);
6071 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6072 exp.cast.typeName = MkTypeName(specs, decl);
6073 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6074 exp.cast.exp.needCast = true;
6081 // TODO: The Symbol tree should be reorganized by namespaces
6083 // - Tree of all symbols within (stored without namespace)
6084 // - Tree of sub-namespaces
6086 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6088 int nsLen = strlen(nameSpace);
6090 // Start at the name space prefix
6091 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6093 char * s = symbol.string;
6094 if(!strncmp(s, nameSpace, nsLen))
6096 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6099 for(c = strlen(s)-1; c >= 0; c--)
6104 if(!strcmp(namePart, name))
6106 // TODO: Error on ambiguity
6116 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6119 char nameSpace[1024];
6121 bool gotColon = false;
6123 nameSpace[0] = '\0';
6124 for(c = strlen(name)-1; c >= 0; c--)
6131 namePart = name+c+1;
6132 while(c >= 0 && name[c] == ':') c--;
6135 // Try an exact match first
6136 Symbol symbol = (Symbol)tree.FindString(name);
6140 // Namespace specified
6141 memcpy(nameSpace, name, c + 1);
6144 return ScanWithNameSpace(tree, nameSpace, namePart);
6148 // Looking for a global symbol, e.g. ::Sleep()
6149 Symbol symbol = (Symbol)tree.FindString(namePart);
6154 // Name only (no namespace specified)
6155 Symbol symbol = (Symbol)tree.FindString(namePart);
6158 return ScanWithNameSpace(tree, "", namePart);
6163 static void ProcessDeclaration(Declaration decl);
6165 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6168 //Time startTime = GetTime();
6170 // Optimize this later? Do this before/less?
6172 Symbol symbol = null;
6173 // First, check if the identifier is declared inside the function
6174 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6176 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6178 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6184 strcpy(curName, thisNameSpace);
6185 strcat(curName, "::");
6186 strcat(curName, name);
6187 // Try to resolve in current namespace first
6188 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6191 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6194 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6196 if(symbol || ctx == endContext) break;
6198 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6200 if(symbol.pointerExternal.type == functionExternal)
6202 FunctionDefinition function = symbol.pointerExternal.function;
6204 // Modified this recently...
6205 Context tmpContext = curContext;
6207 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6208 curContext = tmpContext;
6210 symbol.pointerExternal.symbol = symbol;
6213 DeclareType(symbol.type, true, true);
6215 ast->Insert(curExternal.prev, symbol.pointerExternal);
6217 symbol.id = curExternal.symbol.idCode;
6220 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6222 ast->Move(symbol.pointerExternal, curExternal.prev);
6223 symbol.id = curExternal.symbol.idCode;
6227 //findSymbolTotalTime += GetTime() - startTime;
6232 static void GetTypeSpecs(Type type, OldList * specs)
6234 if(!type.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
6239 if(type._class.registered)
6241 if(!type._class.registered.dataType)
6242 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6243 GetTypeSpecs(type._class.registered.dataType, specs);
6247 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6248 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6249 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6250 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6251 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6254 ListAdd(specs, MkSpecifier(INT)); break;
6258 // WARNING : This function expects a null terminated string since it recursively concatenate...
6259 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6266 if(type._class && type._class.string)
6268 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6269 // look into merging with thisclass ?
6270 if(type.classObjectType == typedObject)
6271 strcat(string, "typed_object");
6273 strcat(string, type._class.string);
6276 if(type._class.registered)
6277 strcat(string, type._class.registered.name);
6279 strcat(string, type._class.string);
6286 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6287 if(funcType && funcType.kind == functionType)
6290 PrintType(funcType.returnType, string, false, fullName);
6291 strcat(string, "(*");
6292 if(printName || funcType.thisClass)
6294 strcat(string, " ");
6295 if(funcType.thisClass)
6297 strcat(string, funcType.thisClass.string);
6298 strcat(string, "::");
6301 strcat(string, type.name);
6303 strcat(string, ")(");
6304 for(param = funcType.params.first; param; param = param.next)
6306 PrintType(param, string, false, fullName);
6307 if(param.next) strcat(string, ", ");
6309 strcat(string, ")");
6313 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6314 strcat(string, " *");
6318 case voidType: strcat(string, "void"); break;
6319 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6320 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6321 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6322 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6323 case floatType: strcat(string, "float"); break;
6324 case doubleType: strcat(string, "double"); break;
6328 strcat(string, "struct ");
6329 strcat(string, type.enumName);
6331 else if(type.typeName)
6333 strcat(string, type.typeName);
6338 strcat(string, "struct ");
6339 strcat(string,"(unnamed)");
6342 strcat(string, "struct {");
6343 for(member = type.members.first; member; member = member.next)
6345 PrintType(member, string, true, fullName);
6346 strcat(string,"; ");
6354 strcat(string, "union ");
6355 strcat(string, type.enumName);
6357 else if(type.typeName)
6359 strcat(string, type.typeName);
6363 strcat(string, "union ");
6364 strcat(string,"(unnamed)");
6370 strcat(string, "enum ");
6371 strcat(string, type.enumName);
6373 else if(type.typeName)
6375 strcat(string, type.typeName);
6378 strcat(string, "enum");
6385 strcat(string, "dllexport ");
6386 PrintType(type.returnType, string, false, fullName);
6387 strcat(string, " ");
6390 // DANGER: Testing This
6396 strcat(string, type.name);
6399 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6400 if(name) name += 2; else name = type.name;
6401 strcat(string, name);
6415 strcat(string, "(");
6416 for(param = type.params.first; param; param = param.next)
6418 PrintType(param, string, true, fullName);
6419 if(param.next) strcat(string, ", ");
6421 strcat(string, ")");
6428 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6429 if(funcType && funcType.kind == functionType)
6432 PrintType(funcType.returnType, string, false, fullName);
6433 strcat(string, "(*");
6434 if(printName || funcType.thisClass)
6436 strcat(string, " ");
6437 if(funcType.thisClass)
6439 strcat(string, funcType.thisClass.string);
6440 strcat(string, "::");
6443 strcat(string, type.name);
6445 strcat(string, ")(");
6446 for(param = funcType.params.first; param; param = param.next)
6448 PrintType(param, string, false, fullName);
6449 if(param.next) strcat(string, ", ");
6451 strcat(string, ")");
6455 char baseType[1024], size[256];
6456 Type arrayType = type;
6460 while(arrayType.kind == TypeKind::arrayType)
6463 if(arrayType.enumClass)
6464 strcat(size, arrayType.enumClass.string);
6465 else if(arrayType.arraySizeExp)
6466 PrintExpression(arrayType.arraySizeExp, size);
6467 //sprintf(string, "%s[%s]", baseType, size);
6470 arrayType = arrayType.arrayType;
6472 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6473 strcat(string, baseType);
6474 strcat(string, size);
6478 PrintType(type.arrayType, baseType, printName, fullName);
6480 strcpy(size, type.enumClass.string);
6481 else if(type.arraySizeExp)
6482 PrintExpression(type.arraySizeExp, size);
6483 //sprintf(string, "%s[%s]", baseType, size);
6484 strcat(string, baseType);
6485 strcat(string, "[");
6486 strcat(string, size);
6487 strcat(string, "]");
6494 strcat(string, "...");
6497 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6500 strcat(string, "subclass(");
6501 strcat(string, type._class ? type._class.string : "int");
6502 strcat(string, ")");
6505 strcat(string, type.templateParameter.identifier.string);
6508 strcat(string, "thisclass");
6511 strcat(string, "__builtin_va_list");
6518 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6520 strcat(string, " ");
6521 strcat(string, type.name);
6527 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6529 void PrintType(Type type, char * string, bool printName, bool fullName)
6532 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6533 if(funcType && funcType.kind == functionType && type != funcType)
6535 char typeString[1024];
6538 PrintType(funcType.returnType, string, false, fullName);
6539 strcat(string, "(");
6540 _PrintType(type, string, printName, false, fullName);
6541 strcat(string, ")");
6544 strcat(string, type.name);
6550 strcat(string, "(");
6551 for(param = funcType.params.first; param; param = param.next)
6553 PrintType(param, string, true, fullName);
6554 if(param.next) strcat(string, ", ");
6556 strcat(string, ")");
6559 _PrintType(type, string, printName, true, fullName);
6560 if(type.bitFieldCount)
6563 sprintf(count, ":%d", type.bitFieldCount);
6564 strcat(string, count);
6568 static Type FindMember(Type type, char * string)
6571 for(memberType = type.members.first; memberType; memberType = memberType.next)
6573 if(!memberType.name)
6575 Type subType = FindMember(memberType, string);
6579 else if(!strcmp(memberType.name, string))
6585 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6588 for(memberType = type.members.first; memberType; memberType = memberType.next)
6590 if(!memberType.name)
6592 Type subType = FindMember(memberType, string);
6595 *offset += memberType.offset;
6599 else if(!strcmp(memberType.name, string))
6601 *offset += memberType.offset;
6608 Expression ParseExpressionString(char * expression)
6610 fileInput = TempFile { };
6611 fileInput.Write(expression, 1, strlen(expression));
6612 fileInput.Seek(0, start);
6615 parsedExpression = null;
6617 expression_yyparse();
6620 return parsedExpression;
6623 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6625 Identifier id = exp.identifier;
6626 Method method = null;
6627 Property prop = null;
6628 DataMember member = null;
6629 ClassProperty classProp = null;
6631 if(_class && _class.type == enumClass)
6633 NamedLink value = null;
6634 Class enumClass = eSystem_FindClass(privateModule, "enum");
6638 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6640 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6641 for(value = e.values.first; value; value = value.next)
6643 if(!strcmp(value.name, id.string))
6650 FreeExpContents(exp);
6652 exp.type = constantExp;
6653 exp.isConstant = true;
6654 if(!strcmp(baseClass.dataTypeString, "int"))
6655 sprintf(constant, "%d",value.data);
6657 sprintf(constant, "0x%X",value.data);
6658 exp.constant = CopyString(constant);
6659 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6660 exp.expType = MkClassType(baseClass.fullName);
6668 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6670 ProcessMethodType(method);
6677 // TOCHECK: Put it back to what it was...
6678 // methodClass = _class;
6679 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6684 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6687 ProcessPropertyType(prop);
6688 exp.expType = prop.dataType;
6689 if(prop.dataType) prop.dataType.refCount++;
6692 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6694 if(!member.dataType)
6695 member.dataType = ProcessTypeString(member.dataTypeString, false);
6696 exp.expType = member.dataType;
6697 if(member.dataType) member.dataType.refCount++;
6700 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6702 if(!classProp.dataType)
6703 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6705 if(classProp.constant)
6707 FreeExpContents(exp);
6709 exp.isConstant = true;
6710 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6712 //char constant[256];
6713 exp.type = stringExp;
6714 exp.constant = QMkString((char *)classProp.Get(_class));
6719 exp.type = constantExp;
6720 sprintf(constant, "%d",classProp.Get(_class));
6721 exp.constant = CopyString(constant);
6729 exp.expType = classProp.dataType;
6730 if(classProp.dataType) classProp.dataType.refCount++;
6736 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6738 BinaryTree * tree = &nameSpace.functions;
6739 GlobalData data = (GlobalData)tree->FindString(name);
6743 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6745 data = ScanGlobalData(child, name);
6753 static GlobalData FindGlobalData(char * name)
6756 NameSpace * nameSpace;
6757 nameSpace = globalData;
6758 for(c = 0; name[c]; c++)
6760 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6762 NameSpace * newSpace;
6763 char * spaceName = new char[c - start + 1];
6764 strncpy(spaceName, name + start, c - start);
6765 spaceName[c-start] = '\0';
6766 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6770 nameSpace = newSpace;
6771 if(name[c] == ':') c++;
6777 return ScanGlobalData(nameSpace, name + start);
6782 static int definedExpStackPos;
6783 static void * definedExpStack[512];
6785 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6786 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6788 Expression prev = checkedExp.prev, next = checkedExp.next;
6790 FreeExpContents(checkedExp);
6791 FreeType(checkedExp.expType);
6792 FreeType(checkedExp.destType);
6794 *checkedExp = *newExp;
6798 checkedExp.prev = prev;
6799 checkedExp.next = next;
6802 void ApplyAnyObjectLogic(Expression e)
6804 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6805 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6807 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6808 //ellipsisDestType = destType;
6811 Type type = e.expType;
6812 Class _class = null;
6813 //Type destType = e.destType;
6815 if(type.kind == classType && type._class && type._class.registered)
6817 _class = type._class.registered;
6819 else if(type.kind == subClassType)
6821 _class = FindClass("ecere::com::Class").registered;
6825 char string[1024] = "";
6828 PrintType(type, string, false, true);
6829 classSym = FindClass(string);
6830 if(classSym) _class = classSym.registered;
6833 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "ecere::com::Class")) || // Patched so that class isn't considered SYSTEM...
6834 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6835 destType.byReference)))
6837 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6839 Expression checkedExp = e, newExp;
6841 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6843 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6845 if(checkedExp.type == extensionCompoundExp)
6847 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6850 checkedExp = checkedExp.list->last;
6852 else if(checkedExp.type == castExp)
6853 checkedExp = checkedExp.cast.exp;
6856 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6858 newExp = checkedExp.op.exp2;
6859 checkedExp.op.exp2 = null;
6860 FreeExpContents(checkedExp);
6862 if(e.expType && e.expType.passAsTemplate)
6865 ComputeTypeSize(e.expType);
6866 sprintf(size, "%d", e.expType.size);
6867 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6868 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6869 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6872 ReplaceExpContents(checkedExp, newExp);
6873 e.byReference = true;
6875 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6877 Expression checkedExp, newExp;
6880 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6882 e.type == identifierExp ||
6883 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6884 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6885 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6888 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6890 Context context = PushContext();
6892 OldList * specs = MkList();
6893 char typeString[1024];
6894 Expression newExp { };
6896 typeString[0] = '\0';
6899 //if(e.destType) e.destType.refCount++;
6900 // if(exp.expType) exp.expType.refCount++;
6903 newExp.expType = null;
6905 PrintType(e.expType, typeString, false, true);
6906 decl = SpecDeclFromString(typeString, specs, null);
6907 newExp.destType = ProcessType(specs, decl);
6909 curContext = context;
6910 e.type = extensionCompoundExp;
6912 // We need a current compound for this
6916 OldList * stmts = MkList();
6917 sprintf(name, "__internalValue%03X", internalValueCounter++);
6918 if(!curCompound.compound.declarations)
6919 curCompound.compound.declarations = MkList();
6920 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
6921 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
6922 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
6923 e.compound = MkCompoundStmt(null, stmts);
6926 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
6929 e.compound = MkCompoundStmt(
6930 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
6931 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
6933 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
6937 Type type = e.destType;
6939 CopyTypeInto(e.destType, type);
6940 e.destType.refCount = 1;
6941 e.destType.classObjectType = none;
6945 e.compound.compound.context = context;
6946 PopContext(context);
6947 curContext = context.parent;
6951 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
6953 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6955 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6957 if(checkedExp.type == extensionCompoundExp)
6959 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6962 checkedExp = checkedExp.list->last;
6964 else if(checkedExp.type == castExp)
6965 checkedExp = checkedExp.cast.exp;
6968 Expression operand { };
6969 operand = *checkedExp;
6970 checkedExp.destType = null;
6971 checkedExp.expType = null;
6973 checkedExp.type = opExp;
6974 checkedExp.op.op = '&';
6975 checkedExp.op.exp1 = null;
6976 checkedExp.op.exp2 = operand;
6978 //newExp = MkExpOp(null, '&', checkedExp);
6980 //ReplaceExpContents(checkedExp, newExp);
6987 // If expression type is a simple class, make it an address
6988 // FixReference(e, true);
6991 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6992 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6993 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
6995 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
6997 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7001 Expression thisExp { };
7004 thisExp.prev = null;
7005 thisExp.next = null;
7008 e.type = bracketsExp;
7009 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
7010 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7011 ((Expression)e.list->first).byReference = true;
7013 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7015 e.expType = thisExp.expType;
7016 e.expType.refCount++;
7021 CopyTypeInto(e.expType, thisExp.expType);
7022 e.expType.byReference = false;
7023 e.expType.refCount = 1;
7025 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7026 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7028 e.expType.classObjectType = none;
7033 // TOFIX: Try this for a nice IDE crash!
7035 // The other way around
7038 if(destType && e.expType &&
7039 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7040 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7041 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7043 if(destType.kind == ellipsisType)
7045 Compiler_Error($"Unspecified type\n");
7047 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7049 bool byReference = e.expType.byReference;
7050 Expression thisExp { };
7052 OldList * specs = MkList();
7053 char typeString[1024]; // Watch buffer overruns
7055 ClassObjectType backupClassObjectType;
7057 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7062 backupClassObjectType = type.classObjectType;
7064 type.classObjectType = none;
7066 typeString[0] = '\0';
7067 PrintType(type, typeString, false, true);
7068 decl = SpecDeclFromString(typeString, specs, null);
7070 type.classObjectType = backupClassObjectType;
7073 thisExp.prev = null;
7074 thisExp.next = null;
7077 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7078 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7079 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7080 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7081 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7086 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7091 e.cast.typeName = MkTypeName(specs, decl);
7092 e.cast.exp = thisExp;
7093 e.byReference = true;
7096 e.destType = destType;
7098 destType.refCount++;
7103 void ProcessExpressionType(Expression exp)
7105 bool unresolved = false;
7106 Location oldyylloc = yylloc;
7107 bool notByReference = false;
7109 char debugExpString[4096];
7110 debugExpString[0] = '\0';
7111 PrintExpression(exp, debugExpString);
7113 if(!exp || exp.expType)
7116 //eSystem_Logf("%s\n", expString);
7118 // Testing this here
7124 Identifier id = exp.identifier;
7127 // DOING THIS LATER NOW...
7128 if(id._class && id._class.name)
7130 id.classSym = id._class.symbol; // FindClass(id._class.name);
7131 /* TODO: Name Space Fix ups
7133 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7137 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7139 exp.expType = ProcessTypeString("Module", true);
7142 else */if(strstr(id.string, "__ecereClass") == id.string)
7144 exp.expType = ProcessTypeString("ecere::com::Class", true);
7147 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7149 // Added this here as well
7150 ReplaceClassMembers(exp, thisClass);
7151 if(exp.type != identifierExp)
7153 ProcessExpressionType(exp);
7157 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7162 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7163 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7164 if(!symbol/* && exp.destType*/)
7166 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7172 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7173 if(exp.type != identifierExp)
7175 ProcessExpressionType(exp);
7179 // Static methods called from inside the _class
7180 else if(currentClass && !id._class)
7182 if(ResolveIdWithClass(exp, currentClass, true))
7185 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7189 // If we manage to resolve this symbol
7192 Type type = symbol.type;
7193 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7195 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7197 Context context = SetupTemplatesContext(_class);
7198 type = ReplaceThisClassType(_class);
7199 FinishTemplatesContext(context);
7200 if(type) type.refCount = 0; // We'll be incrementing it right below...
7203 FreeSpecifier(id._class);
7206 id.string = CopyString(symbol.string);
7212 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7213 // Add missing cases here... enum Classes...
7214 exp.isConstant = true;
7216 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7217 if(symbol.isParam || !strcmp(id.string, "this"))
7219 if(_class && _class.type == structClass)
7220 exp.byReference = true;
7222 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7223 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7224 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7225 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7227 Identifier id = exp.identifier;
7228 exp.type = bracketsExp;
7229 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7233 if(symbol.isIterator)
7235 if(symbol.isIterator == 3)
7237 exp.type = bracketsExp;
7238 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7239 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7241 ProcessExpressionType(exp);
7243 else if(symbol.isIterator != 4)
7245 exp.type = memberExp;
7246 exp.member.exp = MkExpIdentifier(exp.identifier);
7247 exp.member.exp.expType = exp.expType;
7248 /*if(symbol.isIterator == 6)
7249 exp.member.member = MkIdentifier("key");
7251 exp.member.member = MkIdentifier("data");
7253 ProcessExpressionType(exp);
7260 DefinedExpression definedExp = null;
7261 if(thisNameSpace && !(id._class && !id._class.name))
7264 strcpy(name, thisNameSpace);
7266 strcat(name, id.string);
7267 definedExp = eSystem_FindDefine(privateModule, name);
7270 definedExp = eSystem_FindDefine(privateModule, id.string);
7274 for(c = 0; c<definedExpStackPos; c++)
7275 if(definedExpStack[c] == definedExp)
7277 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7279 Location backupYylloc = yylloc;
7280 definedExpStack[definedExpStackPos++] = definedExp;
7281 fileInput = TempFile { };
7282 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7283 fileInput.Seek(0, start);
7286 parsedExpression = null;
7288 expression_yyparse();
7291 yylloc = backupYylloc;
7293 if(parsedExpression)
7296 exp.type = bracketsExp;
7297 exp.list = MkListOne(parsedExpression);
7298 parsedExpression.loc = yylloc;
7299 ProcessExpressionType(exp);
7300 definedExpStackPos--;
7303 definedExpStackPos--;
7309 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7315 GlobalData data = null;
7316 if(thisNameSpace && !(id._class && !id._class.name))
7319 strcpy(name, thisNameSpace);
7321 strcat(name, id.string);
7322 data = FindGlobalData(name);
7325 data = FindGlobalData(id.string);
7328 DeclareGlobalData(data);
7329 exp.expType = data.dataType;
7330 if(data.dataType) data.dataType.refCount++;
7333 id.string = CopyString(data.fullName);
7334 FreeSpecifier(id._class);
7341 GlobalFunction function = null;
7342 if(thisNameSpace && !(id._class && !id._class.name))
7345 strcpy(name, thisNameSpace);
7347 strcat(name, id.string);
7348 function = eSystem_FindFunction(privateModule, name);
7351 function = eSystem_FindFunction(privateModule, id.string);
7356 id.string = CopyString(function.name);
7359 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7360 strcpy(name, "__ecereFunction_");
7361 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7362 if(DeclareFunction(function, name))
7365 id.string = CopyString(name);
7367 exp.expType = function.dataType;
7368 if(function.dataType) function.dataType.refCount++;
7370 FreeSpecifier(id._class);
7387 if(!exp.instance._class)
7389 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7391 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7401 //classSym = FindClass(exp.instance._class.fullName);
7402 //_class = classSym ? classSym.registered : null;
7404 ProcessInstantiationType(exp.instance);
7405 exp.isConstant = exp.instance.isConstant;
7408 if(_class.type == unitClass && _class.base.type != systemClass)
7411 Type destType = exp.destType;
7413 exp.destType = MkClassType(_class.base.fullName);
7414 exp.expType = MkClassType(_class.fullName);
7415 CheckExpressionType(exp, exp.destType, true);
7417 exp.destType = destType;
7419 exp.expType = MkClassType(_class.fullName);
7422 if(exp.instance._class)
7424 exp.expType = MkClassType(exp.instance._class.name);
7425 /*if(exp.expType._class && exp.expType._class.registered &&
7426 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7427 exp.expType.byReference = true;*/
7442 if(exp.constant[0] == '\'')
7444 if((int)((byte *)exp.constant)[1] > 127)
7447 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7448 if(nb < 2) ch = exp.constant[1];
7449 delete exp.constant;
7450 exp.constant = PrintUInt(ch);
7451 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7452 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7453 type._class = FindClass("unichar");
7455 type.isSigned = false;
7459 type.kind = charType;
7460 type.isSigned = true;
7463 else if(strchr(exp.constant, '.'))
7465 char ch = exp.constant[strlen(exp.constant)-1];
7467 type.kind = floatType;
7469 type.kind = doubleType;
7470 type.isSigned = true;
7474 if(exp.constant[0] == '0' && exp.constant[1])
7475 type.isSigned = false;
7476 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7477 type.isSigned = false;
7478 else if(strtoll(exp.constant, null, 0) > MAXINT)
7479 type.isSigned = false;
7481 type.isSigned = true;
7482 type.kind = intType;
7484 exp.isConstant = true;
7490 exp.isConstant = true; // Why wasn't this constant?
7506 ProcessExpressionType(exp._new.size);
7511 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7513 DeclareType(exp.expType.type, false, false);
7517 ProcessExpressionType(exp._renew.size);
7518 ProcessExpressionType(exp._renew.exp);
7523 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7525 DeclareType(exp.expType.type, false, false);
7529 bool assign = false, boolResult = false, boolOps = false;
7530 Type type1 = null, type2 = null;
7531 bool useDestType = false, useSideType = false;
7532 Location oldyylloc = yylloc;
7533 bool useSideUnit = false;
7535 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7544 // Assignment Operators
7558 // boolean Operators
7560 // Expect boolean operators
7562 //boolResult = true;
7566 // Expect boolean operands
7577 // Gives boolean result
7585 // Just added these... testing
7590 // DANGER: Verify units
7595 if(exp.op.op != '*' || exp.op.exp1)
7602 /*// Implement speed etc.
7608 if(exp.op.op == '&')
7610 // Added this here earlier for Iterator address as key
7611 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7613 Identifier id = exp.op.exp2.identifier;
7614 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7615 if(symbol && symbol.isIterator == 2)
7617 exp.type = memberExp;
7618 exp.member.exp = exp.op.exp2;
7619 exp.member.member = MkIdentifier("key");
7621 exp.op.exp2.expType = symbol.type;
7622 symbol.type.refCount++;
7623 ProcessExpressionType(exp);
7627 // exp.op.exp2.usage.usageRef = true;
7631 //dummy.kind = TypeDummy;
7635 if(exp.destType && exp.destType.kind == classType &&
7636 exp.destType._class && exp.destType._class.registered && useDestType &&
7638 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7639 exp.destType._class.registered.type == enumClass ||
7640 exp.destType._class.registered.type == bitClass
7643 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7645 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7646 exp.op.exp1.destType = exp.destType;
7648 exp.destType.refCount++;
7652 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7653 exp.op.exp1.destType = dummy;
7657 // TESTING THIS HERE...
7658 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7659 ProcessExpressionType(exp.op.exp1);
7660 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7662 if(exp.op.exp1.destType == dummy)
7665 exp.op.exp1.destType = null;
7667 type1 = exp.op.exp1.expType;
7672 char expString[10240];
7673 expString[0] = '\0';
7674 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7678 exp.op.exp2.destType = exp.op.exp1.expType;
7679 if(exp.op.exp1.expType)
7680 exp.op.exp1.expType.refCount++;
7684 exp.op.exp2.destType = exp.destType;
7686 exp.destType.refCount++;
7689 if(type1) type1.refCount++;
7690 exp.expType = type1;
7695 PrintExpression(exp.op.exp2, expString);
7697 if(type1 && type1.kind == pointerType)
7699 if(exp.op.op == MUL_ASSIGN || exp.op.op == DIV_ASSIGN ||exp.op.op == MOD_ASSIGN ||exp.op.op == LEFT_ASSIGN ||exp.op.op == RIGHT_ASSIGN ||
7700 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7701 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7702 else if(exp.op.op == '=')
7704 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7705 exp.op.exp2.destType = type1;
7712 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7713 if(exp.op.op == MUL_ASSIGN || exp.op.op == DIV_ASSIGN ||exp.op.op == MOD_ASSIGN ||exp.op.op == LEFT_ASSIGN ||exp.op.op == RIGHT_ASSIGN/* ||
7714 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7717 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7718 exp.op.exp2.destType = type1;
7723 if(type1) type1.refCount++;
7724 exp.expType = type1;
7726 else if(exp.destType && exp.destType.kind == classType &&
7727 exp.destType._class && exp.destType._class.registered &&
7729 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7730 (exp.destType._class.registered.type == enumClass && useDestType))
7733 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7734 exp.op.exp2.destType = exp.destType;
7736 exp.destType.refCount++;
7740 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7741 exp.op.exp2.destType = dummy;
7745 // TESTING THIS HERE... (DANGEROUS)
7746 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7747 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7749 FreeType(exp.op.exp2.destType);
7750 exp.op.exp2.destType = type1;
7753 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7754 ProcessExpressionType(exp.op.exp2);
7755 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7757 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7759 if(exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
7761 if(exp.op.op != '=' && type1.type.kind == voidType)
7762 Compiler_Error($"void *: unknown size\n");
7764 else if(exp.op.exp2.expType.kind == pointerType || exp.op.exp2.expType.kind == arrayType || exp.op.exp2.expType.kind == functionType || exp.op.exp2.expType.kind == methodType||
7765 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7766 (exp.op.exp2.expType._class.registered.type == normalClass ||
7767 exp.op.exp2.expType._class.registered.type == structClass ||
7768 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7770 if(exp.op.op == ADD_ASSIGN)
7771 Compiler_Error($"cannot add two pointers\n");
7773 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7774 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7776 if(exp.op.op == ADD_ASSIGN)
7777 Compiler_Error($"cannot add two pointers\n");
7781 char type1String[1024];
7782 char type2String[1024];
7783 type1String[0] = '\0';
7784 type2String[0] = '\0';
7786 PrintType(exp.op.exp2.expType, type1String, false, true);
7787 PrintType(type1, type2String, false, true);
7788 ChangeCh(expString, '\n', ' ');
7789 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7793 if(exp.op.exp2.destType == dummy)
7796 exp.op.exp2.destType = null;
7799 type2 = exp.op.exp2.expType;
7802 dummy.kind = voidType;
7804 if(exp.op.op == SIZEOF)
7811 exp.isConstant = true;
7813 // Get type of dereferenced pointer
7814 else if(exp.op.op == '*' && !exp.op.exp1)
7816 exp.expType = Dereference(type2);
7817 if(type2 && type2.kind == classType)
7818 notByReference = true;
7820 else if(exp.op.op == '&' && !exp.op.exp1)
7821 exp.expType = Reference(type2);
7828 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7829 exp.op.exp1.destType = MkClassType("bool");
7830 exp.op.exp1.destType.truth = true;
7831 if(!exp.op.exp1.expType)
7832 ProcessExpressionType(exp.op.exp1);
7834 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7835 FreeType(exp.op.exp1.expType);
7836 exp.op.exp1.expType = MkClassType("bool");
7837 exp.op.exp1.expType.truth = true;
7841 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7842 exp.op.exp2.destType = MkClassType("bool");
7843 exp.op.exp2.destType.truth = true;
7844 if(!exp.op.exp2.expType)
7845 ProcessExpressionType(exp.op.exp2);
7847 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7848 FreeType(exp.op.exp2.expType);
7849 exp.op.exp2.expType = MkClassType("bool");
7850 exp.op.exp2.expType.truth = true;
7853 else if(exp.op.exp1 && exp.op.exp2 &&
7856 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7857 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7858 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7859 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7861 if(type1 && type2 &&
7862 // If either both are class or both are not class
7863 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7865 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7866 exp.op.exp2.destType = type1;
7868 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7869 exp.op.exp1.destType = type2;
7871 // Warning here for adding Radians + Degrees with no destination type
7872 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7873 type1._class.registered && type1._class.registered.type == unitClass &&
7874 type2._class.registered && type2._class.registered.type == unitClass &&
7875 type1._class.registered != type2._class.registered)
7876 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7877 type1._class.string, type2._class.string, type1._class.string);
7879 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7881 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7884 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7886 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7887 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7890 ProcessExpressionType(exp.op.exp1);
7892 if(type2.kind != pointerType)
7894 ProcessExpressionType(classExp);
7896 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
7897 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7898 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7900 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
7903 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
7904 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7905 MkPointer(null, null), null)))),
7906 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
7908 if(!exp.op.exp2.expType)
7909 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
7911 ProcessExpressionType(exp.op.exp2);
7916 if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
7918 if(type1.kind != classType && type1.type.kind == voidType)
7919 Compiler_Error($"void *: unknown size\n");
7920 exp.expType = type1;
7921 if(type1) type1.refCount++;
7923 else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
7925 if(type2.kind != classType && type2.type.kind == voidType)
7926 Compiler_Error($"void *: unknown size\n");
7927 exp.expType = type2;
7928 if(type2) type2.refCount++;
7930 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
7931 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
7933 Compiler_Warning($"different levels of indirection\n");
7937 bool success = false;
7938 if(type1.kind == pointerType && type2.kind == pointerType)
7940 if(exp.op.op == '+')
7941 Compiler_Error($"cannot add two pointers\n");
7942 else if(exp.op.op == '-')
7944 // Pointer Subtraction gives integer
7945 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
7954 if(type1.type.kind == templateType)
7956 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7959 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7961 ProcessExpressionType(classExp);
7963 exp.type = bracketsExp;
7964 exp.list = MkListOne(MkExpOp(
7965 MkExpBrackets(MkListOne(MkExpOp(
7966 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
7968 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
7970 //MkExpMember(classExp, MkIdentifier("typeSize"))
7972 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7973 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7975 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
7978 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
7979 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7980 MkPointer(null, null), null)))),
7981 MkExpMember(classExp, MkIdentifier("typeSize")))))
7986 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
7995 if(!success && exp.op.exp1.type == constantExp)
7997 // If first expression is constant, try to match that first
7998 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8000 if(exp.expType) FreeType(exp.expType);
8001 exp.expType = exp.op.exp1.destType;
8002 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8005 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8007 if(exp.expType) FreeType(exp.expType);
8008 exp.expType = exp.op.exp2.destType;
8009 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8015 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8017 if(exp.expType) FreeType(exp.expType);
8018 exp.expType = exp.op.exp2.destType;
8019 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8022 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8024 if(exp.expType) FreeType(exp.expType);
8025 exp.expType = exp.op.exp1.destType;
8026 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8032 char expString1[10240];
8033 char expString2[10240];
8036 expString1[0] = '\0';
8037 expString2[0] = '\0';
8042 PrintExpression(exp.op.exp1, expString1);
8043 ChangeCh(expString1, '\n', ' ');
8044 PrintExpression(exp.op.exp2, expString2);
8045 ChangeCh(expString2, '\n', ' ');
8046 PrintType(exp.op.exp1.expType, type1, false, true);
8047 PrintType(exp.op.exp2.expType, type2, false, true);
8050 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8054 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8055 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8057 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8058 // Convert e.g. / 4 into / 4.0
8059 exp.op.exp1.destType = type2._class.registered.dataType;
8060 if(type2._class.registered.dataType)
8061 type2._class.registered.dataType.refCount++;
8062 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8063 exp.expType = type2;
8064 if(type2) type2.refCount++;
8066 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8068 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8069 // Convert e.g. / 4 into / 4.0
8070 exp.op.exp2.destType = type1._class.registered.dataType;
8071 if(type1._class.registered.dataType)
8072 type1._class.registered.dataType.refCount++;
8073 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8074 exp.expType = type1;
8075 if(type1) type1.refCount++;
8081 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8083 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8085 if(!type1._class.registered.dataType)
8086 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8087 exp.op.exp2.destType = type1._class.registered.dataType;
8088 exp.op.exp2.destType.refCount++;
8090 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8091 type2 = exp.op.exp2.destType;
8093 exp.expType = type2;
8097 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8099 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8101 if(!type2._class.registered.dataType)
8102 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8103 exp.op.exp1.destType = type2._class.registered.dataType;
8104 exp.op.exp1.destType.refCount++;
8106 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8107 type1 = exp.op.exp1.destType;
8108 exp.expType = type1;
8112 // TESTING THIS NEW CODE
8113 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8115 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8117 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8119 if(exp.expType) FreeType(exp.expType);
8120 exp.expType = exp.op.exp1.expType;
8121 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8126 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8128 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8130 if(exp.expType) FreeType(exp.expType);
8131 exp.expType = exp.op.exp2.expType;
8132 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8140 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8141 exp.op.exp2.destType = type1;
8145 // Maybe this was meant to be an enum...
8146 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8148 Type oldType = exp.op.exp2.expType;
8149 exp.op.exp2.expType = null;
8150 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8153 exp.op.exp2.expType = oldType;
8158 // TESTING THIS HERE... LATEST ADDITION
8159 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8161 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8162 exp.op.exp2.destType = type2._class.registered.dataType;
8163 if(type2._class.registered.dataType)
8164 type2._class.registered.dataType.refCount++;
8165 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8167 //exp.expType = type2._class.registered.dataType; //type2;
8168 //if(type2) type2.refCount++;
8171 // TESTING THIS HERE... LATEST ADDITION
8172 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8174 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8175 exp.op.exp1.destType = type1._class.registered.dataType;
8176 if(type1._class.registered.dataType)
8177 type1._class.registered.dataType.refCount++;
8178 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8179 exp.expType = type1._class.registered.dataType; //type1;
8180 if(type1) type1.refCount++;
8184 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8186 if(exp.expType) FreeType(exp.expType);
8187 exp.expType = exp.op.exp2.destType;
8188 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8190 else if(type1 && type2)
8192 char expString1[10240];
8193 char expString2[10240];
8194 char type1String[1024];
8195 char type2String[1024];
8196 expString1[0] = '\0';
8197 expString2[0] = '\0';
8198 type1String[0] = '\0';
8199 type2String[0] = '\0';
8202 PrintExpression(exp.op.exp1, expString1);
8203 ChangeCh(expString1, '\n', ' ');
8204 PrintExpression(exp.op.exp2, expString2);
8205 ChangeCh(expString2, '\n', ' ');
8206 PrintType(exp.op.exp1.expType, type1String, false, true);
8207 PrintType(exp.op.exp2.expType, type2String, false, true);
8210 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8212 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8214 exp.expType = exp.op.exp1.expType;
8215 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8217 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8219 exp.expType = exp.op.exp2.expType;
8220 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8227 // Maybe this was meant to be an enum...
8228 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8230 Type oldType = exp.op.exp1.expType;
8231 exp.op.exp1.expType = null;
8232 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8235 exp.op.exp1.expType = oldType;
8238 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8239 exp.op.exp1.destType = type2;
8242 // TESTING THIS HERE... LATEST ADDITION
8243 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8245 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8246 exp.op.exp1.destType = type1._class.registered.dataType;
8247 if(type1._class.registered.dataType)
8248 type1._class.registered.dataType.refCount++;
8251 // TESTING THIS HERE... LATEST ADDITION
8252 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8254 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8255 exp.op.exp2.destType = type2._class.registered.dataType;
8256 if(type2._class.registered.dataType)
8257 type2._class.registered.dataType.refCount++;
8261 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8263 if(exp.expType) FreeType(exp.expType);
8264 exp.expType = exp.op.exp1.destType;
8265 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8269 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8271 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8273 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8274 // Convert e.g. / 4 into / 4.0
8275 exp.op.exp1.destType = type2._class.registered.dataType;
8276 if(type2._class.registered.dataType)
8277 type2._class.registered.dataType.refCount++;
8278 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8280 if(exp.op.op == '!')
8282 exp.expType = MkClassType("bool");
8283 exp.expType.truth = true;
8287 exp.expType = type2;
8288 if(type2) type2.refCount++;
8291 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8293 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8295 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8296 // Convert e.g. / 4 into / 4.0
8297 exp.op.exp2.destType = type1._class.registered.dataType;
8298 if(type1._class.registered.dataType)
8299 type1._class.registered.dataType.refCount++;
8300 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8302 exp.expType = type1;
8303 if(type1) type1.refCount++;
8308 if(exp.op.exp1 && !exp.op.exp1.expType)
8310 char expString[10000];
8311 expString[0] = '\0';
8314 PrintExpression(exp.op.exp1, expString);
8315 ChangeCh(expString, '\n', ' ');
8318 Compiler_Error($"couldn't determine type of %s\n", expString);
8320 if(exp.op.exp2 && !exp.op.exp2.expType)
8322 char expString[10240];
8323 expString[0] = '\0';
8326 PrintExpression(exp.op.exp2, expString);
8327 ChangeCh(expString, '\n', ' ');
8330 Compiler_Error($"couldn't determine type of %s\n", expString);
8335 FreeType(exp.expType);
8336 exp.expType = MkClassType("bool");
8337 exp.expType.truth = true;
8340 if(exp.op.op != SIZEOF)
8341 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8342 (!exp.op.exp2 || exp.op.exp2.isConstant);
8344 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8346 DeclareType(exp.op.exp2.expType, false, false);
8355 case extensionExpressionExp:
8358 exp.isConstant = true;
8359 for(e = exp.list->first; e; e = e.next)
8364 FreeType(e.destType);
8365 e.destType = exp.destType;
8366 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8368 ProcessExpressionType(e);
8370 exp.destType.count--;
8371 if(!exp.expType && !e.next)
8373 exp.expType = e.expType;
8374 if(e.expType) e.expType.refCount++;
8377 exp.isConstant = false;
8380 // In case a cast became a member...
8381 e = exp.list->first;
8382 if(!e.next && e.type == memberExp)
8384 // Preserve prev, next
8385 Expression next = exp.next, prev = exp.prev;
8388 FreeType(exp.expType);
8389 FreeType(exp.destType);
8399 ProcessExpressionType(exp);
8406 exp.isConstant = true;
8408 ProcessExpressionType(exp.index.exp);
8409 if(!exp.index.exp.isConstant)
8410 exp.isConstant = false;
8412 if(exp.index.exp.expType)
8414 Type source = exp.index.exp.expType;
8415 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8416 eClass_IsDerived(source._class.registered, containerClass) &&
8417 source._class.registered.templateArgs)
8419 Class _class = source._class.registered;
8420 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8422 if(exp.index.index && exp.index.index->last)
8424 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8429 for(e = exp.index.index->first; e; e = e.next)
8431 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8433 if(e.destType) FreeType(e.destType);
8434 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8436 ProcessExpressionType(e);
8439 // Check if this type is int
8442 exp.isConstant = false;
8446 exp.expType = Dereference(exp.index.exp.expType);
8448 DeclareType(exp.expType, false, false);
8455 Type methodType = null;
8461 PrintExpression(exp.call.exp, name);
8462 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8464 //exp.call.exp.expType = null;
8465 PrintExpression(exp.call.exp, name);
8468 if(exp.call.exp.type == identifierExp)
8470 Expression idExp = exp.call.exp;
8471 Identifier id = idExp.identifier;
8472 if(!strcmp(id.string, "__ENDIAN_PAD"))
8474 exp.expType = ProcessTypeString("int", true);
8475 if(exp.call.arguments && exp.call.arguments->first)
8476 ProcessExpressionType(exp.call.arguments->first);
8479 else if(!strcmp(id.string, "Max") ||
8480 !strcmp(id.string, "Min") ||
8481 !strcmp(id.string, "Sgn") ||
8482 !strcmp(id.string, "Abs"))
8484 Expression a = null;
8485 Expression b = null;
8486 Expression tempExp1 = null, tempExp2 = null;
8487 if((!strcmp(id.string, "Max") ||
8488 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8490 a = exp.call.arguments->first;
8491 b = exp.call.arguments->last;
8495 else if(exp.call.arguments->count == 1)
8497 a = exp.call.arguments->first;
8503 exp.call.arguments->Clear();
8504 idExp.identifier = null;
8506 FreeExpContents(exp);
8508 ProcessExpressionType(a);
8510 ProcessExpressionType(b);
8512 exp.type = bracketsExp;
8513 exp.list = MkList();
8515 if(a.expType && (!b || b.expType))
8517 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8519 // Use the simpleStruct name/ids for now...
8522 OldList * specs = MkList();
8523 OldList * decls = MkList();
8525 char temp1[1024], temp2[1024];
8527 GetTypeSpecs(a.expType, specs);
8529 if(a && !a.isConstant && a.type != identifierExp)
8531 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8532 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8533 tempExp1 = QMkExpId(temp1);
8534 tempExp1.expType = a.expType;
8536 a.expType.refCount++;
8537 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8539 if(b && !b.isConstant && b.type != identifierExp)
8541 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8542 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8543 tempExp2 = QMkExpId(temp2);
8544 tempExp2.expType = b.expType;
8546 b.expType.refCount++;
8547 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8550 decl = MkDeclaration(specs, decls);
8551 if(!curCompound.compound.declarations)
8552 curCompound.compound.declarations = MkList();
8553 curCompound.compound.declarations->Insert(null, decl);
8558 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8560 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8562 MkExpCondition(MkExpBrackets(MkListOne(
8563 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8564 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8565 exp.expType = a.expType;
8567 a.expType.refCount++;
8569 else if(!strcmp(id.string, "Abs"))
8572 MkExpCondition(MkExpBrackets(MkListOne(
8573 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8574 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8575 exp.expType = a.expType;
8577 a.expType.refCount++;
8579 else if(!strcmp(id.string, "Sgn"))
8581 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8583 MkExpCondition(MkExpBrackets(MkListOne(
8584 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8585 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8586 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8587 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8588 exp.expType = ProcessTypeString("int", false);
8591 FreeExpression(tempExp1);
8592 if(tempExp2) FreeExpression(tempExp2);
8606 if(!exp.call.exp.destType)
8608 exp.call.exp.destType = dummy;
8611 ProcessExpressionType(exp.call.exp);
8612 if(exp.call.exp.destType == dummy)
8615 exp.call.exp.destType = null;
8620 // Check argument types against parameter types
8621 functionType = exp.call.exp.expType;
8623 if(functionType && functionType.kind == TypeKind::methodType)
8625 methodType = functionType;
8626 functionType = methodType.method.dataType;
8628 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8629 // TOCHECK: Instead of doing this here could this be done per param?
8630 if(exp.call.exp.expType.usedClass)
8632 char typeString[1024];
8633 typeString[0] = '\0';
8634 PrintType(functionType, typeString, true, true);
8635 if(strstr(typeString, "thisclass"))
8637 OldList * specs = MkList();
8640 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8642 decl = SpecDeclFromString(typeString, specs, null);
8644 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8645 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8646 exp.call.exp.expType.usedClass))
8647 thisClassParams = false;
8649 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8651 Class backupThisClass = thisClass;
8652 thisClass = exp.call.exp.expType.usedClass;
8653 ProcessDeclarator(decl);
8654 thisClass = backupThisClass;
8657 thisClassParams = true;
8659 functionType = ProcessType(specs, decl);
8660 functionType.refCount = 0;
8661 FinishTemplatesContext(context);
8664 FreeList(specs, FreeSpecifier);
8665 FreeDeclarator(decl);
8669 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8671 Type type = functionType.type;
8672 if(!functionType.refCount)
8674 functionType.type = null;
8675 FreeType(functionType);
8677 //methodType = functionType;
8678 functionType = type;
8680 if(functionType && functionType.kind != TypeKind::functionType)
8682 Compiler_Error($"called object %s is not a function\n", name);
8684 else if(functionType)
8686 bool emptyParams = false, noParams = false;
8687 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8688 Type type = functionType.params.first;
8689 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8691 Location oldyylloc = yylloc;
8693 if(!type) emptyParams = true;
8696 if(functionType.extraParam && e)
8698 e.destType = MkClassType(functionType.thisClass.string);
8702 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8703 if(!functionType.staticMethod)
8705 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8706 memberExp.member.exp.expType._class)
8708 type = MkClassType(memberExp.member.exp.expType._class.string);
8713 type = functionType.params.first;
8718 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8720 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8725 type = functionType.params.first;
8733 if(type && type.kind == voidType)
8736 if(!type.refCount) FreeType(type);
8740 for( ; e; e = e.next)
8742 if(!type && !emptyParams)
8745 if(methodType && methodType.methodClass)
8746 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8747 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8748 noParams ? 0 : functionType.params.count);
8750 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8751 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8752 noParams ? 0 : functionType.params.count);
8756 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8758 Type templatedType = null;
8759 Class _class = methodType.usedClass;
8760 ClassTemplateParameter curParam = null;
8762 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8765 for(sClass = _class; sClass; sClass = sClass.base)
8767 if(sClass.templateClass) sClass = sClass.templateClass;
8769 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8771 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8774 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8776 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8777 id += nextClass.templateParams.count;
8786 if(curParam && _class.templateArgs[id].dataTypeString)
8788 ClassTemplateArgument arg = _class.templateArgs[id];
8790 Context context = SetupTemplatesContext(_class);
8793 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8794 templatedType = ProcessTypeString(arg.dataTypeString, false);
8795 FinishTemplatesContext(context);
8797 e.destType = templatedType;
8800 templatedType.passAsTemplate = true;
8801 // templatedType.refCount++;
8807 if(type) type.refCount++;
8813 if(type) type.refCount++;
8815 // Don't reach the end for the ellipsis
8816 if(type && type.kind != ellipsisType)
8818 Type next = type.next;
8819 if(!type.refCount) FreeType(type);
8824 if(type && type.kind != ellipsisType)
8826 if(methodType && methodType.methodClass)
8827 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8828 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8829 functionType.params.count + extra);
8831 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8832 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8833 functionType.params.count + extra);
8836 if(type && !type.refCount) FreeType(type);
8843 kind = TypeKind::functionType;
8846 if(exp.call.exp.type == identifierExp)
8848 char * string = exp.call.exp.identifier.string;
8852 Location oldyylloc = yylloc;
8854 yylloc = exp.call.exp.identifier.loc;
8855 if(strstr(string, "__builtin_") == string);
8857 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8858 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8859 globalContext.symbols.Add((BTNode)symbol);
8860 if(strstr(symbol.string, "::"))
8861 globalContext.hasNameSpace = true;
8866 else if(exp.call.exp.type == memberExp)
8868 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8869 exp.call.exp.member.member.string);*/
8872 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8874 if(!functionType.returnType)
8876 functionType.returnType = Type
8883 if(functionType && functionType.kind == TypeKind::functionType)
8885 exp.expType = functionType.returnType;
8887 if(functionType.returnType)
8888 functionType.returnType.refCount++;
8890 if(!functionType.refCount)
8891 FreeType(functionType);
8894 if(exp.call.arguments)
8896 for(e = exp.call.arguments->first; e; e = e.next)
8898 Type destType = e.destType;
8899 ProcessExpressionType(e);
8907 Location oldyylloc = yylloc;
8908 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
8909 exp.thisPtr = thisPtr;
8911 // DOING THIS LATER NOW...
8912 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
8914 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
8915 /* TODO: Name Space Fix ups
8916 if(!exp.member.member.classSym)
8917 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
8921 ProcessExpressionType(exp.member.exp);
8922 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
8923 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
8925 exp.isConstant = false;
8928 exp.isConstant = exp.member.exp.isConstant;
8929 type = exp.member.exp.expType;
8933 if(type && (type.kind == templateType))
8935 Class _class = thisClass ? thisClass : currentClass;
8936 ClassTemplateParameter param = null;
8939 for(param = _class.templateParams.first; param; param = param.next)
8941 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
8945 if(param && param.defaultArg.member)
8947 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
8950 Expression expMember = exp.member.exp;
8952 OldList * specs = MkList();
8953 char thisClassTypeString[1024];
8955 FreeIdentifier(exp.member.member);
8957 ProcessExpressionType(argExp);
8960 char * colon = strstr(param.defaultArg.memberString, "::");
8963 char className[1024];
8966 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
8967 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
8970 strcpy(thisClassTypeString, _class.fullName);
8973 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
8975 exp.expType = ProcessType(specs, decl);
8976 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
8978 Class expClass = exp.expType._class.registered;
8979 Class cClass = null;
8984 char templateString[1024];
8985 ClassTemplateParameter param;
8986 sprintf(templateString, "%s<", expClass.templateClass.fullName);
8987 for(cClass = expClass; cClass; cClass = cClass.base)
8990 for(param = cClass.templateParams.first; param; param = param.next)
8994 ClassTemplateArgument arg;
8995 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
8996 arg = expClass.templateArgs[id];
8998 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9000 ClassTemplateParameter cParam;
9001 //int p = numParams - sClass.templateParams.count;
9004 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9006 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9008 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9010 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9012 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9013 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9025 strcat(argument, arg.name.string);
9026 strcat(argument, " = ");
9032 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9033 char expString[1024];
9034 OldList * specs = MkList();
9035 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9037 char * string = PrintHexUInt64(arg.expression.ui64);
9038 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9040 ProcessExpressionType(exp);
9041 ComputeExpression(exp);
9042 expString[0] = '\0';
9043 PrintExpression(exp, expString);
9044 strcat(argument, expString);
9046 FreeExpression(exp);
9051 strcat(argument, arg.member.name);
9054 case TemplateParameterType::type:
9056 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9058 if(!strcmp(arg.dataTypeString, "thisclass"))
9059 strcat(argument, thisClassTypeString);
9061 strcat(argument, arg.dataTypeString);
9068 if(paramCount) strcat(templateString, ", ");
9069 if(lastParam != p - 1)
9071 strcat(templateString, param.name);
9072 strcat(templateString, " = ");
9074 strcat(templateString, argument);
9083 int len = strlen(templateString);
9084 if(templateString[len-1] == '>') templateString[len++] = ' ';
9085 templateString[len++] = '>';
9086 templateString[len++] = '\0';
9089 Context context = SetupTemplatesContext(_class);
9090 FreeType(exp.expType);
9091 exp.expType = ProcessTypeString(templateString, false);
9092 FinishTemplatesContext(context);
9096 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9097 exp.type = bracketsExp;
9098 exp.list = MkListOne(MkExpOp(null, '*',
9103 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9104 MkExpBrackets(MkListOne(
9105 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9107 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9109 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9114 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9115 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9117 type = ProcessTemplateParameterType(type.templateParameter);
9121 if(type && (type.kind == templateType));
9122 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9124 Identifier id = exp.member.member;
9125 TypeKind typeKind = type.kind;
9126 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9127 if(typeKind == subClassType && exp.member.exp.type == classExp)
9129 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9130 typeKind = classType;
9133 if(id && (typeKind == intType || typeKind == enumType))
9134 _class = eSystem_FindClass(privateModule, "int");
9139 (exp.member.exp.type == identifierExp &&
9140 !strcmp(exp.member.exp.identifier.string, "this"));*/
9141 Property prop = null;
9142 Method method = null;
9143 DataMember member = null;
9144 Property revConvert = null;
9145 ClassProperty classProp = null;
9147 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9148 exp.member.memberType = propertyMember;
9150 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9151 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9153 if(typeKind != subClassType)
9155 // Prioritize data members over properties for "this"
9156 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9158 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9159 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9161 prop = eClass_FindProperty(_class, id.string, privateModule);
9165 if(!member && !prop)
9166 prop = eClass_FindProperty(_class, id.string, privateModule);
9167 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9168 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9169 exp.member.thisPtr = true;
9171 // Prioritize properties over data members otherwise
9174 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9177 prop = eClass_FindProperty(_class, id.string, null);
9178 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9179 member = eClass_FindDataMember(_class, id.string, null, null, null);
9182 if(!prop && !member)
9184 method = eClass_FindMethod(_class, id.string, null);
9187 prop = eClass_FindProperty(_class, id.string, privateModule);
9188 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9189 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9195 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9202 if(!prop && !member)
9203 method = eClass_FindMethod(_class, id.string, privateModule);
9204 if(!prop && !member && !method)
9206 if(typeKind == subClassType)
9208 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9211 exp.member.memberType = classPropertyMember;
9212 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9216 // Assume this is a class_data member
9217 char structName[1024];
9218 Identifier id = exp.member.member;
9219 Expression classExp = exp.member.exp;
9222 FreeType(classExp.expType);
9223 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9225 strcpy(structName, "__ecereClassData_");
9226 FullClassNameCat(structName, type._class.string, false);
9227 exp.type = pointerExp;
9228 exp.member.member = id;
9230 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9231 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9232 MkExpBrackets(MkListOne(MkExpOp(
9233 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9234 MkExpMember(classExp, MkIdentifier("data"))), '+',
9235 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9240 ProcessExpressionType(exp);
9246 // Check for reverse conversion
9247 // (Convert in an instantiation later, so that we can use
9248 // deep properties system)
9249 Symbol classSym = FindClass(id.string);
9252 Class convertClass = classSym.registered;
9254 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9261 exp.member.memberType = propertyMember;
9263 ProcessPropertyType(prop);
9264 exp.expType = prop.dataType;
9265 if(prop.dataType) prop.dataType.refCount++;
9269 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9271 FreeExpContents(exp);
9272 exp.type = identifierExp;
9273 exp.identifier = MkIdentifier("class");
9274 ProcessExpressionType(exp);
9278 exp.member.memberType = dataMember;
9279 DeclareStruct(_class.fullName, false);
9280 if(!member.dataType)
9282 Context context = SetupTemplatesContext(_class);
9283 member.dataType = ProcessTypeString(member.dataTypeString, false);
9284 FinishTemplatesContext(context);
9286 exp.expType = member.dataType;
9287 if(member.dataType) member.dataType.refCount++;
9291 exp.member.memberType = reverseConversionMember;
9292 exp.expType = MkClassType(revConvert._class.fullName);
9300 exp.type = identifierExp;
9301 exp.identifier = exp.member.member;
9304 exp.member.memberType = methodMember;
9306 if(!method.dataType)
9307 ProcessMethodType(method);
9315 // Tricky spot here... To use instance versus class virtual table
9316 // Put it back to what it was... What did we break?
9318 // Had to put it back for overriding Main of Thread global instance
9320 //exp.expType.methodClass = _class;
9321 exp.expType.methodClass = (id && id._class) ? _class : null;
9323 // Need the actual class used for templated classes
9324 exp.expType.usedClass = _class;
9328 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9330 FreeExpContents(exp);
9331 exp.type = identifierExp;
9332 exp.identifier = MkIdentifier("class");
9333 ProcessExpressionType(exp);
9336 yylloc = exp.member.member.loc;
9337 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9339 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9342 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9347 while(tClass && !tClass.templateClass) tClass = tClass.base;
9349 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9352 ClassTemplateParameter curParam = null;
9355 for(sClass = tClass; sClass; sClass = sClass.base)
9358 if(sClass.templateClass) sClass = sClass.templateClass;
9359 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9361 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9363 for(sClass = sClass.base; sClass; sClass = sClass.base)
9364 id += sClass.templateParams.count;
9372 if(curParam && tClass.templateArgs[id].dataTypeString)
9374 ClassTemplateArgument arg = tClass.templateArgs[id];
9375 Context context = SetupTemplatesContext(tClass);
9377 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9378 FreeType(exp.expType);
9379 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9382 if(exp.expType.kind == thisClassType)
9384 FreeType(exp.expType);
9385 exp.expType = ReplaceThisClassType(_class);
9388 if(tClass.templateClass)
9389 exp.expType.passAsTemplate = true;
9390 //exp.expType.refCount++;
9393 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9394 //exp.destType.refCount++;
9396 if(exp.destType.kind == thisClassType)
9398 FreeType(exp.destType);
9399 exp.destType = ReplaceThisClassType(_class);
9403 FinishTemplatesContext(context);
9406 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9407 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9410 ClassTemplateParameter curParam = null;
9413 for(sClass = tClass; sClass; sClass = sClass.base)
9416 if(sClass.templateClass) sClass = sClass.templateClass;
9417 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9419 if(curParam.type == TemplateParameterType::type &&
9420 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9422 for(sClass = sClass.base; sClass; sClass = sClass.base)
9423 id += sClass.templateParams.count;
9433 ClassTemplateArgument arg = tClass.templateArgs[id];
9434 Context context = SetupTemplatesContext(tClass);
9437 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9439 basicType = ProcessTypeString(arg.dataTypeString, false);
9442 if(basicType.kind == thisClassType)
9444 FreeType(basicType);
9445 basicType = ReplaceThisClassType(_class);
9448 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9449 if(tClass.templateClass)
9450 basicType.passAsTemplate = true;
9453 FreeType(exp.expType);
9455 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9456 //exp.expType.refCount++;
9459 exp.destType = exp.expType;
9460 exp.destType.refCount++;
9464 Expression newExp { };
9465 OldList * specs = MkList();
9467 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9469 if(exp.destType) exp.destType.refCount++;
9470 if(exp.expType) exp.expType.refCount++;
9472 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9473 exp.cast.exp = newExp;
9474 //FreeType(exp.expType);
9475 //exp.expType = null;
9476 //ProcessExpressionType(sourceExp);
9479 FinishTemplatesContext(context);
9482 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9484 Class expClass = exp.expType._class.registered;
9487 Class cClass = null;
9492 char templateString[1024];
9493 ClassTemplateParameter param;
9494 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9495 while(cClass != expClass)
9498 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9501 for(param = cClass.templateParams.first; param; param = param.next)
9503 Class cClassCur = null;
9506 ClassTemplateParameter paramCur = null;
9507 ClassTemplateArgument arg;
9508 while(cClassCur != tClass && !paramCur)
9511 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9512 cClassCur = sClassCur;
9514 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9516 if(!strcmp(paramCur.name, param.name))
9524 if(paramCur && paramCur.type == TemplateParameterType::type)
9525 arg = tClass.templateArgs[cp];
9527 arg = expClass.templateArgs[p];
9534 strcat(argument, arg.name.string);
9535 strcat(argument, " = ");
9541 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9542 char expString[1024];
9543 OldList * specs = MkList();
9544 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9546 char * string = PrintHexUInt64(arg.expression.ui64);
9547 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9549 ProcessExpressionType(exp);
9550 ComputeExpression(exp);
9551 expString[0] = '\0';
9552 PrintExpression(exp, expString);
9553 strcat(argument, expString);
9555 FreeExpression(exp);
9560 strcat(argument, arg.member.name);
9563 case TemplateParameterType::type:
9565 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9566 strcat(argument, arg.dataTypeString);
9572 if(paramCount) strcat(templateString, ", ");
9573 if(lastParam != p - 1)
9575 strcat(templateString, param.name);
9576 strcat(templateString, " = ");
9578 strcat(templateString, argument);
9587 int len = strlen(templateString);
9588 if(templateString[len-1] == '>') templateString[len++] = ' ';
9589 templateString[len++] = '>';
9590 templateString[len++] = '\0';
9593 FreeType(exp.expType);
9595 Context context = SetupTemplatesContext(tClass);
9596 exp.expType = ProcessTypeString(templateString, false);
9597 FinishTemplatesContext(context);
9604 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9606 else if(type && (type.kind == structType || type.kind == unionType))
9608 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9611 exp.expType = memberType;
9613 memberType.refCount++;
9618 char expString[10240];
9619 expString[0] = '\0';
9620 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9621 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9624 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9626 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9628 Identifier id = exp.member.member;
9629 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9632 FreeType(exp.expType);
9633 exp.expType = ReplaceThisClassType(_class);
9640 // Convert x->y into (*x).y
9643 Type destType = exp.destType;
9645 // DOING THIS LATER NOW...
9646 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9648 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9649 /* TODO: Name Space Fix ups
9650 if(!exp.member.member.classSym)
9651 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9655 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9656 exp.type = memberExp;
9659 ProcessExpressionType(exp);
9666 //ComputeExpression(exp);
9668 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9669 if(classSym && classSym.registered)
9671 if(classSym.registered.type == noHeadClass)
9675 DeclareStruct(classSym.string, false);
9676 FreeSpecifier(exp._class);
9677 exp.type = typeSizeExp;
9678 FullClassNameCat(name, classSym.string, false);
9679 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9683 if(classSym.registered.fixed)
9685 FreeSpecifier(exp._class);
9686 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9687 exp.type = constantExp;
9691 char className[1024];
9692 strcpy(className, "__ecereClass_");
9693 FullClassNameCat(className, classSym.string, true);
9694 MangleClassName(className);
9696 DeclareClass(classSym, className);
9698 FreeExpContents(exp);
9699 exp.type = pointerExp;
9700 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9701 exp.member.member = MkIdentifier("structSize");
9711 // exp.isConstant = true;
9716 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9723 exp.isConstant = true;
9725 DeclareType(type, false, false);
9731 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9733 FreeType(exp.cast.exp.destType);
9734 exp.cast.exp.destType = type;
9736 ProcessExpressionType(exp.cast.exp);
9741 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9742 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9744 void * prev = exp.prev, * next = exp.next;
9745 Type expType = exp.cast.exp.destType;
9746 Expression castExp = exp.cast.exp;
9747 Type destType = exp.destType;
9749 if(expType) expType.refCount++;
9751 //FreeType(exp.destType);
9752 FreeType(exp.expType);
9753 FreeTypeName(exp.cast.typeName);
9756 FreeType(exp.expType);
9757 FreeType(exp.destType);
9759 exp.expType = expType;
9760 exp.destType = destType;
9770 exp.isConstant = exp.cast.exp.isConstant;
9775 case extensionInitializerExp:
9777 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9780 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9781 // ProcessInitializer(exp.initializer.initializer, type);
9787 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9788 ProcessExpressionType(exp.vaArg.exp);
9796 exp.isConstant = true;
9798 FreeType(exp.cond.cond.destType);
9799 exp.cond.cond.destType = MkClassType("bool");
9800 exp.cond.cond.destType.truth = true;
9801 ProcessExpressionType(exp.cond.cond);
9802 if(!exp.cond.cond.isConstant)
9803 exp.isConstant = false;
9804 for(e = exp.cond.exp->first; e; e = e.next)
9808 FreeType(e.destType);
9809 e.destType = exp.destType;
9810 if(e.destType) e.destType.refCount++;
9812 ProcessExpressionType(e);
9815 exp.expType = e.expType;
9816 if(e.expType) e.expType.refCount++;
9819 exp.isConstant = false;
9822 FreeType(exp.cond.elseExp.destType);
9823 // Added this check if we failed to find an expType
9824 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9827 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9829 if(exp.cond.elseExp.destType)
9830 exp.cond.elseExp.destType.refCount++;
9831 ProcessExpressionType(exp.cond.elseExp);
9833 // FIXED THIS: Was done before calling process on elseExp
9834 if(!exp.cond.elseExp.isConstant)
9835 exp.isConstant = false;
9838 case extensionCompoundExp:
9840 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9842 Statement last = exp.compound.compound.statements->last;
9843 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9845 ((Expression)last.expressions->last).destType = exp.destType;
9847 exp.destType.refCount++;
9849 ProcessStatement(exp.compound);
9850 exp.expType = ((Expression)last.expressions->last).expType;
9851 if(((Expression)last.expressions->last).expType)
9852 exp.expType.refCount++;
9858 Specifier spec = exp._classExp.specifiers->first;
9859 if(spec && spec.type == nameSpecifier)
9861 exp.expType = MkClassType(spec.name);
9862 exp.expType.kind = subClassType;
9863 exp.byReference = true;
9867 exp.expType = MkClassType("ecere::com::Class");
9868 exp.byReference = true;
9874 Class _class = thisClass ? thisClass : currentClass;
9877 Identifier id = exp.classData.id;
9878 char structName[1024];
9879 Expression classExp;
9880 strcpy(structName, "__ecereClassData_");
9881 FullClassNameCat(structName, _class.fullName, false);
9882 exp.type = pointerExp;
9883 exp.member.member = id;
9884 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9885 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9887 classExp = MkExpIdentifier(MkIdentifier("class"));
9889 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9890 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9891 MkExpBrackets(MkListOne(MkExpOp(
9892 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9893 MkExpMember(classExp, MkIdentifier("data"))), '+',
9894 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
9897 ProcessExpressionType(exp);
9905 char * typeString = null;
9906 char typeStringBuf[1024];
9907 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
9908 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
9910 Class templateClass = exp.destType._class.registered;
9911 typeString = templateClass.templateArgs[2].dataTypeString;
9915 // Guess type from expressions in the array
9917 for(e = exp.list->first; e; e = e.next)
9919 ProcessExpressionType(e);
9922 if(!type) { type = e.expType; type.refCount++; }
9925 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
9926 if(!MatchTypeExpression(e, type, null, false))
9932 e = exp.list->first;
9933 ProcessExpressionType(e);
9936 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
9937 if(!MatchTypeExpression(e, type, null, false))
9939 FreeType(e.expType);
9950 FreeType(e.expType);
9957 typeStringBuf[0] = '\0';
9958 PrintType(type, typeStringBuf, false, true);
9959 typeString = typeStringBuf;
9967 (Container)& (struct BuiltInContainer)
9969 ._vTbl = class(BuiltInContainer)._vTbl,
9970 ._class = class(BuiltInContainer),
9972 .data = (int[]){ 1, 7, 3, 4, 5 },
9977 char templateString[1024];
9978 OldList * initializers = MkList();
9979 OldList * structInitializers = MkList();
9980 OldList * specs = MkList();
9982 Declarator decl = SpecDeclFromString(typeString, specs, null);
9983 sprintf(templateString, "Container<%s>", typeString);
9988 type = ProcessTypeString(typeString, false);
9989 while(e = exp.list->first)
9991 exp.list->Remove(e);
9994 ProcessExpressionType(e);
9995 ListAdd(initializers, MkInitializerAssignment(e));
10001 DeclareStruct("ecere::com::BuiltInContainer", false);
10003 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10004 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10005 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10006 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10007 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10008 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10009 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10010 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10011 MkInitializerList(initializers))));
10012 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10013 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10014 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10015 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10016 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10017 exp.expType = ProcessTypeString(templateString, false);
10018 exp.type = bracketsExp;
10019 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10021 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10022 MkInitializerList(structInitializers)))));
10023 ProcessExpressionType(expExt);
10027 exp.expType = ProcessTypeString("Container", false);
10028 Compiler_Error($"Couldn't determine type of array elements\n");
10034 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10036 FreeType(exp.expType);
10037 exp.expType = ReplaceThisClassType(thisClass);
10040 // Resolve structures here
10041 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10043 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10044 // TODO: Fix members reference...
10047 if(exp.expType.kind != enumType)
10050 String enumName = CopyString(exp.expType.enumName);
10052 // Fixed a memory leak on self-referencing C structs typedefs
10053 // by instantiating a new type rather than simply copying members
10054 // into exp.expType
10055 FreeType(exp.expType);
10056 exp.expType = Type { };
10057 exp.expType.kind = symbol.type.kind;
10058 exp.expType.refCount++;
10059 exp.expType.enumName = enumName;
10061 exp.expType.members = symbol.type.members;
10062 for(member = symbol.type.members.first; member; member = member.next)
10068 for(member = symbol.type.members.first; member; member = member.next)
10070 NamedLink value { name = CopyString(member.name) };
10071 exp.expType.members.Add(value);
10078 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10079 else if(exp.destType && !exp.destType.keepCast)
10081 if(!CheckExpressionType(exp, exp.destType, false))
10083 if(!exp.destType.count || unresolved)
10088 if(exp.destType.kind != ellipsisType)
10094 char expString[10240];
10095 expString[0] = '\0';
10097 PrintType(exp.destType, type2, false, true);
10099 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10101 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10102 else if(exp.type != dummyExp)
10103 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10108 char expString[10240] ;
10109 expString[0] = '\0';
10110 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10113 Compiler_Error($"unresolved identifier %s\n", expString);
10114 else if(exp.type != dummyExp)
10115 Compiler_Error($"couldn't determine type of %s\n", expString);
10126 PrintType(exp.expType, type1, false, true);
10127 PrintType(exp.destType, type2, false, true);
10130 //CheckExpressionType(exp, exp.destType, false);
10132 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10133 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10134 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10137 char expString[10240];
10138 expString[0] = '\0';
10139 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10142 CheckExpressionType(exp, exp.destType, false);
10144 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10145 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10146 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10148 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10149 FreeType(exp.expType);
10150 exp.destType.refCount++;
10151 exp.expType = exp.destType;
10156 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10158 Expression newExp { };
10159 char typeString[1024];
10160 OldList * specs = MkList();
10163 typeString[0] = '\0';
10167 if(exp.expType) exp.expType.refCount++;
10168 if(exp.expType) exp.expType.refCount++;
10169 exp.type = castExp;
10170 newExp.destType = exp.expType;
10172 PrintType(exp.expType, typeString, false, false);
10173 decl = SpecDeclFromString(typeString, specs, null);
10175 exp.cast.typeName = MkTypeName(specs, decl);
10176 exp.cast.exp = newExp;
10179 else if(unresolved)
10181 if(exp.identifier._class && exp.identifier._class.name)
10182 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10183 else if(exp.identifier.string && exp.identifier.string[0])
10184 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10186 else if(!exp.expType && exp.type != dummyExp)
10188 char expString[10240];
10189 expString[0] = '\0';
10190 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10191 Compiler_Error($"couldn't determine type of %s\n", expString);
10194 // Let's try to support any_object & typed_object here:
10195 ApplyAnyObjectLogic(exp);
10197 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10198 exp.expType._class.registered.type == noHeadClass)
10200 exp.byReference = true;
10202 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10203 exp.destType._class.registered.type == noHeadClass)
10205 exp.byReference = true;
10207 yylloc = oldyylloc;
10210 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10212 // THIS CODE WILL FIND NEXT MEMBER...
10215 *curMember = (*curMember).next;
10217 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10219 *curMember = subMemberStack[--(*subMemberStackPos)];
10220 *curMember = (*curMember).next;
10223 // SKIP ALL PROPERTIES HERE...
10224 while((*curMember) && (*curMember).isProperty)
10225 *curMember = (*curMember).next;
10227 if(subMemberStackPos)
10229 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10231 subMemberStack[(*subMemberStackPos)++] = *curMember;
10233 *curMember = (*curMember).members.first;
10234 while(*curMember && (*curMember).isProperty)
10235 *curMember = (*curMember).next;
10243 if(subMemberStackPos && *subMemberStackPos)
10245 *curMember = subMemberStack[--(*subMemberStackPos)];
10246 *curMember = (*curMember).next;
10250 Class lastCurClass = *curClass;
10252 if(*curClass == _class) break; // REACHED THE END
10254 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10255 *curMember = (*curClass).membersAndProperties.first;
10258 while((*curMember) && (*curMember).isProperty)
10259 *curMember = (*curMember).next;
10260 if(subMemberStackPos)
10262 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10264 subMemberStack[(*subMemberStackPos)++] = *curMember;
10266 *curMember = (*curMember).members.first;
10267 while(*curMember && (*curMember).isProperty)
10268 *curMember = (*curMember).next;
10276 static void ProcessInitializer(Initializer init, Type type)
10280 case expInitializer:
10281 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10283 // TESTING THIS FOR SHUTTING = 0 WARNING
10284 if(init.exp && !init.exp.destType)
10286 FreeType(init.exp.destType);
10287 init.exp.destType = type;
10288 if(type) type.refCount++;
10292 ProcessExpressionType(init.exp);
10293 init.isConstant = init.exp.isConstant;
10299 Expression exp = init.exp;
10300 Instantiation inst = exp.instance;
10301 MembersInit members;
10303 init.type = listInitializer;
10304 init.list = MkList();
10308 for(members = inst.members->first; members; members = members.next)
10310 if(members.type == dataMembersInit)
10313 for(member = members.dataMembers->first; member; member = member.next)
10315 ListAdd(init.list, member.initializer);
10316 member.initializer = null;
10319 // Discard all MembersInitMethod
10322 FreeExpression(exp);
10324 case listInitializer:
10327 Type initializerType = null;
10328 Class curClass = null;
10329 DataMember curMember = null;
10330 DataMember subMemberStack[256];
10331 int subMemberStackPos = 0;
10333 if(type && type.kind == arrayType)
10334 initializerType = Dereference(type);
10335 else if(type && (type.kind == structType || type.kind == unionType))
10336 initializerType = type.members.first;
10338 for(i = init.list->first; i; i = i.next)
10340 if(type && type.kind == classType && type._class && type._class.registered)
10342 // THIS IS FOR A C STYLE INSTANTIATION OF STRUCT CLASSES ONLY... WE ONLY CARE ABOUT DATA MEMBERS, AND ACTUAL MEMORY ORDER (PRIVATE MEMBERS ARE INCLUDED)
10343 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10344 // TODO: Generate error on initializing a private data member this way from another module...
10347 if(!curMember.dataType)
10348 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10349 initializerType = curMember.dataType;
10352 ProcessInitializer(i, initializerType);
10353 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10354 initializerType = initializerType.next;
10356 init.isConstant = false;
10359 if(type && type.kind == arrayType)
10360 FreeType(initializerType);
10362 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10364 Compiler_Error($"Assigning list initializer to non list\n");
10371 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10375 case baseSpecifier:
10377 if(spec.specifier == THISCLASS)
10381 spec.type = nameSpecifier;
10382 spec.name = ReplaceThisClass(thisClass);
10383 spec.symbol = FindClass(spec.name);
10384 ProcessSpecifier(spec, declareStruct);
10389 case nameSpecifier:
10391 Symbol symbol = FindType(curContext, spec.name);
10393 DeclareType(symbol.type, true, true);
10394 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10395 DeclareStruct(spec.name, false);
10398 case enumSpecifier:
10403 for(e = spec.list->first; e; e = e.next)
10406 ProcessExpressionType(e.exp);
10411 case structSpecifier:
10412 case unionSpecifier:
10414 if(spec.definitions)
10417 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10419 ProcessClass(spec.definitions, symbol);
10422 for(def = spec.definitions->first; def; def = def.next)
10424 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10425 ProcessDeclaration(def.decl);
10432 case classSpecifier:
10434 Symbol classSym = FindClass(spec.name);
10435 if(classSym && classSym.registered && classSym.registered.type == structClass)
10436 DeclareStruct(spec.name, false);
10444 static void ProcessDeclarator(Declarator decl)
10448 case identifierDeclarator:
10449 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10451 FreeSpecifier(decl.identifier._class);
10452 decl.identifier._class = null;
10455 case arrayDeclarator:
10457 ProcessExpressionType(decl.array.exp);
10458 case structDeclarator:
10459 case bracketsDeclarator:
10460 case functionDeclarator:
10461 case pointerDeclarator:
10462 case extendedDeclarator:
10463 case extendedDeclaratorEnd:
10464 if(decl.declarator)
10465 ProcessDeclarator(decl.declarator);
10466 if(decl.type == functionDeclarator)
10468 Identifier id = GetDeclId(decl);
10469 if(id && id._class)
10473 qualifiers = MkListOne(id._class);
10476 if(!decl.function.parameters)
10477 decl.function.parameters = MkList();
10478 decl.function.parameters->Insert(null, param);
10481 if(decl.function.parameters)
10485 for(param = decl.function.parameters->first; param; param = param.next)
10487 if(param.qualifiers && param.qualifiers->first)
10489 Specifier spec = param.qualifiers->first;
10490 if(spec && spec.specifier == TYPED_OBJECT)
10492 Declarator d = param.declarator;
10495 qualifiers = MkListOne(MkSpecifier(VOID));
10496 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10499 FreeList(param.qualifiers, FreeSpecifier);
10501 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10502 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10504 decl.function.parameters->Insert(param, newParam);
10507 else if(spec && spec.specifier == ANY_OBJECT)
10509 Declarator d = param.declarator;
10511 FreeList(param.qualifiers, FreeSpecifier);
10513 param.qualifiers = MkListOne(MkSpecifier(VOID));
10514 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10516 else if(spec.specifier == THISCLASS)
10520 spec.type = nameSpecifier;
10521 spec.name = ReplaceThisClass(thisClass);
10522 spec.symbol = FindClass(spec.name);
10523 ProcessSpecifier(spec, false);
10528 if(param.declarator)
10529 ProcessDeclarator(param.declarator);
10537 static void ProcessDeclaration(Declaration decl)
10542 case initDeclaration:
10544 bool declareStruct = false;
10546 lineNum = decl.pos.line;
10547 column = decl.pos.col;
10550 if(decl.declarators)
10554 for(d = decl.declarators->first; d; d = d.next)
10556 Type type, subType;
10557 ProcessDeclarator(d.declarator);
10559 type = ProcessType(decl.specifiers, d.declarator);
10563 ProcessInitializer(d.initializer, type);
10565 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10567 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10568 d.initializer.exp.type == instanceExp)
10570 if(type.kind == classType && type._class ==
10571 d.initializer.exp.expType._class)
10573 Instantiation inst = d.initializer.exp.instance;
10574 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10576 d.initializer.exp.instance = null;
10577 if(decl.specifiers)
10578 FreeList(decl.specifiers, FreeSpecifier);
10579 FreeList(decl.declarators, FreeInitDeclarator);
10583 decl.type = instDeclaration;
10588 for(subType = type; subType;)
10590 if(subType.kind == classType)
10592 declareStruct = true;
10595 else if(subType.kind == pointerType)
10597 else if(subType.kind == arrayType)
10598 subType = subType.arrayType;
10608 if(decl.specifiers)
10611 for(s = decl.specifiers->first; s; s = s.next)
10613 ProcessSpecifier(s, declareStruct);
10618 case instDeclaration:
10620 ProcessInstantiationType(decl.inst);
10623 case structDeclaration:
10627 bool declareStruct = false;
10629 if(decl.declarators)
10631 for(d = decl.declarators->first; d; d = d.next)
10633 Type type = ProcessType(decl.specifiers, d.declarator);
10635 ProcessDeclarator(d);
10636 for(subType = type; subType;)
10638 if(subType.kind == classType)
10640 declareStruct = true;
10643 else if(subType.kind == pointerType)
10645 else if(subType.kind == arrayType)
10646 subType = subType.arrayType;
10653 if(decl.specifiers)
10655 for(spec = decl.specifiers->first; spec; spec = spec.next)
10656 ProcessSpecifier(spec, declareStruct);
10663 static FunctionDefinition curFunction;
10665 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10667 char propName[1024], propNameM[1024];
10668 char getName[1024], setName[1024];
10671 DeclareProperty(prop, setName, getName);
10673 // eInstance_FireWatchers(object, prop);
10674 strcpy(propName, "__ecereProp_");
10675 FullClassNameCat(propName, prop._class.fullName, false);
10676 strcat(propName, "_");
10677 // strcat(propName, prop.name);
10678 FullClassNameCat(propName, prop.name, true);
10679 MangleClassName(propName);
10681 strcpy(propNameM, "__ecerePropM_");
10682 FullClassNameCat(propNameM, prop._class.fullName, false);
10683 strcat(propNameM, "_");
10684 // strcat(propNameM, prop.name);
10685 FullClassNameCat(propNameM, prop.name, true);
10686 MangleClassName(propNameM);
10688 if(prop.isWatchable)
10691 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10692 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10693 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10696 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10697 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10698 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10704 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10705 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10706 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10709 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10710 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10711 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10714 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10715 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10716 curFunction.propSet.fireWatchersDone = true;
10719 static void ProcessStatement(Statement stmt)
10723 lineNum = stmt.pos.line;
10724 column = stmt.pos.col;
10729 ProcessStatement(stmt.labeled.stmt);
10732 // This expression should be constant...
10733 if(stmt.caseStmt.exp)
10735 FreeType(stmt.caseStmt.exp.destType);
10736 stmt.caseStmt.exp.destType = curSwitchType;
10737 if(curSwitchType) curSwitchType.refCount++;
10738 ProcessExpressionType(stmt.caseStmt.exp);
10739 ComputeExpression(stmt.caseStmt.exp);
10741 if(stmt.caseStmt.stmt)
10742 ProcessStatement(stmt.caseStmt.stmt);
10746 if(stmt.compound.context)
10751 Statement prevCompound = curCompound;
10752 Context prevContext = curContext;
10754 if(!stmt.compound.isSwitch)
10756 curCompound = stmt;
10757 curContext = stmt.compound.context;
10760 if(stmt.compound.declarations)
10762 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10763 ProcessDeclaration(decl);
10765 if(stmt.compound.statements)
10767 for(s = stmt.compound.statements->first; s; s = s.next)
10768 ProcessStatement(s);
10771 curContext = prevContext;
10772 curCompound = prevCompound;
10776 case expressionStmt:
10779 if(stmt.expressions)
10781 for(exp = stmt.expressions->first; exp; exp = exp.next)
10782 ProcessExpressionType(exp);
10790 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10791 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10792 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10793 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10795 ProcessExpressionType(exp);
10797 if(stmt.ifStmt.stmt)
10798 ProcessStatement(stmt.ifStmt.stmt);
10799 if(stmt.ifStmt.elseStmt)
10800 ProcessStatement(stmt.ifStmt.elseStmt);
10805 Type oldSwitchType = curSwitchType;
10806 if(stmt.switchStmt.exp)
10809 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10819 e.exp.destType = destType;
10822 ProcessExpressionType(exp);
10825 curSwitchType = exp.expType;
10828 ProcessStatement(stmt.switchStmt.stmt);
10829 curSwitchType = oldSwitchType;
10834 if(stmt.whileStmt.exp)
10838 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10839 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10840 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10841 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10843 ProcessExpressionType(exp);
10846 if(stmt.whileStmt.stmt)
10847 ProcessStatement(stmt.whileStmt.stmt);
10852 if(stmt.doWhile.exp)
10856 if(stmt.doWhile.exp->last)
10858 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10859 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10860 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10862 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10864 ProcessExpressionType(exp);
10867 if(stmt.doWhile.stmt)
10868 ProcessStatement(stmt.doWhile.stmt);
10874 if(stmt.forStmt.init)
10875 ProcessStatement(stmt.forStmt.init);
10877 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10879 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10880 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10881 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10884 if(stmt.forStmt.check)
10885 ProcessStatement(stmt.forStmt.check);
10886 if(stmt.forStmt.increment)
10888 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10889 ProcessExpressionType(exp);
10892 if(stmt.forStmt.stmt)
10893 ProcessStatement(stmt.forStmt.stmt);
10898 Identifier id = stmt.forEachStmt.id;
10899 OldList * exp = stmt.forEachStmt.exp;
10900 OldList * filter = stmt.forEachStmt.filter;
10901 Statement block = stmt.forEachStmt.stmt;
10902 char iteratorType[1024];
10905 bool isBuiltin = exp && exp->last &&
10906 (((Expression)exp->last).type == ExpressionType::arrayExp ||
10907 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
10908 Expression arrayExp;
10909 char * typeString = null;
10910 int builtinCount = 0;
10912 for(e = exp ? exp->first : null; e; e = e.next)
10916 FreeType(e.destType);
10917 e.destType = ProcessTypeString("Container", false);
10919 if(!isBuiltin || e.next)
10920 ProcessExpressionType(e);
10923 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
10924 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
10925 eClass_IsDerived(source._class.registered, containerClass)))
10927 Class _class = source ? source._class.registered : null;
10929 Expression expIt = null;
10930 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
10931 Class arrayClass = eSystem_FindClass(privateModule, "Array");
10932 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
10933 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
10934 stmt.type = compoundStmt;
10936 stmt.compound.context = Context { };
10937 stmt.compound.context.parent = curContext;
10938 curContext = stmt.compound.context;
10940 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
10942 Class mapClass = eSystem_FindClass(privateModule, "Map");
10943 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
10944 isCustomAVLTree = true;
10945 if(eClass_IsDerived(source._class.registered, avlTreeClass))
10947 else if(eClass_IsDerived(source._class.registered, mapClass))
10950 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
10951 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
10953 Class listClass = eSystem_FindClass(privateModule, "List");
10955 isList = eClass_IsDerived(source._class.registered, listClass);
10961 OldList * specs = MkList();
10962 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
10963 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
10964 stmt.compound.declarations = MkListOne(
10965 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
10966 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
10967 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
10968 MkInitializerAssignment(MkExpBrackets(exp))))));
10973 char typeStringBuf[1024];
10975 // TODO: Merge this code?
10976 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
10977 if(((Expression)exp->last).type == castExp)
10979 TypeName typeName = ((Expression)exp->last).cast.typeName;
10981 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
10984 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
10985 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
10986 arrayExp.destType._class.registered.templateArgs)
10988 Class templateClass = arrayExp.destType._class.registered;
10989 typeString = templateClass.templateArgs[2].dataTypeString;
10991 else if(arrayExp.list)
10993 // Guess type from expressions in the array
10995 for(e = arrayExp.list->first; e; e = e.next)
10997 ProcessExpressionType(e);
11000 if(!type) { type = e.expType; type.refCount++; }
11003 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11004 if(!MatchTypeExpression(e, type, null, false))
11010 e = arrayExp.list->first;
11011 ProcessExpressionType(e);
11014 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11015 if(!MatchTypeExpression(e, type, null, false))
11017 FreeType(e.expType);
11028 FreeType(e.expType);
11035 typeStringBuf[0] = '\0';
11036 PrintType(type, typeStringBuf, false, true);
11037 typeString = typeStringBuf;
11043 OldList * initializers = MkList();
11045 OldList * specs = MkList();
11050 builtinCount = arrayExp.list->count;
11051 type = ProcessTypeString(typeString, false);
11052 while(e = arrayExp.list->first)
11054 arrayExp.list->Remove(e);
11057 ProcessExpressionType(e);
11058 ListAdd(initializers, MkInitializerAssignment(e));
11061 delete arrayExp.list;
11063 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11064 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11065 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11067 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11068 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11070 FreeList(exp, FreeExpression);
11074 arrayExp.expType = ProcessTypeString("Container", false);
11075 Compiler_Error($"Couldn't determine type of array elements\n");
11080 OldList * specs = MkList();
11082 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11083 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11084 stmt.compound.declarations = MkListOne(
11085 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11086 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11087 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11088 MkInitializerAssignment(MkExpBrackets(exp))))));
11091 else if(isLinkList && !isList)
11094 OldList * specs = MkList();
11095 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11096 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11097 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11098 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11099 MkInitializerAssignment(MkExpBrackets(exp))))));
11101 /*else if(isCustomAVLTree)
11104 OldList * specs = MkList();
11105 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11106 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11107 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11108 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11109 MkInitializerAssignment(MkExpBrackets(exp))))));
11111 else if(_class.templateArgs)
11114 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11116 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11118 stmt.compound.declarations = MkListOne(
11119 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11120 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11121 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11123 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11125 if(block && block.type == compoundStmt && block.compound.context)
11127 block.compound.context.parent = stmt.compound.context;
11131 block = MkIfStmt(filter, block, null);
11135 stmt.compound.statements = MkListOne(MkForStmt(
11136 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11137 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11138 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11139 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11141 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11142 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11143 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11148 //OldList * specs = MkList();
11149 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11151 sprintf(count, "%d", builtinCount);
11153 stmt.compound.statements = MkListOne(MkForStmt(
11154 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11155 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11156 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11157 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11161 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11162 stmt.compound.statements = MkListOne(MkForStmt(
11163 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11164 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11165 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11166 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11169 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11170 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11171 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11173 else if(isLinkList && !isList)
11175 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11176 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11177 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11178 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11180 stmt.compound.statements = MkListOne(MkForStmt(
11181 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11182 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11183 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11188 OldList * specs = MkList();
11189 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11190 stmt.compound.statements = MkListOne(MkForStmt(
11191 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11192 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11193 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11194 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11195 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11198 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11199 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11200 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11202 /*else if(isCustomAVLTree)
11204 stmt.compound.statements = MkListOne(MkForStmt(
11205 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11206 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11207 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11208 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11211 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11212 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11213 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11217 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11218 MkIdentifier("Next")), null)), block));
11220 ProcessExpressionType(expIt);
11221 if(stmt.compound.declarations->first)
11222 ProcessDeclaration(stmt.compound.declarations->first);
11225 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11227 ProcessStatement(stmt);
11228 curContext = stmt.compound.context.parent;
11233 Compiler_Error($"Expression is not a container\n");
11246 if(stmt.expressions)
11248 for(exp = stmt.expressions->first; exp; exp = exp.next)
11252 if(curFunction && !curFunction.type)
11253 curFunction.type = ProcessType(
11254 curFunction.specifiers, curFunction.declarator);
11255 FreeType(exp.destType);
11256 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11257 if(exp.destType) exp.destType.refCount++;
11259 ProcessExpressionType(exp);
11264 case badDeclarationStmt:
11266 ProcessDeclaration(stmt.decl);
11272 if(stmt.asmStmt.inputFields)
11274 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11275 if(field.expression)
11276 ProcessExpressionType(field.expression);
11278 if(stmt.asmStmt.outputFields)
11280 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11281 if(field.expression)
11282 ProcessExpressionType(field.expression);
11284 if(stmt.asmStmt.clobberedFields)
11286 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11288 if(field.expression)
11289 ProcessExpressionType(field.expression);
11296 PropertyWatch propWatch;
11297 OldList * watches = stmt._watch.watches;
11298 Expression object = stmt._watch.object;
11299 Expression watcher = stmt._watch.watcher;
11301 ProcessExpressionType(watcher);
11303 ProcessExpressionType(object);
11307 if(watcher || thisClass)
11309 External external = curExternal;
11310 Context context = curContext;
11312 stmt.type = expressionStmt;
11313 stmt.expressions = MkList();
11315 curExternal = external.prev;
11317 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11319 ClassFunction func;
11320 char watcherName[1024];
11321 Class watcherClass = watcher ?
11322 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11323 External createdExternal;
11325 // Create a declaration above
11326 External externalDecl = MkExternalDeclaration(null);
11327 ast->Insert(curExternal.prev, externalDecl);
11329 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11330 if(propWatch.deleteWatch)
11331 strcat(watcherName, "_delete");
11335 for(propID = propWatch.properties->first; propID; propID = propID.next)
11337 strcat(watcherName, "_");
11338 strcat(watcherName, propID.string);
11342 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11344 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11345 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11346 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11347 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11348 ProcessClassFunctionBody(func, propWatch.compound);
11349 propWatch.compound = null;
11351 //afterExternal = afterExternal ? afterExternal : curExternal;
11353 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11354 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11356 createdExternal.symbol.idCode = external.symbol.idCode;
11358 curExternal = createdExternal;
11359 ProcessFunction(createdExternal.function);
11362 // Create a declaration above
11364 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11365 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11366 externalDecl.declaration = decl;
11367 if(decl.symbol && !decl.symbol.pointerExternal)
11368 decl.symbol.pointerExternal = externalDecl;
11371 if(propWatch.deleteWatch)
11373 OldList * args = MkList();
11374 ListAdd(args, CopyExpression(object));
11375 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11376 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11377 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11381 Class _class = object.expType._class.registered;
11384 for(propID = propWatch.properties->first; propID; propID = propID.next)
11386 char propName[1024];
11387 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11390 char getName[1024], setName[1024];
11391 OldList * args = MkList();
11393 DeclareProperty(prop, setName, getName);
11395 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11396 strcpy(propName, "__ecereProp_");
11397 FullClassNameCat(propName, prop._class.fullName, false);
11398 strcat(propName, "_");
11399 // strcat(propName, prop.name);
11400 FullClassNameCat(propName, prop.name, true);
11402 ListAdd(args, CopyExpression(object));
11403 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11404 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11405 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11407 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11410 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11415 Compiler_Error($"Invalid watched object\n");
11418 curExternal = external;
11419 curContext = context;
11422 FreeExpression(watcher);
11424 FreeExpression(object);
11425 FreeList(watches, FreePropertyWatch);
11428 Compiler_Error($"No observer specified and not inside a _class\n");
11432 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11434 ProcessStatement(propWatch.compound);
11440 case fireWatchersStmt:
11442 OldList * watches = stmt._watch.watches;
11443 Expression object = stmt._watch.object;
11445 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11446 // printf("%X\n", watches);
11447 // printf("%X\n", stmt._watch.watches);
11449 ProcessExpressionType(object);
11454 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11460 stmt.type = expressionStmt;
11461 stmt.expressions = MkList();
11463 // Check if we're inside a property set
11464 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11466 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11470 //Compiler_Error($"No property specified and not inside a property set\n");
11474 for(propID = watches->first; propID; propID = propID.next)
11476 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11479 CreateFireWatcher(prop, object, stmt);
11482 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11487 // Fire all properties!
11490 for(base = _class; base; base = base.base)
11492 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11494 if(prop.isProperty && prop.isWatchable)
11496 CreateFireWatcher(prop, object, stmt);
11503 FreeExpression(object);
11504 FreeList(watches, FreeIdentifier);
11507 Compiler_Error($"Invalid object specified and not inside a class\n");
11511 case stopWatchingStmt:
11513 OldList * watches = stmt._watch.watches;
11514 Expression object = stmt._watch.object;
11515 Expression watcher = stmt._watch.watcher;
11518 ProcessExpressionType(object);
11520 ProcessExpressionType(watcher);
11523 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11525 if(watcher || thisClass)
11531 stmt.type = expressionStmt;
11532 stmt.expressions = MkList();
11537 // eInstance_StopWatching(object, null, watcher);
11539 ListAdd(args, CopyExpression(object));
11540 ListAdd(args, MkExpConstant("0"));
11541 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11542 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11546 for(propID = watches->first; propID; propID = propID.next)
11548 char propName[1024];
11549 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11552 char getName[1024], setName[1024];
11553 OldList * args = MkList();
11555 DeclareProperty(prop, setName, getName);
11557 // eInstance_StopWatching(object, prop, watcher);
11558 strcpy(propName, "__ecereProp_");
11559 FullClassNameCat(propName, prop._class.fullName, false);
11560 strcat(propName, "_");
11561 // strcat(propName, prop.name);
11562 FullClassNameCat(propName, prop.name, true);
11563 MangleClassName(propName);
11565 ListAdd(args, CopyExpression(object));
11566 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11567 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11568 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11571 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11576 FreeExpression(object);
11578 FreeExpression(watcher);
11579 FreeList(watches, FreeIdentifier);
11582 Compiler_Error($"Invalid object specified and not inside a class\n");
11585 Compiler_Error($"No observer specified and not inside a class\n");
11592 static void ProcessFunction(FunctionDefinition function)
11594 Identifier id = GetDeclId(function.declarator);
11595 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11596 Type type = symbol ? symbol.type : null;
11597 Class oldThisClass = thisClass;
11598 Context oldTopContext = topContext;
11600 yylloc = function.loc;
11601 // Process thisClass
11603 if(type && type.thisClass)
11605 Symbol classSym = type.thisClass;
11606 Class _class = type.thisClass.registered;
11607 char className[1024];
11608 char structName[1024];
11609 Declarator funcDecl;
11612 bool typedObject = false;
11614 if(_class && !_class.base)
11616 _class = currentClass;
11617 if(_class && !_class.symbol)
11618 _class.symbol = FindClass(_class.fullName);
11619 classSym = _class ? _class.symbol : null;
11620 typedObject = true;
11623 thisClass = _class;
11625 if(inCompiler && _class)
11627 if(type.kind == functionType)
11629 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11631 //TypeName param = symbol.type.params.first;
11632 Type param = symbol.type.params.first;
11633 symbol.type.params.Remove(param);
11634 //FreeTypeName(param);
11637 if(type.classObjectType != classPointer)
11639 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11640 symbol.type.staticMethod = true;
11641 symbol.type.thisClass = null;
11643 // HIGH DANGER: VERIFYING THIS...
11644 symbol.type.extraParam = false;
11648 strcpy(className, "__ecereClass_");
11649 FullClassNameCat(className, _class.fullName, true);
11651 MangleClassName(className);
11654 FullClassNameCat(structName, _class.fullName, false);
11659 funcDecl = GetFuncDecl(function.declarator);
11662 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11664 TypeName param = funcDecl.function.parameters->first;
11665 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11667 funcDecl.function.parameters->Remove(param);
11668 FreeTypeName(param);
11672 // DANGER: Watch for this... Check if it's a Conversion?
11673 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11675 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11676 if(!function.propertyNoThis)
11678 TypeName thisParam;
11680 if(type.classObjectType != classPointer)
11682 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11683 if(!funcDecl.function.parameters)
11684 funcDecl.function.parameters = MkList();
11685 funcDecl.function.parameters->Insert(null, thisParam);
11690 if(type.classObjectType != classPointer)
11692 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11693 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11696 thisParam = TypeName
11698 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11699 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11701 funcDecl.function.parameters->Insert(null, thisParam);
11706 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11708 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11709 funcDecl = GetFuncDecl(initDecl.declarator);
11712 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11714 TypeName param = funcDecl.function.parameters->first;
11715 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11717 funcDecl.function.parameters->Remove(param);
11718 FreeTypeName(param);
11722 if(type.classObjectType != classPointer)
11724 // DANGER: Watch for this... Check if it's a Conversion?
11725 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11727 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11729 if(!funcDecl.function.parameters)
11730 funcDecl.function.parameters = MkList();
11731 funcDecl.function.parameters->Insert(null, thisParam);
11738 // Add this to the context
11741 if(type.classObjectType != classPointer)
11743 thisSymbol = Symbol
11745 string = CopyString("this");
11746 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11748 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11750 if(typedObject && thisSymbol.type)
11752 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11753 thisSymbol.type.byReference = type.byReference;
11755 thisSymbol = Symbol { string = CopyString("class") };
11756 function.body.compound.context.symbols.Add(thisSymbol);
11762 // Pointer to class data
11764 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11766 DataMember member = null;
11769 for(base = _class; base && base.type != systemClass; base = base.next)
11771 for(member = base.membersAndProperties.first; member; member = member.next)
11772 if(!member.isProperty)
11778 for(member = _class.membersAndProperties.first; member; member = member.next)
11779 if(!member.isProperty)
11783 char pointerName[1024];
11786 Initializer initializer;
11787 Expression exp, bytePtr;
11789 strcpy(pointerName, "__ecerePointer_");
11790 FullClassNameCat(pointerName, _class.fullName, false);
11792 char className[1024];
11793 strcpy(className, "__ecereClass_");
11794 FullClassNameCat(className, classSym.string, true);
11795 MangleClassName(className);
11798 DeclareClass(classSym, className);
11802 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11807 sprintf(string, "%d", _class.offset);
11808 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11812 // ([bytePtr] + [className]->offset)
11813 exp = QBrackets(MkExpOp(bytePtr, '+',
11814 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11817 // (this ? [exp] : 0)
11818 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11822 kind = pointerType;
11823 type = Type { refCount = 1, kind = voidType };
11828 yylloc = function.body.loc;
11829 // ([structName] *) [exp]
11830 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11831 initializer = MkInitializerAssignment(
11832 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11834 // [structName] * [pointerName] = [initializer];
11835 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11838 Context prevContext = curContext;
11839 curContext = function.body.compound.context;
11841 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11842 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11844 curContext = prevContext;
11848 decl.symbol = null;
11850 if(!function.body.compound.declarations)
11851 function.body.compound.declarations = MkList();
11852 function.body.compound.declarations->Insert(null, decl);
11858 // Loop through the function and replace undeclared identifiers
11859 // which are a member of the class (methods, properties or data)
11860 // by "this.[member]"
11867 FreeSpecifier(id._class);
11870 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11872 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11873 id = GetDeclId(initDecl.declarator);
11875 FreeSpecifier(id._class);
11880 topContext = function.body.compound.context;
11882 FunctionDefinition oldFunction = curFunction;
11883 curFunction = function;
11885 ProcessStatement(function.body);
11887 // If this is a property set and no firewatchers has been done yet, add one here
11888 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11890 Statement prevCompound = curCompound;
11891 Context prevContext = curContext;
11893 Statement fireWatchers = MkFireWatchersStmt(null, null);
11894 if(!function.body.compound.statements) function.body.compound.statements = MkList();
11895 ListAdd(function.body.compound.statements, fireWatchers);
11897 curCompound = function.body;
11898 curContext = function.body.compound.context;
11900 ProcessStatement(fireWatchers);
11902 curContext = prevContext;
11903 curCompound = prevCompound;
11907 curFunction = oldFunction;
11910 if(function.declarator)
11912 ProcessDeclarator(function.declarator);
11915 topContext = oldTopContext;
11916 thisClass = oldThisClass;
11919 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
11920 static void ProcessClass(OldList definitions, Symbol symbol)
11923 External external = curExternal;
11924 Class regClass = symbol ? symbol.registered : null;
11926 // Process all functions
11927 for(def = definitions.first; def; def = def.next)
11929 if(def.type == functionClassDef)
11931 if(def.function.declarator)
11932 curExternal = def.function.declarator.symbol.pointerExternal;
11934 curExternal = external;
11936 ProcessFunction((FunctionDefinition)def.function);
11938 else if(def.type == declarationClassDef)
11940 if(def.decl.type == instDeclaration)
11942 thisClass = regClass;
11943 ProcessInstantiationType(def.decl.inst);
11949 Class backThisClass = thisClass;
11950 if(regClass) thisClass = regClass;
11951 ProcessDeclaration(def.decl);
11952 thisClass = backThisClass;
11955 else if(def.type == defaultPropertiesClassDef && def.defProperties)
11957 MemberInit defProperty;
11959 // Add this to the context
11960 Symbol thisSymbol = Symbol
11962 string = CopyString("this");
11963 type = regClass ? MkClassType(regClass.fullName) : null;
11965 globalContext.symbols.Add((BTNode)thisSymbol);
11967 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
11969 thisClass = regClass;
11970 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
11974 globalContext.symbols.Remove((BTNode)thisSymbol);
11975 FreeSymbol(thisSymbol);
11977 else if(def.type == propertyClassDef && def.propertyDef)
11979 PropertyDef prop = def.propertyDef;
11981 // Add this to the context
11983 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
11984 globalContext.symbols.Add(thisSymbol);
11987 thisClass = regClass;
11994 string = CopyString("this");
11995 type = MkClassType(regClass.fullName);
11997 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12000 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12001 ProcessStatement(prop.setStmt);
12009 string = CopyString("this");
12010 type = MkClassType(regClass.fullName);
12012 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12015 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12016 ProcessStatement(prop.getStmt);
12024 string = CopyString("this");
12025 type = MkClassType(regClass.fullName);
12027 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12030 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12031 ProcessStatement(prop.issetStmt);
12037 globalContext.symbols.Remove(thisSymbol);
12038 FreeSymbol(thisSymbol);
12041 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12043 PropertyWatch propertyWatch = def.propertyWatch;
12045 thisClass = regClass;
12046 if(propertyWatch.compound)
12050 string = CopyString("this");
12051 type = regClass ? MkClassType(regClass.fullName) : null;
12054 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12056 curExternal = null;
12057 ProcessStatement(propertyWatch.compound);
12064 void ComputeDataTypes()
12068 currentClass = null;
12070 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12072 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12074 // WHERE SHOULD THIS GO?
12075 // curExternal = ast->first;
12076 ast->Insert(null, temp);
12078 curExternal = temp;
12080 DeclareStruct("ecere::com::Class", false);
12081 DeclareStruct("ecere::com::Instance", false);
12082 DeclareStruct("ecere::com::Property", false);
12083 DeclareStruct("ecere::com::DataMember", false);
12084 DeclareStruct("ecere::com::Method", false);
12085 DeclareStruct("ecere::com::SerialBuffer", false);
12086 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12090 for(external = ast->first; external; external = external.next)
12092 afterExternal = curExternal = external;
12093 if(external.type == functionExternal)
12095 currentClass = external.function._class;
12096 ProcessFunction(external.function);
12098 // There shouldn't be any _class member access here anyways...
12099 else if(external.type == declarationExternal)
12101 currentClass = null;
12102 ProcessDeclaration(external.declaration);
12104 else if(external.type == classExternal)
12106 ClassDefinition _class = external._class;
12107 currentClass = external.symbol.registered;
12108 if(_class.definitions)
12110 ProcessClass(_class.definitions, _class.symbol);
12114 // Free class data...
12115 ast->Remove(external);
12119 else if(external.type == nameSpaceExternal)
12121 thisNameSpace = external.id.string;
12124 currentClass = null;
12125 thisNameSpace = null;
12127 delete temp.symbol;