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_DIVIDE(o, name, m, t, p) \
4021 static bool name(Expression exp, Operand op1, Operand op2) \
4024 exp.type = constantExp; \
4025 exp.string = p(value2 ? (op1.m o value2) : 0); \
4027 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4031 #define UNARY(o, name, m, t, p) \
4032 static bool name(Expression exp, Operand op1) \
4034 exp.type = constantExp; \
4035 exp.string = p((t)(o op1.m)); \
4037 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4041 #define OPERATOR_ALL(macro, o, name) \
4042 macro(o, Int##name, i, int, PrintInt) \
4043 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4044 macro(o, Int64##name, i64, int64, PrintInt64) \
4045 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4046 macro(o, Short##name, s, short, PrintShort) \
4047 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4048 macro(o, Char##name, c, char, PrintChar) \
4049 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4050 macro(o, Float##name, f, float, PrintFloat) \
4051 macro(o, Double##name, d, double, PrintDouble)
4053 #define OPERATOR_INTTYPES(macro, o, name) \
4054 macro(o, Int##name, i, int, PrintInt) \
4055 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4056 macro(o, Int64##name, i64, int64, PrintInt64) \
4057 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4058 macro(o, Short##name, s, short, PrintShort) \
4059 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4060 macro(o, Char##name, c, char, PrintChar) \
4061 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4064 // binary arithmetic
4065 OPERATOR_ALL(BINARY, +, Add)
4066 OPERATOR_ALL(BINARY, -, Sub)
4067 OPERATOR_ALL(BINARY, *, Mul)
4068 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4069 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4072 OPERATOR_ALL(UNARY, -, Neg)
4074 // unary arithmetic increment and decrement
4075 OPERATOR_ALL(UNARY, ++, Inc)
4076 OPERATOR_ALL(UNARY, --, Dec)
4078 // binary arithmetic assignment
4079 OPERATOR_ALL(BINARY, =, Asign)
4080 OPERATOR_ALL(BINARY, +=, AddAsign)
4081 OPERATOR_ALL(BINARY, -=, SubAsign)
4082 OPERATOR_ALL(BINARY, *=, MulAsign)
4083 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4084 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4087 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4088 OPERATOR_INTTYPES(BINARY, |, BitOr)
4089 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4090 OPERATOR_INTTYPES(BINARY, <<, LShift)
4091 OPERATOR_INTTYPES(BINARY, >>, RShift)
4094 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4096 // binary bitwise assignment
4097 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4098 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4099 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4100 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4101 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4103 // unary logical negation
4104 OPERATOR_INTTYPES(UNARY, !, Not)
4106 // binary logical equality
4107 OPERATOR_ALL(BINARY, ==, Equ)
4108 OPERATOR_ALL(BINARY, !=, Nqu)
4111 OPERATOR_ALL(BINARY, &&, And)
4112 OPERATOR_ALL(BINARY, ||, Or)
4114 // binary logical relational
4115 OPERATOR_ALL(BINARY, >, Grt)
4116 OPERATOR_ALL(BINARY, <, Sma)
4117 OPERATOR_ALL(BINARY, >=, GrtEqu)
4118 OPERATOR_ALL(BINARY, <=, SmaEqu)
4120 // tertiary condition operator
4121 OPERATOR_ALL(TERTIARY, ?, Cond)
4123 //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
4124 #define OPERATOR_TABLE_ALL(name, type) \
4125 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4127 type##Inc, type##Dec, \
4128 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4129 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4131 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4133 type##Equ, type##Nqu, \
4134 type##And, type##Or, \
4135 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4138 #define OPERATOR_TABLE_INTTYPES(name, type) \
4139 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4141 type##Inc, type##Dec, \
4142 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4143 null, null, null, null, null, \
4145 null, null, null, null, null, \
4147 type##Equ, type##Nqu, \
4148 type##And, type##Or, \
4149 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4152 OPERATOR_TABLE_ALL(int, Int)
4153 OPERATOR_TABLE_ALL(uint, UInt)
4154 OPERATOR_TABLE_ALL(int64, Int64)
4155 OPERATOR_TABLE_ALL(uint64, UInt64)
4156 OPERATOR_TABLE_ALL(short, Short)
4157 OPERATOR_TABLE_ALL(ushort, UShort)
4158 OPERATOR_TABLE_INTTYPES(float, Float)
4159 OPERATOR_TABLE_INTTYPES(double, Double)
4160 OPERATOR_TABLE_ALL(char, Char)
4161 OPERATOR_TABLE_ALL(uchar, UChar)
4163 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4164 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4165 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4166 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4167 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4168 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4169 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4170 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4172 public void ReadString(char * output, char * string)
4174 int len = strlen(string);
4176 bool quoted = false, escaped = false;
4177 for(c = 0; c<len; c++)
4179 char ch = string[c];
4184 case 'n': output[d] = '\n'; break;
4185 case 't': output[d] = '\t'; break;
4186 case 'a': output[d] = '\a'; break;
4187 case 'b': output[d] = '\b'; break;
4188 case 'f': output[d] = '\f'; break;
4189 case 'r': output[d] = '\r'; break;
4190 case 'v': output[d] = '\v'; break;
4191 case '\\': output[d] = '\\'; break;
4192 case '\"': output[d] = '\"'; break;
4193 case '\'': output[d] = '\''; break;
4194 default: output[d] = ch;
4215 // String Unescape Copy
4217 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4218 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4219 public int UnescapeString(char * d, char * s, int len)
4223 while(j < len && (ch = s[j]))
4228 switch((ch = s[++j]))
4230 case 'n': d[k] = '\n'; break;
4231 case 't': d[k] = '\t'; break;
4232 case 'a': d[k] = '\a'; break;
4233 case 'b': d[k] = '\b'; break;
4234 case 'f': d[k] = '\f'; break;
4235 case 'r': d[k] = '\r'; break;
4236 case 'v': d[k] = '\v'; break;
4237 case '\\': d[k] = '\\'; break;
4238 case '\"': d[k] = '\"'; break;
4239 case '\'': d[k] = '\''; break;
4240 default: d[k] = '\\'; d[k] = ch;
4252 public char * OffsetEscapedString(char * s, int len, int offset)
4256 while(j < len && k < offset && (ch = s[j]))
4261 return (k == offset) ? s + j : null;
4264 public Operand GetOperand(Expression exp)
4267 Type type = exp.expType;
4270 while(type.kind == classType &&
4271 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4273 if(!type._class.registered.dataType)
4274 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4275 type = type._class.registered.dataType;
4278 if(exp.type == stringExp && op.kind == pointerType)
4280 op.ui64 = (uint64)exp.string;
4281 op.kind = pointerType;
4284 else if(exp.isConstant && exp.type == constantExp)
4286 op.kind = type.kind;
4287 op.type = exp.expType;
4294 if(exp.constant[0] == '\'')
4296 op.c = exp.constant[1];
4299 else if(type.isSigned)
4301 op.c = (char)strtol(exp.constant, null, 0);
4306 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4314 op.s = (short)strtol(exp.constant, null, 0);
4319 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4327 op.i = (int)strtol(exp.constant, null, 0);
4332 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4340 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4345 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4348 op.kind = int64Type;
4353 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4358 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4361 op.kind = int64Type;
4366 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4371 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4374 op.kind = int64Type;
4377 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4378 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4379 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4380 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4382 op.f = (float)strtod(exp.constant, null);
4386 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4387 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4388 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4389 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4391 op.d = (double)strtod(exp.constant, null);
4394 //case classType: For when we have operator overloading...
4395 // Pointer additions
4396 //case functionType:
4400 op.ui64 = _strtoui64(exp.constant, null, 0);
4401 op.kind = pointerType;
4411 static void UnusedFunction()
4414 a.OnGetString(0,0,0);
4417 extern int __ecereVMethodID_class_OnGetString;
4420 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4422 DataMember dataMember;
4423 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4425 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4426 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4430 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4432 void * ptr = inst.data + dataMember.offset + offset;
4433 char * result = null;
4434 exp.loc = member.loc = inst.loc;
4435 ((Identifier)member.identifiers->first).loc = inst.loc;
4437 if(!dataMember.dataType)
4438 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4439 type = dataMember.dataType;
4440 if(type.kind == classType)
4442 Class _class = type._class.registered;
4443 if(_class.type == enumClass)
4445 Class enumClass = eSystem_FindClass(privateModule, "enum");
4448 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4450 for(item = e.values.first; item; item = item.next)
4452 if((int)item.data == *(int *)ptr)
4460 exp.identifier = MkIdentifier(result);
4461 exp.type = identifierExp;
4462 exp.destType = MkClassType(_class.fullName);
4463 ProcessExpressionType(exp);
4467 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4469 if(!_class.dataType)
4470 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4471 type = _class.dataType;
4480 FreeExpContents(exp);
4482 exp.constant = PrintFloat(*(float*)ptr);
4483 exp.type = constantExp;
4488 FreeExpContents(exp);
4490 exp.constant = PrintDouble(*(double*)ptr);
4491 exp.type = constantExp;
4496 FreeExpContents(exp);
4498 exp.constant = PrintInt(*(int*)ptr);
4499 exp.type = constantExp;
4504 FreeExpContents(exp);
4506 exp.constant = PrintInt64(*(int64*)ptr);
4507 exp.type = constantExp;
4512 FreeExpContents(exp);
4513 // TODO: This should probably use proper type
4514 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4515 exp.type = constantExp;
4520 FreeExpContents(exp);
4521 // TODO: This should probably use proper type
4522 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4523 exp.type = constantExp;
4527 Compiler_Error($"Unhandled type populating instance\n");
4530 ListAdd(memberList, member);
4533 if(parentDataMember.type == unionMember)
4538 void PopulateInstance(Instantiation inst)
4540 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4541 Class _class = classSym.registered;
4542 DataMember dataMember;
4543 OldList * memberList = MkList();
4544 // Added this check and ->Add to prevent memory leaks on bad code
4546 inst.members = MkListOne(MkMembersInitList(memberList));
4548 inst.members->Add(MkMembersInitList(memberList));
4549 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4551 if(!dataMember.isProperty)
4553 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4554 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4558 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4560 void * ptr = inst.data + dataMember.offset;
4561 char * result = null;
4563 exp.loc = member.loc = inst.loc;
4564 ((Identifier)member.identifiers->first).loc = inst.loc;
4566 if(!dataMember.dataType)
4567 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4568 type = dataMember.dataType;
4569 if(type.kind == classType)
4571 Class _class = type._class.registered;
4572 if(_class.type == enumClass)
4574 Class enumClass = eSystem_FindClass(privateModule, "enum");
4577 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4579 for(item = e.values.first; item; item = item.next)
4581 if((int)item.data == *(int *)ptr)
4590 exp.identifier = MkIdentifier(result);
4591 exp.type = identifierExp;
4592 exp.destType = MkClassType(_class.fullName);
4593 ProcessExpressionType(exp);
4596 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4598 if(!_class.dataType)
4599 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4600 type = _class.dataType;
4609 exp.constant = PrintFloat(*(float*)ptr);
4610 exp.type = constantExp;
4615 exp.constant = PrintDouble(*(double*)ptr);
4616 exp.type = constantExp;
4621 exp.constant = PrintInt(*(int*)ptr);
4622 exp.type = constantExp;
4627 exp.constant = PrintInt64(*(int64*)ptr);
4628 exp.type = constantExp;
4633 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4634 exp.type = constantExp;
4638 Compiler_Error($"Unhandled type populating instance\n");
4641 ListAdd(memberList, member);
4647 void ComputeInstantiation(Expression exp)
4649 Instantiation inst = exp.instance;
4650 MembersInit members;
4651 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4652 Class _class = classSym ? classSym.registered : null;
4653 DataMember curMember = null;
4654 Class curClass = null;
4655 DataMember subMemberStack[256];
4656 int subMemberStackPos = 0;
4659 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4661 // Don't recompute the instantiation...
4662 // Non Simple classes will have become constants by now
4666 if(_class.type == normalClass || _class.type == noHeadClass)
4668 inst.data = (byte *)eInstance_New(_class);
4669 if(_class.type == normalClass)
4670 ((Instance)inst.data)._refCount++;
4673 inst.data = new0 byte[_class.structSize];
4678 for(members = inst.members->first; members; members = members.next)
4680 switch(members.type)
4682 case dataMembersInit:
4684 if(members.dataMembers)
4687 for(member = members.dataMembers->first; member; member = member.next)
4689 Identifier ident = member.identifiers ? member.identifiers->first : null;
4692 Property prop = null;
4693 DataMember dataMember = null;
4694 Method method = null;
4695 uint dataMemberOffset;
4699 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4702 if(curMember.isProperty)
4703 prop = (Property)curMember;
4706 dataMember = curMember;
4708 // CHANGED THIS HERE
4709 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4711 // 2013/17/29 -- It seems that this was missing here!
4712 if(_class.type == normalClass)
4713 dataMemberOffset += _class.base.structSize;
4714 // dataMemberOffset = dataMember.offset;
4721 prop = eClass_FindProperty(_class, ident.string, privateModule);
4725 if(prop.memberAccess == publicAccess)
4727 curMember = (DataMember)prop;
4728 curClass = prop._class;
4733 DataMember _subMemberStack[256];
4734 int _subMemberStackPos = 0;
4736 // FILL MEMBER STACK
4737 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4742 if(dataMember.memberAccess == publicAccess)
4744 curMember = dataMember;
4745 curClass = dataMember._class;
4746 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4747 subMemberStackPos = _subMemberStackPos;
4753 if(found && member.initializer && member.initializer.type == expInitializer)
4755 Expression value = member.initializer.exp;
4757 bool deepMember = false;
4760 type = prop.dataType;
4764 if(!dataMember.dataType)
4765 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4767 type = dataMember.dataType;
4770 if(ident && ident.next)
4774 // for(; ident && type; ident = ident.next)
4775 for(ident = ident.next; ident && type; ident = ident.next)
4777 if(type.kind == classType)
4779 prop = eClass_FindProperty(type._class.registered,
4780 ident.string, privateModule);
4782 type = prop.dataType;
4785 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4786 ident.string, &dataMemberOffset, privateModule, null, null);
4788 type = dataMember.dataType;
4791 else if(type.kind == structType || type.kind == unionType)
4794 for(memberType = type.members.first; memberType; memberType = memberType.next)
4796 if(!strcmp(memberType.name, ident.string))
4807 FreeType(value.destType);
4808 value.destType = type;
4809 if(type) type.refCount++;
4810 ComputeExpression(value);
4812 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4814 if(type.kind == classType)
4816 Class _class = type._class.registered;
4817 if(_class.type == bitClass || _class.type == unitClass ||
4818 _class.type == enumClass)
4820 if(!_class.dataType)
4821 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4822 type = _class.dataType;
4828 void * ptr = inst.data + dataMemberOffset;
4830 if(value.type == constantExp)
4836 GetInt(value, (int*)ptr);
4841 GetInt64(value, (int64*)ptr);
4846 GetIntPtr(value, (intptr*)ptr);
4851 GetIntSize(value, (intsize*)ptr);
4856 GetFloat(value, (float*)ptr);
4861 GetDouble(value, (double *)ptr);
4866 else if(value.type == instanceExp)
4868 if(type.kind == classType)
4870 Class _class = type._class.registered;
4871 if(_class.type == structClass)
4873 ComputeTypeSize(type);
4874 if(value.instance.data)
4875 memcpy(ptr, value.instance.data, type.size);
4882 if(value.type == instanceExp && value.instance.data)
4884 if(type.kind == classType)
4886 Class _class = type._class.registered;
4887 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4889 void (*Set)(void *, void *) = (void *)prop.Set;
4890 Set(inst.data, value.instance.data);
4891 PopulateInstance(inst);
4895 else if(value.type == constantExp)
4901 void (*Set)(void *, double) = (void *)prop.Set;
4902 Set(inst.data, strtod(value.constant, null) );
4907 void (*Set)(void *, float) = (void *)prop.Set;
4908 Set(inst.data, (float)(strtod(value.constant, null)));
4913 void (*Set)(void *, int) = (void *)prop.Set;
4914 Set(inst.data, (int)strtol(value.constant, null, 0));
4919 void (*Set)(void *, int64) = (void *)prop.Set;
4920 Set(inst.data, _strtoi64(value.constant, null, 0));
4925 void (*Set)(void *, intptr) = (void *)prop.Set;
4926 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4931 void (*Set)(void *, intsize) = (void *)prop.Set;
4932 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4937 else if(value.type == stringExp)
4940 ReadString(temp, value.string);
4941 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4945 else if(!deepMember && type && _class.type == unitClass)
4949 // Only support converting units to units for now...
4950 if(value.type == constantExp)
4952 if(type.kind == classType)
4954 Class _class = type._class.registered;
4955 if(_class.type == unitClass)
4957 if(!_class.dataType)
4958 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4959 type = _class.dataType;
4962 // TODO: Assuming same base type for units...
4968 float (*Set)(float) = (void *)prop.Set;
4969 GetFloat(member.initializer.exp, &fValue);
4970 exp.constant = PrintFloat(Set(fValue));
4971 exp.type = constantExp;
4977 double (*Set)(double) = (void *)prop.Set;
4978 GetDouble(member.initializer.exp, &dValue);
4979 exp.constant = PrintDouble(Set(dValue));
4980 exp.type = constantExp;
4987 else if(!deepMember && type && _class.type == bitClass)
4991 if(value.type == instanceExp && value.instance.data)
4993 unsigned int (*Set)(void *) = (void *)prop.Set;
4994 bits = Set(value.instance.data);
4996 else if(value.type == constantExp)
5002 BitMember bitMember = (BitMember) dataMember;
5005 GetInt(value, &part);
5006 bits = (bits & ~bitMember.mask);
5007 if(!bitMember.dataType)
5008 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5010 type = bitMember.dataType;
5012 if(type.kind == classType && type._class && type._class.registered)
5014 if(!type._class.registered.dataType)
5015 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5016 type = type._class.registered.dataType;
5024 bits |= ((char)part << bitMember.pos);
5026 bits |= ((unsigned char)part << bitMember.pos);
5030 bits |= ((short)part << bitMember.pos);
5032 bits |= ((unsigned short)part << bitMember.pos);
5037 bits |= ((int)part << bitMember.pos);
5039 bits |= ((unsigned int)part << bitMember.pos);
5043 bits |= ((int64)part << bitMember.pos);
5045 bits |= ((uint64)part << bitMember.pos);
5050 bits |= ((intptr)part << bitMember.pos);
5054 bits |= ((uintptr)part << bitMember.pos);
5060 bits |= ((ssize_t)(intsize)part << bitMember.pos);
5064 bits |= ((size_t) (uintsize)part << bitMember.pos);
5073 if(_class && _class.type == unitClass)
5075 ComputeExpression(member.initializer.exp);
5076 exp.constant = member.initializer.exp.constant;
5077 exp.type = constantExp;
5079 member.initializer.exp.constant = null;
5089 if(_class && _class.type == bitClass)
5091 exp.constant = PrintHexUInt(bits);
5092 exp.type = constantExp;
5094 if(exp.type != instanceExp)
5100 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5102 bool result = false;
5106 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5107 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5111 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5112 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5115 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5116 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5117 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5120 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5121 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5122 result = GetOpFloat(op, &op.f);
5125 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5126 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5127 result = GetOpDouble(op, &op.d);
5130 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5131 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5132 result = GetOpUIntPtr(op, &op.ui64);
5135 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5136 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5137 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5140 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5141 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5144 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5145 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5151 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5153 if(exp.op.op == SIZEOF)
5155 FreeExpContents(exp);
5156 exp.type = constantExp;
5157 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5168 // Provide default unary +
5169 Expression exp2 = exp.op.exp2;
5171 FreeExpContents(exp);
5172 FreeType(exp.expType);
5173 FreeType(exp.destType);
5179 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5181 // unary arithmetic increment and decrement
5182 //OPERATOR_ALL(UNARY, ++, Inc)
5183 //OPERATOR_ALL(UNARY, --, Dec)
5186 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5188 // unary logical negation
5190 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5196 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5198 if(Promote(op2, op1.kind, op1.type.isSigned))
5199 op2.kind = op1.kind, op2.ops = op1.ops;
5200 else if(Promote(op1, op2.kind, op2.type.isSigned))
5201 op1.kind = op2.kind, op1.ops = op2.ops;
5205 // binary arithmetic
5207 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5210 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5213 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5216 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5219 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5221 // binary arithmetic assignment
5222 //OPERATOR_ALL(BINARY, =, Asign)
5223 //OPERATOR_ALL(BINARY, +=, AddAsign)
5224 //OPERATOR_ALL(BINARY, -=, SubAsign)
5225 //OPERATOR_ALL(BINARY, *=, MulAsign)
5226 //OPERATOR_ALL(BINARY, /=, DivAsign)
5227 //OPERATOR_ALL(BINARY, %=, ModAsign)
5232 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5236 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5239 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5242 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5245 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5247 // binary bitwise assignment
5248 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5249 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5250 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5251 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5252 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5253 // binary logical equality
5255 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5258 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5262 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5265 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5267 // binary logical relational
5269 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5272 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5275 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5278 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5285 void ComputeExpression(Expression exp)
5287 char expString[10240];
5288 expString[0] = '\0';
5290 PrintExpression(exp, expString);
5297 ComputeInstantiation(exp);
5306 Expression exp1, exp2 = null;
5310 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5313 Expression e = exp.op.exp2;
5315 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5317 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5319 if(e.type == extensionCompoundExp)
5320 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5325 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5327 if(e.type == stringExp && e.string)
5329 char * string = e.string;
5330 int len = strlen(string);
5331 char * tmp = new char[len-2+1];
5332 len = UnescapeString(tmp, string + 1, len - 2);
5334 FreeExpContents(exp);
5335 exp.type = constantExp;
5336 exp.constant = PrintUInt(len + 1);
5340 Type type = e.expType;
5342 FreeExpContents(exp);
5343 exp.type = constantExp;
5344 exp.constant = PrintUInt(ComputeTypeSize(type));
5350 ComputeExpression(exp.op.exp2);
5354 ComputeExpression(exp.op.exp1);
5357 op1 = GetOperand(exp1);
5358 if(op1.type) op1.type.refCount++;
5361 op2 = GetOperand(exp2);
5362 if(op2.type) op2.type.refCount++;
5368 op1 = GetOperand(exp1);
5369 if(op1.type) op1.type.refCount++;
5372 CallOperator(exp, exp1, exp2, op1, op2);
5379 if(exp.op.exp1 && exp.op.exp2)
5384 FreeExpContents(exp);
5385 op1.ops.BitAnd(exp, op1, op2);
5394 FreeExpContents(exp);
5395 op1.ops.Mul(exp, op1, op2);
5404 FreeExpContents(exp);
5405 op1.ops.Add(exp, op1, op2);
5410 // Provide default unary +
5411 Expression exp2 = exp.op.exp2;
5413 FreeExpContents(exp);
5414 FreeType(exp.expType);
5415 FreeType(exp.destType);
5426 FreeExpContents(exp);
5427 op1.ops.Sub(exp, op1, op2);
5434 FreeExpContents(exp);
5435 op1.ops.Neg(exp, op1);
5442 FreeExpContents(exp);
5443 op1.ops.BitNot(exp, op1);
5449 FreeExpContents(exp);
5450 op1.ops.Not(exp, op1);
5453 // Binary only operators
5457 FreeExpContents(exp);
5458 op1.ops.Div(exp, op1, op2);
5464 FreeExpContents(exp);
5465 op1.ops.Mod(exp, op1, op2);
5477 FreeExpContents(exp);
5478 op1.ops.Sma(exp, op1, op2);
5487 FreeExpContents(exp);
5488 op1.ops.Grt(exp, op1, op2);
5497 FreeExpContents(exp);
5498 op1.ops.SmaEqu(exp, op1, op2);
5507 FreeExpContents(exp);
5508 op1.ops.GrtEqu(exp, op1, op2);
5517 FreeExpContents(exp);
5518 op1.ops.Equ(exp, op1, op2);
5527 FreeExpContents(exp);
5528 op1.ops.Nqu(exp, op1, op2);
5535 FreeExpContents(exp);
5536 op1.ops.BitOr(exp, op1, op2);
5542 FreeExpContents(exp);
5543 op1.ops.BitXor(exp, op1, op2);
5551 FreeExpContents(exp);
5552 exp.type = constantExp;
5553 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5557 if(op1.type) FreeType(op1.type);
5558 if(op2.type) FreeType(op2.type);
5562 case extensionExpressionExp:
5565 for(e = exp.list->first; e; e = n)
5570 OldList * list = exp.list;
5571 ComputeExpression(e);
5572 //FreeExpContents(exp);
5573 FreeType(exp.expType);
5574 FreeType(exp.destType);
5591 exp.isConstant = true;
5593 ComputeExpression(exp.index.exp);
5594 if(!exp.index.exp.isConstant)
5595 exp.isConstant = false;
5597 for(e = exp.index.index->first; e; e = e.next)
5599 ComputeExpression(e);
5602 // Check if this type is int
5605 exp.isConstant = false;
5607 exp.expType = Dereference(exp.index.exp.expType);
5613 Expression memberExp = exp.member.exp;
5614 Identifier memberID = exp.member.member;
5617 ComputeExpression(exp.member.exp);
5618 type = exp.member.exp.expType;
5621 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);
5622 Property prop = null;
5623 DataMember member = null;
5624 Class convertTo = null;
5625 if(type.kind == subClassType && exp.member.exp.type == classExp)
5626 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5633 PrintTypeNoConst(type, string, false, true);
5634 classSym = FindClass(string);
5635 _class = classSym ? classSym.registered : null;
5638 if(exp.member.member)
5640 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5642 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5644 if(!prop && !member && _class && exp.member.member)
5646 Symbol classSym = FindClass(exp.member.member.string);
5648 _class = classSym ? classSym.registered : null;
5649 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5656 Type type = prop.dataType;
5657 // TODO: Assuming same base type for units...
5658 if(_class.type == unitClass)
5660 if(type.kind == classType)
5662 Class _class = type._class.registered;
5663 if(_class.type == unitClass)
5665 if(!_class.dataType)
5666 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5667 type = _class.dataType;
5675 float (*Get)(float) = (void *)prop.Get;
5676 GetFloat(exp.member.exp, &value);
5677 exp.constant = PrintFloat(Get ? Get(value) : value);
5678 exp.type = constantExp;
5684 double (*Get)(double);
5685 GetDouble(exp.member.exp, &value);
5688 Get = (void *)prop.Set;
5690 Get = (void *)prop.Get;
5691 exp.constant = PrintDouble(Get ? Get(value) : value);
5692 exp.type = constantExp;
5701 Expression value = exp.member.exp;
5704 ProcessPropertyType(prop);
5706 type = prop.dataType;
5709 // printf("Investigate this\n");
5711 else if(_class.type == structClass)
5717 Class propertyClass = type._class.registered;
5718 if(propertyClass.type == structClass && value.type == instanceExp)
5720 void (*Set)(void *, void *) = (void *)prop.Set;
5721 exp.instance = Instantiation { };
5722 exp.instance.data = new0 byte[_class.structSize];
5723 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5724 exp.instance.loc = exp.loc;
5725 exp.type = instanceExp;
5726 Set(exp.instance.data, value.instance.data);
5727 PopulateInstance(exp.instance);
5734 void (*Set)(void *, int) = (void *)prop.Set;
5736 exp.instance = Instantiation { };
5737 exp.instance.data = new0 byte[_class.structSize];
5738 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5739 exp.instance.loc = exp.loc;
5740 exp.type = instanceExp;
5742 GetInt(value, &intValue);
5744 Set(exp.instance.data, intValue);
5745 PopulateInstance(exp.instance);
5751 void (*Set)(void *, int64) = (void *)prop.Set;
5753 exp.instance = Instantiation { };
5754 exp.instance.data = new0 byte[_class.structSize];
5755 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5756 exp.instance.loc = exp.loc;
5757 exp.type = instanceExp;
5759 GetInt64(value, &intValue);
5761 Set(exp.instance.data, intValue);
5762 PopulateInstance(exp.instance);
5769 void (*Set)(void *, intptr) = (void *)prop.Set;
5771 exp.instance = Instantiation { };
5772 exp.instance.data = new0 byte[_class.structSize];
5773 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5774 exp.instance.loc = exp.loc;
5775 exp.type = instanceExp;
5777 GetIntPtr(value, &intValue);
5779 Set(exp.instance.data, intValue);
5780 PopulateInstance(exp.instance);
5787 void (*Set)(void *, intsize) = (void *)prop.Set;
5789 exp.instance = Instantiation { };
5790 exp.instance.data = new0 byte[_class.structSize];
5791 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5792 exp.instance.loc = exp.loc;
5793 exp.type = instanceExp;
5795 GetIntSize(value, &intValue);
5797 Set(exp.instance.data, intValue);
5798 PopulateInstance(exp.instance);
5804 void (*Set)(void *, double) = (void *)prop.Set;
5806 exp.instance = Instantiation { };
5807 exp.instance.data = new0 byte[_class.structSize];
5808 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5809 exp.instance.loc = exp.loc;
5810 exp.type = instanceExp;
5812 GetDouble(value, &doubleValue);
5814 Set(exp.instance.data, doubleValue);
5815 PopulateInstance(exp.instance);
5820 else if(_class.type == bitClass)
5826 Class propertyClass = type._class.registered;
5827 if(propertyClass.type == structClass && value.instance.data)
5829 unsigned int (*Set)(void *) = (void *)prop.Set;
5830 unsigned int bits = Set(value.instance.data);
5831 exp.constant = PrintHexUInt(bits);
5832 exp.type = constantExp;
5835 else if(_class.type == bitClass)
5838 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5841 GetUInt(exp.member.exp, &value);
5843 exp.constant = PrintHexUInt(bits);
5844 exp.type = constantExp;
5852 if(_class.type == bitClass)
5855 GetUInt(exp.member.exp, &value);
5861 Class _class = type._class.registered;
5862 if(_class.type == structClass)
5864 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5866 exp.instance = Instantiation { };
5867 exp.instance.data = new0 byte[_class.structSize];
5868 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5869 exp.instance.loc = exp.loc;
5870 //exp.instance.fullSet = true;
5871 exp.type = instanceExp;
5872 Get(value, exp.instance.data);
5873 PopulateInstance(exp.instance);
5875 else if(_class.type == bitClass)
5877 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5878 uint64 bits = Get(value);
5879 exp.constant = PrintHexUInt64(bits);
5880 exp.type = constantExp;
5886 else if(_class.type == structClass)
5888 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5893 Class _class = type._class.registered;
5894 if(_class.type == structClass && value)
5896 void (*Get)(void *, void *) = (void *)prop.Get;
5898 exp.instance = Instantiation { };
5899 exp.instance.data = new0 byte[_class.structSize];
5900 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5901 exp.instance.loc = exp.loc;
5902 //exp.instance.fullSet = true;
5903 exp.type = instanceExp;
5904 Get(value, exp.instance.data);
5905 PopulateInstance(exp.instance);
5913 char * value = exp.member.exp.instance.data;
5918 Class _class = type._class.registered;
5919 if(_class.type == normalClass)
5921 void *(*Get)(void *) = (void *)prop.Get;
5923 exp.instance = Instantiation { };
5924 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5925 exp.type = instanceExp;
5926 exp.instance.data = Get(value, exp.instance.data);
5938 exp.isConstant = false;
5946 if(exp.type != ExpressionType::memberExp)
5948 FreeExpression(memberExp);
5949 FreeIdentifier(memberID);
5955 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5956 FreeExpContents(exp);
5957 exp.constant = PrintUInt(ComputeTypeSize(type));
5958 exp.type = constantExp;
5964 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5965 if(classSym && classSym.registered)
5967 if(classSym.registered.fixed)
5969 FreeSpecifier(exp._class);
5970 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5971 exp.type = constantExp;
5975 char className[1024];
5976 strcpy(className, "__ecereClass_");
5977 FullClassNameCat(className, classSym.string, true);
5978 MangleClassName(className);
5980 DeclareClass(classSym, className);
5982 FreeExpContents(exp);
5983 exp.type = pointerExp;
5984 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5985 exp.member.member = MkIdentifier("structSize");
5995 if(exp.type == castExp)
5998 ComputeExpression(exp.cast.exp);
6001 if(e && exp.expType)
6004 type = exp.destType;
6007 if(type.kind == classType)
6009 Class _class = type._class.registered;
6010 if(_class && (_class.type == unitClass || _class.type == bitClass))
6012 if(!_class.dataType)
6013 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6014 type = _class.dataType;
6025 if(GetChar(e, &value))
6027 FreeExpContents(exp);
6028 exp.constant = PrintChar(value);
6029 exp.type = constantExp;
6034 unsigned char value = 0;
6035 if(GetUChar(e, &value))
6037 FreeExpContents(exp);
6038 exp.constant = PrintUChar(value);
6039 exp.type = constantExp;
6047 if(GetShort(e, &value))
6049 FreeExpContents(exp);
6050 exp.constant = PrintShort(value);
6051 exp.type = constantExp;
6056 unsigned short value = 0;
6057 if(GetUShort(e, &value))
6059 FreeExpContents(exp);
6060 exp.constant = PrintUShort(value);
6061 exp.type = constantExp;
6069 if(GetInt(e, &value))
6071 FreeExpContents(exp);
6072 exp.constant = PrintInt(value);
6073 exp.type = constantExp;
6078 unsigned int value = 0;
6079 if(GetUInt(e, &value))
6081 FreeExpContents(exp);
6082 exp.constant = PrintUInt(value);
6083 exp.type = constantExp;
6091 if(GetInt64(e, &value))
6093 FreeExpContents(exp);
6094 exp.constant = PrintInt64(value);
6095 exp.type = constantExp;
6101 if(GetUInt64(e, &value))
6103 FreeExpContents(exp);
6104 exp.constant = PrintUInt64(value);
6105 exp.type = constantExp;
6113 if(GetIntPtr(e, &value))
6115 FreeExpContents(exp);
6116 exp.constant = PrintInt64((int64)value);
6117 exp.type = constantExp;
6123 if(GetUIntPtr(e, &value))
6125 FreeExpContents(exp);
6126 exp.constant = PrintUInt64((uint64)value);
6127 exp.type = constantExp;
6135 if(GetIntSize(e, &value))
6137 FreeExpContents(exp);
6138 exp.constant = PrintInt64((int64)value);
6139 exp.type = constantExp;
6145 if(GetUIntSize(e, &value))
6147 FreeExpContents(exp);
6148 exp.constant = PrintUInt64((uint64)value);
6149 exp.type = constantExp;
6156 if(GetFloat(e, &value))
6158 FreeExpContents(exp);
6159 exp.constant = PrintFloat(value);
6160 exp.type = constantExp;
6167 if(GetDouble(e, &value))
6169 FreeExpContents(exp);
6170 exp.constant = PrintDouble(value);
6171 exp.type = constantExp;
6186 // Caring only about last expression for now...
6187 ComputeExpression(exp.cond.exp->last);
6188 if(exp.cond.elseExp)
6189 ComputeExpression(exp.cond.elseExp);
6191 ComputeExpression(exp.cond.cond);
6193 op1 = GetOperand(exp.cond.cond);
6194 if(op1.type) op1.type.refCount++;
6195 op2 = GetOperand(exp.cond.exp->last);
6196 if(op2.type) op2.type.refCount++;
6197 op3 = GetOperand(exp.cond.elseExp);
6198 if(op3.type) op3.type.refCount++;
6200 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6201 if(op1.type) FreeType(op1.type);
6202 if(op2.type) FreeType(op2.type);
6203 if(op3.type) FreeType(op3.type);
6209 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6214 OldList converts { };
6217 if(destType.kind == voidType)
6220 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6224 // for(convert = converts.last; convert; convert = convert.prev)
6225 for(convert = converts.first; convert; convert = convert.next)
6227 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6230 Expression newExp { };
6231 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6233 // TODO: Check this...
6235 newExp.destType = null;
6240 exp.type = memberExp;
6241 exp.addedThis = true;
6242 exp.member.exp = newExp;
6243 FreeType(exp.member.exp.expType);
6245 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6246 exp.member.exp.expType.classObjectType = objectType;
6247 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6248 exp.member.memberType = propertyMember;
6249 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6250 // TESTING THIS... for (int)degrees
6251 exp.needCast = true;
6252 if(exp.expType) exp.expType.refCount++;
6253 ApplyAnyObjectLogic(exp.member.exp);
6258 /*if(exp.isConstant)
6260 // Color { ColorRGB = [exp] };
6261 exp.type = instanceExp;
6262 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6263 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6264 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6268 // If not constant, don't turn it yet into an instantiation
6269 // (Go through the deep members system first)
6270 exp.type = memberExp;
6271 exp.addedThis = true;
6272 exp.member.exp = newExp;
6274 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6275 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6276 newExp.expType._class.registered.type == noHeadClass)
6278 newExp.byReference = true;
6281 FreeType(exp.member.exp.expType);
6282 /*exp.member.exp.expType = convert.convert.dataType;
6283 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6284 exp.member.exp.expType = null;
6285 if(convert.convert.dataType)
6287 exp.member.exp.expType = { };
6288 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6289 exp.member.exp.expType.refCount = 1;
6290 exp.member.exp.expType.classObjectType = objectType;
6291 ApplyAnyObjectLogic(exp.member.exp);
6294 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6295 exp.member.memberType = reverseConversionMember;
6296 exp.expType = convert.resultType ? convert.resultType :
6297 MkClassType(convert.convert._class.fullName);
6298 exp.needCast = true;
6299 if(convert.resultType) convert.resultType.refCount++;
6305 FreeType(exp.expType);
6308 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6309 exp.needCast = true;
6310 if(exp.expType) exp.expType.refCount++;
6314 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6315 exp.needCast = true;
6316 if(convert.resultType)
6317 convert.resultType.refCount++;
6321 if(exp.isConstant && inCompiler)
6322 ComputeExpression(exp);
6324 converts.Free(FreeConvert);
6327 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6329 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6331 if(!result && exp.expType && exp.destType)
6333 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6334 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6335 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6336 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6340 // if(result) CheckTemplateTypes(exp);
6344 void CheckTemplateTypes(Expression exp)
6346 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6348 Expression newExp { };
6352 if(exp.destType) exp.destType.refCount++;
6353 if(exp.expType) exp.expType.refCount++;
6357 switch(exp.expType.kind)
6360 if(exp.destType.classObjectType)
6362 // We need to pass the address, just pass it along (Undo what was done above)
6363 if(exp.destType) exp.destType.refCount--;
6364 if(exp.expType) exp.expType.refCount--;
6369 // If we're looking for value:
6370 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6372 OldList * unionDefs = MkList();
6373 OldList * statements = MkList();
6374 context = PushContext();
6375 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6376 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6377 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6378 exp.type = extensionCompoundExp;
6379 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6380 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6381 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6382 exp.compound.compound.context = context;
6383 PopContext(context);
6388 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6389 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6393 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6395 Expression newExp { };
6399 if(exp.destType) exp.destType.refCount++;
6400 if(exp.expType) exp.expType.refCount++;
6404 switch(exp.expType.kind)
6407 if(exp.destType.classObjectType)
6409 // We need to pass the address, just pass it along (Undo what was done above)
6410 if(exp.destType) exp.destType.refCount--;
6411 if(exp.expType) exp.expType.refCount--;
6416 // If we're looking for value:
6417 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6419 OldList * unionDefs = MkList();
6420 OldList * statements = MkList();
6421 context = PushContext();
6422 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6423 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6424 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6425 exp.type = extensionCompoundExp;
6426 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6427 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6428 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6429 exp.compound.compound.context = context;
6430 PopContext(context);
6435 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6437 exp.type = bracketsExp;
6438 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6439 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6440 ProcessExpressionType(exp.list->first);
6445 exp.type = bracketsExp;
6446 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6447 newExp.needCast = true;
6448 ProcessExpressionType(exp.list->first);
6454 if(exp.expType.kind == templateType)
6456 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6459 FreeType(exp.destType);
6460 FreeType(exp.expType);
6465 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6470 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6471 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6475 char typeString[1024];
6477 OldList * specs = MkList();
6478 typeString[0] = '\0';
6479 PrintType(exp.expType, typeString, false, false);
6480 decl = SpecDeclFromString(typeString, specs, null);
6483 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6484 exp.cast.typeName = MkTypeName(specs, decl);
6485 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6486 exp.cast.exp.needCast = true;
6493 // TODO: The Symbol tree should be reorganized by namespaces
6495 // - Tree of all symbols within (stored without namespace)
6496 // - Tree of sub-namespaces
6498 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6500 int nsLen = strlen(nameSpace);
6502 // Start at the name space prefix
6503 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6505 char * s = symbol.string;
6506 if(!strncmp(s, nameSpace, nsLen))
6508 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6511 for(c = strlen(s)-1; c >= 0; c--)
6516 if(!strcmp(namePart, name))
6518 // TODO: Error on ambiguity
6528 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6531 char nameSpace[1024];
6533 bool gotColon = false;
6535 nameSpace[0] = '\0';
6536 for(c = strlen(name)-1; c >= 0; c--)
6543 namePart = name+c+1;
6544 while(c >= 0 && name[c] == ':') c--;
6547 // Try an exact match first
6548 Symbol symbol = (Symbol)tree.FindString(name);
6552 // Namespace specified
6553 memcpy(nameSpace, name, c + 1);
6556 return ScanWithNameSpace(tree, nameSpace, namePart);
6560 // Looking for a global symbol, e.g. ::Sleep()
6561 Symbol symbol = (Symbol)tree.FindString(namePart);
6566 // Name only (no namespace specified)
6567 Symbol symbol = (Symbol)tree.FindString(namePart);
6570 return ScanWithNameSpace(tree, "", namePart);
6575 static void ProcessDeclaration(Declaration decl);
6577 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6580 //Time startTime = GetTime();
6582 // Optimize this later? Do this before/less?
6584 Symbol symbol = null;
6585 // First, check if the identifier is declared inside the function
6586 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6588 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6590 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6596 strcpy(curName, thisNameSpace);
6597 strcat(curName, "::");
6598 strcat(curName, name);
6599 // Try to resolve in current namespace first
6600 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6603 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6606 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6608 if(symbol || ctx == endContext) break;
6610 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6612 if(symbol.pointerExternal.type == functionExternal)
6614 FunctionDefinition function = symbol.pointerExternal.function;
6616 // Modified this recently...
6617 Context tmpContext = curContext;
6619 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6620 curContext = tmpContext;
6622 symbol.pointerExternal.symbol = symbol;
6625 DeclareType(symbol.type, true, true);
6627 ast->Insert(curExternal.prev, symbol.pointerExternal);
6629 symbol.id = curExternal.symbol.idCode;
6632 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6634 ast->Move(symbol.pointerExternal, curExternal.prev);
6635 symbol.id = curExternal.symbol.idCode;
6639 //findSymbolTotalTime += GetTime() - startTime;
6644 static void GetTypeSpecs(Type type, OldList * specs)
6646 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6651 if(type._class.registered)
6653 if(!type._class.registered.dataType)
6654 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6655 GetTypeSpecs(type._class.registered.dataType, specs);
6659 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6660 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6661 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6662 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6663 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6664 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6665 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6666 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6669 ListAdd(specs, MkSpecifier(INT)); break;
6673 static void PrintArraySize(Type arrayType, char * string)
6678 if(arrayType.enumClass)
6679 strcat(size, arrayType.enumClass.string);
6680 else if(arrayType.arraySizeExp)
6681 PrintExpression(arrayType.arraySizeExp, size);
6683 strcat(string, size);
6686 // WARNING : This function expects a null terminated string since it recursively concatenate...
6687 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6691 if(printConst && type.constant)
6692 strcat(string, "const ");
6697 Symbol c = type._class;
6698 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6699 // look into merging with thisclass ?
6700 if(type.classObjectType == typedObject)
6701 strcat(string, "typed_object");
6702 else if(type.classObjectType == anyObject)
6703 strcat(string, "any_object");
6707 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6709 if(type.byReference)
6710 strcat(string, " &");
6713 case voidType: strcat(string, "void"); break;
6714 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6715 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6716 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6717 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6718 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6719 case _BoolType: strcat(string, "_Bool"); break;
6720 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6721 case floatType: strcat(string, "float"); break;
6722 case doubleType: strcat(string, "double"); break;
6726 strcat(string, "struct ");
6727 strcat(string, type.enumName);
6729 else if(type.typeName)
6730 strcat(string, type.typeName);
6734 strcat(string, "struct { ");
6735 for(member = type.members.first; member; member = member.next)
6737 PrintType(member, string, true, fullName);
6738 strcat(string,"; ");
6746 strcat(string, "union ");
6747 strcat(string, type.enumName);
6749 else if(type.typeName)
6750 strcat(string, type.typeName);
6753 strcat(string, "union ");
6754 strcat(string,"(unnamed)");
6760 strcat(string, "enum ");
6761 strcat(string, type.enumName);
6763 else if(type.typeName)
6764 strcat(string, type.typeName);
6766 strcat(string, "int"); // "enum");
6769 strcat(string, "...");
6772 strcat(string, "subclass(");
6773 strcat(string, type._class ? type._class.string : "int");
6774 strcat(string, ")");
6777 strcat(string, type.templateParameter.identifier.string);
6780 strcat(string, "thisclass");
6783 strcat(string, "__builtin_va_list");
6789 static void PrintName(Type type, char * string, bool fullName)
6791 if(type.name && type.name[0])
6794 strcat(string, type.name);
6797 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6798 if(name) name += 2; else name = type.name;
6799 strcat(string, name);
6804 static void PrintAttribs(Type type, char * string)
6808 if(type.dllExport) strcat(string, "dllexport ");
6809 if(type.attrStdcall) strcat(string, "stdcall ");
6813 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6815 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6817 Type attrType = null;
6818 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6819 PrintAttribs(type, string);
6820 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6821 strcat(string, " const");
6822 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6823 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6824 strcat(string, " (");
6825 if(type.kind == pointerType)
6827 if(type.type.kind == functionType || type.type.kind == methodType)
6828 PrintAttribs(type.type, string);
6830 if(type.kind == pointerType)
6832 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6833 strcat(string, "*");
6835 strcat(string, " *");
6837 if(printConst && type.constant && type.kind == pointerType)
6838 strcat(string, " const");
6841 PrintTypeSpecs(type, string, fullName, printConst);
6844 static void PostPrintType(Type type, char * string, bool fullName)
6846 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6847 strcat(string, ")");
6848 if(type.kind == arrayType)
6849 PrintArraySize(type, string);
6850 else if(type.kind == functionType)
6853 strcat(string, "(");
6854 for(param = type.params.first; param; param = param.next)
6856 PrintType(param, string, true, fullName);
6857 if(param.next) strcat(string, ", ");
6859 strcat(string, ")");
6861 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6862 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6866 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6868 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6870 PrePrintType(type, string, fullName, null, printConst);
6872 if(type.thisClass || (printName && type.name && type.name[0]))
6873 strcat(string, " ");
6874 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6876 Symbol _class = type.thisClass;
6877 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6879 if(type.classObjectType == classPointer)
6880 strcat(string, "class");
6882 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6884 else if(_class && _class.string)
6886 String s = _class.string;
6891 char * name = RSearchString(s, "::", strlen(s), true, false);
6892 if(name) name += 2; else name = s;
6893 strcat(string, name);
6896 strcat(string, "::");
6899 if(printName && type.name)
6900 PrintName(type, string, fullName);
6901 PostPrintType(type, string, fullName);
6902 if(type.bitFieldCount)
6905 sprintf(count, ":%d", type.bitFieldCount);
6906 strcat(string, count);
6910 void PrintType(Type type, char * string, bool printName, bool fullName)
6912 _PrintType(type, string, printName, fullName, true);
6915 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6917 _PrintType(type, string, printName, fullName, false);
6920 static Type FindMember(Type type, char * string)
6923 for(memberType = type.members.first; memberType; memberType = memberType.next)
6925 if(!memberType.name)
6927 Type subType = FindMember(memberType, string);
6931 else if(!strcmp(memberType.name, string))
6937 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6940 for(memberType = type.members.first; memberType; memberType = memberType.next)
6942 if(!memberType.name)
6944 Type subType = FindMember(memberType, string);
6947 *offset += memberType.offset;
6951 else if(!strcmp(memberType.name, string))
6953 *offset += memberType.offset;
6960 public bool GetParseError() { return parseError; }
6962 Expression ParseExpressionString(char * expression)
6966 fileInput = TempFile { };
6967 fileInput.Write(expression, 1, strlen(expression));
6968 fileInput.Seek(0, start);
6971 parsedExpression = null;
6973 expression_yyparse();
6976 return parsedExpression;
6979 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6981 Identifier id = exp.identifier;
6982 Method method = null;
6983 Property prop = null;
6984 DataMember member = null;
6985 ClassProperty classProp = null;
6987 if(_class && _class.type == enumClass)
6989 NamedLink value = null;
6990 Class enumClass = eSystem_FindClass(privateModule, "enum");
6994 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6996 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6997 for(value = e.values.first; value; value = value.next)
6999 if(!strcmp(value.name, id.string))
7006 FreeExpContents(exp);
7008 exp.type = constantExp;
7009 exp.isConstant = true;
7010 if(!strcmp(baseClass.dataTypeString, "int"))
7011 sprintf(constant, "%d",(int)value.data);
7013 sprintf(constant, "0x%X",(int)value.data);
7014 exp.constant = CopyString(constant);
7015 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7016 exp.expType = MkClassType(baseClass.fullName);
7024 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7026 ProcessMethodType(method);
7033 // TOCHECK: Put it back to what it was...
7034 // methodClass = _class;
7035 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7040 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7043 ProcessPropertyType(prop);
7044 exp.expType = prop.dataType;
7045 if(prop.dataType) prop.dataType.refCount++;
7048 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7050 if(!member.dataType)
7051 member.dataType = ProcessTypeString(member.dataTypeString, false);
7052 exp.expType = member.dataType;
7053 if(member.dataType) member.dataType.refCount++;
7056 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7058 if(!classProp.dataType)
7059 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7061 if(classProp.constant)
7063 FreeExpContents(exp);
7065 exp.isConstant = true;
7066 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7068 //char constant[256];
7069 exp.type = stringExp;
7070 exp.constant = QMkString((char *)classProp.Get(_class));
7075 exp.type = constantExp;
7076 sprintf(constant, "%d", (int)classProp.Get(_class));
7077 exp.constant = CopyString(constant);
7085 exp.expType = classProp.dataType;
7086 if(classProp.dataType) classProp.dataType.refCount++;
7092 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7094 BinaryTree * tree = &nameSpace.functions;
7095 GlobalData data = (GlobalData)tree->FindString(name);
7099 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7101 data = ScanGlobalData(child, name);
7109 static GlobalData FindGlobalData(char * name)
7112 NameSpace * nameSpace;
7113 nameSpace = globalData;
7114 for(c = 0; name[c]; c++)
7116 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7118 NameSpace * newSpace;
7119 char * spaceName = new char[c - start + 1];
7120 strncpy(spaceName, name + start, c - start);
7121 spaceName[c-start] = '\0';
7122 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7126 nameSpace = newSpace;
7127 if(name[c] == ':') c++;
7133 return ScanGlobalData(nameSpace, name + start);
7138 static int definedExpStackPos;
7139 static void * definedExpStack[512];
7141 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7142 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7144 Expression prev = checkedExp.prev, next = checkedExp.next;
7146 FreeExpContents(checkedExp);
7147 FreeType(checkedExp.expType);
7148 FreeType(checkedExp.destType);
7150 *checkedExp = *newExp;
7154 checkedExp.prev = prev;
7155 checkedExp.next = next;
7158 void ApplyAnyObjectLogic(Expression e)
7160 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7162 char debugExpString[4096];
7163 debugExpString[0] = '\0';
7164 PrintExpression(e, debugExpString);
7167 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7169 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7170 //ellipsisDestType = destType;
7173 Type type = e.expType;
7174 Class _class = null;
7175 //Type destType = e.destType;
7177 if(type.kind == classType && type._class && type._class.registered)
7179 _class = type._class.registered;
7181 else if(type.kind == subClassType)
7183 _class = FindClass("ecere::com::Class").registered;
7187 char string[1024] = "";
7190 PrintTypeNoConst(type, string, false, true);
7191 classSym = FindClass(string);
7192 if(classSym) _class = classSym.registered;
7195 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...
7196 (!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))) ||
7197 destType.byReference)))
7199 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7201 Expression checkedExp = e, newExp;
7203 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7205 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7207 if(checkedExp.type == extensionCompoundExp)
7209 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7212 checkedExp = checkedExp.list->last;
7214 else if(checkedExp.type == castExp)
7215 checkedExp = checkedExp.cast.exp;
7218 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7220 newExp = checkedExp.op.exp2;
7221 checkedExp.op.exp2 = null;
7222 FreeExpContents(checkedExp);
7224 if(e.expType && e.expType.passAsTemplate)
7227 ComputeTypeSize(e.expType);
7228 sprintf(size, "%d", e.expType.size);
7229 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7230 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7231 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7234 ReplaceExpContents(checkedExp, newExp);
7235 e.byReference = true;
7237 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7239 Expression checkedExp, newExp;
7242 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7244 e.type == identifierExp ||
7245 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7246 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7247 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7250 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7252 Context context = PushContext();
7254 OldList * specs = MkList();
7255 char typeString[1024];
7256 Expression newExp { };
7258 typeString[0] = '\0';
7261 //if(e.destType) e.destType.refCount++;
7262 // if(exp.expType) exp.expType.refCount++;
7265 newExp.expType = null;
7267 PrintTypeNoConst(e.expType, typeString, false, true);
7268 decl = SpecDeclFromString(typeString, specs, null);
7269 newExp.destType = ProcessType(specs, decl);
7271 curContext = context;
7273 // We need a current compound for this
7277 OldList * stmts = MkList();
7278 e.type = extensionCompoundExp;
7279 sprintf(name, "__internalValue%03X", internalValueCounter++);
7280 if(!curCompound.compound.declarations)
7281 curCompound.compound.declarations = MkList();
7282 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7283 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7284 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7285 e.compound = MkCompoundStmt(null, stmts);
7288 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7291 e.compound = MkCompoundStmt(
7292 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7293 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7295 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7299 Type type = e.destType;
7301 CopyTypeInto(e.destType, type);
7302 e.destType.refCount = 1;
7303 e.destType.classObjectType = none;
7307 e.compound.compound.context = context;
7308 PopContext(context);
7309 curContext = context.parent;
7313 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7315 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7317 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7319 if(checkedExp.type == extensionCompoundExp)
7321 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7324 checkedExp = checkedExp.list->last;
7326 else if(checkedExp.type == castExp)
7327 checkedExp = checkedExp.cast.exp;
7330 Expression operand { };
7331 operand = *checkedExp;
7332 checkedExp.destType = null;
7333 checkedExp.expType = null;
7335 checkedExp.type = opExp;
7336 checkedExp.op.op = '&';
7337 checkedExp.op.exp1 = null;
7338 checkedExp.op.exp2 = operand;
7340 //newExp = MkExpOp(null, '&', checkedExp);
7342 //ReplaceExpContents(checkedExp, newExp);
7349 // If expression type is a simple class, make it an address
7350 // FixReference(e, true);
7353 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7354 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7355 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7357 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"))
7359 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7363 Expression thisExp { };
7366 thisExp.prev = null;
7367 thisExp.next = null;
7370 e.type = bracketsExp;
7371 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7372 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7373 ((Expression)e.list->first).byReference = true;
7375 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7377 e.expType = thisExp.expType;
7378 e.expType.refCount++;
7383 CopyTypeInto(e.expType, thisExp.expType);
7384 e.expType.byReference = false;
7385 e.expType.refCount = 1;
7387 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7388 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7390 e.expType.classObjectType = none;
7395 // TOFIX: Try this for a nice IDE crash!
7397 // The other way around
7400 if(destType && e.expType &&
7401 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7402 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7403 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7405 if(destType.kind == ellipsisType)
7407 Compiler_Error($"Unspecified type\n");
7409 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7411 bool byReference = e.expType.byReference;
7412 Expression thisExp { };
7414 OldList * specs = MkList();
7415 char typeString[1024]; // Watch buffer overruns
7417 ClassObjectType backupClassObjectType;
7418 bool backupByReference;
7420 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7425 backupClassObjectType = type.classObjectType;
7426 backupByReference = type.byReference;
7428 type.classObjectType = none;
7429 type.byReference = false;
7431 typeString[0] = '\0';
7432 PrintType(type, typeString, false, true);
7433 decl = SpecDeclFromString(typeString, specs, null);
7435 type.classObjectType = backupClassObjectType;
7436 type.byReference = backupByReference;
7439 thisExp.prev = null;
7440 thisExp.next = null;
7443 if( ( type.kind == classType && type._class && type._class.registered &&
7444 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7445 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7446 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7447 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7452 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7455 CopyTypeInto(e.expType, type);
7456 e.expType.byReference = false;
7457 e.expType.refCount = 1;
7462 e.cast.typeName = MkTypeName(specs, decl);
7463 e.cast.exp = thisExp;
7464 e.byReference = true;
7468 e.destType = destType;
7469 destType.refCount++;
7474 void ProcessExpressionType(Expression exp)
7476 bool unresolved = false;
7477 Location oldyylloc = yylloc;
7478 bool notByReference = false;
7480 char debugExpString[4096];
7481 debugExpString[0] = '\0';
7482 PrintExpression(exp, debugExpString);
7484 if(!exp || exp.expType)
7487 //eSystem_Logf("%s\n", expString);
7489 // Testing this here
7495 Identifier id = exp.identifier;
7496 if(!id || !topContext) return;
7498 // DOING THIS LATER NOW...
7499 if(id._class && id._class.name)
7501 id.classSym = id._class.symbol; // FindClass(id._class.name);
7502 /* TODO: Name Space Fix ups
7504 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7508 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7510 exp.expType = ProcessTypeString("Module", true);
7513 else */if(strstr(id.string, "__ecereClass") == id.string)
7515 exp.expType = ProcessTypeString("ecere::com::Class", true);
7518 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7520 // Added this here as well
7521 ReplaceClassMembers(exp, thisClass);
7522 if(exp.type != identifierExp)
7524 ProcessExpressionType(exp);
7528 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7533 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7534 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7535 if(!symbol/* && exp.destType*/)
7537 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7543 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7544 if(exp.type != identifierExp)
7546 ProcessExpressionType(exp);
7550 // Static methods called from inside the _class
7551 else if(currentClass && !id._class)
7553 if(ResolveIdWithClass(exp, currentClass, true))
7556 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7560 // If we manage to resolve this symbol
7563 Type type = symbol.type;
7564 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7566 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7568 Context context = SetupTemplatesContext(_class);
7569 type = ReplaceThisClassType(_class);
7570 FinishTemplatesContext(context);
7571 if(type) type.refCount = 0; // We'll be incrementing it right below...
7574 FreeSpecifier(id._class);
7577 id.string = CopyString(symbol.string);
7583 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7584 // Add missing cases here... enum Classes...
7585 exp.isConstant = true;
7587 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7588 if(symbol.isParam || !strcmp(id.string, "this"))
7590 if(_class && _class.type == structClass && !type.declaredWithStruct)
7591 exp.byReference = true;
7593 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7594 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7595 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7596 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7598 Identifier id = exp.identifier;
7599 exp.type = bracketsExp;
7600 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7604 if(symbol.isIterator)
7606 if(symbol.isIterator == 3)
7608 exp.type = bracketsExp;
7609 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7610 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7612 ProcessExpressionType(exp);
7614 else if(symbol.isIterator != 4)
7616 exp.type = memberExp;
7617 exp.member.exp = MkExpIdentifier(exp.identifier);
7618 exp.member.exp.expType = exp.expType;
7619 /*if(symbol.isIterator == 6)
7620 exp.member.member = MkIdentifier("key");
7622 exp.member.member = MkIdentifier("data");
7624 ProcessExpressionType(exp);
7631 DefinedExpression definedExp = null;
7632 if(thisNameSpace && !(id._class && !id._class.name))
7635 strcpy(name, thisNameSpace);
7637 strcat(name, id.string);
7638 definedExp = eSystem_FindDefine(privateModule, name);
7641 definedExp = eSystem_FindDefine(privateModule, id.string);
7645 for(c = 0; c<definedExpStackPos; c++)
7646 if(definedExpStack[c] == definedExp)
7648 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7650 Location backupYylloc = yylloc;
7651 File backInput = fileInput;
7652 definedExpStack[definedExpStackPos++] = definedExp;
7654 fileInput = TempFile { };
7655 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7656 fileInput.Seek(0, start);
7659 parsedExpression = null;
7661 expression_yyparse();
7664 fileInput = backInput;
7666 yylloc = backupYylloc;
7668 if(parsedExpression)
7671 exp.type = bracketsExp;
7672 exp.list = MkListOne(parsedExpression);
7673 parsedExpression.loc = yylloc;
7674 ProcessExpressionType(exp);
7675 definedExpStackPos--;
7678 definedExpStackPos--;
7684 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7690 GlobalData data = null;
7691 if(thisNameSpace && !(id._class && !id._class.name))
7694 strcpy(name, thisNameSpace);
7696 strcat(name, id.string);
7697 data = FindGlobalData(name);
7700 data = FindGlobalData(id.string);
7703 DeclareGlobalData(data);
7704 exp.expType = data.dataType;
7705 if(data.dataType) data.dataType.refCount++;
7708 id.string = CopyString(data.fullName);
7709 FreeSpecifier(id._class);
7716 GlobalFunction function = null;
7717 if(thisNameSpace && !(id._class && !id._class.name))
7720 strcpy(name, thisNameSpace);
7722 strcat(name, id.string);
7723 function = eSystem_FindFunction(privateModule, name);
7726 function = eSystem_FindFunction(privateModule, id.string);
7731 id.string = CopyString(function.name);
7734 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7735 strcpy(name, "__ecereFunction_");
7736 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7737 if(DeclareFunction(function, name))
7740 id.string = CopyString(name);
7742 exp.expType = function.dataType;
7743 if(function.dataType) function.dataType.refCount++;
7745 FreeSpecifier(id._class);
7762 if(!exp.instance._class)
7764 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7766 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7770 //classSym = FindClass(exp.instance._class.fullName);
7771 //_class = classSym ? classSym.registered : null;
7773 ProcessInstantiationType(exp.instance);
7774 exp.isConstant = exp.instance.isConstant;
7777 if(_class.type == unitClass && _class.base.type != systemClass)
7780 Type destType = exp.destType;
7782 exp.destType = MkClassType(_class.base.fullName);
7783 exp.expType = MkClassType(_class.fullName);
7784 CheckExpressionType(exp, exp.destType, true);
7786 exp.destType = destType;
7788 exp.expType = MkClassType(_class.fullName);
7791 if(exp.instance._class)
7793 exp.expType = MkClassType(exp.instance._class.name);
7794 /*if(exp.expType._class && exp.expType._class.registered &&
7795 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7796 exp.expType.byReference = true;*/
7804 char * constant = exp.constant;
7812 if(constant[0] == '\'')
7814 if((int)((byte *)constant)[1] > 127)
7817 unichar ch = UTF8GetChar(constant + 1, &nb);
7818 if(nb < 2) ch = constant[1];
7820 exp.constant = PrintUInt(ch);
7821 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7822 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7823 type._class = FindClass("unichar");
7825 type.isSigned = false;
7829 type.kind = charType;
7830 type.isSigned = true;
7835 char * dot = strchr(constant, '.');
7836 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7840 exponent = strchr(constant, 'p');
7841 if(!exponent) exponent = strchr(constant, 'P');
7845 exponent = strchr(constant, 'e');
7846 if(!exponent) exponent = strchr(constant, 'E');
7851 if(strchr(constant, 'f') || strchr(constant, 'F'))
7852 type.kind = floatType;
7854 type.kind = doubleType;
7855 type.isSigned = true;
7859 bool isSigned = constant[0] == '-';
7860 int64 i64 = strtoll(constant, null, 0);
7861 uint64 ui64 = strtoull(constant, null, 0);
7862 bool is64Bit = false;
7875 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7879 else if(constant[0] != '0' || !constant[1])
7882 type.kind = is64Bit ? int64Type : intType;
7883 type.isSigned = isSigned;
7886 exp.isConstant = true;
7887 if(exp.destType && exp.destType.kind == doubleType)
7888 type.kind = doubleType;
7889 else if(exp.destType && exp.destType.kind == floatType)
7890 type.kind = floatType;
7891 else if(exp.destType && exp.destType.kind == int64Type)
7892 type.kind = int64Type;
7898 exp.isConstant = true; // Why wasn't this constant?
7915 ProcessExpressionType(exp._new.size);
7920 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7922 DeclareType(exp.expType.type, false, false);
7926 ProcessExpressionType(exp._renew.size);
7927 ProcessExpressionType(exp._renew.exp);
7932 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7934 DeclareType(exp.expType.type, false, false);
7938 bool assign = false, boolResult = false, boolOps = false;
7939 Type type1 = null, type2 = null;
7940 bool useDestType = false, useSideType = false;
7941 Location oldyylloc = yylloc;
7942 bool useSideUnit = false;
7944 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7953 // Assignment Operators
7967 // boolean Operators
7969 // Expect boolean operators
7971 //boolResult = true;
7975 // Expect boolean operands
7986 // Gives boolean result
7994 // Just added these... testing
7999 // DANGER: Verify units
8004 if(exp.op.op != '*' || exp.op.exp1)
8011 /*// Implement speed etc.
8017 if(exp.op.op == '&')
8019 // Added this here earlier for Iterator address as key
8020 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8022 Identifier id = exp.op.exp2.identifier;
8023 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8024 if(symbol && symbol.isIterator == 2)
8026 exp.type = memberExp;
8027 exp.member.exp = exp.op.exp2;
8028 exp.member.member = MkIdentifier("key");
8030 exp.op.exp2.expType = symbol.type;
8031 symbol.type.refCount++;
8032 ProcessExpressionType(exp);
8036 // exp.op.exp2.usage.usageRef = true;
8040 //dummy.kind = TypeDummy;
8044 if(exp.destType && exp.destType.kind == classType &&
8045 exp.destType._class && exp.destType._class.registered && useDestType &&
8047 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
8048 exp.destType._class.registered.type == enumClass ||
8049 exp.destType._class.registered.type == bitClass
8052 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8054 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8055 exp.op.exp1.destType = exp.destType;
8057 exp.destType.refCount++;
8061 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8062 exp.op.exp1.destType = dummy;
8066 // TESTING THIS HERE...
8067 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8068 ProcessExpressionType(exp.op.exp1);
8069 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8071 if(exp.op.exp1.destType == dummy)
8074 exp.op.exp1.destType = null;
8076 type1 = exp.op.exp1.expType;
8081 char expString[10240];
8082 expString[0] = '\0';
8083 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8087 exp.op.exp2.destType = exp.op.exp1.expType;
8088 if(exp.op.exp1.expType)
8089 exp.op.exp1.expType.refCount++;
8093 exp.op.exp2.destType = exp.destType;
8095 exp.destType.refCount++;
8098 if(type1) type1.refCount++;
8099 exp.expType = type1;
8104 PrintExpression(exp.op.exp2, expString);
8106 if(type1 && type1.kind == pointerType)
8108 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 ||
8109 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8110 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8111 else if(exp.op.op == '=')
8113 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8114 exp.op.exp2.destType = type1;
8121 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8122 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/* ||
8123 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8126 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8127 exp.op.exp2.destType = type1;
8132 if(type1) type1.refCount++;
8133 exp.expType = type1;
8135 else if(exp.destType && exp.destType.kind == classType &&
8136 exp.destType._class && exp.destType._class.registered &&
8138 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
8139 (exp.destType._class.registered.type == enumClass && useDestType))
8142 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8143 exp.op.exp2.destType = exp.destType;
8145 exp.destType.refCount++;
8149 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8150 exp.op.exp2.destType = dummy;
8154 // TESTING THIS HERE... (DANGEROUS)
8155 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8156 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8158 FreeType(exp.op.exp2.destType);
8159 exp.op.exp2.destType = type1;
8162 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8163 // Cannot lose the cast on a sizeof
8164 if(exp.op.op == SIZEOF)
8166 Expression e = exp.op.exp2;
8167 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8169 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8171 if(e.type == extensionCompoundExp)
8172 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8177 if(e.type == castExp && e.cast.exp)
8178 e.cast.exp.needCast = true;
8180 ProcessExpressionType(exp.op.exp2);
8181 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8183 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8185 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)
8187 if(exp.op.op != '=' && type1.type.kind == voidType)
8188 Compiler_Error($"void *: unknown size\n");
8190 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||
8191 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8192 (exp.op.exp2.expType._class.registered.type == normalClass ||
8193 exp.op.exp2.expType._class.registered.type == structClass ||
8194 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8196 if(exp.op.op == ADD_ASSIGN)
8197 Compiler_Error($"cannot add two pointers\n");
8199 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8200 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8202 if(exp.op.op == ADD_ASSIGN)
8203 Compiler_Error($"cannot add two pointers\n");
8207 char type1String[1024];
8208 char type2String[1024];
8209 type1String[0] = '\0';
8210 type2String[0] = '\0';
8212 PrintType(exp.op.exp2.expType, type1String, false, true);
8213 PrintType(type1, type2String, false, true);
8214 ChangeCh(expString, '\n', ' ');
8215 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8219 if(exp.op.exp2.destType == dummy)
8222 exp.op.exp2.destType = null;
8225 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8229 CopyTypeInto(type2, exp.op.exp2.expType);
8230 type2.isSigned = true;
8232 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8234 type2 = { kind = intType };
8236 type2.isSigned = true;
8240 type2 = exp.op.exp2.expType;
8241 if(type2) type2.refCount++;
8245 dummy.kind = voidType;
8247 if(exp.op.op == SIZEOF)
8254 exp.isConstant = true;
8256 // Get type of dereferenced pointer
8257 else if(exp.op.op == '*' && !exp.op.exp1)
8259 exp.expType = Dereference(type2);
8260 if(type2 && type2.kind == classType)
8261 notByReference = true;
8263 else if(exp.op.op == '&' && !exp.op.exp1)
8264 exp.expType = Reference(type2);
8271 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8272 exp.op.exp1.destType = MkClassType("bool");
8273 exp.op.exp1.destType.truth = true;
8274 if(!exp.op.exp1.expType)
8275 ProcessExpressionType(exp.op.exp1);
8277 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8278 FreeType(exp.op.exp1.expType);
8279 exp.op.exp1.expType = MkClassType("bool");
8280 exp.op.exp1.expType.truth = true;
8284 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8285 exp.op.exp2.destType = MkClassType("bool");
8286 exp.op.exp2.destType.truth = true;
8287 if(!exp.op.exp2.expType)
8288 ProcessExpressionType(exp.op.exp2);
8290 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8291 FreeType(exp.op.exp2.expType);
8292 exp.op.exp2.expType = MkClassType("bool");
8293 exp.op.exp2.expType.truth = true;
8296 else if(exp.op.exp1 && exp.op.exp2 &&
8299 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8300 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8301 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8302 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8304 if(type1 && type2 &&
8305 // If either both are class or both are not class
8306 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8308 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8309 exp.op.exp2.destType = type1;
8311 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8312 exp.op.exp1.destType = type2;
8314 // Warning here for adding Radians + Degrees with no destination type
8315 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8316 type1._class.registered && type1._class.registered.type == unitClass &&
8317 type2._class.registered && type2._class.registered.type == unitClass &&
8318 type1._class.registered != type2._class.registered)
8319 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8320 type1._class.string, type2._class.string, type1._class.string);
8322 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8324 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8327 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8329 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8330 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8333 ProcessExpressionType(exp.op.exp1);
8335 if(type2.kind != pointerType)
8337 ProcessExpressionType(classExp);
8339 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8340 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8341 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8343 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8346 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8347 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8348 MkPointer(null, null), null)))),
8349 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8351 if(!exp.op.exp2.expType)
8355 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8359 ProcessExpressionType(exp.op.exp2);
8364 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)))
8366 if(type1.kind != classType && type1.type.kind == voidType)
8367 Compiler_Error($"void *: unknown size\n");
8368 exp.expType = type1;
8369 if(type1) type1.refCount++;
8371 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)))
8373 if(type2.kind != classType && type2.type.kind == voidType)
8374 Compiler_Error($"void *: unknown size\n");
8375 exp.expType = type2;
8376 if(type2) type2.refCount++;
8378 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8379 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8381 Compiler_Warning($"different levels of indirection\n");
8385 bool success = false;
8386 if(type1.kind == pointerType && type2.kind == pointerType)
8388 if(exp.op.op == '+')
8389 Compiler_Error($"cannot add two pointers\n");
8390 else if(exp.op.op == '-')
8392 // Pointer Subtraction gives integer
8393 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8402 if(type1.type.kind == templateType)
8404 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8407 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8409 ProcessExpressionType(classExp);
8411 exp.type = bracketsExp;
8412 exp.list = MkListOne(MkExpOp(
8413 MkExpBrackets(MkListOne(MkExpOp(
8414 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8416 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8418 //MkExpMember(classExp, MkIdentifier("typeSize"))
8420 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8421 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8423 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8426 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8427 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8428 MkPointer(null, null), null)))),
8429 MkExpMember(classExp, MkIdentifier("typeSize")))))
8434 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8443 if(!success && exp.op.exp1.type == constantExp)
8445 // If first expression is constant, try to match that first
8446 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8448 if(exp.expType) FreeType(exp.expType);
8449 exp.expType = exp.op.exp1.destType;
8450 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8453 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8455 if(exp.expType) FreeType(exp.expType);
8456 exp.expType = exp.op.exp2.destType;
8457 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8463 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8465 if(exp.expType) FreeType(exp.expType);
8466 exp.expType = exp.op.exp2.destType;
8467 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8470 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8472 if(exp.expType) FreeType(exp.expType);
8473 exp.expType = exp.op.exp1.destType;
8474 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8480 char expString1[10240];
8481 char expString2[10240];
8484 expString1[0] = '\0';
8485 expString2[0] = '\0';
8490 PrintExpression(exp.op.exp1, expString1);
8491 ChangeCh(expString1, '\n', ' ');
8492 PrintExpression(exp.op.exp2, expString2);
8493 ChangeCh(expString2, '\n', ' ');
8494 PrintType(exp.op.exp1.expType, type1, false, true);
8495 PrintType(exp.op.exp2.expType, type2, false, true);
8498 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8502 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8503 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8505 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8506 // Convert e.g. / 4 into / 4.0
8507 exp.op.exp1.destType = type2._class.registered.dataType;
8508 if(type2._class.registered.dataType)
8509 type2._class.registered.dataType.refCount++;
8510 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8511 exp.expType = type2;
8512 if(type2) type2.refCount++;
8514 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8516 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8517 // Convert e.g. / 4 into / 4.0
8518 exp.op.exp2.destType = type1._class.registered.dataType;
8519 if(type1._class.registered.dataType)
8520 type1._class.registered.dataType.refCount++;
8521 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8522 exp.expType = type1;
8523 if(type1) type1.refCount++;
8529 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8531 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8533 if(!type1._class.registered.dataType)
8534 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8535 exp.op.exp2.destType = type1._class.registered.dataType;
8536 exp.op.exp2.destType.refCount++;
8538 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8541 type2 = exp.op.exp2.destType;
8542 if(type2) type2.refCount++;
8544 exp.expType = type2;
8548 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8550 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8552 if(!type2._class.registered.dataType)
8553 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8554 exp.op.exp1.destType = type2._class.registered.dataType;
8555 exp.op.exp1.destType.refCount++;
8557 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8558 type1 = exp.op.exp1.destType;
8559 exp.expType = type1;
8563 // TESTING THIS NEW CODE
8564 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8566 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8568 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8570 if(exp.expType) FreeType(exp.expType);
8571 exp.expType = exp.op.exp1.expType;
8572 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8577 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8579 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8581 if(exp.expType) FreeType(exp.expType);
8582 exp.expType = exp.op.exp2.expType;
8583 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8591 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8592 exp.op.exp2.destType = type1;
8596 // Maybe this was meant to be an enum...
8597 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8599 Type oldType = exp.op.exp2.expType;
8600 exp.op.exp2.expType = null;
8601 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8604 exp.op.exp2.expType = oldType;
8609 // TESTING THIS HERE... LATEST ADDITION
8610 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8612 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8613 exp.op.exp2.destType = type2._class.registered.dataType;
8614 if(type2._class.registered.dataType)
8615 type2._class.registered.dataType.refCount++;
8616 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8618 //exp.expType = type2._class.registered.dataType; //type2;
8619 //if(type2) type2.refCount++;
8622 // TESTING THIS HERE... LATEST ADDITION
8623 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8625 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8626 exp.op.exp1.destType = type1._class.registered.dataType;
8627 if(type1._class.registered.dataType)
8628 type1._class.registered.dataType.refCount++;
8629 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8630 exp.expType = type1._class.registered.dataType; //type1;
8631 if(type1) type1.refCount++;
8635 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8637 if(exp.expType) FreeType(exp.expType);
8638 exp.expType = exp.op.exp2.destType;
8639 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8641 else if(type1 && type2)
8643 char expString1[10240];
8644 char expString2[10240];
8645 char type1String[1024];
8646 char type2String[1024];
8647 expString1[0] = '\0';
8648 expString2[0] = '\0';
8649 type1String[0] = '\0';
8650 type2String[0] = '\0';
8653 PrintExpression(exp.op.exp1, expString1);
8654 ChangeCh(expString1, '\n', ' ');
8655 PrintExpression(exp.op.exp2, expString2);
8656 ChangeCh(expString2, '\n', ' ');
8657 PrintType(exp.op.exp1.expType, type1String, false, true);
8658 PrintType(exp.op.exp2.expType, type2String, false, true);
8661 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8663 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8665 exp.expType = exp.op.exp1.expType;
8666 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8668 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8670 exp.expType = exp.op.exp2.expType;
8671 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8678 // Maybe this was meant to be an enum...
8679 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8681 Type oldType = exp.op.exp1.expType;
8682 exp.op.exp1.expType = null;
8683 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8686 exp.op.exp1.expType = oldType;
8689 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8690 exp.op.exp1.destType = type2;
8693 // TESTING THIS HERE... LATEST ADDITION
8694 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8696 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8697 exp.op.exp1.destType = type1._class.registered.dataType;
8698 if(type1._class.registered.dataType)
8699 type1._class.registered.dataType.refCount++;
8702 // TESTING THIS HERE... LATEST ADDITION
8703 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8705 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8706 exp.op.exp2.destType = type2._class.registered.dataType;
8707 if(type2._class.registered.dataType)
8708 type2._class.registered.dataType.refCount++;
8712 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8714 if(exp.expType) FreeType(exp.expType);
8715 exp.expType = exp.op.exp1.destType;
8716 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8720 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8722 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8724 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8725 // Convert e.g. / 4 into / 4.0
8726 exp.op.exp1.destType = type2._class.registered.dataType;
8727 if(type2._class.registered.dataType)
8728 type2._class.registered.dataType.refCount++;
8729 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8731 if(exp.op.op == '!')
8733 exp.expType = MkClassType("bool");
8734 exp.expType.truth = true;
8738 exp.expType = type2;
8739 if(type2) type2.refCount++;
8742 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8744 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8746 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8747 // Convert e.g. / 4 into / 4.0
8748 exp.op.exp2.destType = type1._class.registered.dataType;
8749 if(type1._class.registered.dataType)
8750 type1._class.registered.dataType.refCount++;
8751 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8753 exp.expType = type1;
8754 if(type1) type1.refCount++;
8759 if(exp.op.exp1 && !exp.op.exp1.expType)
8761 char expString[10000];
8762 expString[0] = '\0';
8765 PrintExpression(exp.op.exp1, expString);
8766 ChangeCh(expString, '\n', ' ');
8769 Compiler_Error($"couldn't determine type of %s\n", expString);
8771 if(exp.op.exp2 && !exp.op.exp2.expType)
8773 char expString[10240];
8774 expString[0] = '\0';
8777 PrintExpression(exp.op.exp2, expString);
8778 ChangeCh(expString, '\n', ' ');
8781 Compiler_Error($"couldn't determine type of %s\n", expString);
8786 FreeType(exp.expType);
8787 exp.expType = MkClassType("bool");
8788 exp.expType.truth = true;
8791 if(exp.op.op != SIZEOF)
8792 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8793 (!exp.op.exp2 || exp.op.exp2.isConstant);
8795 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8797 DeclareType(exp.op.exp2.expType, false, false);
8808 case extensionExpressionExp:
8811 exp.isConstant = true;
8812 for(e = exp.list->first; e; e = e.next)
8817 FreeType(e.destType);
8818 e.destType = exp.destType;
8819 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8821 ProcessExpressionType(e);
8823 exp.destType.count--;
8824 if(!exp.expType && !e.next)
8826 exp.expType = e.expType;
8827 if(e.expType) e.expType.refCount++;
8830 exp.isConstant = false;
8833 // In case a cast became a member...
8834 e = exp.list->first;
8835 if(!e.next && e.type == memberExp)
8837 // Preserve prev, next
8838 Expression next = exp.next, prev = exp.prev;
8841 FreeType(exp.expType);
8842 FreeType(exp.destType);
8852 ProcessExpressionType(exp);
8859 exp.isConstant = true;
8861 ProcessExpressionType(exp.index.exp);
8862 if(!exp.index.exp.isConstant)
8863 exp.isConstant = false;
8865 if(exp.index.exp.expType)
8867 Type source = exp.index.exp.expType;
8868 if(source.kind == classType && source._class && source._class.registered)
8870 Class _class = source._class.registered;
8871 Class c = _class.templateClass ? _class.templateClass : _class;
8872 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8874 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8876 if(exp.index.index && exp.index.index->last)
8878 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8884 for(e = exp.index.index->first; e; e = e.next)
8886 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8888 if(e.destType) FreeType(e.destType);
8889 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8891 ProcessExpressionType(e);
8894 // Check if this type is int
8897 exp.isConstant = false;
8901 exp.expType = Dereference(exp.index.exp.expType);
8903 DeclareType(exp.expType, false, false);
8910 Type methodType = null;
8916 PrintExpression(exp.call.exp, name);
8917 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8919 //exp.call.exp.expType = null;
8920 PrintExpression(exp.call.exp, name);
8923 if(exp.call.exp.type == identifierExp)
8925 Expression idExp = exp.call.exp;
8926 Identifier id = idExp.identifier;
8927 if(!strcmp(id.string, "__builtin_frame_address"))
8929 exp.expType = ProcessTypeString("void *", true);
8930 if(exp.call.arguments && exp.call.arguments->first)
8931 ProcessExpressionType(exp.call.arguments->first);
8934 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8936 exp.expType = ProcessTypeString("int", true);
8937 if(exp.call.arguments && exp.call.arguments->first)
8938 ProcessExpressionType(exp.call.arguments->first);
8941 else if(!strcmp(id.string, "Max") ||
8942 !strcmp(id.string, "Min") ||
8943 !strcmp(id.string, "Sgn") ||
8944 !strcmp(id.string, "Abs"))
8946 Expression a = null;
8947 Expression b = null;
8948 Expression tempExp1 = null, tempExp2 = null;
8949 if((!strcmp(id.string, "Max") ||
8950 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8952 a = exp.call.arguments->first;
8953 b = exp.call.arguments->last;
8957 else if(exp.call.arguments->count == 1)
8959 a = exp.call.arguments->first;
8965 exp.call.arguments->Clear();
8966 idExp.identifier = null;
8968 FreeExpContents(exp);
8970 ProcessExpressionType(a);
8972 ProcessExpressionType(b);
8974 exp.type = bracketsExp;
8975 exp.list = MkList();
8977 if(a.expType && (!b || b.expType))
8979 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8981 // Use the simpleStruct name/ids for now...
8984 OldList * specs = MkList();
8985 OldList * decls = MkList();
8987 char temp1[1024], temp2[1024];
8989 GetTypeSpecs(a.expType, specs);
8991 if(a && !a.isConstant && a.type != identifierExp)
8993 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8994 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8995 tempExp1 = QMkExpId(temp1);
8996 tempExp1.expType = a.expType;
8998 a.expType.refCount++;
8999 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9001 if(b && !b.isConstant && b.type != identifierExp)
9003 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9004 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9005 tempExp2 = QMkExpId(temp2);
9006 tempExp2.expType = b.expType;
9008 b.expType.refCount++;
9009 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9012 decl = MkDeclaration(specs, decls);
9013 if(!curCompound.compound.declarations)
9014 curCompound.compound.declarations = MkList();
9015 curCompound.compound.declarations->Insert(null, decl);
9020 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9022 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9024 MkExpCondition(MkExpBrackets(MkListOne(
9025 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9026 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9027 exp.expType = a.expType;
9029 a.expType.refCount++;
9031 else if(!strcmp(id.string, "Abs"))
9034 MkExpCondition(MkExpBrackets(MkListOne(
9035 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9036 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9037 exp.expType = a.expType;
9039 a.expType.refCount++;
9041 else if(!strcmp(id.string, "Sgn"))
9043 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9045 MkExpCondition(MkExpBrackets(MkListOne(
9046 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9047 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9048 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9049 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9050 exp.expType = ProcessTypeString("int", false);
9053 FreeExpression(tempExp1);
9054 if(tempExp2) FreeExpression(tempExp2);
9068 if(!exp.call.exp.destType)
9070 exp.call.exp.destType = dummy;
9073 ProcessExpressionType(exp.call.exp);
9074 if(exp.call.exp.destType == dummy)
9077 exp.call.exp.destType = null;
9082 // Check argument types against parameter types
9083 functionType = exp.call.exp.expType;
9085 if(functionType && functionType.kind == TypeKind::methodType)
9087 methodType = functionType;
9088 functionType = methodType.method.dataType;
9090 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9091 // TOCHECK: Instead of doing this here could this be done per param?
9092 if(exp.call.exp.expType.usedClass)
9094 char typeString[1024];
9095 typeString[0] = '\0';
9097 Symbol back = functionType.thisClass;
9098 // Do not output class specifier here (thisclass was added to this)
9099 functionType.thisClass = null;
9100 PrintType(functionType, typeString, true, true);
9101 functionType.thisClass = back;
9103 if(strstr(typeString, "thisclass"))
9105 OldList * specs = MkList();
9108 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9110 decl = SpecDeclFromString(typeString, specs, null);
9112 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9113 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9114 exp.call.exp.expType.usedClass))
9115 thisClassParams = false;
9117 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9119 Class backupThisClass = thisClass;
9120 thisClass = exp.call.exp.expType.usedClass;
9121 ProcessDeclarator(decl);
9122 thisClass = backupThisClass;
9125 thisClassParams = true;
9127 functionType = ProcessType(specs, decl);
9128 functionType.refCount = 0;
9129 FinishTemplatesContext(context);
9132 FreeList(specs, FreeSpecifier);
9133 FreeDeclarator(decl);
9137 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9139 Type type = functionType.type;
9140 if(!functionType.refCount)
9142 functionType.type = null;
9143 FreeType(functionType);
9145 //methodType = functionType;
9146 functionType = type;
9148 if(functionType && functionType.kind != TypeKind::functionType)
9150 Compiler_Error($"called object %s is not a function\n", name);
9152 else if(functionType)
9154 bool emptyParams = false, noParams = false;
9155 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9156 Type type = functionType.params.first;
9157 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9159 Location oldyylloc = yylloc;
9161 if(!type) emptyParams = true;
9164 if(functionType.extraParam && e && functionType.thisClass)
9166 e.destType = MkClassType(functionType.thisClass.string);
9170 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9171 // Fixed #141 by adding '&& !functionType.extraParam'
9172 if(!functionType.staticMethod && !functionType.extraParam)
9174 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9175 memberExp.member.exp.expType._class)
9177 type = MkClassType(memberExp.member.exp.expType._class.string);
9182 type = functionType.params.first;
9187 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9189 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9190 type.byReference = functionType.byReference;
9191 type.typedByReference = functionType.typedByReference;
9194 // Allow manually passing a class for typed object
9195 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9199 type = functionType.params.first;
9207 if(type && type.kind == voidType)
9210 if(!type.refCount) FreeType(type);
9214 for( ; e; e = e.next)
9216 if(!type && !emptyParams)
9219 if(methodType && methodType.methodClass)
9220 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9221 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9222 noParams ? 0 : functionType.params.count);
9224 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9225 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9226 noParams ? 0 : functionType.params.count);
9230 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9232 Type templatedType = null;
9233 Class _class = methodType.usedClass;
9234 ClassTemplateParameter curParam = null;
9236 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9239 for(sClass = _class; sClass; sClass = sClass.base)
9241 if(sClass.templateClass) sClass = sClass.templateClass;
9243 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9245 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9248 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9250 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9251 id += nextClass.templateParams.count;
9260 if(curParam && _class.templateArgs[id].dataTypeString)
9262 ClassTemplateArgument arg = _class.templateArgs[id];
9264 Context context = SetupTemplatesContext(_class);
9267 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9268 templatedType = ProcessTypeString(arg.dataTypeString, false);
9269 FinishTemplatesContext(context);
9271 e.destType = templatedType;
9274 templatedType.passAsTemplate = true;
9275 // templatedType.refCount++;
9281 if(type) type.refCount++;
9286 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9288 e.destType = type.prev;
9289 e.destType.refCount++;
9294 if(type) type.refCount++;
9297 // Don't reach the end for the ellipsis
9298 if(type && type.kind != ellipsisType)
9300 Type next = type.next;
9301 if(!type.refCount) FreeType(type);
9306 if(type && type.kind != ellipsisType)
9308 if(methodType && methodType.methodClass)
9309 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9310 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9311 functionType.params.count + extra);
9313 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9314 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9315 functionType.params.count + extra);
9318 if(type && !type.refCount) FreeType(type);
9325 kind = TypeKind::functionType;
9328 if(exp.call.exp.type == identifierExp)
9330 char * string = exp.call.exp.identifier.string;
9334 Location oldyylloc = yylloc;
9336 yylloc = exp.call.exp.identifier.loc;
9337 if(strstr(string, "__builtin_") == string)
9341 functionType.returnType = exp.destType;
9342 exp.destType.refCount++;
9346 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9347 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9348 globalContext.symbols.Add((BTNode)symbol);
9349 if(strstr(symbol.string, "::"))
9350 globalContext.hasNameSpace = true;
9355 else if(exp.call.exp.type == memberExp)
9357 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9358 exp.call.exp.member.member.string);*/
9361 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9363 if(!functionType.returnType)
9365 functionType.returnType = Type
9372 if(functionType && functionType.kind == TypeKind::functionType)
9374 exp.expType = functionType.returnType;
9376 if(functionType.returnType)
9377 functionType.returnType.refCount++;
9379 if(!functionType.refCount)
9380 FreeType(functionType);
9383 if(exp.call.arguments)
9385 for(e = exp.call.arguments->first; e; e = e.next)
9387 Type destType = e.destType;
9388 ProcessExpressionType(e);
9396 Location oldyylloc = yylloc;
9398 Expression checkExp = exp.member.exp;
9401 if(checkExp.type == castExp)
9402 checkExp = checkExp.cast.exp;
9403 else if(checkExp.type == bracketsExp)
9404 checkExp = checkExp.list ? checkExp.list->first : null;
9409 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9410 exp.thisPtr = thisPtr;
9412 // DOING THIS LATER NOW...
9413 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9415 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9416 /* TODO: Name Space Fix ups
9417 if(!exp.member.member.classSym)
9418 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9422 ProcessExpressionType(exp.member.exp);
9423 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9424 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9426 exp.isConstant = false;
9429 exp.isConstant = exp.member.exp.isConstant;
9430 type = exp.member.exp.expType;
9434 if(type && (type.kind == templateType))
9436 Class _class = thisClass ? thisClass : currentClass;
9437 ClassTemplateParameter param = null;
9440 for(param = _class.templateParams.first; param; param = param.next)
9442 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9446 if(param && param.defaultArg.member)
9448 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9451 Expression expMember = exp.member.exp;
9453 OldList * specs = MkList();
9454 char thisClassTypeString[1024];
9456 FreeIdentifier(exp.member.member);
9458 ProcessExpressionType(argExp);
9461 char * colon = strstr(param.defaultArg.memberString, "::");
9464 char className[1024];
9467 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9468 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9471 strcpy(thisClassTypeString, _class.fullName);
9474 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9476 exp.expType = ProcessType(specs, decl);
9477 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9479 Class expClass = exp.expType._class.registered;
9480 Class cClass = null;
9485 char templateString[1024];
9486 ClassTemplateParameter param;
9487 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9488 for(cClass = expClass; cClass; cClass = cClass.base)
9491 for(param = cClass.templateParams.first; param; param = param.next)
9495 ClassTemplateArgument arg;
9496 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9497 arg = expClass.templateArgs[id];
9499 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9501 ClassTemplateParameter cParam;
9502 //int p = numParams - sClass.templateParams.count;
9505 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9507 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9509 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9511 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9513 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9514 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9526 strcat(argument, arg.name.string);
9527 strcat(argument, " = ");
9533 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9534 char expString[1024];
9535 OldList * specs = MkList();
9536 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9538 char * string = PrintHexUInt64(arg.expression.ui64);
9539 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9542 ProcessExpressionType(exp);
9543 ComputeExpression(exp);
9544 expString[0] = '\0';
9545 PrintExpression(exp, expString);
9546 strcat(argument, expString);
9548 FreeExpression(exp);
9553 strcat(argument, arg.member.name);
9556 case TemplateParameterType::type:
9558 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9560 if(!strcmp(arg.dataTypeString, "thisclass"))
9561 strcat(argument, thisClassTypeString);
9563 strcat(argument, arg.dataTypeString);
9570 if(paramCount) strcat(templateString, ", ");
9571 if(lastParam != p - 1)
9573 strcat(templateString, param.name);
9574 strcat(templateString, " = ");
9576 strcat(templateString, argument);
9585 int len = strlen(templateString);
9586 if(templateString[len-1] == '>') templateString[len++] = ' ';
9587 templateString[len++] = '>';
9588 templateString[len++] = '\0';
9591 Context context = SetupTemplatesContext(_class);
9592 FreeType(exp.expType);
9593 exp.expType = ProcessTypeString(templateString, false);
9594 FinishTemplatesContext(context);
9598 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9599 exp.type = bracketsExp;
9600 exp.list = MkListOne(MkExpOp(null, '*',
9605 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9606 MkExpBrackets(MkListOne(
9607 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9609 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9611 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9616 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9617 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9619 type = ProcessTemplateParameterType(type.templateParameter);
9622 // TODO: *** This seems to be where we should add method support for all basic types ***
9623 if(type && (type.kind == templateType));
9624 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9625 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9626 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9627 (type.kind == pointerType && type.type.kind == charType)))
9629 Identifier id = exp.member.member;
9630 TypeKind typeKind = type.kind;
9631 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9632 if(typeKind == subClassType && exp.member.exp.type == classExp)
9634 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9635 typeKind = classType;
9640 if(typeKind == intType || typeKind == enumType)
9641 _class = eSystem_FindClass(privateModule, "int");
9644 if(type.kind == classType && type._class && type._class.registered)
9646 _class = type._class.registered;
9648 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9650 _class = FindClass("char *").registered;
9652 else if(type.kind == pointerType)
9654 _class = eSystem_FindClass(privateModule, "uintptr");
9655 FreeType(exp.expType);
9656 exp.expType = ProcessTypeString("uintptr", false);
9657 exp.byReference = true;
9661 char string[1024] = "";
9663 PrintTypeNoConst(type, string, false, true);
9664 classSym = FindClass(string);
9665 if(classSym) _class = classSym.registered;
9673 (exp.member.exp.type == identifierExp &&
9674 !strcmp(exp.member.exp.identifier.string, "this"));*/
9675 Property prop = null;
9676 Method method = null;
9677 DataMember member = null;
9678 Property revConvert = null;
9679 ClassProperty classProp = null;
9681 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9682 exp.member.memberType = propertyMember;
9684 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9685 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9687 if(typeKind != subClassType)
9689 // Prioritize data members over properties for "this"
9690 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9692 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9693 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9695 prop = eClass_FindProperty(_class, id.string, privateModule);
9699 if(!member && !prop)
9700 prop = eClass_FindProperty(_class, id.string, privateModule);
9701 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9702 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9703 exp.member.thisPtr = true;
9705 // Prioritize properties over data members otherwise
9708 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9711 prop = eClass_FindProperty(_class, id.string, null);
9712 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9713 member = eClass_FindDataMember(_class, id.string, null, null, null);
9716 if(!prop && !member)
9718 method = eClass_FindMethod(_class, id.string, null);
9721 prop = eClass_FindProperty(_class, id.string, privateModule);
9722 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9723 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9729 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9736 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9737 method = eClass_FindMethod(_class, id.string, privateModule);
9738 if(!prop && !member && !method)
9740 if(typeKind == subClassType)
9742 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9745 exp.member.memberType = classPropertyMember;
9746 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9750 // Assume this is a class_data member
9751 char structName[1024];
9752 Identifier id = exp.member.member;
9753 Expression classExp = exp.member.exp;
9756 FreeType(classExp.expType);
9757 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9759 strcpy(structName, "__ecereClassData_");
9760 FullClassNameCat(structName, type._class.string, false);
9761 exp.type = pointerExp;
9762 exp.member.member = id;
9764 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9765 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9766 MkExpBrackets(MkListOne(MkExpOp(
9767 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9768 MkExpMember(classExp, MkIdentifier("data"))), '+',
9769 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9774 ProcessExpressionType(exp);
9780 // Check for reverse conversion
9781 // (Convert in an instantiation later, so that we can use
9782 // deep properties system)
9783 Symbol classSym = FindClass(id.string);
9786 Class convertClass = classSym.registered;
9788 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9795 exp.member.memberType = propertyMember;
9797 ProcessPropertyType(prop);
9798 exp.expType = prop.dataType;
9799 if(prop.dataType) prop.dataType.refCount++;
9803 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9805 FreeExpContents(exp);
9806 exp.type = identifierExp;
9807 exp.identifier = MkIdentifier("class");
9808 ProcessExpressionType(exp);
9812 exp.member.memberType = dataMember;
9813 DeclareStruct(_class.fullName, false);
9814 if(!member.dataType)
9816 Context context = SetupTemplatesContext(_class);
9817 member.dataType = ProcessTypeString(member.dataTypeString, false);
9818 FinishTemplatesContext(context);
9820 exp.expType = member.dataType;
9821 if(member.dataType) member.dataType.refCount++;
9825 exp.member.memberType = reverseConversionMember;
9826 exp.expType = MkClassType(revConvert._class.fullName);
9834 exp.type = identifierExp;
9835 exp.identifier = exp.member.member;
9838 exp.member.memberType = methodMember;
9840 if(!method.dataType)
9841 ProcessMethodType(method);
9849 // Tricky spot here... To use instance versus class virtual table
9850 // Put it back to what it was... What did we break?
9852 // Had to put it back for overriding Main of Thread global instance
9854 //exp.expType.methodClass = _class;
9855 exp.expType.methodClass = (id && id._class) ? _class : null;
9857 // Need the actual class used for templated classes
9858 exp.expType.usedClass = _class;
9862 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9864 FreeExpContents(exp);
9865 exp.type = identifierExp;
9866 exp.identifier = MkIdentifier("class");
9867 FreeType(exp.expType);
9868 exp.expType = MkClassType("ecere::com::Class");
9871 yylloc = exp.member.member.loc;
9872 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9874 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9877 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9882 while(tClass && !tClass.templateClass) tClass = tClass.base;
9884 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9887 ClassTemplateParameter curParam = null;
9890 for(sClass = tClass; sClass; sClass = sClass.base)
9893 if(sClass.templateClass) sClass = sClass.templateClass;
9894 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9896 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9898 for(sClass = sClass.base; sClass; sClass = sClass.base)
9899 id += sClass.templateParams.count;
9907 if(curParam && tClass.templateArgs[id].dataTypeString)
9909 ClassTemplateArgument arg = tClass.templateArgs[id];
9910 Context context = SetupTemplatesContext(tClass);
9912 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9913 FreeType(exp.expType);
9914 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9917 if(exp.expType.kind == thisClassType)
9919 FreeType(exp.expType);
9920 exp.expType = ReplaceThisClassType(_class);
9923 if(tClass.templateClass)
9924 exp.expType.passAsTemplate = true;
9925 //exp.expType.refCount++;
9928 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9929 //exp.destType.refCount++;
9931 if(exp.destType.kind == thisClassType)
9933 FreeType(exp.destType);
9934 exp.destType = ReplaceThisClassType(_class);
9938 FinishTemplatesContext(context);
9941 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9942 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9945 ClassTemplateParameter curParam = null;
9948 for(sClass = tClass; sClass; sClass = sClass.base)
9951 if(sClass.templateClass) sClass = sClass.templateClass;
9952 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9954 if(curParam.type == TemplateParameterType::type &&
9955 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9957 for(sClass = sClass.base; sClass; sClass = sClass.base)
9958 id += sClass.templateParams.count;
9968 ClassTemplateArgument arg = tClass.templateArgs[id];
9969 Context context = SetupTemplatesContext(tClass);
9972 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9974 basicType = ProcessTypeString(arg.dataTypeString, false);
9977 if(basicType.kind == thisClassType)
9979 FreeType(basicType);
9980 basicType = ReplaceThisClassType(_class);
9983 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9984 if(tClass.templateClass)
9985 basicType.passAsTemplate = true;
9988 FreeType(exp.expType);
9990 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9991 //exp.expType.refCount++;
9994 exp.destType = exp.expType;
9995 exp.destType.refCount++;
9999 Expression newExp { };
10000 OldList * specs = MkList();
10002 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10004 if(exp.destType) exp.destType.refCount++;
10005 if(exp.expType) exp.expType.refCount++;
10006 exp.type = castExp;
10007 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10008 exp.cast.exp = newExp;
10009 //FreeType(exp.expType);
10010 //exp.expType = null;
10011 //ProcessExpressionType(sourceExp);
10014 FinishTemplatesContext(context);
10017 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10019 Class expClass = exp.expType._class.registered;
10022 Class cClass = null;
10025 int paramCount = 0;
10026 int lastParam = -1;
10027 char templateString[1024];
10028 ClassTemplateParameter param;
10029 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10030 while(cClass != expClass)
10033 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10036 for(param = cClass.templateParams.first; param; param = param.next)
10038 Class cClassCur = null;
10041 ClassTemplateParameter paramCur = null;
10042 ClassTemplateArgument arg;
10043 while(cClassCur != tClass && !paramCur)
10046 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10047 cClassCur = sClassCur;
10049 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10051 if(!strcmp(paramCur.name, param.name))
10059 if(paramCur && paramCur.type == TemplateParameterType::type)
10060 arg = tClass.templateArgs[cp];
10062 arg = expClass.templateArgs[p];
10065 char argument[256];
10066 argument[0] = '\0';
10069 strcat(argument, arg.name.string);
10070 strcat(argument, " = ");
10076 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10077 char expString[1024];
10078 OldList * specs = MkList();
10079 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10081 char * string = PrintHexUInt64(arg.expression.ui64);
10082 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10085 ProcessExpressionType(exp);
10086 ComputeExpression(exp);
10087 expString[0] = '\0';
10088 PrintExpression(exp, expString);
10089 strcat(argument, expString);
10091 FreeExpression(exp);
10096 strcat(argument, arg.member.name);
10099 case TemplateParameterType::type:
10101 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10102 strcat(argument, arg.dataTypeString);
10108 if(paramCount) strcat(templateString, ", ");
10109 if(lastParam != p - 1)
10111 strcat(templateString, param.name);
10112 strcat(templateString, " = ");
10114 strcat(templateString, argument);
10123 int len = strlen(templateString);
10124 if(templateString[len-1] == '>') templateString[len++] = ' ';
10125 templateString[len++] = '>';
10126 templateString[len++] = '\0';
10129 FreeType(exp.expType);
10131 Context context = SetupTemplatesContext(tClass);
10132 exp.expType = ProcessTypeString(templateString, false);
10133 FinishTemplatesContext(context);
10140 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10142 else if(type && (type.kind == structType || type.kind == unionType))
10144 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10147 exp.expType = memberType;
10149 memberType.refCount++;
10154 char expString[10240];
10155 expString[0] = '\0';
10156 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10157 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10160 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10162 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10164 Identifier id = exp.member.member;
10165 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10168 FreeType(exp.expType);
10169 exp.expType = ReplaceThisClassType(_class);
10173 yylloc = oldyylloc;
10176 // Convert x->y into (*x).y
10179 Type destType = exp.destType;
10181 // DOING THIS LATER NOW...
10182 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10184 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10185 /* TODO: Name Space Fix ups
10186 if(!exp.member.member.classSym)
10187 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10191 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10192 exp.type = memberExp;
10195 ProcessExpressionType(exp);
10202 //ComputeExpression(exp);
10204 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10205 if(classSym && classSym.registered)
10207 if(classSym.registered.type == noHeadClass)
10211 DeclareStruct(classSym.string, false);
10212 FreeSpecifier(exp._class);
10213 exp.type = typeSizeExp;
10214 FullClassNameCat(name, classSym.string, false);
10215 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10219 if(classSym.registered.fixed)
10221 FreeSpecifier(exp._class);
10222 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10223 exp.type = constantExp;
10227 char className[1024];
10228 strcpy(className, "__ecereClass_");
10229 FullClassNameCat(className, classSym.string, true);
10230 MangleClassName(className);
10232 DeclareClass(classSym, className);
10234 FreeExpContents(exp);
10235 exp.type = pointerExp;
10236 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10237 exp.member.member = MkIdentifier("structSize");
10247 // exp.isConstant = true;
10252 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10259 exp.isConstant = true;
10261 DeclareType(type, false, false);
10267 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10269 FreeType(exp.cast.exp.destType);
10270 exp.cast.exp.destType = type;
10272 ProcessExpressionType(exp.cast.exp);
10274 exp.expType = type;
10277 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10278 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10280 void * prev = exp.prev, * next = exp.next;
10281 Type expType = exp.cast.exp.destType;
10282 Expression castExp = exp.cast.exp;
10283 Type destType = exp.destType;
10285 if(expType) expType.refCount++;
10287 //FreeType(exp.destType);
10288 FreeType(exp.expType);
10289 FreeTypeName(exp.cast.typeName);
10292 FreeType(exp.expType);
10293 FreeType(exp.destType);
10295 exp.expType = expType;
10296 exp.destType = destType;
10306 exp.isConstant = exp.cast.exp.isConstant;
10311 case extensionInitializerExp:
10313 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10314 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10315 // ProcessInitializer(exp.initializer.initializer, type);
10316 exp.expType = type;
10321 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10322 ProcessExpressionType(exp.vaArg.exp);
10323 exp.expType = type;
10329 exp.isConstant = true;
10331 FreeType(exp.cond.cond.destType);
10332 exp.cond.cond.destType = MkClassType("bool");
10333 exp.cond.cond.destType.truth = true;
10334 ProcessExpressionType(exp.cond.cond);
10335 if(!exp.cond.cond.isConstant)
10336 exp.isConstant = false;
10337 for(e = exp.cond.exp->first; e; e = e.next)
10341 FreeType(e.destType);
10342 e.destType = exp.destType;
10343 if(e.destType) e.destType.refCount++;
10345 ProcessExpressionType(e);
10348 exp.expType = e.expType;
10349 if(e.expType) e.expType.refCount++;
10352 exp.isConstant = false;
10355 FreeType(exp.cond.elseExp.destType);
10356 // Added this check if we failed to find an expType
10357 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10360 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10362 if(exp.cond.elseExp.destType)
10363 exp.cond.elseExp.destType.refCount++;
10364 ProcessExpressionType(exp.cond.elseExp);
10366 // FIXED THIS: Was done before calling process on elseExp
10367 if(!exp.cond.elseExp.isConstant)
10368 exp.isConstant = false;
10371 case extensionCompoundExp:
10373 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10375 Statement last = exp.compound.compound.statements->last;
10376 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10378 ((Expression)last.expressions->last).destType = exp.destType;
10380 exp.destType.refCount++;
10382 ProcessStatement(exp.compound);
10383 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10385 exp.expType.refCount++;
10391 Specifier spec = exp._classExp.specifiers->first;
10392 if(spec && spec.type == nameSpecifier)
10394 exp.expType = MkClassType(spec.name);
10395 exp.expType.kind = subClassType;
10396 exp.byReference = true;
10400 exp.expType = MkClassType("ecere::com::Class");
10401 exp.byReference = true;
10407 Class _class = thisClass ? thisClass : currentClass;
10410 Identifier id = exp.classData.id;
10411 char structName[1024];
10412 Expression classExp;
10413 strcpy(structName, "__ecereClassData_");
10414 FullClassNameCat(structName, _class.fullName, false);
10415 exp.type = pointerExp;
10416 exp.member.member = id;
10417 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10418 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10420 classExp = MkExpIdentifier(MkIdentifier("class"));
10422 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10423 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10424 MkExpBrackets(MkListOne(MkExpOp(
10425 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10426 MkExpMember(classExp, MkIdentifier("data"))), '+',
10427 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10430 ProcessExpressionType(exp);
10438 char * typeString = null;
10439 char typeStringBuf[1024];
10440 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10441 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10443 Class templateClass = exp.destType._class.registered;
10444 typeString = templateClass.templateArgs[2].dataTypeString;
10448 // Guess type from expressions in the array
10450 for(e = exp.list->first; e; e = e.next)
10452 ProcessExpressionType(e);
10455 if(!type) { type = e.expType; type.refCount++; }
10458 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10459 if(!MatchTypeExpression(e, type, null, false))
10465 e = exp.list->first;
10466 ProcessExpressionType(e);
10469 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10470 if(!MatchTypeExpression(e, type, null, false))
10472 FreeType(e.expType);
10483 FreeType(e.expType);
10490 typeStringBuf[0] = '\0';
10491 PrintTypeNoConst(type, typeStringBuf, false, true);
10492 typeString = typeStringBuf;
10500 (Container)& (struct BuiltInContainer)
10502 ._vTbl = class(BuiltInContainer)._vTbl,
10503 ._class = class(BuiltInContainer),
10505 .data = (int[]){ 1, 7, 3, 4, 5 },
10507 .type = class(int),
10510 char templateString[1024];
10511 OldList * initializers = MkList();
10512 OldList * structInitializers = MkList();
10513 OldList * specs = MkList();
10515 Declarator decl = SpecDeclFromString(typeString, specs, null);
10516 sprintf(templateString, "Container<%s>", typeString);
10521 type = ProcessTypeString(typeString, false);
10522 while(e = exp.list->first)
10524 exp.list->Remove(e);
10527 ProcessExpressionType(e);
10528 ListAdd(initializers, MkInitializerAssignment(e));
10534 DeclareStruct("ecere::com::BuiltInContainer", false);
10536 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10537 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10538 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10539 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10540 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10541 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10542 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10543 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10544 MkInitializerList(initializers))));
10545 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10546 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10547 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10548 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10549 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10550 exp.expType = ProcessTypeString(templateString, false);
10551 exp.type = bracketsExp;
10552 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10554 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10555 MkInitializerList(structInitializers)))));
10556 ProcessExpressionType(expExt);
10560 exp.expType = ProcessTypeString("Container", false);
10561 Compiler_Error($"Couldn't determine type of array elements\n");
10567 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10569 FreeType(exp.expType);
10570 exp.expType = ReplaceThisClassType(thisClass);
10573 // Resolve structures here
10574 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10576 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10577 // TODO: Fix members reference...
10580 if(exp.expType.kind != enumType)
10583 String enumName = CopyString(exp.expType.enumName);
10585 // Fixed a memory leak on self-referencing C structs typedefs
10586 // by instantiating a new type rather than simply copying members
10587 // into exp.expType
10588 FreeType(exp.expType);
10589 exp.expType = Type { };
10590 exp.expType.kind = symbol.type.kind;
10591 exp.expType.refCount++;
10592 exp.expType.enumName = enumName;
10594 exp.expType.members = symbol.type.members;
10595 for(member = symbol.type.members.first; member; member = member.next)
10601 for(member = symbol.type.members.first; member; member = member.next)
10603 NamedLink value { name = CopyString(member.name) };
10604 exp.expType.members.Add(value);
10611 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10612 else if(exp.destType && !exp.destType.keepCast)
10614 if(!CheckExpressionType(exp, exp.destType, false))
10616 if(!exp.destType.count || unresolved)
10621 if(exp.destType.kind != ellipsisType)
10627 char expString[10240];
10628 expString[0] = '\0';
10630 PrintType(exp.destType, type2, false, true);
10632 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10634 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10635 else if(exp.type != dummyExp)
10636 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10641 char expString[10240] ;
10642 expString[0] = '\0';
10643 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10646 Compiler_Error($"unresolved identifier %s\n", expString);
10647 else if(exp.type != dummyExp)
10648 Compiler_Error($"couldn't determine type of %s\n", expString);
10659 PrintType(exp.expType, type1, false, true);
10660 PrintType(exp.destType, type2, false, true);
10663 //CheckExpressionType(exp, exp.destType, false);
10665 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10666 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10667 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10670 char expString[10240];
10671 expString[0] = '\0';
10672 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10675 CheckExpressionType(exp, exp.destType, false);
10677 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10678 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10679 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10681 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10682 FreeType(exp.expType);
10683 exp.destType.refCount++;
10684 exp.expType = exp.destType;
10689 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10691 Expression newExp { };
10692 char typeString[1024];
10693 OldList * specs = MkList();
10696 typeString[0] = '\0';
10700 if(exp.expType) exp.expType.refCount++;
10701 if(exp.expType) exp.expType.refCount++;
10702 exp.type = castExp;
10703 newExp.destType = exp.expType;
10705 PrintType(exp.expType, typeString, false, false);
10706 decl = SpecDeclFromString(typeString, specs, null);
10708 exp.cast.typeName = MkTypeName(specs, decl);
10709 exp.cast.exp = newExp;
10712 else if(unresolved)
10714 if(exp.identifier._class && exp.identifier._class.name)
10715 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10716 else if(exp.identifier.string && exp.identifier.string[0])
10717 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10719 else if(!exp.expType && exp.type != dummyExp)
10721 char expString[10240];
10722 expString[0] = '\0';
10723 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10724 Compiler_Error($"couldn't determine type of %s\n", expString);
10727 // Let's try to support any_object & typed_object here:
10729 ApplyAnyObjectLogic(exp);
10731 // Mark nohead classes as by reference, unless we're casting them to an integral type
10732 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10733 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10734 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10735 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10737 exp.byReference = true;
10739 yylloc = oldyylloc;
10742 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10744 // THIS CODE WILL FIND NEXT MEMBER...
10747 *curMember = (*curMember).next;
10749 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10751 *curMember = subMemberStack[--(*subMemberStackPos)];
10752 *curMember = (*curMember).next;
10755 // SKIP ALL PROPERTIES HERE...
10756 while((*curMember) && (*curMember).isProperty)
10757 *curMember = (*curMember).next;
10759 if(subMemberStackPos)
10761 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10763 subMemberStack[(*subMemberStackPos)++] = *curMember;
10765 *curMember = (*curMember).members.first;
10766 while(*curMember && (*curMember).isProperty)
10767 *curMember = (*curMember).next;
10775 if(subMemberStackPos && *subMemberStackPos)
10777 *curMember = subMemberStack[--(*subMemberStackPos)];
10778 *curMember = (*curMember).next;
10782 Class lastCurClass = *curClass;
10784 if(*curClass == _class) break; // REACHED THE END
10786 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10787 *curMember = (*curClass).membersAndProperties.first;
10790 while((*curMember) && (*curMember).isProperty)
10791 *curMember = (*curMember).next;
10792 if(subMemberStackPos)
10794 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10796 subMemberStack[(*subMemberStackPos)++] = *curMember;
10798 *curMember = (*curMember).members.first;
10799 while(*curMember && (*curMember).isProperty)
10800 *curMember = (*curMember).next;
10808 static void ProcessInitializer(Initializer init, Type type)
10812 case expInitializer:
10813 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10815 // TESTING THIS FOR SHUTTING = 0 WARNING
10816 if(init.exp && !init.exp.destType)
10818 FreeType(init.exp.destType);
10819 init.exp.destType = type;
10820 if(type) type.refCount++;
10824 ProcessExpressionType(init.exp);
10825 init.isConstant = init.exp.isConstant;
10831 Expression exp = init.exp;
10832 Instantiation inst = exp.instance;
10833 MembersInit members;
10835 init.type = listInitializer;
10836 init.list = MkList();
10840 for(members = inst.members->first; members; members = members.next)
10842 if(members.type == dataMembersInit)
10845 for(member = members.dataMembers->first; member; member = member.next)
10847 ListAdd(init.list, member.initializer);
10848 member.initializer = null;
10851 // Discard all MembersInitMethod
10854 FreeExpression(exp);
10856 case listInitializer:
10859 Type initializerType = null;
10860 Class curClass = null;
10861 DataMember curMember = null;
10862 DataMember subMemberStack[256];
10863 int subMemberStackPos = 0;
10865 if(type && type.kind == arrayType)
10866 initializerType = Dereference(type);
10867 else if(type && (type.kind == structType || type.kind == unionType))
10868 initializerType = type.members.first;
10870 for(i = init.list->first; i; i = i.next)
10872 if(type && type.kind == classType && type._class && type._class.registered)
10874 // 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)
10875 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10876 // TODO: Generate error on initializing a private data member this way from another module...
10879 if(!curMember.dataType)
10880 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10881 initializerType = curMember.dataType;
10884 ProcessInitializer(i, initializerType);
10885 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10886 initializerType = initializerType.next;
10888 init.isConstant = false;
10891 if(type && type.kind == arrayType)
10892 FreeType(initializerType);
10894 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10896 Compiler_Error($"Assigning list initializer to non list\n");
10903 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10907 case baseSpecifier:
10909 if(spec.specifier == THISCLASS)
10913 spec.type = nameSpecifier;
10914 spec.name = ReplaceThisClass(thisClass);
10915 spec.symbol = FindClass(spec.name);
10916 ProcessSpecifier(spec, declareStruct);
10921 case nameSpecifier:
10923 Symbol symbol = FindType(curContext, spec.name);
10925 DeclareType(symbol.type, true, true);
10926 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10927 DeclareStruct(spec.name, false);
10930 case enumSpecifier:
10935 for(e = spec.list->first; e; e = e.next)
10938 ProcessExpressionType(e.exp);
10943 case structSpecifier:
10944 case unionSpecifier:
10946 if(spec.definitions)
10949 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10951 ProcessClass(spec.definitions, symbol);
10954 for(def = spec.definitions->first; def; def = def.next)
10956 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10957 ProcessDeclaration(def.decl);
10964 case classSpecifier:
10966 Symbol classSym = FindClass(spec.name);
10967 if(classSym && classSym.registered && classSym.registered.type == structClass)
10968 DeclareStruct(spec.name, false);
10976 static void ProcessDeclarator(Declarator decl)
10980 case identifierDeclarator:
10981 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10983 FreeSpecifier(decl.identifier._class);
10984 decl.identifier._class = null;
10987 case arrayDeclarator:
10989 ProcessExpressionType(decl.array.exp);
10990 case structDeclarator:
10991 case bracketsDeclarator:
10992 case functionDeclarator:
10993 case pointerDeclarator:
10994 case extendedDeclarator:
10995 case extendedDeclaratorEnd:
10996 if(decl.declarator)
10997 ProcessDeclarator(decl.declarator);
10998 if(decl.type == functionDeclarator)
11000 Identifier id = GetDeclId(decl);
11001 if(id && id._class)
11005 qualifiers = MkListOne(id._class);
11008 if(!decl.function.parameters)
11009 decl.function.parameters = MkList();
11010 decl.function.parameters->Insert(null, param);
11013 if(decl.function.parameters)
11017 for(param = decl.function.parameters->first; param; param = param.next)
11019 if(param.qualifiers && param.qualifiers->first)
11021 Specifier spec = param.qualifiers->first;
11022 if(spec && spec.specifier == TYPED_OBJECT)
11024 Declarator d = param.declarator;
11027 qualifiers = MkListOne(MkSpecifier(VOID));
11028 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11031 FreeList(param.qualifiers, FreeSpecifier);
11033 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11034 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11036 decl.function.parameters->Insert(param, newParam);
11039 else if(spec && spec.specifier == ANY_OBJECT)
11041 Declarator d = param.declarator;
11043 FreeList(param.qualifiers, FreeSpecifier);
11045 param.qualifiers = MkListOne(MkSpecifier(VOID));
11046 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11048 else if(spec.specifier == THISCLASS)
11052 spec.type = nameSpecifier;
11053 spec.name = ReplaceThisClass(thisClass);
11054 spec.symbol = FindClass(spec.name);
11055 ProcessSpecifier(spec, false);
11060 if(param.declarator)
11061 ProcessDeclarator(param.declarator);
11069 static void ProcessDeclaration(Declaration decl)
11074 case initDeclaration:
11076 bool declareStruct = false;
11078 lineNum = decl.pos.line;
11079 column = decl.pos.col;
11082 if(decl.declarators)
11086 for(d = decl.declarators->first; d; d = d.next)
11088 Type type, subType;
11089 ProcessDeclarator(d.declarator);
11091 type = ProcessType(decl.specifiers, d.declarator);
11095 ProcessInitializer(d.initializer, type);
11097 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11099 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11100 d.initializer.exp.type == instanceExp)
11102 if(type.kind == classType && type._class ==
11103 d.initializer.exp.expType._class)
11105 Instantiation inst = d.initializer.exp.instance;
11106 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11108 d.initializer.exp.instance = null;
11109 if(decl.specifiers)
11110 FreeList(decl.specifiers, FreeSpecifier);
11111 FreeList(decl.declarators, FreeInitDeclarator);
11115 decl.type = instDeclaration;
11120 for(subType = type; subType;)
11122 if(subType.kind == classType)
11124 declareStruct = true;
11127 else if(subType.kind == pointerType)
11129 else if(subType.kind == arrayType)
11130 subType = subType.arrayType;
11140 if(decl.specifiers)
11143 for(s = decl.specifiers->first; s; s = s.next)
11145 ProcessSpecifier(s, declareStruct);
11150 case instDeclaration:
11152 ProcessInstantiationType(decl.inst);
11155 case structDeclaration:
11159 bool declareStruct = false;
11161 if(decl.declarators)
11163 for(d = decl.declarators->first; d; d = d.next)
11165 Type type = ProcessType(decl.specifiers, d.declarator);
11167 ProcessDeclarator(d);
11168 for(subType = type; subType;)
11170 if(subType.kind == classType)
11172 declareStruct = true;
11175 else if(subType.kind == pointerType)
11177 else if(subType.kind == arrayType)
11178 subType = subType.arrayType;
11185 if(decl.specifiers)
11187 for(spec = decl.specifiers->first; spec; spec = spec.next)
11188 ProcessSpecifier(spec, declareStruct);
11195 static FunctionDefinition curFunction;
11197 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11199 char propName[1024], propNameM[1024];
11200 char getName[1024], setName[1024];
11203 DeclareProperty(prop, setName, getName);
11205 // eInstance_FireWatchers(object, prop);
11206 strcpy(propName, "__ecereProp_");
11207 FullClassNameCat(propName, prop._class.fullName, false);
11208 strcat(propName, "_");
11209 // strcat(propName, prop.name);
11210 FullClassNameCat(propName, prop.name, true);
11211 MangleClassName(propName);
11213 strcpy(propNameM, "__ecerePropM_");
11214 FullClassNameCat(propNameM, prop._class.fullName, false);
11215 strcat(propNameM, "_");
11216 // strcat(propNameM, prop.name);
11217 FullClassNameCat(propNameM, prop.name, true);
11218 MangleClassName(propNameM);
11220 if(prop.isWatchable)
11223 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11224 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11225 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11228 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11229 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11230 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11236 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11237 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11238 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11241 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11242 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11243 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11246 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11247 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11248 curFunction.propSet.fireWatchersDone = true;
11251 static void ProcessStatement(Statement stmt)
11255 lineNum = stmt.pos.line;
11256 column = stmt.pos.col;
11261 ProcessStatement(stmt.labeled.stmt);
11264 // This expression should be constant...
11265 if(stmt.caseStmt.exp)
11267 FreeType(stmt.caseStmt.exp.destType);
11268 stmt.caseStmt.exp.destType = curSwitchType;
11269 if(curSwitchType) curSwitchType.refCount++;
11270 ProcessExpressionType(stmt.caseStmt.exp);
11271 ComputeExpression(stmt.caseStmt.exp);
11273 if(stmt.caseStmt.stmt)
11274 ProcessStatement(stmt.caseStmt.stmt);
11278 if(stmt.compound.context)
11283 Statement prevCompound = curCompound;
11284 Context prevContext = curContext;
11286 if(!stmt.compound.isSwitch)
11287 curCompound = stmt;
11288 curContext = stmt.compound.context;
11290 if(stmt.compound.declarations)
11292 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11293 ProcessDeclaration(decl);
11295 if(stmt.compound.statements)
11297 for(s = stmt.compound.statements->first; s; s = s.next)
11298 ProcessStatement(s);
11301 curContext = prevContext;
11302 curCompound = prevCompound;
11306 case expressionStmt:
11309 if(stmt.expressions)
11311 for(exp = stmt.expressions->first; exp; exp = exp.next)
11312 ProcessExpressionType(exp);
11320 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11321 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11322 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11323 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11325 ProcessExpressionType(exp);
11327 if(stmt.ifStmt.stmt)
11328 ProcessStatement(stmt.ifStmt.stmt);
11329 if(stmt.ifStmt.elseStmt)
11330 ProcessStatement(stmt.ifStmt.elseStmt);
11335 Type oldSwitchType = curSwitchType;
11336 if(stmt.switchStmt.exp)
11339 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11349 e.exp.destType = destType;
11352 ProcessExpressionType(exp);
11355 curSwitchType = exp.expType;
11358 ProcessStatement(stmt.switchStmt.stmt);
11359 curSwitchType = oldSwitchType;
11364 if(stmt.whileStmt.exp)
11368 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11369 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11370 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11371 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11373 ProcessExpressionType(exp);
11376 if(stmt.whileStmt.stmt)
11377 ProcessStatement(stmt.whileStmt.stmt);
11382 if(stmt.doWhile.exp)
11386 if(stmt.doWhile.exp->last)
11388 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11389 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11390 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11392 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11394 ProcessExpressionType(exp);
11397 if(stmt.doWhile.stmt)
11398 ProcessStatement(stmt.doWhile.stmt);
11404 if(stmt.forStmt.init)
11405 ProcessStatement(stmt.forStmt.init);
11407 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11409 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11410 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11411 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11414 if(stmt.forStmt.check)
11415 ProcessStatement(stmt.forStmt.check);
11416 if(stmt.forStmt.increment)
11418 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11419 ProcessExpressionType(exp);
11422 if(stmt.forStmt.stmt)
11423 ProcessStatement(stmt.forStmt.stmt);
11428 Identifier id = stmt.forEachStmt.id;
11429 OldList * exp = stmt.forEachStmt.exp;
11430 OldList * filter = stmt.forEachStmt.filter;
11431 Statement block = stmt.forEachStmt.stmt;
11432 char iteratorType[1024];
11435 bool isBuiltin = exp && exp->last &&
11436 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11437 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11438 Expression arrayExp;
11439 char * typeString = null;
11440 int builtinCount = 0;
11442 for(e = exp ? exp->first : null; e; e = e.next)
11446 FreeType(e.destType);
11447 e.destType = ProcessTypeString("Container", false);
11449 if(!isBuiltin || e.next)
11450 ProcessExpressionType(e);
11453 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11454 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11455 eClass_IsDerived(source._class.registered, containerClass)))
11457 Class _class = source ? source._class.registered : null;
11459 Expression expIt = null;
11460 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11461 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11462 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11463 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11464 stmt.type = compoundStmt;
11466 stmt.compound.context = Context { };
11467 stmt.compound.context.parent = curContext;
11468 curContext = stmt.compound.context;
11470 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11472 Class mapClass = eSystem_FindClass(privateModule, "Map");
11473 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11474 isCustomAVLTree = true;
11475 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11477 else if(eClass_IsDerived(source._class.registered, mapClass))
11480 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11481 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11483 Class listClass = eSystem_FindClass(privateModule, "List");
11485 isList = eClass_IsDerived(source._class.registered, listClass);
11491 OldList * specs = MkList();
11492 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11493 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11494 stmt.compound.declarations = MkListOne(
11495 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11496 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11497 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11498 MkInitializerAssignment(MkExpBrackets(exp))))));
11503 char typeStringBuf[1024];
11505 // TODO: Merge this code?
11506 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11507 if(((Expression)exp->last).type == castExp)
11509 TypeName typeName = ((Expression)exp->last).cast.typeName;
11511 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11514 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11515 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11516 arrayExp.destType._class.registered.templateArgs)
11518 Class templateClass = arrayExp.destType._class.registered;
11519 typeString = templateClass.templateArgs[2].dataTypeString;
11521 else if(arrayExp.list)
11523 // Guess type from expressions in the array
11525 for(e = arrayExp.list->first; e; e = e.next)
11527 ProcessExpressionType(e);
11530 if(!type) { type = e.expType; type.refCount++; }
11533 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11534 if(!MatchTypeExpression(e, type, null, false))
11540 e = arrayExp.list->first;
11541 ProcessExpressionType(e);
11544 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11545 if(!MatchTypeExpression(e, type, null, false))
11547 FreeType(e.expType);
11558 FreeType(e.expType);
11565 typeStringBuf[0] = '\0';
11566 PrintType(type, typeStringBuf, false, true);
11567 typeString = typeStringBuf;
11573 OldList * initializers = MkList();
11575 OldList * specs = MkList();
11580 builtinCount = arrayExp.list->count;
11581 type = ProcessTypeString(typeString, false);
11582 while(e = arrayExp.list->first)
11584 arrayExp.list->Remove(e);
11587 ProcessExpressionType(e);
11588 ListAdd(initializers, MkInitializerAssignment(e));
11591 delete arrayExp.list;
11593 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11594 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11595 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11597 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11599 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11600 ), MkInitializerList(initializers)))));
11601 FreeList(exp, FreeExpression);
11605 arrayExp.expType = ProcessTypeString("Container", false);
11606 Compiler_Error($"Couldn't determine type of array elements\n");
11611 OldList * specs = MkList();
11613 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11614 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11615 stmt.compound.declarations = MkListOne(
11616 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11617 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11618 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11619 MkInitializerAssignment(MkExpBrackets(exp))))));
11622 else if(isLinkList && !isList)
11625 OldList * specs = MkList();
11626 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11627 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11628 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11629 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11630 MkInitializerAssignment(MkExpBrackets(exp))))));
11632 /*else if(isCustomAVLTree)
11635 OldList * specs = MkList();
11636 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11637 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11638 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11639 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11640 MkInitializerAssignment(MkExpBrackets(exp))))));
11642 else if(_class.templateArgs)
11645 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11647 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11649 stmt.compound.declarations = MkListOne(
11650 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11651 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11652 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11654 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11658 // Reparent sub-contexts in this statement
11662 if(block.compound.context)
11663 block.compound.context.parent = stmt.compound.context;
11666 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11667 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11668 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11669 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11672 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11673 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11676 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11677 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11680 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11681 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11684 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11685 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11688 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11689 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11691 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11694 case expressionStmt:
11700 case badDeclarationStmt:
11701 case fireWatchersStmt:
11702 case stopWatchingStmt:
11709 block = MkIfStmt(filter, block, null);
11713 stmt.compound.statements = MkListOne(MkForStmt(
11714 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11715 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11716 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11717 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11719 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11720 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11721 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11726 //OldList * specs = MkList();
11727 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11729 sprintf(count, "%d", builtinCount);
11731 stmt.compound.statements = MkListOne(MkForStmt(
11732 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11733 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11734 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11735 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11739 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11740 stmt.compound.statements = MkListOne(MkForStmt(
11741 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11742 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11743 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11744 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11747 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11748 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11749 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11751 else if(isLinkList && !isList)
11753 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11754 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11755 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11756 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11758 stmt.compound.statements = MkListOne(MkForStmt(
11759 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11760 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11761 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11766 OldList * specs = MkList();
11767 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11768 stmt.compound.statements = MkListOne(MkForStmt(
11769 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11770 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11771 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11772 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11773 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11776 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11777 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11778 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11780 /*else if(isCustomAVLTree)
11782 stmt.compound.statements = MkListOne(MkForStmt(
11783 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11784 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11785 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11786 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11789 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11790 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11791 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11795 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11796 MkIdentifier("Next")), null)), block));
11798 ProcessExpressionType(expIt);
11799 if(stmt.compound.declarations->first)
11800 ProcessDeclaration(stmt.compound.declarations->first);
11803 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11805 ProcessStatement(stmt);
11806 curContext = stmt.compound.context.parent;
11811 Compiler_Error($"Expression is not a container\n");
11824 if(stmt.expressions)
11826 for(exp = stmt.expressions->first; exp; exp = exp.next)
11830 if(curFunction && !curFunction.type)
11831 curFunction.type = ProcessType(
11832 curFunction.specifiers, curFunction.declarator);
11833 FreeType(exp.destType);
11834 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11835 if(exp.destType) exp.destType.refCount++;
11837 ProcessExpressionType(exp);
11842 case badDeclarationStmt:
11844 ProcessDeclaration(stmt.decl);
11850 if(stmt.asmStmt.inputFields)
11852 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11853 if(field.expression)
11854 ProcessExpressionType(field.expression);
11856 if(stmt.asmStmt.outputFields)
11858 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11859 if(field.expression)
11860 ProcessExpressionType(field.expression);
11862 if(stmt.asmStmt.clobberedFields)
11864 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11866 if(field.expression)
11867 ProcessExpressionType(field.expression);
11874 PropertyWatch propWatch;
11875 OldList * watches = stmt._watch.watches;
11876 Expression object = stmt._watch.object;
11877 Expression watcher = stmt._watch.watcher;
11879 ProcessExpressionType(watcher);
11881 ProcessExpressionType(object);
11885 if(watcher || thisClass)
11887 External external = curExternal;
11888 Context context = curContext;
11890 stmt.type = expressionStmt;
11891 stmt.expressions = MkList();
11893 curExternal = external.prev;
11895 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11897 ClassFunction func;
11898 char watcherName[1024];
11899 Class watcherClass = watcher ?
11900 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11901 External createdExternal;
11903 // Create a declaration above
11904 External externalDecl = MkExternalDeclaration(null);
11905 ast->Insert(curExternal.prev, externalDecl);
11907 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11908 if(propWatch.deleteWatch)
11909 strcat(watcherName, "_delete");
11913 for(propID = propWatch.properties->first; propID; propID = propID.next)
11915 strcat(watcherName, "_");
11916 strcat(watcherName, propID.string);
11920 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11922 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11923 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11924 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11925 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11926 ProcessClassFunctionBody(func, propWatch.compound);
11927 propWatch.compound = null;
11929 //afterExternal = afterExternal ? afterExternal : curExternal;
11931 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11932 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11934 createdExternal.symbol.idCode = external.symbol.idCode;
11936 curExternal = createdExternal;
11937 ProcessFunction(createdExternal.function);
11940 // Create a declaration above
11942 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11943 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11944 externalDecl.declaration = decl;
11945 if(decl.symbol && !decl.symbol.pointerExternal)
11946 decl.symbol.pointerExternal = externalDecl;
11949 if(propWatch.deleteWatch)
11951 OldList * args = MkList();
11952 ListAdd(args, CopyExpression(object));
11953 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11954 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11955 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11959 Class _class = object.expType._class.registered;
11962 for(propID = propWatch.properties->first; propID; propID = propID.next)
11964 char propName[1024];
11965 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11968 char getName[1024], setName[1024];
11969 OldList * args = MkList();
11971 DeclareProperty(prop, setName, getName);
11973 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11974 strcpy(propName, "__ecereProp_");
11975 FullClassNameCat(propName, prop._class.fullName, false);
11976 strcat(propName, "_");
11977 // strcat(propName, prop.name);
11978 FullClassNameCat(propName, prop.name, true);
11980 ListAdd(args, CopyExpression(object));
11981 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11982 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11983 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11985 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11988 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11993 Compiler_Error($"Invalid watched object\n");
11996 curExternal = external;
11997 curContext = context;
12000 FreeExpression(watcher);
12002 FreeExpression(object);
12003 FreeList(watches, FreePropertyWatch);
12006 Compiler_Error($"No observer specified and not inside a _class\n");
12010 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12012 ProcessStatement(propWatch.compound);
12018 case fireWatchersStmt:
12020 OldList * watches = stmt._watch.watches;
12021 Expression object = stmt._watch.object;
12023 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12024 // printf("%X\n", watches);
12025 // printf("%X\n", stmt._watch.watches);
12027 ProcessExpressionType(object);
12032 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12038 stmt.type = expressionStmt;
12039 stmt.expressions = MkList();
12041 // Check if we're inside a property set
12042 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12044 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12048 //Compiler_Error($"No property specified and not inside a property set\n");
12052 for(propID = watches->first; propID; propID = propID.next)
12054 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12057 CreateFireWatcher(prop, object, stmt);
12060 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12065 // Fire all properties!
12068 for(base = _class; base; base = base.base)
12070 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12072 if(prop.isProperty && prop.isWatchable)
12074 CreateFireWatcher(prop, object, stmt);
12081 FreeExpression(object);
12082 FreeList(watches, FreeIdentifier);
12085 Compiler_Error($"Invalid object specified and not inside a class\n");
12089 case stopWatchingStmt:
12091 OldList * watches = stmt._watch.watches;
12092 Expression object = stmt._watch.object;
12093 Expression watcher = stmt._watch.watcher;
12096 ProcessExpressionType(object);
12098 ProcessExpressionType(watcher);
12101 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12103 if(watcher || thisClass)
12109 stmt.type = expressionStmt;
12110 stmt.expressions = MkList();
12115 // eInstance_StopWatching(object, null, watcher);
12117 ListAdd(args, CopyExpression(object));
12118 ListAdd(args, MkExpConstant("0"));
12119 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12120 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12124 for(propID = watches->first; propID; propID = propID.next)
12126 char propName[1024];
12127 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12130 char getName[1024], setName[1024];
12131 OldList * args = MkList();
12133 DeclareProperty(prop, setName, getName);
12135 // eInstance_StopWatching(object, prop, watcher);
12136 strcpy(propName, "__ecereProp_");
12137 FullClassNameCat(propName, prop._class.fullName, false);
12138 strcat(propName, "_");
12139 // strcat(propName, prop.name);
12140 FullClassNameCat(propName, prop.name, true);
12141 MangleClassName(propName);
12143 ListAdd(args, CopyExpression(object));
12144 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12145 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12146 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12149 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
12154 FreeExpression(object);
12156 FreeExpression(watcher);
12157 FreeList(watches, FreeIdentifier);
12160 Compiler_Error($"Invalid object specified and not inside a class\n");
12163 Compiler_Error($"No observer specified and not inside a class\n");
12170 static void ProcessFunction(FunctionDefinition function)
12172 Identifier id = GetDeclId(function.declarator);
12173 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12174 Type type = symbol ? symbol.type : null;
12175 Class oldThisClass = thisClass;
12176 Context oldTopContext = topContext;
12178 yylloc = function.loc;
12179 // Process thisClass
12181 if(type && type.thisClass)
12183 Symbol classSym = type.thisClass;
12184 Class _class = type.thisClass.registered;
12185 char className[1024];
12186 char structName[1024];
12187 Declarator funcDecl;
12190 bool typedObject = false;
12192 if(_class && !_class.base)
12194 _class = currentClass;
12195 if(_class && !_class.symbol)
12196 _class.symbol = FindClass(_class.fullName);
12197 classSym = _class ? _class.symbol : null;
12198 typedObject = true;
12201 thisClass = _class;
12203 if(inCompiler && _class)
12205 if(type.kind == functionType)
12207 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12209 //TypeName param = symbol.type.params.first;
12210 Type param = symbol.type.params.first;
12211 symbol.type.params.Remove(param);
12212 //FreeTypeName(param);
12215 if(type.classObjectType != classPointer)
12217 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12218 symbol.type.staticMethod = true;
12219 symbol.type.thisClass = null;
12221 // HIGH DANGER: VERIFYING THIS...
12222 symbol.type.extraParam = false;
12226 strcpy(className, "__ecereClass_");
12227 FullClassNameCat(className, _class.fullName, true);
12229 MangleClassName(className);
12232 FullClassNameCat(structName, _class.fullName, false);
12237 funcDecl = GetFuncDecl(function.declarator);
12240 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12242 TypeName param = funcDecl.function.parameters->first;
12243 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12245 funcDecl.function.parameters->Remove(param);
12246 FreeTypeName(param);
12250 // DANGER: Watch for this... Check if it's a Conversion?
12251 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12253 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12254 if(!function.propertyNoThis)
12256 TypeName thisParam;
12258 if(type.classObjectType != classPointer)
12260 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12261 if(!funcDecl.function.parameters)
12262 funcDecl.function.parameters = MkList();
12263 funcDecl.function.parameters->Insert(null, thisParam);
12268 if(type.classObjectType != classPointer)
12270 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12271 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12274 thisParam = TypeName
12276 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12277 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12279 funcDecl.function.parameters->Insert(null, thisParam);
12284 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12286 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12287 funcDecl = GetFuncDecl(initDecl.declarator);
12290 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12292 TypeName param = funcDecl.function.parameters->first;
12293 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12295 funcDecl.function.parameters->Remove(param);
12296 FreeTypeName(param);
12300 if(type.classObjectType != classPointer)
12302 // DANGER: Watch for this... Check if it's a Conversion?
12303 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12305 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12307 if(!funcDecl.function.parameters)
12308 funcDecl.function.parameters = MkList();
12309 funcDecl.function.parameters->Insert(null, thisParam);
12316 // Add this to the context
12319 if(type.classObjectType != classPointer)
12321 thisSymbol = Symbol
12323 string = CopyString("this");
12324 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12326 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12328 if(typedObject && thisSymbol.type)
12330 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12331 thisSymbol.type.byReference = type.byReference;
12332 thisSymbol.type.typedByReference = type.byReference;
12334 thisSymbol = Symbol { string = CopyString("class") };
12335 function.body.compound.context.symbols.Add(thisSymbol);
12341 // Pointer to class data
12343 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12345 DataMember member = null;
12348 for(base = _class; base && base.type != systemClass; base = base.next)
12350 for(member = base.membersAndProperties.first; member; member = member.next)
12351 if(!member.isProperty)
12357 for(member = _class.membersAndProperties.first; member; member = member.next)
12358 if(!member.isProperty)
12362 char pointerName[1024];
12365 Initializer initializer;
12366 Expression exp, bytePtr;
12368 strcpy(pointerName, "__ecerePointer_");
12369 FullClassNameCat(pointerName, _class.fullName, false);
12371 char className[1024];
12372 strcpy(className, "__ecereClass_");
12373 FullClassNameCat(className, classSym.string, true);
12374 MangleClassName(className);
12377 DeclareClass(classSym, className);
12381 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12386 sprintf(string, "%d", _class.offset);
12387 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12391 // ([bytePtr] + [className]->offset)
12392 exp = QBrackets(MkExpOp(bytePtr, '+',
12393 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12396 // (this ? [exp] : 0)
12397 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12401 kind = pointerType;
12402 type = Type { refCount = 1, kind = voidType };
12407 yylloc = function.body.loc;
12408 // ([structName] *) [exp]
12409 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12410 initializer = MkInitializerAssignment(
12411 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12413 // [structName] * [pointerName] = [initializer];
12414 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12417 Context prevContext = curContext;
12418 curContext = function.body.compound.context;
12420 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12421 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12423 curContext = prevContext;
12427 decl.symbol = null;
12429 if(!function.body.compound.declarations)
12430 function.body.compound.declarations = MkList();
12431 function.body.compound.declarations->Insert(null, decl);
12437 // Loop through the function and replace undeclared identifiers
12438 // which are a member of the class (methods, properties or data)
12439 // by "this.[member]"
12446 FreeSpecifier(id._class);
12449 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12451 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12452 id = GetDeclId(initDecl.declarator);
12454 FreeSpecifier(id._class);
12459 topContext = function.body.compound.context;
12461 FunctionDefinition oldFunction = curFunction;
12462 curFunction = function;
12464 ProcessStatement(function.body);
12466 // If this is a property set and no firewatchers has been done yet, add one here
12467 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12469 Statement prevCompound = curCompound;
12470 Context prevContext = curContext;
12472 Statement fireWatchers = MkFireWatchersStmt(null, null);
12473 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12474 ListAdd(function.body.compound.statements, fireWatchers);
12476 curCompound = function.body;
12477 curContext = function.body.compound.context;
12479 ProcessStatement(fireWatchers);
12481 curContext = prevContext;
12482 curCompound = prevCompound;
12486 curFunction = oldFunction;
12489 if(function.declarator)
12491 ProcessDeclarator(function.declarator);
12494 topContext = oldTopContext;
12495 thisClass = oldThisClass;
12498 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12499 static void ProcessClass(OldList definitions, Symbol symbol)
12502 External external = curExternal;
12503 Class regClass = symbol ? symbol.registered : null;
12505 // Process all functions
12506 for(def = definitions.first; def; def = def.next)
12508 if(def.type == functionClassDef)
12510 if(def.function.declarator)
12511 curExternal = def.function.declarator.symbol.pointerExternal;
12513 curExternal = external;
12515 ProcessFunction((FunctionDefinition)def.function);
12517 else if(def.type == declarationClassDef)
12519 if(def.decl.type == instDeclaration)
12521 thisClass = regClass;
12522 ProcessInstantiationType(def.decl.inst);
12528 Class backThisClass = thisClass;
12529 if(regClass) thisClass = regClass;
12530 ProcessDeclaration(def.decl);
12531 thisClass = backThisClass;
12534 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12536 MemberInit defProperty;
12538 // Add this to the context
12539 Symbol thisSymbol = Symbol
12541 string = CopyString("this");
12542 type = regClass ? MkClassType(regClass.fullName) : null;
12544 globalContext.symbols.Add((BTNode)thisSymbol);
12546 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12548 thisClass = regClass;
12549 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12553 globalContext.symbols.Remove((BTNode)thisSymbol);
12554 FreeSymbol(thisSymbol);
12556 else if(def.type == propertyClassDef && def.propertyDef)
12558 PropertyDef prop = def.propertyDef;
12560 // Add this to the context
12562 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12563 globalContext.symbols.Add(thisSymbol);
12566 thisClass = regClass;
12573 string = CopyString("this");
12574 type = MkClassType(regClass.fullName);
12576 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12579 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12580 ProcessStatement(prop.setStmt);
12588 string = CopyString("this");
12589 type = MkClassType(regClass.fullName);
12591 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12594 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12595 ProcessStatement(prop.getStmt);
12603 string = CopyString("this");
12604 type = MkClassType(regClass.fullName);
12606 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12609 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12610 ProcessStatement(prop.issetStmt);
12616 globalContext.symbols.Remove(thisSymbol);
12617 FreeSymbol(thisSymbol);
12620 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12622 PropertyWatch propertyWatch = def.propertyWatch;
12624 thisClass = regClass;
12625 if(propertyWatch.compound)
12629 string = CopyString("this");
12630 type = regClass ? MkClassType(regClass.fullName) : null;
12633 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12635 curExternal = null;
12636 ProcessStatement(propertyWatch.compound);
12643 void DeclareFunctionUtil(String s)
12645 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12650 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12651 strcpy(name, "__ecereFunction_");
12652 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12653 DeclareFunction(function, name);
12657 void ComputeDataTypes()
12661 External after = null;
12663 currentClass = null;
12665 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12667 for(external = ast->first; external; external = external.next)
12669 if(external.type == declarationExternal)
12671 Declaration decl = external.declaration;
12674 OldList * decls = decl.declarators;
12677 InitDeclarator initDecl = decls->first;
12680 Declarator declarator = initDecl.declarator;
12681 if(declarator && declarator.type == identifierDeclarator)
12683 Identifier id = declarator.identifier;
12684 if(id && id.string)
12686 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12688 external.symbol.id = -1001, external.symbol.idCode = -1001;
12699 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12700 ast->Insert(after, temp);
12701 curExternal = temp;
12703 DeclareFunctionUtil("eSystem_New");
12704 DeclareFunctionUtil("eSystem_New0");
12705 DeclareFunctionUtil("eSystem_Renew");
12706 DeclareFunctionUtil("eSystem_Renew0");
12707 DeclareFunctionUtil("eSystem_Delete");
12708 DeclareFunctionUtil("eClass_GetProperty");
12709 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12711 DeclareStruct("ecere::com::Class", false);
12712 DeclareStruct("ecere::com::Instance", false);
12713 DeclareStruct("ecere::com::Property", false);
12714 DeclareStruct("ecere::com::DataMember", false);
12715 DeclareStruct("ecere::com::Method", false);
12716 DeclareStruct("ecere::com::SerialBuffer", false);
12717 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12721 for(external = ast->first; external; external = external.next)
12723 afterExternal = curExternal = external;
12724 if(external.type == functionExternal)
12726 currentClass = external.function._class;
12727 ProcessFunction(external.function);
12729 // There shouldn't be any _class member access here anyways...
12730 else if(external.type == declarationExternal)
12732 currentClass = null;
12733 ProcessDeclaration(external.declaration);
12735 else if(external.type == classExternal)
12737 ClassDefinition _class = external._class;
12738 currentClass = external.symbol.registered;
12739 if(_class.definitions)
12741 ProcessClass(_class.definitions, _class.symbol);
12745 // Free class data...
12746 ast->Remove(external);
12750 else if(external.type == nameSpaceExternal)
12752 thisNameSpace = external.id.string;
12755 currentClass = null;
12756 thisNameSpace = null;
12758 delete temp.symbol;