3 // UNTIL IMPLEMENTED IN GRAMMAR
4 #define ACCESS_CLASSDATA(_class, baseClass) \
5 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
7 #define YYLTYPE Location
11 extern int returnCode;
12 extern Expression parsedExpression;
14 public void SetYydebug(bool b) { yydebug = b; }
19 // TODO: Reset this to 0 on reinitialization
22 int expression_yyparse();
23 static Statement curCompound;
24 External curExternal, afterExternal;
25 static Type curSwitchType;
26 static Class currentClass;
28 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
29 static char * thisNameSpace;
30 /*static */Class containerClass;
31 bool thisClassParams = true;
33 uint internalValueCounter;
36 Time findSymbolTotalTime;
39 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
40 /*static */public void PrintExpression(Expression exp, char * string)
46 bool backOutputLineNumbers = outputLineNumbers;
47 outputLineNumbers = false;
50 OutputExpression(exp, f);
52 count = strlen(string);
53 count += f.Read(string + count, 1, 1023);
57 outputLineNumbers = backOutputLineNumbers;
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 && type1.isLong == type2.isLong)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || 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)
205 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
207 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
208 if(result > MAXINT || result < MININT)
210 return CopyString(temp);
213 public char * PrintUInt(uint64 result)
216 if(result > MAXDWORD)
217 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
218 else if(result > MAXINT)
219 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
221 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
222 return CopyString(temp);
225 public char * PrintInt64(int64 result)
228 if(result > MAXINT || result < MININT)
229 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
231 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
232 return CopyString(temp);
235 public char * PrintUInt64(uint64 result)
238 if(result > MAXDWORD)
239 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
240 else if(result > MAXINT)
241 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
243 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
244 return CopyString(temp);
247 public char * PrintHexUInt(uint64 result)
250 if(result > MAXDWORD)
251 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
253 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
254 if(result > MAXDWORD)
256 return CopyString(temp);
259 public char * PrintHexUInt64(uint64 result)
262 if(result > MAXDWORD)
263 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
265 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
266 return CopyString(temp);
269 public char * PrintShort(short result)
272 sprintf(temp, "%d", (unsigned short)result);
273 return CopyString(temp);
276 public char * PrintUShort(unsigned short result)
280 sprintf(temp, "0x%X", (int)result);
282 sprintf(temp, "%d", (int)result);
283 return CopyString(temp);
286 public char * PrintChar(char result)
289 if(result > 0 && isprint(result))
290 sprintf(temp, "'%c'", result);
292 sprintf(temp, "%d", (int)result);
294 //sprintf(temp, "%#X", result);
295 sprintf(temp, "0x%X", (unsigned char)result);
296 return CopyString(temp);
299 public char * PrintUChar(unsigned char result)
302 sprintf(temp, "0x%X", result);
303 return CopyString(temp);
306 public char * PrintFloat(float result)
312 strcpy(temp, "-inf");
316 else if(result.isNan)
319 strcpy(temp, "-nan");
324 sprintf(temp, "%.16ff", result);
325 return CopyString(temp);
328 public char * PrintDouble(double result)
334 strcpy(temp, "-inf");
338 else if(result.isNan)
341 strcpy(temp, "-nan");
346 sprintf(temp, "%.16f", result);
347 return CopyString(temp);
350 ////////////////////////////////////////////////////////////////////////
351 ////////////////////////////////////////////////////////////////////////
353 //public Operand GetOperand(Expression exp);
355 #define GETVALUE(name, t) \
356 public bool GetOp##name(Operand op2, t * value2) \
358 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
359 else if(op2.kind == intType) *value2 = (t) op2.ui; \
360 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
361 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
362 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
363 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
364 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
365 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
366 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
367 else if(op2.kind == shortType) *value2 = (t) op2.us; \
368 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
369 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
370 else if(op2.kind == floatType) *value2 = (t) op2.f; \
371 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
372 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
377 public bool Get##name(Expression exp, t * value2) \
379 Operand op2 = GetOperand(exp); \
380 return GetOp##name(op2, value2); \
383 // To help the debugger currently not preprocessing...
386 GETVALUE(Int, HELP(int));
387 GETVALUE(UInt, HELP(unsigned int));
388 GETVALUE(Int64, HELP(int64));
389 GETVALUE(UInt64, HELP(uint64));
390 GETVALUE(IntPtr, HELP(intptr));
391 GETVALUE(UIntPtr, HELP(uintptr));
392 GETVALUE(IntSize, HELP(intsize));
393 GETVALUE(UIntSize, HELP(uintsize));
394 GETVALUE(Short, HELP(short));
395 GETVALUE(UShort, HELP(unsigned short));
396 GETVALUE(Char, HELP(char));
397 GETVALUE(UChar, HELP(unsigned char));
398 GETVALUE(Float, HELP(float));
399 GETVALUE(Double, HELP(double));
401 void ComputeExpression(Expression exp);
403 void ComputeClassMembers(Class _class, bool isMember)
405 DataMember member = isMember ? (DataMember) _class : null;
406 Context context = isMember ? null : SetupTemplatesContext(_class);
407 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
408 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
410 int unionMemberOffset = 0;
414 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
415 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
420 member.memberOffset = 0;
421 if(targetBits < sizeof(void *) * 8)
422 member.structAlignment = 0;
424 else if(targetBits < sizeof(void *) * 8)
425 _class.structAlignment = 0;
427 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
428 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
429 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
431 if(!member && _class.destructionWatchOffset)
432 _class.memberOffset += sizeof(OldList);
434 // To avoid reentrancy...
435 //_class.structSize = -1;
438 DataMember dataMember;
439 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
441 if(!dataMember.isProperty)
443 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
445 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
446 /*if(!dataMember.dataType)
447 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
455 DataMember dataMember;
456 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
458 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
460 if(!isMember && _class.type == bitClass && dataMember.dataType)
462 BitMember bitMember = (BitMember) dataMember;
466 ComputeTypeSize(dataMember.dataType);
468 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
469 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
471 _class.memberOffset = bitMember.pos + bitMember.size;
472 for(d = 0; d<bitMember.size; d++)
478 bitMember.mask = mask << bitMember.pos;
480 else if(dataMember.type == normalMember && dataMember.dataType)
485 // Prevent infinite recursion
486 if(dataMember.dataType.kind != classType ||
487 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
488 _class.type != structClass)))
489 ComputeTypeSize(dataMember.dataType);
491 if(dataMember.dataType.bitFieldCount)
493 bitFields += dataMember.dataType.bitFieldCount;
500 int size = (bitFields + 7) / 8;
504 // TESTING THIS PADDING CODE
507 member.structAlignment = Max(member.structAlignment, alignment);
509 if(member.memberOffset % alignment)
510 member.memberOffset += alignment - (member.memberOffset % alignment);
513 dataMember.offset = member.memberOffset;
514 if(member.type == unionMember)
515 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
518 member.memberOffset += size;
523 // TESTING THIS PADDING CODE
526 _class.structAlignment = Max(_class.structAlignment, alignment);
528 if(_class.memberOffset % alignment)
529 _class.memberOffset += alignment - (_class.memberOffset % alignment);
532 dataMember.offset = _class.memberOffset;
533 _class.memberOffset += size;
537 size = dataMember.dataType.size;
538 alignment = dataMember.dataType.alignment;
543 // TESTING THIS PADDING CODE
546 member.structAlignment = Max(member.structAlignment, alignment);
548 if(member.memberOffset % alignment)
549 member.memberOffset += alignment - (member.memberOffset % alignment);
552 dataMember.offset = member.memberOffset;
553 if(member.type == unionMember)
554 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
557 member.memberOffset += size;
562 // TESTING THIS PADDING CODE
565 _class.structAlignment = Max(_class.structAlignment, alignment);
567 if(_class.memberOffset % alignment)
568 _class.memberOffset += alignment - (_class.memberOffset % alignment);
571 dataMember.offset = _class.memberOffset;
572 _class.memberOffset += size;
579 ComputeClassMembers((Class)dataMember, true);
580 alignment = dataMember.structAlignment;
586 if(member.memberOffset % alignment)
587 member.memberOffset += alignment - (member.memberOffset % alignment);
589 member.structAlignment = Max(member.structAlignment, alignment);
591 dataMember.offset = member.memberOffset;
592 if(member.type == unionMember)
593 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
595 member.memberOffset += dataMember.memberOffset;
601 if(_class.memberOffset % alignment)
602 _class.memberOffset += alignment - (_class.memberOffset % alignment);
603 _class.structAlignment = Max(_class.structAlignment, alignment);
605 dataMember.offset = _class.memberOffset;
606 _class.memberOffset += dataMember.memberOffset;
614 int size = (bitFields + 7) / 8;
618 // TESTING THIS PADDING CODE
621 member.structAlignment = Max(member.structAlignment, alignment);
623 if(member.memberOffset % alignment)
624 member.memberOffset += alignment - (member.memberOffset % alignment);
627 if(member.type == unionMember)
628 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
631 member.memberOffset += size;
636 // TESTING THIS PADDING CODE
639 _class.structAlignment = Max(_class.structAlignment, alignment);
641 if(_class.memberOffset % alignment)
642 _class.memberOffset += alignment - (_class.memberOffset % alignment);
644 _class.memberOffset += size;
649 if(member && member.type == unionMember)
651 member.memberOffset = unionMemberOffset;
656 /*if(_class.type == structClass)
657 _class.size = _class.memberOffset;
661 if(_class.type != bitClass)
664 if(_class.structAlignment)
666 if(_class.memberOffset % _class.structAlignment)
667 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
669 _class.structSize = (_class.base ? (_class.base.templateClass ?
670 (_class.base.type == noHeadClass ? _class.base.templateClass.memberOffset : _class.base.templateClass.structSize) :
671 (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize) ) : 0) + _class.memberOffset + extra;
675 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
677 if(prop.isProperty && prop.isWatchable)
679 prop.watcherOffset = _class.structSize;
680 _class.structSize += sizeof(OldList);
688 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
690 Class deriv = derivative.data;
692 if(deriv.computeSize)
694 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
695 deriv.offset = /*_class.offset + */(_class.type == noHeadClass ? _class.memberOffset : _class.structSize);
696 deriv.memberOffset = 0;
697 // ----------------------
699 deriv.structSize = deriv.offset;
701 ComputeClassMembers(deriv, false);
709 FinishTemplatesContext(context);
712 public void ComputeModuleClasses(Module module)
717 for(subModule = module.modules.first; subModule; subModule = subModule.next)
718 ComputeModuleClasses(subModule.data);
719 for(_class = module.classes.first; _class; _class = _class.next)
720 ComputeClassMembers(_class, false);
724 public int ComputeTypeSize(Type type)
726 uint size = type ? type.size : 0;
727 if(!size && type && !type.computing)
729 type.computing = true;
732 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
733 case charType: type.alignment = size = sizeof(char); break;
734 case intType: type.alignment = size = sizeof(int); break;
735 case int64Type: type.alignment = size = sizeof(int64); break;
736 case intPtrType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
737 case intSizeType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
738 case longType: type.alignment = size = sizeof(long); break;
739 case shortType: type.alignment = size = sizeof(short); break;
740 case floatType: type.alignment = size = sizeof(float); break;
741 case doubleType: type.alignment = size = sizeof(double); break;
744 Class _class = type._class ? type._class.registered : null;
746 if(_class && _class.type == structClass)
748 // Ensure all members are properly registered
749 ComputeClassMembers(_class, false);
750 type.alignment = _class.structAlignment;
751 type.pointerAlignment = (bool)_class.pointerAlignment;
752 size = _class.structSize;
753 if(type.alignment && size % type.alignment)
754 size += type.alignment - (size % type.alignment);
757 else if(_class && (_class.type == unitClass ||
758 _class.type == enumClass ||
759 _class.type == bitClass))
762 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
763 size = type.alignment = ComputeTypeSize(_class.dataType);
767 size = type.alignment = targetBits / 8; // sizeof(Instance *);
768 type.pointerAlignment = true;
772 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */ type.pointerAlignment = true; break;
774 if(type.arraySizeExp)
776 ProcessExpressionType(type.arraySizeExp);
777 ComputeExpression(type.arraySizeExp);
778 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
779 type.arraySizeExp.expType.kind != shortType &&
780 type.arraySizeExp.expType.kind != charType &&
781 type.arraySizeExp.expType.kind != longType &&
782 type.arraySizeExp.expType.kind != int64Type &&
783 type.arraySizeExp.expType.kind != intSizeType &&
784 type.arraySizeExp.expType.kind != intPtrType &&
785 type.arraySizeExp.expType.kind != enumType &&
786 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
788 Location oldLoc = yylloc;
789 // bool isConstant = type.arraySizeExp.isConstant;
790 char expression[10240];
791 expression[0] = '\0';
792 type.arraySizeExp.expType = null;
793 yylloc = type.arraySizeExp.loc;
795 PrintExpression(type.arraySizeExp, expression);
796 Compiler_Error($"Array size not constant int (%s)\n", expression);
799 GetInt(type.arraySizeExp, &type.arraySize);
801 else if(type.enumClass)
803 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
805 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
812 // Unimplemented auto size
816 size = ComputeTypeSize(type.type) * type.arraySize;
819 type.alignment = type.type.alignment;
820 type.pointerAlignment = type.type.pointerAlignment;
826 if(!type.members.first && type.enumName)
828 Symbol symbol = FindStruct(curContext, type.enumName);
829 if(symbol && symbol.type)
831 ComputeTypeSize(symbol.type);
832 size = symbol.type.size;
838 for(member = type.members.first; member; member = member.next)
840 uint addSize = ComputeTypeSize(member);
842 member.offset = size;
843 if(member.alignment && size % member.alignment)
844 member.offset += member.alignment - (size % member.alignment);
845 size = member.offset;
847 if(member.pointerAlignment && type.size <= 4)
848 type.pointerAlignment = true;
849 else if(!member.pointerAlignment && member.alignment >= 8)
850 type.pointerAlignment = false;
852 type.alignment = Max(type.alignment, member.alignment);
855 if(type.alignment && size % type.alignment)
856 size += type.alignment - (size % type.alignment);
862 if(!type.members.first && type.enumName)
864 Symbol symbol = FindStruct(curContext, type.enumName);
865 if(symbol && symbol.type)
867 ComputeTypeSize(symbol.type);
868 size = symbol.type.size;
869 type.alignment = symbol.type.alignment;
875 for(member = type.members.first; member; member = member.next)
877 uint addSize = ComputeTypeSize(member);
879 member.offset = size;
880 if(member.alignment && size % member.alignment)
881 member.offset += member.alignment - (size % member.alignment);
882 size = member.offset;
884 if(member.pointerAlignment && type.size <= 4)
885 type.pointerAlignment = true;
886 else if(!member.pointerAlignment && member.alignment >= 8)
887 type.pointerAlignment = false;
889 type.alignment = Max(type.alignment, member.alignment);
891 size = Max(size, addSize);
893 if(type.alignment && size % type.alignment)
894 size += type.alignment - (size % type.alignment);
900 TemplateParameter param = type.templateParameter;
901 Type baseType = ProcessTemplateParameterType(param);
904 size = ComputeTypeSize(baseType);
905 type.alignment = baseType.alignment;
906 type.pointerAlignment = baseType.pointerAlignment;
909 type.alignment = size = sizeof(uint64);
914 type.alignment = size = sizeof(enum { test });
919 type.alignment = size = targetBits / 8; //sizeof(void *);
920 type.pointerAlignment = true;
925 type.computing = false;
931 /*static */int AddMembers(External neededBy, OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
933 // This function is in need of a major review when implementing private members etc.
934 DataMember topMember = isMember ? (DataMember) _class : null;
941 Context context = isMember ? null : SetupTemplatesContext(_class);
943 *addedPadding = false;
945 if(!isMember && _class.base)
947 maxSize = _class.structSize;
948 //if(_class.base.type != systemClass) // Commented out with new Instance _class
950 // DANGER: Testing this noHeadClass here...
951 if(_class.type == structClass || _class.type == noHeadClass)
952 /*totalSize = */AddMembers(neededBy, declarations, _class.base, false, &totalSize, topClass, null);
955 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
956 if(maxSize > baseSize)
964 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
966 if(!member.isProperty)
972 if(member.dataTypeString)
974 OldList * specs = MkList(), * decls = MkList();
977 decl = SpecDeclFromString(member.dataTypeString, specs,
978 MkDeclaratorIdentifier(MkIdentifier(member.name)));
979 ListAdd(decls, MkStructDeclarator(decl, null));
980 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
983 member.dataType = ProcessType(specs, decl);
985 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
988 Type type = ProcessType(specs, decl);
989 DeclareType(neededBy, member.dataType, true, false);
993 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
994 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
995 DeclareStruct(member.dataType._class.string, false);
998 ComputeTypeSize(member.dataType);
999 size = member.dataType.size;
1000 alignment = member.dataType.alignment;
1004 if(totalSize % alignment)
1005 totalSize += alignment - (totalSize % alignment);
1014 OldList * specs = MkList(), * list = MkList();
1016 sprintf(id, "__anon%d", anonID++);
1019 AddMembers(neededBy, list, (Class)member, true, &size, topClass, null);
1021 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1022 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1023 alignment = member.structAlignment;
1027 if(totalSize % alignment)
1028 totalSize += alignment - (totalSize % alignment);
1038 if(topMember && topMember.type == unionMember)
1039 *retSize = Max(*retSize, totalSize);
1041 *retSize += totalSize;
1043 else if(totalSize < maxSize && _class.type != systemClass)
1045 int autoPadding = 0;
1046 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1047 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1048 if(totalSize + autoPadding < maxSize)
1050 char sizeString[50];
1051 sprintf(sizeString, "%d", maxSize - totalSize);
1052 ListAdd(declarations,
1053 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1054 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1056 *addedPadding = true;
1060 FinishTemplatesContext(context);
1061 return topMember ? topMember.memberID : _class.memberID;
1064 static int DeclareMembers(External neededBy, Class _class, bool isMember)
1066 DataMember topMember = isMember ? (DataMember) _class : null;
1068 Context context = isMember ? null : SetupTemplatesContext(_class);
1070 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1071 DeclareMembers(neededBy, _class.base, false);
1073 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1075 if(!member.isProperty)
1081 if(!member.dataType && member.dataTypeString)
1082 member.dataType = ProcessTypeString(member.dataTypeString, false);
1084 DeclareType(neededBy, member.dataType, true, false);
1090 DeclareMembers(neededBy, (Class)member, true);
1097 FinishTemplatesContext(context);
1099 return topMember ? topMember.memberID : _class.memberID;
1102 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1106 for(def = definitions->first; def; def = def.next)
1108 if(def.type == declarationClassDef)
1110 Declaration decl = def.decl;
1111 if(decl && decl.specifiers)
1114 bool isStruct = false;
1115 for(spec = decl.specifiers->first; spec; spec = spec.next)
1117 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1119 if(spec.definitions)
1120 IdentifyAnonStructs(spec.definitions);
1126 Declarator d = null;
1127 if(decl.declarators)
1129 for(d = decl.declarators->first; d; d = d.next)
1131 Identifier idDecl = GetDeclId(d);
1139 sprintf(id, "__anon%d", anonID++);
1140 if(!decl.declarators)
1141 decl.declarators = MkList();
1142 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1150 External DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference)
1152 return _DeclareStruct(neededBy, name, skipNoHead, needDereference, false);
1155 External _DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference, bool fwdDecl)
1157 External external = null;
1158 Symbol classSym = FindClass(name);
1159 OldList * curDeclarations = null;
1161 if(!inCompiler || !classSym) return null;
1163 // We don't need any declaration for bit classes...
1164 if(classSym.registered &&
1165 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1168 if(!classSym.registered || (classSym.registered.type == normalClass && classSym.registered.structSize && classSym.registered.base && classSym.registered.base.base))
1169 _DeclareStruct(neededBy, "ecere::com::Instance", false, true, fwdDecl);
1171 external = classSym.structExternal;
1173 if(external && external.declaration)
1176 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1177 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1179 curDeclarations = spec.definitions;
1184 if(classSym.registered && !classSym.declaring && classSym.imported && (!classSym.declaredStructSym || (classSym.registered.type == noHeadClass && !skipNoHead && external && !curDeclarations)))
1186 OldList * specifiers, * declarators;
1187 OldList * declarations = null;
1188 char structName[1024];
1189 bool addedPadding = false;
1190 Specifier curSpec = null;
1192 classSym.declaring++;
1194 if(strchr(classSym.string, '<'))
1196 if(classSym.registered.templateClass)
1197 external = _DeclareStruct(neededBy, classSym.registered.templateClass.fullName, skipNoHead, needDereference, fwdDecl);
1198 classSym.declaring--;
1203 FullClassNameCat(structName, name, false);
1205 classSym.declaredStructSym = true;
1206 if(!external || (classSym.registered.type == noHeadClass && !skipNoHead && !curDeclarations))
1211 external = MkExternalDeclaration(null);
1212 classSym.structExternal = external;
1213 external.symbol = classSym;
1220 declarations = MkList();
1221 AddMembers(external, declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1224 if(external.declaration)
1227 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1228 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1231 curDeclarations = spec.definitions;
1236 if(declarations && (!declarations->count || (declarations->count == 1 && addedPadding)))
1238 FreeList(declarations, FreeClassDef);
1239 declarations = null;
1242 if(classSym.registered.type != noHeadClass && !declarations)
1244 FreeExternal(external);
1246 classSym.structExternal = null;
1251 curSpec.definitions = declarations;
1254 specifiers = MkList();
1255 declarators = MkList();
1256 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1257 external.declaration = MkDeclaration(specifiers, declarators);
1263 classSym.declaring--;
1265 else if(!classSym.declaredStructSym && classSym.structExternal)
1267 classSym.declaredStructSym = true;
1269 if(classSym.registered)
1270 DeclareMembers(classSym.structExternal, classSym.registered, false);
1272 if(classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1275 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1277 if(spec.definitions)
1278 IdentifyAnonStructs(spec.definitions);
1282 if(inCompiler && neededBy && (external || !classSym.imported))
1286 classSym.structExternal = external = MkExternalDeclaration(null);
1287 external.symbol = classSym;
1290 if(reachedPass15 && !external.declaration && classSym.registered && classSym.registered.type == noHeadClass)
1292 // Declare nohead classes without definitions here (e.g. IteratorPointer)
1293 char structName[1024];
1294 OldList * specifiers, * declarators;
1296 FullClassNameCat(structName, name, false);
1297 specifiers = MkList();
1298 declarators = MkList();
1299 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), null));
1300 external.declaration = MkDeclaration(specifiers, declarators);
1304 External e = external.fwdDecl ? external.fwdDecl : external;
1305 if(e.incoming.count)
1306 neededBy.CreateUniqueEdge(e, !needDereference && !external.fwdDecl);
1309 neededBy.CreateUniqueEdge(external, !needDereference);
1314 void DeclareProperty(External neededBy, Property prop, char * setName, char * getName)
1316 Symbol symbol = prop.symbol;
1317 bool imported = false;
1318 bool dllImport = false;
1319 External structExternal = null;
1320 External instExternal = null;
1322 strcpy(setName, "__ecereProp_");
1323 FullClassNameCat(setName, prop._class.fullName, false);
1324 strcat(setName, "_Set_");
1325 FullClassNameCat(setName, prop.name, true);
1327 strcpy(getName, "__ecereProp_");
1328 FullClassNameCat(getName, prop._class.fullName, false);
1329 strcat(getName, "_Get_");
1330 FullClassNameCat(getName, prop.name, true);
1332 if(!symbol || symbol._import)
1338 if(!prop._class.symbol)
1339 prop._class.symbol = FindClass(prop._class.fullName);
1340 classSym = prop._class.symbol;
1341 if(classSym && !classSym._import)
1343 ModuleImport module;
1345 if(prop._class.module)
1346 module = FindModule(prop._class.module);
1348 module = mainModule;
1350 classSym._import = ClassImport
1352 name = CopyString(prop._class.fullName);
1353 isRemote = prop._class.isRemote;
1355 module.classes.Add(classSym._import);
1357 symbol = prop.symbol = Symbol { };
1358 symbol._import = (ClassImport)PropertyImport
1360 name = CopyString(prop.name);
1361 isVirtual = false; //prop.isVirtual;
1362 hasSet = prop.Set ? true : false;
1363 hasGet = prop.Get ? true : false;
1366 classSym._import.properties.Add(symbol._import);
1369 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1370 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1371 prop._class.module.importType != staticImport)
1377 Context context = SetupTemplatesContext(prop._class);
1378 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1379 FinishTemplatesContext(context);
1382 if((prop.Get && !symbol.externalGet) || (prop.Set && !symbol.externalSet))
1384 if(prop._class.type == normalClass && prop._class.structSize)
1385 instExternal = DeclareStruct(null, "ecere::com::Instance", false, true);
1386 structExternal = DeclareStruct(null, prop._class.fullName, prop._class.type != structClass /*true*/, false);
1390 if(prop.Get && !symbol.externalGet)
1393 OldList * specifiers, * declarators;
1396 Specifier spec = null;
1398 Declarator typeDecl;
1399 bool simple = false;
1402 specifiers = MkList();
1403 declarators = MkList();
1406 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1407 MkDeclaratorIdentifier(MkIdentifier("this"))));
1409 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1412 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1415 Context context = SetupTemplatesContext(prop._class);
1416 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1417 FinishTemplatesContext(context);
1420 // Make sure the simple _class's type is declared
1421 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1422 for(spec = specifiers->first; spec; spec = spec.next)
1424 if(spec.type == nameSpecifier)
1426 Symbol classSym = spec.symbol;
1429 symbol._class = classSym.registered;
1430 if(classSym.registered && classSym.registered.type == structClass)
1438 d = PlugDeclarator(typeDecl, d);
1441 ListAdd(params, MkTypeName(specifiers,
1442 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1443 specifiers = MkList();
1446 d = MkDeclaratorFunction(d, params);
1450 specifiers->Insert(null, MkSpecifier(EXTERN));
1451 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1452 specifiers->Insert(null, MkSpecifier(STATIC));
1454 ListAdd(specifiers, MkSpecifier(VOID));
1456 ListAdd(declarators, MkInitDeclarator(d, null));
1458 decl = MkDeclaration(specifiers, declarators);
1460 external = MkExternalDeclaration(decl);
1463 external.CreateEdge(structExternal, false);
1465 external.CreateEdge(instExternal, false);
1468 DeclareStruct(external, spec.name, false, needReference);
1471 external.symbol = symbol;
1472 symbol.externalGet = external;
1474 ReplaceThisClassSpecifiers(specifiers, prop._class);
1477 FreeDeclarator(typeDecl);
1481 if(prop.Set && !symbol.externalSet)
1484 OldList * specifiers, * declarators;
1487 Specifier spec = null;
1489 Declarator typeDecl;
1492 declarators = MkList();
1495 if(!prop.conversion || prop._class.type == structClass)
1497 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1498 MkDeclaratorIdentifier(MkIdentifier("this"))));
1501 specifiers = MkList();
1504 Context context = SetupTemplatesContext(prop._class);
1505 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1506 MkDeclaratorIdentifier(MkIdentifier("value")));
1507 FinishTemplatesContext(context);
1509 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1510 specifiers->Insert(null, MkSpecifier(CONST));
1512 ListAdd(params, MkTypeName(specifiers, d));
1514 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1516 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1517 d = MkDeclaratorFunction(d, params);
1519 // Make sure the simple _class's type is declared
1520 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1521 for(spec = specifiers->first; spec; spec = spec.next)
1523 if(spec.type == nameSpecifier)
1525 Symbol classSym = spec.symbol;
1527 symbol._class = classSym.registered;
1532 ListAdd(declarators, MkInitDeclarator(d, null));
1534 specifiers = MkList();
1536 specifiers->Insert(null, MkSpecifier(EXTERN));
1537 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1538 specifiers->Insert(null, MkSpecifier(STATIC));
1540 if(!prop.conversion || prop._class.type == structClass)
1541 ListAdd(specifiers, MkSpecifier(VOID));
1543 ListAdd(specifiers, MkSpecifierName(prop._class.fullName));
1545 decl = MkDeclaration(specifiers, declarators);
1547 external = MkExternalDeclaration(decl);
1550 external.CreateEdge(structExternal, false);
1552 external.CreateEdge(instExternal, false);
1555 DeclareStruct(external, spec.name, false, needReference);
1558 external.symbol = symbol;
1559 symbol.externalSet = external;
1561 ReplaceThisClassSpecifiers(specifiers, prop._class);
1564 // Property (for Watchers)
1565 if(!symbol.externalPtr)
1569 OldList * specifiers = MkList();
1570 char propName[1024];
1573 specifiers->Insert(null, MkSpecifier(EXTERN));
1576 specifiers->Insert(null, MkSpecifier(STATIC));
1577 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1580 ListAdd(specifiers, MkSpecifierName("Property"));
1582 strcpy(propName, "__ecereProp_");
1583 FullClassNameCat(propName, prop._class.fullName, false);
1584 strcat(propName, "_");
1585 FullClassNameCat(propName, prop.name, true);
1588 OldList * list = MkList();
1589 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1593 strcpy(propName, "__ecerePropM_");
1594 FullClassNameCat(propName, prop._class.fullName, false);
1595 strcat(propName, "_");
1596 FullClassNameCat(propName, prop.name, true);
1598 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1600 decl = MkDeclaration(specifiers, list);
1603 external = MkExternalDeclaration(decl);
1604 ast->Insert(curExternal.prev, external);
1605 external.symbol = symbol;
1606 symbol.externalPtr = external;
1609 if(inCompiler && neededBy)
1611 // Could improve this to create edge on only what is needed...
1612 if(symbol.externalPtr)
1613 neededBy.CreateUniqueEdge(symbol.externalPtr, false);
1615 if(symbol.externalGet)
1616 neededBy.CreateUniqueEdge(symbol.externalGet, symbol.externalGet.type == functionExternal);
1618 if(symbol.externalSet)
1619 neededBy.CreateUniqueEdge(symbol.externalSet, symbol.externalSet.type == functionExternal);
1625 // ***************** EXPRESSION PROCESSING ***************************
1626 public Type Dereference(Type source)
1631 if(source.kind == pointerType || source.kind == arrayType)
1634 source.type.refCount++;
1636 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1644 // Support dereferencing of no head classes for now...
1645 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1651 Compiler_Error($"cannot dereference type\n");
1656 static Type Reference(Type source)
1672 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1674 Identifier ident = member.identifiers ? member.identifiers->first : null;
1676 DataMember dataMember = null;
1677 Method method = null;
1678 bool freeType = false;
1680 yylloc = member.loc;
1686 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1690 dataMember = *curMember;
1696 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1697 DataMember _subMemberStack[256];
1698 int _subMemberStackPos = 0;
1700 // FILL MEMBER STACK
1702 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1705 dataMember = thisMember;
1706 if(curMember && thisMember.memberAccess == publicAccess)
1708 *curMember = thisMember;
1709 *curClass = thisMember._class;
1710 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1711 *subMemberStackPos = _subMemberStackPos;
1718 method = eClass_FindMethod(_class, ident.string, privateModule);
1719 if(method && method.type == virtualMethod)
1731 if(!dataMember.dataType && dataMember.dataTypeString)
1733 //Context context = SetupTemplatesContext(dataMember._class);
1734 Context context = SetupTemplatesContext(_class);
1735 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1736 FinishTemplatesContext(context);
1738 type = dataMember.dataType;
1742 // This is for destination type...
1743 if(!method.dataType)
1744 ProcessMethodType(method);
1745 //DeclareMethod(method);
1746 // method.dataType = ((Symbol)method.symbol)->type;
1747 type = method.dataType;
1750 if(ident && ident.next)
1752 for(ident = ident.next; ident && type; ident = ident.next)
1754 if(type.kind == classType)
1756 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1758 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1760 type = dataMember.dataType;
1762 else if(type.kind == structType || type.kind == unionType)
1765 for(memberType = type.members.first; memberType; memberType = memberType.next)
1767 if(!strcmp(memberType.name, ident.string))
1777 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1778 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1781 ClassTemplateParameter curParam = null;
1783 for(sClass = _class; sClass; sClass = sClass.base)
1786 if(sClass.templateClass) sClass = sClass.templateClass;
1787 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1789 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1791 for(sClass = sClass.base; sClass; sClass = sClass.base)
1793 if(sClass.templateClass) sClass = sClass.templateClass;
1794 id += sClass.templateParams.count;
1805 ClassTemplateArgument arg = _class.templateArgs[id];
1806 if(arg.dataTypeString)
1808 bool constant = type.constant;
1810 type = ProcessTypeString(arg.dataTypeString, false);
1811 if(type.kind == classType && constant) type.constant = true;
1812 else if(type.kind == pointerType)
1815 while(t.kind == pointerType) t = t.type;
1816 if(constant) t.constant = constant;
1819 if(type && _class.templateClass)
1820 type.passAsTemplate = true;
1826 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1827 exp.destType.refCount++;
1833 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1835 Class expClass = type._class.registered;
1836 Class cClass = null;
1840 char templateString[1024];
1841 ClassTemplateParameter param;
1842 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1843 for(cClass = expClass; cClass; cClass = cClass.base)
1846 if(cClass.templateClass) cClass = cClass.templateClass;
1847 for(param = cClass.templateParams.first; param; param = param.next)
1851 ClassTemplateArgument arg;
1852 for(sClass = cClass.base; sClass; sClass = sClass.base)
1854 if(sClass.templateClass) sClass = sClass.templateClass;
1855 id += sClass.templateParams.count;
1857 arg = expClass.templateArgs[id];
1859 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1861 ClassTemplateParameter cParam;
1862 //int p = numParams - sClass.templateParams.count;
1865 if(sClass.templateClass) sClass = sClass.templateClass;
1867 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1869 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1870 p += nextClass.templateParams.count;
1873 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1875 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1877 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1879 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1880 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1892 strcat(argument, arg.name.string);
1893 strcat(argument, " = ");
1899 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1900 char expString[1024];
1901 OldList * specs = MkList();
1902 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1904 char * string = PrintHexUInt64(arg.expression.ui64);
1905 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1908 ProcessExpressionType(exp);
1909 ComputeExpression(exp);
1910 expString[0] = '\0';
1911 PrintExpression(exp, expString);
1912 strcat(argument, expString);
1914 FreeExpression(exp);
1919 strcat(argument, arg.member.name);
1922 case TemplateParameterType::type:
1924 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1925 strcat(argument, arg.dataTypeString);
1931 if(paramCount) strcat(templateString, ", ");
1932 if(lastParam != p - 1)
1934 strcat(templateString, param.name);
1935 strcat(templateString, " = ");
1937 strcat(templateString, argument);
1946 int len = strlen(templateString);
1947 if(templateString[len-1] == '<')
1951 if(templateString[len-1] == '>')
1952 templateString[len++] = ' ';
1953 templateString[len++] = '>';
1955 templateString[len++] = '\0';
1958 Context context = SetupTemplatesContext(_class);
1959 if(freeType) FreeType(type);
1960 type = ProcessTypeString(templateString, false);
1962 FinishTemplatesContext(context);
1966 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1968 ProcessExpressionType(member.initializer.exp);
1969 if(!member.initializer.exp.expType)
1973 char expString[10240];
1974 expString[0] = '\0';
1975 PrintExpression(member.initializer.exp, expString);
1976 ChangeCh(expString, '\n', ' ');
1977 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1980 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1981 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1983 Compiler_Error($"incompatible instance method %s\n", ident.string);
1986 else if(member.initializer)
1989 FreeType(member.exp.destType);
1990 member.exp.destType = type;
1991 if(member.exp.destType)
1992 member.exp.destType.refCount++;
1993 ProcessExpressionType(member.exp);
1996 ProcessInitializer(member.initializer, type);
1998 if(freeType) FreeType(type);
2002 if(_class && _class.type == unitClass)
2004 if(member.initializer)
2007 FreeType(member.exp.destType);
2008 member.exp.destType = MkClassType(_class.fullName);
2009 ProcessExpressionType(member.initializer, type);
2011 Type type = MkClassType(_class.fullName);
2012 ProcessInitializer(member.initializer, type);
2018 if(member.initializer)
2020 //ProcessExpressionType(member.exp);
2021 ProcessInitializer(member.initializer, null);
2027 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2031 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2033 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2037 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2042 void ProcessInstantiationType(Instantiation inst)
2047 MembersInit members;
2051 classSym = inst._class.symbol;
2052 _class = classSym ? classSym.registered : null;
2054 if(!_class || _class.type != noHeadClass)
2055 DeclareStruct(curExternal, inst._class.name, false, true);
2057 afterExternal = afterExternal ? afterExternal : curExternal;
2060 ProcessExpressionType(inst.exp);
2062 inst.isConstant = true;
2065 DataMember curMember = null;
2066 Class curClass = null;
2067 DataMember subMemberStack[256];
2068 int subMemberStackPos = 0;
2070 for(members = inst.members->first; members; members = members.next)
2072 switch(members.type)
2074 case methodMembersInit:
2077 static uint instMethodID = 0;
2078 External external = curExternal;
2079 Context context = curContext;
2080 Declarator declarator = members.function.declarator;
2081 Identifier nameID = GetDeclId(declarator);
2082 char * unmangled = nameID ? nameID.string : null;
2084 External createdExternal = null;
2089 strcpy(name, "__ecereInstMeth_");
2090 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2092 strcat(name, nameID.string);
2094 sprintf(number, "_%08d", instMethodID++);
2095 strcat(name, number);
2096 nameID.string = CopyString(name);
2099 // Do modifications here...
2102 Symbol symbol = declarator.symbol;
2103 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2105 if(method && method.type == virtualMethod)
2107 symbol.method = method;
2108 ProcessMethodType(method);
2110 if(!symbol.type.thisClass)
2112 if(method.dataType.thisClass && currentClass &&
2113 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2115 if(!currentClass.symbol)
2116 currentClass.symbol = FindClass(currentClass.fullName);
2117 symbol.type.thisClass = currentClass.symbol;
2122 _class.symbol = FindClass(_class.fullName);
2123 symbol.type.thisClass = _class.symbol;
2126 DeclareType(curExternal, symbol.type, true, true);
2131 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2132 unmangled, classSym.string);
2136 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2140 FreeSpecifier(nameID._class);
2141 nameID._class = null;
2144 curExternal = createdExternal;
2147 if(createdExternal.function)
2148 ProcessFunction(createdExternal.function);
2152 curExternal = declarator.symbol.pointerExternal;
2153 ProcessFunction((FunctionDefinition)members.function);
2155 curExternal = external;
2156 curContext = context;
2160 FreeClassFunction(members.function);
2162 // In this pass, turn this into a MemberInitData
2163 exp = QMkExpId(name);
2164 members.type = dataMembersInit;
2165 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2171 case dataMembersInit:
2173 if(members.dataMembers && classSym)
2176 Location oldyyloc = yylloc;
2177 for(member = members.dataMembers->first; member; member = member.next)
2179 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2180 if(member.initializer && !member.initializer.isConstant)
2181 inst.isConstant = false;
2193 void DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2195 _DeclareType(neededFor, type, needDereference, forFunctionDef, false);
2198 void DeclareTypeForwardDeclare(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2200 _DeclareType(neededFor, type, needDereference, forFunctionDef, true);
2203 static void _DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef, bool fwdDecl)
2207 if(type.kind == functionType)
2210 for(param = type.params.first; param; param = param.next)
2211 _DeclareType(neededFor, param, forFunctionDef, false, fwdDecl);
2212 _DeclareType(neededFor, type.returnType, forFunctionDef, false, fwdDecl);
2214 else if(type.kind == pointerType)
2215 _DeclareType(neededFor, type.type, false, false, fwdDecl);
2216 else if(type.kind == classType)
2218 Class c = type._class.registered;
2219 _DeclareStruct(neededFor, c ? c.fullName : "ecere::com::Instance", c ? c.type == noHeadClass : false, needDereference && c && c.type == structClass, fwdDecl);
2221 else if(type.kind == structType || type.kind == unionType)
2224 for(member = type.members.first; member; member = member.next)
2225 _DeclareType(neededFor, member, needDereference, forFunctionDef, fwdDecl);
2227 else if(type.kind == arrayType)
2228 _DeclareType(neededFor, type.arrayType, true, false, fwdDecl);
2232 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2234 ClassTemplateArgument * arg = null;
2236 ClassTemplateParameter curParam = null;
2238 for(sClass = _class; sClass; sClass = sClass.base)
2241 if(sClass.templateClass) sClass = sClass.templateClass;
2242 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2244 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2246 for(sClass = sClass.base; sClass; sClass = sClass.base)
2248 if(sClass.templateClass) sClass = sClass.templateClass;
2249 id += sClass.templateParams.count;
2259 arg = &_class.templateArgs[id];
2260 if(arg && param.type == type)
2261 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2266 public Context SetupTemplatesContext(Class _class)
2268 Context context = PushContext();
2269 context.templateTypesOnly = true;
2270 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2272 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2273 for(; param; param = param.next)
2275 if(param.type == type && param.identifier)
2277 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2278 curContext.templateTypes.Add((BTNode)type);
2285 for(sClass = _class; sClass; sClass = sClass.base)
2287 ClassTemplateParameter p;
2288 for(p = sClass.templateParams.first; p; p = p.next)
2290 //OldList * specs = MkList();
2291 //Declarator decl = null;
2292 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2295 TemplateParameter param = p.param;
2299 // ADD DATA TYPE HERE...
2300 p.param = param = TemplateParameter
2302 identifier = MkIdentifier(p.name), type = p.type,
2303 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2306 type = TemplatedType { key = (uintptr)p.name, param = param };
2307 curContext.templateTypes.Add((BTNode)type);
2315 public void FinishTemplatesContext(Context context)
2317 PopContext(context);
2318 FreeContext(context);
2322 public void ProcessMethodType(Method method)
2324 if(!method.dataType)
2326 Context context = SetupTemplatesContext(method._class);
2328 method.dataType = ProcessTypeString(method.dataTypeString, false);
2330 FinishTemplatesContext(context);
2332 if(method.type != virtualMethod && method.dataType)
2334 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2336 if(!method._class.symbol)
2337 method._class.symbol = FindClass(method._class.fullName);
2338 method.dataType.thisClass = method._class.symbol;
2342 // Why was this commented out? Working fine without now...
2345 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2346 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2353 char * par = strstr(type, "(");
2354 char * classOp = null;
2359 for(c = par-type-1; c >= 0; c++)
2361 if(type[c] == ':' && type[c+1] == ':')
2363 classOp = type + c - 1;
2364 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2371 else if(!isspace(type[c]))
2378 int typeLen = strlen(type);
2379 memcpy(temp, classOp, classOpLen);
2380 temp[classOpLen] = '\0';
2382 _class = eSystem_FindClass(module, temp);
2385 method.dataTypeString = new char[typeLen - classOpLen + 1];
2386 memcpy(method.dataTypeString, type, classOp - type);
2387 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2390 method.dataTypeString = type;
2396 public void ProcessPropertyType(Property prop)
2400 Context context = SetupTemplatesContext(prop._class);
2401 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2402 FinishTemplatesContext(context);
2406 public void DeclareMethod(External neededFor, Method method, const char * name)
2408 Symbol symbol = method.symbol;
2409 if(!symbol || (!symbol.pointerExternal && (!symbol.methodCodeExternal || method.type == virtualMethod)))
2411 bool dllImport = false;
2413 if(!method.dataType)
2414 method.dataType = ProcessTypeString(method.dataTypeString, false);
2416 //if(!symbol || symbol._import || method.type == virtualMethod)
2418 if(!symbol || method.type == virtualMethod)
2421 if(!method._class.symbol)
2422 method._class.symbol = FindClass(method._class.fullName);
2423 classSym = method._class.symbol;
2424 if(!classSym._import)
2426 ModuleImport module;
2428 if(method._class.module && method._class.module.name)
2429 module = FindModule(method._class.module);
2431 module = mainModule;
2432 classSym._import = ClassImport
2434 name = CopyString(method._class.fullName);
2435 isRemote = method._class.isRemote;
2437 module.classes.Add(classSym._import);
2441 symbol = method.symbol = Symbol { };
2445 symbol._import = (ClassImport)MethodImport
2447 name = CopyString(method.name);
2448 isVirtual = method.type == virtualMethod;
2450 classSym._import.methods.Add(symbol._import);
2454 symbol.type = method.dataType;
2455 if(symbol.type) symbol.type.refCount++;
2458 if(!method.dataType.dllExport)
2460 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2467 // We need a declaration here :)
2469 OldList * specifiers, * declarators;
2471 Declarator funcDecl;
2474 specifiers = MkList();
2475 declarators = MkList();
2478 ListAdd(specifiers, MkSpecifier(EXTERN));
2479 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2480 ListAdd(specifiers, MkSpecifier(STATIC));
2482 if(method.type == virtualMethod)
2484 ListAdd(specifiers, MkSpecifier(INT));
2485 d = MkDeclaratorIdentifier(MkIdentifier(name));
2489 d = MkDeclaratorIdentifier(MkIdentifier(name));
2491 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2493 Context context = SetupTemplatesContext(method._class);
2494 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2495 FinishTemplatesContext(context);
2497 funcDecl = GetFuncDecl(d);
2501 Specifier spec, next;
2502 for(spec = specifiers->first; spec; spec = next)
2505 if(spec.type == extendedSpecifier)
2507 specifiers->Remove(spec);
2508 FreeSpecifier(spec);
2513 // Add this parameter if not a static method
2514 if(method.dataType && !method.dataType.staticMethod)
2516 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2518 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2519 TypeName thisParam = MkTypeName(MkListOne(
2520 MkSpecifierName(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2521 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2522 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2523 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2525 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2527 TypeName param = funcDecl.function.parameters->first;
2528 funcDecl.function.parameters->Remove(param);
2529 FreeTypeName(param);
2532 if(!funcDecl.function.parameters)
2533 funcDecl.function.parameters = MkList();
2534 funcDecl.function.parameters->Insert(null, thisParam);
2538 ProcessDeclarator(d, true);
2540 ListAdd(declarators, MkInitDeclarator(d, null));
2542 decl = MkDeclaration(specifiers, declarators);
2544 ReplaceThisClassSpecifiers(specifiers, method._class);
2546 external = MkExternalDeclaration(decl);
2547 external.symbol = symbol;
2548 symbol.pointerExternal = external;
2550 DeclareStruct(external, method._class.fullName, true, true);
2552 DeclareType(external, method.dataType, true, true);
2555 if(inCompiler && neededFor)
2557 External external = symbol.pointerExternal ? symbol.pointerExternal : symbol.methodCodeExternal;
2558 neededFor.CreateUniqueEdge(external, external.type == functionExternal);
2562 char * ReplaceThisClass(Class _class)
2564 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2568 ClassTemplateParameter param;
2571 char className[1024];
2572 strcpy(className, _class.fullName);
2573 for(param = _class.templateParams.first; param; param = param.next)
2575 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2577 if(first) strcat(className, "<");
2578 if(!first) strcat(className, ", ");
2579 if(lastParam + 1 != p)
2581 strcat(className, param.name);
2582 strcat(className, " = ");
2584 strcat(className, param.name);
2592 int len = strlen(className);
2593 if(className[len-1] == '>') className[len++] = ' ';
2594 className[len++] = '>';
2595 className[len++] = '\0';
2597 return CopyString(className);
2600 return CopyString(_class.fullName);
2603 Type ReplaceThisClassType(Class _class)
2606 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2610 ClassTemplateParameter param;
2612 char className[1024];
2613 strcpy(className, _class.fullName);
2615 for(param = _class.templateParams.first; param; param = param.next)
2617 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2619 if(first) strcat(className, "<");
2620 if(!first) strcat(className, ", ");
2621 if(lastParam + 1 != p)
2623 strcat(className, param.name);
2624 strcat(className, " = ");
2626 strcat(className, param.name);
2634 int len = strlen(className);
2635 if(className[len-1] == '>') className[len++] = ' ';
2636 className[len++] = '>';
2637 className[len++] = '\0';
2639 type = MkClassType(className);
2640 //type = ProcessTypeString(className, false);
2644 type = MkClassType(_class.fullName);
2645 //type = ProcessTypeString(_class.fullName, false);
2647 //type.wasThisClass = true;
2651 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2653 if(specs != null && _class)
2656 for(spec = specs.first; spec; spec = spec.next)
2658 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2660 spec.type = nameSpecifier;
2661 spec.name = ReplaceThisClass(_class);
2662 spec.symbol = FindClass(spec.name); //_class.symbol;
2668 // Returns imported or not
2669 bool DeclareFunction(External neededFor, GlobalFunction function, char * name)
2671 Symbol symbol = function.symbol;
2672 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2673 if(!symbol || !symbol.pointerExternal)
2675 bool imported = false;
2676 bool dllImport = false;
2678 if(!function.dataType)
2680 function.dataType = ProcessTypeString(function.dataTypeString, false);
2681 if(!function.dataType.thisClass)
2682 function.dataType.staticMethod = true;
2689 ModuleImport module = FindModule(function.module);
2690 // WARNING: This is not added anywhere...
2691 symbol = function.symbol = Symbol { };
2695 if(!function.dataType.dllExport)
2697 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2698 module.functions.Add(symbol._import);
2701 // Set the symbol type
2703 symbol.type = ProcessTypeString(function.dataTypeString, false);
2704 if(!symbol.type.thisClass)
2705 symbol.type.staticMethod = true;
2708 imported = symbol._import ? true : false;
2709 if(imported && function.module != privateModule && function.module.importType != staticImport)
2715 // TOCHECK: What's with the functionExternal check here? Is it Edge breaking / forward declaration?
2716 //if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2718 // We need a declaration here :)
2720 OldList * specifiers, * declarators;
2722 Declarator funcDecl;
2725 specifiers = MkList();
2726 declarators = MkList();
2728 ListAdd(specifiers, MkSpecifier(EXTERN));
2730 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 /* Note: This should be handled by the edge breaking...
2769 if(symbol.pointerExternal && symbol.pointerExternal.type == functionExternal)
2771 Symbol functionSymbol { };
2774 *functionSymbol = *symbol;
2775 functionSymbol.string = CopyString(symbol.string);
2776 if(functionSymbol.type)
2777 functionSymbol.type.refCount++;
2780 excludedSymbols->Add(functionSymbol);
2782 symbol.pointerExternal.symbol = functionSymbol;
2785 external = MkExternalDeclaration(decl);
2787 external.symbol = symbol;
2788 symbol.pointerExternal = external;
2790 DeclareType(external, function.dataType, true, true);
2794 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2795 neededFor.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
2796 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2799 void DeclareGlobalData(External neededFor, GlobalData data)
2801 Symbol symbol = data.symbol;
2802 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2803 if(!symbol || !symbol.pointerExternal)
2808 symbol = data.symbol = Symbol { };
2811 data.dataType = ProcessTypeString(data.dataTypeString, false);
2815 // We need a declaration here :)
2817 OldList * specifiers, * declarators;
2821 specifiers = MkList();
2822 declarators = MkList();
2824 ListAdd(specifiers, MkSpecifier(EXTERN));
2825 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2826 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2828 ListAdd(declarators, MkInitDeclarator(d, null));
2830 decl = MkDeclaration(specifiers, declarators);
2831 external = MkExternalDeclaration(decl);
2833 ast->Insert(curExternal.prev, external);
2834 external.symbol = symbol;
2835 symbol.pointerExternal = external;
2837 DeclareType(external, data.dataType, true, true);
2840 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2841 neededFor.CreateUniqueEdge(symbol.pointerExternal, false);
2844 class Conversion : struct
2846 Conversion prev, next;
2852 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2855 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2856 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2858 Class sourceClass = source.kind == classType ? source._class.registered : null;
2859 Class destClass = dest.kind == classType ? dest._class.registered : null;
2860 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2861 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2863 Type sourceType = source, destType = dest;
2864 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2865 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2866 if(!destType.constant && sourceType.constant)
2870 Compiler_Warning($"discarding const qualifier\n");
2877 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2878 bool isConversionExploration, bool warnConst)
2883 CheckConstCompatibility(source, dest, true);
2884 // Property convert;
2886 if(source.kind == templateType && dest.kind != templateType)
2888 Type type = ProcessTemplateParameterType(source.templateParameter);
2889 if(type) source = type;
2892 if(dest.kind == templateType && source.kind != templateType)
2894 Type type = ProcessTemplateParameterType(dest.templateParameter);
2895 if(type) dest = type;
2898 if(dest.classObjectType == typedObject && dest.kind != functionType)
2900 if(source.classObjectType != anyObject)
2904 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2905 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2913 if(source.kind != functionType && source.classObjectType == anyObject)
2915 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2919 if((dest.kind == structType && source.kind == structType) ||
2920 (dest.kind == unionType && source.kind == unionType))
2922 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2923 (source.members.first && source.members.first == dest.members.first))
2927 if(dest.kind == ellipsisType && source.kind != voidType)
2930 if(dest.kind == pointerType && dest.type.kind == voidType &&
2931 ((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))
2932 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2934 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2936 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2938 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2939 ((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))
2940 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2941 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2943 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2946 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2948 if(source._class.registered && source._class.registered.type == unitClass)
2950 if(conversions != null)
2952 if(source._class.registered == dest._class.registered)
2957 Class sourceBase, destBase;
2958 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2959 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2960 if(sourceBase == destBase)
2964 // Don't match enum inheriting from other enum if resolving enumeration values
2965 // TESTING: !dest.classObjectType
2966 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2968 (!source._class.registered || source._class.registered.type != enumClass) ||
2969 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2973 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2975 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2976 ((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)
2978 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2986 // JUST ADDED THIS...
2987 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2992 // Just added this for Straight conversion of ColorAlpha => Color
2993 if(source.kind == classType)
2996 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2999 for(convert = _class.conversions.first; convert; convert = convert.next)
3001 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3003 Conversion after = (conversions != null) ? conversions.last : null;
3005 if(!convert.dataType)
3006 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3007 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3008 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3009 MatchTypes(convert.dataType, dest, conversions, null, null,
3010 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3011 convert.dataType.kind == classType, false, true, warnConst))
3013 if(!conversions && !convert.Get)
3015 else if(conversions != null)
3017 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3018 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3019 (dest.kind != classType || dest._class.registered != _class.base))
3023 Conversion conv { convert = convert, isGet = true };
3024 // conversions.Add(conv);
3025 conversions.Insert(after, conv);
3038 if(dest.kind == classType)
3041 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3044 for(convert = _class.conversions.first; convert; convert = convert.next)
3046 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3048 Type constType = null;
3049 bool success = false;
3050 // Conversion after = (conversions != null) ? conversions.last : null;
3052 if(!convert.dataType)
3053 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3055 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3058 constType = { kind = pointerType, refCount = 1, type = ptrType };
3059 CopyTypeInto(ptrType, convert.dataType.type);
3060 ptrType.constant = true;
3063 // Just added this equality check to prevent recursion.... Make it safer?
3064 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3065 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3067 if(!conversions && !convert.Set)
3069 else if(conversions != null)
3071 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3072 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3073 (source.kind != classType || source._class.registered != _class.base))
3077 // *** Testing this! ***
3078 Conversion conv { convert = convert };
3079 conversions.Add(conv);
3080 //conversions.Insert(after, conv);
3086 FreeType(constType);
3092 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3094 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3095 (source.kind != classType || source._class.registered.type != structClass))
3099 // TESTING THIS... IS THIS OK??
3100 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3102 if(!dest._class.registered.dataType)
3103 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3104 // Only support this for classes...
3105 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3106 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3108 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3117 if(source.kind == classType)
3120 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3123 for(convert = _class.conversions.first; convert; convert = convert.next)
3125 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3127 Conversion after = (conversions != null) ? conversions.last : null;
3129 if(!convert.dataType)
3130 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3131 if(convert.dataType != source &&
3132 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3133 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3135 if(!conversions && !convert.Get)
3137 else if(conversions != null)
3139 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3140 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3141 (dest.kind != classType || dest._class.registered != _class.base))
3145 Conversion conv { convert = convert, isGet = true };
3147 // conversions.Add(conv);
3148 conversions.Insert(after, conv);
3157 // TESTING THIS... IS THIS OK??
3158 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3160 if(!source._class.registered.dataType)
3161 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3162 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3164 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3166 // For bool to be accepted by byte, short, etc.
3167 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3174 if(source.kind == classType || source.kind == subClassType)
3176 else if(dest.kind == source.kind &&
3177 (dest.kind != structType && dest.kind != unionType &&
3178 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3180 // RECENTLY ADDED THESE
3181 else if(dest.kind == doubleType && source.kind == floatType)
3183 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3185 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3187 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3189 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3191 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3193 else if(source.kind == enumType &&
3194 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3196 else if(dest.kind == enumType && !isConversionExploration &&
3197 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3199 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3200 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3202 Type paramSource, paramDest;
3204 if(dest.kind == methodType)
3205 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3206 if(source.kind == methodType)
3207 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3209 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3210 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3211 if(dest.kind == methodType)
3212 dest = dest.method.dataType;
3213 if(source.kind == methodType)
3214 source = source.method.dataType;
3216 paramSource = source.params.first;
3217 if(paramSource && paramSource.kind == voidType) paramSource = null;
3218 paramDest = dest.params.first;
3219 if(paramDest && paramDest.kind == voidType) paramDest = null;
3222 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3223 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3225 // Source thisClass must be derived from destination thisClass
3226 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3227 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3229 if(paramDest && paramDest.kind == classType)
3230 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3232 Compiler_Error($"method class should not take an object\n");
3235 paramDest = paramDest.next;
3237 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3239 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3243 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3245 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3251 // THIS WAS BACKWARDS:
3252 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3253 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3256 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3258 Compiler_Error($"overriding class expected to be derived from method class\n");
3262 paramSource = paramSource.next;
3268 // Source thisClass must be derived from destination thisClass
3269 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3271 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3277 // THIS WAS BACKWARDS TOO??
3278 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3279 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3282 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3284 //Compiler_Error($"overriding class expected to be derived from method class\n");
3292 // Source return type must be derived from destination return type
3293 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3295 Compiler_Warning($"incompatible return type for function\n");
3298 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3300 CheckConstCompatibility(dest.returnType, source.returnType, true);
3304 for(; paramDest; paramDest = paramDest.next)
3308 //Compiler_Warning($"not enough parameters\n");
3309 Compiler_Error($"not enough parameters\n");
3313 Type paramDestType = paramDest;
3314 Type paramSourceType = paramSource;
3315 Type type = paramDestType;
3317 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3318 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3319 paramSource.kind != templateType)
3322 ClassTemplateParameter curParam = null;
3324 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3327 if(sClass.templateClass) sClass = sClass.templateClass;
3328 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3330 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3332 for(sClass = sClass.base; sClass; sClass = sClass.base)
3334 if(sClass.templateClass) sClass = sClass.templateClass;
3335 id += sClass.templateParams.count;
3346 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3347 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3351 // paramDest must be derived from paramSource
3352 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3353 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3357 PrintType(paramDest, type, false, true);
3358 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3360 if(paramDestType != paramDest)
3361 FreeType(paramDestType);
3364 if(paramDestType != paramDest)
3365 FreeType(paramDestType);
3368 paramSource = paramSource.next;
3372 Compiler_Error($"too many parameters\n");
3377 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3381 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3382 (source.kind == arrayType || source.kind == pointerType))
3384 // Pointers to pointer is incompatible with non normal/nohead classes
3385 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3386 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3388 ComputeTypeSize(source.type);
3389 ComputeTypeSize(dest.type);
3390 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3398 static void FreeConvert(Conversion convert)
3400 if(convert.resultType)
3401 FreeType(convert.resultType);
3404 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3405 char * string, OldList conversions)
3409 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3411 Class _class = link.data;
3412 if(_class.type == enumClass)
3414 OldList converts { };
3416 type.kind = classType;
3419 _class.symbol = FindClass(_class.fullName);
3420 type._class = _class.symbol;
3422 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3423 false, false, false, false))
3426 Class enumClass = eSystem_FindClass(privateModule, "enum");
3430 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3432 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3433 for(value = e.values.first; value; value = value.next)
3435 if(!strcmp(value.name, string))
3440 FreeType(sourceExp.expType);
3442 sourceExp.isConstant = true;
3443 sourceExp.expType = MkClassType(baseClass.fullName);
3444 if(inCompiler || inPreCompiler || inDebugger)
3447 FreeExpContents(sourceExp);
3449 sourceExp.type = constantExp;
3450 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3451 sprintf(constant, FORMAT64D, value.data);
3453 sprintf(constant, FORMAT64HEXLL, value.data);
3454 sourceExp.constant = CopyString(constant);
3455 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3458 while(converts.first)
3460 Conversion convert = converts.first;
3461 converts.Remove(convert);
3462 conversions.Add(convert);
3471 converts.Free(FreeConvert);
3475 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3476 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3481 public bool ModuleVisibility(Module searchIn, Module searchFor)
3483 SubModule subModule;
3485 if(searchFor == searchIn)
3488 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3490 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3492 if(ModuleVisibility(subModule.module, searchFor))
3499 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3503 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3505 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3507 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3510 for(module = mainModule.application.allModules.first; module; module = module.next)
3512 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3518 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3521 Type realDest = dest;
3522 Type backupSourceExpType = null;
3523 Expression nbExp = GetNonBracketsExp(sourceExp);
3524 Expression computedExp = nbExp;
3527 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3528 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3530 computedExp = CopyExpression(nbExp); // Keep the original expression, but compute for checking enum ranges
3531 ComputeExpression(computedExp /*sourceExp*/);
3534 source = sourceExp.expType;
3536 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3538 if(computedExp != nbExp)
3540 FreeExpression(computedExp);
3541 computedExp = nbExp;
3547 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3549 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3551 Class sourceBase, destBase;
3552 for(sourceBase = source._class.registered;
3553 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3554 sourceBase = sourceBase.base);
3555 for(destBase = dest._class.registered;
3556 destBase && destBase.base && destBase.base.type != systemClass;
3557 destBase = destBase.base);
3558 //if(source._class.registered == dest._class.registered)
3559 if(sourceBase == destBase)
3561 if(computedExp != nbExp)
3563 FreeExpression(computedExp);
3564 computedExp = nbExp;
3576 int64 value = MAXINT;
3580 if(computedExp.type == constantExp)
3583 value = strtoll(computedExp.constant, null, 0);
3585 value = strtoull(computedExp.constant, null, 0);
3587 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3590 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3592 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3594 if(computedExp != nbExp)
3596 FreeExpression(computedExp);
3597 computedExp = nbExp;
3600 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3601 !strcmp(source._class.registered.fullName, "unichar" /*"ecere::com::unichar"*/))
3604 source = Type { kind = intType, isSigned = false, refCount = 1 };
3607 if(dest.kind == classType)
3609 Class _class = dest._class ? dest._class.registered : null;
3611 if(_class && _class.type == unitClass)
3613 if(source.kind != classType)
3616 Type tempDest, tempSource;
3618 for(; _class.base.type != systemClass; _class = _class.base);
3620 tempDest = tempType;
3622 tempType.kind = classType;
3624 _class.symbol = FindClass(_class.fullName);
3626 tempType._class = _class.symbol;
3627 tempType.truth = dest.truth;
3629 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3631 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3632 backupSourceExpType = sourceExp.expType;
3633 if(dest.passAsTemplate)
3635 // Don't carry passAsTemplate
3636 sourceExp.expType = { };
3637 CopyTypeInto(sourceExp.expType, dest);
3638 sourceExp.expType.passAsTemplate = false;
3642 sourceExp.expType = dest;
3645 //sourceExp.expType = MkClassType(_class.fullName);
3653 // Why wasn't there something like this?
3654 if(_class && _class.type == bitClass && source.kind != classType)
3656 if(!dest._class.registered.dataType)
3657 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3658 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3661 FreeType(sourceExp.expType);
3662 source = sourceExp.expType = MkClassType(dest._class.string);
3665 //source.kind = classType;
3666 //source._class = dest._class;
3670 // Adding two enumerations
3672 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3674 if(!source._class.registered.dataType)
3675 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3676 if(!dest._class.registered.dataType)
3677 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3679 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3682 source = sourceExp.expType = MkClassType(dest._class.string);
3685 //source.kind = classType;
3686 //source._class = dest._class;
3690 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3692 OldList * specs = MkList();
3696 ReadString(string, sourceExp.string);
3697 decl = SpecDeclFromString(string, specs, null);
3699 FreeExpContents(sourceExp);
3700 FreeType(sourceExp.expType);
3702 sourceExp.type = classExp;
3703 sourceExp._classExp.specifiers = specs;
3704 sourceExp._classExp.decl = decl;
3705 sourceExp.expType = dest;
3710 if(backupSourceExpType) FreeType(backupSourceExpType);
3714 else if(source.kind == classType)
3716 Class _class = source._class ? source._class.registered : null;
3718 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || _class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3721 if(dest.kind != classType)
3723 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3724 if(!source._class.registered.dataType)
3725 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3728 dest = MkClassType(source._class.string);
3729 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3730 // dest = MkClassType(source._class.string);
3734 if(dest.kind != classType)
3737 Type tempDest, tempSource;
3739 if(!source._class.registered.dataType)
3740 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3742 for(; _class.base.type != systemClass; _class = _class.base);
3744 tempSource = tempType;
3745 tempType.kind = classType;
3746 tempType._class = FindClass(_class.fullName);
3747 tempType.truth = source.truth;
3748 tempType.classObjectType = source.classObjectType;
3751 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3753 // PUT THIS BACK TESTING UNITS?
3754 if(conversions && conversions.last)
3756 ((Conversion)(conversions.last)).resultType = dest;
3760 FreeType(sourceExp.expType);
3761 sourceExp.expType = MkClassType(_class.fullName);
3762 sourceExp.expType.truth = source.truth;
3763 sourceExp.expType.classObjectType = source.classObjectType;
3765 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3767 if(!sourceExp.destType)
3769 FreeType(sourceExp.destType);
3770 sourceExp.destType = sourceExp.expType;
3771 if(sourceExp.expType)
3772 sourceExp.expType.refCount++;
3775 //source = _class.dataType;
3778 // TOCHECK: TESTING THIS NEW CODE
3779 if(!_class.dataType)
3780 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3782 dest = MkClassType(source._class.string);
3783 dest.truth = source.truth;
3784 dest.classObjectType = source.classObjectType;
3787 source = _class.dataType;
3797 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3807 if(source.kind == classType)
3809 Class _class = source._class.registered;
3810 if(_class.type == unitClass)
3812 if(!_class.dataType)
3813 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3814 source = _class.dataType;
3818 if(dest.kind == classType)
3820 Class _class = dest._class ? dest._class.registered : null;
3821 bool fittingValue = false;
3822 if(_class && _class.type == enumClass)
3824 Class enumClass = eSystem_FindClass(privateModule, "enum");
3825 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3826 if(c && value >= 0 && value <= c.largest)
3827 fittingValue = true;
3830 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3831 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3833 if(_class.type == normalClass || _class.type == noHeadClass)
3835 Expression newExp { };
3836 *newExp = *sourceExp;
3837 if(sourceExp.destType) sourceExp.destType.refCount++;
3838 if(sourceExp.expType) sourceExp.expType.refCount++;
3839 sourceExp.type = castExp;
3840 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3841 sourceExp.cast.exp = newExp;
3842 FreeType(sourceExp.expType);
3843 sourceExp.expType = null;
3844 ProcessExpressionType(sourceExp);
3846 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3849 FreeType(sourceExp.expType);
3850 sourceExp.expType = dest;
3854 if(inCompiler) FreeType(dest);
3856 if(backupSourceExpType) FreeType(backupSourceExpType);
3860 if(!_class.dataType)
3861 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3863 dest = _class.dataType;
3867 // Accept lower precision types for units, since we want to keep the unit type
3868 if(dest.kind == doubleType &&
3869 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3870 source.kind == charType || source.kind == _BoolType))
3872 specs = MkListOne(MkSpecifier(DOUBLE));
3874 else if(dest.kind == floatType &&
3875 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3876 source.kind == _BoolType || source.kind == doubleType))
3878 specs = MkListOne(MkSpecifier(FLOAT));
3880 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3881 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3884 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3885 ListAdd(specs, MkSpecifier(INT64));
3887 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3888 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3891 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3892 ListAdd(specs, MkSpecifier(INT));
3894 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3895 source.kind == floatType || source.kind == doubleType))
3898 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3899 ListAdd(specs, MkSpecifier(SHORT));
3901 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3902 source.kind == floatType || source.kind == doubleType))
3905 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3906 ListAdd(specs, MkSpecifier(CHAR));
3912 if(backupSourceExpType)
3914 // Failed to convert: revert previous exp type
3915 if(sourceExp.expType) FreeType(sourceExp.expType);
3916 sourceExp.expType = backupSourceExpType;
3921 else if(dest.kind == doubleType &&
3922 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3923 source.kind == _BoolType || source.kind == charType))
3925 specs = MkListOne(MkSpecifier(DOUBLE));
3927 else if(dest.kind == floatType &&
3928 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3930 specs = MkListOne(MkSpecifier(FLOAT));
3932 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3933 (value == 1 || value == 0))
3936 ListAdd(specs, MkSpecifier(BOOL));
3938 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3939 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3941 if(source.kind == intType)
3945 if(backupSourceExpType) FreeType(backupSourceExpType);
3951 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3952 ListAdd(specs, MkSpecifier(CHAR));
3955 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3956 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3958 if(source.kind == intType)
3962 if(backupSourceExpType) FreeType(backupSourceExpType);
3968 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3969 ListAdd(specs, MkSpecifier(SHORT));
3972 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3975 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3976 ListAdd(specs, MkSpecifier(INT));
3978 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3981 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3982 ListAdd(specs, MkSpecifier(INT64));
3984 else if(dest.kind == enumType &&
3985 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3987 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3993 if(backupSourceExpType)
3995 // Failed to convert: revert previous exp type
3996 if(sourceExp.expType) FreeType(sourceExp.expType);
3997 sourceExp.expType = backupSourceExpType;
4002 if(!flag && !sourceExp.opDestType)
4004 Expression newExp { };
4005 *newExp = *sourceExp;
4008 if(sourceExp.destType) sourceExp.destType.refCount++;
4009 if(sourceExp.expType) sourceExp.expType.refCount++;
4011 sourceExp.type = castExp;
4012 if(realDest.kind == classType)
4014 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4015 FreeList(specs, FreeSpecifier);
4018 sourceExp.cast.typeName = MkTypeName(specs, null);
4019 if(newExp.type == opExp)
4021 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4024 sourceExp.cast.exp = newExp;
4026 FreeType(sourceExp.expType);
4027 sourceExp.expType = null;
4028 ProcessExpressionType(sourceExp);
4031 FreeList(specs, FreeSpecifier);
4035 if(backupSourceExpType) FreeType(backupSourceExpType);
4041 if(computedExp != nbExp)
4043 FreeExpression(computedExp);
4044 computedExp = nbExp;
4047 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4048 if(sourceExp.type == identifierExp)
4050 Identifier id = sourceExp.identifier;
4051 if(dest.kind == classType)
4053 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4055 Class _class = dest._class.registered;
4056 Class enumClass = eSystem_FindClass(privateModule, "enum");
4059 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4062 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4063 for(value = e.values.first; value; value = value.next)
4065 if(!strcmp(value.name, id.string))
4070 FreeType(sourceExp.expType);
4072 sourceExp.isConstant = true;
4073 sourceExp.expType = MkClassType(_class.fullName);
4074 if(inCompiler || inPreCompiler || inDebugger)
4076 FreeExpContents(sourceExp);
4078 sourceExp.type = constantExp;
4079 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4080 sourceExp.constant = PrintInt64(value.data);
4082 sourceExp.constant = PrintUInt64(value.data);
4083 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4093 // Loop through all enum classes
4094 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4105 #define TERTIARY(o, name, m, t, p) \
4106 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4108 exp.type = constantExp; \
4109 exp.string = p(op1.m ? op2.m : op3.m); \
4111 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4115 #define BINARY(o, name, m, t, p) \
4116 static bool name(Expression exp, Operand op1, Operand op2) \
4119 exp.type = constantExp; \
4120 exp.string = p((t)(op1.m o value2)); \
4122 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4126 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4127 static bool name(Expression exp, Operand op1, Operand op2) \
4130 exp.type = constantExp; \
4131 exp.string = p(value2 ? ((t)(op1.m o value2)) : 0); \
4133 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4137 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4138 static bool name(Expression exp, Operand op1, Operand op2) \
4141 exp.type = constantExp; \
4142 exp.string = p((t)(op1.m o value2)); \
4144 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4148 #define UNARY(o, name, m, t, p) \
4149 static bool name(Expression exp, Operand op1) \
4151 exp.type = constantExp; \
4152 exp.string = p((t)(o op1.m)); \
4154 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4158 #define OPERATOR_ALL(macro, o, name) \
4159 macro(o, Int##name, i, int, PrintInt) \
4160 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4161 macro(o, Int64##name, i64, int64, PrintInt64) \
4162 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4163 macro(o, Short##name, s, short, PrintShort) \
4164 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4165 macro(o, Char##name, c, char, PrintChar) \
4166 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4167 macro(o, Float##name, f, float, PrintFloat) \
4168 macro(o, Double##name, d, double, PrintDouble)
4170 #define OPERATOR_INTTYPES(macro, o, name) \
4171 macro(o, Int##name, i, int, PrintInt) \
4172 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4173 macro(o, Int64##name, i64, int64, PrintInt64) \
4174 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4175 macro(o, Short##name, s, short, PrintShort) \
4176 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4177 macro(o, Char##name, c, char, PrintChar) \
4178 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4180 #define OPERATOR_REALTYPES(macro, o, name) \
4181 macro(o, Float##name, f, float, PrintFloat) \
4182 macro(o, Double##name, d, double, PrintDouble)
4184 // binary arithmetic
4185 OPERATOR_ALL(BINARY, +, Add)
4186 OPERATOR_ALL(BINARY, -, Sub)
4187 OPERATOR_ALL(BINARY, *, Mul)
4188 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4189 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4190 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4193 OPERATOR_ALL(UNARY, -, Neg)
4195 // unary arithmetic increment and decrement
4196 OPERATOR_ALL(UNARY, ++, Inc)
4197 OPERATOR_ALL(UNARY, --, Dec)
4199 // binary arithmetic assignment
4200 OPERATOR_ALL(BINARY, =, Asign)
4201 OPERATOR_ALL(BINARY, +=, AddAsign)
4202 OPERATOR_ALL(BINARY, -=, SubAsign)
4203 OPERATOR_ALL(BINARY, *=, MulAsign)
4204 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4205 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4206 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4209 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4210 OPERATOR_INTTYPES(BINARY, |, BitOr)
4211 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4212 OPERATOR_INTTYPES(BINARY, <<, LShift)
4213 OPERATOR_INTTYPES(BINARY, >>, RShift)
4216 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4218 // binary bitwise assignment
4219 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4220 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4221 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4222 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4223 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4225 // unary logical negation
4226 OPERATOR_INTTYPES(UNARY, !, Not)
4228 // binary logical equality
4229 OPERATOR_ALL(BINARY, ==, Equ)
4230 OPERATOR_ALL(BINARY, !=, Nqu)
4233 OPERATOR_ALL(BINARY, &&, And)
4234 OPERATOR_ALL(BINARY, ||, Or)
4236 // binary logical relational
4237 OPERATOR_ALL(BINARY, >, Grt)
4238 OPERATOR_ALL(BINARY, <, Sma)
4239 OPERATOR_ALL(BINARY, >=, GrtEqu)
4240 OPERATOR_ALL(BINARY, <=, SmaEqu)
4242 // tertiary condition operator
4243 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4245 //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
4246 #define OPERATOR_TABLE_ALL(name, type) \
4247 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4249 type##Inc, type##Dec, \
4250 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4251 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4253 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4255 type##Equ, type##Nqu, \
4256 type##And, type##Or, \
4257 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4260 #define OPERATOR_TABLE_INTTYPES(name, type) \
4261 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4263 type##Inc, type##Dec, \
4264 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4265 null, null, null, null, null, \
4267 null, null, null, null, null, \
4269 type##Equ, type##Nqu, \
4270 type##And, type##Or, \
4271 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4274 OPERATOR_TABLE_ALL(int, Int)
4275 OPERATOR_TABLE_ALL(uint, UInt)
4276 OPERATOR_TABLE_ALL(int64, Int64)
4277 OPERATOR_TABLE_ALL(uint64, UInt64)
4278 OPERATOR_TABLE_ALL(short, Short)
4279 OPERATOR_TABLE_ALL(ushort, UShort)
4280 OPERATOR_TABLE_INTTYPES(float, Float)
4281 OPERATOR_TABLE_INTTYPES(double, Double)
4282 OPERATOR_TABLE_ALL(char, Char)
4283 OPERATOR_TABLE_ALL(uchar, UChar)
4285 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4286 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4287 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4288 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4289 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4290 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4291 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4292 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4294 public void ReadString(char * output, char * string)
4296 int len = strlen(string);
4298 bool quoted = false, escaped = false;
4299 for(c = 0; c<len; c++)
4301 char ch = string[c];
4306 case 'n': output[d] = '\n'; break;
4307 case 't': output[d] = '\t'; break;
4308 case 'a': output[d] = '\a'; break;
4309 case 'b': output[d] = '\b'; break;
4310 case 'f': output[d] = '\f'; break;
4311 case 'r': output[d] = '\r'; break;
4312 case 'v': output[d] = '\v'; break;
4313 case '\\': output[d] = '\\'; break;
4314 case '\"': output[d] = '\"'; break;
4315 case '\'': output[d] = '\''; break;
4316 default: output[d] = ch;
4337 // String Unescape Copy
4339 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4340 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4341 public int UnescapeString(char * d, char * s, int len)
4345 while(j < len && (ch = s[j]))
4350 switch((ch = s[++j]))
4352 case 'n': d[k] = '\n'; break;
4353 case 't': d[k] = '\t'; break;
4354 case 'a': d[k] = '\a'; break;
4355 case 'b': d[k] = '\b'; break;
4356 case 'f': d[k] = '\f'; break;
4357 case 'r': d[k] = '\r'; break;
4358 case 'v': d[k] = '\v'; break;
4359 case '\\': d[k] = '\\'; break;
4360 case '\"': d[k] = '\"'; break;
4361 case '\'': d[k] = '\''; break;
4362 default: d[k] = '\\'; d[k] = ch;
4374 public char * OffsetEscapedString(char * s, int len, int offset)
4378 while(j < len && k < offset && (ch = s[j]))
4383 return (k == offset) ? s + j : null;
4386 public Operand GetOperand(Expression exp)
4389 Type type = exp.expType;
4392 while(type.kind == classType &&
4393 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4395 if(!type._class.registered.dataType)
4396 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4397 type = type._class.registered.dataType;
4400 if(exp.type == stringExp && op.kind == pointerType)
4402 op.ui64 = (uint64)(uintptr)exp.string;
4403 op.kind = pointerType;
4406 else if(exp.isConstant && exp.type == constantExp)
4408 op.kind = type.kind;
4416 if(exp.constant[0] == '\'')
4418 op.c = exp.constant[1];
4421 else if(type.isSigned)
4423 op.c = (char)strtol(exp.constant, null, 0);
4428 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4434 if(exp.constant[0] == '\'')
4436 op.s = exp.constant[1];
4439 else if(type.isSigned)
4441 op.s = (short)strtol(exp.constant, null, 0);
4446 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4452 if(exp.constant[0] == '\'')
4454 op.i = exp.constant[1];
4457 else if(type.isSigned)
4459 op.i = (int)strtol(exp.constant, null, 0);
4464 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4472 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4477 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4480 op.kind = int64Type;
4485 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4490 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4493 op.kind = int64Type;
4498 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4503 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4506 op.kind = int64Type;
4509 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4510 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4511 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4512 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4514 op.f = (float)strtod(exp.constant, null);
4518 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4519 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4520 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4521 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4523 op.d = (double)strtod(exp.constant, null);
4526 //case classType: For when we have operator overloading...
4527 // Pointer additions
4528 //case functionType:
4532 op.ui64 = _strtoui64(exp.constant, null, 0);
4533 op.kind = pointerType;
4543 static int64 GetEnumValue(Class _class, void * ptr)
4546 switch(_class.typeSize)
4549 if(!strcmp(_class.dataTypeString, "uint64"))
4550 v = (int64)*(uint64 *)ptr;
4552 v = (int64)*(int64 *)ptr;
4555 if(!strcmp(_class.dataTypeString, "uint"))
4556 v = (int64)*(uint *)ptr;
4558 v = (int64)*(int *)ptr;
4561 if(!strcmp(_class.dataTypeString, "uint16"))
4562 v = (int64)*(uint16 *)ptr;
4564 v = (int64)*(short *)ptr;
4567 if(!strcmp(_class.dataTypeString, "byte"))
4568 v = (int64)*(byte *)ptr;
4570 v = (int64)*(char *)ptr;
4576 static __attribute__((unused)) void UnusedFunction()
4579 a.OnGetString(0,0,0);
4582 extern int __ecereVMethodID_class_OnGetString;
4585 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4587 DataMember dataMember;
4588 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4590 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4591 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4595 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4597 void * ptr = inst.data + dataMember.offset + offset;
4598 char * result = null;
4599 exp.loc = member.loc = inst.loc;
4600 ((Identifier)member.identifiers->first).loc = inst.loc;
4602 if(!dataMember.dataType)
4603 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4604 type = dataMember.dataType;
4605 if(type.kind == classType)
4607 Class _class = type._class.registered;
4608 if(_class.type == enumClass)
4610 Class enumClass = eSystem_FindClass(privateModule, "enum");
4613 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4615 for(item = e.values.first; item; item = item.next)
4617 if(item.data == GetEnumValue(_class, ptr))
4625 exp.identifier = MkIdentifier(result);
4626 exp.type = identifierExp;
4627 exp.destType = MkClassType(_class.fullName);
4628 ProcessExpressionType(exp);
4632 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4634 if(!_class.dataType)
4635 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4636 type = _class.dataType;
4645 FreeExpContents(exp);
4647 exp.constant = PrintFloat(*(float*)ptr);
4648 exp.type = constantExp;
4653 FreeExpContents(exp);
4655 exp.constant = PrintDouble(*(double*)ptr);
4656 exp.type = constantExp;
4661 FreeExpContents(exp);
4663 exp.constant = PrintInt(*(int*)ptr);
4664 exp.type = constantExp;
4669 FreeExpContents(exp);
4671 exp.constant = PrintInt64(*(int64*)ptr);
4672 exp.type = constantExp;
4677 FreeExpContents(exp);
4678 // TODO: This should probably use proper type
4679 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4680 exp.type = constantExp;
4685 FreeExpContents(exp);
4686 // TODO: This should probably use proper type
4687 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4688 exp.type = constantExp;
4692 Compiler_Error($"Unhandled type populating instance\n");
4695 ListAdd(memberList, member);
4698 if(parentDataMember.type == unionMember)
4703 void PopulateInstance(Instantiation inst)
4705 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4706 Class _class = classSym.registered;
4707 DataMember dataMember;
4708 OldList * memberList = MkList();
4709 // Added this check and ->Add to prevent memory leaks on bad code
4711 inst.members = MkListOne(MkMembersInitList(memberList));
4713 inst.members->Add(MkMembersInitList(memberList));
4714 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4716 if(!dataMember.isProperty)
4718 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4719 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4723 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4725 void * ptr = inst.data + dataMember.offset;
4726 char * result = null;
4728 exp.loc = member.loc = inst.loc;
4729 ((Identifier)member.identifiers->first).loc = inst.loc;
4731 if(!dataMember.dataType)
4732 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4733 type = dataMember.dataType;
4734 if(type.kind == classType)
4736 Class _class = type._class.registered;
4737 if(_class.type == enumClass)
4739 Class enumClass = eSystem_FindClass(privateModule, "enum");
4742 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4744 for(item = e.values.first; item; item = item.next)
4746 if(item.data == GetEnumValue(_class, ptr))
4755 exp.identifier = MkIdentifier(result);
4756 exp.type = identifierExp;
4757 exp.destType = MkClassType(_class.fullName);
4758 ProcessExpressionType(exp);
4761 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4763 if(!_class.dataType)
4764 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4765 type = _class.dataType;
4774 exp.constant = PrintFloat(*(float*)ptr);
4775 exp.type = constantExp;
4780 exp.constant = PrintDouble(*(double*)ptr);
4781 exp.type = constantExp;
4786 exp.constant = PrintInt(*(int*)ptr);
4787 exp.type = constantExp;
4792 exp.constant = PrintInt64(*(int64*)ptr);
4793 exp.type = constantExp;
4798 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4799 exp.type = constantExp;
4803 Compiler_Error($"Unhandled type populating instance\n");
4806 ListAdd(memberList, member);
4812 void ComputeInstantiation(Expression exp)
4814 Instantiation inst = exp.instance;
4815 MembersInit members;
4816 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4817 Class _class = classSym ? classSym.registered : null;
4818 DataMember curMember = null;
4819 Class curClass = null;
4820 DataMember subMemberStack[256];
4821 int subMemberStackPos = 0;
4824 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4826 // Don't recompute the instantiation...
4827 // Non Simple classes will have become constants by now
4831 if(_class.type == normalClass || _class.type == noHeadClass)
4833 inst.data = (byte *)eInstance_New(_class);
4834 if(_class.type == normalClass)
4835 ((Instance)inst.data)._refCount++;
4838 inst.data = new0 byte[_class.structSize];
4843 for(members = inst.members->first; members; members = members.next)
4845 switch(members.type)
4847 case dataMembersInit:
4849 if(members.dataMembers)
4852 for(member = members.dataMembers->first; member; member = member.next)
4854 Identifier ident = member.identifiers ? member.identifiers->first : null;
4857 Property prop = null;
4858 DataMember dataMember = null;
4859 uint dataMemberOffset;
4863 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4866 if(curMember.isProperty)
4867 prop = (Property)curMember;
4870 dataMember = curMember;
4872 // CHANGED THIS HERE
4873 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4875 // 2013/17/29 -- It seems that this was missing here!
4876 if(_class.type == normalClass)
4877 dataMemberOffset += _class.base.structSize;
4878 // dataMemberOffset = dataMember.offset;
4885 prop = eClass_FindProperty(_class, ident.string, privateModule);
4889 if(prop.memberAccess == publicAccess)
4891 curMember = (DataMember)prop;
4892 curClass = prop._class;
4897 DataMember _subMemberStack[256];
4898 int _subMemberStackPos = 0;
4900 // FILL MEMBER STACK
4901 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4906 if(dataMember.memberAccess == publicAccess)
4908 curMember = dataMember;
4909 curClass = dataMember._class;
4910 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4911 subMemberStackPos = _subMemberStackPos;
4917 if(found && member.initializer && member.initializer.type == expInitializer)
4919 Expression value = member.initializer.exp;
4921 bool deepMember = false;
4924 type = prop.dataType;
4928 if(!dataMember.dataType)
4929 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4931 type = dataMember.dataType;
4934 if(ident && ident.next)
4938 // for(; ident && type; ident = ident.next)
4939 for(ident = ident.next; ident && type; ident = ident.next)
4941 if(type.kind == classType)
4943 prop = eClass_FindProperty(type._class.registered,
4944 ident.string, privateModule);
4946 type = prop.dataType;
4949 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4950 ident.string, &dataMemberOffset, privateModule, null, null);
4952 type = dataMember.dataType;
4955 else if(type.kind == structType || type.kind == unionType)
4958 for(memberType = type.members.first; memberType; memberType = memberType.next)
4960 if(!strcmp(memberType.name, ident.string))
4971 FreeType(value.destType);
4972 value.destType = type;
4973 if(type) type.refCount++;
4974 ComputeExpression(value);
4976 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4978 if(type.kind == classType)
4980 Class _class = type._class.registered;
4981 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4983 if(!_class.dataType)
4984 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4985 type = _class.dataType;
4991 void * ptr = inst.data + dataMemberOffset;
4993 if(value.type == constantExp)
4999 GetInt(value, (int*)ptr);
5004 GetInt64(value, (int64*)ptr);
5009 GetIntPtr(value, (intptr*)ptr);
5014 GetIntSize(value, (intsize*)ptr);
5019 GetFloat(value, (float*)ptr);
5024 GetDouble(value, (double *)ptr);
5029 else if(value.type == instanceExp)
5031 if(type.kind == classType)
5033 Class _class = type._class.registered;
5034 if(_class.type == structClass)
5036 ComputeTypeSize(type);
5037 if(value.instance.data)
5038 memcpy(ptr, value.instance.data, type.size);
5043 else if(prop && prop.Set != (void *)(intptr)1)
5045 if(value.type == instanceExp && value.instance.data)
5047 if(type.kind == classType)
5049 Class _class = type._class.registered;
5050 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5052 void (*Set)(void *, void *) = (void *)prop.Set;
5053 Set(inst.data, value.instance.data);
5054 PopulateInstance(inst);
5058 else if(value.type == constantExp)
5064 void (*Set)(void *, double) = (void *)prop.Set;
5065 Set(inst.data, strtod(value.constant, null) );
5070 void (*Set)(void *, float) = (void *)prop.Set;
5071 Set(inst.data, (float)(strtod(value.constant, null)));
5076 void (*Set)(void *, int) = (void *)prop.Set;
5077 Set(inst.data, (int)strtol(value.constant, null, 0));
5082 void (*Set)(void *, int64) = (void *)prop.Set;
5083 Set(inst.data, _strtoi64(value.constant, null, 0));
5088 void (*Set)(void *, intptr) = (void *)prop.Set;
5089 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5094 void (*Set)(void *, intsize) = (void *)prop.Set;
5095 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5100 else if(value.type == stringExp)
5103 ReadString(temp, value.string);
5104 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5108 else if(!deepMember && type && _class.type == unitClass)
5112 // Only support converting units to units for now...
5113 if(value.type == constantExp)
5115 if(type.kind == classType)
5117 Class _class = type._class.registered;
5118 if(_class.type == unitClass)
5120 if(!_class.dataType)
5121 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5122 type = _class.dataType;
5125 // TODO: Assuming same base type for units...
5131 float (*Set)(float) = (void *)prop.Set;
5132 GetFloat(member.initializer.exp, &fValue);
5133 exp.constant = PrintFloat(Set(fValue));
5134 exp.type = constantExp;
5140 double (*Set)(double) = (void *)prop.Set;
5141 GetDouble(member.initializer.exp, &dValue);
5142 exp.constant = PrintDouble(Set(dValue));
5143 exp.type = constantExp;
5150 else if(!deepMember && type && _class.type == bitClass)
5154 if(value.type == instanceExp && value.instance.data)
5156 unsigned int (*Set)(void *) = (void *)prop.Set;
5157 bits = Set(value.instance.data);
5159 else if(value.type == constantExp)
5165 BitMember bitMember = (BitMember) dataMember;
5168 bits = (bits & ~bitMember.mask);
5169 if(!bitMember.dataType)
5170 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5171 type = bitMember.dataType;
5172 if(type.kind == classType && type._class && type._class.registered)
5174 if(!type._class.registered.dataType)
5175 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5176 type = type._class.registered.dataType;
5181 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5182 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5184 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5185 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5186 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5187 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5189 bits |= part << bitMember.pos;
5195 if(_class && _class.type == unitClass)
5197 ComputeExpression(member.initializer.exp);
5198 exp.constant = member.initializer.exp.constant;
5199 exp.type = constantExp;
5201 member.initializer.exp.constant = null;
5211 if(_class && _class.type == bitClass)
5213 exp.constant = PrintHexUInt(bits);
5214 exp.type = constantExp;
5216 if(exp.type != instanceExp)
5222 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5224 bool result = false;
5228 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5229 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5233 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5234 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5237 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5238 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5239 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5242 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5243 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5244 result = GetOpFloat(op, &op.f);
5247 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5248 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5249 result = GetOpDouble(op, &op.d);
5252 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5253 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5254 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5257 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5258 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5259 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5262 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5263 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5266 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5267 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5273 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5275 if(exp.op.op == SIZEOF)
5277 FreeExpContents(exp);
5278 exp.type = constantExp;
5279 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5290 // Provide default unary +
5291 Expression exp2 = exp.op.exp2;
5293 FreeExpContents(exp);
5294 FreeType(exp.expType);
5295 FreeType(exp.destType);
5301 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5303 // unary arithmetic increment and decrement
5304 //OPERATOR_ALL(UNARY, ++, Inc)
5305 //OPERATOR_ALL(UNARY, --, Dec)
5308 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5310 // unary logical negation
5312 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5318 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5320 if(Promote(op2, op1.kind, op1.type.isSigned))
5321 op2.kind = op1.kind, op2.ops = op1.ops;
5322 else if(Promote(op1, op2.kind, op2.type.isSigned))
5323 op1.kind = op2.kind, op1.ops = op2.ops;
5327 // binary arithmetic
5329 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5332 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5335 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5338 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5341 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5343 // binary arithmetic assignment
5344 //OPERATOR_ALL(BINARY, =, Asign)
5345 //OPERATOR_ALL(BINARY, +=, AddAsign)
5346 //OPERATOR_ALL(BINARY, -=, SubAsign)
5347 //OPERATOR_ALL(BINARY, *=, MulAsign)
5348 //OPERATOR_ALL(BINARY, /=, DivAsign)
5349 //OPERATOR_ALL(BINARY, %=, ModAsign)
5354 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5358 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5361 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5364 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5367 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5369 // binary bitwise assignment
5370 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5371 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5372 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5373 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5374 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5375 // binary logical equality
5377 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5380 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5384 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5387 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5389 // binary logical relational
5391 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5394 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5397 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5400 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5407 void ComputeExpression(Expression exp)
5410 char expString[10240];
5411 expString[0] = '\0';
5412 PrintExpression(exp, expString);
5419 Identifier id = exp.identifier;
5420 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5422 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5423 if(c && c.type == enumClass)
5425 Class enumClass = eSystem_FindClass(privateModule, "enum");
5429 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5430 for(value = e.values.first; value; value = value.next)
5432 if(!strcmp(value.name, id.string))
5437 const String dts = c.dataTypeString;
5438 FreeExpContents(exp);
5439 exp.type = constantExp;
5440 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5449 ComputeInstantiation(exp);
5458 Expression exp1, exp2 = null;
5462 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5465 Expression e = exp.op.exp2;
5467 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5469 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5471 if(e.type == extensionCompoundExp)
5472 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5477 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5479 if(e.type == stringExp && e.string)
5481 char * string = e.string;
5482 int len = strlen(string);
5483 char * tmp = new char[len-2+1];
5484 len = UnescapeString(tmp, string + 1, len - 2);
5486 FreeExpContents(exp);
5487 exp.type = constantExp;
5488 exp.constant = PrintUInt(len + 1);
5492 Type type = e.expType;
5494 FreeExpContents(exp);
5495 exp.type = constantExp;
5496 exp.constant = PrintUInt(ComputeTypeSize(type));
5502 ComputeExpression(exp.op.exp2);
5506 ComputeExpression(exp.op.exp1);
5509 op1 = GetOperand(exp1);
5510 if(op1.type) op1.type.refCount++;
5513 op2 = GetOperand(exp2);
5514 if(op2.type) op2.type.refCount++;
5520 op1 = GetOperand(exp1);
5521 if(op1.type) op1.type.refCount++;
5524 CallOperator(exp, exp1, exp2, op1, op2);
5531 if(exp.op.exp1 && exp.op.exp2)
5536 FreeExpContents(exp);
5537 op1.ops.BitAnd(exp, op1, op2);
5546 FreeExpContents(exp);
5547 op1.ops.Mul(exp, op1, op2);
5556 FreeExpContents(exp);
5557 op1.ops.Add(exp, op1, op2);
5562 // Provide default unary +
5563 Expression exp2 = exp.op.exp2;
5565 FreeExpContents(exp);
5566 FreeType(exp.expType);
5567 FreeType(exp.destType);
5578 FreeExpContents(exp);
5579 op1.ops.Sub(exp, op1, op2);
5586 FreeExpContents(exp);
5587 op1.ops.Neg(exp, op1);
5594 FreeExpContents(exp);
5595 op1.ops.BitNot(exp, op1);
5601 FreeExpContents(exp);
5602 op1.ops.Not(exp, op1);
5605 // Binary only operators
5609 FreeExpContents(exp);
5610 op1.ops.Div(exp, op1, op2);
5616 FreeExpContents(exp);
5617 op1.ops.Mod(exp, op1, op2);
5629 FreeExpContents(exp);
5630 op1.ops.Sma(exp, op1, op2);
5639 FreeExpContents(exp);
5640 op1.ops.Grt(exp, op1, op2);
5649 FreeExpContents(exp);
5650 op1.ops.SmaEqu(exp, op1, op2);
5659 FreeExpContents(exp);
5660 op1.ops.GrtEqu(exp, op1, op2);
5669 FreeExpContents(exp);
5670 op1.ops.Equ(exp, op1, op2);
5679 FreeExpContents(exp);
5680 op1.ops.Nqu(exp, op1, op2);
5687 FreeExpContents(exp);
5688 op1.ops.BitOr(exp, op1, op2);
5694 FreeExpContents(exp);
5695 op1.ops.BitXor(exp, op1, op2);
5703 FreeExpContents(exp);
5704 exp.type = constantExp;
5705 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5709 if(op1.type) FreeType(op1.type);
5710 if(op2.type) FreeType(op2.type);
5714 case extensionExpressionExp:
5717 for(e = exp.list->first; e; e = n)
5722 OldList * list = exp.list;
5723 Expression prev = exp.prev;
5724 Expression next = exp.next;
5725 ComputeExpression(e);
5726 //FreeExpContents(exp);
5727 FreeType(exp.expType);
5728 FreeType(exp.destType);
5747 exp.isConstant = true;
5749 ComputeExpression(exp.index.exp);
5750 if(!exp.index.exp.isConstant)
5751 exp.isConstant = false;
5753 for(e = exp.index.index->first; e; e = e.next)
5755 ComputeExpression(e);
5758 // Check if this type is int
5761 exp.isConstant = false;
5763 exp.expType = Dereference(exp.index.exp.expType);
5769 Expression memberExp = exp.member.exp;
5770 Identifier memberID = exp.member.member;
5773 ComputeExpression(exp.member.exp);
5774 type = exp.member.exp.expType;
5777 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);
5778 Property prop = null;
5779 DataMember member = null;
5780 Class convertTo = null;
5781 if(type.kind == subClassType && exp.member.exp.type == classExp)
5782 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5789 PrintTypeNoConst(type, string, false, true);
5790 classSym = FindClass(string);
5791 _class = classSym ? classSym.registered : null;
5794 if(exp.member.member)
5796 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5798 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5800 if(!prop && !member && _class && exp.member.member)
5802 Symbol classSym = FindClass(exp.member.member.string);
5804 _class = classSym ? classSym.registered : null;
5805 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5812 Type type = prop.dataType;
5813 // TODO: Assuming same base type for units...
5814 if(_class.type == unitClass)
5816 if(type.kind == classType)
5818 Class _class = type._class.registered;
5819 if(_class.type == unitClass)
5821 if(!_class.dataType)
5822 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5823 type = _class.dataType;
5831 float (*Get)(float) = (void *)prop.Get;
5832 GetFloat(exp.member.exp, &value);
5833 exp.constant = PrintFloat(Get ? Get(value) : value);
5834 exp.type = constantExp;
5840 double (*Get)(double);
5841 GetDouble(exp.member.exp, &value);
5844 Get = (void *)prop.Set;
5846 Get = (void *)prop.Get;
5847 exp.constant = PrintDouble(Get ? Get(value) : value);
5848 exp.type = constantExp;
5857 Expression value = exp.member.exp;
5860 ProcessPropertyType(prop);
5862 type = prop.dataType;
5865 // printf("Investigate this\n");
5867 else if(_class.type == structClass)
5873 Class propertyClass = type._class.registered;
5874 if(propertyClass.type == structClass && value.type == instanceExp)
5876 void (*Set)(void *, void *) = (void *)prop.Set;
5877 exp.instance = Instantiation { };
5878 exp.instance.data = new0 byte[_class.structSize];
5879 exp.instance._class = MkSpecifierName(_class.fullName);
5880 exp.instance.loc = exp.loc;
5881 exp.type = instanceExp;
5882 Set(exp.instance.data, value.instance.data);
5883 PopulateInstance(exp.instance);
5890 void (*Set)(void *, int) = (void *)prop.Set;
5892 exp.instance = Instantiation { };
5893 exp.instance.data = new0 byte[_class.structSize];
5894 exp.instance._class = MkSpecifierName(_class.fullName);
5895 exp.instance.loc = exp.loc;
5896 exp.type = instanceExp;
5898 GetInt(value, &intValue);
5900 Set(exp.instance.data, intValue);
5901 PopulateInstance(exp.instance);
5907 void (*Set)(void *, int64) = (void *)prop.Set;
5909 exp.instance = Instantiation { };
5910 exp.instance.data = new0 byte[_class.structSize];
5911 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5912 exp.instance.loc = exp.loc;
5913 exp.type = instanceExp;
5915 GetInt64(value, &intValue);
5917 Set(exp.instance.data, intValue);
5918 PopulateInstance(exp.instance);
5925 void (*Set)(void *, intptr) = (void *)prop.Set;
5927 exp.instance = Instantiation { };
5928 exp.instance.data = new0 byte[_class.structSize];
5929 exp.instance._class = MkSpecifierName(_class.fullName);
5930 exp.instance.loc = exp.loc;
5931 exp.type = instanceExp;
5933 GetIntPtr(value, &intValue);
5935 Set(exp.instance.data, intValue);
5936 PopulateInstance(exp.instance);
5943 void (*Set)(void *, intsize) = (void *)prop.Set;
5945 exp.instance = Instantiation { };
5946 exp.instance.data = new0 byte[_class.structSize];
5947 exp.instance._class = MkSpecifierName(_class.fullName);
5948 exp.instance.loc = exp.loc;
5949 exp.type = instanceExp;
5951 GetIntSize(value, &intValue);
5953 Set(exp.instance.data, intValue);
5954 PopulateInstance(exp.instance);
5960 void (*Set)(void *, float) = (void *)prop.Set;
5962 exp.instance = Instantiation { };
5963 exp.instance.data = new0 byte[_class.structSize];
5964 exp.instance._class = MkSpecifierName(_class.fullName);
5965 exp.instance.loc = exp.loc;
5966 exp.type = instanceExp;
5968 GetFloat(value, &floatValue);
5970 Set(exp.instance.data, floatValue);
5971 PopulateInstance(exp.instance);
5977 void (*Set)(void *, double) = (void *)prop.Set;
5979 exp.instance = Instantiation { };
5980 exp.instance.data = new0 byte[_class.structSize];
5981 exp.instance._class = MkSpecifierName(_class.fullName);
5982 exp.instance.loc = exp.loc;
5983 exp.type = instanceExp;
5985 GetDouble(value, &doubleValue);
5987 Set(exp.instance.data, doubleValue);
5988 PopulateInstance(exp.instance);
5993 else if(_class.type == bitClass)
5999 Class propertyClass = type._class.registered;
6000 if(propertyClass.type == structClass && value.instance.data)
6002 unsigned int (*Set)(void *) = (void *)prop.Set;
6003 unsigned int bits = Set(value.instance.data);
6004 exp.constant = PrintHexUInt(bits);
6005 exp.type = constantExp;
6008 else if(_class.type == bitClass)
6011 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6014 GetUInt(exp.member.exp, &value);
6016 exp.constant = PrintHexUInt(bits);
6017 exp.type = constantExp;
6025 if(_class.type == bitClass)
6028 GetUInt(exp.member.exp, &value);
6034 Class _class = type._class.registered;
6035 if(_class.type == structClass)
6037 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6039 exp.instance = Instantiation { };
6040 exp.instance.data = new0 byte[_class.structSize];
6041 exp.instance._class = MkSpecifierName(_class.fullName);
6042 exp.instance.loc = exp.loc;
6043 //exp.instance.fullSet = true;
6044 exp.type = instanceExp;
6045 Get(value, exp.instance.data);
6046 PopulateInstance(exp.instance);
6048 else if(_class.type == bitClass)
6050 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6051 uint64 bits = Get(value);
6052 exp.constant = PrintHexUInt64(bits);
6053 exp.type = constantExp;
6059 else if(_class.type == structClass)
6061 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6066 Class _class = type._class.registered;
6067 if(_class.type == structClass && value)
6069 void (*Get)(void *, void *) = (void *)prop.Get;
6071 exp.instance = Instantiation { };
6072 exp.instance.data = new0 byte[_class.structSize];
6073 exp.instance._class = MkSpecifierName(_class.fullName);
6074 exp.instance.loc = exp.loc;
6075 //exp.instance.fullSet = true;
6076 exp.type = instanceExp;
6077 Get(value, exp.instance.data);
6078 PopulateInstance(exp.instance);
6086 char * value = exp.member.exp.instance.data;
6091 Class _class = type._class.registered;
6092 if(_class.type == normalClass)
6094 void *(*Get)(void *) = (void *)prop.Get;
6096 exp.instance = Instantiation { };
6097 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6098 exp.type = instanceExp;
6099 exp.instance.data = Get(value, exp.instance.data);
6111 exp.isConstant = false;
6119 if(exp.type != ExpressionType::memberExp)
6121 FreeExpression(memberExp);
6122 FreeIdentifier(memberID);
6128 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6129 FreeExpContents(exp);
6130 exp.constant = PrintUInt(ComputeTypeSize(type));
6131 exp.type = constantExp;
6137 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6138 if(classSym && classSym.registered)
6140 if(classSym.registered.fixed)
6142 FreeSpecifier(exp._class);
6143 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6144 exp.type = constantExp;
6148 char className[1024];
6149 strcpy(className, "__ecereClass_");
6150 FullClassNameCat(className, classSym.string, true);
6152 DeclareClass(curExternal, classSym, className);
6154 FreeExpContents(exp);
6155 exp.type = pointerExp;
6156 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6157 exp.member.member = MkIdentifier("structSize");
6167 if(exp.type == castExp)
6170 ComputeExpression(exp.cast.exp);
6173 if(e && exp.expType)
6176 type = exp.destType;
6179 if(type.kind == classType)
6181 Class _class = type._class.registered;
6182 if(_class && (_class.type == unitClass || _class.type == bitClass))
6184 if(!_class.dataType)
6185 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6186 type = _class.dataType;
6197 if(GetChar(e, &value))
6199 FreeExpContents(exp);
6200 exp.constant = PrintChar(value);
6201 exp.type = constantExp;
6206 unsigned char value = 0;
6207 if(GetUChar(e, &value))
6209 FreeExpContents(exp);
6210 exp.constant = PrintUChar(value);
6211 exp.type = constantExp;
6219 if(GetShort(e, &value))
6221 FreeExpContents(exp);
6222 exp.constant = PrintShort(value);
6223 exp.type = constantExp;
6228 unsigned short value = 0;
6229 if(GetUShort(e, &value))
6231 FreeExpContents(exp);
6232 exp.constant = PrintUShort(value);
6233 exp.type = constantExp;
6241 if(GetInt(e, &value))
6243 FreeExpContents(exp);
6244 exp.constant = PrintInt(value);
6245 exp.type = constantExp;
6250 unsigned int value = 0;
6251 if(GetUInt(e, &value))
6253 FreeExpContents(exp);
6254 exp.constant = PrintUInt(value);
6255 exp.type = constantExp;
6263 if(GetInt64(e, &value))
6265 FreeExpContents(exp);
6266 exp.constant = PrintInt64(value);
6267 exp.type = constantExp;
6273 if(GetUInt64(e, &value))
6275 FreeExpContents(exp);
6276 exp.constant = PrintUInt64(value);
6277 exp.type = constantExp;
6285 if(GetIntPtr(e, &value))
6287 FreeExpContents(exp);
6288 exp.constant = PrintInt64((int64)value);
6289 exp.type = constantExp;
6295 if(GetUIntPtr(e, &value))
6297 FreeExpContents(exp);
6298 exp.constant = PrintUInt64((uint64)value);
6299 exp.type = constantExp;
6307 if(GetIntSize(e, &value))
6309 FreeExpContents(exp);
6310 exp.constant = PrintInt64((int64)value);
6311 exp.type = constantExp;
6317 if(GetUIntSize(e, &value))
6319 FreeExpContents(exp);
6320 exp.constant = PrintUInt64((uint64)value);
6321 exp.type = constantExp;
6328 if(GetFloat(e, &value))
6330 FreeExpContents(exp);
6331 exp.constant = PrintFloat(value);
6332 exp.type = constantExp;
6339 if(GetDouble(e, &value))
6341 FreeExpContents(exp);
6342 exp.constant = PrintDouble(value);
6343 exp.type = constantExp;
6358 // Caring only about last expression for now...
6359 ComputeExpression(exp.cond.exp->last);
6360 if(exp.cond.elseExp)
6361 ComputeExpression(exp.cond.elseExp);
6363 ComputeExpression(exp.cond.cond);
6365 op1 = GetOperand(exp.cond.cond);
6366 if(op1.type) op1.type.refCount++;
6367 op2 = GetOperand(exp.cond.exp->last);
6368 if(op2.type) op2.type.refCount++;
6369 op3 = GetOperand(exp.cond.elseExp);
6370 if(op3.type) op3.type.refCount++;
6372 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6373 if(op1.type) FreeType(op1.type);
6374 if(op2.type) FreeType(op2.type);
6375 if(op3.type) FreeType(op3.type);
6381 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6386 OldList converts { };
6389 if(destType.kind == voidType)
6392 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6396 // for(convert = converts.last; convert; convert = convert.prev)
6397 for(convert = converts.first; convert; convert = convert.next)
6399 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6402 Expression newExp { };
6403 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6405 // TODO: Check this...
6409 newExp.destType = null;
6414 exp.type = memberExp;
6415 exp.addedThis = true;
6416 exp.member.exp = newExp;
6417 FreeType(exp.member.exp.expType);
6419 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6420 exp.member.exp.expType.classObjectType = objectType;
6421 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6422 exp.member.memberType = propertyMember;
6423 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6424 // TESTING THIS... for (int)degrees
6425 exp.needCast = true;
6426 if(exp.expType) exp.expType.refCount++;
6427 ApplyAnyObjectLogic(exp.member.exp);
6432 /*if(exp.isConstant)
6434 // Color { ColorRGB = [exp] };
6435 exp.type = instanceExp;
6436 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6437 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6438 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6442 // If not constant, don't turn it yet into an instantiation
6443 // (Go through the deep members system first)
6444 exp.type = memberExp;
6445 exp.addedThis = true;
6446 exp.member.exp = newExp;
6448 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6449 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6450 newExp.expType._class.registered.type == noHeadClass)
6452 newExp.byReference = true;
6455 FreeType(exp.member.exp.expType);
6456 /*exp.member.exp.expType = convert.convert.dataType;
6457 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6458 exp.member.exp.expType = null;
6459 if(convert.convert.dataType)
6461 exp.member.exp.expType = { };
6462 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6463 exp.member.exp.expType.refCount = 1;
6464 exp.member.exp.expType.classObjectType = objectType;
6465 ApplyAnyObjectLogic(exp.member.exp);
6468 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6469 exp.member.memberType = reverseConversionMember;
6470 exp.expType = convert.resultType ? convert.resultType :
6471 MkClassType(convert.convert._class.fullName);
6472 exp.needCast = true;
6473 if(convert.resultType) convert.resultType.refCount++;
6479 FreeType(exp.expType);
6482 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6483 if(exp.destType.casted)
6484 exp.needCast = true;
6485 if(exp.expType) exp.expType.refCount++;
6489 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6490 if(exp.destType.casted)
6491 exp.needCast = true;
6492 if(convert.resultType)
6493 convert.resultType.refCount++;
6497 if(exp.isConstant && inCompiler)
6498 ComputeExpression(exp);
6500 converts.Free(FreeConvert);
6503 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6505 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6507 if(!result && exp.expType && exp.destType)
6509 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6510 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6511 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6512 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6516 // if(result) CheckTemplateTypes(exp);
6520 void CheckTemplateTypes(Expression exp)
6523 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6524 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6526 Expression nbExp = GetNonBracketsExp(exp);
6527 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6528 (nbExp == exp || nbExp.type != castExp))
6530 Expression newExp { };
6532 TypeKind kind = exp.expType.kind;
6534 if(exp.destType) exp.destType.refCount++;
6535 if(exp.expType) exp.expType.refCount++;
6539 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6541 Class c = exp.expType._class.registered;
6542 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6545 c.dataType = ProcessTypeString(c.dataTypeString, false);
6546 kind = c.dataType.kind;
6553 if(exp.destType.classObjectType)
6555 // We need to pass the address, just pass it along (Undo what was done above)
6556 if(exp.destType) exp.destType.refCount--;
6557 if(exp.expType) exp.expType.refCount--;
6562 // If we're looking for value:
6563 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6565 OldList * unionDefs = MkList();
6566 OldList * statements = MkList();
6567 context = PushContext();
6568 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6569 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6570 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6571 exp.type = extensionCompoundExp;
6572 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6573 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6574 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6575 exp.compound.compound.context = context;
6576 PopContext(context);
6581 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6582 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6583 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6585 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6586 exp.needCast = true;
6590 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6592 Expression newExp { };
6594 TypeKind kind = exp.expType.kind;
6596 if(exp.destType) exp.destType.refCount++;
6597 if(exp.expType) exp.expType.refCount++;
6601 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6603 Class c = exp.expType._class.registered;
6604 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6607 c.dataType = ProcessTypeString(c.dataTypeString, false);
6608 kind = c.dataType.kind;
6615 if(exp.destType.classObjectType)
6617 // We need to pass the address, just pass it along (Undo what was done above)
6618 if(exp.destType) exp.destType.refCount--;
6619 if(exp.expType) exp.expType.refCount--;
6624 // If we're looking for value:
6625 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6627 OldList * unionDefs = MkList();
6628 OldList * statements = MkList();
6629 context = PushContext();
6630 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6631 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6632 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6633 exp.type = extensionCompoundExp;
6634 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6635 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6636 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6637 exp.compound.compound.context = context;
6638 PopContext(context);
6643 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6645 exp.type = bracketsExp;
6647 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6648 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6649 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6650 ProcessExpressionType(exp.list->first);
6655 exp.type = bracketsExp;
6656 if(exp.expType.isPointerType)
6658 exp.needTemplateCast = 2;
6659 newExp.needCast = true;
6660 newExp.needTemplateCast = 2;
6661 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6664 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6665 exp.needTemplateCast = 2;
6666 newExp.needCast = true;
6667 newExp.needTemplateCast = 2;
6668 ProcessExpressionType(exp.list->first);
6674 if(exp.expType.kind == templateType)
6676 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6679 FreeType(exp.destType);
6680 FreeType(exp.expType);
6685 /*if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6687 // When was this required? Removed to address using templated values to pass to printf()
6691 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6692 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6696 char typeString[1024];
6698 OldList * specs = MkList();
6699 typeString[0] = '\0';
6700 PrintType(exp.expType, typeString, false, false);
6701 decl = SpecDeclFromString(typeString, specs, null);
6704 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6705 exp.cast.typeName = MkTypeName(specs, decl);
6706 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6707 exp.cast.exp.needCast = true;
6708 exp.needTemplateCast = 2;
6709 newExp.needTemplateCast = 2;
6716 // TODO: The Symbol tree should be reorganized by namespaces
6718 // - Tree of all symbols within (stored without namespace)
6719 // - Tree of sub-namespaces
6721 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6723 int nsLen = strlen(nameSpace);
6725 // Start at the name space prefix
6726 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6728 char * s = symbol.string;
6729 if(!strncmp(s, nameSpace, nsLen))
6731 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6734 for(c = strlen(s)-1; c >= 0; c--)
6739 if(!strcmp(namePart, name))
6741 // TODO: Error on ambiguity
6751 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6754 char nameSpace[1024];
6755 const char * namePart;
6756 bool gotColon = false;
6758 nameSpace[0] = '\0';
6759 for(c = strlen(name)-1; c >= 0; c--)
6766 namePart = name+c+1;
6767 while(c >= 0 && name[c] == ':') c--;
6770 // Try an exact match first
6771 Symbol symbol = (Symbol)tree.FindString(name);
6775 // Namespace specified
6776 memcpy(nameSpace, name, c + 1);
6779 return ScanWithNameSpace(tree, nameSpace, namePart);
6783 // Looking for a global symbol, e.g. ::Sleep()
6784 Symbol symbol = (Symbol)tree.FindString(namePart);
6789 // Name only (no namespace specified)
6790 Symbol symbol = (Symbol)tree.FindString(namePart);
6793 return ScanWithNameSpace(tree, "", namePart);
6798 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6801 //Time startTime = GetTime();
6803 // Optimize this later? Do this before/less?
6805 Symbol symbol = null;
6807 // First, check if the identifier is declared inside the function
6808 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6810 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6812 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6818 strcpy(curName, thisNameSpace);
6819 strcat(curName, "::");
6820 strcat(curName, name);
6821 // Try to resolve in current namespace first
6822 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6825 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6828 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6830 if(symbol || ctx == endContext) break;
6832 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6833 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6835 //findSymbolTotalTime += GetTime() - startTime;
6840 static void GetTypeSpecs(Type type, OldList * specs)
6842 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6847 if(type._class.registered)
6849 if(!type._class.registered.dataType)
6850 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6851 GetTypeSpecs(type._class.registered.dataType, specs);
6855 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6856 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6857 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6858 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6859 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6860 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6861 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6862 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6865 ListAdd(specs, MkSpecifier(INT)); break;
6869 static void PrintArraySize(Type arrayType, char * string)
6874 if(arrayType.enumClass)
6875 strcat(size, arrayType.enumClass.string);
6876 else if(arrayType.arraySizeExp)
6877 PrintExpression(arrayType.arraySizeExp, size);
6879 strcat(string, size);
6882 // WARNING : This function expects a null terminated string since it recursively concatenate...
6883 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6887 if(printConst && type.constant)
6888 strcat(string, "const ");
6893 Symbol c = type._class;
6894 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
6895 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6896 // look into merging with thisclass ?
6897 if(type.classObjectType == typedObject && isObjectBaseClass)
6898 strcat(string, "typed_object");
6899 else if(type.classObjectType == anyObject && isObjectBaseClass)
6900 strcat(string, "any_object");
6904 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6906 if(type.byReference)
6907 strcat(string, " &");
6910 case voidType: strcat(string, "void"); break;
6911 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6912 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6913 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6914 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6915 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6916 case _BoolType: strcat(string, "_Bool"); break;
6917 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6918 case floatType: strcat(string, "float"); break;
6919 case doubleType: strcat(string, "double"); break;
6923 strcat(string, "struct ");
6924 strcat(string, type.enumName);
6926 else if(type.typeName)
6927 strcat(string, type.typeName);
6931 strcat(string, "struct { ");
6932 for(member = type.members.first; member; member = member.next)
6934 PrintType(member, string, true, fullName);
6935 strcat(string,"; ");
6943 strcat(string, "union ");
6944 strcat(string, type.enumName);
6946 else if(type.typeName)
6947 strcat(string, type.typeName);
6950 strcat(string, "union ");
6951 strcat(string,"(unnamed)");
6957 strcat(string, "enum ");
6958 strcat(string, type.enumName);
6960 else if(type.typeName)
6961 strcat(string, type.typeName);
6963 strcat(string, "int"); // "enum");
6966 strcat(string, "...");
6969 strcat(string, "subclass(");
6970 strcat(string, type._class ? type._class.string : "int");
6971 strcat(string, ")");
6974 strcat(string, type.templateParameter.identifier.string);
6977 strcat(string, "thisclass");
6980 strcat(string, "__builtin_va_list");
6986 static void PrintName(Type type, char * string, bool fullName)
6988 if(type.name && type.name[0])
6991 strcat(string, type.name);
6994 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6995 if(name) name += 2; else name = type.name;
6996 strcat(string, name);
7001 static void PrintAttribs(Type type, char * string)
7005 if(type.dllExport) strcat(string, "dllexport ");
7006 if(type.attrStdcall) strcat(string, "stdcall ");
7010 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7012 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7014 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7015 PrintAttribs(type, string);
7016 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7017 strcat(string, " const");
7018 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7019 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7020 strcat(string, " (");
7021 if(type.kind == pointerType)
7023 if(type.type.kind == functionType || type.type.kind == methodType)
7024 PrintAttribs(type.type, string);
7026 if(type.kind == pointerType)
7028 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7029 strcat(string, "*");
7031 strcat(string, " *");
7033 if(printConst && type.constant && type.kind == pointerType)
7034 strcat(string, " const");
7037 PrintTypeSpecs(type, string, fullName, printConst);
7040 static void PostPrintType(Type type, char * string, bool fullName)
7042 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7043 strcat(string, ")");
7044 if(type.kind == arrayType)
7045 PrintArraySize(type, string);
7046 else if(type.kind == functionType)
7049 strcat(string, "(");
7050 for(param = type.params.first; param; param = param.next)
7052 PrintType(param, string, true, fullName);
7053 if(param.next) strcat(string, ", ");
7055 strcat(string, ")");
7057 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7058 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7062 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7064 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7066 PrePrintType(type, string, fullName, null, printConst);
7068 if(type.thisClass || (printName && type.name && type.name[0]))
7069 strcat(string, " ");
7070 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7072 Symbol _class = type.thisClass;
7073 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7075 if(type.classObjectType == classPointer)
7076 strcat(string, "class");
7078 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7080 else if(_class && _class.string)
7082 String s = _class.string;
7087 char * name = RSearchString(s, "::", strlen(s), true, false);
7088 if(name) name += 2; else name = s;
7089 strcat(string, name);
7092 strcat(string, "::");
7095 if(printName && type.name)
7096 PrintName(type, string, fullName);
7097 PostPrintType(type, string, fullName);
7098 if(type.bitFieldCount)
7101 sprintf(count, ":%d", type.bitFieldCount);
7102 strcat(string, count);
7106 void PrintType(Type type, char * string, bool printName, bool fullName)
7108 _PrintType(type, string, printName, fullName, true);
7111 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7113 _PrintType(type, string, printName, fullName, false);
7116 static Type FindMember(Type type, char * string)
7119 for(memberType = type.members.first; memberType; memberType = memberType.next)
7121 if(!memberType.name)
7123 Type subType = FindMember(memberType, string);
7127 else if(!strcmp(memberType.name, string))
7133 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7136 for(memberType = type.members.first; memberType; memberType = memberType.next)
7138 if(!memberType.name)
7140 Type subType = FindMember(memberType, string);
7143 *offset += memberType.offset;
7147 else if(!strcmp(memberType.name, string))
7149 *offset += memberType.offset;
7156 public bool GetParseError() { return parseError; }
7158 Expression ParseExpressionString(char * expression)
7162 fileInput = TempFile { };
7163 fileInput.Write(expression, 1, strlen(expression));
7164 fileInput.Seek(0, start);
7167 parsedExpression = null;
7169 expression_yyparse();
7172 return parsedExpression;
7175 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7177 Identifier id = exp.identifier;
7178 Method method = null;
7179 Property prop = null;
7180 DataMember member = null;
7181 ClassProperty classProp = null;
7183 if(_class && _class.type == enumClass)
7185 NamedLink64 value = null;
7186 Class enumClass = eSystem_FindClass(privateModule, "enum");
7190 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7192 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7193 for(value = e.values.first; value; value = value.next)
7195 if(!strcmp(value.name, id.string))
7200 exp.isConstant = true;
7201 if(inCompiler || inPreCompiler || inDebugger)
7204 FreeExpContents(exp);
7206 exp.type = constantExp;
7207 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7208 sprintf(constant, FORMAT64D, value.data);
7210 sprintf(constant, FORMAT64HEX, value.data);
7211 exp.constant = CopyString(constant);
7213 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7214 exp.expType = MkClassType(baseClass.fullName);
7222 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7224 ProcessMethodType(method);
7231 // TOCHECK: Put it back to what it was...
7232 // methodClass = _class;
7233 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7238 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7241 ProcessPropertyType(prop);
7242 exp.expType = prop.dataType;
7243 if(prop.dataType) prop.dataType.refCount++;
7246 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7248 if(!member.dataType)
7249 member.dataType = ProcessTypeString(member.dataTypeString, false);
7250 exp.expType = member.dataType;
7251 if(member.dataType) member.dataType.refCount++;
7254 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7256 if(!classProp.dataType)
7257 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7259 if(classProp.constant)
7261 FreeExpContents(exp);
7263 exp.isConstant = true;
7264 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7266 //char constant[256];
7267 exp.type = stringExp;
7268 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7273 exp.type = constantExp;
7274 sprintf(constant, "%d", (int)classProp.Get(_class));
7275 exp.constant = CopyString(constant);
7283 exp.expType = classProp.dataType;
7284 if(classProp.dataType) classProp.dataType.refCount++;
7290 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7292 BinaryTree * tree = &nameSpace.functions;
7293 GlobalData data = (GlobalData)tree->FindString(name);
7297 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7299 data = ScanGlobalData(child, name);
7307 static GlobalData FindGlobalData(char * name)
7310 NameSpace * nameSpace;
7311 nameSpace = globalData;
7312 for(c = 0; name[c]; c++)
7314 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7316 NameSpace * newSpace;
7317 char * spaceName = new char[c - start + 1];
7318 strncpy(spaceName, name + start, c - start);
7319 spaceName[c-start] = '\0';
7320 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7324 nameSpace = newSpace;
7325 if(name[c] == ':') c++;
7331 return ScanGlobalData(nameSpace, name + start);
7336 static int definedExpStackPos;
7337 static void * definedExpStack[512];
7339 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7340 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7342 Expression prev = checkedExp.prev, next = checkedExp.next;
7344 FreeExpContents(checkedExp);
7345 FreeType(checkedExp.expType);
7346 FreeType(checkedExp.destType);
7348 *checkedExp = *newExp;
7352 checkedExp.prev = prev;
7353 checkedExp.next = next;
7356 void ApplyAnyObjectLogic(Expression e)
7358 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7360 char debugExpString[4096];
7361 debugExpString[0] = '\0';
7362 PrintExpression(e, debugExpString);
7365 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7367 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7368 //ellipsisDestType = destType;
7371 Type type = e.expType;
7372 Class _class = null;
7373 //Type destType = e.destType;
7375 if(type.kind == classType && type._class && type._class.registered)
7377 _class = type._class.registered;
7379 else if(type.kind == subClassType)
7381 _class = FindClass("ecere::com::Class").registered;
7385 char string[1024] = "";
7388 PrintTypeNoConst(type, string, false, true);
7389 classSym = FindClass(string);
7390 if(classSym) _class = classSym.registered;
7393 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...
7394 (!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))) ||
7395 destType.byReference)))
7397 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7399 Expression checkedExp = e, newExp;
7401 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7403 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7405 if(checkedExp.type == extensionCompoundExp)
7407 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7410 checkedExp = checkedExp.list->last;
7412 else if(checkedExp.type == castExp)
7413 checkedExp = checkedExp.cast.exp;
7416 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7418 newExp = checkedExp.op.exp2;
7419 checkedExp.op.exp2 = null;
7420 FreeExpContents(checkedExp);
7422 if(e.expType && e.expType.passAsTemplate)
7425 ComputeTypeSize(e.expType);
7426 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7427 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7428 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7429 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7432 ReplaceExpContents(checkedExp, newExp);
7433 e.byReference = true;
7435 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7437 Expression checkedExp; //, newExp;
7440 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7442 e.type == identifierExp ||
7443 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7444 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7445 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7448 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7450 Context context = PushContext();
7452 OldList * specs = MkList();
7453 char typeString[1024];
7454 Expression newExp { };
7456 typeString[0] = '\0';
7459 //if(e.destType) e.destType.refCount++;
7460 // if(exp.expType) exp.expType.refCount++;
7463 newExp.expType = null;
7465 PrintTypeNoConst(e.expType, typeString, false, true);
7466 decl = SpecDeclFromString(typeString, specs, null);
7467 newExp.destType = ProcessType(specs, decl);
7469 curContext = context;
7471 // We need a current compound for this
7475 OldList * stmts = MkList();
7476 e.type = extensionCompoundExp;
7477 sprintf(name, "__internalValue%03X", internalValueCounter++);
7478 if(!curCompound.compound.declarations)
7479 curCompound.compound.declarations = MkList();
7480 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7481 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7482 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7483 e.compound = MkCompoundStmt(null, stmts);
7486 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7489 e.compound = MkCompoundStmt(
7490 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7491 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7493 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7497 Type type = e.destType;
7499 CopyTypeInto(e.destType, type);
7500 e.destType.refCount = 1;
7501 e.destType.classObjectType = none;
7505 e.compound.compound.context = context;
7506 PopContext(context);
7507 curContext = context.parent;
7511 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7513 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7515 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7517 if(checkedExp.type == extensionCompoundExp)
7519 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7522 checkedExp = checkedExp.list->last;
7524 else if(checkedExp.type == castExp)
7525 checkedExp = checkedExp.cast.exp;
7528 Expression operand { };
7529 operand = *checkedExp;
7531 checkedExp.destType = ProcessTypeString("void *", false);
7532 checkedExp.expType = checkedExp.destType;
7533 checkedExp.destType.refCount++;
7535 checkedExp.type = opExp;
7536 checkedExp.op.op = '&';
7537 checkedExp.op.exp1 = null;
7538 checkedExp.op.exp2 = operand;
7540 //newExp = MkExpOp(null, '&', checkedExp);
7542 //ReplaceExpContents(checkedExp, newExp);
7549 // If expression type is a simple class, make it an address
7550 // FixReference(e, true);
7553 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7554 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7555 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7557 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"))
7559 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7563 Expression thisExp { };
7566 thisExp.prev = null;
7567 thisExp.next = null;
7570 e.type = bracketsExp;
7571 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7572 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7573 ((Expression)e.list->first).byReference = true;
7575 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7577 e.expType = thisExp.expType;
7578 e.expType.refCount++;
7583 CopyTypeInto(e.expType, thisExp.expType);
7584 e.expType.byReference = false;
7585 e.expType.refCount = 1;
7587 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7588 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7590 e.expType.classObjectType = none;
7595 // TOFIX: Try this for a nice IDE crash!
7597 // The other way around
7600 if(destType && e.expType &&
7601 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7602 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7603 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7605 if(destType.kind == ellipsisType)
7607 Compiler_Error($"Unspecified type\n");
7609 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7611 bool byReference = e.expType.byReference;
7612 Expression thisExp { };
7614 OldList * specs = MkList();
7615 char typeString[1024]; // Watch buffer overruns
7617 ClassObjectType backupClassObjectType;
7618 bool backupByReference;
7620 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7625 backupClassObjectType = type.classObjectType;
7626 backupByReference = type.byReference;
7628 type.classObjectType = none;
7629 type.byReference = false;
7631 typeString[0] = '\0';
7632 PrintType(type, typeString, false, true);
7633 decl = SpecDeclFromString(typeString, specs, null);
7635 type.classObjectType = backupClassObjectType;
7636 type.byReference = backupByReference;
7639 thisExp.prev = null;
7640 thisExp.next = null;
7643 if( ( type.kind == classType && type._class && type._class.registered &&
7644 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7645 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7646 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7647 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7649 bool passAsTemplate = thisExp.destType.passAsTemplate;
7652 destType.refCount++;
7657 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7660 CopyTypeInto(t, thisExp.destType);
7661 t.passAsTemplate = false;
7662 FreeType(thisExp.destType);
7663 thisExp.destType = t;
7666 CopyTypeInto(t, destType);
7667 t.passAsTemplate = passAsTemplate;
7670 destType.refCount = 0;
7673 CopyTypeInto(e.expType, type);
7674 if(type.passAsTemplate)
7676 e.expType.classObjectType = none;
7677 e.expType.passAsTemplate = false;
7679 e.expType.byReference = false;
7680 e.expType.refCount = 1;
7685 e.cast.typeName = MkTypeName(specs, decl);
7686 e.cast.exp = thisExp;
7687 e.byReference = true;
7693 FreeType(e.destType);
7695 e.destType = destType;
7696 destType.refCount++;
7701 void ApplyLocation(Expression exp, Location loc)
7707 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7708 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7714 for(e = exp.list->first; e; e = e.next)
7715 ApplyLocation(e, loc);
7722 for(e = exp.index.index->first; e; e = e.next)
7723 ApplyLocation(e, loc);
7726 ApplyLocation(exp.index.exp, loc);
7729 if(exp.call.arguments)
7732 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7733 ApplyLocation(arg, loc);
7736 ApplyLocation(exp.call.exp, loc);
7741 ApplyLocation(exp.member.exp, loc);
7745 ApplyLocation(exp.cast.exp, loc);
7751 for(e = exp.cond.exp->first; e; e = e.next)
7752 ApplyLocation(e, loc);
7755 ApplyLocation(exp.cond.cond, loc);
7756 if(exp.cond.elseExp)
7757 ApplyLocation(exp.cond.elseExp, loc);
7761 ApplyLocation(exp.vaArg.exp, loc);
7768 void ProcessExpressionType(Expression exp)
7770 bool unresolved = false;
7771 Location oldyylloc = yylloc;
7772 bool notByReference = false;
7774 char debugExpString[4096];
7775 debugExpString[0] = '\0';
7776 PrintExpression(exp, debugExpString);
7778 if(!exp || exp.expType)
7781 //eSystem_Logf("%s\n", expString);
7783 // Testing this here
7789 Identifier id = exp.identifier;
7790 if(!id || !topContext) return;
7792 // DOING THIS LATER NOW...
7793 if(id._class && id._class.name)
7795 id.classSym = id._class.symbol; // FindClass(id._class.name);
7796 /* TODO: Name Space Fix ups
7798 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7802 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7804 exp.expType = ProcessTypeString("Module", true);
7808 if(!strcmp(id.string, "__runtimePlatform"))
7810 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7813 else if(strstr(id.string, "__ecereClass") == id.string)
7815 exp.expType = ProcessTypeString("ecere::com::Class", true);
7818 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7820 // Added this here as well
7821 ReplaceClassMembers(exp, thisClass);
7822 if(exp.type != identifierExp)
7824 ProcessExpressionType(exp);
7828 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7833 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7834 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7835 if(!symbol/* && exp.destType*/)
7837 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7843 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7844 if(exp.type != identifierExp)
7846 ProcessExpressionType(exp);
7850 // Static methods called from inside the _class
7851 else if(currentClass && !id._class)
7853 if(ResolveIdWithClass(exp, currentClass, true))
7856 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7860 // If we manage to resolve this symbol
7863 Type type = symbol.type;
7864 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7866 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7868 Context context = SetupTemplatesContext(_class);
7869 type = ReplaceThisClassType(_class);
7870 FinishTemplatesContext(context);
7871 if(type) type.refCount = 0; // We'll be incrementing it right below...
7874 FreeSpecifier(id._class);
7877 id.string = CopyString(symbol.string);
7884 // Commented this out, it was making non-constant enum parameters seen as constant
7885 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7886 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7887 // Add missing cases here... enum Classes...
7888 exp.isConstant = true;
7890 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7891 if(symbol.isParam || !strcmp(id.string, "this"))
7893 if(_class && _class.type == structClass && !type.declaredWithStruct)
7894 exp.byReference = true;
7896 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7897 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7898 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7899 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7901 Identifier id = exp.identifier;
7902 exp.type = bracketsExp;
7903 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7907 if(symbol.isIterator)
7909 if(symbol.isIterator == 3)
7911 exp.type = bracketsExp;
7912 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7913 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7915 ProcessExpressionType(exp);
7917 else if(symbol.isIterator != 4)
7919 exp.type = memberExp;
7920 exp.member.exp = MkExpIdentifier(exp.identifier);
7921 exp.member.exp.expType = exp.expType;
7922 /*if(symbol.isIterator == 6)
7923 exp.member.member = MkIdentifier("key");
7925 exp.member.member = MkIdentifier("data");
7927 ProcessExpressionType(exp);
7934 DefinedExpression definedExp = null;
7935 if(thisNameSpace && !(id._class && !id._class.name))
7938 strcpy(name, thisNameSpace);
7940 strcat(name, id.string);
7941 definedExp = eSystem_FindDefine(privateModule, name);
7944 definedExp = eSystem_FindDefine(privateModule, id.string);
7948 for(c = 0; c<definedExpStackPos; c++)
7949 if(definedExpStack[c] == definedExp)
7951 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7953 Location backupYylloc = yylloc;
7954 File backInput = fileInput;
7955 definedExpStack[definedExpStackPos++] = definedExp;
7957 fileInput = TempFile { };
7958 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7959 fileInput.Seek(0, start);
7962 parsedExpression = null;
7964 expression_yyparse();
7967 fileInput = backInput;
7969 yylloc = backupYylloc;
7971 if(parsedExpression)
7974 exp.type = bracketsExp;
7975 exp.list = MkListOne(parsedExpression);
7976 ApplyLocation(parsedExpression, yylloc);
7977 ProcessExpressionType(exp);
7978 definedExpStackPos--;
7981 definedExpStackPos--;
7987 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7993 GlobalData data = null;
7994 if(thisNameSpace && !(id._class && !id._class.name))
7997 strcpy(name, thisNameSpace);
7999 strcat(name, id.string);
8000 data = FindGlobalData(name);
8003 data = FindGlobalData(id.string);
8006 DeclareGlobalData(curExternal, data);
8007 exp.expType = data.dataType;
8008 if(data.dataType) data.dataType.refCount++;
8011 id.string = CopyString(data.fullName);
8012 FreeSpecifier(id._class);
8019 GlobalFunction function = null;
8020 if(thisNameSpace && !(id._class && !id._class.name))
8023 strcpy(name, thisNameSpace);
8025 strcat(name, id.string);
8026 function = eSystem_FindFunction(privateModule, name);
8029 function = eSystem_FindFunction(privateModule, id.string);
8034 id.string = CopyString(function.name);
8037 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8038 strcpy(name, "__ecereFunction_");
8039 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8040 if(DeclareFunction(curExternal, function, name))
8043 id.string = CopyString(name);
8045 exp.expType = function.dataType;
8046 if(function.dataType) function.dataType.refCount++;
8048 FreeSpecifier(id._class);
8065 if(!exp.instance._class)
8067 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8069 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8073 //classSym = FindClass(exp.instance._class.fullName);
8074 //_class = classSym ? classSym.registered : null;
8076 ProcessInstantiationType(exp.instance);
8078 exp.isConstant = exp.instance.isConstant;
8081 if(_class.type == unitClass && _class.base.type != systemClass)
8084 Type destType = exp.destType;
8086 exp.destType = MkClassType(_class.base.fullName);
8087 exp.expType = MkClassType(_class.fullName);
8088 CheckExpressionType(exp, exp.destType, true);
8090 exp.destType = destType;
8092 exp.expType = MkClassType(_class.fullName);
8095 if(exp.instance._class)
8097 exp.expType = MkClassType(exp.instance._class.name);
8098 /*if(exp.expType._class && exp.expType._class.registered &&
8099 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8100 exp.expType.byReference = true;*/
8108 char * constant = exp.constant;
8116 if(constant[0] == '\'')
8118 if((int)((byte *)constant)[1] > 127)
8121 unichar ch = UTF8GetChar(constant + 1, &nb);
8122 if(nb < 2) ch = constant[1];
8124 exp.constant = PrintUInt(ch);
8125 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8126 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8127 type._class = FindClass("unichar");
8129 type.isSigned = false;
8133 type.kind = charType;
8134 type.isSigned = true;
8139 char * dot = strchr(constant, '.');
8140 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8144 exponent = strchr(constant, 'p');
8145 if(!exponent) exponent = strchr(constant, 'P');
8149 exponent = strchr(constant, 'e');
8150 if(!exponent) exponent = strchr(constant, 'E');
8155 if(strchr(constant, 'f') || strchr(constant, 'F'))
8156 type.kind = floatType;
8158 type.kind = doubleType;
8159 type.isSigned = true;
8163 bool isSigned = constant[0] == '-';
8165 int64 i64 = strtoll(constant, &endP, 0);
8166 uint64 ui64 = strtoull(constant, &endP, 0);
8167 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8168 bool forceUnsigned = endP && (!strcmp(endP, "U") || !strcmp(endP, "u") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8181 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8185 else if(constant[0] != '0' || !constant[1])
8190 type.kind = is64Bit ? int64Type : intType;
8191 type.isSigned = isSigned;
8194 exp.isConstant = true;
8195 if(exp.destType && exp.destType.kind == doubleType)
8196 type.kind = doubleType;
8197 else if(exp.destType && exp.destType.kind == floatType)
8198 type.kind = floatType;
8199 else if(exp.destType && exp.destType.kind == int64Type)
8200 type.kind = int64Type;
8206 exp.isConstant = true; // Why wasn't this constant?
8214 kind = exp.wideString ? shortType : charType;
8216 isSigned = exp.wideString ? false : true;
8223 ProcessExpressionType(exp._new.size);
8228 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8230 DeclareType(curExternal, exp.expType.type, true, false);
8234 ProcessExpressionType(exp._renew.size);
8235 ProcessExpressionType(exp._renew.exp);
8240 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8242 DeclareType(curExternal, exp.expType.type, true, false);
8246 bool assign = false, boolResult = false, boolOps = false;
8247 Type type1 = null, type2 = null;
8248 bool useDestType = false, useSideType = false;
8249 Location oldyylloc = yylloc;
8250 bool useSideUnit = false;
8251 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8253 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8262 // Assignment Operators
8276 // boolean Operators
8278 // Expect boolean operators
8280 //boolResult = true;
8284 // Expect boolean operands
8295 // Gives boolean result
8308 // useSideType = true;
8309 // useDestType = true;
8327 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8333 /*// Implement speed etc.
8339 if(exp.op.op == '&')
8341 // Added this here earlier for Iterator address as key
8342 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8344 Identifier id = exp.op.exp2.identifier;
8345 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8346 if(symbol && symbol.isIterator == 2)
8348 exp.type = memberExp;
8349 exp.member.exp = exp.op.exp2;
8350 exp.member.member = MkIdentifier("key");
8352 exp.op.exp2.expType = symbol.type;
8353 symbol.type.refCount++;
8354 ProcessExpressionType(exp);
8358 // exp.op.exp2.usage.usageRef = true;
8362 //dummy.kind = TypeDummy;
8365 // Added this check here to use the dest type only for units derived from the base unit
8366 // So that untyped units will use the side unit as opposed to the untyped destination unit
8367 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8368 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8369 useDestType = false;
8371 if(destClass && useDestType &&
8372 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8374 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8376 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8377 exp.op.exp1.destType = exp.destType;
8378 exp.op.exp1.opDestType = true;
8380 exp.destType.refCount++;
8384 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8385 exp.op.exp1.destType = dummy;
8389 // TESTING THIS HERE...
8390 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8391 ProcessExpressionType(exp.op.exp1);
8392 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8394 exp.op.exp1.opDestType = false;
8396 // Fix for unit and ++ / --
8397 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8398 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8400 exp.op.exp2 = MkExpConstant("1");
8401 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8405 if(exp.op.exp1.destType == dummy)
8408 exp.op.exp1.destType = null;
8413 if(!assign && exp.op.exp1.expType && (exp.op.exp1.expType.kind == charType || exp.op.exp1.expType.kind == shortType))
8415 Type type { kind = intType, isSigned = true, refCount = 1, signedBeforePromotion = exp.op.exp1.expType.isSigned, bitMemberSize = exp.op.exp1.expType.bitMemberSize, promotedFrom = exp.op.exp1.expType.kind };
8416 FreeType(exp.op.exp1.expType);
8417 exp.op.exp1.expType = type;
8421 type1 = exp.op.exp1.expType;
8426 char expString[10240];
8427 expString[0] = '\0';
8428 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8432 exp.op.exp2.destType = exp.op.exp1.expType;
8433 if(exp.op.exp1.expType)
8434 exp.op.exp1.expType.refCount++;
8438 exp.op.exp2.destType = exp.destType;
8439 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8440 exp.op.exp2.opDestType = true;
8442 exp.destType.refCount++;
8445 if(type1) type1.refCount++;
8446 exp.expType = type1;
8451 PrintExpression(exp.op.exp2, expString);
8453 if(type1 && type1.kind == pointerType)
8455 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 ||
8456 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8457 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8458 else if(exp.op.op == '=')
8460 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8461 exp.op.exp2.destType = type1;
8468 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8469 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/* ||
8470 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8473 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8474 exp.op.exp2.destType = type1;
8479 if(type1) type1.refCount++;
8480 exp.expType = type1;
8482 else if(destClass &&
8483 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8484 (destClass.type == enumClass && useDestType)))
8486 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8487 exp.op.exp2.destType = exp.destType;
8488 if(exp.op.op != '&' && exp.op.op != '^')
8489 exp.op.exp2.opDestType = true;
8491 exp.destType.refCount++;
8495 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8496 exp.op.exp2.destType = dummy;
8500 // TESTING THIS HERE... (DANGEROUS)
8501 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8502 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8504 FreeType(exp.op.exp2.destType);
8505 exp.op.exp2.destType = type1;
8508 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8509 // Cannot lose the cast on a sizeof
8510 if(exp.op.op == SIZEOF)
8512 Expression e = exp.op.exp2;
8513 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8515 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8517 if(e.type == extensionCompoundExp)
8518 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8523 if(e.type == castExp && e.cast.exp)
8524 e.cast.exp.needCast = true;
8526 ProcessExpressionType(exp.op.exp2);
8527 exp.op.exp2.opDestType = false;
8528 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8530 if(!assign && (exp.op.exp1 || exp.op.op == '~'))
8532 if(exp.op.exp2.expType && (exp.op.exp2.expType.kind == charType || exp.op.exp2.expType.kind == shortType))
8534 Type type { kind = intType, isSigned = true, refCount = 1, signedBeforePromotion = exp.op.exp2.expType.isSigned, bitMemberSize = exp.op.exp2.expType.bitMemberSize, promotedFrom = exp.op.exp2.expType.kind };
8535 FreeType(exp.op.exp2.expType);
8536 exp.op.exp2.expType = type;
8540 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8542 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)
8544 if(exp.op.op != '=' && type1.type.kind == voidType)
8545 Compiler_Error($"void *: unknown size\n");
8547 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||
8548 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8549 (exp.op.exp2.expType._class.registered.type == normalClass ||
8550 exp.op.exp2.expType._class.registered.type == structClass ||
8551 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8553 if(exp.op.op == ADD_ASSIGN)
8554 Compiler_Error($"cannot add two pointers\n");
8556 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8557 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8559 if(exp.op.op == ADD_ASSIGN)
8560 Compiler_Error($"cannot add two pointers\n");
8564 char type1String[1024];
8565 char type2String[1024];
8566 type1String[0] = '\0';
8567 type2String[0] = '\0';
8569 PrintType(exp.op.exp2.expType, type1String, false, true);
8570 PrintType(type1, type2String, false, true);
8571 ChangeCh(expString, '\n', ' ');
8572 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8576 if(exp.op.exp2.destType == dummy)
8579 exp.op.exp2.destType = null;
8582 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8586 CopyTypeInto(type2, exp.op.exp2.expType);
8587 type2.isSigned = true;
8589 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8591 type2 = { kind = intType };
8593 type2.isSigned = true;
8597 type2 = exp.op.exp2.expType;
8598 if(type2) type2.refCount++;
8602 dummy.kind = voidType;
8604 if(exp.op.op == SIZEOF)
8611 exp.isConstant = true;
8613 // Get type of dereferenced pointer
8614 else if(exp.op.op == '*' && !exp.op.exp1)
8616 exp.expType = Dereference(type2);
8617 if(type2 && type2.kind == classType)
8618 notByReference = true;
8620 else if(exp.op.op == '&' && !exp.op.exp1)
8621 exp.expType = Reference(type2);
8622 else if(exp.op.op == LEFT_OP || exp.op.op == RIGHT_OP)
8624 if(exp.op.exp1.expType)
8626 exp.expType = exp.op.exp1.expType;
8627 exp.expType.refCount++;
8636 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8637 exp.op.exp1.destType = MkClassType("bool");
8638 exp.op.exp1.destType.truth = true;
8639 if(!exp.op.exp1.expType)
8640 ProcessExpressionType(exp.op.exp1);
8642 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8643 FreeType(exp.op.exp1.expType);
8644 exp.op.exp1.expType = MkClassType("bool");
8645 exp.op.exp1.expType.truth = true;
8649 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8650 exp.op.exp2.destType = MkClassType("bool");
8651 exp.op.exp2.destType.truth = true;
8652 if(!exp.op.exp2.expType)
8653 ProcessExpressionType(exp.op.exp2);
8655 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8656 FreeType(exp.op.exp2.expType);
8657 exp.op.exp2.expType = MkClassType("bool");
8658 exp.op.exp2.expType.truth = true;
8661 else if(exp.op.exp1 && exp.op.exp2 &&
8664 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8665 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8666 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8667 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8669 if(type1 && type2 &&
8670 // If either both are class or both are not class
8671 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8673 // Added this check for enum subtraction to result in an int type:
8674 if(exp.op.op == '-' &&
8675 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8676 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8679 if(!type1._class.registered.dataType)
8680 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8681 if(!type2._class.registered.dataType)
8682 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8684 intType = ProcessTypeString(
8685 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8687 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8688 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8689 exp.op.exp1.destType = intType;
8690 exp.op.exp2.destType = intType;
8695 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8696 exp.op.exp2.destType = type1;
8698 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8699 exp.op.exp1.destType = type2;
8703 // Warning here for adding Radians + Degrees with no destination type
8704 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8705 type1._class.registered && type1._class.registered.type == unitClass &&
8706 type2._class.registered && type2._class.registered.type == unitClass &&
8707 type1._class.registered != type2._class.registered)
8708 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8709 type1._class.string, type2._class.string, type1._class.string);
8711 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8713 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8716 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8718 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8719 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8722 ProcessExpressionType(exp.op.exp1);
8724 if(type2.kind != pointerType)
8726 ProcessExpressionType(classExp);
8728 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8730 if(!exp.op.exp2.expType)
8734 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8738 ProcessExpressionType(exp.op.exp2);
8743 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)))
8745 if(type1.kind != classType && type1.type.kind == voidType)
8746 Compiler_Error($"void *: unknown size\n");
8747 exp.expType = type1;
8748 if(type1) type1.refCount++;
8750 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)))
8752 if(type2.kind != classType && type2.type.kind == voidType)
8753 Compiler_Error($"void *: unknown size\n");
8754 exp.expType = type2;
8755 if(type2) type2.refCount++;
8757 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8758 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8760 Compiler_Warning($"different levels of indirection\n");
8764 bool success = false;
8765 if(type1.kind == pointerType && type2.kind == pointerType)
8767 if(exp.op.op == '+')
8768 Compiler_Error($"cannot add two pointers\n");
8769 else if(exp.op.op == '-')
8771 // Pointer Subtraction gives integer
8772 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8781 if(type1.type.kind == templateType)
8783 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8786 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8788 ProcessExpressionType(classExp);
8790 exp.type = bracketsExp;
8791 exp.list = MkListOne(MkExpOp(
8792 MkExpBrackets(MkListOne(MkExpOp(
8793 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8795 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8796 MkExpMember(classExp, MkIdentifier("typeSize"))));
8798 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8807 if(!success && exp.op.exp1.type == constantExp)
8809 // If first expression is constant, try to match that first
8810 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8812 if(exp.expType) FreeType(exp.expType);
8813 exp.expType = exp.op.exp1.destType;
8814 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8817 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8819 if(exp.expType) FreeType(exp.expType);
8820 exp.expType = exp.op.exp2.destType;
8821 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8827 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8829 if(exp.expType) FreeType(exp.expType);
8830 exp.expType = exp.op.exp2.destType;
8831 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8834 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8836 if(exp.expType) FreeType(exp.expType);
8837 exp.expType = exp.op.exp1.destType;
8838 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8844 char expString1[10240];
8845 char expString2[10240];
8848 expString1[0] = '\0';
8849 expString2[0] = '\0';
8854 PrintExpression(exp.op.exp1, expString1);
8855 ChangeCh(expString1, '\n', ' ');
8856 PrintExpression(exp.op.exp2, expString2);
8857 ChangeCh(expString2, '\n', ' ');
8858 PrintType(exp.op.exp1.expType, type1, false, true);
8859 PrintType(exp.op.exp2.expType, type2, false, true);
8862 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8866 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8867 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8869 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8870 // Convert e.g. / 4 into / 4.0
8871 exp.op.exp1.destType = type2._class.registered.dataType;
8872 if(type2._class.registered.dataType)
8873 type2._class.registered.dataType.refCount++;
8874 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8875 exp.expType = type2;
8876 if(type2) type2.refCount++;
8878 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8880 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8881 // Convert e.g. / 4 into / 4.0
8882 exp.op.exp2.destType = type1._class.registered.dataType;
8883 if(type1._class.registered.dataType)
8884 type1._class.registered.dataType.refCount++;
8885 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8886 exp.expType = type1;
8887 if(type1) type1.refCount++;
8893 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8895 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8897 if(!type1._class.registered.dataType)
8898 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8899 exp.op.exp2.destType = type1._class.registered.dataType;
8900 exp.op.exp2.destType.refCount++;
8902 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8905 type2 = exp.op.exp2.destType;
8906 if(type2) type2.refCount++;
8908 exp.expType = type2;
8912 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8914 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8916 if(!type2._class.registered.dataType)
8917 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8918 exp.op.exp1.destType = type2._class.registered.dataType;
8919 exp.op.exp1.destType.refCount++;
8921 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8922 type1 = exp.op.exp1.destType;
8923 exp.expType = type1;
8927 // TESTING THIS NEW CODE
8928 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8930 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8931 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8932 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8934 // Convert the enum to an int instead for these operators
8935 if(op1IsEnum && exp.op.exp2.expType)
8937 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8939 if(exp.expType) FreeType(exp.expType);
8940 exp.expType = exp.op.exp2.expType;
8941 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8945 else if(op2IsEnum && exp.op.exp1.expType)
8947 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8949 if(exp.expType) FreeType(exp.expType);
8950 exp.expType = exp.op.exp1.expType;
8951 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8958 if(op1IsEnum && exp.op.exp2.expType)
8960 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8962 if(exp.expType) FreeType(exp.expType);
8963 exp.expType = exp.op.exp1.expType;
8964 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8968 else if(op2IsEnum && exp.op.exp1.expType)
8970 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8972 if(exp.expType) FreeType(exp.expType);
8973 exp.expType = exp.op.exp2.expType;
8974 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8983 // Added this first part of the if here to handle 5 + Degrees { 5 } with either a base unit dest or not a unit dest type
8984 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8985 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8987 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8988 exp.op.exp1.destType = type2;
8991 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8993 if(exp.expType) FreeType(exp.expType);
8994 exp.expType = exp.op.exp1.destType;
8995 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9000 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9001 exp.op.exp2.destType = type1;
9005 // Maybe this was meant to be an enum...
9006 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9008 Type oldType = exp.op.exp2.expType;
9009 exp.op.exp2.expType = null;
9010 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9013 exp.op.exp2.expType = oldType;
9018 // TESTING THIS HERE... LATEST ADDITION
9019 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9021 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9022 exp.op.exp2.destType = type2._class.registered.dataType;
9023 if(type2._class.registered.dataType)
9024 type2._class.registered.dataType.refCount++;
9025 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9027 //exp.expType = type2._class.registered.dataType; //type2;
9028 //if(type2) type2.refCount++;
9031 // TESTING THIS HERE... LATEST ADDITION
9032 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9034 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9035 exp.op.exp1.destType = type1._class.registered.dataType;
9036 if(type1._class.registered.dataType)
9037 type1._class.registered.dataType.refCount++;
9038 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9039 exp.expType = type1._class.registered.dataType; //type1;
9040 if(type1) type1.refCount++;
9044 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9046 if(exp.expType) FreeType(exp.expType);
9047 exp.expType = exp.op.exp2.destType;
9048 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9050 else if(type1 && type2)
9052 char expString1[10240];
9053 char expString2[10240];
9054 char type1String[1024];
9055 char type2String[1024];
9056 expString1[0] = '\0';
9057 expString2[0] = '\0';
9058 type1String[0] = '\0';
9059 type2String[0] = '\0';
9062 PrintExpression(exp.op.exp1, expString1);
9063 ChangeCh(expString1, '\n', ' ');
9064 PrintExpression(exp.op.exp2, expString2);
9065 ChangeCh(expString2, '\n', ' ');
9066 PrintType(exp.op.exp1.expType, type1String, false, true);
9067 PrintType(exp.op.exp2.expType, type2String, false, true);
9070 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9072 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9074 exp.expType = exp.op.exp1.expType;
9075 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9077 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9079 exp.expType = exp.op.exp2.expType;
9080 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9088 // Maybe this was meant to be an enum...
9089 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9091 Type oldType = exp.op.exp1.expType;
9092 exp.op.exp1.expType = null;
9093 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9096 exp.op.exp1.expType = oldType;
9099 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9100 exp.op.exp1.destType = type2;
9103 // TESTING THIS HERE... LATEST ADDITION
9104 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9106 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9107 exp.op.exp1.destType = type1._class.registered.dataType;
9108 if(type1._class.registered.dataType)
9109 type1._class.registered.dataType.refCount++;
9112 // TESTING THIS HERE... LATEST ADDITION
9113 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9115 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9116 exp.op.exp2.destType = type2._class.registered.dataType;
9117 if(type2._class.registered.dataType)
9118 type2._class.registered.dataType.refCount++;
9122 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9124 if(exp.expType) FreeType(exp.expType);
9125 exp.expType = exp.op.exp1.destType;
9126 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9130 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9132 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9134 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9135 // Convert e.g. / 4 into / 4.0
9136 exp.op.exp1.destType = type2._class.registered.dataType;
9137 if(type2._class.registered.dataType)
9138 type2._class.registered.dataType.refCount++;
9139 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9141 if(exp.op.op == '!')
9143 exp.expType = MkClassType("bool");
9144 exp.expType.truth = true;
9148 exp.expType = type2;
9149 if(type2) type2.refCount++;
9152 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9154 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9156 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9157 // Convert e.g. / 4 into / 4.0
9158 exp.op.exp2.destType = type1._class.registered.dataType;
9159 if(type1._class.registered.dataType)
9160 type1._class.registered.dataType.refCount++;
9161 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9163 exp.expType = type1;
9164 if(type1) type1.refCount++;
9169 if(exp.op.exp1 && !exp.op.exp1.expType)
9171 char expString[10000];
9172 expString[0] = '\0';
9175 PrintExpression(exp.op.exp1, expString);
9176 ChangeCh(expString, '\n', ' ');
9179 Compiler_Error($"couldn't determine type of %s\n", expString);
9181 if(exp.op.exp2 && !exp.op.exp2.expType)
9183 char expString[10240];
9184 expString[0] = '\0';
9187 PrintExpression(exp.op.exp2, expString);
9188 ChangeCh(expString, '\n', ' ');
9191 Compiler_Error($"couldn't determine type of %s\n", expString);
9196 FreeType(exp.expType);
9197 exp.expType = MkClassType("bool");
9198 exp.expType.truth = true;
9201 if(exp.op.op != SIZEOF)
9202 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9203 (!exp.op.exp2 || exp.op.exp2.isConstant);
9205 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9207 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9210 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9211 Compiler_Warning($"deleting const qualified object\n");
9221 case extensionExpressionExp:
9224 exp.isConstant = true;
9225 for(e = exp.list->first; e; e = e.next)
9227 //bool inced = false;
9230 FreeType(e.destType);
9231 e.opDestType = exp.opDestType;
9232 e.destType = exp.destType;
9233 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9235 ProcessExpressionType(e);
9237 exp.destType.count--;*/
9238 if(!exp.expType && !e.next)
9240 exp.expType = e.expType;
9241 if(e.expType) e.expType.refCount++;
9244 exp.isConstant = false;
9247 // In case a cast became a member...
9248 e = exp.list->first;
9249 if(!e.next && e.type == memberExp)
9251 // Preserve prev, next
9252 Expression next = exp.next, prev = exp.prev;
9255 FreeType(exp.expType);
9256 FreeType(exp.destType);
9266 ProcessExpressionType(exp);
9273 exp.isConstant = true;
9275 ProcessExpressionType(exp.index.exp);
9276 if(!exp.index.exp.isConstant)
9277 exp.isConstant = false;
9279 if(exp.index.exp.expType)
9281 Type source = exp.index.exp.expType;
9282 if(source.kind == classType && source._class && source._class.registered)
9284 Class _class = source._class.registered;
9285 Class c = _class.templateClass ? _class.templateClass : _class;
9286 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9288 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9290 if(exp.index.index && exp.index.index->last)
9292 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9294 if(type.kind == classType) type.constant = true;
9295 else if(type.kind == pointerType)
9298 while(t.kind == pointerType) t = t.type;
9302 ((Expression)exp.index.index->last).destType = type;
9308 for(e = exp.index.index->first; e; e = e.next)
9310 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9312 if(e.destType) FreeType(e.destType);
9313 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9315 ProcessExpressionType(e);
9318 // Check if this type is int
9321 exp.isConstant = false;
9325 exp.expType = Dereference(exp.index.exp.expType);
9327 DeclareType(curExternal, exp.expType, true, false);
9334 Type methodType = null;
9340 PrintExpression(exp.call.exp, name);
9341 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9343 //exp.call.exp.expType = null;
9344 PrintExpression(exp.call.exp, name);
9347 if(exp.call.exp.type == identifierExp)
9349 Expression idExp = exp.call.exp;
9350 Identifier id = idExp.identifier;
9351 if(!strcmp(id.string, "__builtin_frame_address"))
9353 exp.expType = ProcessTypeString("void *", true);
9354 if(exp.call.arguments && exp.call.arguments->first)
9355 ProcessExpressionType(exp.call.arguments->first);
9358 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9360 exp.expType = ProcessTypeString("int", true);
9361 if(exp.call.arguments && exp.call.arguments->first)
9362 ProcessExpressionType(exp.call.arguments->first);
9365 else if(!strcmp(id.string, "Max") ||
9366 !strcmp(id.string, "Min") ||
9367 !strcmp(id.string, "Sgn") ||
9368 !strcmp(id.string, "Abs"))
9370 Expression a = null;
9371 Expression b = null;
9372 Expression tempExp1 = null, tempExp2 = null;
9373 if((!strcmp(id.string, "Max") ||
9374 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9376 a = exp.call.arguments->first;
9377 b = exp.call.arguments->last;
9381 else if(exp.call.arguments->count == 1)
9383 a = exp.call.arguments->first;
9389 exp.call.arguments->Clear();
9390 idExp.identifier = null;
9392 FreeExpContents(exp);
9394 ProcessExpressionType(a);
9396 ProcessExpressionType(b);
9398 exp.type = bracketsExp;
9399 exp.list = MkList();
9401 if(a.expType && (!b || b.expType))
9403 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9405 // Use the simpleStruct name/ids for now...
9408 OldList * specs = MkList();
9409 OldList * decls = MkList();
9411 char temp1[1024], temp2[1024];
9413 GetTypeSpecs(a.expType, specs);
9415 if(a && !a.isConstant && a.type != identifierExp)
9417 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9418 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9419 tempExp1 = QMkExpId(temp1);
9420 tempExp1.expType = a.expType;
9422 a.expType.refCount++;
9423 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9425 if(b && !b.isConstant && b.type != identifierExp)
9427 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9428 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9429 tempExp2 = QMkExpId(temp2);
9430 tempExp2.expType = b.expType;
9432 b.expType.refCount++;
9433 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9436 decl = MkDeclaration(specs, decls);
9437 if(!curCompound.compound.declarations)
9438 curCompound.compound.declarations = MkList();
9439 curCompound.compound.declarations->Insert(null, decl);
9444 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9446 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9448 MkExpCondition(MkExpBrackets(MkListOne(
9449 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9450 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9451 exp.expType = a.expType;
9453 a.expType.refCount++;
9455 else if(!strcmp(id.string, "Abs"))
9458 MkExpCondition(MkExpBrackets(MkListOne(
9459 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9460 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9461 exp.expType = a.expType;
9463 a.expType.refCount++;
9465 else if(!strcmp(id.string, "Sgn"))
9467 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9469 MkExpCondition(MkExpBrackets(MkListOne(
9470 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9471 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9472 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9473 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9474 exp.expType = ProcessTypeString("int", false);
9477 FreeExpression(tempExp1);
9478 if(tempExp2) FreeExpression(tempExp2);
9492 if(!exp.call.exp.destType)
9494 exp.call.exp.destType = dummy;
9497 ProcessExpressionType(exp.call.exp);
9498 if(exp.call.exp.destType == dummy)
9501 exp.call.exp.destType = null;
9506 // Check argument types against parameter types
9507 functionType = exp.call.exp.expType;
9509 if(functionType && functionType.kind == TypeKind::methodType)
9511 methodType = functionType;
9512 functionType = methodType.method.dataType;
9514 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9515 // TOCHECK: Instead of doing this here could this be done per param?
9516 if(exp.call.exp.expType.usedClass)
9518 char typeString[1024];
9519 typeString[0] = '\0';
9521 Symbol back = functionType.thisClass;
9522 // Do not output class specifier here (thisclass was added to this)
9523 functionType.thisClass = null;
9524 PrintType(functionType, typeString, true, true);
9525 functionType.thisClass = back;
9527 if(strstr(typeString, "thisclass"))
9529 OldList * specs = MkList();
9532 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9534 decl = SpecDeclFromString(typeString, specs, null);
9536 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9537 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9538 exp.call.exp.expType.usedClass))
9539 thisClassParams = false;
9541 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9543 Class backupThisClass = thisClass;
9544 thisClass = exp.call.exp.expType.usedClass;
9545 ProcessDeclarator(decl, true);
9546 thisClass = backupThisClass;
9549 thisClassParams = true;
9551 functionType = ProcessType(specs, decl);
9552 functionType.refCount = 0;
9553 FinishTemplatesContext(context);
9555 // Mark parameters that were 'thisclass'
9558 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9560 //p.wasThisClass = op.kind == thisClassType;
9561 if(op.kind == thisClassType)
9562 p.thisClassFrom = methodType.method._class;
9565 if(methodType.method.dataType.returnType.kind == thisClassType)
9567 // functionType.returnType.wasThisClass = true;
9568 functionType.returnType.thisClassFrom = methodType.method._class;
9572 FreeList(specs, FreeSpecifier);
9573 FreeDeclarator(decl);
9577 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9579 Type type = functionType.type;
9580 if(!functionType.refCount)
9582 functionType.type = null;
9583 FreeType(functionType);
9585 //methodType = functionType;
9586 functionType = type;
9588 if(functionType && functionType.kind != TypeKind::functionType)
9590 Compiler_Error($"called object %s is not a function\n", name);
9592 else if(functionType)
9594 bool emptyParams = false, noParams = false;
9595 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9596 Type type = functionType.params.first;
9597 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9599 Location oldyylloc = yylloc;
9601 if(!type) emptyParams = true;
9604 if(functionType.extraParam && e && functionType.thisClass)
9606 e.destType = MkClassType(functionType.thisClass.string);
9610 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9611 // Fixed #141 by adding '&& !functionType.extraParam'
9612 if(!functionType.staticMethod && !functionType.extraParam)
9614 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9615 memberExp.member.exp.expType._class)
9617 type = MkClassType(memberExp.member.exp.expType._class.string);
9622 type = functionType.params.first;
9627 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9629 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9630 type.byReference = functionType.byReference;
9631 type.typedByReference = functionType.typedByReference;
9634 // Allow manually passing a class for typed object
9635 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9639 type = functionType.params.first;
9647 if(type && type.kind == voidType)
9650 if(!type.refCount) FreeType(type);
9654 for( ; e; e = e.next)
9656 if(!type && !emptyParams)
9659 if(methodType && methodType.methodClass)
9660 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9661 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9662 noParams ? 0 : functionType.params.count);
9664 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9665 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9666 noParams ? 0 : functionType.params.count);
9670 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9672 Type templatedType = null;
9673 Class _class = methodType.usedClass;
9674 ClassTemplateParameter curParam = null;
9676 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9679 for(sClass = _class; sClass; sClass = sClass.base)
9681 if(sClass.templateClass) sClass = sClass.templateClass;
9683 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9685 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9688 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9690 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9691 id += nextClass.templateParams.count;
9700 if(curParam && _class.templateArgs[id].dataTypeString)
9702 bool constant = type.constant;
9703 ClassTemplateArgument arg = _class.templateArgs[id];
9705 Context context = SetupTemplatesContext(_class);
9708 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9709 templatedType = ProcessTypeString(arg.dataTypeString, false);
9710 FinishTemplatesContext(context);
9713 if(templatedType.kind == classType && constant) templatedType.constant = true;
9714 else if(templatedType.kind == pointerType)
9716 Type t = templatedType.type;
9717 while(t.kind == pointerType) t = t.type;
9718 if(constant) t.constant = constant;
9721 e.destType = templatedType;
9724 templatedType.passAsTemplate = true;
9725 // templatedType.refCount++;
9731 if(type) type.refCount++;
9736 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9738 e.destType = type.prev;
9739 e.destType.refCount++;
9744 if(type) type.refCount++;
9747 // Don't reach the end for the ellipsis
9748 if(type && type.kind != ellipsisType)
9750 Type next = type.next;
9751 if(!type.refCount) FreeType(type);
9756 if(type && type.kind != ellipsisType)
9758 if(methodType && methodType.methodClass)
9759 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9760 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9761 functionType.params.count + extra);
9763 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9764 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9765 functionType.params.count + extra);
9768 if(type && !type.refCount) FreeType(type);
9775 kind = TypeKind::functionType;
9778 if(exp.call.exp.type == identifierExp)
9780 char * string = exp.call.exp.identifier.string;
9784 Location oldyylloc = yylloc;
9786 yylloc = exp.call.exp.identifier.loc;
9787 if(strstr(string, "__builtin_") == string)
9791 functionType.returnType = exp.destType;
9792 exp.destType.refCount++;
9796 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9797 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9798 globalContext.symbols.Add((BTNode)symbol);
9799 if(strstr(symbol.string, "::"))
9800 globalContext.hasNameSpace = true;
9805 else if(exp.call.exp.type == memberExp)
9807 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9808 exp.call.exp.member.member.string);*/
9811 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9813 if(!functionType.returnType)
9815 functionType.returnType = Type
9822 if(functionType && functionType.kind == TypeKind::functionType)
9824 exp.expType = functionType.returnType;
9826 if(functionType.returnType)
9827 functionType.returnType.refCount++;
9829 if(!functionType.refCount)
9830 FreeType(functionType);
9833 if(exp.call.arguments)
9835 for(e = exp.call.arguments->first; e; e = e.next)
9836 ProcessExpressionType(e);
9843 Location oldyylloc = yylloc;
9845 Expression checkExp = exp.member.exp;
9848 if(checkExp.type == castExp)
9849 checkExp = checkExp.cast.exp;
9850 else if(checkExp.type == bracketsExp)
9851 checkExp = checkExp.list ? checkExp.list->first : null;
9856 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9857 exp.thisPtr = thisPtr;
9859 // DOING THIS LATER NOW...
9860 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9862 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9863 /* TODO: Name Space Fix ups
9864 if(!exp.member.member.classSym)
9865 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9869 ProcessExpressionType(exp.member.exp);
9870 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9871 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9873 exp.isConstant = false;
9876 exp.isConstant = exp.member.exp.isConstant;
9877 type = exp.member.exp.expType;
9881 if(type && (type.kind == templateType))
9883 Class _class = thisClass ? thisClass : currentClass;
9884 ClassTemplateParameter param = null;
9887 for(param = _class.templateParams.first; param; param = param.next)
9889 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9893 if(param && param.defaultArg.member)
9895 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9898 Expression expMember = exp.member.exp;
9900 OldList * specs = MkList();
9901 char thisClassTypeString[1024];
9903 FreeIdentifier(exp.member.member);
9905 ProcessExpressionType(argExp);
9908 char * colon = strstr(param.defaultArg.memberString, "::");
9911 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9912 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9915 strcpy(thisClassTypeString, _class.fullName);
9918 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9920 exp.expType = ProcessType(specs, decl);
9921 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9923 Class expClass = exp.expType._class.registered;
9924 Class cClass = null;
9928 char templateString[1024];
9929 ClassTemplateParameter param;
9930 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9931 for(cClass = expClass; cClass; cClass = cClass.base)
9934 for(param = cClass.templateParams.first; param; param = param.next)
9938 ClassTemplateArgument arg;
9939 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9940 arg = expClass.templateArgs[id];
9942 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9944 ClassTemplateParameter cParam;
9945 //int p = numParams - sClass.templateParams.count;
9948 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9950 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9952 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9954 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9956 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9957 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9969 strcat(argument, arg.name.string);
9970 strcat(argument, " = ");
9976 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9977 char expString[1024];
9978 OldList * specs = MkList();
9979 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9981 char * string = PrintHexUInt64(arg.expression.ui64);
9982 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9985 ProcessExpressionType(exp);
9986 ComputeExpression(exp);
9987 expString[0] = '\0';
9988 PrintExpression(exp, expString);
9989 strcat(argument, expString);
9991 FreeExpression(exp);
9996 strcat(argument, arg.member.name);
9999 case TemplateParameterType::type:
10001 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10003 if(!strcmp(arg.dataTypeString, "thisclass"))
10004 strcat(argument, thisClassTypeString);
10006 strcat(argument, arg.dataTypeString);
10013 if(paramCount) strcat(templateString, ", ");
10014 if(lastParam != p - 1)
10016 strcat(templateString, param.name);
10017 strcat(templateString, " = ");
10019 strcat(templateString, argument);
10028 int len = strlen(templateString);
10029 if(templateString[len-1] == '>') templateString[len++] = ' ';
10030 templateString[len++] = '>';
10031 templateString[len++] = '\0';
10034 Context context = SetupTemplatesContext(_class);
10035 FreeType(exp.expType);
10036 exp.expType = ProcessTypeString(templateString, false);
10037 FinishTemplatesContext(context);
10041 if(!expMember.expType.isPointerType)
10042 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10043 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10044 exp.type = bracketsExp;
10045 exp.list = MkListOne(MkExpOp(null, '*',
10048 exp.op.exp1 = null;
10050 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10051 MkExpBrackets(MkListOne(
10052 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10055 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10057 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10062 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10063 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10065 type = ProcessTemplateParameterType(type.templateParameter);
10068 // TODO: *** This seems to be where we should add method support for all basic types ***
10069 if(type && (type.kind == templateType));
10070 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10071 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10072 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10073 (type.kind == pointerType && type.type.kind == charType)))
10075 Identifier id = exp.member.member;
10076 TypeKind typeKind = type.kind;
10077 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10078 if(typeKind == subClassType && exp.member.exp.type == classExp)
10080 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10081 typeKind = classType;
10086 if(typeKind == intType || typeKind == enumType)
10087 _class = eSystem_FindClass(privateModule, "int");
10090 if(type.kind == classType && type._class && type._class.registered)
10092 _class = type._class.registered;
10094 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10096 _class = FindClass("char *").registered;
10098 else if(type.kind == pointerType)
10100 _class = eSystem_FindClass(privateModule, "uintptr");
10101 FreeType(exp.expType);
10102 exp.expType = ProcessTypeString("uintptr", false);
10103 exp.byReference = true;
10107 char string[1024] = "";
10109 PrintTypeNoConst(type, string, false, true);
10110 classSym = FindClass(string);
10111 if(classSym) _class = classSym.registered;
10119 (exp.member.exp.type == identifierExp &&
10120 !strcmp(exp.member.exp.identifier.string, "this"));*/
10121 Property prop = null;
10122 Method method = null;
10123 DataMember member = null;
10124 Property revConvert = null;
10125 ClassProperty classProp = null;
10127 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10128 exp.member.memberType = propertyMember;
10130 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10131 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10133 if(typeKind != subClassType)
10135 // Prioritize data members over properties for "this"
10136 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10138 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10139 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10141 prop = eClass_FindProperty(_class, id.string, privateModule);
10145 if(!member && !prop)
10146 prop = eClass_FindProperty(_class, id.string, privateModule);
10147 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10148 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10149 exp.member.thisPtr = true;
10151 // Prioritize properties over data members otherwise
10154 bool useMemberForNonConst = false;
10155 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10158 prop = eClass_FindProperty(_class, id.string, null);
10160 useMemberForNonConst = prop && exp.destType &&
10161 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10162 !strncmp(prop.dataTypeString, "const ", 6);
10164 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10165 member = eClass_FindDataMember(_class, id.string, null, null, null);
10168 if((!prop || useMemberForNonConst) && !member)
10170 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10173 prop = eClass_FindProperty(_class, id.string, privateModule);
10175 useMemberForNonConst |= prop && exp.destType &&
10176 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10177 !strncmp(prop.dataTypeString, "const ", 6);
10179 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10180 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10186 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10193 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10194 method = eClass_FindMethod(_class, id.string, privateModule);
10195 if(!prop && !member && !method)
10197 if(typeKind == subClassType)
10199 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10202 exp.member.memberType = classPropertyMember;
10203 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10207 // Assume this is a class_data member
10208 char structName[1024];
10209 Identifier id = exp.member.member;
10210 Expression classExp = exp.member.exp;
10213 FreeType(classExp.expType);
10214 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10216 strcpy(structName, "__ecereClassData_");
10217 FullClassNameCat(structName, type._class.string, false);
10218 exp.type = pointerExp;
10219 exp.member.member = id;
10221 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10222 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10223 MkExpBrackets(MkListOne(MkExpOp(
10224 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10225 MkExpMember(classExp, MkIdentifier("data"))), '+',
10226 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10231 ProcessExpressionType(exp);
10237 // Check for reverse conversion
10238 // (Convert in an instantiation later, so that we can use
10239 // deep properties system)
10240 Symbol classSym = FindClass(id.string);
10243 Class convertClass = classSym.registered;
10245 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10250 //if(!exp.member.exp.destType)
10251 if(exp.member.exp.destType)
10252 FreeType(exp.member.exp.destType);
10254 if(method && !method._class.symbol)
10255 method._class.symbol = FindClass(method._class.fullName);
10256 if(prop && !prop._class.symbol)
10257 prop._class.symbol = FindClass(prop._class.fullName);
10259 exp.member.exp.destType = Type
10263 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10264 // wasThisClass = type ? type.wasThisClass : false;
10265 thisClassFrom = type ? type.thisClassFrom : null;
10271 exp.member.memberType = propertyMember;
10273 ProcessPropertyType(prop);
10274 exp.expType = prop.dataType;
10275 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10278 CopyTypeInto(type, exp.expType);
10280 type.constant = true;
10281 exp.expType = type;
10283 else if(prop.dataType)
10284 prop.dataType.refCount++;
10288 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10290 FreeExpContents(exp);
10291 exp.type = identifierExp;
10292 exp.identifier = MkIdentifier("class");
10293 ProcessExpressionType(exp);
10297 exp.member.memberType = dataMember;
10298 DeclareStruct(curExternal, _class.fullName, false, true);
10299 if(member._class != _class)
10300 DeclareStruct(curExternal, member._class.fullName, false, true);
10302 if(!member.dataType)
10304 Context context = SetupTemplatesContext(_class);
10305 member.dataType = ProcessTypeString(member.dataTypeString, false);
10306 FinishTemplatesContext(context);
10308 if(exp.member.exp.expType.kind == classType && exp.member.exp.expType._class && exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == bitClass)
10309 member.dataType.bitMemberSize = ((BitMember)member).size;
10310 exp.expType = member.dataType;
10311 if(member.dataType) member.dataType.refCount++;
10313 else if(revConvert)
10315 exp.member.memberType = reverseConversionMember;
10316 exp.expType = MkClassType(revConvert._class.fullName);
10324 exp.type = identifierExp;
10325 exp.identifier = exp.member.member;
10328 exp.member.memberType = methodMember;
10330 if(!method.dataType)
10331 ProcessMethodType(method);
10339 // Tricky spot here... To use instance versus class virtual table
10340 // Put it back to what it was... What did we break?
10342 // Had to put it back for overriding Main of Thread global instance
10344 //exp.expType.methodClass = _class;
10345 exp.expType.methodClass = (id && id._class) ? _class : null;
10347 // Need the actual class used for templated classes
10348 exp.expType.usedClass = _class;
10350 else if(!classProp)
10352 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10354 FreeExpContents(exp);
10355 exp.type = identifierExp;
10356 exp.identifier = MkIdentifier("class");
10357 FreeType(exp.expType);
10358 exp.expType = MkClassType("ecere::com::Class");
10361 yylloc = exp.member.member.loc;
10362 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10364 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10367 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10371 tClass = type._class && type._class.registered ? type._class.registered : _class;
10372 while(tClass && !tClass.templateClass) tClass = tClass.base;
10374 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10377 ClassTemplateParameter curParam = null;
10380 for(sClass = tClass; sClass; sClass = sClass.base)
10383 if(sClass.templateClass) sClass = sClass.templateClass;
10384 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10386 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10388 for(sClass = sClass.base; sClass; sClass = sClass.base)
10389 id += sClass.templateParams.count;
10394 if(curParam) break;
10397 if(curParam && tClass.templateArgs[id].dataTypeString)
10399 ClassTemplateArgument arg = tClass.templateArgs[id];
10400 Context context = SetupTemplatesContext(tClass);
10401 bool constant = exp.expType.constant;
10402 bool passAsTemplate = false;
10403 Class thisClassFrom = null;
10404 Type t = ProcessTypeString(exp.expType.templateParameter.dataTypeString, false);
10405 if(t && t.kind == classType && t._class)
10406 thisClassFrom = t._class.registered;
10408 // Mark that 'thisClassFrom' was set to something
10409 thisClassFrom = eSystem_FindClass(GetPrivateModule(), "class");
10413 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10414 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10416 /*if(!arg.dataType)
10417 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10418 FreeType(exp.expType);
10420 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10421 exp.expType.thisClassFrom = thisClassFrom;
10422 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10423 else if(exp.expType.kind == pointerType)
10425 Type t = exp.expType.type;
10426 while(t.kind == pointerType) t = t.type;
10427 if(constant) t.constant = constant;
10431 if(exp.expType.kind == thisClassType)
10433 FreeType(exp.expType);
10434 exp.expType = ReplaceThisClassType(_class);
10438 exp.expType.passAsTemplate = true;
10439 //exp.expType.refCount++;
10442 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10443 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10444 else if(exp.destType.kind == pointerType)
10446 Type t = exp.destType.type;
10447 while(t.kind == pointerType) t = t.type;
10448 if(constant) t.constant = constant;
10451 //exp.destType.refCount++;
10453 if(exp.destType.kind == thisClassType)
10455 FreeType(exp.destType);
10456 exp.destType = ReplaceThisClassType(_class);
10460 FinishTemplatesContext(context);
10463 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10464 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10467 ClassTemplateParameter curParam = null;
10470 for(sClass = tClass; sClass; sClass = sClass.base)
10473 if(sClass.templateClass) sClass = sClass.templateClass;
10474 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10476 if(curParam.type == TemplateParameterType::type &&
10477 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10479 for(sClass = sClass.base; sClass; sClass = sClass.base)
10480 id += sClass.templateParams.count;
10485 if(curParam) break;
10490 ClassTemplateArgument arg = tClass.templateArgs[id];
10491 Context context = SetupTemplatesContext(tClass);
10493 /*if(!arg.dataType)
10494 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10496 basicType = ProcessTypeString(arg.dataTypeString, false);
10499 if(basicType.kind == thisClassType)
10501 FreeType(basicType);
10502 basicType = ReplaceThisClassType(_class);
10505 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10506 if(tClass.templateClass)
10507 basicType.passAsTemplate = true;
10510 FreeType(exp.expType);
10512 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10513 //exp.expType.refCount++;
10516 exp.destType = exp.expType;
10517 exp.destType.refCount++;
10521 Expression newExp { };
10522 OldList * specs = MkList();
10524 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10526 if(exp.destType) exp.destType.refCount++;
10527 if(exp.expType) exp.expType.refCount++;
10528 exp.type = castExp;
10529 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10530 exp.cast.exp = newExp;
10531 //FreeType(exp.expType);
10532 //exp.expType = null;
10533 //ProcessExpressionType(sourceExp);
10536 FinishTemplatesContext(context);
10539 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10541 Class expClass = exp.expType._class.registered;
10544 Class cClass = null;
10546 int paramCount = 0;
10547 int lastParam = -1;
10548 char templateString[1024];
10549 ClassTemplateParameter param;
10550 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10551 while(cClass != expClass)
10554 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10557 for(param = cClass.templateParams.first; param; param = param.next)
10559 Class cClassCur = null;
10561 ClassTemplateParameter paramCur = null;
10562 ClassTemplateArgument arg;
10563 while(cClassCur != tClass && !paramCur)
10566 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10567 cClassCur = sClassCur;
10569 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10571 if(!strcmp(paramCur.name, param.name))
10579 if(paramCur && paramCur.type == TemplateParameterType::type)
10580 arg = tClass.templateArgs[cp];
10582 arg = expClass.templateArgs[p];
10585 char argument[256];
10586 argument[0] = '\0';
10589 strcat(argument, arg.name.string);
10590 strcat(argument, " = ");
10596 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10597 char expString[1024];
10598 OldList * specs = MkList();
10599 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10601 char * string = PrintHexUInt64(arg.expression.ui64);
10602 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10605 ProcessExpressionType(exp);
10606 ComputeExpression(exp);
10607 expString[0] = '\0';
10608 PrintExpression(exp, expString);
10609 strcat(argument, expString);
10611 FreeExpression(exp);
10616 strcat(argument, arg.member.name);
10619 case TemplateParameterType::type:
10621 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10622 strcat(argument, arg.dataTypeString);
10628 if(paramCount) strcat(templateString, ", ");
10629 if(lastParam != p - 1)
10631 strcat(templateString, param.name);
10632 strcat(templateString, " = ");
10634 strcat(templateString, argument);
10643 int len = strlen(templateString);
10644 if(templateString[len-1] == '>') templateString[len++] = ' ';
10645 templateString[len++] = '>';
10646 templateString[len++] = '\0';
10649 FreeType(exp.expType);
10651 Context context = SetupTemplatesContext(tClass);
10652 exp.expType = ProcessTypeString(templateString, false);
10653 FinishTemplatesContext(context);
10660 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10662 else if(type && (type.kind == structType || type.kind == unionType))
10664 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10667 exp.expType = memberType;
10669 memberType.refCount++;
10674 char expString[10240];
10675 expString[0] = '\0';
10676 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10677 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10680 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10682 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10684 Identifier id = exp.member.member;
10685 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10688 FreeType(exp.expType);
10689 exp.expType = ReplaceThisClassType(_class);
10693 yylloc = oldyylloc;
10696 // Convert x->y into (*x).y
10699 Type destType = exp.destType;
10701 // DOING THIS LATER NOW...
10702 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10704 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10705 /* TODO: Name Space Fix ups
10706 if(!exp.member.member.classSym)
10707 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10711 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10712 exp.type = memberExp;
10715 ProcessExpressionType(exp);
10722 //ComputeExpression(exp);
10724 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10725 if(classSym && classSym.registered)
10727 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10730 Class b = classSym.registered;
10732 DeclareStruct(curExternal, classSym.string, false, true);
10733 FreeSpecifier(exp._class);
10734 FullClassNameCat(name, classSym.string, false);
10738 exp.type = typeSizeExp;
10739 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10745 if(b.structSize == b.offset)
10746 exp.op.exp1 = MkExpConstant("0");
10748 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10751 while(b.offset != 0)
10754 Expression typeSize;
10757 sym = FindClass(b.fullName);
10760 DeclareStruct(curExternal, sym.string, false, true);
10761 FullClassNameCat(name, sym.string, false);
10763 if(b.structSize == b.offset)
10764 typeSize = MkExpConstant("0");
10766 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10767 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10774 if(classSym.registered.fixed && !classSym.registered.structSize)
10776 FreeSpecifier(exp._class);
10777 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10778 exp.type = constantExp;
10782 char className[1024];
10783 strcpy(className, "__ecereClass_");
10784 FullClassNameCat(className, classSym.string, true);
10786 DeclareClass(curExternal, classSym, className);
10788 FreeExpContents(exp);
10789 exp.type = pointerExp;
10790 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10791 exp.member.member = MkIdentifier("structSize");
10799 kind = intSizeType;
10801 // exp.isConstant = true;
10806 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10811 kind = intSizeType;
10813 exp.isConstant = true;
10815 DeclareType(curExternal, type, true, false);
10821 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10823 FreeType(exp.cast.exp.destType);
10824 exp.cast.exp.destType = type;
10826 type.casted = true;
10827 ProcessExpressionType(exp.cast.exp);
10828 type.casted = false;
10830 exp.expType = type;
10833 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10834 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10836 void * prev = exp.prev, * next = exp.next;
10837 Type expType = exp.cast.exp.destType;
10838 Expression castExp = exp.cast.exp;
10839 Type destType = exp.destType;
10841 if(expType) expType.refCount++;
10843 //FreeType(exp.destType);
10844 FreeType(exp.expType);
10845 FreeTypeName(exp.cast.typeName);
10848 FreeType(exp.expType);
10849 FreeType(exp.destType);
10851 exp.expType = expType;
10852 exp.destType = destType;
10862 exp.isConstant = exp.cast.exp.isConstant;
10867 case extensionInitializerExp:
10869 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10870 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10871 // ProcessInitializer(exp.initializer.initializer, type);
10872 exp.expType = type;
10877 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10878 ProcessExpressionType(exp.vaArg.exp);
10879 exp.expType = type;
10885 Type t = exp.destType;
10886 if(t && !exp.destType.casted)
10889 CopyTypeInto(t, exp.destType);
10895 exp.isConstant = true;
10897 FreeType(exp.cond.cond.destType);
10898 exp.cond.cond.destType = MkClassType("bool");
10899 exp.cond.cond.destType.truth = true;
10900 ProcessExpressionType(exp.cond.cond);
10901 if(!exp.cond.cond.isConstant)
10902 exp.isConstant = false;
10903 for(e = exp.cond.exp->first; e; e = e.next)
10907 FreeType(e.destType);
10909 if(e.destType) e.destType.refCount++;
10911 ProcessExpressionType(e);
10914 exp.expType = e.expType;
10915 if(e.expType) e.expType.refCount++;
10918 exp.isConstant = false;
10921 FreeType(exp.cond.elseExp.destType);
10922 // Added this check if we failed to find an expType
10923 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10926 exp.cond.elseExp.destType = t ? t : exp.expType;
10928 if(exp.cond.elseExp.destType)
10929 exp.cond.elseExp.destType.refCount++;
10930 ProcessExpressionType(exp.cond.elseExp);
10932 // FIXED THIS: Was done before calling process on elseExp
10933 if(!exp.cond.elseExp.isConstant)
10934 exp.isConstant = false;
10939 case extensionCompoundExp:
10941 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10943 Statement last = exp.compound.compound.statements->last;
10944 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10946 ((Expression)last.expressions->last).destType = exp.destType;
10948 exp.destType.refCount++;
10950 ProcessStatement(exp.compound);
10951 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10953 exp.expType.refCount++;
10959 Specifier spec = exp._classExp.specifiers->first;
10960 if(spec && spec.type == nameSpecifier)
10962 exp.expType = MkClassType(spec.name);
10963 exp.expType.kind = subClassType;
10964 exp.byReference = true;
10968 exp.expType = MkClassType("ecere::com::Class");
10969 exp.byReference = true;
10975 Class _class = thisClass ? thisClass : currentClass;
10978 Identifier id = exp.classData.id;
10979 char structName[1024];
10980 Expression classExp;
10981 strcpy(structName, "__ecereClassData_");
10982 FullClassNameCat(structName, _class.fullName, false);
10983 exp.type = pointerExp;
10984 exp.member.member = id;
10985 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10986 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10988 classExp = MkExpIdentifier(MkIdentifier("class"));
10990 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10991 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10992 MkExpBrackets(MkListOne(MkExpOp(
10993 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10994 MkExpMember(classExp, MkIdentifier("data"))), '+',
10995 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10998 ProcessExpressionType(exp);
11006 const char * typeString = null;
11007 char typeStringBuf[1024];
11008 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11009 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11011 Class templateClass = exp.destType._class.registered;
11012 typeString = templateClass.templateArgs[2].dataTypeString;
11016 // Guess type from expressions in the array
11018 for(e = exp.list->first; e; e = e.next)
11020 ProcessExpressionType(e);
11023 if(!type) { type = e.expType; type.refCount++; }
11026 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11027 if(!MatchTypeExpression(e, type, null, false, true))
11033 e = exp.list->first;
11034 ProcessExpressionType(e);
11037 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11038 if(!MatchTypeExpression(e, type, null, false, true))
11040 FreeType(e.expType);
11051 FreeType(e.expType);
11058 typeStringBuf[0] = '\0';
11059 PrintTypeNoConst(type, typeStringBuf, false, true);
11060 typeString = typeStringBuf;
11068 (Container)& (struct BuiltInContainer)
11070 ._vTbl = class(BuiltInContainer)._vTbl,
11071 ._class = class(BuiltInContainer),
11073 .data = (int[]){ 1, 7, 3, 4, 5 },
11075 .type = class(int),
11078 char templateString[1024];
11079 OldList * initializers = MkList();
11080 OldList * structInitializers = MkList();
11081 OldList * specs = MkList();
11083 Declarator decl = SpecDeclFromString(typeString, specs, null);
11084 sprintf(templateString, "Container<%s>", typeString);
11089 type = ProcessTypeString(typeString, false);
11090 while((e = exp.list->first))
11092 exp.list->Remove(e);
11095 ProcessExpressionType(e);
11096 ListAdd(initializers, MkInitializerAssignment(e));
11102 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11104 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11105 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11106 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11107 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11108 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11109 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11110 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11111 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11112 MkInitializerList(initializers))));
11113 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11114 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11115 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11116 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11117 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11118 exp.expType = ProcessTypeString(templateString, false);
11119 exp.type = bracketsExp;
11120 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11122 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11123 MkInitializerList(structInitializers)))));
11124 ProcessExpressionType(expExt);
11128 exp.expType = ProcessTypeString("Container", false);
11129 Compiler_Error($"Couldn't determine type of array elements\n");
11135 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11137 FreeType(exp.expType);
11138 exp.expType = ReplaceThisClassType(thisClass);
11141 // Resolve structures here
11142 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11144 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11145 // TODO: Fix members reference...
11148 if(exp.expType.kind != enumType)
11151 String enumName = CopyString(exp.expType.enumName);
11153 // Fixed a memory leak on self-referencing C structs typedefs
11154 // by instantiating a new type rather than simply copying members
11155 // into exp.expType
11156 FreeType(exp.expType);
11157 exp.expType = Type { };
11158 exp.expType.kind = symbol.type.kind;
11159 exp.expType.refCount++;
11160 exp.expType.enumName = enumName;
11162 exp.expType.members = symbol.type.members;
11163 for(member = symbol.type.members.first; member; member = member.next)
11168 NamedLink64 member;
11169 for(member = symbol.type.members.first; member; member = member.next)
11171 NamedLink64 value { name = CopyString(member.name) };
11172 exp.expType.members.Add(value);
11178 // Trying to do this here before conversion properties kick in and this becomes a new expression... (Fixing Class c; const char * a = c;)
11179 // Mark nohead classes as by reference, unless we're casting them to an integral type
11180 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11181 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11182 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11183 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11185 exp.byReference = true;
11189 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11190 else if(exp.destType && !exp.destType.keepCast)
11192 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11193 exp.needTemplateCast = 1;
11195 if(exp.destType.kind == voidType);
11196 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11198 // Warn for casting unrelated types to/from struct classes
11199 bool invalidCast = false;
11200 if(inCompiler && exp.destType.count && exp.expType)
11202 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11203 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11204 if(c1 && c1.type != structClass) c1 = null;
11205 if(c2 && c2.type != structClass) c2 = null;
11206 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11207 invalidCast = true;
11209 if(!exp.destType.count || unresolved || invalidCast)
11214 if(exp.destType.kind != ellipsisType)
11220 char expString[10240];
11221 expString[0] = '\0';
11223 PrintType(exp.destType, type2, false, true);
11225 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11227 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11228 else if(exp.type != dummyExp)
11229 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11234 char expString[10240] ;
11235 expString[0] = '\0';
11236 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11239 Compiler_Error($"unresolved identifier %s\n", expString);
11240 else if(exp.type != dummyExp)
11241 Compiler_Error($"couldn't determine type of %s\n", expString);
11252 PrintType(exp.expType, type1, false, true);
11253 PrintType(exp.destType, type2, false, true);
11256 //CheckExpressionType(exp, exp.destType, false);
11258 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11259 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11260 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11263 Expression nbExp = GetNonBracketsExp(exp);
11264 bool skipWarning = false;
11265 TypeKind kind = exp.destType.kind;
11266 if(nbExp.type == conditionExp && nbExp.destType && !nbExp.destType.casted && nbExp.destType.kind == exp.destType.kind)
11267 // The if/else operands have already been checked / warned about
11268 skipWarning = true;
11269 if((kind == charType || kind == shortType) && exp.destType.isSigned == exp.expType.signedBeforePromotion && nbExp.type == opExp && nbExp.op.exp1 && nbExp.op.exp2)
11271 int op = nbExp.op.op;
11272 Expression nbExp1, nbExp2;
11277 case '%': case '/':
11278 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11279 from = nbExp1.expType.promotedFrom;
11280 // Division and Modulo will not take more room than type before promotion
11281 if(from == charType || (kind == shortType && from == shortType))
11282 skipWarning = true;
11285 case LEFT_OP: case RIGHT_OP:
11286 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11287 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11288 from = nbExp1.expType.promotedFrom;
11289 // Right shift will not take more room than type before promotion
11290 if(op == RIGHT_OP && (from == charType || (kind == shortType && from == shortType)))
11291 skipWarning = true;
11292 else if(nbExp2.isConstant && nbExp2.type == constantExp && (nbExp.op.op == RIGHT_OP || nbExp1.expType.bitMemberSize))
11294 int n = (int)strtol(nbExp2.constant, null, 0);
11295 int s = from == charType ? 8 : 16;
11296 // Left shifting a bit member constrained in size may still fit in type before promotion
11297 if(nbExp1.expType.bitMemberSize && nbExp1.expType.bitMemberSize < s)
11298 s = nbExp1.expType.bitMemberSize;
11300 // If right shifted enough things will fit in smaller type
11301 if(nbExp.op.op == RIGHT_OP)
11305 if(s <= (kind == charType ? 8 : 16))
11306 skipWarning = true;
11310 if(!exp.destType.isSigned)
11312 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11313 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11314 from = nbExp2.expType.promotedFrom;
11315 // Max value of unsigned type before promotion minus the same will always fit
11316 if((from == charType || from == shortType) && nbExp1.isConstant && nbExp1.type == constantExp)
11318 int n = (int)strtol(nbExp1.constant, null, 0);
11319 if(n == (from == charType ? 255 : 65535))
11320 skipWarning = true;
11326 TypeKind kind1, kind2;
11327 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11328 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11329 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11330 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11331 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) &&
11332 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11333 skipWarning = true;
11338 TypeKind kind1, kind2;
11339 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11340 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11341 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11342 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11343 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) ||
11344 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11345 skipWarning = true;
11353 char expString[10240];
11354 expString[0] = '\0';
11355 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11358 CheckExpressionType(exp, exp.destType, false, true);
11361 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11362 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11363 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11364 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11365 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11368 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11370 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11374 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11377 FreeType(exp.expType);
11378 exp.destType.refCount++;
11379 exp.expType = exp.destType;
11385 // Cast function pointers to void * as eC already checked compatibility
11386 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11387 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11389 Expression nbExp = GetNonBracketsExp(exp);
11390 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11392 Expression e = MoveExpContents(exp);
11393 exp.cast.exp = MkExpBrackets(MkListOne(e));
11394 exp.type = castExp;
11395 exp.cast.exp.destType = exp.destType;
11396 if(exp.destType) exp.destType.refCount++;
11397 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11401 else if(unresolved)
11403 if(exp.identifier._class && exp.identifier._class.name)
11404 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11405 else if(exp.identifier.string && exp.identifier.string[0])
11406 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11408 else if(!exp.expType && exp.type != dummyExp)
11410 char expString[10240];
11411 expString[0] = '\0';
11412 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11413 Compiler_Error($"couldn't determine type of %s\n", expString);
11416 // Let's try to support any_object & typed_object here:
11418 ApplyAnyObjectLogic(exp);
11420 // Mark nohead classes as by reference, unless we're casting them to an integral type
11421 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11422 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11423 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11424 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11426 exp.byReference = true;
11428 yylloc = oldyylloc;
11431 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11433 // THIS CODE WILL FIND NEXT MEMBER...
11436 *curMember = (*curMember).next;
11438 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11440 *curMember = subMemberStack[--(*subMemberStackPos)];
11441 *curMember = (*curMember).next;
11444 // SKIP ALL PROPERTIES HERE...
11445 while((*curMember) && (*curMember).isProperty)
11446 *curMember = (*curMember).next;
11448 if(subMemberStackPos)
11450 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11452 subMemberStack[(*subMemberStackPos)++] = *curMember;
11454 *curMember = (*curMember).members.first;
11455 while(*curMember && (*curMember).isProperty)
11456 *curMember = (*curMember).next;
11464 if(subMemberStackPos && *subMemberStackPos)
11466 *curMember = subMemberStack[--(*subMemberStackPos)];
11467 *curMember = (*curMember).next;
11471 Class lastCurClass = *curClass;
11473 if(*curClass == _class) break; // REACHED THE END
11475 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11476 *curMember = (*curClass).membersAndProperties.first;
11479 while((*curMember) && (*curMember).isProperty)
11480 *curMember = (*curMember).next;
11481 if(subMemberStackPos)
11483 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11485 subMemberStack[(*subMemberStackPos)++] = *curMember;
11487 *curMember = (*curMember).members.first;
11488 while(*curMember && (*curMember).isProperty)
11489 *curMember = (*curMember).next;
11497 static void ProcessInitializer(Initializer init, Type type)
11501 case expInitializer:
11502 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11504 // TESTING THIS FOR SHUTTING = 0 WARNING
11505 if(init.exp && !init.exp.destType)
11507 FreeType(init.exp.destType);
11508 init.exp.destType = type;
11509 if(type) type.refCount++;
11513 ProcessExpressionType(init.exp);
11514 init.isConstant = init.exp.isConstant;
11520 Expression exp = init.exp;
11521 Instantiation inst = exp.instance;
11522 MembersInit members;
11524 init.type = listInitializer;
11525 init.list = MkList();
11529 for(members = inst.members->first; members; members = members.next)
11531 if(members.type == dataMembersInit)
11534 for(member = members.dataMembers->first; member; member = member.next)
11536 ListAdd(init.list, member.initializer);
11537 member.initializer = null;
11540 // Discard all MembersInitMethod
11543 FreeExpression(exp);
11545 case listInitializer:
11548 Type initializerType = null;
11549 Class curClass = null;
11550 DataMember curMember = null;
11551 DataMember subMemberStack[256];
11552 int subMemberStackPos = 0;
11554 if(type && type.kind == arrayType)
11555 initializerType = Dereference(type);
11556 else if(type && (type.kind == structType || type.kind == unionType))
11557 initializerType = type.members.first;
11559 for(i = init.list->first; i; i = i.next)
11561 if(type && type.kind == classType && type._class && type._class.registered)
11563 // 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)
11564 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11565 // TODO: Generate error on initializing a private data member this way from another module...
11568 if(!curMember.dataType)
11569 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11570 initializerType = curMember.dataType;
11573 ProcessInitializer(i, initializerType);
11574 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11575 initializerType = initializerType.next;
11577 init.isConstant = false;
11580 if(type && type.kind == arrayType)
11581 FreeType(initializerType);
11583 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11585 Compiler_Error($"Assigning list initializer to non list\n");
11592 static void ProcessSpecifier(Specifier spec, bool declareStruct, bool warnClasses)
11596 case baseSpecifier:
11598 if(spec.specifier == THISCLASS)
11602 spec.type = nameSpecifier;
11603 spec.name = ReplaceThisClass(thisClass);
11604 spec.symbol = FindClass(spec.name);
11605 ProcessSpecifier(spec, declareStruct, false);
11610 case nameSpecifier:
11612 Symbol symbol = FindType(curContext, spec.name);
11614 DeclareType(curExternal, symbol.type, true, true);
11615 else if(spec.symbol /*&& declareStruct*/)
11617 Class c = spec.symbol.registered;
11618 if(warnClasses && !c)
11619 Compiler_Warning("Undeclared class %s\n", spec.name);
11620 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11624 case enumSpecifier:
11629 for(e = spec.list->first; e; e = e.next)
11632 ProcessExpressionType(e.exp);
11635 // Fall through for IDE type processing
11639 case structSpecifier:
11640 case unionSpecifier:
11642 if(spec.definitions)
11645 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11647 ProcessClass(spec.definitions, symbol);
11650 for(def = spec.definitions->first; def; def = def.next)
11652 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11653 ProcessDeclaration(def.decl);
11660 case classSpecifier:
11662 Symbol classSym = FindClass(spec.name);
11663 if(classSym && classSym.registered && classSym.registered.type == structClass)
11664 DeclareStruct(spec.name, false, true);
11672 static void ProcessDeclarator(Declarator decl, bool isFunction)
11676 case identifierDeclarator:
11677 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11679 FreeSpecifier(decl.identifier._class);
11680 decl.identifier._class = null;
11683 case arrayDeclarator:
11685 ProcessExpressionType(decl.array.exp);
11686 case structDeclarator:
11687 case bracketsDeclarator:
11688 case functionDeclarator:
11689 case pointerDeclarator:
11690 case extendedDeclarator:
11691 case extendedDeclaratorEnd:
11693 Identifier id = null;
11694 Specifier classSpec = null;
11695 if(decl.type == functionDeclarator)
11697 id = GetDeclId(decl);
11698 if(id && id._class)
11700 classSpec = id._class;
11704 if(decl.declarator)
11705 ProcessDeclarator(decl.declarator, isFunction);
11706 if(decl.type == functionDeclarator)
11712 qualifiers = MkListOne(classSpec);
11715 if(!decl.function.parameters)
11716 decl.function.parameters = MkList();
11717 decl.function.parameters->Insert(null, param);
11719 if(decl.function.parameters)
11723 for(param = decl.function.parameters->first; param; param = param.next)
11725 if(param.qualifiers)
11728 for(spec = param.qualifiers->first; spec; spec = spec.next)
11730 if(spec.type == baseSpecifier)
11732 if(spec.specifier == TYPED_OBJECT)
11734 Declarator d = param.declarator;
11737 qualifiers = MkListOne(MkSpecifier(VOID));
11738 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11740 if(!d || d.type != pointerDeclarator)
11741 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11743 FreeList(param.qualifiers, FreeSpecifier);
11745 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11746 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11748 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11750 decl.function.parameters->Insert(param, newParam);
11754 else if(spec.specifier == ANY_OBJECT)
11756 Declarator d = param.declarator;
11758 FreeList(param.qualifiers, FreeSpecifier);
11760 param.qualifiers = MkListOne(MkSpecifier(VOID));
11761 if(!d || d.type != pointerDeclarator)
11762 param.qualifiers->Insert(null, MkSpecifier(CONST));
11763 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11766 else if(spec.specifier == THISCLASS)
11770 spec.type = nameSpecifier;
11771 spec.name = ReplaceThisClass(thisClass);
11772 spec.symbol = FindClass(spec.name);
11773 ProcessSpecifier(spec, false, false);
11778 else if(spec.type == nameSpecifier)
11780 ProcessSpecifier(spec, isFunction, true);
11782 else if((spec.type == structSpecifier || spec.type == unionSpecifier) && !spec.definitions && spec.id && spec.id.string)
11784 Declarator d = param.declarator;
11785 if(!d || d.type != pointerDeclarator)
11786 DeclareStruct(curExternal, spec.id.string, false, true);
11791 if(param.declarator)
11792 ProcessDeclarator(param.declarator, false);
11801 static void ProcessDeclaration(Declaration decl, bool warnClasses)
11806 case initDeclaration:
11808 bool declareStruct = false;
11810 lineNum = decl.pos.line;
11811 column = decl.pos.col;
11814 if(decl.declarators)
11818 for(d = decl.declarators->first; d; d = d.next)
11820 Type type, subType;
11821 ProcessDeclarator(d.declarator, false);
11823 type = ProcessType(decl.specifiers, d.declarator);
11827 ProcessInitializer(d.initializer, type);
11829 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11831 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11832 d.initializer.exp.type == instanceExp)
11834 if(type.kind == classType && type._class ==
11835 d.initializer.exp.expType._class)
11837 Instantiation inst = d.initializer.exp.instance;
11838 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11840 d.initializer.exp.instance = null;
11841 if(decl.specifiers)
11842 FreeList(decl.specifiers, FreeSpecifier);
11843 FreeList(decl.declarators, FreeInitDeclarator);
11847 decl.type = instDeclaration;
11852 for(subType = type; subType;)
11854 if(subType.kind == classType)
11856 declareStruct = true;
11859 else if(subType.kind == pointerType)
11861 else if(subType.kind == arrayType)
11862 subType = subType.arrayType;
11872 if(decl.specifiers)
11875 for(s = decl.specifiers->first; s; s = s.next)
11877 ProcessSpecifier(s, declareStruct, true);
11882 case instDeclaration:
11884 ProcessInstantiationType(decl.inst);
11887 case structDeclaration:
11891 bool declareStruct = false;
11893 if(decl.declarators)
11895 for(d = decl.declarators->first; d; d = d.next)
11897 Type type = ProcessType(decl.specifiers, d.declarator);
11899 ProcessDeclarator(d, false);
11900 for(subType = type; subType;)
11902 if(subType.kind == classType)
11904 declareStruct = true;
11907 else if(subType.kind == pointerType)
11909 else if(subType.kind == arrayType)
11910 subType = subType.arrayType;
11917 if(decl.specifiers)
11919 for(spec = decl.specifiers->first; spec; spec = spec.next)
11920 ProcessSpecifier(spec, declareStruct, warnClasses);
11927 static FunctionDefinition curFunction;
11929 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11931 char propName[1024], propNameM[1024];
11932 char getName[1024], setName[1024];
11935 DeclareProperty(curExternal, prop, setName, getName);
11937 // eInstance_FireWatchers(object, prop);
11938 strcpy(propName, "__ecereProp_");
11939 FullClassNameCat(propName, prop._class.fullName, false);
11940 strcat(propName, "_");
11941 FullClassNameCat(propName, prop.name, true);
11943 strcpy(propNameM, "__ecerePropM_");
11944 FullClassNameCat(propNameM, prop._class.fullName, false);
11945 strcat(propNameM, "_");
11946 FullClassNameCat(propNameM, prop.name, true);
11948 if(prop.isWatchable)
11951 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11952 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11953 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11956 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11957 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11958 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11960 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
11965 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11966 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11967 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11970 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11971 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11972 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11974 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
11977 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11978 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11979 curFunction.propSet.fireWatchersDone = true;
11982 static void ProcessStatement(Statement stmt)
11986 lineNum = stmt.pos.line;
11987 column = stmt.pos.col;
11992 ProcessStatement(stmt.labeled.stmt);
11995 // This expression should be constant...
11996 if(stmt.caseStmt.exp)
11998 FreeType(stmt.caseStmt.exp.destType);
11999 stmt.caseStmt.exp.destType = curSwitchType;
12000 if(curSwitchType) curSwitchType.refCount++;
12001 ProcessExpressionType(stmt.caseStmt.exp);
12002 ComputeExpression(stmt.caseStmt.exp);
12004 if(stmt.caseStmt.stmt)
12005 ProcessStatement(stmt.caseStmt.stmt);
12009 if(stmt.compound.context)
12014 Statement prevCompound = curCompound;
12015 Context prevContext = curContext;
12017 if(!stmt.compound.isSwitch)
12018 curCompound = stmt;
12019 curContext = stmt.compound.context;
12021 if(stmt.compound.declarations)
12023 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
12024 ProcessDeclaration(decl, true);
12026 if(stmt.compound.statements)
12028 for(s = stmt.compound.statements->first; s; s = s.next)
12029 ProcessStatement(s);
12032 curContext = prevContext;
12033 curCompound = prevCompound;
12037 case expressionStmt:
12040 if(stmt.expressions)
12042 for(exp = stmt.expressions->first; exp; exp = exp.next)
12043 ProcessExpressionType(exp);
12051 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
12052 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
12053 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
12054 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
12056 ProcessExpressionType(exp);
12058 if(stmt.ifStmt.stmt)
12059 ProcessStatement(stmt.ifStmt.stmt);
12060 if(stmt.ifStmt.elseStmt)
12061 ProcessStatement(stmt.ifStmt.elseStmt);
12066 Type oldSwitchType = curSwitchType;
12067 if(stmt.switchStmt.exp)
12070 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12080 e.exp.destType = destType;
12083 ProcessExpressionType(exp);
12086 curSwitchType = exp.expType;
12089 ProcessStatement(stmt.switchStmt.stmt);
12090 curSwitchType = oldSwitchType;
12095 if(stmt.whileStmt.exp)
12099 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12100 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12101 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12102 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12104 ProcessExpressionType(exp);
12107 if(stmt.whileStmt.stmt)
12108 ProcessStatement(stmt.whileStmt.stmt);
12113 if(stmt.doWhile.exp)
12117 if(stmt.doWhile.exp->last)
12119 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12120 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12121 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12123 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12125 ProcessExpressionType(exp);
12128 if(stmt.doWhile.stmt)
12129 ProcessStatement(stmt.doWhile.stmt);
12135 if(stmt.forStmt.init)
12136 ProcessStatement(stmt.forStmt.init);
12138 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12140 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12141 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12142 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12145 if(stmt.forStmt.check)
12146 ProcessStatement(stmt.forStmt.check);
12147 if(stmt.forStmt.increment)
12149 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12150 ProcessExpressionType(exp);
12153 if(stmt.forStmt.stmt)
12154 ProcessStatement(stmt.forStmt.stmt);
12159 Identifier id = stmt.forEachStmt.id;
12160 OldList * exp = stmt.forEachStmt.exp;
12161 OldList * filter = stmt.forEachStmt.filter;
12162 Statement block = stmt.forEachStmt.stmt;
12163 char iteratorType[1024];
12166 bool isBuiltin = exp && exp->last &&
12167 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12168 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12169 Expression arrayExp;
12170 const char * typeString = null;
12171 int builtinCount = 0;
12173 for(e = exp ? exp->first : null; e; e = e.next)
12177 FreeType(e.destType);
12178 e.destType = ProcessTypeString("Container", false);
12180 if(!isBuiltin || e.next)
12181 ProcessExpressionType(e);
12184 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12185 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12186 eClass_IsDerived(source._class.registered, containerClass)))
12188 Class _class = source ? source._class.registered : null;
12190 Expression expIt = null;
12191 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12192 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12193 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12194 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12198 stmt.type = compoundStmt;
12200 stmt.compound.context = Context { };
12201 stmt.compound.context.parent = curContext;
12202 curContext = stmt.compound.context;
12205 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12207 Class mapClass = eSystem_FindClass(privateModule, "Map");
12208 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12209 isCustomAVLTree = true;
12210 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12212 else */if(eClass_IsDerived(source._class.registered, mapClass))
12215 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12216 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12218 Class listClass = eSystem_FindClass(privateModule, "List");
12220 isList = eClass_IsDerived(source._class.registered, listClass);
12223 if(inCompiler && isArray)
12226 OldList * specs = MkList();
12227 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12228 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12229 stmt.compound.declarations = MkListOne(
12230 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12231 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12232 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12233 MkInitializerAssignment(MkExpBrackets(exp))))));
12238 char typeStringBuf[1024];
12240 // TODO: Merge this code?
12241 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12242 if(((Expression)exp->last).type == castExp)
12244 TypeName typeName = ((Expression)exp->last).cast.typeName;
12246 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12249 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12250 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12251 arrayExp.destType._class.registered.templateArgs)
12253 Class templateClass = arrayExp.destType._class.registered;
12254 typeString = templateClass.templateArgs[2].dataTypeString;
12256 else if(arrayExp.list)
12258 // Guess type from expressions in the array
12260 for(e = arrayExp.list->first; e; e = e.next)
12262 ProcessExpressionType(e);
12265 if(!type) { type = e.expType; type.refCount++; }
12268 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12269 if(!MatchTypeExpression(e, type, null, false, true))
12275 e = arrayExp.list->first;
12276 ProcessExpressionType(e);
12279 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12280 if(!MatchTypeExpression(e, type, null, false, true))
12282 FreeType(e.expType);
12293 FreeType(e.expType);
12300 typeStringBuf[0] = '\0';
12301 PrintType(type, typeStringBuf, false, true);
12302 typeString = typeStringBuf;
12310 OldList * initializers = MkList();
12312 OldList * specs = MkList();
12317 builtinCount = arrayExp.list->count;
12318 type = ProcessTypeString(typeString, false);
12319 while((e = arrayExp.list->first))
12321 arrayExp.list->Remove(e);
12324 ProcessExpressionType(e);
12326 ListAdd(initializers, MkInitializerAssignment(e));
12329 delete arrayExp.list;
12331 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12333 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12334 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12336 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12338 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12339 ), MkInitializerList(initializers)))));
12340 FreeList(exp, FreeExpression);
12342 else if(arrayExp.list)
12345 type = ProcessTypeString(typeString, false);
12346 for(e = arrayExp.list->first; e; e = e.next)
12350 ProcessExpressionType(e);
12357 arrayExp.expType = ProcessTypeString("Container", false);
12358 Compiler_Error($"Couldn't determine type of array elements\n");
12363 OldList * specs = MkList();
12365 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12366 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12367 stmt.compound.declarations = MkListOne(
12368 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12369 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12370 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12371 MkInitializerAssignment(MkExpBrackets(exp))))));
12374 else if(inCompiler && isLinkList && !isList)
12377 OldList * specs = MkList();
12378 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12379 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12380 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12381 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12382 MkInitializerAssignment(MkExpBrackets(exp))))));
12384 /*else if(isCustomAVLTree)
12387 OldList * specs = MkList();
12388 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12389 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12390 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12391 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12392 MkInitializerAssignment(MkExpBrackets(exp))))));
12394 else if(inCompiler && _class.templateArgs)
12397 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12399 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12401 stmt.compound.declarations = MkListOne(
12402 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12403 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12404 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12408 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12412 // Reparent sub-contexts in this statement
12416 if(block.compound.context)
12417 block.compound.context.parent = stmt.compound.context;
12420 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12421 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12422 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12423 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12426 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12427 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12430 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12431 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12434 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12435 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12438 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12439 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12442 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12443 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12445 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12448 case expressionStmt:
12454 case badDeclarationStmt:
12455 case fireWatchersStmt:
12456 case stopWatchingStmt:
12464 block = MkIfStmt(filter, block, null);
12468 stmt.compound.statements = MkListOne(MkForStmt(
12469 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12470 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12471 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12472 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12474 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12475 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12476 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12481 //OldList * specs = MkList();
12482 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12484 sprintf(count, "%d", builtinCount);
12486 stmt.compound.statements = MkListOne(MkForStmt(
12487 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12488 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12489 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12490 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12494 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12495 stmt.compound.statements = MkListOne(MkForStmt(
12496 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12497 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12498 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12499 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12502 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12503 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12504 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12506 else if(isLinkList && !isList)
12508 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12509 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12510 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12511 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12513 stmt.compound.statements = MkListOne(MkForStmt(
12514 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12515 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12516 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12521 OldList * specs = MkList();
12522 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12523 stmt.compound.statements = MkListOne(MkForStmt(
12524 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12525 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12526 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12527 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12528 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12531 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12532 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12533 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12535 /*else if(isCustomAVLTree)
12537 stmt.compound.statements = MkListOne(MkForStmt(
12538 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12539 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12540 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12541 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12544 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12545 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12546 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12550 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12551 MkIdentifier("Next")), null)), block));
12553 ProcessExpressionType(expIt);
12554 if(stmt.compound.declarations->first)
12555 ProcessDeclaration(stmt.compound.declarations->first, true);
12558 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12560 ProcessStatement(stmt);
12563 ProcessStatement(stmt.forEachStmt.stmt);
12565 curContext = stmt.compound.context.parent;
12570 Compiler_Error($"Expression is not a container\n");
12583 if(stmt.expressions)
12585 for(exp = stmt.expressions->first; exp; exp = exp.next)
12589 if(curFunction && !curFunction.type)
12590 curFunction.type = ProcessType(
12591 curFunction.specifiers, curFunction.declarator);
12592 FreeType(exp.destType);
12593 // TODO: current property if not compiling
12594 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12595 if(exp.destType) exp.destType.refCount++;
12597 ProcessExpressionType(exp);
12602 case badDeclarationStmt:
12604 ProcessDeclaration(stmt.decl, true);
12610 if(stmt.asmStmt.inputFields)
12612 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12613 if(field.expression)
12614 ProcessExpressionType(field.expression);
12616 if(stmt.asmStmt.outputFields)
12618 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12619 if(field.expression)
12620 ProcessExpressionType(field.expression);
12622 if(stmt.asmStmt.clobberedFields)
12624 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12626 if(field.expression)
12627 ProcessExpressionType(field.expression);
12634 PropertyWatch propWatch;
12635 OldList * watches = stmt._watch.watches;
12636 Expression object = stmt._watch.object;
12637 Expression watcher = stmt._watch.watcher;
12639 ProcessExpressionType(watcher);
12641 ProcessExpressionType(object);
12645 if(watcher || thisClass)
12647 External external = curExternal;
12648 Context context = curContext;
12650 stmt.type = expressionStmt;
12651 stmt.expressions = MkList();
12653 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12655 ClassFunction func;
12656 char watcherName[1024];
12657 Class watcherClass = watcher ?
12658 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12659 External createdExternal;
12661 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12662 if(propWatch.deleteWatch)
12663 strcat(watcherName, "_delete");
12667 for(propID = propWatch.properties->first; propID; propID = propID.next)
12669 strcat(watcherName, "_");
12670 strcat(watcherName, propID.string);
12674 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12676 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12677 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12678 ProcessClassFunctionBody(func, propWatch.compound);
12679 propWatch.compound = null;
12681 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12683 FreeClassFunction(func);
12685 curExternal = createdExternal;
12686 ProcessFunction(createdExternal.function);
12688 if(propWatch.deleteWatch)
12690 OldList * args = MkList();
12691 ListAdd(args, CopyExpression(object));
12692 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12693 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12694 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12698 Class _class = object.expType._class.registered;
12701 for(propID = propWatch.properties->first; propID; propID = propID.next)
12703 char propName[1024];
12704 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12707 char getName[1024], setName[1024];
12708 OldList * args = MkList();
12710 DeclareProperty(createdExternal, prop, setName, getName);
12712 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12713 strcpy(propName, "__ecereProp_");
12714 FullClassNameCat(propName, prop._class.fullName, false);
12715 strcat(propName, "_");
12716 FullClassNameCat(propName, prop.name, true);
12718 ListAdd(args, CopyExpression(object));
12719 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12720 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12721 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12723 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12725 external.CreateUniqueEdge(createdExternal, true);
12728 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12733 Compiler_Error($"Invalid watched object\n");
12736 curExternal = external;
12737 curContext = context;
12740 FreeExpression(watcher);
12742 FreeExpression(object);
12743 FreeList(watches, FreePropertyWatch);
12746 Compiler_Error($"No observer specified and not inside a class\n");
12750 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12752 ProcessStatement(propWatch.compound);
12758 case fireWatchersStmt:
12760 OldList * watches = stmt._watch.watches;
12761 Expression object = stmt._watch.object;
12763 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12764 // printf("%X\n", watches);
12765 // printf("%X\n", stmt._watch.watches);
12767 ProcessExpressionType(object);
12772 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12778 stmt.type = expressionStmt;
12779 stmt.expressions = MkList();
12781 // Check if we're inside a property set
12782 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12784 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12788 //Compiler_Error($"No property specified and not inside a property set\n");
12792 for(propID = watches->first; propID; propID = propID.next)
12794 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12797 CreateFireWatcher(prop, object, stmt);
12800 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12805 // Fire all properties!
12808 for(base = _class; base; base = base.base)
12810 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12812 if(prop.isProperty && prop.isWatchable)
12814 CreateFireWatcher(prop, object, stmt);
12821 FreeExpression(object);
12822 FreeList(watches, FreeIdentifier);
12825 Compiler_Error($"Invalid object specified and not inside a class\n");
12829 case stopWatchingStmt:
12831 OldList * watches = stmt._watch.watches;
12832 Expression object = stmt._watch.object;
12833 Expression watcher = stmt._watch.watcher;
12836 ProcessExpressionType(object);
12838 ProcessExpressionType(watcher);
12841 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12843 if(watcher || thisClass)
12849 stmt.type = expressionStmt;
12850 stmt.expressions = MkList();
12855 // eInstance_StopWatching(object, null, watcher);
12857 ListAdd(args, CopyExpression(object));
12858 ListAdd(args, MkExpConstant("0"));
12859 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12860 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12864 for(propID = watches->first; propID; propID = propID.next)
12866 char propName[1024];
12867 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12870 char getName[1024], setName[1024];
12871 OldList * args = MkList();
12873 DeclareProperty(curExternal, prop, setName, getName);
12875 // eInstance_StopWatching(object, prop, watcher);
12876 strcpy(propName, "__ecereProp_");
12877 FullClassNameCat(propName, prop._class.fullName, false);
12878 strcat(propName, "_");
12879 FullClassNameCat(propName, prop.name, true);
12881 ListAdd(args, CopyExpression(object));
12882 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12883 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12884 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12887 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12892 FreeExpression(object);
12894 FreeExpression(watcher);
12895 FreeList(watches, FreeIdentifier);
12898 Compiler_Error($"Invalid object specified and not inside a class\n");
12901 Compiler_Error($"No observer specified and not inside a class\n");
12908 static void ProcessFunction(FunctionDefinition function)
12910 Identifier id = GetDeclId(function.declarator);
12911 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12912 Type type = symbol ? symbol.type : null;
12913 Class oldThisClass = thisClass;
12914 Context oldTopContext = topContext;
12916 yylloc = function.loc;
12917 // Process thisClass
12919 if(type && type.thisClass)
12921 Symbol classSym = type.thisClass;
12922 Class _class = type.thisClass.registered;
12923 char className[1024];
12924 char structName[1024];
12925 Declarator funcDecl;
12928 bool typedObject = false;
12930 if(_class && !_class.base)
12932 _class = currentClass;
12933 if(_class && !_class.symbol)
12934 _class.symbol = FindClass(_class.fullName);
12935 classSym = _class ? _class.symbol : null;
12936 typedObject = true;
12939 thisClass = _class;
12941 if(inCompiler && _class)
12943 if(type.kind == functionType)
12945 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12947 //TypeName param = symbol.type.params.first;
12948 Type param = symbol.type.params.first;
12949 symbol.type.params.Remove(param);
12950 //FreeTypeName(param);
12953 if(type.classObjectType != classPointer)
12955 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12956 symbol.type.staticMethod = true;
12957 symbol.type.thisClass = null;
12959 // HIGH DANGER: VERIFYING THIS...
12960 symbol.type.extraParam = false;
12964 strcpy(className, "__ecereClass_");
12965 FullClassNameCat(className, _class.fullName, true);
12968 FullClassNameCat(structName, _class.fullName, false);
12971 funcDecl = GetFuncDecl(function.declarator);
12974 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12976 TypeName param = funcDecl.function.parameters->first;
12977 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12979 funcDecl.function.parameters->Remove(param);
12980 FreeTypeName(param);
12984 if(!function.propertyNoThis)
12986 TypeName thisParam = null;
12988 if(type.classObjectType != classPointer)
12990 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12991 if(!funcDecl.function.parameters)
12992 funcDecl.function.parameters = MkList();
12993 funcDecl.function.parameters->Insert(null, thisParam);
12998 if(type.classObjectType != classPointer)
13000 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
13001 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
13004 thisParam = TypeName
13006 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
13007 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
13009 DeclareStruct(curExternal, "ecere::com::Class", false, true);
13010 funcDecl.function.parameters->Insert(null, thisParam);
13015 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13017 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13018 funcDecl = GetFuncDecl(initDecl.declarator);
13021 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13023 TypeName param = funcDecl.function.parameters->first;
13024 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13026 funcDecl.function.parameters->Remove(param);
13027 FreeTypeName(param);
13031 if(type.classObjectType != classPointer)
13033 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
13035 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13037 if(!funcDecl.function.parameters)
13038 funcDecl.function.parameters = MkList();
13039 funcDecl.function.parameters->Insert(null, thisParam);
13046 // Add this to the context
13049 if(type.classObjectType != classPointer)
13051 thisSymbol = Symbol
13053 string = CopyString("this");
13054 type = classSym ? MkClassType(classSym.string) : null;
13056 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13058 if(typedObject && thisSymbol.type)
13060 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13061 thisSymbol.type.byReference = type.byReference;
13062 thisSymbol.type.typedByReference = type.byReference;
13067 // Pointer to class data
13068 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
13070 DataMember member = null;
13073 for(base = _class; base && base.type != systemClass; base = base.next)
13075 for(member = base.membersAndProperties.first; member; member = member.next)
13076 if(!member.isProperty)
13082 for(member = _class.membersAndProperties.first; member; member = member.next)
13083 if(!member.isProperty)
13087 char pointerName[1024];
13090 Initializer initializer;
13091 Expression exp, bytePtr;
13093 strcpy(pointerName, "__ecerePointer_");
13094 FullClassNameCat(pointerName, _class.fullName, false);
13096 char className[1024];
13097 strcpy(className, "__ecereClass_");
13098 FullClassNameCat(className, classSym.string, true);
13100 DeclareClass(curExternal, classSym, className);
13104 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13109 if(_class.offset && _class.offset == (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize))
13111 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
13112 ProcessExpressionType(e);
13117 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
13118 e = MkExpConstant(string);
13120 exp = QBrackets(MkExpOp(bytePtr, '+', e));
13124 // ([bytePtr] + [className]->offset)
13125 exp = QBrackets(MkExpOp(bytePtr, '+',
13126 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13129 // (this ? [exp] : 0)
13130 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13134 kind = pointerType;
13135 type = Type { refCount = 1, kind = voidType };
13140 yylloc = function.body.loc;
13141 // ([structName] *) [exp]
13142 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13143 initializer = MkInitializerAssignment(
13144 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13146 // [structName] * [pointerName] = [initializer];
13147 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13150 Context prevContext = curContext;
13152 curContext = function.body.compound.context;
13154 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13155 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13156 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13158 curContext = prevContext;
13162 decl.symbol = null;
13164 if(!function.body.compound.declarations)
13165 function.body.compound.declarations = MkList();
13166 function.body.compound.declarations->Insert(null, decl);
13172 // Loop through the function and replace undeclared identifiers
13173 // which are a member of the class (methods, properties or data)
13174 // by "this.[member]"
13181 FreeSpecifier(id._class);
13184 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13186 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13187 id = GetDeclId(initDecl.declarator);
13189 FreeSpecifier(id._class);
13194 topContext = function.body.compound.context;
13196 FunctionDefinition oldFunction = curFunction;
13197 curFunction = function;
13199 ProcessStatement(function.body);
13201 // If this is a property set and no firewatchers has been done yet, add one here
13202 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13204 Statement prevCompound = curCompound;
13205 Context prevContext = curContext;
13207 Statement fireWatchers = MkFireWatchersStmt(null, null);
13208 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13209 ListAdd(function.body.compound.statements, fireWatchers);
13211 curCompound = function.body;
13212 curContext = function.body.compound.context;
13214 ProcessStatement(fireWatchers);
13216 curContext = prevContext;
13217 curCompound = prevCompound;
13221 curFunction = oldFunction;
13224 if(function.declarator)
13226 ProcessDeclarator(function.declarator, true);
13229 topContext = oldTopContext;
13230 thisClass = oldThisClass;
13233 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13234 static void ProcessClass(OldList definitions, Symbol symbol)
13237 External external = curExternal;
13238 Class regClass = symbol ? symbol.registered : null;
13240 // Process all functions
13241 for(def = definitions.first; def; def = def.next)
13243 if(def.type == functionClassDef)
13245 if(def.function.declarator)
13246 curExternal = def.function.declarator.symbol.pointerExternal;
13248 curExternal = external;
13250 ProcessFunction((FunctionDefinition)def.function);
13252 else if(def.type == declarationClassDef)
13254 if(def.decl.type == instDeclaration)
13256 thisClass = regClass;
13257 ProcessInstantiationType(def.decl.inst);
13263 Class backThisClass = thisClass;
13264 if(regClass) thisClass = regClass;
13265 ProcessDeclaration(def.decl, symbol ? true : false);
13266 thisClass = backThisClass;
13269 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13271 MemberInit defProperty;
13273 // Add this to the context
13274 Symbol thisSymbol = Symbol
13276 string = CopyString("this");
13277 type = regClass ? MkClassType(regClass.fullName) : null;
13279 globalContext.symbols.Add((BTNode)thisSymbol);
13281 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13283 thisClass = regClass;
13284 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13288 globalContext.symbols.Remove((BTNode)thisSymbol);
13289 FreeSymbol(thisSymbol);
13291 else if(def.type == propertyClassDef && def.propertyDef)
13293 PropertyDef prop = def.propertyDef;
13295 // Add this to the context
13296 thisClass = regClass;
13303 string = CopyString("this");
13304 type = MkClassType(regClass.fullName);
13306 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13309 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13310 ProcessStatement(prop.setStmt);
13318 string = CopyString("this");
13319 type = MkClassType(regClass.fullName);
13321 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13324 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13325 ProcessStatement(prop.getStmt);
13333 string = CopyString("this");
13334 type = MkClassType(regClass.fullName);
13336 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13339 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13340 ProcessStatement(prop.issetStmt);
13345 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13347 PropertyWatch propertyWatch = def.propertyWatch;
13349 thisClass = regClass;
13350 if(propertyWatch.compound)
13354 string = CopyString("this");
13355 type = regClass ? MkClassType(regClass.fullName) : null;
13358 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13360 curExternal = null;
13361 ProcessStatement(propertyWatch.compound);
13368 void DeclareFunctionUtil(External neededBy, const String s)
13370 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13375 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13376 strcpy(name, "__ecereFunction_");
13377 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13378 DeclareFunction(neededBy, function, name);
13381 FindSymbol(s, globalContext, globalContext, false, false);
13384 bool reachedPass15;
13386 void ComputeDataTypes()
13390 currentClass = null;
13392 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13394 DeclareStruct(null, "ecere::com::Class", false, true);
13395 DeclareStruct(null, "ecere::com::Instance", false, true);
13396 DeclareStruct(null, "ecere::com::Property", false, true);
13397 DeclareStruct(null, "ecere::com::DataMember", false, true);
13398 DeclareStruct(null, "ecere::com::Method", false, true);
13399 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13400 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13402 DeclareFunctionUtil(null, "eSystem_New");
13403 DeclareFunctionUtil(null, "eSystem_New0");
13404 DeclareFunctionUtil(null, "eSystem_Renew");
13405 DeclareFunctionUtil(null, "eSystem_Renew0");
13406 DeclareFunctionUtil(null, "eSystem_Delete");
13407 DeclareFunctionUtil(null, "eClass_GetProperty");
13408 DeclareFunctionUtil(null, "eClass_SetProperty");
13409 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13410 DeclareFunctionUtil(null, "eInstance_SetMethod");
13411 DeclareFunctionUtil(null, "eInstance_IncRef");
13412 DeclareFunctionUtil(null, "eInstance_StopWatching");
13413 DeclareFunctionUtil(null, "eInstance_Watch");
13414 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13415 reachedPass15 = true;
13417 for(external = ast->first; external; external = external.next)
13419 afterExternal = curExternal = external;
13420 if(external.type == functionExternal)
13424 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13425 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13428 currentClass = external.function._class;
13429 ProcessFunction(external.function);
13431 // There shouldn't be any _class member access here anyways...
13432 else if(external.type == declarationExternal)
13434 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13436 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13437 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13440 currentClass = null;
13441 if(external.declaration)
13442 ProcessDeclaration(external.declaration, true);
13444 else if(external.type == classExternal)
13446 ClassDefinition _class = external._class;
13447 currentClass = external.symbol.registered;
13450 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13451 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13453 if(_class.definitions)
13455 ProcessClass(_class.definitions, _class.symbol);
13459 // Free class data...
13460 ast->Remove(external);
13464 else if(external.type == nameSpaceExternal)
13466 thisNameSpace = external.id.string;
13469 currentClass = null;
13470 thisNameSpace = null;
13471 curExternal = null;