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;
38 Time findSymbolTotalTime;
41 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
42 /*static */public void PrintExpression(Expression exp, char * string)
50 OutputExpression(exp, f);
52 count = strlen(string);
53 count += f.Read(string + count, 1, 1023);
59 int64 _strtoi64(char * string, char ** endString, int base)
65 for(c = 0; (ch = string[c]) && isspace(ch); c++);
67 else if(ch == '-') { sign = -1; c++; };
70 if(ch == 0 && string[c+1] == 'x')
83 for( ;(ch = string[c]); c++)
87 else if(ch >= '1' && ch <= '9')
89 else if(ch >= 'a' && ch <= 'z')
91 else if(ch >= 'A' && ch <= 'Z')
95 *endString = string + c;
106 *endString = string + c;
114 uint64 _strtoui64(char * string, char ** endString, int base)
120 for(c = 0; (ch = string[c]) && isspace(ch); c++);
122 else if(ch == '-') { sign = -1; c++; };
125 if(ch == 0 && string[c+1] == 'x')
138 for( ;(ch = string[c]); c++)
142 else if(ch >= '1' && ch <= '9')
144 else if(ch >= 'a' && ch <= 'z')
146 else if(ch >= 'A' && ch <= 'Z')
150 if(endString) *endString = string + c;
162 *endString = string + c;
170 Type ProcessTemplateParameterType(TemplateParameter param)
172 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
174 // TOFIX: Will need to free this Type
177 if(param.dataTypeString)
178 param.baseType = ProcessTypeString(param.dataTypeString, false);
180 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
182 return param.baseType;
187 bool NeedCast(Type type1, Type type2)
189 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
191 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
196 if(type1.kind == type2.kind)
204 if(type1.passAsTemplate && !type2.passAsTemplate)
206 return type1.isSigned != type2.isSigned;
208 return type1._class != type2._class;
210 return NeedCast(type1.type, type2.type);
212 return true; //false; ????
218 static void ReplaceClassMembers(Expression exp, Class _class)
220 if(exp.type == identifierExp && exp.identifier)
222 Identifier id = exp.identifier;
224 Symbol symbol = null;
225 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
227 // First, check if the identifier is declared inside the function
228 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
230 symbol = (Symbol)ctx.symbols.FindString(id.string);
235 // If it is not, check if it is a member of the _class
236 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
238 Property prop = eClass_FindProperty(_class, id.string, privateModule);
239 Method method = null;
240 DataMember member = null;
241 ClassProperty classProp;
244 method = eClass_FindMethod(_class, id.string, privateModule);
247 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
248 if(!prop && !method && !member)
250 classProp = eClass_FindClassProperty(_class, id.string);
252 if(prop || method || member || classProp)
254 // Replace by this.[member]
255 exp.type = memberExp;
256 exp.member.member = id;
257 exp.member.memberType = unresolvedMember;
258 exp.member.exp = QMkExpId("this");
259 //exp.member.exp.loc = exp.loc;
260 exp.addedThis = true;
262 else if(_class && _class.templateParams.first)
265 for(sClass = _class; sClass; sClass = sClass.base)
267 if(sClass.templateParams.first)
269 ClassTemplateParameter param;
270 for(param = sClass.templateParams.first; param; param = param.next)
272 if(param.type == expression && !strcmp(param.name, id.string))
274 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
279 OldList * specs = MkList();
281 FreeIdentifier(exp.member.member);
283 ProcessExpressionType(argExp);
285 decl = SpecDeclFromString(param.dataTypeString, specs, null);
287 exp.expType = ProcessType(specs, decl);
289 // *[expType] *[argExp]
290 exp.type = bracketsExp;
291 exp.list = MkListOne(MkExpOp(null, '*',
292 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
303 ////////////////////////////////////////////////////////////////////////
304 // PRINTING ////////////////////////////////////////////////////////////
305 ////////////////////////////////////////////////////////////////////////
307 public char * PrintInt(int64 result)
310 if(result > MAXINT64)
311 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
313 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
314 return CopyString(temp);
317 public char * PrintUInt(uint64 result)
320 if(result > MAXDWORD)
321 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
322 else if(result > MAXINT)
323 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
325 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
326 return CopyString(temp);
329 public char * PrintInt64(int64 result)
332 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
333 return CopyString(temp);
336 public char * PrintUInt64(uint64 result)
339 if(result > MAXINT64)
340 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
342 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
343 return CopyString(temp);
346 public char * PrintHexUInt(uint64 result)
349 if(result > MAXDWORD)
350 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
352 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
353 return CopyString(temp);
356 public char * PrintHexUInt64(uint64 result)
359 if(result > MAXDWORD)
360 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
362 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
363 return CopyString(temp);
366 public char * PrintShort(short result)
369 sprintf(temp, "%d", (unsigned short)result);
370 return CopyString(temp);
373 public char * PrintUShort(unsigned short result)
377 sprintf(temp, "0x%X", (int)result);
379 sprintf(temp, "%d", result);
380 return CopyString(temp);
383 public char * PrintChar(char result)
386 if(result > 0 && isprint(result))
387 sprintf(temp, "'%c'", result);
389 sprintf(temp, "%d", result);
391 //sprintf(temp, "%#X", result);
392 sprintf(temp, "0x%X", (unsigned char)result);
393 return CopyString(temp);
396 public char * PrintUChar(unsigned char result)
399 sprintf(temp, "0x%X", result);
400 return CopyString(temp);
403 public char * PrintFloat(float result)
406 sprintf(temp, "%.16ff", result);
407 return CopyString(temp);
410 public char * PrintDouble(double result)
413 sprintf(temp, "%.16f", result);
414 return CopyString(temp);
417 ////////////////////////////////////////////////////////////////////////
418 ////////////////////////////////////////////////////////////////////////
420 //public Operand GetOperand(Expression exp);
422 #define GETVALUE(name, t) \
423 public bool Get##name(Expression exp, t * value2) \
425 Operand op2 = GetOperand(exp); \
426 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
427 else if(op2.kind == intType) *value2 = (t) op2.ui; \
428 if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
429 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
430 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
431 else if(op2.kind == shortType) *value2 = (t) op2.us; \
432 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
433 else if(op2.kind == charType) *value2 = (t) op2.uc; \
434 else if(op2.kind == floatType) *value2 = (t) op2.f; \
435 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
436 else if(op2.kind == pointerType) *value2 = (t) op2.ui; \
443 GETVALUE(UInt, unsigned int);
444 GETVALUE(Int64, int64);
445 GETVALUE(UInt64, uint64);
446 GETVALUE(Short, short);
447 GETVALUE(UShort, unsigned short);
448 GETVALUE(Char, char);
449 GETVALUE(UChar, unsigned char);
450 GETVALUE(Float, float);
451 GETVALUE(Double, double);
453 void ComputeExpression(Expression exp);
455 void ComputeClassMembers(Class _class, bool isMember)
457 DataMember member = isMember ? (DataMember) _class : null;
458 Context context = isMember ? null : SetupTemplatesContext(_class);
459 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
460 (_class.type == bitClass || _class.structSize == _class.offset) && _class.computeSize))
463 int unionMemberOffset = 0;
466 if(!member && _class.destructionWatchOffset)
467 _class.memberOffset += sizeof(OldList);
469 // To avoid reentrancy...
470 //_class.structSize = -1;
473 DataMember dataMember;
474 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
476 if(!dataMember.isProperty)
478 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
480 /*if(dataMember.dataType)
482 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
483 /*if(!dataMember.dataType)
484 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
492 DataMember dataMember;
493 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
495 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
497 if(!isMember && _class.type == bitClass && dataMember.dataType)
499 BitMember bitMember = (BitMember) dataMember;
503 ComputeTypeSize(dataMember.dataType);
505 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
506 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
508 _class.memberOffset = bitMember.pos + bitMember.size;
509 for(d = 0; d<bitMember.size; d++)
515 bitMember.mask = mask << bitMember.pos;
517 else if(dataMember.type == normalMember && dataMember.dataType)
522 // Prevent infinite recursion
523 if(dataMember.dataType.kind != classType ||
524 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
525 _class.type != structClass)))
526 ComputeTypeSize(dataMember.dataType);
528 if(dataMember.dataType.bitFieldCount)
530 bitFields += dataMember.dataType.bitFieldCount;
537 int size = (bitFields + 7) / 8;
541 // TESTING THIS PADDING CODE
544 member.structAlignment = Max(member.structAlignment, alignment);
546 if(member.memberOffset % alignment)
547 member.memberOffset += alignment - (member.memberOffset % alignment);
550 dataMember.offset = member.memberOffset;
551 if(member.type == unionMember)
552 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
555 member.memberOffset += size;
560 // TESTING THIS PADDING CODE
563 _class.structAlignment = Max(_class.structAlignment, alignment);
565 if(_class.memberOffset % alignment)
566 _class.memberOffset += alignment - (_class.memberOffset % alignment);
569 dataMember.offset = _class.memberOffset;
570 _class.memberOffset += size;
574 size = dataMember.dataType.size;
575 alignment = dataMember.dataType.alignment;
586 // TESTING THIS PADDING CODE
589 member.structAlignment = Max(member.structAlignment, alignment);
591 if(member.memberOffset % alignment)
592 member.memberOffset += alignment - (member.memberOffset % alignment);
595 dataMember.offset = member.memberOffset;
596 if(member.type == unionMember)
597 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
600 member.memberOffset += size;
605 // TESTING THIS PADDING CODE
608 _class.structAlignment = Max(_class.structAlignment, alignment);
610 if(_class.memberOffset % alignment)
611 _class.memberOffset += alignment - (_class.memberOffset % alignment);
614 dataMember.offset = _class.memberOffset;
615 _class.memberOffset += size;
620 ComputeClassMembers((Class)dataMember, true);
624 // THERE WASN'T A MAX HERE ? member.structAlignment = dataMember.structAlignment;
625 member.structAlignment = Max(member.structAlignment, dataMember.structAlignment);
626 dataMember.offset = member.memberOffset;
627 if(member.type == unionMember)
628 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
630 member.memberOffset += dataMember.memberOffset;
634 _class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
635 dataMember.offset = _class.memberOffset;
636 _class.memberOffset += dataMember.memberOffset;
644 int size = (bitFields + 7) / 8;
648 // TESTING THIS PADDING CODE
651 member.structAlignment = Max(member.structAlignment, alignment);
653 if(member.memberOffset % alignment)
654 member.memberOffset += alignment - (member.memberOffset % alignment);
657 if(member.type == unionMember)
658 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
661 member.memberOffset += size;
666 // TESTING THIS PADDING CODE
669 _class.structAlignment = Max(_class.structAlignment, alignment);
671 if(_class.memberOffset % alignment)
672 _class.memberOffset += alignment - (_class.memberOffset % alignment);
674 _class.memberOffset += size;
679 if(member && member.type == unionMember)
681 member.memberOffset = unionMemberOffset;
686 /*if(_class.type == structClass)
687 _class.size = _class.memberOffset;
691 if(_class.type != bitClass)
693 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset;
697 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
699 if(prop.isProperty && prop.isWatchable)
701 prop.watcherOffset = _class.structSize;
702 _class.structSize += sizeof(OldList);
710 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
712 Class deriv = derivative.data;
714 if(deriv.computeSize)
716 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
717 deriv.offset = /*_class.offset + */_class.structSize;
718 deriv.memberOffset = 0;
719 // ----------------------
721 deriv.structSize = deriv.offset;
723 ComputeClassMembers(deriv, false);
731 FinishTemplatesContext(context);
734 public void ComputeModuleClasses(Module module)
739 for(subModule = module.modules.first; subModule; subModule = subModule.next)
740 ComputeModuleClasses(subModule.data);
741 for(_class = module.classes.first; _class; _class = _class.next)
742 ComputeClassMembers(_class, false);
746 public int ComputeTypeSize(Type type)
748 uint size = type ? type.size : 0;
749 if(!size && type && !type.computing)
751 type.computing = true;
754 case charType: type.alignment = size = sizeof(char); break;
755 case intType: type.alignment = size = sizeof(int); break;
756 case int64Type: type.alignment = size = sizeof(int64); break;
757 case longType: type.alignment = size = sizeof(long); break;
758 case shortType: type.alignment = size = sizeof(short); break;
759 case floatType: type.alignment = size = sizeof(float); break;
760 case doubleType: type.alignment = size = sizeof(double); break;
763 Class _class = type._class ? type._class.registered : null;
765 if(_class && _class.type == structClass)
767 // Ensure all members are properly registered
768 ComputeClassMembers(_class, false);
769 type.alignment = _class.structAlignment;
770 size = _class.structSize;
771 if(type.alignment && size % type.alignment)
772 size += type.alignment - (size % type.alignment);
775 else if(_class && (_class.type == unitClass ||
776 _class.type == enumClass ||
777 _class.type == bitClass))
780 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
781 size = type.alignment = ComputeTypeSize(_class.dataType);
784 size = type.alignment = sizeof(Instance *);
787 case pointerType: case subClassType: size = type.alignment = sizeof(void *); break;
789 if(type.arraySizeExp)
791 ProcessExpressionType(type.arraySizeExp);
792 ComputeExpression(type.arraySizeExp);
793 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
794 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
796 Location oldLoc = yylloc;
797 // bool isConstant = type.arraySizeExp.isConstant;
798 char expression[10240];
799 expression[0] = '\0';
800 type.arraySizeExp.expType = null;
801 yylloc = type.arraySizeExp.loc;
803 PrintExpression(type.arraySizeExp, expression);
804 Compiler_Error($"Array size not constant int (%s)\n", expression);
807 GetInt(type.arraySizeExp, &type.arraySize);
815 else if(type.enumClass)
817 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
819 type.arraySize = eClass_GetProperty(type.enumClass.registered, "enumSize");
826 // Unimplemented auto size
830 size = ComputeTypeSize(type.type) * type.arraySize;
831 type.alignment = type.type.alignment;
837 for(member = type.members.first; member; member = member.next)
839 uint addSize = ComputeTypeSize(member);
841 member.offset = size;
842 if(member.alignment && size % member.alignment)
843 member.offset += member.alignment - (size % member.alignment);
844 size = member.offset;
846 type.alignment = Max(type.alignment, member.alignment);
849 if(type.alignment && size % type.alignment)
850 size += type.alignment - (size % 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);
866 size = Max(size, addSize);
868 if(type.alignment && size % type.alignment)
869 size += type.alignment - (size % type.alignment);
874 TemplateParameter param = type.templateParameter;
875 Type baseType = ProcessTemplateParameterType(param);
877 size = ComputeTypeSize(baseType);
879 size = sizeof(uint64);
884 size = sizeof(enum { test });
889 size = sizeof(void *);
894 type.computing = false;
900 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass)
902 // This function is in need of a major review when implementing private members etc.
903 DataMember topMember = isMember ? (DataMember) _class : null;
908 Context context = isMember ? null : SetupTemplatesContext(_class);
910 if(!isMember && _class.base)
912 maxSize = _class.structSize;
913 //if(_class.base.type != systemClass) // Commented out with new Instance _class
915 // DANGER: Testing this noHeadClass here...
916 if(_class.type == structClass || _class.type == noHeadClass)
917 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass);
919 maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
923 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
925 if(!member.isProperty)
931 if(member.dataTypeString)
933 OldList * specs = MkList(), * decls = MkList();
936 decl = SpecDeclFromString(member.dataTypeString, specs,
937 MkDeclaratorIdentifier(MkIdentifier(member.name)));
938 ListAdd(decls, MkStructDeclarator(decl, null));
939 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
942 member.dataType = ProcessType(specs, decl);
944 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
947 Type type = ProcessType(specs, decl);
948 DeclareType(member.dataType, false, false);
952 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
953 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
954 DeclareStruct(member.dataType._class.string, false);
957 ComputeTypeSize(member.dataType);
958 size = member.dataType.size;
959 alignment = member.dataType.alignment;
963 if(totalSize % alignment)
964 totalSize += alignment - (totalSize % alignment);
973 OldList * specs = MkList(), * list = MkList();
976 AddMembers(list, (Class)member, true, &size, topClass);
978 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
979 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
980 alignment = member.structAlignment;
984 if(totalSize % alignment)
985 totalSize += alignment - (totalSize % alignment);
995 if(topMember && topMember.type == unionMember)
996 *retSize = Max(*retSize, totalSize);
998 *retSize += totalSize;
1000 else if(totalSize < maxSize && _class.type != systemClass)
1002 char sizeString[50];
1003 sprintf(sizeString, "%d", maxSize - totalSize);
1004 ListAdd(declarations,
1005 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1006 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1009 FinishTemplatesContext(context);
1010 return topMember ? topMember.memberID : _class.memberID;
1013 static int DeclareMembers(Class _class, bool isMember)
1015 DataMember topMember = isMember ? (DataMember) _class : null;
1018 Context context = isMember ? null : SetupTemplatesContext(_class);
1020 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1021 DeclareMembers(_class.base, false);
1023 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1025 if(!member.isProperty)
1032 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1033 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1034 DeclareStruct(member.dataType._class.string, false);
1036 if(!member.dataType && member.dataTypeString)
1037 member.dataType = ProcessTypeString(member.dataTypeString, false);
1039 DeclareType(member.dataType, false, false);
1045 DeclareMembers((Class)member, true);
1052 FinishTemplatesContext(context);
1054 return topMember ? topMember.memberID : _class.memberID;
1057 void DeclareStruct(char * name, bool skipNoHead)
1059 External external = null;
1060 Symbol classSym = FindClass(name);
1062 if(!inCompiler || !classSym) return null;
1064 // We don't need any declaration for bit classes...
1065 if(classSym.registered &&
1066 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1069 /*if(classSym.registered.templateClass)
1070 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1073 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1075 // Add typedef struct
1077 OldList * specifiers, * declarators;
1078 OldList * declarations = null;
1079 char structName[1024];
1080 external = (classSym.registered && classSym.registered.type == structClass) ?
1081 classSym.pointerExternal : classSym.structExternal;
1083 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1084 // Moved this one up because DeclareClass done later will need it
1086 classSym.declaring++;
1088 if(strchr(classSym.string, '<'))
1090 if(classSym.registered.templateClass)
1092 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1093 classSym.declaring--;
1099 DeclareMembers(classSym.registered, false);
1102 FullClassNameCat(structName, name, false);
1105 external = MkExternalDeclaration(null);*/
1109 classSym.declaredStructSym = true;
1111 declarations = MkList();
1113 AddMembers(declarations, classSym.registered, false, null, classSym.registered);
1115 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1116 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1118 if(!declarations->count)
1120 FreeList(declarations, null);
1121 declarations = null;
1124 if(skipNoHead || declarations)
1126 if(external && external.declaration)
1128 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1130 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1133 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1136 if(classSym.structExternal)
1137 ast->Move(classSym.structExternal, curExternal.prev);
1138 ast->Move(classSym.pointerExternal, curExternal.prev);
1140 classSym.id = curExternal.symbol.idCode;
1141 classSym.idCode = curExternal.symbol.idCode;
1142 // external = classSym.pointerExternal;
1143 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1149 external = MkExternalDeclaration(null);
1151 specifiers = MkList();
1152 declarators = MkList();
1153 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1156 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1157 ListAdd(declarators, MkInitDeclarator(d, null));
1159 external.declaration = decl = MkDeclaration(specifiers, declarators);
1160 if(decl.symbol && !decl.symbol.pointerExternal)
1161 decl.symbol.pointerExternal = external;
1163 // For simple classes, keep the declaration as the external to move around
1164 if(classSym.registered && classSym.registered.type == structClass)
1166 char className[1024];
1167 strcpy(className, "__ecereClass_");
1168 FullClassNameCat(className, classSym.string, true);
1169 MangleClassName(className);
1172 DeclareClass(classSym, className);
1174 external.symbol = classSym;
1175 classSym.pointerExternal = external;
1176 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1177 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1181 char className[1024];
1182 strcpy(className, "__ecereClass_");
1183 FullClassNameCat(className, classSym.string, true);
1184 MangleClassName(className);
1186 // TOFIX: TESTING THIS...
1187 classSym.structExternal = external;
1188 DeclareClass(classSym, className);
1189 external.symbol = classSym;
1193 ast->Insert(curExternal ? curExternal.prev : null, external);
1197 classSym.declaring--;
1199 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1201 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1202 // Moved this one up because DeclareClass done later will need it
1205 classSym.declaring++;
1209 if(classSym.registered)
1210 DeclareMembers(classSym.registered, false);
1213 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1216 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1219 if(classSym.structExternal)
1220 ast->Move(classSym.structExternal, curExternal.prev);
1221 ast->Move(classSym.pointerExternal, curExternal.prev);
1223 classSym.id = curExternal.symbol.idCode;
1224 classSym.idCode = curExternal.symbol.idCode;
1225 // external = classSym.pointerExternal;
1226 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1229 classSym.declaring--;
1234 void DeclareProperty(Property prop, char * setName, char * getName)
1236 Symbol symbol = prop.symbol;
1237 char propName[1024];
1239 strcpy(setName, "__ecereProp_");
1240 FullClassNameCat(setName, prop._class.fullName, false);
1241 strcat(setName, "_Set_");
1242 // strcat(setName, prop.name);
1243 FullClassNameCat(setName, prop.name, true);
1245 strcpy(getName, "__ecereProp_");
1246 FullClassNameCat(getName, prop._class.fullName, false);
1247 strcat(getName, "_Get_");
1248 FullClassNameCat(getName, prop.name, true);
1249 // strcat(getName, prop.name);
1251 strcpy(propName, "__ecereProp_");
1252 FullClassNameCat(propName, prop._class.fullName, false);
1253 strcat(propName, "_");
1254 FullClassNameCat(propName, prop.name, true);
1255 // strcat(propName, prop.name);
1257 // To support "char *" property
1258 MangleClassName(getName);
1259 MangleClassName(setName);
1260 MangleClassName(propName);
1262 if(prop._class.type == structClass)
1263 DeclareStruct(prop._class.fullName, false);
1265 if(!symbol || curExternal.symbol.idCode < symbol.id)
1267 bool imported = false;
1268 bool dllImport = false;
1269 if(!symbol || symbol._import)
1274 if(!prop._class.symbol)
1275 prop._class.symbol = FindClass(prop._class.fullName);
1276 classSym = prop._class.symbol;
1277 if(classSym && !classSym._import)
1279 ModuleImport module;
1281 if(prop._class.module)
1282 module = FindModule(prop._class.module);
1284 module = mainModule;
1286 classSym._import = ClassImport
1288 name = CopyString(prop._class.fullName);
1289 isRemote = prop._class.isRemote;
1291 module.classes.Add(classSym._import);
1293 symbol = prop.symbol = Symbol { };
1294 symbol._import = (ClassImport)PropertyImport
1296 name = CopyString(prop.name);
1297 isVirtual = false; //prop.isVirtual;
1298 hasSet = prop.Set ? true : false;
1299 hasGet = prop.Get ? true : false;
1302 classSym._import.properties.Add(symbol._import);
1305 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1311 Context context = SetupTemplatesContext(prop._class);
1312 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1313 FinishTemplatesContext(context);
1319 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1322 OldList * specifiers, * declarators;
1327 Declarator typeDecl;
1328 bool simple = false;
1330 specifiers = MkList();
1331 declarators = MkList();
1334 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1335 MkDeclaratorIdentifier(MkIdentifier("this"))));
1337 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1340 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1343 Context context = SetupTemplatesContext(prop._class);
1344 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1345 FinishTemplatesContext(context);
1348 // Make sure the simple _class's type is declared
1349 for(spec = specifiers->first; spec; spec = spec.next)
1351 if(spec.type == nameSpecifier /*SpecifierClass*/)
1353 if((!typeDecl || typeDecl.type == identifierDeclarator))
1355 Symbol classSym = spec.symbol; // FindClass(spec.name);
1356 symbol._class = classSym.registered;
1357 if(classSym.registered && classSym.registered.type == structClass)
1359 DeclareStruct(spec.name, false);
1367 d = PlugDeclarator(typeDecl, d);
1370 ListAdd(params, MkTypeName(specifiers,
1371 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1372 specifiers = MkList();
1375 d = MkDeclaratorFunction(d, params);
1379 specifiers->Insert(null, MkSpecifier(EXTERN));
1380 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1381 specifiers->Insert(null, MkSpecifier(STATIC));
1383 ListAdd(specifiers, MkSpecifier(VOID));
1385 ListAdd(declarators, MkInitDeclarator(d, null));
1387 decl = MkDeclaration(specifiers, declarators);
1389 external = MkExternalDeclaration(decl);
1390 ast->Insert(curExternal.prev, external);
1391 external.symbol = symbol;
1392 symbol.externalGet = external;
1394 ReplaceThisClassSpecifiers(specifiers, prop._class);
1397 FreeDeclarator(typeDecl);
1401 // Move declaration higher...
1402 ast->Move(symbol.externalGet, curExternal.prev);
1409 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1412 OldList * specifiers, * declarators;
1417 Declarator typeDecl;
1419 declarators = MkList();
1422 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1423 if(!prop.conversion || prop._class.type == structClass)
1425 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1426 MkDeclaratorIdentifier(MkIdentifier("this"))));
1429 specifiers = MkList();
1432 Context context = SetupTemplatesContext(prop._class);
1433 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1434 MkDeclaratorIdentifier(MkIdentifier("value")));
1435 FinishTemplatesContext(context);
1437 ListAdd(params, MkTypeName(specifiers, d));
1439 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1442 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1443 d = MkDeclaratorFunction(d, params);
1445 // Make sure the simple _class's type is declared
1446 for(spec = specifiers->first; spec; spec = spec.next)
1448 if(spec.type == nameSpecifier /*SpecifierClass*/)
1450 if((!typeDecl || typeDecl.type == identifierDeclarator))
1452 Symbol classSym = spec.symbol; // FindClass(spec.name);
1453 symbol._class = classSym.registered;
1454 if(classSym.registered && classSym.registered.type == structClass)
1455 DeclareStruct(spec.name, false);
1460 ListAdd(declarators, MkInitDeclarator(d, null));
1462 specifiers = MkList();
1465 specifiers->Insert(null, MkSpecifier(EXTERN));
1466 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1467 specifiers->Insert(null, MkSpecifier(STATIC));
1469 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1470 if(!prop.conversion || prop._class.type == structClass)
1471 ListAdd(specifiers, MkSpecifier(VOID));
1473 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1475 decl = MkDeclaration(specifiers, declarators);
1477 external = MkExternalDeclaration(decl);
1478 ast->Insert(curExternal.prev, external);
1479 external.symbol = symbol;
1480 symbol.externalSet = external;
1482 ReplaceThisClassSpecifiers(specifiers, prop._class);
1486 // Move declaration higher...
1487 ast->Move(symbol.externalSet, curExternal.prev);
1491 // Property (for Watchers)
1492 if(!symbol.externalPtr)
1496 OldList * specifiers = MkList();
1499 specifiers->Insert(null, MkSpecifier(EXTERN));
1501 specifiers->Insert(null, MkSpecifier(STATIC));
1503 ListAdd(specifiers, MkSpecifierName("Property"));
1506 OldList * list = MkList();
1507 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1508 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1512 strcpy(propName, "__ecerePropM_");
1513 FullClassNameCat(propName, prop._class.fullName, false);
1514 strcat(propName, "_");
1515 // strcat(propName, prop.name);
1516 FullClassNameCat(propName, prop.name, true);
1518 MangleClassName(propName);
1520 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1521 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1523 decl = MkDeclaration(specifiers, list);
1526 external = MkExternalDeclaration(decl);
1527 ast->Insert(curExternal.prev, external);
1528 external.symbol = symbol;
1529 symbol.externalPtr = external;
1533 // Move declaration higher...
1534 ast->Move(symbol.externalPtr, curExternal.prev);
1537 symbol.id = curExternal.symbol.idCode;
1541 // ***************** EXPRESSION PROCESSING ***************************
1542 public Type Dereference(Type source)
1547 if(source.kind == pointerType || source.kind == arrayType)
1550 source.type.refCount++;
1552 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1560 // Support dereferencing of no head classes for now...
1561 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1567 Compiler_Error($"cannot dereference type\n");
1572 static Type Reference(Type source)
1588 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1590 Identifier ident = member.identifiers ? member.identifiers->first : null;
1592 DataMember dataMember = null;
1593 Method method = null;
1594 bool freeType = false;
1596 yylloc = member.loc;
1602 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1606 dataMember = *curMember;
1612 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1613 DataMember _subMemberStack[256];
1614 int _subMemberStackPos = 0;
1616 // FILL MEMBER STACK
1618 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1621 dataMember = thisMember;
1622 if(curMember && thisMember.memberAccess == publicAccess)
1624 *curMember = thisMember;
1625 *curClass = thisMember._class;
1626 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
1627 *subMemberStackPos = _subMemberStackPos;
1634 method = eClass_FindMethod(_class, ident.string, privateModule);
1635 if(method && method.type == virtualMethod)
1647 if(!dataMember.dataType && dataMember.dataTypeString)
1649 //Context context = SetupTemplatesContext(dataMember._class);
1650 Context context = SetupTemplatesContext(_class);
1651 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1652 FinishTemplatesContext(context);
1654 type = dataMember.dataType;
1658 // This is for destination type...
1659 if(!method.dataType)
1660 ProcessMethodType(method);
1661 //DeclareMethod(method);
1662 // method.dataType = ((Symbol)method.symbol)->type;
1663 type = method.dataType;
1666 if(ident && ident.next)
1668 for(ident = ident.next; ident && type; ident = ident.next)
1670 if(type.kind == classType)
1672 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1674 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1676 type = dataMember.dataType;
1678 else if(type.kind == structType || type.kind == unionType)
1681 for(memberType = type.members.first; memberType; memberType = memberType.next)
1683 if(!strcmp(memberType.name, ident.string))
1693 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1694 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1697 ClassTemplateParameter curParam;
1699 for(sClass = _class; sClass; sClass = sClass.base)
1702 if(sClass.templateClass) sClass = sClass.templateClass;
1703 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1705 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1707 for(sClass = sClass.base; sClass; sClass = sClass.base)
1709 if(sClass.templateClass) sClass = sClass.templateClass;
1710 id += sClass.templateParams.count;
1721 ClassTemplateArgument arg = _class.templateArgs[id];
1722 if(arg.dataTypeString)
1725 type = ProcessTypeString(arg.dataTypeString, false);
1727 if(type && _class.templateClass)
1728 type.passAsTemplate = true;
1734 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1735 exp.destType.refCount++;
1741 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1743 Class expClass = type._class.registered;
1744 Class cClass = null;
1749 char templateString[1024];
1750 ClassTemplateParameter param;
1751 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1752 for(cClass = expClass; cClass; cClass = cClass.base)
1755 if(cClass.templateClass) cClass = cClass.templateClass;
1756 for(param = cClass.templateParams.first; param; param = param.next)
1760 ClassTemplateArgument arg;
1761 for(sClass = cClass.base; sClass; sClass = sClass.base)
1763 if(sClass.templateClass) sClass = sClass.templateClass;
1764 id += sClass.templateParams.count;
1766 arg = expClass.templateArgs[id];
1768 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1770 ClassTemplateParameter cParam;
1771 //int p = numParams - sClass.templateParams.count;
1774 if(sClass.templateClass) sClass = sClass.templateClass;
1776 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1778 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1779 p += nextClass.templateParams.count;
1782 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1784 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1786 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1788 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1789 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1801 strcat(argument, arg.name.string);
1802 strcat(argument, " = ");
1808 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1809 char expString[1024];
1810 OldList * specs = MkList();
1811 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1813 char * string = PrintHexUInt64(arg.expression.ui64);
1814 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1816 ProcessExpressionType(exp);
1817 ComputeExpression(exp);
1818 expString[0] = '\0';
1819 PrintExpression(exp, expString);
1820 strcat(argument, expString);
1822 FreeExpression(exp);
1827 strcat(argument, arg.member.name);
1830 case TemplateParameterType::type:
1832 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1833 strcat(argument, arg.dataTypeString);
1839 if(paramCount) strcat(templateString, ", ");
1840 if(lastParam != p - 1)
1842 strcat(templateString, param.name);
1843 strcat(templateString, " = ");
1845 strcat(templateString, argument);
1854 int len = strlen(templateString);
1855 if(templateString[len-1] == '<')
1859 if(templateString[len-1] == '>')
1860 templateString[len++] = ' ';
1861 templateString[len++] = '>';
1863 templateString[len++] = '\0';
1866 Context context = SetupTemplatesContext(_class);
1867 if(freeType) FreeType(type);
1868 type = ProcessTypeString(templateString, false);
1870 FinishTemplatesContext(context);
1874 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1876 ProcessExpressionType(member.initializer.exp);
1877 if(!member.initializer.exp.expType)
1881 char expString[10240];
1882 expString[0] = '\0';
1883 PrintExpression(member.initializer.exp, expString);
1884 ChangeCh(expString, '\n', ' ');
1885 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1888 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1889 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1891 Compiler_Error($"incompatible instance method %s\n", ident.string);
1894 else if(member.initializer)
1897 FreeType(member.exp.destType);
1898 member.exp.destType = type;
1899 if(member.exp.destType)
1900 member.exp.destType.refCount++;
1901 ProcessExpressionType(member.exp);
1904 ProcessInitializer(member.initializer, type);
1906 if(freeType) FreeType(type);
1910 if(_class && _class.type == unitClass)
1912 if(member.initializer)
1915 FreeType(member.exp.destType);
1916 member.exp.destType = MkClassType(_class.fullName);
1917 ProcessExpressionType(member.initializer, type);
1919 Type type = MkClassType(_class.fullName);
1920 ProcessInitializer(member.initializer, type);
1926 if(member.initializer)
1928 //ProcessExpressionType(member.exp);
1929 ProcessInitializer(member.initializer, null);
1935 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1939 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1941 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1945 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1950 void ProcessInstantiationType(Instantiation inst)
1955 MembersInit members;
1956 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1959 /*if(!inst._class.symbol)
1960 inst._class.symbol = FindClass(inst._class.name);*/
1961 classSym = inst._class.symbol;
1962 _class = classSym ? classSym.registered : null;
1964 // DANGER: Patch for mutex not declaring its struct when not needed
1965 if(!_class || _class.type != noHeadClass)
1966 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1968 afterExternal = afterExternal ? afterExternal : curExternal;
1971 ProcessExpressionType(inst.exp);
1973 inst.isConstant = true;
1976 DataMember curMember = null;
1977 Class curClass = null;
1978 DataMember subMemberStack[256];
1979 int subMemberStackPos = 0;
1981 for(members = inst.members->first; members; members = members.next)
1983 switch(members.type)
1985 case methodMembersInit:
1988 static uint instMethodID = 0;
1989 External external = curExternal;
1990 Context context = curContext;
1991 Declarator declarator = members.function.declarator;
1992 Identifier nameID = GetDeclId(declarator);
1993 char * unmangled = nameID ? nameID.string : null;
1995 External createdExternal = null;
2000 //members.function.dontMangle = true;
2001 strcpy(name, "__ecereInstMeth_");
2002 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2004 strcat(name, nameID.string);
2006 sprintf(number, "_%08d", instMethodID++);
2007 strcat(name, number);
2008 nameID.string = CopyString(name);
2011 // Do modifications here...
2014 Symbol symbol = declarator.symbol;
2015 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2017 if(method && method.type == virtualMethod)
2019 symbol.method = method;
2020 ProcessMethodType(method);
2022 if(!symbol.type.thisClass)
2024 if(method.dataType.thisClass && currentClass &&
2025 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2027 if(!currentClass.symbol)
2028 currentClass.symbol = FindClass(currentClass.fullName);
2029 symbol.type.thisClass = currentClass.symbol;
2034 _class.symbol = FindClass(_class.fullName);
2035 symbol.type.thisClass = _class.symbol;
2038 // TESTING THIS HERE:
2039 DeclareType(symbol.type, true, true);
2044 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2045 unmangled, classSym.string);
2049 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2050 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2054 FreeSpecifier(nameID._class);
2055 nameID._class = null;
2061 Type type = declarator.symbol.type;
2062 External oldExternal = curExternal;
2064 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2065 // *** It was commented out for problems such as
2067 class VirtualDesktop : Window
2069 clientSize = Size { };
2080 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2082 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2085 if(strcmp(declarator.symbol.string, name))
2087 printf("TOCHECK: Look out for this\n");
2088 delete declarator.symbol.string;
2089 declarator.symbol.string = CopyString(name);
2092 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2094 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2095 excludedSymbols->Remove(declarator.symbol);
2096 globalContext.symbols.Add((BTNode)declarator.symbol);
2097 if(strstr(declarator.symbol.string), "::")
2098 globalContext.hasNameSpace = true;
2103 //curExternal = curExternal.prev;
2104 //afterExternal = afterExternal->next;
2106 //ProcessFunction(afterExternal->function);
2108 //curExternal = afterExternal;
2110 External externalDecl;
2111 externalDecl = MkExternalDeclaration(null);
2112 ast->Insert(oldExternal.prev, externalDecl);
2114 // Which function does this process?
2115 if(createdExternal.function)
2117 ProcessFunction(createdExternal.function);
2119 //curExternal = oldExternal;
2122 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2124 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2125 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2127 //externalDecl = MkExternalDeclaration(decl);
2129 //***** ast->Insert(external.prev, externalDecl);
2130 //ast->Insert(curExternal.prev, externalDecl);
2131 externalDecl.declaration = decl;
2132 if(decl.symbol && !decl.symbol.pointerExternal)
2133 decl.symbol.pointerExternal = externalDecl;
2135 // Trying this out...
2136 declarator.symbol.pointerExternal = externalDecl;
2143 curExternal = declarator.symbol.pointerExternal;
2144 ProcessFunction((FunctionDefinition)members.function);
2146 curExternal = external;
2147 curContext = context;
2151 FreeClassFunction(members.function);
2153 // In this pass, turn this into a MemberInitData
2154 exp = QMkExpId(name);
2155 members.type = dataMembersInit;
2156 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2162 case dataMembersInit:
2164 if(members.dataMembers && classSym)
2167 Location oldyyloc = yylloc;
2168 for(member = members.dataMembers->first; member; member = member.next)
2170 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2171 if(member.initializer && !member.initializer.isConstant)
2172 inst.isConstant = false;
2184 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2186 // OPTIMIZATIONS: TESTING THIS...
2189 if(type.kind == functionType)
2194 for(param = type.params.first; param; param = param.next)
2195 DeclareType(param, declarePointers, true);
2197 DeclareType(type.returnType, declarePointers, true);
2199 else if(type.kind == pointerType && declarePointers)
2200 DeclareType(type.type, declarePointers, false);
2201 else if(type.kind == classType)
2203 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2204 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2206 else if(type.kind == structType || type.kind == unionType)
2209 for(member = type.members.first; member; member = member.next)
2210 DeclareType(member, false, false);
2212 else if(type.kind == arrayType)
2213 DeclareType(type.arrayType, declarePointers, false);
2217 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2219 ClassTemplateArgument * arg = null;
2221 ClassTemplateParameter curParam;
2223 for(sClass = _class; sClass; sClass = sClass.base)
2226 if(sClass.templateClass) sClass = sClass.templateClass;
2227 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2229 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2231 for(sClass = sClass.base; sClass; sClass = sClass.base)
2233 if(sClass.templateClass) sClass = sClass.templateClass;
2234 id += sClass.templateParams.count;
2244 arg = &_class.templateArgs[id];
2245 if(arg && param.type == type)
2246 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2251 public Context SetupTemplatesContext(Class _class)
2253 Context context = PushContext();
2254 context.templateTypesOnly = true;
2255 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2257 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2258 for(; param; param = param.next)
2260 if(param.type == type && param.identifier)
2262 TemplatedType type { key = (uint)param.identifier.string, param = param };
2263 curContext.templateTypes.Add((BTNode)type);
2270 for(sClass = _class; sClass; sClass = sClass.base)
2272 ClassTemplateParameter p;
2273 for(p = sClass.templateParams.first; p; p = p.next)
2275 //OldList * specs = MkList();
2276 //Declarator decl = null;
2277 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2280 TemplateParameter param = p.param;
2284 // ADD DATA TYPE HERE...
2285 p.param = param = TemplateParameter
2287 identifier = MkIdentifier(p.name), type = p.type,
2288 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2291 type = TemplatedType { key = (uint)p.name, param = param };
2292 curContext.templateTypes.Add((BTNode)type);
2300 public void FinishTemplatesContext(Context context)
2302 PopContext(context);
2303 FreeContext(context);
2307 public void ProcessMethodType(Method method)
2309 if(!method.dataType)
2311 Context context = SetupTemplatesContext(method._class);
2313 method.dataType = ProcessTypeString(method.dataTypeString, false);
2315 FinishTemplatesContext(context);
2317 if(method.type != virtualMethod && method.dataType)
2319 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2321 if(!method._class.symbol)
2322 method._class.symbol = FindClass(method._class.fullName);
2323 method.dataType.thisClass = method._class.symbol;
2327 // Why was this commented out? Working fine without now...
2330 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2331 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2338 char * par = strstr(type, "(");
2339 char * classOp = null;
2344 for(c = par-type-1; c >= 0; c++)
2346 if(type[c] == ':' && type[c+1] == ':')
2348 classOp = type + c - 1;
2349 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2356 else if(!isspace(type[c]))
2363 int typeLen = strlen(type);
2364 memcpy(temp, classOp, classOpLen);
2365 temp[classOpLen] = '\0';
2367 _class = eSystem_FindClass(module, temp);
2370 method.dataTypeString = new char[typeLen - classOpLen + 1];
2371 memcpy(method.dataTypeString, type, classOp - type);
2372 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2375 method.dataTypeString = type;
2381 public void ProcessPropertyType(Property prop)
2385 Context context = SetupTemplatesContext(prop._class);
2386 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2387 FinishTemplatesContext(context);
2391 public void DeclareMethod(Method method, char * name)
2393 Symbol symbol = method.symbol;
2394 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2396 bool imported = false;
2397 bool dllImport = false;
2399 if(!method.dataType)
2400 method.dataType = ProcessTypeString(method.dataTypeString, false);
2402 if(!symbol || symbol._import || method.type == virtualMethod)
2404 if(!symbol || method.type == virtualMethod)
2407 if(!method._class.symbol)
2408 method._class.symbol = FindClass(method._class.fullName);
2409 classSym = method._class.symbol;
2410 if(!classSym._import)
2412 ModuleImport module;
2414 if(method._class.module && method._class.module.name)
2415 module = FindModule(method._class.module);
2417 module = mainModule;
2418 classSym._import = ClassImport
2420 name = CopyString(method._class.fullName);
2421 isRemote = method._class.isRemote;
2423 module.classes.Add(classSym._import);
2427 symbol = method.symbol = Symbol { };
2431 symbol._import = (ClassImport)MethodImport
2433 name = CopyString(method.name);
2434 isVirtual = method.type == virtualMethod;
2436 classSym._import.methods.Add(symbol._import);
2440 // Set the symbol type
2444 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2446 else if(type.thisClass == (void *)-1)
2448 type.thisClass = null;
2451 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2452 symbol.type = method.dataType;
2453 if(symbol.type) symbol.type.refCount++;
2456 if(!method.thisClass || strcmp(method.thisClass, "void"))
2457 symbol.type.params.Insert(null,
2458 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2461 if(!method.dataType.dllExport)
2464 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2470 if(!method.dataType)
2471 method.dataType = ((Symbol)method.symbol).type;
2472 //ProcessMethodType(method);
2475 if(method.type != virtualMethod && method.dataType)
2476 DeclareType(method.dataType, true, true);
2478 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2480 // We need a declaration here :)
2482 OldList * specifiers, * declarators;
2484 Declarator funcDecl;
2487 specifiers = MkList();
2488 declarators = MkList();
2492 ListAdd(specifiers, MkSpecifier(EXTERN));
2493 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2494 ListAdd(specifiers, MkSpecifier(STATIC));
2496 if(method.type == virtualMethod)
2498 ListAdd(specifiers, MkSpecifier(INT));
2499 d = MkDeclaratorIdentifier(MkIdentifier(name));
2503 d = MkDeclaratorIdentifier(MkIdentifier(name));
2506 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2508 Context context = SetupTemplatesContext(method._class);
2509 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2510 FinishTemplatesContext(context);
2512 funcDecl = GetFuncDecl(d);
2516 Specifier spec, next;
2517 for(spec = specifiers->first; spec; spec = next)
2520 if(spec.type == extendedSpecifier)
2522 specifiers->Remove(spec);
2523 FreeSpecifier(spec);
2528 // Add this parameter if not a static method
2529 if(method.dataType && !method.dataType.staticMethod)
2531 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2533 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2534 TypeName thisParam = MkTypeName(MkListOne(
2535 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2536 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2537 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2538 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2540 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2542 TypeName param = funcDecl.function.parameters->first;
2543 funcDecl.function.parameters->Remove(param);
2544 FreeTypeName(param);
2547 if(!funcDecl.function.parameters)
2548 funcDecl.function.parameters = MkList();
2549 funcDecl.function.parameters->Insert(null, thisParam);
2552 // Make sure we don't have empty parameter declarations for static methods...
2554 else if(!funcDecl.function.parameters)
2556 funcDecl.function.parameters = MkList();
2557 funcDecl.function.parameters->Insert(null,
2558 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2562 ProcessDeclarator(d);
2564 ListAdd(declarators, MkInitDeclarator(d, null));
2566 decl = MkDeclaration(specifiers, declarators);
2568 ReplaceThisClassSpecifiers(specifiers, method._class);
2570 // Keep a different symbol for the function definition than the declaration...
2571 if(symbol.pointerExternal)
2573 Symbol functionSymbol { };
2577 *functionSymbol = *symbol;
2578 functionSymbol.string = CopyString(symbol.string);
2579 if(functionSymbol.type)
2580 functionSymbol.type.refCount++;
2583 excludedSymbols->Add(functionSymbol);
2584 symbol.pointerExternal.symbol = functionSymbol;
2586 external = MkExternalDeclaration(decl);
2588 ast->Insert(curExternal ? curExternal.prev : null, external);
2589 external.symbol = symbol;
2590 symbol.pointerExternal = external;
2594 // Move declaration higher...
2595 ast->Move(symbol.pointerExternal, curExternal.prev);
2598 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2602 char * ReplaceThisClass(Class _class)
2604 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2608 ClassTemplateParameter param;
2611 char className[1024];
2612 strcpy(className, _class.fullName);
2613 for(param = _class.templateParams.first; param; param = param.next)
2615 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2617 if(first) strcat(className, "<");
2618 if(!first) strcat(className, ", ");
2619 if(lastParam + 1 != p)
2621 strcat(className, param.name);
2622 strcat(className, " = ");
2624 strcat(className, param.name);
2632 int len = strlen(className);
2633 if(className[len-1] == '>') className[len++] = ' ';
2634 className[len++] = '>';
2635 className[len++] = '\0';
2637 return CopyString(className);
2640 return CopyString(_class.fullName);
2643 Type ReplaceThisClassType(Class _class)
2645 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2649 ClassTemplateParameter param;
2651 char className[1024];
2652 strcpy(className, _class.fullName);
2654 for(param = _class.templateParams.first; param; param = param.next)
2656 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2658 if(first) strcat(className, "<");
2659 if(!first) strcat(className, ", ");
2660 if(lastParam + 1 != p)
2662 strcat(className, param.name);
2663 strcat(className, " = ");
2665 strcat(className, param.name);
2673 int len = strlen(className);
2674 if(className[len-1] == '>') className[len++] = ' ';
2675 className[len++] = '>';
2676 className[len++] = '\0';
2678 return MkClassType(className);
2679 //return ProcessTypeString(className, false);
2683 return MkClassType(_class.fullName);
2684 //return ProcessTypeString(_class.fullName, false);
2688 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2690 if(specs != null && _class)
2693 for(spec = specs.first; spec; spec = spec.next)
2695 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2697 spec.type = nameSpecifier;
2698 spec.name = ReplaceThisClass(_class);
2699 spec.symbol = FindClass(spec.name); //_class.symbol;
2705 // Returns imported or not
2706 bool DeclareFunction(GlobalFunction function, char * name)
2708 Symbol symbol = function.symbol;
2709 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2711 bool imported = false;
2712 bool dllImport = false;
2714 if(!function.dataType)
2716 function.dataType = ProcessTypeString(function.dataTypeString, false);
2717 if(!function.dataType.thisClass)
2718 function.dataType.staticMethod = true;
2725 ModuleImport module = FindModule(function.module);
2726 // WARNING: This is not added anywhere...
2727 symbol = function.symbol = Symbol { };
2731 if(!function.dataType.dllExport)
2733 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2734 module.functions.Add(symbol._import);
2737 // Set the symbol type
2739 symbol.type = ProcessTypeString(function.dataTypeString, false);
2740 if(!symbol.type.thisClass)
2741 symbol.type.staticMethod = true;
2744 imported = symbol._import ? true : false;
2745 if(imported && function.module != privateModule && function.module.importType != staticImport)
2749 DeclareType(function.dataType, true, true);
2753 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2755 // We need a declaration here :)
2757 OldList * specifiers, * declarators;
2759 Declarator funcDecl;
2762 specifiers = MkList();
2763 declarators = MkList();
2766 ListAdd(specifiers, MkSpecifier(EXTERN));
2769 ListAdd(specifiers, MkSpecifier(STATIC));
2772 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2775 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2777 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2778 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2779 if(function.module.importType == staticImport)
2782 for(spec = specifiers->first; spec; spec = spec.next)
2783 if(spec.type == extendedSpecifier && !strcmp(spec.name, "dllexport"))
2785 specifiers->Remove(spec);
2786 FreeSpecifier(spec);
2791 funcDecl = GetFuncDecl(d);
2793 // Make sure we don't have empty parameter declarations for static methods...
2794 if(funcDecl && !funcDecl.function.parameters)
2796 funcDecl.function.parameters = MkList();
2797 funcDecl.function.parameters->Insert(null,
2798 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2801 ListAdd(declarators, MkInitDeclarator(d, null));
2804 Context oldCtx = curContext;
2805 curContext = globalContext;
2806 decl = MkDeclaration(specifiers, declarators);
2807 curContext = oldCtx;
2810 // Keep a different symbol for the function definition than the declaration...
2811 if(symbol.pointerExternal)
2813 Symbol functionSymbol { };
2816 *functionSymbol = *symbol;
2817 functionSymbol.string = CopyString(symbol.string);
2818 if(functionSymbol.type)
2819 functionSymbol.type.refCount++;
2822 excludedSymbols->Add(functionSymbol);
2824 symbol.pointerExternal.symbol = functionSymbol;
2826 external = MkExternalDeclaration(decl);
2828 ast->Insert(curExternal.prev, external);
2829 external.symbol = symbol;
2830 symbol.pointerExternal = external;
2834 // Move declaration higher...
2835 ast->Move(symbol.pointerExternal, curExternal.prev);
2839 symbol.id = curExternal.symbol.idCode;
2842 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2845 void DeclareGlobalData(GlobalData data)
2847 Symbol symbol = data.symbol;
2848 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2853 symbol = data.symbol = Symbol { };
2856 data.dataType = ProcessTypeString(data.dataTypeString, false);
2857 DeclareType(data.dataType, true, true);
2860 if(!symbol.pointerExternal)
2862 // We need a declaration here :)
2864 OldList * specifiers, * declarators;
2868 specifiers = MkList();
2869 declarators = MkList();
2871 ListAdd(specifiers, MkSpecifier(EXTERN));
2872 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2873 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2875 ListAdd(declarators, MkInitDeclarator(d, null));
2877 decl = MkDeclaration(specifiers, declarators);
2878 external = MkExternalDeclaration(decl);
2880 ast->Insert(curExternal.prev, external);
2881 external.symbol = symbol;
2882 symbol.pointerExternal = external;
2886 // Move declaration higher...
2887 ast->Move(symbol.pointerExternal, curExternal.prev);
2891 symbol.id = curExternal.symbol.idCode;
2896 class Conversion : struct
2898 Conversion prev, next;
2904 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2908 // Property convert;
2910 if(source.kind == templateType && dest.kind != templateType)
2912 Type type = ProcessTemplateParameterType(source.templateParameter);
2913 if(type) source = type;
2916 if(dest.kind == templateType && source.kind != templateType)
2918 Type type = ProcessTemplateParameterType(dest.templateParameter);
2919 if(type) dest = type;
2922 if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
2927 if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
2932 if((dest.kind == structType && source.kind == structType) ||
2933 (dest.kind == unionType && source.kind == unionType))
2935 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2936 (source.members.first && source.members.first == dest.members.first))
2940 if(dest.kind == ellipsisType && source.kind != voidType)
2943 if(dest.kind == pointerType && dest.type.kind == voidType &&
2944 ((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))
2945 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2947 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2949 /*&& (source.kind != classType /*|| source._class.registered.type != structClass)*/)
2951 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2952 ((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))
2953 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2955 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2957 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2960 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2962 if(source._class.registered && source._class.registered.type == unitClass)
2964 if(conversions != null)
2966 if(source._class.registered == dest._class.registered)
2971 Class sourceBase, destBase;
2972 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2973 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2974 if(sourceBase == destBase)
2978 // Don't match enum inheriting from other enum if resolving enumeration values
2979 // TESTING: !dest.classObjectType
2980 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2982 (!source._class.registered || source._class.registered.type != enumClass) ||
2983 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2987 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2989 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2990 source._class && source._class.registered && source._class.registered.type != enumClass)
2992 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3000 // JUST ADDED THIS...
3001 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3006 // Just added this for Straight conversion of ColorAlpha => Color
3007 if(source.kind == classType)
3010 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3013 for(convert = _class.conversions.first; convert; convert = convert.next)
3015 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3017 Conversion after = (conversions != null) ? conversions.last : null;
3019 if(!convert.dataType)
3020 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3021 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
3023 if(!conversions && !convert.Get)
3025 else if(conversions != null)
3027 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3028 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3029 (dest.kind != classType || dest._class.registered != _class.base))
3033 Conversion conv { convert = convert, isGet = true };
3034 // conversions.Add(conv);
3035 conversions.Insert(after, conv);
3047 if(dest.kind == classType)
3050 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3053 for(convert = _class.conversions.first; convert; convert = convert.next)
3055 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3057 // Conversion after = (conversions != null) ? conversions.last : null;
3059 if(!convert.dataType)
3060 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3061 // Just added this equality check to prevent recursion.... Make it safer?
3062 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3063 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3065 if(!conversions && !convert.Set)
3067 else if(conversions != null)
3069 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3070 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3071 (source.kind != classType || source._class.registered != _class.base))
3075 // *** Testing this! ***
3076 Conversion conv { convert = convert };
3077 conversions.Add(conv);
3078 //conversions.Insert(after, conv);
3086 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3088 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3089 (source.kind != classType || source._class.registered.type != structClass))
3093 // TESTING THIS... IS THIS OK??
3094 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3096 if(!dest._class.registered.dataType)
3097 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3098 // Only support this for classes...
3099 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3100 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3102 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3111 if(source.kind == classType)
3114 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3117 for(convert = _class.conversions.first; convert; convert = convert.next)
3119 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3121 Conversion after = (conversions != null) ? conversions.last : null;
3123 if(!convert.dataType)
3124 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3125 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3127 if(!conversions && !convert.Get)
3129 else if(conversions != null)
3131 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3132 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3133 (dest.kind != classType || dest._class.registered != _class.base))
3137 Conversion conv { convert = convert, isGet = true };
3139 // conversions.Add(conv);
3140 conversions.Insert(after, conv);
3149 // TESTING THIS... IS THIS OK??
3150 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3152 if(!source._class.registered.dataType)
3153 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3154 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3162 if(source.kind == classType || source.kind == subClassType)
3164 else if(dest.kind == source.kind &&
3165 (dest.kind != structType && dest.kind != unionType &&
3166 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3168 // RECENTLY ADDED THESE
3169 else if(dest.kind == doubleType && source.kind == floatType)
3171 else if(dest.kind == shortType && source.kind == charType)
3173 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType))
3175 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType))
3177 else if(source.kind == enumType &&
3178 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type))
3180 else if(dest.kind == enumType &&
3181 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || dest.kind == int64Type))
3183 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3184 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3186 Type paramSource, paramDest;
3188 if(dest.kind == methodType)
3189 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3190 if(source.kind == methodType)
3191 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3193 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3194 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3195 if(dest.kind == methodType)
3196 dest = dest.method.dataType;
3197 if(source.kind == methodType)
3198 source = source.method.dataType;
3200 paramSource = source.params.first;
3201 if(paramSource && paramSource.kind == voidType) paramSource = null;
3202 paramDest = dest.params.first;
3203 if(paramDest && paramDest.kind == voidType) paramDest = null;
3206 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3207 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3209 // Source thisClass must be derived from destination thisClass
3210 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3211 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3213 if(paramDest && paramDest.kind == classType)
3214 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3216 Compiler_Error($"method class should not take an object\n");
3219 paramDest = paramDest.next;
3221 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3223 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3227 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3229 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3235 // THIS WAS BACKWARDS:
3236 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3237 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3240 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3242 Compiler_Error($"overriding class expected to be derived from method class\n");
3246 paramSource = paramSource.next;
3252 // Source thisClass must be derived from destination thisClass
3253 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3255 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3261 // THIS WAS BACKWARDS TOO??
3262 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3263 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3266 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3268 //Compiler_Error($"overriding class expected to be derived from method class\n");
3276 // Source return type must be derived from destination return type
3277 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3279 Compiler_Warning($"incompatible return type for function\n");
3285 for(; paramDest; paramDest = paramDest.next)
3289 //Compiler_Warning($"not enough parameters\n");
3290 Compiler_Error($"not enough parameters\n");
3294 Type paramDestType = paramDest;
3295 Type paramSourceType = paramSource;
3296 Type type = paramDestType;
3298 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3299 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3300 paramSource.kind != templateType)
3303 ClassTemplateParameter curParam;
3305 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3308 if(sClass.templateClass) sClass = sClass.templateClass;
3309 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3311 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3313 for(sClass = sClass.base; sClass; sClass = sClass.base)
3315 if(sClass.templateClass) sClass = sClass.templateClass;
3316 id += sClass.templateParams.count;
3327 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3328 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3332 // paramDest must be derived from paramSource
3333 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3334 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3338 PrintType(paramDest, type, false, true);
3339 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3341 if(paramDestType != paramDest)
3342 FreeType(paramDestType);
3345 if(paramDestType != paramDest)
3346 FreeType(paramDestType);
3349 paramSource = paramSource.next;
3353 Compiler_Error($"too many parameters\n");
3358 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3362 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3363 (source.kind == arrayType || source.kind == pointerType))
3365 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3372 static void FreeConvert(Conversion convert)
3374 if(convert.resultType)
3375 FreeType(convert.resultType);
3378 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3379 char * string, OldList conversions)
3383 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3385 Class _class = link.data;
3386 if(_class.type == enumClass)
3388 OldList converts { };
3390 type.kind = classType;
3393 _class.symbol = FindClass(_class.fullName);
3394 type._class = _class.symbol;
3396 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3399 Class enumClass = eSystem_FindClass(privateModule, "enum");
3403 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3405 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3406 for(value = e.values.first; value; value = value.next)
3408 if(!strcmp(value.name, string))
3413 FreeExpContents(sourceExp);
3414 FreeType(sourceExp.expType);
3416 sourceExp.isConstant = true;
3417 sourceExp.expType = MkClassType(baseClass.fullName);
3421 sourceExp.type = constantExp;
3422 if(!strcmp(baseClass.dataTypeString, "int"))
3423 sprintf(constant, "%d",value.data);
3425 sprintf(constant, "0x%X",value.data);
3426 sourceExp.constant = CopyString(constant);
3427 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3430 while(converts.first)
3432 Conversion convert = converts.first;
3433 converts.Remove(convert);
3434 conversions.Add(convert);
3443 converts.Free(FreeConvert);
3447 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3448 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3453 public bool ModuleVisibility(Module searchIn, Module searchFor)
3455 SubModule subModule;
3457 if(searchFor == searchIn)
3460 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3462 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3464 if(ModuleVisibility(subModule.module, searchFor))
3471 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3475 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3477 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3479 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3482 for(module = mainModule.application.allModules.first; module; module = module.next)
3484 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3490 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3492 Type source = sourceExp.expType;
3493 Type realDest = dest;
3495 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3498 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3500 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3502 Class sourceBase, destBase;
3503 for(sourceBase = source._class.registered;
3504 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3505 sourceBase = sourceBase.base);
3506 for(destBase = dest._class.registered;
3507 destBase && destBase.base && destBase.base.type != systemClass;
3508 destBase = destBase.base);
3509 //if(source._class.registered == dest._class.registered)
3510 if(sourceBase == destBase)
3519 int64 value = MAXINT;
3524 if(sourceExp.type == constantExp)
3527 value = strtoll(sourceExp.constant, null, 0);
3529 value = strtoull(sourceExp.constant, null, 0);
3531 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3534 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3536 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3539 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3540 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3543 source = Type { kind = intType, isSigned = false, refCount = 1 };
3546 if(dest.kind == classType)
3548 Class _class = dest._class ? dest._class.registered : null;
3550 if(_class && _class.type == unitClass)
3552 if(source.kind != classType)
3555 Type tempDest, tempSource;
3557 for(; _class.base.type != systemClass; _class = _class.base);
3559 tempDest = tempType;
3561 tempType.kind = classType;
3563 _class.symbol = FindClass(_class.fullName);
3565 tempType._class = _class.symbol;
3566 tempType.truth = dest.truth;
3568 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3570 FreeType(sourceExp.expType);
3571 sourceExp.expType = dest; dest.refCount++;
3573 //sourceExp.expType = MkClassType(_class.fullName);
3581 // Why wasn't there something like this?
3582 if(_class && _class.type == bitClass && source.kind != classType)
3584 if(!dest._class.registered.dataType)
3585 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3586 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3589 FreeType(sourceExp.expType);
3590 source = sourceExp.expType = MkClassType(dest._class.string);
3593 //source.kind = classType;
3594 //source._class = dest._class;
3598 // Adding two enumerations
3600 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3602 if(!source._class.registered.dataType)
3603 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3604 if(!dest._class.registered.dataType)
3605 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3607 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3610 source = sourceExp.expType = MkClassType(dest._class.string);
3613 //source.kind = classType;
3614 //source._class = dest._class;
3618 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3620 OldList * specs = MkList();
3624 ReadString(string, sourceExp.string);
3625 decl = SpecDeclFromString(string, specs, null);
3627 FreeExpContents(sourceExp);
3628 FreeType(sourceExp.expType);
3630 sourceExp.type = classExp;
3631 sourceExp._classExp.specifiers = specs;
3632 sourceExp._classExp.decl = decl;
3633 sourceExp.expType = dest;
3641 else if(source.kind == classType)
3643 Class _class = source._class ? source._class.registered : null;
3645 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3648 if(dest.kind != classType)
3650 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3651 if(!source._class.registered.dataType)
3652 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3655 dest = MkClassType(source._class.string);
3656 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3657 // dest = MkClassType(source._class.string);
3661 if(dest.kind != classType)
3664 Type tempDest, tempSource;
3666 if(!source._class.registered.dataType)
3667 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3669 for(; _class.base.type != systemClass; _class = _class.base);
3671 tempSource = tempType;
3672 tempType.kind = classType;
3673 tempType._class = FindClass(_class.fullName);
3674 tempType.truth = source.truth;
3675 tempType.classObjectType = source.classObjectType;
3678 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3680 // PUT THIS BACK TESTING UNITS?
3681 if(conversions.last)
3683 ((Conversion)(conversions.last)).resultType = dest;
3687 FreeType(sourceExp.expType);
3688 sourceExp.expType = MkClassType(_class.fullName);
3689 sourceExp.expType.truth = source.truth;
3690 sourceExp.expType.classObjectType = source.classObjectType;
3692 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3694 if(!sourceExp.destType)
3696 FreeType(sourceExp.destType);
3697 sourceExp.destType = sourceExp.expType;
3698 if(sourceExp.expType)
3699 sourceExp.expType.refCount++;
3702 //source = _class.dataType;
3705 // TOCHECK: TESTING THIS NEW CODE
3706 if(!_class.dataType)
3707 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3709 dest = MkClassType(source._class.string);
3710 dest.truth = source.truth;
3711 dest.classObjectType = source.classObjectType;
3714 source = _class.dataType;
3724 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3734 if(source.kind == classType)
3736 Class _class = source._class.registered;
3737 if(_class.type == unitClass)
3739 if(!_class.dataType)
3740 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3741 source = _class.dataType;
3745 if(dest.kind == classType)
3747 Class _class = dest._class ? dest._class.registered : null;
3748 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3749 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3751 if(_class.type == normalClass || _class.type == noHeadClass)
3753 Expression newExp { };
3754 *newExp = *sourceExp;
3755 if(sourceExp.destType) sourceExp.destType.refCount++;
3756 if(sourceExp.expType) sourceExp.expType.refCount++;
3757 sourceExp.type = castExp;
3758 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3759 sourceExp.cast.exp = newExp;
3760 FreeType(sourceExp.expType);
3761 sourceExp.expType = null;
3762 ProcessExpressionType(sourceExp);
3764 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3767 FreeType(sourceExp.expType);
3768 sourceExp.expType = dest;
3772 if(inCompiler) FreeType(dest);
3777 if(!_class.dataType)
3778 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3780 dest = _class.dataType;
3784 // Accept lower precision types for units, since we want to keep the unit type
3785 if(dest.kind == doubleType &&
3786 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3787 source.kind == charType))
3789 specs = MkListOne(MkSpecifier(DOUBLE));
3791 else if(dest.kind == floatType &&
3792 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3793 source.kind == doubleType))
3795 specs = MkListOne(MkSpecifier(FLOAT));
3797 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3798 source.kind == floatType || source.kind == doubleType))
3801 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3802 ListAdd(specs, MkSpecifier(INT64));
3804 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3805 source.kind == floatType || source.kind == doubleType))
3808 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3809 ListAdd(specs, MkSpecifier(INT));
3811 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3812 source.kind == floatType || source.kind == doubleType))
3815 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3816 ListAdd(specs, MkSpecifier(SHORT));
3818 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3819 source.kind == floatType || source.kind == doubleType))
3822 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3823 ListAdd(specs, MkSpecifier(CHAR));
3832 else if(dest.kind == doubleType &&
3833 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3834 source.kind == charType))
3836 specs = MkListOne(MkSpecifier(DOUBLE));
3838 else if(dest.kind == floatType &&
3839 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3841 specs = MkListOne(MkSpecifier(FLOAT));
3843 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3844 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3847 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3848 ListAdd(specs, MkSpecifier(CHAR));
3850 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3851 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3854 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3855 ListAdd(specs, MkSpecifier(SHORT));
3857 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3860 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3861 ListAdd(specs, MkSpecifier(INT));
3863 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3866 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3867 ListAdd(specs, MkSpecifier(INT64));
3869 else if(dest.kind == enumType &&
3870 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3872 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3883 Expression newExp { };
3884 *newExp = *sourceExp;
3887 if(sourceExp.destType) sourceExp.destType.refCount++;
3888 if(sourceExp.expType) sourceExp.expType.refCount++;
3890 sourceExp.type = castExp;
3891 if(realDest.kind == classType)
3893 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3894 FreeList(specs, FreeSpecifier);
3897 sourceExp.cast.typeName = MkTypeName(specs, null);
3898 if(newExp.type == opExp)
3900 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3903 sourceExp.cast.exp = newExp;
3905 FreeType(sourceExp.expType);
3906 sourceExp.expType = null;
3907 ProcessExpressionType(sourceExp);
3910 FreeList(specs, FreeSpecifier);
3918 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3919 if(sourceExp.type == identifierExp)
3921 Identifier id = sourceExp.identifier;
3922 if(dest.kind == classType)
3924 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3926 Class _class = dest._class.registered;
3927 Class enumClass = eSystem_FindClass(privateModule, "enum");
3930 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3933 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3934 for(value = e.values.first; value; value = value.next)
3936 if(!strcmp(value.name, id.string))
3941 FreeExpContents(sourceExp);
3942 FreeType(sourceExp.expType);
3944 sourceExp.isConstant = true;
3945 sourceExp.expType = MkClassType(_class.fullName);
3949 sourceExp.type = constantExp;
3950 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3951 sprintf(constant, "%d",value.data);
3953 sprintf(constant, "0x%X",value.data);
3954 sourceExp.constant = CopyString(constant);
3955 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3964 // Loop through all enum classes
3965 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3972 #define TERTIARY(o, name, m, t, p) \
3973 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3975 exp.type = constantExp; \
3976 exp.string = p(op1.m ? op2.m : op3.m); \
3978 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3982 #define BINARY(o, name, m, t, p) \
3983 static bool name(Expression exp, Operand op1, Operand op2) \
3986 exp.type = constantExp; \
3987 exp.string = p(op1.m o value2); \
3989 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3993 #define BINARY_DIVIDE(o, name, m, t, p) \
3994 static bool name(Expression exp, Operand op1, Operand op2) \
3997 exp.type = constantExp; \
3998 exp.string = p(value2 ? (op1.m o value2) : 0); \
4000 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4004 #define UNARY(o, name, m, t, p) \
4005 static bool name(Expression exp, Operand op1) \
4007 exp.type = constantExp; \
4008 exp.string = p(o op1.m); \
4010 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4014 #define OPERATOR_ALL(macro, o, name) \
4015 macro(o, Int##name, i, int, PrintInt) \
4016 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4017 macro(o, Short##name, s, short, PrintShort) \
4018 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4019 macro(o, Char##name, c, char, PrintChar) \
4020 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4021 macro(o, Float##name, f, float, PrintFloat) \
4022 macro(o, Double##name, d, double, PrintDouble)
4024 #define OPERATOR_INTTYPES(macro, o, name) \
4025 macro(o, Int##name, i, int, PrintInt) \
4026 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4027 macro(o, Short##name, s, short, PrintShort) \
4028 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4029 macro(o, Char##name, c, char, PrintChar) \
4030 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4033 // binary arithmetic
4034 OPERATOR_ALL(BINARY, +, Add)
4035 OPERATOR_ALL(BINARY, -, Sub)
4036 OPERATOR_ALL(BINARY, *, Mul)
4037 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4038 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4041 OPERATOR_ALL(UNARY, -, Neg)
4043 // unary arithmetic increment and decrement
4044 OPERATOR_ALL(UNARY, ++, Inc)
4045 OPERATOR_ALL(UNARY, --, Dec)
4047 // binary arithmetic assignment
4048 OPERATOR_ALL(BINARY, =, Asign)
4049 OPERATOR_ALL(BINARY, +=, AddAsign)
4050 OPERATOR_ALL(BINARY, -=, SubAsign)
4051 OPERATOR_ALL(BINARY, *=, MulAsign)
4052 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4053 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4056 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4057 OPERATOR_INTTYPES(BINARY, |, BitOr)
4058 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4059 OPERATOR_INTTYPES(BINARY, <<, LShift)
4060 OPERATOR_INTTYPES(BINARY, >>, RShift)
4063 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4065 // binary bitwise assignment
4066 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4067 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4068 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4069 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4070 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4072 // unary logical negation
4073 OPERATOR_INTTYPES(UNARY, !, Not)
4075 // binary logical equality
4076 OPERATOR_ALL(BINARY, ==, Equ)
4077 OPERATOR_ALL(BINARY, !=, Nqu)
4080 OPERATOR_ALL(BINARY, &&, And)
4081 OPERATOR_ALL(BINARY, ||, Or)
4083 // binary logical relational
4084 OPERATOR_ALL(BINARY, >, Grt)
4085 OPERATOR_ALL(BINARY, <, Sma)
4086 OPERATOR_ALL(BINARY, >=, GrtEqu)
4087 OPERATOR_ALL(BINARY, <=, SmaEqu)
4089 // tertiary condition operator
4090 OPERATOR_ALL(TERTIARY, ?, Cond)
4092 //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
4093 #define OPERATOR_TABLE_ALL(name, type) \
4094 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4096 type##Inc, type##Dec, \
4097 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4098 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4100 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4102 type##Equ, type##Nqu, \
4103 type##And, type##Or, \
4104 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4107 #define OPERATOR_TABLE_INTTYPES(name, type) \
4108 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4110 type##Inc, type##Dec, \
4111 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4112 null, null, null, null, null, \
4114 null, null, null, null, null, \
4116 type##Equ, type##Nqu, \
4117 type##And, type##Or, \
4118 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4121 OPERATOR_TABLE_ALL(int, Int)
4122 OPERATOR_TABLE_ALL(uint, UInt)
4123 OPERATOR_TABLE_ALL(short, Short)
4124 OPERATOR_TABLE_ALL(ushort, UShort)
4125 OPERATOR_TABLE_INTTYPES(float, Float)
4126 OPERATOR_TABLE_INTTYPES(double, Double)
4127 OPERATOR_TABLE_ALL(char, Char)
4128 OPERATOR_TABLE_ALL(uchar, UChar)
4130 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4131 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4132 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4133 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4134 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4135 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4136 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4137 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4139 public void ReadString(char * output, char * string)
4141 int len = strlen(string);
4143 bool quoted = false, escaped = false;
4144 for(c = 0; c<len; c++)
4146 char ch = string[c];
4151 case 'n': output[d] = '\n'; break;
4152 case 't': output[d] = '\t'; break;
4153 case 'a': output[d] = '\a'; break;
4154 case 'b': output[d] = '\b'; break;
4155 case 'f': output[d] = '\f'; break;
4156 case 'r': output[d] = '\r'; break;
4157 case 'v': output[d] = '\v'; break;
4158 case '\\': output[d] = '\\'; break;
4159 case '\"': output[d] = '\"'; break;
4160 default: output[d++] = '\\'; output[d] = ch;
4161 //default: output[d] = ch;
4182 public Operand GetOperand(Expression exp)
4185 Type type = exp.expType;
4188 while(type.kind == classType &&
4189 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4191 if(!type._class.registered.dataType)
4192 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4193 type = type._class.registered.dataType;
4196 op.kind = type.kind;
4197 op.type = exp.expType;
4198 if(exp.isConstant && exp.type == constantExp)
4204 if(exp.constant[0] == '\'')
4205 op.c = exp.constant[1];
4206 else if(type.isSigned)
4208 op.c = (char)strtol(exp.constant, null, 0);
4213 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4221 op.s = (short)strtol(exp.constant, null, 0);
4226 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4234 op.i = (int)strtol(exp.constant, null, 0);
4239 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4247 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4252 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4258 op.f = (float)strtod(exp.constant, null);
4262 op.d = (double)strtod(exp.constant, null);
4265 //case classType: For when we have operator overloading...
4266 // Pointer additions
4267 //case functionType:
4271 op.p = (unsigned char *)strtoul(exp.constant, null, 0);
4272 op.kind = pointerType;
4282 static void UnusedFunction()
4285 a.OnGetString(0,0,0);
4288 extern int __ecereVMethodID_class_OnGetString;
4291 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4293 DataMember dataMember;
4294 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4296 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4297 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4301 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4303 void * ptr = inst.data + dataMember.offset + offset;
4304 char * result = null;
4305 exp.loc = member.loc = inst.loc;
4306 ((Identifier)member.identifiers->first).loc = inst.loc;
4308 if(!dataMember.dataType)
4309 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4310 type = dataMember.dataType;
4311 if(type.kind == classType)
4313 Class _class = type._class.registered;
4314 if(_class.type == enumClass)
4316 Class enumClass = eSystem_FindClass(privateModule, "enum");
4319 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4321 for(item = e.values.first; item; item = item.next)
4323 if((int)item.data == *(int *)ptr)
4331 exp.identifier = MkIdentifier(result);
4332 exp.type = identifierExp;
4333 exp.destType = MkClassType(_class.fullName);
4334 ProcessExpressionType(exp);
4338 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4340 if(!_class.dataType)
4341 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4342 type = _class.dataType;
4351 FreeExpContents(exp);
4353 exp.constant = PrintFloat(*(float*)ptr);
4354 exp.type = constantExp;
4359 FreeExpContents(exp);
4361 exp.constant = PrintDouble(*(double*)ptr);
4362 exp.type = constantExp;
4367 FreeExpContents(exp);
4369 exp.constant = PrintInt(*(int*)ptr);
4370 exp.type = constantExp;
4375 FreeExpContents(exp);
4377 exp.constant = PrintInt64(*(int64*)ptr);
4378 exp.type = constantExp;
4382 Compiler_Error($"Unhandled type populating instance\n");
4385 ListAdd(memberList, member);
4388 if(parentDataMember.type == unionMember)
4393 void PopulateInstance(Instantiation inst)
4395 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4396 Class _class = classSym.registered;
4397 DataMember dataMember;
4398 OldList * memberList = MkList();
4399 inst.members = MkListOne(MkMembersInitList(memberList));
4400 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4402 if(!dataMember.isProperty)
4404 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4405 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4409 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4411 void * ptr = inst.data + dataMember.offset;
4412 char * result = null;
4414 exp.loc = member.loc = inst.loc;
4415 ((Identifier)member.identifiers->first).loc = inst.loc;
4417 if(!dataMember.dataType)
4418 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4419 type = dataMember.dataType;
4420 if(type.kind == classType)
4422 Class _class = type._class.registered;
4423 if(_class.type == enumClass)
4425 Class enumClass = eSystem_FindClass(privateModule, "enum");
4428 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4430 for(item = e.values.first; item; item = item.next)
4432 if((int)item.data == *(int *)ptr)
4441 exp.identifier = MkIdentifier(result);
4442 exp.type = identifierExp;
4443 exp.destType = MkClassType(_class.fullName);
4444 ProcessExpressionType(exp);
4447 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4449 if(!_class.dataType)
4450 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4451 type = _class.dataType;
4460 exp.constant = PrintFloat(*(float*)ptr);
4461 exp.type = constantExp;
4466 exp.constant = PrintDouble(*(double*)ptr);
4467 exp.type = constantExp;
4472 exp.constant = PrintInt(*(int*)ptr);
4473 exp.type = constantExp;
4478 exp.constant = PrintInt64(*(int64*)ptr);
4479 exp.type = constantExp;
4483 Compiler_Error($"Unhandled type populating instance\n");
4486 ListAdd(memberList, member);
4492 void ComputeInstantiation(Expression exp)
4494 Instantiation inst = exp.instance;
4495 MembersInit members;
4496 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4497 Class _class = classSym ? classSym.registered : null;
4498 DataMember curMember = null;
4499 Class curClass = null;
4500 DataMember subMemberStack[256];
4501 int subMemberStackPos = 0;
4504 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4506 // Don't recompute the instantiation...
4507 // Non Simple classes will have become constants by now
4511 if(_class.type == normalClass || _class.type == noHeadClass)
4512 inst.data = (byte *)eInstance_New(_class);
4514 inst.data = new0 byte[_class.structSize];
4519 for(members = inst.members->first; members; members = members.next)
4521 switch(members.type)
4523 case dataMembersInit:
4525 if(members.dataMembers)
4528 for(member = members.dataMembers->first; member; member = member.next)
4530 Identifier ident = member.identifiers ? member.identifiers->first : null;
4533 Property prop = null;
4534 DataMember dataMember = null;
4535 Method method = null;
4536 uint dataMemberOffset;
4540 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4543 if(curMember.isProperty)
4544 prop = (Property)curMember;
4547 dataMember = curMember;
4549 // CHANGED THIS HERE
4550 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4551 // dataMemberOffset = dataMember.offset;
4558 prop = eClass_FindProperty(_class, ident.string, privateModule);
4562 if(prop.memberAccess == publicAccess)
4564 curMember = (DataMember)prop;
4565 curClass = prop._class;
4570 DataMember _subMemberStack[256];
4571 int _subMemberStackPos = 0;
4573 // FILL MEMBER STACK
4574 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4579 if(dataMember.memberAccess == publicAccess)
4581 curMember = dataMember;
4582 curClass = dataMember._class;
4583 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4584 subMemberStackPos = _subMemberStackPos;
4590 if(found && member.initializer && member.initializer.type == expInitializer)
4592 Expression value = member.initializer.exp;
4596 type = prop.dataType;
4600 if(!dataMember.dataType)
4601 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4603 type = dataMember.dataType;
4606 if(ident && ident.next)
4608 // for(; ident && type; ident = ident.next)
4609 for(ident = ident.next; ident && type; ident = ident.next)
4611 if(type.kind == classType)
4613 prop = eClass_FindProperty(type._class.registered,
4614 ident.string, privateModule);
4616 type = prop.dataType;
4619 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4620 ident.string, &dataMemberOffset, privateModule, null, null);
4622 type = dataMember.dataType;
4625 else if(type.kind == structType || type.kind == unionType)
4628 for(memberType = type.members.first; memberType; memberType = memberType.next)
4630 if(!strcmp(memberType.name, ident.string))
4641 FreeType(value.destType);
4642 value.destType = type;
4643 if(type) type.refCount++;
4644 ComputeExpression(value);
4646 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4648 if(type.kind == classType)
4650 Class _class = type._class.registered;
4651 if(_class.type == bitClass || _class.type == unitClass ||
4652 _class.type == enumClass)
4654 if(!_class.dataType)
4655 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4656 type = _class.dataType;
4662 void * ptr = inst.data + dataMemberOffset;
4664 if(value.type == constantExp)
4670 GetInt(value, (int*)ptr);
4675 GetInt64(value, (int64*)ptr);
4680 GetFloat(value, (float*)ptr);
4685 GetDouble(value, (double *)ptr);
4690 else if(value.type == instanceExp)
4692 if(type.kind == classType)
4694 Class _class = type._class.registered;
4695 if(_class.type == structClass)
4697 ComputeTypeSize(type);
4698 if(value.instance.data)
4699 memcpy(ptr, value.instance.data, type.size);
4706 if(value.type == instanceExp && value.instance.data)
4708 void (*Set)(void *, void *) = (void *)prop.Set;
4709 Set(inst.data, value.instance.data);
4710 PopulateInstance(inst);
4712 else if(value.type == constantExp)
4718 void (*Set)(void *, double) = (void *)prop.Set;
4719 Set(inst.data, strtod(value.constant, null) );
4724 void (*Set)(void *, float) = (void *)prop.Set;
4725 Set(inst.data, (float)(strtod(value.constant, null)));
4730 void (*Set)(void *, int) = (void *)prop.Set;
4731 Set(inst.data, strtol(value.constant, null, 0));
4736 void (*Set)(void *, int64) = (void *)prop.Set;
4737 Set(inst.data, _strtoi64(value.constant, null, 0));
4742 else if(value.type == stringExp)
4745 ReadString(temp, value.string);
4746 prop.Set(inst.data, temp);
4750 else if(_class.type == unitClass)
4754 // Only support converting units to units for now...
4755 if(value.type == constantExp)
4757 if(type.kind == classType)
4759 Class _class = type._class.registered;
4760 if(_class.type == unitClass)
4762 if(!_class.dataType)
4763 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4764 type = _class.dataType;
4767 // TODO: Assuming same base type for units...
4773 float (*Set)(float) = (void *)prop.Set;
4774 GetFloat(member.initializer.exp, &fValue);
4775 exp.constant = PrintFloat(Set(fValue));
4776 exp.type = constantExp;
4782 double (*Set)(double) = (void *)prop.Set;
4783 GetDouble(member.initializer.exp, &dValue);
4784 exp.constant = PrintDouble(Set(dValue));
4785 exp.type = constantExp;
4792 else if(_class.type == bitClass)
4796 if(value.type == instanceExp && value.instance.data)
4798 unsigned int (*Set)(void *) = (void *)prop.Set;
4799 bits = Set(value.instance.data);
4801 else if(value.type == constantExp)
4807 BitMember bitMember = (BitMember) dataMember;
4810 GetInt(value, &part);
4811 bits = (bits & ~bitMember.mask);
4812 if(!bitMember.dataType)
4813 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4815 type = bitMember.dataType;
4817 if(type.kind == classType && type._class && type._class.registered)
4819 if(!type._class.registered.dataType)
4820 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4821 type = type._class.registered.dataType;
4828 bits |= ((char)part << bitMember.pos);
4830 bits |= ((unsigned char)part << bitMember.pos);
4834 bits |= ((short)part << bitMember.pos);
4836 bits |= ((unsigned short)part << bitMember.pos);
4841 bits |= ((int)part << bitMember.pos);
4843 bits |= ((unsigned int)part << bitMember.pos);
4847 bits |= ((int64)part << bitMember.pos);
4849 bits |= ((uint64)part << bitMember.pos);
4857 if(_class && _class.type == unitClass)
4859 ComputeExpression(member.initializer.exp);
4860 exp.constant = member.initializer.exp.constant;
4861 exp.type = constantExp;
4863 member.initializer.exp.constant = null;
4873 if(_class && _class.type == bitClass)
4875 exp.constant = PrintHexUInt(bits);
4876 exp.type = constantExp;
4878 if(exp.type != instanceExp)
4884 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4886 if(exp.op.op == SIZEOF)
4888 FreeExpContents(exp);
4889 exp.type = constantExp;
4890 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4901 // Provide default unary +
4902 Expression exp2 = exp.op.exp2;
4904 FreeExpContents(exp);
4905 FreeType(exp.expType);
4906 FreeType(exp.destType);
4912 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4914 // unary arithmetic increment and decrement
4915 //OPERATOR_ALL(UNARY, ++, Inc)
4916 //OPERATOR_ALL(UNARY, --, Dec)
4919 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4921 // unary logical negation
4923 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4931 // binary arithmetic
4933 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4936 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
4939 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
4942 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
4945 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
4947 // binary arithmetic assignment
4948 //OPERATOR_ALL(BINARY, =, Asign)
4949 //OPERATOR_ALL(BINARY, +=, AddAsign)
4950 //OPERATOR_ALL(BINARY, -=, SubAsign)
4951 //OPERATOR_ALL(BINARY, *=, MulAsign)
4952 //OPERATOR_ALL(BINARY, /=, DivAsign)
4953 //OPERATOR_ALL(BINARY, %=, ModAsign)
4958 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
4962 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
4965 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
4968 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
4971 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
4973 // binary bitwise assignment
4974 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4975 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4976 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4977 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4978 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4979 // binary logical equality
4981 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
4984 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
4988 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
4991 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
4993 // binary logical relational
4995 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
4998 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5001 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5004 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5011 void ComputeExpression(Expression exp)
5013 char expString[10240];
5014 expString[0] = '\0';
5016 PrintExpression(exp, expString);
5023 ComputeInstantiation(exp);
5032 Expression exp1, exp2 = null;
5036 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5038 ComputeExpression(exp.op.exp2);
5041 ComputeExpression(exp.op.exp1);
5044 op1 = GetOperand(exp1);
5045 if(op1.type) op1.type.refCount++;
5048 op2 = GetOperand(exp2);
5049 if(op2.type) op2.type.refCount++;
5055 op1 = GetOperand(exp1);
5056 if(op1.type) op1.type.refCount++;
5059 CallOperator(exp, exp1, exp2, op1, op2);
5066 if(exp.op.exp1 && exp.op.exp2)
5071 FreeExpContents(exp);
5072 op1.ops.BitAnd(exp, op1, op2);
5081 FreeExpContents(exp);
5082 op1.ops.Mul(exp, op1, op2);
5091 FreeExpContents(exp);
5092 op1.ops.Add(exp, op1, op2);
5097 // Provide default unary +
5098 Expression exp2 = exp.op.exp2;
5100 FreeExpContents(exp);
5101 FreeType(exp.expType);
5102 FreeType(exp.destType);
5113 FreeExpContents(exp);
5114 op1.ops.Sub(exp, op1, op2);
5121 FreeExpContents(exp);
5122 op1.ops.Neg(exp, op1);
5129 FreeExpContents(exp);
5130 op1.ops.BitNot(exp, op1);
5136 FreeExpContents(exp);
5137 op1.ops.Not(exp, op1);
5140 // Binary only operators
5144 FreeExpContents(exp);
5145 op1.ops.Div(exp, op1, op2);
5151 FreeExpContents(exp);
5152 op1.ops.Mod(exp, op1, op2);
5164 FreeExpContents(exp);
5165 op1.ops.Sma(exp, op1, op2);
5174 FreeExpContents(exp);
5175 op1.ops.Grt(exp, op1, op2);
5184 FreeExpContents(exp);
5185 op1.ops.SmaEqu(exp, op1, op2);
5194 FreeExpContents(exp);
5195 op1.ops.GrtEqu(exp, op1, op2);
5204 FreeExpContents(exp);
5205 op1.ops.Equ(exp, op1, op2);
5214 FreeExpContents(exp);
5215 op1.ops.Nqu(exp, op1, op2);
5222 FreeExpContents(exp);
5223 op1.ops.BitOr(exp, op1, op2);
5229 FreeExpContents(exp);
5230 op1.ops.BitXor(exp, op1, op2);
5238 FreeExpContents(exp);
5239 exp.type = constantExp;
5240 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5244 if(op1.type) FreeType(op1.type);
5245 if(op2.type) FreeType(op2.type);
5249 case extensionExpressionExp:
5252 for(e = exp.list->first; e; e = n)
5257 OldList * list = exp.list;
5258 ComputeExpression(e);
5259 //FreeExpContents(exp);
5260 FreeType(exp.expType);
5261 FreeType(exp.destType);
5278 exp.isConstant = true;
5280 ComputeExpression(exp.index.exp);
5281 if(!exp.index.exp.isConstant)
5282 exp.isConstant = false;
5284 for(e = exp.index.index->first; e; e = e.next)
5286 ComputeExpression(e);
5289 // Check if this type is int
5292 exp.isConstant = false;
5294 exp.expType = Dereference(exp.index.exp.expType);
5300 Expression memberExp = exp.member.exp;
5301 Identifier memberID = exp.member.member;
5304 ComputeExpression(exp.member.exp);
5305 type = exp.member.exp.expType;
5308 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);
5309 Property prop = null;
5310 DataMember member = null;
5311 Class convertTo = null;
5312 if(type.kind == subClassType && exp.member.exp.type == classExp)
5313 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5320 PrintType(type, string, false, true);
5321 classSym = FindClass(string);
5322 _class = classSym ? classSym.registered : null;
5325 if(exp.member.member)
5327 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5329 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5331 if(!prop && !member && _class && exp.member.member)
5333 Symbol classSym = FindClass(exp.member.member.string);
5335 _class = classSym ? classSym.registered : null;
5336 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5343 Type type = prop.dataType;
5344 // TODO: Assuming same base type for units...
5345 if(_class.type == unitClass)
5347 if(type.kind == classType)
5349 Class _class = type._class.registered;
5350 if(_class.type == unitClass)
5352 if(!_class.dataType)
5353 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5354 type = _class.dataType;
5362 float (*Get)(float) = (void *)prop.Get;
5363 GetFloat(exp.member.exp, &value);
5364 exp.constant = PrintFloat(Get ? Get(value) : value);
5365 exp.type = constantExp;
5371 double (*Get)(double);
5372 GetDouble(exp.member.exp, &value);
5375 Get = (void *)prop.Set;
5377 Get = (void *)prop.Get;
5378 exp.constant = PrintDouble(Get ? Get(value) : value);
5379 exp.type = constantExp;
5388 Expression value = exp.member.exp;
5391 ProcessPropertyType(prop);
5393 type = prop.dataType;
5396 // printf("Investigate this\n");
5398 else if(_class.type == structClass)
5404 Class propertyClass = type._class.registered;
5405 if(propertyClass.type == structClass && value.type == instanceExp)
5407 void (*Set)(void *, void *) = (void *)prop.Set;
5408 exp.instance = Instantiation { };
5409 exp.instance.data = new0 byte[_class.structSize];
5410 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5411 exp.instance.loc = exp.loc;
5412 exp.type = instanceExp;
5413 Set(exp.instance.data, value.instance.data);
5414 PopulateInstance(exp.instance);
5421 void (*Set)(void *, int) = (void *)prop.Set;
5423 exp.instance = Instantiation { };
5424 exp.instance.data = new0 byte[_class.structSize];
5425 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5426 exp.instance.loc = exp.loc;
5427 exp.type = instanceExp;
5429 GetInt(value, &intValue);
5431 Set(exp.instance.data, intValue);
5432 PopulateInstance(exp.instance);
5438 void (*Set)(void *, int64) = (void *)prop.Set;
5440 exp.instance = Instantiation { };
5441 exp.instance.data = new0 byte[_class.structSize];
5442 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5443 exp.instance.loc = exp.loc;
5444 exp.type = instanceExp;
5446 GetInt64(value, &intValue);
5448 Set(exp.instance.data, intValue);
5449 PopulateInstance(exp.instance);
5455 void (*Set)(void *, double) = (void *)prop.Set;
5457 exp.instance = Instantiation { };
5458 exp.instance.data = new0 byte[_class.structSize];
5459 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5460 exp.instance.loc = exp.loc;
5461 exp.type = instanceExp;
5463 GetDouble(value, &doubleValue);
5465 Set(exp.instance.data, doubleValue);
5466 PopulateInstance(exp.instance);
5471 else if(_class.type == bitClass)
5477 Class propertyClass = type._class.registered;
5478 if(propertyClass.type == structClass && value.instance.data)
5480 unsigned int (*Set)(void *) = (void *)prop.Set;
5481 unsigned int bits = Set(value.instance.data);
5482 exp.constant = PrintHexUInt(bits);
5483 exp.type = constantExp;
5486 else if(_class.type == bitClass)
5489 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5492 GetUInt(exp.member.exp, &value);
5494 exp.constant = PrintHexUInt(bits);
5495 exp.type = constantExp;
5503 if(_class.type == bitClass)
5506 GetUInt(exp.member.exp, &value);
5512 Class _class = type._class.registered;
5513 if(_class.type == structClass)
5515 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5517 exp.instance = Instantiation { };
5518 exp.instance.data = new0 byte[_class.structSize];
5519 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5520 exp.instance.loc = exp.loc;
5521 //exp.instance.fullSet = true;
5522 exp.type = instanceExp;
5523 Get(value, exp.instance.data);
5524 PopulateInstance(exp.instance);
5526 else if(_class.type == bitClass)
5528 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5529 uint64 bits = Get(value);
5530 exp.constant = PrintHexUInt64(bits);
5531 exp.type = constantExp;
5537 else if(_class.type == structClass)
5539 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5544 Class _class = type._class.registered;
5545 if(_class.type == structClass && value)
5547 void (*Get)(void *, void *) = (void *)prop.Get;
5549 exp.instance = Instantiation { };
5550 exp.instance.data = new0 byte[_class.structSize];
5551 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5552 exp.instance.loc = exp.loc;
5553 //exp.instance.fullSet = true;
5554 exp.type = instanceExp;
5555 Get(value, exp.instance.data);
5556 PopulateInstance(exp.instance);
5564 char * value = exp.member.exp.instance.data;
5569 Class _class = type._class.registered;
5570 if(_class.type == normalClass)
5572 void *(*Get)(void *) = (void *)prop.Get;
5574 exp.instance = Instantiation { };
5575 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5576 exp.type = instanceExp;
5577 exp.instance.data = Get(value, exp.instance.data);
5589 exp.isConstant = false;
5597 if(exp.type != ExpressionType::memberExp)
5599 FreeExpression(memberExp);
5600 FreeIdentifier(memberID);
5606 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5607 FreeExpContents(exp);
5608 exp.constant = PrintUInt(ComputeTypeSize(type));
5609 exp.type = constantExp;
5615 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5616 if(classSym && classSym.registered)
5618 if(classSym.registered.fixed)
5620 FreeSpecifier(exp._class);
5621 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5622 exp.type = constantExp;
5626 char className[1024];
5627 strcpy(className, "__ecereClass_");
5628 FullClassNameCat(className, classSym.string, true);
5629 MangleClassName(className);
5631 FreeExpContents(exp);
5632 exp.type = pointerExp;
5633 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5634 exp.member.member = MkIdentifier("structSize");
5644 if(exp.type == castExp)
5647 ComputeExpression(exp.cast.exp);
5650 if(e && exp.expType)
5653 type = exp.destType;
5656 if(type.kind == classType)
5658 Class _class = type._class.registered;
5659 if(_class && (_class.type == unitClass || _class.type == bitClass))
5661 if(!_class.dataType)
5662 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5663 type = _class.dataType;
5674 FreeExpContents(exp);
5675 exp.constant = PrintChar(value);
5676 exp.type = constantExp;
5680 unsigned char value;
5681 GetUChar(e, &value);
5682 FreeExpContents(exp);
5683 exp.constant = PrintUChar(value);
5684 exp.type = constantExp;
5691 GetShort(e, &value);
5692 FreeExpContents(exp);
5693 exp.constant = PrintShort(value);
5694 exp.type = constantExp;
5698 unsigned short value;
5699 GetUShort(e, &value);
5700 FreeExpContents(exp);
5701 exp.constant = PrintUShort(value);
5702 exp.type = constantExp;
5710 FreeExpContents(exp);
5711 exp.constant = PrintInt(value);
5712 exp.type = constantExp;
5718 FreeExpContents(exp);
5719 exp.constant = PrintUInt(value);
5720 exp.type = constantExp;
5727 GetInt64(e, &value);
5728 FreeExpContents(exp);
5729 exp.constant = PrintInt64(value);
5730 exp.type = constantExp;
5735 GetUInt64(e, &value);
5736 FreeExpContents(exp);
5737 exp.constant = PrintUInt64(value);
5738 exp.type = constantExp;
5744 GetFloat(e, &value);
5745 FreeExpContents(exp);
5746 exp.constant = PrintFloat(value);
5747 exp.type = constantExp;
5753 GetDouble(e, &value);
5754 FreeExpContents(exp);
5755 exp.constant = PrintDouble(value);
5756 exp.type = constantExp;
5770 // Caring only about last expression for now...
5771 ComputeExpression(exp.cond.exp->last);
5772 if(exp.cond.elseExp)
5773 ComputeExpression(exp.cond.elseExp);
5775 ComputeExpression(exp.cond.cond);
5777 op1 = GetOperand(exp.cond.cond);
5778 if(op1.type) op1.type.refCount++;
5779 op2 = GetOperand(exp.cond.exp->last);
5780 if(op2.type) op2.type.refCount++;
5781 op3 = GetOperand(exp.cond.elseExp);
5782 if(op3.type) op3.type.refCount++;
5784 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5785 if(op1.type) FreeType(op1.type);
5786 if(op2.type) FreeType(op2.type);
5787 if(op3.type) FreeType(op3.type);
5793 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5798 OldList converts { };
5801 if(destType.kind == voidType)
5804 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5808 // for(convert = converts.last; convert; convert = convert.prev)
5809 for(convert = converts.first; convert; convert = convert.next)
5811 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5814 Expression newExp { };
5815 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5817 // TODO: Check this...
5819 newExp.destType = null;
5824 exp.type = memberExp;
5825 exp.addedThis = true;
5826 exp.member.exp = newExp;
5827 FreeType(exp.member.exp.expType);
5829 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5830 exp.member.exp.expType.classObjectType = objectType;
5831 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5832 exp.member.memberType = propertyMember;
5833 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5834 // TESTING THIS... for (int)degrees
5835 exp.needCast = true;
5836 if(exp.expType) exp.expType.refCount++;
5837 ApplyAnyObjectLogic(exp.member.exp);
5842 /*if(exp.isConstant)
5844 // Color { ColorRGB = [exp] };
5845 exp.type = instanceExp;
5846 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5847 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5848 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5852 // If not constant, don't turn it yet into an instantiation
5853 // (Go through the deep members system first)
5854 exp.type = memberExp;
5855 exp.addedThis = true;
5856 exp.member.exp = newExp;
5858 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5859 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5860 newExp.expType._class.registered.type == noHeadClass)
5862 newExp.byReference = true;
5865 FreeType(exp.member.exp.expType);
5866 /*exp.member.exp.expType = convert.convert.dataType;
5867 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
5868 exp.member.exp.expType = null;
5869 if(convert.convert.dataType)
5871 exp.member.exp.expType = { };
5872 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
5873 exp.member.exp.expType.refCount = 1;
5874 exp.member.exp.expType.classObjectType = objectType;
5875 ApplyAnyObjectLogic(exp.member.exp);
5878 exp.member.member = MkIdentifier(convert.convert._class.fullName);
5879 exp.member.memberType = reverseConversionMember;
5880 exp.expType = convert.resultType ? convert.resultType :
5881 MkClassType(convert.convert._class.fullName);
5882 exp.needCast = true;
5883 if(convert.resultType) convert.resultType.refCount++;
5889 FreeType(exp.expType);
5892 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5893 exp.needCast = true;
5894 if(exp.expType) exp.expType.refCount++;
5898 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
5899 exp.needCast = true;
5900 if(convert.resultType)
5901 convert.resultType.refCount++;
5905 if(exp.isConstant && inCompiler)
5906 ComputeExpression(exp);
5908 converts.Free(FreeConvert);
5911 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
5913 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
5915 if(!result && exp.expType && exp.destType)
5917 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
5918 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
5919 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
5920 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
5924 // if(result) CheckTemplateTypes(exp);
5928 void CheckTemplateTypes(Expression exp)
5930 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
5932 Expression newExp { };
5936 if(exp.destType) exp.destType.refCount++;
5937 if(exp.expType) exp.expType.refCount++;
5941 switch(exp.expType.kind)
5946 context = PushContext();
5947 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
5948 MkExpExtensionCompound(compound = MkCompoundStmt(
5949 MkListOne(MkDeclaration(MkListOne(MkSpecifier(DOUBLE)),
5950 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
5951 MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
5952 compound.compound.context = context;
5953 PopContext(context);
5958 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
5959 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
5963 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
5965 Expression newExp { };
5969 if(exp.destType) exp.destType.refCount++;
5970 if(exp.expType) exp.expType.refCount++;
5974 switch(exp.expType.kind)
5979 context = PushContext();
5980 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifier(DOUBLE)), MkDeclaratorPointer(MkPointer(null, null), null)),
5981 MkExpExtensionCompound(compound = MkCompoundStmt(
5982 MkListOne(MkDeclaration(MkListOne(MkSpecifierName("uint64")),
5983 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
5984 MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
5985 compound.compound.context = context;
5986 PopContext(context);
5988 ProcessExpressionType(exp.op.exp2);
5992 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
5994 exp.type = bracketsExp;
5995 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
5996 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
5997 ProcessExpressionType(exp.list->first);
6002 exp.type = bracketsExp;
6003 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6004 newExp.needCast = true;
6005 ProcessExpressionType(exp.list->first);
6011 if(exp.expType.kind == templateType)
6013 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6016 FreeType(exp.destType);
6017 FreeType(exp.expType);
6022 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6027 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6028 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6032 char typeString[1024];
6034 OldList * specs = MkList();
6035 typeString[0] = '\0';
6036 PrintType(exp.expType, typeString, false, false);
6037 decl = SpecDeclFromString(typeString, specs, null);
6040 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6041 exp.cast.typeName = MkTypeName(specs, decl);
6042 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6043 exp.cast.exp.needCast = true;
6050 // TODO: The Symbol tree should be reorganized by namespaces
6052 // - Tree of all symbols within (stored without namespace)
6053 // - Tree of sub-namespaces
6055 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6057 int nsLen = strlen(nameSpace);
6059 // Start at the name space prefix
6060 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6062 char * s = symbol.string;
6063 if(!strncmp(s, nameSpace, nsLen))
6065 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6068 for(c = strlen(s)-1; c >= 0; c--)
6073 if(!strcmp(namePart, name))
6075 // TODO: Error on ambiguity
6085 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6088 char nameSpace[1024];
6090 bool gotColon = false;
6092 nameSpace[0] = '\0';
6093 for(c = strlen(name)-1; c >= 0; c--)
6100 namePart = name+c+1;
6101 while(c >= 0 && name[c] == ':') c--;
6104 // Try an exact match first
6105 Symbol symbol = (Symbol)tree.FindString(name);
6109 // Namespace specified
6110 memcpy(nameSpace, name, c + 1);
6113 return ScanWithNameSpace(tree, nameSpace, namePart);
6117 // Looking for a global symbol, e.g. ::Sleep()
6118 Symbol symbol = (Symbol)tree.FindString(namePart);
6123 // Name only (no namespace specified)
6124 Symbol symbol = (Symbol)tree.FindString(namePart);
6127 return ScanWithNameSpace(tree, "", namePart);
6132 static void ProcessDeclaration(Declaration decl);
6134 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6137 //Time startTime = GetTime();
6139 // Optimize this later? Do this before/less?
6141 Symbol symbol = null;
6142 // First, check if the identifier is declared inside the function
6143 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6145 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6147 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6153 strcpy(curName, thisNameSpace);
6154 strcat(curName, "::");
6155 strcat(curName, name);
6156 // Try to resolve in current namespace first
6157 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6160 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6163 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6165 if(symbol || ctx == endContext) break;
6167 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6169 if(symbol.pointerExternal.type == functionExternal)
6171 FunctionDefinition function = symbol.pointerExternal.function;
6173 // Modified this recently...
6174 Context tmpContext = curContext;
6176 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6177 curContext = tmpContext;
6179 symbol.pointerExternal.symbol = symbol;
6182 DeclareType(symbol.type, true, true);
6184 ast->Insert(curExternal.prev, symbol.pointerExternal);
6186 symbol.id = curExternal.symbol.idCode;
6189 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6191 ast->Move(symbol.pointerExternal, curExternal.prev);
6192 symbol.id = curExternal.symbol.idCode;
6196 //findSymbolTotalTime += GetTime() - startTime;
6201 static void GetTypeSpecs(Type type, OldList * specs)
6203 if(!type.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
6208 if(type._class.registered)
6210 if(!type._class.registered.dataType)
6211 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6212 GetTypeSpecs(type._class.registered.dataType, specs);
6216 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6217 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6218 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6219 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6220 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6223 ListAdd(specs, MkSpecifier(INT)); break;
6227 // WARNING : This function expects a null terminated string since it recursively concatenate...
6228 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6235 if(type._class && type._class.string)
6237 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6238 // look into merging with thisclass ?
6239 if(type.classObjectType == typedObject)
6240 strcat(string, "typed_object");
6242 strcat(string, type._class.string);
6245 if(type._class.registered)
6246 strcat(string, type._class.registered.name);
6248 strcat(string, type._class.string);
6255 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6256 if(funcType && funcType.kind == functionType)
6259 PrintType(funcType.returnType, string, false, fullName);
6260 strcat(string, "(*");
6261 if(printName || funcType.thisClass)
6263 strcat(string, " ");
6264 if(funcType.thisClass)
6266 strcat(string, funcType.thisClass.string);
6267 strcat(string, "::");
6270 strcat(string, type.name);
6272 strcat(string, ")(");
6273 for(param = funcType.params.first; param; param = param.next)
6275 PrintType(param, string, false, fullName);
6276 if(param.next) strcat(string, ", ");
6278 strcat(string, ")");
6282 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6283 strcat(string, " *");
6287 case voidType: strcat(string, "void"); break;
6288 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6289 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6290 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6291 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6292 case floatType: strcat(string, "float"); break;
6293 case doubleType: strcat(string, "double"); break;
6297 strcat(string, "struct ");
6298 strcat(string, type.enumName);
6300 else if(type.typeName)
6302 strcat(string, type.typeName);
6307 strcat(string, "struct ");
6308 strcat(string,"(unnamed)");
6311 strcat(string, "struct {");
6312 for(member = type.members.first; member; member = member.next)
6314 PrintType(member, string, true, fullName);
6315 strcat(string,"; ");
6323 strcat(string, "union ");
6324 strcat(string, type.enumName);
6326 else if(type.typeName)
6328 strcat(string, type.typeName);
6332 strcat(string, "union ");
6333 strcat(string,"(unnamed)");
6339 strcat(string, "enum ");
6340 strcat(string, type.enumName);
6342 else if(type.typeName)
6344 strcat(string, type.typeName);
6347 strcat(string, "enum");
6354 strcat(string, "dllexport ");
6355 PrintType(type.returnType, string, false, fullName);
6356 strcat(string, " ");
6359 // DANGER: Testing This
6365 strcat(string, type.name);
6368 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6369 if(name) name += 2; else name = type.name;
6370 strcat(string, name);
6384 strcat(string, "(");
6385 for(param = type.params.first; param; param = param.next)
6387 PrintType(param, string, true, fullName);
6388 if(param.next) strcat(string, ", ");
6390 strcat(string, ")");
6397 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6398 if(funcType && funcType.kind == functionType)
6401 PrintType(funcType.returnType, string, false, fullName);
6402 strcat(string, "(*");
6403 if(printName || funcType.thisClass)
6405 strcat(string, " ");
6406 if(funcType.thisClass)
6408 strcat(string, funcType.thisClass.string);
6409 strcat(string, "::");
6412 strcat(string, type.name);
6414 strcat(string, ")(");
6415 for(param = funcType.params.first; param; param = param.next)
6417 PrintType(param, string, false, fullName);
6418 if(param.next) strcat(string, ", ");
6420 strcat(string, ")");
6424 char baseType[1024], size[256];
6425 Type arrayType = type;
6429 while(arrayType.kind == TypeKind::arrayType)
6432 if(arrayType.enumClass)
6433 strcat(size, arrayType.enumClass.string);
6434 else if(arrayType.arraySizeExp)
6435 PrintExpression(arrayType.arraySizeExp, size);
6436 //sprintf(string, "%s[%s]", baseType, size);
6439 arrayType = arrayType.arrayType;
6441 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6442 strcat(string, baseType);
6443 strcat(string, size);
6447 PrintType(type.arrayType, baseType, printName, fullName);
6449 strcpy(size, type.enumClass.string);
6450 else if(type.arraySizeExp)
6451 PrintExpression(type.arraySizeExp, size);
6452 //sprintf(string, "%s[%s]", baseType, size);
6453 strcat(string, baseType);
6454 strcat(string, "[");
6455 strcat(string, size);
6456 strcat(string, "]");
6463 strcat(string, "...");
6466 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6469 strcat(string, "subclass(");
6470 strcat(string, type._class ? type._class.string : "int");
6471 strcat(string, ")");
6474 strcat(string, type.templateParameter.identifier.string);
6477 strcat(string, "thisclass");
6480 strcat(string, "__builtin_va_list");
6487 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6489 strcat(string, " ");
6490 strcat(string, type.name);
6495 void PrintType(Type type, char * string, bool printName, bool fullName)
6498 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6499 if(funcType && funcType.kind == functionType && type != funcType)
6501 char typeString[1024];
6504 PrintType(funcType.returnType, string, false, fullName);
6505 strcat(string, "(");
6506 _PrintType(type, string, printName, false, fullName);
6507 strcat(string, ")");
6510 strcat(string, type.name);
6516 strcat(string, "(");
6517 for(param = funcType.params.first; param; param = param.next)
6519 PrintType(param, string, true, fullName);
6520 if(param.next) strcat(string, ", ");
6522 strcat(string, ")");
6525 _PrintType(type, string, printName, true, fullName);
6526 if(type.bitFieldCount)
6529 sprintf(count, ":%d", type.bitFieldCount);
6530 strcat(string, count);
6534 static Type FindMember(Type type, char * string)
6537 for(memberType = type.members.first; memberType; memberType = memberType.next)
6539 if(!memberType.name)
6541 Type subType = FindMember(memberType, string);
6545 else if(!strcmp(memberType.name, string))
6551 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6554 for(memberType = type.members.first; memberType; memberType = memberType.next)
6556 if(!memberType.name)
6558 Type subType = FindMember(memberType, string);
6561 *offset += memberType.offset;
6565 else if(!strcmp(memberType.name, string))
6567 *offset += memberType.offset;
6574 Expression ParseExpressionString(char * expression)
6576 fileInput = TempFile { };
6577 fileInput.Write(expression, 1, strlen(expression));
6578 fileInput.Seek(0, start);
6581 parsedExpression = null;
6583 expression_yyparse();
6586 return parsedExpression;
6589 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6591 Identifier id = exp.identifier;
6592 Method method = null;
6593 Property prop = null;
6594 DataMember member = null;
6595 ClassProperty classProp = null;
6597 if(_class && _class.type == enumClass)
6599 NamedLink value = null;
6600 Class enumClass = eSystem_FindClass(privateModule, "enum");
6604 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6606 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6607 for(value = e.values.first; value; value = value.next)
6609 if(!strcmp(value.name, id.string))
6616 FreeExpContents(exp);
6618 exp.type = constantExp;
6619 exp.isConstant = true;
6620 if(!strcmp(baseClass.dataTypeString, "int"))
6621 sprintf(constant, "%d",value.data);
6623 sprintf(constant, "0x%X",value.data);
6624 exp.constant = CopyString(constant);
6625 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6626 exp.expType = MkClassType(baseClass.fullName);
6634 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6636 ProcessMethodType(method);
6643 // TOCHECK: Put it back to what it was...
6644 // methodClass = _class;
6645 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6650 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6653 ProcessPropertyType(prop);
6654 exp.expType = prop.dataType;
6655 if(prop.dataType) prop.dataType.refCount++;
6658 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6660 if(!member.dataType)
6661 member.dataType = ProcessTypeString(member.dataTypeString, false);
6662 exp.expType = member.dataType;
6663 if(member.dataType) member.dataType.refCount++;
6666 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6668 if(!classProp.dataType)
6669 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6671 if(classProp.constant)
6673 FreeExpContents(exp);
6675 exp.isConstant = true;
6676 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6678 //char constant[256];
6679 exp.type = stringExp;
6680 exp.constant = QMkString((char *)classProp.Get(_class));
6685 exp.type = constantExp;
6686 sprintf(constant, "%d",classProp.Get(_class));
6687 exp.constant = CopyString(constant);
6695 exp.expType = classProp.dataType;
6696 if(classProp.dataType) classProp.dataType.refCount++;
6702 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6704 BinaryTree * tree = &nameSpace.functions;
6705 GlobalData data = (GlobalData)tree->FindString(name);
6709 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6711 data = ScanGlobalData(child, name);
6719 static GlobalData FindGlobalData(char * name)
6722 NameSpace * nameSpace;
6723 nameSpace = globalData;
6724 for(c = 0; name[c]; c++)
6726 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6728 NameSpace * newSpace;
6729 char * spaceName = new char[c - start + 1];
6730 strncpy(spaceName, name + start, c - start);
6731 spaceName[c-start] = '\0';
6732 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6736 nameSpace = newSpace;
6737 if(name[c] == ':') c++;
6743 return ScanGlobalData(nameSpace, name + start);
6748 static int definedExpStackPos;
6749 static void * definedExpStack[512];
6751 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6752 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6754 Expression prev = checkedExp.prev, next = checkedExp.next;
6756 FreeExpContents(checkedExp);
6757 FreeType(checkedExp.expType);
6758 FreeType(checkedExp.destType);
6760 *checkedExp = *newExp;
6764 checkedExp.prev = prev;
6765 checkedExp.next = next;
6768 void ApplyAnyObjectLogic(Expression e)
6770 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6771 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6773 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6774 //ellipsisDestType = destType;
6777 Type type = e.expType;
6778 Class _class = null;
6779 //Type destType = e.destType;
6781 if(type.kind == classType && type._class && type._class.registered)
6783 _class = type._class.registered;
6785 else if(type.kind == subClassType)
6787 _class = FindClass("ecere::com::Class").registered;
6791 char string[1024] = "";
6794 PrintType(type, string, false, true);
6795 classSym = FindClass(string);
6796 if(classSym) _class = classSym.registered;
6799 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...
6800 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6801 destType.byReference)))
6803 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6805 Expression checkedExp = e, newExp;
6807 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6809 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6811 if(checkedExp.type == extensionCompoundExp)
6813 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6816 checkedExp = checkedExp.list->last;
6818 else if(checkedExp.type == castExp)
6819 checkedExp = checkedExp.cast.exp;
6822 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6824 newExp = checkedExp.op.exp2;
6825 checkedExp.op.exp2 = null;
6826 FreeExpContents(checkedExp);
6828 if(e.expType && e.expType.passAsTemplate)
6831 ComputeTypeSize(e.expType);
6832 sprintf(size, "%d", e.expType.size);
6833 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6834 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6835 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6838 ReplaceExpContents(checkedExp, newExp);
6839 e.byReference = true;
6841 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6843 Expression checkedExp, newExp;
6846 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6848 e.type == identifierExp ||
6849 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6850 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6851 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6854 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6856 Context context = PushContext();
6858 OldList * specs = MkList();
6859 char typeString[1024];
6860 Expression newExp { };
6862 typeString[0] = '\0';
6865 //if(e.destType) e.destType.refCount++;
6866 // if(exp.expType) exp.expType.refCount++;
6869 newExp.expType = null;
6871 PrintType(e.expType, typeString, false, true);
6872 decl = SpecDeclFromString(typeString, specs, null);
6873 newExp.destType = ProcessType(specs, decl);
6875 curContext = context;
6876 e.type = extensionCompoundExp;
6877 e.compound = MkCompoundStmt(
6878 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
6879 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
6881 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
6884 Type type = e.destType;
6886 CopyTypeInto(e.destType, type);
6887 e.destType.refCount = 1;
6888 e.destType.classObjectType = none;
6892 e.compound.compound.context = context;
6893 PopContext(context);
6894 curContext = context.parent;
6898 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
6900 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6902 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6904 if(checkedExp.type == extensionCompoundExp)
6906 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6909 checkedExp = checkedExp.list->last;
6911 else if(checkedExp.type == castExp)
6912 checkedExp = checkedExp.cast.exp;
6915 Expression operand { };
6916 operand = *checkedExp;
6917 checkedExp.destType = null;
6918 checkedExp.expType = null;
6920 checkedExp.type = opExp;
6921 checkedExp.op.op = '&';
6922 checkedExp.op.exp1 = null;
6923 checkedExp.op.exp2 = operand;
6925 //newExp = MkExpOp(null, '&', checkedExp);
6927 //ReplaceExpContents(checkedExp, newExp);
6934 // If expression type is a simple class, make it an address
6935 // FixReference(e, true);
6938 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6939 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6940 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
6942 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
6944 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
6948 Expression thisExp { };
6951 thisExp.prev = null;
6952 thisExp.next = null;
6955 e.type = bracketsExp;
6956 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
6957 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
6958 ((Expression)e.list->first).byReference = true;
6960 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
6962 e.expType = thisExp.expType;
6963 e.expType.refCount++;
6968 CopyTypeInto(e.expType, thisExp.expType);
6969 e.expType.byReference = false;
6970 e.expType.refCount = 1;
6972 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6973 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
6975 e.expType.classObjectType = none;
6980 // TOFIX: Try this for a nice IDE crash!
6982 // The other way around
6985 if(destType && e.expType &&
6986 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
6987 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6988 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
6990 if(destType.kind == ellipsisType)
6992 Compiler_Error($"Unspecified type\n");
6994 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
6996 bool byReference = e.expType.byReference;
6997 Expression thisExp { };
6999 OldList * specs = MkList();
7000 char typeString[1024]; // Watch buffer overruns
7002 ClassObjectType backupClassObjectType;
7004 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7009 backupClassObjectType = type.classObjectType;
7011 type.classObjectType = none;
7013 typeString[0] = '\0';
7014 PrintType(type, typeString, false, true);
7015 decl = SpecDeclFromString(typeString, specs, null);
7017 type.classObjectType = backupClassObjectType;
7020 thisExp.prev = null;
7021 thisExp.next = null;
7024 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7025 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7026 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7027 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7028 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7033 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7038 e.cast.typeName = MkTypeName(specs, decl);
7039 e.cast.exp = thisExp;
7040 e.byReference = true;
7043 e.destType = destType;
7045 destType.refCount++;
7050 void ProcessExpressionType(Expression exp)
7052 bool unresolved = false;
7053 Location oldyylloc = yylloc;
7054 bool notByReference = false;
7056 char debugExpString[4096];
7057 debugExpString[0] = '\0';
7058 PrintExpression(exp, debugExpString);
7060 if(!exp || exp.expType)
7063 //eSystem_Logf("%s\n", expString);
7065 // Testing this here
7071 Identifier id = exp.identifier;
7074 // DOING THIS LATER NOW...
7075 if(id._class && id._class.name)
7077 id.classSym = id._class.symbol; // FindClass(id._class.name);
7078 /* TODO: Name Space Fix ups
7080 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7084 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7086 exp.expType = ProcessTypeString("Module", true);
7089 else */if(strstr(id.string, "__ecereClass") == id.string)
7091 exp.expType = ProcessTypeString("ecere::com::Class", true);
7094 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7096 // Added this here as well
7097 ReplaceClassMembers(exp, thisClass);
7098 if(exp.type != identifierExp)
7100 ProcessExpressionType(exp);
7104 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7109 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7110 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7111 if(!symbol/* && exp.destType*/)
7113 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7119 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7120 if(exp.type != identifierExp)
7122 ProcessExpressionType(exp);
7126 // Static methods called from inside the _class
7127 else if(currentClass && !id._class)
7129 if(ResolveIdWithClass(exp, currentClass, true))
7132 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7136 // If we manage to resolve this symbol
7139 Type type = symbol.type;
7140 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7142 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7144 Context context = SetupTemplatesContext(_class);
7145 type = ReplaceThisClassType(_class);
7146 FinishTemplatesContext(context);
7147 if(type) type.refCount = 0; // We'll be incrementing it right below...
7150 FreeSpecifier(id._class);
7153 id.string = CopyString(symbol.string);
7159 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7160 // Add missing cases here... enum Classes...
7161 exp.isConstant = true;
7163 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7164 if(symbol.isParam || !strcmp(id.string, "this"))
7166 if(_class && _class.type == structClass)
7167 exp.byReference = true;
7169 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7170 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7171 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7172 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7174 Identifier id = exp.identifier;
7175 exp.type = bracketsExp;
7176 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7180 if(symbol.isIterator)
7182 if(symbol.isIterator == 3)
7184 exp.type = bracketsExp;
7185 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7186 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7188 ProcessExpressionType(exp);
7190 else if(symbol.isIterator != 4)
7192 exp.type = memberExp;
7193 exp.member.exp = MkExpIdentifier(exp.identifier);
7194 exp.member.exp.expType = exp.expType;
7195 /*if(symbol.isIterator == 6)
7196 exp.member.member = MkIdentifier("key");
7198 exp.member.member = MkIdentifier("data");
7200 ProcessExpressionType(exp);
7207 DefinedExpression definedExp = null;
7208 if(thisNameSpace && !(id._class && !id._class.name))
7211 strcpy(name, thisNameSpace);
7213 strcat(name, id.string);
7214 definedExp = eSystem_FindDefine(privateModule, name);
7217 definedExp = eSystem_FindDefine(privateModule, id.string);
7221 for(c = 0; c<definedExpStackPos; c++)
7222 if(definedExpStack[c] == definedExp)
7224 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7226 Location backupYylloc = yylloc;
7227 definedExpStack[definedExpStackPos++] = definedExp;
7228 fileInput = TempFile { };
7229 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7230 fileInput.Seek(0, start);
7233 parsedExpression = null;
7235 expression_yyparse();
7238 yylloc = backupYylloc;
7240 if(parsedExpression)
7243 exp.type = bracketsExp;
7244 exp.list = MkListOne(parsedExpression);
7245 parsedExpression.loc = yylloc;
7246 ProcessExpressionType(exp);
7247 definedExpStackPos--;
7250 definedExpStackPos--;
7256 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7262 GlobalData data = null;
7263 if(thisNameSpace && !(id._class && !id._class.name))
7266 strcpy(name, thisNameSpace);
7268 strcat(name, id.string);
7269 data = FindGlobalData(name);
7272 data = FindGlobalData(id.string);
7275 DeclareGlobalData(data);
7276 exp.expType = data.dataType;
7277 if(data.dataType) data.dataType.refCount++;
7280 id.string = CopyString(data.fullName);
7281 FreeSpecifier(id._class);
7288 GlobalFunction function = null;
7289 if(thisNameSpace && !(id._class && !id._class.name))
7292 strcpy(name, thisNameSpace);
7294 strcat(name, id.string);
7295 function = eSystem_FindFunction(privateModule, name);
7298 function = eSystem_FindFunction(privateModule, id.string);
7303 id.string = CopyString(function.name);
7306 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7307 strcpy(name, "__ecereFunction_");
7308 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7309 if(DeclareFunction(function, name))
7312 id.string = CopyString(name);
7314 exp.expType = function.dataType;
7315 if(function.dataType) function.dataType.refCount++;
7317 FreeSpecifier(id._class);
7334 if(!exp.instance._class)
7336 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7338 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7348 //classSym = FindClass(exp.instance._class.fullName);
7349 //_class = classSym ? classSym.registered : null;
7351 ProcessInstantiationType(exp.instance);
7352 exp.isConstant = exp.instance.isConstant;
7355 if(_class.type == unitClass && _class.base.type != systemClass)
7358 Type destType = exp.destType;
7360 exp.destType = MkClassType(_class.base.fullName);
7361 exp.expType = MkClassType(_class.fullName);
7362 CheckExpressionType(exp, exp.destType, true);
7364 exp.destType = destType;
7366 exp.expType = MkClassType(_class.fullName);
7369 if(exp.instance._class)
7371 exp.expType = MkClassType(exp.instance._class.name);
7372 /*if(exp.expType._class && exp.expType._class.registered &&
7373 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7374 exp.expType.byReference = true;*/
7389 if(exp.constant[0] == '\'')
7391 if((int)((byte *)exp.constant)[1] > 127)
7394 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7395 if(nb < 2) ch = exp.constant[1];
7396 delete exp.constant;
7397 exp.constant = PrintUInt(ch);
7398 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7399 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7400 type._class = FindClass("unichar");
7402 type.isSigned = false;
7406 type.kind = charType;
7407 type.isSigned = true;
7410 else if(strchr(exp.constant, '.'))
7412 char ch = exp.constant[strlen(exp.constant)-1];
7414 type.kind = floatType;
7416 type.kind = doubleType;
7417 type.isSigned = true;
7421 if(exp.constant[0] == '0' && exp.constant[1])
7422 type.isSigned = false;
7423 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7424 type.isSigned = false;
7425 else if(strtoll(exp.constant, null, 0) > MAXINT)
7426 type.isSigned = false;
7428 type.isSigned = true;
7429 type.kind = intType;
7431 exp.isConstant = true;
7437 exp.isConstant = true; // Why wasn't this constant?
7453 ProcessExpressionType(exp._new.size);
7458 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7460 DeclareType(exp.expType.type, false, false);
7464 ProcessExpressionType(exp._renew.size);
7465 ProcessExpressionType(exp._renew.exp);
7470 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7472 DeclareType(exp.expType.type, false, false);
7476 bool assign = false, boolResult = false, boolOps = false;
7477 Type type1 = null, type2 = null;
7478 bool useDestType = false, useSideType = false;
7479 Location oldyylloc = yylloc;
7480 bool useSideUnit = false;
7482 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7491 // Assignment Operators
7505 // boolean Operators
7507 // Expect boolean operators
7509 //boolResult = true;
7513 // Expect boolean operands
7524 // Gives boolean result
7532 // Just added these... testing
7537 // DANGER: Verify units
7542 if(exp.op.op != '*' || exp.op.exp1)
7549 /*// Implement speed etc.
7555 if(exp.op.op == '&')
7557 // Added this here earlier for Iterator address as key
7558 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7560 Identifier id = exp.op.exp2.identifier;
7561 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7562 if(symbol && symbol.isIterator == 2)
7564 exp.type = memberExp;
7565 exp.member.exp = exp.op.exp2;
7566 exp.member.member = MkIdentifier("key");
7568 exp.op.exp2.expType = symbol.type;
7569 symbol.type.refCount++;
7570 ProcessExpressionType(exp);
7574 // exp.op.exp2.usage.usageRef = true;
7578 //dummy.kind = TypeDummy;
7582 if(exp.destType && exp.destType.kind == classType &&
7583 exp.destType._class && exp.destType._class.registered && useDestType &&
7585 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7586 exp.destType._class.registered.type == enumClass ||
7587 exp.destType._class.registered.type == bitClass
7590 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7592 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7593 exp.op.exp1.destType = exp.destType;
7595 exp.destType.refCount++;
7599 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7600 exp.op.exp1.destType = dummy;
7604 // TESTING THIS HERE...
7605 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7606 ProcessExpressionType(exp.op.exp1);
7607 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7609 if(exp.op.exp1.destType == dummy)
7612 exp.op.exp1.destType = null;
7614 type1 = exp.op.exp1.expType;
7619 char expString[10240];
7620 expString[0] = '\0';
7621 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7625 exp.op.exp2.destType = exp.op.exp1.expType;
7626 if(exp.op.exp1.expType)
7627 exp.op.exp1.expType.refCount++;
7631 exp.op.exp2.destType = exp.destType;
7633 exp.destType.refCount++;
7636 if(type1) type1.refCount++;
7637 exp.expType = type1;
7642 PrintExpression(exp.op.exp2, expString);
7644 if(type1 && type1.kind == pointerType)
7646 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 ||
7647 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7648 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7649 else if(exp.op.op == '=')
7651 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7652 exp.op.exp2.destType = type1;
7659 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7660 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/* ||
7661 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7664 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7665 exp.op.exp2.destType = type1;
7670 if(type1) type1.refCount++;
7671 exp.expType = type1;
7673 else if(exp.destType && exp.destType.kind == classType &&
7674 exp.destType._class && exp.destType._class.registered &&
7676 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7677 (exp.destType._class.registered.type == enumClass && useDestType))
7680 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7681 exp.op.exp2.destType = exp.destType;
7683 exp.destType.refCount++;
7687 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7688 exp.op.exp2.destType = dummy;
7692 // TESTING THIS HERE... (DANGEROUS)
7693 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7694 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7696 FreeType(exp.op.exp2.destType);
7697 exp.op.exp2.destType = type1;
7700 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7701 ProcessExpressionType(exp.op.exp2);
7702 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7704 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7706 if(exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
7708 if(exp.op.op != '=' && type1.type.kind == voidType)
7709 Compiler_Error($"void *: unknown size\n");
7711 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||
7712 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7713 (exp.op.exp2.expType._class.registered.type == normalClass ||
7714 exp.op.exp2.expType._class.registered.type == structClass ||
7715 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7717 if(exp.op.op == ADD_ASSIGN)
7718 Compiler_Error($"cannot add two pointers\n");
7720 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7721 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7723 if(exp.op.op == ADD_ASSIGN)
7724 Compiler_Error($"cannot add two pointers\n");
7728 char type1String[1024];
7729 char type2String[1024];
7730 type1String[0] = '\0';
7731 type2String[0] = '\0';
7733 PrintType(exp.op.exp2.expType, type1String, false, true);
7734 PrintType(type1, type2String, false, true);
7735 ChangeCh(expString, '\n', ' ');
7736 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7740 if(exp.op.exp2.destType == dummy)
7743 exp.op.exp2.destType = null;
7746 type2 = exp.op.exp2.expType;
7749 dummy.kind = voidType;
7751 if(exp.op.op == SIZEOF)
7758 exp.isConstant = true;
7760 // Get type of dereferenced pointer
7761 else if(exp.op.op == '*' && !exp.op.exp1)
7763 exp.expType = Dereference(type2);
7764 if(type2 && type2.kind == classType)
7765 notByReference = true;
7767 else if(exp.op.op == '&' && !exp.op.exp1)
7768 exp.expType = Reference(type2);
7775 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7776 exp.op.exp1.destType = MkClassType("bool");
7777 exp.op.exp1.destType.truth = true;
7778 if(!exp.op.exp1.expType)
7779 ProcessExpressionType(exp.op.exp1);
7781 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7782 FreeType(exp.op.exp1.expType);
7783 exp.op.exp1.expType = MkClassType("bool");
7784 exp.op.exp1.expType.truth = true;
7788 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7789 exp.op.exp2.destType = MkClassType("bool");
7790 exp.op.exp2.destType.truth = true;
7791 if(!exp.op.exp2.expType)
7792 ProcessExpressionType(exp.op.exp2);
7794 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7795 FreeType(exp.op.exp2.expType);
7796 exp.op.exp2.expType = MkClassType("bool");
7797 exp.op.exp2.expType.truth = true;
7800 else if(exp.op.exp1 && exp.op.exp2 &&
7803 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7804 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7805 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7806 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7808 if(type1 && type2 &&
7809 // If either both are class or both are not class
7810 ((type1.kind == classType && strcmp(type1._class.string, "String")) == (type2.kind == classType && strcmp(type2._class.string, "String"))))
7812 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7813 exp.op.exp2.destType = type1;
7815 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7816 exp.op.exp1.destType = type2;
7818 // Warning here for adding Radians + Degrees with no destination type
7819 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7820 type1._class.registered && type1._class.registered.type == unitClass &&
7821 type2._class.registered && type2._class.registered.type == unitClass &&
7822 type1._class.registered != type2._class.registered)
7823 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7824 type1._class.string, type2._class.string, type1._class.string);
7826 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7828 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7831 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7833 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7834 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7837 ProcessExpressionType(exp.op.exp1);
7839 if(type2.kind != pointerType)
7841 ProcessExpressionType(classExp);
7843 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
7844 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7845 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7847 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
7850 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
7851 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7852 MkPointer(null, null), null)))),
7853 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
7855 if(!exp.op.exp2.expType)
7856 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
7858 ProcessExpressionType(exp.op.exp2);
7863 if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
7865 if(type1.kind != classType && type1.type.kind == voidType)
7866 Compiler_Error($"void *: unknown size\n");
7867 exp.expType = type1;
7868 if(type1) type1.refCount++;
7870 else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
7872 if(type2.kind != classType && type2.type.kind == voidType)
7873 Compiler_Error($"void *: unknown size\n");
7874 exp.expType = type2;
7875 if(type2) type2.refCount++;
7877 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
7878 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
7880 Compiler_Warning($"different levels of indirection\n");
7884 bool success = false;
7885 if(type1.kind == pointerType && type2.kind == pointerType)
7887 if(exp.op.op == '+')
7888 Compiler_Error($"cannot add two pointers\n");
7889 else if(exp.op.op == '-')
7891 // Pointer Subtraction gives integer
7892 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
7901 if(type1.type.kind == templateType)
7903 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7906 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7908 ProcessExpressionType(classExp);
7910 exp.type = bracketsExp;
7911 exp.list = MkListOne(MkExpOp(
7912 MkExpBrackets(MkListOne(MkExpOp(
7913 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
7915 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
7917 //MkExpMember(classExp, MkIdentifier("typeSize"))
7919 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7920 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7922 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
7925 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
7926 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7927 MkPointer(null, null), null)))),
7928 MkExpMember(classExp, MkIdentifier("typeSize")))))
7933 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
7942 if(!success && exp.op.exp1.type == constantExp)
7944 // If first expression is constant, try to match that first
7945 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
7947 if(exp.expType) FreeType(exp.expType);
7948 exp.expType = exp.op.exp1.destType;
7949 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
7952 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
7954 if(exp.expType) FreeType(exp.expType);
7955 exp.expType = exp.op.exp2.destType;
7956 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
7962 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
7964 if(exp.expType) FreeType(exp.expType);
7965 exp.expType = exp.op.exp2.destType;
7966 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
7969 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
7971 if(exp.expType) FreeType(exp.expType);
7972 exp.expType = exp.op.exp1.destType;
7973 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
7979 char expString1[10240];
7980 char expString2[10240];
7983 expString1[0] = '\0';
7984 expString2[0] = '\0';
7989 PrintExpression(exp.op.exp1, expString1);
7990 ChangeCh(expString1, '\n', ' ');
7991 PrintExpression(exp.op.exp2, expString2);
7992 ChangeCh(expString2, '\n', ' ');
7993 PrintType(exp.op.exp1.expType, type1, false, true);
7994 PrintType(exp.op.exp2.expType, type2, false, true);
7997 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8001 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8002 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8004 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8005 // Convert e.g. / 4 into / 4.0
8006 exp.op.exp1.destType = type2._class.registered.dataType;
8007 if(type2._class.registered.dataType)
8008 type2._class.registered.dataType.refCount++;
8009 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8010 exp.expType = type2;
8011 if(type2) type2.refCount++;
8013 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8015 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8016 // Convert e.g. / 4 into / 4.0
8017 exp.op.exp2.destType = type1._class.registered.dataType;
8018 if(type1._class.registered.dataType)
8019 type1._class.registered.dataType.refCount++;
8020 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8021 exp.expType = type1;
8022 if(type1) type1.refCount++;
8028 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8030 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8032 if(!type1._class.registered.dataType)
8033 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8034 exp.op.exp2.destType = type1._class.registered.dataType;
8035 exp.op.exp2.destType.refCount++;
8037 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8038 type2 = exp.op.exp2.destType;
8040 exp.expType = type2;
8044 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8046 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8048 if(!type2._class.registered.dataType)
8049 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8050 exp.op.exp1.destType = type2._class.registered.dataType;
8051 exp.op.exp1.destType.refCount++;
8053 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8054 type1 = exp.op.exp1.destType;
8055 exp.expType = type1;
8059 // TESTING THIS NEW CODE
8060 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8062 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8064 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8066 if(exp.expType) FreeType(exp.expType);
8067 exp.expType = exp.op.exp1.expType;
8068 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8073 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8075 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8077 if(exp.expType) FreeType(exp.expType);
8078 exp.expType = exp.op.exp2.expType;
8079 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8087 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8088 exp.op.exp2.destType = type1;
8092 // Maybe this was meant to be an enum...
8093 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8095 Type oldType = exp.op.exp2.expType;
8096 exp.op.exp2.expType = null;
8097 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8100 exp.op.exp2.expType = oldType;
8105 // TESTING THIS HERE... LATEST ADDITION
8106 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8108 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8109 exp.op.exp2.destType = type2._class.registered.dataType;
8110 if(type2._class.registered.dataType)
8111 type2._class.registered.dataType.refCount++;
8112 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8114 //exp.expType = type2._class.registered.dataType; //type2;
8115 //if(type2) type2.refCount++;
8118 // TESTING THIS HERE... LATEST ADDITION
8119 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8121 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8122 exp.op.exp1.destType = type1._class.registered.dataType;
8123 if(type1._class.registered.dataType)
8124 type1._class.registered.dataType.refCount++;
8125 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8126 exp.expType = type1._class.registered.dataType; //type1;
8127 if(type1) type1.refCount++;
8131 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8133 if(exp.expType) FreeType(exp.expType);
8134 exp.expType = exp.op.exp2.destType;
8135 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8137 else if(type1 && type2)
8139 char expString1[10240];
8140 char expString2[10240];
8141 char type1String[1024];
8142 char type2String[1024];
8143 expString1[0] = '\0';
8144 expString2[0] = '\0';
8145 type1String[0] = '\0';
8146 type2String[0] = '\0';
8149 PrintExpression(exp.op.exp1, expString1);
8150 ChangeCh(expString1, '\n', ' ');
8151 PrintExpression(exp.op.exp2, expString2);
8152 ChangeCh(expString2, '\n', ' ');
8153 PrintType(exp.op.exp1.expType, type1String, false, true);
8154 PrintType(exp.op.exp2.expType, type2String, false, true);
8157 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8159 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8161 exp.expType = exp.op.exp1.expType;
8162 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8164 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8166 exp.expType = exp.op.exp2.expType;
8167 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8174 // Maybe this was meant to be an enum...
8175 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8177 Type oldType = exp.op.exp1.expType;
8178 exp.op.exp1.expType = null;
8179 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8182 exp.op.exp1.expType = oldType;
8185 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8186 exp.op.exp1.destType = type2;
8189 // TESTING THIS HERE... LATEST ADDITION
8190 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8192 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8193 exp.op.exp1.destType = type1._class.registered.dataType;
8194 if(type1._class.registered.dataType)
8195 type1._class.registered.dataType.refCount++;
8198 // TESTING THIS HERE... LATEST ADDITION
8199 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8201 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8202 exp.op.exp2.destType = type2._class.registered.dataType;
8203 if(type2._class.registered.dataType)
8204 type2._class.registered.dataType.refCount++;
8208 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8210 if(exp.expType) FreeType(exp.expType);
8211 exp.expType = exp.op.exp1.destType;
8212 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8216 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8218 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8220 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8221 // Convert e.g. / 4 into / 4.0
8222 exp.op.exp1.destType = type2._class.registered.dataType;
8223 if(type2._class.registered.dataType)
8224 type2._class.registered.dataType.refCount++;
8225 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8227 if(exp.op.op == '!')
8229 exp.expType = MkClassType("bool");
8230 exp.expType.truth = true;
8234 exp.expType = type2;
8235 if(type2) type2.refCount++;
8238 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8240 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8242 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8243 // Convert e.g. / 4 into / 4.0
8244 exp.op.exp2.destType = type1._class.registered.dataType;
8245 if(type1._class.registered.dataType)
8246 type1._class.registered.dataType.refCount++;
8247 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8249 exp.expType = type1;
8250 if(type1) type1.refCount++;
8255 if(exp.op.exp1 && !exp.op.exp1.expType)
8257 char expString[10000];
8258 expString[0] = '\0';
8261 PrintExpression(exp.op.exp1, expString);
8262 ChangeCh(expString, '\n', ' ');
8265 Compiler_Error($"couldn't determine type of %s\n", expString);
8267 if(exp.op.exp2 && !exp.op.exp2.expType)
8269 char expString[10240];
8270 expString[0] = '\0';
8273 PrintExpression(exp.op.exp2, expString);
8274 ChangeCh(expString, '\n', ' ');
8277 Compiler_Error($"couldn't determine type of %s\n", expString);
8282 FreeType(exp.expType);
8283 exp.expType = MkClassType("bool");
8284 exp.expType.truth = true;
8287 if(exp.op.op != SIZEOF)
8288 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8289 (!exp.op.exp2 || exp.op.exp2.isConstant);
8291 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8293 DeclareType(exp.op.exp2.expType, false, false);
8302 case extensionExpressionExp:
8305 exp.isConstant = true;
8306 for(e = exp.list->first; e; e = e.next)
8311 FreeType(e.destType);
8312 e.destType = exp.destType;
8313 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8315 ProcessExpressionType(e);
8317 exp.destType.count--;
8318 if(!exp.expType && !e.next)
8320 exp.expType = e.expType;
8321 if(e.expType) e.expType.refCount++;
8324 exp.isConstant = false;
8327 // In case a cast became a member...
8328 e = exp.list->first;
8329 if(!e.next && e.type == memberExp)
8331 // Preserve prev, next
8332 Expression next = exp.next, prev = exp.prev;
8335 FreeType(exp.expType);
8336 FreeType(exp.destType);
8346 ProcessExpressionType(exp);
8353 exp.isConstant = true;
8355 ProcessExpressionType(exp.index.exp);
8356 if(!exp.index.exp.isConstant)
8357 exp.isConstant = false;
8359 if(exp.index.exp.expType)
8361 Type source = exp.index.exp.expType;
8362 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8363 eClass_IsDerived(source._class.registered, containerClass) &&
8364 source._class.registered.templateArgs)
8366 Class _class = source._class.registered;
8367 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8369 if(exp.index.index && exp.index.index->last)
8371 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8376 for(e = exp.index.index->first; e; e = e.next)
8378 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8380 if(e.destType) FreeType(e.destType);
8381 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8383 ProcessExpressionType(e);
8386 // Check if this type is int
8389 exp.isConstant = false;
8393 exp.expType = Dereference(exp.index.exp.expType);
8395 DeclareType(exp.expType, false, false);
8402 Type methodType = null;
8408 PrintExpression(exp.call.exp, name);
8409 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8411 //exp.call.exp.expType = null;
8412 PrintExpression(exp.call.exp, name);
8415 if(exp.call.exp.type == identifierExp)
8417 Expression idExp = exp.call.exp;
8418 Identifier id = idExp.identifier;
8419 if(!strcmp(id.string, "__ENDIAN_PAD"))
8421 exp.expType = ProcessTypeString("int", true);
8422 if(exp.call.arguments && exp.call.arguments->first)
8423 ProcessExpressionType(exp.call.arguments->first);
8426 else if(!strcmp(id.string, "Max") ||
8427 !strcmp(id.string, "Min") ||
8428 !strcmp(id.string, "Sgn") ||
8429 !strcmp(id.string, "Abs"))
8431 Expression a = null;
8432 Expression b = null;
8433 Expression tempExp1 = null, tempExp2 = null;
8434 if((!strcmp(id.string, "Max") ||
8435 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8437 a = exp.call.arguments->first;
8438 b = exp.call.arguments->last;
8442 else if(exp.call.arguments->count == 1)
8444 a = exp.call.arguments->first;
8450 exp.call.arguments->Clear();
8451 idExp.identifier = null;
8453 FreeExpContents(exp);
8455 ProcessExpressionType(a);
8457 ProcessExpressionType(b);
8459 exp.type = bracketsExp;
8460 exp.list = MkList();
8462 if(a.expType && (!b || b.expType))
8464 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8466 // Use the simpleStruct name/ids for now...
8469 OldList * specs = MkList();
8470 OldList * decls = MkList();
8472 char temp1[1024], temp2[1024];
8474 GetTypeSpecs(a.expType, specs);
8476 if(a && !a.isConstant && a.type != identifierExp)
8478 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8479 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8480 tempExp1 = QMkExpId(temp1);
8481 tempExp1.expType = a.expType;
8483 a.expType.refCount++;
8484 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8486 if(b && !b.isConstant && b.type != identifierExp)
8488 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8489 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8490 tempExp2 = QMkExpId(temp2);
8491 tempExp2.expType = b.expType;
8493 b.expType.refCount++;
8494 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8497 decl = MkDeclaration(specs, decls);
8498 if(!curCompound.compound.declarations)
8499 curCompound.compound.declarations = MkList();
8500 curCompound.compound.declarations->Insert(null, decl);
8505 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8507 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8509 MkExpCondition(MkExpBrackets(MkListOne(
8510 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8511 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8512 exp.expType = a.expType;
8514 a.expType.refCount++;
8516 else if(!strcmp(id.string, "Abs"))
8519 MkExpCondition(MkExpBrackets(MkListOne(
8520 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8521 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8522 exp.expType = a.expType;
8524 a.expType.refCount++;
8526 else if(!strcmp(id.string, "Sgn"))
8528 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8530 MkExpCondition(MkExpBrackets(MkListOne(
8531 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8532 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8533 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8534 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8535 exp.expType = ProcessTypeString("int", false);
8538 FreeExpression(tempExp1);
8539 if(tempExp2) FreeExpression(tempExp2);
8553 if(!exp.call.exp.destType)
8555 exp.call.exp.destType = dummy;
8558 ProcessExpressionType(exp.call.exp);
8559 if(exp.call.exp.destType == dummy)
8562 exp.call.exp.destType = null;
8567 // Check argument types against parameter types
8568 functionType = exp.call.exp.expType;
8570 if(functionType && functionType.kind == TypeKind::methodType)
8572 methodType = functionType;
8573 functionType = methodType.method.dataType;
8575 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8576 // TOCHECK: Instead of doing this here could this be done per param?
8577 if(exp.call.exp.expType.usedClass)
8579 char typeString[1024];
8580 typeString[0] = '\0';
8581 PrintType(functionType, typeString, true, true);
8582 if(strstr(typeString, "thisclass"))
8584 OldList * specs = MkList();
8587 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8589 decl = SpecDeclFromString(typeString, specs, null);
8591 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8592 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8593 exp.call.exp.expType.usedClass))
8594 thisClassParams = false;
8596 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8598 Class backupThisClass = thisClass;
8599 thisClass = exp.call.exp.expType.usedClass;
8600 ProcessDeclarator(decl);
8601 thisClass = backupThisClass;
8604 thisClassParams = true;
8606 functionType = ProcessType(specs, decl);
8607 functionType.refCount = 0;
8608 FinishTemplatesContext(context);
8611 FreeList(specs, FreeSpecifier);
8612 FreeDeclarator(decl);
8616 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8618 Type type = functionType.type;
8619 if(!functionType.refCount)
8621 functionType.type = null;
8622 FreeType(functionType);
8624 //methodType = functionType;
8625 functionType = type;
8627 if(functionType && functionType.kind != TypeKind::functionType)
8629 Compiler_Error($"called object %s is not a function\n", name);
8631 else if(functionType)
8633 bool emptyParams = false, noParams = false;
8634 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8635 Type type = functionType.params.first;
8636 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8638 Location oldyylloc = yylloc;
8640 if(!type) emptyParams = true;
8643 if(functionType.extraParam && e)
8645 e.destType = MkClassType(functionType.thisClass.string);
8649 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8650 if(!functionType.staticMethod)
8652 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8653 memberExp.member.exp.expType._class)
8655 type = MkClassType(memberExp.member.exp.expType._class.string);
8660 type = functionType.params.first;
8665 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8667 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8672 type = functionType.params.first;
8680 if(type && type.kind == voidType)
8683 if(!type.refCount) FreeType(type);
8687 for( ; e; e = e.next)
8689 if(!type && !emptyParams)
8692 if(methodType && methodType.methodClass)
8693 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8694 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8695 noParams ? 0 : functionType.params.count);
8697 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8698 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8699 noParams ? 0 : functionType.params.count);
8703 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8705 Type templatedType = null;
8706 Class _class = methodType.usedClass;
8707 ClassTemplateParameter curParam = null;
8709 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8712 for(sClass = _class; sClass; sClass = sClass.base)
8714 if(sClass.templateClass) sClass = sClass.templateClass;
8716 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8718 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8721 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8723 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8724 id += nextClass.templateParams.count;
8733 if(curParam && _class.templateArgs[id].dataTypeString)
8735 ClassTemplateArgument arg = _class.templateArgs[id];
8737 Context context = SetupTemplatesContext(_class);
8740 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8741 templatedType = ProcessTypeString(arg.dataTypeString, false);
8742 FinishTemplatesContext(context);
8744 e.destType = templatedType;
8747 templatedType.passAsTemplate = true;
8748 // templatedType.refCount++;
8754 if(type) type.refCount++;
8760 if(type) type.refCount++;
8762 // Don't reach the end for the ellipsis
8763 if(type && type.kind != ellipsisType)
8765 Type next = type.next;
8766 if(!type.refCount) FreeType(type);
8771 if(type && type.kind != ellipsisType)
8773 if(methodType && methodType.methodClass)
8774 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8775 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8776 functionType.params.count + extra);
8778 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8779 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8780 functionType.params.count + extra);
8783 if(type && !type.refCount) FreeType(type);
8790 kind = TypeKind::functionType;
8793 if(exp.call.exp.type == identifierExp)
8795 char * string = exp.call.exp.identifier.string;
8799 Location oldyylloc = yylloc;
8801 yylloc = exp.call.exp.identifier.loc;
8802 if(strstr(string, "__builtin_") == string);
8804 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8805 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8806 globalContext.symbols.Add((BTNode)symbol);
8807 if(strstr(symbol.string, "::"))
8808 globalContext.hasNameSpace = true;
8813 else if(exp.call.exp.type == memberExp)
8815 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8816 exp.call.exp.member.member.string);*/
8819 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8821 if(!functionType.returnType)
8823 functionType.returnType = Type
8830 if(functionType && functionType.kind == TypeKind::functionType)
8832 exp.expType = functionType.returnType;
8834 if(functionType.returnType)
8835 functionType.returnType.refCount++;
8837 if(!functionType.refCount)
8838 FreeType(functionType);
8841 if(exp.call.arguments)
8843 for(e = exp.call.arguments->first; e; e = e.next)
8845 Type destType = e.destType;
8846 ProcessExpressionType(e);
8854 Location oldyylloc = yylloc;
8855 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
8856 exp.thisPtr = thisPtr;
8858 // DOING THIS LATER NOW...
8859 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
8861 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
8862 /* TODO: Name Space Fix ups
8863 if(!exp.member.member.classSym)
8864 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
8868 ProcessExpressionType(exp.member.exp);
8869 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
8870 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
8872 exp.isConstant = false;
8875 exp.isConstant = exp.member.exp.isConstant;
8876 type = exp.member.exp.expType;
8880 if(type && (type.kind == templateType))
8882 Class _class = thisClass ? thisClass : currentClass;
8883 ClassTemplateParameter param = null;
8886 for(param = _class.templateParams.first; param; param = param.next)
8888 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
8892 if(param && param.defaultArg.member)
8894 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
8897 Expression expMember = exp.member.exp;
8899 OldList * specs = MkList();
8900 char thisClassTypeString[1024];
8902 FreeIdentifier(exp.member.member);
8904 ProcessExpressionType(argExp);
8907 char * colon = strstr(param.defaultArg.memberString, "::");
8910 char className[1024];
8913 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
8914 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
8917 strcpy(thisClassTypeString, _class.fullName);
8920 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
8922 exp.expType = ProcessType(specs, decl);
8923 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
8925 Class expClass = exp.expType._class.registered;
8926 Class cClass = null;
8931 char templateString[1024];
8932 ClassTemplateParameter param;
8933 sprintf(templateString, "%s<", expClass.templateClass.fullName);
8934 for(cClass = expClass; cClass; cClass = cClass.base)
8937 for(param = cClass.templateParams.first; param; param = param.next)
8941 ClassTemplateArgument arg;
8942 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
8943 arg = expClass.templateArgs[id];
8945 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
8947 ClassTemplateParameter cParam;
8948 //int p = numParams - sClass.templateParams.count;
8951 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
8953 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
8955 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
8957 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
8959 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
8960 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
8972 strcat(argument, arg.name.string);
8973 strcat(argument, " = ");
8979 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
8980 char expString[1024];
8981 OldList * specs = MkList();
8982 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
8984 char * string = PrintHexUInt64(arg.expression.ui64);
8985 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
8987 ProcessExpressionType(exp);
8988 ComputeExpression(exp);
8989 expString[0] = '\0';
8990 PrintExpression(exp, expString);
8991 strcat(argument, expString);
8993 FreeExpression(exp);
8998 strcat(argument, arg.member.name);
9001 case TemplateParameterType::type:
9003 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9005 if(!strcmp(arg.dataTypeString, "thisclass"))
9006 strcat(argument, thisClassTypeString);
9008 strcat(argument, arg.dataTypeString);
9015 if(paramCount) strcat(templateString, ", ");
9016 if(lastParam != p - 1)
9018 strcat(templateString, param.name);
9019 strcat(templateString, " = ");
9021 strcat(templateString, argument);
9030 int len = strlen(templateString);
9031 if(templateString[len-1] == '>') templateString[len++] = ' ';
9032 templateString[len++] = '>';
9033 templateString[len++] = '\0';
9036 Context context = SetupTemplatesContext(_class);
9037 FreeType(exp.expType);
9038 exp.expType = ProcessTypeString(templateString, false);
9039 FinishTemplatesContext(context);
9043 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9044 exp.type = bracketsExp;
9045 exp.list = MkListOne(MkExpOp(null, '*',
9050 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9051 MkExpBrackets(MkListOne(
9052 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9054 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9056 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9061 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9062 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9064 type = ProcessTemplateParameterType(type.templateParameter);
9068 if(type && (type.kind == templateType));
9069 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9071 Identifier id = exp.member.member;
9072 TypeKind typeKind = type.kind;
9073 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9074 if(typeKind == subClassType && exp.member.exp.type == classExp)
9076 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9077 typeKind = classType;
9080 if(id && (typeKind == intType || typeKind == enumType))
9081 _class = eSystem_FindClass(privateModule, "int");
9086 (exp.member.exp.type == identifierExp &&
9087 !strcmp(exp.member.exp.identifier.string, "this"));*/
9088 Property prop = null;
9089 Method method = null;
9090 DataMember member = null;
9091 Property revConvert = null;
9092 ClassProperty classProp = null;
9094 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9095 exp.member.memberType = propertyMember;
9097 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9098 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9100 if(typeKind != subClassType)
9102 // Prioritize data members over properties for "this"
9103 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9105 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9106 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9108 prop = eClass_FindProperty(_class, id.string, privateModule);
9112 if(!member && !prop)
9113 prop = eClass_FindProperty(_class, id.string, privateModule);
9114 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9115 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9116 exp.member.thisPtr = true;
9118 // Prioritize properties over data members otherwise
9121 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9124 prop = eClass_FindProperty(_class, id.string, null);
9125 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9126 member = eClass_FindDataMember(_class, id.string, null, null, null);
9129 if(!prop && !member)
9131 method = eClass_FindMethod(_class, id.string, null);
9134 prop = eClass_FindProperty(_class, id.string, privateModule);
9135 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9136 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9142 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9149 if(!prop && !member)
9150 method = eClass_FindMethod(_class, id.string, privateModule);
9151 if(!prop && !member && !method)
9153 if(typeKind == subClassType)
9155 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9158 exp.member.memberType = classPropertyMember;
9159 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9163 // Assume this is a class_data member
9164 char structName[1024];
9165 Identifier id = exp.member.member;
9166 Expression classExp = exp.member.exp;
9169 FreeType(classExp.expType);
9170 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9172 strcpy(structName, "__ecereClassData_");
9173 FullClassNameCat(structName, type._class.string, false);
9174 exp.type = pointerExp;
9175 exp.member.member = id;
9177 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9178 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9179 MkExpBrackets(MkListOne(MkExpOp(
9180 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9181 MkExpMember(classExp, MkIdentifier("data"))), '+',
9182 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9187 ProcessExpressionType(exp);
9193 // Check for reverse conversion
9194 // (Convert in an instantiation later, so that we can use
9195 // deep properties system)
9196 Symbol classSym = FindClass(id.string);
9199 Class convertClass = classSym.registered;
9201 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9208 exp.member.memberType = propertyMember;
9210 ProcessPropertyType(prop);
9211 exp.expType = prop.dataType;
9212 if(prop.dataType) prop.dataType.refCount++;
9216 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9218 FreeExpContents(exp);
9219 exp.type = identifierExp;
9220 exp.identifier = MkIdentifier("class");
9221 ProcessExpressionType(exp);
9225 exp.member.memberType = dataMember;
9226 DeclareStruct(_class.fullName, false);
9227 if(!member.dataType)
9229 Context context = SetupTemplatesContext(_class);
9230 member.dataType = ProcessTypeString(member.dataTypeString, false);
9231 FinishTemplatesContext(context);
9233 exp.expType = member.dataType;
9234 if(member.dataType) member.dataType.refCount++;
9238 exp.member.memberType = reverseConversionMember;
9239 exp.expType = MkClassType(revConvert._class.fullName);
9247 exp.type = identifierExp;
9248 exp.identifier = exp.member.member;
9251 exp.member.memberType = methodMember;
9253 if(!method.dataType)
9254 ProcessMethodType(method);
9262 // Tricky spot here... To use instance versus class virtual table
9263 // Put it back to what it was... What did we break?
9265 // Had to put it back for overriding Main of Thread global instance
9267 //exp.expType.methodClass = _class;
9268 exp.expType.methodClass = (id && id._class) ? _class : null;
9270 // Need the actual class used for templated classes
9271 exp.expType.usedClass = _class;
9275 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9277 FreeExpContents(exp);
9278 exp.type = identifierExp;
9279 exp.identifier = MkIdentifier("class");
9280 ProcessExpressionType(exp);
9283 yylloc = exp.member.member.loc;
9284 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9286 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9289 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9294 while(tClass && !tClass.templateClass) tClass = tClass.base;
9296 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9299 ClassTemplateParameter curParam;
9302 for(sClass = tClass; sClass; sClass = sClass.base)
9305 if(sClass.templateClass) sClass = sClass.templateClass;
9306 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9308 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9310 for(sClass = sClass.base; sClass; sClass = sClass.base)
9311 id += sClass.templateParams.count;
9319 if(curParam && tClass.templateArgs[id].dataTypeString)
9321 ClassTemplateArgument arg = tClass.templateArgs[id];
9322 Context context = SetupTemplatesContext(tClass);
9324 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9325 FreeType(exp.expType);
9326 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9329 if(exp.expType.kind == thisClassType)
9331 FreeType(exp.expType);
9332 exp.expType = ReplaceThisClassType(_class);
9335 if(tClass.templateClass)
9336 exp.expType.passAsTemplate = true;
9337 //exp.expType.refCount++;
9340 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9341 //exp.destType.refCount++;
9343 if(exp.destType.kind == thisClassType)
9345 FreeType(exp.destType);
9346 exp.destType = ReplaceThisClassType(_class);
9350 FinishTemplatesContext(context);
9353 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9354 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9357 ClassTemplateParameter curParam;
9360 for(sClass = tClass; sClass; sClass = sClass.base)
9363 if(sClass.templateClass) sClass = sClass.templateClass;
9364 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9366 if(curParam.type == TemplateParameterType::type &&
9367 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9369 for(sClass = sClass.base; sClass; sClass = sClass.base)
9370 id += sClass.templateParams.count;
9380 ClassTemplateArgument arg = tClass.templateArgs[id];
9381 Context context = SetupTemplatesContext(tClass);
9384 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9386 basicType = ProcessTypeString(arg.dataTypeString, false);
9389 if(basicType.kind == thisClassType)
9391 FreeType(basicType);
9392 basicType = ReplaceThisClassType(_class);
9395 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9396 if(tClass.templateClass)
9397 basicType.passAsTemplate = true;
9400 FreeType(exp.expType);
9402 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9403 //exp.expType.refCount++;
9406 exp.destType = exp.expType;
9407 exp.destType.refCount++;
9411 Expression newExp { };
9412 OldList * specs = MkList();
9414 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9416 if(exp.destType) exp.destType.refCount++;
9417 if(exp.expType) exp.expType.refCount++;
9419 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9420 exp.cast.exp = newExp;
9421 //FreeType(exp.expType);
9422 //exp.expType = null;
9423 //ProcessExpressionType(sourceExp);
9426 FinishTemplatesContext(context);
9429 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9431 Class expClass = exp.expType._class.registered;
9434 Class cClass = null;
9439 char templateString[1024];
9440 ClassTemplateParameter param;
9441 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9442 while(cClass != expClass)
9445 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9448 for(param = cClass.templateParams.first; param; param = param.next)
9450 Class cClassCur = null;
9453 ClassTemplateParameter paramCur = null;
9454 ClassTemplateArgument arg;
9455 while(cClassCur != tClass && !paramCur)
9458 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9459 cClassCur = sClassCur;
9461 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9463 if(!strcmp(paramCur.name, param.name))
9471 if(paramCur && paramCur.type == TemplateParameterType::type)
9472 arg = tClass.templateArgs[cp];
9474 arg = expClass.templateArgs[p];
9481 strcat(argument, arg.name.string);
9482 strcat(argument, " = ");
9488 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9489 char expString[1024];
9490 OldList * specs = MkList();
9491 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9493 char * string = PrintHexUInt64(arg.expression.ui64);
9494 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9496 ProcessExpressionType(exp);
9497 ComputeExpression(exp);
9498 expString[0] = '\0';
9499 PrintExpression(exp, expString);
9500 strcat(argument, expString);
9502 FreeExpression(exp);
9507 strcat(argument, arg.member.name);
9510 case TemplateParameterType::type:
9512 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9513 strcat(argument, arg.dataTypeString);
9519 if(paramCount) strcat(templateString, ", ");
9520 if(lastParam != p - 1)
9522 strcat(templateString, param.name);
9523 strcat(templateString, " = ");
9525 strcat(templateString, argument);
9534 int len = strlen(templateString);
9535 if(templateString[len-1] == '>') templateString[len++] = ' ';
9536 templateString[len++] = '>';
9537 templateString[len++] = '\0';
9540 FreeType(exp.expType);
9542 Context context = SetupTemplatesContext(tClass);
9543 exp.expType = ProcessTypeString(templateString, false);
9544 FinishTemplatesContext(context);
9551 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9553 else if(type && (type.kind == structType || type.kind == unionType))
9555 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9558 exp.expType = memberType;
9560 memberType.refCount++;
9565 char expString[10240];
9566 expString[0] = '\0';
9567 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9568 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9571 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9573 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9575 Identifier id = exp.member.member;
9576 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9579 FreeType(exp.expType);
9580 exp.expType = ReplaceThisClassType(_class);
9587 // Convert x->y into (*x).y
9590 Type destType = exp.destType;
9592 // DOING THIS LATER NOW...
9593 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9595 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9596 /* TODO: Name Space Fix ups
9597 if(!exp.member.member.classSym)
9598 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9602 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9603 exp.type = memberExp;
9606 ProcessExpressionType(exp);
9613 //ComputeExpression(exp);
9615 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9616 if(classSym && classSym.registered)
9618 if(classSym.registered.type == noHeadClass)
9622 DeclareStruct(classSym.string, false);
9623 FreeSpecifier(exp._class);
9624 exp.type = typeSizeExp;
9625 FullClassNameCat(name, classSym.string, false);
9626 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9630 if(classSym.registered.fixed)
9632 FreeSpecifier(exp._class);
9633 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9634 exp.type = constantExp;
9638 char className[1024];
9639 strcpy(className, "__ecereClass_");
9640 FullClassNameCat(className, classSym.string, true);
9641 MangleClassName(className);
9643 DeclareClass(classSym, className);
9645 FreeExpContents(exp);
9646 exp.type = pointerExp;
9647 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9648 exp.member.member = MkIdentifier("structSize");
9658 // exp.isConstant = true;
9663 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9670 exp.isConstant = true;
9672 DeclareType(type, false, false);
9678 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9680 FreeType(exp.cast.exp.destType);
9681 exp.cast.exp.destType = type;
9683 ProcessExpressionType(exp.cast.exp);
9688 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9689 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9691 void * prev = exp.prev, * next = exp.next;
9692 Type expType = exp.cast.exp.destType;
9693 Expression castExp = exp.cast.exp;
9694 Type destType = exp.destType;
9696 if(expType) expType.refCount++;
9698 //FreeType(exp.destType);
9699 FreeType(exp.expType);
9700 FreeTypeName(exp.cast.typeName);
9703 FreeType(exp.expType);
9704 FreeType(exp.destType);
9706 exp.expType = expType;
9707 exp.destType = destType;
9717 exp.isConstant = exp.cast.exp.isConstant;
9722 case extensionInitializerExp:
9724 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9726 // ProcessInitializer(exp.initializer.initializer, type);
9732 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9733 ProcessExpressionType(exp.vaArg.exp);
9741 exp.isConstant = true;
9743 FreeType(exp.cond.cond.destType);
9744 exp.cond.cond.destType = MkClassType("bool");
9745 exp.cond.cond.destType.truth = true;
9746 ProcessExpressionType(exp.cond.cond);
9747 if(!exp.cond.cond.isConstant)
9748 exp.isConstant = false;
9749 for(e = exp.cond.exp->first; e; e = e.next)
9753 FreeType(e.destType);
9754 e.destType = exp.destType;
9755 if(e.destType) e.destType.refCount++;
9757 ProcessExpressionType(e);
9760 exp.expType = e.expType;
9761 if(e.expType) e.expType.refCount++;
9764 exp.isConstant = false;
9767 FreeType(exp.cond.elseExp.destType);
9768 // Added this check if we failed to find an expType
9769 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9772 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9774 if(exp.cond.elseExp.destType)
9775 exp.cond.elseExp.destType.refCount++;
9776 ProcessExpressionType(exp.cond.elseExp);
9778 // FIXED THIS: Was done before calling process on elseExp
9779 if(!exp.cond.elseExp.isConstant)
9780 exp.isConstant = false;
9783 case extensionCompoundExp:
9785 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9787 Statement last = exp.compound.compound.statements->last;
9788 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9790 ((Expression)last.expressions->last).destType = exp.destType;
9792 exp.destType.refCount++;
9794 ProcessStatement(exp.compound);
9795 exp.expType = ((Expression)last.expressions->last).expType;
9796 if(((Expression)last.expressions->last).expType)
9797 exp.expType.refCount++;
9803 Specifier spec = exp._classExp.specifiers->first;
9804 if(spec && spec.type == nameSpecifier)
9806 exp.expType = MkClassType(spec.name);
9807 exp.expType.kind = subClassType;
9808 exp.byReference = true;
9812 exp.expType = MkClassType("ecere::com::Class");
9813 exp.byReference = true;
9819 Class _class = thisClass ? thisClass : currentClass;
9822 Identifier id = exp.classData.id;
9823 char structName[1024];
9824 Expression classExp;
9825 strcpy(structName, "__ecereClassData_");
9826 FullClassNameCat(structName, _class.fullName, false);
9827 exp.type = pointerExp;
9828 exp.member.member = id;
9829 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9830 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9832 classExp = MkExpIdentifier(MkIdentifier("class"));
9834 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9835 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9836 MkExpBrackets(MkListOne(MkExpOp(
9837 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9838 MkExpMember(classExp, MkIdentifier("data"))), '+',
9839 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
9842 ProcessExpressionType(exp);
9850 char * typeString = null;
9851 char typeStringBuf[1024];
9852 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
9853 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
9855 Class templateClass = exp.destType._class.registered;
9856 typeString = templateClass.templateArgs[2].dataTypeString;
9860 // Guess type from expressions in the array
9862 for(e = exp.list->first; e; e = e.next)
9864 ProcessExpressionType(e);
9867 if(!type) { type = e.expType; type.refCount++; }
9870 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
9871 if(!MatchTypeExpression(e, type, null, false))
9877 e = exp.list->first;
9878 ProcessExpressionType(e);
9881 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
9882 if(!MatchTypeExpression(e, type, null, false))
9884 FreeType(e.expType);
9895 FreeType(e.expType);
9902 typeStringBuf[0] = '\0';
9903 PrintType(type, typeStringBuf, false, true);
9904 typeString = typeStringBuf;
9912 (Container)(__extension__( {
9913 int __arrayMembers[] = { 1, 7, 3, 4, 5 };
9914 BuiltInContainer __baseContainer
9916 data = __arrayMembers,
9919 _vTbl = class(BuiltInContainer)._vTbl,
9920 _class = class(BuiltInContainer) };
9925 char templateString[1024];
9926 OldList * declarations = MkList();
9927 OldList * instMembers = MkList();
9928 OldList * specs = MkList();
9929 OldList * initializers = MkList();
9933 Declarator decl = SpecDeclFromString(typeString, specs, null);
9934 Context context = PushContext();
9936 // sprintf(templateString, "Container<%s >", typeString);
9937 sprintf(templateString, "Container<%s>", typeString);
9939 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("data")), MkInitializerAssignment(MkExpIdentifier(MkIdentifier("__internalList")))));
9941 sprintf(count, "%d", exp.list->count);
9942 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("count")), MkInitializerAssignment(MkExpConstant(count))));
9944 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("type")), MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier),
9945 CopyDeclarator(decl)))));
9947 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_vTbl")), MkInitializerAssignment(MkExpMember(
9948 MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl")))));
9950 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_class")), MkInitializerAssignment(
9951 MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null))));
9955 type = ProcessTypeString(typeString, false);
9956 while(e = exp.list->first)
9958 exp.list->Remove(e);
9961 ProcessExpressionType(e);
9962 ListAdd(initializers, MkInitializerAssignment(e));
9968 ListAdd(declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(decl,
9969 MkDeclaratorIdentifier(MkIdentifier("__internalList"))), null),
9970 MkInitializerList(initializers)))));
9971 ListAdd(declarations, MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName("BuiltInContainer")),
9972 MkExpIdentifier(MkIdentifier("__internalContainer")), MkListOne(MkMembersInitList(instMembers)))));
9974 exp.expType = ProcessTypeString(templateString, false);
9975 exp.type = bracketsExp;
9976 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
9977 (expExt = MkExpExtensionCompound(MkCompoundStmt(
9978 declarations, MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internalContainer")))))))))));
9979 expExt.compound.compound.context = context;
9980 PopContext(context);
9981 ProcessExpressionType(expExt);
9985 exp.expType = ProcessTypeString("Container", false);
9986 Compiler_Error($"Couldn't determine type of array elements\n");
9992 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
9994 FreeType(exp.expType);
9995 exp.expType = ReplaceThisClassType(thisClass);
9998 // Resolve structures here
9999 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10001 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10002 // TODO: Fix members reference...
10005 if(exp.expType.kind != enumType)
10008 String enumName = CopyString(exp.expType.enumName);
10010 // Fixed a memory leak on self-referencing C structs typedefs
10011 // by instantiating a new type rather than simply copying members
10012 // into exp.expType
10013 FreeType(exp.expType);
10014 exp.expType = Type { };
10015 exp.expType.kind = symbol.type.kind;
10016 exp.expType.refCount++;
10017 exp.expType.enumName = enumName;
10019 exp.expType.members = symbol.type.members;
10020 for(member = symbol.type.members.first; member; member = member.next)
10026 for(member = symbol.type.members.first; member; member = member.next)
10028 NamedLink value { name = CopyString(member.name) };
10029 exp.expType.members.Add(value);
10036 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10037 else if(exp.destType && !exp.destType.keepCast)
10039 if(!CheckExpressionType(exp, exp.destType, false))
10041 if(!exp.destType.count || unresolved)
10046 if(exp.destType.kind != ellipsisType)
10052 char expString[10240];
10053 expString[0] = '\0';
10055 PrintType(exp.destType, type2, false, true);
10057 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10059 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10060 else if(exp.type != dummyExp)
10061 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10066 char expString[10240] ;
10067 expString[0] = '\0';
10068 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10071 Compiler_Error($"unresolved identifier %s\n", expString);
10072 else if(exp.type != dummyExp)
10073 Compiler_Error($"couldn't determine type of %s\n", expString);
10084 PrintType(exp.expType, type1, false, true);
10085 PrintType(exp.destType, type2, false, true);
10088 //CheckExpressionType(exp, exp.destType, false);
10090 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10091 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10092 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10095 char expString[10240];
10096 expString[0] = '\0';
10097 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10100 CheckExpressionType(exp, exp.destType, false);
10102 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10104 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10105 FreeType(exp.expType);
10106 exp.destType.refCount++;
10107 exp.expType = exp.destType;
10112 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10114 Expression newExp { };
10115 char typeString[1024];
10116 OldList * specs = MkList();
10119 typeString[0] = '\0';
10123 if(exp.expType) exp.expType.refCount++;
10124 if(exp.expType) exp.expType.refCount++;
10125 exp.type = castExp;
10126 newExp.destType = exp.expType;
10128 PrintType(exp.expType, typeString, false, false);
10129 decl = SpecDeclFromString(typeString, specs, null);
10131 exp.cast.typeName = MkTypeName(specs, decl);
10132 exp.cast.exp = newExp;
10135 else if(unresolved)
10137 if(exp.identifier._class && exp.identifier._class.name)
10138 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10139 else if(exp.identifier.string && exp.identifier.string[0])
10140 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10142 else if(!exp.expType && exp.type != dummyExp)
10144 char expString[10240];
10145 expString[0] = '\0';
10146 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10147 Compiler_Error($"couldn't determine type of %s\n", expString);
10150 // Let's try to support any_object & typed_object here:
10151 ApplyAnyObjectLogic(exp);
10153 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10154 exp.expType._class.registered.type == noHeadClass)
10156 exp.byReference = true;
10158 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10159 exp.destType._class.registered.type == noHeadClass)
10161 exp.byReference = true;
10163 yylloc = oldyylloc;
10166 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10168 // THIS CODE WILL FIND NEXT MEMBER...
10171 *curMember = (*curMember).next;
10173 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10175 *curMember = subMemberStack[--(*subMemberStackPos)];
10176 *curMember = (*curMember).next;
10179 // SKIP ALL PROPERTIES HERE...
10180 while((*curMember) && (*curMember).isProperty)
10181 *curMember = (*curMember).next;
10183 if(subMemberStackPos)
10185 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10187 subMemberStack[(*subMemberStackPos)++] = *curMember;
10189 *curMember = (*curMember).members.first;
10190 while(*curMember && (*curMember).isProperty)
10191 *curMember = (*curMember).next;
10199 if(subMemberStackPos && *subMemberStackPos)
10201 *curMember = subMemberStack[--(*subMemberStackPos)];
10202 *curMember = (*curMember).next;
10206 Class lastCurClass = *curClass;
10208 if(*curClass == _class) break; // REACHED THE END
10210 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10211 *curMember = (*curClass).membersAndProperties.first;
10214 while((*curMember) && (*curMember).isProperty)
10215 *curMember = (*curMember).next;
10216 if(subMemberStackPos)
10218 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10220 subMemberStack[(*subMemberStackPos)++] = *curMember;
10222 *curMember = (*curMember).members.first;
10223 while(*curMember && (*curMember).isProperty)
10224 *curMember = (*curMember).next;
10232 static void ProcessInitializer(Initializer init, Type type)
10236 case expInitializer:
10237 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10239 // TESTING THIS FOR SHUTTING = 0 WARNING
10240 if(init.exp && !init.exp.destType)
10242 FreeType(init.exp.destType);
10243 init.exp.destType = type;
10244 if(type) type.refCount++;
10248 ProcessExpressionType(init.exp);
10249 init.isConstant = init.exp.isConstant;
10255 Expression exp = init.exp;
10256 Instantiation inst = exp.instance;
10257 MembersInit members;
10259 init.type = listInitializer;
10260 init.list = MkList();
10264 for(members = inst.members->first; members; members = members.next)
10266 if(members.type == dataMembersInit)
10269 for(member = members.dataMembers->first; member; member = member.next)
10271 ListAdd(init.list, member.initializer);
10272 member.initializer = null;
10275 // Discard all MembersInitMethod
10278 FreeExpression(exp);
10280 case listInitializer:
10283 Type initializerType = null;
10284 Class curClass = null;
10285 DataMember curMember = null;
10286 DataMember subMemberStack[256];
10287 int subMemberStackPos = 0;
10289 if(type && type.kind == arrayType)
10290 initializerType = Dereference(type);
10291 else if(type && (type.kind == structType || type.kind == unionType))
10292 initializerType = type.members.first;
10294 for(i = init.list->first; i; i = i.next)
10296 if(type && type.kind == classType && type._class && type._class.registered)
10298 // 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)
10299 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10300 // TODO: Generate error on initializing a private data member this way from another module...
10303 if(!curMember.dataType)
10304 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10305 initializerType = curMember.dataType;
10308 ProcessInitializer(i, initializerType);
10309 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10310 initializerType = initializerType.next;
10312 init.isConstant = false;
10315 if(type && type.kind == arrayType)
10316 FreeType(initializerType);
10318 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10320 Compiler_Error($"Assigning list initializer to non list\n");
10327 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10331 case baseSpecifier:
10333 if(spec.specifier == THISCLASS)
10337 spec.type = nameSpecifier;
10338 spec.name = ReplaceThisClass(thisClass);
10339 spec.symbol = FindClass(spec.name);
10340 ProcessSpecifier(spec, declareStruct);
10345 case nameSpecifier:
10347 Symbol symbol = FindType(curContext, spec.name);
10349 DeclareType(symbol.type, true, true);
10350 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10351 DeclareStruct(spec.name, false);
10354 case enumSpecifier:
10359 for(e = spec.list->first; e; e = e.next)
10362 ProcessExpressionType(e.exp);
10367 case structSpecifier:
10368 case unionSpecifier:
10370 if(spec.definitions)
10373 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10375 ProcessClass(spec.definitions, symbol);
10378 for(def = spec.definitions->first; def; def = def.next)
10380 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10381 ProcessDeclaration(def.decl);
10388 case classSpecifier:
10390 Symbol classSym = FindClass(spec.name);
10391 if(classSym && classSym.registered && classSym.registered.type == structClass)
10392 DeclareStruct(spec.name, false);
10400 static void ProcessDeclarator(Declarator decl)
10404 case identifierDeclarator:
10405 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10407 FreeSpecifier(decl.identifier._class);
10408 decl.identifier._class = null;
10411 case arrayDeclarator:
10413 ProcessExpressionType(decl.array.exp);
10414 case structDeclarator:
10415 case bracketsDeclarator:
10416 case functionDeclarator:
10417 case pointerDeclarator:
10418 case extendedDeclarator:
10419 case extendedDeclaratorEnd:
10420 if(decl.declarator)
10421 ProcessDeclarator(decl.declarator);
10422 if(decl.type == functionDeclarator)
10424 Identifier id = GetDeclId(decl);
10425 if(id && id._class)
10429 qualifiers = MkListOne(id._class);
10432 if(!decl.function.parameters)
10433 decl.function.parameters = MkList();
10434 decl.function.parameters->Insert(null, param);
10437 if(decl.function.parameters)
10441 for(param = decl.function.parameters->first; param; param = param.next)
10443 if(param.qualifiers && param.qualifiers->first)
10445 Specifier spec = param.qualifiers->first;
10446 if(spec && spec.specifier == TYPED_OBJECT)
10448 Declarator d = param.declarator;
10451 qualifiers = MkListOne(MkSpecifier(VOID));
10452 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10455 FreeList(param.qualifiers, FreeSpecifier);
10457 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10458 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10460 decl.function.parameters->Insert(param, newParam);
10463 else if(spec && spec.specifier == ANY_OBJECT)
10465 Declarator d = param.declarator;
10467 FreeList(param.qualifiers, FreeSpecifier);
10469 param.qualifiers = MkListOne(MkSpecifier(VOID));
10470 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10472 else if(spec.specifier == THISCLASS)
10476 spec.type = nameSpecifier;
10477 spec.name = ReplaceThisClass(thisClass);
10478 spec.symbol = FindClass(spec.name);
10479 ProcessSpecifier(spec, false);
10484 if(param.declarator)
10485 ProcessDeclarator(param.declarator);
10493 static void ProcessDeclaration(Declaration decl)
10498 case initDeclaration:
10500 bool declareStruct = false;
10502 lineNum = decl.pos.line;
10503 column = decl.pos.col;
10506 if(decl.declarators)
10510 for(d = decl.declarators->first; d; d = d.next)
10512 Type type, subType;
10513 ProcessDeclarator(d.declarator);
10515 type = ProcessType(decl.specifiers, d.declarator);
10519 ProcessInitializer(d.initializer, type);
10521 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10523 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10524 d.initializer.exp.type == instanceExp)
10526 if(type.kind == classType && type._class ==
10527 d.initializer.exp.expType._class)
10529 Instantiation inst = d.initializer.exp.instance;
10530 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10532 d.initializer.exp.instance = null;
10533 if(decl.specifiers)
10534 FreeList(decl.specifiers, FreeSpecifier);
10535 FreeList(decl.declarators, FreeInitDeclarator);
10539 decl.type = instDeclaration;
10544 for(subType = type; subType;)
10546 if(subType.kind == classType)
10548 declareStruct = true;
10551 else if(subType.kind == pointerType)
10553 else if(subType.kind == arrayType)
10554 subType = subType.arrayType;
10564 if(decl.specifiers)
10567 for(s = decl.specifiers->first; s; s = s.next)
10569 ProcessSpecifier(s, declareStruct);
10574 case instDeclaration:
10576 ProcessInstantiationType(decl.inst);
10579 case structDeclaration:
10583 bool declareStruct = false;
10585 if(decl.declarators)
10587 for(d = decl.declarators->first; d; d = d.next)
10589 Type type = ProcessType(decl.specifiers, d.declarator);
10591 ProcessDeclarator(d);
10592 for(subType = type; subType;)
10594 if(subType.kind == classType)
10596 declareStruct = true;
10599 else if(subType.kind == pointerType)
10601 else if(subType.kind == arrayType)
10602 subType = subType.arrayType;
10609 if(decl.specifiers)
10611 for(spec = decl.specifiers->first; spec; spec = spec.next)
10612 ProcessSpecifier(spec, declareStruct);
10619 static FunctionDefinition curFunction;
10621 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10623 char propName[1024], propNameM[1024];
10624 char getName[1024], setName[1024];
10627 DeclareProperty(prop, setName, getName);
10629 // eInstance_FireWatchers(object, prop);
10630 strcpy(propName, "__ecereProp_");
10631 FullClassNameCat(propName, prop._class.fullName, false);
10632 strcat(propName, "_");
10633 // strcat(propName, prop.name);
10634 FullClassNameCat(propName, prop.name, true);
10635 MangleClassName(propName);
10637 strcpy(propNameM, "__ecerePropM_");
10638 FullClassNameCat(propNameM, prop._class.fullName, false);
10639 strcat(propNameM, "_");
10640 // strcat(propNameM, prop.name);
10641 FullClassNameCat(propNameM, prop.name, true);
10642 MangleClassName(propNameM);
10644 if(prop.isWatchable)
10647 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10648 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10649 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10652 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10653 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10654 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10660 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10661 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10662 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10665 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10666 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10667 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10670 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10671 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10672 curFunction.propSet.fireWatchersDone = true;
10675 static void ProcessStatement(Statement stmt)
10679 lineNum = stmt.pos.line;
10680 column = stmt.pos.col;
10685 ProcessStatement(stmt.labeled.stmt);
10688 // This expression should be constant...
10689 if(stmt.caseStmt.exp)
10691 FreeType(stmt.caseStmt.exp.destType);
10692 stmt.caseStmt.exp.destType = curSwitchType;
10693 if(curSwitchType) curSwitchType.refCount++;
10694 ProcessExpressionType(stmt.caseStmt.exp);
10695 ComputeExpression(stmt.caseStmt.exp);
10697 if(stmt.caseStmt.stmt)
10698 ProcessStatement(stmt.caseStmt.stmt);
10702 if(stmt.compound.context)
10707 Statement prevCompound = curCompound;
10708 Context prevContext = curContext;
10710 if(!stmt.compound.isSwitch)
10712 curCompound = stmt;
10713 curContext = stmt.compound.context;
10716 if(stmt.compound.declarations)
10718 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10719 ProcessDeclaration(decl);
10721 if(stmt.compound.statements)
10723 for(s = stmt.compound.statements->first; s; s = s.next)
10724 ProcessStatement(s);
10727 curContext = prevContext;
10728 curCompound = prevCompound;
10732 case expressionStmt:
10735 if(stmt.expressions)
10737 for(exp = stmt.expressions->first; exp; exp = exp.next)
10738 ProcessExpressionType(exp);
10746 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10747 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10748 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10749 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10751 ProcessExpressionType(exp);
10753 if(stmt.ifStmt.stmt)
10754 ProcessStatement(stmt.ifStmt.stmt);
10755 if(stmt.ifStmt.elseStmt)
10756 ProcessStatement(stmt.ifStmt.elseStmt);
10761 Type oldSwitchType = curSwitchType;
10762 if(stmt.switchStmt.exp)
10765 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10775 e.exp.destType = destType;
10778 ProcessExpressionType(exp);
10781 curSwitchType = exp.expType;
10784 ProcessStatement(stmt.switchStmt.stmt);
10785 curSwitchType = oldSwitchType;
10790 if(stmt.whileStmt.exp)
10794 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10795 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10796 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10797 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10799 ProcessExpressionType(exp);
10802 if(stmt.whileStmt.stmt)
10803 ProcessStatement(stmt.whileStmt.stmt);
10808 if(stmt.doWhile.exp)
10812 if(stmt.doWhile.exp->last)
10814 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10815 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10816 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10818 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10820 ProcessExpressionType(exp);
10823 if(stmt.doWhile.stmt)
10824 ProcessStatement(stmt.doWhile.stmt);
10830 if(stmt.forStmt.init)
10831 ProcessStatement(stmt.forStmt.init);
10833 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10835 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10836 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10837 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10840 if(stmt.forStmt.check)
10841 ProcessStatement(stmt.forStmt.check);
10842 if(stmt.forStmt.increment)
10844 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10845 ProcessExpressionType(exp);
10848 if(stmt.forStmt.stmt)
10849 ProcessStatement(stmt.forStmt.stmt);
10854 Identifier id = stmt.forEachStmt.id;
10855 OldList * exp = stmt.forEachStmt.exp;
10856 OldList * filter = stmt.forEachStmt.filter;
10857 Statement block = stmt.forEachStmt.stmt;
10858 char iteratorType[1024];
10861 bool isBuiltin = exp && exp->last &&
10862 (((Expression)exp->last).type == ExpressionType::arrayExp ||
10863 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
10864 Expression arrayExp;
10865 char * typeString = null;
10866 int builtinCount = 0;
10868 for(e = exp ? exp->first : null; e; e = e.next)
10872 FreeType(e.destType);
10873 e.destType = ProcessTypeString("Container", false);
10875 if(!isBuiltin || e.next)
10876 ProcessExpressionType(e);
10879 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
10880 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
10881 eClass_IsDerived(source._class.registered, containerClass)))
10883 Class _class = source ? source._class.registered : null;
10885 Expression expIt = null;
10886 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
10887 Class arrayClass = eSystem_FindClass(privateModule, "Array");
10888 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
10889 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
10890 stmt.type = compoundStmt;
10892 stmt.compound.context = Context { };
10893 stmt.compound.context.parent = curContext;
10894 curContext = stmt.compound.context;
10896 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
10898 Class mapClass = eSystem_FindClass(privateModule, "Map");
10899 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
10900 isCustomAVLTree = true;
10901 if(eClass_IsDerived(source._class.registered, avlTreeClass))
10903 else if(eClass_IsDerived(source._class.registered, mapClass))
10906 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
10907 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
10909 Class listClass = eSystem_FindClass(privateModule, "List");
10911 isList = eClass_IsDerived(source._class.registered, listClass);
10917 OldList * specs = MkList();
10918 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
10919 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
10920 stmt.compound.declarations = MkListOne(
10921 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
10922 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
10923 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
10924 MkInitializerAssignment(MkExpBrackets(exp))))));
10929 char typeStringBuf[1024];
10931 // TODO: Merge this code?
10932 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
10933 if(((Expression)exp->last).type == castExp)
10935 TypeName typeName = ((Expression)exp->last).cast.typeName;
10937 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
10940 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
10941 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
10942 arrayExp.destType._class.registered.templateArgs)
10944 Class templateClass = arrayExp.destType._class.registered;
10945 typeString = templateClass.templateArgs[2].dataTypeString;
10947 else if(arrayExp.list)
10949 // Guess type from expressions in the array
10951 for(e = arrayExp.list->first; e; e = e.next)
10953 ProcessExpressionType(e);
10956 if(!type) { type = e.expType; type.refCount++; }
10959 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10960 if(!MatchTypeExpression(e, type, null, false))
10966 e = arrayExp.list->first;
10967 ProcessExpressionType(e);
10970 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
10971 if(!MatchTypeExpression(e, type, null, false))
10973 FreeType(e.expType);
10984 FreeType(e.expType);
10991 typeStringBuf[0] = '\0';
10992 PrintType(type, typeStringBuf, false, true);
10993 typeString = typeStringBuf;
10999 OldList * initializers = MkList();
11001 OldList * specs = MkList();
11006 builtinCount = arrayExp.list->count;
11007 type = ProcessTypeString(typeString, false);
11008 while(e = arrayExp.list->first)
11010 arrayExp.list->Remove(e);
11013 ProcessExpressionType(e);
11014 ListAdd(initializers, MkInitializerAssignment(e));
11017 delete arrayExp.list;
11019 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11020 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11021 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11023 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11024 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11026 FreeList(exp, FreeExpression);
11030 arrayExp.expType = ProcessTypeString("Container", false);
11031 Compiler_Error($"Couldn't determine type of array elements\n");
11036 OldList * specs = MkList();
11038 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11039 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11040 stmt.compound.declarations = MkListOne(
11041 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11042 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11043 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11044 MkInitializerAssignment(MkExpBrackets(exp))))));
11047 else if(isLinkList && !isList)
11050 OldList * specs = MkList();
11051 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11052 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11053 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11054 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11055 MkInitializerAssignment(MkExpBrackets(exp))))));
11057 /*else if(isCustomAVLTree)
11060 OldList * specs = MkList();
11061 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11062 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11063 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11064 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11065 MkInitializerAssignment(MkExpBrackets(exp))))));
11067 else if(_class.templateArgs)
11070 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11072 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11074 stmt.compound.declarations = MkListOne(
11075 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11076 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11077 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11079 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11081 if(block && block.type == compoundStmt && block.compound.context)
11083 block.compound.context.parent = stmt.compound.context;
11087 block = MkIfStmt(filter, block, null);
11091 stmt.compound.statements = MkListOne(MkForStmt(
11092 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11093 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11094 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11095 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11097 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11098 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11099 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11104 //OldList * specs = MkList();
11105 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11107 sprintf(count, "%d", builtinCount);
11109 stmt.compound.statements = MkListOne(MkForStmt(
11110 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11111 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11112 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11113 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11117 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11118 stmt.compound.statements = MkListOne(MkForStmt(
11119 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11120 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11121 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11122 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11125 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11126 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11127 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11129 else if(isLinkList && !isList)
11131 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11132 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11133 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11134 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11136 stmt.compound.statements = MkListOne(MkForStmt(
11137 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11138 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11139 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11144 OldList * specs = MkList();
11145 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11146 stmt.compound.statements = MkListOne(MkForStmt(
11147 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11148 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11149 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11150 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11151 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11154 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11155 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11156 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11158 /*else if(isCustomAVLTree)
11160 stmt.compound.statements = MkListOne(MkForStmt(
11161 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11162 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11163 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11164 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11167 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11168 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11169 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11173 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11174 MkIdentifier("Next")), null)), block));
11176 ProcessExpressionType(expIt);
11177 if(stmt.compound.declarations->first)
11178 ProcessDeclaration(stmt.compound.declarations->first);
11181 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11183 ProcessStatement(stmt);
11184 curContext = stmt.compound.context.parent;
11189 Compiler_Error($"Expression is not a container\n");
11202 if(stmt.expressions)
11204 for(exp = stmt.expressions->first; exp; exp = exp.next)
11208 if(curFunction && !curFunction.type)
11209 curFunction.type = ProcessType(
11210 curFunction.specifiers, curFunction.declarator);
11211 FreeType(exp.destType);
11212 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11213 if(exp.destType) exp.destType.refCount++;
11215 ProcessExpressionType(exp);
11220 case badDeclarationStmt:
11222 ProcessDeclaration(stmt.decl);
11228 if(stmt.asmStmt.inputFields)
11230 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11231 if(field.expression)
11232 ProcessExpressionType(field.expression);
11234 if(stmt.asmStmt.outputFields)
11236 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11237 if(field.expression)
11238 ProcessExpressionType(field.expression);
11240 if(stmt.asmStmt.clobberedFields)
11242 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11244 if(field.expression)
11245 ProcessExpressionType(field.expression);
11252 PropertyWatch propWatch;
11253 OldList * watches = stmt._watch.watches;
11254 Expression object = stmt._watch.object;
11255 Expression watcher = stmt._watch.watcher;
11257 ProcessExpressionType(watcher);
11259 ProcessExpressionType(object);
11263 if(watcher || thisClass)
11265 External external = curExternal;
11266 Context context = curContext;
11268 stmt.type = expressionStmt;
11269 stmt.expressions = MkList();
11271 curExternal = external.prev;
11273 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11275 ClassFunction func;
11276 char watcherName[1024];
11277 Class watcherClass = watcher ?
11278 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11279 External createdExternal;
11281 // Create a declaration above
11282 External externalDecl = MkExternalDeclaration(null);
11283 ast->Insert(curExternal.prev, externalDecl);
11285 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11286 if(propWatch.deleteWatch)
11287 strcat(watcherName, "_delete");
11291 for(propID = propWatch.properties->first; propID; propID = propID.next)
11293 strcat(watcherName, "_");
11294 strcat(watcherName, propID.string);
11298 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11300 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11301 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11302 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11303 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11304 ProcessClassFunctionBody(func, propWatch.compound);
11305 propWatch.compound = null;
11307 //afterExternal = afterExternal ? afterExternal : curExternal;
11309 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11310 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11312 createdExternal.symbol.idCode = external.symbol.idCode;
11314 curExternal = createdExternal;
11315 ProcessFunction(createdExternal.function);
11318 // Create a declaration above
11320 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11321 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11322 externalDecl.declaration = decl;
11323 if(decl.symbol && !decl.symbol.pointerExternal)
11324 decl.symbol.pointerExternal = externalDecl;
11327 if(propWatch.deleteWatch)
11329 OldList * args = MkList();
11330 ListAdd(args, CopyExpression(object));
11331 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11332 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11333 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11337 Class _class = object.expType._class.registered;
11340 for(propID = propWatch.properties->first; propID; propID = propID.next)
11342 char propName[1024];
11343 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11346 char getName[1024], setName[1024];
11347 OldList * args = MkList();
11349 DeclareProperty(prop, setName, getName);
11351 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11352 strcpy(propName, "__ecereProp_");
11353 FullClassNameCat(propName, prop._class.fullName, false);
11354 strcat(propName, "_");
11355 // strcat(propName, prop.name);
11356 FullClassNameCat(propName, prop.name, true);
11358 ListAdd(args, CopyExpression(object));
11359 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11360 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11361 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11363 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11366 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11371 Compiler_Error($"Invalid watched object\n");
11374 curExternal = external;
11375 curContext = context;
11378 FreeExpression(watcher);
11380 FreeExpression(object);
11381 FreeList(watches, FreePropertyWatch);
11384 Compiler_Error($"No observer specified and not inside a _class\n");
11388 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11390 ProcessStatement(propWatch.compound);
11396 case fireWatchersStmt:
11398 OldList * watches = stmt._watch.watches;
11399 Expression object = stmt._watch.object;
11401 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11402 // printf("%X\n", watches);
11403 // printf("%X\n", stmt._watch.watches);
11405 ProcessExpressionType(object);
11410 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11416 stmt.type = expressionStmt;
11417 stmt.expressions = MkList();
11419 // Check if we're inside a property set
11420 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11422 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11426 //Compiler_Error($"No property specified and not inside a property set\n");
11430 for(propID = watches->first; propID; propID = propID.next)
11432 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11435 CreateFireWatcher(prop, object, stmt);
11438 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11443 // Fire all properties!
11446 for(base = _class; base; base = base.base)
11448 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11450 if(prop.isProperty && prop.isWatchable)
11452 CreateFireWatcher(prop, object, stmt);
11459 FreeExpression(object);
11460 FreeList(watches, FreeIdentifier);
11463 Compiler_Error($"Invalid object specified and not inside a class\n");
11467 case stopWatchingStmt:
11469 OldList * watches = stmt._watch.watches;
11470 Expression object = stmt._watch.object;
11471 Expression watcher = stmt._watch.watcher;
11474 ProcessExpressionType(object);
11476 ProcessExpressionType(watcher);
11479 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11481 if(watcher || thisClass)
11487 stmt.type = expressionStmt;
11488 stmt.expressions = MkList();
11493 // eInstance_StopWatching(object, null, watcher);
11495 ListAdd(args, CopyExpression(object));
11496 ListAdd(args, MkExpConstant("0"));
11497 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11498 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11502 for(propID = watches->first; propID; propID = propID.next)
11504 char propName[1024];
11505 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11508 char getName[1024], setName[1024];
11509 OldList * args = MkList();
11511 DeclareProperty(prop, setName, getName);
11513 // eInstance_StopWatching(object, prop, watcher);
11514 strcpy(propName, "__ecereProp_");
11515 FullClassNameCat(propName, prop._class.fullName, false);
11516 strcat(propName, "_");
11517 // strcat(propName, prop.name);
11518 FullClassNameCat(propName, prop.name, true);
11519 MangleClassName(propName);
11521 ListAdd(args, CopyExpression(object));
11522 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11523 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11524 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11527 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11532 FreeExpression(object);
11534 FreeExpression(watcher);
11535 FreeList(watches, FreeIdentifier);
11538 Compiler_Error($"Invalid object specified and not inside a class\n");
11541 Compiler_Error($"No observer specified and not inside a class\n");
11548 static void ProcessFunction(FunctionDefinition function)
11550 Identifier id = GetDeclId(function.declarator);
11551 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11552 Type type = symbol ? symbol.type : null;
11553 Class oldThisClass = thisClass;
11554 Context oldTopContext = topContext;
11556 yylloc = function.loc;
11557 // Process thisClass
11559 if(type && type.thisClass)
11561 Symbol classSym = type.thisClass;
11562 Class _class = type.thisClass.registered;
11563 char className[1024];
11564 char structName[1024];
11565 Declarator funcDecl;
11568 bool typedObject = false;
11570 if(_class && !_class.base)
11572 _class = currentClass;
11573 if(_class && !_class.symbol)
11574 _class.symbol = FindClass(_class.fullName);
11575 classSym = _class ? _class.symbol : null;
11576 typedObject = true;
11579 thisClass = _class;
11581 if(inCompiler && _class)
11583 if(type.kind == functionType)
11585 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11587 //TypeName param = symbol.type.params.first;
11588 Type param = symbol.type.params.first;
11589 symbol.type.params.Remove(param);
11590 //FreeTypeName(param);
11593 if(type.classObjectType != classPointer)
11595 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11596 symbol.type.staticMethod = true;
11597 symbol.type.thisClass = null;
11599 // HIGH DANGER: VERIFYING THIS...
11600 symbol.type.extraParam = false;
11604 strcpy(className, "__ecereClass_");
11605 FullClassNameCat(className, _class.fullName, true);
11607 MangleClassName(className);
11610 FullClassNameCat(structName, _class.fullName, false);
11615 funcDecl = GetFuncDecl(function.declarator);
11618 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11620 TypeName param = funcDecl.function.parameters->first;
11621 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11623 funcDecl.function.parameters->Remove(param);
11624 FreeTypeName(param);
11628 // DANGER: Watch for this... Check if it's a Conversion?
11629 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11631 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11632 if(!function.propertyNoThis)
11634 TypeName thisParam;
11636 if(type.classObjectType != classPointer)
11638 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11639 if(!funcDecl.function.parameters)
11640 funcDecl.function.parameters = MkList();
11641 funcDecl.function.parameters->Insert(null, thisParam);
11646 if(type.classObjectType != classPointer)
11648 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11649 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11652 thisParam = TypeName
11654 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11655 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11657 funcDecl.function.parameters->Insert(null, thisParam);
11662 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11664 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11665 funcDecl = GetFuncDecl(initDecl.declarator);
11668 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11670 TypeName param = funcDecl.function.parameters->first;
11671 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11673 funcDecl.function.parameters->Remove(param);
11674 FreeTypeName(param);
11678 if(type.classObjectType != classPointer)
11680 // DANGER: Watch for this... Check if it's a Conversion?
11681 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11683 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11685 if(!funcDecl.function.parameters)
11686 funcDecl.function.parameters = MkList();
11687 funcDecl.function.parameters->Insert(null, thisParam);
11694 // Add this to the context
11697 if(type.classObjectType != classPointer)
11699 thisSymbol = Symbol
11701 string = CopyString("this");
11702 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11704 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11706 if(typedObject && thisSymbol.type)
11708 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11709 thisSymbol.type.byReference = type.byReference;
11711 thisSymbol = Symbol { string = CopyString("class") };
11712 function.body.compound.context.symbols.Add(thisSymbol);
11718 // Pointer to class data
11720 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11722 DataMember member = null;
11725 for(base = _class; base && base.type != systemClass; base = base.next)
11727 for(member = base.membersAndProperties.first; member; member = member.next)
11728 if(!member.isProperty)
11734 for(member = _class.membersAndProperties.first; member; member = member.next)
11735 if(!member.isProperty)
11739 char pointerName[1024];
11742 Initializer initializer;
11743 Expression exp, bytePtr;
11745 strcpy(pointerName, "__ecerePointer_");
11746 FullClassNameCat(pointerName, _class.fullName, false);
11748 char className[1024];
11749 strcpy(className, "__ecereClass_");
11750 FullClassNameCat(className, classSym.string, true);
11751 MangleClassName(className);
11754 DeclareClass(classSym, className);
11758 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11763 sprintf(string, "%d", _class.offset);
11764 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11768 // ([bytePtr] + [className]->offset)
11769 exp = QBrackets(MkExpOp(bytePtr, '+',
11770 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11773 // (this ? [exp] : 0)
11774 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11778 kind = pointerType;
11779 type = Type { refCount = 1, kind = voidType };
11784 yylloc = function.body.loc;
11785 // ([structName] *) [exp]
11786 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11787 initializer = MkInitializerAssignment(
11788 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11790 // [structName] * [pointerName] = [initializer];
11791 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11794 Context prevContext = curContext;
11795 curContext = function.body.compound.context;
11797 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11798 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11800 curContext = prevContext;
11804 decl.symbol = null;
11806 if(!function.body.compound.declarations)
11807 function.body.compound.declarations = MkList();
11808 function.body.compound.declarations->Insert(null, decl);
11814 // Loop through the function and replace undeclared identifiers
11815 // which are a member of the class (methods, properties or data)
11816 // by "this.[member]"
11823 FreeSpecifier(id._class);
11826 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11828 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11829 id = GetDeclId(initDecl.declarator);
11831 FreeSpecifier(id._class);
11836 topContext = function.body.compound.context;
11838 FunctionDefinition oldFunction = curFunction;
11839 curFunction = function;
11841 ProcessStatement(function.body);
11843 // If this is a property set and no firewatchers has been done yet, add one here
11844 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11846 Statement prevCompound = curCompound;
11847 Context prevContext = curContext;
11849 Statement fireWatchers = MkFireWatchersStmt(null, null);
11850 if(!function.body.compound.statements) function.body.compound.statements = MkList();
11851 ListAdd(function.body.compound.statements, fireWatchers);
11853 curCompound = function.body;
11854 curContext = function.body.compound.context;
11856 ProcessStatement(fireWatchers);
11858 curContext = prevContext;
11859 curCompound = prevCompound;
11863 curFunction = oldFunction;
11866 if(function.declarator)
11868 ProcessDeclarator(function.declarator);
11871 topContext = oldTopContext;
11872 thisClass = oldThisClass;
11875 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
11876 static void ProcessClass(OldList definitions, Symbol symbol)
11879 External external = curExternal;
11880 Class regClass = symbol ? symbol.registered : null;
11882 // Process all functions
11883 for(def = definitions.first; def; def = def.next)
11885 if(def.type == functionClassDef)
11887 if(def.function.declarator)
11888 curExternal = def.function.declarator.symbol.pointerExternal;
11890 curExternal = external;
11892 ProcessFunction((FunctionDefinition)def.function);
11894 else if(def.type == declarationClassDef)
11896 if(def.decl.type == instDeclaration)
11898 thisClass = regClass;
11899 ProcessInstantiationType(def.decl.inst);
11905 Class backThisClass = thisClass;
11906 if(regClass) thisClass = regClass;
11907 ProcessDeclaration(def.decl);
11908 thisClass = backThisClass;
11911 else if(def.type == defaultPropertiesClassDef && def.defProperties)
11913 MemberInit defProperty;
11915 // Add this to the context
11916 Symbol thisSymbol = Symbol
11918 string = CopyString("this");
11919 type = regClass ? MkClassType(regClass.fullName) : null;
11921 globalContext.symbols.Add((BTNode)thisSymbol);
11923 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
11925 thisClass = regClass;
11926 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
11930 globalContext.symbols.Remove((BTNode)thisSymbol);
11931 FreeSymbol(thisSymbol);
11933 else if(def.type == propertyClassDef && def.propertyDef)
11935 PropertyDef prop = def.propertyDef;
11937 // Add this to the context
11939 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
11940 globalContext.symbols.Add(thisSymbol);
11943 thisClass = regClass;
11950 string = CopyString("this");
11951 type = MkClassType(regClass.fullName);
11953 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11956 curExternal = prop.symbol ? prop.symbol.externalSet : null;
11957 ProcessStatement(prop.setStmt);
11965 string = CopyString("this");
11966 type = MkClassType(regClass.fullName);
11968 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11971 curExternal = prop.symbol ? prop.symbol.externalGet : null;
11972 ProcessStatement(prop.getStmt);
11980 string = CopyString("this");
11981 type = MkClassType(regClass.fullName);
11983 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11986 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
11987 ProcessStatement(prop.issetStmt);
11993 globalContext.symbols.Remove(thisSymbol);
11994 FreeSymbol(thisSymbol);
11997 else if(def.type == propertyWatchClassDef && def.propertyWatch)
11999 PropertyWatch propertyWatch = def.propertyWatch;
12001 thisClass = regClass;
12002 if(propertyWatch.compound)
12006 string = CopyString("this");
12007 type = regClass ? MkClassType(regClass.fullName) : null;
12010 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12012 curExternal = null;
12013 ProcessStatement(propertyWatch.compound);
12020 void ComputeDataTypes()
12024 currentClass = null;
12026 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12028 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12030 // WHERE SHOULD THIS GO?
12031 // curExternal = ast->first;
12032 ast->Insert(null, temp);
12034 curExternal = temp;
12036 DeclareStruct("ecere::com::Class", false);
12037 DeclareStruct("ecere::com::Instance", false);
12038 DeclareStruct("ecere::com::Property", false);
12039 DeclareStruct("ecere::com::DataMember", false);
12040 DeclareStruct("ecere::com::Method", false);
12041 DeclareStruct("ecere::com::SerialBuffer", false);
12042 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12046 for(external = ast->first; external; external = external.next)
12048 afterExternal = curExternal = external;
12049 if(external.type == functionExternal)
12051 currentClass = external.function._class;
12052 ProcessFunction(external.function);
12054 // There shouldn't be any _class member access here anyways...
12055 else if(external.type == declarationExternal)
12057 currentClass = null;
12058 ProcessDeclaration(external.declaration);
12060 else if(external.type == classExternal)
12062 ClassDefinition _class = external._class;
12063 currentClass = external.symbol.registered;
12064 if(_class.definitions)
12066 ProcessClass(_class.definitions, _class.symbol);
12070 // Free class data...
12071 ast->Remove(external);
12075 else if(external.type == nameSpaceExternal)
12077 thisNameSpace = external.id.string;
12080 currentClass = null;
12081 thisNameSpace = null;
12083 delete temp.symbol;