4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
52 OutputExpression(exp, f);
54 count = strlen(string);
55 count += f.Read(string + count, 1, 1023);
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return NeedCast(type1.type, type2.type);
106 return true; //false; ????
112 static void ReplaceClassMembers(Expression exp, Class _class)
114 if(exp.type == identifierExp && exp.identifier)
116 Identifier id = exp.identifier;
118 Symbol symbol = null;
119 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
121 // First, check if the identifier is declared inside the function
122 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
124 symbol = (Symbol)ctx.symbols.FindString(id.string);
129 // If it is not, check if it is a member of the _class
130 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
132 Property prop = eClass_FindProperty(_class, id.string, privateModule);
133 Method method = null;
134 DataMember member = null;
135 ClassProperty classProp = null;
138 method = eClass_FindMethod(_class, id.string, privateModule);
141 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
142 if(!prop && !method && !member)
144 classProp = eClass_FindClassProperty(_class, id.string);
146 if(prop || method || member || classProp)
148 // Replace by this.[member]
149 exp.type = memberExp;
150 exp.member.member = id;
151 exp.member.memberType = unresolvedMember;
152 exp.member.exp = QMkExpId("this");
153 //exp.member.exp.loc = exp.loc;
154 exp.addedThis = true;
156 else if(_class && _class.templateParams.first)
159 for(sClass = _class; sClass; sClass = sClass.base)
161 if(sClass.templateParams.first)
163 ClassTemplateParameter param;
164 for(param = sClass.templateParams.first; param; param = param.next)
166 if(param.type == expression && !strcmp(param.name, id.string))
168 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
173 OldList * specs = MkList();
175 FreeIdentifier(exp.member.member);
177 ProcessExpressionType(argExp);
179 decl = SpecDeclFromString(param.dataTypeString, specs, null);
181 exp.expType = ProcessType(specs, decl);
183 // *[expType] *[argExp]
184 exp.type = bracketsExp;
185 exp.list = MkListOne(MkExpOp(null, '*',
186 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
197 ////////////////////////////////////////////////////////////////////////
198 // PRINTING ////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////
201 public char * PrintInt(int64 result)
204 if(result > MAXINT64)
205 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
207 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
208 return CopyString(temp);
211 public char * PrintUInt(uint64 result)
214 if(result > MAXDWORD)
215 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
216 else if(result > MAXINT)
217 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
219 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
220 return CopyString(temp);
223 public char * PrintInt64(int64 result)
226 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
227 return CopyString(temp);
230 public char * PrintUInt64(uint64 result)
233 if(result > MAXINT64)
234 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
236 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
237 return CopyString(temp);
240 public char * PrintHexUInt(uint64 result)
243 if(result > MAXDWORD)
244 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
246 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
247 return CopyString(temp);
250 public char * PrintHexUInt64(uint64 result)
253 if(result > MAXDWORD)
254 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
256 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
257 return CopyString(temp);
260 public char * PrintShort(short result)
263 sprintf(temp, "%d", (unsigned short)result);
264 return CopyString(temp);
267 public char * PrintUShort(unsigned short result)
271 sprintf(temp, "0x%X", (int)result);
273 sprintf(temp, "%d", (int)result);
274 return CopyString(temp);
277 public char * PrintChar(char result)
280 if(result > 0 && isprint(result))
281 sprintf(temp, "'%c'", result);
283 sprintf(temp, "%d", (int)result);
285 //sprintf(temp, "%#X", result);
286 sprintf(temp, "0x%X", (unsigned char)result);
287 return CopyString(temp);
290 public char * PrintUChar(unsigned char result)
293 sprintf(temp, "0x%X", result);
294 return CopyString(temp);
297 public char * PrintFloat(float result)
303 strcpy(temp, "-inf");
307 else if(result.isNan)
310 strcpy(temp, "-nan");
315 sprintf(temp, "%.16ff", result);
316 return CopyString(temp);
319 public char * PrintDouble(double result)
325 strcpy(temp, "-inf");
329 else if(result.isNan)
332 strcpy(temp, "-nan");
337 sprintf(temp, "%.16f", result);
338 return CopyString(temp);
341 ////////////////////////////////////////////////////////////////////////
342 ////////////////////////////////////////////////////////////////////////
344 //public Operand GetOperand(Expression exp);
346 #define GETVALUE(name, t) \
347 public bool GetOp##name(Operand op2, t * value2) \
349 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
350 else if(op2.kind == intType) *value2 = (t) op2.ui; \
351 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
352 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
353 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
354 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
355 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
356 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
357 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
358 else if(op2.kind == shortType) *value2 = (t) op2.us; \
359 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
360 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
361 else if(op2.kind == floatType) *value2 = (t) op2.f; \
362 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
363 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
368 public bool Get##name(Expression exp, t * value2) \
370 Operand op2 = GetOperand(exp); \
371 return GetOp##name(op2, value2); \
374 // To help the deubugger currently not preprocessing...
377 GETVALUE(Int, HELP(int));
378 GETVALUE(UInt, HELP(unsigned int));
379 GETVALUE(Int64, HELP(int64));
380 GETVALUE(UInt64, HELP(uint64));
381 GETVALUE(IntPtr, HELP(intptr));
382 GETVALUE(UIntPtr, HELP(uintptr));
383 GETVALUE(IntSize, HELP(intsize));
384 GETVALUE(UIntSize, HELP(uintsize));
385 GETVALUE(Short, HELP(short));
386 GETVALUE(UShort, HELP(unsigned short));
387 GETVALUE(Char, HELP(char));
388 GETVALUE(UChar, HELP(unsigned char));
389 GETVALUE(Float, HELP(float));
390 GETVALUE(Double, HELP(double));
392 void ComputeExpression(Expression exp);
394 void ComputeClassMembers(Class _class, bool isMember)
396 DataMember member = isMember ? (DataMember) _class : null;
397 Context context = isMember ? null : SetupTemplatesContext(_class);
398 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
399 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
402 int unionMemberOffset = 0;
406 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
407 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
412 member.memberOffset = 0;
413 if(targetBits < sizeof(void *) * 8)
414 member.structAlignment = 0;
416 else if(targetBits < sizeof(void *) * 8)
417 _class.structAlignment = 0;
419 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
420 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
421 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
423 if(!member && _class.destructionWatchOffset)
424 _class.memberOffset += sizeof(OldList);
426 // To avoid reentrancy...
427 //_class.structSize = -1;
430 DataMember dataMember;
431 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
433 if(!dataMember.isProperty)
435 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
437 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
438 /*if(!dataMember.dataType)
439 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
447 DataMember dataMember;
448 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
450 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
452 if(!isMember && _class.type == bitClass && dataMember.dataType)
454 BitMember bitMember = (BitMember) dataMember;
458 ComputeTypeSize(dataMember.dataType);
460 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
461 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
463 _class.memberOffset = bitMember.pos + bitMember.size;
464 for(d = 0; d<bitMember.size; d++)
470 bitMember.mask = mask << bitMember.pos;
472 else if(dataMember.type == normalMember && dataMember.dataType)
477 // Prevent infinite recursion
478 if(dataMember.dataType.kind != classType ||
479 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
480 _class.type != structClass)))
481 ComputeTypeSize(dataMember.dataType);
483 if(dataMember.dataType.bitFieldCount)
485 bitFields += dataMember.dataType.bitFieldCount;
492 int size = (bitFields + 7) / 8;
496 // TESTING THIS PADDING CODE
499 member.structAlignment = Max(member.structAlignment, alignment);
501 if(member.memberOffset % alignment)
502 member.memberOffset += alignment - (member.memberOffset % alignment);
505 dataMember.offset = member.memberOffset;
506 if(member.type == unionMember)
507 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
510 member.memberOffset += size;
515 // TESTING THIS PADDING CODE
518 _class.structAlignment = Max(_class.structAlignment, alignment);
520 if(_class.memberOffset % alignment)
521 _class.memberOffset += alignment - (_class.memberOffset % alignment);
524 dataMember.offset = _class.memberOffset;
525 _class.memberOffset += size;
529 size = dataMember.dataType.size;
530 alignment = dataMember.dataType.alignment;
535 // TESTING THIS PADDING CODE
538 member.structAlignment = Max(member.structAlignment, alignment);
540 if(member.memberOffset % alignment)
541 member.memberOffset += alignment - (member.memberOffset % alignment);
544 dataMember.offset = member.memberOffset;
545 if(member.type == unionMember)
546 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
549 member.memberOffset += size;
554 // TESTING THIS PADDING CODE
557 _class.structAlignment = Max(_class.structAlignment, alignment);
559 if(_class.memberOffset % alignment)
560 _class.memberOffset += alignment - (_class.memberOffset % alignment);
563 dataMember.offset = _class.memberOffset;
564 _class.memberOffset += size;
571 ComputeClassMembers((Class)dataMember, true);
572 alignment = dataMember.structAlignment;
578 if(member.memberOffset % alignment)
579 member.memberOffset += alignment - (member.memberOffset % alignment);
581 member.structAlignment = Max(member.structAlignment, alignment);
583 dataMember.offset = member.memberOffset;
584 if(member.type == unionMember)
585 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
587 member.memberOffset += dataMember.memberOffset;
593 if(_class.memberOffset % alignment)
594 _class.memberOffset += alignment - (_class.memberOffset % alignment);
595 _class.structAlignment = Max(_class.structAlignment, alignment);
597 dataMember.offset = _class.memberOffset;
598 _class.memberOffset += dataMember.memberOffset;
606 int size = (bitFields + 7) / 8;
610 // TESTING THIS PADDING CODE
613 member.structAlignment = Max(member.structAlignment, alignment);
615 if(member.memberOffset % alignment)
616 member.memberOffset += alignment - (member.memberOffset % alignment);
619 if(member.type == unionMember)
620 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
623 member.memberOffset += size;
628 // TESTING THIS PADDING CODE
631 _class.structAlignment = Max(_class.structAlignment, alignment);
633 if(_class.memberOffset % alignment)
634 _class.memberOffset += alignment - (_class.memberOffset % alignment);
636 _class.memberOffset += size;
641 if(member && member.type == unionMember)
643 member.memberOffset = unionMemberOffset;
648 /*if(_class.type == structClass)
649 _class.size = _class.memberOffset;
653 if(_class.type != bitClass)
656 if(_class.structAlignment)
658 if(_class.memberOffset % _class.structAlignment)
659 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
661 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
665 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
667 if(prop.isProperty && prop.isWatchable)
669 prop.watcherOffset = _class.structSize;
670 _class.structSize += sizeof(OldList);
678 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
680 Class deriv = derivative.data;
682 if(deriv.computeSize)
684 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
685 deriv.offset = /*_class.offset + */_class.structSize;
686 deriv.memberOffset = 0;
687 // ----------------------
689 deriv.structSize = deriv.offset;
691 ComputeClassMembers(deriv, false);
699 FinishTemplatesContext(context);
702 public void ComputeModuleClasses(Module module)
707 for(subModule = module.modules.first; subModule; subModule = subModule.next)
708 ComputeModuleClasses(subModule.data);
709 for(_class = module.classes.first; _class; _class = _class.next)
710 ComputeClassMembers(_class, false);
714 public int ComputeTypeSize(Type type)
716 uint size = type ? type.size : 0;
717 if(!size && type && !type.computing)
719 type.computing = true;
722 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
723 case charType: type.alignment = size = sizeof(char); break;
724 case intType: type.alignment = size = sizeof(int); break;
725 case int64Type: type.alignment = size = sizeof(int64); break;
726 case intPtrType: type.alignment = size = targetBits / 8; break;
727 case intSizeType: type.alignment = size = targetBits / 8; break;
728 case longType: type.alignment = size = sizeof(long); break;
729 case shortType: type.alignment = size = sizeof(short); break;
730 case floatType: type.alignment = size = sizeof(float); break;
731 case doubleType: type.alignment = size = sizeof(double); break;
734 Class _class = type._class ? type._class.registered : null;
736 if(_class && _class.type == structClass)
738 // Ensure all members are properly registered
739 ComputeClassMembers(_class, false);
740 type.alignment = _class.structAlignment;
741 size = _class.structSize;
742 if(type.alignment && size % type.alignment)
743 size += type.alignment - (size % type.alignment);
746 else if(_class && (_class.type == unitClass ||
747 _class.type == enumClass ||
748 _class.type == bitClass))
751 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
752 size = type.alignment = ComputeTypeSize(_class.dataType);
755 size = type.alignment = targetBits / 8; // sizeof(Instance *);
758 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
760 if(type.arraySizeExp)
762 ProcessExpressionType(type.arraySizeExp);
763 ComputeExpression(type.arraySizeExp);
764 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
765 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
767 Location oldLoc = yylloc;
768 // bool isConstant = type.arraySizeExp.isConstant;
769 char expression[10240];
770 expression[0] = '\0';
771 type.arraySizeExp.expType = null;
772 yylloc = type.arraySizeExp.loc;
774 PrintExpression(type.arraySizeExp, expression);
775 Compiler_Error($"Array size not constant int (%s)\n", expression);
778 GetInt(type.arraySizeExp, &type.arraySize);
780 else if(type.enumClass)
782 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
784 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
791 // Unimplemented auto size
795 size = ComputeTypeSize(type.type) * type.arraySize;
797 type.alignment = type.type.alignment;
803 for(member = type.members.first; member; member = member.next)
805 uint addSize = ComputeTypeSize(member);
807 member.offset = size;
808 if(member.alignment && size % member.alignment)
809 member.offset += member.alignment - (size % member.alignment);
810 size = member.offset;
812 type.alignment = Max(type.alignment, member.alignment);
815 if(type.alignment && size % type.alignment)
816 size += type.alignment - (size % type.alignment);
822 for(member = type.members.first; member; member = member.next)
824 uint addSize = ComputeTypeSize(member);
826 member.offset = size;
827 if(member.alignment && size % member.alignment)
828 member.offset += member.alignment - (size % member.alignment);
829 size = member.offset;
831 type.alignment = Max(type.alignment, member.alignment);
832 size = Max(size, addSize);
834 if(type.alignment && size % type.alignment)
835 size += type.alignment - (size % type.alignment);
840 TemplateParameter param = type.templateParameter;
841 Type baseType = ProcessTemplateParameterType(param);
844 size = ComputeTypeSize(baseType);
845 type.alignment = baseType.alignment;
848 type.alignment = size = sizeof(uint64);
853 type.alignment = size = sizeof(enum { test });
858 type.alignment = size = targetBits / 8; //sizeof(void *);
863 type.computing = false;
869 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
871 // This function is in need of a major review when implementing private members etc.
872 DataMember topMember = isMember ? (DataMember) _class : null;
877 Context context = isMember ? null : SetupTemplatesContext(_class);
879 *addedPadding = false;
881 if(!isMember && _class.base)
883 maxSize = _class.structSize;
884 //if(_class.base.type != systemClass) // Commented out with new Instance _class
886 // DANGER: Testing this noHeadClass here...
887 if(_class.type == structClass || _class.type == noHeadClass)
888 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
891 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
892 if(maxSize > baseSize)
900 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
902 if(!member.isProperty)
908 if(member.dataTypeString)
910 OldList * specs = MkList(), * decls = MkList();
913 decl = SpecDeclFromString(member.dataTypeString, specs,
914 MkDeclaratorIdentifier(MkIdentifier(member.name)));
915 ListAdd(decls, MkStructDeclarator(decl, null));
916 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
919 member.dataType = ProcessType(specs, decl);
921 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
924 Type type = ProcessType(specs, decl);
925 DeclareType(member.dataType, false, false);
929 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
930 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
931 DeclareStruct(member.dataType._class.string, false);
934 ComputeTypeSize(member.dataType);
935 size = member.dataType.size;
936 alignment = member.dataType.alignment;
940 if(totalSize % alignment)
941 totalSize += alignment - (totalSize % alignment);
950 OldList * specs = MkList(), * list = MkList();
953 AddMembers(list, (Class)member, true, &size, topClass, null);
955 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
956 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
957 alignment = member.structAlignment;
961 if(totalSize % alignment)
962 totalSize += alignment - (totalSize % alignment);
972 if(topMember && topMember.type == unionMember)
973 *retSize = Max(*retSize, totalSize);
975 *retSize += totalSize;
977 else if(totalSize < maxSize && _class.type != systemClass)
980 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
981 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
982 if(totalSize + autoPadding < maxSize)
985 sprintf(sizeString, "%d", maxSize - totalSize);
986 ListAdd(declarations,
987 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
988 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
990 *addedPadding = true;
994 FinishTemplatesContext(context);
995 return topMember ? topMember.memberID : _class.memberID;
998 static int DeclareMembers(Class _class, bool isMember)
1000 DataMember topMember = isMember ? (DataMember) _class : null;
1003 Context context = isMember ? null : SetupTemplatesContext(_class);
1005 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1006 DeclareMembers(_class.base, false);
1008 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1010 if(!member.isProperty)
1017 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1018 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1019 DeclareStruct(member.dataType._class.string, false);
1021 if(!member.dataType && member.dataTypeString)
1022 member.dataType = ProcessTypeString(member.dataTypeString, false);
1024 DeclareType(member.dataType, false, false);
1030 DeclareMembers((Class)member, true);
1037 FinishTemplatesContext(context);
1039 return topMember ? topMember.memberID : _class.memberID;
1042 void DeclareStruct(char * name, bool skipNoHead)
1044 External external = null;
1045 Symbol classSym = FindClass(name);
1047 if(!inCompiler || !classSym) return;
1049 // We don't need any declaration for bit classes...
1050 if(classSym.registered &&
1051 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1054 /*if(classSym.registered.templateClass)
1055 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1058 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1060 // Add typedef struct
1062 OldList * specifiers, * declarators;
1063 OldList * declarations = null;
1064 char structName[1024];
1065 external = (classSym.registered && classSym.registered.type == structClass) ?
1066 classSym.pointerExternal : classSym.structExternal;
1068 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1069 // Moved this one up because DeclareClass done later will need it
1071 classSym.declaring++;
1073 if(strchr(classSym.string, '<'))
1075 if(classSym.registered.templateClass)
1077 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1078 classSym.declaring--;
1084 DeclareMembers(classSym.registered, false);
1087 FullClassNameCat(structName, name, false);
1090 external = MkExternalDeclaration(null);*/
1094 bool addedPadding = false;
1095 classSym.declaredStructSym = true;
1097 declarations = MkList();
1099 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1101 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1102 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1104 if(!declarations->count || (declarations->count == 1 && addedPadding))
1106 FreeList(declarations, FreeClassDef);
1107 declarations = null;
1110 if(skipNoHead || declarations)
1112 if(external && external.declaration)
1114 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1116 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1119 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1122 if(classSym.structExternal)
1123 ast->Move(classSym.structExternal, curExternal.prev);
1124 ast->Move(classSym.pointerExternal, curExternal.prev);
1126 classSym.id = curExternal.symbol.idCode;
1127 classSym.idCode = curExternal.symbol.idCode;
1128 // external = classSym.pointerExternal;
1129 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1135 external = MkExternalDeclaration(null);
1137 specifiers = MkList();
1138 declarators = MkList();
1139 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1142 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1143 ListAdd(declarators, MkInitDeclarator(d, null));
1145 external.declaration = decl = MkDeclaration(specifiers, declarators);
1146 if(decl.symbol && !decl.symbol.pointerExternal)
1147 decl.symbol.pointerExternal = external;
1149 // For simple classes, keep the declaration as the external to move around
1150 if(classSym.registered && classSym.registered.type == structClass)
1152 char className[1024];
1153 strcpy(className, "__ecereClass_");
1154 FullClassNameCat(className, classSym.string, true);
1155 MangleClassName(className);
1158 DeclareClass(classSym, className);
1160 external.symbol = classSym;
1161 classSym.pointerExternal = external;
1162 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1163 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1167 char className[1024];
1168 strcpy(className, "__ecereClass_");
1169 FullClassNameCat(className, classSym.string, true);
1170 MangleClassName(className);
1172 // TOFIX: TESTING THIS...
1173 classSym.structExternal = external;
1174 DeclareClass(classSym, className);
1175 external.symbol = classSym;
1179 ast->Insert(curExternal ? curExternal.prev : null, external);
1183 classSym.declaring--;
1185 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1187 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1188 // Moved this one up because DeclareClass done later will need it
1191 classSym.declaring++;
1195 if(classSym.registered)
1196 DeclareMembers(classSym.registered, false);
1199 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1202 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1205 if(classSym.structExternal)
1206 ast->Move(classSym.structExternal, curExternal.prev);
1207 ast->Move(classSym.pointerExternal, curExternal.prev);
1209 classSym.id = curExternal.symbol.idCode;
1210 classSym.idCode = curExternal.symbol.idCode;
1211 // external = classSym.pointerExternal;
1212 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1215 classSym.declaring--;
1220 void DeclareProperty(Property prop, char * setName, char * getName)
1222 Symbol symbol = prop.symbol;
1223 char propName[1024];
1225 strcpy(setName, "__ecereProp_");
1226 FullClassNameCat(setName, prop._class.fullName, false);
1227 strcat(setName, "_Set_");
1228 // strcat(setName, prop.name);
1229 FullClassNameCat(setName, prop.name, true);
1231 strcpy(getName, "__ecereProp_");
1232 FullClassNameCat(getName, prop._class.fullName, false);
1233 strcat(getName, "_Get_");
1234 FullClassNameCat(getName, prop.name, true);
1235 // strcat(getName, prop.name);
1237 strcpy(propName, "__ecereProp_");
1238 FullClassNameCat(propName, prop._class.fullName, false);
1239 strcat(propName, "_");
1240 FullClassNameCat(propName, prop.name, true);
1241 // strcat(propName, prop.name);
1243 // To support "char *" property
1244 MangleClassName(getName);
1245 MangleClassName(setName);
1246 MangleClassName(propName);
1248 if(prop._class.type == structClass)
1249 DeclareStruct(prop._class.fullName, false);
1251 if(!symbol || curExternal.symbol.idCode < symbol.id)
1253 bool imported = false;
1254 bool dllImport = false;
1255 if(!symbol || symbol._import)
1260 if(!prop._class.symbol)
1261 prop._class.symbol = FindClass(prop._class.fullName);
1262 classSym = prop._class.symbol;
1263 if(classSym && !classSym._import)
1265 ModuleImport module;
1267 if(prop._class.module)
1268 module = FindModule(prop._class.module);
1270 module = mainModule;
1272 classSym._import = ClassImport
1274 name = CopyString(prop._class.fullName);
1275 isRemote = prop._class.isRemote;
1277 module.classes.Add(classSym._import);
1279 symbol = prop.symbol = Symbol { };
1280 symbol._import = (ClassImport)PropertyImport
1282 name = CopyString(prop.name);
1283 isVirtual = false; //prop.isVirtual;
1284 hasSet = prop.Set ? true : false;
1285 hasGet = prop.Get ? true : false;
1288 classSym._import.properties.Add(symbol._import);
1291 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1292 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1293 prop._class.module.importType != staticImport)
1299 Context context = SetupTemplatesContext(prop._class);
1300 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1301 FinishTemplatesContext(context);
1307 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1310 OldList * specifiers, * declarators;
1315 Declarator typeDecl;
1316 bool simple = false;
1318 specifiers = MkList();
1319 declarators = MkList();
1322 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1323 MkDeclaratorIdentifier(MkIdentifier("this"))));
1325 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1328 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1331 Context context = SetupTemplatesContext(prop._class);
1332 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1333 FinishTemplatesContext(context);
1336 // Make sure the simple _class's type is declared
1337 for(spec = specifiers->first; spec; spec = spec.next)
1339 if(spec.type == nameSpecifier /*SpecifierClass*/)
1341 if((!typeDecl || typeDecl.type == identifierDeclarator))
1343 Symbol classSym = spec.symbol; // FindClass(spec.name);
1344 symbol._class = classSym.registered;
1345 if(classSym.registered && classSym.registered.type == structClass)
1347 DeclareStruct(spec.name, false);
1355 d = PlugDeclarator(typeDecl, d);
1358 ListAdd(params, MkTypeName(specifiers,
1359 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1360 specifiers = MkList();
1363 d = MkDeclaratorFunction(d, params);
1367 specifiers->Insert(null, MkSpecifier(EXTERN));
1368 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1369 specifiers->Insert(null, MkSpecifier(STATIC));
1371 ListAdd(specifiers, MkSpecifier(VOID));
1373 ListAdd(declarators, MkInitDeclarator(d, null));
1375 decl = MkDeclaration(specifiers, declarators);
1377 external = MkExternalDeclaration(decl);
1378 ast->Insert(curExternal.prev, external);
1379 external.symbol = symbol;
1380 symbol.externalGet = external;
1382 ReplaceThisClassSpecifiers(specifiers, prop._class);
1385 FreeDeclarator(typeDecl);
1389 // Move declaration higher...
1390 ast->Move(symbol.externalGet, curExternal.prev);
1397 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1400 OldList * specifiers, * declarators;
1405 Declarator typeDecl;
1407 declarators = MkList();
1410 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1411 if(!prop.conversion || prop._class.type == structClass)
1413 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1414 MkDeclaratorIdentifier(MkIdentifier("this"))));
1417 specifiers = MkList();
1420 Context context = SetupTemplatesContext(prop._class);
1421 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1422 MkDeclaratorIdentifier(MkIdentifier("value")));
1423 FinishTemplatesContext(context);
1425 ListAdd(params, MkTypeName(specifiers, d));
1427 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1430 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1431 d = MkDeclaratorFunction(d, params);
1433 // Make sure the simple _class's type is declared
1434 for(spec = specifiers->first; spec; spec = spec.next)
1436 if(spec.type == nameSpecifier /*SpecifierClass*/)
1438 if((!typeDecl || typeDecl.type == identifierDeclarator))
1440 Symbol classSym = spec.symbol; // FindClass(spec.name);
1441 symbol._class = classSym.registered;
1442 if(classSym.registered && classSym.registered.type == structClass)
1443 DeclareStruct(spec.name, false);
1448 ListAdd(declarators, MkInitDeclarator(d, null));
1450 specifiers = MkList();
1453 specifiers->Insert(null, MkSpecifier(EXTERN));
1454 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1455 specifiers->Insert(null, MkSpecifier(STATIC));
1457 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1458 if(!prop.conversion || prop._class.type == structClass)
1459 ListAdd(specifiers, MkSpecifier(VOID));
1461 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1463 decl = MkDeclaration(specifiers, declarators);
1465 external = MkExternalDeclaration(decl);
1466 ast->Insert(curExternal.prev, external);
1467 external.symbol = symbol;
1468 symbol.externalSet = external;
1470 ReplaceThisClassSpecifiers(specifiers, prop._class);
1474 // Move declaration higher...
1475 ast->Move(symbol.externalSet, curExternal.prev);
1479 // Property (for Watchers)
1480 if(!symbol.externalPtr)
1484 OldList * specifiers = MkList();
1487 specifiers->Insert(null, MkSpecifier(EXTERN));
1489 specifiers->Insert(null, MkSpecifier(STATIC));
1491 ListAdd(specifiers, MkSpecifierName("Property"));
1494 OldList * list = MkList();
1495 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1496 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1500 strcpy(propName, "__ecerePropM_");
1501 FullClassNameCat(propName, prop._class.fullName, false);
1502 strcat(propName, "_");
1503 // strcat(propName, prop.name);
1504 FullClassNameCat(propName, prop.name, true);
1506 MangleClassName(propName);
1508 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1509 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1511 decl = MkDeclaration(specifiers, list);
1514 external = MkExternalDeclaration(decl);
1515 ast->Insert(curExternal.prev, external);
1516 external.symbol = symbol;
1517 symbol.externalPtr = external;
1521 // Move declaration higher...
1522 ast->Move(symbol.externalPtr, curExternal.prev);
1525 symbol.id = curExternal.symbol.idCode;
1529 // ***************** EXPRESSION PROCESSING ***************************
1530 public Type Dereference(Type source)
1535 if(source.kind == pointerType || source.kind == arrayType)
1538 source.type.refCount++;
1540 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1548 // Support dereferencing of no head classes for now...
1549 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1555 Compiler_Error($"cannot dereference type\n");
1560 static Type Reference(Type source)
1576 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1578 Identifier ident = member.identifiers ? member.identifiers->first : null;
1580 DataMember dataMember = null;
1581 Method method = null;
1582 bool freeType = false;
1584 yylloc = member.loc;
1590 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1594 dataMember = *curMember;
1600 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1601 DataMember _subMemberStack[256];
1602 int _subMemberStackPos = 0;
1604 // FILL MEMBER STACK
1606 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1609 dataMember = thisMember;
1610 if(curMember && thisMember.memberAccess == publicAccess)
1612 *curMember = thisMember;
1613 *curClass = thisMember._class;
1614 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1615 *subMemberStackPos = _subMemberStackPos;
1622 method = eClass_FindMethod(_class, ident.string, privateModule);
1623 if(method && method.type == virtualMethod)
1635 if(!dataMember.dataType && dataMember.dataTypeString)
1637 //Context context = SetupTemplatesContext(dataMember._class);
1638 Context context = SetupTemplatesContext(_class);
1639 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1640 FinishTemplatesContext(context);
1642 type = dataMember.dataType;
1646 // This is for destination type...
1647 if(!method.dataType)
1648 ProcessMethodType(method);
1649 //DeclareMethod(method);
1650 // method.dataType = ((Symbol)method.symbol)->type;
1651 type = method.dataType;
1654 if(ident && ident.next)
1656 for(ident = ident.next; ident && type; ident = ident.next)
1658 if(type.kind == classType)
1660 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1662 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1664 type = dataMember.dataType;
1666 else if(type.kind == structType || type.kind == unionType)
1669 for(memberType = type.members.first; memberType; memberType = memberType.next)
1671 if(!strcmp(memberType.name, ident.string))
1681 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1682 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1685 ClassTemplateParameter curParam = null;
1687 for(sClass = _class; sClass; sClass = sClass.base)
1690 if(sClass.templateClass) sClass = sClass.templateClass;
1691 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1693 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1695 for(sClass = sClass.base; sClass; sClass = sClass.base)
1697 if(sClass.templateClass) sClass = sClass.templateClass;
1698 id += sClass.templateParams.count;
1709 ClassTemplateArgument arg = _class.templateArgs[id];
1710 if(arg.dataTypeString)
1713 type = ProcessTypeString(arg.dataTypeString, false);
1715 if(type && _class.templateClass)
1716 type.passAsTemplate = true;
1722 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1723 exp.destType.refCount++;
1729 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1731 Class expClass = type._class.registered;
1732 Class cClass = null;
1737 char templateString[1024];
1738 ClassTemplateParameter param;
1739 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1740 for(cClass = expClass; cClass; cClass = cClass.base)
1743 if(cClass.templateClass) cClass = cClass.templateClass;
1744 for(param = cClass.templateParams.first; param; param = param.next)
1748 ClassTemplateArgument arg;
1749 for(sClass = cClass.base; sClass; sClass = sClass.base)
1751 if(sClass.templateClass) sClass = sClass.templateClass;
1752 id += sClass.templateParams.count;
1754 arg = expClass.templateArgs[id];
1756 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1758 ClassTemplateParameter cParam;
1759 //int p = numParams - sClass.templateParams.count;
1762 if(sClass.templateClass) sClass = sClass.templateClass;
1764 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1766 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1767 p += nextClass.templateParams.count;
1770 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1772 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1774 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1776 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1777 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1789 strcat(argument, arg.name.string);
1790 strcat(argument, " = ");
1796 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1797 char expString[1024];
1798 OldList * specs = MkList();
1799 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1801 char * string = PrintHexUInt64(arg.expression.ui64);
1802 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1805 ProcessExpressionType(exp);
1806 ComputeExpression(exp);
1807 expString[0] = '\0';
1808 PrintExpression(exp, expString);
1809 strcat(argument, expString);
1811 FreeExpression(exp);
1816 strcat(argument, arg.member.name);
1819 case TemplateParameterType::type:
1821 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1822 strcat(argument, arg.dataTypeString);
1828 if(paramCount) strcat(templateString, ", ");
1829 if(lastParam != p - 1)
1831 strcat(templateString, param.name);
1832 strcat(templateString, " = ");
1834 strcat(templateString, argument);
1843 int len = strlen(templateString);
1844 if(templateString[len-1] == '<')
1848 if(templateString[len-1] == '>')
1849 templateString[len++] = ' ';
1850 templateString[len++] = '>';
1852 templateString[len++] = '\0';
1855 Context context = SetupTemplatesContext(_class);
1856 if(freeType) FreeType(type);
1857 type = ProcessTypeString(templateString, false);
1859 FinishTemplatesContext(context);
1863 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1865 ProcessExpressionType(member.initializer.exp);
1866 if(!member.initializer.exp.expType)
1870 char expString[10240];
1871 expString[0] = '\0';
1872 PrintExpression(member.initializer.exp, expString);
1873 ChangeCh(expString, '\n', ' ');
1874 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1877 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1878 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1880 Compiler_Error($"incompatible instance method %s\n", ident.string);
1883 else if(member.initializer)
1886 FreeType(member.exp.destType);
1887 member.exp.destType = type;
1888 if(member.exp.destType)
1889 member.exp.destType.refCount++;
1890 ProcessExpressionType(member.exp);
1893 ProcessInitializer(member.initializer, type);
1895 if(freeType) FreeType(type);
1899 if(_class && _class.type == unitClass)
1901 if(member.initializer)
1904 FreeType(member.exp.destType);
1905 member.exp.destType = MkClassType(_class.fullName);
1906 ProcessExpressionType(member.initializer, type);
1908 Type type = MkClassType(_class.fullName);
1909 ProcessInitializer(member.initializer, type);
1915 if(member.initializer)
1917 //ProcessExpressionType(member.exp);
1918 ProcessInitializer(member.initializer, null);
1924 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1928 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1930 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1934 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1939 void ProcessInstantiationType(Instantiation inst)
1944 MembersInit members;
1945 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1948 /*if(!inst._class.symbol)
1949 inst._class.symbol = FindClass(inst._class.name);*/
1950 classSym = inst._class.symbol;
1951 _class = classSym ? classSym.registered : null;
1953 // DANGER: Patch for mutex not declaring its struct when not needed
1954 if(!_class || _class.type != noHeadClass)
1955 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1957 afterExternal = afterExternal ? afterExternal : curExternal;
1960 ProcessExpressionType(inst.exp);
1962 inst.isConstant = true;
1965 DataMember curMember = null;
1966 Class curClass = null;
1967 DataMember subMemberStack[256];
1968 int subMemberStackPos = 0;
1970 for(members = inst.members->first; members; members = members.next)
1972 switch(members.type)
1974 case methodMembersInit:
1977 static uint instMethodID = 0;
1978 External external = curExternal;
1979 Context context = curContext;
1980 Declarator declarator = members.function.declarator;
1981 Identifier nameID = GetDeclId(declarator);
1982 char * unmangled = nameID ? nameID.string : null;
1984 External createdExternal = null;
1989 //members.function.dontMangle = true;
1990 strcpy(name, "__ecereInstMeth_");
1991 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1993 strcat(name, nameID.string);
1995 sprintf(number, "_%08d", instMethodID++);
1996 strcat(name, number);
1997 nameID.string = CopyString(name);
2000 // Do modifications here...
2003 Symbol symbol = declarator.symbol;
2004 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2006 if(method && method.type == virtualMethod)
2008 symbol.method = method;
2009 ProcessMethodType(method);
2011 if(!symbol.type.thisClass)
2013 if(method.dataType.thisClass && currentClass &&
2014 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2016 if(!currentClass.symbol)
2017 currentClass.symbol = FindClass(currentClass.fullName);
2018 symbol.type.thisClass = currentClass.symbol;
2023 _class.symbol = FindClass(_class.fullName);
2024 symbol.type.thisClass = _class.symbol;
2027 // TESTING THIS HERE:
2028 DeclareType(symbol.type, true, true);
2033 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2034 unmangled, classSym.string);
2038 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2039 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2043 FreeSpecifier(nameID._class);
2044 nameID._class = null;
2050 Type type = declarator.symbol.type;
2051 External oldExternal = curExternal;
2053 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2054 // *** It was commented out for problems such as
2056 class VirtualDesktop : Window
2058 clientSize = Size { };
2069 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2071 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2074 if(strcmp(declarator.symbol.string, name))
2076 printf("TOCHECK: Look out for this\n");
2077 delete declarator.symbol.string;
2078 declarator.symbol.string = CopyString(name);
2081 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2083 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2084 excludedSymbols->Remove(declarator.symbol);
2085 globalContext.symbols.Add((BTNode)declarator.symbol);
2086 if(strstr(declarator.symbol.string), "::")
2087 globalContext.hasNameSpace = true;
2092 //curExternal = curExternal.prev;
2093 //afterExternal = afterExternal->next;
2095 //ProcessFunction(afterExternal->function);
2097 //curExternal = afterExternal;
2099 External externalDecl;
2100 externalDecl = MkExternalDeclaration(null);
2101 ast->Insert(oldExternal.prev, externalDecl);
2103 // Which function does this process?
2104 if(createdExternal.function)
2106 ProcessFunction(createdExternal.function);
2108 //curExternal = oldExternal;
2111 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2113 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2114 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2116 //externalDecl = MkExternalDeclaration(decl);
2118 //***** ast->Insert(external.prev, externalDecl);
2119 //ast->Insert(curExternal.prev, externalDecl);
2120 externalDecl.declaration = decl;
2121 if(decl.symbol && !decl.symbol.pointerExternal)
2122 decl.symbol.pointerExternal = externalDecl;
2124 // Trying this out...
2125 declarator.symbol.pointerExternal = externalDecl;
2132 curExternal = declarator.symbol.pointerExternal;
2133 ProcessFunction((FunctionDefinition)members.function);
2135 curExternal = external;
2136 curContext = context;
2140 FreeClassFunction(members.function);
2142 // In this pass, turn this into a MemberInitData
2143 exp = QMkExpId(name);
2144 members.type = dataMembersInit;
2145 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2151 case dataMembersInit:
2153 if(members.dataMembers && classSym)
2156 Location oldyyloc = yylloc;
2157 for(member = members.dataMembers->first; member; member = member.next)
2159 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2160 if(member.initializer && !member.initializer.isConstant)
2161 inst.isConstant = false;
2173 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2175 // OPTIMIZATIONS: TESTING THIS...
2178 if(type.kind == functionType)
2183 for(param = type.params.first; param; param = param.next)
2184 DeclareType(param, declarePointers, true);
2186 DeclareType(type.returnType, declarePointers, true);
2188 else if(type.kind == pointerType && declarePointers)
2189 DeclareType(type.type, declarePointers, false);
2190 else if(type.kind == classType)
2192 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2193 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2195 else if(type.kind == structType || type.kind == unionType)
2198 for(member = type.members.first; member; member = member.next)
2199 DeclareType(member, false, false);
2201 else if(type.kind == arrayType)
2202 DeclareType(type.arrayType, declarePointers, false);
2206 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2208 ClassTemplateArgument * arg = null;
2210 ClassTemplateParameter curParam = null;
2212 for(sClass = _class; sClass; sClass = sClass.base)
2215 if(sClass.templateClass) sClass = sClass.templateClass;
2216 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2218 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2220 for(sClass = sClass.base; sClass; sClass = sClass.base)
2222 if(sClass.templateClass) sClass = sClass.templateClass;
2223 id += sClass.templateParams.count;
2233 arg = &_class.templateArgs[id];
2234 if(arg && param.type == type)
2235 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2240 public Context SetupTemplatesContext(Class _class)
2242 Context context = PushContext();
2243 context.templateTypesOnly = true;
2244 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2246 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2247 for(; param; param = param.next)
2249 if(param.type == type && param.identifier)
2251 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2252 curContext.templateTypes.Add((BTNode)type);
2259 for(sClass = _class; sClass; sClass = sClass.base)
2261 ClassTemplateParameter p;
2262 for(p = sClass.templateParams.first; p; p = p.next)
2264 //OldList * specs = MkList();
2265 //Declarator decl = null;
2266 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2269 TemplateParameter param = p.param;
2273 // ADD DATA TYPE HERE...
2274 p.param = param = TemplateParameter
2276 identifier = MkIdentifier(p.name), type = p.type,
2277 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2280 type = TemplatedType { key = (uintptr)p.name, param = param };
2281 curContext.templateTypes.Add((BTNode)type);
2289 public void FinishTemplatesContext(Context context)
2291 PopContext(context);
2292 FreeContext(context);
2296 public void ProcessMethodType(Method method)
2298 if(!method.dataType)
2300 Context context = SetupTemplatesContext(method._class);
2302 method.dataType = ProcessTypeString(method.dataTypeString, false);
2304 FinishTemplatesContext(context);
2306 if(method.type != virtualMethod && method.dataType)
2308 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2310 if(!method._class.symbol)
2311 method._class.symbol = FindClass(method._class.fullName);
2312 method.dataType.thisClass = method._class.symbol;
2316 // Why was this commented out? Working fine without now...
2319 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2320 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2327 char * par = strstr(type, "(");
2328 char * classOp = null;
2333 for(c = par-type-1; c >= 0; c++)
2335 if(type[c] == ':' && type[c+1] == ':')
2337 classOp = type + c - 1;
2338 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2345 else if(!isspace(type[c]))
2352 int typeLen = strlen(type);
2353 memcpy(temp, classOp, classOpLen);
2354 temp[classOpLen] = '\0';
2356 _class = eSystem_FindClass(module, temp);
2359 method.dataTypeString = new char[typeLen - classOpLen + 1];
2360 memcpy(method.dataTypeString, type, classOp - type);
2361 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2364 method.dataTypeString = type;
2370 public void ProcessPropertyType(Property prop)
2374 Context context = SetupTemplatesContext(prop._class);
2375 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2376 FinishTemplatesContext(context);
2380 public void DeclareMethod(Method method, char * name)
2382 Symbol symbol = method.symbol;
2383 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2385 bool imported = false;
2386 bool dllImport = false;
2388 if(!method.dataType)
2389 method.dataType = ProcessTypeString(method.dataTypeString, false);
2391 if(!symbol || symbol._import || method.type == virtualMethod)
2393 if(!symbol || method.type == virtualMethod)
2396 if(!method._class.symbol)
2397 method._class.symbol = FindClass(method._class.fullName);
2398 classSym = method._class.symbol;
2399 if(!classSym._import)
2401 ModuleImport module;
2403 if(method._class.module && method._class.module.name)
2404 module = FindModule(method._class.module);
2406 module = mainModule;
2407 classSym._import = ClassImport
2409 name = CopyString(method._class.fullName);
2410 isRemote = method._class.isRemote;
2412 module.classes.Add(classSym._import);
2416 symbol = method.symbol = Symbol { };
2420 symbol._import = (ClassImport)MethodImport
2422 name = CopyString(method.name);
2423 isVirtual = method.type == virtualMethod;
2425 classSym._import.methods.Add(symbol._import);
2429 // Set the symbol type
2433 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2435 else if(type.thisClass == (void *)-1)
2437 type.thisClass = null;
2440 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2441 symbol.type = method.dataType;
2442 if(symbol.type) symbol.type.refCount++;
2445 if(!method.thisClass || strcmp(method.thisClass, "void"))
2446 symbol.type.params.Insert(null,
2447 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2450 if(!method.dataType.dllExport)
2453 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2459 if(!method.dataType)
2460 method.dataType = ((Symbol)method.symbol).type;
2461 //ProcessMethodType(method);
2464 if(method.type != virtualMethod && method.dataType)
2465 DeclareType(method.dataType, true, true);
2467 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2469 // We need a declaration here :)
2471 OldList * specifiers, * declarators;
2473 Declarator funcDecl;
2476 specifiers = MkList();
2477 declarators = MkList();
2481 ListAdd(specifiers, MkSpecifier(EXTERN));
2482 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2483 ListAdd(specifiers, MkSpecifier(STATIC));
2485 if(method.type == virtualMethod)
2487 ListAdd(specifiers, MkSpecifier(INT));
2488 d = MkDeclaratorIdentifier(MkIdentifier(name));
2492 d = MkDeclaratorIdentifier(MkIdentifier(name));
2495 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2497 Context context = SetupTemplatesContext(method._class);
2498 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2499 FinishTemplatesContext(context);
2501 funcDecl = GetFuncDecl(d);
2505 Specifier spec, next;
2506 for(spec = specifiers->first; spec; spec = next)
2509 if(spec.type == extendedSpecifier)
2511 specifiers->Remove(spec);
2512 FreeSpecifier(spec);
2517 // Add this parameter if not a static method
2518 if(method.dataType && !method.dataType.staticMethod)
2520 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2522 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2523 TypeName thisParam = MkTypeName(MkListOne(
2524 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2525 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2526 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2527 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2529 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2531 TypeName param = funcDecl.function.parameters->first;
2532 funcDecl.function.parameters->Remove(param);
2533 FreeTypeName(param);
2536 if(!funcDecl.function.parameters)
2537 funcDecl.function.parameters = MkList();
2538 funcDecl.function.parameters->Insert(null, thisParam);
2541 // Make sure we don't have empty parameter declarations for static methods...
2543 else if(!funcDecl.function.parameters)
2545 funcDecl.function.parameters = MkList();
2546 funcDecl.function.parameters->Insert(null,
2547 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2551 ProcessDeclarator(d);
2553 ListAdd(declarators, MkInitDeclarator(d, null));
2555 decl = MkDeclaration(specifiers, declarators);
2557 ReplaceThisClassSpecifiers(specifiers, method._class);
2559 // Keep a different symbol for the function definition than the declaration...
2560 if(symbol.pointerExternal)
2562 Symbol functionSymbol { };
2566 *functionSymbol = *symbol;
2567 functionSymbol.string = CopyString(symbol.string);
2568 if(functionSymbol.type)
2569 functionSymbol.type.refCount++;
2572 excludedSymbols->Add(functionSymbol);
2573 symbol.pointerExternal.symbol = functionSymbol;
2575 external = MkExternalDeclaration(decl);
2577 ast->Insert(curExternal ? curExternal.prev : null, external);
2578 external.symbol = symbol;
2579 symbol.pointerExternal = external;
2583 // Move declaration higher...
2584 ast->Move(symbol.pointerExternal, curExternal.prev);
2587 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2591 char * ReplaceThisClass(Class _class)
2593 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2597 ClassTemplateParameter param;
2600 char className[1024];
2601 strcpy(className, _class.fullName);
2602 for(param = _class.templateParams.first; param; param = param.next)
2604 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2606 if(first) strcat(className, "<");
2607 if(!first) strcat(className, ", ");
2608 if(lastParam + 1 != p)
2610 strcat(className, param.name);
2611 strcat(className, " = ");
2613 strcat(className, param.name);
2621 int len = strlen(className);
2622 if(className[len-1] == '>') className[len++] = ' ';
2623 className[len++] = '>';
2624 className[len++] = '\0';
2626 return CopyString(className);
2629 return CopyString(_class.fullName);
2632 Type ReplaceThisClassType(Class _class)
2634 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2638 ClassTemplateParameter param;
2640 char className[1024];
2641 strcpy(className, _class.fullName);
2643 for(param = _class.templateParams.first; param; param = param.next)
2645 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2647 if(first) strcat(className, "<");
2648 if(!first) strcat(className, ", ");
2649 if(lastParam + 1 != p)
2651 strcat(className, param.name);
2652 strcat(className, " = ");
2654 strcat(className, param.name);
2662 int len = strlen(className);
2663 if(className[len-1] == '>') className[len++] = ' ';
2664 className[len++] = '>';
2665 className[len++] = '\0';
2667 return MkClassType(className);
2668 //return ProcessTypeString(className, false);
2672 return MkClassType(_class.fullName);
2673 //return ProcessTypeString(_class.fullName, false);
2677 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2679 if(specs != null && _class)
2682 for(spec = specs.first; spec; spec = spec.next)
2684 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2686 spec.type = nameSpecifier;
2687 spec.name = ReplaceThisClass(_class);
2688 spec.symbol = FindClass(spec.name); //_class.symbol;
2694 // Returns imported or not
2695 bool DeclareFunction(GlobalFunction function, char * name)
2697 Symbol symbol = function.symbol;
2698 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2700 bool imported = false;
2701 bool dllImport = false;
2703 if(!function.dataType)
2705 function.dataType = ProcessTypeString(function.dataTypeString, false);
2706 if(!function.dataType.thisClass)
2707 function.dataType.staticMethod = true;
2714 ModuleImport module = FindModule(function.module);
2715 // WARNING: This is not added anywhere...
2716 symbol = function.symbol = Symbol { };
2720 if(!function.dataType.dllExport)
2722 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2723 module.functions.Add(symbol._import);
2726 // Set the symbol type
2728 symbol.type = ProcessTypeString(function.dataTypeString, false);
2729 if(!symbol.type.thisClass)
2730 symbol.type.staticMethod = true;
2733 imported = symbol._import ? true : false;
2734 if(imported && function.module != privateModule && function.module.importType != staticImport)
2738 DeclareType(function.dataType, true, true);
2742 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2744 // We need a declaration here :)
2746 OldList * specifiers, * declarators;
2748 Declarator funcDecl;
2751 specifiers = MkList();
2752 declarators = MkList();
2755 ListAdd(specifiers, MkSpecifier(EXTERN));
2758 ListAdd(specifiers, MkSpecifier(STATIC));
2761 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2764 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2766 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2767 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2768 if(function.module.importType == staticImport)
2771 for(spec = specifiers->first; spec; spec = spec.next)
2772 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2774 specifiers->Remove(spec);
2775 FreeSpecifier(spec);
2780 funcDecl = GetFuncDecl(d);
2782 // Make sure we don't have empty parameter declarations for static methods...
2783 if(funcDecl && !funcDecl.function.parameters)
2785 funcDecl.function.parameters = MkList();
2786 funcDecl.function.parameters->Insert(null,
2787 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2790 ListAdd(declarators, MkInitDeclarator(d, null));
2793 Context oldCtx = curContext;
2794 curContext = globalContext;
2795 decl = MkDeclaration(specifiers, declarators);
2796 curContext = oldCtx;
2799 // Keep a different symbol for the function definition than the declaration...
2800 if(symbol.pointerExternal)
2802 Symbol functionSymbol { };
2805 *functionSymbol = *symbol;
2806 functionSymbol.string = CopyString(symbol.string);
2807 if(functionSymbol.type)
2808 functionSymbol.type.refCount++;
2811 excludedSymbols->Add(functionSymbol);
2813 symbol.pointerExternal.symbol = functionSymbol;
2815 external = MkExternalDeclaration(decl);
2817 ast->Insert(curExternal.prev, external);
2818 external.symbol = symbol;
2819 symbol.pointerExternal = external;
2823 // Move declaration higher...
2824 ast->Move(symbol.pointerExternal, curExternal.prev);
2828 symbol.id = curExternal.symbol.idCode;
2831 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2834 void DeclareGlobalData(GlobalData data)
2836 Symbol symbol = data.symbol;
2837 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2842 symbol = data.symbol = Symbol { };
2845 data.dataType = ProcessTypeString(data.dataTypeString, false);
2846 DeclareType(data.dataType, true, true);
2849 if(!symbol.pointerExternal)
2851 // We need a declaration here :)
2853 OldList * specifiers, * declarators;
2857 specifiers = MkList();
2858 declarators = MkList();
2860 ListAdd(specifiers, MkSpecifier(EXTERN));
2861 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2862 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2864 ListAdd(declarators, MkInitDeclarator(d, null));
2866 decl = MkDeclaration(specifiers, declarators);
2867 external = MkExternalDeclaration(decl);
2869 ast->Insert(curExternal.prev, external);
2870 external.symbol = symbol;
2871 symbol.pointerExternal = external;
2875 // Move declaration higher...
2876 ast->Move(symbol.pointerExternal, curExternal.prev);
2880 symbol.id = curExternal.symbol.idCode;
2885 class Conversion : struct
2887 Conversion prev, next;
2893 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2897 // Property convert;
2899 if(source.kind == templateType && dest.kind != templateType)
2901 Type type = ProcessTemplateParameterType(source.templateParameter);
2902 if(type) source = type;
2905 if(dest.kind == templateType && source.kind != templateType)
2907 Type type = ProcessTemplateParameterType(dest.templateParameter);
2908 if(type) dest = type;
2911 if(dest.classObjectType == typedObject)
2913 if(source.classObjectType != anyObject)
2917 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2918 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2926 if(source.classObjectType == anyObject)
2928 if(dest.classObjectType == anyObject && source.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) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
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 || source.kind == _BoolType))
3173 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3175 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3177 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3179 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3181 else if(source.kind == enumType &&
3182 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3184 else if(dest.kind == enumType &&
3185 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3187 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3188 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3190 Type paramSource, paramDest;
3192 if(dest.kind == methodType)
3193 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3194 if(source.kind == methodType)
3195 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3197 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3198 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3199 if(dest.kind == methodType)
3200 dest = dest.method.dataType;
3201 if(source.kind == methodType)
3202 source = source.method.dataType;
3204 paramSource = source.params.first;
3205 if(paramSource && paramSource.kind == voidType) paramSource = null;
3206 paramDest = dest.params.first;
3207 if(paramDest && paramDest.kind == voidType) paramDest = null;
3210 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3211 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3213 // Source thisClass must be derived from destination thisClass
3214 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3215 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3217 if(paramDest && paramDest.kind == classType)
3218 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3220 Compiler_Error($"method class should not take an object\n");
3223 paramDest = paramDest.next;
3225 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3227 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3231 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3233 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3239 // THIS WAS BACKWARDS:
3240 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3241 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3244 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3246 Compiler_Error($"overriding class expected to be derived from method class\n");
3250 paramSource = paramSource.next;
3256 // Source thisClass must be derived from destination thisClass
3257 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3259 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3265 // THIS WAS BACKWARDS TOO??
3266 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3267 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3270 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3272 //Compiler_Error($"overriding class expected to be derived from method class\n");
3280 // Source return type must be derived from destination return type
3281 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3283 Compiler_Warning($"incompatible return type for function\n");
3289 for(; paramDest; paramDest = paramDest.next)
3293 //Compiler_Warning($"not enough parameters\n");
3294 Compiler_Error($"not enough parameters\n");
3298 Type paramDestType = paramDest;
3299 Type paramSourceType = paramSource;
3300 Type type = paramDestType;
3302 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3303 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3304 paramSource.kind != templateType)
3307 ClassTemplateParameter curParam = null;
3309 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3312 if(sClass.templateClass) sClass = sClass.templateClass;
3313 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3315 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3317 for(sClass = sClass.base; sClass; sClass = sClass.base)
3319 if(sClass.templateClass) sClass = sClass.templateClass;
3320 id += sClass.templateParams.count;
3331 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3332 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3336 // paramDest must be derived from paramSource
3337 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3338 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3342 PrintType(paramDest, type, false, true);
3343 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3345 if(paramDestType != paramDest)
3346 FreeType(paramDestType);
3349 if(paramDestType != paramDest)
3350 FreeType(paramDestType);
3353 paramSource = paramSource.next;
3357 Compiler_Error($"too many parameters\n");
3362 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3366 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3367 (source.kind == arrayType || source.kind == pointerType))
3369 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3376 static void FreeConvert(Conversion convert)
3378 if(convert.resultType)
3379 FreeType(convert.resultType);
3382 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3383 char * string, OldList conversions)
3387 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3389 Class _class = link.data;
3390 if(_class.type == enumClass)
3392 OldList converts { };
3394 type.kind = classType;
3397 _class.symbol = FindClass(_class.fullName);
3398 type._class = _class.symbol;
3400 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3403 Class enumClass = eSystem_FindClass(privateModule, "enum");
3407 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3409 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3410 for(value = e.values.first; value; value = value.next)
3412 if(!strcmp(value.name, string))
3417 FreeExpContents(sourceExp);
3418 FreeType(sourceExp.expType);
3420 sourceExp.isConstant = true;
3421 sourceExp.expType = MkClassType(baseClass.fullName);
3425 sourceExp.type = constantExp;
3426 if(!strcmp(baseClass.dataTypeString, "int"))
3427 sprintf(constant, "%d",(int)value.data);
3429 sprintf(constant, "0x%X",(int)value.data);
3430 sourceExp.constant = CopyString(constant);
3431 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3434 while(converts.first)
3436 Conversion convert = converts.first;
3437 converts.Remove(convert);
3438 conversions.Add(convert);
3447 converts.Free(FreeConvert);
3451 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3452 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3457 public bool ModuleVisibility(Module searchIn, Module searchFor)
3459 SubModule subModule;
3461 if(searchFor == searchIn)
3464 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3466 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3468 if(ModuleVisibility(subModule.module, searchFor))
3475 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3479 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3481 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3483 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3486 for(module = mainModule.application.allModules.first; module; module = module.next)
3488 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3494 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3496 Type source = sourceExp.expType;
3497 Type realDest = dest;
3498 Type backupSourceExpType = null;
3500 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3503 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3505 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3507 Class sourceBase, destBase;
3508 for(sourceBase = source._class.registered;
3509 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3510 sourceBase = sourceBase.base);
3511 for(destBase = dest._class.registered;
3512 destBase && destBase.base && destBase.base.type != systemClass;
3513 destBase = destBase.base);
3514 //if(source._class.registered == dest._class.registered)
3515 if(sourceBase == destBase)
3524 int64 value = MAXINT;
3529 if(sourceExp.type == constantExp)
3532 value = strtoll(sourceExp.constant, null, 0);
3534 value = strtoull(sourceExp.constant, null, 0);
3536 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3539 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3541 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3544 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3545 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3548 source = Type { kind = intType, isSigned = false, refCount = 1 };
3551 if(dest.kind == classType)
3553 Class _class = dest._class ? dest._class.registered : null;
3555 if(_class && _class.type == unitClass)
3557 if(source.kind != classType)
3560 Type tempDest, tempSource;
3562 for(; _class.base.type != systemClass; _class = _class.base);
3564 tempDest = tempType;
3566 tempType.kind = classType;
3568 _class.symbol = FindClass(_class.fullName);
3570 tempType._class = _class.symbol;
3571 tempType.truth = dest.truth;
3573 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3575 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3576 backupSourceExpType = sourceExp.expType;
3577 sourceExp.expType = dest; dest.refCount++;
3578 //sourceExp.expType = MkClassType(_class.fullName);
3586 // Why wasn't there something like this?
3587 if(_class && _class.type == bitClass && source.kind != classType)
3589 if(!dest._class.registered.dataType)
3590 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3591 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3594 FreeType(sourceExp.expType);
3595 source = sourceExp.expType = MkClassType(dest._class.string);
3598 //source.kind = classType;
3599 //source._class = dest._class;
3603 // Adding two enumerations
3605 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3607 if(!source._class.registered.dataType)
3608 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3609 if(!dest._class.registered.dataType)
3610 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3612 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3615 source = sourceExp.expType = MkClassType(dest._class.string);
3618 //source.kind = classType;
3619 //source._class = dest._class;
3623 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3625 OldList * specs = MkList();
3629 ReadString(string, sourceExp.string);
3630 decl = SpecDeclFromString(string, specs, null);
3632 FreeExpContents(sourceExp);
3633 FreeType(sourceExp.expType);
3635 sourceExp.type = classExp;
3636 sourceExp._classExp.specifiers = specs;
3637 sourceExp._classExp.decl = decl;
3638 sourceExp.expType = dest;
3643 if(backupSourceExpType) FreeType(backupSourceExpType);
3647 else if(source.kind == classType)
3649 Class _class = source._class ? source._class.registered : null;
3651 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3654 if(dest.kind != classType)
3656 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3657 if(!source._class.registered.dataType)
3658 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3661 dest = MkClassType(source._class.string);
3662 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3663 // dest = MkClassType(source._class.string);
3667 if(dest.kind != classType)
3670 Type tempDest, tempSource;
3672 if(!source._class.registered.dataType)
3673 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3675 for(; _class.base.type != systemClass; _class = _class.base);
3677 tempSource = tempType;
3678 tempType.kind = classType;
3679 tempType._class = FindClass(_class.fullName);
3680 tempType.truth = source.truth;
3681 tempType.classObjectType = source.classObjectType;
3684 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3686 // PUT THIS BACK TESTING UNITS?
3687 if(conversions.last)
3689 ((Conversion)(conversions.last)).resultType = dest;
3693 FreeType(sourceExp.expType);
3694 sourceExp.expType = MkClassType(_class.fullName);
3695 sourceExp.expType.truth = source.truth;
3696 sourceExp.expType.classObjectType = source.classObjectType;
3698 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3700 if(!sourceExp.destType)
3702 FreeType(sourceExp.destType);
3703 sourceExp.destType = sourceExp.expType;
3704 if(sourceExp.expType)
3705 sourceExp.expType.refCount++;
3708 //source = _class.dataType;
3711 // TOCHECK: TESTING THIS NEW CODE
3712 if(!_class.dataType)
3713 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3715 dest = MkClassType(source._class.string);
3716 dest.truth = source.truth;
3717 dest.classObjectType = source.classObjectType;
3720 source = _class.dataType;
3730 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3740 if(source.kind == classType)
3742 Class _class = source._class.registered;
3743 if(_class.type == unitClass)
3745 if(!_class.dataType)
3746 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3747 source = _class.dataType;
3751 if(dest.kind == classType)
3753 Class _class = dest._class ? dest._class.registered : null;
3754 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3755 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3757 if(_class.type == normalClass || _class.type == noHeadClass)
3759 Expression newExp { };
3760 *newExp = *sourceExp;
3761 if(sourceExp.destType) sourceExp.destType.refCount++;
3762 if(sourceExp.expType) sourceExp.expType.refCount++;
3763 sourceExp.type = castExp;
3764 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3765 sourceExp.cast.exp = newExp;
3766 FreeType(sourceExp.expType);
3767 sourceExp.expType = null;
3768 ProcessExpressionType(sourceExp);
3770 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3773 FreeType(sourceExp.expType);
3774 sourceExp.expType = dest;
3778 if(inCompiler) FreeType(dest);
3780 if(backupSourceExpType) FreeType(backupSourceExpType);
3784 if(!_class.dataType)
3785 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3787 dest = _class.dataType;
3791 // Accept lower precision types for units, since we want to keep the unit type
3792 if(dest.kind == doubleType &&
3793 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3794 source.kind == charType || source.kind == _BoolType))
3796 specs = MkListOne(MkSpecifier(DOUBLE));
3798 else if(dest.kind == floatType &&
3799 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3800 source.kind == _BoolType || source.kind == doubleType))
3802 specs = MkListOne(MkSpecifier(FLOAT));
3804 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3805 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3808 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3809 ListAdd(specs, MkSpecifier(INT64));
3811 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3812 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3815 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3816 ListAdd(specs, MkSpecifier(INT));
3818 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3819 source.kind == floatType || source.kind == doubleType))
3822 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3823 ListAdd(specs, MkSpecifier(SHORT));
3825 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3826 source.kind == floatType || source.kind == doubleType))
3829 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3830 ListAdd(specs, MkSpecifier(CHAR));
3836 if(backupSourceExpType)
3838 // Failed to convert: revert previous exp type
3839 if(sourceExp.expType) FreeType(sourceExp.expType);
3840 sourceExp.expType = backupSourceExpType;
3845 else if(dest.kind == doubleType &&
3846 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3847 source.kind == _BoolType || source.kind == charType))
3849 specs = MkListOne(MkSpecifier(DOUBLE));
3851 else if(dest.kind == floatType &&
3852 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3854 specs = MkListOne(MkSpecifier(FLOAT));
3856 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3857 (value == 1 || value == 0))
3860 ListAdd(specs, MkSpecifier(BOOL));
3862 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3863 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3866 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3867 ListAdd(specs, MkSpecifier(CHAR));
3869 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3870 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3873 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3874 ListAdd(specs, MkSpecifier(SHORT));
3876 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3879 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3880 ListAdd(specs, MkSpecifier(INT));
3882 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3885 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3886 ListAdd(specs, MkSpecifier(INT64));
3888 else if(dest.kind == enumType &&
3889 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3891 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3897 if(backupSourceExpType)
3899 // Failed to convert: revert previous exp type
3900 if(sourceExp.expType) FreeType(sourceExp.expType);
3901 sourceExp.expType = backupSourceExpType;
3908 Expression newExp { };
3909 *newExp = *sourceExp;
3912 if(sourceExp.destType) sourceExp.destType.refCount++;
3913 if(sourceExp.expType) sourceExp.expType.refCount++;
3915 sourceExp.type = castExp;
3916 if(realDest.kind == classType)
3918 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3919 FreeList(specs, FreeSpecifier);
3922 sourceExp.cast.typeName = MkTypeName(specs, null);
3923 if(newExp.type == opExp)
3925 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3928 sourceExp.cast.exp = newExp;
3930 FreeType(sourceExp.expType);
3931 sourceExp.expType = null;
3932 ProcessExpressionType(sourceExp);
3935 FreeList(specs, FreeSpecifier);
3939 if(backupSourceExpType) FreeType(backupSourceExpType);
3945 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3946 if(sourceExp.type == identifierExp)
3948 Identifier id = sourceExp.identifier;
3949 if(dest.kind == classType)
3951 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3953 Class _class = dest._class.registered;
3954 Class enumClass = eSystem_FindClass(privateModule, "enum");
3957 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3960 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3961 for(value = e.values.first; value; value = value.next)
3963 if(!strcmp(value.name, id.string))
3968 FreeExpContents(sourceExp);
3969 FreeType(sourceExp.expType);
3971 sourceExp.isConstant = true;
3972 sourceExp.expType = MkClassType(_class.fullName);
3976 sourceExp.type = constantExp;
3977 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3978 sprintf(constant, "%d", (int) value.data);
3980 sprintf(constant, "0x%X", (int) value.data);
3981 sourceExp.constant = CopyString(constant);
3982 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3991 // Loop through all enum classes
3992 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3999 #define TERTIARY(o, name, m, t, p) \
4000 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4002 exp.type = constantExp; \
4003 exp.string = p(op1.m ? op2.m : op3.m); \
4005 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4009 #define BINARY(o, name, m, t, p) \
4010 static bool name(Expression exp, Operand op1, Operand op2) \
4013 exp.type = constantExp; \
4014 exp.string = p(op1.m o value2); \
4016 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4020 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4021 static bool name(Expression exp, Operand op1, Operand op2) \
4024 exp.type = constantExp; \
4025 exp.string = p(value2 ? (op1.m o value2) : 0); \
4027 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4031 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4032 static bool name(Expression exp, Operand op1, Operand op2) \
4035 exp.type = constantExp; \
4036 exp.string = p(op1.m o value2); \
4038 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4042 #define UNARY(o, name, m, t, p) \
4043 static bool name(Expression exp, Operand op1) \
4045 exp.type = constantExp; \
4046 exp.string = p((t)(o op1.m)); \
4048 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4052 #define OPERATOR_ALL(macro, o, name) \
4053 macro(o, Int##name, i, int, PrintInt) \
4054 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4055 macro(o, Int64##name, i64, int64, PrintInt64) \
4056 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4057 macro(o, Short##name, s, short, PrintShort) \
4058 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4059 macro(o, Char##name, c, char, PrintChar) \
4060 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4061 macro(o, Float##name, f, float, PrintFloat) \
4062 macro(o, Double##name, d, double, PrintDouble)
4064 #define OPERATOR_INTTYPES(macro, o, name) \
4065 macro(o, Int##name, i, int, PrintInt) \
4066 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4067 macro(o, Int64##name, i64, int64, PrintInt64) \
4068 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4069 macro(o, Short##name, s, short, PrintShort) \
4070 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4071 macro(o, Char##name, c, char, PrintChar) \
4072 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4074 #define OPERATOR_REALTYPES(macro, o, name) \
4075 macro(o, Float##name, f, float, PrintFloat) \
4076 macro(o, Double##name, d, double, PrintDouble)
4078 // binary arithmetic
4079 OPERATOR_ALL(BINARY, +, Add)
4080 OPERATOR_ALL(BINARY, -, Sub)
4081 OPERATOR_ALL(BINARY, *, Mul)
4082 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4083 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4084 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4087 OPERATOR_ALL(UNARY, -, Neg)
4089 // unary arithmetic increment and decrement
4090 OPERATOR_ALL(UNARY, ++, Inc)
4091 OPERATOR_ALL(UNARY, --, Dec)
4093 // binary arithmetic assignment
4094 OPERATOR_ALL(BINARY, =, Asign)
4095 OPERATOR_ALL(BINARY, +=, AddAsign)
4096 OPERATOR_ALL(BINARY, -=, SubAsign)
4097 OPERATOR_ALL(BINARY, *=, MulAsign)
4098 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4099 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4100 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4103 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4104 OPERATOR_INTTYPES(BINARY, |, BitOr)
4105 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4106 OPERATOR_INTTYPES(BINARY, <<, LShift)
4107 OPERATOR_INTTYPES(BINARY, >>, RShift)
4110 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4112 // binary bitwise assignment
4113 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4114 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4115 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4116 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4117 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4119 // unary logical negation
4120 OPERATOR_INTTYPES(UNARY, !, Not)
4122 // binary logical equality
4123 OPERATOR_ALL(BINARY, ==, Equ)
4124 OPERATOR_ALL(BINARY, !=, Nqu)
4127 OPERATOR_ALL(BINARY, &&, And)
4128 OPERATOR_ALL(BINARY, ||, Or)
4130 // binary logical relational
4131 OPERATOR_ALL(BINARY, >, Grt)
4132 OPERATOR_ALL(BINARY, <, Sma)
4133 OPERATOR_ALL(BINARY, >=, GrtEqu)
4134 OPERATOR_ALL(BINARY, <=, SmaEqu)
4136 // tertiary condition operator
4137 OPERATOR_ALL(TERTIARY, ?, Cond)
4139 //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
4140 #define OPERATOR_TABLE_ALL(name, type) \
4141 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4143 type##Inc, type##Dec, \
4144 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4145 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4147 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4149 type##Equ, type##Nqu, \
4150 type##And, type##Or, \
4151 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4154 #define OPERATOR_TABLE_INTTYPES(name, type) \
4155 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4157 type##Inc, type##Dec, \
4158 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4159 null, null, null, null, null, \
4161 null, null, null, null, null, \
4163 type##Equ, type##Nqu, \
4164 type##And, type##Or, \
4165 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4168 OPERATOR_TABLE_ALL(int, Int)
4169 OPERATOR_TABLE_ALL(uint, UInt)
4170 OPERATOR_TABLE_ALL(int64, Int64)
4171 OPERATOR_TABLE_ALL(uint64, UInt64)
4172 OPERATOR_TABLE_ALL(short, Short)
4173 OPERATOR_TABLE_ALL(ushort, UShort)
4174 OPERATOR_TABLE_INTTYPES(float, Float)
4175 OPERATOR_TABLE_INTTYPES(double, Double)
4176 OPERATOR_TABLE_ALL(char, Char)
4177 OPERATOR_TABLE_ALL(uchar, UChar)
4179 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4180 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4181 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4182 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4183 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4184 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4185 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4186 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4188 public void ReadString(char * output, char * string)
4190 int len = strlen(string);
4192 bool quoted = false, escaped = false;
4193 for(c = 0; c<len; c++)
4195 char ch = string[c];
4200 case 'n': output[d] = '\n'; break;
4201 case 't': output[d] = '\t'; break;
4202 case 'a': output[d] = '\a'; break;
4203 case 'b': output[d] = '\b'; break;
4204 case 'f': output[d] = '\f'; break;
4205 case 'r': output[d] = '\r'; break;
4206 case 'v': output[d] = '\v'; break;
4207 case '\\': output[d] = '\\'; break;
4208 case '\"': output[d] = '\"'; break;
4209 case '\'': output[d] = '\''; break;
4210 default: output[d] = ch;
4231 // String Unescape Copy
4233 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4234 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4235 public int UnescapeString(char * d, char * s, int len)
4239 while(j < len && (ch = s[j]))
4244 switch((ch = s[++j]))
4246 case 'n': d[k] = '\n'; break;
4247 case 't': d[k] = '\t'; break;
4248 case 'a': d[k] = '\a'; break;
4249 case 'b': d[k] = '\b'; break;
4250 case 'f': d[k] = '\f'; break;
4251 case 'r': d[k] = '\r'; break;
4252 case 'v': d[k] = '\v'; break;
4253 case '\\': d[k] = '\\'; break;
4254 case '\"': d[k] = '\"'; break;
4255 case '\'': d[k] = '\''; break;
4256 default: d[k] = '\\'; d[k] = ch;
4268 public char * OffsetEscapedString(char * s, int len, int offset)
4272 while(j < len && k < offset && (ch = s[j]))
4277 return (k == offset) ? s + j : null;
4280 public Operand GetOperand(Expression exp)
4283 Type type = exp.expType;
4286 while(type.kind == classType &&
4287 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4289 if(!type._class.registered.dataType)
4290 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4291 type = type._class.registered.dataType;
4294 if(exp.type == stringExp && op.kind == pointerType)
4296 op.ui64 = (uint64)exp.string;
4297 op.kind = pointerType;
4300 else if(exp.isConstant && exp.type == constantExp)
4302 op.kind = type.kind;
4303 op.type = exp.expType;
4310 if(exp.constant[0] == '\'')
4312 op.c = exp.constant[1];
4315 else if(type.isSigned)
4317 op.c = (char)strtol(exp.constant, null, 0);
4322 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4330 op.s = (short)strtol(exp.constant, null, 0);
4335 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4343 op.i = (int)strtol(exp.constant, null, 0);
4348 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4356 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4361 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4364 op.kind = int64Type;
4369 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4374 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4377 op.kind = int64Type;
4382 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4387 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4390 op.kind = int64Type;
4393 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4394 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4395 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4396 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4398 op.f = (float)strtod(exp.constant, null);
4402 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4403 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4404 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4405 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4407 op.d = (double)strtod(exp.constant, null);
4410 //case classType: For when we have operator overloading...
4411 // Pointer additions
4412 //case functionType:
4416 op.ui64 = _strtoui64(exp.constant, null, 0);
4417 op.kind = pointerType;
4427 static void UnusedFunction()
4430 a.OnGetString(0,0,0);
4433 extern int __ecereVMethodID_class_OnGetString;
4436 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4438 DataMember dataMember;
4439 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4441 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4442 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4446 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4448 void * ptr = inst.data + dataMember.offset + offset;
4449 char * result = null;
4450 exp.loc = member.loc = inst.loc;
4451 ((Identifier)member.identifiers->first).loc = inst.loc;
4453 if(!dataMember.dataType)
4454 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4455 type = dataMember.dataType;
4456 if(type.kind == classType)
4458 Class _class = type._class.registered;
4459 if(_class.type == enumClass)
4461 Class enumClass = eSystem_FindClass(privateModule, "enum");
4464 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4466 for(item = e.values.first; item; item = item.next)
4468 if((int)item.data == *(int *)ptr)
4476 exp.identifier = MkIdentifier(result);
4477 exp.type = identifierExp;
4478 exp.destType = MkClassType(_class.fullName);
4479 ProcessExpressionType(exp);
4483 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4485 if(!_class.dataType)
4486 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4487 type = _class.dataType;
4496 FreeExpContents(exp);
4498 exp.constant = PrintFloat(*(float*)ptr);
4499 exp.type = constantExp;
4504 FreeExpContents(exp);
4506 exp.constant = PrintDouble(*(double*)ptr);
4507 exp.type = constantExp;
4512 FreeExpContents(exp);
4514 exp.constant = PrintInt(*(int*)ptr);
4515 exp.type = constantExp;
4520 FreeExpContents(exp);
4522 exp.constant = PrintInt64(*(int64*)ptr);
4523 exp.type = constantExp;
4528 FreeExpContents(exp);
4529 // TODO: This should probably use proper type
4530 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4531 exp.type = constantExp;
4536 FreeExpContents(exp);
4537 // TODO: This should probably use proper type
4538 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4539 exp.type = constantExp;
4543 Compiler_Error($"Unhandled type populating instance\n");
4546 ListAdd(memberList, member);
4549 if(parentDataMember.type == unionMember)
4554 void PopulateInstance(Instantiation inst)
4556 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4557 Class _class = classSym.registered;
4558 DataMember dataMember;
4559 OldList * memberList = MkList();
4560 // Added this check and ->Add to prevent memory leaks on bad code
4562 inst.members = MkListOne(MkMembersInitList(memberList));
4564 inst.members->Add(MkMembersInitList(memberList));
4565 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4567 if(!dataMember.isProperty)
4569 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4570 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4574 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4576 void * ptr = inst.data + dataMember.offset;
4577 char * result = null;
4579 exp.loc = member.loc = inst.loc;
4580 ((Identifier)member.identifiers->first).loc = inst.loc;
4582 if(!dataMember.dataType)
4583 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4584 type = dataMember.dataType;
4585 if(type.kind == classType)
4587 Class _class = type._class.registered;
4588 if(_class.type == enumClass)
4590 Class enumClass = eSystem_FindClass(privateModule, "enum");
4593 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4595 for(item = e.values.first; item; item = item.next)
4597 if((int)item.data == *(int *)ptr)
4606 exp.identifier = MkIdentifier(result);
4607 exp.type = identifierExp;
4608 exp.destType = MkClassType(_class.fullName);
4609 ProcessExpressionType(exp);
4612 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4614 if(!_class.dataType)
4615 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4616 type = _class.dataType;
4625 exp.constant = PrintFloat(*(float*)ptr);
4626 exp.type = constantExp;
4631 exp.constant = PrintDouble(*(double*)ptr);
4632 exp.type = constantExp;
4637 exp.constant = PrintInt(*(int*)ptr);
4638 exp.type = constantExp;
4643 exp.constant = PrintInt64(*(int64*)ptr);
4644 exp.type = constantExp;
4649 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4650 exp.type = constantExp;
4654 Compiler_Error($"Unhandled type populating instance\n");
4657 ListAdd(memberList, member);
4663 void ComputeInstantiation(Expression exp)
4665 Instantiation inst = exp.instance;
4666 MembersInit members;
4667 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4668 Class _class = classSym ? classSym.registered : null;
4669 DataMember curMember = null;
4670 Class curClass = null;
4671 DataMember subMemberStack[256];
4672 int subMemberStackPos = 0;
4675 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4677 // Don't recompute the instantiation...
4678 // Non Simple classes will have become constants by now
4682 if(_class.type == normalClass || _class.type == noHeadClass)
4684 inst.data = (byte *)eInstance_New(_class);
4685 if(_class.type == normalClass)
4686 ((Instance)inst.data)._refCount++;
4689 inst.data = new0 byte[_class.structSize];
4694 for(members = inst.members->first; members; members = members.next)
4696 switch(members.type)
4698 case dataMembersInit:
4700 if(members.dataMembers)
4703 for(member = members.dataMembers->first; member; member = member.next)
4705 Identifier ident = member.identifiers ? member.identifiers->first : null;
4708 Property prop = null;
4709 DataMember dataMember = null;
4710 Method method = null;
4711 uint dataMemberOffset;
4715 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4718 if(curMember.isProperty)
4719 prop = (Property)curMember;
4722 dataMember = curMember;
4724 // CHANGED THIS HERE
4725 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4727 // 2013/17/29 -- It seems that this was missing here!
4728 if(_class.type == normalClass)
4729 dataMemberOffset += _class.base.structSize;
4730 // dataMemberOffset = dataMember.offset;
4737 prop = eClass_FindProperty(_class, ident.string, privateModule);
4741 if(prop.memberAccess == publicAccess)
4743 curMember = (DataMember)prop;
4744 curClass = prop._class;
4749 DataMember _subMemberStack[256];
4750 int _subMemberStackPos = 0;
4752 // FILL MEMBER STACK
4753 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4758 if(dataMember.memberAccess == publicAccess)
4760 curMember = dataMember;
4761 curClass = dataMember._class;
4762 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4763 subMemberStackPos = _subMemberStackPos;
4769 if(found && member.initializer && member.initializer.type == expInitializer)
4771 Expression value = member.initializer.exp;
4773 bool deepMember = false;
4776 type = prop.dataType;
4780 if(!dataMember.dataType)
4781 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4783 type = dataMember.dataType;
4786 if(ident && ident.next)
4790 // for(; ident && type; ident = ident.next)
4791 for(ident = ident.next; ident && type; ident = ident.next)
4793 if(type.kind == classType)
4795 prop = eClass_FindProperty(type._class.registered,
4796 ident.string, privateModule);
4798 type = prop.dataType;
4801 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4802 ident.string, &dataMemberOffset, privateModule, null, null);
4804 type = dataMember.dataType;
4807 else if(type.kind == structType || type.kind == unionType)
4810 for(memberType = type.members.first; memberType; memberType = memberType.next)
4812 if(!strcmp(memberType.name, ident.string))
4823 FreeType(value.destType);
4824 value.destType = type;
4825 if(type) type.refCount++;
4826 ComputeExpression(value);
4828 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4830 if(type.kind == classType)
4832 Class _class = type._class.registered;
4833 if(_class.type == bitClass || _class.type == unitClass ||
4834 _class.type == enumClass)
4836 if(!_class.dataType)
4837 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4838 type = _class.dataType;
4844 void * ptr = inst.data + dataMemberOffset;
4846 if(value.type == constantExp)
4852 GetInt(value, (int*)ptr);
4857 GetInt64(value, (int64*)ptr);
4862 GetIntPtr(value, (intptr*)ptr);
4867 GetIntSize(value, (intsize*)ptr);
4872 GetFloat(value, (float*)ptr);
4877 GetDouble(value, (double *)ptr);
4882 else if(value.type == instanceExp)
4884 if(type.kind == classType)
4886 Class _class = type._class.registered;
4887 if(_class.type == structClass)
4889 ComputeTypeSize(type);
4890 if(value.instance.data)
4891 memcpy(ptr, value.instance.data, type.size);
4898 if(value.type == instanceExp && value.instance.data)
4900 if(type.kind == classType)
4902 Class _class = type._class.registered;
4903 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4905 void (*Set)(void *, void *) = (void *)prop.Set;
4906 Set(inst.data, value.instance.data);
4907 PopulateInstance(inst);
4911 else if(value.type == constantExp)
4917 void (*Set)(void *, double) = (void *)prop.Set;
4918 Set(inst.data, strtod(value.constant, null) );
4923 void (*Set)(void *, float) = (void *)prop.Set;
4924 Set(inst.data, (float)(strtod(value.constant, null)));
4929 void (*Set)(void *, int) = (void *)prop.Set;
4930 Set(inst.data, (int)strtol(value.constant, null, 0));
4935 void (*Set)(void *, int64) = (void *)prop.Set;
4936 Set(inst.data, _strtoi64(value.constant, null, 0));
4941 void (*Set)(void *, intptr) = (void *)prop.Set;
4942 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4947 void (*Set)(void *, intsize) = (void *)prop.Set;
4948 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4953 else if(value.type == stringExp)
4956 ReadString(temp, value.string);
4957 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4961 else if(!deepMember && type && _class.type == unitClass)
4965 // Only support converting units to units for now...
4966 if(value.type == constantExp)
4968 if(type.kind == classType)
4970 Class _class = type._class.registered;
4971 if(_class.type == unitClass)
4973 if(!_class.dataType)
4974 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4975 type = _class.dataType;
4978 // TODO: Assuming same base type for units...
4984 float (*Set)(float) = (void *)prop.Set;
4985 GetFloat(member.initializer.exp, &fValue);
4986 exp.constant = PrintFloat(Set(fValue));
4987 exp.type = constantExp;
4993 double (*Set)(double) = (void *)prop.Set;
4994 GetDouble(member.initializer.exp, &dValue);
4995 exp.constant = PrintDouble(Set(dValue));
4996 exp.type = constantExp;
5003 else if(!deepMember && type && _class.type == bitClass)
5007 if(value.type == instanceExp && value.instance.data)
5009 unsigned int (*Set)(void *) = (void *)prop.Set;
5010 bits = Set(value.instance.data);
5012 else if(value.type == constantExp)
5018 BitMember bitMember = (BitMember) dataMember;
5021 GetInt(value, &part);
5022 bits = (bits & ~bitMember.mask);
5023 if(!bitMember.dataType)
5024 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5026 type = bitMember.dataType;
5028 if(type.kind == classType && type._class && type._class.registered)
5030 if(!type._class.registered.dataType)
5031 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5032 type = type._class.registered.dataType;
5040 bits |= ((char)part << bitMember.pos);
5042 bits |= ((unsigned char)part << bitMember.pos);
5046 bits |= ((short)part << bitMember.pos);
5048 bits |= ((unsigned short)part << bitMember.pos);
5053 bits |= ((int)part << bitMember.pos);
5055 bits |= ((unsigned int)part << bitMember.pos);
5059 bits |= ((int64)part << bitMember.pos);
5061 bits |= ((uint64)part << bitMember.pos);
5066 bits |= ((intptr)part << bitMember.pos);
5070 bits |= ((uintptr)part << bitMember.pos);
5076 bits |= ((ssize_t)(intsize)part << bitMember.pos);
5080 bits |= ((size_t) (uintsize)part << bitMember.pos);
5089 if(_class && _class.type == unitClass)
5091 ComputeExpression(member.initializer.exp);
5092 exp.constant = member.initializer.exp.constant;
5093 exp.type = constantExp;
5095 member.initializer.exp.constant = null;
5105 if(_class && _class.type == bitClass)
5107 exp.constant = PrintHexUInt(bits);
5108 exp.type = constantExp;
5110 if(exp.type != instanceExp)
5116 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5118 bool result = false;
5122 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5123 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5127 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5128 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5131 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5132 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5133 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5136 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5137 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5138 result = GetOpFloat(op, &op.f);
5141 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5142 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5143 result = GetOpDouble(op, &op.d);
5146 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5147 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5148 result = GetOpUIntPtr(op, &op.ui64);
5151 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5152 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5153 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5156 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5157 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5160 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5161 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5167 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5169 if(exp.op.op == SIZEOF)
5171 FreeExpContents(exp);
5172 exp.type = constantExp;
5173 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5184 // Provide default unary +
5185 Expression exp2 = exp.op.exp2;
5187 FreeExpContents(exp);
5188 FreeType(exp.expType);
5189 FreeType(exp.destType);
5195 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5197 // unary arithmetic increment and decrement
5198 //OPERATOR_ALL(UNARY, ++, Inc)
5199 //OPERATOR_ALL(UNARY, --, Dec)
5202 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5204 // unary logical negation
5206 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5212 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5214 if(Promote(op2, op1.kind, op1.type.isSigned))
5215 op2.kind = op1.kind, op2.ops = op1.ops;
5216 else if(Promote(op1, op2.kind, op2.type.isSigned))
5217 op1.kind = op2.kind, op1.ops = op2.ops;
5221 // binary arithmetic
5223 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5226 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5229 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5232 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5235 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5237 // binary arithmetic assignment
5238 //OPERATOR_ALL(BINARY, =, Asign)
5239 //OPERATOR_ALL(BINARY, +=, AddAsign)
5240 //OPERATOR_ALL(BINARY, -=, SubAsign)
5241 //OPERATOR_ALL(BINARY, *=, MulAsign)
5242 //OPERATOR_ALL(BINARY, /=, DivAsign)
5243 //OPERATOR_ALL(BINARY, %=, ModAsign)
5248 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5252 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5255 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5258 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5261 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5263 // binary bitwise assignment
5264 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5265 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5266 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5267 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5268 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5269 // binary logical equality
5271 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5274 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5278 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5281 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5283 // binary logical relational
5285 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5288 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5291 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5294 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5301 void ComputeExpression(Expression exp)
5303 char expString[10240];
5304 expString[0] = '\0';
5306 PrintExpression(exp, expString);
5313 ComputeInstantiation(exp);
5322 Expression exp1, exp2 = null;
5326 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5329 Expression e = exp.op.exp2;
5331 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5333 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5335 if(e.type == extensionCompoundExp)
5336 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5341 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5343 if(e.type == stringExp && e.string)
5345 char * string = e.string;
5346 int len = strlen(string);
5347 char * tmp = new char[len-2+1];
5348 len = UnescapeString(tmp, string + 1, len - 2);
5350 FreeExpContents(exp);
5351 exp.type = constantExp;
5352 exp.constant = PrintUInt(len + 1);
5356 Type type = e.expType;
5358 FreeExpContents(exp);
5359 exp.type = constantExp;
5360 exp.constant = PrintUInt(ComputeTypeSize(type));
5366 ComputeExpression(exp.op.exp2);
5370 ComputeExpression(exp.op.exp1);
5373 op1 = GetOperand(exp1);
5374 if(op1.type) op1.type.refCount++;
5377 op2 = GetOperand(exp2);
5378 if(op2.type) op2.type.refCount++;
5384 op1 = GetOperand(exp1);
5385 if(op1.type) op1.type.refCount++;
5388 CallOperator(exp, exp1, exp2, op1, op2);
5395 if(exp.op.exp1 && exp.op.exp2)
5400 FreeExpContents(exp);
5401 op1.ops.BitAnd(exp, op1, op2);
5410 FreeExpContents(exp);
5411 op1.ops.Mul(exp, op1, op2);
5420 FreeExpContents(exp);
5421 op1.ops.Add(exp, op1, op2);
5426 // Provide default unary +
5427 Expression exp2 = exp.op.exp2;
5429 FreeExpContents(exp);
5430 FreeType(exp.expType);
5431 FreeType(exp.destType);
5442 FreeExpContents(exp);
5443 op1.ops.Sub(exp, op1, op2);
5450 FreeExpContents(exp);
5451 op1.ops.Neg(exp, op1);
5458 FreeExpContents(exp);
5459 op1.ops.BitNot(exp, op1);
5465 FreeExpContents(exp);
5466 op1.ops.Not(exp, op1);
5469 // Binary only operators
5473 FreeExpContents(exp);
5474 op1.ops.Div(exp, op1, op2);
5480 FreeExpContents(exp);
5481 op1.ops.Mod(exp, op1, op2);
5493 FreeExpContents(exp);
5494 op1.ops.Sma(exp, op1, op2);
5503 FreeExpContents(exp);
5504 op1.ops.Grt(exp, op1, op2);
5513 FreeExpContents(exp);
5514 op1.ops.SmaEqu(exp, op1, op2);
5523 FreeExpContents(exp);
5524 op1.ops.GrtEqu(exp, op1, op2);
5533 FreeExpContents(exp);
5534 op1.ops.Equ(exp, op1, op2);
5543 FreeExpContents(exp);
5544 op1.ops.Nqu(exp, op1, op2);
5551 FreeExpContents(exp);
5552 op1.ops.BitOr(exp, op1, op2);
5558 FreeExpContents(exp);
5559 op1.ops.BitXor(exp, op1, op2);
5567 FreeExpContents(exp);
5568 exp.type = constantExp;
5569 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5573 if(op1.type) FreeType(op1.type);
5574 if(op2.type) FreeType(op2.type);
5578 case extensionExpressionExp:
5581 for(e = exp.list->first; e; e = n)
5586 OldList * list = exp.list;
5587 ComputeExpression(e);
5588 //FreeExpContents(exp);
5589 FreeType(exp.expType);
5590 FreeType(exp.destType);
5607 exp.isConstant = true;
5609 ComputeExpression(exp.index.exp);
5610 if(!exp.index.exp.isConstant)
5611 exp.isConstant = false;
5613 for(e = exp.index.index->first; e; e = e.next)
5615 ComputeExpression(e);
5618 // Check if this type is int
5621 exp.isConstant = false;
5623 exp.expType = Dereference(exp.index.exp.expType);
5629 Expression memberExp = exp.member.exp;
5630 Identifier memberID = exp.member.member;
5633 ComputeExpression(exp.member.exp);
5634 type = exp.member.exp.expType;
5637 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);
5638 Property prop = null;
5639 DataMember member = null;
5640 Class convertTo = null;
5641 if(type.kind == subClassType && exp.member.exp.type == classExp)
5642 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5649 PrintTypeNoConst(type, string, false, true);
5650 classSym = FindClass(string);
5651 _class = classSym ? classSym.registered : null;
5654 if(exp.member.member)
5656 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5658 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5660 if(!prop && !member && _class && exp.member.member)
5662 Symbol classSym = FindClass(exp.member.member.string);
5664 _class = classSym ? classSym.registered : null;
5665 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5672 Type type = prop.dataType;
5673 // TODO: Assuming same base type for units...
5674 if(_class.type == unitClass)
5676 if(type.kind == classType)
5678 Class _class = type._class.registered;
5679 if(_class.type == unitClass)
5681 if(!_class.dataType)
5682 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5683 type = _class.dataType;
5691 float (*Get)(float) = (void *)prop.Get;
5692 GetFloat(exp.member.exp, &value);
5693 exp.constant = PrintFloat(Get ? Get(value) : value);
5694 exp.type = constantExp;
5700 double (*Get)(double);
5701 GetDouble(exp.member.exp, &value);
5704 Get = (void *)prop.Set;
5706 Get = (void *)prop.Get;
5707 exp.constant = PrintDouble(Get ? Get(value) : value);
5708 exp.type = constantExp;
5717 Expression value = exp.member.exp;
5720 ProcessPropertyType(prop);
5722 type = prop.dataType;
5725 // printf("Investigate this\n");
5727 else if(_class.type == structClass)
5733 Class propertyClass = type._class.registered;
5734 if(propertyClass.type == structClass && value.type == instanceExp)
5736 void (*Set)(void *, void *) = (void *)prop.Set;
5737 exp.instance = Instantiation { };
5738 exp.instance.data = new0 byte[_class.structSize];
5739 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5740 exp.instance.loc = exp.loc;
5741 exp.type = instanceExp;
5742 Set(exp.instance.data, value.instance.data);
5743 PopulateInstance(exp.instance);
5750 void (*Set)(void *, int) = (void *)prop.Set;
5752 exp.instance = Instantiation { };
5753 exp.instance.data = new0 byte[_class.structSize];
5754 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5755 exp.instance.loc = exp.loc;
5756 exp.type = instanceExp;
5758 GetInt(value, &intValue);
5760 Set(exp.instance.data, intValue);
5761 PopulateInstance(exp.instance);
5767 void (*Set)(void *, int64) = (void *)prop.Set;
5769 exp.instance = Instantiation { };
5770 exp.instance.data = new0 byte[_class.structSize];
5771 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5772 exp.instance.loc = exp.loc;
5773 exp.type = instanceExp;
5775 GetInt64(value, &intValue);
5777 Set(exp.instance.data, intValue);
5778 PopulateInstance(exp.instance);
5785 void (*Set)(void *, intptr) = (void *)prop.Set;
5787 exp.instance = Instantiation { };
5788 exp.instance.data = new0 byte[_class.structSize];
5789 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5790 exp.instance.loc = exp.loc;
5791 exp.type = instanceExp;
5793 GetIntPtr(value, &intValue);
5795 Set(exp.instance.data, intValue);
5796 PopulateInstance(exp.instance);
5803 void (*Set)(void *, intsize) = (void *)prop.Set;
5805 exp.instance = Instantiation { };
5806 exp.instance.data = new0 byte[_class.structSize];
5807 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5808 exp.instance.loc = exp.loc;
5809 exp.type = instanceExp;
5811 GetIntSize(value, &intValue);
5813 Set(exp.instance.data, intValue);
5814 PopulateInstance(exp.instance);
5820 void (*Set)(void *, double) = (void *)prop.Set;
5822 exp.instance = Instantiation { };
5823 exp.instance.data = new0 byte[_class.structSize];
5824 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5825 exp.instance.loc = exp.loc;
5826 exp.type = instanceExp;
5828 GetDouble(value, &doubleValue);
5830 Set(exp.instance.data, doubleValue);
5831 PopulateInstance(exp.instance);
5836 else if(_class.type == bitClass)
5842 Class propertyClass = type._class.registered;
5843 if(propertyClass.type == structClass && value.instance.data)
5845 unsigned int (*Set)(void *) = (void *)prop.Set;
5846 unsigned int bits = Set(value.instance.data);
5847 exp.constant = PrintHexUInt(bits);
5848 exp.type = constantExp;
5851 else if(_class.type == bitClass)
5854 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5857 GetUInt(exp.member.exp, &value);
5859 exp.constant = PrintHexUInt(bits);
5860 exp.type = constantExp;
5868 if(_class.type == bitClass)
5871 GetUInt(exp.member.exp, &value);
5877 Class _class = type._class.registered;
5878 if(_class.type == structClass)
5880 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5882 exp.instance = Instantiation { };
5883 exp.instance.data = new0 byte[_class.structSize];
5884 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5885 exp.instance.loc = exp.loc;
5886 //exp.instance.fullSet = true;
5887 exp.type = instanceExp;
5888 Get(value, exp.instance.data);
5889 PopulateInstance(exp.instance);
5891 else if(_class.type == bitClass)
5893 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5894 uint64 bits = Get(value);
5895 exp.constant = PrintHexUInt64(bits);
5896 exp.type = constantExp;
5902 else if(_class.type == structClass)
5904 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5909 Class _class = type._class.registered;
5910 if(_class.type == structClass && value)
5912 void (*Get)(void *, void *) = (void *)prop.Get;
5914 exp.instance = Instantiation { };
5915 exp.instance.data = new0 byte[_class.structSize];
5916 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5917 exp.instance.loc = exp.loc;
5918 //exp.instance.fullSet = true;
5919 exp.type = instanceExp;
5920 Get(value, exp.instance.data);
5921 PopulateInstance(exp.instance);
5929 char * value = exp.member.exp.instance.data;
5934 Class _class = type._class.registered;
5935 if(_class.type == normalClass)
5937 void *(*Get)(void *) = (void *)prop.Get;
5939 exp.instance = Instantiation { };
5940 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5941 exp.type = instanceExp;
5942 exp.instance.data = Get(value, exp.instance.data);
5954 exp.isConstant = false;
5962 if(exp.type != ExpressionType::memberExp)
5964 FreeExpression(memberExp);
5965 FreeIdentifier(memberID);
5971 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5972 FreeExpContents(exp);
5973 exp.constant = PrintUInt(ComputeTypeSize(type));
5974 exp.type = constantExp;
5980 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5981 if(classSym && classSym.registered)
5983 if(classSym.registered.fixed)
5985 FreeSpecifier(exp._class);
5986 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5987 exp.type = constantExp;
5991 char className[1024];
5992 strcpy(className, "__ecereClass_");
5993 FullClassNameCat(className, classSym.string, true);
5994 MangleClassName(className);
5996 DeclareClass(classSym, className);
5998 FreeExpContents(exp);
5999 exp.type = pointerExp;
6000 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6001 exp.member.member = MkIdentifier("structSize");
6011 if(exp.type == castExp)
6014 ComputeExpression(exp.cast.exp);
6017 if(e && exp.expType)
6020 type = exp.destType;
6023 if(type.kind == classType)
6025 Class _class = type._class.registered;
6026 if(_class && (_class.type == unitClass || _class.type == bitClass))
6028 if(!_class.dataType)
6029 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6030 type = _class.dataType;
6041 if(GetChar(e, &value))
6043 FreeExpContents(exp);
6044 exp.constant = PrintChar(value);
6045 exp.type = constantExp;
6050 unsigned char value = 0;
6051 if(GetUChar(e, &value))
6053 FreeExpContents(exp);
6054 exp.constant = PrintUChar(value);
6055 exp.type = constantExp;
6063 if(GetShort(e, &value))
6065 FreeExpContents(exp);
6066 exp.constant = PrintShort(value);
6067 exp.type = constantExp;
6072 unsigned short value = 0;
6073 if(GetUShort(e, &value))
6075 FreeExpContents(exp);
6076 exp.constant = PrintUShort(value);
6077 exp.type = constantExp;
6085 if(GetInt(e, &value))
6087 FreeExpContents(exp);
6088 exp.constant = PrintInt(value);
6089 exp.type = constantExp;
6094 unsigned int value = 0;
6095 if(GetUInt(e, &value))
6097 FreeExpContents(exp);
6098 exp.constant = PrintUInt(value);
6099 exp.type = constantExp;
6107 if(GetInt64(e, &value))
6109 FreeExpContents(exp);
6110 exp.constant = PrintInt64(value);
6111 exp.type = constantExp;
6117 if(GetUInt64(e, &value))
6119 FreeExpContents(exp);
6120 exp.constant = PrintUInt64(value);
6121 exp.type = constantExp;
6129 if(GetIntPtr(e, &value))
6131 FreeExpContents(exp);
6132 exp.constant = PrintInt64((int64)value);
6133 exp.type = constantExp;
6139 if(GetUIntPtr(e, &value))
6141 FreeExpContents(exp);
6142 exp.constant = PrintUInt64((uint64)value);
6143 exp.type = constantExp;
6151 if(GetIntSize(e, &value))
6153 FreeExpContents(exp);
6154 exp.constant = PrintInt64((int64)value);
6155 exp.type = constantExp;
6161 if(GetUIntSize(e, &value))
6163 FreeExpContents(exp);
6164 exp.constant = PrintUInt64((uint64)value);
6165 exp.type = constantExp;
6172 if(GetFloat(e, &value))
6174 FreeExpContents(exp);
6175 exp.constant = PrintFloat(value);
6176 exp.type = constantExp;
6183 if(GetDouble(e, &value))
6185 FreeExpContents(exp);
6186 exp.constant = PrintDouble(value);
6187 exp.type = constantExp;
6202 // Caring only about last expression for now...
6203 ComputeExpression(exp.cond.exp->last);
6204 if(exp.cond.elseExp)
6205 ComputeExpression(exp.cond.elseExp);
6207 ComputeExpression(exp.cond.cond);
6209 op1 = GetOperand(exp.cond.cond);
6210 if(op1.type) op1.type.refCount++;
6211 op2 = GetOperand(exp.cond.exp->last);
6212 if(op2.type) op2.type.refCount++;
6213 op3 = GetOperand(exp.cond.elseExp);
6214 if(op3.type) op3.type.refCount++;
6216 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6217 if(op1.type) FreeType(op1.type);
6218 if(op2.type) FreeType(op2.type);
6219 if(op3.type) FreeType(op3.type);
6225 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6230 OldList converts { };
6233 if(destType.kind == voidType)
6236 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6240 // for(convert = converts.last; convert; convert = convert.prev)
6241 for(convert = converts.first; convert; convert = convert.next)
6243 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6246 Expression newExp { };
6247 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6249 // TODO: Check this...
6251 newExp.destType = null;
6256 exp.type = memberExp;
6257 exp.addedThis = true;
6258 exp.member.exp = newExp;
6259 FreeType(exp.member.exp.expType);
6261 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6262 exp.member.exp.expType.classObjectType = objectType;
6263 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6264 exp.member.memberType = propertyMember;
6265 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6266 // TESTING THIS... for (int)degrees
6267 exp.needCast = true;
6268 if(exp.expType) exp.expType.refCount++;
6269 ApplyAnyObjectLogic(exp.member.exp);
6274 /*if(exp.isConstant)
6276 // Color { ColorRGB = [exp] };
6277 exp.type = instanceExp;
6278 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6279 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6280 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6284 // If not constant, don't turn it yet into an instantiation
6285 // (Go through the deep members system first)
6286 exp.type = memberExp;
6287 exp.addedThis = true;
6288 exp.member.exp = newExp;
6290 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6291 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6292 newExp.expType._class.registered.type == noHeadClass)
6294 newExp.byReference = true;
6297 FreeType(exp.member.exp.expType);
6298 /*exp.member.exp.expType = convert.convert.dataType;
6299 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6300 exp.member.exp.expType = null;
6301 if(convert.convert.dataType)
6303 exp.member.exp.expType = { };
6304 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6305 exp.member.exp.expType.refCount = 1;
6306 exp.member.exp.expType.classObjectType = objectType;
6307 ApplyAnyObjectLogic(exp.member.exp);
6310 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6311 exp.member.memberType = reverseConversionMember;
6312 exp.expType = convert.resultType ? convert.resultType :
6313 MkClassType(convert.convert._class.fullName);
6314 exp.needCast = true;
6315 if(convert.resultType) convert.resultType.refCount++;
6321 FreeType(exp.expType);
6324 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6325 exp.needCast = true;
6326 if(exp.expType) exp.expType.refCount++;
6330 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6331 exp.needCast = true;
6332 if(convert.resultType)
6333 convert.resultType.refCount++;
6337 if(exp.isConstant && inCompiler)
6338 ComputeExpression(exp);
6340 converts.Free(FreeConvert);
6343 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6345 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6347 if(!result && exp.expType && exp.destType)
6349 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6350 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6351 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6352 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6356 // if(result) CheckTemplateTypes(exp);
6360 void CheckTemplateTypes(Expression exp)
6362 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6364 Expression newExp { };
6368 if(exp.destType) exp.destType.refCount++;
6369 if(exp.expType) exp.expType.refCount++;
6373 switch(exp.expType.kind)
6376 if(exp.destType.classObjectType)
6378 // We need to pass the address, just pass it along (Undo what was done above)
6379 if(exp.destType) exp.destType.refCount--;
6380 if(exp.expType) exp.expType.refCount--;
6385 // If we're looking for value:
6386 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6388 OldList * unionDefs = MkList();
6389 OldList * statements = MkList();
6390 context = PushContext();
6391 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6392 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6393 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6394 exp.type = extensionCompoundExp;
6395 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6396 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6397 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6398 exp.compound.compound.context = context;
6399 PopContext(context);
6404 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6405 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6409 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6411 Expression newExp { };
6415 if(exp.destType) exp.destType.refCount++;
6416 if(exp.expType) exp.expType.refCount++;
6420 switch(exp.expType.kind)
6423 if(exp.destType.classObjectType)
6425 // We need to pass the address, just pass it along (Undo what was done above)
6426 if(exp.destType) exp.destType.refCount--;
6427 if(exp.expType) exp.expType.refCount--;
6432 // If we're looking for value:
6433 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6435 OldList * unionDefs = MkList();
6436 OldList * statements = MkList();
6437 context = PushContext();
6438 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6439 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6440 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6441 exp.type = extensionCompoundExp;
6442 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6443 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6444 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6445 exp.compound.compound.context = context;
6446 PopContext(context);
6451 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6453 exp.type = bracketsExp;
6454 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6455 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6456 ProcessExpressionType(exp.list->first);
6461 exp.type = bracketsExp;
6462 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6463 newExp.needCast = true;
6464 ProcessExpressionType(exp.list->first);
6470 if(exp.expType.kind == templateType)
6472 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6475 FreeType(exp.destType);
6476 FreeType(exp.expType);
6481 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6486 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6487 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6491 char typeString[1024];
6493 OldList * specs = MkList();
6494 typeString[0] = '\0';
6495 PrintType(exp.expType, typeString, false, false);
6496 decl = SpecDeclFromString(typeString, specs, null);
6499 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6500 exp.cast.typeName = MkTypeName(specs, decl);
6501 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6502 exp.cast.exp.needCast = true;
6509 // TODO: The Symbol tree should be reorganized by namespaces
6511 // - Tree of all symbols within (stored without namespace)
6512 // - Tree of sub-namespaces
6514 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6516 int nsLen = strlen(nameSpace);
6518 // Start at the name space prefix
6519 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6521 char * s = symbol.string;
6522 if(!strncmp(s, nameSpace, nsLen))
6524 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6527 for(c = strlen(s)-1; c >= 0; c--)
6532 if(!strcmp(namePart, name))
6534 // TODO: Error on ambiguity
6544 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6547 char nameSpace[1024];
6549 bool gotColon = false;
6551 nameSpace[0] = '\0';
6552 for(c = strlen(name)-1; c >= 0; c--)
6559 namePart = name+c+1;
6560 while(c >= 0 && name[c] == ':') c--;
6563 // Try an exact match first
6564 Symbol symbol = (Symbol)tree.FindString(name);
6568 // Namespace specified
6569 memcpy(nameSpace, name, c + 1);
6572 return ScanWithNameSpace(tree, nameSpace, namePart);
6576 // Looking for a global symbol, e.g. ::Sleep()
6577 Symbol symbol = (Symbol)tree.FindString(namePart);
6582 // Name only (no namespace specified)
6583 Symbol symbol = (Symbol)tree.FindString(namePart);
6586 return ScanWithNameSpace(tree, "", namePart);
6591 static void ProcessDeclaration(Declaration decl);
6593 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6596 //Time startTime = GetTime();
6598 // Optimize this later? Do this before/less?
6600 Symbol symbol = null;
6601 // First, check if the identifier is declared inside the function
6602 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6604 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6606 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6612 strcpy(curName, thisNameSpace);
6613 strcat(curName, "::");
6614 strcat(curName, name);
6615 // Try to resolve in current namespace first
6616 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6619 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6622 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6624 if(symbol || ctx == endContext) break;
6626 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6628 if(symbol.pointerExternal.type == functionExternal)
6630 FunctionDefinition function = symbol.pointerExternal.function;
6632 // Modified this recently...
6633 Context tmpContext = curContext;
6635 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6636 curContext = tmpContext;
6638 symbol.pointerExternal.symbol = symbol;
6641 DeclareType(symbol.type, true, true);
6643 ast->Insert(curExternal.prev, symbol.pointerExternal);
6645 symbol.id = curExternal.symbol.idCode;
6648 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6650 ast->Move(symbol.pointerExternal, curExternal.prev);
6651 symbol.id = curExternal.symbol.idCode;
6655 //findSymbolTotalTime += GetTime() - startTime;
6660 static void GetTypeSpecs(Type type, OldList * specs)
6662 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6667 if(type._class.registered)
6669 if(!type._class.registered.dataType)
6670 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6671 GetTypeSpecs(type._class.registered.dataType, specs);
6675 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6676 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6677 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6678 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6679 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6680 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6681 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6682 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6685 ListAdd(specs, MkSpecifier(INT)); break;
6689 static void PrintArraySize(Type arrayType, char * string)
6694 if(arrayType.enumClass)
6695 strcat(size, arrayType.enumClass.string);
6696 else if(arrayType.arraySizeExp)
6697 PrintExpression(arrayType.arraySizeExp, size);
6699 strcat(string, size);
6702 // WARNING : This function expects a null terminated string since it recursively concatenate...
6703 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6707 if(printConst && type.constant)
6708 strcat(string, "const ");
6713 Symbol c = type._class;
6714 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6715 // look into merging with thisclass ?
6716 if(type.classObjectType == typedObject)
6717 strcat(string, "typed_object");
6718 else if(type.classObjectType == anyObject)
6719 strcat(string, "any_object");
6723 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6725 if(type.byReference)
6726 strcat(string, " &");
6729 case voidType: strcat(string, "void"); break;
6730 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6731 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6732 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6733 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6734 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6735 case _BoolType: strcat(string, "_Bool"); break;
6736 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6737 case floatType: strcat(string, "float"); break;
6738 case doubleType: strcat(string, "double"); break;
6742 strcat(string, "struct ");
6743 strcat(string, type.enumName);
6745 else if(type.typeName)
6746 strcat(string, type.typeName);
6750 strcat(string, "struct { ");
6751 for(member = type.members.first; member; member = member.next)
6753 PrintType(member, string, true, fullName);
6754 strcat(string,"; ");
6762 strcat(string, "union ");
6763 strcat(string, type.enumName);
6765 else if(type.typeName)
6766 strcat(string, type.typeName);
6769 strcat(string, "union ");
6770 strcat(string,"(unnamed)");
6776 strcat(string, "enum ");
6777 strcat(string, type.enumName);
6779 else if(type.typeName)
6780 strcat(string, type.typeName);
6782 strcat(string, "int"); // "enum");
6785 strcat(string, "...");
6788 strcat(string, "subclass(");
6789 strcat(string, type._class ? type._class.string : "int");
6790 strcat(string, ")");
6793 strcat(string, type.templateParameter.identifier.string);
6796 strcat(string, "thisclass");
6799 strcat(string, "__builtin_va_list");
6805 static void PrintName(Type type, char * string, bool fullName)
6807 if(type.name && type.name[0])
6810 strcat(string, type.name);
6813 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6814 if(name) name += 2; else name = type.name;
6815 strcat(string, name);
6820 static void PrintAttribs(Type type, char * string)
6824 if(type.dllExport) strcat(string, "dllexport ");
6825 if(type.attrStdcall) strcat(string, "stdcall ");
6829 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6831 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6833 Type attrType = null;
6834 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6835 PrintAttribs(type, string);
6836 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6837 strcat(string, " const");
6838 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6839 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6840 strcat(string, " (");
6841 if(type.kind == pointerType)
6843 if(type.type.kind == functionType || type.type.kind == methodType)
6844 PrintAttribs(type.type, string);
6846 if(type.kind == pointerType)
6848 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6849 strcat(string, "*");
6851 strcat(string, " *");
6853 if(printConst && type.constant && type.kind == pointerType)
6854 strcat(string, " const");
6857 PrintTypeSpecs(type, string, fullName, printConst);
6860 static void PostPrintType(Type type, char * string, bool fullName)
6862 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6863 strcat(string, ")");
6864 if(type.kind == arrayType)
6865 PrintArraySize(type, string);
6866 else if(type.kind == functionType)
6869 strcat(string, "(");
6870 for(param = type.params.first; param; param = param.next)
6872 PrintType(param, string, true, fullName);
6873 if(param.next) strcat(string, ", ");
6875 strcat(string, ")");
6877 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6878 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6882 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6884 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6886 PrePrintType(type, string, fullName, null, printConst);
6888 if(type.thisClass || (printName && type.name && type.name[0]))
6889 strcat(string, " ");
6890 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6892 Symbol _class = type.thisClass;
6893 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6895 if(type.classObjectType == classPointer)
6896 strcat(string, "class");
6898 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6900 else if(_class && _class.string)
6902 String s = _class.string;
6907 char * name = RSearchString(s, "::", strlen(s), true, false);
6908 if(name) name += 2; else name = s;
6909 strcat(string, name);
6912 strcat(string, "::");
6915 if(printName && type.name)
6916 PrintName(type, string, fullName);
6917 PostPrintType(type, string, fullName);
6918 if(type.bitFieldCount)
6921 sprintf(count, ":%d", type.bitFieldCount);
6922 strcat(string, count);
6926 void PrintType(Type type, char * string, bool printName, bool fullName)
6928 _PrintType(type, string, printName, fullName, true);
6931 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6933 _PrintType(type, string, printName, fullName, false);
6936 static Type FindMember(Type type, char * string)
6939 for(memberType = type.members.first; memberType; memberType = memberType.next)
6941 if(!memberType.name)
6943 Type subType = FindMember(memberType, string);
6947 else if(!strcmp(memberType.name, string))
6953 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6956 for(memberType = type.members.first; memberType; memberType = memberType.next)
6958 if(!memberType.name)
6960 Type subType = FindMember(memberType, string);
6963 *offset += memberType.offset;
6967 else if(!strcmp(memberType.name, string))
6969 *offset += memberType.offset;
6976 public bool GetParseError() { return parseError; }
6978 Expression ParseExpressionString(char * expression)
6982 fileInput = TempFile { };
6983 fileInput.Write(expression, 1, strlen(expression));
6984 fileInput.Seek(0, start);
6987 parsedExpression = null;
6989 expression_yyparse();
6992 return parsedExpression;
6995 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6997 Identifier id = exp.identifier;
6998 Method method = null;
6999 Property prop = null;
7000 DataMember member = null;
7001 ClassProperty classProp = null;
7003 if(_class && _class.type == enumClass)
7005 NamedLink value = null;
7006 Class enumClass = eSystem_FindClass(privateModule, "enum");
7010 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7012 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7013 for(value = e.values.first; value; value = value.next)
7015 if(!strcmp(value.name, id.string))
7022 FreeExpContents(exp);
7024 exp.type = constantExp;
7025 exp.isConstant = true;
7026 if(!strcmp(baseClass.dataTypeString, "int"))
7027 sprintf(constant, "%d",(int)value.data);
7029 sprintf(constant, "0x%X",(int)value.data);
7030 exp.constant = CopyString(constant);
7031 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7032 exp.expType = MkClassType(baseClass.fullName);
7040 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7042 ProcessMethodType(method);
7049 // TOCHECK: Put it back to what it was...
7050 // methodClass = _class;
7051 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7056 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7059 ProcessPropertyType(prop);
7060 exp.expType = prop.dataType;
7061 if(prop.dataType) prop.dataType.refCount++;
7064 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7066 if(!member.dataType)
7067 member.dataType = ProcessTypeString(member.dataTypeString, false);
7068 exp.expType = member.dataType;
7069 if(member.dataType) member.dataType.refCount++;
7072 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7074 if(!classProp.dataType)
7075 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7077 if(classProp.constant)
7079 FreeExpContents(exp);
7081 exp.isConstant = true;
7082 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7084 //char constant[256];
7085 exp.type = stringExp;
7086 exp.constant = QMkString((char *)classProp.Get(_class));
7091 exp.type = constantExp;
7092 sprintf(constant, "%d", (int)classProp.Get(_class));
7093 exp.constant = CopyString(constant);
7101 exp.expType = classProp.dataType;
7102 if(classProp.dataType) classProp.dataType.refCount++;
7108 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7110 BinaryTree * tree = &nameSpace.functions;
7111 GlobalData data = (GlobalData)tree->FindString(name);
7115 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7117 data = ScanGlobalData(child, name);
7125 static GlobalData FindGlobalData(char * name)
7128 NameSpace * nameSpace;
7129 nameSpace = globalData;
7130 for(c = 0; name[c]; c++)
7132 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7134 NameSpace * newSpace;
7135 char * spaceName = new char[c - start + 1];
7136 strncpy(spaceName, name + start, c - start);
7137 spaceName[c-start] = '\0';
7138 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7142 nameSpace = newSpace;
7143 if(name[c] == ':') c++;
7149 return ScanGlobalData(nameSpace, name + start);
7154 static int definedExpStackPos;
7155 static void * definedExpStack[512];
7157 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7158 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7160 Expression prev = checkedExp.prev, next = checkedExp.next;
7162 FreeExpContents(checkedExp);
7163 FreeType(checkedExp.expType);
7164 FreeType(checkedExp.destType);
7166 *checkedExp = *newExp;
7170 checkedExp.prev = prev;
7171 checkedExp.next = next;
7174 void ApplyAnyObjectLogic(Expression e)
7176 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7178 char debugExpString[4096];
7179 debugExpString[0] = '\0';
7180 PrintExpression(e, debugExpString);
7183 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7185 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7186 //ellipsisDestType = destType;
7189 Type type = e.expType;
7190 Class _class = null;
7191 //Type destType = e.destType;
7193 if(type.kind == classType && type._class && type._class.registered)
7195 _class = type._class.registered;
7197 else if(type.kind == subClassType)
7199 _class = FindClass("ecere::com::Class").registered;
7203 char string[1024] = "";
7206 PrintTypeNoConst(type, string, false, true);
7207 classSym = FindClass(string);
7208 if(classSym) _class = classSym.registered;
7211 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "uintptr") && strcmp(_class.fullName, "intptr")) || // Patched so that class isn't considered SYSTEM...
7212 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != intPtrType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
7213 destType.byReference)))
7215 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7217 Expression checkedExp = e, newExp;
7219 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7221 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7223 if(checkedExp.type == extensionCompoundExp)
7225 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7228 checkedExp = checkedExp.list->last;
7230 else if(checkedExp.type == castExp)
7231 checkedExp = checkedExp.cast.exp;
7234 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7236 newExp = checkedExp.op.exp2;
7237 checkedExp.op.exp2 = null;
7238 FreeExpContents(checkedExp);
7240 if(e.expType && e.expType.passAsTemplate)
7243 ComputeTypeSize(e.expType);
7244 sprintf(size, "%d", e.expType.size);
7245 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7246 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7247 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7250 ReplaceExpContents(checkedExp, newExp);
7251 e.byReference = true;
7253 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7255 Expression checkedExp, newExp;
7258 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7260 e.type == identifierExp ||
7261 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7262 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7263 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7266 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7268 Context context = PushContext();
7270 OldList * specs = MkList();
7271 char typeString[1024];
7272 Expression newExp { };
7274 typeString[0] = '\0';
7277 //if(e.destType) e.destType.refCount++;
7278 // if(exp.expType) exp.expType.refCount++;
7281 newExp.expType = null;
7283 PrintTypeNoConst(e.expType, typeString, false, true);
7284 decl = SpecDeclFromString(typeString, specs, null);
7285 newExp.destType = ProcessType(specs, decl);
7287 curContext = context;
7289 // We need a current compound for this
7293 OldList * stmts = MkList();
7294 e.type = extensionCompoundExp;
7295 sprintf(name, "__internalValue%03X", internalValueCounter++);
7296 if(!curCompound.compound.declarations)
7297 curCompound.compound.declarations = MkList();
7298 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7299 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7300 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7301 e.compound = MkCompoundStmt(null, stmts);
7304 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7307 e.compound = MkCompoundStmt(
7308 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7309 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7311 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7315 Type type = e.destType;
7317 CopyTypeInto(e.destType, type);
7318 e.destType.refCount = 1;
7319 e.destType.classObjectType = none;
7323 e.compound.compound.context = context;
7324 PopContext(context);
7325 curContext = context.parent;
7329 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7331 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7333 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7335 if(checkedExp.type == extensionCompoundExp)
7337 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7340 checkedExp = checkedExp.list->last;
7342 else if(checkedExp.type == castExp)
7343 checkedExp = checkedExp.cast.exp;
7346 Expression operand { };
7347 operand = *checkedExp;
7348 checkedExp.destType = null;
7349 checkedExp.expType = null;
7351 checkedExp.type = opExp;
7352 checkedExp.op.op = '&';
7353 checkedExp.op.exp1 = null;
7354 checkedExp.op.exp2 = operand;
7356 //newExp = MkExpOp(null, '&', checkedExp);
7358 //ReplaceExpContents(checkedExp, newExp);
7365 // If expression type is a simple class, make it an address
7366 // FixReference(e, true);
7369 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7370 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7371 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7373 if(e.expType.classObjectType && destType && destType.classObjectType) //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7375 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7379 Expression thisExp { };
7382 thisExp.prev = null;
7383 thisExp.next = null;
7386 e.type = bracketsExp;
7387 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7388 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7389 ((Expression)e.list->first).byReference = true;
7391 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7393 e.expType = thisExp.expType;
7394 e.expType.refCount++;
7399 CopyTypeInto(e.expType, thisExp.expType);
7400 e.expType.byReference = false;
7401 e.expType.refCount = 1;
7403 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7404 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7406 e.expType.classObjectType = none;
7411 // TOFIX: Try this for a nice IDE crash!
7413 // The other way around
7416 if(destType && e.expType &&
7417 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7418 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7419 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7421 if(destType.kind == ellipsisType)
7423 Compiler_Error($"Unspecified type\n");
7425 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7427 bool byReference = e.expType.byReference;
7428 Expression thisExp { };
7430 OldList * specs = MkList();
7431 char typeString[1024]; // Watch buffer overruns
7433 ClassObjectType backupClassObjectType;
7434 bool backupByReference;
7436 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7441 backupClassObjectType = type.classObjectType;
7442 backupByReference = type.byReference;
7444 type.classObjectType = none;
7445 type.byReference = false;
7447 typeString[0] = '\0';
7448 PrintType(type, typeString, false, true);
7449 decl = SpecDeclFromString(typeString, specs, null);
7451 type.classObjectType = backupClassObjectType;
7452 type.byReference = backupByReference;
7455 thisExp.prev = null;
7456 thisExp.next = null;
7459 if( ( type.kind == classType && type._class && type._class.registered &&
7460 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7461 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7462 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7463 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7468 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7471 CopyTypeInto(e.expType, type);
7472 e.expType.byReference = false;
7473 e.expType.refCount = 1;
7478 e.cast.typeName = MkTypeName(specs, decl);
7479 e.cast.exp = thisExp;
7480 e.byReference = true;
7484 e.destType = destType;
7485 destType.refCount++;
7490 void ProcessExpressionType(Expression exp)
7492 bool unresolved = false;
7493 Location oldyylloc = yylloc;
7494 bool notByReference = false;
7496 char debugExpString[4096];
7497 debugExpString[0] = '\0';
7498 PrintExpression(exp, debugExpString);
7500 if(!exp || exp.expType)
7503 //eSystem_Logf("%s\n", expString);
7505 // Testing this here
7511 Identifier id = exp.identifier;
7512 if(!id || !topContext) return;
7514 // DOING THIS LATER NOW...
7515 if(id._class && id._class.name)
7517 id.classSym = id._class.symbol; // FindClass(id._class.name);
7518 /* TODO: Name Space Fix ups
7520 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7524 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7526 exp.expType = ProcessTypeString("Module", true);
7529 else */if(strstr(id.string, "__ecereClass") == id.string)
7531 exp.expType = ProcessTypeString("ecere::com::Class", true);
7534 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7536 // Added this here as well
7537 ReplaceClassMembers(exp, thisClass);
7538 if(exp.type != identifierExp)
7540 ProcessExpressionType(exp);
7544 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7549 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7550 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7551 if(!symbol/* && exp.destType*/)
7553 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7559 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7560 if(exp.type != identifierExp)
7562 ProcessExpressionType(exp);
7566 // Static methods called from inside the _class
7567 else if(currentClass && !id._class)
7569 if(ResolveIdWithClass(exp, currentClass, true))
7572 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7576 // If we manage to resolve this symbol
7579 Type type = symbol.type;
7580 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7582 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7584 Context context = SetupTemplatesContext(_class);
7585 type = ReplaceThisClassType(_class);
7586 FinishTemplatesContext(context);
7587 if(type) type.refCount = 0; // We'll be incrementing it right below...
7590 FreeSpecifier(id._class);
7593 id.string = CopyString(symbol.string);
7599 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7600 // Add missing cases here... enum Classes...
7601 exp.isConstant = true;
7603 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7604 if(symbol.isParam || !strcmp(id.string, "this"))
7606 if(_class && _class.type == structClass && !type.declaredWithStruct)
7607 exp.byReference = true;
7609 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7610 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7611 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7612 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7614 Identifier id = exp.identifier;
7615 exp.type = bracketsExp;
7616 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7620 if(symbol.isIterator)
7622 if(symbol.isIterator == 3)
7624 exp.type = bracketsExp;
7625 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7626 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7628 ProcessExpressionType(exp);
7630 else if(symbol.isIterator != 4)
7632 exp.type = memberExp;
7633 exp.member.exp = MkExpIdentifier(exp.identifier);
7634 exp.member.exp.expType = exp.expType;
7635 /*if(symbol.isIterator == 6)
7636 exp.member.member = MkIdentifier("key");
7638 exp.member.member = MkIdentifier("data");
7640 ProcessExpressionType(exp);
7647 DefinedExpression definedExp = null;
7648 if(thisNameSpace && !(id._class && !id._class.name))
7651 strcpy(name, thisNameSpace);
7653 strcat(name, id.string);
7654 definedExp = eSystem_FindDefine(privateModule, name);
7657 definedExp = eSystem_FindDefine(privateModule, id.string);
7661 for(c = 0; c<definedExpStackPos; c++)
7662 if(definedExpStack[c] == definedExp)
7664 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7666 Location backupYylloc = yylloc;
7667 File backInput = fileInput;
7668 definedExpStack[definedExpStackPos++] = definedExp;
7670 fileInput = TempFile { };
7671 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7672 fileInput.Seek(0, start);
7675 parsedExpression = null;
7677 expression_yyparse();
7680 fileInput = backInput;
7682 yylloc = backupYylloc;
7684 if(parsedExpression)
7687 exp.type = bracketsExp;
7688 exp.list = MkListOne(parsedExpression);
7689 parsedExpression.loc = yylloc;
7690 ProcessExpressionType(exp);
7691 definedExpStackPos--;
7694 definedExpStackPos--;
7700 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7706 GlobalData data = null;
7707 if(thisNameSpace && !(id._class && !id._class.name))
7710 strcpy(name, thisNameSpace);
7712 strcat(name, id.string);
7713 data = FindGlobalData(name);
7716 data = FindGlobalData(id.string);
7719 DeclareGlobalData(data);
7720 exp.expType = data.dataType;
7721 if(data.dataType) data.dataType.refCount++;
7724 id.string = CopyString(data.fullName);
7725 FreeSpecifier(id._class);
7732 GlobalFunction function = null;
7733 if(thisNameSpace && !(id._class && !id._class.name))
7736 strcpy(name, thisNameSpace);
7738 strcat(name, id.string);
7739 function = eSystem_FindFunction(privateModule, name);
7742 function = eSystem_FindFunction(privateModule, id.string);
7747 id.string = CopyString(function.name);
7750 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7751 strcpy(name, "__ecereFunction_");
7752 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7753 if(DeclareFunction(function, name))
7756 id.string = CopyString(name);
7758 exp.expType = function.dataType;
7759 if(function.dataType) function.dataType.refCount++;
7761 FreeSpecifier(id._class);
7778 if(!exp.instance._class)
7780 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7782 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7786 //classSym = FindClass(exp.instance._class.fullName);
7787 //_class = classSym ? classSym.registered : null;
7789 ProcessInstantiationType(exp.instance);
7790 exp.isConstant = exp.instance.isConstant;
7793 if(_class.type == unitClass && _class.base.type != systemClass)
7796 Type destType = exp.destType;
7798 exp.destType = MkClassType(_class.base.fullName);
7799 exp.expType = MkClassType(_class.fullName);
7800 CheckExpressionType(exp, exp.destType, true);
7802 exp.destType = destType;
7804 exp.expType = MkClassType(_class.fullName);
7807 if(exp.instance._class)
7809 exp.expType = MkClassType(exp.instance._class.name);
7810 /*if(exp.expType._class && exp.expType._class.registered &&
7811 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7812 exp.expType.byReference = true;*/
7820 char * constant = exp.constant;
7828 if(constant[0] == '\'')
7830 if((int)((byte *)constant)[1] > 127)
7833 unichar ch = UTF8GetChar(constant + 1, &nb);
7834 if(nb < 2) ch = constant[1];
7836 exp.constant = PrintUInt(ch);
7837 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7838 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7839 type._class = FindClass("unichar");
7841 type.isSigned = false;
7845 type.kind = charType;
7846 type.isSigned = true;
7851 char * dot = strchr(constant, '.');
7852 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7856 exponent = strchr(constant, 'p');
7857 if(!exponent) exponent = strchr(constant, 'P');
7861 exponent = strchr(constant, 'e');
7862 if(!exponent) exponent = strchr(constant, 'E');
7867 if(strchr(constant, 'f') || strchr(constant, 'F'))
7868 type.kind = floatType;
7870 type.kind = doubleType;
7871 type.isSigned = true;
7875 bool isSigned = constant[0] == '-';
7876 int64 i64 = strtoll(constant, null, 0);
7877 uint64 ui64 = strtoull(constant, null, 0);
7878 bool is64Bit = false;
7891 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7895 else if(constant[0] != '0' || !constant[1])
7898 type.kind = is64Bit ? int64Type : intType;
7899 type.isSigned = isSigned;
7902 exp.isConstant = true;
7903 if(exp.destType && exp.destType.kind == doubleType)
7904 type.kind = doubleType;
7905 else if(exp.destType && exp.destType.kind == floatType)
7906 type.kind = floatType;
7907 else if(exp.destType && exp.destType.kind == int64Type)
7908 type.kind = int64Type;
7914 exp.isConstant = true; // Why wasn't this constant?
7931 ProcessExpressionType(exp._new.size);
7936 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7938 DeclareType(exp.expType.type, false, false);
7942 ProcessExpressionType(exp._renew.size);
7943 ProcessExpressionType(exp._renew.exp);
7948 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7950 DeclareType(exp.expType.type, false, false);
7954 bool assign = false, boolResult = false, boolOps = false;
7955 Type type1 = null, type2 = null;
7956 bool useDestType = false, useSideType = false;
7957 Location oldyylloc = yylloc;
7958 bool useSideUnit = false;
7960 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7969 // Assignment Operators
7983 // boolean Operators
7985 // Expect boolean operators
7987 //boolResult = true;
7991 // Expect boolean operands
8002 // Gives boolean result
8010 // Just added these... testing
8015 // DANGER: Verify units
8020 if(exp.op.op != '*' || exp.op.exp1)
8027 /*// Implement speed etc.
8033 if(exp.op.op == '&')
8035 // Added this here earlier for Iterator address as key
8036 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8038 Identifier id = exp.op.exp2.identifier;
8039 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8040 if(symbol && symbol.isIterator == 2)
8042 exp.type = memberExp;
8043 exp.member.exp = exp.op.exp2;
8044 exp.member.member = MkIdentifier("key");
8046 exp.op.exp2.expType = symbol.type;
8047 symbol.type.refCount++;
8048 ProcessExpressionType(exp);
8052 // exp.op.exp2.usage.usageRef = true;
8056 //dummy.kind = TypeDummy;
8060 if(exp.destType && exp.destType.kind == classType &&
8061 exp.destType._class && exp.destType._class.registered && useDestType &&
8063 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
8064 exp.destType._class.registered.type == enumClass ||
8065 exp.destType._class.registered.type == bitClass
8068 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8070 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8071 exp.op.exp1.destType = exp.destType;
8073 exp.destType.refCount++;
8077 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8078 exp.op.exp1.destType = dummy;
8082 // TESTING THIS HERE...
8083 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8084 ProcessExpressionType(exp.op.exp1);
8085 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8087 if(exp.op.exp1.destType == dummy)
8090 exp.op.exp1.destType = null;
8092 type1 = exp.op.exp1.expType;
8097 char expString[10240];
8098 expString[0] = '\0';
8099 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8103 exp.op.exp2.destType = exp.op.exp1.expType;
8104 if(exp.op.exp1.expType)
8105 exp.op.exp1.expType.refCount++;
8109 exp.op.exp2.destType = exp.destType;
8111 exp.destType.refCount++;
8114 if(type1) type1.refCount++;
8115 exp.expType = type1;
8120 PrintExpression(exp.op.exp2, expString);
8122 if(type1 && type1.kind == pointerType)
8124 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 ||
8125 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8126 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8127 else if(exp.op.op == '=')
8129 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8130 exp.op.exp2.destType = type1;
8137 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8138 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/* ||
8139 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8142 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8143 exp.op.exp2.destType = type1;
8148 if(type1) type1.refCount++;
8149 exp.expType = type1;
8151 else if(exp.destType && exp.destType.kind == classType &&
8152 exp.destType._class && exp.destType._class.registered &&
8154 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
8155 (exp.destType._class.registered.type == enumClass && useDestType))
8158 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8159 exp.op.exp2.destType = exp.destType;
8161 exp.destType.refCount++;
8165 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8166 exp.op.exp2.destType = dummy;
8170 // TESTING THIS HERE... (DANGEROUS)
8171 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8172 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8174 FreeType(exp.op.exp2.destType);
8175 exp.op.exp2.destType = type1;
8178 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8179 // Cannot lose the cast on a sizeof
8180 if(exp.op.op == SIZEOF)
8182 Expression e = exp.op.exp2;
8183 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8185 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8187 if(e.type == extensionCompoundExp)
8188 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8193 if(e.type == castExp && e.cast.exp)
8194 e.cast.exp.needCast = true;
8196 ProcessExpressionType(exp.op.exp2);
8197 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8199 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8201 if(exp.op.exp2.expType.kind == intSizeType || exp.op.exp2.expType.kind == intPtrType || exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
8203 if(exp.op.op != '=' && type1.type.kind == voidType)
8204 Compiler_Error($"void *: unknown size\n");
8206 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||
8207 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8208 (exp.op.exp2.expType._class.registered.type == normalClass ||
8209 exp.op.exp2.expType._class.registered.type == structClass ||
8210 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8212 if(exp.op.op == ADD_ASSIGN)
8213 Compiler_Error($"cannot add two pointers\n");
8215 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8216 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8218 if(exp.op.op == ADD_ASSIGN)
8219 Compiler_Error($"cannot add two pointers\n");
8223 char type1String[1024];
8224 char type2String[1024];
8225 type1String[0] = '\0';
8226 type2String[0] = '\0';
8228 PrintType(exp.op.exp2.expType, type1String, false, true);
8229 PrintType(type1, type2String, false, true);
8230 ChangeCh(expString, '\n', ' ');
8231 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8235 if(exp.op.exp2.destType == dummy)
8238 exp.op.exp2.destType = null;
8241 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8245 CopyTypeInto(type2, exp.op.exp2.expType);
8246 type2.isSigned = true;
8248 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8250 type2 = { kind = intType };
8252 type2.isSigned = true;
8256 type2 = exp.op.exp2.expType;
8257 if(type2) type2.refCount++;
8261 dummy.kind = voidType;
8263 if(exp.op.op == SIZEOF)
8270 exp.isConstant = true;
8272 // Get type of dereferenced pointer
8273 else if(exp.op.op == '*' && !exp.op.exp1)
8275 exp.expType = Dereference(type2);
8276 if(type2 && type2.kind == classType)
8277 notByReference = true;
8279 else if(exp.op.op == '&' && !exp.op.exp1)
8280 exp.expType = Reference(type2);
8287 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8288 exp.op.exp1.destType = MkClassType("bool");
8289 exp.op.exp1.destType.truth = true;
8290 if(!exp.op.exp1.expType)
8291 ProcessExpressionType(exp.op.exp1);
8293 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8294 FreeType(exp.op.exp1.expType);
8295 exp.op.exp1.expType = MkClassType("bool");
8296 exp.op.exp1.expType.truth = true;
8300 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8301 exp.op.exp2.destType = MkClassType("bool");
8302 exp.op.exp2.destType.truth = true;
8303 if(!exp.op.exp2.expType)
8304 ProcessExpressionType(exp.op.exp2);
8306 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8307 FreeType(exp.op.exp2.expType);
8308 exp.op.exp2.expType = MkClassType("bool");
8309 exp.op.exp2.expType.truth = true;
8312 else if(exp.op.exp1 && exp.op.exp2 &&
8315 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8316 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8317 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8318 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8320 if(type1 && type2 &&
8321 // If either both are class or both are not class
8322 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8324 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8325 exp.op.exp2.destType = type1;
8327 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8328 exp.op.exp1.destType = type2;
8330 // Warning here for adding Radians + Degrees with no destination type
8331 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8332 type1._class.registered && type1._class.registered.type == unitClass &&
8333 type2._class.registered && type2._class.registered.type == unitClass &&
8334 type1._class.registered != type2._class.registered)
8335 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8336 type1._class.string, type2._class.string, type1._class.string);
8338 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8340 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8343 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8345 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8346 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8349 ProcessExpressionType(exp.op.exp1);
8351 if(type2.kind != pointerType)
8353 ProcessExpressionType(classExp);
8355 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8356 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8357 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8359 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8362 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8363 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8364 MkPointer(null, null), null)))),
8365 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8367 if(!exp.op.exp2.expType)
8371 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8375 ProcessExpressionType(exp.op.exp2);
8380 if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == intSizeType || type2.kind == intPtrType || type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
8382 if(type1.kind != classType && type1.type.kind == voidType)
8383 Compiler_Error($"void *: unknown size\n");
8384 exp.expType = type1;
8385 if(type1) type1.refCount++;
8387 else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == intSizeType || type1.kind == intPtrType || type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
8389 if(type2.kind != classType && type2.type.kind == voidType)
8390 Compiler_Error($"void *: unknown size\n");
8391 exp.expType = type2;
8392 if(type2) type2.refCount++;
8394 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8395 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8397 Compiler_Warning($"different levels of indirection\n");
8401 bool success = false;
8402 if(type1.kind == pointerType && type2.kind == pointerType)
8404 if(exp.op.op == '+')
8405 Compiler_Error($"cannot add two pointers\n");
8406 else if(exp.op.op == '-')
8408 // Pointer Subtraction gives integer
8409 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8418 if(type1.type.kind == templateType)
8420 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8423 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8425 ProcessExpressionType(classExp);
8427 exp.type = bracketsExp;
8428 exp.list = MkListOne(MkExpOp(
8429 MkExpBrackets(MkListOne(MkExpOp(
8430 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8432 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8434 //MkExpMember(classExp, MkIdentifier("typeSize"))
8436 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8437 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8439 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8442 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8443 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8444 MkPointer(null, null), null)))),
8445 MkExpMember(classExp, MkIdentifier("typeSize")))))
8450 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8459 if(!success && exp.op.exp1.type == constantExp)
8461 // If first expression is constant, try to match that first
8462 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8464 if(exp.expType) FreeType(exp.expType);
8465 exp.expType = exp.op.exp1.destType;
8466 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8469 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8471 if(exp.expType) FreeType(exp.expType);
8472 exp.expType = exp.op.exp2.destType;
8473 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8479 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8481 if(exp.expType) FreeType(exp.expType);
8482 exp.expType = exp.op.exp2.destType;
8483 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8486 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8488 if(exp.expType) FreeType(exp.expType);
8489 exp.expType = exp.op.exp1.destType;
8490 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8496 char expString1[10240];
8497 char expString2[10240];
8500 expString1[0] = '\0';
8501 expString2[0] = '\0';
8506 PrintExpression(exp.op.exp1, expString1);
8507 ChangeCh(expString1, '\n', ' ');
8508 PrintExpression(exp.op.exp2, expString2);
8509 ChangeCh(expString2, '\n', ' ');
8510 PrintType(exp.op.exp1.expType, type1, false, true);
8511 PrintType(exp.op.exp2.expType, type2, false, true);
8514 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8518 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8519 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8521 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8522 // Convert e.g. / 4 into / 4.0
8523 exp.op.exp1.destType = type2._class.registered.dataType;
8524 if(type2._class.registered.dataType)
8525 type2._class.registered.dataType.refCount++;
8526 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8527 exp.expType = type2;
8528 if(type2) type2.refCount++;
8530 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8532 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8533 // Convert e.g. / 4 into / 4.0
8534 exp.op.exp2.destType = type1._class.registered.dataType;
8535 if(type1._class.registered.dataType)
8536 type1._class.registered.dataType.refCount++;
8537 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8538 exp.expType = type1;
8539 if(type1) type1.refCount++;
8545 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8547 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8549 if(!type1._class.registered.dataType)
8550 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8551 exp.op.exp2.destType = type1._class.registered.dataType;
8552 exp.op.exp2.destType.refCount++;
8554 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8557 type2 = exp.op.exp2.destType;
8558 if(type2) type2.refCount++;
8560 exp.expType = type2;
8564 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8566 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8568 if(!type2._class.registered.dataType)
8569 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8570 exp.op.exp1.destType = type2._class.registered.dataType;
8571 exp.op.exp1.destType.refCount++;
8573 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8574 type1 = exp.op.exp1.destType;
8575 exp.expType = type1;
8579 // TESTING THIS NEW CODE
8580 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8582 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8584 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8586 if(exp.expType) FreeType(exp.expType);
8587 exp.expType = exp.op.exp1.expType;
8588 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8593 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8595 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8597 if(exp.expType) FreeType(exp.expType);
8598 exp.expType = exp.op.exp2.expType;
8599 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8607 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8608 exp.op.exp2.destType = type1;
8612 // Maybe this was meant to be an enum...
8613 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8615 Type oldType = exp.op.exp2.expType;
8616 exp.op.exp2.expType = null;
8617 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8620 exp.op.exp2.expType = oldType;
8625 // TESTING THIS HERE... LATEST ADDITION
8626 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8628 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8629 exp.op.exp2.destType = type2._class.registered.dataType;
8630 if(type2._class.registered.dataType)
8631 type2._class.registered.dataType.refCount++;
8632 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8634 //exp.expType = type2._class.registered.dataType; //type2;
8635 //if(type2) type2.refCount++;
8638 // TESTING THIS HERE... LATEST ADDITION
8639 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8641 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8642 exp.op.exp1.destType = type1._class.registered.dataType;
8643 if(type1._class.registered.dataType)
8644 type1._class.registered.dataType.refCount++;
8645 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8646 exp.expType = type1._class.registered.dataType; //type1;
8647 if(type1) type1.refCount++;
8651 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8653 if(exp.expType) FreeType(exp.expType);
8654 exp.expType = exp.op.exp2.destType;
8655 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8657 else if(type1 && type2)
8659 char expString1[10240];
8660 char expString2[10240];
8661 char type1String[1024];
8662 char type2String[1024];
8663 expString1[0] = '\0';
8664 expString2[0] = '\0';
8665 type1String[0] = '\0';
8666 type2String[0] = '\0';
8669 PrintExpression(exp.op.exp1, expString1);
8670 ChangeCh(expString1, '\n', ' ');
8671 PrintExpression(exp.op.exp2, expString2);
8672 ChangeCh(expString2, '\n', ' ');
8673 PrintType(exp.op.exp1.expType, type1String, false, true);
8674 PrintType(exp.op.exp2.expType, type2String, false, true);
8677 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8679 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8681 exp.expType = exp.op.exp1.expType;
8682 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8684 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8686 exp.expType = exp.op.exp2.expType;
8687 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8694 // Maybe this was meant to be an enum...
8695 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8697 Type oldType = exp.op.exp1.expType;
8698 exp.op.exp1.expType = null;
8699 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8702 exp.op.exp1.expType = oldType;
8705 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8706 exp.op.exp1.destType = type2;
8709 // TESTING THIS HERE... LATEST ADDITION
8710 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8712 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8713 exp.op.exp1.destType = type1._class.registered.dataType;
8714 if(type1._class.registered.dataType)
8715 type1._class.registered.dataType.refCount++;
8718 // TESTING THIS HERE... LATEST ADDITION
8719 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8721 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8722 exp.op.exp2.destType = type2._class.registered.dataType;
8723 if(type2._class.registered.dataType)
8724 type2._class.registered.dataType.refCount++;
8728 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8730 if(exp.expType) FreeType(exp.expType);
8731 exp.expType = exp.op.exp1.destType;
8732 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8736 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8738 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8740 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8741 // Convert e.g. / 4 into / 4.0
8742 exp.op.exp1.destType = type2._class.registered.dataType;
8743 if(type2._class.registered.dataType)
8744 type2._class.registered.dataType.refCount++;
8745 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8747 if(exp.op.op == '!')
8749 exp.expType = MkClassType("bool");
8750 exp.expType.truth = true;
8754 exp.expType = type2;
8755 if(type2) type2.refCount++;
8758 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8760 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8762 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8763 // Convert e.g. / 4 into / 4.0
8764 exp.op.exp2.destType = type1._class.registered.dataType;
8765 if(type1._class.registered.dataType)
8766 type1._class.registered.dataType.refCount++;
8767 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8769 exp.expType = type1;
8770 if(type1) type1.refCount++;
8775 if(exp.op.exp1 && !exp.op.exp1.expType)
8777 char expString[10000];
8778 expString[0] = '\0';
8781 PrintExpression(exp.op.exp1, expString);
8782 ChangeCh(expString, '\n', ' ');
8785 Compiler_Error($"couldn't determine type of %s\n", expString);
8787 if(exp.op.exp2 && !exp.op.exp2.expType)
8789 char expString[10240];
8790 expString[0] = '\0';
8793 PrintExpression(exp.op.exp2, expString);
8794 ChangeCh(expString, '\n', ' ');
8797 Compiler_Error($"couldn't determine type of %s\n", expString);
8802 FreeType(exp.expType);
8803 exp.expType = MkClassType("bool");
8804 exp.expType.truth = true;
8807 if(exp.op.op != SIZEOF)
8808 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8809 (!exp.op.exp2 || exp.op.exp2.isConstant);
8811 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8813 DeclareType(exp.op.exp2.expType, false, false);
8824 case extensionExpressionExp:
8827 exp.isConstant = true;
8828 for(e = exp.list->first; e; e = e.next)
8833 FreeType(e.destType);
8834 e.destType = exp.destType;
8835 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8837 ProcessExpressionType(e);
8839 exp.destType.count--;
8840 if(!exp.expType && !e.next)
8842 exp.expType = e.expType;
8843 if(e.expType) e.expType.refCount++;
8846 exp.isConstant = false;
8849 // In case a cast became a member...
8850 e = exp.list->first;
8851 if(!e.next && e.type == memberExp)
8853 // Preserve prev, next
8854 Expression next = exp.next, prev = exp.prev;
8857 FreeType(exp.expType);
8858 FreeType(exp.destType);
8868 ProcessExpressionType(exp);
8875 exp.isConstant = true;
8877 ProcessExpressionType(exp.index.exp);
8878 if(!exp.index.exp.isConstant)
8879 exp.isConstant = false;
8881 if(exp.index.exp.expType)
8883 Type source = exp.index.exp.expType;
8884 if(source.kind == classType && source._class && source._class.registered)
8886 Class _class = source._class.registered;
8887 Class c = _class.templateClass ? _class.templateClass : _class;
8888 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8890 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8892 if(exp.index.index && exp.index.index->last)
8894 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8900 for(e = exp.index.index->first; e; e = e.next)
8902 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8904 if(e.destType) FreeType(e.destType);
8905 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8907 ProcessExpressionType(e);
8910 // Check if this type is int
8913 exp.isConstant = false;
8917 exp.expType = Dereference(exp.index.exp.expType);
8919 DeclareType(exp.expType, false, false);
8926 Type methodType = null;
8932 PrintExpression(exp.call.exp, name);
8933 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8935 //exp.call.exp.expType = null;
8936 PrintExpression(exp.call.exp, name);
8939 if(exp.call.exp.type == identifierExp)
8941 Expression idExp = exp.call.exp;
8942 Identifier id = idExp.identifier;
8943 if(!strcmp(id.string, "__builtin_frame_address"))
8945 exp.expType = ProcessTypeString("void *", true);
8946 if(exp.call.arguments && exp.call.arguments->first)
8947 ProcessExpressionType(exp.call.arguments->first);
8950 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8952 exp.expType = ProcessTypeString("int", true);
8953 if(exp.call.arguments && exp.call.arguments->first)
8954 ProcessExpressionType(exp.call.arguments->first);
8957 else if(!strcmp(id.string, "Max") ||
8958 !strcmp(id.string, "Min") ||
8959 !strcmp(id.string, "Sgn") ||
8960 !strcmp(id.string, "Abs"))
8962 Expression a = null;
8963 Expression b = null;
8964 Expression tempExp1 = null, tempExp2 = null;
8965 if((!strcmp(id.string, "Max") ||
8966 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8968 a = exp.call.arguments->first;
8969 b = exp.call.arguments->last;
8973 else if(exp.call.arguments->count == 1)
8975 a = exp.call.arguments->first;
8981 exp.call.arguments->Clear();
8982 idExp.identifier = null;
8984 FreeExpContents(exp);
8986 ProcessExpressionType(a);
8988 ProcessExpressionType(b);
8990 exp.type = bracketsExp;
8991 exp.list = MkList();
8993 if(a.expType && (!b || b.expType))
8995 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8997 // Use the simpleStruct name/ids for now...
9000 OldList * specs = MkList();
9001 OldList * decls = MkList();
9003 char temp1[1024], temp2[1024];
9005 GetTypeSpecs(a.expType, specs);
9007 if(a && !a.isConstant && a.type != identifierExp)
9009 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9010 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9011 tempExp1 = QMkExpId(temp1);
9012 tempExp1.expType = a.expType;
9014 a.expType.refCount++;
9015 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9017 if(b && !b.isConstant && b.type != identifierExp)
9019 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9020 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9021 tempExp2 = QMkExpId(temp2);
9022 tempExp2.expType = b.expType;
9024 b.expType.refCount++;
9025 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9028 decl = MkDeclaration(specs, decls);
9029 if(!curCompound.compound.declarations)
9030 curCompound.compound.declarations = MkList();
9031 curCompound.compound.declarations->Insert(null, decl);
9036 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9038 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9040 MkExpCondition(MkExpBrackets(MkListOne(
9041 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9042 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9043 exp.expType = a.expType;
9045 a.expType.refCount++;
9047 else if(!strcmp(id.string, "Abs"))
9050 MkExpCondition(MkExpBrackets(MkListOne(
9051 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9052 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9053 exp.expType = a.expType;
9055 a.expType.refCount++;
9057 else if(!strcmp(id.string, "Sgn"))
9059 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9061 MkExpCondition(MkExpBrackets(MkListOne(
9062 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9063 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9064 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9065 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9066 exp.expType = ProcessTypeString("int", false);
9069 FreeExpression(tempExp1);
9070 if(tempExp2) FreeExpression(tempExp2);
9084 if(!exp.call.exp.destType)
9086 exp.call.exp.destType = dummy;
9089 ProcessExpressionType(exp.call.exp);
9090 if(exp.call.exp.destType == dummy)
9093 exp.call.exp.destType = null;
9098 // Check argument types against parameter types
9099 functionType = exp.call.exp.expType;
9101 if(functionType && functionType.kind == TypeKind::methodType)
9103 methodType = functionType;
9104 functionType = methodType.method.dataType;
9106 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9107 // TOCHECK: Instead of doing this here could this be done per param?
9108 if(exp.call.exp.expType.usedClass)
9110 char typeString[1024];
9111 typeString[0] = '\0';
9113 Symbol back = functionType.thisClass;
9114 // Do not output class specifier here (thisclass was added to this)
9115 functionType.thisClass = null;
9116 PrintType(functionType, typeString, true, true);
9117 functionType.thisClass = back;
9119 if(strstr(typeString, "thisclass"))
9121 OldList * specs = MkList();
9124 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9126 decl = SpecDeclFromString(typeString, specs, null);
9128 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9129 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9130 exp.call.exp.expType.usedClass))
9131 thisClassParams = false;
9133 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9135 Class backupThisClass = thisClass;
9136 thisClass = exp.call.exp.expType.usedClass;
9137 ProcessDeclarator(decl);
9138 thisClass = backupThisClass;
9141 thisClassParams = true;
9143 functionType = ProcessType(specs, decl);
9144 functionType.refCount = 0;
9145 FinishTemplatesContext(context);
9148 FreeList(specs, FreeSpecifier);
9149 FreeDeclarator(decl);
9153 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9155 Type type = functionType.type;
9156 if(!functionType.refCount)
9158 functionType.type = null;
9159 FreeType(functionType);
9161 //methodType = functionType;
9162 functionType = type;
9164 if(functionType && functionType.kind != TypeKind::functionType)
9166 Compiler_Error($"called object %s is not a function\n", name);
9168 else if(functionType)
9170 bool emptyParams = false, noParams = false;
9171 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9172 Type type = functionType.params.first;
9173 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9175 Location oldyylloc = yylloc;
9177 if(!type) emptyParams = true;
9180 if(functionType.extraParam && e && functionType.thisClass)
9182 e.destType = MkClassType(functionType.thisClass.string);
9186 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9187 // Fixed #141 by adding '&& !functionType.extraParam'
9188 if(!functionType.staticMethod && !functionType.extraParam)
9190 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9191 memberExp.member.exp.expType._class)
9193 type = MkClassType(memberExp.member.exp.expType._class.string);
9198 type = functionType.params.first;
9203 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9205 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9206 type.byReference = functionType.byReference;
9207 type.typedByReference = functionType.typedByReference;
9210 // Allow manually passing a class for typed object
9211 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9215 type = functionType.params.first;
9223 if(type && type.kind == voidType)
9226 if(!type.refCount) FreeType(type);
9230 for( ; e; e = e.next)
9232 if(!type && !emptyParams)
9235 if(methodType && methodType.methodClass)
9236 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9237 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9238 noParams ? 0 : functionType.params.count);
9240 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9241 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9242 noParams ? 0 : functionType.params.count);
9246 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9248 Type templatedType = null;
9249 Class _class = methodType.usedClass;
9250 ClassTemplateParameter curParam = null;
9252 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9255 for(sClass = _class; sClass; sClass = sClass.base)
9257 if(sClass.templateClass) sClass = sClass.templateClass;
9259 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9261 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9264 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9266 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9267 id += nextClass.templateParams.count;
9276 if(curParam && _class.templateArgs[id].dataTypeString)
9278 ClassTemplateArgument arg = _class.templateArgs[id];
9280 Context context = SetupTemplatesContext(_class);
9283 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9284 templatedType = ProcessTypeString(arg.dataTypeString, false);
9285 FinishTemplatesContext(context);
9287 e.destType = templatedType;
9290 templatedType.passAsTemplate = true;
9291 // templatedType.refCount++;
9297 if(type) type.refCount++;
9302 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9304 e.destType = type.prev;
9305 e.destType.refCount++;
9310 if(type) type.refCount++;
9313 // Don't reach the end for the ellipsis
9314 if(type && type.kind != ellipsisType)
9316 Type next = type.next;
9317 if(!type.refCount) FreeType(type);
9322 if(type && type.kind != ellipsisType)
9324 if(methodType && methodType.methodClass)
9325 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9326 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9327 functionType.params.count + extra);
9329 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9330 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9331 functionType.params.count + extra);
9334 if(type && !type.refCount) FreeType(type);
9341 kind = TypeKind::functionType;
9344 if(exp.call.exp.type == identifierExp)
9346 char * string = exp.call.exp.identifier.string;
9350 Location oldyylloc = yylloc;
9352 yylloc = exp.call.exp.identifier.loc;
9353 if(strstr(string, "__builtin_") == string)
9357 functionType.returnType = exp.destType;
9358 exp.destType.refCount++;
9362 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9363 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9364 globalContext.symbols.Add((BTNode)symbol);
9365 if(strstr(symbol.string, "::"))
9366 globalContext.hasNameSpace = true;
9371 else if(exp.call.exp.type == memberExp)
9373 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9374 exp.call.exp.member.member.string);*/
9377 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9379 if(!functionType.returnType)
9381 functionType.returnType = Type
9388 if(functionType && functionType.kind == TypeKind::functionType)
9390 exp.expType = functionType.returnType;
9392 if(functionType.returnType)
9393 functionType.returnType.refCount++;
9395 if(!functionType.refCount)
9396 FreeType(functionType);
9399 if(exp.call.arguments)
9401 for(e = exp.call.arguments->first; e; e = e.next)
9403 Type destType = e.destType;
9404 ProcessExpressionType(e);
9412 Location oldyylloc = yylloc;
9414 Expression checkExp = exp.member.exp;
9417 if(checkExp.type == castExp)
9418 checkExp = checkExp.cast.exp;
9419 else if(checkExp.type == bracketsExp)
9420 checkExp = checkExp.list ? checkExp.list->first : null;
9425 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9426 exp.thisPtr = thisPtr;
9428 // DOING THIS LATER NOW...
9429 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9431 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9432 /* TODO: Name Space Fix ups
9433 if(!exp.member.member.classSym)
9434 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9438 ProcessExpressionType(exp.member.exp);
9439 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9440 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9442 exp.isConstant = false;
9445 exp.isConstant = exp.member.exp.isConstant;
9446 type = exp.member.exp.expType;
9450 if(type && (type.kind == templateType))
9452 Class _class = thisClass ? thisClass : currentClass;
9453 ClassTemplateParameter param = null;
9456 for(param = _class.templateParams.first; param; param = param.next)
9458 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9462 if(param && param.defaultArg.member)
9464 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9467 Expression expMember = exp.member.exp;
9469 OldList * specs = MkList();
9470 char thisClassTypeString[1024];
9472 FreeIdentifier(exp.member.member);
9474 ProcessExpressionType(argExp);
9477 char * colon = strstr(param.defaultArg.memberString, "::");
9480 char className[1024];
9483 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9484 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9487 strcpy(thisClassTypeString, _class.fullName);
9490 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9492 exp.expType = ProcessType(specs, decl);
9493 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9495 Class expClass = exp.expType._class.registered;
9496 Class cClass = null;
9501 char templateString[1024];
9502 ClassTemplateParameter param;
9503 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9504 for(cClass = expClass; cClass; cClass = cClass.base)
9507 for(param = cClass.templateParams.first; param; param = param.next)
9511 ClassTemplateArgument arg;
9512 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9513 arg = expClass.templateArgs[id];
9515 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9517 ClassTemplateParameter cParam;
9518 //int p = numParams - sClass.templateParams.count;
9521 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9523 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9525 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9527 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9529 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9530 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9542 strcat(argument, arg.name.string);
9543 strcat(argument, " = ");
9549 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9550 char expString[1024];
9551 OldList * specs = MkList();
9552 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9554 char * string = PrintHexUInt64(arg.expression.ui64);
9555 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9558 ProcessExpressionType(exp);
9559 ComputeExpression(exp);
9560 expString[0] = '\0';
9561 PrintExpression(exp, expString);
9562 strcat(argument, expString);
9564 FreeExpression(exp);
9569 strcat(argument, arg.member.name);
9572 case TemplateParameterType::type:
9574 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9576 if(!strcmp(arg.dataTypeString, "thisclass"))
9577 strcat(argument, thisClassTypeString);
9579 strcat(argument, arg.dataTypeString);
9586 if(paramCount) strcat(templateString, ", ");
9587 if(lastParam != p - 1)
9589 strcat(templateString, param.name);
9590 strcat(templateString, " = ");
9592 strcat(templateString, argument);
9601 int len = strlen(templateString);
9602 if(templateString[len-1] == '>') templateString[len++] = ' ';
9603 templateString[len++] = '>';
9604 templateString[len++] = '\0';
9607 Context context = SetupTemplatesContext(_class);
9608 FreeType(exp.expType);
9609 exp.expType = ProcessTypeString(templateString, false);
9610 FinishTemplatesContext(context);
9614 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9615 exp.type = bracketsExp;
9616 exp.list = MkListOne(MkExpOp(null, '*',
9621 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9622 MkExpBrackets(MkListOne(
9623 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9625 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9627 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9632 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9633 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9635 type = ProcessTemplateParameterType(type.templateParameter);
9638 // TODO: *** This seems to be where we should add method support for all basic types ***
9639 if(type && (type.kind == templateType));
9640 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9641 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9642 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9643 (type.kind == pointerType && type.type.kind == charType)))
9645 Identifier id = exp.member.member;
9646 TypeKind typeKind = type.kind;
9647 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9648 if(typeKind == subClassType && exp.member.exp.type == classExp)
9650 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9651 typeKind = classType;
9656 if(typeKind == intType || typeKind == enumType)
9657 _class = eSystem_FindClass(privateModule, "int");
9660 if(type.kind == classType && type._class && type._class.registered)
9662 _class = type._class.registered;
9664 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9666 _class = FindClass("char *").registered;
9668 else if(type.kind == pointerType)
9670 _class = eSystem_FindClass(privateModule, "uintptr");
9671 FreeType(exp.expType);
9672 exp.expType = ProcessTypeString("uintptr", false);
9673 exp.byReference = true;
9677 char string[1024] = "";
9679 PrintTypeNoConst(type, string, false, true);
9680 classSym = FindClass(string);
9681 if(classSym) _class = classSym.registered;
9689 (exp.member.exp.type == identifierExp &&
9690 !strcmp(exp.member.exp.identifier.string, "this"));*/
9691 Property prop = null;
9692 Method method = null;
9693 DataMember member = null;
9694 Property revConvert = null;
9695 ClassProperty classProp = null;
9697 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9698 exp.member.memberType = propertyMember;
9700 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9701 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9703 if(typeKind != subClassType)
9705 // Prioritize data members over properties for "this"
9706 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9708 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9709 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9711 prop = eClass_FindProperty(_class, id.string, privateModule);
9715 if(!member && !prop)
9716 prop = eClass_FindProperty(_class, id.string, privateModule);
9717 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9718 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9719 exp.member.thisPtr = true;
9721 // Prioritize properties over data members otherwise
9724 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9727 prop = eClass_FindProperty(_class, id.string, null);
9728 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9729 member = eClass_FindDataMember(_class, id.string, null, null, null);
9732 if(!prop && !member)
9734 method = eClass_FindMethod(_class, id.string, null);
9737 prop = eClass_FindProperty(_class, id.string, privateModule);
9738 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9739 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9745 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9752 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9753 method = eClass_FindMethod(_class, id.string, privateModule);
9754 if(!prop && !member && !method)
9756 if(typeKind == subClassType)
9758 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9761 exp.member.memberType = classPropertyMember;
9762 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9766 // Assume this is a class_data member
9767 char structName[1024];
9768 Identifier id = exp.member.member;
9769 Expression classExp = exp.member.exp;
9772 FreeType(classExp.expType);
9773 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9775 strcpy(structName, "__ecereClassData_");
9776 FullClassNameCat(structName, type._class.string, false);
9777 exp.type = pointerExp;
9778 exp.member.member = id;
9780 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9781 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9782 MkExpBrackets(MkListOne(MkExpOp(
9783 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9784 MkExpMember(classExp, MkIdentifier("data"))), '+',
9785 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9790 ProcessExpressionType(exp);
9796 // Check for reverse conversion
9797 // (Convert in an instantiation later, so that we can use
9798 // deep properties system)
9799 Symbol classSym = FindClass(id.string);
9802 Class convertClass = classSym.registered;
9804 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9811 exp.member.memberType = propertyMember;
9813 ProcessPropertyType(prop);
9814 exp.expType = prop.dataType;
9815 if(prop.dataType) prop.dataType.refCount++;
9819 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9821 FreeExpContents(exp);
9822 exp.type = identifierExp;
9823 exp.identifier = MkIdentifier("class");
9824 ProcessExpressionType(exp);
9828 exp.member.memberType = dataMember;
9829 DeclareStruct(_class.fullName, false);
9830 if(!member.dataType)
9832 Context context = SetupTemplatesContext(_class);
9833 member.dataType = ProcessTypeString(member.dataTypeString, false);
9834 FinishTemplatesContext(context);
9836 exp.expType = member.dataType;
9837 if(member.dataType) member.dataType.refCount++;
9841 exp.member.memberType = reverseConversionMember;
9842 exp.expType = MkClassType(revConvert._class.fullName);
9850 exp.type = identifierExp;
9851 exp.identifier = exp.member.member;
9854 exp.member.memberType = methodMember;
9856 if(!method.dataType)
9857 ProcessMethodType(method);
9865 // Tricky spot here... To use instance versus class virtual table
9866 // Put it back to what it was... What did we break?
9868 // Had to put it back for overriding Main of Thread global instance
9870 //exp.expType.methodClass = _class;
9871 exp.expType.methodClass = (id && id._class) ? _class : null;
9873 // Need the actual class used for templated classes
9874 exp.expType.usedClass = _class;
9878 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9880 FreeExpContents(exp);
9881 exp.type = identifierExp;
9882 exp.identifier = MkIdentifier("class");
9883 FreeType(exp.expType);
9884 exp.expType = MkClassType("ecere::com::Class");
9887 yylloc = exp.member.member.loc;
9888 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9890 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9893 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9898 while(tClass && !tClass.templateClass) tClass = tClass.base;
9900 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9903 ClassTemplateParameter curParam = null;
9906 for(sClass = tClass; sClass; sClass = sClass.base)
9909 if(sClass.templateClass) sClass = sClass.templateClass;
9910 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9912 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9914 for(sClass = sClass.base; sClass; sClass = sClass.base)
9915 id += sClass.templateParams.count;
9923 if(curParam && tClass.templateArgs[id].dataTypeString)
9925 ClassTemplateArgument arg = tClass.templateArgs[id];
9926 Context context = SetupTemplatesContext(tClass);
9928 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9929 FreeType(exp.expType);
9930 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9933 if(exp.expType.kind == thisClassType)
9935 FreeType(exp.expType);
9936 exp.expType = ReplaceThisClassType(_class);
9939 if(tClass.templateClass)
9940 exp.expType.passAsTemplate = true;
9941 //exp.expType.refCount++;
9944 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9945 //exp.destType.refCount++;
9947 if(exp.destType.kind == thisClassType)
9949 FreeType(exp.destType);
9950 exp.destType = ReplaceThisClassType(_class);
9954 FinishTemplatesContext(context);
9957 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9958 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9961 ClassTemplateParameter curParam = null;
9964 for(sClass = tClass; sClass; sClass = sClass.base)
9967 if(sClass.templateClass) sClass = sClass.templateClass;
9968 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9970 if(curParam.type == TemplateParameterType::type &&
9971 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9973 for(sClass = sClass.base; sClass; sClass = sClass.base)
9974 id += sClass.templateParams.count;
9984 ClassTemplateArgument arg = tClass.templateArgs[id];
9985 Context context = SetupTemplatesContext(tClass);
9988 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9990 basicType = ProcessTypeString(arg.dataTypeString, false);
9993 if(basicType.kind == thisClassType)
9995 FreeType(basicType);
9996 basicType = ReplaceThisClassType(_class);
9999 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10000 if(tClass.templateClass)
10001 basicType.passAsTemplate = true;
10004 FreeType(exp.expType);
10006 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10007 //exp.expType.refCount++;
10010 exp.destType = exp.expType;
10011 exp.destType.refCount++;
10015 Expression newExp { };
10016 OldList * specs = MkList();
10018 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10020 if(exp.destType) exp.destType.refCount++;
10021 if(exp.expType) exp.expType.refCount++;
10022 exp.type = castExp;
10023 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10024 exp.cast.exp = newExp;
10025 //FreeType(exp.expType);
10026 //exp.expType = null;
10027 //ProcessExpressionType(sourceExp);
10030 FinishTemplatesContext(context);
10033 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10035 Class expClass = exp.expType._class.registered;
10038 Class cClass = null;
10041 int paramCount = 0;
10042 int lastParam = -1;
10043 char templateString[1024];
10044 ClassTemplateParameter param;
10045 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10046 while(cClass != expClass)
10049 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10052 for(param = cClass.templateParams.first; param; param = param.next)
10054 Class cClassCur = null;
10057 ClassTemplateParameter paramCur = null;
10058 ClassTemplateArgument arg;
10059 while(cClassCur != tClass && !paramCur)
10062 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10063 cClassCur = sClassCur;
10065 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10067 if(!strcmp(paramCur.name, param.name))
10075 if(paramCur && paramCur.type == TemplateParameterType::type)
10076 arg = tClass.templateArgs[cp];
10078 arg = expClass.templateArgs[p];
10081 char argument[256];
10082 argument[0] = '\0';
10085 strcat(argument, arg.name.string);
10086 strcat(argument, " = ");
10092 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10093 char expString[1024];
10094 OldList * specs = MkList();
10095 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10097 char * string = PrintHexUInt64(arg.expression.ui64);
10098 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10101 ProcessExpressionType(exp);
10102 ComputeExpression(exp);
10103 expString[0] = '\0';
10104 PrintExpression(exp, expString);
10105 strcat(argument, expString);
10107 FreeExpression(exp);
10112 strcat(argument, arg.member.name);
10115 case TemplateParameterType::type:
10117 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10118 strcat(argument, arg.dataTypeString);
10124 if(paramCount) strcat(templateString, ", ");
10125 if(lastParam != p - 1)
10127 strcat(templateString, param.name);
10128 strcat(templateString, " = ");
10130 strcat(templateString, argument);
10139 int len = strlen(templateString);
10140 if(templateString[len-1] == '>') templateString[len++] = ' ';
10141 templateString[len++] = '>';
10142 templateString[len++] = '\0';
10145 FreeType(exp.expType);
10147 Context context = SetupTemplatesContext(tClass);
10148 exp.expType = ProcessTypeString(templateString, false);
10149 FinishTemplatesContext(context);
10156 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10158 else if(type && (type.kind == structType || type.kind == unionType))
10160 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10163 exp.expType = memberType;
10165 memberType.refCount++;
10170 char expString[10240];
10171 expString[0] = '\0';
10172 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10173 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10176 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10178 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10180 Identifier id = exp.member.member;
10181 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10184 FreeType(exp.expType);
10185 exp.expType = ReplaceThisClassType(_class);
10189 yylloc = oldyylloc;
10192 // Convert x->y into (*x).y
10195 Type destType = exp.destType;
10197 // DOING THIS LATER NOW...
10198 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10200 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10201 /* TODO: Name Space Fix ups
10202 if(!exp.member.member.classSym)
10203 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10207 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10208 exp.type = memberExp;
10211 ProcessExpressionType(exp);
10218 //ComputeExpression(exp);
10220 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10221 if(classSym && classSym.registered)
10223 if(classSym.registered.type == noHeadClass)
10227 DeclareStruct(classSym.string, false);
10228 FreeSpecifier(exp._class);
10229 exp.type = typeSizeExp;
10230 FullClassNameCat(name, classSym.string, false);
10231 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10235 if(classSym.registered.fixed)
10237 FreeSpecifier(exp._class);
10238 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10239 exp.type = constantExp;
10243 char className[1024];
10244 strcpy(className, "__ecereClass_");
10245 FullClassNameCat(className, classSym.string, true);
10246 MangleClassName(className);
10248 DeclareClass(classSym, className);
10250 FreeExpContents(exp);
10251 exp.type = pointerExp;
10252 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10253 exp.member.member = MkIdentifier("structSize");
10263 // exp.isConstant = true;
10268 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10275 exp.isConstant = true;
10277 DeclareType(type, false, false);
10283 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10285 FreeType(exp.cast.exp.destType);
10286 exp.cast.exp.destType = type;
10288 ProcessExpressionType(exp.cast.exp);
10290 exp.expType = type;
10293 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10294 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10296 void * prev = exp.prev, * next = exp.next;
10297 Type expType = exp.cast.exp.destType;
10298 Expression castExp = exp.cast.exp;
10299 Type destType = exp.destType;
10301 if(expType) expType.refCount++;
10303 //FreeType(exp.destType);
10304 FreeType(exp.expType);
10305 FreeTypeName(exp.cast.typeName);
10308 FreeType(exp.expType);
10309 FreeType(exp.destType);
10311 exp.expType = expType;
10312 exp.destType = destType;
10322 exp.isConstant = exp.cast.exp.isConstant;
10327 case extensionInitializerExp:
10329 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10330 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10331 // ProcessInitializer(exp.initializer.initializer, type);
10332 exp.expType = type;
10337 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10338 ProcessExpressionType(exp.vaArg.exp);
10339 exp.expType = type;
10345 exp.isConstant = true;
10347 FreeType(exp.cond.cond.destType);
10348 exp.cond.cond.destType = MkClassType("bool");
10349 exp.cond.cond.destType.truth = true;
10350 ProcessExpressionType(exp.cond.cond);
10351 if(!exp.cond.cond.isConstant)
10352 exp.isConstant = false;
10353 for(e = exp.cond.exp->first; e; e = e.next)
10357 FreeType(e.destType);
10358 e.destType = exp.destType;
10359 if(e.destType) e.destType.refCount++;
10361 ProcessExpressionType(e);
10364 exp.expType = e.expType;
10365 if(e.expType) e.expType.refCount++;
10368 exp.isConstant = false;
10371 FreeType(exp.cond.elseExp.destType);
10372 // Added this check if we failed to find an expType
10373 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10376 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10378 if(exp.cond.elseExp.destType)
10379 exp.cond.elseExp.destType.refCount++;
10380 ProcessExpressionType(exp.cond.elseExp);
10382 // FIXED THIS: Was done before calling process on elseExp
10383 if(!exp.cond.elseExp.isConstant)
10384 exp.isConstant = false;
10387 case extensionCompoundExp:
10389 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10391 Statement last = exp.compound.compound.statements->last;
10392 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10394 ((Expression)last.expressions->last).destType = exp.destType;
10396 exp.destType.refCount++;
10398 ProcessStatement(exp.compound);
10399 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10401 exp.expType.refCount++;
10407 Specifier spec = exp._classExp.specifiers->first;
10408 if(spec && spec.type == nameSpecifier)
10410 exp.expType = MkClassType(spec.name);
10411 exp.expType.kind = subClassType;
10412 exp.byReference = true;
10416 exp.expType = MkClassType("ecere::com::Class");
10417 exp.byReference = true;
10423 Class _class = thisClass ? thisClass : currentClass;
10426 Identifier id = exp.classData.id;
10427 char structName[1024];
10428 Expression classExp;
10429 strcpy(structName, "__ecereClassData_");
10430 FullClassNameCat(structName, _class.fullName, false);
10431 exp.type = pointerExp;
10432 exp.member.member = id;
10433 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10434 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10436 classExp = MkExpIdentifier(MkIdentifier("class"));
10438 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10439 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10440 MkExpBrackets(MkListOne(MkExpOp(
10441 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10442 MkExpMember(classExp, MkIdentifier("data"))), '+',
10443 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10446 ProcessExpressionType(exp);
10454 char * typeString = null;
10455 char typeStringBuf[1024];
10456 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10457 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10459 Class templateClass = exp.destType._class.registered;
10460 typeString = templateClass.templateArgs[2].dataTypeString;
10464 // Guess type from expressions in the array
10466 for(e = exp.list->first; e; e = e.next)
10468 ProcessExpressionType(e);
10471 if(!type) { type = e.expType; type.refCount++; }
10474 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10475 if(!MatchTypeExpression(e, type, null, false))
10481 e = exp.list->first;
10482 ProcessExpressionType(e);
10485 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10486 if(!MatchTypeExpression(e, type, null, false))
10488 FreeType(e.expType);
10499 FreeType(e.expType);
10506 typeStringBuf[0] = '\0';
10507 PrintTypeNoConst(type, typeStringBuf, false, true);
10508 typeString = typeStringBuf;
10516 (Container)& (struct BuiltInContainer)
10518 ._vTbl = class(BuiltInContainer)._vTbl,
10519 ._class = class(BuiltInContainer),
10521 .data = (int[]){ 1, 7, 3, 4, 5 },
10523 .type = class(int),
10526 char templateString[1024];
10527 OldList * initializers = MkList();
10528 OldList * structInitializers = MkList();
10529 OldList * specs = MkList();
10531 Declarator decl = SpecDeclFromString(typeString, specs, null);
10532 sprintf(templateString, "Container<%s>", typeString);
10537 type = ProcessTypeString(typeString, false);
10538 while(e = exp.list->first)
10540 exp.list->Remove(e);
10543 ProcessExpressionType(e);
10544 ListAdd(initializers, MkInitializerAssignment(e));
10550 DeclareStruct("ecere::com::BuiltInContainer", false);
10552 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10553 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10554 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10555 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10556 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10557 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10558 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10559 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10560 MkInitializerList(initializers))));
10561 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10562 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10563 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10564 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10565 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10566 exp.expType = ProcessTypeString(templateString, false);
10567 exp.type = bracketsExp;
10568 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10570 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10571 MkInitializerList(structInitializers)))));
10572 ProcessExpressionType(expExt);
10576 exp.expType = ProcessTypeString("Container", false);
10577 Compiler_Error($"Couldn't determine type of array elements\n");
10583 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10585 FreeType(exp.expType);
10586 exp.expType = ReplaceThisClassType(thisClass);
10589 // Resolve structures here
10590 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10592 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10593 // TODO: Fix members reference...
10596 if(exp.expType.kind != enumType)
10599 String enumName = CopyString(exp.expType.enumName);
10601 // Fixed a memory leak on self-referencing C structs typedefs
10602 // by instantiating a new type rather than simply copying members
10603 // into exp.expType
10604 FreeType(exp.expType);
10605 exp.expType = Type { };
10606 exp.expType.kind = symbol.type.kind;
10607 exp.expType.refCount++;
10608 exp.expType.enumName = enumName;
10610 exp.expType.members = symbol.type.members;
10611 for(member = symbol.type.members.first; member; member = member.next)
10617 for(member = symbol.type.members.first; member; member = member.next)
10619 NamedLink value { name = CopyString(member.name) };
10620 exp.expType.members.Add(value);
10627 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10628 else if(exp.destType && !exp.destType.keepCast)
10630 if(!CheckExpressionType(exp, exp.destType, false))
10632 if(!exp.destType.count || unresolved)
10637 if(exp.destType.kind != ellipsisType)
10643 char expString[10240];
10644 expString[0] = '\0';
10646 PrintType(exp.destType, type2, false, true);
10648 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10650 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10651 else if(exp.type != dummyExp)
10652 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10657 char expString[10240] ;
10658 expString[0] = '\0';
10659 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10662 Compiler_Error($"unresolved identifier %s\n", expString);
10663 else if(exp.type != dummyExp)
10664 Compiler_Error($"couldn't determine type of %s\n", expString);
10675 PrintType(exp.expType, type1, false, true);
10676 PrintType(exp.destType, type2, false, true);
10679 //CheckExpressionType(exp, exp.destType, false);
10681 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10682 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10683 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10686 char expString[10240];
10687 expString[0] = '\0';
10688 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10691 CheckExpressionType(exp, exp.destType, false);
10693 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10694 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10695 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10697 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10698 FreeType(exp.expType);
10699 exp.destType.refCount++;
10700 exp.expType = exp.destType;
10705 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10707 Expression newExp { };
10708 char typeString[1024];
10709 OldList * specs = MkList();
10712 typeString[0] = '\0';
10716 if(exp.expType) exp.expType.refCount++;
10717 if(exp.expType) exp.expType.refCount++;
10718 exp.type = castExp;
10719 newExp.destType = exp.expType;
10721 PrintType(exp.expType, typeString, false, false);
10722 decl = SpecDeclFromString(typeString, specs, null);
10724 exp.cast.typeName = MkTypeName(specs, decl);
10725 exp.cast.exp = newExp;
10728 else if(unresolved)
10730 if(exp.identifier._class && exp.identifier._class.name)
10731 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10732 else if(exp.identifier.string && exp.identifier.string[0])
10733 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10735 else if(!exp.expType && exp.type != dummyExp)
10737 char expString[10240];
10738 expString[0] = '\0';
10739 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10740 Compiler_Error($"couldn't determine type of %s\n", expString);
10743 // Let's try to support any_object & typed_object here:
10745 ApplyAnyObjectLogic(exp);
10747 // Mark nohead classes as by reference, unless we're casting them to an integral type
10748 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10749 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10750 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10751 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10753 exp.byReference = true;
10755 yylloc = oldyylloc;
10758 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10760 // THIS CODE WILL FIND NEXT MEMBER...
10763 *curMember = (*curMember).next;
10765 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10767 *curMember = subMemberStack[--(*subMemberStackPos)];
10768 *curMember = (*curMember).next;
10771 // SKIP ALL PROPERTIES HERE...
10772 while((*curMember) && (*curMember).isProperty)
10773 *curMember = (*curMember).next;
10775 if(subMemberStackPos)
10777 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10779 subMemberStack[(*subMemberStackPos)++] = *curMember;
10781 *curMember = (*curMember).members.first;
10782 while(*curMember && (*curMember).isProperty)
10783 *curMember = (*curMember).next;
10791 if(subMemberStackPos && *subMemberStackPos)
10793 *curMember = subMemberStack[--(*subMemberStackPos)];
10794 *curMember = (*curMember).next;
10798 Class lastCurClass = *curClass;
10800 if(*curClass == _class) break; // REACHED THE END
10802 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10803 *curMember = (*curClass).membersAndProperties.first;
10806 while((*curMember) && (*curMember).isProperty)
10807 *curMember = (*curMember).next;
10808 if(subMemberStackPos)
10810 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10812 subMemberStack[(*subMemberStackPos)++] = *curMember;
10814 *curMember = (*curMember).members.first;
10815 while(*curMember && (*curMember).isProperty)
10816 *curMember = (*curMember).next;
10824 static void ProcessInitializer(Initializer init, Type type)
10828 case expInitializer:
10829 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10831 // TESTING THIS FOR SHUTTING = 0 WARNING
10832 if(init.exp && !init.exp.destType)
10834 FreeType(init.exp.destType);
10835 init.exp.destType = type;
10836 if(type) type.refCount++;
10840 ProcessExpressionType(init.exp);
10841 init.isConstant = init.exp.isConstant;
10847 Expression exp = init.exp;
10848 Instantiation inst = exp.instance;
10849 MembersInit members;
10851 init.type = listInitializer;
10852 init.list = MkList();
10856 for(members = inst.members->first; members; members = members.next)
10858 if(members.type == dataMembersInit)
10861 for(member = members.dataMembers->first; member; member = member.next)
10863 ListAdd(init.list, member.initializer);
10864 member.initializer = null;
10867 // Discard all MembersInitMethod
10870 FreeExpression(exp);
10872 case listInitializer:
10875 Type initializerType = null;
10876 Class curClass = null;
10877 DataMember curMember = null;
10878 DataMember subMemberStack[256];
10879 int subMemberStackPos = 0;
10881 if(type && type.kind == arrayType)
10882 initializerType = Dereference(type);
10883 else if(type && (type.kind == structType || type.kind == unionType))
10884 initializerType = type.members.first;
10886 for(i = init.list->first; i; i = i.next)
10888 if(type && type.kind == classType && type._class && type._class.registered)
10890 // 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)
10891 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10892 // TODO: Generate error on initializing a private data member this way from another module...
10895 if(!curMember.dataType)
10896 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10897 initializerType = curMember.dataType;
10900 ProcessInitializer(i, initializerType);
10901 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10902 initializerType = initializerType.next;
10904 init.isConstant = false;
10907 if(type && type.kind == arrayType)
10908 FreeType(initializerType);
10910 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10912 Compiler_Error($"Assigning list initializer to non list\n");
10919 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10923 case baseSpecifier:
10925 if(spec.specifier == THISCLASS)
10929 spec.type = nameSpecifier;
10930 spec.name = ReplaceThisClass(thisClass);
10931 spec.symbol = FindClass(spec.name);
10932 ProcessSpecifier(spec, declareStruct);
10937 case nameSpecifier:
10939 Symbol symbol = FindType(curContext, spec.name);
10941 DeclareType(symbol.type, true, true);
10942 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10943 DeclareStruct(spec.name, false);
10946 case enumSpecifier:
10951 for(e = spec.list->first; e; e = e.next)
10954 ProcessExpressionType(e.exp);
10959 case structSpecifier:
10960 case unionSpecifier:
10962 if(spec.definitions)
10965 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10967 ProcessClass(spec.definitions, symbol);
10970 for(def = spec.definitions->first; def; def = def.next)
10972 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10973 ProcessDeclaration(def.decl);
10980 case classSpecifier:
10982 Symbol classSym = FindClass(spec.name);
10983 if(classSym && classSym.registered && classSym.registered.type == structClass)
10984 DeclareStruct(spec.name, false);
10992 static void ProcessDeclarator(Declarator decl)
10996 case identifierDeclarator:
10997 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10999 FreeSpecifier(decl.identifier._class);
11000 decl.identifier._class = null;
11003 case arrayDeclarator:
11005 ProcessExpressionType(decl.array.exp);
11006 case structDeclarator:
11007 case bracketsDeclarator:
11008 case functionDeclarator:
11009 case pointerDeclarator:
11010 case extendedDeclarator:
11011 case extendedDeclaratorEnd:
11012 if(decl.declarator)
11013 ProcessDeclarator(decl.declarator);
11014 if(decl.type == functionDeclarator)
11016 Identifier id = GetDeclId(decl);
11017 if(id && id._class)
11021 qualifiers = MkListOne(id._class);
11024 if(!decl.function.parameters)
11025 decl.function.parameters = MkList();
11026 decl.function.parameters->Insert(null, param);
11029 if(decl.function.parameters)
11033 for(param = decl.function.parameters->first; param; param = param.next)
11035 if(param.qualifiers && param.qualifiers->first)
11037 Specifier spec = param.qualifiers->first;
11038 if(spec && spec.specifier == TYPED_OBJECT)
11040 Declarator d = param.declarator;
11043 qualifiers = MkListOne(MkSpecifier(VOID));
11044 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11047 FreeList(param.qualifiers, FreeSpecifier);
11049 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11050 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11052 decl.function.parameters->Insert(param, newParam);
11055 else if(spec && spec.specifier == ANY_OBJECT)
11057 Declarator d = param.declarator;
11059 FreeList(param.qualifiers, FreeSpecifier);
11061 param.qualifiers = MkListOne(MkSpecifier(VOID));
11062 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11064 else if(spec.specifier == THISCLASS)
11068 spec.type = nameSpecifier;
11069 spec.name = ReplaceThisClass(thisClass);
11070 spec.symbol = FindClass(spec.name);
11071 ProcessSpecifier(spec, false);
11076 if(param.declarator)
11077 ProcessDeclarator(param.declarator);
11085 static void ProcessDeclaration(Declaration decl)
11090 case initDeclaration:
11092 bool declareStruct = false;
11094 lineNum = decl.pos.line;
11095 column = decl.pos.col;
11098 if(decl.declarators)
11102 for(d = decl.declarators->first; d; d = d.next)
11104 Type type, subType;
11105 ProcessDeclarator(d.declarator);
11107 type = ProcessType(decl.specifiers, d.declarator);
11111 ProcessInitializer(d.initializer, type);
11113 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11115 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11116 d.initializer.exp.type == instanceExp)
11118 if(type.kind == classType && type._class ==
11119 d.initializer.exp.expType._class)
11121 Instantiation inst = d.initializer.exp.instance;
11122 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11124 d.initializer.exp.instance = null;
11125 if(decl.specifiers)
11126 FreeList(decl.specifiers, FreeSpecifier);
11127 FreeList(decl.declarators, FreeInitDeclarator);
11131 decl.type = instDeclaration;
11136 for(subType = type; subType;)
11138 if(subType.kind == classType)
11140 declareStruct = true;
11143 else if(subType.kind == pointerType)
11145 else if(subType.kind == arrayType)
11146 subType = subType.arrayType;
11156 if(decl.specifiers)
11159 for(s = decl.specifiers->first; s; s = s.next)
11161 ProcessSpecifier(s, declareStruct);
11166 case instDeclaration:
11168 ProcessInstantiationType(decl.inst);
11171 case structDeclaration:
11175 bool declareStruct = false;
11177 if(decl.declarators)
11179 for(d = decl.declarators->first; d; d = d.next)
11181 Type type = ProcessType(decl.specifiers, d.declarator);
11183 ProcessDeclarator(d);
11184 for(subType = type; subType;)
11186 if(subType.kind == classType)
11188 declareStruct = true;
11191 else if(subType.kind == pointerType)
11193 else if(subType.kind == arrayType)
11194 subType = subType.arrayType;
11201 if(decl.specifiers)
11203 for(spec = decl.specifiers->first; spec; spec = spec.next)
11204 ProcessSpecifier(spec, declareStruct);
11211 static FunctionDefinition curFunction;
11213 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11215 char propName[1024], propNameM[1024];
11216 char getName[1024], setName[1024];
11219 DeclareProperty(prop, setName, getName);
11221 // eInstance_FireWatchers(object, prop);
11222 strcpy(propName, "__ecereProp_");
11223 FullClassNameCat(propName, prop._class.fullName, false);
11224 strcat(propName, "_");
11225 // strcat(propName, prop.name);
11226 FullClassNameCat(propName, prop.name, true);
11227 MangleClassName(propName);
11229 strcpy(propNameM, "__ecerePropM_");
11230 FullClassNameCat(propNameM, prop._class.fullName, false);
11231 strcat(propNameM, "_");
11232 // strcat(propNameM, prop.name);
11233 FullClassNameCat(propNameM, prop.name, true);
11234 MangleClassName(propNameM);
11236 if(prop.isWatchable)
11239 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11240 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11241 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11244 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11245 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11246 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11252 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11253 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11254 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11257 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11258 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11259 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11262 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11263 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11264 curFunction.propSet.fireWatchersDone = true;
11267 static void ProcessStatement(Statement stmt)
11271 lineNum = stmt.pos.line;
11272 column = stmt.pos.col;
11277 ProcessStatement(stmt.labeled.stmt);
11280 // This expression should be constant...
11281 if(stmt.caseStmt.exp)
11283 FreeType(stmt.caseStmt.exp.destType);
11284 stmt.caseStmt.exp.destType = curSwitchType;
11285 if(curSwitchType) curSwitchType.refCount++;
11286 ProcessExpressionType(stmt.caseStmt.exp);
11287 ComputeExpression(stmt.caseStmt.exp);
11289 if(stmt.caseStmt.stmt)
11290 ProcessStatement(stmt.caseStmt.stmt);
11294 if(stmt.compound.context)
11299 Statement prevCompound = curCompound;
11300 Context prevContext = curContext;
11302 if(!stmt.compound.isSwitch)
11303 curCompound = stmt;
11304 curContext = stmt.compound.context;
11306 if(stmt.compound.declarations)
11308 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11309 ProcessDeclaration(decl);
11311 if(stmt.compound.statements)
11313 for(s = stmt.compound.statements->first; s; s = s.next)
11314 ProcessStatement(s);
11317 curContext = prevContext;
11318 curCompound = prevCompound;
11322 case expressionStmt:
11325 if(stmt.expressions)
11327 for(exp = stmt.expressions->first; exp; exp = exp.next)
11328 ProcessExpressionType(exp);
11336 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11337 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11338 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11339 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11341 ProcessExpressionType(exp);
11343 if(stmt.ifStmt.stmt)
11344 ProcessStatement(stmt.ifStmt.stmt);
11345 if(stmt.ifStmt.elseStmt)
11346 ProcessStatement(stmt.ifStmt.elseStmt);
11351 Type oldSwitchType = curSwitchType;
11352 if(stmt.switchStmt.exp)
11355 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11365 e.exp.destType = destType;
11368 ProcessExpressionType(exp);
11371 curSwitchType = exp.expType;
11374 ProcessStatement(stmt.switchStmt.stmt);
11375 curSwitchType = oldSwitchType;
11380 if(stmt.whileStmt.exp)
11384 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11385 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11386 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11387 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11389 ProcessExpressionType(exp);
11392 if(stmt.whileStmt.stmt)
11393 ProcessStatement(stmt.whileStmt.stmt);
11398 if(stmt.doWhile.exp)
11402 if(stmt.doWhile.exp->last)
11404 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11405 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11406 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11408 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11410 ProcessExpressionType(exp);
11413 if(stmt.doWhile.stmt)
11414 ProcessStatement(stmt.doWhile.stmt);
11420 if(stmt.forStmt.init)
11421 ProcessStatement(stmt.forStmt.init);
11423 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11425 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11426 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11427 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11430 if(stmt.forStmt.check)
11431 ProcessStatement(stmt.forStmt.check);
11432 if(stmt.forStmt.increment)
11434 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11435 ProcessExpressionType(exp);
11438 if(stmt.forStmt.stmt)
11439 ProcessStatement(stmt.forStmt.stmt);
11444 Identifier id = stmt.forEachStmt.id;
11445 OldList * exp = stmt.forEachStmt.exp;
11446 OldList * filter = stmt.forEachStmt.filter;
11447 Statement block = stmt.forEachStmt.stmt;
11448 char iteratorType[1024];
11451 bool isBuiltin = exp && exp->last &&
11452 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11453 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11454 Expression arrayExp;
11455 char * typeString = null;
11456 int builtinCount = 0;
11458 for(e = exp ? exp->first : null; e; e = e.next)
11462 FreeType(e.destType);
11463 e.destType = ProcessTypeString("Container", false);
11465 if(!isBuiltin || e.next)
11466 ProcessExpressionType(e);
11469 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11470 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11471 eClass_IsDerived(source._class.registered, containerClass)))
11473 Class _class = source ? source._class.registered : null;
11475 Expression expIt = null;
11476 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11477 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11478 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11479 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11480 stmt.type = compoundStmt;
11482 stmt.compound.context = Context { };
11483 stmt.compound.context.parent = curContext;
11484 curContext = stmt.compound.context;
11486 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11488 Class mapClass = eSystem_FindClass(privateModule, "Map");
11489 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11490 isCustomAVLTree = true;
11491 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11493 else if(eClass_IsDerived(source._class.registered, mapClass))
11496 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11497 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11499 Class listClass = eSystem_FindClass(privateModule, "List");
11501 isList = eClass_IsDerived(source._class.registered, listClass);
11507 OldList * specs = MkList();
11508 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11509 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11510 stmt.compound.declarations = MkListOne(
11511 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11512 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11513 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11514 MkInitializerAssignment(MkExpBrackets(exp))))));
11519 char typeStringBuf[1024];
11521 // TODO: Merge this code?
11522 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11523 if(((Expression)exp->last).type == castExp)
11525 TypeName typeName = ((Expression)exp->last).cast.typeName;
11527 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11530 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11531 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11532 arrayExp.destType._class.registered.templateArgs)
11534 Class templateClass = arrayExp.destType._class.registered;
11535 typeString = templateClass.templateArgs[2].dataTypeString;
11537 else if(arrayExp.list)
11539 // Guess type from expressions in the array
11541 for(e = arrayExp.list->first; e; e = e.next)
11543 ProcessExpressionType(e);
11546 if(!type) { type = e.expType; type.refCount++; }
11549 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11550 if(!MatchTypeExpression(e, type, null, false))
11556 e = arrayExp.list->first;
11557 ProcessExpressionType(e);
11560 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11561 if(!MatchTypeExpression(e, type, null, false))
11563 FreeType(e.expType);
11574 FreeType(e.expType);
11581 typeStringBuf[0] = '\0';
11582 PrintType(type, typeStringBuf, false, true);
11583 typeString = typeStringBuf;
11589 OldList * initializers = MkList();
11591 OldList * specs = MkList();
11596 builtinCount = arrayExp.list->count;
11597 type = ProcessTypeString(typeString, false);
11598 while(e = arrayExp.list->first)
11600 arrayExp.list->Remove(e);
11603 ProcessExpressionType(e);
11604 ListAdd(initializers, MkInitializerAssignment(e));
11607 delete arrayExp.list;
11609 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11610 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11611 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11613 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11615 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11616 ), MkInitializerList(initializers)))));
11617 FreeList(exp, FreeExpression);
11621 arrayExp.expType = ProcessTypeString("Container", false);
11622 Compiler_Error($"Couldn't determine type of array elements\n");
11627 OldList * specs = MkList();
11629 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11630 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11631 stmt.compound.declarations = MkListOne(
11632 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11633 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11634 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11635 MkInitializerAssignment(MkExpBrackets(exp))))));
11638 else if(isLinkList && !isList)
11641 OldList * specs = MkList();
11642 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11643 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11644 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11645 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11646 MkInitializerAssignment(MkExpBrackets(exp))))));
11648 /*else if(isCustomAVLTree)
11651 OldList * specs = MkList();
11652 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11653 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11654 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11655 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11656 MkInitializerAssignment(MkExpBrackets(exp))))));
11658 else if(_class.templateArgs)
11661 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11663 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11665 stmt.compound.declarations = MkListOne(
11666 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11667 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11668 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11670 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11674 // Reparent sub-contexts in this statement
11678 if(block.compound.context)
11679 block.compound.context.parent = stmt.compound.context;
11682 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11683 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11684 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11685 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11688 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11689 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11692 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11693 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11696 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11697 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11700 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11701 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11704 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11705 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11707 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11710 case expressionStmt:
11716 case badDeclarationStmt:
11717 case fireWatchersStmt:
11718 case stopWatchingStmt:
11725 block = MkIfStmt(filter, block, null);
11729 stmt.compound.statements = MkListOne(MkForStmt(
11730 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11731 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11732 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11733 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11735 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11736 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11737 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11742 //OldList * specs = MkList();
11743 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11745 sprintf(count, "%d", builtinCount);
11747 stmt.compound.statements = MkListOne(MkForStmt(
11748 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11749 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11750 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11751 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11755 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11756 stmt.compound.statements = MkListOne(MkForStmt(
11757 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11758 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11759 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11760 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11763 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11764 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11765 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11767 else if(isLinkList && !isList)
11769 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11770 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11771 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11772 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11774 stmt.compound.statements = MkListOne(MkForStmt(
11775 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11776 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11777 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11782 OldList * specs = MkList();
11783 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11784 stmt.compound.statements = MkListOne(MkForStmt(
11785 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11786 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11787 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11788 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11789 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11792 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11793 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11794 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11796 /*else if(isCustomAVLTree)
11798 stmt.compound.statements = MkListOne(MkForStmt(
11799 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11800 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11801 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11802 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11805 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11806 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11807 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11811 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11812 MkIdentifier("Next")), null)), block));
11814 ProcessExpressionType(expIt);
11815 if(stmt.compound.declarations->first)
11816 ProcessDeclaration(stmt.compound.declarations->first);
11819 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11821 ProcessStatement(stmt);
11822 curContext = stmt.compound.context.parent;
11827 Compiler_Error($"Expression is not a container\n");
11840 if(stmt.expressions)
11842 for(exp = stmt.expressions->first; exp; exp = exp.next)
11846 if(curFunction && !curFunction.type)
11847 curFunction.type = ProcessType(
11848 curFunction.specifiers, curFunction.declarator);
11849 FreeType(exp.destType);
11850 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11851 if(exp.destType) exp.destType.refCount++;
11853 ProcessExpressionType(exp);
11858 case badDeclarationStmt:
11860 ProcessDeclaration(stmt.decl);
11866 if(stmt.asmStmt.inputFields)
11868 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11869 if(field.expression)
11870 ProcessExpressionType(field.expression);
11872 if(stmt.asmStmt.outputFields)
11874 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11875 if(field.expression)
11876 ProcessExpressionType(field.expression);
11878 if(stmt.asmStmt.clobberedFields)
11880 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11882 if(field.expression)
11883 ProcessExpressionType(field.expression);
11890 PropertyWatch propWatch;
11891 OldList * watches = stmt._watch.watches;
11892 Expression object = stmt._watch.object;
11893 Expression watcher = stmt._watch.watcher;
11895 ProcessExpressionType(watcher);
11897 ProcessExpressionType(object);
11901 if(watcher || thisClass)
11903 External external = curExternal;
11904 Context context = curContext;
11906 stmt.type = expressionStmt;
11907 stmt.expressions = MkList();
11909 curExternal = external.prev;
11911 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11913 ClassFunction func;
11914 char watcherName[1024];
11915 Class watcherClass = watcher ?
11916 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11917 External createdExternal;
11919 // Create a declaration above
11920 External externalDecl = MkExternalDeclaration(null);
11921 ast->Insert(curExternal.prev, externalDecl);
11923 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11924 if(propWatch.deleteWatch)
11925 strcat(watcherName, "_delete");
11929 for(propID = propWatch.properties->first; propID; propID = propID.next)
11931 strcat(watcherName, "_");
11932 strcat(watcherName, propID.string);
11936 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11938 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11939 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11940 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11941 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11942 ProcessClassFunctionBody(func, propWatch.compound);
11943 propWatch.compound = null;
11945 //afterExternal = afterExternal ? afterExternal : curExternal;
11947 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11948 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11950 createdExternal.symbol.idCode = external.symbol.idCode;
11952 curExternal = createdExternal;
11953 ProcessFunction(createdExternal.function);
11956 // Create a declaration above
11958 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11959 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11960 externalDecl.declaration = decl;
11961 if(decl.symbol && !decl.symbol.pointerExternal)
11962 decl.symbol.pointerExternal = externalDecl;
11965 if(propWatch.deleteWatch)
11967 OldList * args = MkList();
11968 ListAdd(args, CopyExpression(object));
11969 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11970 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11971 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11975 Class _class = object.expType._class.registered;
11978 for(propID = propWatch.properties->first; propID; propID = propID.next)
11980 char propName[1024];
11981 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11984 char getName[1024], setName[1024];
11985 OldList * args = MkList();
11987 DeclareProperty(prop, setName, getName);
11989 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11990 strcpy(propName, "__ecereProp_");
11991 FullClassNameCat(propName, prop._class.fullName, false);
11992 strcat(propName, "_");
11993 // strcat(propName, prop.name);
11994 FullClassNameCat(propName, prop.name, true);
11996 ListAdd(args, CopyExpression(object));
11997 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11998 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11999 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12001 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12004 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
12009 Compiler_Error($"Invalid watched object\n");
12012 curExternal = external;
12013 curContext = context;
12016 FreeExpression(watcher);
12018 FreeExpression(object);
12019 FreeList(watches, FreePropertyWatch);
12022 Compiler_Error($"No observer specified and not inside a _class\n");
12026 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12028 ProcessStatement(propWatch.compound);
12034 case fireWatchersStmt:
12036 OldList * watches = stmt._watch.watches;
12037 Expression object = stmt._watch.object;
12039 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12040 // printf("%X\n", watches);
12041 // printf("%X\n", stmt._watch.watches);
12043 ProcessExpressionType(object);
12048 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12054 stmt.type = expressionStmt;
12055 stmt.expressions = MkList();
12057 // Check if we're inside a property set
12058 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12060 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12064 //Compiler_Error($"No property specified and not inside a property set\n");
12068 for(propID = watches->first; propID; propID = propID.next)
12070 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12073 CreateFireWatcher(prop, object, stmt);
12076 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12081 // Fire all properties!
12084 for(base = _class; base; base = base.base)
12086 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12088 if(prop.isProperty && prop.isWatchable)
12090 CreateFireWatcher(prop, object, stmt);
12097 FreeExpression(object);
12098 FreeList(watches, FreeIdentifier);
12101 Compiler_Error($"Invalid object specified and not inside a class\n");
12105 case stopWatchingStmt:
12107 OldList * watches = stmt._watch.watches;
12108 Expression object = stmt._watch.object;
12109 Expression watcher = stmt._watch.watcher;
12112 ProcessExpressionType(object);
12114 ProcessExpressionType(watcher);
12117 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12119 if(watcher || thisClass)
12125 stmt.type = expressionStmt;
12126 stmt.expressions = MkList();
12131 // eInstance_StopWatching(object, null, watcher);
12133 ListAdd(args, CopyExpression(object));
12134 ListAdd(args, MkExpConstant("0"));
12135 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12136 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12140 for(propID = watches->first; propID; propID = propID.next)
12142 char propName[1024];
12143 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12146 char getName[1024], setName[1024];
12147 OldList * args = MkList();
12149 DeclareProperty(prop, setName, getName);
12151 // eInstance_StopWatching(object, prop, watcher);
12152 strcpy(propName, "__ecereProp_");
12153 FullClassNameCat(propName, prop._class.fullName, false);
12154 strcat(propName, "_");
12155 // strcat(propName, prop.name);
12156 FullClassNameCat(propName, prop.name, true);
12157 MangleClassName(propName);
12159 ListAdd(args, CopyExpression(object));
12160 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12161 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12162 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12165 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
12170 FreeExpression(object);
12172 FreeExpression(watcher);
12173 FreeList(watches, FreeIdentifier);
12176 Compiler_Error($"Invalid object specified and not inside a class\n");
12179 Compiler_Error($"No observer specified and not inside a class\n");
12186 static void ProcessFunction(FunctionDefinition function)
12188 Identifier id = GetDeclId(function.declarator);
12189 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12190 Type type = symbol ? symbol.type : null;
12191 Class oldThisClass = thisClass;
12192 Context oldTopContext = topContext;
12194 yylloc = function.loc;
12195 // Process thisClass
12197 if(type && type.thisClass)
12199 Symbol classSym = type.thisClass;
12200 Class _class = type.thisClass.registered;
12201 char className[1024];
12202 char structName[1024];
12203 Declarator funcDecl;
12206 bool typedObject = false;
12208 if(_class && !_class.base)
12210 _class = currentClass;
12211 if(_class && !_class.symbol)
12212 _class.symbol = FindClass(_class.fullName);
12213 classSym = _class ? _class.symbol : null;
12214 typedObject = true;
12217 thisClass = _class;
12219 if(inCompiler && _class)
12221 if(type.kind == functionType)
12223 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12225 //TypeName param = symbol.type.params.first;
12226 Type param = symbol.type.params.first;
12227 symbol.type.params.Remove(param);
12228 //FreeTypeName(param);
12231 if(type.classObjectType != classPointer)
12233 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12234 symbol.type.staticMethod = true;
12235 symbol.type.thisClass = null;
12237 // HIGH DANGER: VERIFYING THIS...
12238 symbol.type.extraParam = false;
12242 strcpy(className, "__ecereClass_");
12243 FullClassNameCat(className, _class.fullName, true);
12245 MangleClassName(className);
12248 FullClassNameCat(structName, _class.fullName, false);
12253 funcDecl = GetFuncDecl(function.declarator);
12256 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12258 TypeName param = funcDecl.function.parameters->first;
12259 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12261 funcDecl.function.parameters->Remove(param);
12262 FreeTypeName(param);
12266 // DANGER: Watch for this... Check if it's a Conversion?
12267 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12269 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12270 if(!function.propertyNoThis)
12272 TypeName thisParam;
12274 if(type.classObjectType != classPointer)
12276 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12277 if(!funcDecl.function.parameters)
12278 funcDecl.function.parameters = MkList();
12279 funcDecl.function.parameters->Insert(null, thisParam);
12284 if(type.classObjectType != classPointer)
12286 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12287 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12290 thisParam = TypeName
12292 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12293 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12295 funcDecl.function.parameters->Insert(null, thisParam);
12300 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12302 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12303 funcDecl = GetFuncDecl(initDecl.declarator);
12306 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12308 TypeName param = funcDecl.function.parameters->first;
12309 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12311 funcDecl.function.parameters->Remove(param);
12312 FreeTypeName(param);
12316 if(type.classObjectType != classPointer)
12318 // DANGER: Watch for this... Check if it's a Conversion?
12319 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12321 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12323 if(!funcDecl.function.parameters)
12324 funcDecl.function.parameters = MkList();
12325 funcDecl.function.parameters->Insert(null, thisParam);
12332 // Add this to the context
12335 if(type.classObjectType != classPointer)
12337 thisSymbol = Symbol
12339 string = CopyString("this");
12340 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12342 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12344 if(typedObject && thisSymbol.type)
12346 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12347 thisSymbol.type.byReference = type.byReference;
12348 thisSymbol.type.typedByReference = type.byReference;
12350 thisSymbol = Symbol { string = CopyString("class") };
12351 function.body.compound.context.symbols.Add(thisSymbol);
12357 // Pointer to class data
12359 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12361 DataMember member = null;
12364 for(base = _class; base && base.type != systemClass; base = base.next)
12366 for(member = base.membersAndProperties.first; member; member = member.next)
12367 if(!member.isProperty)
12373 for(member = _class.membersAndProperties.first; member; member = member.next)
12374 if(!member.isProperty)
12378 char pointerName[1024];
12381 Initializer initializer;
12382 Expression exp, bytePtr;
12384 strcpy(pointerName, "__ecerePointer_");
12385 FullClassNameCat(pointerName, _class.fullName, false);
12387 char className[1024];
12388 strcpy(className, "__ecereClass_");
12389 FullClassNameCat(className, classSym.string, true);
12390 MangleClassName(className);
12393 DeclareClass(classSym, className);
12397 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12402 sprintf(string, "%d", _class.offset);
12403 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12407 // ([bytePtr] + [className]->offset)
12408 exp = QBrackets(MkExpOp(bytePtr, '+',
12409 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12412 // (this ? [exp] : 0)
12413 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12417 kind = pointerType;
12418 type = Type { refCount = 1, kind = voidType };
12423 yylloc = function.body.loc;
12424 // ([structName] *) [exp]
12425 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12426 initializer = MkInitializerAssignment(
12427 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12429 // [structName] * [pointerName] = [initializer];
12430 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12433 Context prevContext = curContext;
12434 curContext = function.body.compound.context;
12436 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12437 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12439 curContext = prevContext;
12443 decl.symbol = null;
12445 if(!function.body.compound.declarations)
12446 function.body.compound.declarations = MkList();
12447 function.body.compound.declarations->Insert(null, decl);
12453 // Loop through the function and replace undeclared identifiers
12454 // which are a member of the class (methods, properties or data)
12455 // by "this.[member]"
12462 FreeSpecifier(id._class);
12465 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12467 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12468 id = GetDeclId(initDecl.declarator);
12470 FreeSpecifier(id._class);
12475 topContext = function.body.compound.context;
12477 FunctionDefinition oldFunction = curFunction;
12478 curFunction = function;
12480 ProcessStatement(function.body);
12482 // If this is a property set and no firewatchers has been done yet, add one here
12483 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12485 Statement prevCompound = curCompound;
12486 Context prevContext = curContext;
12488 Statement fireWatchers = MkFireWatchersStmt(null, null);
12489 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12490 ListAdd(function.body.compound.statements, fireWatchers);
12492 curCompound = function.body;
12493 curContext = function.body.compound.context;
12495 ProcessStatement(fireWatchers);
12497 curContext = prevContext;
12498 curCompound = prevCompound;
12502 curFunction = oldFunction;
12505 if(function.declarator)
12507 ProcessDeclarator(function.declarator);
12510 topContext = oldTopContext;
12511 thisClass = oldThisClass;
12514 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12515 static void ProcessClass(OldList definitions, Symbol symbol)
12518 External external = curExternal;
12519 Class regClass = symbol ? symbol.registered : null;
12521 // Process all functions
12522 for(def = definitions.first; def; def = def.next)
12524 if(def.type == functionClassDef)
12526 if(def.function.declarator)
12527 curExternal = def.function.declarator.symbol.pointerExternal;
12529 curExternal = external;
12531 ProcessFunction((FunctionDefinition)def.function);
12533 else if(def.type == declarationClassDef)
12535 if(def.decl.type == instDeclaration)
12537 thisClass = regClass;
12538 ProcessInstantiationType(def.decl.inst);
12544 Class backThisClass = thisClass;
12545 if(regClass) thisClass = regClass;
12546 ProcessDeclaration(def.decl);
12547 thisClass = backThisClass;
12550 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12552 MemberInit defProperty;
12554 // Add this to the context
12555 Symbol thisSymbol = Symbol
12557 string = CopyString("this");
12558 type = regClass ? MkClassType(regClass.fullName) : null;
12560 globalContext.symbols.Add((BTNode)thisSymbol);
12562 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12564 thisClass = regClass;
12565 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12569 globalContext.symbols.Remove((BTNode)thisSymbol);
12570 FreeSymbol(thisSymbol);
12572 else if(def.type == propertyClassDef && def.propertyDef)
12574 PropertyDef prop = def.propertyDef;
12576 // Add this to the context
12578 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12579 globalContext.symbols.Add(thisSymbol);
12582 thisClass = regClass;
12589 string = CopyString("this");
12590 type = MkClassType(regClass.fullName);
12592 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12595 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12596 ProcessStatement(prop.setStmt);
12604 string = CopyString("this");
12605 type = MkClassType(regClass.fullName);
12607 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12610 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12611 ProcessStatement(prop.getStmt);
12619 string = CopyString("this");
12620 type = MkClassType(regClass.fullName);
12622 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12625 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12626 ProcessStatement(prop.issetStmt);
12632 globalContext.symbols.Remove(thisSymbol);
12633 FreeSymbol(thisSymbol);
12636 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12638 PropertyWatch propertyWatch = def.propertyWatch;
12640 thisClass = regClass;
12641 if(propertyWatch.compound)
12645 string = CopyString("this");
12646 type = regClass ? MkClassType(regClass.fullName) : null;
12649 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12651 curExternal = null;
12652 ProcessStatement(propertyWatch.compound);
12659 void DeclareFunctionUtil(String s)
12661 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12666 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12667 strcpy(name, "__ecereFunction_");
12668 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12669 DeclareFunction(function, name);
12673 void ComputeDataTypes()
12677 External after = null;
12679 currentClass = null;
12681 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12683 for(external = ast->first; external; external = external.next)
12685 if(external.type == declarationExternal)
12687 Declaration decl = external.declaration;
12690 OldList * decls = decl.declarators;
12693 InitDeclarator initDecl = decls->first;
12696 Declarator declarator = initDecl.declarator;
12697 if(declarator && declarator.type == identifierDeclarator)
12699 Identifier id = declarator.identifier;
12700 if(id && id.string)
12702 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12704 external.symbol.id = -1001, external.symbol.idCode = -1001;
12715 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12716 ast->Insert(after, temp);
12717 curExternal = temp;
12719 DeclareFunctionUtil("eSystem_New");
12720 DeclareFunctionUtil("eSystem_New0");
12721 DeclareFunctionUtil("eSystem_Renew");
12722 DeclareFunctionUtil("eSystem_Renew0");
12723 DeclareFunctionUtil("eSystem_Delete");
12724 DeclareFunctionUtil("eClass_GetProperty");
12725 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12727 DeclareStruct("ecere::com::Class", false);
12728 DeclareStruct("ecere::com::Instance", false);
12729 DeclareStruct("ecere::com::Property", false);
12730 DeclareStruct("ecere::com::DataMember", false);
12731 DeclareStruct("ecere::com::Method", false);
12732 DeclareStruct("ecere::com::SerialBuffer", false);
12733 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12737 for(external = ast->first; external; external = external.next)
12739 afterExternal = curExternal = external;
12740 if(external.type == functionExternal)
12742 currentClass = external.function._class;
12743 ProcessFunction(external.function);
12745 // There shouldn't be any _class member access here anyways...
12746 else if(external.type == declarationExternal)
12748 currentClass = null;
12749 ProcessDeclaration(external.declaration);
12751 else if(external.type == classExternal)
12753 ClassDefinition _class = external._class;
12754 currentClass = external.symbol.registered;
12755 if(_class.definitions)
12757 ProcessClass(_class.definitions, _class.symbol);
12761 // Free class data...
12762 ast->Remove(external);
12766 else if(external.type == nameSpaceExternal)
12768 thisNameSpace = external.id.string;
12771 currentClass = null;
12772 thisNameSpace = null;
12774 delete temp.symbol;