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)
300 sprintf(temp, "%.16ff", result);
301 return CopyString(temp);
304 public char * PrintDouble(double result)
307 sprintf(temp, "%.16f", result);
308 return CopyString(temp);
311 ////////////////////////////////////////////////////////////////////////
312 ////////////////////////////////////////////////////////////////////////
314 //public Operand GetOperand(Expression exp);
316 #define GETVALUE(name, t) \
317 public bool GetOp##name(Operand op2, t * value2) \
319 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
320 else if(op2.kind == intType) *value2 = (t) op2.ui; \
321 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
322 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
323 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
324 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
325 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
326 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
327 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
328 else if(op2.kind == shortType) *value2 = (t) op2.us; \
329 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
330 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
331 else if(op2.kind == floatType) *value2 = (t) op2.f; \
332 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
333 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
338 public bool Get##name(Expression exp, t * value2) \
340 Operand op2 = GetOperand(exp); \
341 return GetOp##name(op2, value2); \
344 // To help the deubugger currently not preprocessing...
347 GETVALUE(Int, HELP(int));
348 GETVALUE(UInt, HELP(unsigned int));
349 GETVALUE(Int64, HELP(int64));
350 GETVALUE(UInt64, HELP(uint64));
351 GETVALUE(IntPtr, HELP(intptr));
352 GETVALUE(UIntPtr, HELP(uintptr));
353 GETVALUE(IntSize, HELP(intsize));
354 GETVALUE(UIntSize, HELP(uintsize));
355 GETVALUE(Short, HELP(short));
356 GETVALUE(UShort, HELP(unsigned short));
357 GETVALUE(Char, HELP(char));
358 GETVALUE(UChar, HELP(unsigned char));
359 GETVALUE(Float, HELP(float));
360 GETVALUE(Double, HELP(double));
362 void ComputeExpression(Expression exp);
364 void ComputeClassMembers(Class _class, bool isMember)
366 DataMember member = isMember ? (DataMember) _class : null;
367 Context context = isMember ? null : SetupTemplatesContext(_class);
368 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
369 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
372 int unionMemberOffset = 0;
376 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
377 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
382 member.memberOffset = 0;
383 if(targetBits < sizeof(void *) * 8)
384 member.structAlignment = 0;
386 else if(targetBits < sizeof(void *) * 8)
387 _class.structAlignment = 0;
389 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
390 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
391 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
393 if(!member && _class.destructionWatchOffset)
394 _class.memberOffset += sizeof(OldList);
396 // To avoid reentrancy...
397 //_class.structSize = -1;
400 DataMember dataMember;
401 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
403 if(!dataMember.isProperty)
405 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
407 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
408 /*if(!dataMember.dataType)
409 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
417 DataMember dataMember;
418 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
420 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
422 if(!isMember && _class.type == bitClass && dataMember.dataType)
424 BitMember bitMember = (BitMember) dataMember;
428 ComputeTypeSize(dataMember.dataType);
430 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
431 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
433 _class.memberOffset = bitMember.pos + bitMember.size;
434 for(d = 0; d<bitMember.size; d++)
440 bitMember.mask = mask << bitMember.pos;
442 else if(dataMember.type == normalMember && dataMember.dataType)
447 // Prevent infinite recursion
448 if(dataMember.dataType.kind != classType ||
449 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
450 _class.type != structClass)))
451 ComputeTypeSize(dataMember.dataType);
453 if(dataMember.dataType.bitFieldCount)
455 bitFields += dataMember.dataType.bitFieldCount;
462 int size = (bitFields + 7) / 8;
466 // TESTING THIS PADDING CODE
469 member.structAlignment = Max(member.structAlignment, alignment);
471 if(member.memberOffset % alignment)
472 member.memberOffset += alignment - (member.memberOffset % alignment);
475 dataMember.offset = member.memberOffset;
476 if(member.type == unionMember)
477 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
480 member.memberOffset += size;
485 // TESTING THIS PADDING CODE
488 _class.structAlignment = Max(_class.structAlignment, alignment);
490 if(_class.memberOffset % alignment)
491 _class.memberOffset += alignment - (_class.memberOffset % alignment);
494 dataMember.offset = _class.memberOffset;
495 _class.memberOffset += size;
499 size = dataMember.dataType.size;
500 alignment = dataMember.dataType.alignment;
505 // TESTING THIS PADDING CODE
508 member.structAlignment = Max(member.structAlignment, alignment);
510 if(member.memberOffset % alignment)
511 member.memberOffset += alignment - (member.memberOffset % alignment);
514 dataMember.offset = member.memberOffset;
515 if(member.type == unionMember)
516 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
519 member.memberOffset += size;
524 // TESTING THIS PADDING CODE
527 _class.structAlignment = Max(_class.structAlignment, alignment);
529 if(_class.memberOffset % alignment)
530 _class.memberOffset += alignment - (_class.memberOffset % alignment);
533 dataMember.offset = _class.memberOffset;
534 _class.memberOffset += size;
541 ComputeClassMembers((Class)dataMember, true);
542 alignment = dataMember.structAlignment;
548 if(member.memberOffset % alignment)
549 member.memberOffset += alignment - (member.memberOffset % alignment);
551 member.structAlignment = Max(member.structAlignment, alignment);
553 dataMember.offset = member.memberOffset;
554 if(member.type == unionMember)
555 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
557 member.memberOffset += dataMember.memberOffset;
563 if(_class.memberOffset % alignment)
564 _class.memberOffset += alignment - (_class.memberOffset % alignment);
565 _class.structAlignment = Max(_class.structAlignment, alignment);
567 dataMember.offset = _class.memberOffset;
568 _class.memberOffset += dataMember.memberOffset;
576 int size = (bitFields + 7) / 8;
580 // TESTING THIS PADDING CODE
583 member.structAlignment = Max(member.structAlignment, alignment);
585 if(member.memberOffset % alignment)
586 member.memberOffset += alignment - (member.memberOffset % alignment);
589 if(member.type == unionMember)
590 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
593 member.memberOffset += size;
598 // TESTING THIS PADDING CODE
601 _class.structAlignment = Max(_class.structAlignment, alignment);
603 if(_class.memberOffset % alignment)
604 _class.memberOffset += alignment - (_class.memberOffset % alignment);
606 _class.memberOffset += size;
611 if(member && member.type == unionMember)
613 member.memberOffset = unionMemberOffset;
618 /*if(_class.type == structClass)
619 _class.size = _class.memberOffset;
623 if(_class.type != bitClass)
626 if(_class.structAlignment)
628 if(_class.memberOffset % _class.structAlignment)
629 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
631 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
635 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
637 if(prop.isProperty && prop.isWatchable)
639 prop.watcherOffset = _class.structSize;
640 _class.structSize += sizeof(OldList);
648 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
650 Class deriv = derivative.data;
652 if(deriv.computeSize)
654 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
655 deriv.offset = /*_class.offset + */_class.structSize;
656 deriv.memberOffset = 0;
657 // ----------------------
659 deriv.structSize = deriv.offset;
661 ComputeClassMembers(deriv, false);
669 FinishTemplatesContext(context);
672 public void ComputeModuleClasses(Module module)
677 for(subModule = module.modules.first; subModule; subModule = subModule.next)
678 ComputeModuleClasses(subModule.data);
679 for(_class = module.classes.first; _class; _class = _class.next)
680 ComputeClassMembers(_class, false);
684 public int ComputeTypeSize(Type type)
686 uint size = type ? type.size : 0;
687 if(!size && type && !type.computing)
689 type.computing = true;
692 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
693 case charType: type.alignment = size = sizeof(char); break;
694 case intType: type.alignment = size = sizeof(int); break;
695 case int64Type: type.alignment = size = sizeof(int64); break;
696 case intPtrType: type.alignment = size = targetBits / 8; break;
697 case intSizeType: type.alignment = size = targetBits / 8; break;
698 case longType: type.alignment = size = sizeof(long); break;
699 case shortType: type.alignment = size = sizeof(short); break;
700 case floatType: type.alignment = size = sizeof(float); break;
701 case doubleType: type.alignment = size = sizeof(double); break;
704 Class _class = type._class ? type._class.registered : null;
706 if(_class && _class.type == structClass)
708 // Ensure all members are properly registered
709 ComputeClassMembers(_class, false);
710 type.alignment = _class.structAlignment;
711 size = _class.structSize;
712 if(type.alignment && size % type.alignment)
713 size += type.alignment - (size % type.alignment);
716 else if(_class && (_class.type == unitClass ||
717 _class.type == enumClass ||
718 _class.type == bitClass))
721 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
722 size = type.alignment = ComputeTypeSize(_class.dataType);
725 size = type.alignment = targetBits / 8; // sizeof(Instance *);
728 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
730 if(type.arraySizeExp)
732 ProcessExpressionType(type.arraySizeExp);
733 ComputeExpression(type.arraySizeExp);
734 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
735 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
737 Location oldLoc = yylloc;
738 // bool isConstant = type.arraySizeExp.isConstant;
739 char expression[10240];
740 expression[0] = '\0';
741 type.arraySizeExp.expType = null;
742 yylloc = type.arraySizeExp.loc;
744 PrintExpression(type.arraySizeExp, expression);
745 Compiler_Error($"Array size not constant int (%s)\n", expression);
748 GetInt(type.arraySizeExp, &type.arraySize);
750 else if(type.enumClass)
752 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
754 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
761 // Unimplemented auto size
765 size = ComputeTypeSize(type.type) * type.arraySize;
767 type.alignment = type.type.alignment;
773 for(member = type.members.first; member; member = member.next)
775 uint addSize = ComputeTypeSize(member);
777 member.offset = size;
778 if(member.alignment && size % member.alignment)
779 member.offset += member.alignment - (size % member.alignment);
780 size = member.offset;
782 type.alignment = Max(type.alignment, member.alignment);
785 if(type.alignment && size % type.alignment)
786 size += type.alignment - (size % type.alignment);
792 for(member = type.members.first; member; member = member.next)
794 uint addSize = ComputeTypeSize(member);
796 member.offset = size;
797 if(member.alignment && size % member.alignment)
798 member.offset += member.alignment - (size % member.alignment);
799 size = member.offset;
801 type.alignment = Max(type.alignment, member.alignment);
802 size = Max(size, addSize);
804 if(type.alignment && size % type.alignment)
805 size += type.alignment - (size % type.alignment);
810 TemplateParameter param = type.templateParameter;
811 Type baseType = ProcessTemplateParameterType(param);
814 size = ComputeTypeSize(baseType);
815 type.alignment = baseType.alignment;
818 type.alignment = size = sizeof(uint64);
823 type.alignment = size = sizeof(enum { test });
828 type.alignment = size = targetBits / 8; //sizeof(void *);
833 type.computing = false;
839 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
841 // This function is in need of a major review when implementing private members etc.
842 DataMember topMember = isMember ? (DataMember) _class : null;
847 Context context = isMember ? null : SetupTemplatesContext(_class);
849 *addedPadding = false;
851 if(!isMember && _class.base)
853 maxSize = _class.structSize;
854 //if(_class.base.type != systemClass) // Commented out with new Instance _class
856 // DANGER: Testing this noHeadClass here...
857 if(_class.type == structClass || _class.type == noHeadClass)
858 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
861 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
862 if(maxSize > baseSize)
870 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
872 if(!member.isProperty)
878 if(member.dataTypeString)
880 OldList * specs = MkList(), * decls = MkList();
883 decl = SpecDeclFromString(member.dataTypeString, specs,
884 MkDeclaratorIdentifier(MkIdentifier(member.name)));
885 ListAdd(decls, MkStructDeclarator(decl, null));
886 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
889 member.dataType = ProcessType(specs, decl);
891 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
894 Type type = ProcessType(specs, decl);
895 DeclareType(member.dataType, false, false);
899 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
900 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
901 DeclareStruct(member.dataType._class.string, false);
904 ComputeTypeSize(member.dataType);
905 size = member.dataType.size;
906 alignment = member.dataType.alignment;
910 if(totalSize % alignment)
911 totalSize += alignment - (totalSize % alignment);
920 OldList * specs = MkList(), * list = MkList();
923 AddMembers(list, (Class)member, true, &size, topClass, null);
925 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
926 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
927 alignment = member.structAlignment;
931 if(totalSize % alignment)
932 totalSize += alignment - (totalSize % alignment);
942 if(topMember && topMember.type == unionMember)
943 *retSize = Max(*retSize, totalSize);
945 *retSize += totalSize;
947 else if(totalSize < maxSize && _class.type != systemClass)
950 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
951 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
952 if(totalSize + autoPadding < maxSize)
955 sprintf(sizeString, "%d", maxSize - totalSize);
956 ListAdd(declarations,
957 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
958 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
960 *addedPadding = true;
964 FinishTemplatesContext(context);
965 return topMember ? topMember.memberID : _class.memberID;
968 static int DeclareMembers(Class _class, bool isMember)
970 DataMember topMember = isMember ? (DataMember) _class : null;
973 Context context = isMember ? null : SetupTemplatesContext(_class);
975 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
976 DeclareMembers(_class.base, false);
978 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
980 if(!member.isProperty)
987 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
988 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
989 DeclareStruct(member.dataType._class.string, false);
991 if(!member.dataType && member.dataTypeString)
992 member.dataType = ProcessTypeString(member.dataTypeString, false);
994 DeclareType(member.dataType, false, false);
1000 DeclareMembers((Class)member, true);
1007 FinishTemplatesContext(context);
1009 return topMember ? topMember.memberID : _class.memberID;
1012 void DeclareStruct(char * name, bool skipNoHead)
1014 External external = null;
1015 Symbol classSym = FindClass(name);
1017 if(!inCompiler || !classSym) return;
1019 // We don't need any declaration for bit classes...
1020 if(classSym.registered &&
1021 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1024 /*if(classSym.registered.templateClass)
1025 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1028 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1030 // Add typedef struct
1032 OldList * specifiers, * declarators;
1033 OldList * declarations = null;
1034 char structName[1024];
1035 external = (classSym.registered && classSym.registered.type == structClass) ?
1036 classSym.pointerExternal : classSym.structExternal;
1038 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1039 // Moved this one up because DeclareClass done later will need it
1041 classSym.declaring++;
1043 if(strchr(classSym.string, '<'))
1045 if(classSym.registered.templateClass)
1047 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1048 classSym.declaring--;
1054 DeclareMembers(classSym.registered, false);
1057 FullClassNameCat(structName, name, false);
1060 external = MkExternalDeclaration(null);*/
1064 bool addedPadding = false;
1065 classSym.declaredStructSym = true;
1067 declarations = MkList();
1069 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1071 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1072 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1074 if(!declarations->count || (declarations->count == 1 && addedPadding))
1076 FreeList(declarations, FreeClassDef);
1077 declarations = null;
1080 if(skipNoHead || declarations)
1082 if(external && external.declaration)
1084 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1086 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1089 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1092 if(classSym.structExternal)
1093 ast->Move(classSym.structExternal, curExternal.prev);
1094 ast->Move(classSym.pointerExternal, curExternal.prev);
1096 classSym.id = curExternal.symbol.idCode;
1097 classSym.idCode = curExternal.symbol.idCode;
1098 // external = classSym.pointerExternal;
1099 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1105 external = MkExternalDeclaration(null);
1107 specifiers = MkList();
1108 declarators = MkList();
1109 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1112 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1113 ListAdd(declarators, MkInitDeclarator(d, null));
1115 external.declaration = decl = MkDeclaration(specifiers, declarators);
1116 if(decl.symbol && !decl.symbol.pointerExternal)
1117 decl.symbol.pointerExternal = external;
1119 // For simple classes, keep the declaration as the external to move around
1120 if(classSym.registered && classSym.registered.type == structClass)
1122 char className[1024];
1123 strcpy(className, "__ecereClass_");
1124 FullClassNameCat(className, classSym.string, true);
1125 MangleClassName(className);
1128 DeclareClass(classSym, className);
1130 external.symbol = classSym;
1131 classSym.pointerExternal = external;
1132 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1133 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1137 char className[1024];
1138 strcpy(className, "__ecereClass_");
1139 FullClassNameCat(className, classSym.string, true);
1140 MangleClassName(className);
1142 // TOFIX: TESTING THIS...
1143 classSym.structExternal = external;
1144 DeclareClass(classSym, className);
1145 external.symbol = classSym;
1149 ast->Insert(curExternal ? curExternal.prev : null, external);
1153 classSym.declaring--;
1155 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1157 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1158 // Moved this one up because DeclareClass done later will need it
1161 classSym.declaring++;
1165 if(classSym.registered)
1166 DeclareMembers(classSym.registered, false);
1169 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1172 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1175 if(classSym.structExternal)
1176 ast->Move(classSym.structExternal, curExternal.prev);
1177 ast->Move(classSym.pointerExternal, curExternal.prev);
1179 classSym.id = curExternal.symbol.idCode;
1180 classSym.idCode = curExternal.symbol.idCode;
1181 // external = classSym.pointerExternal;
1182 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1185 classSym.declaring--;
1190 void DeclareProperty(Property prop, char * setName, char * getName)
1192 Symbol symbol = prop.symbol;
1193 char propName[1024];
1195 strcpy(setName, "__ecereProp_");
1196 FullClassNameCat(setName, prop._class.fullName, false);
1197 strcat(setName, "_Set_");
1198 // strcat(setName, prop.name);
1199 FullClassNameCat(setName, prop.name, true);
1201 strcpy(getName, "__ecereProp_");
1202 FullClassNameCat(getName, prop._class.fullName, false);
1203 strcat(getName, "_Get_");
1204 FullClassNameCat(getName, prop.name, true);
1205 // strcat(getName, prop.name);
1207 strcpy(propName, "__ecereProp_");
1208 FullClassNameCat(propName, prop._class.fullName, false);
1209 strcat(propName, "_");
1210 FullClassNameCat(propName, prop.name, true);
1211 // strcat(propName, prop.name);
1213 // To support "char *" property
1214 MangleClassName(getName);
1215 MangleClassName(setName);
1216 MangleClassName(propName);
1218 if(prop._class.type == structClass)
1219 DeclareStruct(prop._class.fullName, false);
1221 if(!symbol || curExternal.symbol.idCode < symbol.id)
1223 bool imported = false;
1224 bool dllImport = false;
1225 if(!symbol || symbol._import)
1230 if(!prop._class.symbol)
1231 prop._class.symbol = FindClass(prop._class.fullName);
1232 classSym = prop._class.symbol;
1233 if(classSym && !classSym._import)
1235 ModuleImport module;
1237 if(prop._class.module)
1238 module = FindModule(prop._class.module);
1240 module = mainModule;
1242 classSym._import = ClassImport
1244 name = CopyString(prop._class.fullName);
1245 isRemote = prop._class.isRemote;
1247 module.classes.Add(classSym._import);
1249 symbol = prop.symbol = Symbol { };
1250 symbol._import = (ClassImport)PropertyImport
1252 name = CopyString(prop.name);
1253 isVirtual = false; //prop.isVirtual;
1254 hasSet = prop.Set ? true : false;
1255 hasGet = prop.Get ? true : false;
1258 classSym._import.properties.Add(symbol._import);
1261 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1267 Context context = SetupTemplatesContext(prop._class);
1268 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1269 FinishTemplatesContext(context);
1275 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1278 OldList * specifiers, * declarators;
1283 Declarator typeDecl;
1284 bool simple = false;
1286 specifiers = MkList();
1287 declarators = MkList();
1290 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1291 MkDeclaratorIdentifier(MkIdentifier("this"))));
1293 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1296 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1299 Context context = SetupTemplatesContext(prop._class);
1300 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1301 FinishTemplatesContext(context);
1304 // Make sure the simple _class's type is declared
1305 for(spec = specifiers->first; spec; spec = spec.next)
1307 if(spec.type == nameSpecifier /*SpecifierClass*/)
1309 if((!typeDecl || typeDecl.type == identifierDeclarator))
1311 Symbol classSym = spec.symbol; // FindClass(spec.name);
1312 symbol._class = classSym.registered;
1313 if(classSym.registered && classSym.registered.type == structClass)
1315 DeclareStruct(spec.name, false);
1323 d = PlugDeclarator(typeDecl, d);
1326 ListAdd(params, MkTypeName(specifiers,
1327 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1328 specifiers = MkList();
1331 d = MkDeclaratorFunction(d, params);
1335 specifiers->Insert(null, MkSpecifier(EXTERN));
1336 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1337 specifiers->Insert(null, MkSpecifier(STATIC));
1339 ListAdd(specifiers, MkSpecifier(VOID));
1341 ListAdd(declarators, MkInitDeclarator(d, null));
1343 decl = MkDeclaration(specifiers, declarators);
1345 external = MkExternalDeclaration(decl);
1346 ast->Insert(curExternal.prev, external);
1347 external.symbol = symbol;
1348 symbol.externalGet = external;
1350 ReplaceThisClassSpecifiers(specifiers, prop._class);
1353 FreeDeclarator(typeDecl);
1357 // Move declaration higher...
1358 ast->Move(symbol.externalGet, curExternal.prev);
1365 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1368 OldList * specifiers, * declarators;
1373 Declarator typeDecl;
1375 declarators = MkList();
1378 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1379 if(!prop.conversion || prop._class.type == structClass)
1381 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1382 MkDeclaratorIdentifier(MkIdentifier("this"))));
1385 specifiers = MkList();
1388 Context context = SetupTemplatesContext(prop._class);
1389 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1390 MkDeclaratorIdentifier(MkIdentifier("value")));
1391 FinishTemplatesContext(context);
1393 ListAdd(params, MkTypeName(specifiers, d));
1395 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1398 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1399 d = MkDeclaratorFunction(d, params);
1401 // Make sure the simple _class's type is declared
1402 for(spec = specifiers->first; spec; spec = spec.next)
1404 if(spec.type == nameSpecifier /*SpecifierClass*/)
1406 if((!typeDecl || typeDecl.type == identifierDeclarator))
1408 Symbol classSym = spec.symbol; // FindClass(spec.name);
1409 symbol._class = classSym.registered;
1410 if(classSym.registered && classSym.registered.type == structClass)
1411 DeclareStruct(spec.name, false);
1416 ListAdd(declarators, MkInitDeclarator(d, null));
1418 specifiers = MkList();
1421 specifiers->Insert(null, MkSpecifier(EXTERN));
1422 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1423 specifiers->Insert(null, MkSpecifier(STATIC));
1425 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1426 if(!prop.conversion || prop._class.type == structClass)
1427 ListAdd(specifiers, MkSpecifier(VOID));
1429 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1431 decl = MkDeclaration(specifiers, declarators);
1433 external = MkExternalDeclaration(decl);
1434 ast->Insert(curExternal.prev, external);
1435 external.symbol = symbol;
1436 symbol.externalSet = external;
1438 ReplaceThisClassSpecifiers(specifiers, prop._class);
1442 // Move declaration higher...
1443 ast->Move(symbol.externalSet, curExternal.prev);
1447 // Property (for Watchers)
1448 if(!symbol.externalPtr)
1452 OldList * specifiers = MkList();
1455 specifiers->Insert(null, MkSpecifier(EXTERN));
1457 specifiers->Insert(null, MkSpecifier(STATIC));
1459 ListAdd(specifiers, MkSpecifierName("Property"));
1462 OldList * list = MkList();
1463 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1464 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1468 strcpy(propName, "__ecerePropM_");
1469 FullClassNameCat(propName, prop._class.fullName, false);
1470 strcat(propName, "_");
1471 // strcat(propName, prop.name);
1472 FullClassNameCat(propName, prop.name, true);
1474 MangleClassName(propName);
1476 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1477 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1479 decl = MkDeclaration(specifiers, list);
1482 external = MkExternalDeclaration(decl);
1483 ast->Insert(curExternal.prev, external);
1484 external.symbol = symbol;
1485 symbol.externalPtr = external;
1489 // Move declaration higher...
1490 ast->Move(symbol.externalPtr, curExternal.prev);
1493 symbol.id = curExternal.symbol.idCode;
1497 // ***************** EXPRESSION PROCESSING ***************************
1498 public Type Dereference(Type source)
1503 if(source.kind == pointerType || source.kind == arrayType)
1506 source.type.refCount++;
1508 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1516 // Support dereferencing of no head classes for now...
1517 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1523 Compiler_Error($"cannot dereference type\n");
1528 static Type Reference(Type source)
1544 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1546 Identifier ident = member.identifiers ? member.identifiers->first : null;
1548 DataMember dataMember = null;
1549 Method method = null;
1550 bool freeType = false;
1552 yylloc = member.loc;
1558 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1562 dataMember = *curMember;
1568 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1569 DataMember _subMemberStack[256];
1570 int _subMemberStackPos = 0;
1572 // FILL MEMBER STACK
1574 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1577 dataMember = thisMember;
1578 if(curMember && thisMember.memberAccess == publicAccess)
1580 *curMember = thisMember;
1581 *curClass = thisMember._class;
1582 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1583 *subMemberStackPos = _subMemberStackPos;
1590 method = eClass_FindMethod(_class, ident.string, privateModule);
1591 if(method && method.type == virtualMethod)
1603 if(!dataMember.dataType && dataMember.dataTypeString)
1605 //Context context = SetupTemplatesContext(dataMember._class);
1606 Context context = SetupTemplatesContext(_class);
1607 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1608 FinishTemplatesContext(context);
1610 type = dataMember.dataType;
1614 // This is for destination type...
1615 if(!method.dataType)
1616 ProcessMethodType(method);
1617 //DeclareMethod(method);
1618 // method.dataType = ((Symbol)method.symbol)->type;
1619 type = method.dataType;
1622 if(ident && ident.next)
1624 for(ident = ident.next; ident && type; ident = ident.next)
1626 if(type.kind == classType)
1628 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1630 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1632 type = dataMember.dataType;
1634 else if(type.kind == structType || type.kind == unionType)
1637 for(memberType = type.members.first; memberType; memberType = memberType.next)
1639 if(!strcmp(memberType.name, ident.string))
1649 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1650 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1653 ClassTemplateParameter curParam = null;
1655 for(sClass = _class; sClass; sClass = sClass.base)
1658 if(sClass.templateClass) sClass = sClass.templateClass;
1659 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1661 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1663 for(sClass = sClass.base; sClass; sClass = sClass.base)
1665 if(sClass.templateClass) sClass = sClass.templateClass;
1666 id += sClass.templateParams.count;
1677 ClassTemplateArgument arg = _class.templateArgs[id];
1678 if(arg.dataTypeString)
1681 type = ProcessTypeString(arg.dataTypeString, false);
1683 if(type && _class.templateClass)
1684 type.passAsTemplate = true;
1690 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1691 exp.destType.refCount++;
1697 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1699 Class expClass = type._class.registered;
1700 Class cClass = null;
1705 char templateString[1024];
1706 ClassTemplateParameter param;
1707 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1708 for(cClass = expClass; cClass; cClass = cClass.base)
1711 if(cClass.templateClass) cClass = cClass.templateClass;
1712 for(param = cClass.templateParams.first; param; param = param.next)
1716 ClassTemplateArgument arg;
1717 for(sClass = cClass.base; sClass; sClass = sClass.base)
1719 if(sClass.templateClass) sClass = sClass.templateClass;
1720 id += sClass.templateParams.count;
1722 arg = expClass.templateArgs[id];
1724 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1726 ClassTemplateParameter cParam;
1727 //int p = numParams - sClass.templateParams.count;
1730 if(sClass.templateClass) sClass = sClass.templateClass;
1732 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1734 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1735 p += nextClass.templateParams.count;
1738 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1740 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1742 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1744 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1745 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1757 strcat(argument, arg.name.string);
1758 strcat(argument, " = ");
1764 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1765 char expString[1024];
1766 OldList * specs = MkList();
1767 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1769 char * string = PrintHexUInt64(arg.expression.ui64);
1770 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1773 ProcessExpressionType(exp);
1774 ComputeExpression(exp);
1775 expString[0] = '\0';
1776 PrintExpression(exp, expString);
1777 strcat(argument, expString);
1779 FreeExpression(exp);
1784 strcat(argument, arg.member.name);
1787 case TemplateParameterType::type:
1789 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1790 strcat(argument, arg.dataTypeString);
1796 if(paramCount) strcat(templateString, ", ");
1797 if(lastParam != p - 1)
1799 strcat(templateString, param.name);
1800 strcat(templateString, " = ");
1802 strcat(templateString, argument);
1811 int len = strlen(templateString);
1812 if(templateString[len-1] == '<')
1816 if(templateString[len-1] == '>')
1817 templateString[len++] = ' ';
1818 templateString[len++] = '>';
1820 templateString[len++] = '\0';
1823 Context context = SetupTemplatesContext(_class);
1824 if(freeType) FreeType(type);
1825 type = ProcessTypeString(templateString, false);
1827 FinishTemplatesContext(context);
1831 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1833 ProcessExpressionType(member.initializer.exp);
1834 if(!member.initializer.exp.expType)
1838 char expString[10240];
1839 expString[0] = '\0';
1840 PrintExpression(member.initializer.exp, expString);
1841 ChangeCh(expString, '\n', ' ');
1842 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1845 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1846 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1848 Compiler_Error($"incompatible instance method %s\n", ident.string);
1851 else if(member.initializer)
1854 FreeType(member.exp.destType);
1855 member.exp.destType = type;
1856 if(member.exp.destType)
1857 member.exp.destType.refCount++;
1858 ProcessExpressionType(member.exp);
1861 ProcessInitializer(member.initializer, type);
1863 if(freeType) FreeType(type);
1867 if(_class && _class.type == unitClass)
1869 if(member.initializer)
1872 FreeType(member.exp.destType);
1873 member.exp.destType = MkClassType(_class.fullName);
1874 ProcessExpressionType(member.initializer, type);
1876 Type type = MkClassType(_class.fullName);
1877 ProcessInitializer(member.initializer, type);
1883 if(member.initializer)
1885 //ProcessExpressionType(member.exp);
1886 ProcessInitializer(member.initializer, null);
1892 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1896 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1898 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1902 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1907 void ProcessInstantiationType(Instantiation inst)
1912 MembersInit members;
1913 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1916 /*if(!inst._class.symbol)
1917 inst._class.symbol = FindClass(inst._class.name);*/
1918 classSym = inst._class.symbol;
1919 _class = classSym ? classSym.registered : null;
1921 // DANGER: Patch for mutex not declaring its struct when not needed
1922 if(!_class || _class.type != noHeadClass)
1923 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1925 afterExternal = afterExternal ? afterExternal : curExternal;
1928 ProcessExpressionType(inst.exp);
1930 inst.isConstant = true;
1933 DataMember curMember = null;
1934 Class curClass = null;
1935 DataMember subMemberStack[256];
1936 int subMemberStackPos = 0;
1938 for(members = inst.members->first; members; members = members.next)
1940 switch(members.type)
1942 case methodMembersInit:
1945 static uint instMethodID = 0;
1946 External external = curExternal;
1947 Context context = curContext;
1948 Declarator declarator = members.function.declarator;
1949 Identifier nameID = GetDeclId(declarator);
1950 char * unmangled = nameID ? nameID.string : null;
1952 External createdExternal = null;
1957 //members.function.dontMangle = true;
1958 strcpy(name, "__ecereInstMeth_");
1959 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1961 strcat(name, nameID.string);
1963 sprintf(number, "_%08d", instMethodID++);
1964 strcat(name, number);
1965 nameID.string = CopyString(name);
1968 // Do modifications here...
1971 Symbol symbol = declarator.symbol;
1972 Method method = eClass_FindMethod(_class, unmangled, privateModule);
1974 if(method && method.type == virtualMethod)
1976 symbol.method = method;
1977 ProcessMethodType(method);
1979 if(!symbol.type.thisClass)
1981 if(method.dataType.thisClass && currentClass &&
1982 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
1984 if(!currentClass.symbol)
1985 currentClass.symbol = FindClass(currentClass.fullName);
1986 symbol.type.thisClass = currentClass.symbol;
1991 _class.symbol = FindClass(_class.fullName);
1992 symbol.type.thisClass = _class.symbol;
1995 // TESTING THIS HERE:
1996 DeclareType(symbol.type, true, true);
2001 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2002 unmangled, classSym.string);
2006 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2007 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2011 FreeSpecifier(nameID._class);
2012 nameID._class = null;
2018 Type type = declarator.symbol.type;
2019 External oldExternal = curExternal;
2021 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2022 // *** It was commented out for problems such as
2024 class VirtualDesktop : Window
2026 clientSize = Size { };
2037 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2039 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2042 if(strcmp(declarator.symbol.string, name))
2044 printf("TOCHECK: Look out for this\n");
2045 delete declarator.symbol.string;
2046 declarator.symbol.string = CopyString(name);
2049 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2051 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2052 excludedSymbols->Remove(declarator.symbol);
2053 globalContext.symbols.Add((BTNode)declarator.symbol);
2054 if(strstr(declarator.symbol.string), "::")
2055 globalContext.hasNameSpace = true;
2060 //curExternal = curExternal.prev;
2061 //afterExternal = afterExternal->next;
2063 //ProcessFunction(afterExternal->function);
2065 //curExternal = afterExternal;
2067 External externalDecl;
2068 externalDecl = MkExternalDeclaration(null);
2069 ast->Insert(oldExternal.prev, externalDecl);
2071 // Which function does this process?
2072 if(createdExternal.function)
2074 ProcessFunction(createdExternal.function);
2076 //curExternal = oldExternal;
2079 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2081 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2082 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2084 //externalDecl = MkExternalDeclaration(decl);
2086 //***** ast->Insert(external.prev, externalDecl);
2087 //ast->Insert(curExternal.prev, externalDecl);
2088 externalDecl.declaration = decl;
2089 if(decl.symbol && !decl.symbol.pointerExternal)
2090 decl.symbol.pointerExternal = externalDecl;
2092 // Trying this out...
2093 declarator.symbol.pointerExternal = externalDecl;
2100 curExternal = declarator.symbol.pointerExternal;
2101 ProcessFunction((FunctionDefinition)members.function);
2103 curExternal = external;
2104 curContext = context;
2108 FreeClassFunction(members.function);
2110 // In this pass, turn this into a MemberInitData
2111 exp = QMkExpId(name);
2112 members.type = dataMembersInit;
2113 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2119 case dataMembersInit:
2121 if(members.dataMembers && classSym)
2124 Location oldyyloc = yylloc;
2125 for(member = members.dataMembers->first; member; member = member.next)
2127 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2128 if(member.initializer && !member.initializer.isConstant)
2129 inst.isConstant = false;
2141 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2143 // OPTIMIZATIONS: TESTING THIS...
2146 if(type.kind == functionType)
2151 for(param = type.params.first; param; param = param.next)
2152 DeclareType(param, declarePointers, true);
2154 DeclareType(type.returnType, declarePointers, true);
2156 else if(type.kind == pointerType && declarePointers)
2157 DeclareType(type.type, declarePointers, false);
2158 else if(type.kind == classType)
2160 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2161 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2163 else if(type.kind == structType || type.kind == unionType)
2166 for(member = type.members.first; member; member = member.next)
2167 DeclareType(member, false, false);
2169 else if(type.kind == arrayType)
2170 DeclareType(type.arrayType, declarePointers, false);
2174 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2176 ClassTemplateArgument * arg = null;
2178 ClassTemplateParameter curParam = null;
2180 for(sClass = _class; sClass; sClass = sClass.base)
2183 if(sClass.templateClass) sClass = sClass.templateClass;
2184 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2186 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2188 for(sClass = sClass.base; sClass; sClass = sClass.base)
2190 if(sClass.templateClass) sClass = sClass.templateClass;
2191 id += sClass.templateParams.count;
2201 arg = &_class.templateArgs[id];
2202 if(arg && param.type == type)
2203 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2208 public Context SetupTemplatesContext(Class _class)
2210 Context context = PushContext();
2211 context.templateTypesOnly = true;
2212 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2214 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2215 for(; param; param = param.next)
2217 if(param.type == type && param.identifier)
2219 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2220 curContext.templateTypes.Add((BTNode)type);
2227 for(sClass = _class; sClass; sClass = sClass.base)
2229 ClassTemplateParameter p;
2230 for(p = sClass.templateParams.first; p; p = p.next)
2232 //OldList * specs = MkList();
2233 //Declarator decl = null;
2234 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2237 TemplateParameter param = p.param;
2241 // ADD DATA TYPE HERE...
2242 p.param = param = TemplateParameter
2244 identifier = MkIdentifier(p.name), type = p.type,
2245 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2248 type = TemplatedType { key = (uintptr)p.name, param = param };
2249 curContext.templateTypes.Add((BTNode)type);
2257 public void FinishTemplatesContext(Context context)
2259 PopContext(context);
2260 FreeContext(context);
2264 public void ProcessMethodType(Method method)
2266 if(!method.dataType)
2268 Context context = SetupTemplatesContext(method._class);
2270 method.dataType = ProcessTypeString(method.dataTypeString, false);
2272 FinishTemplatesContext(context);
2274 if(method.type != virtualMethod && method.dataType)
2276 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2278 if(!method._class.symbol)
2279 method._class.symbol = FindClass(method._class.fullName);
2280 method.dataType.thisClass = method._class.symbol;
2284 // Why was this commented out? Working fine without now...
2287 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2288 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2295 char * par = strstr(type, "(");
2296 char * classOp = null;
2301 for(c = par-type-1; c >= 0; c++)
2303 if(type[c] == ':' && type[c+1] == ':')
2305 classOp = type + c - 1;
2306 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2313 else if(!isspace(type[c]))
2320 int typeLen = strlen(type);
2321 memcpy(temp, classOp, classOpLen);
2322 temp[classOpLen] = '\0';
2324 _class = eSystem_FindClass(module, temp);
2327 method.dataTypeString = new char[typeLen - classOpLen + 1];
2328 memcpy(method.dataTypeString, type, classOp - type);
2329 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2332 method.dataTypeString = type;
2338 public void ProcessPropertyType(Property prop)
2342 Context context = SetupTemplatesContext(prop._class);
2343 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2344 FinishTemplatesContext(context);
2348 public void DeclareMethod(Method method, char * name)
2350 Symbol symbol = method.symbol;
2351 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2353 bool imported = false;
2354 bool dllImport = false;
2356 if(!method.dataType)
2357 method.dataType = ProcessTypeString(method.dataTypeString, false);
2359 if(!symbol || symbol._import || method.type == virtualMethod)
2361 if(!symbol || method.type == virtualMethod)
2364 if(!method._class.symbol)
2365 method._class.symbol = FindClass(method._class.fullName);
2366 classSym = method._class.symbol;
2367 if(!classSym._import)
2369 ModuleImport module;
2371 if(method._class.module && method._class.module.name)
2372 module = FindModule(method._class.module);
2374 module = mainModule;
2375 classSym._import = ClassImport
2377 name = CopyString(method._class.fullName);
2378 isRemote = method._class.isRemote;
2380 module.classes.Add(classSym._import);
2384 symbol = method.symbol = Symbol { };
2388 symbol._import = (ClassImport)MethodImport
2390 name = CopyString(method.name);
2391 isVirtual = method.type == virtualMethod;
2393 classSym._import.methods.Add(symbol._import);
2397 // Set the symbol type
2401 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2403 else if(type.thisClass == (void *)-1)
2405 type.thisClass = null;
2408 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2409 symbol.type = method.dataType;
2410 if(symbol.type) symbol.type.refCount++;
2413 if(!method.thisClass || strcmp(method.thisClass, "void"))
2414 symbol.type.params.Insert(null,
2415 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2418 if(!method.dataType.dllExport)
2421 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2427 if(!method.dataType)
2428 method.dataType = ((Symbol)method.symbol).type;
2429 //ProcessMethodType(method);
2432 if(method.type != virtualMethod && method.dataType)
2433 DeclareType(method.dataType, true, true);
2435 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2437 // We need a declaration here :)
2439 OldList * specifiers, * declarators;
2441 Declarator funcDecl;
2444 specifiers = MkList();
2445 declarators = MkList();
2449 ListAdd(specifiers, MkSpecifier(EXTERN));
2450 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2451 ListAdd(specifiers, MkSpecifier(STATIC));
2453 if(method.type == virtualMethod)
2455 ListAdd(specifiers, MkSpecifier(INT));
2456 d = MkDeclaratorIdentifier(MkIdentifier(name));
2460 d = MkDeclaratorIdentifier(MkIdentifier(name));
2463 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2465 Context context = SetupTemplatesContext(method._class);
2466 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2467 FinishTemplatesContext(context);
2469 funcDecl = GetFuncDecl(d);
2473 Specifier spec, next;
2474 for(spec = specifiers->first; spec; spec = next)
2477 if(spec.type == extendedSpecifier)
2479 specifiers->Remove(spec);
2480 FreeSpecifier(spec);
2485 // Add this parameter if not a static method
2486 if(method.dataType && !method.dataType.staticMethod)
2488 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2490 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2491 TypeName thisParam = MkTypeName(MkListOne(
2492 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2493 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2494 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2495 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2497 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2499 TypeName param = funcDecl.function.parameters->first;
2500 funcDecl.function.parameters->Remove(param);
2501 FreeTypeName(param);
2504 if(!funcDecl.function.parameters)
2505 funcDecl.function.parameters = MkList();
2506 funcDecl.function.parameters->Insert(null, thisParam);
2509 // Make sure we don't have empty parameter declarations for static methods...
2511 else if(!funcDecl.function.parameters)
2513 funcDecl.function.parameters = MkList();
2514 funcDecl.function.parameters->Insert(null,
2515 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2519 ProcessDeclarator(d);
2521 ListAdd(declarators, MkInitDeclarator(d, null));
2523 decl = MkDeclaration(specifiers, declarators);
2525 ReplaceThisClassSpecifiers(specifiers, method._class);
2527 // Keep a different symbol for the function definition than the declaration...
2528 if(symbol.pointerExternal)
2530 Symbol functionSymbol { };
2534 *functionSymbol = *symbol;
2535 functionSymbol.string = CopyString(symbol.string);
2536 if(functionSymbol.type)
2537 functionSymbol.type.refCount++;
2540 excludedSymbols->Add(functionSymbol);
2541 symbol.pointerExternal.symbol = functionSymbol;
2543 external = MkExternalDeclaration(decl);
2545 ast->Insert(curExternal ? curExternal.prev : null, external);
2546 external.symbol = symbol;
2547 symbol.pointerExternal = external;
2551 // Move declaration higher...
2552 ast->Move(symbol.pointerExternal, curExternal.prev);
2555 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2559 char * ReplaceThisClass(Class _class)
2561 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2565 ClassTemplateParameter param;
2568 char className[1024];
2569 strcpy(className, _class.fullName);
2570 for(param = _class.templateParams.first; param; param = param.next)
2572 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2574 if(first) strcat(className, "<");
2575 if(!first) strcat(className, ", ");
2576 if(lastParam + 1 != p)
2578 strcat(className, param.name);
2579 strcat(className, " = ");
2581 strcat(className, param.name);
2589 int len = strlen(className);
2590 if(className[len-1] == '>') className[len++] = ' ';
2591 className[len++] = '>';
2592 className[len++] = '\0';
2594 return CopyString(className);
2597 return CopyString(_class.fullName);
2600 Type ReplaceThisClassType(Class _class)
2602 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2606 ClassTemplateParameter param;
2608 char className[1024];
2609 strcpy(className, _class.fullName);
2611 for(param = _class.templateParams.first; param; param = param.next)
2613 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2615 if(first) strcat(className, "<");
2616 if(!first) strcat(className, ", ");
2617 if(lastParam + 1 != p)
2619 strcat(className, param.name);
2620 strcat(className, " = ");
2622 strcat(className, param.name);
2630 int len = strlen(className);
2631 if(className[len-1] == '>') className[len++] = ' ';
2632 className[len++] = '>';
2633 className[len++] = '\0';
2635 return MkClassType(className);
2636 //return ProcessTypeString(className, false);
2640 return MkClassType(_class.fullName);
2641 //return ProcessTypeString(_class.fullName, false);
2645 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2647 if(specs != null && _class)
2650 for(spec = specs.first; spec; spec = spec.next)
2652 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2654 spec.type = nameSpecifier;
2655 spec.name = ReplaceThisClass(_class);
2656 spec.symbol = FindClass(spec.name); //_class.symbol;
2662 // Returns imported or not
2663 bool DeclareFunction(GlobalFunction function, char * name)
2665 Symbol symbol = function.symbol;
2666 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2668 bool imported = false;
2669 bool dllImport = false;
2671 if(!function.dataType)
2673 function.dataType = ProcessTypeString(function.dataTypeString, false);
2674 if(!function.dataType.thisClass)
2675 function.dataType.staticMethod = true;
2682 ModuleImport module = FindModule(function.module);
2683 // WARNING: This is not added anywhere...
2684 symbol = function.symbol = Symbol { };
2688 if(!function.dataType.dllExport)
2690 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2691 module.functions.Add(symbol._import);
2694 // Set the symbol type
2696 symbol.type = ProcessTypeString(function.dataTypeString, false);
2697 if(!symbol.type.thisClass)
2698 symbol.type.staticMethod = true;
2701 imported = symbol._import ? true : false;
2702 if(imported && function.module != privateModule && function.module.importType != staticImport)
2706 DeclareType(function.dataType, true, true);
2710 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2712 // We need a declaration here :)
2714 OldList * specifiers, * declarators;
2716 Declarator funcDecl;
2719 specifiers = MkList();
2720 declarators = MkList();
2723 ListAdd(specifiers, MkSpecifier(EXTERN));
2726 ListAdd(specifiers, MkSpecifier(STATIC));
2729 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2732 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2734 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2735 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2736 if(function.module.importType == staticImport)
2739 for(spec = specifiers->first; spec; spec = spec.next)
2740 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2742 specifiers->Remove(spec);
2743 FreeSpecifier(spec);
2748 funcDecl = GetFuncDecl(d);
2750 // Make sure we don't have empty parameter declarations for static methods...
2751 if(funcDecl && !funcDecl.function.parameters)
2753 funcDecl.function.parameters = MkList();
2754 funcDecl.function.parameters->Insert(null,
2755 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2758 ListAdd(declarators, MkInitDeclarator(d, null));
2761 Context oldCtx = curContext;
2762 curContext = globalContext;
2763 decl = MkDeclaration(specifiers, declarators);
2764 curContext = oldCtx;
2767 // Keep a different symbol for the function definition than the declaration...
2768 if(symbol.pointerExternal)
2770 Symbol functionSymbol { };
2773 *functionSymbol = *symbol;
2774 functionSymbol.string = CopyString(symbol.string);
2775 if(functionSymbol.type)
2776 functionSymbol.type.refCount++;
2779 excludedSymbols->Add(functionSymbol);
2781 symbol.pointerExternal.symbol = functionSymbol;
2783 external = MkExternalDeclaration(decl);
2785 ast->Insert(curExternal.prev, external);
2786 external.symbol = symbol;
2787 symbol.pointerExternal = external;
2791 // Move declaration higher...
2792 ast->Move(symbol.pointerExternal, curExternal.prev);
2796 symbol.id = curExternal.symbol.idCode;
2799 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2802 void DeclareGlobalData(GlobalData data)
2804 Symbol symbol = data.symbol;
2805 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2810 symbol = data.symbol = Symbol { };
2813 data.dataType = ProcessTypeString(data.dataTypeString, false);
2814 DeclareType(data.dataType, true, true);
2817 if(!symbol.pointerExternal)
2819 // We need a declaration here :)
2821 OldList * specifiers, * declarators;
2825 specifiers = MkList();
2826 declarators = MkList();
2828 ListAdd(specifiers, MkSpecifier(EXTERN));
2829 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2830 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2832 ListAdd(declarators, MkInitDeclarator(d, null));
2834 decl = MkDeclaration(specifiers, declarators);
2835 external = MkExternalDeclaration(decl);
2837 ast->Insert(curExternal.prev, external);
2838 external.symbol = symbol;
2839 symbol.pointerExternal = external;
2843 // Move declaration higher...
2844 ast->Move(symbol.pointerExternal, curExternal.prev);
2848 symbol.id = curExternal.symbol.idCode;
2853 class Conversion : struct
2855 Conversion prev, next;
2861 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2865 // Property convert;
2867 if(source.kind == templateType && dest.kind != templateType)
2869 Type type = ProcessTemplateParameterType(source.templateParameter);
2870 if(type) source = type;
2873 if(dest.kind == templateType && source.kind != templateType)
2875 Type type = ProcessTemplateParameterType(dest.templateParameter);
2876 if(type) dest = type;
2879 if(dest.classObjectType == typedObject)
2881 if(source.classObjectType != anyObject)
2885 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2886 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2894 if(source.classObjectType == anyObject)
2896 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2900 if((dest.kind == structType && source.kind == structType) ||
2901 (dest.kind == unionType && source.kind == unionType))
2903 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2904 (source.members.first && source.members.first == dest.members.first))
2908 if(dest.kind == ellipsisType && source.kind != voidType)
2911 if(dest.kind == pointerType && dest.type.kind == voidType &&
2912 ((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))
2913 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2915 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2917 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2919 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2920 ((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))
2921 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2923 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2925 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2928 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2930 if(source._class.registered && source._class.registered.type == unitClass)
2932 if(conversions != null)
2934 if(source._class.registered == dest._class.registered)
2939 Class sourceBase, destBase;
2940 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2941 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2942 if(sourceBase == destBase)
2946 // Don't match enum inheriting from other enum if resolving enumeration values
2947 // TESTING: !dest.classObjectType
2948 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2950 (!source._class.registered || source._class.registered.type != enumClass) ||
2951 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2955 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2957 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2958 ((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)
2960 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2968 // JUST ADDED THIS...
2969 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2974 // Just added this for Straight conversion of ColorAlpha => Color
2975 if(source.kind == classType)
2978 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2981 for(convert = _class.conversions.first; convert; convert = convert.next)
2983 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2985 Conversion after = (conversions != null) ? conversions.last : null;
2987 if(!convert.dataType)
2988 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2989 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
2991 if(!conversions && !convert.Get)
2993 else if(conversions != null)
2995 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2996 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
2997 (dest.kind != classType || dest._class.registered != _class.base))
3001 Conversion conv { convert = convert, isGet = true };
3002 // conversions.Add(conv);
3003 conversions.Insert(after, conv);
3015 if(dest.kind == classType)
3018 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3021 for(convert = _class.conversions.first; convert; convert = convert.next)
3023 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3025 // Conversion after = (conversions != null) ? conversions.last : null;
3027 if(!convert.dataType)
3028 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3029 // Just added this equality check to prevent recursion.... Make it safer?
3030 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3031 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3033 if(!conversions && !convert.Set)
3035 else if(conversions != null)
3037 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3038 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3039 (source.kind != classType || source._class.registered != _class.base))
3043 // *** Testing this! ***
3044 Conversion conv { convert = convert };
3045 conversions.Add(conv);
3046 //conversions.Insert(after, conv);
3054 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3056 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3057 (source.kind != classType || source._class.registered.type != structClass))
3061 // TESTING THIS... IS THIS OK??
3062 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3064 if(!dest._class.registered.dataType)
3065 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3066 // Only support this for classes...
3067 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3068 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3070 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3079 if(source.kind == classType)
3082 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3085 for(convert = _class.conversions.first; convert; convert = convert.next)
3087 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3089 Conversion after = (conversions != null) ? conversions.last : null;
3091 if(!convert.dataType)
3092 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3093 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3095 if(!conversions && !convert.Get)
3097 else if(conversions != null)
3099 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3100 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3101 (dest.kind != classType || dest._class.registered != _class.base))
3105 Conversion conv { convert = convert, isGet = true };
3107 // conversions.Add(conv);
3108 conversions.Insert(after, conv);
3117 // TESTING THIS... IS THIS OK??
3118 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3120 if(!source._class.registered.dataType)
3121 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3122 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3130 if(source.kind == classType || source.kind == subClassType)
3132 else if(dest.kind == source.kind &&
3133 (dest.kind != structType && dest.kind != unionType &&
3134 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3136 // RECENTLY ADDED THESE
3137 else if(dest.kind == doubleType && source.kind == floatType)
3139 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3141 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3143 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3145 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3147 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3149 else if(source.kind == enumType &&
3150 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3152 else if(dest.kind == enumType &&
3153 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3155 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3156 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3158 Type paramSource, paramDest;
3160 if(dest.kind == methodType)
3161 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3162 if(source.kind == methodType)
3163 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3165 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3166 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3167 if(dest.kind == methodType)
3168 dest = dest.method.dataType;
3169 if(source.kind == methodType)
3170 source = source.method.dataType;
3172 paramSource = source.params.first;
3173 if(paramSource && paramSource.kind == voidType) paramSource = null;
3174 paramDest = dest.params.first;
3175 if(paramDest && paramDest.kind == voidType) paramDest = null;
3178 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3179 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3181 // Source thisClass must be derived from destination thisClass
3182 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3183 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3185 if(paramDest && paramDest.kind == classType)
3186 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3188 Compiler_Error($"method class should not take an object\n");
3191 paramDest = paramDest.next;
3193 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3195 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3199 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3201 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3207 // THIS WAS BACKWARDS:
3208 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3209 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3212 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3214 Compiler_Error($"overriding class expected to be derived from method class\n");
3218 paramSource = paramSource.next;
3224 // Source thisClass must be derived from destination thisClass
3225 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3227 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3233 // THIS WAS BACKWARDS TOO??
3234 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3235 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3238 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3240 //Compiler_Error($"overriding class expected to be derived from method class\n");
3248 // Source return type must be derived from destination return type
3249 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3251 Compiler_Warning($"incompatible return type for function\n");
3257 for(; paramDest; paramDest = paramDest.next)
3261 //Compiler_Warning($"not enough parameters\n");
3262 Compiler_Error($"not enough parameters\n");
3266 Type paramDestType = paramDest;
3267 Type paramSourceType = paramSource;
3268 Type type = paramDestType;
3270 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3271 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3272 paramSource.kind != templateType)
3275 ClassTemplateParameter curParam = null;
3277 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3280 if(sClass.templateClass) sClass = sClass.templateClass;
3281 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3283 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3285 for(sClass = sClass.base; sClass; sClass = sClass.base)
3287 if(sClass.templateClass) sClass = sClass.templateClass;
3288 id += sClass.templateParams.count;
3299 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3300 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3304 // paramDest must be derived from paramSource
3305 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3306 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3310 PrintType(paramDest, type, false, true);
3311 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3313 if(paramDestType != paramDest)
3314 FreeType(paramDestType);
3317 if(paramDestType != paramDest)
3318 FreeType(paramDestType);
3321 paramSource = paramSource.next;
3325 Compiler_Error($"too many parameters\n");
3330 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3334 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3335 (source.kind == arrayType || source.kind == pointerType))
3337 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3344 static void FreeConvert(Conversion convert)
3346 if(convert.resultType)
3347 FreeType(convert.resultType);
3350 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3351 char * string, OldList conversions)
3355 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3357 Class _class = link.data;
3358 if(_class.type == enumClass)
3360 OldList converts { };
3362 type.kind = classType;
3365 _class.symbol = FindClass(_class.fullName);
3366 type._class = _class.symbol;
3368 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3371 Class enumClass = eSystem_FindClass(privateModule, "enum");
3375 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3377 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3378 for(value = e.values.first; value; value = value.next)
3380 if(!strcmp(value.name, string))
3385 FreeExpContents(sourceExp);
3386 FreeType(sourceExp.expType);
3388 sourceExp.isConstant = true;
3389 sourceExp.expType = MkClassType(baseClass.fullName);
3393 sourceExp.type = constantExp;
3394 if(!strcmp(baseClass.dataTypeString, "int"))
3395 sprintf(constant, "%d",(int)value.data);
3397 sprintf(constant, "0x%X",(int)value.data);
3398 sourceExp.constant = CopyString(constant);
3399 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3402 while(converts.first)
3404 Conversion convert = converts.first;
3405 converts.Remove(convert);
3406 conversions.Add(convert);
3415 converts.Free(FreeConvert);
3419 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3420 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3425 public bool ModuleVisibility(Module searchIn, Module searchFor)
3427 SubModule subModule;
3429 if(searchFor == searchIn)
3432 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3434 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3436 if(ModuleVisibility(subModule.module, searchFor))
3443 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3447 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3449 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3451 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3454 for(module = mainModule.application.allModules.first; module; module = module.next)
3456 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3462 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3464 Type source = sourceExp.expType;
3465 Type realDest = dest;
3466 Type backupSourceExpType = null;
3468 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3471 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3473 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3475 Class sourceBase, destBase;
3476 for(sourceBase = source._class.registered;
3477 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3478 sourceBase = sourceBase.base);
3479 for(destBase = dest._class.registered;
3480 destBase && destBase.base && destBase.base.type != systemClass;
3481 destBase = destBase.base);
3482 //if(source._class.registered == dest._class.registered)
3483 if(sourceBase == destBase)
3492 int64 value = MAXINT;
3497 if(sourceExp.type == constantExp)
3500 value = strtoll(sourceExp.constant, null, 0);
3502 value = strtoull(sourceExp.constant, null, 0);
3504 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3507 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3509 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3512 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3513 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3516 source = Type { kind = intType, isSigned = false, refCount = 1 };
3519 if(dest.kind == classType)
3521 Class _class = dest._class ? dest._class.registered : null;
3523 if(_class && _class.type == unitClass)
3525 if(source.kind != classType)
3528 Type tempDest, tempSource;
3530 for(; _class.base.type != systemClass; _class = _class.base);
3532 tempDest = tempType;
3534 tempType.kind = classType;
3536 _class.symbol = FindClass(_class.fullName);
3538 tempType._class = _class.symbol;
3539 tempType.truth = dest.truth;
3541 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3543 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3544 backupSourceExpType = sourceExp.expType;
3545 sourceExp.expType = dest; dest.refCount++;
3546 //sourceExp.expType = MkClassType(_class.fullName);
3554 // Why wasn't there something like this?
3555 if(_class && _class.type == bitClass && source.kind != classType)
3557 if(!dest._class.registered.dataType)
3558 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3559 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3562 FreeType(sourceExp.expType);
3563 source = sourceExp.expType = MkClassType(dest._class.string);
3566 //source.kind = classType;
3567 //source._class = dest._class;
3571 // Adding two enumerations
3573 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3575 if(!source._class.registered.dataType)
3576 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3577 if(!dest._class.registered.dataType)
3578 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3580 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3583 source = sourceExp.expType = MkClassType(dest._class.string);
3586 //source.kind = classType;
3587 //source._class = dest._class;
3591 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3593 OldList * specs = MkList();
3597 ReadString(string, sourceExp.string);
3598 decl = SpecDeclFromString(string, specs, null);
3600 FreeExpContents(sourceExp);
3601 FreeType(sourceExp.expType);
3603 sourceExp.type = classExp;
3604 sourceExp._classExp.specifiers = specs;
3605 sourceExp._classExp.decl = decl;
3606 sourceExp.expType = dest;
3611 if(backupSourceExpType) FreeType(backupSourceExpType);
3615 else if(source.kind == classType)
3617 Class _class = source._class ? source._class.registered : null;
3619 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3622 if(dest.kind != classType)
3624 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3625 if(!source._class.registered.dataType)
3626 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3629 dest = MkClassType(source._class.string);
3630 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3631 // dest = MkClassType(source._class.string);
3635 if(dest.kind != classType)
3638 Type tempDest, tempSource;
3640 if(!source._class.registered.dataType)
3641 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3643 for(; _class.base.type != systemClass; _class = _class.base);
3645 tempSource = tempType;
3646 tempType.kind = classType;
3647 tempType._class = FindClass(_class.fullName);
3648 tempType.truth = source.truth;
3649 tempType.classObjectType = source.classObjectType;
3652 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3654 // PUT THIS BACK TESTING UNITS?
3655 if(conversions.last)
3657 ((Conversion)(conversions.last)).resultType = dest;
3661 FreeType(sourceExp.expType);
3662 sourceExp.expType = MkClassType(_class.fullName);
3663 sourceExp.expType.truth = source.truth;
3664 sourceExp.expType.classObjectType = source.classObjectType;
3666 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3668 if(!sourceExp.destType)
3670 FreeType(sourceExp.destType);
3671 sourceExp.destType = sourceExp.expType;
3672 if(sourceExp.expType)
3673 sourceExp.expType.refCount++;
3676 //source = _class.dataType;
3679 // TOCHECK: TESTING THIS NEW CODE
3680 if(!_class.dataType)
3681 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3683 dest = MkClassType(source._class.string);
3684 dest.truth = source.truth;
3685 dest.classObjectType = source.classObjectType;
3688 source = _class.dataType;
3698 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3708 if(source.kind == classType)
3710 Class _class = source._class.registered;
3711 if(_class.type == unitClass)
3713 if(!_class.dataType)
3714 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3715 source = _class.dataType;
3719 if(dest.kind == classType)
3721 Class _class = dest._class ? dest._class.registered : null;
3722 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3723 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3725 if(_class.type == normalClass || _class.type == noHeadClass)
3727 Expression newExp { };
3728 *newExp = *sourceExp;
3729 if(sourceExp.destType) sourceExp.destType.refCount++;
3730 if(sourceExp.expType) sourceExp.expType.refCount++;
3731 sourceExp.type = castExp;
3732 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3733 sourceExp.cast.exp = newExp;
3734 FreeType(sourceExp.expType);
3735 sourceExp.expType = null;
3736 ProcessExpressionType(sourceExp);
3738 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3741 FreeType(sourceExp.expType);
3742 sourceExp.expType = dest;
3746 if(inCompiler) FreeType(dest);
3748 if(backupSourceExpType) FreeType(backupSourceExpType);
3752 if(!_class.dataType)
3753 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3755 dest = _class.dataType;
3759 // Accept lower precision types for units, since we want to keep the unit type
3760 if(dest.kind == doubleType &&
3761 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3762 source.kind == charType || source.kind == _BoolType))
3764 specs = MkListOne(MkSpecifier(DOUBLE));
3766 else if(dest.kind == floatType &&
3767 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3768 source.kind == _BoolType || source.kind == doubleType))
3770 specs = MkListOne(MkSpecifier(FLOAT));
3772 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3773 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3776 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3777 ListAdd(specs, MkSpecifier(INT64));
3779 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3780 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3783 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3784 ListAdd(specs, MkSpecifier(INT));
3786 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3787 source.kind == floatType || source.kind == doubleType))
3790 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3791 ListAdd(specs, MkSpecifier(SHORT));
3793 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3794 source.kind == floatType || source.kind == doubleType))
3797 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3798 ListAdd(specs, MkSpecifier(CHAR));
3804 if(backupSourceExpType)
3806 // Failed to convert: revert previous exp type
3807 if(sourceExp.expType) FreeType(sourceExp.expType);
3808 sourceExp.expType = backupSourceExpType;
3813 else if(dest.kind == doubleType &&
3814 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3815 source.kind == _BoolType || source.kind == charType))
3817 specs = MkListOne(MkSpecifier(DOUBLE));
3819 else if(dest.kind == floatType &&
3820 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3822 specs = MkListOne(MkSpecifier(FLOAT));
3824 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3825 (value == 1 || value == 0))
3828 ListAdd(specs, MkSpecifier(BOOL));
3830 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3831 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3834 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3835 ListAdd(specs, MkSpecifier(CHAR));
3837 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3838 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3841 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3842 ListAdd(specs, MkSpecifier(SHORT));
3844 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3847 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3848 ListAdd(specs, MkSpecifier(INT));
3850 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3853 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3854 ListAdd(specs, MkSpecifier(INT64));
3856 else if(dest.kind == enumType &&
3857 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3859 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3865 if(backupSourceExpType)
3867 // Failed to convert: revert previous exp type
3868 if(sourceExp.expType) FreeType(sourceExp.expType);
3869 sourceExp.expType = backupSourceExpType;
3876 Expression newExp { };
3877 *newExp = *sourceExp;
3880 if(sourceExp.destType) sourceExp.destType.refCount++;
3881 if(sourceExp.expType) sourceExp.expType.refCount++;
3883 sourceExp.type = castExp;
3884 if(realDest.kind == classType)
3886 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3887 FreeList(specs, FreeSpecifier);
3890 sourceExp.cast.typeName = MkTypeName(specs, null);
3891 if(newExp.type == opExp)
3893 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3896 sourceExp.cast.exp = newExp;
3898 FreeType(sourceExp.expType);
3899 sourceExp.expType = null;
3900 ProcessExpressionType(sourceExp);
3903 FreeList(specs, FreeSpecifier);
3907 if(backupSourceExpType) FreeType(backupSourceExpType);
3913 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3914 if(sourceExp.type == identifierExp)
3916 Identifier id = sourceExp.identifier;
3917 if(dest.kind == classType)
3919 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3921 Class _class = dest._class.registered;
3922 Class enumClass = eSystem_FindClass(privateModule, "enum");
3925 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3928 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3929 for(value = e.values.first; value; value = value.next)
3931 if(!strcmp(value.name, id.string))
3936 FreeExpContents(sourceExp);
3937 FreeType(sourceExp.expType);
3939 sourceExp.isConstant = true;
3940 sourceExp.expType = MkClassType(_class.fullName);
3944 sourceExp.type = constantExp;
3945 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3946 sprintf(constant, "%d", (int) value.data);
3948 sprintf(constant, "0x%X", (int) value.data);
3949 sourceExp.constant = CopyString(constant);
3950 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3959 // Loop through all enum classes
3960 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3967 #define TERTIARY(o, name, m, t, p) \
3968 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3970 exp.type = constantExp; \
3971 exp.string = p(op1.m ? op2.m : op3.m); \
3973 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3977 #define BINARY(o, name, m, t, p) \
3978 static bool name(Expression exp, Operand op1, Operand op2) \
3981 exp.type = constantExp; \
3982 exp.string = p(op1.m o value2); \
3984 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3988 #define BINARY_DIVIDE(o, name, m, t, p) \
3989 static bool name(Expression exp, Operand op1, Operand op2) \
3992 exp.type = constantExp; \
3993 exp.string = p(value2 ? (op1.m o value2) : 0); \
3995 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3999 #define UNARY(o, name, m, t, p) \
4000 static bool name(Expression exp, Operand op1) \
4002 exp.type = constantExp; \
4003 exp.string = p((t)(o op1.m)); \
4005 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4009 #define OPERATOR_ALL(macro, o, name) \
4010 macro(o, Int##name, i, int, PrintInt) \
4011 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4012 macro(o, Int64##name, i64, int64, PrintInt64) \
4013 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4014 macro(o, Short##name, s, short, PrintShort) \
4015 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4016 macro(o, Char##name, c, char, PrintChar) \
4017 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4018 macro(o, Float##name, f, float, PrintFloat) \
4019 macro(o, Double##name, d, double, PrintDouble)
4021 #define OPERATOR_INTTYPES(macro, o, name) \
4022 macro(o, Int##name, i, int, PrintInt) \
4023 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4024 macro(o, Int64##name, i64, int64, PrintInt64) \
4025 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4026 macro(o, Short##name, s, short, PrintShort) \
4027 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4028 macro(o, Char##name, c, char, PrintChar) \
4029 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4032 // binary arithmetic
4033 OPERATOR_ALL(BINARY, +, Add)
4034 OPERATOR_ALL(BINARY, -, Sub)
4035 OPERATOR_ALL(BINARY, *, Mul)
4036 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4037 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4040 OPERATOR_ALL(UNARY, -, Neg)
4042 // unary arithmetic increment and decrement
4043 OPERATOR_ALL(UNARY, ++, Inc)
4044 OPERATOR_ALL(UNARY, --, Dec)
4046 // binary arithmetic assignment
4047 OPERATOR_ALL(BINARY, =, Asign)
4048 OPERATOR_ALL(BINARY, +=, AddAsign)
4049 OPERATOR_ALL(BINARY, -=, SubAsign)
4050 OPERATOR_ALL(BINARY, *=, MulAsign)
4051 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4052 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4055 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4056 OPERATOR_INTTYPES(BINARY, |, BitOr)
4057 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4058 OPERATOR_INTTYPES(BINARY, <<, LShift)
4059 OPERATOR_INTTYPES(BINARY, >>, RShift)
4062 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4064 // binary bitwise assignment
4065 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4066 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4067 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4068 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4069 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4071 // unary logical negation
4072 OPERATOR_INTTYPES(UNARY, !, Not)
4074 // binary logical equality
4075 OPERATOR_ALL(BINARY, ==, Equ)
4076 OPERATOR_ALL(BINARY, !=, Nqu)
4079 OPERATOR_ALL(BINARY, &&, And)
4080 OPERATOR_ALL(BINARY, ||, Or)
4082 // binary logical relational
4083 OPERATOR_ALL(BINARY, >, Grt)
4084 OPERATOR_ALL(BINARY, <, Sma)
4085 OPERATOR_ALL(BINARY, >=, GrtEqu)
4086 OPERATOR_ALL(BINARY, <=, SmaEqu)
4088 // tertiary condition operator
4089 OPERATOR_ALL(TERTIARY, ?, Cond)
4091 //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
4092 #define OPERATOR_TABLE_ALL(name, type) \
4093 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4095 type##Inc, type##Dec, \
4096 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4097 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4099 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4101 type##Equ, type##Nqu, \
4102 type##And, type##Or, \
4103 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4106 #define OPERATOR_TABLE_INTTYPES(name, type) \
4107 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4109 type##Inc, type##Dec, \
4110 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4111 null, null, null, null, null, \
4113 null, null, null, null, null, \
4115 type##Equ, type##Nqu, \
4116 type##And, type##Or, \
4117 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4120 OPERATOR_TABLE_ALL(int, Int)
4121 OPERATOR_TABLE_ALL(uint, UInt)
4122 OPERATOR_TABLE_ALL(int64, Int64)
4123 OPERATOR_TABLE_ALL(uint64, UInt64)
4124 OPERATOR_TABLE_ALL(short, Short)
4125 OPERATOR_TABLE_ALL(ushort, UShort)
4126 OPERATOR_TABLE_INTTYPES(float, Float)
4127 OPERATOR_TABLE_INTTYPES(double, Double)
4128 OPERATOR_TABLE_ALL(char, Char)
4129 OPERATOR_TABLE_ALL(uchar, UChar)
4131 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4132 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4133 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4134 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4135 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4136 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4137 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4138 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4140 public void ReadString(char * output, char * string)
4142 int len = strlen(string);
4144 bool quoted = false, escaped = false;
4145 for(c = 0; c<len; c++)
4147 char ch = string[c];
4152 case 'n': output[d] = '\n'; break;
4153 case 't': output[d] = '\t'; break;
4154 case 'a': output[d] = '\a'; break;
4155 case 'b': output[d] = '\b'; break;
4156 case 'f': output[d] = '\f'; break;
4157 case 'r': output[d] = '\r'; break;
4158 case 'v': output[d] = '\v'; break;
4159 case '\\': output[d] = '\\'; break;
4160 case '\"': output[d] = '\"'; break;
4161 case '\'': output[d] = '\''; break;
4162 default: output[d] = ch;
4183 // String Unescape Copy
4185 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4186 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4187 public int UnescapeString(char * d, char * s, int len)
4191 while(j < len && (ch = s[j]))
4196 switch((ch = s[++j]))
4198 case 'n': d[k] = '\n'; break;
4199 case 't': d[k] = '\t'; break;
4200 case 'a': d[k] = '\a'; break;
4201 case 'b': d[k] = '\b'; break;
4202 case 'f': d[k] = '\f'; break;
4203 case 'r': d[k] = '\r'; break;
4204 case 'v': d[k] = '\v'; break;
4205 case '\\': d[k] = '\\'; break;
4206 case '\"': d[k] = '\"'; break;
4207 case '\'': d[k] = '\''; break;
4208 default: d[k] = '\\'; d[k] = ch;
4220 public char * OffsetEscapedString(char * s, int len, int offset)
4224 while(j < len && k < offset && (ch = s[j]))
4229 return (k == offset) ? s + j : null;
4232 public Operand GetOperand(Expression exp)
4235 Type type = exp.expType;
4238 while(type.kind == classType &&
4239 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4241 if(!type._class.registered.dataType)
4242 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4243 type = type._class.registered.dataType;
4246 op.kind = type.kind;
4247 op.type = exp.expType;
4248 if(exp.type == stringExp && op.kind == pointerType)
4250 op.ui64 = (uint64)exp.string;
4251 op.kind = pointerType;
4254 else if(exp.isConstant && exp.type == constantExp)
4261 if(exp.constant[0] == '\'')
4263 op.c = exp.constant[1];
4266 else if(type.isSigned)
4268 op.c = (char)strtol(exp.constant, null, 0);
4273 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4281 op.s = (short)strtol(exp.constant, null, 0);
4286 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4294 op.i = (int)strtol(exp.constant, null, 0);
4299 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4307 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4312 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4315 op.kind = int64Type;
4320 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4325 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4328 op.kind = int64Type;
4333 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4338 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4341 op.kind = int64Type;
4344 op.f = (float)strtod(exp.constant, null);
4348 op.d = (double)strtod(exp.constant, null);
4351 //case classType: For when we have operator overloading...
4352 // Pointer additions
4353 //case functionType:
4357 op.ui64 = _strtoui64(exp.constant, null, 0);
4358 op.kind = pointerType;
4368 static void UnusedFunction()
4371 a.OnGetString(0,0,0);
4374 extern int __ecereVMethodID_class_OnGetString;
4377 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4379 DataMember dataMember;
4380 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4382 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4383 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4387 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4389 void * ptr = inst.data + dataMember.offset + offset;
4390 char * result = null;
4391 exp.loc = member.loc = inst.loc;
4392 ((Identifier)member.identifiers->first).loc = inst.loc;
4394 if(!dataMember.dataType)
4395 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4396 type = dataMember.dataType;
4397 if(type.kind == classType)
4399 Class _class = type._class.registered;
4400 if(_class.type == enumClass)
4402 Class enumClass = eSystem_FindClass(privateModule, "enum");
4405 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4407 for(item = e.values.first; item; item = item.next)
4409 if((int)item.data == *(int *)ptr)
4417 exp.identifier = MkIdentifier(result);
4418 exp.type = identifierExp;
4419 exp.destType = MkClassType(_class.fullName);
4420 ProcessExpressionType(exp);
4424 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4426 if(!_class.dataType)
4427 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4428 type = _class.dataType;
4437 FreeExpContents(exp);
4439 exp.constant = PrintFloat(*(float*)ptr);
4440 exp.type = constantExp;
4445 FreeExpContents(exp);
4447 exp.constant = PrintDouble(*(double*)ptr);
4448 exp.type = constantExp;
4453 FreeExpContents(exp);
4455 exp.constant = PrintInt(*(int*)ptr);
4456 exp.type = constantExp;
4461 FreeExpContents(exp);
4463 exp.constant = PrintInt64(*(int64*)ptr);
4464 exp.type = constantExp;
4469 FreeExpContents(exp);
4470 // TODO: This should probably use proper type
4471 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4472 exp.type = constantExp;
4477 FreeExpContents(exp);
4478 // TODO: This should probably use proper type
4479 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4480 exp.type = constantExp;
4484 Compiler_Error($"Unhandled type populating instance\n");
4487 ListAdd(memberList, member);
4490 if(parentDataMember.type == unionMember)
4495 void PopulateInstance(Instantiation inst)
4497 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4498 Class _class = classSym.registered;
4499 DataMember dataMember;
4500 OldList * memberList = MkList();
4501 // Added this check and ->Add to prevent memory leaks on bad code
4503 inst.members = MkListOne(MkMembersInitList(memberList));
4505 inst.members->Add(MkMembersInitList(memberList));
4506 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4508 if(!dataMember.isProperty)
4510 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4511 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4515 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4517 void * ptr = inst.data + dataMember.offset;
4518 char * result = null;
4520 exp.loc = member.loc = inst.loc;
4521 ((Identifier)member.identifiers->first).loc = inst.loc;
4523 if(!dataMember.dataType)
4524 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4525 type = dataMember.dataType;
4526 if(type.kind == classType)
4528 Class _class = type._class.registered;
4529 if(_class.type == enumClass)
4531 Class enumClass = eSystem_FindClass(privateModule, "enum");
4534 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4536 for(item = e.values.first; item; item = item.next)
4538 if((int)item.data == *(int *)ptr)
4547 exp.identifier = MkIdentifier(result);
4548 exp.type = identifierExp;
4549 exp.destType = MkClassType(_class.fullName);
4550 ProcessExpressionType(exp);
4553 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4555 if(!_class.dataType)
4556 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4557 type = _class.dataType;
4566 exp.constant = PrintFloat(*(float*)ptr);
4567 exp.type = constantExp;
4572 exp.constant = PrintDouble(*(double*)ptr);
4573 exp.type = constantExp;
4578 exp.constant = PrintInt(*(int*)ptr);
4579 exp.type = constantExp;
4584 exp.constant = PrintInt64(*(int64*)ptr);
4585 exp.type = constantExp;
4590 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4591 exp.type = constantExp;
4595 Compiler_Error($"Unhandled type populating instance\n");
4598 ListAdd(memberList, member);
4604 void ComputeInstantiation(Expression exp)
4606 Instantiation inst = exp.instance;
4607 MembersInit members;
4608 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4609 Class _class = classSym ? classSym.registered : null;
4610 DataMember curMember = null;
4611 Class curClass = null;
4612 DataMember subMemberStack[256];
4613 int subMemberStackPos = 0;
4616 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4618 // Don't recompute the instantiation...
4619 // Non Simple classes will have become constants by now
4623 if(_class.type == normalClass || _class.type == noHeadClass)
4625 inst.data = (byte *)eInstance_New(_class);
4626 if(_class.type == normalClass)
4627 ((Instance)inst.data)._refCount++;
4630 inst.data = new0 byte[_class.structSize];
4635 for(members = inst.members->first; members; members = members.next)
4637 switch(members.type)
4639 case dataMembersInit:
4641 if(members.dataMembers)
4644 for(member = members.dataMembers->first; member; member = member.next)
4646 Identifier ident = member.identifiers ? member.identifiers->first : null;
4649 Property prop = null;
4650 DataMember dataMember = null;
4651 Method method = null;
4652 uint dataMemberOffset;
4656 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4659 if(curMember.isProperty)
4660 prop = (Property)curMember;
4663 dataMember = curMember;
4665 // CHANGED THIS HERE
4666 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4668 // 2013/17/29 -- It seems that this was missing here!
4669 if(_class.type == normalClass)
4670 dataMemberOffset += _class.base.structSize;
4671 // dataMemberOffset = dataMember.offset;
4678 prop = eClass_FindProperty(_class, ident.string, privateModule);
4682 if(prop.memberAccess == publicAccess)
4684 curMember = (DataMember)prop;
4685 curClass = prop._class;
4690 DataMember _subMemberStack[256];
4691 int _subMemberStackPos = 0;
4693 // FILL MEMBER STACK
4694 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4699 if(dataMember.memberAccess == publicAccess)
4701 curMember = dataMember;
4702 curClass = dataMember._class;
4703 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4704 subMemberStackPos = _subMemberStackPos;
4710 if(found && member.initializer && member.initializer.type == expInitializer)
4712 Expression value = member.initializer.exp;
4714 bool deepMember = false;
4717 type = prop.dataType;
4721 if(!dataMember.dataType)
4722 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4724 type = dataMember.dataType;
4727 if(ident && ident.next)
4731 // for(; ident && type; ident = ident.next)
4732 for(ident = ident.next; ident && type; ident = ident.next)
4734 if(type.kind == classType)
4736 prop = eClass_FindProperty(type._class.registered,
4737 ident.string, privateModule);
4739 type = prop.dataType;
4742 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4743 ident.string, &dataMemberOffset, privateModule, null, null);
4745 type = dataMember.dataType;
4748 else if(type.kind == structType || type.kind == unionType)
4751 for(memberType = type.members.first; memberType; memberType = memberType.next)
4753 if(!strcmp(memberType.name, ident.string))
4764 FreeType(value.destType);
4765 value.destType = type;
4766 if(type) type.refCount++;
4767 ComputeExpression(value);
4769 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4771 if(type.kind == classType)
4773 Class _class = type._class.registered;
4774 if(_class.type == bitClass || _class.type == unitClass ||
4775 _class.type == enumClass)
4777 if(!_class.dataType)
4778 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4779 type = _class.dataType;
4785 void * ptr = inst.data + dataMemberOffset;
4787 if(value.type == constantExp)
4793 GetInt(value, (int*)ptr);
4798 GetInt64(value, (int64*)ptr);
4803 GetIntPtr(value, (intptr*)ptr);
4808 GetIntSize(value, (intsize*)ptr);
4813 GetFloat(value, (float*)ptr);
4818 GetDouble(value, (double *)ptr);
4823 else if(value.type == instanceExp)
4825 if(type.kind == classType)
4827 Class _class = type._class.registered;
4828 if(_class.type == structClass)
4830 ComputeTypeSize(type);
4831 if(value.instance.data)
4832 memcpy(ptr, value.instance.data, type.size);
4839 if(value.type == instanceExp && value.instance.data)
4841 if(type.kind == classType)
4843 Class _class = type._class.registered;
4844 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4846 void (*Set)(void *, void *) = (void *)prop.Set;
4847 Set(inst.data, value.instance.data);
4848 PopulateInstance(inst);
4852 else if(value.type == constantExp)
4858 void (*Set)(void *, double) = (void *)prop.Set;
4859 Set(inst.data, strtod(value.constant, null) );
4864 void (*Set)(void *, float) = (void *)prop.Set;
4865 Set(inst.data, (float)(strtod(value.constant, null)));
4870 void (*Set)(void *, int) = (void *)prop.Set;
4871 Set(inst.data, (int)strtol(value.constant, null, 0));
4876 void (*Set)(void *, int64) = (void *)prop.Set;
4877 Set(inst.data, _strtoi64(value.constant, null, 0));
4882 void (*Set)(void *, intptr) = (void *)prop.Set;
4883 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4888 void (*Set)(void *, intsize) = (void *)prop.Set;
4889 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4894 else if(value.type == stringExp)
4897 ReadString(temp, value.string);
4898 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4902 else if(!deepMember && type && _class.type == unitClass)
4906 // Only support converting units to units for now...
4907 if(value.type == constantExp)
4909 if(type.kind == classType)
4911 Class _class = type._class.registered;
4912 if(_class.type == unitClass)
4914 if(!_class.dataType)
4915 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4916 type = _class.dataType;
4919 // TODO: Assuming same base type for units...
4925 float (*Set)(float) = (void *)prop.Set;
4926 GetFloat(member.initializer.exp, &fValue);
4927 exp.constant = PrintFloat(Set(fValue));
4928 exp.type = constantExp;
4934 double (*Set)(double) = (void *)prop.Set;
4935 GetDouble(member.initializer.exp, &dValue);
4936 exp.constant = PrintDouble(Set(dValue));
4937 exp.type = constantExp;
4944 else if(!deepMember && type && _class.type == bitClass)
4948 if(value.type == instanceExp && value.instance.data)
4950 unsigned int (*Set)(void *) = (void *)prop.Set;
4951 bits = Set(value.instance.data);
4953 else if(value.type == constantExp)
4959 BitMember bitMember = (BitMember) dataMember;
4962 GetInt(value, &part);
4963 bits = (bits & ~bitMember.mask);
4964 if(!bitMember.dataType)
4965 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4967 type = bitMember.dataType;
4969 if(type.kind == classType && type._class && type._class.registered)
4971 if(!type._class.registered.dataType)
4972 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4973 type = type._class.registered.dataType;
4981 bits |= ((char)part << bitMember.pos);
4983 bits |= ((unsigned char)part << bitMember.pos);
4987 bits |= ((short)part << bitMember.pos);
4989 bits |= ((unsigned short)part << bitMember.pos);
4994 bits |= ((int)part << bitMember.pos);
4996 bits |= ((unsigned int)part << bitMember.pos);
5000 bits |= ((int64)part << bitMember.pos);
5002 bits |= ((uint64)part << bitMember.pos);
5007 bits |= ((intptr)part << bitMember.pos);
5011 bits |= ((uintptr)part << bitMember.pos);
5017 bits |= ((ssize_t)(intsize)part << bitMember.pos);
5021 bits |= ((size_t) (uintsize)part << bitMember.pos);
5030 if(_class && _class.type == unitClass)
5032 ComputeExpression(member.initializer.exp);
5033 exp.constant = member.initializer.exp.constant;
5034 exp.type = constantExp;
5036 member.initializer.exp.constant = null;
5046 if(_class && _class.type == bitClass)
5048 exp.constant = PrintHexUInt(bits);
5049 exp.type = constantExp;
5051 if(exp.type != instanceExp)
5057 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5059 bool result = false;
5063 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5064 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5068 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5069 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5072 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5073 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5074 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5077 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5078 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5079 result = GetOpFloat(op, &op.f);
5082 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5083 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5084 result = GetOpDouble(op, &op.d);
5087 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5088 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5089 result = GetOpUIntPtr(op, &op.ui64);
5092 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5093 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5094 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5097 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5098 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5101 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5102 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5108 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5110 if(exp.op.op == SIZEOF)
5112 FreeExpContents(exp);
5113 exp.type = constantExp;
5114 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5125 // Provide default unary +
5126 Expression exp2 = exp.op.exp2;
5128 FreeExpContents(exp);
5129 FreeType(exp.expType);
5130 FreeType(exp.destType);
5136 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5138 // unary arithmetic increment and decrement
5139 //OPERATOR_ALL(UNARY, ++, Inc)
5140 //OPERATOR_ALL(UNARY, --, Dec)
5143 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5145 // unary logical negation
5147 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5153 if(op1 && op2 && op1.kind != op2.kind)
5155 if(Promote(op2, op1.kind, op1.type.isSigned))
5156 op2.kind = op1.kind, op2.ops = op1.ops;
5157 else if(Promote(op1, op2.kind, op2.type.isSigned))
5158 op1.kind = op2.kind, op1.ops = op2.ops;
5162 // binary arithmetic
5164 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5167 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5170 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5173 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5176 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5178 // binary arithmetic assignment
5179 //OPERATOR_ALL(BINARY, =, Asign)
5180 //OPERATOR_ALL(BINARY, +=, AddAsign)
5181 //OPERATOR_ALL(BINARY, -=, SubAsign)
5182 //OPERATOR_ALL(BINARY, *=, MulAsign)
5183 //OPERATOR_ALL(BINARY, /=, DivAsign)
5184 //OPERATOR_ALL(BINARY, %=, ModAsign)
5189 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5193 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5196 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5199 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5202 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5204 // binary bitwise assignment
5205 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5206 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5207 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5208 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5209 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5210 // binary logical equality
5212 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5215 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5219 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5222 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5224 // binary logical relational
5226 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5229 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5232 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5235 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5242 void ComputeExpression(Expression exp)
5244 char expString[10240];
5245 expString[0] = '\0';
5247 PrintExpression(exp, expString);
5254 ComputeInstantiation(exp);
5263 Expression exp1, exp2 = null;
5267 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5270 Expression e = exp.op.exp2;
5272 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5274 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5276 if(e.type == extensionCompoundExp)
5277 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5282 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5284 if(e.type == stringExp && e.string)
5286 char * string = e.string;
5287 int len = strlen(string);
5288 char * tmp = new char[len-2+1];
5289 len = UnescapeString(tmp, string + 1, len - 2);
5291 FreeExpContents(exp);
5292 exp.type = constantExp;
5293 exp.constant = PrintUInt(len + 1);
5297 Type type = e.expType;
5299 FreeExpContents(exp);
5300 exp.type = constantExp;
5301 exp.constant = PrintUInt(ComputeTypeSize(type));
5307 ComputeExpression(exp.op.exp2);
5311 ComputeExpression(exp.op.exp1);
5314 op1 = GetOperand(exp1);
5315 if(op1.type) op1.type.refCount++;
5318 op2 = GetOperand(exp2);
5319 if(op2.type) op2.type.refCount++;
5325 op1 = GetOperand(exp1);
5326 if(op1.type) op1.type.refCount++;
5329 CallOperator(exp, exp1, exp2, op1, op2);
5336 if(exp.op.exp1 && exp.op.exp2)
5341 FreeExpContents(exp);
5342 op1.ops.BitAnd(exp, op1, op2);
5351 FreeExpContents(exp);
5352 op1.ops.Mul(exp, op1, op2);
5361 FreeExpContents(exp);
5362 op1.ops.Add(exp, op1, op2);
5367 // Provide default unary +
5368 Expression exp2 = exp.op.exp2;
5370 FreeExpContents(exp);
5371 FreeType(exp.expType);
5372 FreeType(exp.destType);
5383 FreeExpContents(exp);
5384 op1.ops.Sub(exp, op1, op2);
5391 FreeExpContents(exp);
5392 op1.ops.Neg(exp, op1);
5399 FreeExpContents(exp);
5400 op1.ops.BitNot(exp, op1);
5406 FreeExpContents(exp);
5407 op1.ops.Not(exp, op1);
5410 // Binary only operators
5414 FreeExpContents(exp);
5415 op1.ops.Div(exp, op1, op2);
5421 FreeExpContents(exp);
5422 op1.ops.Mod(exp, op1, op2);
5434 FreeExpContents(exp);
5435 op1.ops.Sma(exp, op1, op2);
5444 FreeExpContents(exp);
5445 op1.ops.Grt(exp, op1, op2);
5454 FreeExpContents(exp);
5455 op1.ops.SmaEqu(exp, op1, op2);
5464 FreeExpContents(exp);
5465 op1.ops.GrtEqu(exp, op1, op2);
5474 FreeExpContents(exp);
5475 op1.ops.Equ(exp, op1, op2);
5484 FreeExpContents(exp);
5485 op1.ops.Nqu(exp, op1, op2);
5492 FreeExpContents(exp);
5493 op1.ops.BitOr(exp, op1, op2);
5499 FreeExpContents(exp);
5500 op1.ops.BitXor(exp, op1, op2);
5508 FreeExpContents(exp);
5509 exp.type = constantExp;
5510 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5514 if(op1.type) FreeType(op1.type);
5515 if(op2.type) FreeType(op2.type);
5519 case extensionExpressionExp:
5522 for(e = exp.list->first; e; e = n)
5527 OldList * list = exp.list;
5528 ComputeExpression(e);
5529 //FreeExpContents(exp);
5530 FreeType(exp.expType);
5531 FreeType(exp.destType);
5548 exp.isConstant = true;
5550 ComputeExpression(exp.index.exp);
5551 if(!exp.index.exp.isConstant)
5552 exp.isConstant = false;
5554 for(e = exp.index.index->first; e; e = e.next)
5556 ComputeExpression(e);
5559 // Check if this type is int
5562 exp.isConstant = false;
5564 exp.expType = Dereference(exp.index.exp.expType);
5570 Expression memberExp = exp.member.exp;
5571 Identifier memberID = exp.member.member;
5574 ComputeExpression(exp.member.exp);
5575 type = exp.member.exp.expType;
5578 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);
5579 Property prop = null;
5580 DataMember member = null;
5581 Class convertTo = null;
5582 if(type.kind == subClassType && exp.member.exp.type == classExp)
5583 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5590 PrintTypeNoConst(type, string, false, true);
5591 classSym = FindClass(string);
5592 _class = classSym ? classSym.registered : null;
5595 if(exp.member.member)
5597 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5599 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5601 if(!prop && !member && _class && exp.member.member)
5603 Symbol classSym = FindClass(exp.member.member.string);
5605 _class = classSym ? classSym.registered : null;
5606 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5613 Type type = prop.dataType;
5614 // TODO: Assuming same base type for units...
5615 if(_class.type == unitClass)
5617 if(type.kind == classType)
5619 Class _class = type._class.registered;
5620 if(_class.type == unitClass)
5622 if(!_class.dataType)
5623 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5624 type = _class.dataType;
5632 float (*Get)(float) = (void *)prop.Get;
5633 GetFloat(exp.member.exp, &value);
5634 exp.constant = PrintFloat(Get ? Get(value) : value);
5635 exp.type = constantExp;
5641 double (*Get)(double);
5642 GetDouble(exp.member.exp, &value);
5645 Get = (void *)prop.Set;
5647 Get = (void *)prop.Get;
5648 exp.constant = PrintDouble(Get ? Get(value) : value);
5649 exp.type = constantExp;
5658 Expression value = exp.member.exp;
5661 ProcessPropertyType(prop);
5663 type = prop.dataType;
5666 // printf("Investigate this\n");
5668 else if(_class.type == structClass)
5674 Class propertyClass = type._class.registered;
5675 if(propertyClass.type == structClass && value.type == instanceExp)
5677 void (*Set)(void *, void *) = (void *)prop.Set;
5678 exp.instance = Instantiation { };
5679 exp.instance.data = new0 byte[_class.structSize];
5680 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5681 exp.instance.loc = exp.loc;
5682 exp.type = instanceExp;
5683 Set(exp.instance.data, value.instance.data);
5684 PopulateInstance(exp.instance);
5691 void (*Set)(void *, int) = (void *)prop.Set;
5693 exp.instance = Instantiation { };
5694 exp.instance.data = new0 byte[_class.structSize];
5695 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5696 exp.instance.loc = exp.loc;
5697 exp.type = instanceExp;
5699 GetInt(value, &intValue);
5701 Set(exp.instance.data, intValue);
5702 PopulateInstance(exp.instance);
5708 void (*Set)(void *, int64) = (void *)prop.Set;
5710 exp.instance = Instantiation { };
5711 exp.instance.data = new0 byte[_class.structSize];
5712 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5713 exp.instance.loc = exp.loc;
5714 exp.type = instanceExp;
5716 GetInt64(value, &intValue);
5718 Set(exp.instance.data, intValue);
5719 PopulateInstance(exp.instance);
5726 void (*Set)(void *, intptr) = (void *)prop.Set;
5728 exp.instance = Instantiation { };
5729 exp.instance.data = new0 byte[_class.structSize];
5730 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5731 exp.instance.loc = exp.loc;
5732 exp.type = instanceExp;
5734 GetIntPtr(value, &intValue);
5736 Set(exp.instance.data, intValue);
5737 PopulateInstance(exp.instance);
5744 void (*Set)(void *, intsize) = (void *)prop.Set;
5746 exp.instance = Instantiation { };
5747 exp.instance.data = new0 byte[_class.structSize];
5748 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5749 exp.instance.loc = exp.loc;
5750 exp.type = instanceExp;
5752 GetIntSize(value, &intValue);
5754 Set(exp.instance.data, intValue);
5755 PopulateInstance(exp.instance);
5761 void (*Set)(void *, double) = (void *)prop.Set;
5763 exp.instance = Instantiation { };
5764 exp.instance.data = new0 byte[_class.structSize];
5765 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5766 exp.instance.loc = exp.loc;
5767 exp.type = instanceExp;
5769 GetDouble(value, &doubleValue);
5771 Set(exp.instance.data, doubleValue);
5772 PopulateInstance(exp.instance);
5777 else if(_class.type == bitClass)
5783 Class propertyClass = type._class.registered;
5784 if(propertyClass.type == structClass && value.instance.data)
5786 unsigned int (*Set)(void *) = (void *)prop.Set;
5787 unsigned int bits = Set(value.instance.data);
5788 exp.constant = PrintHexUInt(bits);
5789 exp.type = constantExp;
5792 else if(_class.type == bitClass)
5795 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5798 GetUInt(exp.member.exp, &value);
5800 exp.constant = PrintHexUInt(bits);
5801 exp.type = constantExp;
5809 if(_class.type == bitClass)
5812 GetUInt(exp.member.exp, &value);
5818 Class _class = type._class.registered;
5819 if(_class.type == structClass)
5821 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5823 exp.instance = Instantiation { };
5824 exp.instance.data = new0 byte[_class.structSize];
5825 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5826 exp.instance.loc = exp.loc;
5827 //exp.instance.fullSet = true;
5828 exp.type = instanceExp;
5829 Get(value, exp.instance.data);
5830 PopulateInstance(exp.instance);
5832 else if(_class.type == bitClass)
5834 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5835 uint64 bits = Get(value);
5836 exp.constant = PrintHexUInt64(bits);
5837 exp.type = constantExp;
5843 else if(_class.type == structClass)
5845 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5850 Class _class = type._class.registered;
5851 if(_class.type == structClass && value)
5853 void (*Get)(void *, void *) = (void *)prop.Get;
5855 exp.instance = Instantiation { };
5856 exp.instance.data = new0 byte[_class.structSize];
5857 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5858 exp.instance.loc = exp.loc;
5859 //exp.instance.fullSet = true;
5860 exp.type = instanceExp;
5861 Get(value, exp.instance.data);
5862 PopulateInstance(exp.instance);
5870 char * value = exp.member.exp.instance.data;
5875 Class _class = type._class.registered;
5876 if(_class.type == normalClass)
5878 void *(*Get)(void *) = (void *)prop.Get;
5880 exp.instance = Instantiation { };
5881 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5882 exp.type = instanceExp;
5883 exp.instance.data = Get(value, exp.instance.data);
5895 exp.isConstant = false;
5903 if(exp.type != ExpressionType::memberExp)
5905 FreeExpression(memberExp);
5906 FreeIdentifier(memberID);
5912 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5913 FreeExpContents(exp);
5914 exp.constant = PrintUInt(ComputeTypeSize(type));
5915 exp.type = constantExp;
5921 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5922 if(classSym && classSym.registered)
5924 if(classSym.registered.fixed)
5926 FreeSpecifier(exp._class);
5927 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5928 exp.type = constantExp;
5932 char className[1024];
5933 strcpy(className, "__ecereClass_");
5934 FullClassNameCat(className, classSym.string, true);
5935 MangleClassName(className);
5937 DeclareClass(classSym, className);
5939 FreeExpContents(exp);
5940 exp.type = pointerExp;
5941 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5942 exp.member.member = MkIdentifier("structSize");
5952 if(exp.type == castExp)
5955 ComputeExpression(exp.cast.exp);
5958 if(e && exp.expType)
5961 type = exp.destType;
5964 if(type.kind == classType)
5966 Class _class = type._class.registered;
5967 if(_class && (_class.type == unitClass || _class.type == bitClass))
5969 if(!_class.dataType)
5970 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5971 type = _class.dataType;
5983 FreeExpContents(exp);
5984 exp.constant = PrintChar(value);
5985 exp.type = constantExp;
5989 unsigned char value;
5990 GetUChar(e, &value);
5991 FreeExpContents(exp);
5992 exp.constant = PrintUChar(value);
5993 exp.type = constantExp;
6000 GetShort(e, &value);
6001 FreeExpContents(exp);
6002 exp.constant = PrintShort(value);
6003 exp.type = constantExp;
6007 unsigned short value;
6008 GetUShort(e, &value);
6009 FreeExpContents(exp);
6010 exp.constant = PrintUShort(value);
6011 exp.type = constantExp;
6019 FreeExpContents(exp);
6020 exp.constant = PrintInt(value);
6021 exp.type = constantExp;
6027 FreeExpContents(exp);
6028 exp.constant = PrintUInt(value);
6029 exp.type = constantExp;
6036 GetInt64(e, &value);
6037 FreeExpContents(exp);
6038 exp.constant = PrintInt64(value);
6039 exp.type = constantExp;
6044 GetUInt64(e, &value);
6045 FreeExpContents(exp);
6046 exp.constant = PrintUInt64(value);
6047 exp.type = constantExp;
6054 GetIntPtr(e, &value);
6055 FreeExpContents(exp);
6056 exp.constant = PrintInt64((int64)value);
6057 exp.type = constantExp;
6062 GetUIntPtr(e, &value);
6063 FreeExpContents(exp);
6064 exp.constant = PrintUInt64((uint64)value);
6065 exp.type = constantExp;
6072 GetIntSize(e, &value);
6073 FreeExpContents(exp);
6074 exp.constant = PrintInt64((int64)value);
6075 exp.type = constantExp;
6080 GetUIntSize(e, &value);
6081 FreeExpContents(exp);
6082 exp.constant = PrintUInt64((uint64)value);
6083 exp.type = constantExp;
6089 GetFloat(e, &value);
6090 FreeExpContents(exp);
6091 exp.constant = PrintFloat(value);
6092 exp.type = constantExp;
6098 GetDouble(e, &value);
6099 FreeExpContents(exp);
6100 exp.constant = PrintDouble(value);
6101 exp.type = constantExp;
6115 // Caring only about last expression for now...
6116 ComputeExpression(exp.cond.exp->last);
6117 if(exp.cond.elseExp)
6118 ComputeExpression(exp.cond.elseExp);
6120 ComputeExpression(exp.cond.cond);
6122 op1 = GetOperand(exp.cond.cond);
6123 if(op1.type) op1.type.refCount++;
6124 op2 = GetOperand(exp.cond.exp->last);
6125 if(op2.type) op2.type.refCount++;
6126 op3 = GetOperand(exp.cond.elseExp);
6127 if(op3.type) op3.type.refCount++;
6129 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6130 if(op1.type) FreeType(op1.type);
6131 if(op2.type) FreeType(op2.type);
6132 if(op3.type) FreeType(op3.type);
6138 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6143 OldList converts { };
6146 if(destType.kind == voidType)
6149 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6153 // for(convert = converts.last; convert; convert = convert.prev)
6154 for(convert = converts.first; convert; convert = convert.next)
6156 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6159 Expression newExp { };
6160 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6162 // TODO: Check this...
6164 newExp.destType = null;
6169 exp.type = memberExp;
6170 exp.addedThis = true;
6171 exp.member.exp = newExp;
6172 FreeType(exp.member.exp.expType);
6174 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6175 exp.member.exp.expType.classObjectType = objectType;
6176 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6177 exp.member.memberType = propertyMember;
6178 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6179 // TESTING THIS... for (int)degrees
6180 exp.needCast = true;
6181 if(exp.expType) exp.expType.refCount++;
6182 ApplyAnyObjectLogic(exp.member.exp);
6187 /*if(exp.isConstant)
6189 // Color { ColorRGB = [exp] };
6190 exp.type = instanceExp;
6191 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6192 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6193 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6197 // If not constant, don't turn it yet into an instantiation
6198 // (Go through the deep members system first)
6199 exp.type = memberExp;
6200 exp.addedThis = true;
6201 exp.member.exp = newExp;
6203 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6204 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6205 newExp.expType._class.registered.type == noHeadClass)
6207 newExp.byReference = true;
6210 FreeType(exp.member.exp.expType);
6211 /*exp.member.exp.expType = convert.convert.dataType;
6212 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6213 exp.member.exp.expType = null;
6214 if(convert.convert.dataType)
6216 exp.member.exp.expType = { };
6217 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6218 exp.member.exp.expType.refCount = 1;
6219 exp.member.exp.expType.classObjectType = objectType;
6220 ApplyAnyObjectLogic(exp.member.exp);
6223 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6224 exp.member.memberType = reverseConversionMember;
6225 exp.expType = convert.resultType ? convert.resultType :
6226 MkClassType(convert.convert._class.fullName);
6227 exp.needCast = true;
6228 if(convert.resultType) convert.resultType.refCount++;
6234 FreeType(exp.expType);
6237 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6238 exp.needCast = true;
6239 if(exp.expType) exp.expType.refCount++;
6243 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6244 exp.needCast = true;
6245 if(convert.resultType)
6246 convert.resultType.refCount++;
6250 if(exp.isConstant && inCompiler)
6251 ComputeExpression(exp);
6253 converts.Free(FreeConvert);
6256 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6258 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6260 if(!result && exp.expType && exp.destType)
6262 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6263 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6264 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6265 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6269 // if(result) CheckTemplateTypes(exp);
6273 void CheckTemplateTypes(Expression exp)
6275 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6277 Expression newExp { };
6281 if(exp.destType) exp.destType.refCount++;
6282 if(exp.expType) exp.expType.refCount++;
6286 switch(exp.expType.kind)
6289 if(exp.destType.classObjectType)
6291 // We need to pass the address, just pass it along (Undo what was done above)
6292 if(exp.destType) exp.destType.refCount--;
6293 if(exp.expType) exp.expType.refCount--;
6298 // If we're looking for value:
6299 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6301 OldList * unionDefs = MkList();
6302 OldList * statements = MkList();
6303 context = PushContext();
6304 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6305 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6306 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6307 exp.type = extensionCompoundExp;
6308 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6309 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6310 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6311 exp.compound.compound.context = context;
6312 PopContext(context);
6317 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6318 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6322 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6324 Expression newExp { };
6328 if(exp.destType) exp.destType.refCount++;
6329 if(exp.expType) exp.expType.refCount++;
6333 switch(exp.expType.kind)
6336 if(exp.destType.classObjectType)
6338 // We need to pass the address, just pass it along (Undo what was done above)
6339 if(exp.destType) exp.destType.refCount--;
6340 if(exp.expType) exp.expType.refCount--;
6345 // If we're looking for value:
6346 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6348 OldList * unionDefs = MkList();
6349 OldList * statements = MkList();
6350 context = PushContext();
6351 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6352 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6353 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6354 exp.type = extensionCompoundExp;
6355 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6356 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6357 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6358 exp.compound.compound.context = context;
6359 PopContext(context);
6364 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6366 exp.type = bracketsExp;
6367 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6368 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6369 ProcessExpressionType(exp.list->first);
6374 exp.type = bracketsExp;
6375 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6376 newExp.needCast = true;
6377 ProcessExpressionType(exp.list->first);
6383 if(exp.expType.kind == templateType)
6385 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6388 FreeType(exp.destType);
6389 FreeType(exp.expType);
6394 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6399 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6400 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6404 char typeString[1024];
6406 OldList * specs = MkList();
6407 typeString[0] = '\0';
6408 PrintType(exp.expType, typeString, false, false);
6409 decl = SpecDeclFromString(typeString, specs, null);
6412 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6413 exp.cast.typeName = MkTypeName(specs, decl);
6414 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6415 exp.cast.exp.needCast = true;
6422 // TODO: The Symbol tree should be reorganized by namespaces
6424 // - Tree of all symbols within (stored without namespace)
6425 // - Tree of sub-namespaces
6427 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6429 int nsLen = strlen(nameSpace);
6431 // Start at the name space prefix
6432 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6434 char * s = symbol.string;
6435 if(!strncmp(s, nameSpace, nsLen))
6437 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6440 for(c = strlen(s)-1; c >= 0; c--)
6445 if(!strcmp(namePart, name))
6447 // TODO: Error on ambiguity
6457 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6460 char nameSpace[1024];
6462 bool gotColon = false;
6464 nameSpace[0] = '\0';
6465 for(c = strlen(name)-1; c >= 0; c--)
6472 namePart = name+c+1;
6473 while(c >= 0 && name[c] == ':') c--;
6476 // Try an exact match first
6477 Symbol symbol = (Symbol)tree.FindString(name);
6481 // Namespace specified
6482 memcpy(nameSpace, name, c + 1);
6485 return ScanWithNameSpace(tree, nameSpace, namePart);
6489 // Looking for a global symbol, e.g. ::Sleep()
6490 Symbol symbol = (Symbol)tree.FindString(namePart);
6495 // Name only (no namespace specified)
6496 Symbol symbol = (Symbol)tree.FindString(namePart);
6499 return ScanWithNameSpace(tree, "", namePart);
6504 static void ProcessDeclaration(Declaration decl);
6506 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6509 //Time startTime = GetTime();
6511 // Optimize this later? Do this before/less?
6513 Symbol symbol = null;
6514 // First, check if the identifier is declared inside the function
6515 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6517 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6519 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6525 strcpy(curName, thisNameSpace);
6526 strcat(curName, "::");
6527 strcat(curName, name);
6528 // Try to resolve in current namespace first
6529 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6532 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6535 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6537 if(symbol || ctx == endContext) break;
6539 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6541 if(symbol.pointerExternal.type == functionExternal)
6543 FunctionDefinition function = symbol.pointerExternal.function;
6545 // Modified this recently...
6546 Context tmpContext = curContext;
6548 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6549 curContext = tmpContext;
6551 symbol.pointerExternal.symbol = symbol;
6554 DeclareType(symbol.type, true, true);
6556 ast->Insert(curExternal.prev, symbol.pointerExternal);
6558 symbol.id = curExternal.symbol.idCode;
6561 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6563 ast->Move(symbol.pointerExternal, curExternal.prev);
6564 symbol.id = curExternal.symbol.idCode;
6568 //findSymbolTotalTime += GetTime() - startTime;
6573 static void GetTypeSpecs(Type type, OldList * specs)
6575 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6580 if(type._class.registered)
6582 if(!type._class.registered.dataType)
6583 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6584 GetTypeSpecs(type._class.registered.dataType, specs);
6588 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6589 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6590 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6591 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6592 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6593 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6594 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6595 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6598 ListAdd(specs, MkSpecifier(INT)); break;
6602 static void PrintArraySize(Type arrayType, char * string)
6607 if(arrayType.enumClass)
6608 strcat(size, arrayType.enumClass.string);
6609 else if(arrayType.arraySizeExp)
6610 PrintExpression(arrayType.arraySizeExp, size);
6612 strcat(string, size);
6615 // WARNING : This function expects a null terminated string since it recursively concatenate...
6616 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6620 if(printConst && type.constant)
6621 strcat(string, "const ");
6626 Symbol c = type._class;
6627 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6628 // look into merging with thisclass ?
6629 if(type.classObjectType == typedObject)
6630 strcat(string, "typed_object");
6631 else if(type.classObjectType == anyObject)
6632 strcat(string, "any_object");
6636 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6638 if(type.byReference)
6639 strcat(string, " &");
6642 case voidType: strcat(string, "void"); break;
6643 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6644 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6645 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6646 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6647 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6648 case _BoolType: strcat(string, "_Bool"); break;
6649 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6650 case floatType: strcat(string, "float"); break;
6651 case doubleType: strcat(string, "double"); break;
6655 strcat(string, "struct ");
6656 strcat(string, type.enumName);
6658 else if(type.typeName)
6659 strcat(string, type.typeName);
6663 strcat(string, "struct { ");
6664 for(member = type.members.first; member; member = member.next)
6666 PrintType(member, string, true, fullName);
6667 strcat(string,"; ");
6675 strcat(string, "union ");
6676 strcat(string, type.enumName);
6678 else if(type.typeName)
6679 strcat(string, type.typeName);
6682 strcat(string, "union ");
6683 strcat(string,"(unnamed)");
6689 strcat(string, "enum ");
6690 strcat(string, type.enumName);
6692 else if(type.typeName)
6693 strcat(string, type.typeName);
6695 strcat(string, "int"); // "enum");
6698 strcat(string, "...");
6701 strcat(string, "subclass(");
6702 strcat(string, type._class ? type._class.string : "int");
6703 strcat(string, ")");
6706 strcat(string, type.templateParameter.identifier.string);
6709 strcat(string, "thisclass");
6712 strcat(string, "__builtin_va_list");
6718 static void PrintName(Type type, char * string, bool fullName)
6720 if(type.name && type.name[0])
6723 strcat(string, type.name);
6726 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6727 if(name) name += 2; else name = type.name;
6728 strcat(string, name);
6733 static void PrintAttribs(Type type, char * string)
6737 if(type.dllExport) strcat(string, "dllexport ");
6738 if(type.attrStdcall) strcat(string, "stdcall ");
6742 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6744 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6746 Type attrType = null;
6747 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6748 PrintAttribs(type, string);
6749 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6750 strcat(string, " const");
6751 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6752 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6753 strcat(string, " (");
6754 if(type.kind == pointerType)
6756 if(type.type.kind == functionType || type.type.kind == methodType)
6757 PrintAttribs(type.type, string);
6759 if(type.kind == pointerType)
6761 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6762 strcat(string, "*");
6764 strcat(string, " *");
6766 if(printConst && type.constant && type.kind == pointerType)
6767 strcat(string, " const");
6770 PrintTypeSpecs(type, string, fullName, printConst);
6773 static void PostPrintType(Type type, char * string, bool fullName)
6775 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6776 strcat(string, ")");
6777 if(type.kind == arrayType)
6778 PrintArraySize(type, string);
6779 else if(type.kind == functionType)
6782 strcat(string, "(");
6783 for(param = type.params.first; param; param = param.next)
6785 PrintType(param, string, true, fullName);
6786 if(param.next) strcat(string, ", ");
6788 strcat(string, ")");
6790 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6791 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6795 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6797 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6799 PrePrintType(type, string, fullName, null, printConst);
6801 if(type.thisClass || (printName && type.name && type.name[0]))
6802 strcat(string, " ");
6803 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6805 Symbol _class = type.thisClass;
6806 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6808 if(type.classObjectType == classPointer)
6809 strcat(string, "class");
6811 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6813 else if(_class && _class.string)
6815 String s = _class.string;
6820 char * name = RSearchString(s, "::", strlen(s), true, false);
6821 if(name) name += 2; else name = s;
6822 strcat(string, name);
6825 strcat(string, "::");
6828 if(printName && type.name)
6829 PrintName(type, string, fullName);
6830 PostPrintType(type, string, fullName);
6831 if(type.bitFieldCount)
6834 sprintf(count, ":%d", type.bitFieldCount);
6835 strcat(string, count);
6839 void PrintType(Type type, char * string, bool printName, bool fullName)
6841 _PrintType(type, string, printName, fullName, true);
6844 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6846 _PrintType(type, string, printName, fullName, false);
6849 static Type FindMember(Type type, char * string)
6852 for(memberType = type.members.first; memberType; memberType = memberType.next)
6854 if(!memberType.name)
6856 Type subType = FindMember(memberType, string);
6860 else if(!strcmp(memberType.name, string))
6866 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6869 for(memberType = type.members.first; memberType; memberType = memberType.next)
6871 if(!memberType.name)
6873 Type subType = FindMember(memberType, string);
6876 *offset += memberType.offset;
6880 else if(!strcmp(memberType.name, string))
6882 *offset += memberType.offset;
6889 public bool GetParseError() { return parseError; }
6891 Expression ParseExpressionString(char * expression)
6895 fileInput = TempFile { };
6896 fileInput.Write(expression, 1, strlen(expression));
6897 fileInput.Seek(0, start);
6900 parsedExpression = null;
6902 expression_yyparse();
6905 return parsedExpression;
6908 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6910 Identifier id = exp.identifier;
6911 Method method = null;
6912 Property prop = null;
6913 DataMember member = null;
6914 ClassProperty classProp = null;
6916 if(_class && _class.type == enumClass)
6918 NamedLink value = null;
6919 Class enumClass = eSystem_FindClass(privateModule, "enum");
6923 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6925 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6926 for(value = e.values.first; value; value = value.next)
6928 if(!strcmp(value.name, id.string))
6935 FreeExpContents(exp);
6937 exp.type = constantExp;
6938 exp.isConstant = true;
6939 if(!strcmp(baseClass.dataTypeString, "int"))
6940 sprintf(constant, "%d",(int)value.data);
6942 sprintf(constant, "0x%X",(int)value.data);
6943 exp.constant = CopyString(constant);
6944 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6945 exp.expType = MkClassType(baseClass.fullName);
6953 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6955 ProcessMethodType(method);
6962 // TOCHECK: Put it back to what it was...
6963 // methodClass = _class;
6964 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6969 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6972 ProcessPropertyType(prop);
6973 exp.expType = prop.dataType;
6974 if(prop.dataType) prop.dataType.refCount++;
6977 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6979 if(!member.dataType)
6980 member.dataType = ProcessTypeString(member.dataTypeString, false);
6981 exp.expType = member.dataType;
6982 if(member.dataType) member.dataType.refCount++;
6985 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6987 if(!classProp.dataType)
6988 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6990 if(classProp.constant)
6992 FreeExpContents(exp);
6994 exp.isConstant = true;
6995 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6997 //char constant[256];
6998 exp.type = stringExp;
6999 exp.constant = QMkString((char *)classProp.Get(_class));
7004 exp.type = constantExp;
7005 sprintf(constant, "%d", (int)classProp.Get(_class));
7006 exp.constant = CopyString(constant);
7014 exp.expType = classProp.dataType;
7015 if(classProp.dataType) classProp.dataType.refCount++;
7021 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7023 BinaryTree * tree = &nameSpace.functions;
7024 GlobalData data = (GlobalData)tree->FindString(name);
7028 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7030 data = ScanGlobalData(child, name);
7038 static GlobalData FindGlobalData(char * name)
7041 NameSpace * nameSpace;
7042 nameSpace = globalData;
7043 for(c = 0; name[c]; c++)
7045 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7047 NameSpace * newSpace;
7048 char * spaceName = new char[c - start + 1];
7049 strncpy(spaceName, name + start, c - start);
7050 spaceName[c-start] = '\0';
7051 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7055 nameSpace = newSpace;
7056 if(name[c] == ':') c++;
7062 return ScanGlobalData(nameSpace, name + start);
7067 static int definedExpStackPos;
7068 static void * definedExpStack[512];
7070 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7071 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7073 Expression prev = checkedExp.prev, next = checkedExp.next;
7075 FreeExpContents(checkedExp);
7076 FreeType(checkedExp.expType);
7077 FreeType(checkedExp.destType);
7079 *checkedExp = *newExp;
7083 checkedExp.prev = prev;
7084 checkedExp.next = next;
7087 void ApplyAnyObjectLogic(Expression e)
7089 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7091 char debugExpString[4096];
7092 debugExpString[0] = '\0';
7093 PrintExpression(e, debugExpString);
7096 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7098 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7099 //ellipsisDestType = destType;
7102 Type type = e.expType;
7103 Class _class = null;
7104 //Type destType = e.destType;
7106 if(type.kind == classType && type._class && type._class.registered)
7108 _class = type._class.registered;
7110 else if(type.kind == subClassType)
7112 _class = FindClass("ecere::com::Class").registered;
7116 char string[1024] = "";
7119 PrintTypeNoConst(type, string, false, true);
7120 classSym = FindClass(string);
7121 if(classSym) _class = classSym.registered;
7124 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...
7125 (!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))) ||
7126 destType.byReference)))
7128 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7130 Expression checkedExp = e, newExp;
7132 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7134 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7136 if(checkedExp.type == extensionCompoundExp)
7138 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7141 checkedExp = checkedExp.list->last;
7143 else if(checkedExp.type == castExp)
7144 checkedExp = checkedExp.cast.exp;
7147 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7149 newExp = checkedExp.op.exp2;
7150 checkedExp.op.exp2 = null;
7151 FreeExpContents(checkedExp);
7153 if(e.expType && e.expType.passAsTemplate)
7156 ComputeTypeSize(e.expType);
7157 sprintf(size, "%d", e.expType.size);
7158 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7159 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7160 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7163 ReplaceExpContents(checkedExp, newExp);
7164 e.byReference = true;
7166 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7168 Expression checkedExp, newExp;
7171 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7173 e.type == identifierExp ||
7174 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7175 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7176 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7179 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7181 Context context = PushContext();
7183 OldList * specs = MkList();
7184 char typeString[1024];
7185 Expression newExp { };
7187 typeString[0] = '\0';
7190 //if(e.destType) e.destType.refCount++;
7191 // if(exp.expType) exp.expType.refCount++;
7194 newExp.expType = null;
7196 PrintTypeNoConst(e.expType, typeString, false, true);
7197 decl = SpecDeclFromString(typeString, specs, null);
7198 newExp.destType = ProcessType(specs, decl);
7200 curContext = context;
7202 // We need a current compound for this
7206 OldList * stmts = MkList();
7207 e.type = extensionCompoundExp;
7208 sprintf(name, "__internalValue%03X", internalValueCounter++);
7209 if(!curCompound.compound.declarations)
7210 curCompound.compound.declarations = MkList();
7211 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7212 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7213 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7214 e.compound = MkCompoundStmt(null, stmts);
7217 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7220 e.compound = MkCompoundStmt(
7221 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7222 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7224 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7228 Type type = e.destType;
7230 CopyTypeInto(e.destType, type);
7231 e.destType.refCount = 1;
7232 e.destType.classObjectType = none;
7236 e.compound.compound.context = context;
7237 PopContext(context);
7238 curContext = context.parent;
7242 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7244 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7246 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7248 if(checkedExp.type == extensionCompoundExp)
7250 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7253 checkedExp = checkedExp.list->last;
7255 else if(checkedExp.type == castExp)
7256 checkedExp = checkedExp.cast.exp;
7259 Expression operand { };
7260 operand = *checkedExp;
7261 checkedExp.destType = null;
7262 checkedExp.expType = null;
7264 checkedExp.type = opExp;
7265 checkedExp.op.op = '&';
7266 checkedExp.op.exp1 = null;
7267 checkedExp.op.exp2 = operand;
7269 //newExp = MkExpOp(null, '&', checkedExp);
7271 //ReplaceExpContents(checkedExp, newExp);
7278 // If expression type is a simple class, make it an address
7279 // FixReference(e, true);
7282 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7283 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7284 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7286 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"))
7288 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7292 Expression thisExp { };
7295 thisExp.prev = null;
7296 thisExp.next = null;
7299 e.type = bracketsExp;
7300 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7301 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7302 ((Expression)e.list->first).byReference = true;
7304 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7306 e.expType = thisExp.expType;
7307 e.expType.refCount++;
7312 CopyTypeInto(e.expType, thisExp.expType);
7313 e.expType.byReference = false;
7314 e.expType.refCount = 1;
7316 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7317 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7319 e.expType.classObjectType = none;
7324 // TOFIX: Try this for a nice IDE crash!
7326 // The other way around
7329 if(destType && e.expType &&
7330 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7331 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7332 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7334 if(destType.kind == ellipsisType)
7336 Compiler_Error($"Unspecified type\n");
7338 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7340 bool byReference = e.expType.byReference;
7341 Expression thisExp { };
7343 OldList * specs = MkList();
7344 char typeString[1024]; // Watch buffer overruns
7346 ClassObjectType backupClassObjectType;
7347 bool backupByReference;
7349 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7354 backupClassObjectType = type.classObjectType;
7355 backupByReference = type.byReference;
7357 type.classObjectType = none;
7358 type.byReference = false;
7360 typeString[0] = '\0';
7361 PrintType(type, typeString, false, true);
7362 decl = SpecDeclFromString(typeString, specs, null);
7364 type.classObjectType = backupClassObjectType;
7365 type.byReference = backupByReference;
7368 thisExp.prev = null;
7369 thisExp.next = null;
7372 if( ( type.kind == classType && type._class && type._class.registered &&
7373 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7374 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7375 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7376 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7381 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7384 CopyTypeInto(e.expType, type);
7385 e.expType.byReference = false;
7386 e.expType.refCount = 1;
7391 e.cast.typeName = MkTypeName(specs, decl);
7392 e.cast.exp = thisExp;
7393 e.byReference = true;
7397 e.destType = destType;
7398 destType.refCount++;
7403 void ProcessExpressionType(Expression exp)
7405 bool unresolved = false;
7406 Location oldyylloc = yylloc;
7407 bool notByReference = false;
7409 char debugExpString[4096];
7410 debugExpString[0] = '\0';
7411 PrintExpression(exp, debugExpString);
7413 if(!exp || exp.expType)
7416 //eSystem_Logf("%s\n", expString);
7418 // Testing this here
7424 Identifier id = exp.identifier;
7425 if(!id || !topContext) return;
7427 // DOING THIS LATER NOW...
7428 if(id._class && id._class.name)
7430 id.classSym = id._class.symbol; // FindClass(id._class.name);
7431 /* TODO: Name Space Fix ups
7433 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7437 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7439 exp.expType = ProcessTypeString("Module", true);
7442 else */if(strstr(id.string, "__ecereClass") == id.string)
7444 exp.expType = ProcessTypeString("ecere::com::Class", true);
7447 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7449 // Added this here as well
7450 ReplaceClassMembers(exp, thisClass);
7451 if(exp.type != identifierExp)
7453 ProcessExpressionType(exp);
7457 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7462 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7463 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7464 if(!symbol/* && exp.destType*/)
7466 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7472 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7473 if(exp.type != identifierExp)
7475 ProcessExpressionType(exp);
7479 // Static methods called from inside the _class
7480 else if(currentClass && !id._class)
7482 if(ResolveIdWithClass(exp, currentClass, true))
7485 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7489 // If we manage to resolve this symbol
7492 Type type = symbol.type;
7493 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7495 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7497 Context context = SetupTemplatesContext(_class);
7498 type = ReplaceThisClassType(_class);
7499 FinishTemplatesContext(context);
7500 if(type) type.refCount = 0; // We'll be incrementing it right below...
7503 FreeSpecifier(id._class);
7506 id.string = CopyString(symbol.string);
7512 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7513 // Add missing cases here... enum Classes...
7514 exp.isConstant = true;
7516 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7517 if(symbol.isParam || !strcmp(id.string, "this"))
7519 if(_class && _class.type == structClass && !type.declaredWithStruct)
7520 exp.byReference = true;
7522 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7523 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7524 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7525 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7527 Identifier id = exp.identifier;
7528 exp.type = bracketsExp;
7529 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7533 if(symbol.isIterator)
7535 if(symbol.isIterator == 3)
7537 exp.type = bracketsExp;
7538 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7539 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7541 ProcessExpressionType(exp);
7543 else if(symbol.isIterator != 4)
7545 exp.type = memberExp;
7546 exp.member.exp = MkExpIdentifier(exp.identifier);
7547 exp.member.exp.expType = exp.expType;
7548 /*if(symbol.isIterator == 6)
7549 exp.member.member = MkIdentifier("key");
7551 exp.member.member = MkIdentifier("data");
7553 ProcessExpressionType(exp);
7560 DefinedExpression definedExp = null;
7561 if(thisNameSpace && !(id._class && !id._class.name))
7564 strcpy(name, thisNameSpace);
7566 strcat(name, id.string);
7567 definedExp = eSystem_FindDefine(privateModule, name);
7570 definedExp = eSystem_FindDefine(privateModule, id.string);
7574 for(c = 0; c<definedExpStackPos; c++)
7575 if(definedExpStack[c] == definedExp)
7577 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7579 Location backupYylloc = yylloc;
7580 File backInput = fileInput;
7581 definedExpStack[definedExpStackPos++] = definedExp;
7583 fileInput = TempFile { };
7584 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7585 fileInput.Seek(0, start);
7588 parsedExpression = null;
7590 expression_yyparse();
7593 fileInput = backInput;
7595 yylloc = backupYylloc;
7597 if(parsedExpression)
7600 exp.type = bracketsExp;
7601 exp.list = MkListOne(parsedExpression);
7602 parsedExpression.loc = yylloc;
7603 ProcessExpressionType(exp);
7604 definedExpStackPos--;
7607 definedExpStackPos--;
7613 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7619 GlobalData data = null;
7620 if(thisNameSpace && !(id._class && !id._class.name))
7623 strcpy(name, thisNameSpace);
7625 strcat(name, id.string);
7626 data = FindGlobalData(name);
7629 data = FindGlobalData(id.string);
7632 DeclareGlobalData(data);
7633 exp.expType = data.dataType;
7634 if(data.dataType) data.dataType.refCount++;
7637 id.string = CopyString(data.fullName);
7638 FreeSpecifier(id._class);
7645 GlobalFunction function = null;
7646 if(thisNameSpace && !(id._class && !id._class.name))
7649 strcpy(name, thisNameSpace);
7651 strcat(name, id.string);
7652 function = eSystem_FindFunction(privateModule, name);
7655 function = eSystem_FindFunction(privateModule, id.string);
7660 id.string = CopyString(function.name);
7663 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7664 strcpy(name, "__ecereFunction_");
7665 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7666 if(DeclareFunction(function, name))
7669 id.string = CopyString(name);
7671 exp.expType = function.dataType;
7672 if(function.dataType) function.dataType.refCount++;
7674 FreeSpecifier(id._class);
7691 if(!exp.instance._class)
7693 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7695 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7699 //classSym = FindClass(exp.instance._class.fullName);
7700 //_class = classSym ? classSym.registered : null;
7702 ProcessInstantiationType(exp.instance);
7703 exp.isConstant = exp.instance.isConstant;
7706 if(_class.type == unitClass && _class.base.type != systemClass)
7709 Type destType = exp.destType;
7711 exp.destType = MkClassType(_class.base.fullName);
7712 exp.expType = MkClassType(_class.fullName);
7713 CheckExpressionType(exp, exp.destType, true);
7715 exp.destType = destType;
7717 exp.expType = MkClassType(_class.fullName);
7720 if(exp.instance._class)
7722 exp.expType = MkClassType(exp.instance._class.name);
7723 /*if(exp.expType._class && exp.expType._class.registered &&
7724 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7725 exp.expType.byReference = true;*/
7733 char * constant = exp.constant;
7741 if(constant[0] == '\'')
7743 if((int)((byte *)constant)[1] > 127)
7746 unichar ch = UTF8GetChar(constant + 1, &nb);
7747 if(nb < 2) ch = constant[1];
7749 exp.constant = PrintUInt(ch);
7750 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7751 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7752 type._class = FindClass("unichar");
7754 type.isSigned = false;
7758 type.kind = charType;
7759 type.isSigned = true;
7764 char * dot = strchr(constant, '.');
7765 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7769 exponent = strchr(constant, 'p');
7770 if(!exponent) exponent = strchr(constant, 'P');
7774 exponent = strchr(constant, 'e');
7775 if(!exponent) exponent = strchr(constant, 'E');
7780 if(strchr(constant, 'f') || strchr(constant, 'F'))
7781 type.kind = floatType;
7783 type.kind = doubleType;
7784 type.isSigned = true;
7788 bool isSigned = constant[0] == '-';
7789 int64 i64 = strtoll(constant, null, 0);
7790 uint64 ui64 = strtoull(constant, null, 0);
7791 bool is64Bit = false;
7804 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7808 else if(constant[0] != '0' || !constant[1])
7811 type.kind = is64Bit ? int64Type : intType;
7812 type.isSigned = isSigned;
7815 exp.isConstant = true;
7816 if(exp.destType && exp.destType.kind == doubleType)
7817 type.kind = doubleType;
7818 else if(exp.destType && exp.destType.kind == floatType)
7819 type.kind = floatType;
7820 else if(exp.destType && exp.destType.kind == int64Type)
7821 type.kind = int64Type;
7827 exp.isConstant = true; // Why wasn't this constant?
7844 ProcessExpressionType(exp._new.size);
7849 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7851 DeclareType(exp.expType.type, false, false);
7855 ProcessExpressionType(exp._renew.size);
7856 ProcessExpressionType(exp._renew.exp);
7861 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7863 DeclareType(exp.expType.type, false, false);
7867 bool assign = false, boolResult = false, boolOps = false;
7868 Type type1 = null, type2 = null;
7869 bool useDestType = false, useSideType = false;
7870 Location oldyylloc = yylloc;
7871 bool useSideUnit = false;
7873 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7882 // Assignment Operators
7896 // boolean Operators
7898 // Expect boolean operators
7900 //boolResult = true;
7904 // Expect boolean operands
7915 // Gives boolean result
7923 // Just added these... testing
7928 // DANGER: Verify units
7933 if(exp.op.op != '*' || exp.op.exp1)
7940 /*// Implement speed etc.
7946 if(exp.op.op == '&')
7948 // Added this here earlier for Iterator address as key
7949 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7951 Identifier id = exp.op.exp2.identifier;
7952 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7953 if(symbol && symbol.isIterator == 2)
7955 exp.type = memberExp;
7956 exp.member.exp = exp.op.exp2;
7957 exp.member.member = MkIdentifier("key");
7959 exp.op.exp2.expType = symbol.type;
7960 symbol.type.refCount++;
7961 ProcessExpressionType(exp);
7965 // exp.op.exp2.usage.usageRef = true;
7969 //dummy.kind = TypeDummy;
7973 if(exp.destType && exp.destType.kind == classType &&
7974 exp.destType._class && exp.destType._class.registered && useDestType &&
7976 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7977 exp.destType._class.registered.type == enumClass ||
7978 exp.destType._class.registered.type == bitClass
7981 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7983 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7984 exp.op.exp1.destType = exp.destType;
7986 exp.destType.refCount++;
7990 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7991 exp.op.exp1.destType = dummy;
7995 // TESTING THIS HERE...
7996 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7997 ProcessExpressionType(exp.op.exp1);
7998 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8000 if(exp.op.exp1.destType == dummy)
8003 exp.op.exp1.destType = null;
8005 type1 = exp.op.exp1.expType;
8010 char expString[10240];
8011 expString[0] = '\0';
8012 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8016 exp.op.exp2.destType = exp.op.exp1.expType;
8017 if(exp.op.exp1.expType)
8018 exp.op.exp1.expType.refCount++;
8022 exp.op.exp2.destType = exp.destType;
8024 exp.destType.refCount++;
8027 if(type1) type1.refCount++;
8028 exp.expType = type1;
8033 PrintExpression(exp.op.exp2, expString);
8035 if(type1 && type1.kind == pointerType)
8037 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 ||
8038 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8039 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8040 else if(exp.op.op == '=')
8042 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8043 exp.op.exp2.destType = type1;
8050 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8051 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/* ||
8052 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8055 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8056 exp.op.exp2.destType = type1;
8061 if(type1) type1.refCount++;
8062 exp.expType = type1;
8064 else if(exp.destType && exp.destType.kind == classType &&
8065 exp.destType._class && exp.destType._class.registered &&
8067 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
8068 (exp.destType._class.registered.type == enumClass && useDestType))
8071 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8072 exp.op.exp2.destType = exp.destType;
8074 exp.destType.refCount++;
8078 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8079 exp.op.exp2.destType = dummy;
8083 // TESTING THIS HERE... (DANGEROUS)
8084 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8085 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8087 FreeType(exp.op.exp2.destType);
8088 exp.op.exp2.destType = type1;
8091 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8092 // Cannot lose the cast on a sizeof
8093 if(exp.op.op == SIZEOF)
8095 Expression e = exp.op.exp2;
8096 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8098 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8100 if(e.type == extensionCompoundExp)
8101 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8106 if(e.type == castExp && e.cast.exp)
8107 e.cast.exp.needCast = true;
8109 ProcessExpressionType(exp.op.exp2);
8110 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8112 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8114 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)
8116 if(exp.op.op != '=' && type1.type.kind == voidType)
8117 Compiler_Error($"void *: unknown size\n");
8119 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||
8120 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8121 (exp.op.exp2.expType._class.registered.type == normalClass ||
8122 exp.op.exp2.expType._class.registered.type == structClass ||
8123 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8125 if(exp.op.op == ADD_ASSIGN)
8126 Compiler_Error($"cannot add two pointers\n");
8128 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8129 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8131 if(exp.op.op == ADD_ASSIGN)
8132 Compiler_Error($"cannot add two pointers\n");
8136 char type1String[1024];
8137 char type2String[1024];
8138 type1String[0] = '\0';
8139 type2String[0] = '\0';
8141 PrintType(exp.op.exp2.expType, type1String, false, true);
8142 PrintType(type1, type2String, false, true);
8143 ChangeCh(expString, '\n', ' ');
8144 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8148 if(exp.op.exp2.destType == dummy)
8151 exp.op.exp2.destType = null;
8154 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8158 CopyTypeInto(type2, exp.op.exp2.expType);
8159 type2.isSigned = true;
8161 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8163 type2 = { kind = intType };
8165 type2.isSigned = true;
8169 type2 = exp.op.exp2.expType;
8170 if(type2) type2.refCount++;
8174 dummy.kind = voidType;
8176 if(exp.op.op == SIZEOF)
8183 exp.isConstant = true;
8185 // Get type of dereferenced pointer
8186 else if(exp.op.op == '*' && !exp.op.exp1)
8188 exp.expType = Dereference(type2);
8189 if(type2 && type2.kind == classType)
8190 notByReference = true;
8192 else if(exp.op.op == '&' && !exp.op.exp1)
8193 exp.expType = Reference(type2);
8200 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8201 exp.op.exp1.destType = MkClassType("bool");
8202 exp.op.exp1.destType.truth = true;
8203 if(!exp.op.exp1.expType)
8204 ProcessExpressionType(exp.op.exp1);
8206 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8207 FreeType(exp.op.exp1.expType);
8208 exp.op.exp1.expType = MkClassType("bool");
8209 exp.op.exp1.expType.truth = true;
8213 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8214 exp.op.exp2.destType = MkClassType("bool");
8215 exp.op.exp2.destType.truth = true;
8216 if(!exp.op.exp2.expType)
8217 ProcessExpressionType(exp.op.exp2);
8219 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8220 FreeType(exp.op.exp2.expType);
8221 exp.op.exp2.expType = MkClassType("bool");
8222 exp.op.exp2.expType.truth = true;
8225 else if(exp.op.exp1 && exp.op.exp2 &&
8228 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8229 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8230 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8231 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8233 if(type1 && type2 &&
8234 // If either both are class or both are not class
8235 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8237 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8238 exp.op.exp2.destType = type1;
8240 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8241 exp.op.exp1.destType = type2;
8243 // Warning here for adding Radians + Degrees with no destination type
8244 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8245 type1._class.registered && type1._class.registered.type == unitClass &&
8246 type2._class.registered && type2._class.registered.type == unitClass &&
8247 type1._class.registered != type2._class.registered)
8248 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8249 type1._class.string, type2._class.string, type1._class.string);
8251 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8253 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8256 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8258 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8259 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8262 ProcessExpressionType(exp.op.exp1);
8264 if(type2.kind != pointerType)
8266 ProcessExpressionType(classExp);
8268 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8269 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8270 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8272 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8275 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8276 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8277 MkPointer(null, null), null)))),
8278 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8280 if(!exp.op.exp2.expType)
8284 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8288 ProcessExpressionType(exp.op.exp2);
8293 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)))
8295 if(type1.kind != classType && type1.type.kind == voidType)
8296 Compiler_Error($"void *: unknown size\n");
8297 exp.expType = type1;
8298 if(type1) type1.refCount++;
8300 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)))
8302 if(type2.kind != classType && type2.type.kind == voidType)
8303 Compiler_Error($"void *: unknown size\n");
8304 exp.expType = type2;
8305 if(type2) type2.refCount++;
8307 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8308 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8310 Compiler_Warning($"different levels of indirection\n");
8314 bool success = false;
8315 if(type1.kind == pointerType && type2.kind == pointerType)
8317 if(exp.op.op == '+')
8318 Compiler_Error($"cannot add two pointers\n");
8319 else if(exp.op.op == '-')
8321 // Pointer Subtraction gives integer
8322 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8331 if(type1.type.kind == templateType)
8333 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8336 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8338 ProcessExpressionType(classExp);
8340 exp.type = bracketsExp;
8341 exp.list = MkListOne(MkExpOp(
8342 MkExpBrackets(MkListOne(MkExpOp(
8343 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8345 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8347 //MkExpMember(classExp, MkIdentifier("typeSize"))
8349 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8350 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8352 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8355 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8356 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8357 MkPointer(null, null), null)))),
8358 MkExpMember(classExp, MkIdentifier("typeSize")))))
8363 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8372 if(!success && exp.op.exp1.type == constantExp)
8374 // If first expression is constant, try to match that first
8375 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8377 if(exp.expType) FreeType(exp.expType);
8378 exp.expType = exp.op.exp1.destType;
8379 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8382 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8384 if(exp.expType) FreeType(exp.expType);
8385 exp.expType = exp.op.exp2.destType;
8386 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8392 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8394 if(exp.expType) FreeType(exp.expType);
8395 exp.expType = exp.op.exp2.destType;
8396 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8399 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8401 if(exp.expType) FreeType(exp.expType);
8402 exp.expType = exp.op.exp1.destType;
8403 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8409 char expString1[10240];
8410 char expString2[10240];
8413 expString1[0] = '\0';
8414 expString2[0] = '\0';
8419 PrintExpression(exp.op.exp1, expString1);
8420 ChangeCh(expString1, '\n', ' ');
8421 PrintExpression(exp.op.exp2, expString2);
8422 ChangeCh(expString2, '\n', ' ');
8423 PrintType(exp.op.exp1.expType, type1, false, true);
8424 PrintType(exp.op.exp2.expType, type2, false, true);
8427 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8431 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8432 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8434 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8435 // Convert e.g. / 4 into / 4.0
8436 exp.op.exp1.destType = type2._class.registered.dataType;
8437 if(type2._class.registered.dataType)
8438 type2._class.registered.dataType.refCount++;
8439 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8440 exp.expType = type2;
8441 if(type2) type2.refCount++;
8443 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8445 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8446 // Convert e.g. / 4 into / 4.0
8447 exp.op.exp2.destType = type1._class.registered.dataType;
8448 if(type1._class.registered.dataType)
8449 type1._class.registered.dataType.refCount++;
8450 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8451 exp.expType = type1;
8452 if(type1) type1.refCount++;
8458 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8460 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8462 if(!type1._class.registered.dataType)
8463 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8464 exp.op.exp2.destType = type1._class.registered.dataType;
8465 exp.op.exp2.destType.refCount++;
8467 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8470 type2 = exp.op.exp2.destType;
8471 if(type2) type2.refCount++;
8473 exp.expType = type2;
8477 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8479 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8481 if(!type2._class.registered.dataType)
8482 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8483 exp.op.exp1.destType = type2._class.registered.dataType;
8484 exp.op.exp1.destType.refCount++;
8486 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8487 type1 = exp.op.exp1.destType;
8488 exp.expType = type1;
8492 // TESTING THIS NEW CODE
8493 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8495 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8497 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8499 if(exp.expType) FreeType(exp.expType);
8500 exp.expType = exp.op.exp1.expType;
8501 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8506 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8508 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8510 if(exp.expType) FreeType(exp.expType);
8511 exp.expType = exp.op.exp2.expType;
8512 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8520 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8521 exp.op.exp2.destType = type1;
8525 // Maybe this was meant to be an enum...
8526 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8528 Type oldType = exp.op.exp2.expType;
8529 exp.op.exp2.expType = null;
8530 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8533 exp.op.exp2.expType = oldType;
8538 // TESTING THIS HERE... LATEST ADDITION
8539 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8541 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8542 exp.op.exp2.destType = type2._class.registered.dataType;
8543 if(type2._class.registered.dataType)
8544 type2._class.registered.dataType.refCount++;
8545 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8547 //exp.expType = type2._class.registered.dataType; //type2;
8548 //if(type2) type2.refCount++;
8551 // TESTING THIS HERE... LATEST ADDITION
8552 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8554 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8555 exp.op.exp1.destType = type1._class.registered.dataType;
8556 if(type1._class.registered.dataType)
8557 type1._class.registered.dataType.refCount++;
8558 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8559 exp.expType = type1._class.registered.dataType; //type1;
8560 if(type1) type1.refCount++;
8564 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8566 if(exp.expType) FreeType(exp.expType);
8567 exp.expType = exp.op.exp2.destType;
8568 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8570 else if(type1 && type2)
8572 char expString1[10240];
8573 char expString2[10240];
8574 char type1String[1024];
8575 char type2String[1024];
8576 expString1[0] = '\0';
8577 expString2[0] = '\0';
8578 type1String[0] = '\0';
8579 type2String[0] = '\0';
8582 PrintExpression(exp.op.exp1, expString1);
8583 ChangeCh(expString1, '\n', ' ');
8584 PrintExpression(exp.op.exp2, expString2);
8585 ChangeCh(expString2, '\n', ' ');
8586 PrintType(exp.op.exp1.expType, type1String, false, true);
8587 PrintType(exp.op.exp2.expType, type2String, false, true);
8590 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8592 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8594 exp.expType = exp.op.exp1.expType;
8595 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8597 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8599 exp.expType = exp.op.exp2.expType;
8600 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8607 // Maybe this was meant to be an enum...
8608 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8610 Type oldType = exp.op.exp1.expType;
8611 exp.op.exp1.expType = null;
8612 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8615 exp.op.exp1.expType = oldType;
8618 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8619 exp.op.exp1.destType = type2;
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++;
8631 // TESTING THIS HERE... LATEST ADDITION
8632 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8634 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8635 exp.op.exp2.destType = type2._class.registered.dataType;
8636 if(type2._class.registered.dataType)
8637 type2._class.registered.dataType.refCount++;
8641 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8643 if(exp.expType) FreeType(exp.expType);
8644 exp.expType = exp.op.exp1.destType;
8645 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8649 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8651 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8653 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8654 // Convert e.g. / 4 into / 4.0
8655 exp.op.exp1.destType = type2._class.registered.dataType;
8656 if(type2._class.registered.dataType)
8657 type2._class.registered.dataType.refCount++;
8658 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8660 if(exp.op.op == '!')
8662 exp.expType = MkClassType("bool");
8663 exp.expType.truth = true;
8667 exp.expType = type2;
8668 if(type2) type2.refCount++;
8671 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8673 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8675 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8676 // Convert e.g. / 4 into / 4.0
8677 exp.op.exp2.destType = type1._class.registered.dataType;
8678 if(type1._class.registered.dataType)
8679 type1._class.registered.dataType.refCount++;
8680 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8682 exp.expType = type1;
8683 if(type1) type1.refCount++;
8688 if(exp.op.exp1 && !exp.op.exp1.expType)
8690 char expString[10000];
8691 expString[0] = '\0';
8694 PrintExpression(exp.op.exp1, expString);
8695 ChangeCh(expString, '\n', ' ');
8698 Compiler_Error($"couldn't determine type of %s\n", expString);
8700 if(exp.op.exp2 && !exp.op.exp2.expType)
8702 char expString[10240];
8703 expString[0] = '\0';
8706 PrintExpression(exp.op.exp2, expString);
8707 ChangeCh(expString, '\n', ' ');
8710 Compiler_Error($"couldn't determine type of %s\n", expString);
8715 FreeType(exp.expType);
8716 exp.expType = MkClassType("bool");
8717 exp.expType.truth = true;
8720 if(exp.op.op != SIZEOF)
8721 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8722 (!exp.op.exp2 || exp.op.exp2.isConstant);
8724 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8726 DeclareType(exp.op.exp2.expType, false, false);
8737 case extensionExpressionExp:
8740 exp.isConstant = true;
8741 for(e = exp.list->first; e; e = e.next)
8746 FreeType(e.destType);
8747 e.destType = exp.destType;
8748 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8750 ProcessExpressionType(e);
8752 exp.destType.count--;
8753 if(!exp.expType && !e.next)
8755 exp.expType = e.expType;
8756 if(e.expType) e.expType.refCount++;
8759 exp.isConstant = false;
8762 // In case a cast became a member...
8763 e = exp.list->first;
8764 if(!e.next && e.type == memberExp)
8766 // Preserve prev, next
8767 Expression next = exp.next, prev = exp.prev;
8770 FreeType(exp.expType);
8771 FreeType(exp.destType);
8781 ProcessExpressionType(exp);
8788 exp.isConstant = true;
8790 ProcessExpressionType(exp.index.exp);
8791 if(!exp.index.exp.isConstant)
8792 exp.isConstant = false;
8794 if(exp.index.exp.expType)
8796 Type source = exp.index.exp.expType;
8797 if(source.kind == classType && source._class && source._class.registered)
8799 Class _class = source._class.registered;
8800 Class c = _class.templateClass ? _class.templateClass : _class;
8801 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8803 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8805 if(exp.index.index && exp.index.index->last)
8807 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8813 for(e = exp.index.index->first; e; e = e.next)
8815 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8817 if(e.destType) FreeType(e.destType);
8818 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8820 ProcessExpressionType(e);
8823 // Check if this type is int
8826 exp.isConstant = false;
8830 exp.expType = Dereference(exp.index.exp.expType);
8832 DeclareType(exp.expType, false, false);
8839 Type methodType = null;
8845 PrintExpression(exp.call.exp, name);
8846 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8848 //exp.call.exp.expType = null;
8849 PrintExpression(exp.call.exp, name);
8852 if(exp.call.exp.type == identifierExp)
8854 Expression idExp = exp.call.exp;
8855 Identifier id = idExp.identifier;
8856 if(!strcmp(id.string, "__builtin_frame_address"))
8858 exp.expType = ProcessTypeString("void *", true);
8859 if(exp.call.arguments && exp.call.arguments->first)
8860 ProcessExpressionType(exp.call.arguments->first);
8863 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8865 exp.expType = ProcessTypeString("int", true);
8866 if(exp.call.arguments && exp.call.arguments->first)
8867 ProcessExpressionType(exp.call.arguments->first);
8870 else if(!strcmp(id.string, "Max") ||
8871 !strcmp(id.string, "Min") ||
8872 !strcmp(id.string, "Sgn") ||
8873 !strcmp(id.string, "Abs"))
8875 Expression a = null;
8876 Expression b = null;
8877 Expression tempExp1 = null, tempExp2 = null;
8878 if((!strcmp(id.string, "Max") ||
8879 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8881 a = exp.call.arguments->first;
8882 b = exp.call.arguments->last;
8886 else if(exp.call.arguments->count == 1)
8888 a = exp.call.arguments->first;
8894 exp.call.arguments->Clear();
8895 idExp.identifier = null;
8897 FreeExpContents(exp);
8899 ProcessExpressionType(a);
8901 ProcessExpressionType(b);
8903 exp.type = bracketsExp;
8904 exp.list = MkList();
8906 if(a.expType && (!b || b.expType))
8908 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8910 // Use the simpleStruct name/ids for now...
8913 OldList * specs = MkList();
8914 OldList * decls = MkList();
8916 char temp1[1024], temp2[1024];
8918 GetTypeSpecs(a.expType, specs);
8920 if(a && !a.isConstant && a.type != identifierExp)
8922 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8923 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8924 tempExp1 = QMkExpId(temp1);
8925 tempExp1.expType = a.expType;
8927 a.expType.refCount++;
8928 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8930 if(b && !b.isConstant && b.type != identifierExp)
8932 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8933 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8934 tempExp2 = QMkExpId(temp2);
8935 tempExp2.expType = b.expType;
8937 b.expType.refCount++;
8938 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8941 decl = MkDeclaration(specs, decls);
8942 if(!curCompound.compound.declarations)
8943 curCompound.compound.declarations = MkList();
8944 curCompound.compound.declarations->Insert(null, decl);
8949 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8951 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8953 MkExpCondition(MkExpBrackets(MkListOne(
8954 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8955 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8956 exp.expType = a.expType;
8958 a.expType.refCount++;
8960 else if(!strcmp(id.string, "Abs"))
8963 MkExpCondition(MkExpBrackets(MkListOne(
8964 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8965 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8966 exp.expType = a.expType;
8968 a.expType.refCount++;
8970 else if(!strcmp(id.string, "Sgn"))
8972 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8974 MkExpCondition(MkExpBrackets(MkListOne(
8975 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8976 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8977 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8978 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8979 exp.expType = ProcessTypeString("int", false);
8982 FreeExpression(tempExp1);
8983 if(tempExp2) FreeExpression(tempExp2);
8997 if(!exp.call.exp.destType)
8999 exp.call.exp.destType = dummy;
9002 ProcessExpressionType(exp.call.exp);
9003 if(exp.call.exp.destType == dummy)
9006 exp.call.exp.destType = null;
9011 // Check argument types against parameter types
9012 functionType = exp.call.exp.expType;
9014 if(functionType && functionType.kind == TypeKind::methodType)
9016 methodType = functionType;
9017 functionType = methodType.method.dataType;
9019 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9020 // TOCHECK: Instead of doing this here could this be done per param?
9021 if(exp.call.exp.expType.usedClass)
9023 char typeString[1024];
9024 typeString[0] = '\0';
9026 Symbol back = functionType.thisClass;
9027 // Do not output class specifier here (thisclass was added to this)
9028 functionType.thisClass = null;
9029 PrintType(functionType, typeString, true, true);
9030 functionType.thisClass = back;
9032 if(strstr(typeString, "thisclass"))
9034 OldList * specs = MkList();
9037 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9039 decl = SpecDeclFromString(typeString, specs, null);
9041 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9042 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9043 exp.call.exp.expType.usedClass))
9044 thisClassParams = false;
9046 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9048 Class backupThisClass = thisClass;
9049 thisClass = exp.call.exp.expType.usedClass;
9050 ProcessDeclarator(decl);
9051 thisClass = backupThisClass;
9054 thisClassParams = true;
9056 functionType = ProcessType(specs, decl);
9057 functionType.refCount = 0;
9058 FinishTemplatesContext(context);
9061 FreeList(specs, FreeSpecifier);
9062 FreeDeclarator(decl);
9066 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9068 Type type = functionType.type;
9069 if(!functionType.refCount)
9071 functionType.type = null;
9072 FreeType(functionType);
9074 //methodType = functionType;
9075 functionType = type;
9077 if(functionType && functionType.kind != TypeKind::functionType)
9079 Compiler_Error($"called object %s is not a function\n", name);
9081 else if(functionType)
9083 bool emptyParams = false, noParams = false;
9084 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9085 Type type = functionType.params.first;
9086 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9088 Location oldyylloc = yylloc;
9090 if(!type) emptyParams = true;
9093 if(functionType.extraParam && e && functionType.thisClass)
9095 e.destType = MkClassType(functionType.thisClass.string);
9099 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9100 // Fixed #141 by adding '&& !functionType.extraParam'
9101 if(!functionType.staticMethod && !functionType.extraParam)
9103 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9104 memberExp.member.exp.expType._class)
9106 type = MkClassType(memberExp.member.exp.expType._class.string);
9111 type = functionType.params.first;
9116 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9118 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9119 type.byReference = functionType.byReference;
9120 type.typedByReference = functionType.typedByReference;
9123 // Allow manually passing a class for typed object
9124 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9128 type = functionType.params.first;
9136 if(type && type.kind == voidType)
9139 if(!type.refCount) FreeType(type);
9143 for( ; e; e = e.next)
9145 if(!type && !emptyParams)
9148 if(methodType && methodType.methodClass)
9149 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9150 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9151 noParams ? 0 : functionType.params.count);
9153 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9154 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9155 noParams ? 0 : functionType.params.count);
9159 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9161 Type templatedType = null;
9162 Class _class = methodType.usedClass;
9163 ClassTemplateParameter curParam = null;
9165 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9168 for(sClass = _class; sClass; sClass = sClass.base)
9170 if(sClass.templateClass) sClass = sClass.templateClass;
9172 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9174 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9177 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9179 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9180 id += nextClass.templateParams.count;
9189 if(curParam && _class.templateArgs[id].dataTypeString)
9191 ClassTemplateArgument arg = _class.templateArgs[id];
9193 Context context = SetupTemplatesContext(_class);
9196 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9197 templatedType = ProcessTypeString(arg.dataTypeString, false);
9198 FinishTemplatesContext(context);
9200 e.destType = templatedType;
9203 templatedType.passAsTemplate = true;
9204 // templatedType.refCount++;
9210 if(type) type.refCount++;
9215 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9217 e.destType = type.prev;
9218 e.destType.refCount++;
9223 if(type) type.refCount++;
9226 // Don't reach the end for the ellipsis
9227 if(type && type.kind != ellipsisType)
9229 Type next = type.next;
9230 if(!type.refCount) FreeType(type);
9235 if(type && type.kind != ellipsisType)
9237 if(methodType && methodType.methodClass)
9238 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9239 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9240 functionType.params.count + extra);
9242 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9243 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9244 functionType.params.count + extra);
9247 if(type && !type.refCount) FreeType(type);
9254 kind = TypeKind::functionType;
9257 if(exp.call.exp.type == identifierExp)
9259 char * string = exp.call.exp.identifier.string;
9263 Location oldyylloc = yylloc;
9265 yylloc = exp.call.exp.identifier.loc;
9266 if(strstr(string, "__builtin_") == string)
9270 functionType.returnType = exp.destType;
9271 exp.destType.refCount++;
9275 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9276 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9277 globalContext.symbols.Add((BTNode)symbol);
9278 if(strstr(symbol.string, "::"))
9279 globalContext.hasNameSpace = true;
9284 else if(exp.call.exp.type == memberExp)
9286 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9287 exp.call.exp.member.member.string);*/
9290 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9292 if(!functionType.returnType)
9294 functionType.returnType = Type
9301 if(functionType && functionType.kind == TypeKind::functionType)
9303 exp.expType = functionType.returnType;
9305 if(functionType.returnType)
9306 functionType.returnType.refCount++;
9308 if(!functionType.refCount)
9309 FreeType(functionType);
9312 if(exp.call.arguments)
9314 for(e = exp.call.arguments->first; e; e = e.next)
9316 Type destType = e.destType;
9317 ProcessExpressionType(e);
9325 Location oldyylloc = yylloc;
9327 Expression checkExp = exp.member.exp;
9330 if(checkExp.type == castExp)
9331 checkExp = checkExp.cast.exp;
9332 else if(checkExp.type == bracketsExp)
9333 checkExp = checkExp.list ? checkExp.list->first : null;
9338 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9339 exp.thisPtr = thisPtr;
9341 // DOING THIS LATER NOW...
9342 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9344 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9345 /* TODO: Name Space Fix ups
9346 if(!exp.member.member.classSym)
9347 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9351 ProcessExpressionType(exp.member.exp);
9352 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9353 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9355 exp.isConstant = false;
9358 exp.isConstant = exp.member.exp.isConstant;
9359 type = exp.member.exp.expType;
9363 if(type && (type.kind == templateType))
9365 Class _class = thisClass ? thisClass : currentClass;
9366 ClassTemplateParameter param = null;
9369 for(param = _class.templateParams.first; param; param = param.next)
9371 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9375 if(param && param.defaultArg.member)
9377 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9380 Expression expMember = exp.member.exp;
9382 OldList * specs = MkList();
9383 char thisClassTypeString[1024];
9385 FreeIdentifier(exp.member.member);
9387 ProcessExpressionType(argExp);
9390 char * colon = strstr(param.defaultArg.memberString, "::");
9393 char className[1024];
9396 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9397 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9400 strcpy(thisClassTypeString, _class.fullName);
9403 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9405 exp.expType = ProcessType(specs, decl);
9406 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9408 Class expClass = exp.expType._class.registered;
9409 Class cClass = null;
9414 char templateString[1024];
9415 ClassTemplateParameter param;
9416 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9417 for(cClass = expClass; cClass; cClass = cClass.base)
9420 for(param = cClass.templateParams.first; param; param = param.next)
9424 ClassTemplateArgument arg;
9425 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9426 arg = expClass.templateArgs[id];
9428 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9430 ClassTemplateParameter cParam;
9431 //int p = numParams - sClass.templateParams.count;
9434 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9436 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9438 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9440 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9442 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9443 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9455 strcat(argument, arg.name.string);
9456 strcat(argument, " = ");
9462 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9463 char expString[1024];
9464 OldList * specs = MkList();
9465 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9467 char * string = PrintHexUInt64(arg.expression.ui64);
9468 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9471 ProcessExpressionType(exp);
9472 ComputeExpression(exp);
9473 expString[0] = '\0';
9474 PrintExpression(exp, expString);
9475 strcat(argument, expString);
9477 FreeExpression(exp);
9482 strcat(argument, arg.member.name);
9485 case TemplateParameterType::type:
9487 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9489 if(!strcmp(arg.dataTypeString, "thisclass"))
9490 strcat(argument, thisClassTypeString);
9492 strcat(argument, arg.dataTypeString);
9499 if(paramCount) strcat(templateString, ", ");
9500 if(lastParam != p - 1)
9502 strcat(templateString, param.name);
9503 strcat(templateString, " = ");
9505 strcat(templateString, argument);
9514 int len = strlen(templateString);
9515 if(templateString[len-1] == '>') templateString[len++] = ' ';
9516 templateString[len++] = '>';
9517 templateString[len++] = '\0';
9520 Context context = SetupTemplatesContext(_class);
9521 FreeType(exp.expType);
9522 exp.expType = ProcessTypeString(templateString, false);
9523 FinishTemplatesContext(context);
9527 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9528 exp.type = bracketsExp;
9529 exp.list = MkListOne(MkExpOp(null, '*',
9534 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9535 MkExpBrackets(MkListOne(
9536 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9538 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9540 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9545 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9546 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9548 type = ProcessTemplateParameterType(type.templateParameter);
9551 // TODO: *** This seems to be where we should add method support for all basic types ***
9552 if(type && (type.kind == templateType));
9553 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9554 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9555 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9556 (type.kind == pointerType && type.type.kind == charType)))
9558 Identifier id = exp.member.member;
9559 TypeKind typeKind = type.kind;
9560 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9561 if(typeKind == subClassType && exp.member.exp.type == classExp)
9563 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9564 typeKind = classType;
9569 if(typeKind == intType || typeKind == enumType)
9570 _class = eSystem_FindClass(privateModule, "int");
9573 if(type.kind == classType && type._class && type._class.registered)
9575 _class = type._class.registered;
9577 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9579 _class = FindClass("char *").registered;
9581 else if(type.kind == pointerType)
9583 _class = eSystem_FindClass(privateModule, "uintptr");
9584 FreeType(exp.expType);
9585 exp.expType = ProcessTypeString("uintptr", false);
9586 exp.byReference = true;
9590 char string[1024] = "";
9592 PrintTypeNoConst(type, string, false, true);
9593 classSym = FindClass(string);
9594 if(classSym) _class = classSym.registered;
9602 (exp.member.exp.type == identifierExp &&
9603 !strcmp(exp.member.exp.identifier.string, "this"));*/
9604 Property prop = null;
9605 Method method = null;
9606 DataMember member = null;
9607 Property revConvert = null;
9608 ClassProperty classProp = null;
9610 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9611 exp.member.memberType = propertyMember;
9613 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9614 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9616 if(typeKind != subClassType)
9618 // Prioritize data members over properties for "this"
9619 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9621 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9622 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9624 prop = eClass_FindProperty(_class, id.string, privateModule);
9628 if(!member && !prop)
9629 prop = eClass_FindProperty(_class, id.string, privateModule);
9630 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9631 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9632 exp.member.thisPtr = true;
9634 // Prioritize properties over data members otherwise
9637 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9640 prop = eClass_FindProperty(_class, id.string, null);
9641 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9642 member = eClass_FindDataMember(_class, id.string, null, null, null);
9645 if(!prop && !member)
9647 method = eClass_FindMethod(_class, id.string, null);
9650 prop = eClass_FindProperty(_class, id.string, privateModule);
9651 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9652 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9658 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9665 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9666 method = eClass_FindMethod(_class, id.string, privateModule);
9667 if(!prop && !member && !method)
9669 if(typeKind == subClassType)
9671 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9674 exp.member.memberType = classPropertyMember;
9675 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9679 // Assume this is a class_data member
9680 char structName[1024];
9681 Identifier id = exp.member.member;
9682 Expression classExp = exp.member.exp;
9685 FreeType(classExp.expType);
9686 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9688 strcpy(structName, "__ecereClassData_");
9689 FullClassNameCat(structName, type._class.string, false);
9690 exp.type = pointerExp;
9691 exp.member.member = id;
9693 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9694 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9695 MkExpBrackets(MkListOne(MkExpOp(
9696 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9697 MkExpMember(classExp, MkIdentifier("data"))), '+',
9698 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9703 ProcessExpressionType(exp);
9709 // Check for reverse conversion
9710 // (Convert in an instantiation later, so that we can use
9711 // deep properties system)
9712 Symbol classSym = FindClass(id.string);
9715 Class convertClass = classSym.registered;
9717 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9724 exp.member.memberType = propertyMember;
9726 ProcessPropertyType(prop);
9727 exp.expType = prop.dataType;
9728 if(prop.dataType) prop.dataType.refCount++;
9732 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9734 FreeExpContents(exp);
9735 exp.type = identifierExp;
9736 exp.identifier = MkIdentifier("class");
9737 ProcessExpressionType(exp);
9741 exp.member.memberType = dataMember;
9742 DeclareStruct(_class.fullName, false);
9743 if(!member.dataType)
9745 Context context = SetupTemplatesContext(_class);
9746 member.dataType = ProcessTypeString(member.dataTypeString, false);
9747 FinishTemplatesContext(context);
9749 exp.expType = member.dataType;
9750 if(member.dataType) member.dataType.refCount++;
9754 exp.member.memberType = reverseConversionMember;
9755 exp.expType = MkClassType(revConvert._class.fullName);
9763 exp.type = identifierExp;
9764 exp.identifier = exp.member.member;
9767 exp.member.memberType = methodMember;
9769 if(!method.dataType)
9770 ProcessMethodType(method);
9778 // Tricky spot here... To use instance versus class virtual table
9779 // Put it back to what it was... What did we break?
9781 // Had to put it back for overriding Main of Thread global instance
9783 //exp.expType.methodClass = _class;
9784 exp.expType.methodClass = (id && id._class) ? _class : null;
9786 // Need the actual class used for templated classes
9787 exp.expType.usedClass = _class;
9791 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9793 FreeExpContents(exp);
9794 exp.type = identifierExp;
9795 exp.identifier = MkIdentifier("class");
9796 FreeType(exp.expType);
9797 exp.expType = MkClassType("ecere::com::Class");
9800 yylloc = exp.member.member.loc;
9801 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9803 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9806 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9811 while(tClass && !tClass.templateClass) tClass = tClass.base;
9813 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9816 ClassTemplateParameter curParam = null;
9819 for(sClass = tClass; sClass; sClass = sClass.base)
9822 if(sClass.templateClass) sClass = sClass.templateClass;
9823 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9825 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9827 for(sClass = sClass.base; sClass; sClass = sClass.base)
9828 id += sClass.templateParams.count;
9836 if(curParam && tClass.templateArgs[id].dataTypeString)
9838 ClassTemplateArgument arg = tClass.templateArgs[id];
9839 Context context = SetupTemplatesContext(tClass);
9841 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9842 FreeType(exp.expType);
9843 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9846 if(exp.expType.kind == thisClassType)
9848 FreeType(exp.expType);
9849 exp.expType = ReplaceThisClassType(_class);
9852 if(tClass.templateClass)
9853 exp.expType.passAsTemplate = true;
9854 //exp.expType.refCount++;
9857 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9858 //exp.destType.refCount++;
9860 if(exp.destType.kind == thisClassType)
9862 FreeType(exp.destType);
9863 exp.destType = ReplaceThisClassType(_class);
9867 FinishTemplatesContext(context);
9870 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9871 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9874 ClassTemplateParameter curParam = null;
9877 for(sClass = tClass; sClass; sClass = sClass.base)
9880 if(sClass.templateClass) sClass = sClass.templateClass;
9881 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9883 if(curParam.type == TemplateParameterType::type &&
9884 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9886 for(sClass = sClass.base; sClass; sClass = sClass.base)
9887 id += sClass.templateParams.count;
9897 ClassTemplateArgument arg = tClass.templateArgs[id];
9898 Context context = SetupTemplatesContext(tClass);
9901 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9903 basicType = ProcessTypeString(arg.dataTypeString, false);
9906 if(basicType.kind == thisClassType)
9908 FreeType(basicType);
9909 basicType = ReplaceThisClassType(_class);
9912 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9913 if(tClass.templateClass)
9914 basicType.passAsTemplate = true;
9917 FreeType(exp.expType);
9919 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9920 //exp.expType.refCount++;
9923 exp.destType = exp.expType;
9924 exp.destType.refCount++;
9928 Expression newExp { };
9929 OldList * specs = MkList();
9931 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9933 if(exp.destType) exp.destType.refCount++;
9934 if(exp.expType) exp.expType.refCount++;
9936 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9937 exp.cast.exp = newExp;
9938 //FreeType(exp.expType);
9939 //exp.expType = null;
9940 //ProcessExpressionType(sourceExp);
9943 FinishTemplatesContext(context);
9946 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9948 Class expClass = exp.expType._class.registered;
9951 Class cClass = null;
9956 char templateString[1024];
9957 ClassTemplateParameter param;
9958 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9959 while(cClass != expClass)
9962 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9965 for(param = cClass.templateParams.first; param; param = param.next)
9967 Class cClassCur = null;
9970 ClassTemplateParameter paramCur = null;
9971 ClassTemplateArgument arg;
9972 while(cClassCur != tClass && !paramCur)
9975 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9976 cClassCur = sClassCur;
9978 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9980 if(!strcmp(paramCur.name, param.name))
9988 if(paramCur && paramCur.type == TemplateParameterType::type)
9989 arg = tClass.templateArgs[cp];
9991 arg = expClass.templateArgs[p];
9998 strcat(argument, arg.name.string);
9999 strcat(argument, " = ");
10005 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10006 char expString[1024];
10007 OldList * specs = MkList();
10008 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10010 char * string = PrintHexUInt64(arg.expression.ui64);
10011 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10014 ProcessExpressionType(exp);
10015 ComputeExpression(exp);
10016 expString[0] = '\0';
10017 PrintExpression(exp, expString);
10018 strcat(argument, expString);
10020 FreeExpression(exp);
10025 strcat(argument, arg.member.name);
10028 case TemplateParameterType::type:
10030 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10031 strcat(argument, arg.dataTypeString);
10037 if(paramCount) strcat(templateString, ", ");
10038 if(lastParam != p - 1)
10040 strcat(templateString, param.name);
10041 strcat(templateString, " = ");
10043 strcat(templateString, argument);
10052 int len = strlen(templateString);
10053 if(templateString[len-1] == '>') templateString[len++] = ' ';
10054 templateString[len++] = '>';
10055 templateString[len++] = '\0';
10058 FreeType(exp.expType);
10060 Context context = SetupTemplatesContext(tClass);
10061 exp.expType = ProcessTypeString(templateString, false);
10062 FinishTemplatesContext(context);
10069 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10071 else if(type && (type.kind == structType || type.kind == unionType))
10073 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10076 exp.expType = memberType;
10078 memberType.refCount++;
10083 char expString[10240];
10084 expString[0] = '\0';
10085 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10086 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10089 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10091 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10093 Identifier id = exp.member.member;
10094 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10097 FreeType(exp.expType);
10098 exp.expType = ReplaceThisClassType(_class);
10102 yylloc = oldyylloc;
10105 // Convert x->y into (*x).y
10108 Type destType = exp.destType;
10110 // DOING THIS LATER NOW...
10111 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10113 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10114 /* TODO: Name Space Fix ups
10115 if(!exp.member.member.classSym)
10116 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10120 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10121 exp.type = memberExp;
10124 ProcessExpressionType(exp);
10131 //ComputeExpression(exp);
10133 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10134 if(classSym && classSym.registered)
10136 if(classSym.registered.type == noHeadClass)
10140 DeclareStruct(classSym.string, false);
10141 FreeSpecifier(exp._class);
10142 exp.type = typeSizeExp;
10143 FullClassNameCat(name, classSym.string, false);
10144 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10148 if(classSym.registered.fixed)
10150 FreeSpecifier(exp._class);
10151 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10152 exp.type = constantExp;
10156 char className[1024];
10157 strcpy(className, "__ecereClass_");
10158 FullClassNameCat(className, classSym.string, true);
10159 MangleClassName(className);
10161 DeclareClass(classSym, className);
10163 FreeExpContents(exp);
10164 exp.type = pointerExp;
10165 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10166 exp.member.member = MkIdentifier("structSize");
10176 // exp.isConstant = true;
10181 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10188 exp.isConstant = true;
10190 DeclareType(type, false, false);
10196 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10198 FreeType(exp.cast.exp.destType);
10199 exp.cast.exp.destType = type;
10201 ProcessExpressionType(exp.cast.exp);
10203 exp.expType = type;
10206 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10207 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10209 void * prev = exp.prev, * next = exp.next;
10210 Type expType = exp.cast.exp.destType;
10211 Expression castExp = exp.cast.exp;
10212 Type destType = exp.destType;
10214 if(expType) expType.refCount++;
10216 //FreeType(exp.destType);
10217 FreeType(exp.expType);
10218 FreeTypeName(exp.cast.typeName);
10221 FreeType(exp.expType);
10222 FreeType(exp.destType);
10224 exp.expType = expType;
10225 exp.destType = destType;
10235 exp.isConstant = exp.cast.exp.isConstant;
10240 case extensionInitializerExp:
10242 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10243 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10244 // ProcessInitializer(exp.initializer.initializer, type);
10245 exp.expType = type;
10250 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10251 ProcessExpressionType(exp.vaArg.exp);
10252 exp.expType = type;
10258 exp.isConstant = true;
10260 FreeType(exp.cond.cond.destType);
10261 exp.cond.cond.destType = MkClassType("bool");
10262 exp.cond.cond.destType.truth = true;
10263 ProcessExpressionType(exp.cond.cond);
10264 if(!exp.cond.cond.isConstant)
10265 exp.isConstant = false;
10266 for(e = exp.cond.exp->first; e; e = e.next)
10270 FreeType(e.destType);
10271 e.destType = exp.destType;
10272 if(e.destType) e.destType.refCount++;
10274 ProcessExpressionType(e);
10277 exp.expType = e.expType;
10278 if(e.expType) e.expType.refCount++;
10281 exp.isConstant = false;
10284 FreeType(exp.cond.elseExp.destType);
10285 // Added this check if we failed to find an expType
10286 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10289 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10291 if(exp.cond.elseExp.destType)
10292 exp.cond.elseExp.destType.refCount++;
10293 ProcessExpressionType(exp.cond.elseExp);
10295 // FIXED THIS: Was done before calling process on elseExp
10296 if(!exp.cond.elseExp.isConstant)
10297 exp.isConstant = false;
10300 case extensionCompoundExp:
10302 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10304 Statement last = exp.compound.compound.statements->last;
10305 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10307 ((Expression)last.expressions->last).destType = exp.destType;
10309 exp.destType.refCount++;
10311 ProcessStatement(exp.compound);
10312 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10314 exp.expType.refCount++;
10320 Specifier spec = exp._classExp.specifiers->first;
10321 if(spec && spec.type == nameSpecifier)
10323 exp.expType = MkClassType(spec.name);
10324 exp.expType.kind = subClassType;
10325 exp.byReference = true;
10329 exp.expType = MkClassType("ecere::com::Class");
10330 exp.byReference = true;
10336 Class _class = thisClass ? thisClass : currentClass;
10339 Identifier id = exp.classData.id;
10340 char structName[1024];
10341 Expression classExp;
10342 strcpy(structName, "__ecereClassData_");
10343 FullClassNameCat(structName, _class.fullName, false);
10344 exp.type = pointerExp;
10345 exp.member.member = id;
10346 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10347 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10349 classExp = MkExpIdentifier(MkIdentifier("class"));
10351 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10352 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10353 MkExpBrackets(MkListOne(MkExpOp(
10354 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10355 MkExpMember(classExp, MkIdentifier("data"))), '+',
10356 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10359 ProcessExpressionType(exp);
10367 char * typeString = null;
10368 char typeStringBuf[1024];
10369 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10370 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10372 Class templateClass = exp.destType._class.registered;
10373 typeString = templateClass.templateArgs[2].dataTypeString;
10377 // Guess type from expressions in the array
10379 for(e = exp.list->first; e; e = e.next)
10381 ProcessExpressionType(e);
10384 if(!type) { type = e.expType; type.refCount++; }
10387 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10388 if(!MatchTypeExpression(e, type, null, false))
10394 e = exp.list->first;
10395 ProcessExpressionType(e);
10398 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10399 if(!MatchTypeExpression(e, type, null, false))
10401 FreeType(e.expType);
10412 FreeType(e.expType);
10419 typeStringBuf[0] = '\0';
10420 PrintTypeNoConst(type, typeStringBuf, false, true);
10421 typeString = typeStringBuf;
10429 (Container)& (struct BuiltInContainer)
10431 ._vTbl = class(BuiltInContainer)._vTbl,
10432 ._class = class(BuiltInContainer),
10434 .data = (int[]){ 1, 7, 3, 4, 5 },
10436 .type = class(int),
10439 char templateString[1024];
10440 OldList * initializers = MkList();
10441 OldList * structInitializers = MkList();
10442 OldList * specs = MkList();
10444 Declarator decl = SpecDeclFromString(typeString, specs, null);
10445 sprintf(templateString, "Container<%s>", typeString);
10450 type = ProcessTypeString(typeString, false);
10451 while(e = exp.list->first)
10453 exp.list->Remove(e);
10456 ProcessExpressionType(e);
10457 ListAdd(initializers, MkInitializerAssignment(e));
10463 DeclareStruct("ecere::com::BuiltInContainer", false);
10465 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10466 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10467 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10468 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10469 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10470 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10471 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10472 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10473 MkInitializerList(initializers))));
10474 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10475 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10476 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10477 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10478 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10479 exp.expType = ProcessTypeString(templateString, false);
10480 exp.type = bracketsExp;
10481 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10483 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10484 MkInitializerList(structInitializers)))));
10485 ProcessExpressionType(expExt);
10489 exp.expType = ProcessTypeString("Container", false);
10490 Compiler_Error($"Couldn't determine type of array elements\n");
10496 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10498 FreeType(exp.expType);
10499 exp.expType = ReplaceThisClassType(thisClass);
10502 // Resolve structures here
10503 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10505 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10506 // TODO: Fix members reference...
10509 if(exp.expType.kind != enumType)
10512 String enumName = CopyString(exp.expType.enumName);
10514 // Fixed a memory leak on self-referencing C structs typedefs
10515 // by instantiating a new type rather than simply copying members
10516 // into exp.expType
10517 FreeType(exp.expType);
10518 exp.expType = Type { };
10519 exp.expType.kind = symbol.type.kind;
10520 exp.expType.refCount++;
10521 exp.expType.enumName = enumName;
10523 exp.expType.members = symbol.type.members;
10524 for(member = symbol.type.members.first; member; member = member.next)
10530 for(member = symbol.type.members.first; member; member = member.next)
10532 NamedLink value { name = CopyString(member.name) };
10533 exp.expType.members.Add(value);
10540 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10541 else if(exp.destType && !exp.destType.keepCast)
10543 if(!CheckExpressionType(exp, exp.destType, false))
10545 if(!exp.destType.count || unresolved)
10550 if(exp.destType.kind != ellipsisType)
10556 char expString[10240];
10557 expString[0] = '\0';
10559 PrintType(exp.destType, type2, false, true);
10561 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10563 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10564 else if(exp.type != dummyExp)
10565 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10570 char expString[10240] ;
10571 expString[0] = '\0';
10572 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10575 Compiler_Error($"unresolved identifier %s\n", expString);
10576 else if(exp.type != dummyExp)
10577 Compiler_Error($"couldn't determine type of %s\n", expString);
10588 PrintType(exp.expType, type1, false, true);
10589 PrintType(exp.destType, type2, false, true);
10592 //CheckExpressionType(exp, exp.destType, false);
10594 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10595 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10596 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10599 char expString[10240];
10600 expString[0] = '\0';
10601 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10604 CheckExpressionType(exp, exp.destType, false);
10606 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10607 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10608 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10610 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10611 FreeType(exp.expType);
10612 exp.destType.refCount++;
10613 exp.expType = exp.destType;
10618 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10620 Expression newExp { };
10621 char typeString[1024];
10622 OldList * specs = MkList();
10625 typeString[0] = '\0';
10629 if(exp.expType) exp.expType.refCount++;
10630 if(exp.expType) exp.expType.refCount++;
10631 exp.type = castExp;
10632 newExp.destType = exp.expType;
10634 PrintType(exp.expType, typeString, false, false);
10635 decl = SpecDeclFromString(typeString, specs, null);
10637 exp.cast.typeName = MkTypeName(specs, decl);
10638 exp.cast.exp = newExp;
10641 else if(unresolved)
10643 if(exp.identifier._class && exp.identifier._class.name)
10644 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10645 else if(exp.identifier.string && exp.identifier.string[0])
10646 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10648 else if(!exp.expType && exp.type != dummyExp)
10650 char expString[10240];
10651 expString[0] = '\0';
10652 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10653 Compiler_Error($"couldn't determine type of %s\n", expString);
10656 // Let's try to support any_object & typed_object here:
10658 ApplyAnyObjectLogic(exp);
10660 // Mark nohead classes as by reference, unless we're casting them to an integral type
10661 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10662 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10663 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10664 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10666 exp.byReference = true;
10668 yylloc = oldyylloc;
10671 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10673 // THIS CODE WILL FIND NEXT MEMBER...
10676 *curMember = (*curMember).next;
10678 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10680 *curMember = subMemberStack[--(*subMemberStackPos)];
10681 *curMember = (*curMember).next;
10684 // SKIP ALL PROPERTIES HERE...
10685 while((*curMember) && (*curMember).isProperty)
10686 *curMember = (*curMember).next;
10688 if(subMemberStackPos)
10690 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10692 subMemberStack[(*subMemberStackPos)++] = *curMember;
10694 *curMember = (*curMember).members.first;
10695 while(*curMember && (*curMember).isProperty)
10696 *curMember = (*curMember).next;
10704 if(subMemberStackPos && *subMemberStackPos)
10706 *curMember = subMemberStack[--(*subMemberStackPos)];
10707 *curMember = (*curMember).next;
10711 Class lastCurClass = *curClass;
10713 if(*curClass == _class) break; // REACHED THE END
10715 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10716 *curMember = (*curClass).membersAndProperties.first;
10719 while((*curMember) && (*curMember).isProperty)
10720 *curMember = (*curMember).next;
10721 if(subMemberStackPos)
10723 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10725 subMemberStack[(*subMemberStackPos)++] = *curMember;
10727 *curMember = (*curMember).members.first;
10728 while(*curMember && (*curMember).isProperty)
10729 *curMember = (*curMember).next;
10737 static void ProcessInitializer(Initializer init, Type type)
10741 case expInitializer:
10742 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10744 // TESTING THIS FOR SHUTTING = 0 WARNING
10745 if(init.exp && !init.exp.destType)
10747 FreeType(init.exp.destType);
10748 init.exp.destType = type;
10749 if(type) type.refCount++;
10753 ProcessExpressionType(init.exp);
10754 init.isConstant = init.exp.isConstant;
10760 Expression exp = init.exp;
10761 Instantiation inst = exp.instance;
10762 MembersInit members;
10764 init.type = listInitializer;
10765 init.list = MkList();
10769 for(members = inst.members->first; members; members = members.next)
10771 if(members.type == dataMembersInit)
10774 for(member = members.dataMembers->first; member; member = member.next)
10776 ListAdd(init.list, member.initializer);
10777 member.initializer = null;
10780 // Discard all MembersInitMethod
10783 FreeExpression(exp);
10785 case listInitializer:
10788 Type initializerType = null;
10789 Class curClass = null;
10790 DataMember curMember = null;
10791 DataMember subMemberStack[256];
10792 int subMemberStackPos = 0;
10794 if(type && type.kind == arrayType)
10795 initializerType = Dereference(type);
10796 else if(type && (type.kind == structType || type.kind == unionType))
10797 initializerType = type.members.first;
10799 for(i = init.list->first; i; i = i.next)
10801 if(type && type.kind == classType && type._class && type._class.registered)
10803 // 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)
10804 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10805 // TODO: Generate error on initializing a private data member this way from another module...
10808 if(!curMember.dataType)
10809 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10810 initializerType = curMember.dataType;
10813 ProcessInitializer(i, initializerType);
10814 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10815 initializerType = initializerType.next;
10817 init.isConstant = false;
10820 if(type && type.kind == arrayType)
10821 FreeType(initializerType);
10823 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10825 Compiler_Error($"Assigning list initializer to non list\n");
10832 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10836 case baseSpecifier:
10838 if(spec.specifier == THISCLASS)
10842 spec.type = nameSpecifier;
10843 spec.name = ReplaceThisClass(thisClass);
10844 spec.symbol = FindClass(spec.name);
10845 ProcessSpecifier(spec, declareStruct);
10850 case nameSpecifier:
10852 Symbol symbol = FindType(curContext, spec.name);
10854 DeclareType(symbol.type, true, true);
10855 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10856 DeclareStruct(spec.name, false);
10859 case enumSpecifier:
10864 for(e = spec.list->first; e; e = e.next)
10867 ProcessExpressionType(e.exp);
10872 case structSpecifier:
10873 case unionSpecifier:
10875 if(spec.definitions)
10878 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10880 ProcessClass(spec.definitions, symbol);
10883 for(def = spec.definitions->first; def; def = def.next)
10885 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10886 ProcessDeclaration(def.decl);
10893 case classSpecifier:
10895 Symbol classSym = FindClass(spec.name);
10896 if(classSym && classSym.registered && classSym.registered.type == structClass)
10897 DeclareStruct(spec.name, false);
10905 static void ProcessDeclarator(Declarator decl)
10909 case identifierDeclarator:
10910 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10912 FreeSpecifier(decl.identifier._class);
10913 decl.identifier._class = null;
10916 case arrayDeclarator:
10918 ProcessExpressionType(decl.array.exp);
10919 case structDeclarator:
10920 case bracketsDeclarator:
10921 case functionDeclarator:
10922 case pointerDeclarator:
10923 case extendedDeclarator:
10924 case extendedDeclaratorEnd:
10925 if(decl.declarator)
10926 ProcessDeclarator(decl.declarator);
10927 if(decl.type == functionDeclarator)
10929 Identifier id = GetDeclId(decl);
10930 if(id && id._class)
10934 qualifiers = MkListOne(id._class);
10937 if(!decl.function.parameters)
10938 decl.function.parameters = MkList();
10939 decl.function.parameters->Insert(null, param);
10942 if(decl.function.parameters)
10946 for(param = decl.function.parameters->first; param; param = param.next)
10948 if(param.qualifiers && param.qualifiers->first)
10950 Specifier spec = param.qualifiers->first;
10951 if(spec && spec.specifier == TYPED_OBJECT)
10953 Declarator d = param.declarator;
10956 qualifiers = MkListOne(MkSpecifier(VOID));
10957 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10960 FreeList(param.qualifiers, FreeSpecifier);
10962 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10963 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10965 decl.function.parameters->Insert(param, newParam);
10968 else if(spec && spec.specifier == ANY_OBJECT)
10970 Declarator d = param.declarator;
10972 FreeList(param.qualifiers, FreeSpecifier);
10974 param.qualifiers = MkListOne(MkSpecifier(VOID));
10975 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10977 else if(spec.specifier == THISCLASS)
10981 spec.type = nameSpecifier;
10982 spec.name = ReplaceThisClass(thisClass);
10983 spec.symbol = FindClass(spec.name);
10984 ProcessSpecifier(spec, false);
10989 if(param.declarator)
10990 ProcessDeclarator(param.declarator);
10998 static void ProcessDeclaration(Declaration decl)
11003 case initDeclaration:
11005 bool declareStruct = false;
11007 lineNum = decl.pos.line;
11008 column = decl.pos.col;
11011 if(decl.declarators)
11015 for(d = decl.declarators->first; d; d = d.next)
11017 Type type, subType;
11018 ProcessDeclarator(d.declarator);
11020 type = ProcessType(decl.specifiers, d.declarator);
11024 ProcessInitializer(d.initializer, type);
11026 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11028 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11029 d.initializer.exp.type == instanceExp)
11031 if(type.kind == classType && type._class ==
11032 d.initializer.exp.expType._class)
11034 Instantiation inst = d.initializer.exp.instance;
11035 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11037 d.initializer.exp.instance = null;
11038 if(decl.specifiers)
11039 FreeList(decl.specifiers, FreeSpecifier);
11040 FreeList(decl.declarators, FreeInitDeclarator);
11044 decl.type = instDeclaration;
11049 for(subType = type; subType;)
11051 if(subType.kind == classType)
11053 declareStruct = true;
11056 else if(subType.kind == pointerType)
11058 else if(subType.kind == arrayType)
11059 subType = subType.arrayType;
11069 if(decl.specifiers)
11072 for(s = decl.specifiers->first; s; s = s.next)
11074 ProcessSpecifier(s, declareStruct);
11079 case instDeclaration:
11081 ProcessInstantiationType(decl.inst);
11084 case structDeclaration:
11088 bool declareStruct = false;
11090 if(decl.declarators)
11092 for(d = decl.declarators->first; d; d = d.next)
11094 Type type = ProcessType(decl.specifiers, d.declarator);
11096 ProcessDeclarator(d);
11097 for(subType = type; subType;)
11099 if(subType.kind == classType)
11101 declareStruct = true;
11104 else if(subType.kind == pointerType)
11106 else if(subType.kind == arrayType)
11107 subType = subType.arrayType;
11114 if(decl.specifiers)
11116 for(spec = decl.specifiers->first; spec; spec = spec.next)
11117 ProcessSpecifier(spec, declareStruct);
11124 static FunctionDefinition curFunction;
11126 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11128 char propName[1024], propNameM[1024];
11129 char getName[1024], setName[1024];
11132 DeclareProperty(prop, setName, getName);
11134 // eInstance_FireWatchers(object, prop);
11135 strcpy(propName, "__ecereProp_");
11136 FullClassNameCat(propName, prop._class.fullName, false);
11137 strcat(propName, "_");
11138 // strcat(propName, prop.name);
11139 FullClassNameCat(propName, prop.name, true);
11140 MangleClassName(propName);
11142 strcpy(propNameM, "__ecerePropM_");
11143 FullClassNameCat(propNameM, prop._class.fullName, false);
11144 strcat(propNameM, "_");
11145 // strcat(propNameM, prop.name);
11146 FullClassNameCat(propNameM, prop.name, true);
11147 MangleClassName(propNameM);
11149 if(prop.isWatchable)
11152 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11153 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11154 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11157 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11158 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11159 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11165 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11166 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11167 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11170 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11171 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11172 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11175 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11176 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11177 curFunction.propSet.fireWatchersDone = true;
11180 static void ProcessStatement(Statement stmt)
11184 lineNum = stmt.pos.line;
11185 column = stmt.pos.col;
11190 ProcessStatement(stmt.labeled.stmt);
11193 // This expression should be constant...
11194 if(stmt.caseStmt.exp)
11196 FreeType(stmt.caseStmt.exp.destType);
11197 stmt.caseStmt.exp.destType = curSwitchType;
11198 if(curSwitchType) curSwitchType.refCount++;
11199 ProcessExpressionType(stmt.caseStmt.exp);
11200 ComputeExpression(stmt.caseStmt.exp);
11202 if(stmt.caseStmt.stmt)
11203 ProcessStatement(stmt.caseStmt.stmt);
11207 if(stmt.compound.context)
11212 Statement prevCompound = curCompound;
11213 Context prevContext = curContext;
11215 if(!stmt.compound.isSwitch)
11216 curCompound = stmt;
11217 curContext = stmt.compound.context;
11219 if(stmt.compound.declarations)
11221 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11222 ProcessDeclaration(decl);
11224 if(stmt.compound.statements)
11226 for(s = stmt.compound.statements->first; s; s = s.next)
11227 ProcessStatement(s);
11230 curContext = prevContext;
11231 curCompound = prevCompound;
11235 case expressionStmt:
11238 if(stmt.expressions)
11240 for(exp = stmt.expressions->first; exp; exp = exp.next)
11241 ProcessExpressionType(exp);
11249 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11250 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11251 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11252 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11254 ProcessExpressionType(exp);
11256 if(stmt.ifStmt.stmt)
11257 ProcessStatement(stmt.ifStmt.stmt);
11258 if(stmt.ifStmt.elseStmt)
11259 ProcessStatement(stmt.ifStmt.elseStmt);
11264 Type oldSwitchType = curSwitchType;
11265 if(stmt.switchStmt.exp)
11268 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11278 e.exp.destType = destType;
11281 ProcessExpressionType(exp);
11284 curSwitchType = exp.expType;
11287 ProcessStatement(stmt.switchStmt.stmt);
11288 curSwitchType = oldSwitchType;
11293 if(stmt.whileStmt.exp)
11297 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11298 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11299 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11300 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11302 ProcessExpressionType(exp);
11305 if(stmt.whileStmt.stmt)
11306 ProcessStatement(stmt.whileStmt.stmt);
11311 if(stmt.doWhile.exp)
11315 if(stmt.doWhile.exp->last)
11317 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11318 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11319 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11321 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11323 ProcessExpressionType(exp);
11326 if(stmt.doWhile.stmt)
11327 ProcessStatement(stmt.doWhile.stmt);
11333 if(stmt.forStmt.init)
11334 ProcessStatement(stmt.forStmt.init);
11336 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11338 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11339 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11340 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11343 if(stmt.forStmt.check)
11344 ProcessStatement(stmt.forStmt.check);
11345 if(stmt.forStmt.increment)
11347 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11348 ProcessExpressionType(exp);
11351 if(stmt.forStmt.stmt)
11352 ProcessStatement(stmt.forStmt.stmt);
11357 Identifier id = stmt.forEachStmt.id;
11358 OldList * exp = stmt.forEachStmt.exp;
11359 OldList * filter = stmt.forEachStmt.filter;
11360 Statement block = stmt.forEachStmt.stmt;
11361 char iteratorType[1024];
11364 bool isBuiltin = exp && exp->last &&
11365 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11366 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11367 Expression arrayExp;
11368 char * typeString = null;
11369 int builtinCount = 0;
11371 for(e = exp ? exp->first : null; e; e = e.next)
11375 FreeType(e.destType);
11376 e.destType = ProcessTypeString("Container", false);
11378 if(!isBuiltin || e.next)
11379 ProcessExpressionType(e);
11382 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11383 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11384 eClass_IsDerived(source._class.registered, containerClass)))
11386 Class _class = source ? source._class.registered : null;
11388 Expression expIt = null;
11389 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11390 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11391 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11392 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11393 stmt.type = compoundStmt;
11395 stmt.compound.context = Context { };
11396 stmt.compound.context.parent = curContext;
11397 curContext = stmt.compound.context;
11399 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11401 Class mapClass = eSystem_FindClass(privateModule, "Map");
11402 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11403 isCustomAVLTree = true;
11404 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11406 else if(eClass_IsDerived(source._class.registered, mapClass))
11409 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11410 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11412 Class listClass = eSystem_FindClass(privateModule, "List");
11414 isList = eClass_IsDerived(source._class.registered, listClass);
11420 OldList * specs = MkList();
11421 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11422 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11423 stmt.compound.declarations = MkListOne(
11424 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11425 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11426 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11427 MkInitializerAssignment(MkExpBrackets(exp))))));
11432 char typeStringBuf[1024];
11434 // TODO: Merge this code?
11435 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11436 if(((Expression)exp->last).type == castExp)
11438 TypeName typeName = ((Expression)exp->last).cast.typeName;
11440 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11443 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11444 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11445 arrayExp.destType._class.registered.templateArgs)
11447 Class templateClass = arrayExp.destType._class.registered;
11448 typeString = templateClass.templateArgs[2].dataTypeString;
11450 else if(arrayExp.list)
11452 // Guess type from expressions in the array
11454 for(e = arrayExp.list->first; e; e = e.next)
11456 ProcessExpressionType(e);
11459 if(!type) { type = e.expType; type.refCount++; }
11462 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11463 if(!MatchTypeExpression(e, type, null, false))
11469 e = arrayExp.list->first;
11470 ProcessExpressionType(e);
11473 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11474 if(!MatchTypeExpression(e, type, null, false))
11476 FreeType(e.expType);
11487 FreeType(e.expType);
11494 typeStringBuf[0] = '\0';
11495 PrintType(type, typeStringBuf, false, true);
11496 typeString = typeStringBuf;
11502 OldList * initializers = MkList();
11504 OldList * specs = MkList();
11509 builtinCount = arrayExp.list->count;
11510 type = ProcessTypeString(typeString, false);
11511 while(e = arrayExp.list->first)
11513 arrayExp.list->Remove(e);
11516 ProcessExpressionType(e);
11517 ListAdd(initializers, MkInitializerAssignment(e));
11520 delete arrayExp.list;
11522 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11523 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11524 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11526 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11528 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11529 ), MkInitializerList(initializers)))));
11530 FreeList(exp, FreeExpression);
11534 arrayExp.expType = ProcessTypeString("Container", false);
11535 Compiler_Error($"Couldn't determine type of array elements\n");
11540 OldList * specs = MkList();
11542 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11543 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11544 stmt.compound.declarations = MkListOne(
11545 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11546 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11547 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11548 MkInitializerAssignment(MkExpBrackets(exp))))));
11551 else if(isLinkList && !isList)
11554 OldList * specs = MkList();
11555 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11556 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11557 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11558 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11559 MkInitializerAssignment(MkExpBrackets(exp))))));
11561 /*else if(isCustomAVLTree)
11564 OldList * specs = MkList();
11565 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11566 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11567 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11568 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11569 MkInitializerAssignment(MkExpBrackets(exp))))));
11571 else if(_class.templateArgs)
11574 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11576 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11578 stmt.compound.declarations = MkListOne(
11579 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11580 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11581 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11583 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11587 // Reparent sub-contexts in this statement
11591 if(block.compound.context)
11592 block.compound.context.parent = stmt.compound.context;
11595 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11596 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11597 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11598 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11601 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11602 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11605 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11606 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11609 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11610 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11613 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11614 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11617 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11618 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11620 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11623 case expressionStmt:
11629 case badDeclarationStmt:
11630 case fireWatchersStmt:
11631 case stopWatchingStmt:
11638 block = MkIfStmt(filter, block, null);
11642 stmt.compound.statements = MkListOne(MkForStmt(
11643 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11644 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11645 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11646 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11648 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11649 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11650 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11655 //OldList * specs = MkList();
11656 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11658 sprintf(count, "%d", builtinCount);
11660 stmt.compound.statements = MkListOne(MkForStmt(
11661 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11662 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11663 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11664 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11668 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11669 stmt.compound.statements = MkListOne(MkForStmt(
11670 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11671 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11672 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11673 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11676 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11677 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11678 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11680 else if(isLinkList && !isList)
11682 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11683 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11684 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11685 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11687 stmt.compound.statements = MkListOne(MkForStmt(
11688 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11689 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11690 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11695 OldList * specs = MkList();
11696 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11697 stmt.compound.statements = MkListOne(MkForStmt(
11698 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11699 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11700 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11701 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11702 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11705 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11706 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11707 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11709 /*else if(isCustomAVLTree)
11711 stmt.compound.statements = MkListOne(MkForStmt(
11712 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11713 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11714 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11715 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11718 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11719 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11720 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11724 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11725 MkIdentifier("Next")), null)), block));
11727 ProcessExpressionType(expIt);
11728 if(stmt.compound.declarations->first)
11729 ProcessDeclaration(stmt.compound.declarations->first);
11732 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11734 ProcessStatement(stmt);
11735 curContext = stmt.compound.context.parent;
11740 Compiler_Error($"Expression is not a container\n");
11753 if(stmt.expressions)
11755 for(exp = stmt.expressions->first; exp; exp = exp.next)
11759 if(curFunction && !curFunction.type)
11760 curFunction.type = ProcessType(
11761 curFunction.specifiers, curFunction.declarator);
11762 FreeType(exp.destType);
11763 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11764 if(exp.destType) exp.destType.refCount++;
11766 ProcessExpressionType(exp);
11771 case badDeclarationStmt:
11773 ProcessDeclaration(stmt.decl);
11779 if(stmt.asmStmt.inputFields)
11781 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11782 if(field.expression)
11783 ProcessExpressionType(field.expression);
11785 if(stmt.asmStmt.outputFields)
11787 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11788 if(field.expression)
11789 ProcessExpressionType(field.expression);
11791 if(stmt.asmStmt.clobberedFields)
11793 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11795 if(field.expression)
11796 ProcessExpressionType(field.expression);
11803 PropertyWatch propWatch;
11804 OldList * watches = stmt._watch.watches;
11805 Expression object = stmt._watch.object;
11806 Expression watcher = stmt._watch.watcher;
11808 ProcessExpressionType(watcher);
11810 ProcessExpressionType(object);
11814 if(watcher || thisClass)
11816 External external = curExternal;
11817 Context context = curContext;
11819 stmt.type = expressionStmt;
11820 stmt.expressions = MkList();
11822 curExternal = external.prev;
11824 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11826 ClassFunction func;
11827 char watcherName[1024];
11828 Class watcherClass = watcher ?
11829 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11830 External createdExternal;
11832 // Create a declaration above
11833 External externalDecl = MkExternalDeclaration(null);
11834 ast->Insert(curExternal.prev, externalDecl);
11836 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11837 if(propWatch.deleteWatch)
11838 strcat(watcherName, "_delete");
11842 for(propID = propWatch.properties->first; propID; propID = propID.next)
11844 strcat(watcherName, "_");
11845 strcat(watcherName, propID.string);
11849 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11851 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11852 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11853 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11854 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11855 ProcessClassFunctionBody(func, propWatch.compound);
11856 propWatch.compound = null;
11858 //afterExternal = afterExternal ? afterExternal : curExternal;
11860 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11861 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11863 createdExternal.symbol.idCode = external.symbol.idCode;
11865 curExternal = createdExternal;
11866 ProcessFunction(createdExternal.function);
11869 // Create a declaration above
11871 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11872 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11873 externalDecl.declaration = decl;
11874 if(decl.symbol && !decl.symbol.pointerExternal)
11875 decl.symbol.pointerExternal = externalDecl;
11878 if(propWatch.deleteWatch)
11880 OldList * args = MkList();
11881 ListAdd(args, CopyExpression(object));
11882 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11883 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11884 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11888 Class _class = object.expType._class.registered;
11891 for(propID = propWatch.properties->first; propID; propID = propID.next)
11893 char propName[1024];
11894 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11897 char getName[1024], setName[1024];
11898 OldList * args = MkList();
11900 DeclareProperty(prop, setName, getName);
11902 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11903 strcpy(propName, "__ecereProp_");
11904 FullClassNameCat(propName, prop._class.fullName, false);
11905 strcat(propName, "_");
11906 // strcat(propName, prop.name);
11907 FullClassNameCat(propName, prop.name, true);
11909 ListAdd(args, CopyExpression(object));
11910 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11911 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11912 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11914 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11917 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11922 Compiler_Error($"Invalid watched object\n");
11925 curExternal = external;
11926 curContext = context;
11929 FreeExpression(watcher);
11931 FreeExpression(object);
11932 FreeList(watches, FreePropertyWatch);
11935 Compiler_Error($"No observer specified and not inside a _class\n");
11939 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11941 ProcessStatement(propWatch.compound);
11947 case fireWatchersStmt:
11949 OldList * watches = stmt._watch.watches;
11950 Expression object = stmt._watch.object;
11952 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11953 // printf("%X\n", watches);
11954 // printf("%X\n", stmt._watch.watches);
11956 ProcessExpressionType(object);
11961 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11967 stmt.type = expressionStmt;
11968 stmt.expressions = MkList();
11970 // Check if we're inside a property set
11971 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11973 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11977 //Compiler_Error($"No property specified and not inside a property set\n");
11981 for(propID = watches->first; propID; propID = propID.next)
11983 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11986 CreateFireWatcher(prop, object, stmt);
11989 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11994 // Fire all properties!
11997 for(base = _class; base; base = base.base)
11999 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12001 if(prop.isProperty && prop.isWatchable)
12003 CreateFireWatcher(prop, object, stmt);
12010 FreeExpression(object);
12011 FreeList(watches, FreeIdentifier);
12014 Compiler_Error($"Invalid object specified and not inside a class\n");
12018 case stopWatchingStmt:
12020 OldList * watches = stmt._watch.watches;
12021 Expression object = stmt._watch.object;
12022 Expression watcher = stmt._watch.watcher;
12025 ProcessExpressionType(object);
12027 ProcessExpressionType(watcher);
12030 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12032 if(watcher || thisClass)
12038 stmt.type = expressionStmt;
12039 stmt.expressions = MkList();
12044 // eInstance_StopWatching(object, null, watcher);
12046 ListAdd(args, CopyExpression(object));
12047 ListAdd(args, MkExpConstant("0"));
12048 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12049 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12053 for(propID = watches->first; propID; propID = propID.next)
12055 char propName[1024];
12056 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12059 char getName[1024], setName[1024];
12060 OldList * args = MkList();
12062 DeclareProperty(prop, setName, getName);
12064 // eInstance_StopWatching(object, prop, watcher);
12065 strcpy(propName, "__ecereProp_");
12066 FullClassNameCat(propName, prop._class.fullName, false);
12067 strcat(propName, "_");
12068 // strcat(propName, prop.name);
12069 FullClassNameCat(propName, prop.name, true);
12070 MangleClassName(propName);
12072 ListAdd(args, CopyExpression(object));
12073 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12074 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12075 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12078 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
12083 FreeExpression(object);
12085 FreeExpression(watcher);
12086 FreeList(watches, FreeIdentifier);
12089 Compiler_Error($"Invalid object specified and not inside a class\n");
12092 Compiler_Error($"No observer specified and not inside a class\n");
12099 static void ProcessFunction(FunctionDefinition function)
12101 Identifier id = GetDeclId(function.declarator);
12102 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12103 Type type = symbol ? symbol.type : null;
12104 Class oldThisClass = thisClass;
12105 Context oldTopContext = topContext;
12107 yylloc = function.loc;
12108 // Process thisClass
12110 if(type && type.thisClass)
12112 Symbol classSym = type.thisClass;
12113 Class _class = type.thisClass.registered;
12114 char className[1024];
12115 char structName[1024];
12116 Declarator funcDecl;
12119 bool typedObject = false;
12121 if(_class && !_class.base)
12123 _class = currentClass;
12124 if(_class && !_class.symbol)
12125 _class.symbol = FindClass(_class.fullName);
12126 classSym = _class ? _class.symbol : null;
12127 typedObject = true;
12130 thisClass = _class;
12132 if(inCompiler && _class)
12134 if(type.kind == functionType)
12136 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12138 //TypeName param = symbol.type.params.first;
12139 Type param = symbol.type.params.first;
12140 symbol.type.params.Remove(param);
12141 //FreeTypeName(param);
12144 if(type.classObjectType != classPointer)
12146 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12147 symbol.type.staticMethod = true;
12148 symbol.type.thisClass = null;
12150 // HIGH DANGER: VERIFYING THIS...
12151 symbol.type.extraParam = false;
12155 strcpy(className, "__ecereClass_");
12156 FullClassNameCat(className, _class.fullName, true);
12158 MangleClassName(className);
12161 FullClassNameCat(structName, _class.fullName, false);
12166 funcDecl = GetFuncDecl(function.declarator);
12169 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12171 TypeName param = funcDecl.function.parameters->first;
12172 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12174 funcDecl.function.parameters->Remove(param);
12175 FreeTypeName(param);
12179 // DANGER: Watch for this... Check if it's a Conversion?
12180 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12182 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12183 if(!function.propertyNoThis)
12185 TypeName thisParam;
12187 if(type.classObjectType != classPointer)
12189 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12190 if(!funcDecl.function.parameters)
12191 funcDecl.function.parameters = MkList();
12192 funcDecl.function.parameters->Insert(null, thisParam);
12197 if(type.classObjectType != classPointer)
12199 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12200 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12203 thisParam = TypeName
12205 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12206 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12208 funcDecl.function.parameters->Insert(null, thisParam);
12213 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12215 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12216 funcDecl = GetFuncDecl(initDecl.declarator);
12219 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12221 TypeName param = funcDecl.function.parameters->first;
12222 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12224 funcDecl.function.parameters->Remove(param);
12225 FreeTypeName(param);
12229 if(type.classObjectType != classPointer)
12231 // DANGER: Watch for this... Check if it's a Conversion?
12232 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12234 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12236 if(!funcDecl.function.parameters)
12237 funcDecl.function.parameters = MkList();
12238 funcDecl.function.parameters->Insert(null, thisParam);
12245 // Add this to the context
12248 if(type.classObjectType != classPointer)
12250 thisSymbol = Symbol
12252 string = CopyString("this");
12253 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12255 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12257 if(typedObject && thisSymbol.type)
12259 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12260 thisSymbol.type.byReference = type.byReference;
12261 thisSymbol.type.typedByReference = type.byReference;
12263 thisSymbol = Symbol { string = CopyString("class") };
12264 function.body.compound.context.symbols.Add(thisSymbol);
12270 // Pointer to class data
12272 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12274 DataMember member = null;
12277 for(base = _class; base && base.type != systemClass; base = base.next)
12279 for(member = base.membersAndProperties.first; member; member = member.next)
12280 if(!member.isProperty)
12286 for(member = _class.membersAndProperties.first; member; member = member.next)
12287 if(!member.isProperty)
12291 char pointerName[1024];
12294 Initializer initializer;
12295 Expression exp, bytePtr;
12297 strcpy(pointerName, "__ecerePointer_");
12298 FullClassNameCat(pointerName, _class.fullName, false);
12300 char className[1024];
12301 strcpy(className, "__ecereClass_");
12302 FullClassNameCat(className, classSym.string, true);
12303 MangleClassName(className);
12306 DeclareClass(classSym, className);
12310 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12315 sprintf(string, "%d", _class.offset);
12316 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12320 // ([bytePtr] + [className]->offset)
12321 exp = QBrackets(MkExpOp(bytePtr, '+',
12322 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12325 // (this ? [exp] : 0)
12326 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12330 kind = pointerType;
12331 type = Type { refCount = 1, kind = voidType };
12336 yylloc = function.body.loc;
12337 // ([structName] *) [exp]
12338 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12339 initializer = MkInitializerAssignment(
12340 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12342 // [structName] * [pointerName] = [initializer];
12343 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12346 Context prevContext = curContext;
12347 curContext = function.body.compound.context;
12349 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12350 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12352 curContext = prevContext;
12356 decl.symbol = null;
12358 if(!function.body.compound.declarations)
12359 function.body.compound.declarations = MkList();
12360 function.body.compound.declarations->Insert(null, decl);
12366 // Loop through the function and replace undeclared identifiers
12367 // which are a member of the class (methods, properties or data)
12368 // by "this.[member]"
12375 FreeSpecifier(id._class);
12378 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12380 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12381 id = GetDeclId(initDecl.declarator);
12383 FreeSpecifier(id._class);
12388 topContext = function.body.compound.context;
12390 FunctionDefinition oldFunction = curFunction;
12391 curFunction = function;
12393 ProcessStatement(function.body);
12395 // If this is a property set and no firewatchers has been done yet, add one here
12396 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12398 Statement prevCompound = curCompound;
12399 Context prevContext = curContext;
12401 Statement fireWatchers = MkFireWatchersStmt(null, null);
12402 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12403 ListAdd(function.body.compound.statements, fireWatchers);
12405 curCompound = function.body;
12406 curContext = function.body.compound.context;
12408 ProcessStatement(fireWatchers);
12410 curContext = prevContext;
12411 curCompound = prevCompound;
12415 curFunction = oldFunction;
12418 if(function.declarator)
12420 ProcessDeclarator(function.declarator);
12423 topContext = oldTopContext;
12424 thisClass = oldThisClass;
12427 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12428 static void ProcessClass(OldList definitions, Symbol symbol)
12431 External external = curExternal;
12432 Class regClass = symbol ? symbol.registered : null;
12434 // Process all functions
12435 for(def = definitions.first; def; def = def.next)
12437 if(def.type == functionClassDef)
12439 if(def.function.declarator)
12440 curExternal = def.function.declarator.symbol.pointerExternal;
12442 curExternal = external;
12444 ProcessFunction((FunctionDefinition)def.function);
12446 else if(def.type == declarationClassDef)
12448 if(def.decl.type == instDeclaration)
12450 thisClass = regClass;
12451 ProcessInstantiationType(def.decl.inst);
12457 Class backThisClass = thisClass;
12458 if(regClass) thisClass = regClass;
12459 ProcessDeclaration(def.decl);
12460 thisClass = backThisClass;
12463 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12465 MemberInit defProperty;
12467 // Add this to the context
12468 Symbol thisSymbol = Symbol
12470 string = CopyString("this");
12471 type = regClass ? MkClassType(regClass.fullName) : null;
12473 globalContext.symbols.Add((BTNode)thisSymbol);
12475 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12477 thisClass = regClass;
12478 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12482 globalContext.symbols.Remove((BTNode)thisSymbol);
12483 FreeSymbol(thisSymbol);
12485 else if(def.type == propertyClassDef && def.propertyDef)
12487 PropertyDef prop = def.propertyDef;
12489 // Add this to the context
12491 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12492 globalContext.symbols.Add(thisSymbol);
12495 thisClass = regClass;
12502 string = CopyString("this");
12503 type = MkClassType(regClass.fullName);
12505 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12508 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12509 ProcessStatement(prop.setStmt);
12517 string = CopyString("this");
12518 type = MkClassType(regClass.fullName);
12520 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12523 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12524 ProcessStatement(prop.getStmt);
12532 string = CopyString("this");
12533 type = MkClassType(regClass.fullName);
12535 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12538 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12539 ProcessStatement(prop.issetStmt);
12545 globalContext.symbols.Remove(thisSymbol);
12546 FreeSymbol(thisSymbol);
12549 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12551 PropertyWatch propertyWatch = def.propertyWatch;
12553 thisClass = regClass;
12554 if(propertyWatch.compound)
12558 string = CopyString("this");
12559 type = regClass ? MkClassType(regClass.fullName) : null;
12562 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12564 curExternal = null;
12565 ProcessStatement(propertyWatch.compound);
12572 void DeclareFunctionUtil(String s)
12574 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12579 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12580 strcpy(name, "__ecereFunction_");
12581 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12582 DeclareFunction(function, name);
12586 void ComputeDataTypes()
12590 External after = null;
12592 currentClass = null;
12594 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12596 for(external = ast->first; external; external = external.next)
12598 if(external.type == declarationExternal)
12600 Declaration decl = external.declaration;
12603 OldList * decls = decl.declarators;
12606 InitDeclarator initDecl = decls->first;
12609 Declarator declarator = initDecl.declarator;
12610 if(declarator && declarator.type == identifierDeclarator)
12612 Identifier id = declarator.identifier;
12613 if(id && id.string)
12615 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12617 external.symbol.id = -1001, external.symbol.idCode = -1001;
12628 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12629 ast->Insert(after, temp);
12630 curExternal = temp;
12632 DeclareFunctionUtil("eSystem_New");
12633 DeclareFunctionUtil("eSystem_New0");
12634 DeclareFunctionUtil("eSystem_Renew");
12635 DeclareFunctionUtil("eSystem_Renew0");
12636 DeclareFunctionUtil("eSystem_Delete");
12637 DeclareFunctionUtil("eClass_GetProperty");
12638 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12640 DeclareStruct("ecere::com::Class", false);
12641 DeclareStruct("ecere::com::Instance", false);
12642 DeclareStruct("ecere::com::Property", false);
12643 DeclareStruct("ecere::com::DataMember", false);
12644 DeclareStruct("ecere::com::Method", false);
12645 DeclareStruct("ecere::com::SerialBuffer", false);
12646 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12650 for(external = ast->first; external; external = external.next)
12652 afterExternal = curExternal = external;
12653 if(external.type == functionExternal)
12655 currentClass = external.function._class;
12656 ProcessFunction(external.function);
12658 // There shouldn't be any _class member access here anyways...
12659 else if(external.type == declarationExternal)
12661 currentClass = null;
12662 ProcessDeclaration(external.declaration);
12664 else if(external.type == classExternal)
12666 ClassDefinition _class = external._class;
12667 currentClass = external.symbol.registered;
12668 if(_class.definitions)
12670 ProcessClass(_class.definitions, _class.symbol);
12674 // Free class data...
12675 ast->Remove(external);
12679 else if(external.type == nameSpaceExternal)
12681 thisNameSpace = external.id.string;
12684 currentClass = null;
12685 thisNameSpace = null;
12687 delete temp.symbol;