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)
209 if(type1.passAsTemplate && !type2.passAsTemplate)
211 return type1.isSigned != type2.isSigned;
213 return type1._class != type2._class;
215 return NeedCast(type1.type, type2.type);
217 return true; //false; ????
223 static void ReplaceClassMembers(Expression exp, Class _class)
225 if(exp.type == identifierExp && exp.identifier)
227 Identifier id = exp.identifier;
229 Symbol symbol = null;
230 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
232 // First, check if the identifier is declared inside the function
233 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
235 symbol = (Symbol)ctx.symbols.FindString(id.string);
240 // If it is not, check if it is a member of the _class
241 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
243 Property prop = eClass_FindProperty(_class, id.string, privateModule);
244 Method method = null;
245 DataMember member = null;
246 ClassProperty classProp = null;
249 method = eClass_FindMethod(_class, id.string, privateModule);
252 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
253 if(!prop && !method && !member)
255 classProp = eClass_FindClassProperty(_class, id.string);
257 if(prop || method || member || classProp)
259 // Replace by this.[member]
260 exp.type = memberExp;
261 exp.member.member = id;
262 exp.member.memberType = unresolvedMember;
263 exp.member.exp = QMkExpId("this");
264 //exp.member.exp.loc = exp.loc;
265 exp.addedThis = true;
267 else if(_class && _class.templateParams.first)
270 for(sClass = _class; sClass; sClass = sClass.base)
272 if(sClass.templateParams.first)
274 ClassTemplateParameter param;
275 for(param = sClass.templateParams.first; param; param = param.next)
277 if(param.type == expression && !strcmp(param.name, id.string))
279 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
284 OldList * specs = MkList();
286 FreeIdentifier(exp.member.member);
288 ProcessExpressionType(argExp);
290 decl = SpecDeclFromString(param.dataTypeString, specs, null);
292 exp.expType = ProcessType(specs, decl);
294 // *[expType] *[argExp]
295 exp.type = bracketsExp;
296 exp.list = MkListOne(MkExpOp(null, '*',
297 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
308 ////////////////////////////////////////////////////////////////////////
309 // PRINTING ////////////////////////////////////////////////////////////
310 ////////////////////////////////////////////////////////////////////////
312 public char * PrintInt(int64 result)
315 if(result > MAXINT64)
316 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
318 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
319 return CopyString(temp);
322 public char * PrintUInt(uint64 result)
325 if(result > MAXDWORD)
326 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
327 else if(result > MAXINT)
328 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
330 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
331 return CopyString(temp);
334 public char * PrintInt64(int64 result)
337 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
338 return CopyString(temp);
341 public char * PrintUInt64(uint64 result)
344 if(result > MAXINT64)
345 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
347 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
348 return CopyString(temp);
351 public char * PrintHexUInt(uint64 result)
354 if(result > MAXDWORD)
355 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
357 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
358 return CopyString(temp);
361 public char * PrintHexUInt64(uint64 result)
364 if(result > MAXDWORD)
365 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
367 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
368 return CopyString(temp);
371 public char * PrintShort(short result)
374 sprintf(temp, "%d", (unsigned short)result);
375 return CopyString(temp);
378 public char * PrintUShort(unsigned short result)
382 sprintf(temp, "0x%X", (int)result);
384 sprintf(temp, "%d", result);
385 return CopyString(temp);
388 public char * PrintChar(char result)
391 if(result > 0 && isprint(result))
392 sprintf(temp, "'%c'", result);
394 sprintf(temp, "%d", result);
396 //sprintf(temp, "%#X", result);
397 sprintf(temp, "0x%X", (unsigned char)result);
398 return CopyString(temp);
401 public char * PrintUChar(unsigned char result)
404 sprintf(temp, "0x%X", result);
405 return CopyString(temp);
408 public char * PrintFloat(float result)
411 sprintf(temp, "%.16ff", result);
412 return CopyString(temp);
415 public char * PrintDouble(double result)
418 sprintf(temp, "%.16f", result);
419 return CopyString(temp);
422 ////////////////////////////////////////////////////////////////////////
423 ////////////////////////////////////////////////////////////////////////
425 //public Operand GetOperand(Expression exp);
427 #define GETVALUE(name, t) \
428 public bool Get##name(Expression exp, t * value2) \
430 Operand op2 = GetOperand(exp); \
431 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
432 else if(op2.kind == intType) *value2 = (t) op2.ui; \
433 if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
434 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
435 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.iptr; \
436 else if(op2.kind == intPtrType) *value2 = (t) op2.uiptr; \
437 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
438 else if(op2.kind == shortType) *value2 = (t) op2.us; \
439 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
440 else if(op2.kind == charType) *value2 = (t) op2.uc; \
441 else if(op2.kind == floatType) *value2 = (t) op2.f; \
442 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
443 else if(op2.kind == pointerType) *value2 = (t) op2.ui; \
450 GETVALUE(UInt, unsigned int);
451 GETVALUE(Int64, int64);
452 GETVALUE(UInt64, uint64);
453 GETVALUE(IntPtr, intptr);
454 GETVALUE(UIntPtr, uintptr);
455 GETVALUE(Short, short);
456 GETVALUE(UShort, unsigned short);
457 GETVALUE(Char, char);
458 GETVALUE(UChar, unsigned char);
459 GETVALUE(Float, float);
460 GETVALUE(Double, double);
462 void ComputeExpression(Expression exp);
464 void ComputeClassMembers(Class _class, bool isMember)
466 DataMember member = isMember ? (DataMember) _class : null;
467 Context context = isMember ? null : SetupTemplatesContext(_class);
468 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
469 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
472 int unionMemberOffset = 0;
475 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
476 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
478 if(!member && _class.destructionWatchOffset)
479 _class.memberOffset += sizeof(OldList);
481 // To avoid reentrancy...
482 //_class.structSize = -1;
485 DataMember dataMember;
486 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
488 if(!dataMember.isProperty)
490 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
492 /*if(dataMember.dataType)
494 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
495 /*if(!dataMember.dataType)
496 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
504 DataMember dataMember;
505 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
507 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
509 if(!isMember && _class.type == bitClass && dataMember.dataType)
511 BitMember bitMember = (BitMember) dataMember;
515 ComputeTypeSize(dataMember.dataType);
517 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
518 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
520 _class.memberOffset = bitMember.pos + bitMember.size;
521 for(d = 0; d<bitMember.size; d++)
527 bitMember.mask = mask << bitMember.pos;
529 else if(dataMember.type == normalMember && dataMember.dataType)
534 // Prevent infinite recursion
535 if(dataMember.dataType.kind != classType ||
536 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
537 _class.type != structClass)))
538 ComputeTypeSize(dataMember.dataType);
540 if(dataMember.dataType.bitFieldCount)
542 bitFields += dataMember.dataType.bitFieldCount;
549 int size = (bitFields + 7) / 8;
553 // TESTING THIS PADDING CODE
556 member.structAlignment = Max(member.structAlignment, alignment);
558 if(member.memberOffset % alignment)
559 member.memberOffset += alignment - (member.memberOffset % alignment);
562 dataMember.offset = member.memberOffset;
563 if(member.type == unionMember)
564 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
567 member.memberOffset += size;
572 // TESTING THIS PADDING CODE
575 _class.structAlignment = Max(_class.structAlignment, alignment);
577 if(_class.memberOffset % alignment)
578 _class.memberOffset += alignment - (_class.memberOffset % alignment);
581 dataMember.offset = _class.memberOffset;
582 _class.memberOffset += size;
586 size = dataMember.dataType.size;
587 alignment = dataMember.dataType.alignment;
598 // TESTING THIS PADDING CODE
601 member.structAlignment = Max(member.structAlignment, alignment);
603 if(member.memberOffset % alignment)
604 member.memberOffset += alignment - (member.memberOffset % alignment);
607 dataMember.offset = member.memberOffset;
608 if(member.type == unionMember)
609 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
612 member.memberOffset += size;
617 // TESTING THIS PADDING CODE
620 _class.structAlignment = Max(_class.structAlignment, alignment);
622 if(_class.memberOffset % alignment)
623 _class.memberOffset += alignment - (_class.memberOffset % alignment);
626 dataMember.offset = _class.memberOffset;
627 _class.memberOffset += size;
632 ComputeClassMembers((Class)dataMember, true);
636 // THERE WASN'T A MAX HERE ? member.structAlignment = dataMember.structAlignment;
637 member.structAlignment = Max(member.structAlignment, dataMember.structAlignment);
638 dataMember.offset = member.memberOffset;
639 if(member.type == unionMember)
640 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
642 member.memberOffset += dataMember.memberOffset;
646 _class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
647 dataMember.offset = _class.memberOffset;
648 _class.memberOffset += dataMember.memberOffset;
656 int size = (bitFields + 7) / 8;
660 // TESTING THIS PADDING CODE
663 member.structAlignment = Max(member.structAlignment, alignment);
665 if(member.memberOffset % alignment)
666 member.memberOffset += alignment - (member.memberOffset % alignment);
669 if(member.type == unionMember)
670 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
673 member.memberOffset += size;
678 // TESTING THIS PADDING CODE
681 _class.structAlignment = Max(_class.structAlignment, alignment);
683 if(_class.memberOffset % alignment)
684 _class.memberOffset += alignment - (_class.memberOffset % alignment);
686 _class.memberOffset += size;
691 if(member && member.type == unionMember)
693 member.memberOffset = unionMemberOffset;
698 /*if(_class.type == structClass)
699 _class.size = _class.memberOffset;
703 if(_class.type != bitClass)
706 if(_class.structAlignment)
708 if(_class.memberOffset % _class.structAlignment)
709 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
711 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
715 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
717 if(prop.isProperty && prop.isWatchable)
719 prop.watcherOffset = _class.structSize;
720 _class.structSize += sizeof(OldList);
728 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
730 Class deriv = derivative.data;
732 if(deriv.computeSize)
734 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
735 deriv.offset = /*_class.offset + */_class.structSize;
736 deriv.memberOffset = 0;
737 // ----------------------
739 deriv.structSize = deriv.offset;
741 ComputeClassMembers(deriv, false);
749 FinishTemplatesContext(context);
752 public void ComputeModuleClasses(Module module)
757 for(subModule = module.modules.first; subModule; subModule = subModule.next)
758 ComputeModuleClasses(subModule.data);
759 for(_class = module.classes.first; _class; _class = _class.next)
760 ComputeClassMembers(_class, false);
764 public int ComputeTypeSize(Type type)
766 uint size = type ? type.size : 0;
767 if(!size && type && !type.computing)
769 type.computing = true;
772 case charType: type.alignment = size = sizeof(char); break;
773 case intType: type.alignment = size = sizeof(int); break;
774 case int64Type: type.alignment = size = sizeof(int64); break;
775 case intPtrType: type.alignment = size = targetBits / 8; break;
776 case longType: type.alignment = size = sizeof(long); break;
777 case shortType: type.alignment = size = sizeof(short); break;
778 case floatType: type.alignment = size = sizeof(float); break;
779 case doubleType: type.alignment = size = sizeof(double); break;
782 Class _class = type._class ? type._class.registered : null;
784 if(_class && _class.type == structClass)
786 // Ensure all members are properly registered
787 ComputeClassMembers(_class, false);
788 type.alignment = _class.structAlignment;
789 size = _class.structSize;
790 if(type.alignment && size % type.alignment)
791 size += type.alignment - (size % type.alignment);
794 else if(_class && (_class.type == unitClass ||
795 _class.type == enumClass ||
796 _class.type == bitClass))
799 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
800 size = type.alignment = ComputeTypeSize(_class.dataType);
803 size = type.alignment = targetBits / 8; // sizeof(Instance *);
806 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
808 if(type.arraySizeExp)
810 ProcessExpressionType(type.arraySizeExp);
811 ComputeExpression(type.arraySizeExp);
812 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
813 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
815 Location oldLoc = yylloc;
816 // bool isConstant = type.arraySizeExp.isConstant;
817 char expression[10240];
818 expression[0] = '\0';
819 type.arraySizeExp.expType = null;
820 yylloc = type.arraySizeExp.loc;
822 PrintExpression(type.arraySizeExp, expression);
823 Compiler_Error($"Array size not constant int (%s)\n", expression);
826 GetInt(type.arraySizeExp, &type.arraySize);
834 else if(type.enumClass)
836 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
838 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
845 // Unimplemented auto size
849 size = ComputeTypeSize(type.type) * type.arraySize;
850 type.alignment = type.type.alignment;
856 for(member = type.members.first; member; member = member.next)
858 uint addSize = ComputeTypeSize(member);
860 member.offset = size;
861 if(member.alignment && size % member.alignment)
862 member.offset += member.alignment - (size % member.alignment);
863 size = member.offset;
865 type.alignment = Max(type.alignment, member.alignment);
868 if(type.alignment && size % type.alignment)
869 size += type.alignment - (size % type.alignment);
875 for(member = type.members.first; member; member = member.next)
877 uint addSize = ComputeTypeSize(member);
879 member.offset = size;
880 if(member.alignment && size % member.alignment)
881 member.offset += member.alignment - (size % member.alignment);
882 size = member.offset;
884 type.alignment = Max(type.alignment, member.alignment);
885 size = Max(size, addSize);
887 if(type.alignment && size % type.alignment)
888 size += type.alignment - (size % type.alignment);
893 TemplateParameter param = type.templateParameter;
894 Type baseType = ProcessTemplateParameterType(param);
896 size = ComputeTypeSize(baseType);
898 size = sizeof(uint64);
903 size = sizeof(enum { test });
908 size = targetBits / 8; //sizeof(void *);
913 type.computing = false;
919 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass)
921 // This function is in need of a major review when implementing private members etc.
922 DataMember topMember = isMember ? (DataMember) _class : null;
927 Context context = isMember ? null : SetupTemplatesContext(_class);
929 if(!isMember && _class.base)
931 maxSize = _class.structSize;
932 //if(_class.base.type != systemClass) // Commented out with new Instance _class
934 // DANGER: Testing this noHeadClass here...
935 if(_class.type == structClass || _class.type == noHeadClass)
936 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass);
938 maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
942 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
944 if(!member.isProperty)
950 if(member.dataTypeString)
952 OldList * specs = MkList(), * decls = MkList();
955 decl = SpecDeclFromString(member.dataTypeString, specs,
956 MkDeclaratorIdentifier(MkIdentifier(member.name)));
957 ListAdd(decls, MkStructDeclarator(decl, null));
958 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
961 member.dataType = ProcessType(specs, decl);
963 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
966 Type type = ProcessType(specs, decl);
967 DeclareType(member.dataType, false, false);
971 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
972 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
973 DeclareStruct(member.dataType._class.string, false);
976 ComputeTypeSize(member.dataType);
977 size = member.dataType.size;
978 alignment = member.dataType.alignment;
982 if(totalSize % alignment)
983 totalSize += alignment - (totalSize % alignment);
992 OldList * specs = MkList(), * list = MkList();
995 AddMembers(list, (Class)member, true, &size, topClass);
997 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
998 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
999 alignment = member.structAlignment;
1003 if(totalSize % alignment)
1004 totalSize += alignment - (totalSize % alignment);
1014 if(topMember && topMember.type == unionMember)
1015 *retSize = Max(*retSize, totalSize);
1017 *retSize += totalSize;
1019 else if(totalSize < maxSize && _class.type != systemClass)
1021 int autoPadding = 0;
1022 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1023 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1024 if(totalSize + autoPadding < maxSize)
1026 char sizeString[50];
1027 sprintf(sizeString, "%d", maxSize - totalSize);
1028 ListAdd(declarations,
1029 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1030 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1034 FinishTemplatesContext(context);
1035 return topMember ? topMember.memberID : _class.memberID;
1038 static int DeclareMembers(Class _class, bool isMember)
1040 DataMember topMember = isMember ? (DataMember) _class : null;
1043 Context context = isMember ? null : SetupTemplatesContext(_class);
1045 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1046 DeclareMembers(_class.base, false);
1048 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1050 if(!member.isProperty)
1057 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1058 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1059 DeclareStruct(member.dataType._class.string, false);
1061 if(!member.dataType && member.dataTypeString)
1062 member.dataType = ProcessTypeString(member.dataTypeString, false);
1064 DeclareType(member.dataType, false, false);
1070 DeclareMembers((Class)member, true);
1077 FinishTemplatesContext(context);
1079 return topMember ? topMember.memberID : _class.memberID;
1082 void DeclareStruct(char * name, bool skipNoHead)
1084 External external = null;
1085 Symbol classSym = FindClass(name);
1087 if(!inCompiler || !classSym) return null;
1089 // We don't need any declaration for bit classes...
1090 if(classSym.registered &&
1091 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1094 /*if(classSym.registered.templateClass)
1095 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1098 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1100 // Add typedef struct
1102 OldList * specifiers, * declarators;
1103 OldList * declarations = null;
1104 char structName[1024];
1105 external = (classSym.registered && classSym.registered.type == structClass) ?
1106 classSym.pointerExternal : classSym.structExternal;
1108 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1109 // Moved this one up because DeclareClass done later will need it
1111 classSym.declaring++;
1113 if(strchr(classSym.string, '<'))
1115 if(classSym.registered.templateClass)
1117 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1118 classSym.declaring--;
1124 DeclareMembers(classSym.registered, false);
1127 FullClassNameCat(structName, name, false);
1130 external = MkExternalDeclaration(null);*/
1134 classSym.declaredStructSym = true;
1136 declarations = MkList();
1138 AddMembers(declarations, classSym.registered, false, null, classSym.registered);
1140 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1141 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1143 if(!declarations->count)
1145 FreeList(declarations, null);
1146 declarations = null;
1149 if(skipNoHead || declarations)
1151 if(external && external.declaration)
1153 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1155 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1158 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1161 if(classSym.structExternal)
1162 ast->Move(classSym.structExternal, curExternal.prev);
1163 ast->Move(classSym.pointerExternal, curExternal.prev);
1165 classSym.id = curExternal.symbol.idCode;
1166 classSym.idCode = curExternal.symbol.idCode;
1167 // external = classSym.pointerExternal;
1168 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1174 external = MkExternalDeclaration(null);
1176 specifiers = MkList();
1177 declarators = MkList();
1178 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1181 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1182 ListAdd(declarators, MkInitDeclarator(d, null));
1184 external.declaration = decl = MkDeclaration(specifiers, declarators);
1185 if(decl.symbol && !decl.symbol.pointerExternal)
1186 decl.symbol.pointerExternal = external;
1188 // For simple classes, keep the declaration as the external to move around
1189 if(classSym.registered && classSym.registered.type == structClass)
1191 char className[1024];
1192 strcpy(className, "__ecereClass_");
1193 FullClassNameCat(className, classSym.string, true);
1194 MangleClassName(className);
1197 DeclareClass(classSym, className);
1199 external.symbol = classSym;
1200 classSym.pointerExternal = external;
1201 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1202 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1206 char className[1024];
1207 strcpy(className, "__ecereClass_");
1208 FullClassNameCat(className, classSym.string, true);
1209 MangleClassName(className);
1211 // TOFIX: TESTING THIS...
1212 classSym.structExternal = external;
1213 DeclareClass(classSym, className);
1214 external.symbol = classSym;
1218 ast->Insert(curExternal ? curExternal.prev : null, external);
1222 classSym.declaring--;
1224 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1226 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1227 // Moved this one up because DeclareClass done later will need it
1230 classSym.declaring++;
1234 if(classSym.registered)
1235 DeclareMembers(classSym.registered, false);
1238 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1241 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1244 if(classSym.structExternal)
1245 ast->Move(classSym.structExternal, curExternal.prev);
1246 ast->Move(classSym.pointerExternal, curExternal.prev);
1248 classSym.id = curExternal.symbol.idCode;
1249 classSym.idCode = curExternal.symbol.idCode;
1250 // external = classSym.pointerExternal;
1251 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1254 classSym.declaring--;
1259 void DeclareProperty(Property prop, char * setName, char * getName)
1261 Symbol symbol = prop.symbol;
1262 char propName[1024];
1264 strcpy(setName, "__ecereProp_");
1265 FullClassNameCat(setName, prop._class.fullName, false);
1266 strcat(setName, "_Set_");
1267 // strcat(setName, prop.name);
1268 FullClassNameCat(setName, prop.name, true);
1270 strcpy(getName, "__ecereProp_");
1271 FullClassNameCat(getName, prop._class.fullName, false);
1272 strcat(getName, "_Get_");
1273 FullClassNameCat(getName, prop.name, true);
1274 // strcat(getName, prop.name);
1276 strcpy(propName, "__ecereProp_");
1277 FullClassNameCat(propName, prop._class.fullName, false);
1278 strcat(propName, "_");
1279 FullClassNameCat(propName, prop.name, true);
1280 // strcat(propName, prop.name);
1282 // To support "char *" property
1283 MangleClassName(getName);
1284 MangleClassName(setName);
1285 MangleClassName(propName);
1287 if(prop._class.type == structClass)
1288 DeclareStruct(prop._class.fullName, false);
1290 if(!symbol || curExternal.symbol.idCode < symbol.id)
1292 bool imported = false;
1293 bool dllImport = false;
1294 if(!symbol || symbol._import)
1299 if(!prop._class.symbol)
1300 prop._class.symbol = FindClass(prop._class.fullName);
1301 classSym = prop._class.symbol;
1302 if(classSym && !classSym._import)
1304 ModuleImport module;
1306 if(prop._class.module)
1307 module = FindModule(prop._class.module);
1309 module = mainModule;
1311 classSym._import = ClassImport
1313 name = CopyString(prop._class.fullName);
1314 isRemote = prop._class.isRemote;
1316 module.classes.Add(classSym._import);
1318 symbol = prop.symbol = Symbol { };
1319 symbol._import = (ClassImport)PropertyImport
1321 name = CopyString(prop.name);
1322 isVirtual = false; //prop.isVirtual;
1323 hasSet = prop.Set ? true : false;
1324 hasGet = prop.Get ? true : false;
1327 classSym._import.properties.Add(symbol._import);
1330 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1336 Context context = SetupTemplatesContext(prop._class);
1337 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1338 FinishTemplatesContext(context);
1344 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1347 OldList * specifiers, * declarators;
1352 Declarator typeDecl;
1353 bool simple = false;
1355 specifiers = MkList();
1356 declarators = MkList();
1359 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1360 MkDeclaratorIdentifier(MkIdentifier("this"))));
1362 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1365 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1368 Context context = SetupTemplatesContext(prop._class);
1369 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1370 FinishTemplatesContext(context);
1373 // Make sure the simple _class's type is declared
1374 for(spec = specifiers->first; spec; spec = spec.next)
1376 if(spec.type == nameSpecifier /*SpecifierClass*/)
1378 if((!typeDecl || typeDecl.type == identifierDeclarator))
1380 Symbol classSym = spec.symbol; // FindClass(spec.name);
1381 symbol._class = classSym.registered;
1382 if(classSym.registered && classSym.registered.type == structClass)
1384 DeclareStruct(spec.name, false);
1392 d = PlugDeclarator(typeDecl, d);
1395 ListAdd(params, MkTypeName(specifiers,
1396 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1397 specifiers = MkList();
1400 d = MkDeclaratorFunction(d, params);
1404 specifiers->Insert(null, MkSpecifier(EXTERN));
1405 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1406 specifiers->Insert(null, MkSpecifier(STATIC));
1408 ListAdd(specifiers, MkSpecifier(VOID));
1410 ListAdd(declarators, MkInitDeclarator(d, null));
1412 decl = MkDeclaration(specifiers, declarators);
1414 external = MkExternalDeclaration(decl);
1415 ast->Insert(curExternal.prev, external);
1416 external.symbol = symbol;
1417 symbol.externalGet = external;
1419 ReplaceThisClassSpecifiers(specifiers, prop._class);
1422 FreeDeclarator(typeDecl);
1426 // Move declaration higher...
1427 ast->Move(symbol.externalGet, curExternal.prev);
1434 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1437 OldList * specifiers, * declarators;
1442 Declarator typeDecl;
1444 declarators = MkList();
1447 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1448 if(!prop.conversion || prop._class.type == structClass)
1450 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1451 MkDeclaratorIdentifier(MkIdentifier("this"))));
1454 specifiers = MkList();
1457 Context context = SetupTemplatesContext(prop._class);
1458 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1459 MkDeclaratorIdentifier(MkIdentifier("value")));
1460 FinishTemplatesContext(context);
1462 ListAdd(params, MkTypeName(specifiers, d));
1464 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1467 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1468 d = MkDeclaratorFunction(d, params);
1470 // Make sure the simple _class's type is declared
1471 for(spec = specifiers->first; spec; spec = spec.next)
1473 if(spec.type == nameSpecifier /*SpecifierClass*/)
1475 if((!typeDecl || typeDecl.type == identifierDeclarator))
1477 Symbol classSym = spec.symbol; // FindClass(spec.name);
1478 symbol._class = classSym.registered;
1479 if(classSym.registered && classSym.registered.type == structClass)
1480 DeclareStruct(spec.name, false);
1485 ListAdd(declarators, MkInitDeclarator(d, null));
1487 specifiers = MkList();
1490 specifiers->Insert(null, MkSpecifier(EXTERN));
1491 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1492 specifiers->Insert(null, MkSpecifier(STATIC));
1494 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1495 if(!prop.conversion || prop._class.type == structClass)
1496 ListAdd(specifiers, MkSpecifier(VOID));
1498 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1500 decl = MkDeclaration(specifiers, declarators);
1502 external = MkExternalDeclaration(decl);
1503 ast->Insert(curExternal.prev, external);
1504 external.symbol = symbol;
1505 symbol.externalSet = external;
1507 ReplaceThisClassSpecifiers(specifiers, prop._class);
1511 // Move declaration higher...
1512 ast->Move(symbol.externalSet, curExternal.prev);
1516 // Property (for Watchers)
1517 if(!symbol.externalPtr)
1521 OldList * specifiers = MkList();
1524 specifiers->Insert(null, MkSpecifier(EXTERN));
1526 specifiers->Insert(null, MkSpecifier(STATIC));
1528 ListAdd(specifiers, MkSpecifierName("Property"));
1531 OldList * list = MkList();
1532 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1533 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1537 strcpy(propName, "__ecerePropM_");
1538 FullClassNameCat(propName, prop._class.fullName, false);
1539 strcat(propName, "_");
1540 // strcat(propName, prop.name);
1541 FullClassNameCat(propName, prop.name, true);
1543 MangleClassName(propName);
1545 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1546 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1548 decl = MkDeclaration(specifiers, list);
1551 external = MkExternalDeclaration(decl);
1552 ast->Insert(curExternal.prev, external);
1553 external.symbol = symbol;
1554 symbol.externalPtr = external;
1558 // Move declaration higher...
1559 ast->Move(symbol.externalPtr, curExternal.prev);
1562 symbol.id = curExternal.symbol.idCode;
1566 // ***************** EXPRESSION PROCESSING ***************************
1567 public Type Dereference(Type source)
1572 if(source.kind == pointerType || source.kind == arrayType)
1575 source.type.refCount++;
1577 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1585 // Support dereferencing of no head classes for now...
1586 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1592 Compiler_Error($"cannot dereference type\n");
1597 static Type Reference(Type source)
1613 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1615 Identifier ident = member.identifiers ? member.identifiers->first : null;
1617 DataMember dataMember = null;
1618 Method method = null;
1619 bool freeType = false;
1621 yylloc = member.loc;
1627 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1631 dataMember = *curMember;
1637 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1638 DataMember _subMemberStack[256];
1639 int _subMemberStackPos = 0;
1641 // FILL MEMBER STACK
1643 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1646 dataMember = thisMember;
1647 if(curMember && thisMember.memberAccess == publicAccess)
1649 *curMember = thisMember;
1650 *curClass = thisMember._class;
1651 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
1652 *subMemberStackPos = _subMemberStackPos;
1659 method = eClass_FindMethod(_class, ident.string, privateModule);
1660 if(method && method.type == virtualMethod)
1672 if(!dataMember.dataType && dataMember.dataTypeString)
1674 //Context context = SetupTemplatesContext(dataMember._class);
1675 Context context = SetupTemplatesContext(_class);
1676 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1677 FinishTemplatesContext(context);
1679 type = dataMember.dataType;
1683 // This is for destination type...
1684 if(!method.dataType)
1685 ProcessMethodType(method);
1686 //DeclareMethod(method);
1687 // method.dataType = ((Symbol)method.symbol)->type;
1688 type = method.dataType;
1691 if(ident && ident.next)
1693 for(ident = ident.next; ident && type; ident = ident.next)
1695 if(type.kind == classType)
1697 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1699 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1701 type = dataMember.dataType;
1703 else if(type.kind == structType || type.kind == unionType)
1706 for(memberType = type.members.first; memberType; memberType = memberType.next)
1708 if(!strcmp(memberType.name, ident.string))
1718 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1719 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1722 ClassTemplateParameter curParam = null;
1724 for(sClass = _class; sClass; sClass = sClass.base)
1727 if(sClass.templateClass) sClass = sClass.templateClass;
1728 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1730 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1732 for(sClass = sClass.base; sClass; sClass = sClass.base)
1734 if(sClass.templateClass) sClass = sClass.templateClass;
1735 id += sClass.templateParams.count;
1746 ClassTemplateArgument arg = _class.templateArgs[id];
1747 if(arg.dataTypeString)
1750 type = ProcessTypeString(arg.dataTypeString, false);
1752 if(type && _class.templateClass)
1753 type.passAsTemplate = true;
1759 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1760 exp.destType.refCount++;
1766 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1768 Class expClass = type._class.registered;
1769 Class cClass = null;
1774 char templateString[1024];
1775 ClassTemplateParameter param;
1776 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1777 for(cClass = expClass; cClass; cClass = cClass.base)
1780 if(cClass.templateClass) cClass = cClass.templateClass;
1781 for(param = cClass.templateParams.first; param; param = param.next)
1785 ClassTemplateArgument arg;
1786 for(sClass = cClass.base; sClass; sClass = sClass.base)
1788 if(sClass.templateClass) sClass = sClass.templateClass;
1789 id += sClass.templateParams.count;
1791 arg = expClass.templateArgs[id];
1793 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1795 ClassTemplateParameter cParam;
1796 //int p = numParams - sClass.templateParams.count;
1799 if(sClass.templateClass) sClass = sClass.templateClass;
1801 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1803 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1804 p += nextClass.templateParams.count;
1807 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1809 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1811 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1813 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1814 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1826 strcat(argument, arg.name.string);
1827 strcat(argument, " = ");
1833 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1834 char expString[1024];
1835 OldList * specs = MkList();
1836 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1838 char * string = PrintHexUInt64(arg.expression.ui64);
1839 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1841 ProcessExpressionType(exp);
1842 ComputeExpression(exp);
1843 expString[0] = '\0';
1844 PrintExpression(exp, expString);
1845 strcat(argument, expString);
1847 FreeExpression(exp);
1852 strcat(argument, arg.member.name);
1855 case TemplateParameterType::type:
1857 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1858 strcat(argument, arg.dataTypeString);
1864 if(paramCount) strcat(templateString, ", ");
1865 if(lastParam != p - 1)
1867 strcat(templateString, param.name);
1868 strcat(templateString, " = ");
1870 strcat(templateString, argument);
1879 int len = strlen(templateString);
1880 if(templateString[len-1] == '<')
1884 if(templateString[len-1] == '>')
1885 templateString[len++] = ' ';
1886 templateString[len++] = '>';
1888 templateString[len++] = '\0';
1891 Context context = SetupTemplatesContext(_class);
1892 if(freeType) FreeType(type);
1893 type = ProcessTypeString(templateString, false);
1895 FinishTemplatesContext(context);
1899 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1901 ProcessExpressionType(member.initializer.exp);
1902 if(!member.initializer.exp.expType)
1906 char expString[10240];
1907 expString[0] = '\0';
1908 PrintExpression(member.initializer.exp, expString);
1909 ChangeCh(expString, '\n', ' ');
1910 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1913 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1914 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1916 Compiler_Error($"incompatible instance method %s\n", ident.string);
1919 else if(member.initializer)
1922 FreeType(member.exp.destType);
1923 member.exp.destType = type;
1924 if(member.exp.destType)
1925 member.exp.destType.refCount++;
1926 ProcessExpressionType(member.exp);
1929 ProcessInitializer(member.initializer, type);
1931 if(freeType) FreeType(type);
1935 if(_class && _class.type == unitClass)
1937 if(member.initializer)
1940 FreeType(member.exp.destType);
1941 member.exp.destType = MkClassType(_class.fullName);
1942 ProcessExpressionType(member.initializer, type);
1944 Type type = MkClassType(_class.fullName);
1945 ProcessInitializer(member.initializer, type);
1951 if(member.initializer)
1953 //ProcessExpressionType(member.exp);
1954 ProcessInitializer(member.initializer, null);
1960 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1964 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1966 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1970 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1975 void ProcessInstantiationType(Instantiation inst)
1980 MembersInit members;
1981 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1984 /*if(!inst._class.symbol)
1985 inst._class.symbol = FindClass(inst._class.name);*/
1986 classSym = inst._class.symbol;
1987 _class = classSym ? classSym.registered : null;
1989 // DANGER: Patch for mutex not declaring its struct when not needed
1990 if(!_class || _class.type != noHeadClass)
1991 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1993 afterExternal = afterExternal ? afterExternal : curExternal;
1996 ProcessExpressionType(inst.exp);
1998 inst.isConstant = true;
2001 DataMember curMember = null;
2002 Class curClass = null;
2003 DataMember subMemberStack[256];
2004 int subMemberStackPos = 0;
2006 for(members = inst.members->first; members; members = members.next)
2008 switch(members.type)
2010 case methodMembersInit:
2013 static uint instMethodID = 0;
2014 External external = curExternal;
2015 Context context = curContext;
2016 Declarator declarator = members.function.declarator;
2017 Identifier nameID = GetDeclId(declarator);
2018 char * unmangled = nameID ? nameID.string : null;
2020 External createdExternal = null;
2025 //members.function.dontMangle = true;
2026 strcpy(name, "__ecereInstMeth_");
2027 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2029 strcat(name, nameID.string);
2031 sprintf(number, "_%08d", instMethodID++);
2032 strcat(name, number);
2033 nameID.string = CopyString(name);
2036 // Do modifications here...
2039 Symbol symbol = declarator.symbol;
2040 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2042 if(method && method.type == virtualMethod)
2044 symbol.method = method;
2045 ProcessMethodType(method);
2047 if(!symbol.type.thisClass)
2049 if(method.dataType.thisClass && currentClass &&
2050 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2052 if(!currentClass.symbol)
2053 currentClass.symbol = FindClass(currentClass.fullName);
2054 symbol.type.thisClass = currentClass.symbol;
2059 _class.symbol = FindClass(_class.fullName);
2060 symbol.type.thisClass = _class.symbol;
2063 // TESTING THIS HERE:
2064 DeclareType(symbol.type, true, true);
2069 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2070 unmangled, classSym.string);
2074 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2075 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2079 FreeSpecifier(nameID._class);
2080 nameID._class = null;
2086 Type type = declarator.symbol.type;
2087 External oldExternal = curExternal;
2089 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2090 // *** It was commented out for problems such as
2092 class VirtualDesktop : Window
2094 clientSize = Size { };
2105 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2107 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2110 if(strcmp(declarator.symbol.string, name))
2112 printf("TOCHECK: Look out for this\n");
2113 delete declarator.symbol.string;
2114 declarator.symbol.string = CopyString(name);
2117 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2119 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2120 excludedSymbols->Remove(declarator.symbol);
2121 globalContext.symbols.Add((BTNode)declarator.symbol);
2122 if(strstr(declarator.symbol.string), "::")
2123 globalContext.hasNameSpace = true;
2128 //curExternal = curExternal.prev;
2129 //afterExternal = afterExternal->next;
2131 //ProcessFunction(afterExternal->function);
2133 //curExternal = afterExternal;
2135 External externalDecl;
2136 externalDecl = MkExternalDeclaration(null);
2137 ast->Insert(oldExternal.prev, externalDecl);
2139 // Which function does this process?
2140 if(createdExternal.function)
2142 ProcessFunction(createdExternal.function);
2144 //curExternal = oldExternal;
2147 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2149 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2150 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2152 //externalDecl = MkExternalDeclaration(decl);
2154 //***** ast->Insert(external.prev, externalDecl);
2155 //ast->Insert(curExternal.prev, externalDecl);
2156 externalDecl.declaration = decl;
2157 if(decl.symbol && !decl.symbol.pointerExternal)
2158 decl.symbol.pointerExternal = externalDecl;
2160 // Trying this out...
2161 declarator.symbol.pointerExternal = externalDecl;
2168 curExternal = declarator.symbol.pointerExternal;
2169 ProcessFunction((FunctionDefinition)members.function);
2171 curExternal = external;
2172 curContext = context;
2176 FreeClassFunction(members.function);
2178 // In this pass, turn this into a MemberInitData
2179 exp = QMkExpId(name);
2180 members.type = dataMembersInit;
2181 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2187 case dataMembersInit:
2189 if(members.dataMembers && classSym)
2192 Location oldyyloc = yylloc;
2193 for(member = members.dataMembers->first; member; member = member.next)
2195 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2196 if(member.initializer && !member.initializer.isConstant)
2197 inst.isConstant = false;
2209 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2211 // OPTIMIZATIONS: TESTING THIS...
2214 if(type.kind == functionType)
2219 for(param = type.params.first; param; param = param.next)
2220 DeclareType(param, declarePointers, true);
2222 DeclareType(type.returnType, declarePointers, true);
2224 else if(type.kind == pointerType && declarePointers)
2225 DeclareType(type.type, declarePointers, false);
2226 else if(type.kind == classType)
2228 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2229 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2231 else if(type.kind == structType || type.kind == unionType)
2234 for(member = type.members.first; member; member = member.next)
2235 DeclareType(member, false, false);
2237 else if(type.kind == arrayType)
2238 DeclareType(type.arrayType, declarePointers, false);
2242 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2244 ClassTemplateArgument * arg = null;
2246 ClassTemplateParameter curParam = null;
2248 for(sClass = _class; sClass; sClass = sClass.base)
2251 if(sClass.templateClass) sClass = sClass.templateClass;
2252 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2254 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2256 for(sClass = sClass.base; sClass; sClass = sClass.base)
2258 if(sClass.templateClass) sClass = sClass.templateClass;
2259 id += sClass.templateParams.count;
2269 arg = &_class.templateArgs[id];
2270 if(arg && param.type == type)
2271 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2276 public Context SetupTemplatesContext(Class _class)
2278 Context context = PushContext();
2279 context.templateTypesOnly = true;
2280 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2282 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2283 for(; param; param = param.next)
2285 if(param.type == type && param.identifier)
2287 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2288 curContext.templateTypes.Add((BTNode)type);
2295 for(sClass = _class; sClass; sClass = sClass.base)
2297 ClassTemplateParameter p;
2298 for(p = sClass.templateParams.first; p; p = p.next)
2300 //OldList * specs = MkList();
2301 //Declarator decl = null;
2302 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2305 TemplateParameter param = p.param;
2309 // ADD DATA TYPE HERE...
2310 p.param = param = TemplateParameter
2312 identifier = MkIdentifier(p.name), type = p.type,
2313 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2316 type = TemplatedType { key = (uintptr)p.name, param = param };
2317 curContext.templateTypes.Add((BTNode)type);
2325 public void FinishTemplatesContext(Context context)
2327 PopContext(context);
2328 FreeContext(context);
2332 public void ProcessMethodType(Method method)
2334 if(!method.dataType)
2336 Context context = SetupTemplatesContext(method._class);
2338 method.dataType = ProcessTypeString(method.dataTypeString, false);
2340 FinishTemplatesContext(context);
2342 if(method.type != virtualMethod && method.dataType)
2344 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2346 if(!method._class.symbol)
2347 method._class.symbol = FindClass(method._class.fullName);
2348 method.dataType.thisClass = method._class.symbol;
2352 // Why was this commented out? Working fine without now...
2355 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2356 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2363 char * par = strstr(type, "(");
2364 char * classOp = null;
2369 for(c = par-type-1; c >= 0; c++)
2371 if(type[c] == ':' && type[c+1] == ':')
2373 classOp = type + c - 1;
2374 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2381 else if(!isspace(type[c]))
2388 int typeLen = strlen(type);
2389 memcpy(temp, classOp, classOpLen);
2390 temp[classOpLen] = '\0';
2392 _class = eSystem_FindClass(module, temp);
2395 method.dataTypeString = new char[typeLen - classOpLen + 1];
2396 memcpy(method.dataTypeString, type, classOp - type);
2397 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2400 method.dataTypeString = type;
2406 public void ProcessPropertyType(Property prop)
2410 Context context = SetupTemplatesContext(prop._class);
2411 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2412 FinishTemplatesContext(context);
2416 public void DeclareMethod(Method method, char * name)
2418 Symbol symbol = method.symbol;
2419 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2421 bool imported = false;
2422 bool dllImport = false;
2424 if(!method.dataType)
2425 method.dataType = ProcessTypeString(method.dataTypeString, false);
2427 if(!symbol || symbol._import || method.type == virtualMethod)
2429 if(!symbol || method.type == virtualMethod)
2432 if(!method._class.symbol)
2433 method._class.symbol = FindClass(method._class.fullName);
2434 classSym = method._class.symbol;
2435 if(!classSym._import)
2437 ModuleImport module;
2439 if(method._class.module && method._class.module.name)
2440 module = FindModule(method._class.module);
2442 module = mainModule;
2443 classSym._import = ClassImport
2445 name = CopyString(method._class.fullName);
2446 isRemote = method._class.isRemote;
2448 module.classes.Add(classSym._import);
2452 symbol = method.symbol = Symbol { };
2456 symbol._import = (ClassImport)MethodImport
2458 name = CopyString(method.name);
2459 isVirtual = method.type == virtualMethod;
2461 classSym._import.methods.Add(symbol._import);
2465 // Set the symbol type
2469 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2471 else if(type.thisClass == (void *)-1)
2473 type.thisClass = null;
2476 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2477 symbol.type = method.dataType;
2478 if(symbol.type) symbol.type.refCount++;
2481 if(!method.thisClass || strcmp(method.thisClass, "void"))
2482 symbol.type.params.Insert(null,
2483 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2486 if(!method.dataType.dllExport)
2489 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2495 if(!method.dataType)
2496 method.dataType = ((Symbol)method.symbol).type;
2497 //ProcessMethodType(method);
2500 if(method.type != virtualMethod && method.dataType)
2501 DeclareType(method.dataType, true, true);
2503 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2505 // We need a declaration here :)
2507 OldList * specifiers, * declarators;
2509 Declarator funcDecl;
2512 specifiers = MkList();
2513 declarators = MkList();
2517 ListAdd(specifiers, MkSpecifier(EXTERN));
2518 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2519 ListAdd(specifiers, MkSpecifier(STATIC));
2521 if(method.type == virtualMethod)
2523 ListAdd(specifiers, MkSpecifier(INT));
2524 d = MkDeclaratorIdentifier(MkIdentifier(name));
2528 d = MkDeclaratorIdentifier(MkIdentifier(name));
2531 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2533 Context context = SetupTemplatesContext(method._class);
2534 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2535 FinishTemplatesContext(context);
2537 funcDecl = GetFuncDecl(d);
2541 Specifier spec, next;
2542 for(spec = specifiers->first; spec; spec = next)
2545 if(spec.type == extendedSpecifier)
2547 specifiers->Remove(spec);
2548 FreeSpecifier(spec);
2553 // Add this parameter if not a static method
2554 if(method.dataType && !method.dataType.staticMethod)
2556 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2558 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2559 TypeName thisParam = MkTypeName(MkListOne(
2560 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2561 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2562 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2563 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2565 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2567 TypeName param = funcDecl.function.parameters->first;
2568 funcDecl.function.parameters->Remove(param);
2569 FreeTypeName(param);
2572 if(!funcDecl.function.parameters)
2573 funcDecl.function.parameters = MkList();
2574 funcDecl.function.parameters->Insert(null, thisParam);
2577 // Make sure we don't have empty parameter declarations for static methods...
2579 else if(!funcDecl.function.parameters)
2581 funcDecl.function.parameters = MkList();
2582 funcDecl.function.parameters->Insert(null,
2583 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2587 ProcessDeclarator(d);
2589 ListAdd(declarators, MkInitDeclarator(d, null));
2591 decl = MkDeclaration(specifiers, declarators);
2593 ReplaceThisClassSpecifiers(specifiers, method._class);
2595 // Keep a different symbol for the function definition than the declaration...
2596 if(symbol.pointerExternal)
2598 Symbol functionSymbol { };
2602 *functionSymbol = *symbol;
2603 functionSymbol.string = CopyString(symbol.string);
2604 if(functionSymbol.type)
2605 functionSymbol.type.refCount++;
2608 excludedSymbols->Add(functionSymbol);
2609 symbol.pointerExternal.symbol = functionSymbol;
2611 external = MkExternalDeclaration(decl);
2613 ast->Insert(curExternal ? curExternal.prev : null, external);
2614 external.symbol = symbol;
2615 symbol.pointerExternal = external;
2619 // Move declaration higher...
2620 ast->Move(symbol.pointerExternal, curExternal.prev);
2623 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2627 char * ReplaceThisClass(Class _class)
2629 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2633 ClassTemplateParameter param;
2636 char className[1024];
2637 strcpy(className, _class.fullName);
2638 for(param = _class.templateParams.first; param; param = param.next)
2640 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2642 if(first) strcat(className, "<");
2643 if(!first) strcat(className, ", ");
2644 if(lastParam + 1 != p)
2646 strcat(className, param.name);
2647 strcat(className, " = ");
2649 strcat(className, param.name);
2657 int len = strlen(className);
2658 if(className[len-1] == '>') className[len++] = ' ';
2659 className[len++] = '>';
2660 className[len++] = '\0';
2662 return CopyString(className);
2665 return CopyString(_class.fullName);
2668 Type ReplaceThisClassType(Class _class)
2670 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2674 ClassTemplateParameter param;
2676 char className[1024];
2677 strcpy(className, _class.fullName);
2679 for(param = _class.templateParams.first; param; param = param.next)
2681 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2683 if(first) strcat(className, "<");
2684 if(!first) strcat(className, ", ");
2685 if(lastParam + 1 != p)
2687 strcat(className, param.name);
2688 strcat(className, " = ");
2690 strcat(className, param.name);
2698 int len = strlen(className);
2699 if(className[len-1] == '>') className[len++] = ' ';
2700 className[len++] = '>';
2701 className[len++] = '\0';
2703 return MkClassType(className);
2704 //return ProcessTypeString(className, false);
2708 return MkClassType(_class.fullName);
2709 //return ProcessTypeString(_class.fullName, false);
2713 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2715 if(specs != null && _class)
2718 for(spec = specs.first; spec; spec = spec.next)
2720 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2722 spec.type = nameSpecifier;
2723 spec.name = ReplaceThisClass(_class);
2724 spec.symbol = FindClass(spec.name); //_class.symbol;
2730 // Returns imported or not
2731 bool DeclareFunction(GlobalFunction function, char * name)
2733 Symbol symbol = function.symbol;
2734 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2736 bool imported = false;
2737 bool dllImport = false;
2739 if(!function.dataType)
2741 function.dataType = ProcessTypeString(function.dataTypeString, false);
2742 if(!function.dataType.thisClass)
2743 function.dataType.staticMethod = true;
2750 ModuleImport module = FindModule(function.module);
2751 // WARNING: This is not added anywhere...
2752 symbol = function.symbol = Symbol { };
2756 if(!function.dataType.dllExport)
2758 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2759 module.functions.Add(symbol._import);
2762 // Set the symbol type
2764 symbol.type = ProcessTypeString(function.dataTypeString, false);
2765 if(!symbol.type.thisClass)
2766 symbol.type.staticMethod = true;
2769 imported = symbol._import ? true : false;
2770 if(imported && function.module != privateModule && function.module.importType != staticImport)
2774 DeclareType(function.dataType, true, true);
2778 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2780 // We need a declaration here :)
2782 OldList * specifiers, * declarators;
2784 Declarator funcDecl;
2787 specifiers = MkList();
2788 declarators = MkList();
2791 ListAdd(specifiers, MkSpecifier(EXTERN));
2794 ListAdd(specifiers, MkSpecifier(STATIC));
2797 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2800 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2802 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2803 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2804 if(function.module.importType == staticImport)
2807 for(spec = specifiers->first; spec; spec = spec.next)
2808 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2810 specifiers->Remove(spec);
2811 FreeSpecifier(spec);
2816 funcDecl = GetFuncDecl(d);
2818 // Make sure we don't have empty parameter declarations for static methods...
2819 if(funcDecl && !funcDecl.function.parameters)
2821 funcDecl.function.parameters = MkList();
2822 funcDecl.function.parameters->Insert(null,
2823 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2826 ListAdd(declarators, MkInitDeclarator(d, null));
2829 Context oldCtx = curContext;
2830 curContext = globalContext;
2831 decl = MkDeclaration(specifiers, declarators);
2832 curContext = oldCtx;
2835 // Keep a different symbol for the function definition than the declaration...
2836 if(symbol.pointerExternal)
2838 Symbol functionSymbol { };
2841 *functionSymbol = *symbol;
2842 functionSymbol.string = CopyString(symbol.string);
2843 if(functionSymbol.type)
2844 functionSymbol.type.refCount++;
2847 excludedSymbols->Add(functionSymbol);
2849 symbol.pointerExternal.symbol = functionSymbol;
2851 external = MkExternalDeclaration(decl);
2853 ast->Insert(curExternal.prev, external);
2854 external.symbol = symbol;
2855 symbol.pointerExternal = external;
2859 // Move declaration higher...
2860 ast->Move(symbol.pointerExternal, curExternal.prev);
2864 symbol.id = curExternal.symbol.idCode;
2867 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2870 void DeclareGlobalData(GlobalData data)
2872 Symbol symbol = data.symbol;
2873 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2878 symbol = data.symbol = Symbol { };
2881 data.dataType = ProcessTypeString(data.dataTypeString, false);
2882 DeclareType(data.dataType, true, true);
2885 if(!symbol.pointerExternal)
2887 // We need a declaration here :)
2889 OldList * specifiers, * declarators;
2893 specifiers = MkList();
2894 declarators = MkList();
2896 ListAdd(specifiers, MkSpecifier(EXTERN));
2897 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2898 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2900 ListAdd(declarators, MkInitDeclarator(d, null));
2902 decl = MkDeclaration(specifiers, declarators);
2903 external = MkExternalDeclaration(decl);
2905 ast->Insert(curExternal.prev, external);
2906 external.symbol = symbol;
2907 symbol.pointerExternal = external;
2911 // Move declaration higher...
2912 ast->Move(symbol.pointerExternal, curExternal.prev);
2916 symbol.id = curExternal.symbol.idCode;
2921 class Conversion : struct
2923 Conversion prev, next;
2929 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2933 // Property convert;
2935 if(source.kind == templateType && dest.kind != templateType)
2937 Type type = ProcessTemplateParameterType(source.templateParameter);
2938 if(type) source = type;
2941 if(dest.kind == templateType && source.kind != templateType)
2943 Type type = ProcessTemplateParameterType(dest.templateParameter);
2944 if(type) dest = type;
2947 if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
2952 if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
2957 if((dest.kind == structType && source.kind == structType) ||
2958 (dest.kind == unionType && source.kind == unionType))
2960 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2961 (source.members.first && source.members.first == dest.members.first))
2965 if(dest.kind == ellipsisType && source.kind != voidType)
2968 if(dest.kind == pointerType && dest.type.kind == voidType &&
2969 ((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))
2970 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2972 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2974 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2976 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2977 ((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))
2978 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2980 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2982 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2985 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2987 if(source._class.registered && source._class.registered.type == unitClass)
2989 if(conversions != null)
2991 if(source._class.registered == dest._class.registered)
2996 Class sourceBase, destBase;
2997 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2998 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2999 if(sourceBase == destBase)
3003 // Don't match enum inheriting from other enum if resolving enumeration values
3004 // TESTING: !dest.classObjectType
3005 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3007 (!source._class.registered || source._class.registered.type != enumClass) ||
3008 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3012 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3014 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3015 source._class && source._class.registered && source._class.registered.type != enumClass)
3017 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3025 // JUST ADDED THIS...
3026 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3031 // Just added this for Straight conversion of ColorAlpha => Color
3032 if(source.kind == classType)
3035 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3038 for(convert = _class.conversions.first; convert; convert = convert.next)
3040 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3042 Conversion after = (conversions != null) ? conversions.last : null;
3044 if(!convert.dataType)
3045 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3046 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
3048 if(!conversions && !convert.Get)
3050 else if(conversions != null)
3052 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3053 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3054 (dest.kind != classType || dest._class.registered != _class.base))
3058 Conversion conv { convert = convert, isGet = true };
3059 // conversions.Add(conv);
3060 conversions.Insert(after, conv);
3072 if(dest.kind == classType)
3075 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3078 for(convert = _class.conversions.first; convert; convert = convert.next)
3080 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3082 // Conversion after = (conversions != null) ? conversions.last : null;
3084 if(!convert.dataType)
3085 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3086 // Just added this equality check to prevent recursion.... Make it safer?
3087 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3088 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3090 if(!conversions && !convert.Set)
3092 else if(conversions != null)
3094 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3095 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3096 (source.kind != classType || source._class.registered != _class.base))
3100 // *** Testing this! ***
3101 Conversion conv { convert = convert };
3102 conversions.Add(conv);
3103 //conversions.Insert(after, conv);
3111 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3113 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3114 (source.kind != classType || source._class.registered.type != structClass))
3118 // TESTING THIS... IS THIS OK??
3119 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3121 if(!dest._class.registered.dataType)
3122 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3123 // Only support this for classes...
3124 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3125 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3127 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3136 if(source.kind == classType)
3139 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3142 for(convert = _class.conversions.first; convert; convert = convert.next)
3144 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3146 Conversion after = (conversions != null) ? conversions.last : null;
3148 if(!convert.dataType)
3149 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3150 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3152 if(!conversions && !convert.Get)
3154 else if(conversions != null)
3156 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3157 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3158 (dest.kind != classType || dest._class.registered != _class.base))
3162 Conversion conv { convert = convert, isGet = true };
3164 // conversions.Add(conv);
3165 conversions.Insert(after, conv);
3174 // TESTING THIS... IS THIS OK??
3175 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3177 if(!source._class.registered.dataType)
3178 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3179 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3187 if(source.kind == classType || source.kind == subClassType)
3189 else if(dest.kind == source.kind &&
3190 (dest.kind != structType && dest.kind != unionType &&
3191 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3193 // RECENTLY ADDED THESE
3194 else if(dest.kind == doubleType && source.kind == floatType)
3196 else if(dest.kind == shortType && source.kind == charType)
3198 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType))
3200 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType))
3202 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType))
3204 else if(source.kind == enumType &&
3205 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType))
3207 else if(dest.kind == enumType &&
3208 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType))
3210 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3211 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3213 Type paramSource, paramDest;
3215 if(dest.kind == methodType)
3216 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3217 if(source.kind == methodType)
3218 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3220 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3221 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3222 if(dest.kind == methodType)
3223 dest = dest.method.dataType;
3224 if(source.kind == methodType)
3225 source = source.method.dataType;
3227 paramSource = source.params.first;
3228 if(paramSource && paramSource.kind == voidType) paramSource = null;
3229 paramDest = dest.params.first;
3230 if(paramDest && paramDest.kind == voidType) paramDest = null;
3233 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3234 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3236 // Source thisClass must be derived from destination thisClass
3237 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3238 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3240 if(paramDest && paramDest.kind == classType)
3241 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3243 Compiler_Error($"method class should not take an object\n");
3246 paramDest = paramDest.next;
3248 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3250 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3254 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3256 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3262 // THIS WAS BACKWARDS:
3263 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3264 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3267 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3269 Compiler_Error($"overriding class expected to be derived from method class\n");
3273 paramSource = paramSource.next;
3279 // Source thisClass must be derived from destination thisClass
3280 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3282 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3288 // THIS WAS BACKWARDS TOO??
3289 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3290 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3293 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3295 //Compiler_Error($"overriding class expected to be derived from method class\n");
3303 // Source return type must be derived from destination return type
3304 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3306 Compiler_Warning($"incompatible return type for function\n");
3312 for(; paramDest; paramDest = paramDest.next)
3316 //Compiler_Warning($"not enough parameters\n");
3317 Compiler_Error($"not enough parameters\n");
3321 Type paramDestType = paramDest;
3322 Type paramSourceType = paramSource;
3323 Type type = paramDestType;
3325 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3326 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3327 paramSource.kind != templateType)
3330 ClassTemplateParameter curParam = null;
3332 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3335 if(sClass.templateClass) sClass = sClass.templateClass;
3336 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3338 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3340 for(sClass = sClass.base; sClass; sClass = sClass.base)
3342 if(sClass.templateClass) sClass = sClass.templateClass;
3343 id += sClass.templateParams.count;
3354 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3355 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3359 // paramDest must be derived from paramSource
3360 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3361 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3365 PrintType(paramDest, type, false, true);
3366 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3368 if(paramDestType != paramDest)
3369 FreeType(paramDestType);
3372 if(paramDestType != paramDest)
3373 FreeType(paramDestType);
3376 paramSource = paramSource.next;
3380 Compiler_Error($"too many parameters\n");
3385 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3389 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3390 (source.kind == arrayType || source.kind == pointerType))
3392 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3399 static void FreeConvert(Conversion convert)
3401 if(convert.resultType)
3402 FreeType(convert.resultType);
3405 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3406 char * string, OldList conversions)
3410 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3412 Class _class = link.data;
3413 if(_class.type == enumClass)
3415 OldList converts { };
3417 type.kind = classType;
3420 _class.symbol = FindClass(_class.fullName);
3421 type._class = _class.symbol;
3423 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3426 Class enumClass = eSystem_FindClass(privateModule, "enum");
3430 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3432 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3433 for(value = e.values.first; value; value = value.next)
3435 if(!strcmp(value.name, string))
3440 FreeExpContents(sourceExp);
3441 FreeType(sourceExp.expType);
3443 sourceExp.isConstant = true;
3444 sourceExp.expType = MkClassType(baseClass.fullName);
3448 sourceExp.type = constantExp;
3449 if(!strcmp(baseClass.dataTypeString, "int"))
3450 sprintf(constant, "%d",value.data);
3452 sprintf(constant, "0x%X",value.data);
3453 sourceExp.constant = CopyString(constant);
3454 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3457 while(converts.first)
3459 Conversion convert = converts.first;
3460 converts.Remove(convert);
3461 conversions.Add(convert);
3470 converts.Free(FreeConvert);
3474 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3475 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3480 public bool ModuleVisibility(Module searchIn, Module searchFor)
3482 SubModule subModule;
3484 if(searchFor == searchIn)
3487 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3489 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3491 if(ModuleVisibility(subModule.module, searchFor))
3498 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3502 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3504 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3506 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3509 for(module = mainModule.application.allModules.first; module; module = module.next)
3511 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3517 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3519 Type source = sourceExp.expType;
3520 Type realDest = dest;
3522 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3525 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3527 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3529 Class sourceBase, destBase;
3530 for(sourceBase = source._class.registered;
3531 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3532 sourceBase = sourceBase.base);
3533 for(destBase = dest._class.registered;
3534 destBase && destBase.base && destBase.base.type != systemClass;
3535 destBase = destBase.base);
3536 //if(source._class.registered == dest._class.registered)
3537 if(sourceBase == destBase)
3546 int64 value = MAXINT;
3551 if(sourceExp.type == constantExp)
3554 value = strtoll(sourceExp.constant, null, 0);
3556 value = strtoull(sourceExp.constant, null, 0);
3558 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3561 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3563 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3566 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3567 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3570 source = Type { kind = intType, isSigned = false, refCount = 1 };
3573 if(dest.kind == classType)
3575 Class _class = dest._class ? dest._class.registered : null;
3577 if(_class && _class.type == unitClass)
3579 if(source.kind != classType)
3582 Type tempDest, tempSource;
3584 for(; _class.base.type != systemClass; _class = _class.base);
3586 tempDest = tempType;
3588 tempType.kind = classType;
3590 _class.symbol = FindClass(_class.fullName);
3592 tempType._class = _class.symbol;
3593 tempType.truth = dest.truth;
3595 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3597 FreeType(sourceExp.expType);
3598 sourceExp.expType = dest; dest.refCount++;
3600 //sourceExp.expType = MkClassType(_class.fullName);
3608 // Why wasn't there something like this?
3609 if(_class && _class.type == bitClass && source.kind != classType)
3611 if(!dest._class.registered.dataType)
3612 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3613 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3616 FreeType(sourceExp.expType);
3617 source = sourceExp.expType = MkClassType(dest._class.string);
3620 //source.kind = classType;
3621 //source._class = dest._class;
3625 // Adding two enumerations
3627 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3629 if(!source._class.registered.dataType)
3630 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3631 if(!dest._class.registered.dataType)
3632 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3634 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3637 source = sourceExp.expType = MkClassType(dest._class.string);
3640 //source.kind = classType;
3641 //source._class = dest._class;
3645 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3647 OldList * specs = MkList();
3651 ReadString(string, sourceExp.string);
3652 decl = SpecDeclFromString(string, specs, null);
3654 FreeExpContents(sourceExp);
3655 FreeType(sourceExp.expType);
3657 sourceExp.type = classExp;
3658 sourceExp._classExp.specifiers = specs;
3659 sourceExp._classExp.decl = decl;
3660 sourceExp.expType = dest;
3668 else if(source.kind == classType)
3670 Class _class = source._class ? source._class.registered : null;
3672 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3675 if(dest.kind != classType)
3677 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3678 if(!source._class.registered.dataType)
3679 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3682 dest = MkClassType(source._class.string);
3683 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3684 // dest = MkClassType(source._class.string);
3688 if(dest.kind != classType)
3691 Type tempDest, tempSource;
3693 if(!source._class.registered.dataType)
3694 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3696 for(; _class.base.type != systemClass; _class = _class.base);
3698 tempSource = tempType;
3699 tempType.kind = classType;
3700 tempType._class = FindClass(_class.fullName);
3701 tempType.truth = source.truth;
3702 tempType.classObjectType = source.classObjectType;
3705 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3707 // PUT THIS BACK TESTING UNITS?
3708 if(conversions.last)
3710 ((Conversion)(conversions.last)).resultType = dest;
3714 FreeType(sourceExp.expType);
3715 sourceExp.expType = MkClassType(_class.fullName);
3716 sourceExp.expType.truth = source.truth;
3717 sourceExp.expType.classObjectType = source.classObjectType;
3719 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3721 if(!sourceExp.destType)
3723 FreeType(sourceExp.destType);
3724 sourceExp.destType = sourceExp.expType;
3725 if(sourceExp.expType)
3726 sourceExp.expType.refCount++;
3729 //source = _class.dataType;
3732 // TOCHECK: TESTING THIS NEW CODE
3733 if(!_class.dataType)
3734 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3736 dest = MkClassType(source._class.string);
3737 dest.truth = source.truth;
3738 dest.classObjectType = source.classObjectType;
3741 source = _class.dataType;
3751 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3761 if(source.kind == classType)
3763 Class _class = source._class.registered;
3764 if(_class.type == unitClass)
3766 if(!_class.dataType)
3767 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3768 source = _class.dataType;
3772 if(dest.kind == classType)
3774 Class _class = dest._class ? dest._class.registered : null;
3775 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3776 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3778 if(_class.type == normalClass || _class.type == noHeadClass)
3780 Expression newExp { };
3781 *newExp = *sourceExp;
3782 if(sourceExp.destType) sourceExp.destType.refCount++;
3783 if(sourceExp.expType) sourceExp.expType.refCount++;
3784 sourceExp.type = castExp;
3785 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3786 sourceExp.cast.exp = newExp;
3787 FreeType(sourceExp.expType);
3788 sourceExp.expType = null;
3789 ProcessExpressionType(sourceExp);
3791 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3794 FreeType(sourceExp.expType);
3795 sourceExp.expType = dest;
3799 if(inCompiler) FreeType(dest);
3804 if(!_class.dataType)
3805 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3807 dest = _class.dataType;
3811 // Accept lower precision types for units, since we want to keep the unit type
3812 if(dest.kind == doubleType &&
3813 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3814 source.kind == charType))
3816 specs = MkListOne(MkSpecifier(DOUBLE));
3818 else if(dest.kind == floatType &&
3819 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3820 source.kind == doubleType))
3822 specs = MkListOne(MkSpecifier(FLOAT));
3824 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3825 source.kind == floatType || source.kind == doubleType))
3828 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3829 ListAdd(specs, MkSpecifier(INT64));
3831 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3832 source.kind == floatType || source.kind == doubleType))
3835 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3836 ListAdd(specs, MkSpecifier(INT));
3838 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3839 source.kind == floatType || source.kind == doubleType))
3842 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3843 ListAdd(specs, MkSpecifier(SHORT));
3845 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3846 source.kind == floatType || source.kind == doubleType))
3849 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3850 ListAdd(specs, MkSpecifier(CHAR));
3859 else if(dest.kind == doubleType &&
3860 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3861 source.kind == charType))
3863 specs = MkListOne(MkSpecifier(DOUBLE));
3865 else if(dest.kind == floatType &&
3866 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3868 specs = MkListOne(MkSpecifier(FLOAT));
3870 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3871 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3874 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3875 ListAdd(specs, MkSpecifier(CHAR));
3877 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3878 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3881 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3882 ListAdd(specs, MkSpecifier(SHORT));
3884 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3887 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3888 ListAdd(specs, MkSpecifier(INT));
3890 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3893 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3894 ListAdd(specs, MkSpecifier(INT64));
3896 else if(dest.kind == enumType &&
3897 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3899 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3910 Expression newExp { };
3911 *newExp = *sourceExp;
3914 if(sourceExp.destType) sourceExp.destType.refCount++;
3915 if(sourceExp.expType) sourceExp.expType.refCount++;
3917 sourceExp.type = castExp;
3918 if(realDest.kind == classType)
3920 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3921 FreeList(specs, FreeSpecifier);
3924 sourceExp.cast.typeName = MkTypeName(specs, null);
3925 if(newExp.type == opExp)
3927 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3930 sourceExp.cast.exp = newExp;
3932 FreeType(sourceExp.expType);
3933 sourceExp.expType = null;
3934 ProcessExpressionType(sourceExp);
3937 FreeList(specs, FreeSpecifier);
3945 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3946 if(sourceExp.type == identifierExp)
3948 Identifier id = sourceExp.identifier;
3949 if(dest.kind == classType)
3951 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3953 Class _class = dest._class.registered;
3954 Class enumClass = eSystem_FindClass(privateModule, "enum");
3957 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3960 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3961 for(value = e.values.first; value; value = value.next)
3963 if(!strcmp(value.name, id.string))
3968 FreeExpContents(sourceExp);
3969 FreeType(sourceExp.expType);
3971 sourceExp.isConstant = true;
3972 sourceExp.expType = MkClassType(_class.fullName);
3976 sourceExp.type = constantExp;
3977 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3978 sprintf(constant, "%d",value.data);
3980 sprintf(constant, "0x%X",value.data);
3981 sourceExp.constant = CopyString(constant);
3982 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3991 // Loop through all enum classes
3992 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3999 #define TERTIARY(o, name, m, t, p) \
4000 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4002 exp.type = constantExp; \
4003 exp.string = p(op1.m ? op2.m : op3.m); \
4005 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4009 #define BINARY(o, name, m, t, p) \
4010 static bool name(Expression exp, Operand op1, Operand op2) \
4013 exp.type = constantExp; \
4014 exp.string = p(op1.m o value2); \
4016 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4020 #define BINARY_DIVIDE(o, name, m, t, p) \
4021 static bool name(Expression exp, Operand op1, Operand op2) \
4024 exp.type = constantExp; \
4025 exp.string = p(value2 ? (op1.m o value2) : 0); \
4027 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4031 #define UNARY(o, name, m, t, p) \
4032 static bool name(Expression exp, Operand op1) \
4034 exp.type = constantExp; \
4035 exp.string = p(o op1.m); \
4037 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4041 #define OPERATOR_ALL(macro, o, name) \
4042 macro(o, Int##name, i, int, PrintInt) \
4043 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4044 macro(o, Short##name, s, short, PrintShort) \
4045 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4046 macro(o, Char##name, c, char, PrintChar) \
4047 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4048 macro(o, Float##name, f, float, PrintFloat) \
4049 macro(o, Double##name, d, double, PrintDouble)
4051 #define OPERATOR_INTTYPES(macro, o, name) \
4052 macro(o, Int##name, i, int, PrintInt) \
4053 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4054 macro(o, Short##name, s, short, PrintShort) \
4055 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4056 macro(o, Char##name, c, char, PrintChar) \
4057 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4060 // binary arithmetic
4061 OPERATOR_ALL(BINARY, +, Add)
4062 OPERATOR_ALL(BINARY, -, Sub)
4063 OPERATOR_ALL(BINARY, *, Mul)
4064 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4065 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4068 OPERATOR_ALL(UNARY, -, Neg)
4070 // unary arithmetic increment and decrement
4071 OPERATOR_ALL(UNARY, ++, Inc)
4072 OPERATOR_ALL(UNARY, --, Dec)
4074 // binary arithmetic assignment
4075 OPERATOR_ALL(BINARY, =, Asign)
4076 OPERATOR_ALL(BINARY, +=, AddAsign)
4077 OPERATOR_ALL(BINARY, -=, SubAsign)
4078 OPERATOR_ALL(BINARY, *=, MulAsign)
4079 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4080 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4083 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4084 OPERATOR_INTTYPES(BINARY, |, BitOr)
4085 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4086 OPERATOR_INTTYPES(BINARY, <<, LShift)
4087 OPERATOR_INTTYPES(BINARY, >>, RShift)
4090 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4092 // binary bitwise assignment
4093 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4094 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4095 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4096 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4097 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4099 // unary logical negation
4100 OPERATOR_INTTYPES(UNARY, !, Not)
4102 // binary logical equality
4103 OPERATOR_ALL(BINARY, ==, Equ)
4104 OPERATOR_ALL(BINARY, !=, Nqu)
4107 OPERATOR_ALL(BINARY, &&, And)
4108 OPERATOR_ALL(BINARY, ||, Or)
4110 // binary logical relational
4111 OPERATOR_ALL(BINARY, >, Grt)
4112 OPERATOR_ALL(BINARY, <, Sma)
4113 OPERATOR_ALL(BINARY, >=, GrtEqu)
4114 OPERATOR_ALL(BINARY, <=, SmaEqu)
4116 // tertiary condition operator
4117 OPERATOR_ALL(TERTIARY, ?, Cond)
4119 //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
4120 #define OPERATOR_TABLE_ALL(name, type) \
4121 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4123 type##Inc, type##Dec, \
4124 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4125 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4127 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4129 type##Equ, type##Nqu, \
4130 type##And, type##Or, \
4131 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4134 #define OPERATOR_TABLE_INTTYPES(name, type) \
4135 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4137 type##Inc, type##Dec, \
4138 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4139 null, null, null, null, null, \
4141 null, null, null, null, null, \
4143 type##Equ, type##Nqu, \
4144 type##And, type##Or, \
4145 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4148 OPERATOR_TABLE_ALL(int, Int)
4149 OPERATOR_TABLE_ALL(uint, UInt)
4150 OPERATOR_TABLE_ALL(short, Short)
4151 OPERATOR_TABLE_ALL(ushort, UShort)
4152 OPERATOR_TABLE_INTTYPES(float, Float)
4153 OPERATOR_TABLE_INTTYPES(double, Double)
4154 OPERATOR_TABLE_ALL(char, Char)
4155 OPERATOR_TABLE_ALL(uchar, UChar)
4157 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4158 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4159 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4160 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4161 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4162 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4163 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4164 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4166 public void ReadString(char * output, char * string)
4168 int len = strlen(string);
4170 bool quoted = false, escaped = false;
4171 for(c = 0; c<len; c++)
4173 char ch = string[c];
4178 case 'n': output[d] = '\n'; break;
4179 case 't': output[d] = '\t'; break;
4180 case 'a': output[d] = '\a'; break;
4181 case 'b': output[d] = '\b'; break;
4182 case 'f': output[d] = '\f'; break;
4183 case 'r': output[d] = '\r'; break;
4184 case 'v': output[d] = '\v'; break;
4185 case '\\': output[d] = '\\'; break;
4186 case '\"': output[d] = '\"'; break;
4187 default: output[d++] = '\\'; output[d] = ch;
4188 //default: output[d] = ch;
4209 public Operand GetOperand(Expression exp)
4212 Type type = exp.expType;
4215 while(type.kind == classType &&
4216 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4218 if(!type._class.registered.dataType)
4219 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4220 type = type._class.registered.dataType;
4223 op.kind = type.kind;
4224 op.type = exp.expType;
4225 if(exp.isConstant && exp.type == constantExp)
4231 if(exp.constant[0] == '\'')
4232 op.c = exp.constant[1];
4233 else if(type.isSigned)
4235 op.c = (char)strtol(exp.constant, null, 0);
4240 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4248 op.s = (short)strtol(exp.constant, null, 0);
4253 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4261 op.i = (int)strtol(exp.constant, null, 0);
4266 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4274 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4279 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4287 op.iptr = (intptr)_strtoi64(exp.constant, null, 0);
4292 op.uiptr = (uintptr)_strtoui64(exp.constant, null, 0);
4298 op.f = (float)strtod(exp.constant, null);
4302 op.d = (double)strtod(exp.constant, null);
4305 //case classType: For when we have operator overloading...
4306 // Pointer additions
4307 //case functionType:
4311 op.p = (unsigned char *)strtoul(exp.constant, null, 0);
4312 op.kind = pointerType;
4322 static void UnusedFunction()
4325 a.OnGetString(0,0,0);
4328 extern int __ecereVMethodID_class_OnGetString;
4331 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4333 DataMember dataMember;
4334 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4336 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4337 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4341 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4343 void * ptr = inst.data + dataMember.offset + offset;
4344 char * result = null;
4345 exp.loc = member.loc = inst.loc;
4346 ((Identifier)member.identifiers->first).loc = inst.loc;
4348 if(!dataMember.dataType)
4349 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4350 type = dataMember.dataType;
4351 if(type.kind == classType)
4353 Class _class = type._class.registered;
4354 if(_class.type == enumClass)
4356 Class enumClass = eSystem_FindClass(privateModule, "enum");
4359 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4361 for(item = e.values.first; item; item = item.next)
4363 if((int)item.data == *(int *)ptr)
4371 exp.identifier = MkIdentifier(result);
4372 exp.type = identifierExp;
4373 exp.destType = MkClassType(_class.fullName);
4374 ProcessExpressionType(exp);
4378 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4380 if(!_class.dataType)
4381 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4382 type = _class.dataType;
4391 FreeExpContents(exp);
4393 exp.constant = PrintFloat(*(float*)ptr);
4394 exp.type = constantExp;
4399 FreeExpContents(exp);
4401 exp.constant = PrintDouble(*(double*)ptr);
4402 exp.type = constantExp;
4407 FreeExpContents(exp);
4409 exp.constant = PrintInt(*(int*)ptr);
4410 exp.type = constantExp;
4415 FreeExpContents(exp);
4417 exp.constant = PrintInt64(*(int64*)ptr);
4418 exp.type = constantExp;
4423 FreeExpContents(exp);
4425 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4426 exp.type = constantExp;
4430 Compiler_Error($"Unhandled type populating instance\n");
4433 ListAdd(memberList, member);
4436 if(parentDataMember.type == unionMember)
4441 void PopulateInstance(Instantiation inst)
4443 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4444 Class _class = classSym.registered;
4445 DataMember dataMember;
4446 OldList * memberList = MkList();
4447 inst.members = MkListOne(MkMembersInitList(memberList));
4448 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4450 if(!dataMember.isProperty)
4452 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4453 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4457 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4459 void * ptr = inst.data + dataMember.offset;
4460 char * result = null;
4462 exp.loc = member.loc = inst.loc;
4463 ((Identifier)member.identifiers->first).loc = inst.loc;
4465 if(!dataMember.dataType)
4466 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4467 type = dataMember.dataType;
4468 if(type.kind == classType)
4470 Class _class = type._class.registered;
4471 if(_class.type == enumClass)
4473 Class enumClass = eSystem_FindClass(privateModule, "enum");
4476 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4478 for(item = e.values.first; item; item = item.next)
4480 if((int)item.data == *(int *)ptr)
4489 exp.identifier = MkIdentifier(result);
4490 exp.type = identifierExp;
4491 exp.destType = MkClassType(_class.fullName);
4492 ProcessExpressionType(exp);
4495 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4497 if(!_class.dataType)
4498 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4499 type = _class.dataType;
4508 exp.constant = PrintFloat(*(float*)ptr);
4509 exp.type = constantExp;
4514 exp.constant = PrintDouble(*(double*)ptr);
4515 exp.type = constantExp;
4520 exp.constant = PrintInt(*(int*)ptr);
4521 exp.type = constantExp;
4526 exp.constant = PrintInt64(*(int64*)ptr);
4527 exp.type = constantExp;
4532 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4533 exp.type = constantExp;
4537 Compiler_Error($"Unhandled type populating instance\n");
4540 ListAdd(memberList, member);
4546 void ComputeInstantiation(Expression exp)
4548 Instantiation inst = exp.instance;
4549 MembersInit members;
4550 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4551 Class _class = classSym ? classSym.registered : null;
4552 DataMember curMember = null;
4553 Class curClass = null;
4554 DataMember subMemberStack[256];
4555 int subMemberStackPos = 0;
4558 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4560 // Don't recompute the instantiation...
4561 // Non Simple classes will have become constants by now
4565 if(_class.type == normalClass || _class.type == noHeadClass)
4566 inst.data = (byte *)eInstance_New(_class);
4568 inst.data = new0 byte[_class.structSize];
4573 for(members = inst.members->first; members; members = members.next)
4575 switch(members.type)
4577 case dataMembersInit:
4579 if(members.dataMembers)
4582 for(member = members.dataMembers->first; member; member = member.next)
4584 Identifier ident = member.identifiers ? member.identifiers->first : null;
4587 Property prop = null;
4588 DataMember dataMember = null;
4589 Method method = null;
4590 uint dataMemberOffset;
4594 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4597 if(curMember.isProperty)
4598 prop = (Property)curMember;
4601 dataMember = curMember;
4603 // CHANGED THIS HERE
4604 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4605 // dataMemberOffset = dataMember.offset;
4612 prop = eClass_FindProperty(_class, ident.string, privateModule);
4616 if(prop.memberAccess == publicAccess)
4618 curMember = (DataMember)prop;
4619 curClass = prop._class;
4624 DataMember _subMemberStack[256];
4625 int _subMemberStackPos = 0;
4627 // FILL MEMBER STACK
4628 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4633 if(dataMember.memberAccess == publicAccess)
4635 curMember = dataMember;
4636 curClass = dataMember._class;
4637 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4638 subMemberStackPos = _subMemberStackPos;
4644 if(found && member.initializer && member.initializer.type == expInitializer)
4646 Expression value = member.initializer.exp;
4650 type = prop.dataType;
4654 if(!dataMember.dataType)
4655 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4657 type = dataMember.dataType;
4660 if(ident && ident.next)
4662 // for(; ident && type; ident = ident.next)
4663 for(ident = ident.next; ident && type; ident = ident.next)
4665 if(type.kind == classType)
4667 prop = eClass_FindProperty(type._class.registered,
4668 ident.string, privateModule);
4670 type = prop.dataType;
4673 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4674 ident.string, &dataMemberOffset, privateModule, null, null);
4676 type = dataMember.dataType;
4679 else if(type.kind == structType || type.kind == unionType)
4682 for(memberType = type.members.first; memberType; memberType = memberType.next)
4684 if(!strcmp(memberType.name, ident.string))
4695 FreeType(value.destType);
4696 value.destType = type;
4697 if(type) type.refCount++;
4698 ComputeExpression(value);
4700 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4702 if(type.kind == classType)
4704 Class _class = type._class.registered;
4705 if(_class.type == bitClass || _class.type == unitClass ||
4706 _class.type == enumClass)
4708 if(!_class.dataType)
4709 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4710 type = _class.dataType;
4716 void * ptr = inst.data + dataMemberOffset;
4718 if(value.type == constantExp)
4724 GetInt(value, (int*)ptr);
4729 GetInt64(value, (int64*)ptr);
4734 GetIntPtr(value, (intptr*)ptr);
4739 GetFloat(value, (float*)ptr);
4744 GetDouble(value, (double *)ptr);
4749 else if(value.type == instanceExp)
4751 if(type.kind == classType)
4753 Class _class = type._class.registered;
4754 if(_class.type == structClass)
4756 ComputeTypeSize(type);
4757 if(value.instance.data)
4758 memcpy(ptr, value.instance.data, type.size);
4765 if(value.type == instanceExp && value.instance.data)
4767 void (*Set)(void *, void *) = (void *)prop.Set;
4768 Set(inst.data, value.instance.data);
4769 PopulateInstance(inst);
4771 else if(value.type == constantExp)
4777 void (*Set)(void *, double) = (void *)prop.Set;
4778 Set(inst.data, strtod(value.constant, null) );
4783 void (*Set)(void *, float) = (void *)prop.Set;
4784 Set(inst.data, (float)(strtod(value.constant, null)));
4789 void (*Set)(void *, int) = (void *)prop.Set;
4790 Set(inst.data, strtol(value.constant, null, 0));
4795 void (*Set)(void *, int64) = (void *)prop.Set;
4796 Set(inst.data, _strtoi64(value.constant, null, 0));
4801 void (*Set)(void *, intptr) = (void *)prop.Set;
4802 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4807 else if(value.type == stringExp)
4810 ReadString(temp, value.string);
4811 prop.Set(inst.data, temp);
4815 else if(_class.type == unitClass)
4819 // Only support converting units to units for now...
4820 if(value.type == constantExp)
4822 if(type.kind == classType)
4824 Class _class = type._class.registered;
4825 if(_class.type == unitClass)
4827 if(!_class.dataType)
4828 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4829 type = _class.dataType;
4832 // TODO: Assuming same base type for units...
4838 float (*Set)(float) = (void *)prop.Set;
4839 GetFloat(member.initializer.exp, &fValue);
4840 exp.constant = PrintFloat(Set(fValue));
4841 exp.type = constantExp;
4847 double (*Set)(double) = (void *)prop.Set;
4848 GetDouble(member.initializer.exp, &dValue);
4849 exp.constant = PrintDouble(Set(dValue));
4850 exp.type = constantExp;
4857 else if(_class.type == bitClass)
4861 if(value.type == instanceExp && value.instance.data)
4863 unsigned int (*Set)(void *) = (void *)prop.Set;
4864 bits = Set(value.instance.data);
4866 else if(value.type == constantExp)
4872 BitMember bitMember = (BitMember) dataMember;
4875 GetInt(value, &part);
4876 bits = (bits & ~bitMember.mask);
4877 if(!bitMember.dataType)
4878 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4880 type = bitMember.dataType;
4882 if(type.kind == classType && type._class && type._class.registered)
4884 if(!type._class.registered.dataType)
4885 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4886 type = type._class.registered.dataType;
4893 bits |= ((char)part << bitMember.pos);
4895 bits |= ((unsigned char)part << bitMember.pos);
4899 bits |= ((short)part << bitMember.pos);
4901 bits |= ((unsigned short)part << bitMember.pos);
4906 bits |= ((int)part << bitMember.pos);
4908 bits |= ((unsigned int)part << bitMember.pos);
4912 bits |= ((int64)part << bitMember.pos);
4914 bits |= ((uint64)part << bitMember.pos);
4918 bits |= ((intptr)part << bitMember.pos);
4920 bits |= ((uintptr)part << bitMember.pos);
4928 if(_class && _class.type == unitClass)
4930 ComputeExpression(member.initializer.exp);
4931 exp.constant = member.initializer.exp.constant;
4932 exp.type = constantExp;
4934 member.initializer.exp.constant = null;
4944 if(_class && _class.type == bitClass)
4946 exp.constant = PrintHexUInt(bits);
4947 exp.type = constantExp;
4949 if(exp.type != instanceExp)
4955 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4957 if(exp.op.op == SIZEOF)
4959 FreeExpContents(exp);
4960 exp.type = constantExp;
4961 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4972 // Provide default unary +
4973 Expression exp2 = exp.op.exp2;
4975 FreeExpContents(exp);
4976 FreeType(exp.expType);
4977 FreeType(exp.destType);
4983 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4985 // unary arithmetic increment and decrement
4986 //OPERATOR_ALL(UNARY, ++, Inc)
4987 //OPERATOR_ALL(UNARY, --, Dec)
4990 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4992 // unary logical negation
4994 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5002 // binary arithmetic
5004 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5007 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5010 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5013 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5016 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5018 // binary arithmetic assignment
5019 //OPERATOR_ALL(BINARY, =, Asign)
5020 //OPERATOR_ALL(BINARY, +=, AddAsign)
5021 //OPERATOR_ALL(BINARY, -=, SubAsign)
5022 //OPERATOR_ALL(BINARY, *=, MulAsign)
5023 //OPERATOR_ALL(BINARY, /=, DivAsign)
5024 //OPERATOR_ALL(BINARY, %=, ModAsign)
5029 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5033 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5036 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5039 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5042 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5044 // binary bitwise assignment
5045 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5046 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5047 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5048 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5049 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5050 // binary logical equality
5052 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5055 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5059 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5062 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5064 // binary logical relational
5066 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5069 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5072 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5075 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5082 void ComputeExpression(Expression exp)
5084 char expString[10240];
5085 expString[0] = '\0';
5087 PrintExpression(exp, expString);
5094 ComputeInstantiation(exp);
5103 Expression exp1, exp2 = null;
5107 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5109 ComputeExpression(exp.op.exp2);
5112 ComputeExpression(exp.op.exp1);
5115 op1 = GetOperand(exp1);
5116 if(op1.type) op1.type.refCount++;
5119 op2 = GetOperand(exp2);
5120 if(op2.type) op2.type.refCount++;
5126 op1 = GetOperand(exp1);
5127 if(op1.type) op1.type.refCount++;
5130 CallOperator(exp, exp1, exp2, op1, op2);
5137 if(exp.op.exp1 && exp.op.exp2)
5142 FreeExpContents(exp);
5143 op1.ops.BitAnd(exp, op1, op2);
5152 FreeExpContents(exp);
5153 op1.ops.Mul(exp, op1, op2);
5162 FreeExpContents(exp);
5163 op1.ops.Add(exp, op1, op2);
5168 // Provide default unary +
5169 Expression exp2 = exp.op.exp2;
5171 FreeExpContents(exp);
5172 FreeType(exp.expType);
5173 FreeType(exp.destType);
5184 FreeExpContents(exp);
5185 op1.ops.Sub(exp, op1, op2);
5192 FreeExpContents(exp);
5193 op1.ops.Neg(exp, op1);
5200 FreeExpContents(exp);
5201 op1.ops.BitNot(exp, op1);
5207 FreeExpContents(exp);
5208 op1.ops.Not(exp, op1);
5211 // Binary only operators
5215 FreeExpContents(exp);
5216 op1.ops.Div(exp, op1, op2);
5222 FreeExpContents(exp);
5223 op1.ops.Mod(exp, op1, op2);
5235 FreeExpContents(exp);
5236 op1.ops.Sma(exp, op1, op2);
5245 FreeExpContents(exp);
5246 op1.ops.Grt(exp, op1, op2);
5255 FreeExpContents(exp);
5256 op1.ops.SmaEqu(exp, op1, op2);
5265 FreeExpContents(exp);
5266 op1.ops.GrtEqu(exp, op1, op2);
5275 FreeExpContents(exp);
5276 op1.ops.Equ(exp, op1, op2);
5285 FreeExpContents(exp);
5286 op1.ops.Nqu(exp, op1, op2);
5293 FreeExpContents(exp);
5294 op1.ops.BitOr(exp, op1, op2);
5300 FreeExpContents(exp);
5301 op1.ops.BitXor(exp, op1, op2);
5309 FreeExpContents(exp);
5310 exp.type = constantExp;
5311 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5315 if(op1.type) FreeType(op1.type);
5316 if(op2.type) FreeType(op2.type);
5320 case extensionExpressionExp:
5323 for(e = exp.list->first; e; e = n)
5328 OldList * list = exp.list;
5329 ComputeExpression(e);
5330 //FreeExpContents(exp);
5331 FreeType(exp.expType);
5332 FreeType(exp.destType);
5349 exp.isConstant = true;
5351 ComputeExpression(exp.index.exp);
5352 if(!exp.index.exp.isConstant)
5353 exp.isConstant = false;
5355 for(e = exp.index.index->first; e; e = e.next)
5357 ComputeExpression(e);
5360 // Check if this type is int
5363 exp.isConstant = false;
5365 exp.expType = Dereference(exp.index.exp.expType);
5371 Expression memberExp = exp.member.exp;
5372 Identifier memberID = exp.member.member;
5375 ComputeExpression(exp.member.exp);
5376 type = exp.member.exp.expType;
5379 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);
5380 Property prop = null;
5381 DataMember member = null;
5382 Class convertTo = null;
5383 if(type.kind == subClassType && exp.member.exp.type == classExp)
5384 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5391 PrintType(type, string, false, true);
5392 classSym = FindClass(string);
5393 _class = classSym ? classSym.registered : null;
5396 if(exp.member.member)
5398 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5400 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5402 if(!prop && !member && _class && exp.member.member)
5404 Symbol classSym = FindClass(exp.member.member.string);
5406 _class = classSym ? classSym.registered : null;
5407 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5414 Type type = prop.dataType;
5415 // TODO: Assuming same base type for units...
5416 if(_class.type == unitClass)
5418 if(type.kind == classType)
5420 Class _class = type._class.registered;
5421 if(_class.type == unitClass)
5423 if(!_class.dataType)
5424 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5425 type = _class.dataType;
5433 float (*Get)(float) = (void *)prop.Get;
5434 GetFloat(exp.member.exp, &value);
5435 exp.constant = PrintFloat(Get ? Get(value) : value);
5436 exp.type = constantExp;
5442 double (*Get)(double);
5443 GetDouble(exp.member.exp, &value);
5446 Get = (void *)prop.Set;
5448 Get = (void *)prop.Get;
5449 exp.constant = PrintDouble(Get ? Get(value) : value);
5450 exp.type = constantExp;
5459 Expression value = exp.member.exp;
5462 ProcessPropertyType(prop);
5464 type = prop.dataType;
5467 // printf("Investigate this\n");
5469 else if(_class.type == structClass)
5475 Class propertyClass = type._class.registered;
5476 if(propertyClass.type == structClass && value.type == instanceExp)
5478 void (*Set)(void *, void *) = (void *)prop.Set;
5479 exp.instance = Instantiation { };
5480 exp.instance.data = new0 byte[_class.structSize];
5481 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5482 exp.instance.loc = exp.loc;
5483 exp.type = instanceExp;
5484 Set(exp.instance.data, value.instance.data);
5485 PopulateInstance(exp.instance);
5492 void (*Set)(void *, int) = (void *)prop.Set;
5494 exp.instance = Instantiation { };
5495 exp.instance.data = new0 byte[_class.structSize];
5496 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5497 exp.instance.loc = exp.loc;
5498 exp.type = instanceExp;
5500 GetInt(value, &intValue);
5502 Set(exp.instance.data, intValue);
5503 PopulateInstance(exp.instance);
5509 void (*Set)(void *, int64) = (void *)prop.Set;
5511 exp.instance = Instantiation { };
5512 exp.instance.data = new0 byte[_class.structSize];
5513 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5514 exp.instance.loc = exp.loc;
5515 exp.type = instanceExp;
5517 GetInt64(value, &intValue);
5519 Set(exp.instance.data, intValue);
5520 PopulateInstance(exp.instance);
5527 void (*Set)(void *, intptr) = (void *)prop.Set;
5529 exp.instance = Instantiation { };
5530 exp.instance.data = new0 byte[_class.structSize];
5531 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5532 exp.instance.loc = exp.loc;
5533 exp.type = instanceExp;
5535 GetIntPtr(value, &intValue);
5537 Set(exp.instance.data, intValue);
5538 PopulateInstance(exp.instance);
5544 void (*Set)(void *, double) = (void *)prop.Set;
5546 exp.instance = Instantiation { };
5547 exp.instance.data = new0 byte[_class.structSize];
5548 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5549 exp.instance.loc = exp.loc;
5550 exp.type = instanceExp;
5552 GetDouble(value, &doubleValue);
5554 Set(exp.instance.data, doubleValue);
5555 PopulateInstance(exp.instance);
5560 else if(_class.type == bitClass)
5566 Class propertyClass = type._class.registered;
5567 if(propertyClass.type == structClass && value.instance.data)
5569 unsigned int (*Set)(void *) = (void *)prop.Set;
5570 unsigned int bits = Set(value.instance.data);
5571 exp.constant = PrintHexUInt(bits);
5572 exp.type = constantExp;
5575 else if(_class.type == bitClass)
5578 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5581 GetUInt(exp.member.exp, &value);
5583 exp.constant = PrintHexUInt(bits);
5584 exp.type = constantExp;
5592 if(_class.type == bitClass)
5595 GetUInt(exp.member.exp, &value);
5601 Class _class = type._class.registered;
5602 if(_class.type == structClass)
5604 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5606 exp.instance = Instantiation { };
5607 exp.instance.data = new0 byte[_class.structSize];
5608 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5609 exp.instance.loc = exp.loc;
5610 //exp.instance.fullSet = true;
5611 exp.type = instanceExp;
5612 Get(value, exp.instance.data);
5613 PopulateInstance(exp.instance);
5615 else if(_class.type == bitClass)
5617 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5618 uint64 bits = Get(value);
5619 exp.constant = PrintHexUInt64(bits);
5620 exp.type = constantExp;
5626 else if(_class.type == structClass)
5628 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5633 Class _class = type._class.registered;
5634 if(_class.type == structClass && value)
5636 void (*Get)(void *, void *) = (void *)prop.Get;
5638 exp.instance = Instantiation { };
5639 exp.instance.data = new0 byte[_class.structSize];
5640 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5641 exp.instance.loc = exp.loc;
5642 //exp.instance.fullSet = true;
5643 exp.type = instanceExp;
5644 Get(value, exp.instance.data);
5645 PopulateInstance(exp.instance);
5653 char * value = exp.member.exp.instance.data;
5658 Class _class = type._class.registered;
5659 if(_class.type == normalClass)
5661 void *(*Get)(void *) = (void *)prop.Get;
5663 exp.instance = Instantiation { };
5664 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5665 exp.type = instanceExp;
5666 exp.instance.data = Get(value, exp.instance.data);
5678 exp.isConstant = false;
5686 if(exp.type != ExpressionType::memberExp)
5688 FreeExpression(memberExp);
5689 FreeIdentifier(memberID);
5695 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5696 FreeExpContents(exp);
5697 exp.constant = PrintUInt(ComputeTypeSize(type));
5698 exp.type = constantExp;
5704 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5705 if(classSym && classSym.registered)
5707 if(classSym.registered.fixed)
5709 FreeSpecifier(exp._class);
5710 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5711 exp.type = constantExp;
5715 char className[1024];
5716 strcpy(className, "__ecereClass_");
5717 FullClassNameCat(className, classSym.string, true);
5718 MangleClassName(className);
5720 FreeExpContents(exp);
5721 exp.type = pointerExp;
5722 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5723 exp.member.member = MkIdentifier("structSize");
5733 if(exp.type == castExp)
5736 ComputeExpression(exp.cast.exp);
5739 if(e && exp.expType)
5742 type = exp.destType;
5745 if(type.kind == classType)
5747 Class _class = type._class.registered;
5748 if(_class && (_class.type == unitClass || _class.type == bitClass))
5750 if(!_class.dataType)
5751 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5752 type = _class.dataType;
5763 FreeExpContents(exp);
5764 exp.constant = PrintChar(value);
5765 exp.type = constantExp;
5769 unsigned char value;
5770 GetUChar(e, &value);
5771 FreeExpContents(exp);
5772 exp.constant = PrintUChar(value);
5773 exp.type = constantExp;
5780 GetShort(e, &value);
5781 FreeExpContents(exp);
5782 exp.constant = PrintShort(value);
5783 exp.type = constantExp;
5787 unsigned short value;
5788 GetUShort(e, &value);
5789 FreeExpContents(exp);
5790 exp.constant = PrintUShort(value);
5791 exp.type = constantExp;
5799 FreeExpContents(exp);
5800 exp.constant = PrintInt(value);
5801 exp.type = constantExp;
5807 FreeExpContents(exp);
5808 exp.constant = PrintUInt(value);
5809 exp.type = constantExp;
5816 GetInt64(e, &value);
5817 FreeExpContents(exp);
5818 exp.constant = PrintInt64(value);
5819 exp.type = constantExp;
5824 GetUInt64(e, &value);
5825 FreeExpContents(exp);
5826 exp.constant = PrintUInt64(value);
5827 exp.type = constantExp;
5834 GetIntPtr(e, &value);
5835 FreeExpContents(exp);
5836 exp.constant = PrintInt64((int64)value);
5837 exp.type = constantExp;
5842 GetUIntPtr(e, &value);
5843 FreeExpContents(exp);
5844 exp.constant = PrintUInt64((uint64)value);
5845 exp.type = constantExp;
5851 GetFloat(e, &value);
5852 FreeExpContents(exp);
5853 exp.constant = PrintFloat(value);
5854 exp.type = constantExp;
5860 GetDouble(e, &value);
5861 FreeExpContents(exp);
5862 exp.constant = PrintDouble(value);
5863 exp.type = constantExp;
5877 // Caring only about last expression for now...
5878 ComputeExpression(exp.cond.exp->last);
5879 if(exp.cond.elseExp)
5880 ComputeExpression(exp.cond.elseExp);
5882 ComputeExpression(exp.cond.cond);
5884 op1 = GetOperand(exp.cond.cond);
5885 if(op1.type) op1.type.refCount++;
5886 op2 = GetOperand(exp.cond.exp->last);
5887 if(op2.type) op2.type.refCount++;
5888 op3 = GetOperand(exp.cond.elseExp);
5889 if(op3.type) op3.type.refCount++;
5891 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5892 if(op1.type) FreeType(op1.type);
5893 if(op2.type) FreeType(op2.type);
5894 if(op3.type) FreeType(op3.type);
5900 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5905 OldList converts { };
5908 if(destType.kind == voidType)
5911 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5915 // for(convert = converts.last; convert; convert = convert.prev)
5916 for(convert = converts.first; convert; convert = convert.next)
5918 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5921 Expression newExp { };
5922 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5924 // TODO: Check this...
5926 newExp.destType = null;
5931 exp.type = memberExp;
5932 exp.addedThis = true;
5933 exp.member.exp = newExp;
5934 FreeType(exp.member.exp.expType);
5936 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5937 exp.member.exp.expType.classObjectType = objectType;
5938 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5939 exp.member.memberType = propertyMember;
5940 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5941 // TESTING THIS... for (int)degrees
5942 exp.needCast = true;
5943 if(exp.expType) exp.expType.refCount++;
5944 ApplyAnyObjectLogic(exp.member.exp);
5949 /*if(exp.isConstant)
5951 // Color { ColorRGB = [exp] };
5952 exp.type = instanceExp;
5953 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5954 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5955 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5959 // If not constant, don't turn it yet into an instantiation
5960 // (Go through the deep members system first)
5961 exp.type = memberExp;
5962 exp.addedThis = true;
5963 exp.member.exp = newExp;
5965 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5966 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5967 newExp.expType._class.registered.type == noHeadClass)
5969 newExp.byReference = true;
5972 FreeType(exp.member.exp.expType);
5973 /*exp.member.exp.expType = convert.convert.dataType;
5974 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
5975 exp.member.exp.expType = null;
5976 if(convert.convert.dataType)
5978 exp.member.exp.expType = { };
5979 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
5980 exp.member.exp.expType.refCount = 1;
5981 exp.member.exp.expType.classObjectType = objectType;
5982 ApplyAnyObjectLogic(exp.member.exp);
5985 exp.member.member = MkIdentifier(convert.convert._class.fullName);
5986 exp.member.memberType = reverseConversionMember;
5987 exp.expType = convert.resultType ? convert.resultType :
5988 MkClassType(convert.convert._class.fullName);
5989 exp.needCast = true;
5990 if(convert.resultType) convert.resultType.refCount++;
5996 FreeType(exp.expType);
5999 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6000 exp.needCast = true;
6001 if(exp.expType) exp.expType.refCount++;
6005 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6006 exp.needCast = true;
6007 if(convert.resultType)
6008 convert.resultType.refCount++;
6012 if(exp.isConstant && inCompiler)
6013 ComputeExpression(exp);
6015 converts.Free(FreeConvert);
6018 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6020 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6022 if(!result && exp.expType && exp.destType)
6024 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6025 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6026 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6027 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6031 // if(result) CheckTemplateTypes(exp);
6035 void CheckTemplateTypes(Expression exp)
6037 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6039 Expression newExp { };
6043 if(exp.destType) exp.destType.refCount++;
6044 if(exp.expType) exp.expType.refCount++;
6048 switch(exp.expType.kind)
6051 if(exp.destType.classObjectType)
6053 // We need to pass the address, just pass it along (Undo what was done above)
6054 if(exp.destType) exp.destType.refCount--;
6055 if(exp.expType) exp.expType.refCount--;
6060 // If we're looking for value:
6061 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6063 OldList * unionDefs = MkList();
6064 OldList * statements = MkList();
6065 context = PushContext();
6066 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6067 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6068 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6069 exp.type = extensionCompoundExp;
6070 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6071 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6072 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6073 exp.compound.compound.context = context;
6074 PopContext(context);
6079 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6080 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6084 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6086 Expression newExp { };
6090 if(exp.destType) exp.destType.refCount++;
6091 if(exp.expType) exp.expType.refCount++;
6095 switch(exp.expType.kind)
6098 if(exp.destType.classObjectType)
6100 // We need to pass the address, just pass it along (Undo what was done above)
6101 if(exp.destType) exp.destType.refCount--;
6102 if(exp.expType) exp.expType.refCount--;
6107 // If we're looking for value:
6108 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6110 OldList * unionDefs = MkList();
6111 OldList * statements = MkList();
6112 context = PushContext();
6113 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6114 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6115 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6116 exp.type = extensionCompoundExp;
6117 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6118 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6119 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6120 exp.compound.compound.context = context;
6121 PopContext(context);
6126 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6128 exp.type = bracketsExp;
6129 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6130 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6131 ProcessExpressionType(exp.list->first);
6136 exp.type = bracketsExp;
6137 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6138 newExp.needCast = true;
6139 ProcessExpressionType(exp.list->first);
6145 if(exp.expType.kind == templateType)
6147 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6150 FreeType(exp.destType);
6151 FreeType(exp.expType);
6156 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6161 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6162 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6166 char typeString[1024];
6168 OldList * specs = MkList();
6169 typeString[0] = '\0';
6170 PrintType(exp.expType, typeString, false, false);
6171 decl = SpecDeclFromString(typeString, specs, null);
6174 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6175 exp.cast.typeName = MkTypeName(specs, decl);
6176 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6177 exp.cast.exp.needCast = true;
6184 // TODO: The Symbol tree should be reorganized by namespaces
6186 // - Tree of all symbols within (stored without namespace)
6187 // - Tree of sub-namespaces
6189 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6191 int nsLen = strlen(nameSpace);
6193 // Start at the name space prefix
6194 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6196 char * s = symbol.string;
6197 if(!strncmp(s, nameSpace, nsLen))
6199 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6202 for(c = strlen(s)-1; c >= 0; c--)
6207 if(!strcmp(namePart, name))
6209 // TODO: Error on ambiguity
6219 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6222 char nameSpace[1024];
6224 bool gotColon = false;
6226 nameSpace[0] = '\0';
6227 for(c = strlen(name)-1; c >= 0; c--)
6234 namePart = name+c+1;
6235 while(c >= 0 && name[c] == ':') c--;
6238 // Try an exact match first
6239 Symbol symbol = (Symbol)tree.FindString(name);
6243 // Namespace specified
6244 memcpy(nameSpace, name, c + 1);
6247 return ScanWithNameSpace(tree, nameSpace, namePart);
6251 // Looking for a global symbol, e.g. ::Sleep()
6252 Symbol symbol = (Symbol)tree.FindString(namePart);
6257 // Name only (no namespace specified)
6258 Symbol symbol = (Symbol)tree.FindString(namePart);
6261 return ScanWithNameSpace(tree, "", namePart);
6266 static void ProcessDeclaration(Declaration decl);
6268 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6271 //Time startTime = GetTime();
6273 // Optimize this later? Do this before/less?
6275 Symbol symbol = null;
6276 // First, check if the identifier is declared inside the function
6277 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6279 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6281 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6287 strcpy(curName, thisNameSpace);
6288 strcat(curName, "::");
6289 strcat(curName, name);
6290 // Try to resolve in current namespace first
6291 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6294 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6297 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6299 if(symbol || ctx == endContext) break;
6301 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6303 if(symbol.pointerExternal.type == functionExternal)
6305 FunctionDefinition function = symbol.pointerExternal.function;
6307 // Modified this recently...
6308 Context tmpContext = curContext;
6310 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6311 curContext = tmpContext;
6313 symbol.pointerExternal.symbol = symbol;
6316 DeclareType(symbol.type, true, true);
6318 ast->Insert(curExternal.prev, symbol.pointerExternal);
6320 symbol.id = curExternal.symbol.idCode;
6323 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6325 ast->Move(symbol.pointerExternal, curExternal.prev);
6326 symbol.id = curExternal.symbol.idCode;
6330 //findSymbolTotalTime += GetTime() - startTime;
6335 static void GetTypeSpecs(Type type, OldList * specs)
6337 if(!type.isSigned && type.kind != intPtrType) ListAdd(specs, MkSpecifier(UNSIGNED));
6342 if(type._class.registered)
6344 if(!type._class.registered.dataType)
6345 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6346 GetTypeSpecs(type._class.registered.dataType, specs);
6350 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6351 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6352 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6353 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6354 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6355 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6358 ListAdd(specs, MkSpecifier(INT)); break;
6362 // WARNING : This function expects a null terminated string since it recursively concatenate...
6363 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6370 if(type._class && type._class.string)
6372 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6373 // look into merging with thisclass ?
6374 if(type.classObjectType == typedObject)
6375 strcat(string, "typed_object");
6377 strcat(string, type._class.string);
6380 if(type._class.registered)
6381 strcat(string, type._class.registered.name);
6383 strcat(string, type._class.string);
6390 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6391 if(funcType && funcType.kind == functionType)
6394 PrintType(funcType.returnType, string, false, fullName);
6395 strcat(string, "(*");
6396 if(printName || funcType.thisClass)
6398 strcat(string, " ");
6399 if(funcType.thisClass)
6401 strcat(string, funcType.thisClass.string);
6402 strcat(string, "::");
6405 strcat(string, type.name);
6407 strcat(string, ")(");
6408 for(param = funcType.params.first; param; param = param.next)
6410 PrintType(param, string, false, fullName);
6411 if(param.next) strcat(string, ", ");
6413 strcat(string, ")");
6417 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6418 strcat(string, " *");
6422 case voidType: strcat(string, "void"); break;
6423 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6424 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6425 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6426 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6427 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6428 case floatType: strcat(string, "float"); break;
6429 case doubleType: strcat(string, "double"); break;
6433 strcat(string, "struct ");
6434 strcat(string, type.enumName);
6436 else if(type.typeName)
6438 strcat(string, type.typeName);
6443 strcat(string, "struct ");
6444 strcat(string,"(unnamed)");
6447 strcat(string, "struct {");
6448 for(member = type.members.first; member; member = member.next)
6450 PrintType(member, string, true, fullName);
6451 strcat(string,"; ");
6459 strcat(string, "union ");
6460 strcat(string, type.enumName);
6462 else if(type.typeName)
6464 strcat(string, type.typeName);
6468 strcat(string, "union ");
6469 strcat(string,"(unnamed)");
6475 strcat(string, "enum ");
6476 strcat(string, type.enumName);
6478 else if(type.typeName)
6480 strcat(string, type.typeName);
6483 strcat(string, "enum");
6490 strcat(string, "dllexport ");
6491 PrintType(type.returnType, string, false, fullName);
6492 strcat(string, " ");
6495 // DANGER: Testing This
6501 strcat(string, type.name);
6504 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6505 if(name) name += 2; else name = type.name;
6506 strcat(string, name);
6520 strcat(string, "(");
6521 for(param = type.params.first; param; param = param.next)
6523 PrintType(param, string, true, fullName);
6524 if(param.next) strcat(string, ", ");
6526 strcat(string, ")");
6533 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6534 if(funcType && funcType.kind == functionType)
6537 PrintType(funcType.returnType, string, false, fullName);
6538 strcat(string, "(*");
6539 if(printName || funcType.thisClass)
6541 strcat(string, " ");
6542 if(funcType.thisClass)
6544 strcat(string, funcType.thisClass.string);
6545 strcat(string, "::");
6548 strcat(string, type.name);
6550 strcat(string, ")(");
6551 for(param = funcType.params.first; param; param = param.next)
6553 PrintType(param, string, false, fullName);
6554 if(param.next) strcat(string, ", ");
6556 strcat(string, ")");
6560 char baseType[1024], size[256];
6561 Type arrayType = type;
6565 while(arrayType.kind == TypeKind::arrayType)
6568 if(arrayType.enumClass)
6569 strcat(size, arrayType.enumClass.string);
6570 else if(arrayType.arraySizeExp)
6571 PrintExpression(arrayType.arraySizeExp, size);
6572 //sprintf(string, "%s[%s]", baseType, size);
6575 arrayType = arrayType.arrayType;
6577 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6578 strcat(string, baseType);
6579 strcat(string, size);
6583 PrintType(type.arrayType, baseType, printName, fullName);
6585 strcpy(size, type.enumClass.string);
6586 else if(type.arraySizeExp)
6587 PrintExpression(type.arraySizeExp, size);
6588 //sprintf(string, "%s[%s]", baseType, size);
6589 strcat(string, baseType);
6590 strcat(string, "[");
6591 strcat(string, size);
6592 strcat(string, "]");
6599 strcat(string, "...");
6602 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6605 strcat(string, "subclass(");
6606 strcat(string, type._class ? type._class.string : "int");
6607 strcat(string, ")");
6610 strcat(string, type.templateParameter.identifier.string);
6613 strcat(string, "thisclass");
6616 strcat(string, "__builtin_va_list");
6623 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6625 strcat(string, " ");
6626 strcat(string, type.name);
6632 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6634 void PrintType(Type type, char * string, bool printName, bool fullName)
6637 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6638 if(funcType && funcType.kind == functionType && type != funcType)
6640 char typeString[1024];
6643 PrintType(funcType.returnType, string, false, fullName);
6644 strcat(string, "(");
6645 _PrintType(type, string, printName, false, fullName);
6646 strcat(string, ")");
6649 strcat(string, type.name);
6655 strcat(string, "(");
6656 for(param = funcType.params.first; param; param = param.next)
6658 PrintType(param, string, true, fullName);
6659 if(param.next) strcat(string, ", ");
6661 strcat(string, ")");
6664 _PrintType(type, string, printName, true, fullName);
6665 if(type.bitFieldCount)
6668 sprintf(count, ":%d", type.bitFieldCount);
6669 strcat(string, count);
6673 static Type FindMember(Type type, char * string)
6676 for(memberType = type.members.first; memberType; memberType = memberType.next)
6678 if(!memberType.name)
6680 Type subType = FindMember(memberType, string);
6684 else if(!strcmp(memberType.name, string))
6690 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6693 for(memberType = type.members.first; memberType; memberType = memberType.next)
6695 if(!memberType.name)
6697 Type subType = FindMember(memberType, string);
6700 *offset += memberType.offset;
6704 else if(!strcmp(memberType.name, string))
6706 *offset += memberType.offset;
6713 Expression ParseExpressionString(char * expression)
6715 fileInput = TempFile { };
6716 fileInput.Write(expression, 1, strlen(expression));
6717 fileInput.Seek(0, start);
6720 parsedExpression = null;
6722 expression_yyparse();
6725 return parsedExpression;
6728 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6730 Identifier id = exp.identifier;
6731 Method method = null;
6732 Property prop = null;
6733 DataMember member = null;
6734 ClassProperty classProp = null;
6736 if(_class && _class.type == enumClass)
6738 NamedLink value = null;
6739 Class enumClass = eSystem_FindClass(privateModule, "enum");
6743 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6745 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6746 for(value = e.values.first; value; value = value.next)
6748 if(!strcmp(value.name, id.string))
6755 FreeExpContents(exp);
6757 exp.type = constantExp;
6758 exp.isConstant = true;
6759 if(!strcmp(baseClass.dataTypeString, "int"))
6760 sprintf(constant, "%d",value.data);
6762 sprintf(constant, "0x%X",value.data);
6763 exp.constant = CopyString(constant);
6764 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6765 exp.expType = MkClassType(baseClass.fullName);
6773 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6775 ProcessMethodType(method);
6782 // TOCHECK: Put it back to what it was...
6783 // methodClass = _class;
6784 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6789 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6792 ProcessPropertyType(prop);
6793 exp.expType = prop.dataType;
6794 if(prop.dataType) prop.dataType.refCount++;
6797 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6799 if(!member.dataType)
6800 member.dataType = ProcessTypeString(member.dataTypeString, false);
6801 exp.expType = member.dataType;
6802 if(member.dataType) member.dataType.refCount++;
6805 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6807 if(!classProp.dataType)
6808 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6810 if(classProp.constant)
6812 FreeExpContents(exp);
6814 exp.isConstant = true;
6815 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6817 //char constant[256];
6818 exp.type = stringExp;
6819 exp.constant = QMkString((char *)classProp.Get(_class));
6824 exp.type = constantExp;
6825 sprintf(constant, "%d",classProp.Get(_class));
6826 exp.constant = CopyString(constant);
6834 exp.expType = classProp.dataType;
6835 if(classProp.dataType) classProp.dataType.refCount++;
6841 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6843 BinaryTree * tree = &nameSpace.functions;
6844 GlobalData data = (GlobalData)tree->FindString(name);
6848 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6850 data = ScanGlobalData(child, name);
6858 static GlobalData FindGlobalData(char * name)
6861 NameSpace * nameSpace;
6862 nameSpace = globalData;
6863 for(c = 0; name[c]; c++)
6865 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6867 NameSpace * newSpace;
6868 char * spaceName = new char[c - start + 1];
6869 strncpy(spaceName, name + start, c - start);
6870 spaceName[c-start] = '\0';
6871 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6875 nameSpace = newSpace;
6876 if(name[c] == ':') c++;
6882 return ScanGlobalData(nameSpace, name + start);
6887 static int definedExpStackPos;
6888 static void * definedExpStack[512];
6890 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6891 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6893 Expression prev = checkedExp.prev, next = checkedExp.next;
6895 FreeExpContents(checkedExp);
6896 FreeType(checkedExp.expType);
6897 FreeType(checkedExp.destType);
6899 *checkedExp = *newExp;
6903 checkedExp.prev = prev;
6904 checkedExp.next = next;
6907 void ApplyAnyObjectLogic(Expression e)
6909 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6910 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6912 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6913 //ellipsisDestType = destType;
6916 Type type = e.expType;
6917 Class _class = null;
6918 //Type destType = e.destType;
6920 if(type.kind == classType && type._class && type._class.registered)
6922 _class = type._class.registered;
6924 else if(type.kind == subClassType)
6926 _class = FindClass("ecere::com::Class").registered;
6930 char string[1024] = "";
6933 PrintType(type, string, false, true);
6934 classSym = FindClass(string);
6935 if(classSym) _class = classSym.registered;
6938 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...
6939 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6940 destType.byReference)))
6942 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6944 Expression checkedExp = e, newExp;
6946 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6948 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6950 if(checkedExp.type == extensionCompoundExp)
6952 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6955 checkedExp = checkedExp.list->last;
6957 else if(checkedExp.type == castExp)
6958 checkedExp = checkedExp.cast.exp;
6961 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6963 newExp = checkedExp.op.exp2;
6964 checkedExp.op.exp2 = null;
6965 FreeExpContents(checkedExp);
6967 if(e.expType && e.expType.passAsTemplate)
6970 ComputeTypeSize(e.expType);
6971 sprintf(size, "%d", e.expType.size);
6972 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6973 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6974 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6977 ReplaceExpContents(checkedExp, newExp);
6978 e.byReference = true;
6980 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6982 Expression checkedExp, newExp;
6985 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6987 e.type == identifierExp ||
6988 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6989 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6990 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6993 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6995 Context context = PushContext();
6997 OldList * specs = MkList();
6998 char typeString[1024];
6999 Expression newExp { };
7001 typeString[0] = '\0';
7004 //if(e.destType) e.destType.refCount++;
7005 // if(exp.expType) exp.expType.refCount++;
7008 newExp.expType = null;
7010 PrintType(e.expType, typeString, false, true);
7011 decl = SpecDeclFromString(typeString, specs, null);
7012 newExp.destType = ProcessType(specs, decl);
7014 curContext = context;
7015 e.type = extensionCompoundExp;
7017 // We need a current compound for this
7021 OldList * stmts = MkList();
7022 sprintf(name, "__internalValue%03X", internalValueCounter++);
7023 if(!curCompound.compound.declarations)
7024 curCompound.compound.declarations = MkList();
7025 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7026 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7027 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7028 e.compound = MkCompoundStmt(null, stmts);
7031 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7034 e.compound = MkCompoundStmt(
7035 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7036 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7038 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7042 Type type = e.destType;
7044 CopyTypeInto(e.destType, type);
7045 e.destType.refCount = 1;
7046 e.destType.classObjectType = none;
7050 e.compound.compound.context = context;
7051 PopContext(context);
7052 curContext = context.parent;
7056 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7058 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7060 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7062 if(checkedExp.type == extensionCompoundExp)
7064 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7067 checkedExp = checkedExp.list->last;
7069 else if(checkedExp.type == castExp)
7070 checkedExp = checkedExp.cast.exp;
7073 Expression operand { };
7074 operand = *checkedExp;
7075 checkedExp.destType = null;
7076 checkedExp.expType = null;
7078 checkedExp.type = opExp;
7079 checkedExp.op.op = '&';
7080 checkedExp.op.exp1 = null;
7081 checkedExp.op.exp2 = operand;
7083 //newExp = MkExpOp(null, '&', checkedExp);
7085 //ReplaceExpContents(checkedExp, newExp);
7092 // If expression type is a simple class, make it an address
7093 // FixReference(e, true);
7096 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7097 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7098 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7100 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7102 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7106 Expression thisExp { };
7109 thisExp.prev = null;
7110 thisExp.next = null;
7113 e.type = bracketsExp;
7114 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
7115 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7116 ((Expression)e.list->first).byReference = true;
7118 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7120 e.expType = thisExp.expType;
7121 e.expType.refCount++;
7126 CopyTypeInto(e.expType, thisExp.expType);
7127 e.expType.byReference = false;
7128 e.expType.refCount = 1;
7130 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7131 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7133 e.expType.classObjectType = none;
7138 // TOFIX: Try this for a nice IDE crash!
7140 // The other way around
7143 if(destType && e.expType &&
7144 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7145 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7146 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7148 if(destType.kind == ellipsisType)
7150 Compiler_Error($"Unspecified type\n");
7152 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7154 bool byReference = e.expType.byReference;
7155 Expression thisExp { };
7157 OldList * specs = MkList();
7158 char typeString[1024]; // Watch buffer overruns
7160 ClassObjectType backupClassObjectType;
7162 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7167 backupClassObjectType = type.classObjectType;
7169 type.classObjectType = none;
7171 typeString[0] = '\0';
7172 PrintType(type, typeString, false, true);
7173 decl = SpecDeclFromString(typeString, specs, null);
7175 type.classObjectType = backupClassObjectType;
7178 thisExp.prev = null;
7179 thisExp.next = null;
7182 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7183 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7184 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7185 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7186 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7191 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7196 e.cast.typeName = MkTypeName(specs, decl);
7197 e.cast.exp = thisExp;
7198 e.byReference = true;
7201 e.destType = destType;
7203 destType.refCount++;
7208 void ProcessExpressionType(Expression exp)
7210 bool unresolved = false;
7211 Location oldyylloc = yylloc;
7212 bool notByReference = false;
7214 char debugExpString[4096];
7215 debugExpString[0] = '\0';
7216 PrintExpression(exp, debugExpString);
7218 if(!exp || exp.expType)
7221 //eSystem_Logf("%s\n", expString);
7223 // Testing this here
7229 Identifier id = exp.identifier;
7232 // DOING THIS LATER NOW...
7233 if(id._class && id._class.name)
7235 id.classSym = id._class.symbol; // FindClass(id._class.name);
7236 /* TODO: Name Space Fix ups
7238 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7242 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7244 exp.expType = ProcessTypeString("Module", true);
7247 else */if(strstr(id.string, "__ecereClass") == id.string)
7249 exp.expType = ProcessTypeString("ecere::com::Class", true);
7252 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7254 // Added this here as well
7255 ReplaceClassMembers(exp, thisClass);
7256 if(exp.type != identifierExp)
7258 ProcessExpressionType(exp);
7262 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7267 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7268 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7269 if(!symbol/* && exp.destType*/)
7271 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7277 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7278 if(exp.type != identifierExp)
7280 ProcessExpressionType(exp);
7284 // Static methods called from inside the _class
7285 else if(currentClass && !id._class)
7287 if(ResolveIdWithClass(exp, currentClass, true))
7290 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7294 // If we manage to resolve this symbol
7297 Type type = symbol.type;
7298 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7300 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7302 Context context = SetupTemplatesContext(_class);
7303 type = ReplaceThisClassType(_class);
7304 FinishTemplatesContext(context);
7305 if(type) type.refCount = 0; // We'll be incrementing it right below...
7308 FreeSpecifier(id._class);
7311 id.string = CopyString(symbol.string);
7317 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7318 // Add missing cases here... enum Classes...
7319 exp.isConstant = true;
7321 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7322 if(symbol.isParam || !strcmp(id.string, "this"))
7324 if(_class && _class.type == structClass)
7325 exp.byReference = true;
7327 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7328 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7329 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7330 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7332 Identifier id = exp.identifier;
7333 exp.type = bracketsExp;
7334 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7338 if(symbol.isIterator)
7340 if(symbol.isIterator == 3)
7342 exp.type = bracketsExp;
7343 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7344 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7346 ProcessExpressionType(exp);
7348 else if(symbol.isIterator != 4)
7350 exp.type = memberExp;
7351 exp.member.exp = MkExpIdentifier(exp.identifier);
7352 exp.member.exp.expType = exp.expType;
7353 /*if(symbol.isIterator == 6)
7354 exp.member.member = MkIdentifier("key");
7356 exp.member.member = MkIdentifier("data");
7358 ProcessExpressionType(exp);
7365 DefinedExpression definedExp = null;
7366 if(thisNameSpace && !(id._class && !id._class.name))
7369 strcpy(name, thisNameSpace);
7371 strcat(name, id.string);
7372 definedExp = eSystem_FindDefine(privateModule, name);
7375 definedExp = eSystem_FindDefine(privateModule, id.string);
7379 for(c = 0; c<definedExpStackPos; c++)
7380 if(definedExpStack[c] == definedExp)
7382 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7384 Location backupYylloc = yylloc;
7385 definedExpStack[definedExpStackPos++] = definedExp;
7386 fileInput = TempFile { };
7387 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7388 fileInput.Seek(0, start);
7391 parsedExpression = null;
7393 expression_yyparse();
7396 yylloc = backupYylloc;
7398 if(parsedExpression)
7401 exp.type = bracketsExp;
7402 exp.list = MkListOne(parsedExpression);
7403 parsedExpression.loc = yylloc;
7404 ProcessExpressionType(exp);
7405 definedExpStackPos--;
7408 definedExpStackPos--;
7414 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7420 GlobalData data = null;
7421 if(thisNameSpace && !(id._class && !id._class.name))
7424 strcpy(name, thisNameSpace);
7426 strcat(name, id.string);
7427 data = FindGlobalData(name);
7430 data = FindGlobalData(id.string);
7433 DeclareGlobalData(data);
7434 exp.expType = data.dataType;
7435 if(data.dataType) data.dataType.refCount++;
7438 id.string = CopyString(data.fullName);
7439 FreeSpecifier(id._class);
7446 GlobalFunction function = null;
7447 if(thisNameSpace && !(id._class && !id._class.name))
7450 strcpy(name, thisNameSpace);
7452 strcat(name, id.string);
7453 function = eSystem_FindFunction(privateModule, name);
7456 function = eSystem_FindFunction(privateModule, id.string);
7461 id.string = CopyString(function.name);
7464 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7465 strcpy(name, "__ecereFunction_");
7466 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7467 if(DeclareFunction(function, name))
7470 id.string = CopyString(name);
7472 exp.expType = function.dataType;
7473 if(function.dataType) function.dataType.refCount++;
7475 FreeSpecifier(id._class);
7492 if(!exp.instance._class)
7494 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7496 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7506 //classSym = FindClass(exp.instance._class.fullName);
7507 //_class = classSym ? classSym.registered : null;
7509 ProcessInstantiationType(exp.instance);
7510 exp.isConstant = exp.instance.isConstant;
7513 if(_class.type == unitClass && _class.base.type != systemClass)
7516 Type destType = exp.destType;
7518 exp.destType = MkClassType(_class.base.fullName);
7519 exp.expType = MkClassType(_class.fullName);
7520 CheckExpressionType(exp, exp.destType, true);
7522 exp.destType = destType;
7524 exp.expType = MkClassType(_class.fullName);
7527 if(exp.instance._class)
7529 exp.expType = MkClassType(exp.instance._class.name);
7530 /*if(exp.expType._class && exp.expType._class.registered &&
7531 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7532 exp.expType.byReference = true;*/
7547 if(exp.constant[0] == '\'')
7549 if((int)((byte *)exp.constant)[1] > 127)
7552 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7553 if(nb < 2) ch = exp.constant[1];
7554 delete exp.constant;
7555 exp.constant = PrintUInt(ch);
7556 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7557 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7558 type._class = FindClass("unichar");
7560 type.isSigned = false;
7564 type.kind = charType;
7565 type.isSigned = true;
7568 else if(strchr(exp.constant, '.'))
7570 char ch = exp.constant[strlen(exp.constant)-1];
7572 type.kind = floatType;
7574 type.kind = doubleType;
7575 type.isSigned = true;
7579 if(exp.constant[0] == '0' && exp.constant[1])
7580 type.isSigned = false;
7581 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7582 type.isSigned = false;
7583 else if(strtoll(exp.constant, null, 0) > MAXINT)
7584 type.isSigned = false;
7586 type.isSigned = true;
7587 type.kind = intType;
7589 exp.isConstant = true;
7595 exp.isConstant = true; // Why wasn't this constant?
7611 ProcessExpressionType(exp._new.size);
7616 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7618 DeclareType(exp.expType.type, false, false);
7622 ProcessExpressionType(exp._renew.size);
7623 ProcessExpressionType(exp._renew.exp);
7628 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7630 DeclareType(exp.expType.type, false, false);
7634 bool assign = false, boolResult = false, boolOps = false;
7635 Type type1 = null, type2 = null;
7636 bool useDestType = false, useSideType = false;
7637 Location oldyylloc = yylloc;
7638 bool useSideUnit = false;
7640 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7649 // Assignment Operators
7663 // boolean Operators
7665 // Expect boolean operators
7667 //boolResult = true;
7671 // Expect boolean operands
7682 // Gives boolean result
7690 // Just added these... testing
7695 // DANGER: Verify units
7700 if(exp.op.op != '*' || exp.op.exp1)
7707 /*// Implement speed etc.
7713 if(exp.op.op == '&')
7715 // Added this here earlier for Iterator address as key
7716 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7718 Identifier id = exp.op.exp2.identifier;
7719 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7720 if(symbol && symbol.isIterator == 2)
7722 exp.type = memberExp;
7723 exp.member.exp = exp.op.exp2;
7724 exp.member.member = MkIdentifier("key");
7726 exp.op.exp2.expType = symbol.type;
7727 symbol.type.refCount++;
7728 ProcessExpressionType(exp);
7732 // exp.op.exp2.usage.usageRef = true;
7736 //dummy.kind = TypeDummy;
7740 if(exp.destType && exp.destType.kind == classType &&
7741 exp.destType._class && exp.destType._class.registered && useDestType &&
7743 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7744 exp.destType._class.registered.type == enumClass ||
7745 exp.destType._class.registered.type == bitClass
7748 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7750 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7751 exp.op.exp1.destType = exp.destType;
7753 exp.destType.refCount++;
7757 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7758 exp.op.exp1.destType = dummy;
7762 // TESTING THIS HERE...
7763 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7764 ProcessExpressionType(exp.op.exp1);
7765 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7767 if(exp.op.exp1.destType == dummy)
7770 exp.op.exp1.destType = null;
7772 type1 = exp.op.exp1.expType;
7777 char expString[10240];
7778 expString[0] = '\0';
7779 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7783 exp.op.exp2.destType = exp.op.exp1.expType;
7784 if(exp.op.exp1.expType)
7785 exp.op.exp1.expType.refCount++;
7789 exp.op.exp2.destType = exp.destType;
7791 exp.destType.refCount++;
7794 if(type1) type1.refCount++;
7795 exp.expType = type1;
7800 PrintExpression(exp.op.exp2, expString);
7802 if(type1 && type1.kind == pointerType)
7804 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 ||
7805 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7806 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7807 else if(exp.op.op == '=')
7809 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7810 exp.op.exp2.destType = type1;
7817 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7818 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/* ||
7819 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7822 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7823 exp.op.exp2.destType = type1;
7828 if(type1) type1.refCount++;
7829 exp.expType = type1;
7831 else if(exp.destType && exp.destType.kind == classType &&
7832 exp.destType._class && exp.destType._class.registered &&
7834 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7835 (exp.destType._class.registered.type == enumClass && useDestType))
7838 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7839 exp.op.exp2.destType = exp.destType;
7841 exp.destType.refCount++;
7845 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7846 exp.op.exp2.destType = dummy;
7850 // TESTING THIS HERE... (DANGEROUS)
7851 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7852 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7854 FreeType(exp.op.exp2.destType);
7855 exp.op.exp2.destType = type1;
7858 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7859 ProcessExpressionType(exp.op.exp2);
7860 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7862 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7864 if(exp.op.exp2.expType.kind == intPtrType || exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
7866 if(exp.op.op != '=' && type1.type.kind == voidType)
7867 Compiler_Error($"void *: unknown size\n");
7869 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||
7870 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7871 (exp.op.exp2.expType._class.registered.type == normalClass ||
7872 exp.op.exp2.expType._class.registered.type == structClass ||
7873 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7875 if(exp.op.op == ADD_ASSIGN)
7876 Compiler_Error($"cannot add two pointers\n");
7878 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7879 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7881 if(exp.op.op == ADD_ASSIGN)
7882 Compiler_Error($"cannot add two pointers\n");
7886 char type1String[1024];
7887 char type2String[1024];
7888 type1String[0] = '\0';
7889 type2String[0] = '\0';
7891 PrintType(exp.op.exp2.expType, type1String, false, true);
7892 PrintType(type1, type2String, false, true);
7893 ChangeCh(expString, '\n', ' ');
7894 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7898 if(exp.op.exp2.destType == dummy)
7901 exp.op.exp2.destType = null;
7904 type2 = exp.op.exp2.expType;
7907 dummy.kind = voidType;
7909 if(exp.op.op == SIZEOF)
7916 exp.isConstant = true;
7918 // Get type of dereferenced pointer
7919 else if(exp.op.op == '*' && !exp.op.exp1)
7921 exp.expType = Dereference(type2);
7922 if(type2 && type2.kind == classType)
7923 notByReference = true;
7925 else if(exp.op.op == '&' && !exp.op.exp1)
7926 exp.expType = Reference(type2);
7933 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7934 exp.op.exp1.destType = MkClassType("bool");
7935 exp.op.exp1.destType.truth = true;
7936 if(!exp.op.exp1.expType)
7937 ProcessExpressionType(exp.op.exp1);
7939 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7940 FreeType(exp.op.exp1.expType);
7941 exp.op.exp1.expType = MkClassType("bool");
7942 exp.op.exp1.expType.truth = true;
7946 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7947 exp.op.exp2.destType = MkClassType("bool");
7948 exp.op.exp2.destType.truth = true;
7949 if(!exp.op.exp2.expType)
7950 ProcessExpressionType(exp.op.exp2);
7952 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7953 FreeType(exp.op.exp2.expType);
7954 exp.op.exp2.expType = MkClassType("bool");
7955 exp.op.exp2.expType.truth = true;
7958 else if(exp.op.exp1 && exp.op.exp2 &&
7961 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7962 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7963 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7964 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7966 if(type1 && type2 &&
7967 // If either both are class or both are not class
7968 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7970 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7971 exp.op.exp2.destType = type1;
7973 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7974 exp.op.exp1.destType = type2;
7976 // Warning here for adding Radians + Degrees with no destination type
7977 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7978 type1._class.registered && type1._class.registered.type == unitClass &&
7979 type2._class.registered && type2._class.registered.type == unitClass &&
7980 type1._class.registered != type2._class.registered)
7981 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7982 type1._class.string, type2._class.string, type1._class.string);
7984 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7986 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7989 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7991 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7992 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7995 ProcessExpressionType(exp.op.exp1);
7997 if(type2.kind != pointerType)
7999 ProcessExpressionType(classExp);
8001 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8002 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8003 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8005 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8008 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8009 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8010 MkPointer(null, null), null)))),
8011 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8013 if(!exp.op.exp2.expType)
8014 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8016 ProcessExpressionType(exp.op.exp2);
8021 if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == intPtrType || type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
8023 if(type1.kind != classType && type1.type.kind == voidType)
8024 Compiler_Error($"void *: unknown size\n");
8025 exp.expType = type1;
8026 if(type1) type1.refCount++;
8028 else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == intPtrType || type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
8030 if(type2.kind != classType && type2.type.kind == voidType)
8031 Compiler_Error($"void *: unknown size\n");
8032 exp.expType = type2;
8033 if(type2) type2.refCount++;
8035 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8036 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8038 Compiler_Warning($"different levels of indirection\n");
8042 bool success = false;
8043 if(type1.kind == pointerType && type2.kind == pointerType)
8045 if(exp.op.op == '+')
8046 Compiler_Error($"cannot add two pointers\n");
8047 else if(exp.op.op == '-')
8049 // Pointer Subtraction gives integer
8050 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8059 if(type1.type.kind == templateType)
8061 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8064 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8066 ProcessExpressionType(classExp);
8068 exp.type = bracketsExp;
8069 exp.list = MkListOne(MkExpOp(
8070 MkExpBrackets(MkListOne(MkExpOp(
8071 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8073 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8075 //MkExpMember(classExp, MkIdentifier("typeSize"))
8077 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8078 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8080 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8083 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8084 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8085 MkPointer(null, null), null)))),
8086 MkExpMember(classExp, MkIdentifier("typeSize")))))
8091 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8100 if(!success && exp.op.exp1.type == constantExp)
8102 // If first expression is constant, try to match that first
8103 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8105 if(exp.expType) FreeType(exp.expType);
8106 exp.expType = exp.op.exp1.destType;
8107 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8110 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8112 if(exp.expType) FreeType(exp.expType);
8113 exp.expType = exp.op.exp2.destType;
8114 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8120 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8122 if(exp.expType) FreeType(exp.expType);
8123 exp.expType = exp.op.exp2.destType;
8124 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8127 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8129 if(exp.expType) FreeType(exp.expType);
8130 exp.expType = exp.op.exp1.destType;
8131 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8137 char expString1[10240];
8138 char expString2[10240];
8141 expString1[0] = '\0';
8142 expString2[0] = '\0';
8147 PrintExpression(exp.op.exp1, expString1);
8148 ChangeCh(expString1, '\n', ' ');
8149 PrintExpression(exp.op.exp2, expString2);
8150 ChangeCh(expString2, '\n', ' ');
8151 PrintType(exp.op.exp1.expType, type1, false, true);
8152 PrintType(exp.op.exp2.expType, type2, false, true);
8155 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8159 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8160 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8162 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8163 // Convert e.g. / 4 into / 4.0
8164 exp.op.exp1.destType = type2._class.registered.dataType;
8165 if(type2._class.registered.dataType)
8166 type2._class.registered.dataType.refCount++;
8167 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8168 exp.expType = type2;
8169 if(type2) type2.refCount++;
8171 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8173 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8174 // Convert e.g. / 4 into / 4.0
8175 exp.op.exp2.destType = type1._class.registered.dataType;
8176 if(type1._class.registered.dataType)
8177 type1._class.registered.dataType.refCount++;
8178 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8179 exp.expType = type1;
8180 if(type1) type1.refCount++;
8186 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8188 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8190 if(!type1._class.registered.dataType)
8191 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8192 exp.op.exp2.destType = type1._class.registered.dataType;
8193 exp.op.exp2.destType.refCount++;
8195 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8196 type2 = exp.op.exp2.destType;
8198 exp.expType = type2;
8202 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8204 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8206 if(!type2._class.registered.dataType)
8207 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8208 exp.op.exp1.destType = type2._class.registered.dataType;
8209 exp.op.exp1.destType.refCount++;
8211 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8212 type1 = exp.op.exp1.destType;
8213 exp.expType = type1;
8217 // TESTING THIS NEW CODE
8218 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8220 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8222 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8224 if(exp.expType) FreeType(exp.expType);
8225 exp.expType = exp.op.exp1.expType;
8226 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8231 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8233 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8235 if(exp.expType) FreeType(exp.expType);
8236 exp.expType = exp.op.exp2.expType;
8237 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8245 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8246 exp.op.exp2.destType = type1;
8250 // Maybe this was meant to be an enum...
8251 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8253 Type oldType = exp.op.exp2.expType;
8254 exp.op.exp2.expType = null;
8255 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8258 exp.op.exp2.expType = oldType;
8263 // TESTING THIS HERE... LATEST ADDITION
8264 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8266 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8267 exp.op.exp2.destType = type2._class.registered.dataType;
8268 if(type2._class.registered.dataType)
8269 type2._class.registered.dataType.refCount++;
8270 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8272 //exp.expType = type2._class.registered.dataType; //type2;
8273 //if(type2) type2.refCount++;
8276 // TESTING THIS HERE... LATEST ADDITION
8277 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8279 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8280 exp.op.exp1.destType = type1._class.registered.dataType;
8281 if(type1._class.registered.dataType)
8282 type1._class.registered.dataType.refCount++;
8283 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8284 exp.expType = type1._class.registered.dataType; //type1;
8285 if(type1) type1.refCount++;
8289 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8291 if(exp.expType) FreeType(exp.expType);
8292 exp.expType = exp.op.exp2.destType;
8293 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8295 else if(type1 && type2)
8297 char expString1[10240];
8298 char expString2[10240];
8299 char type1String[1024];
8300 char type2String[1024];
8301 expString1[0] = '\0';
8302 expString2[0] = '\0';
8303 type1String[0] = '\0';
8304 type2String[0] = '\0';
8307 PrintExpression(exp.op.exp1, expString1);
8308 ChangeCh(expString1, '\n', ' ');
8309 PrintExpression(exp.op.exp2, expString2);
8310 ChangeCh(expString2, '\n', ' ');
8311 PrintType(exp.op.exp1.expType, type1String, false, true);
8312 PrintType(exp.op.exp2.expType, type2String, false, true);
8315 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8317 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8319 exp.expType = exp.op.exp1.expType;
8320 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8322 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8324 exp.expType = exp.op.exp2.expType;
8325 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8332 // Maybe this was meant to be an enum...
8333 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8335 Type oldType = exp.op.exp1.expType;
8336 exp.op.exp1.expType = null;
8337 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8340 exp.op.exp1.expType = oldType;
8343 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8344 exp.op.exp1.destType = type2;
8347 // TESTING THIS HERE... LATEST ADDITION
8348 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8350 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8351 exp.op.exp1.destType = type1._class.registered.dataType;
8352 if(type1._class.registered.dataType)
8353 type1._class.registered.dataType.refCount++;
8356 // TESTING THIS HERE... LATEST ADDITION
8357 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8359 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8360 exp.op.exp2.destType = type2._class.registered.dataType;
8361 if(type2._class.registered.dataType)
8362 type2._class.registered.dataType.refCount++;
8366 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8368 if(exp.expType) FreeType(exp.expType);
8369 exp.expType = exp.op.exp1.destType;
8370 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8374 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8376 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8378 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8379 // Convert e.g. / 4 into / 4.0
8380 exp.op.exp1.destType = type2._class.registered.dataType;
8381 if(type2._class.registered.dataType)
8382 type2._class.registered.dataType.refCount++;
8383 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8385 if(exp.op.op == '!')
8387 exp.expType = MkClassType("bool");
8388 exp.expType.truth = true;
8392 exp.expType = type2;
8393 if(type2) type2.refCount++;
8396 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8398 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8400 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8401 // Convert e.g. / 4 into / 4.0
8402 exp.op.exp2.destType = type1._class.registered.dataType;
8403 if(type1._class.registered.dataType)
8404 type1._class.registered.dataType.refCount++;
8405 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8407 exp.expType = type1;
8408 if(type1) type1.refCount++;
8413 if(exp.op.exp1 && !exp.op.exp1.expType)
8415 char expString[10000];
8416 expString[0] = '\0';
8419 PrintExpression(exp.op.exp1, expString);
8420 ChangeCh(expString, '\n', ' ');
8423 Compiler_Error($"couldn't determine type of %s\n", expString);
8425 if(exp.op.exp2 && !exp.op.exp2.expType)
8427 char expString[10240];
8428 expString[0] = '\0';
8431 PrintExpression(exp.op.exp2, expString);
8432 ChangeCh(expString, '\n', ' ');
8435 Compiler_Error($"couldn't determine type of %s\n", expString);
8440 FreeType(exp.expType);
8441 exp.expType = MkClassType("bool");
8442 exp.expType.truth = true;
8445 if(exp.op.op != SIZEOF)
8446 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8447 (!exp.op.exp2 || exp.op.exp2.isConstant);
8449 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8451 DeclareType(exp.op.exp2.expType, false, false);
8460 case extensionExpressionExp:
8463 exp.isConstant = true;
8464 for(e = exp.list->first; e; e = e.next)
8469 FreeType(e.destType);
8470 e.destType = exp.destType;
8471 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8473 ProcessExpressionType(e);
8475 exp.destType.count--;
8476 if(!exp.expType && !e.next)
8478 exp.expType = e.expType;
8479 if(e.expType) e.expType.refCount++;
8482 exp.isConstant = false;
8485 // In case a cast became a member...
8486 e = exp.list->first;
8487 if(!e.next && e.type == memberExp)
8489 // Preserve prev, next
8490 Expression next = exp.next, prev = exp.prev;
8493 FreeType(exp.expType);
8494 FreeType(exp.destType);
8504 ProcessExpressionType(exp);
8511 exp.isConstant = true;
8513 ProcessExpressionType(exp.index.exp);
8514 if(!exp.index.exp.isConstant)
8515 exp.isConstant = false;
8517 if(exp.index.exp.expType)
8519 Type source = exp.index.exp.expType;
8520 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8521 eClass_IsDerived(source._class.registered, containerClass) &&
8522 source._class.registered.templateArgs)
8524 Class _class = source._class.registered;
8525 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8527 if(exp.index.index && exp.index.index->last)
8529 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8534 for(e = exp.index.index->first; e; e = e.next)
8536 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8538 if(e.destType) FreeType(e.destType);
8539 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8541 ProcessExpressionType(e);
8544 // Check if this type is int
8547 exp.isConstant = false;
8551 exp.expType = Dereference(exp.index.exp.expType);
8553 DeclareType(exp.expType, false, false);
8560 Type methodType = null;
8566 PrintExpression(exp.call.exp, name);
8567 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8569 //exp.call.exp.expType = null;
8570 PrintExpression(exp.call.exp, name);
8573 if(exp.call.exp.type == identifierExp)
8575 Expression idExp = exp.call.exp;
8576 Identifier id = idExp.identifier;
8577 if(!strcmp(id.string, "__ENDIAN_PAD"))
8579 exp.expType = ProcessTypeString("int", true);
8580 if(exp.call.arguments && exp.call.arguments->first)
8581 ProcessExpressionType(exp.call.arguments->first);
8584 else if(!strcmp(id.string, "Max") ||
8585 !strcmp(id.string, "Min") ||
8586 !strcmp(id.string, "Sgn") ||
8587 !strcmp(id.string, "Abs"))
8589 Expression a = null;
8590 Expression b = null;
8591 Expression tempExp1 = null, tempExp2 = null;
8592 if((!strcmp(id.string, "Max") ||
8593 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8595 a = exp.call.arguments->first;
8596 b = exp.call.arguments->last;
8600 else if(exp.call.arguments->count == 1)
8602 a = exp.call.arguments->first;
8608 exp.call.arguments->Clear();
8609 idExp.identifier = null;
8611 FreeExpContents(exp);
8613 ProcessExpressionType(a);
8615 ProcessExpressionType(b);
8617 exp.type = bracketsExp;
8618 exp.list = MkList();
8620 if(a.expType && (!b || b.expType))
8622 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8624 // Use the simpleStruct name/ids for now...
8627 OldList * specs = MkList();
8628 OldList * decls = MkList();
8630 char temp1[1024], temp2[1024];
8632 GetTypeSpecs(a.expType, specs);
8634 if(a && !a.isConstant && a.type != identifierExp)
8636 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8637 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8638 tempExp1 = QMkExpId(temp1);
8639 tempExp1.expType = a.expType;
8641 a.expType.refCount++;
8642 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8644 if(b && !b.isConstant && b.type != identifierExp)
8646 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8647 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8648 tempExp2 = QMkExpId(temp2);
8649 tempExp2.expType = b.expType;
8651 b.expType.refCount++;
8652 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8655 decl = MkDeclaration(specs, decls);
8656 if(!curCompound.compound.declarations)
8657 curCompound.compound.declarations = MkList();
8658 curCompound.compound.declarations->Insert(null, decl);
8663 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8665 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8667 MkExpCondition(MkExpBrackets(MkListOne(
8668 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8669 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8670 exp.expType = a.expType;
8672 a.expType.refCount++;
8674 else if(!strcmp(id.string, "Abs"))
8677 MkExpCondition(MkExpBrackets(MkListOne(
8678 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8679 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8680 exp.expType = a.expType;
8682 a.expType.refCount++;
8684 else if(!strcmp(id.string, "Sgn"))
8686 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8688 MkExpCondition(MkExpBrackets(MkListOne(
8689 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8690 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8691 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8692 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8693 exp.expType = ProcessTypeString("int", false);
8696 FreeExpression(tempExp1);
8697 if(tempExp2) FreeExpression(tempExp2);
8711 if(!exp.call.exp.destType)
8713 exp.call.exp.destType = dummy;
8716 ProcessExpressionType(exp.call.exp);
8717 if(exp.call.exp.destType == dummy)
8720 exp.call.exp.destType = null;
8725 // Check argument types against parameter types
8726 functionType = exp.call.exp.expType;
8728 if(functionType && functionType.kind == TypeKind::methodType)
8730 methodType = functionType;
8731 functionType = methodType.method.dataType;
8733 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8734 // TOCHECK: Instead of doing this here could this be done per param?
8735 if(exp.call.exp.expType.usedClass)
8737 char typeString[1024];
8738 typeString[0] = '\0';
8739 PrintType(functionType, typeString, true, true);
8740 if(strstr(typeString, "thisclass"))
8742 OldList * specs = MkList();
8745 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8747 decl = SpecDeclFromString(typeString, specs, null);
8749 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8750 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8751 exp.call.exp.expType.usedClass))
8752 thisClassParams = false;
8754 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8756 Class backupThisClass = thisClass;
8757 thisClass = exp.call.exp.expType.usedClass;
8758 ProcessDeclarator(decl);
8759 thisClass = backupThisClass;
8762 thisClassParams = true;
8764 functionType = ProcessType(specs, decl);
8765 functionType.refCount = 0;
8766 FinishTemplatesContext(context);
8769 FreeList(specs, FreeSpecifier);
8770 FreeDeclarator(decl);
8774 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8776 Type type = functionType.type;
8777 if(!functionType.refCount)
8779 functionType.type = null;
8780 FreeType(functionType);
8782 //methodType = functionType;
8783 functionType = type;
8785 if(functionType && functionType.kind != TypeKind::functionType)
8787 Compiler_Error($"called object %s is not a function\n", name);
8789 else if(functionType)
8791 bool emptyParams = false, noParams = false;
8792 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8793 Type type = functionType.params.first;
8794 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8796 Location oldyylloc = yylloc;
8798 if(!type) emptyParams = true;
8801 if(functionType.extraParam && e)
8803 e.destType = MkClassType(functionType.thisClass.string);
8807 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8808 if(!functionType.staticMethod)
8810 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8811 memberExp.member.exp.expType._class)
8813 type = MkClassType(memberExp.member.exp.expType._class.string);
8818 type = functionType.params.first;
8823 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8825 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8830 type = functionType.params.first;
8838 if(type && type.kind == voidType)
8841 if(!type.refCount) FreeType(type);
8845 for( ; e; e = e.next)
8847 if(!type && !emptyParams)
8850 if(methodType && methodType.methodClass)
8851 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8852 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8853 noParams ? 0 : functionType.params.count);
8855 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8856 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8857 noParams ? 0 : functionType.params.count);
8861 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8863 Type templatedType = null;
8864 Class _class = methodType.usedClass;
8865 ClassTemplateParameter curParam = null;
8867 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8870 for(sClass = _class; sClass; sClass = sClass.base)
8872 if(sClass.templateClass) sClass = sClass.templateClass;
8874 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8876 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8879 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8881 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8882 id += nextClass.templateParams.count;
8891 if(curParam && _class.templateArgs[id].dataTypeString)
8893 ClassTemplateArgument arg = _class.templateArgs[id];
8895 Context context = SetupTemplatesContext(_class);
8898 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8899 templatedType = ProcessTypeString(arg.dataTypeString, false);
8900 FinishTemplatesContext(context);
8902 e.destType = templatedType;
8905 templatedType.passAsTemplate = true;
8906 // templatedType.refCount++;
8912 if(type) type.refCount++;
8918 if(type) type.refCount++;
8920 // Don't reach the end for the ellipsis
8921 if(type && type.kind != ellipsisType)
8923 Type next = type.next;
8924 if(!type.refCount) FreeType(type);
8929 if(type && type.kind != ellipsisType)
8931 if(methodType && methodType.methodClass)
8932 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8933 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8934 functionType.params.count + extra);
8936 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8937 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8938 functionType.params.count + extra);
8941 if(type && !type.refCount) FreeType(type);
8948 kind = TypeKind::functionType;
8951 if(exp.call.exp.type == identifierExp)
8953 char * string = exp.call.exp.identifier.string;
8957 Location oldyylloc = yylloc;
8959 yylloc = exp.call.exp.identifier.loc;
8960 if(strstr(string, "__builtin_") == string);
8962 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8963 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8964 globalContext.symbols.Add((BTNode)symbol);
8965 if(strstr(symbol.string, "::"))
8966 globalContext.hasNameSpace = true;
8971 else if(exp.call.exp.type == memberExp)
8973 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8974 exp.call.exp.member.member.string);*/
8977 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8979 if(!functionType.returnType)
8981 functionType.returnType = Type
8988 if(functionType && functionType.kind == TypeKind::functionType)
8990 exp.expType = functionType.returnType;
8992 if(functionType.returnType)
8993 functionType.returnType.refCount++;
8995 if(!functionType.refCount)
8996 FreeType(functionType);
8999 if(exp.call.arguments)
9001 for(e = exp.call.arguments->first; e; e = e.next)
9003 Type destType = e.destType;
9004 ProcessExpressionType(e);
9012 Location oldyylloc = yylloc;
9013 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
9014 exp.thisPtr = thisPtr;
9016 // DOING THIS LATER NOW...
9017 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9019 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9020 /* TODO: Name Space Fix ups
9021 if(!exp.member.member.classSym)
9022 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9026 ProcessExpressionType(exp.member.exp);
9027 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9028 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9030 exp.isConstant = false;
9033 exp.isConstant = exp.member.exp.isConstant;
9034 type = exp.member.exp.expType;
9038 if(type && (type.kind == templateType))
9040 Class _class = thisClass ? thisClass : currentClass;
9041 ClassTemplateParameter param = null;
9044 for(param = _class.templateParams.first; param; param = param.next)
9046 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9050 if(param && param.defaultArg.member)
9052 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9055 Expression expMember = exp.member.exp;
9057 OldList * specs = MkList();
9058 char thisClassTypeString[1024];
9060 FreeIdentifier(exp.member.member);
9062 ProcessExpressionType(argExp);
9065 char * colon = strstr(param.defaultArg.memberString, "::");
9068 char className[1024];
9071 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9072 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9075 strcpy(thisClassTypeString, _class.fullName);
9078 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9080 exp.expType = ProcessType(specs, decl);
9081 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9083 Class expClass = exp.expType._class.registered;
9084 Class cClass = null;
9089 char templateString[1024];
9090 ClassTemplateParameter param;
9091 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9092 for(cClass = expClass; cClass; cClass = cClass.base)
9095 for(param = cClass.templateParams.first; param; param = param.next)
9099 ClassTemplateArgument arg;
9100 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9101 arg = expClass.templateArgs[id];
9103 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9105 ClassTemplateParameter cParam;
9106 //int p = numParams - sClass.templateParams.count;
9109 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9111 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9113 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9115 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9117 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9118 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9130 strcat(argument, arg.name.string);
9131 strcat(argument, " = ");
9137 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9138 char expString[1024];
9139 OldList * specs = MkList();
9140 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9142 char * string = PrintHexUInt64(arg.expression.ui64);
9143 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9145 ProcessExpressionType(exp);
9146 ComputeExpression(exp);
9147 expString[0] = '\0';
9148 PrintExpression(exp, expString);
9149 strcat(argument, expString);
9151 FreeExpression(exp);
9156 strcat(argument, arg.member.name);
9159 case TemplateParameterType::type:
9161 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9163 if(!strcmp(arg.dataTypeString, "thisclass"))
9164 strcat(argument, thisClassTypeString);
9166 strcat(argument, arg.dataTypeString);
9173 if(paramCount) strcat(templateString, ", ");
9174 if(lastParam != p - 1)
9176 strcat(templateString, param.name);
9177 strcat(templateString, " = ");
9179 strcat(templateString, argument);
9188 int len = strlen(templateString);
9189 if(templateString[len-1] == '>') templateString[len++] = ' ';
9190 templateString[len++] = '>';
9191 templateString[len++] = '\0';
9194 Context context = SetupTemplatesContext(_class);
9195 FreeType(exp.expType);
9196 exp.expType = ProcessTypeString(templateString, false);
9197 FinishTemplatesContext(context);
9201 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9202 exp.type = bracketsExp;
9203 exp.list = MkListOne(MkExpOp(null, '*',
9208 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9209 MkExpBrackets(MkListOne(
9210 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9212 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9214 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9219 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9220 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9222 type = ProcessTemplateParameterType(type.templateParameter);
9226 if(type && (type.kind == templateType));
9227 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9229 Identifier id = exp.member.member;
9230 TypeKind typeKind = type.kind;
9231 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9232 if(typeKind == subClassType && exp.member.exp.type == classExp)
9234 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9235 typeKind = classType;
9238 if(id && (typeKind == intType || typeKind == enumType))
9239 _class = eSystem_FindClass(privateModule, "int");
9244 (exp.member.exp.type == identifierExp &&
9245 !strcmp(exp.member.exp.identifier.string, "this"));*/
9246 Property prop = null;
9247 Method method = null;
9248 DataMember member = null;
9249 Property revConvert = null;
9250 ClassProperty classProp = null;
9252 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9253 exp.member.memberType = propertyMember;
9255 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9256 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9258 if(typeKind != subClassType)
9260 // Prioritize data members over properties for "this"
9261 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9263 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9264 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9266 prop = eClass_FindProperty(_class, id.string, privateModule);
9270 if(!member && !prop)
9271 prop = eClass_FindProperty(_class, id.string, privateModule);
9272 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9273 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9274 exp.member.thisPtr = true;
9276 // Prioritize properties over data members otherwise
9279 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9282 prop = eClass_FindProperty(_class, id.string, null);
9283 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9284 member = eClass_FindDataMember(_class, id.string, null, null, null);
9287 if(!prop && !member)
9289 method = eClass_FindMethod(_class, id.string, null);
9292 prop = eClass_FindProperty(_class, id.string, privateModule);
9293 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9294 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9300 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9307 if(!prop && !member)
9308 method = eClass_FindMethod(_class, id.string, privateModule);
9309 if(!prop && !member && !method)
9311 if(typeKind == subClassType)
9313 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9316 exp.member.memberType = classPropertyMember;
9317 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9321 // Assume this is a class_data member
9322 char structName[1024];
9323 Identifier id = exp.member.member;
9324 Expression classExp = exp.member.exp;
9327 FreeType(classExp.expType);
9328 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9330 strcpy(structName, "__ecereClassData_");
9331 FullClassNameCat(structName, type._class.string, false);
9332 exp.type = pointerExp;
9333 exp.member.member = id;
9335 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9336 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9337 MkExpBrackets(MkListOne(MkExpOp(
9338 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9339 MkExpMember(classExp, MkIdentifier("data"))), '+',
9340 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9345 ProcessExpressionType(exp);
9351 // Check for reverse conversion
9352 // (Convert in an instantiation later, so that we can use
9353 // deep properties system)
9354 Symbol classSym = FindClass(id.string);
9357 Class convertClass = classSym.registered;
9359 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9366 exp.member.memberType = propertyMember;
9368 ProcessPropertyType(prop);
9369 exp.expType = prop.dataType;
9370 if(prop.dataType) prop.dataType.refCount++;
9374 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9376 FreeExpContents(exp);
9377 exp.type = identifierExp;
9378 exp.identifier = MkIdentifier("class");
9379 ProcessExpressionType(exp);
9383 exp.member.memberType = dataMember;
9384 DeclareStruct(_class.fullName, false);
9385 if(!member.dataType)
9387 Context context = SetupTemplatesContext(_class);
9388 member.dataType = ProcessTypeString(member.dataTypeString, false);
9389 FinishTemplatesContext(context);
9391 exp.expType = member.dataType;
9392 if(member.dataType) member.dataType.refCount++;
9396 exp.member.memberType = reverseConversionMember;
9397 exp.expType = MkClassType(revConvert._class.fullName);
9405 exp.type = identifierExp;
9406 exp.identifier = exp.member.member;
9409 exp.member.memberType = methodMember;
9411 if(!method.dataType)
9412 ProcessMethodType(method);
9420 // Tricky spot here... To use instance versus class virtual table
9421 // Put it back to what it was... What did we break?
9423 // Had to put it back for overriding Main of Thread global instance
9425 //exp.expType.methodClass = _class;
9426 exp.expType.methodClass = (id && id._class) ? _class : null;
9428 // Need the actual class used for templated classes
9429 exp.expType.usedClass = _class;
9433 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9435 FreeExpContents(exp);
9436 exp.type = identifierExp;
9437 exp.identifier = MkIdentifier("class");
9438 ProcessExpressionType(exp);
9441 yylloc = exp.member.member.loc;
9442 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9444 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9447 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9452 while(tClass && !tClass.templateClass) tClass = tClass.base;
9454 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9457 ClassTemplateParameter curParam = null;
9460 for(sClass = tClass; sClass; sClass = sClass.base)
9463 if(sClass.templateClass) sClass = sClass.templateClass;
9464 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9466 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9468 for(sClass = sClass.base; sClass; sClass = sClass.base)
9469 id += sClass.templateParams.count;
9477 if(curParam && tClass.templateArgs[id].dataTypeString)
9479 ClassTemplateArgument arg = tClass.templateArgs[id];
9480 Context context = SetupTemplatesContext(tClass);
9482 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9483 FreeType(exp.expType);
9484 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9487 if(exp.expType.kind == thisClassType)
9489 FreeType(exp.expType);
9490 exp.expType = ReplaceThisClassType(_class);
9493 if(tClass.templateClass)
9494 exp.expType.passAsTemplate = true;
9495 //exp.expType.refCount++;
9498 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9499 //exp.destType.refCount++;
9501 if(exp.destType.kind == thisClassType)
9503 FreeType(exp.destType);
9504 exp.destType = ReplaceThisClassType(_class);
9508 FinishTemplatesContext(context);
9511 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9512 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9515 ClassTemplateParameter curParam = null;
9518 for(sClass = tClass; sClass; sClass = sClass.base)
9521 if(sClass.templateClass) sClass = sClass.templateClass;
9522 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9524 if(curParam.type == TemplateParameterType::type &&
9525 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9527 for(sClass = sClass.base; sClass; sClass = sClass.base)
9528 id += sClass.templateParams.count;
9538 ClassTemplateArgument arg = tClass.templateArgs[id];
9539 Context context = SetupTemplatesContext(tClass);
9542 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9544 basicType = ProcessTypeString(arg.dataTypeString, false);
9547 if(basicType.kind == thisClassType)
9549 FreeType(basicType);
9550 basicType = ReplaceThisClassType(_class);
9553 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9554 if(tClass.templateClass)
9555 basicType.passAsTemplate = true;
9558 FreeType(exp.expType);
9560 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9561 //exp.expType.refCount++;
9564 exp.destType = exp.expType;
9565 exp.destType.refCount++;
9569 Expression newExp { };
9570 OldList * specs = MkList();
9572 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9574 if(exp.destType) exp.destType.refCount++;
9575 if(exp.expType) exp.expType.refCount++;
9577 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9578 exp.cast.exp = newExp;
9579 //FreeType(exp.expType);
9580 //exp.expType = null;
9581 //ProcessExpressionType(sourceExp);
9584 FinishTemplatesContext(context);
9587 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9589 Class expClass = exp.expType._class.registered;
9592 Class cClass = null;
9597 char templateString[1024];
9598 ClassTemplateParameter param;
9599 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9600 while(cClass != expClass)
9603 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9606 for(param = cClass.templateParams.first; param; param = param.next)
9608 Class cClassCur = null;
9611 ClassTemplateParameter paramCur = null;
9612 ClassTemplateArgument arg;
9613 while(cClassCur != tClass && !paramCur)
9616 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9617 cClassCur = sClassCur;
9619 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9621 if(!strcmp(paramCur.name, param.name))
9629 if(paramCur && paramCur.type == TemplateParameterType::type)
9630 arg = tClass.templateArgs[cp];
9632 arg = expClass.templateArgs[p];
9639 strcat(argument, arg.name.string);
9640 strcat(argument, " = ");
9646 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9647 char expString[1024];
9648 OldList * specs = MkList();
9649 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9651 char * string = PrintHexUInt64(arg.expression.ui64);
9652 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9654 ProcessExpressionType(exp);
9655 ComputeExpression(exp);
9656 expString[0] = '\0';
9657 PrintExpression(exp, expString);
9658 strcat(argument, expString);
9660 FreeExpression(exp);
9665 strcat(argument, arg.member.name);
9668 case TemplateParameterType::type:
9670 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9671 strcat(argument, arg.dataTypeString);
9677 if(paramCount) strcat(templateString, ", ");
9678 if(lastParam != p - 1)
9680 strcat(templateString, param.name);
9681 strcat(templateString, " = ");
9683 strcat(templateString, argument);
9692 int len = strlen(templateString);
9693 if(templateString[len-1] == '>') templateString[len++] = ' ';
9694 templateString[len++] = '>';
9695 templateString[len++] = '\0';
9698 FreeType(exp.expType);
9700 Context context = SetupTemplatesContext(tClass);
9701 exp.expType = ProcessTypeString(templateString, false);
9702 FinishTemplatesContext(context);
9709 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9711 else if(type && (type.kind == structType || type.kind == unionType))
9713 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9716 exp.expType = memberType;
9718 memberType.refCount++;
9723 char expString[10240];
9724 expString[0] = '\0';
9725 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9726 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9729 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9731 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9733 Identifier id = exp.member.member;
9734 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9737 FreeType(exp.expType);
9738 exp.expType = ReplaceThisClassType(_class);
9745 // Convert x->y into (*x).y
9748 Type destType = exp.destType;
9750 // DOING THIS LATER NOW...
9751 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9753 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9754 /* TODO: Name Space Fix ups
9755 if(!exp.member.member.classSym)
9756 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9760 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9761 exp.type = memberExp;
9764 ProcessExpressionType(exp);
9771 //ComputeExpression(exp);
9773 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9774 if(classSym && classSym.registered)
9776 if(classSym.registered.type == noHeadClass)
9780 DeclareStruct(classSym.string, false);
9781 FreeSpecifier(exp._class);
9782 exp.type = typeSizeExp;
9783 FullClassNameCat(name, classSym.string, false);
9784 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9788 if(classSym.registered.fixed)
9790 FreeSpecifier(exp._class);
9791 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9792 exp.type = constantExp;
9796 char className[1024];
9797 strcpy(className, "__ecereClass_");
9798 FullClassNameCat(className, classSym.string, true);
9799 MangleClassName(className);
9801 DeclareClass(classSym, className);
9803 FreeExpContents(exp);
9804 exp.type = pointerExp;
9805 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9806 exp.member.member = MkIdentifier("structSize");
9816 // exp.isConstant = true;
9821 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9828 exp.isConstant = true;
9830 DeclareType(type, false, false);
9836 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9838 FreeType(exp.cast.exp.destType);
9839 exp.cast.exp.destType = type;
9841 ProcessExpressionType(exp.cast.exp);
9846 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9847 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9849 void * prev = exp.prev, * next = exp.next;
9850 Type expType = exp.cast.exp.destType;
9851 Expression castExp = exp.cast.exp;
9852 Type destType = exp.destType;
9854 if(expType) expType.refCount++;
9856 //FreeType(exp.destType);
9857 FreeType(exp.expType);
9858 FreeTypeName(exp.cast.typeName);
9861 FreeType(exp.expType);
9862 FreeType(exp.destType);
9864 exp.expType = expType;
9865 exp.destType = destType;
9875 exp.isConstant = exp.cast.exp.isConstant;
9880 case extensionInitializerExp:
9882 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9885 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9886 // ProcessInitializer(exp.initializer.initializer, type);
9892 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9893 ProcessExpressionType(exp.vaArg.exp);
9901 exp.isConstant = true;
9903 FreeType(exp.cond.cond.destType);
9904 exp.cond.cond.destType = MkClassType("bool");
9905 exp.cond.cond.destType.truth = true;
9906 ProcessExpressionType(exp.cond.cond);
9907 if(!exp.cond.cond.isConstant)
9908 exp.isConstant = false;
9909 for(e = exp.cond.exp->first; e; e = e.next)
9913 FreeType(e.destType);
9914 e.destType = exp.destType;
9915 if(e.destType) e.destType.refCount++;
9917 ProcessExpressionType(e);
9920 exp.expType = e.expType;
9921 if(e.expType) e.expType.refCount++;
9924 exp.isConstant = false;
9927 FreeType(exp.cond.elseExp.destType);
9928 // Added this check if we failed to find an expType
9929 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9932 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9934 if(exp.cond.elseExp.destType)
9935 exp.cond.elseExp.destType.refCount++;
9936 ProcessExpressionType(exp.cond.elseExp);
9938 // FIXED THIS: Was done before calling process on elseExp
9939 if(!exp.cond.elseExp.isConstant)
9940 exp.isConstant = false;
9943 case extensionCompoundExp:
9945 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9947 Statement last = exp.compound.compound.statements->last;
9948 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9950 ((Expression)last.expressions->last).destType = exp.destType;
9952 exp.destType.refCount++;
9954 ProcessStatement(exp.compound);
9955 exp.expType = ((Expression)last.expressions->last).expType;
9956 if(((Expression)last.expressions->last).expType)
9957 exp.expType.refCount++;
9963 Specifier spec = exp._classExp.specifiers->first;
9964 if(spec && spec.type == nameSpecifier)
9966 exp.expType = MkClassType(spec.name);
9967 exp.expType.kind = subClassType;
9968 exp.byReference = true;
9972 exp.expType = MkClassType("ecere::com::Class");
9973 exp.byReference = true;
9979 Class _class = thisClass ? thisClass : currentClass;
9982 Identifier id = exp.classData.id;
9983 char structName[1024];
9984 Expression classExp;
9985 strcpy(structName, "__ecereClassData_");
9986 FullClassNameCat(structName, _class.fullName, false);
9987 exp.type = pointerExp;
9988 exp.member.member = id;
9989 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9990 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9992 classExp = MkExpIdentifier(MkIdentifier("class"));
9994 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9995 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9996 MkExpBrackets(MkListOne(MkExpOp(
9997 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9998 MkExpMember(classExp, MkIdentifier("data"))), '+',
9999 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10002 ProcessExpressionType(exp);
10010 char * typeString = null;
10011 char typeStringBuf[1024];
10012 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10013 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10015 Class templateClass = exp.destType._class.registered;
10016 typeString = templateClass.templateArgs[2].dataTypeString;
10020 // Guess type from expressions in the array
10022 for(e = exp.list->first; e; e = e.next)
10024 ProcessExpressionType(e);
10027 if(!type) { type = e.expType; type.refCount++; }
10030 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10031 if(!MatchTypeExpression(e, type, null, false))
10037 e = exp.list->first;
10038 ProcessExpressionType(e);
10041 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10042 if(!MatchTypeExpression(e, type, null, false))
10044 FreeType(e.expType);
10055 FreeType(e.expType);
10062 typeStringBuf[0] = '\0';
10063 PrintType(type, typeStringBuf, false, true);
10064 typeString = typeStringBuf;
10072 (Container)& (struct BuiltInContainer)
10074 ._vTbl = class(BuiltInContainer)._vTbl,
10075 ._class = class(BuiltInContainer),
10077 .data = (int[]){ 1, 7, 3, 4, 5 },
10079 .type = class(int),
10082 char templateString[1024];
10083 OldList * initializers = MkList();
10084 OldList * structInitializers = MkList();
10085 OldList * specs = MkList();
10087 Declarator decl = SpecDeclFromString(typeString, specs, null);
10088 sprintf(templateString, "Container<%s>", typeString);
10093 type = ProcessTypeString(typeString, false);
10094 while(e = exp.list->first)
10096 exp.list->Remove(e);
10099 ProcessExpressionType(e);
10100 ListAdd(initializers, MkInitializerAssignment(e));
10106 DeclareStruct("ecere::com::BuiltInContainer", false);
10108 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10109 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10110 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10111 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10112 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10113 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10114 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10115 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10116 MkInitializerList(initializers))));
10117 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10118 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10119 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10120 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10121 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10122 exp.expType = ProcessTypeString(templateString, false);
10123 exp.type = bracketsExp;
10124 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10126 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10127 MkInitializerList(structInitializers)))));
10128 ProcessExpressionType(expExt);
10132 exp.expType = ProcessTypeString("Container", false);
10133 Compiler_Error($"Couldn't determine type of array elements\n");
10139 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10141 FreeType(exp.expType);
10142 exp.expType = ReplaceThisClassType(thisClass);
10145 // Resolve structures here
10146 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10148 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10149 // TODO: Fix members reference...
10152 if(exp.expType.kind != enumType)
10155 String enumName = CopyString(exp.expType.enumName);
10157 // Fixed a memory leak on self-referencing C structs typedefs
10158 // by instantiating a new type rather than simply copying members
10159 // into exp.expType
10160 FreeType(exp.expType);
10161 exp.expType = Type { };
10162 exp.expType.kind = symbol.type.kind;
10163 exp.expType.refCount++;
10164 exp.expType.enumName = enumName;
10166 exp.expType.members = symbol.type.members;
10167 for(member = symbol.type.members.first; member; member = member.next)
10173 for(member = symbol.type.members.first; member; member = member.next)
10175 NamedLink value { name = CopyString(member.name) };
10176 exp.expType.members.Add(value);
10183 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10184 else if(exp.destType && !exp.destType.keepCast)
10186 if(!CheckExpressionType(exp, exp.destType, false))
10188 if(!exp.destType.count || unresolved)
10193 if(exp.destType.kind != ellipsisType)
10199 char expString[10240];
10200 expString[0] = '\0';
10202 PrintType(exp.destType, type2, false, true);
10204 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10206 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10207 else if(exp.type != dummyExp)
10208 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10213 char expString[10240] ;
10214 expString[0] = '\0';
10215 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10218 Compiler_Error($"unresolved identifier %s\n", expString);
10219 else if(exp.type != dummyExp)
10220 Compiler_Error($"couldn't determine type of %s\n", expString);
10231 PrintType(exp.expType, type1, false, true);
10232 PrintType(exp.destType, type2, false, true);
10235 //CheckExpressionType(exp, exp.destType, false);
10237 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10238 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10239 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10242 char expString[10240];
10243 expString[0] = '\0';
10244 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10247 CheckExpressionType(exp, exp.destType, false);
10249 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10250 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10251 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10253 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10254 FreeType(exp.expType);
10255 exp.destType.refCount++;
10256 exp.expType = exp.destType;
10261 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10263 Expression newExp { };
10264 char typeString[1024];
10265 OldList * specs = MkList();
10268 typeString[0] = '\0';
10272 if(exp.expType) exp.expType.refCount++;
10273 if(exp.expType) exp.expType.refCount++;
10274 exp.type = castExp;
10275 newExp.destType = exp.expType;
10277 PrintType(exp.expType, typeString, false, false);
10278 decl = SpecDeclFromString(typeString, specs, null);
10280 exp.cast.typeName = MkTypeName(specs, decl);
10281 exp.cast.exp = newExp;
10284 else if(unresolved)
10286 if(exp.identifier._class && exp.identifier._class.name)
10287 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10288 else if(exp.identifier.string && exp.identifier.string[0])
10289 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10291 else if(!exp.expType && exp.type != dummyExp)
10293 char expString[10240];
10294 expString[0] = '\0';
10295 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10296 Compiler_Error($"couldn't determine type of %s\n", expString);
10299 // Let's try to support any_object & typed_object here:
10300 ApplyAnyObjectLogic(exp);
10302 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10303 exp.expType._class.registered.type == noHeadClass)
10305 exp.byReference = true;
10307 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10308 exp.destType._class.registered.type == noHeadClass)
10310 exp.byReference = true;
10312 yylloc = oldyylloc;
10315 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10317 // THIS CODE WILL FIND NEXT MEMBER...
10320 *curMember = (*curMember).next;
10322 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10324 *curMember = subMemberStack[--(*subMemberStackPos)];
10325 *curMember = (*curMember).next;
10328 // SKIP ALL PROPERTIES HERE...
10329 while((*curMember) && (*curMember).isProperty)
10330 *curMember = (*curMember).next;
10332 if(subMemberStackPos)
10334 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10336 subMemberStack[(*subMemberStackPos)++] = *curMember;
10338 *curMember = (*curMember).members.first;
10339 while(*curMember && (*curMember).isProperty)
10340 *curMember = (*curMember).next;
10348 if(subMemberStackPos && *subMemberStackPos)
10350 *curMember = subMemberStack[--(*subMemberStackPos)];
10351 *curMember = (*curMember).next;
10355 Class lastCurClass = *curClass;
10357 if(*curClass == _class) break; // REACHED THE END
10359 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10360 *curMember = (*curClass).membersAndProperties.first;
10363 while((*curMember) && (*curMember).isProperty)
10364 *curMember = (*curMember).next;
10365 if(subMemberStackPos)
10367 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10369 subMemberStack[(*subMemberStackPos)++] = *curMember;
10371 *curMember = (*curMember).members.first;
10372 while(*curMember && (*curMember).isProperty)
10373 *curMember = (*curMember).next;
10381 static void ProcessInitializer(Initializer init, Type type)
10385 case expInitializer:
10386 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10388 // TESTING THIS FOR SHUTTING = 0 WARNING
10389 if(init.exp && !init.exp.destType)
10391 FreeType(init.exp.destType);
10392 init.exp.destType = type;
10393 if(type) type.refCount++;
10397 ProcessExpressionType(init.exp);
10398 init.isConstant = init.exp.isConstant;
10404 Expression exp = init.exp;
10405 Instantiation inst = exp.instance;
10406 MembersInit members;
10408 init.type = listInitializer;
10409 init.list = MkList();
10413 for(members = inst.members->first; members; members = members.next)
10415 if(members.type == dataMembersInit)
10418 for(member = members.dataMembers->first; member; member = member.next)
10420 ListAdd(init.list, member.initializer);
10421 member.initializer = null;
10424 // Discard all MembersInitMethod
10427 FreeExpression(exp);
10429 case listInitializer:
10432 Type initializerType = null;
10433 Class curClass = null;
10434 DataMember curMember = null;
10435 DataMember subMemberStack[256];
10436 int subMemberStackPos = 0;
10438 if(type && type.kind == arrayType)
10439 initializerType = Dereference(type);
10440 else if(type && (type.kind == structType || type.kind == unionType))
10441 initializerType = type.members.first;
10443 for(i = init.list->first; i; i = i.next)
10445 if(type && type.kind == classType && type._class && type._class.registered)
10447 // 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)
10448 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10449 // TODO: Generate error on initializing a private data member this way from another module...
10452 if(!curMember.dataType)
10453 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10454 initializerType = curMember.dataType;
10457 ProcessInitializer(i, initializerType);
10458 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10459 initializerType = initializerType.next;
10461 init.isConstant = false;
10464 if(type && type.kind == arrayType)
10465 FreeType(initializerType);
10467 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10469 Compiler_Error($"Assigning list initializer to non list\n");
10476 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10480 case baseSpecifier:
10482 if(spec.specifier == THISCLASS)
10486 spec.type = nameSpecifier;
10487 spec.name = ReplaceThisClass(thisClass);
10488 spec.symbol = FindClass(spec.name);
10489 ProcessSpecifier(spec, declareStruct);
10494 case nameSpecifier:
10496 Symbol symbol = FindType(curContext, spec.name);
10498 DeclareType(symbol.type, true, true);
10499 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10500 DeclareStruct(spec.name, false);
10503 case enumSpecifier:
10508 for(e = spec.list->first; e; e = e.next)
10511 ProcessExpressionType(e.exp);
10516 case structSpecifier:
10517 case unionSpecifier:
10519 if(spec.definitions)
10522 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10524 ProcessClass(spec.definitions, symbol);
10527 for(def = spec.definitions->first; def; def = def.next)
10529 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10530 ProcessDeclaration(def.decl);
10537 case classSpecifier:
10539 Symbol classSym = FindClass(spec.name);
10540 if(classSym && classSym.registered && classSym.registered.type == structClass)
10541 DeclareStruct(spec.name, false);
10549 static void ProcessDeclarator(Declarator decl)
10553 case identifierDeclarator:
10554 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10556 FreeSpecifier(decl.identifier._class);
10557 decl.identifier._class = null;
10560 case arrayDeclarator:
10562 ProcessExpressionType(decl.array.exp);
10563 case structDeclarator:
10564 case bracketsDeclarator:
10565 case functionDeclarator:
10566 case pointerDeclarator:
10567 case extendedDeclarator:
10568 case extendedDeclaratorEnd:
10569 if(decl.declarator)
10570 ProcessDeclarator(decl.declarator);
10571 if(decl.type == functionDeclarator)
10573 Identifier id = GetDeclId(decl);
10574 if(id && id._class)
10578 qualifiers = MkListOne(id._class);
10581 if(!decl.function.parameters)
10582 decl.function.parameters = MkList();
10583 decl.function.parameters->Insert(null, param);
10586 if(decl.function.parameters)
10590 for(param = decl.function.parameters->first; param; param = param.next)
10592 if(param.qualifiers && param.qualifiers->first)
10594 Specifier spec = param.qualifiers->first;
10595 if(spec && spec.specifier == TYPED_OBJECT)
10597 Declarator d = param.declarator;
10600 qualifiers = MkListOne(MkSpecifier(VOID));
10601 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10604 FreeList(param.qualifiers, FreeSpecifier);
10606 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10607 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10609 decl.function.parameters->Insert(param, newParam);
10612 else if(spec && spec.specifier == ANY_OBJECT)
10614 Declarator d = param.declarator;
10616 FreeList(param.qualifiers, FreeSpecifier);
10618 param.qualifiers = MkListOne(MkSpecifier(VOID));
10619 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10621 else if(spec.specifier == THISCLASS)
10625 spec.type = nameSpecifier;
10626 spec.name = ReplaceThisClass(thisClass);
10627 spec.symbol = FindClass(spec.name);
10628 ProcessSpecifier(spec, false);
10633 if(param.declarator)
10634 ProcessDeclarator(param.declarator);
10642 static void ProcessDeclaration(Declaration decl)
10647 case initDeclaration:
10649 bool declareStruct = false;
10651 lineNum = decl.pos.line;
10652 column = decl.pos.col;
10655 if(decl.declarators)
10659 for(d = decl.declarators->first; d; d = d.next)
10661 Type type, subType;
10662 ProcessDeclarator(d.declarator);
10664 type = ProcessType(decl.specifiers, d.declarator);
10668 ProcessInitializer(d.initializer, type);
10670 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10672 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10673 d.initializer.exp.type == instanceExp)
10675 if(type.kind == classType && type._class ==
10676 d.initializer.exp.expType._class)
10678 Instantiation inst = d.initializer.exp.instance;
10679 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10681 d.initializer.exp.instance = null;
10682 if(decl.specifiers)
10683 FreeList(decl.specifiers, FreeSpecifier);
10684 FreeList(decl.declarators, FreeInitDeclarator);
10688 decl.type = instDeclaration;
10693 for(subType = type; subType;)
10695 if(subType.kind == classType)
10697 declareStruct = true;
10700 else if(subType.kind == pointerType)
10702 else if(subType.kind == arrayType)
10703 subType = subType.arrayType;
10713 if(decl.specifiers)
10716 for(s = decl.specifiers->first; s; s = s.next)
10718 ProcessSpecifier(s, declareStruct);
10723 case instDeclaration:
10725 ProcessInstantiationType(decl.inst);
10728 case structDeclaration:
10732 bool declareStruct = false;
10734 if(decl.declarators)
10736 for(d = decl.declarators->first; d; d = d.next)
10738 Type type = ProcessType(decl.specifiers, d.declarator);
10740 ProcessDeclarator(d);
10741 for(subType = type; subType;)
10743 if(subType.kind == classType)
10745 declareStruct = true;
10748 else if(subType.kind == pointerType)
10750 else if(subType.kind == arrayType)
10751 subType = subType.arrayType;
10758 if(decl.specifiers)
10760 for(spec = decl.specifiers->first; spec; spec = spec.next)
10761 ProcessSpecifier(spec, declareStruct);
10768 static FunctionDefinition curFunction;
10770 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10772 char propName[1024], propNameM[1024];
10773 char getName[1024], setName[1024];
10776 DeclareProperty(prop, setName, getName);
10778 // eInstance_FireWatchers(object, prop);
10779 strcpy(propName, "__ecereProp_");
10780 FullClassNameCat(propName, prop._class.fullName, false);
10781 strcat(propName, "_");
10782 // strcat(propName, prop.name);
10783 FullClassNameCat(propName, prop.name, true);
10784 MangleClassName(propName);
10786 strcpy(propNameM, "__ecerePropM_");
10787 FullClassNameCat(propNameM, prop._class.fullName, false);
10788 strcat(propNameM, "_");
10789 // strcat(propNameM, prop.name);
10790 FullClassNameCat(propNameM, prop.name, true);
10791 MangleClassName(propNameM);
10793 if(prop.isWatchable)
10796 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10797 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10798 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10801 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10802 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10803 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10809 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10810 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10811 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10814 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10815 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10816 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10819 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10820 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10821 curFunction.propSet.fireWatchersDone = true;
10824 static void ProcessStatement(Statement stmt)
10828 lineNum = stmt.pos.line;
10829 column = stmt.pos.col;
10834 ProcessStatement(stmt.labeled.stmt);
10837 // This expression should be constant...
10838 if(stmt.caseStmt.exp)
10840 FreeType(stmt.caseStmt.exp.destType);
10841 stmt.caseStmt.exp.destType = curSwitchType;
10842 if(curSwitchType) curSwitchType.refCount++;
10843 ProcessExpressionType(stmt.caseStmt.exp);
10844 ComputeExpression(stmt.caseStmt.exp);
10846 if(stmt.caseStmt.stmt)
10847 ProcessStatement(stmt.caseStmt.stmt);
10851 if(stmt.compound.context)
10856 Statement prevCompound = curCompound;
10857 Context prevContext = curContext;
10859 if(!stmt.compound.isSwitch)
10861 curCompound = stmt;
10862 curContext = stmt.compound.context;
10865 if(stmt.compound.declarations)
10867 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10868 ProcessDeclaration(decl);
10870 if(stmt.compound.statements)
10872 for(s = stmt.compound.statements->first; s; s = s.next)
10873 ProcessStatement(s);
10876 curContext = prevContext;
10877 curCompound = prevCompound;
10881 case expressionStmt:
10884 if(stmt.expressions)
10886 for(exp = stmt.expressions->first; exp; exp = exp.next)
10887 ProcessExpressionType(exp);
10895 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10896 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10897 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10898 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10900 ProcessExpressionType(exp);
10902 if(stmt.ifStmt.stmt)
10903 ProcessStatement(stmt.ifStmt.stmt);
10904 if(stmt.ifStmt.elseStmt)
10905 ProcessStatement(stmt.ifStmt.elseStmt);
10910 Type oldSwitchType = curSwitchType;
10911 if(stmt.switchStmt.exp)
10914 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10924 e.exp.destType = destType;
10927 ProcessExpressionType(exp);
10930 curSwitchType = exp.expType;
10933 ProcessStatement(stmt.switchStmt.stmt);
10934 curSwitchType = oldSwitchType;
10939 if(stmt.whileStmt.exp)
10943 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10944 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10945 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10946 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10948 ProcessExpressionType(exp);
10951 if(stmt.whileStmt.stmt)
10952 ProcessStatement(stmt.whileStmt.stmt);
10957 if(stmt.doWhile.exp)
10961 if(stmt.doWhile.exp->last)
10963 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10964 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10965 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10967 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10969 ProcessExpressionType(exp);
10972 if(stmt.doWhile.stmt)
10973 ProcessStatement(stmt.doWhile.stmt);
10979 if(stmt.forStmt.init)
10980 ProcessStatement(stmt.forStmt.init);
10982 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10984 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10985 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10986 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10989 if(stmt.forStmt.check)
10990 ProcessStatement(stmt.forStmt.check);
10991 if(stmt.forStmt.increment)
10993 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10994 ProcessExpressionType(exp);
10997 if(stmt.forStmt.stmt)
10998 ProcessStatement(stmt.forStmt.stmt);
11003 Identifier id = stmt.forEachStmt.id;
11004 OldList * exp = stmt.forEachStmt.exp;
11005 OldList * filter = stmt.forEachStmt.filter;
11006 Statement block = stmt.forEachStmt.stmt;
11007 char iteratorType[1024];
11010 bool isBuiltin = exp && exp->last &&
11011 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11012 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11013 Expression arrayExp;
11014 char * typeString = null;
11015 int builtinCount = 0;
11017 for(e = exp ? exp->first : null; e; e = e.next)
11021 FreeType(e.destType);
11022 e.destType = ProcessTypeString("Container", false);
11024 if(!isBuiltin || e.next)
11025 ProcessExpressionType(e);
11028 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11029 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11030 eClass_IsDerived(source._class.registered, containerClass)))
11032 Class _class = source ? source._class.registered : null;
11034 Expression expIt = null;
11035 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11036 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11037 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11038 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11039 stmt.type = compoundStmt;
11041 stmt.compound.context = Context { };
11042 stmt.compound.context.parent = curContext;
11043 curContext = stmt.compound.context;
11045 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11047 Class mapClass = eSystem_FindClass(privateModule, "Map");
11048 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11049 isCustomAVLTree = true;
11050 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11052 else if(eClass_IsDerived(source._class.registered, mapClass))
11055 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11056 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11058 Class listClass = eSystem_FindClass(privateModule, "List");
11060 isList = eClass_IsDerived(source._class.registered, listClass);
11066 OldList * specs = MkList();
11067 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11068 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11069 stmt.compound.declarations = MkListOne(
11070 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11071 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11072 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11073 MkInitializerAssignment(MkExpBrackets(exp))))));
11078 char typeStringBuf[1024];
11080 // TODO: Merge this code?
11081 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11082 if(((Expression)exp->last).type == castExp)
11084 TypeName typeName = ((Expression)exp->last).cast.typeName;
11086 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11089 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11090 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11091 arrayExp.destType._class.registered.templateArgs)
11093 Class templateClass = arrayExp.destType._class.registered;
11094 typeString = templateClass.templateArgs[2].dataTypeString;
11096 else if(arrayExp.list)
11098 // Guess type from expressions in the array
11100 for(e = arrayExp.list->first; e; e = e.next)
11102 ProcessExpressionType(e);
11105 if(!type) { type = e.expType; type.refCount++; }
11108 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11109 if(!MatchTypeExpression(e, type, null, false))
11115 e = arrayExp.list->first;
11116 ProcessExpressionType(e);
11119 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11120 if(!MatchTypeExpression(e, type, null, false))
11122 FreeType(e.expType);
11133 FreeType(e.expType);
11140 typeStringBuf[0] = '\0';
11141 PrintType(type, typeStringBuf, false, true);
11142 typeString = typeStringBuf;
11148 OldList * initializers = MkList();
11150 OldList * specs = MkList();
11155 builtinCount = arrayExp.list->count;
11156 type = ProcessTypeString(typeString, false);
11157 while(e = arrayExp.list->first)
11159 arrayExp.list->Remove(e);
11162 ProcessExpressionType(e);
11163 ListAdd(initializers, MkInitializerAssignment(e));
11166 delete arrayExp.list;
11168 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11169 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11170 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11172 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11173 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11175 FreeList(exp, FreeExpression);
11179 arrayExp.expType = ProcessTypeString("Container", false);
11180 Compiler_Error($"Couldn't determine type of array elements\n");
11185 OldList * specs = MkList();
11187 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11188 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11189 stmt.compound.declarations = MkListOne(
11190 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11191 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11192 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11193 MkInitializerAssignment(MkExpBrackets(exp))))));
11196 else if(isLinkList && !isList)
11199 OldList * specs = MkList();
11200 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11201 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11202 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11203 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11204 MkInitializerAssignment(MkExpBrackets(exp))))));
11206 /*else if(isCustomAVLTree)
11209 OldList * specs = MkList();
11210 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11211 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11212 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11213 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11214 MkInitializerAssignment(MkExpBrackets(exp))))));
11216 else if(_class.templateArgs)
11219 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11221 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11223 stmt.compound.declarations = MkListOne(
11224 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11225 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11226 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11228 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11230 if(block && block.type == compoundStmt && block.compound.context)
11232 block.compound.context.parent = stmt.compound.context;
11236 block = MkIfStmt(filter, block, null);
11240 stmt.compound.statements = MkListOne(MkForStmt(
11241 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11242 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11243 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11244 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11246 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11247 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11248 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11253 //OldList * specs = MkList();
11254 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11256 sprintf(count, "%d", builtinCount);
11258 stmt.compound.statements = MkListOne(MkForStmt(
11259 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11260 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11261 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11262 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11266 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11267 stmt.compound.statements = MkListOne(MkForStmt(
11268 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11269 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11270 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11271 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11274 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11275 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11276 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11278 else if(isLinkList && !isList)
11280 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11281 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11282 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11283 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11285 stmt.compound.statements = MkListOne(MkForStmt(
11286 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11287 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11288 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11293 OldList * specs = MkList();
11294 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11295 stmt.compound.statements = MkListOne(MkForStmt(
11296 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11297 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11298 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11299 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11300 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11303 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11304 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11305 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11307 /*else if(isCustomAVLTree)
11309 stmt.compound.statements = MkListOne(MkForStmt(
11310 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11311 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11312 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11313 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11316 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11317 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11318 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11322 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11323 MkIdentifier("Next")), null)), block));
11325 ProcessExpressionType(expIt);
11326 if(stmt.compound.declarations->first)
11327 ProcessDeclaration(stmt.compound.declarations->first);
11330 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11332 ProcessStatement(stmt);
11333 curContext = stmt.compound.context.parent;
11338 Compiler_Error($"Expression is not a container\n");
11351 if(stmt.expressions)
11353 for(exp = stmt.expressions->first; exp; exp = exp.next)
11357 if(curFunction && !curFunction.type)
11358 curFunction.type = ProcessType(
11359 curFunction.specifiers, curFunction.declarator);
11360 FreeType(exp.destType);
11361 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11362 if(exp.destType) exp.destType.refCount++;
11364 ProcessExpressionType(exp);
11369 case badDeclarationStmt:
11371 ProcessDeclaration(stmt.decl);
11377 if(stmt.asmStmt.inputFields)
11379 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11380 if(field.expression)
11381 ProcessExpressionType(field.expression);
11383 if(stmt.asmStmt.outputFields)
11385 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11386 if(field.expression)
11387 ProcessExpressionType(field.expression);
11389 if(stmt.asmStmt.clobberedFields)
11391 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11393 if(field.expression)
11394 ProcessExpressionType(field.expression);
11401 PropertyWatch propWatch;
11402 OldList * watches = stmt._watch.watches;
11403 Expression object = stmt._watch.object;
11404 Expression watcher = stmt._watch.watcher;
11406 ProcessExpressionType(watcher);
11408 ProcessExpressionType(object);
11412 if(watcher || thisClass)
11414 External external = curExternal;
11415 Context context = curContext;
11417 stmt.type = expressionStmt;
11418 stmt.expressions = MkList();
11420 curExternal = external.prev;
11422 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11424 ClassFunction func;
11425 char watcherName[1024];
11426 Class watcherClass = watcher ?
11427 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11428 External createdExternal;
11430 // Create a declaration above
11431 External externalDecl = MkExternalDeclaration(null);
11432 ast->Insert(curExternal.prev, externalDecl);
11434 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11435 if(propWatch.deleteWatch)
11436 strcat(watcherName, "_delete");
11440 for(propID = propWatch.properties->first; propID; propID = propID.next)
11442 strcat(watcherName, "_");
11443 strcat(watcherName, propID.string);
11447 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11449 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11450 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11451 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11452 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11453 ProcessClassFunctionBody(func, propWatch.compound);
11454 propWatch.compound = null;
11456 //afterExternal = afterExternal ? afterExternal : curExternal;
11458 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11459 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11461 createdExternal.symbol.idCode = external.symbol.idCode;
11463 curExternal = createdExternal;
11464 ProcessFunction(createdExternal.function);
11467 // Create a declaration above
11469 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11470 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11471 externalDecl.declaration = decl;
11472 if(decl.symbol && !decl.symbol.pointerExternal)
11473 decl.symbol.pointerExternal = externalDecl;
11476 if(propWatch.deleteWatch)
11478 OldList * args = MkList();
11479 ListAdd(args, CopyExpression(object));
11480 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11481 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11482 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11486 Class _class = object.expType._class.registered;
11489 for(propID = propWatch.properties->first; propID; propID = propID.next)
11491 char propName[1024];
11492 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11495 char getName[1024], setName[1024];
11496 OldList * args = MkList();
11498 DeclareProperty(prop, setName, getName);
11500 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11501 strcpy(propName, "__ecereProp_");
11502 FullClassNameCat(propName, prop._class.fullName, false);
11503 strcat(propName, "_");
11504 // strcat(propName, prop.name);
11505 FullClassNameCat(propName, prop.name, true);
11507 ListAdd(args, CopyExpression(object));
11508 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11509 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11510 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11512 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11515 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11520 Compiler_Error($"Invalid watched object\n");
11523 curExternal = external;
11524 curContext = context;
11527 FreeExpression(watcher);
11529 FreeExpression(object);
11530 FreeList(watches, FreePropertyWatch);
11533 Compiler_Error($"No observer specified and not inside a _class\n");
11537 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11539 ProcessStatement(propWatch.compound);
11545 case fireWatchersStmt:
11547 OldList * watches = stmt._watch.watches;
11548 Expression object = stmt._watch.object;
11550 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11551 // printf("%X\n", watches);
11552 // printf("%X\n", stmt._watch.watches);
11554 ProcessExpressionType(object);
11559 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11565 stmt.type = expressionStmt;
11566 stmt.expressions = MkList();
11568 // Check if we're inside a property set
11569 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11571 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11575 //Compiler_Error($"No property specified and not inside a property set\n");
11579 for(propID = watches->first; propID; propID = propID.next)
11581 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11584 CreateFireWatcher(prop, object, stmt);
11587 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11592 // Fire all properties!
11595 for(base = _class; base; base = base.base)
11597 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11599 if(prop.isProperty && prop.isWatchable)
11601 CreateFireWatcher(prop, object, stmt);
11608 FreeExpression(object);
11609 FreeList(watches, FreeIdentifier);
11612 Compiler_Error($"Invalid object specified and not inside a class\n");
11616 case stopWatchingStmt:
11618 OldList * watches = stmt._watch.watches;
11619 Expression object = stmt._watch.object;
11620 Expression watcher = stmt._watch.watcher;
11623 ProcessExpressionType(object);
11625 ProcessExpressionType(watcher);
11628 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11630 if(watcher || thisClass)
11636 stmt.type = expressionStmt;
11637 stmt.expressions = MkList();
11642 // eInstance_StopWatching(object, null, watcher);
11644 ListAdd(args, CopyExpression(object));
11645 ListAdd(args, MkExpConstant("0"));
11646 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11647 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11651 for(propID = watches->first; propID; propID = propID.next)
11653 char propName[1024];
11654 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11657 char getName[1024], setName[1024];
11658 OldList * args = MkList();
11660 DeclareProperty(prop, setName, getName);
11662 // eInstance_StopWatching(object, prop, watcher);
11663 strcpy(propName, "__ecereProp_");
11664 FullClassNameCat(propName, prop._class.fullName, false);
11665 strcat(propName, "_");
11666 // strcat(propName, prop.name);
11667 FullClassNameCat(propName, prop.name, true);
11668 MangleClassName(propName);
11670 ListAdd(args, CopyExpression(object));
11671 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11672 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11673 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11676 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11681 FreeExpression(object);
11683 FreeExpression(watcher);
11684 FreeList(watches, FreeIdentifier);
11687 Compiler_Error($"Invalid object specified and not inside a class\n");
11690 Compiler_Error($"No observer specified and not inside a class\n");
11697 static void ProcessFunction(FunctionDefinition function)
11699 Identifier id = GetDeclId(function.declarator);
11700 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11701 Type type = symbol ? symbol.type : null;
11702 Class oldThisClass = thisClass;
11703 Context oldTopContext = topContext;
11705 yylloc = function.loc;
11706 // Process thisClass
11708 if(type && type.thisClass)
11710 Symbol classSym = type.thisClass;
11711 Class _class = type.thisClass.registered;
11712 char className[1024];
11713 char structName[1024];
11714 Declarator funcDecl;
11717 bool typedObject = false;
11719 if(_class && !_class.base)
11721 _class = currentClass;
11722 if(_class && !_class.symbol)
11723 _class.symbol = FindClass(_class.fullName);
11724 classSym = _class ? _class.symbol : null;
11725 typedObject = true;
11728 thisClass = _class;
11730 if(inCompiler && _class)
11732 if(type.kind == functionType)
11734 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11736 //TypeName param = symbol.type.params.first;
11737 Type param = symbol.type.params.first;
11738 symbol.type.params.Remove(param);
11739 //FreeTypeName(param);
11742 if(type.classObjectType != classPointer)
11744 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11745 symbol.type.staticMethod = true;
11746 symbol.type.thisClass = null;
11748 // HIGH DANGER: VERIFYING THIS...
11749 symbol.type.extraParam = false;
11753 strcpy(className, "__ecereClass_");
11754 FullClassNameCat(className, _class.fullName, true);
11756 MangleClassName(className);
11759 FullClassNameCat(structName, _class.fullName, false);
11764 funcDecl = GetFuncDecl(function.declarator);
11767 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11769 TypeName param = funcDecl.function.parameters->first;
11770 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11772 funcDecl.function.parameters->Remove(param);
11773 FreeTypeName(param);
11777 // DANGER: Watch for this... Check if it's a Conversion?
11778 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11780 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11781 if(!function.propertyNoThis)
11783 TypeName thisParam;
11785 if(type.classObjectType != classPointer)
11787 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11788 if(!funcDecl.function.parameters)
11789 funcDecl.function.parameters = MkList();
11790 funcDecl.function.parameters->Insert(null, thisParam);
11795 if(type.classObjectType != classPointer)
11797 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11798 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11801 thisParam = TypeName
11803 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11804 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11806 funcDecl.function.parameters->Insert(null, thisParam);
11811 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11813 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11814 funcDecl = GetFuncDecl(initDecl.declarator);
11817 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11819 TypeName param = funcDecl.function.parameters->first;
11820 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11822 funcDecl.function.parameters->Remove(param);
11823 FreeTypeName(param);
11827 if(type.classObjectType != classPointer)
11829 // DANGER: Watch for this... Check if it's a Conversion?
11830 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11832 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11834 if(!funcDecl.function.parameters)
11835 funcDecl.function.parameters = MkList();
11836 funcDecl.function.parameters->Insert(null, thisParam);
11843 // Add this to the context
11846 if(type.classObjectType != classPointer)
11848 thisSymbol = Symbol
11850 string = CopyString("this");
11851 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11853 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11855 if(typedObject && thisSymbol.type)
11857 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11858 thisSymbol.type.byReference = type.byReference;
11860 thisSymbol = Symbol { string = CopyString("class") };
11861 function.body.compound.context.symbols.Add(thisSymbol);
11867 // Pointer to class data
11869 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11871 DataMember member = null;
11874 for(base = _class; base && base.type != systemClass; base = base.next)
11876 for(member = base.membersAndProperties.first; member; member = member.next)
11877 if(!member.isProperty)
11883 for(member = _class.membersAndProperties.first; member; member = member.next)
11884 if(!member.isProperty)
11888 char pointerName[1024];
11891 Initializer initializer;
11892 Expression exp, bytePtr;
11894 strcpy(pointerName, "__ecerePointer_");
11895 FullClassNameCat(pointerName, _class.fullName, false);
11897 char className[1024];
11898 strcpy(className, "__ecereClass_");
11899 FullClassNameCat(className, classSym.string, true);
11900 MangleClassName(className);
11903 DeclareClass(classSym, className);
11907 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11912 sprintf(string, "%d", _class.offset);
11913 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11917 // ([bytePtr] + [className]->offset)
11918 exp = QBrackets(MkExpOp(bytePtr, '+',
11919 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11922 // (this ? [exp] : 0)
11923 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11927 kind = pointerType;
11928 type = Type { refCount = 1, kind = voidType };
11933 yylloc = function.body.loc;
11934 // ([structName] *) [exp]
11935 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11936 initializer = MkInitializerAssignment(
11937 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11939 // [structName] * [pointerName] = [initializer];
11940 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11943 Context prevContext = curContext;
11944 curContext = function.body.compound.context;
11946 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11947 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11949 curContext = prevContext;
11953 decl.symbol = null;
11955 if(!function.body.compound.declarations)
11956 function.body.compound.declarations = MkList();
11957 function.body.compound.declarations->Insert(null, decl);
11963 // Loop through the function and replace undeclared identifiers
11964 // which are a member of the class (methods, properties or data)
11965 // by "this.[member]"
11972 FreeSpecifier(id._class);
11975 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11977 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11978 id = GetDeclId(initDecl.declarator);
11980 FreeSpecifier(id._class);
11985 topContext = function.body.compound.context;
11987 FunctionDefinition oldFunction = curFunction;
11988 curFunction = function;
11990 ProcessStatement(function.body);
11992 // If this is a property set and no firewatchers has been done yet, add one here
11993 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11995 Statement prevCompound = curCompound;
11996 Context prevContext = curContext;
11998 Statement fireWatchers = MkFireWatchersStmt(null, null);
11999 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12000 ListAdd(function.body.compound.statements, fireWatchers);
12002 curCompound = function.body;
12003 curContext = function.body.compound.context;
12005 ProcessStatement(fireWatchers);
12007 curContext = prevContext;
12008 curCompound = prevCompound;
12012 curFunction = oldFunction;
12015 if(function.declarator)
12017 ProcessDeclarator(function.declarator);
12020 topContext = oldTopContext;
12021 thisClass = oldThisClass;
12024 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12025 static void ProcessClass(OldList definitions, Symbol symbol)
12028 External external = curExternal;
12029 Class regClass = symbol ? symbol.registered : null;
12031 // Process all functions
12032 for(def = definitions.first; def; def = def.next)
12034 if(def.type == functionClassDef)
12036 if(def.function.declarator)
12037 curExternal = def.function.declarator.symbol.pointerExternal;
12039 curExternal = external;
12041 ProcessFunction((FunctionDefinition)def.function);
12043 else if(def.type == declarationClassDef)
12045 if(def.decl.type == instDeclaration)
12047 thisClass = regClass;
12048 ProcessInstantiationType(def.decl.inst);
12054 Class backThisClass = thisClass;
12055 if(regClass) thisClass = regClass;
12056 ProcessDeclaration(def.decl);
12057 thisClass = backThisClass;
12060 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12062 MemberInit defProperty;
12064 // Add this to the context
12065 Symbol thisSymbol = Symbol
12067 string = CopyString("this");
12068 type = regClass ? MkClassType(regClass.fullName) : null;
12070 globalContext.symbols.Add((BTNode)thisSymbol);
12072 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12074 thisClass = regClass;
12075 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12079 globalContext.symbols.Remove((BTNode)thisSymbol);
12080 FreeSymbol(thisSymbol);
12082 else if(def.type == propertyClassDef && def.propertyDef)
12084 PropertyDef prop = def.propertyDef;
12086 // Add this to the context
12088 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12089 globalContext.symbols.Add(thisSymbol);
12092 thisClass = regClass;
12099 string = CopyString("this");
12100 type = MkClassType(regClass.fullName);
12102 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12105 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12106 ProcessStatement(prop.setStmt);
12114 string = CopyString("this");
12115 type = MkClassType(regClass.fullName);
12117 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12120 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12121 ProcessStatement(prop.getStmt);
12129 string = CopyString("this");
12130 type = MkClassType(regClass.fullName);
12132 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12135 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12136 ProcessStatement(prop.issetStmt);
12142 globalContext.symbols.Remove(thisSymbol);
12143 FreeSymbol(thisSymbol);
12146 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12148 PropertyWatch propertyWatch = def.propertyWatch;
12150 thisClass = regClass;
12151 if(propertyWatch.compound)
12155 string = CopyString("this");
12156 type = regClass ? MkClassType(regClass.fullName) : null;
12159 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12161 curExternal = null;
12162 ProcessStatement(propertyWatch.compound);
12169 void DeclareFunctionUtil(String s)
12171 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12176 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12177 strcpy(name, "__ecereFunction_");
12178 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12179 DeclareFunction(function, name);
12183 void ComputeDataTypes()
12187 currentClass = null;
12189 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12191 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12193 // WHERE SHOULD THIS GO?
12194 // curExternal = ast->first;
12195 ast->Insert(null, temp);
12197 curExternal = temp;
12199 DeclareFunctionUtil("eSystem_New");
12200 DeclareFunctionUtil("eSystem_New0");
12201 DeclareFunctionUtil("eSystem_Renew");
12202 DeclareFunctionUtil("eSystem_Renew0");
12203 DeclareFunctionUtil("eClass_GetProperty");
12205 DeclareStruct("ecere::com::Class", false);
12206 DeclareStruct("ecere::com::Instance", false);
12207 DeclareStruct("ecere::com::Property", false);
12208 DeclareStruct("ecere::com::DataMember", false);
12209 DeclareStruct("ecere::com::Method", false);
12210 DeclareStruct("ecere::com::SerialBuffer", false);
12211 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12215 for(external = ast->first; external; external = external.next)
12217 afterExternal = curExternal = external;
12218 if(external.type == functionExternal)
12220 currentClass = external.function._class;
12221 ProcessFunction(external.function);
12223 // There shouldn't be any _class member access here anyways...
12224 else if(external.type == declarationExternal)
12226 currentClass = null;
12227 ProcessDeclaration(external.declaration);
12229 else if(external.type == classExternal)
12231 ClassDefinition _class = external._class;
12232 currentClass = external.symbol.registered;
12233 if(_class.definitions)
12235 ProcessClass(_class.definitions, _class.symbol);
12239 // Free class data...
12240 ast->Remove(external);
12244 else if(external.type == nameSpaceExternal)
12246 thisNameSpace = external.id.string;
12249 currentClass = null;
12250 thisNameSpace = null;
12252 delete temp.symbol;