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 && !strcmp(spec.name, "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);
6526 void PrintType(Type type, char * string, bool printName, bool fullName)
6529 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6530 if(funcType && funcType.kind == functionType && type != funcType)
6532 char typeString[1024];
6535 PrintType(funcType.returnType, string, false, fullName);
6536 strcat(string, "(");
6537 _PrintType(type, string, printName, false, fullName);
6538 strcat(string, ")");
6541 strcat(string, type.name);
6547 strcat(string, "(");
6548 for(param = funcType.params.first; param; param = param.next)
6550 PrintType(param, string, true, fullName);
6551 if(param.next) strcat(string, ", ");
6553 strcat(string, ")");
6556 _PrintType(type, string, printName, true, fullName);
6557 if(type.bitFieldCount)
6560 sprintf(count, ":%d", type.bitFieldCount);
6561 strcat(string, count);
6565 static Type FindMember(Type type, char * string)
6568 for(memberType = type.members.first; memberType; memberType = memberType.next)
6570 if(!memberType.name)
6572 Type subType = FindMember(memberType, string);
6576 else if(!strcmp(memberType.name, string))
6582 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6585 for(memberType = type.members.first; memberType; memberType = memberType.next)
6587 if(!memberType.name)
6589 Type subType = FindMember(memberType, string);
6592 *offset += memberType.offset;
6596 else if(!strcmp(memberType.name, string))
6598 *offset += memberType.offset;
6605 Expression ParseExpressionString(char * expression)
6607 fileInput = TempFile { };
6608 fileInput.Write(expression, 1, strlen(expression));
6609 fileInput.Seek(0, start);
6612 parsedExpression = null;
6614 expression_yyparse();
6617 return parsedExpression;
6620 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6622 Identifier id = exp.identifier;
6623 Method method = null;
6624 Property prop = null;
6625 DataMember member = null;
6626 ClassProperty classProp = null;
6628 if(_class && _class.type == enumClass)
6630 NamedLink value = null;
6631 Class enumClass = eSystem_FindClass(privateModule, "enum");
6635 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6637 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6638 for(value = e.values.first; value; value = value.next)
6640 if(!strcmp(value.name, id.string))
6647 FreeExpContents(exp);
6649 exp.type = constantExp;
6650 exp.isConstant = true;
6651 if(!strcmp(baseClass.dataTypeString, "int"))
6652 sprintf(constant, "%d",value.data);
6654 sprintf(constant, "0x%X",value.data);
6655 exp.constant = CopyString(constant);
6656 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6657 exp.expType = MkClassType(baseClass.fullName);
6665 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6667 ProcessMethodType(method);
6674 // TOCHECK: Put it back to what it was...
6675 // methodClass = _class;
6676 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6681 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6684 ProcessPropertyType(prop);
6685 exp.expType = prop.dataType;
6686 if(prop.dataType) prop.dataType.refCount++;
6689 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6691 if(!member.dataType)
6692 member.dataType = ProcessTypeString(member.dataTypeString, false);
6693 exp.expType = member.dataType;
6694 if(member.dataType) member.dataType.refCount++;
6697 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6699 if(!classProp.dataType)
6700 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6702 if(classProp.constant)
6704 FreeExpContents(exp);
6706 exp.isConstant = true;
6707 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6709 //char constant[256];
6710 exp.type = stringExp;
6711 exp.constant = QMkString((char *)classProp.Get(_class));
6716 exp.type = constantExp;
6717 sprintf(constant, "%d",classProp.Get(_class));
6718 exp.constant = CopyString(constant);
6726 exp.expType = classProp.dataType;
6727 if(classProp.dataType) classProp.dataType.refCount++;
6733 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6735 BinaryTree * tree = &nameSpace.functions;
6736 GlobalData data = (GlobalData)tree->FindString(name);
6740 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6742 data = ScanGlobalData(child, name);
6750 static GlobalData FindGlobalData(char * name)
6753 NameSpace * nameSpace;
6754 nameSpace = globalData;
6755 for(c = 0; name[c]; c++)
6757 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6759 NameSpace * newSpace;
6760 char * spaceName = new char[c - start + 1];
6761 strncpy(spaceName, name + start, c - start);
6762 spaceName[c-start] = '\0';
6763 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6767 nameSpace = newSpace;
6768 if(name[c] == ':') c++;
6774 return ScanGlobalData(nameSpace, name + start);
6779 static int definedExpStackPos;
6780 static void * definedExpStack[512];
6782 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6783 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6785 Expression prev = checkedExp.prev, next = checkedExp.next;
6787 FreeExpContents(checkedExp);
6788 FreeType(checkedExp.expType);
6789 FreeType(checkedExp.destType);
6791 *checkedExp = *newExp;
6795 checkedExp.prev = prev;
6796 checkedExp.next = next;
6799 void ApplyAnyObjectLogic(Expression e)
6801 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6802 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6804 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6805 //ellipsisDestType = destType;
6808 Type type = e.expType;
6809 Class _class = null;
6810 //Type destType = e.destType;
6812 if(type.kind == classType && type._class && type._class.registered)
6814 _class = type._class.registered;
6816 else if(type.kind == subClassType)
6818 _class = FindClass("ecere::com::Class").registered;
6822 char string[1024] = "";
6825 PrintType(type, string, false, true);
6826 classSym = FindClass(string);
6827 if(classSym) _class = classSym.registered;
6830 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...
6831 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6832 destType.byReference)))
6834 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6836 Expression checkedExp = e, newExp;
6838 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6840 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6842 if(checkedExp.type == extensionCompoundExp)
6844 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6847 checkedExp = checkedExp.list->last;
6849 else if(checkedExp.type == castExp)
6850 checkedExp = checkedExp.cast.exp;
6853 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6855 newExp = checkedExp.op.exp2;
6856 checkedExp.op.exp2 = null;
6857 FreeExpContents(checkedExp);
6859 if(e.expType && e.expType.passAsTemplate)
6862 ComputeTypeSize(e.expType);
6863 sprintf(size, "%d", e.expType.size);
6864 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6865 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6866 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6869 ReplaceExpContents(checkedExp, newExp);
6870 e.byReference = true;
6872 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6874 Expression checkedExp, newExp;
6877 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6879 e.type == identifierExp ||
6880 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6881 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6882 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6885 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6887 Context context = PushContext();
6889 OldList * specs = MkList();
6890 char typeString[1024];
6891 Expression newExp { };
6893 typeString[0] = '\0';
6896 //if(e.destType) e.destType.refCount++;
6897 // if(exp.expType) exp.expType.refCount++;
6900 newExp.expType = null;
6902 PrintType(e.expType, typeString, false, true);
6903 decl = SpecDeclFromString(typeString, specs, null);
6904 newExp.destType = ProcessType(specs, decl);
6906 curContext = context;
6907 e.type = extensionCompoundExp;
6909 // We need a current compound for this
6913 OldList * stmts = MkList();
6914 sprintf(name, "__internalValue%03X", internalValueCounter++);
6915 if(!curCompound.compound.declarations)
6916 curCompound.compound.declarations = MkList();
6917 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
6918 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
6919 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
6920 e.compound = MkCompoundStmt(null, stmts);
6923 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
6926 e.compound = MkCompoundStmt(
6927 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
6928 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
6930 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
6934 Type type = e.destType;
6936 CopyTypeInto(e.destType, type);
6937 e.destType.refCount = 1;
6938 e.destType.classObjectType = none;
6942 e.compound.compound.context = context;
6943 PopContext(context);
6944 curContext = context.parent;
6948 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
6950 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6952 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6954 if(checkedExp.type == extensionCompoundExp)
6956 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6959 checkedExp = checkedExp.list->last;
6961 else if(checkedExp.type == castExp)
6962 checkedExp = checkedExp.cast.exp;
6965 Expression operand { };
6966 operand = *checkedExp;
6967 checkedExp.destType = null;
6968 checkedExp.expType = null;
6970 checkedExp.type = opExp;
6971 checkedExp.op.op = '&';
6972 checkedExp.op.exp1 = null;
6973 checkedExp.op.exp2 = operand;
6975 //newExp = MkExpOp(null, '&', checkedExp);
6977 //ReplaceExpContents(checkedExp, newExp);
6984 // If expression type is a simple class, make it an address
6985 // FixReference(e, true);
6988 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6989 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6990 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
6992 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
6994 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
6998 Expression thisExp { };
7001 thisExp.prev = null;
7002 thisExp.next = null;
7005 e.type = bracketsExp;
7006 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
7007 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7008 ((Expression)e.list->first).byReference = true;
7010 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7012 e.expType = thisExp.expType;
7013 e.expType.refCount++;
7018 CopyTypeInto(e.expType, thisExp.expType);
7019 e.expType.byReference = false;
7020 e.expType.refCount = 1;
7022 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7023 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7025 e.expType.classObjectType = none;
7030 // TOFIX: Try this for a nice IDE crash!
7032 // The other way around
7035 if(destType && e.expType &&
7036 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7037 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7038 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7040 if(destType.kind == ellipsisType)
7042 Compiler_Error($"Unspecified type\n");
7044 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7046 bool byReference = e.expType.byReference;
7047 Expression thisExp { };
7049 OldList * specs = MkList();
7050 char typeString[1024]; // Watch buffer overruns
7052 ClassObjectType backupClassObjectType;
7054 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7059 backupClassObjectType = type.classObjectType;
7061 type.classObjectType = none;
7063 typeString[0] = '\0';
7064 PrintType(type, typeString, false, true);
7065 decl = SpecDeclFromString(typeString, specs, null);
7067 type.classObjectType = backupClassObjectType;
7070 thisExp.prev = null;
7071 thisExp.next = null;
7074 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7075 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7076 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7077 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7078 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7083 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7088 e.cast.typeName = MkTypeName(specs, decl);
7089 e.cast.exp = thisExp;
7090 e.byReference = true;
7093 e.destType = destType;
7095 destType.refCount++;
7100 void ProcessExpressionType(Expression exp)
7102 bool unresolved = false;
7103 Location oldyylloc = yylloc;
7104 bool notByReference = false;
7106 char debugExpString[4096];
7107 debugExpString[0] = '\0';
7108 PrintExpression(exp, debugExpString);
7110 if(!exp || exp.expType)
7113 //eSystem_Logf("%s\n", expString);
7115 // Testing this here
7121 Identifier id = exp.identifier;
7124 // DOING THIS LATER NOW...
7125 if(id._class && id._class.name)
7127 id.classSym = id._class.symbol; // FindClass(id._class.name);
7128 /* TODO: Name Space Fix ups
7130 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7134 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7136 exp.expType = ProcessTypeString("Module", true);
7139 else */if(strstr(id.string, "__ecereClass") == id.string)
7141 exp.expType = ProcessTypeString("ecere::com::Class", true);
7144 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7146 // Added this here as well
7147 ReplaceClassMembers(exp, thisClass);
7148 if(exp.type != identifierExp)
7150 ProcessExpressionType(exp);
7154 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7159 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7160 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7161 if(!symbol/* && exp.destType*/)
7163 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7169 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7170 if(exp.type != identifierExp)
7172 ProcessExpressionType(exp);
7176 // Static methods called from inside the _class
7177 else if(currentClass && !id._class)
7179 if(ResolveIdWithClass(exp, currentClass, true))
7182 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7186 // If we manage to resolve this symbol
7189 Type type = symbol.type;
7190 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7192 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7194 Context context = SetupTemplatesContext(_class);
7195 type = ReplaceThisClassType(_class);
7196 FinishTemplatesContext(context);
7197 if(type) type.refCount = 0; // We'll be incrementing it right below...
7200 FreeSpecifier(id._class);
7203 id.string = CopyString(symbol.string);
7209 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7210 // Add missing cases here... enum Classes...
7211 exp.isConstant = true;
7213 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7214 if(symbol.isParam || !strcmp(id.string, "this"))
7216 if(_class && _class.type == structClass)
7217 exp.byReference = true;
7219 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7220 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7221 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7222 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7224 Identifier id = exp.identifier;
7225 exp.type = bracketsExp;
7226 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7230 if(symbol.isIterator)
7232 if(symbol.isIterator == 3)
7234 exp.type = bracketsExp;
7235 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7236 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7238 ProcessExpressionType(exp);
7240 else if(symbol.isIterator != 4)
7242 exp.type = memberExp;
7243 exp.member.exp = MkExpIdentifier(exp.identifier);
7244 exp.member.exp.expType = exp.expType;
7245 /*if(symbol.isIterator == 6)
7246 exp.member.member = MkIdentifier("key");
7248 exp.member.member = MkIdentifier("data");
7250 ProcessExpressionType(exp);
7257 DefinedExpression definedExp = null;
7258 if(thisNameSpace && !(id._class && !id._class.name))
7261 strcpy(name, thisNameSpace);
7263 strcat(name, id.string);
7264 definedExp = eSystem_FindDefine(privateModule, name);
7267 definedExp = eSystem_FindDefine(privateModule, id.string);
7271 for(c = 0; c<definedExpStackPos; c++)
7272 if(definedExpStack[c] == definedExp)
7274 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7276 Location backupYylloc = yylloc;
7277 definedExpStack[definedExpStackPos++] = definedExp;
7278 fileInput = TempFile { };
7279 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7280 fileInput.Seek(0, start);
7283 parsedExpression = null;
7285 expression_yyparse();
7288 yylloc = backupYylloc;
7290 if(parsedExpression)
7293 exp.type = bracketsExp;
7294 exp.list = MkListOne(parsedExpression);
7295 parsedExpression.loc = yylloc;
7296 ProcessExpressionType(exp);
7297 definedExpStackPos--;
7300 definedExpStackPos--;
7306 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7312 GlobalData data = null;
7313 if(thisNameSpace && !(id._class && !id._class.name))
7316 strcpy(name, thisNameSpace);
7318 strcat(name, id.string);
7319 data = FindGlobalData(name);
7322 data = FindGlobalData(id.string);
7325 DeclareGlobalData(data);
7326 exp.expType = data.dataType;
7327 if(data.dataType) data.dataType.refCount++;
7330 id.string = CopyString(data.fullName);
7331 FreeSpecifier(id._class);
7338 GlobalFunction function = null;
7339 if(thisNameSpace && !(id._class && !id._class.name))
7342 strcpy(name, thisNameSpace);
7344 strcat(name, id.string);
7345 function = eSystem_FindFunction(privateModule, name);
7348 function = eSystem_FindFunction(privateModule, id.string);
7353 id.string = CopyString(function.name);
7356 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7357 strcpy(name, "__ecereFunction_");
7358 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7359 if(DeclareFunction(function, name))
7362 id.string = CopyString(name);
7364 exp.expType = function.dataType;
7365 if(function.dataType) function.dataType.refCount++;
7367 FreeSpecifier(id._class);
7384 if(!exp.instance._class)
7386 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7388 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7398 //classSym = FindClass(exp.instance._class.fullName);
7399 //_class = classSym ? classSym.registered : null;
7401 ProcessInstantiationType(exp.instance);
7402 exp.isConstant = exp.instance.isConstant;
7405 if(_class.type == unitClass && _class.base.type != systemClass)
7408 Type destType = exp.destType;
7410 exp.destType = MkClassType(_class.base.fullName);
7411 exp.expType = MkClassType(_class.fullName);
7412 CheckExpressionType(exp, exp.destType, true);
7414 exp.destType = destType;
7416 exp.expType = MkClassType(_class.fullName);
7419 if(exp.instance._class)
7421 exp.expType = MkClassType(exp.instance._class.name);
7422 /*if(exp.expType._class && exp.expType._class.registered &&
7423 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7424 exp.expType.byReference = true;*/
7439 if(exp.constant[0] == '\'')
7441 if((int)((byte *)exp.constant)[1] > 127)
7444 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7445 if(nb < 2) ch = exp.constant[1];
7446 delete exp.constant;
7447 exp.constant = PrintUInt(ch);
7448 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7449 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7450 type._class = FindClass("unichar");
7452 type.isSigned = false;
7456 type.kind = charType;
7457 type.isSigned = true;
7460 else if(strchr(exp.constant, '.'))
7462 char ch = exp.constant[strlen(exp.constant)-1];
7464 type.kind = floatType;
7466 type.kind = doubleType;
7467 type.isSigned = true;
7471 if(exp.constant[0] == '0' && exp.constant[1])
7472 type.isSigned = false;
7473 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7474 type.isSigned = false;
7475 else if(strtoll(exp.constant, null, 0) > MAXINT)
7476 type.isSigned = false;
7478 type.isSigned = true;
7479 type.kind = intType;
7481 exp.isConstant = true;
7487 exp.isConstant = true; // Why wasn't this constant?
7503 ProcessExpressionType(exp._new.size);
7508 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7510 DeclareType(exp.expType.type, false, false);
7514 ProcessExpressionType(exp._renew.size);
7515 ProcessExpressionType(exp._renew.exp);
7520 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7522 DeclareType(exp.expType.type, false, false);
7526 bool assign = false, boolResult = false, boolOps = false;
7527 Type type1 = null, type2 = null;
7528 bool useDestType = false, useSideType = false;
7529 Location oldyylloc = yylloc;
7530 bool useSideUnit = false;
7532 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7541 // Assignment Operators
7555 // boolean Operators
7557 // Expect boolean operators
7559 //boolResult = true;
7563 // Expect boolean operands
7574 // Gives boolean result
7582 // Just added these... testing
7587 // DANGER: Verify units
7592 if(exp.op.op != '*' || exp.op.exp1)
7599 /*// Implement speed etc.
7605 if(exp.op.op == '&')
7607 // Added this here earlier for Iterator address as key
7608 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7610 Identifier id = exp.op.exp2.identifier;
7611 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7612 if(symbol && symbol.isIterator == 2)
7614 exp.type = memberExp;
7615 exp.member.exp = exp.op.exp2;
7616 exp.member.member = MkIdentifier("key");
7618 exp.op.exp2.expType = symbol.type;
7619 symbol.type.refCount++;
7620 ProcessExpressionType(exp);
7624 // exp.op.exp2.usage.usageRef = true;
7628 //dummy.kind = TypeDummy;
7632 if(exp.destType && exp.destType.kind == classType &&
7633 exp.destType._class && exp.destType._class.registered && useDestType &&
7635 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7636 exp.destType._class.registered.type == enumClass ||
7637 exp.destType._class.registered.type == bitClass
7640 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7642 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7643 exp.op.exp1.destType = exp.destType;
7645 exp.destType.refCount++;
7649 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7650 exp.op.exp1.destType = dummy;
7654 // TESTING THIS HERE...
7655 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7656 ProcessExpressionType(exp.op.exp1);
7657 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7659 if(exp.op.exp1.destType == dummy)
7662 exp.op.exp1.destType = null;
7664 type1 = exp.op.exp1.expType;
7669 char expString[10240];
7670 expString[0] = '\0';
7671 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7675 exp.op.exp2.destType = exp.op.exp1.expType;
7676 if(exp.op.exp1.expType)
7677 exp.op.exp1.expType.refCount++;
7681 exp.op.exp2.destType = exp.destType;
7683 exp.destType.refCount++;
7686 if(type1) type1.refCount++;
7687 exp.expType = type1;
7692 PrintExpression(exp.op.exp2, expString);
7694 if(type1 && type1.kind == pointerType)
7696 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 ||
7697 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7698 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7699 else if(exp.op.op == '=')
7701 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7702 exp.op.exp2.destType = type1;
7709 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7710 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/* ||
7711 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7714 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7715 exp.op.exp2.destType = type1;
7720 if(type1) type1.refCount++;
7721 exp.expType = type1;
7723 else if(exp.destType && exp.destType.kind == classType &&
7724 exp.destType._class && exp.destType._class.registered &&
7726 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7727 (exp.destType._class.registered.type == enumClass && useDestType))
7730 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7731 exp.op.exp2.destType = exp.destType;
7733 exp.destType.refCount++;
7737 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7738 exp.op.exp2.destType = dummy;
7742 // TESTING THIS HERE... (DANGEROUS)
7743 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7744 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7746 FreeType(exp.op.exp2.destType);
7747 exp.op.exp2.destType = type1;
7750 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7751 ProcessExpressionType(exp.op.exp2);
7752 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7754 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7756 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)
7758 if(exp.op.op != '=' && type1.type.kind == voidType)
7759 Compiler_Error($"void *: unknown size\n");
7761 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||
7762 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7763 (exp.op.exp2.expType._class.registered.type == normalClass ||
7764 exp.op.exp2.expType._class.registered.type == structClass ||
7765 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7767 if(exp.op.op == ADD_ASSIGN)
7768 Compiler_Error($"cannot add two pointers\n");
7770 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7771 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7773 if(exp.op.op == ADD_ASSIGN)
7774 Compiler_Error($"cannot add two pointers\n");
7778 char type1String[1024];
7779 char type2String[1024];
7780 type1String[0] = '\0';
7781 type2String[0] = '\0';
7783 PrintType(exp.op.exp2.expType, type1String, false, true);
7784 PrintType(type1, type2String, false, true);
7785 ChangeCh(expString, '\n', ' ');
7786 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7790 if(exp.op.exp2.destType == dummy)
7793 exp.op.exp2.destType = null;
7796 type2 = exp.op.exp2.expType;
7799 dummy.kind = voidType;
7801 if(exp.op.op == SIZEOF)
7808 exp.isConstant = true;
7810 // Get type of dereferenced pointer
7811 else if(exp.op.op == '*' && !exp.op.exp1)
7813 exp.expType = Dereference(type2);
7814 if(type2 && type2.kind == classType)
7815 notByReference = true;
7817 else if(exp.op.op == '&' && !exp.op.exp1)
7818 exp.expType = Reference(type2);
7825 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7826 exp.op.exp1.destType = MkClassType("bool");
7827 exp.op.exp1.destType.truth = true;
7828 if(!exp.op.exp1.expType)
7829 ProcessExpressionType(exp.op.exp1);
7831 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7832 FreeType(exp.op.exp1.expType);
7833 exp.op.exp1.expType = MkClassType("bool");
7834 exp.op.exp1.expType.truth = true;
7838 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7839 exp.op.exp2.destType = MkClassType("bool");
7840 exp.op.exp2.destType.truth = true;
7841 if(!exp.op.exp2.expType)
7842 ProcessExpressionType(exp.op.exp2);
7844 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7845 FreeType(exp.op.exp2.expType);
7846 exp.op.exp2.expType = MkClassType("bool");
7847 exp.op.exp2.expType.truth = true;
7850 else if(exp.op.exp1 && exp.op.exp2 &&
7853 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7854 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7855 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7856 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7858 if(type1 && type2 &&
7859 // If either both are class or both are not class
7860 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7862 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7863 exp.op.exp2.destType = type1;
7865 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7866 exp.op.exp1.destType = type2;
7868 // Warning here for adding Radians + Degrees with no destination type
7869 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7870 type1._class.registered && type1._class.registered.type == unitClass &&
7871 type2._class.registered && type2._class.registered.type == unitClass &&
7872 type1._class.registered != type2._class.registered)
7873 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7874 type1._class.string, type2._class.string, type1._class.string);
7876 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7878 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7881 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7883 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7884 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7887 ProcessExpressionType(exp.op.exp1);
7889 if(type2.kind != pointerType)
7891 ProcessExpressionType(classExp);
7893 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
7894 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7895 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7897 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
7900 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
7901 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7902 MkPointer(null, null), null)))),
7903 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
7905 if(!exp.op.exp2.expType)
7906 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
7908 ProcessExpressionType(exp.op.exp2);
7913 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)))
7915 if(type1.kind != classType && type1.type.kind == voidType)
7916 Compiler_Error($"void *: unknown size\n");
7917 exp.expType = type1;
7918 if(type1) type1.refCount++;
7920 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)))
7922 if(type2.kind != classType && type2.type.kind == voidType)
7923 Compiler_Error($"void *: unknown size\n");
7924 exp.expType = type2;
7925 if(type2) type2.refCount++;
7927 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
7928 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
7930 Compiler_Warning($"different levels of indirection\n");
7934 bool success = false;
7935 if(type1.kind == pointerType && type2.kind == pointerType)
7937 if(exp.op.op == '+')
7938 Compiler_Error($"cannot add two pointers\n");
7939 else if(exp.op.op == '-')
7941 // Pointer Subtraction gives integer
7942 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
7951 if(type1.type.kind == templateType)
7953 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7956 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7958 ProcessExpressionType(classExp);
7960 exp.type = bracketsExp;
7961 exp.list = MkListOne(MkExpOp(
7962 MkExpBrackets(MkListOne(MkExpOp(
7963 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
7965 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
7967 //MkExpMember(classExp, MkIdentifier("typeSize"))
7969 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7970 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7972 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
7975 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
7976 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7977 MkPointer(null, null), null)))),
7978 MkExpMember(classExp, MkIdentifier("typeSize")))))
7983 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
7992 if(!success && exp.op.exp1.type == constantExp)
7994 // If first expression is constant, try to match that first
7995 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
7997 if(exp.expType) FreeType(exp.expType);
7998 exp.expType = exp.op.exp1.destType;
7999 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8002 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8004 if(exp.expType) FreeType(exp.expType);
8005 exp.expType = exp.op.exp2.destType;
8006 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8012 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8014 if(exp.expType) FreeType(exp.expType);
8015 exp.expType = exp.op.exp2.destType;
8016 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8019 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8021 if(exp.expType) FreeType(exp.expType);
8022 exp.expType = exp.op.exp1.destType;
8023 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8029 char expString1[10240];
8030 char expString2[10240];
8033 expString1[0] = '\0';
8034 expString2[0] = '\0';
8039 PrintExpression(exp.op.exp1, expString1);
8040 ChangeCh(expString1, '\n', ' ');
8041 PrintExpression(exp.op.exp2, expString2);
8042 ChangeCh(expString2, '\n', ' ');
8043 PrintType(exp.op.exp1.expType, type1, false, true);
8044 PrintType(exp.op.exp2.expType, type2, false, true);
8047 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8051 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8052 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8054 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8055 // Convert e.g. / 4 into / 4.0
8056 exp.op.exp1.destType = type2._class.registered.dataType;
8057 if(type2._class.registered.dataType)
8058 type2._class.registered.dataType.refCount++;
8059 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8060 exp.expType = type2;
8061 if(type2) type2.refCount++;
8063 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8065 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8066 // Convert e.g. / 4 into / 4.0
8067 exp.op.exp2.destType = type1._class.registered.dataType;
8068 if(type1._class.registered.dataType)
8069 type1._class.registered.dataType.refCount++;
8070 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8071 exp.expType = type1;
8072 if(type1) type1.refCount++;
8078 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8080 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8082 if(!type1._class.registered.dataType)
8083 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8084 exp.op.exp2.destType = type1._class.registered.dataType;
8085 exp.op.exp2.destType.refCount++;
8087 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8088 type2 = exp.op.exp2.destType;
8090 exp.expType = type2;
8094 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8096 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8098 if(!type2._class.registered.dataType)
8099 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8100 exp.op.exp1.destType = type2._class.registered.dataType;
8101 exp.op.exp1.destType.refCount++;
8103 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8104 type1 = exp.op.exp1.destType;
8105 exp.expType = type1;
8109 // TESTING THIS NEW CODE
8110 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8112 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8114 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8116 if(exp.expType) FreeType(exp.expType);
8117 exp.expType = exp.op.exp1.expType;
8118 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8123 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8125 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8127 if(exp.expType) FreeType(exp.expType);
8128 exp.expType = exp.op.exp2.expType;
8129 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8137 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8138 exp.op.exp2.destType = type1;
8142 // Maybe this was meant to be an enum...
8143 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8145 Type oldType = exp.op.exp2.expType;
8146 exp.op.exp2.expType = null;
8147 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8150 exp.op.exp2.expType = oldType;
8155 // TESTING THIS HERE... LATEST ADDITION
8156 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8158 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8159 exp.op.exp2.destType = type2._class.registered.dataType;
8160 if(type2._class.registered.dataType)
8161 type2._class.registered.dataType.refCount++;
8162 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8164 //exp.expType = type2._class.registered.dataType; //type2;
8165 //if(type2) type2.refCount++;
8168 // TESTING THIS HERE... LATEST ADDITION
8169 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8171 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8172 exp.op.exp1.destType = type1._class.registered.dataType;
8173 if(type1._class.registered.dataType)
8174 type1._class.registered.dataType.refCount++;
8175 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8176 exp.expType = type1._class.registered.dataType; //type1;
8177 if(type1) type1.refCount++;
8181 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8183 if(exp.expType) FreeType(exp.expType);
8184 exp.expType = exp.op.exp2.destType;
8185 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8187 else if(type1 && type2)
8189 char expString1[10240];
8190 char expString2[10240];
8191 char type1String[1024];
8192 char type2String[1024];
8193 expString1[0] = '\0';
8194 expString2[0] = '\0';
8195 type1String[0] = '\0';
8196 type2String[0] = '\0';
8199 PrintExpression(exp.op.exp1, expString1);
8200 ChangeCh(expString1, '\n', ' ');
8201 PrintExpression(exp.op.exp2, expString2);
8202 ChangeCh(expString2, '\n', ' ');
8203 PrintType(exp.op.exp1.expType, type1String, false, true);
8204 PrintType(exp.op.exp2.expType, type2String, false, true);
8207 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8209 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8211 exp.expType = exp.op.exp1.expType;
8212 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8214 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8216 exp.expType = exp.op.exp2.expType;
8217 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8224 // Maybe this was meant to be an enum...
8225 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8227 Type oldType = exp.op.exp1.expType;
8228 exp.op.exp1.expType = null;
8229 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8232 exp.op.exp1.expType = oldType;
8235 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8236 exp.op.exp1.destType = type2;
8239 // TESTING THIS HERE... LATEST ADDITION
8240 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8242 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8243 exp.op.exp1.destType = type1._class.registered.dataType;
8244 if(type1._class.registered.dataType)
8245 type1._class.registered.dataType.refCount++;
8248 // TESTING THIS HERE... LATEST ADDITION
8249 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8251 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8252 exp.op.exp2.destType = type2._class.registered.dataType;
8253 if(type2._class.registered.dataType)
8254 type2._class.registered.dataType.refCount++;
8258 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8260 if(exp.expType) FreeType(exp.expType);
8261 exp.expType = exp.op.exp1.destType;
8262 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8266 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8268 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8270 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8271 // Convert e.g. / 4 into / 4.0
8272 exp.op.exp1.destType = type2._class.registered.dataType;
8273 if(type2._class.registered.dataType)
8274 type2._class.registered.dataType.refCount++;
8275 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8277 if(exp.op.op == '!')
8279 exp.expType = MkClassType("bool");
8280 exp.expType.truth = true;
8284 exp.expType = type2;
8285 if(type2) type2.refCount++;
8288 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8290 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8292 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8293 // Convert e.g. / 4 into / 4.0
8294 exp.op.exp2.destType = type1._class.registered.dataType;
8295 if(type1._class.registered.dataType)
8296 type1._class.registered.dataType.refCount++;
8297 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8299 exp.expType = type1;
8300 if(type1) type1.refCount++;
8305 if(exp.op.exp1 && !exp.op.exp1.expType)
8307 char expString[10000];
8308 expString[0] = '\0';
8311 PrintExpression(exp.op.exp1, expString);
8312 ChangeCh(expString, '\n', ' ');
8315 Compiler_Error($"couldn't determine type of %s\n", expString);
8317 if(exp.op.exp2 && !exp.op.exp2.expType)
8319 char expString[10240];
8320 expString[0] = '\0';
8323 PrintExpression(exp.op.exp2, expString);
8324 ChangeCh(expString, '\n', ' ');
8327 Compiler_Error($"couldn't determine type of %s\n", expString);
8332 FreeType(exp.expType);
8333 exp.expType = MkClassType("bool");
8334 exp.expType.truth = true;
8337 if(exp.op.op != SIZEOF)
8338 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8339 (!exp.op.exp2 || exp.op.exp2.isConstant);
8341 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8343 DeclareType(exp.op.exp2.expType, false, false);
8352 case extensionExpressionExp:
8355 exp.isConstant = true;
8356 for(e = exp.list->first; e; e = e.next)
8361 FreeType(e.destType);
8362 e.destType = exp.destType;
8363 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8365 ProcessExpressionType(e);
8367 exp.destType.count--;
8368 if(!exp.expType && !e.next)
8370 exp.expType = e.expType;
8371 if(e.expType) e.expType.refCount++;
8374 exp.isConstant = false;
8377 // In case a cast became a member...
8378 e = exp.list->first;
8379 if(!e.next && e.type == memberExp)
8381 // Preserve prev, next
8382 Expression next = exp.next, prev = exp.prev;
8385 FreeType(exp.expType);
8386 FreeType(exp.destType);
8396 ProcessExpressionType(exp);
8403 exp.isConstant = true;
8405 ProcessExpressionType(exp.index.exp);
8406 if(!exp.index.exp.isConstant)
8407 exp.isConstant = false;
8409 if(exp.index.exp.expType)
8411 Type source = exp.index.exp.expType;
8412 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8413 eClass_IsDerived(source._class.registered, containerClass) &&
8414 source._class.registered.templateArgs)
8416 Class _class = source._class.registered;
8417 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8419 if(exp.index.index && exp.index.index->last)
8421 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8426 for(e = exp.index.index->first; e; e = e.next)
8428 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8430 if(e.destType) FreeType(e.destType);
8431 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8433 ProcessExpressionType(e);
8436 // Check if this type is int
8439 exp.isConstant = false;
8443 exp.expType = Dereference(exp.index.exp.expType);
8445 DeclareType(exp.expType, false, false);
8452 Type methodType = null;
8458 PrintExpression(exp.call.exp, name);
8459 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8461 //exp.call.exp.expType = null;
8462 PrintExpression(exp.call.exp, name);
8465 if(exp.call.exp.type == identifierExp)
8467 Expression idExp = exp.call.exp;
8468 Identifier id = idExp.identifier;
8469 if(!strcmp(id.string, "__ENDIAN_PAD"))
8471 exp.expType = ProcessTypeString("int", true);
8472 if(exp.call.arguments && exp.call.arguments->first)
8473 ProcessExpressionType(exp.call.arguments->first);
8476 else if(!strcmp(id.string, "Max") ||
8477 !strcmp(id.string, "Min") ||
8478 !strcmp(id.string, "Sgn") ||
8479 !strcmp(id.string, "Abs"))
8481 Expression a = null;
8482 Expression b = null;
8483 Expression tempExp1 = null, tempExp2 = null;
8484 if((!strcmp(id.string, "Max") ||
8485 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8487 a = exp.call.arguments->first;
8488 b = exp.call.arguments->last;
8492 else if(exp.call.arguments->count == 1)
8494 a = exp.call.arguments->first;
8500 exp.call.arguments->Clear();
8501 idExp.identifier = null;
8503 FreeExpContents(exp);
8505 ProcessExpressionType(a);
8507 ProcessExpressionType(b);
8509 exp.type = bracketsExp;
8510 exp.list = MkList();
8512 if(a.expType && (!b || b.expType))
8514 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8516 // Use the simpleStruct name/ids for now...
8519 OldList * specs = MkList();
8520 OldList * decls = MkList();
8522 char temp1[1024], temp2[1024];
8524 GetTypeSpecs(a.expType, specs);
8526 if(a && !a.isConstant && a.type != identifierExp)
8528 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8529 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8530 tempExp1 = QMkExpId(temp1);
8531 tempExp1.expType = a.expType;
8533 a.expType.refCount++;
8534 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8536 if(b && !b.isConstant && b.type != identifierExp)
8538 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8539 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8540 tempExp2 = QMkExpId(temp2);
8541 tempExp2.expType = b.expType;
8543 b.expType.refCount++;
8544 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8547 decl = MkDeclaration(specs, decls);
8548 if(!curCompound.compound.declarations)
8549 curCompound.compound.declarations = MkList();
8550 curCompound.compound.declarations->Insert(null, decl);
8555 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8557 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8559 MkExpCondition(MkExpBrackets(MkListOne(
8560 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8561 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8562 exp.expType = a.expType;
8564 a.expType.refCount++;
8566 else if(!strcmp(id.string, "Abs"))
8569 MkExpCondition(MkExpBrackets(MkListOne(
8570 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8571 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8572 exp.expType = a.expType;
8574 a.expType.refCount++;
8576 else if(!strcmp(id.string, "Sgn"))
8578 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8580 MkExpCondition(MkExpBrackets(MkListOne(
8581 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8582 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8583 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8584 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8585 exp.expType = ProcessTypeString("int", false);
8588 FreeExpression(tempExp1);
8589 if(tempExp2) FreeExpression(tempExp2);
8603 if(!exp.call.exp.destType)
8605 exp.call.exp.destType = dummy;
8608 ProcessExpressionType(exp.call.exp);
8609 if(exp.call.exp.destType == dummy)
8612 exp.call.exp.destType = null;
8617 // Check argument types against parameter types
8618 functionType = exp.call.exp.expType;
8620 if(functionType && functionType.kind == TypeKind::methodType)
8622 methodType = functionType;
8623 functionType = methodType.method.dataType;
8625 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8626 // TOCHECK: Instead of doing this here could this be done per param?
8627 if(exp.call.exp.expType.usedClass)
8629 char typeString[1024];
8630 typeString[0] = '\0';
8631 PrintType(functionType, typeString, true, true);
8632 if(strstr(typeString, "thisclass"))
8634 OldList * specs = MkList();
8637 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8639 decl = SpecDeclFromString(typeString, specs, null);
8641 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8642 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8643 exp.call.exp.expType.usedClass))
8644 thisClassParams = false;
8646 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8648 Class backupThisClass = thisClass;
8649 thisClass = exp.call.exp.expType.usedClass;
8650 ProcessDeclarator(decl);
8651 thisClass = backupThisClass;
8654 thisClassParams = true;
8656 functionType = ProcessType(specs, decl);
8657 functionType.refCount = 0;
8658 FinishTemplatesContext(context);
8661 FreeList(specs, FreeSpecifier);
8662 FreeDeclarator(decl);
8666 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8668 Type type = functionType.type;
8669 if(!functionType.refCount)
8671 functionType.type = null;
8672 FreeType(functionType);
8674 //methodType = functionType;
8675 functionType = type;
8677 if(functionType && functionType.kind != TypeKind::functionType)
8679 Compiler_Error($"called object %s is not a function\n", name);
8681 else if(functionType)
8683 bool emptyParams = false, noParams = false;
8684 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8685 Type type = functionType.params.first;
8686 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8688 Location oldyylloc = yylloc;
8690 if(!type) emptyParams = true;
8693 if(functionType.extraParam && e)
8695 e.destType = MkClassType(functionType.thisClass.string);
8699 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8700 if(!functionType.staticMethod)
8702 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8703 memberExp.member.exp.expType._class)
8705 type = MkClassType(memberExp.member.exp.expType._class.string);
8710 type = functionType.params.first;
8715 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8717 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8722 type = functionType.params.first;
8730 if(type && type.kind == voidType)
8733 if(!type.refCount) FreeType(type);
8737 for( ; e; e = e.next)
8739 if(!type && !emptyParams)
8742 if(methodType && methodType.methodClass)
8743 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8744 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8745 noParams ? 0 : functionType.params.count);
8747 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8748 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8749 noParams ? 0 : functionType.params.count);
8753 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8755 Type templatedType = null;
8756 Class _class = methodType.usedClass;
8757 ClassTemplateParameter curParam = null;
8759 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8762 for(sClass = _class; sClass; sClass = sClass.base)
8764 if(sClass.templateClass) sClass = sClass.templateClass;
8766 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8768 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8771 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8773 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8774 id += nextClass.templateParams.count;
8783 if(curParam && _class.templateArgs[id].dataTypeString)
8785 ClassTemplateArgument arg = _class.templateArgs[id];
8787 Context context = SetupTemplatesContext(_class);
8790 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8791 templatedType = ProcessTypeString(arg.dataTypeString, false);
8792 FinishTemplatesContext(context);
8794 e.destType = templatedType;
8797 templatedType.passAsTemplate = true;
8798 // templatedType.refCount++;
8804 if(type) type.refCount++;
8810 if(type) type.refCount++;
8812 // Don't reach the end for the ellipsis
8813 if(type && type.kind != ellipsisType)
8815 Type next = type.next;
8816 if(!type.refCount) FreeType(type);
8821 if(type && type.kind != ellipsisType)
8823 if(methodType && methodType.methodClass)
8824 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8825 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8826 functionType.params.count + extra);
8828 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8829 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8830 functionType.params.count + extra);
8833 if(type && !type.refCount) FreeType(type);
8840 kind = TypeKind::functionType;
8843 if(exp.call.exp.type == identifierExp)
8845 char * string = exp.call.exp.identifier.string;
8849 Location oldyylloc = yylloc;
8851 yylloc = exp.call.exp.identifier.loc;
8852 if(strstr(string, "__builtin_") == string);
8854 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8855 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8856 globalContext.symbols.Add((BTNode)symbol);
8857 if(strstr(symbol.string, "::"))
8858 globalContext.hasNameSpace = true;
8863 else if(exp.call.exp.type == memberExp)
8865 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8866 exp.call.exp.member.member.string);*/
8869 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8871 if(!functionType.returnType)
8873 functionType.returnType = Type
8880 if(functionType && functionType.kind == TypeKind::functionType)
8882 exp.expType = functionType.returnType;
8884 if(functionType.returnType)
8885 functionType.returnType.refCount++;
8887 if(!functionType.refCount)
8888 FreeType(functionType);
8891 if(exp.call.arguments)
8893 for(e = exp.call.arguments->first; e; e = e.next)
8895 Type destType = e.destType;
8896 ProcessExpressionType(e);
8904 Location oldyylloc = yylloc;
8905 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
8906 exp.thisPtr = thisPtr;
8908 // DOING THIS LATER NOW...
8909 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
8911 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
8912 /* TODO: Name Space Fix ups
8913 if(!exp.member.member.classSym)
8914 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
8918 ProcessExpressionType(exp.member.exp);
8919 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
8920 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
8922 exp.isConstant = false;
8925 exp.isConstant = exp.member.exp.isConstant;
8926 type = exp.member.exp.expType;
8930 if(type && (type.kind == templateType))
8932 Class _class = thisClass ? thisClass : currentClass;
8933 ClassTemplateParameter param = null;
8936 for(param = _class.templateParams.first; param; param = param.next)
8938 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
8942 if(param && param.defaultArg.member)
8944 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
8947 Expression expMember = exp.member.exp;
8949 OldList * specs = MkList();
8950 char thisClassTypeString[1024];
8952 FreeIdentifier(exp.member.member);
8954 ProcessExpressionType(argExp);
8957 char * colon = strstr(param.defaultArg.memberString, "::");
8960 char className[1024];
8963 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
8964 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
8967 strcpy(thisClassTypeString, _class.fullName);
8970 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
8972 exp.expType = ProcessType(specs, decl);
8973 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
8975 Class expClass = exp.expType._class.registered;
8976 Class cClass = null;
8981 char templateString[1024];
8982 ClassTemplateParameter param;
8983 sprintf(templateString, "%s<", expClass.templateClass.fullName);
8984 for(cClass = expClass; cClass; cClass = cClass.base)
8987 for(param = cClass.templateParams.first; param; param = param.next)
8991 ClassTemplateArgument arg;
8992 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
8993 arg = expClass.templateArgs[id];
8995 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
8997 ClassTemplateParameter cParam;
8998 //int p = numParams - sClass.templateParams.count;
9001 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9003 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9005 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9007 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9009 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9010 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9022 strcat(argument, arg.name.string);
9023 strcat(argument, " = ");
9029 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9030 char expString[1024];
9031 OldList * specs = MkList();
9032 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9034 char * string = PrintHexUInt64(arg.expression.ui64);
9035 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9037 ProcessExpressionType(exp);
9038 ComputeExpression(exp);
9039 expString[0] = '\0';
9040 PrintExpression(exp, expString);
9041 strcat(argument, expString);
9043 FreeExpression(exp);
9048 strcat(argument, arg.member.name);
9051 case TemplateParameterType::type:
9053 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9055 if(!strcmp(arg.dataTypeString, "thisclass"))
9056 strcat(argument, thisClassTypeString);
9058 strcat(argument, arg.dataTypeString);
9065 if(paramCount) strcat(templateString, ", ");
9066 if(lastParam != p - 1)
9068 strcat(templateString, param.name);
9069 strcat(templateString, " = ");
9071 strcat(templateString, argument);
9080 int len = strlen(templateString);
9081 if(templateString[len-1] == '>') templateString[len++] = ' ';
9082 templateString[len++] = '>';
9083 templateString[len++] = '\0';
9086 Context context = SetupTemplatesContext(_class);
9087 FreeType(exp.expType);
9088 exp.expType = ProcessTypeString(templateString, false);
9089 FinishTemplatesContext(context);
9093 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9094 exp.type = bracketsExp;
9095 exp.list = MkListOne(MkExpOp(null, '*',
9100 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9101 MkExpBrackets(MkListOne(
9102 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9104 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9106 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9111 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9112 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9114 type = ProcessTemplateParameterType(type.templateParameter);
9118 if(type && (type.kind == templateType));
9119 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9121 Identifier id = exp.member.member;
9122 TypeKind typeKind = type.kind;
9123 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9124 if(typeKind == subClassType && exp.member.exp.type == classExp)
9126 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9127 typeKind = classType;
9130 if(id && (typeKind == intType || typeKind == enumType))
9131 _class = eSystem_FindClass(privateModule, "int");
9136 (exp.member.exp.type == identifierExp &&
9137 !strcmp(exp.member.exp.identifier.string, "this"));*/
9138 Property prop = null;
9139 Method method = null;
9140 DataMember member = null;
9141 Property revConvert = null;
9142 ClassProperty classProp = null;
9144 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9145 exp.member.memberType = propertyMember;
9147 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9148 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9150 if(typeKind != subClassType)
9152 // Prioritize data members over properties for "this"
9153 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9155 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9156 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9158 prop = eClass_FindProperty(_class, id.string, privateModule);
9162 if(!member && !prop)
9163 prop = eClass_FindProperty(_class, id.string, privateModule);
9164 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9165 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9166 exp.member.thisPtr = true;
9168 // Prioritize properties over data members otherwise
9171 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9174 prop = eClass_FindProperty(_class, id.string, null);
9175 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9176 member = eClass_FindDataMember(_class, id.string, null, null, null);
9179 if(!prop && !member)
9181 method = eClass_FindMethod(_class, id.string, null);
9184 prop = eClass_FindProperty(_class, id.string, privateModule);
9185 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9186 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9192 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9199 if(!prop && !member)
9200 method = eClass_FindMethod(_class, id.string, privateModule);
9201 if(!prop && !member && !method)
9203 if(typeKind == subClassType)
9205 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9208 exp.member.memberType = classPropertyMember;
9209 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9213 // Assume this is a class_data member
9214 char structName[1024];
9215 Identifier id = exp.member.member;
9216 Expression classExp = exp.member.exp;
9219 FreeType(classExp.expType);
9220 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9222 strcpy(structName, "__ecereClassData_");
9223 FullClassNameCat(structName, type._class.string, false);
9224 exp.type = pointerExp;
9225 exp.member.member = id;
9227 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9228 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9229 MkExpBrackets(MkListOne(MkExpOp(
9230 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9231 MkExpMember(classExp, MkIdentifier("data"))), '+',
9232 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9237 ProcessExpressionType(exp);
9243 // Check for reverse conversion
9244 // (Convert in an instantiation later, so that we can use
9245 // deep properties system)
9246 Symbol classSym = FindClass(id.string);
9249 Class convertClass = classSym.registered;
9251 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9258 exp.member.memberType = propertyMember;
9260 ProcessPropertyType(prop);
9261 exp.expType = prop.dataType;
9262 if(prop.dataType) prop.dataType.refCount++;
9266 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9268 FreeExpContents(exp);
9269 exp.type = identifierExp;
9270 exp.identifier = MkIdentifier("class");
9271 ProcessExpressionType(exp);
9275 exp.member.memberType = dataMember;
9276 DeclareStruct(_class.fullName, false);
9277 if(!member.dataType)
9279 Context context = SetupTemplatesContext(_class);
9280 member.dataType = ProcessTypeString(member.dataTypeString, false);
9281 FinishTemplatesContext(context);
9283 exp.expType = member.dataType;
9284 if(member.dataType) member.dataType.refCount++;
9288 exp.member.memberType = reverseConversionMember;
9289 exp.expType = MkClassType(revConvert._class.fullName);
9297 exp.type = identifierExp;
9298 exp.identifier = exp.member.member;
9301 exp.member.memberType = methodMember;
9303 if(!method.dataType)
9304 ProcessMethodType(method);
9312 // Tricky spot here... To use instance versus class virtual table
9313 // Put it back to what it was... What did we break?
9315 // Had to put it back for overriding Main of Thread global instance
9317 //exp.expType.methodClass = _class;
9318 exp.expType.methodClass = (id && id._class) ? _class : null;
9320 // Need the actual class used for templated classes
9321 exp.expType.usedClass = _class;
9325 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9327 FreeExpContents(exp);
9328 exp.type = identifierExp;
9329 exp.identifier = MkIdentifier("class");
9330 ProcessExpressionType(exp);
9333 yylloc = exp.member.member.loc;
9334 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9336 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9339 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9344 while(tClass && !tClass.templateClass) tClass = tClass.base;
9346 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9349 ClassTemplateParameter curParam = null;
9352 for(sClass = tClass; sClass; sClass = sClass.base)
9355 if(sClass.templateClass) sClass = sClass.templateClass;
9356 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9358 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9360 for(sClass = sClass.base; sClass; sClass = sClass.base)
9361 id += sClass.templateParams.count;
9369 if(curParam && tClass.templateArgs[id].dataTypeString)
9371 ClassTemplateArgument arg = tClass.templateArgs[id];
9372 Context context = SetupTemplatesContext(tClass);
9374 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9375 FreeType(exp.expType);
9376 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9379 if(exp.expType.kind == thisClassType)
9381 FreeType(exp.expType);
9382 exp.expType = ReplaceThisClassType(_class);
9385 if(tClass.templateClass)
9386 exp.expType.passAsTemplate = true;
9387 //exp.expType.refCount++;
9390 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9391 //exp.destType.refCount++;
9393 if(exp.destType.kind == thisClassType)
9395 FreeType(exp.destType);
9396 exp.destType = ReplaceThisClassType(_class);
9400 FinishTemplatesContext(context);
9403 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9404 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9407 ClassTemplateParameter curParam = null;
9410 for(sClass = tClass; sClass; sClass = sClass.base)
9413 if(sClass.templateClass) sClass = sClass.templateClass;
9414 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9416 if(curParam.type == TemplateParameterType::type &&
9417 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9419 for(sClass = sClass.base; sClass; sClass = sClass.base)
9420 id += sClass.templateParams.count;
9430 ClassTemplateArgument arg = tClass.templateArgs[id];
9431 Context context = SetupTemplatesContext(tClass);
9434 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9436 basicType = ProcessTypeString(arg.dataTypeString, false);
9439 if(basicType.kind == thisClassType)
9441 FreeType(basicType);
9442 basicType = ReplaceThisClassType(_class);
9445 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9446 if(tClass.templateClass)
9447 basicType.passAsTemplate = true;
9450 FreeType(exp.expType);
9452 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9453 //exp.expType.refCount++;
9456 exp.destType = exp.expType;
9457 exp.destType.refCount++;
9461 Expression newExp { };
9462 OldList * specs = MkList();
9464 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9466 if(exp.destType) exp.destType.refCount++;
9467 if(exp.expType) exp.expType.refCount++;
9469 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9470 exp.cast.exp = newExp;
9471 //FreeType(exp.expType);
9472 //exp.expType = null;
9473 //ProcessExpressionType(sourceExp);
9476 FinishTemplatesContext(context);
9479 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9481 Class expClass = exp.expType._class.registered;
9484 Class cClass = null;
9489 char templateString[1024];
9490 ClassTemplateParameter param;
9491 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9492 while(cClass != expClass)
9495 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9498 for(param = cClass.templateParams.first; param; param = param.next)
9500 Class cClassCur = null;
9503 ClassTemplateParameter paramCur = null;
9504 ClassTemplateArgument arg;
9505 while(cClassCur != tClass && !paramCur)
9508 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9509 cClassCur = sClassCur;
9511 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9513 if(!strcmp(paramCur.name, param.name))
9521 if(paramCur && paramCur.type == TemplateParameterType::type)
9522 arg = tClass.templateArgs[cp];
9524 arg = expClass.templateArgs[p];
9531 strcat(argument, arg.name.string);
9532 strcat(argument, " = ");
9538 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9539 char expString[1024];
9540 OldList * specs = MkList();
9541 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9543 char * string = PrintHexUInt64(arg.expression.ui64);
9544 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9546 ProcessExpressionType(exp);
9547 ComputeExpression(exp);
9548 expString[0] = '\0';
9549 PrintExpression(exp, expString);
9550 strcat(argument, expString);
9552 FreeExpression(exp);
9557 strcat(argument, arg.member.name);
9560 case TemplateParameterType::type:
9562 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9563 strcat(argument, arg.dataTypeString);
9569 if(paramCount) strcat(templateString, ", ");
9570 if(lastParam != p - 1)
9572 strcat(templateString, param.name);
9573 strcat(templateString, " = ");
9575 strcat(templateString, argument);
9584 int len = strlen(templateString);
9585 if(templateString[len-1] == '>') templateString[len++] = ' ';
9586 templateString[len++] = '>';
9587 templateString[len++] = '\0';
9590 FreeType(exp.expType);
9592 Context context = SetupTemplatesContext(tClass);
9593 exp.expType = ProcessTypeString(templateString, false);
9594 FinishTemplatesContext(context);
9601 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9603 else if(type && (type.kind == structType || type.kind == unionType))
9605 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9608 exp.expType = memberType;
9610 memberType.refCount++;
9615 char expString[10240];
9616 expString[0] = '\0';
9617 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9618 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9621 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9623 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9625 Identifier id = exp.member.member;
9626 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9629 FreeType(exp.expType);
9630 exp.expType = ReplaceThisClassType(_class);
9637 // Convert x->y into (*x).y
9640 Type destType = exp.destType;
9642 // DOING THIS LATER NOW...
9643 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9645 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9646 /* TODO: Name Space Fix ups
9647 if(!exp.member.member.classSym)
9648 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9652 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9653 exp.type = memberExp;
9656 ProcessExpressionType(exp);
9663 //ComputeExpression(exp);
9665 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9666 if(classSym && classSym.registered)
9668 if(classSym.registered.type == noHeadClass)
9672 DeclareStruct(classSym.string, false);
9673 FreeSpecifier(exp._class);
9674 exp.type = typeSizeExp;
9675 FullClassNameCat(name, classSym.string, false);
9676 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9680 if(classSym.registered.fixed)
9682 FreeSpecifier(exp._class);
9683 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9684 exp.type = constantExp;
9688 char className[1024];
9689 strcpy(className, "__ecereClass_");
9690 FullClassNameCat(className, classSym.string, true);
9691 MangleClassName(className);
9693 DeclareClass(classSym, className);
9695 FreeExpContents(exp);
9696 exp.type = pointerExp;
9697 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9698 exp.member.member = MkIdentifier("structSize");
9708 // exp.isConstant = true;
9713 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9720 exp.isConstant = true;
9722 DeclareType(type, false, false);
9728 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9730 FreeType(exp.cast.exp.destType);
9731 exp.cast.exp.destType = type;
9733 ProcessExpressionType(exp.cast.exp);
9738 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9739 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9741 void * prev = exp.prev, * next = exp.next;
9742 Type expType = exp.cast.exp.destType;
9743 Expression castExp = exp.cast.exp;
9744 Type destType = exp.destType;
9746 if(expType) expType.refCount++;
9748 //FreeType(exp.destType);
9749 FreeType(exp.expType);
9750 FreeTypeName(exp.cast.typeName);
9753 FreeType(exp.expType);
9754 FreeType(exp.destType);
9756 exp.expType = expType;
9757 exp.destType = destType;
9767 exp.isConstant = exp.cast.exp.isConstant;
9772 case extensionInitializerExp:
9774 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9777 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9778 // ProcessInitializer(exp.initializer.initializer, type);
9784 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9785 ProcessExpressionType(exp.vaArg.exp);
9793 exp.isConstant = true;
9795 FreeType(exp.cond.cond.destType);
9796 exp.cond.cond.destType = MkClassType("bool");
9797 exp.cond.cond.destType.truth = true;
9798 ProcessExpressionType(exp.cond.cond);
9799 if(!exp.cond.cond.isConstant)
9800 exp.isConstant = false;
9801 for(e = exp.cond.exp->first; e; e = e.next)
9805 FreeType(e.destType);
9806 e.destType = exp.destType;
9807 if(e.destType) e.destType.refCount++;
9809 ProcessExpressionType(e);
9812 exp.expType = e.expType;
9813 if(e.expType) e.expType.refCount++;
9816 exp.isConstant = false;
9819 FreeType(exp.cond.elseExp.destType);
9820 // Added this check if we failed to find an expType
9821 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9824 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9826 if(exp.cond.elseExp.destType)
9827 exp.cond.elseExp.destType.refCount++;
9828 ProcessExpressionType(exp.cond.elseExp);
9830 // FIXED THIS: Was done before calling process on elseExp
9831 if(!exp.cond.elseExp.isConstant)
9832 exp.isConstant = false;
9835 case extensionCompoundExp:
9837 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9839 Statement last = exp.compound.compound.statements->last;
9840 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9842 ((Expression)last.expressions->last).destType = exp.destType;
9844 exp.destType.refCount++;
9846 ProcessStatement(exp.compound);
9847 exp.expType = ((Expression)last.expressions->last).expType;
9848 if(((Expression)last.expressions->last).expType)
9849 exp.expType.refCount++;
9855 Specifier spec = exp._classExp.specifiers->first;
9856 if(spec && spec.type == nameSpecifier)
9858 exp.expType = MkClassType(spec.name);
9859 exp.expType.kind = subClassType;
9860 exp.byReference = true;
9864 exp.expType = MkClassType("ecere::com::Class");
9865 exp.byReference = true;
9871 Class _class = thisClass ? thisClass : currentClass;
9874 Identifier id = exp.classData.id;
9875 char structName[1024];
9876 Expression classExp;
9877 strcpy(structName, "__ecereClassData_");
9878 FullClassNameCat(structName, _class.fullName, false);
9879 exp.type = pointerExp;
9880 exp.member.member = id;
9881 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9882 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9884 classExp = MkExpIdentifier(MkIdentifier("class"));
9886 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9887 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9888 MkExpBrackets(MkListOne(MkExpOp(
9889 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9890 MkExpMember(classExp, MkIdentifier("data"))), '+',
9891 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
9894 ProcessExpressionType(exp);
9902 char * typeString = null;
9903 char typeStringBuf[1024];
9904 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
9905 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
9907 Class templateClass = exp.destType._class.registered;
9908 typeString = templateClass.templateArgs[2].dataTypeString;
9912 // Guess type from expressions in the array
9914 for(e = exp.list->first; e; e = e.next)
9916 ProcessExpressionType(e);
9919 if(!type) { type = e.expType; type.refCount++; }
9922 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
9923 if(!MatchTypeExpression(e, type, null, false))
9929 e = exp.list->first;
9930 ProcessExpressionType(e);
9933 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
9934 if(!MatchTypeExpression(e, type, null, false))
9936 FreeType(e.expType);
9947 FreeType(e.expType);
9954 typeStringBuf[0] = '\0';
9955 PrintType(type, typeStringBuf, false, true);
9956 typeString = typeStringBuf;
9964 (Container)& (struct BuiltInContainer)
9966 ._vTbl = class(BuiltInContainer)._vTbl,
9967 ._class = class(BuiltInContainer),
9969 .data = (int[]){ 1, 7, 3, 4, 5 },
9974 char templateString[1024];
9975 OldList * initializers = MkList();
9976 OldList * structInitializers = MkList();
9977 OldList * specs = MkList();
9979 Declarator decl = SpecDeclFromString(typeString, specs, null);
9980 sprintf(templateString, "Container<%s>", typeString);
9985 type = ProcessTypeString(typeString, false);
9986 while(e = exp.list->first)
9988 exp.list->Remove(e);
9991 ProcessExpressionType(e);
9992 ListAdd(initializers, MkInitializerAssignment(e));
9998 DeclareStruct("ecere::com::BuiltInContainer", false);
10000 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10001 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10002 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10003 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10004 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10005 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10006 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10007 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10008 MkInitializerList(initializers))));
10009 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10010 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10011 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10012 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10013 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10014 exp.expType = ProcessTypeString(templateString, false);
10015 exp.type = bracketsExp;
10016 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10018 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10019 MkInitializerList(structInitializers)))));
10020 ProcessExpressionType(expExt);
10024 exp.expType = ProcessTypeString("Container", false);
10025 Compiler_Error($"Couldn't determine type of array elements\n");
10031 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10033 FreeType(exp.expType);
10034 exp.expType = ReplaceThisClassType(thisClass);
10037 // Resolve structures here
10038 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10040 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10041 // TODO: Fix members reference...
10044 if(exp.expType.kind != enumType)
10047 String enumName = CopyString(exp.expType.enumName);
10049 // Fixed a memory leak on self-referencing C structs typedefs
10050 // by instantiating a new type rather than simply copying members
10051 // into exp.expType
10052 FreeType(exp.expType);
10053 exp.expType = Type { };
10054 exp.expType.kind = symbol.type.kind;
10055 exp.expType.refCount++;
10056 exp.expType.enumName = enumName;
10058 exp.expType.members = symbol.type.members;
10059 for(member = symbol.type.members.first; member; member = member.next)
10065 for(member = symbol.type.members.first; member; member = member.next)
10067 NamedLink value { name = CopyString(member.name) };
10068 exp.expType.members.Add(value);
10075 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10076 else if(exp.destType && !exp.destType.keepCast)
10078 if(!CheckExpressionType(exp, exp.destType, false))
10080 if(!exp.destType.count || unresolved)
10085 if(exp.destType.kind != ellipsisType)
10091 char expString[10240];
10092 expString[0] = '\0';
10094 PrintType(exp.destType, type2, false, true);
10096 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10098 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10099 else if(exp.type != dummyExp)
10100 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10105 char expString[10240] ;
10106 expString[0] = '\0';
10107 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10110 Compiler_Error($"unresolved identifier %s\n", expString);
10111 else if(exp.type != dummyExp)
10112 Compiler_Error($"couldn't determine type of %s\n", expString);
10123 PrintType(exp.expType, type1, false, true);
10124 PrintType(exp.destType, type2, false, true);
10127 //CheckExpressionType(exp, exp.destType, false);
10129 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10130 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10131 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10134 char expString[10240];
10135 expString[0] = '\0';
10136 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10139 CheckExpressionType(exp, exp.destType, false);
10141 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10143 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10144 FreeType(exp.expType);
10145 exp.destType.refCount++;
10146 exp.expType = exp.destType;
10151 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10153 Expression newExp { };
10154 char typeString[1024];
10155 OldList * specs = MkList();
10158 typeString[0] = '\0';
10162 if(exp.expType) exp.expType.refCount++;
10163 if(exp.expType) exp.expType.refCount++;
10164 exp.type = castExp;
10165 newExp.destType = exp.expType;
10167 PrintType(exp.expType, typeString, false, false);
10168 decl = SpecDeclFromString(typeString, specs, null);
10170 exp.cast.typeName = MkTypeName(specs, decl);
10171 exp.cast.exp = newExp;
10174 else if(unresolved)
10176 if(exp.identifier._class && exp.identifier._class.name)
10177 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10178 else if(exp.identifier.string && exp.identifier.string[0])
10179 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10181 else if(!exp.expType && exp.type != dummyExp)
10183 char expString[10240];
10184 expString[0] = '\0';
10185 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10186 Compiler_Error($"couldn't determine type of %s\n", expString);
10189 // Let's try to support any_object & typed_object here:
10190 ApplyAnyObjectLogic(exp);
10192 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10193 exp.expType._class.registered.type == noHeadClass)
10195 exp.byReference = true;
10197 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10198 exp.destType._class.registered.type == noHeadClass)
10200 exp.byReference = true;
10202 yylloc = oldyylloc;
10205 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10207 // THIS CODE WILL FIND NEXT MEMBER...
10210 *curMember = (*curMember).next;
10212 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10214 *curMember = subMemberStack[--(*subMemberStackPos)];
10215 *curMember = (*curMember).next;
10218 // SKIP ALL PROPERTIES HERE...
10219 while((*curMember) && (*curMember).isProperty)
10220 *curMember = (*curMember).next;
10222 if(subMemberStackPos)
10224 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10226 subMemberStack[(*subMemberStackPos)++] = *curMember;
10228 *curMember = (*curMember).members.first;
10229 while(*curMember && (*curMember).isProperty)
10230 *curMember = (*curMember).next;
10238 if(subMemberStackPos && *subMemberStackPos)
10240 *curMember = subMemberStack[--(*subMemberStackPos)];
10241 *curMember = (*curMember).next;
10245 Class lastCurClass = *curClass;
10247 if(*curClass == _class) break; // REACHED THE END
10249 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10250 *curMember = (*curClass).membersAndProperties.first;
10253 while((*curMember) && (*curMember).isProperty)
10254 *curMember = (*curMember).next;
10255 if(subMemberStackPos)
10257 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10259 subMemberStack[(*subMemberStackPos)++] = *curMember;
10261 *curMember = (*curMember).members.first;
10262 while(*curMember && (*curMember).isProperty)
10263 *curMember = (*curMember).next;
10271 static void ProcessInitializer(Initializer init, Type type)
10275 case expInitializer:
10276 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10278 // TESTING THIS FOR SHUTTING = 0 WARNING
10279 if(init.exp && !init.exp.destType)
10281 FreeType(init.exp.destType);
10282 init.exp.destType = type;
10283 if(type) type.refCount++;
10287 ProcessExpressionType(init.exp);
10288 init.isConstant = init.exp.isConstant;
10294 Expression exp = init.exp;
10295 Instantiation inst = exp.instance;
10296 MembersInit members;
10298 init.type = listInitializer;
10299 init.list = MkList();
10303 for(members = inst.members->first; members; members = members.next)
10305 if(members.type == dataMembersInit)
10308 for(member = members.dataMembers->first; member; member = member.next)
10310 ListAdd(init.list, member.initializer);
10311 member.initializer = null;
10314 // Discard all MembersInitMethod
10317 FreeExpression(exp);
10319 case listInitializer:
10322 Type initializerType = null;
10323 Class curClass = null;
10324 DataMember curMember = null;
10325 DataMember subMemberStack[256];
10326 int subMemberStackPos = 0;
10328 if(type && type.kind == arrayType)
10329 initializerType = Dereference(type);
10330 else if(type && (type.kind == structType || type.kind == unionType))
10331 initializerType = type.members.first;
10333 for(i = init.list->first; i; i = i.next)
10335 if(type && type.kind == classType && type._class && type._class.registered)
10337 // 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)
10338 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10339 // TODO: Generate error on initializing a private data member this way from another module...
10342 if(!curMember.dataType)
10343 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10344 initializerType = curMember.dataType;
10347 ProcessInitializer(i, initializerType);
10348 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10349 initializerType = initializerType.next;
10351 init.isConstant = false;
10354 if(type && type.kind == arrayType)
10355 FreeType(initializerType);
10357 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10359 Compiler_Error($"Assigning list initializer to non list\n");
10366 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10370 case baseSpecifier:
10372 if(spec.specifier == THISCLASS)
10376 spec.type = nameSpecifier;
10377 spec.name = ReplaceThisClass(thisClass);
10378 spec.symbol = FindClass(spec.name);
10379 ProcessSpecifier(spec, declareStruct);
10384 case nameSpecifier:
10386 Symbol symbol = FindType(curContext, spec.name);
10388 DeclareType(symbol.type, true, true);
10389 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10390 DeclareStruct(spec.name, false);
10393 case enumSpecifier:
10398 for(e = spec.list->first; e; e = e.next)
10401 ProcessExpressionType(e.exp);
10406 case structSpecifier:
10407 case unionSpecifier:
10409 if(spec.definitions)
10412 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10414 ProcessClass(spec.definitions, symbol);
10417 for(def = spec.definitions->first; def; def = def.next)
10419 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10420 ProcessDeclaration(def.decl);
10427 case classSpecifier:
10429 Symbol classSym = FindClass(spec.name);
10430 if(classSym && classSym.registered && classSym.registered.type == structClass)
10431 DeclareStruct(spec.name, false);
10439 static void ProcessDeclarator(Declarator decl)
10443 case identifierDeclarator:
10444 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10446 FreeSpecifier(decl.identifier._class);
10447 decl.identifier._class = null;
10450 case arrayDeclarator:
10452 ProcessExpressionType(decl.array.exp);
10453 case structDeclarator:
10454 case bracketsDeclarator:
10455 case functionDeclarator:
10456 case pointerDeclarator:
10457 case extendedDeclarator:
10458 case extendedDeclaratorEnd:
10459 if(decl.declarator)
10460 ProcessDeclarator(decl.declarator);
10461 if(decl.type == functionDeclarator)
10463 Identifier id = GetDeclId(decl);
10464 if(id && id._class)
10468 qualifiers = MkListOne(id._class);
10471 if(!decl.function.parameters)
10472 decl.function.parameters = MkList();
10473 decl.function.parameters->Insert(null, param);
10476 if(decl.function.parameters)
10480 for(param = decl.function.parameters->first; param; param = param.next)
10482 if(param.qualifiers && param.qualifiers->first)
10484 Specifier spec = param.qualifiers->first;
10485 if(spec && spec.specifier == TYPED_OBJECT)
10487 Declarator d = param.declarator;
10490 qualifiers = MkListOne(MkSpecifier(VOID));
10491 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10494 FreeList(param.qualifiers, FreeSpecifier);
10496 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10497 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10499 decl.function.parameters->Insert(param, newParam);
10502 else if(spec && spec.specifier == ANY_OBJECT)
10504 Declarator d = param.declarator;
10506 FreeList(param.qualifiers, FreeSpecifier);
10508 param.qualifiers = MkListOne(MkSpecifier(VOID));
10509 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10511 else if(spec.specifier == THISCLASS)
10515 spec.type = nameSpecifier;
10516 spec.name = ReplaceThisClass(thisClass);
10517 spec.symbol = FindClass(spec.name);
10518 ProcessSpecifier(spec, false);
10523 if(param.declarator)
10524 ProcessDeclarator(param.declarator);
10532 static void ProcessDeclaration(Declaration decl)
10537 case initDeclaration:
10539 bool declareStruct = false;
10541 lineNum = decl.pos.line;
10542 column = decl.pos.col;
10545 if(decl.declarators)
10549 for(d = decl.declarators->first; d; d = d.next)
10551 Type type, subType;
10552 ProcessDeclarator(d.declarator);
10554 type = ProcessType(decl.specifiers, d.declarator);
10558 ProcessInitializer(d.initializer, type);
10560 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10562 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10563 d.initializer.exp.type == instanceExp)
10565 if(type.kind == classType && type._class ==
10566 d.initializer.exp.expType._class)
10568 Instantiation inst = d.initializer.exp.instance;
10569 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10571 d.initializer.exp.instance = null;
10572 if(decl.specifiers)
10573 FreeList(decl.specifiers, FreeSpecifier);
10574 FreeList(decl.declarators, FreeInitDeclarator);
10578 decl.type = instDeclaration;
10583 for(subType = type; subType;)
10585 if(subType.kind == classType)
10587 declareStruct = true;
10590 else if(subType.kind == pointerType)
10592 else if(subType.kind == arrayType)
10593 subType = subType.arrayType;
10603 if(decl.specifiers)
10606 for(s = decl.specifiers->first; s; s = s.next)
10608 ProcessSpecifier(s, declareStruct);
10613 case instDeclaration:
10615 ProcessInstantiationType(decl.inst);
10618 case structDeclaration:
10622 bool declareStruct = false;
10624 if(decl.declarators)
10626 for(d = decl.declarators->first; d; d = d.next)
10628 Type type = ProcessType(decl.specifiers, d.declarator);
10630 ProcessDeclarator(d);
10631 for(subType = type; subType;)
10633 if(subType.kind == classType)
10635 declareStruct = true;
10638 else if(subType.kind == pointerType)
10640 else if(subType.kind == arrayType)
10641 subType = subType.arrayType;
10648 if(decl.specifiers)
10650 for(spec = decl.specifiers->first; spec; spec = spec.next)
10651 ProcessSpecifier(spec, declareStruct);
10658 static FunctionDefinition curFunction;
10660 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10662 char propName[1024], propNameM[1024];
10663 char getName[1024], setName[1024];
10666 DeclareProperty(prop, setName, getName);
10668 // eInstance_FireWatchers(object, prop);
10669 strcpy(propName, "__ecereProp_");
10670 FullClassNameCat(propName, prop._class.fullName, false);
10671 strcat(propName, "_");
10672 // strcat(propName, prop.name);
10673 FullClassNameCat(propName, prop.name, true);
10674 MangleClassName(propName);
10676 strcpy(propNameM, "__ecerePropM_");
10677 FullClassNameCat(propNameM, prop._class.fullName, false);
10678 strcat(propNameM, "_");
10679 // strcat(propNameM, prop.name);
10680 FullClassNameCat(propNameM, prop.name, true);
10681 MangleClassName(propNameM);
10683 if(prop.isWatchable)
10686 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10687 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10688 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10691 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10692 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10693 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10699 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10700 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10701 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10704 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10705 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10706 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10709 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10710 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10711 curFunction.propSet.fireWatchersDone = true;
10714 static void ProcessStatement(Statement stmt)
10718 lineNum = stmt.pos.line;
10719 column = stmt.pos.col;
10724 ProcessStatement(stmt.labeled.stmt);
10727 // This expression should be constant...
10728 if(stmt.caseStmt.exp)
10730 FreeType(stmt.caseStmt.exp.destType);
10731 stmt.caseStmt.exp.destType = curSwitchType;
10732 if(curSwitchType) curSwitchType.refCount++;
10733 ProcessExpressionType(stmt.caseStmt.exp);
10734 ComputeExpression(stmt.caseStmt.exp);
10736 if(stmt.caseStmt.stmt)
10737 ProcessStatement(stmt.caseStmt.stmt);
10741 if(stmt.compound.context)
10746 Statement prevCompound = curCompound;
10747 Context prevContext = curContext;
10749 if(!stmt.compound.isSwitch)
10751 curCompound = stmt;
10752 curContext = stmt.compound.context;
10755 if(stmt.compound.declarations)
10757 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10758 ProcessDeclaration(decl);
10760 if(stmt.compound.statements)
10762 for(s = stmt.compound.statements->first; s; s = s.next)
10763 ProcessStatement(s);
10766 curContext = prevContext;
10767 curCompound = prevCompound;
10771 case expressionStmt:
10774 if(stmt.expressions)
10776 for(exp = stmt.expressions->first; exp; exp = exp.next)
10777 ProcessExpressionType(exp);
10785 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10786 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10787 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10788 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10790 ProcessExpressionType(exp);
10792 if(stmt.ifStmt.stmt)
10793 ProcessStatement(stmt.ifStmt.stmt);
10794 if(stmt.ifStmt.elseStmt)
10795 ProcessStatement(stmt.ifStmt.elseStmt);
10800 Type oldSwitchType = curSwitchType;
10801 if(stmt.switchStmt.exp)
10804 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10814 e.exp.destType = destType;
10817 ProcessExpressionType(exp);
10820 curSwitchType = exp.expType;
10823 ProcessStatement(stmt.switchStmt.stmt);
10824 curSwitchType = oldSwitchType;
10829 if(stmt.whileStmt.exp)
10833 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10834 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10835 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10836 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10838 ProcessExpressionType(exp);
10841 if(stmt.whileStmt.stmt)
10842 ProcessStatement(stmt.whileStmt.stmt);
10847 if(stmt.doWhile.exp)
10851 if(stmt.doWhile.exp->last)
10853 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10854 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10855 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10857 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10859 ProcessExpressionType(exp);
10862 if(stmt.doWhile.stmt)
10863 ProcessStatement(stmt.doWhile.stmt);
10869 if(stmt.forStmt.init)
10870 ProcessStatement(stmt.forStmt.init);
10872 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10874 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10875 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10876 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10879 if(stmt.forStmt.check)
10880 ProcessStatement(stmt.forStmt.check);
10881 if(stmt.forStmt.increment)
10883 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10884 ProcessExpressionType(exp);
10887 if(stmt.forStmt.stmt)
10888 ProcessStatement(stmt.forStmt.stmt);
10893 Identifier id = stmt.forEachStmt.id;
10894 OldList * exp = stmt.forEachStmt.exp;
10895 OldList * filter = stmt.forEachStmt.filter;
10896 Statement block = stmt.forEachStmt.stmt;
10897 char iteratorType[1024];
10900 bool isBuiltin = exp && exp->last &&
10901 (((Expression)exp->last).type == ExpressionType::arrayExp ||
10902 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
10903 Expression arrayExp;
10904 char * typeString = null;
10905 int builtinCount = 0;
10907 for(e = exp ? exp->first : null; e; e = e.next)
10911 FreeType(e.destType);
10912 e.destType = ProcessTypeString("Container", false);
10914 if(!isBuiltin || e.next)
10915 ProcessExpressionType(e);
10918 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
10919 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
10920 eClass_IsDerived(source._class.registered, containerClass)))
10922 Class _class = source ? source._class.registered : null;
10924 Expression expIt = null;
10925 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
10926 Class arrayClass = eSystem_FindClass(privateModule, "Array");
10927 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
10928 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
10929 stmt.type = compoundStmt;
10931 stmt.compound.context = Context { };
10932 stmt.compound.context.parent = curContext;
10933 curContext = stmt.compound.context;
10935 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
10937 Class mapClass = eSystem_FindClass(privateModule, "Map");
10938 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
10939 isCustomAVLTree = true;
10940 if(eClass_IsDerived(source._class.registered, avlTreeClass))
10942 else if(eClass_IsDerived(source._class.registered, mapClass))
10945 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
10946 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
10948 Class listClass = eSystem_FindClass(privateModule, "List");
10950 isList = eClass_IsDerived(source._class.registered, listClass);
10956 OldList * specs = MkList();
10957 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
10958 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
10959 stmt.compound.declarations = MkListOne(
10960 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
10961 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
10962 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
10963 MkInitializerAssignment(MkExpBrackets(exp))))));
10968 char typeStringBuf[1024];
10970 // TODO: Merge this code?
10971 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
10972 if(((Expression)exp->last).type == castExp)
10974 TypeName typeName = ((Expression)exp->last).cast.typeName;
10976 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
10979 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
10980 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
10981 arrayExp.destType._class.registered.templateArgs)
10983 Class templateClass = arrayExp.destType._class.registered;
10984 typeString = templateClass.templateArgs[2].dataTypeString;
10986 else if(arrayExp.list)
10988 // Guess type from expressions in the array
10990 for(e = arrayExp.list->first; e; e = e.next)
10992 ProcessExpressionType(e);
10995 if(!type) { type = e.expType; type.refCount++; }
10998 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10999 if(!MatchTypeExpression(e, type, null, false))
11005 e = arrayExp.list->first;
11006 ProcessExpressionType(e);
11009 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11010 if(!MatchTypeExpression(e, type, null, false))
11012 FreeType(e.expType);
11023 FreeType(e.expType);
11030 typeStringBuf[0] = '\0';
11031 PrintType(type, typeStringBuf, false, true);
11032 typeString = typeStringBuf;
11038 OldList * initializers = MkList();
11040 OldList * specs = MkList();
11045 builtinCount = arrayExp.list->count;
11046 type = ProcessTypeString(typeString, false);
11047 while(e = arrayExp.list->first)
11049 arrayExp.list->Remove(e);
11052 ProcessExpressionType(e);
11053 ListAdd(initializers, MkInitializerAssignment(e));
11056 delete arrayExp.list;
11058 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11059 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11060 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11062 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11063 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11065 FreeList(exp, FreeExpression);
11069 arrayExp.expType = ProcessTypeString("Container", false);
11070 Compiler_Error($"Couldn't determine type of array elements\n");
11075 OldList * specs = MkList();
11077 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11078 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11079 stmt.compound.declarations = MkListOne(
11080 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11081 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11082 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11083 MkInitializerAssignment(MkExpBrackets(exp))))));
11086 else if(isLinkList && !isList)
11089 OldList * specs = MkList();
11090 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11091 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11092 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11093 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11094 MkInitializerAssignment(MkExpBrackets(exp))))));
11096 /*else if(isCustomAVLTree)
11099 OldList * specs = MkList();
11100 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11101 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11102 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11103 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11104 MkInitializerAssignment(MkExpBrackets(exp))))));
11106 else if(_class.templateArgs)
11109 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11111 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11113 stmt.compound.declarations = MkListOne(
11114 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11115 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11116 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11118 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11120 if(block && block.type == compoundStmt && block.compound.context)
11122 block.compound.context.parent = stmt.compound.context;
11126 block = MkIfStmt(filter, block, null);
11130 stmt.compound.statements = MkListOne(MkForStmt(
11131 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11132 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11133 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11134 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11136 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11137 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11138 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11143 //OldList * specs = MkList();
11144 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11146 sprintf(count, "%d", builtinCount);
11148 stmt.compound.statements = MkListOne(MkForStmt(
11149 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11150 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11151 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11152 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11156 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11157 stmt.compound.statements = MkListOne(MkForStmt(
11158 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11159 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11160 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11161 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11164 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11165 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11166 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11168 else if(isLinkList && !isList)
11170 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11171 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11172 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11173 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11175 stmt.compound.statements = MkListOne(MkForStmt(
11176 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11177 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11178 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11183 OldList * specs = MkList();
11184 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11185 stmt.compound.statements = MkListOne(MkForStmt(
11186 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11187 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11188 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11189 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11190 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11193 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11194 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11195 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11197 /*else if(isCustomAVLTree)
11199 stmt.compound.statements = MkListOne(MkForStmt(
11200 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11201 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11202 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11203 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11206 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11207 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11208 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11212 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11213 MkIdentifier("Next")), null)), block));
11215 ProcessExpressionType(expIt);
11216 if(stmt.compound.declarations->first)
11217 ProcessDeclaration(stmt.compound.declarations->first);
11220 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11222 ProcessStatement(stmt);
11223 curContext = stmt.compound.context.parent;
11228 Compiler_Error($"Expression is not a container\n");
11241 if(stmt.expressions)
11243 for(exp = stmt.expressions->first; exp; exp = exp.next)
11247 if(curFunction && !curFunction.type)
11248 curFunction.type = ProcessType(
11249 curFunction.specifiers, curFunction.declarator);
11250 FreeType(exp.destType);
11251 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11252 if(exp.destType) exp.destType.refCount++;
11254 ProcessExpressionType(exp);
11259 case badDeclarationStmt:
11261 ProcessDeclaration(stmt.decl);
11267 if(stmt.asmStmt.inputFields)
11269 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11270 if(field.expression)
11271 ProcessExpressionType(field.expression);
11273 if(stmt.asmStmt.outputFields)
11275 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11276 if(field.expression)
11277 ProcessExpressionType(field.expression);
11279 if(stmt.asmStmt.clobberedFields)
11281 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11283 if(field.expression)
11284 ProcessExpressionType(field.expression);
11291 PropertyWatch propWatch;
11292 OldList * watches = stmt._watch.watches;
11293 Expression object = stmt._watch.object;
11294 Expression watcher = stmt._watch.watcher;
11296 ProcessExpressionType(watcher);
11298 ProcessExpressionType(object);
11302 if(watcher || thisClass)
11304 External external = curExternal;
11305 Context context = curContext;
11307 stmt.type = expressionStmt;
11308 stmt.expressions = MkList();
11310 curExternal = external.prev;
11312 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11314 ClassFunction func;
11315 char watcherName[1024];
11316 Class watcherClass = watcher ?
11317 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11318 External createdExternal;
11320 // Create a declaration above
11321 External externalDecl = MkExternalDeclaration(null);
11322 ast->Insert(curExternal.prev, externalDecl);
11324 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11325 if(propWatch.deleteWatch)
11326 strcat(watcherName, "_delete");
11330 for(propID = propWatch.properties->first; propID; propID = propID.next)
11332 strcat(watcherName, "_");
11333 strcat(watcherName, propID.string);
11337 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11339 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11340 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11341 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11342 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11343 ProcessClassFunctionBody(func, propWatch.compound);
11344 propWatch.compound = null;
11346 //afterExternal = afterExternal ? afterExternal : curExternal;
11348 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11349 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11351 createdExternal.symbol.idCode = external.symbol.idCode;
11353 curExternal = createdExternal;
11354 ProcessFunction(createdExternal.function);
11357 // Create a declaration above
11359 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11360 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11361 externalDecl.declaration = decl;
11362 if(decl.symbol && !decl.symbol.pointerExternal)
11363 decl.symbol.pointerExternal = externalDecl;
11366 if(propWatch.deleteWatch)
11368 OldList * args = MkList();
11369 ListAdd(args, CopyExpression(object));
11370 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11371 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11372 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11376 Class _class = object.expType._class.registered;
11379 for(propID = propWatch.properties->first; propID; propID = propID.next)
11381 char propName[1024];
11382 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11385 char getName[1024], setName[1024];
11386 OldList * args = MkList();
11388 DeclareProperty(prop, setName, getName);
11390 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11391 strcpy(propName, "__ecereProp_");
11392 FullClassNameCat(propName, prop._class.fullName, false);
11393 strcat(propName, "_");
11394 // strcat(propName, prop.name);
11395 FullClassNameCat(propName, prop.name, true);
11397 ListAdd(args, CopyExpression(object));
11398 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11399 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11400 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11402 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11405 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11410 Compiler_Error($"Invalid watched object\n");
11413 curExternal = external;
11414 curContext = context;
11417 FreeExpression(watcher);
11419 FreeExpression(object);
11420 FreeList(watches, FreePropertyWatch);
11423 Compiler_Error($"No observer specified and not inside a _class\n");
11427 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11429 ProcessStatement(propWatch.compound);
11435 case fireWatchersStmt:
11437 OldList * watches = stmt._watch.watches;
11438 Expression object = stmt._watch.object;
11440 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11441 // printf("%X\n", watches);
11442 // printf("%X\n", stmt._watch.watches);
11444 ProcessExpressionType(object);
11449 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11455 stmt.type = expressionStmt;
11456 stmt.expressions = MkList();
11458 // Check if we're inside a property set
11459 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11461 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11465 //Compiler_Error($"No property specified and not inside a property set\n");
11469 for(propID = watches->first; propID; propID = propID.next)
11471 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11474 CreateFireWatcher(prop, object, stmt);
11477 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11482 // Fire all properties!
11485 for(base = _class; base; base = base.base)
11487 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11489 if(prop.isProperty && prop.isWatchable)
11491 CreateFireWatcher(prop, object, stmt);
11498 FreeExpression(object);
11499 FreeList(watches, FreeIdentifier);
11502 Compiler_Error($"Invalid object specified and not inside a class\n");
11506 case stopWatchingStmt:
11508 OldList * watches = stmt._watch.watches;
11509 Expression object = stmt._watch.object;
11510 Expression watcher = stmt._watch.watcher;
11513 ProcessExpressionType(object);
11515 ProcessExpressionType(watcher);
11518 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11520 if(watcher || thisClass)
11526 stmt.type = expressionStmt;
11527 stmt.expressions = MkList();
11532 // eInstance_StopWatching(object, null, watcher);
11534 ListAdd(args, CopyExpression(object));
11535 ListAdd(args, MkExpConstant("0"));
11536 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11537 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11541 for(propID = watches->first; propID; propID = propID.next)
11543 char propName[1024];
11544 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11547 char getName[1024], setName[1024];
11548 OldList * args = MkList();
11550 DeclareProperty(prop, setName, getName);
11552 // eInstance_StopWatching(object, prop, watcher);
11553 strcpy(propName, "__ecereProp_");
11554 FullClassNameCat(propName, prop._class.fullName, false);
11555 strcat(propName, "_");
11556 // strcat(propName, prop.name);
11557 FullClassNameCat(propName, prop.name, true);
11558 MangleClassName(propName);
11560 ListAdd(args, CopyExpression(object));
11561 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11562 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11563 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11566 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11571 FreeExpression(object);
11573 FreeExpression(watcher);
11574 FreeList(watches, FreeIdentifier);
11577 Compiler_Error($"Invalid object specified and not inside a class\n");
11580 Compiler_Error($"No observer specified and not inside a class\n");
11587 static void ProcessFunction(FunctionDefinition function)
11589 Identifier id = GetDeclId(function.declarator);
11590 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11591 Type type = symbol ? symbol.type : null;
11592 Class oldThisClass = thisClass;
11593 Context oldTopContext = topContext;
11595 yylloc = function.loc;
11596 // Process thisClass
11598 if(type && type.thisClass)
11600 Symbol classSym = type.thisClass;
11601 Class _class = type.thisClass.registered;
11602 char className[1024];
11603 char structName[1024];
11604 Declarator funcDecl;
11607 bool typedObject = false;
11609 if(_class && !_class.base)
11611 _class = currentClass;
11612 if(_class && !_class.symbol)
11613 _class.symbol = FindClass(_class.fullName);
11614 classSym = _class ? _class.symbol : null;
11615 typedObject = true;
11618 thisClass = _class;
11620 if(inCompiler && _class)
11622 if(type.kind == functionType)
11624 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11626 //TypeName param = symbol.type.params.first;
11627 Type param = symbol.type.params.first;
11628 symbol.type.params.Remove(param);
11629 //FreeTypeName(param);
11632 if(type.classObjectType != classPointer)
11634 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11635 symbol.type.staticMethod = true;
11636 symbol.type.thisClass = null;
11638 // HIGH DANGER: VERIFYING THIS...
11639 symbol.type.extraParam = false;
11643 strcpy(className, "__ecereClass_");
11644 FullClassNameCat(className, _class.fullName, true);
11646 MangleClassName(className);
11649 FullClassNameCat(structName, _class.fullName, false);
11654 funcDecl = GetFuncDecl(function.declarator);
11657 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11659 TypeName param = funcDecl.function.parameters->first;
11660 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11662 funcDecl.function.parameters->Remove(param);
11663 FreeTypeName(param);
11667 // DANGER: Watch for this... Check if it's a Conversion?
11668 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11670 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11671 if(!function.propertyNoThis)
11673 TypeName thisParam;
11675 if(type.classObjectType != classPointer)
11677 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11678 if(!funcDecl.function.parameters)
11679 funcDecl.function.parameters = MkList();
11680 funcDecl.function.parameters->Insert(null, thisParam);
11685 if(type.classObjectType != classPointer)
11687 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11688 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11691 thisParam = TypeName
11693 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11694 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11696 funcDecl.function.parameters->Insert(null, thisParam);
11701 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11703 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11704 funcDecl = GetFuncDecl(initDecl.declarator);
11707 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11709 TypeName param = funcDecl.function.parameters->first;
11710 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11712 funcDecl.function.parameters->Remove(param);
11713 FreeTypeName(param);
11717 if(type.classObjectType != classPointer)
11719 // DANGER: Watch for this... Check if it's a Conversion?
11720 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11722 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11724 if(!funcDecl.function.parameters)
11725 funcDecl.function.parameters = MkList();
11726 funcDecl.function.parameters->Insert(null, thisParam);
11733 // Add this to the context
11736 if(type.classObjectType != classPointer)
11738 thisSymbol = Symbol
11740 string = CopyString("this");
11741 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11743 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11745 if(typedObject && thisSymbol.type)
11747 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11748 thisSymbol.type.byReference = type.byReference;
11750 thisSymbol = Symbol { string = CopyString("class") };
11751 function.body.compound.context.symbols.Add(thisSymbol);
11757 // Pointer to class data
11759 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11761 DataMember member = null;
11764 for(base = _class; base && base.type != systemClass; base = base.next)
11766 for(member = base.membersAndProperties.first; member; member = member.next)
11767 if(!member.isProperty)
11773 for(member = _class.membersAndProperties.first; member; member = member.next)
11774 if(!member.isProperty)
11778 char pointerName[1024];
11781 Initializer initializer;
11782 Expression exp, bytePtr;
11784 strcpy(pointerName, "__ecerePointer_");
11785 FullClassNameCat(pointerName, _class.fullName, false);
11787 char className[1024];
11788 strcpy(className, "__ecereClass_");
11789 FullClassNameCat(className, classSym.string, true);
11790 MangleClassName(className);
11793 DeclareClass(classSym, className);
11797 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11802 sprintf(string, "%d", _class.offset);
11803 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11807 // ([bytePtr] + [className]->offset)
11808 exp = QBrackets(MkExpOp(bytePtr, '+',
11809 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11812 // (this ? [exp] : 0)
11813 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11817 kind = pointerType;
11818 type = Type { refCount = 1, kind = voidType };
11823 yylloc = function.body.loc;
11824 // ([structName] *) [exp]
11825 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11826 initializer = MkInitializerAssignment(
11827 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11829 // [structName] * [pointerName] = [initializer];
11830 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11833 Context prevContext = curContext;
11834 curContext = function.body.compound.context;
11836 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11837 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11839 curContext = prevContext;
11843 decl.symbol = null;
11845 if(!function.body.compound.declarations)
11846 function.body.compound.declarations = MkList();
11847 function.body.compound.declarations->Insert(null, decl);
11853 // Loop through the function and replace undeclared identifiers
11854 // which are a member of the class (methods, properties or data)
11855 // by "this.[member]"
11862 FreeSpecifier(id._class);
11865 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11867 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11868 id = GetDeclId(initDecl.declarator);
11870 FreeSpecifier(id._class);
11875 topContext = function.body.compound.context;
11877 FunctionDefinition oldFunction = curFunction;
11878 curFunction = function;
11880 ProcessStatement(function.body);
11882 // If this is a property set and no firewatchers has been done yet, add one here
11883 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11885 Statement prevCompound = curCompound;
11886 Context prevContext = curContext;
11888 Statement fireWatchers = MkFireWatchersStmt(null, null);
11889 if(!function.body.compound.statements) function.body.compound.statements = MkList();
11890 ListAdd(function.body.compound.statements, fireWatchers);
11892 curCompound = function.body;
11893 curContext = function.body.compound.context;
11895 ProcessStatement(fireWatchers);
11897 curContext = prevContext;
11898 curCompound = prevCompound;
11902 curFunction = oldFunction;
11905 if(function.declarator)
11907 ProcessDeclarator(function.declarator);
11910 topContext = oldTopContext;
11911 thisClass = oldThisClass;
11914 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
11915 static void ProcessClass(OldList definitions, Symbol symbol)
11918 External external = curExternal;
11919 Class regClass = symbol ? symbol.registered : null;
11921 // Process all functions
11922 for(def = definitions.first; def; def = def.next)
11924 if(def.type == functionClassDef)
11926 if(def.function.declarator)
11927 curExternal = def.function.declarator.symbol.pointerExternal;
11929 curExternal = external;
11931 ProcessFunction((FunctionDefinition)def.function);
11933 else if(def.type == declarationClassDef)
11935 if(def.decl.type == instDeclaration)
11937 thisClass = regClass;
11938 ProcessInstantiationType(def.decl.inst);
11944 Class backThisClass = thisClass;
11945 if(regClass) thisClass = regClass;
11946 ProcessDeclaration(def.decl);
11947 thisClass = backThisClass;
11950 else if(def.type == defaultPropertiesClassDef && def.defProperties)
11952 MemberInit defProperty;
11954 // Add this to the context
11955 Symbol thisSymbol = Symbol
11957 string = CopyString("this");
11958 type = regClass ? MkClassType(regClass.fullName) : null;
11960 globalContext.symbols.Add((BTNode)thisSymbol);
11962 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
11964 thisClass = regClass;
11965 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
11969 globalContext.symbols.Remove((BTNode)thisSymbol);
11970 FreeSymbol(thisSymbol);
11972 else if(def.type == propertyClassDef && def.propertyDef)
11974 PropertyDef prop = def.propertyDef;
11976 // Add this to the context
11978 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
11979 globalContext.symbols.Add(thisSymbol);
11982 thisClass = regClass;
11989 string = CopyString("this");
11990 type = MkClassType(regClass.fullName);
11992 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11995 curExternal = prop.symbol ? prop.symbol.externalSet : null;
11996 ProcessStatement(prop.setStmt);
12004 string = CopyString("this");
12005 type = MkClassType(regClass.fullName);
12007 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12010 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12011 ProcessStatement(prop.getStmt);
12019 string = CopyString("this");
12020 type = MkClassType(regClass.fullName);
12022 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12025 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12026 ProcessStatement(prop.issetStmt);
12032 globalContext.symbols.Remove(thisSymbol);
12033 FreeSymbol(thisSymbol);
12036 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12038 PropertyWatch propertyWatch = def.propertyWatch;
12040 thisClass = regClass;
12041 if(propertyWatch.compound)
12045 string = CopyString("this");
12046 type = regClass ? MkClassType(regClass.fullName) : null;
12049 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12051 curExternal = null;
12052 ProcessStatement(propertyWatch.compound);
12059 void ComputeDataTypes()
12063 currentClass = null;
12065 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12067 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12069 // WHERE SHOULD THIS GO?
12070 // curExternal = ast->first;
12071 ast->Insert(null, temp);
12073 curExternal = temp;
12075 DeclareStruct("ecere::com::Class", false);
12076 DeclareStruct("ecere::com::Instance", false);
12077 DeclareStruct("ecere::com::Property", false);
12078 DeclareStruct("ecere::com::DataMember", false);
12079 DeclareStruct("ecere::com::Method", false);
12080 DeclareStruct("ecere::com::SerialBuffer", false);
12081 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12085 for(external = ast->first; external; external = external.next)
12087 afterExternal = curExternal = external;
12088 if(external.type == functionExternal)
12090 currentClass = external.function._class;
12091 ProcessFunction(external.function);
12093 // There shouldn't be any _class member access here anyways...
12094 else if(external.type == declarationExternal)
12096 currentClass = null;
12097 ProcessDeclaration(external.declaration);
12099 else if(external.type == classExternal)
12101 ClassDefinition _class = external._class;
12102 currentClass = external.symbol.registered;
12103 if(_class.definitions)
12105 ProcessClass(_class.definitions, _class.symbol);
12109 // Free class data...
12110 ast->Remove(external);
12114 else if(external.type == nameSpaceExternal)
12116 thisNameSpace = external.id.string;
12119 currentClass = null;
12120 thisNameSpace = null;
12122 delete temp.symbol;