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 ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
673 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
675 if(prop.isProperty && prop.isWatchable)
677 prop.watcherOffset = _class.structSize;
678 _class.structSize += sizeof(OldList);
686 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
688 Class deriv = derivative.data;
690 if(deriv.computeSize)
692 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
693 deriv.offset = /*_class.offset + */_class.structSize;
694 deriv.memberOffset = 0;
695 // ----------------------
697 deriv.structSize = deriv.offset;
699 ComputeClassMembers(deriv, false);
707 FinishTemplatesContext(context);
710 public void ComputeModuleClasses(Module module)
715 for(subModule = module.modules.first; subModule; subModule = subModule.next)
716 ComputeModuleClasses(subModule.data);
717 for(_class = module.classes.first; _class; _class = _class.next)
718 ComputeClassMembers(_class, false);
722 public int ComputeTypeSize(Type type)
724 uint size = type ? type.size : 0;
725 if(!size && type && !type.computing)
727 type.computing = true;
730 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
731 case charType: type.alignment = size = sizeof(char); break;
732 case intType: type.alignment = size = sizeof(int); break;
733 case int64Type: type.alignment = size = sizeof(int64); break;
734 case intPtrType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
735 case intSizeType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
736 case longType: type.alignment = size = sizeof(long); break;
737 case shortType: type.alignment = size = sizeof(short); break;
738 case floatType: type.alignment = size = sizeof(float); break;
739 case doubleType: type.alignment = size = sizeof(double); break;
742 Class _class = type._class ? type._class.registered : null;
744 if(_class && _class.type == structClass)
746 // Ensure all members are properly registered
747 ComputeClassMembers(_class, false);
748 type.alignment = _class.structAlignment;
749 type.pointerAlignment = (bool)_class.pointerAlignment;
750 size = _class.structSize;
751 if(type.alignment && size % type.alignment)
752 size += type.alignment - (size % type.alignment);
755 else if(_class && (_class.type == unitClass ||
756 _class.type == enumClass ||
757 _class.type == bitClass))
760 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
761 size = type.alignment = ComputeTypeSize(_class.dataType);
765 size = type.alignment = targetBits / 8; // sizeof(Instance *);
766 type.pointerAlignment = true;
770 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */ type.pointerAlignment = true; break;
772 if(type.arraySizeExp)
774 ProcessExpressionType(type.arraySizeExp);
775 ComputeExpression(type.arraySizeExp);
776 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
777 type.arraySizeExp.expType.kind != shortType &&
778 type.arraySizeExp.expType.kind != charType &&
779 type.arraySizeExp.expType.kind != longType &&
780 type.arraySizeExp.expType.kind != int64Type &&
781 type.arraySizeExp.expType.kind != intSizeType &&
782 type.arraySizeExp.expType.kind != intPtrType &&
783 type.arraySizeExp.expType.kind != enumType &&
784 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
786 Location oldLoc = yylloc;
787 // bool isConstant = type.arraySizeExp.isConstant;
788 char expression[10240];
789 expression[0] = '\0';
790 type.arraySizeExp.expType = null;
791 yylloc = type.arraySizeExp.loc;
793 PrintExpression(type.arraySizeExp, expression);
794 Compiler_Error($"Array size not constant int (%s)\n", expression);
797 GetInt(type.arraySizeExp, &type.arraySize);
799 else if(type.enumClass)
801 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
803 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
810 // Unimplemented auto size
814 size = ComputeTypeSize(type.type) * type.arraySize;
817 type.alignment = type.type.alignment;
818 type.pointerAlignment = type.type.pointerAlignment;
824 if(!type.members.first && type.enumName)
826 Symbol symbol = FindStruct(curContext, type.enumName);
827 if(symbol && symbol.type)
829 ComputeTypeSize(symbol.type);
830 size = symbol.type.size;
836 for(member = type.members.first; member; member = member.next)
838 uint addSize = ComputeTypeSize(member);
840 member.offset = size;
841 if(member.alignment && size % member.alignment)
842 member.offset += member.alignment - (size % member.alignment);
843 size = member.offset;
845 if(member.pointerAlignment && type.size <= 4)
846 type.pointerAlignment = true;
847 else if(!member.pointerAlignment && member.alignment >= 8)
848 type.pointerAlignment = false;
850 type.alignment = Max(type.alignment, member.alignment);
853 if(type.alignment && size % type.alignment)
854 size += type.alignment - (size % type.alignment);
860 if(!type.members.first && type.enumName)
862 Symbol symbol = FindStruct(curContext, type.enumName);
863 if(symbol && symbol.type)
865 ComputeTypeSize(symbol.type);
866 size = symbol.type.size;
867 type.alignment = symbol.type.alignment;
873 for(member = type.members.first; member; member = member.next)
875 uint addSize = ComputeTypeSize(member);
877 member.offset = size;
878 if(member.alignment && size % member.alignment)
879 member.offset += member.alignment - (size % member.alignment);
880 size = member.offset;
882 if(member.pointerAlignment && type.size <= 4)
883 type.pointerAlignment = true;
884 else if(!member.pointerAlignment && member.alignment >= 8)
885 type.pointerAlignment = false;
887 type.alignment = Max(type.alignment, member.alignment);
889 size = Max(size, addSize);
891 if(type.alignment && size % type.alignment)
892 size += type.alignment - (size % type.alignment);
898 TemplateParameter param = type.templateParameter;
899 Type baseType = ProcessTemplateParameterType(param);
902 size = ComputeTypeSize(baseType);
903 type.alignment = baseType.alignment;
904 type.pointerAlignment = baseType.pointerAlignment;
907 type.alignment = size = sizeof(uint64);
912 type.alignment = size = sizeof(enum { test });
917 type.alignment = size = targetBits / 8; //sizeof(void *);
918 type.pointerAlignment = true;
923 type.computing = false;
929 /*static */int AddMembers(External neededBy, OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
931 // This function is in need of a major review when implementing private members etc.
932 DataMember topMember = isMember ? (DataMember) _class : null;
939 Context context = isMember ? null : SetupTemplatesContext(_class);
941 *addedPadding = false;
943 if(!isMember && _class.base)
945 maxSize = _class.structSize;
946 //if(_class.base.type != systemClass) // Commented out with new Instance _class
948 // DANGER: Testing this noHeadClass here...
949 if(_class.type == structClass || _class.type == noHeadClass)
950 /*totalSize = */AddMembers(neededBy, declarations, _class.base, false, &totalSize, topClass, null);
953 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
954 if(maxSize > baseSize)
962 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
964 if(!member.isProperty)
970 if(member.dataTypeString)
972 OldList * specs = MkList(), * decls = MkList();
975 decl = SpecDeclFromString(member.dataTypeString, specs,
976 MkDeclaratorIdentifier(MkIdentifier(member.name)));
977 ListAdd(decls, MkStructDeclarator(decl, null));
978 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
981 member.dataType = ProcessType(specs, decl);
983 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
986 Type type = ProcessType(specs, decl);
987 DeclareType(neededBy, member.dataType, true, false);
991 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
992 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
993 DeclareStruct(member.dataType._class.string, false);
996 ComputeTypeSize(member.dataType);
997 size = member.dataType.size;
998 alignment = member.dataType.alignment;
1002 if(totalSize % alignment)
1003 totalSize += alignment - (totalSize % alignment);
1012 OldList * specs = MkList(), * list = MkList();
1014 sprintf(id, "__anon%d", anonID++);
1017 AddMembers(neededBy, list, (Class)member, true, &size, topClass, null);
1019 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1020 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1021 alignment = member.structAlignment;
1025 if(totalSize % alignment)
1026 totalSize += alignment - (totalSize % alignment);
1036 if(topMember && topMember.type == unionMember)
1037 *retSize = Max(*retSize, totalSize);
1039 *retSize += totalSize;
1041 else if(totalSize < maxSize && _class.type != systemClass)
1043 int autoPadding = 0;
1044 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1045 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1046 if(totalSize + autoPadding < maxSize)
1048 char sizeString[50];
1049 sprintf(sizeString, "%d", maxSize - totalSize);
1050 ListAdd(declarations,
1051 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1052 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1054 *addedPadding = true;
1058 FinishTemplatesContext(context);
1059 return topMember ? topMember.memberID : _class.memberID;
1062 static int DeclareMembers(External neededBy, Class _class, bool isMember)
1064 DataMember topMember = isMember ? (DataMember) _class : null;
1066 Context context = isMember ? null : SetupTemplatesContext(_class);
1068 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1069 DeclareMembers(neededBy, _class.base, false);
1071 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1073 if(!member.isProperty)
1079 if(!member.dataType && member.dataTypeString)
1080 member.dataType = ProcessTypeString(member.dataTypeString, false);
1082 DeclareType(neededBy, member.dataType, true, false);
1088 DeclareMembers(neededBy, (Class)member, true);
1095 FinishTemplatesContext(context);
1097 return topMember ? topMember.memberID : _class.memberID;
1100 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1104 for(def = definitions->first; def; def = def.next)
1106 if(def.type == declarationClassDef)
1108 Declaration decl = def.decl;
1109 if(decl && decl.specifiers)
1112 bool isStruct = false;
1113 for(spec = decl.specifiers->first; spec; spec = spec.next)
1115 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1117 if(spec.definitions)
1118 IdentifyAnonStructs(spec.definitions);
1124 Declarator d = null;
1125 if(decl.declarators)
1127 for(d = decl.declarators->first; d; d = d.next)
1129 Identifier idDecl = GetDeclId(d);
1137 sprintf(id, "__anon%d", anonID++);
1138 if(!decl.declarators)
1139 decl.declarators = MkList();
1140 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1148 External DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference)
1150 return _DeclareStruct(neededBy, name, skipNoHead, needDereference, false);
1153 External _DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference, bool fwdDecl)
1155 External external = null;
1156 Symbol classSym = FindClass(name);
1157 OldList * curDeclarations = null;
1159 if(!inCompiler || !classSym) return null;
1161 // We don't need any declaration for bit classes...
1162 if(classSym.registered &&
1163 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1166 if(!classSym.registered || (classSym.registered.type == normalClass && classSym.registered.structSize && classSym.registered.base && classSym.registered.base.base))
1167 _DeclareStruct(neededBy, "ecere::com::Instance", false, true, fwdDecl);
1169 external = classSym.structExternal;
1171 if(external && external.declaration)
1174 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1175 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1177 curDeclarations = spec.definitions;
1182 if(classSym.registered && !classSym.declaring && classSym.imported && (!classSym.declaredStructSym || (classSym.registered.type == noHeadClass && !skipNoHead && external && !curDeclarations)))
1184 OldList * specifiers, * declarators;
1185 OldList * declarations = null;
1186 char structName[1024];
1187 bool addedPadding = false;
1188 Specifier curSpec = null;
1190 classSym.declaring++;
1192 if(strchr(classSym.string, '<'))
1194 if(classSym.registered.templateClass)
1195 external = _DeclareStruct(neededBy, classSym.registered.templateClass.fullName, skipNoHead, needDereference, fwdDecl);
1196 classSym.declaring--;
1201 FullClassNameCat(structName, name, false);
1203 classSym.declaredStructSym = true;
1204 if(!external || (classSym.registered.type == noHeadClass && !skipNoHead && !curDeclarations))
1209 external = MkExternalDeclaration(null);
1210 classSym.structExternal = external;
1211 external.symbol = classSym;
1218 declarations = MkList();
1219 AddMembers(external, declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1222 if(external.declaration)
1225 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1226 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1229 curDeclarations = spec.definitions;
1234 if(declarations && (!declarations->count || (declarations->count == 1 && addedPadding)))
1236 FreeList(declarations, FreeClassDef);
1237 declarations = null;
1240 if(classSym.registered.type != noHeadClass && !declarations)
1242 FreeExternal(external);
1244 classSym.structExternal = null;
1249 curSpec.definitions = declarations;
1252 specifiers = MkList();
1253 declarators = MkList();
1254 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1255 external.declaration = MkDeclaration(specifiers, declarators);
1261 classSym.declaring--;
1263 else if(!classSym.declaredStructSym && classSym.structExternal)
1265 classSym.declaredStructSym = true;
1267 if(classSym.registered)
1268 DeclareMembers(classSym.structExternal, classSym.registered, false);
1270 if(classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1273 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1275 if(spec.definitions)
1276 IdentifyAnonStructs(spec.definitions);
1280 if(inCompiler && neededBy && (external || !classSym.imported))
1284 classSym.structExternal = external = MkExternalDeclaration(null);
1285 external.symbol = classSym;
1288 if(reachedPass15 && !external.declaration && classSym.registered && classSym.registered.type == noHeadClass)
1290 // Declare nohead classes without definitions here (e.g. IteratorPointer)
1291 char structName[1024];
1292 OldList * specifiers, * declarators;
1294 FullClassNameCat(structName, name, false);
1295 specifiers = MkList();
1296 declarators = MkList();
1297 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), null));
1298 external.declaration = MkDeclaration(specifiers, declarators);
1302 External e = external.fwdDecl ? external.fwdDecl : external;
1303 if(e.incoming.count)
1304 neededBy.CreateUniqueEdge(e, !needDereference && !external.fwdDecl);
1307 neededBy.CreateUniqueEdge(external, !needDereference);
1312 void DeclareProperty(External neededBy, Property prop, char * setName, char * getName)
1314 Symbol symbol = prop.symbol;
1315 bool imported = false;
1316 bool dllImport = false;
1317 External structExternal = null;
1318 External instExternal = null;
1320 strcpy(setName, "__ecereProp_");
1321 FullClassNameCat(setName, prop._class.fullName, false);
1322 strcat(setName, "_Set_");
1323 FullClassNameCat(setName, prop.name, true);
1325 strcpy(getName, "__ecereProp_");
1326 FullClassNameCat(getName, prop._class.fullName, false);
1327 strcat(getName, "_Get_");
1328 FullClassNameCat(getName, prop.name, true);
1330 if(!symbol || symbol._import)
1336 if(!prop._class.symbol)
1337 prop._class.symbol = FindClass(prop._class.fullName);
1338 classSym = prop._class.symbol;
1339 if(classSym && !classSym._import)
1341 ModuleImport module;
1343 if(prop._class.module)
1344 module = FindModule(prop._class.module);
1346 module = mainModule;
1348 classSym._import = ClassImport
1350 name = CopyString(prop._class.fullName);
1351 isRemote = prop._class.isRemote;
1353 module.classes.Add(classSym._import);
1355 symbol = prop.symbol = Symbol { };
1356 symbol._import = (ClassImport)PropertyImport
1358 name = CopyString(prop.name);
1359 isVirtual = false; //prop.isVirtual;
1360 hasSet = prop.Set ? true : false;
1361 hasGet = prop.Get ? true : false;
1364 classSym._import.properties.Add(symbol._import);
1367 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1368 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1369 prop._class.module.importType != staticImport)
1375 Context context = SetupTemplatesContext(prop._class);
1376 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1377 FinishTemplatesContext(context);
1380 if((prop.Get && !symbol.externalGet) || (prop.Set && !symbol.externalSet))
1382 if(prop._class.type == normalClass && prop._class.structSize)
1383 instExternal = DeclareStruct(null, "ecere::com::Instance", false, true);
1384 structExternal = DeclareStruct(null, prop._class.fullName, prop._class.type != structClass /*true*/, false);
1388 if(prop.Get && !symbol.externalGet)
1391 OldList * specifiers, * declarators;
1394 Specifier spec = null;
1396 Declarator typeDecl;
1397 bool simple = false;
1400 specifiers = MkList();
1401 declarators = MkList();
1404 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1405 MkDeclaratorIdentifier(MkIdentifier("this"))));
1407 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1410 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1413 Context context = SetupTemplatesContext(prop._class);
1414 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1415 FinishTemplatesContext(context);
1418 // Make sure the simple _class's type is declared
1419 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1420 for(spec = specifiers->first; spec; spec = spec.next)
1422 if(spec.type == nameSpecifier)
1424 Symbol classSym = spec.symbol;
1427 symbol._class = classSym.registered;
1428 if(classSym.registered && classSym.registered.type == structClass)
1436 d = PlugDeclarator(typeDecl, d);
1439 ListAdd(params, MkTypeName(specifiers,
1440 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1441 specifiers = MkList();
1444 d = MkDeclaratorFunction(d, params);
1448 specifiers->Insert(null, MkSpecifier(EXTERN));
1449 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1450 specifiers->Insert(null, MkSpecifier(STATIC));
1452 ListAdd(specifiers, MkSpecifier(VOID));
1454 ListAdd(declarators, MkInitDeclarator(d, null));
1456 decl = MkDeclaration(specifiers, declarators);
1458 external = MkExternalDeclaration(decl);
1461 external.CreateEdge(structExternal, false);
1463 external.CreateEdge(instExternal, false);
1466 DeclareStruct(external, spec.name, false, needReference);
1469 external.symbol = symbol;
1470 symbol.externalGet = external;
1472 ReplaceThisClassSpecifiers(specifiers, prop._class);
1475 FreeDeclarator(typeDecl);
1479 if(prop.Set && !symbol.externalSet)
1482 OldList * specifiers, * declarators;
1485 Specifier spec = null;
1487 Declarator typeDecl;
1490 declarators = MkList();
1493 if(!prop.conversion || prop._class.type == structClass)
1495 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1496 MkDeclaratorIdentifier(MkIdentifier("this"))));
1499 specifiers = MkList();
1502 Context context = SetupTemplatesContext(prop._class);
1503 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1504 MkDeclaratorIdentifier(MkIdentifier("value")));
1505 FinishTemplatesContext(context);
1507 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1508 specifiers->Insert(null, MkSpecifier(CONST));
1510 ListAdd(params, MkTypeName(specifiers, d));
1512 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1514 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1515 d = MkDeclaratorFunction(d, params);
1517 // Make sure the simple _class's type is declared
1518 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1519 for(spec = specifiers->first; spec; spec = spec.next)
1521 if(spec.type == nameSpecifier)
1523 Symbol classSym = spec.symbol;
1525 symbol._class = classSym.registered;
1530 ListAdd(declarators, MkInitDeclarator(d, null));
1532 specifiers = MkList();
1534 specifiers->Insert(null, MkSpecifier(EXTERN));
1535 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1536 specifiers->Insert(null, MkSpecifier(STATIC));
1538 if(!prop.conversion || prop._class.type == structClass)
1539 ListAdd(specifiers, MkSpecifier(VOID));
1541 ListAdd(specifiers, MkSpecifierName(prop._class.fullName));
1543 decl = MkDeclaration(specifiers, declarators);
1545 external = MkExternalDeclaration(decl);
1548 external.CreateEdge(structExternal, false);
1550 external.CreateEdge(instExternal, false);
1553 DeclareStruct(external, spec.name, false, needReference);
1556 external.symbol = symbol;
1557 symbol.externalSet = external;
1559 ReplaceThisClassSpecifiers(specifiers, prop._class);
1562 // Property (for Watchers)
1563 if(!symbol.externalPtr)
1567 OldList * specifiers = MkList();
1568 char propName[1024];
1571 specifiers->Insert(null, MkSpecifier(EXTERN));
1574 specifiers->Insert(null, MkSpecifier(STATIC));
1575 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1578 ListAdd(specifiers, MkSpecifierName("Property"));
1580 strcpy(propName, "__ecereProp_");
1581 FullClassNameCat(propName, prop._class.fullName, false);
1582 strcat(propName, "_");
1583 FullClassNameCat(propName, prop.name, true);
1586 OldList * list = MkList();
1587 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1591 strcpy(propName, "__ecerePropM_");
1592 FullClassNameCat(propName, prop._class.fullName, false);
1593 strcat(propName, "_");
1594 FullClassNameCat(propName, prop.name, true);
1596 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1598 decl = MkDeclaration(specifiers, list);
1601 external = MkExternalDeclaration(decl);
1602 ast->Insert(curExternal.prev, external);
1603 external.symbol = symbol;
1604 symbol.externalPtr = external;
1607 if(inCompiler && neededBy)
1609 // Could improve this to create edge on only what is needed...
1610 if(symbol.externalPtr)
1611 neededBy.CreateUniqueEdge(symbol.externalPtr, false);
1613 if(symbol.externalGet)
1614 neededBy.CreateUniqueEdge(symbol.externalGet, symbol.externalGet.type == functionExternal);
1616 if(symbol.externalSet)
1617 neededBy.CreateUniqueEdge(symbol.externalSet, symbol.externalSet.type == functionExternal);
1623 // ***************** EXPRESSION PROCESSING ***************************
1624 public Type Dereference(Type source)
1629 if(source.kind == pointerType || source.kind == arrayType)
1632 source.type.refCount++;
1634 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1642 // Support dereferencing of no head classes for now...
1643 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1649 Compiler_Error($"cannot dereference type\n");
1654 static Type Reference(Type source)
1670 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1672 Identifier ident = member.identifiers ? member.identifiers->first : null;
1674 DataMember dataMember = null;
1675 Method method = null;
1676 bool freeType = false;
1678 yylloc = member.loc;
1684 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1688 dataMember = *curMember;
1694 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1695 DataMember _subMemberStack[256];
1696 int _subMemberStackPos = 0;
1698 // FILL MEMBER STACK
1700 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1703 dataMember = thisMember;
1704 if(curMember && thisMember.memberAccess == publicAccess)
1706 *curMember = thisMember;
1707 *curClass = thisMember._class;
1708 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1709 *subMemberStackPos = _subMemberStackPos;
1716 method = eClass_FindMethod(_class, ident.string, privateModule);
1717 if(method && method.type == virtualMethod)
1729 if(!dataMember.dataType && dataMember.dataTypeString)
1731 //Context context = SetupTemplatesContext(dataMember._class);
1732 Context context = SetupTemplatesContext(_class);
1733 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1734 FinishTemplatesContext(context);
1736 type = dataMember.dataType;
1740 // This is for destination type...
1741 if(!method.dataType)
1742 ProcessMethodType(method);
1743 //DeclareMethod(method);
1744 // method.dataType = ((Symbol)method.symbol)->type;
1745 type = method.dataType;
1748 if(ident && ident.next)
1750 for(ident = ident.next; ident && type; ident = ident.next)
1752 if(type.kind == classType)
1754 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1756 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1758 type = dataMember.dataType;
1760 else if(type.kind == structType || type.kind == unionType)
1763 for(memberType = type.members.first; memberType; memberType = memberType.next)
1765 if(!strcmp(memberType.name, ident.string))
1775 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1776 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1779 ClassTemplateParameter curParam = null;
1781 for(sClass = _class; sClass; sClass = sClass.base)
1784 if(sClass.templateClass) sClass = sClass.templateClass;
1785 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1787 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1789 for(sClass = sClass.base; sClass; sClass = sClass.base)
1791 if(sClass.templateClass) sClass = sClass.templateClass;
1792 id += sClass.templateParams.count;
1803 ClassTemplateArgument arg = _class.templateArgs[id];
1804 if(arg.dataTypeString)
1806 bool constant = type.constant;
1808 type = ProcessTypeString(arg.dataTypeString, false);
1809 if(type.kind == classType && constant) type.constant = true;
1810 else if(type.kind == pointerType)
1813 while(t.kind == pointerType) t = t.type;
1814 if(constant) t.constant = constant;
1817 if(type && _class.templateClass)
1818 type.passAsTemplate = true;
1824 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1825 exp.destType.refCount++;
1831 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1833 Class expClass = type._class.registered;
1834 Class cClass = null;
1838 char templateString[1024];
1839 ClassTemplateParameter param;
1840 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1841 for(cClass = expClass; cClass; cClass = cClass.base)
1844 if(cClass.templateClass) cClass = cClass.templateClass;
1845 for(param = cClass.templateParams.first; param; param = param.next)
1849 ClassTemplateArgument arg;
1850 for(sClass = cClass.base; sClass; sClass = sClass.base)
1852 if(sClass.templateClass) sClass = sClass.templateClass;
1853 id += sClass.templateParams.count;
1855 arg = expClass.templateArgs[id];
1857 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1859 ClassTemplateParameter cParam;
1860 //int p = numParams - sClass.templateParams.count;
1863 if(sClass.templateClass) sClass = sClass.templateClass;
1865 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1867 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1868 p += nextClass.templateParams.count;
1871 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1873 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1875 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1877 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1878 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1890 strcat(argument, arg.name.string);
1891 strcat(argument, " = ");
1897 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1898 char expString[1024];
1899 OldList * specs = MkList();
1900 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1902 char * string = PrintHexUInt64(arg.expression.ui64);
1903 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1906 ProcessExpressionType(exp);
1907 ComputeExpression(exp);
1908 expString[0] = '\0';
1909 PrintExpression(exp, expString);
1910 strcat(argument, expString);
1912 FreeExpression(exp);
1917 strcat(argument, arg.member.name);
1920 case TemplateParameterType::type:
1922 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1923 strcat(argument, arg.dataTypeString);
1929 if(paramCount) strcat(templateString, ", ");
1930 if(lastParam != p - 1)
1932 strcat(templateString, param.name);
1933 strcat(templateString, " = ");
1935 strcat(templateString, argument);
1944 int len = strlen(templateString);
1945 if(templateString[len-1] == '<')
1949 if(templateString[len-1] == '>')
1950 templateString[len++] = ' ';
1951 templateString[len++] = '>';
1953 templateString[len++] = '\0';
1956 Context context = SetupTemplatesContext(_class);
1957 if(freeType) FreeType(type);
1958 type = ProcessTypeString(templateString, false);
1960 FinishTemplatesContext(context);
1964 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1966 ProcessExpressionType(member.initializer.exp);
1967 if(!member.initializer.exp.expType)
1971 char expString[10240];
1972 expString[0] = '\0';
1973 PrintExpression(member.initializer.exp, expString);
1974 ChangeCh(expString, '\n', ' ');
1975 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1978 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1979 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1981 Compiler_Error($"incompatible instance method %s\n", ident.string);
1984 else if(member.initializer)
1987 FreeType(member.exp.destType);
1988 member.exp.destType = type;
1989 if(member.exp.destType)
1990 member.exp.destType.refCount++;
1991 ProcessExpressionType(member.exp);
1994 ProcessInitializer(member.initializer, type);
1996 if(freeType) FreeType(type);
2000 if(_class && _class.type == unitClass)
2002 if(member.initializer)
2005 FreeType(member.exp.destType);
2006 member.exp.destType = MkClassType(_class.fullName);
2007 ProcessExpressionType(member.initializer, type);
2009 Type type = MkClassType(_class.fullName);
2010 ProcessInitializer(member.initializer, type);
2016 if(member.initializer)
2018 //ProcessExpressionType(member.exp);
2019 ProcessInitializer(member.initializer, null);
2025 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2029 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2031 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2035 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2040 void ProcessInstantiationType(Instantiation inst)
2045 MembersInit members;
2049 classSym = inst._class.symbol;
2050 _class = classSym ? classSym.registered : null;
2052 if(!_class || _class.type != noHeadClass)
2053 DeclareStruct(curExternal, inst._class.name, false, true);
2055 afterExternal = afterExternal ? afterExternal : curExternal;
2058 ProcessExpressionType(inst.exp);
2060 inst.isConstant = true;
2063 DataMember curMember = null;
2064 Class curClass = null;
2065 DataMember subMemberStack[256];
2066 int subMemberStackPos = 0;
2068 for(members = inst.members->first; members; members = members.next)
2070 switch(members.type)
2072 case methodMembersInit:
2075 static uint instMethodID = 0;
2076 External external = curExternal;
2077 Context context = curContext;
2078 Declarator declarator = members.function.declarator;
2079 Identifier nameID = GetDeclId(declarator);
2080 char * unmangled = nameID ? nameID.string : null;
2082 External createdExternal = null;
2087 strcpy(name, "__ecereInstMeth_");
2088 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2090 strcat(name, nameID.string);
2092 sprintf(number, "_%08d", instMethodID++);
2093 strcat(name, number);
2094 nameID.string = CopyString(name);
2097 // Do modifications here...
2100 Symbol symbol = declarator.symbol;
2101 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2103 if(method && method.type == virtualMethod)
2105 symbol.method = method;
2106 ProcessMethodType(method);
2108 if(!symbol.type.thisClass)
2110 if(method.dataType.thisClass && currentClass &&
2111 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2113 if(!currentClass.symbol)
2114 currentClass.symbol = FindClass(currentClass.fullName);
2115 symbol.type.thisClass = currentClass.symbol;
2120 _class.symbol = FindClass(_class.fullName);
2121 symbol.type.thisClass = _class.symbol;
2124 DeclareType(curExternal, symbol.type, true, true);
2129 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2130 unmangled, classSym.string);
2134 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2138 FreeSpecifier(nameID._class);
2139 nameID._class = null;
2142 curExternal = createdExternal;
2145 if(createdExternal.function)
2146 ProcessFunction(createdExternal.function);
2150 curExternal = declarator.symbol.pointerExternal;
2151 ProcessFunction((FunctionDefinition)members.function);
2153 curExternal = external;
2154 curContext = context;
2158 FreeClassFunction(members.function);
2160 // In this pass, turn this into a MemberInitData
2161 exp = QMkExpId(name);
2162 members.type = dataMembersInit;
2163 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2169 case dataMembersInit:
2171 if(members.dataMembers && classSym)
2174 Location oldyyloc = yylloc;
2175 for(member = members.dataMembers->first; member; member = member.next)
2177 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2178 if(member.initializer && !member.initializer.isConstant)
2179 inst.isConstant = false;
2191 void DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2193 _DeclareType(neededFor, type, needDereference, forFunctionDef, false);
2196 void DeclareTypeForwardDeclare(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2198 _DeclareType(neededFor, type, needDereference, forFunctionDef, true);
2201 static void _DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef, bool fwdDecl)
2205 if(type.kind == functionType)
2208 for(param = type.params.first; param; param = param.next)
2209 _DeclareType(neededFor, param, forFunctionDef, false, fwdDecl);
2210 _DeclareType(neededFor, type.returnType, forFunctionDef, false, fwdDecl);
2212 else if(type.kind == pointerType)
2213 _DeclareType(neededFor, type.type, false, false, fwdDecl);
2214 else if(type.kind == classType)
2216 Class c = type._class.registered;
2217 _DeclareStruct(neededFor, c ? c.fullName : "ecere::com::Instance", c ? c.type == noHeadClass : false, needDereference && c && c.type == structClass, fwdDecl);
2219 else if(type.kind == structType || type.kind == unionType)
2222 for(member = type.members.first; member; member = member.next)
2223 _DeclareType(neededFor, member, needDereference, forFunctionDef, fwdDecl);
2225 else if(type.kind == arrayType)
2226 _DeclareType(neededFor, type.arrayType, true, false, fwdDecl);
2230 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2232 ClassTemplateArgument * arg = null;
2234 ClassTemplateParameter curParam = null;
2236 for(sClass = _class; sClass; sClass = sClass.base)
2239 if(sClass.templateClass) sClass = sClass.templateClass;
2240 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2242 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2244 for(sClass = sClass.base; sClass; sClass = sClass.base)
2246 if(sClass.templateClass) sClass = sClass.templateClass;
2247 id += sClass.templateParams.count;
2257 arg = &_class.templateArgs[id];
2258 if(arg && param.type == type)
2259 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2264 public Context SetupTemplatesContext(Class _class)
2266 Context context = PushContext();
2267 context.templateTypesOnly = true;
2268 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2270 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2271 for(; param; param = param.next)
2273 if(param.type == type && param.identifier)
2275 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2276 curContext.templateTypes.Add((BTNode)type);
2283 for(sClass = _class; sClass; sClass = sClass.base)
2285 ClassTemplateParameter p;
2286 for(p = sClass.templateParams.first; p; p = p.next)
2288 //OldList * specs = MkList();
2289 //Declarator decl = null;
2290 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2293 TemplateParameter param = p.param;
2297 // ADD DATA TYPE HERE...
2298 p.param = param = TemplateParameter
2300 identifier = MkIdentifier(p.name), type = p.type,
2301 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2304 type = TemplatedType { key = (uintptr)p.name, param = param };
2305 curContext.templateTypes.Add((BTNode)type);
2313 public void FinishTemplatesContext(Context context)
2315 PopContext(context);
2316 FreeContext(context);
2320 public void ProcessMethodType(Method method)
2322 if(!method.dataType)
2324 Context context = SetupTemplatesContext(method._class);
2326 method.dataType = ProcessTypeString(method.dataTypeString, false);
2328 FinishTemplatesContext(context);
2330 if(method.type != virtualMethod && method.dataType)
2332 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2334 if(!method._class.symbol)
2335 method._class.symbol = FindClass(method._class.fullName);
2336 method.dataType.thisClass = method._class.symbol;
2340 // Why was this commented out? Working fine without now...
2343 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2344 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2351 char * par = strstr(type, "(");
2352 char * classOp = null;
2357 for(c = par-type-1; c >= 0; c++)
2359 if(type[c] == ':' && type[c+1] == ':')
2361 classOp = type + c - 1;
2362 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2369 else if(!isspace(type[c]))
2376 int typeLen = strlen(type);
2377 memcpy(temp, classOp, classOpLen);
2378 temp[classOpLen] = '\0';
2380 _class = eSystem_FindClass(module, temp);
2383 method.dataTypeString = new char[typeLen - classOpLen + 1];
2384 memcpy(method.dataTypeString, type, classOp - type);
2385 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2388 method.dataTypeString = type;
2394 public void ProcessPropertyType(Property prop)
2398 Context context = SetupTemplatesContext(prop._class);
2399 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2400 FinishTemplatesContext(context);
2404 public void DeclareMethod(External neededFor, Method method, const char * name)
2406 Symbol symbol = method.symbol;
2407 if(!symbol || (!symbol.pointerExternal && (!symbol.methodCodeExternal || method.type == virtualMethod)))
2409 bool dllImport = false;
2411 if(!method.dataType)
2412 method.dataType = ProcessTypeString(method.dataTypeString, false);
2414 //if(!symbol || symbol._import || method.type == virtualMethod)
2416 if(!symbol || method.type == virtualMethod)
2419 if(!method._class.symbol)
2420 method._class.symbol = FindClass(method._class.fullName);
2421 classSym = method._class.symbol;
2422 if(!classSym._import)
2424 ModuleImport module;
2426 if(method._class.module && method._class.module.name)
2427 module = FindModule(method._class.module);
2429 module = mainModule;
2430 classSym._import = ClassImport
2432 name = CopyString(method._class.fullName);
2433 isRemote = method._class.isRemote;
2435 module.classes.Add(classSym._import);
2439 symbol = method.symbol = Symbol { };
2443 symbol._import = (ClassImport)MethodImport
2445 name = CopyString(method.name);
2446 isVirtual = method.type == virtualMethod;
2448 classSym._import.methods.Add(symbol._import);
2452 symbol.type = method.dataType;
2453 if(symbol.type) symbol.type.refCount++;
2456 if(!method.dataType.dllExport)
2458 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2465 // We need a declaration here :)
2467 OldList * specifiers, * declarators;
2469 Declarator funcDecl;
2472 specifiers = MkList();
2473 declarators = MkList();
2476 ListAdd(specifiers, MkSpecifier(EXTERN));
2477 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2478 ListAdd(specifiers, MkSpecifier(STATIC));
2480 if(method.type == virtualMethod)
2482 ListAdd(specifiers, MkSpecifier(INT));
2483 d = MkDeclaratorIdentifier(MkIdentifier(name));
2487 d = MkDeclaratorIdentifier(MkIdentifier(name));
2489 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2491 Context context = SetupTemplatesContext(method._class);
2492 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2493 FinishTemplatesContext(context);
2495 funcDecl = GetFuncDecl(d);
2499 Specifier spec, next;
2500 for(spec = specifiers->first; spec; spec = next)
2503 if(spec.type == extendedSpecifier)
2505 specifiers->Remove(spec);
2506 FreeSpecifier(spec);
2511 // Add this parameter if not a static method
2512 if(method.dataType && !method.dataType.staticMethod)
2514 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2516 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2517 TypeName thisParam = MkTypeName(MkListOne(
2518 MkSpecifierName(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2519 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2520 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2521 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2523 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2525 TypeName param = funcDecl.function.parameters->first;
2526 funcDecl.function.parameters->Remove(param);
2527 FreeTypeName(param);
2530 if(!funcDecl.function.parameters)
2531 funcDecl.function.parameters = MkList();
2532 funcDecl.function.parameters->Insert(null, thisParam);
2536 ProcessDeclarator(d, true);
2538 ListAdd(declarators, MkInitDeclarator(d, null));
2540 decl = MkDeclaration(specifiers, declarators);
2542 ReplaceThisClassSpecifiers(specifiers, method._class);
2544 external = MkExternalDeclaration(decl);
2545 external.symbol = symbol;
2546 symbol.pointerExternal = external;
2548 DeclareStruct(external, method._class.fullName, true, true);
2550 DeclareType(external, method.dataType, true, true);
2553 if(inCompiler && neededFor)
2555 External external = symbol.pointerExternal ? symbol.pointerExternal : symbol.methodCodeExternal;
2556 neededFor.CreateUniqueEdge(external, external.type == functionExternal);
2560 char * ReplaceThisClass(Class _class)
2562 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2566 ClassTemplateParameter param;
2569 char className[1024];
2570 strcpy(className, _class.fullName);
2571 for(param = _class.templateParams.first; param; param = param.next)
2573 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2575 if(first) strcat(className, "<");
2576 if(!first) strcat(className, ", ");
2577 if(lastParam + 1 != p)
2579 strcat(className, param.name);
2580 strcat(className, " = ");
2582 strcat(className, param.name);
2590 int len = strlen(className);
2591 if(className[len-1] == '>') className[len++] = ' ';
2592 className[len++] = '>';
2593 className[len++] = '\0';
2595 return CopyString(className);
2598 return CopyString(_class.fullName);
2601 Type ReplaceThisClassType(Class _class)
2604 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2608 ClassTemplateParameter param;
2610 char className[1024];
2611 strcpy(className, _class.fullName);
2613 for(param = _class.templateParams.first; param; param = param.next)
2615 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2617 if(first) strcat(className, "<");
2618 if(!first) strcat(className, ", ");
2619 if(lastParam + 1 != p)
2621 strcat(className, param.name);
2622 strcat(className, " = ");
2624 strcat(className, param.name);
2632 int len = strlen(className);
2633 if(className[len-1] == '>') className[len++] = ' ';
2634 className[len++] = '>';
2635 className[len++] = '\0';
2637 type = MkClassType(className);
2638 //type = ProcessTypeString(className, false);
2642 type = MkClassType(_class.fullName);
2643 //type = ProcessTypeString(_class.fullName, false);
2645 //type.wasThisClass = true;
2649 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2651 if(specs != null && _class)
2654 for(spec = specs.first; spec; spec = spec.next)
2656 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2658 spec.type = nameSpecifier;
2659 spec.name = ReplaceThisClass(_class);
2660 spec.symbol = FindClass(spec.name); //_class.symbol;
2666 // Returns imported or not
2667 bool DeclareFunction(External neededFor, GlobalFunction function, char * name)
2669 Symbol symbol = function.symbol;
2670 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2671 if(!symbol || !symbol.pointerExternal)
2673 bool imported = false;
2674 bool dllImport = false;
2676 if(!function.dataType)
2678 function.dataType = ProcessTypeString(function.dataTypeString, false);
2679 if(!function.dataType.thisClass)
2680 function.dataType.staticMethod = true;
2687 ModuleImport module = FindModule(function.module);
2688 // WARNING: This is not added anywhere...
2689 symbol = function.symbol = Symbol { };
2693 if(!function.dataType.dllExport)
2695 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2696 module.functions.Add(symbol._import);
2699 // Set the symbol type
2701 symbol.type = ProcessTypeString(function.dataTypeString, false);
2702 if(!symbol.type.thisClass)
2703 symbol.type.staticMethod = true;
2706 imported = symbol._import ? true : false;
2707 if(imported && function.module != privateModule && function.module.importType != staticImport)
2713 // TOCHECK: What's with the functionExternal check here? Is it Edge breaking / forward declaration?
2714 //if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2716 // We need a declaration here :)
2718 OldList * specifiers, * declarators;
2720 Declarator funcDecl;
2723 specifiers = MkList();
2724 declarators = MkList();
2726 ListAdd(specifiers, MkSpecifier(EXTERN));
2728 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2730 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2732 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2733 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2734 if(function.module.importType == staticImport)
2737 for(spec = specifiers->first; spec; spec = spec.next)
2738 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2740 specifiers->Remove(spec);
2741 FreeSpecifier(spec);
2746 funcDecl = GetFuncDecl(d);
2748 // Make sure we don't have empty parameter declarations for static methods...
2749 if(funcDecl && !funcDecl.function.parameters)
2751 funcDecl.function.parameters = MkList();
2752 funcDecl.function.parameters->Insert(null,
2753 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2756 ListAdd(declarators, MkInitDeclarator(d, null));
2759 Context oldCtx = curContext;
2760 curContext = globalContext;
2761 decl = MkDeclaration(specifiers, declarators);
2762 curContext = oldCtx;
2765 // Keep a different symbol for the function definition than the declaration...
2766 /* Note: This should be handled by the edge breaking...
2767 if(symbol.pointerExternal && symbol.pointerExternal.type == functionExternal)
2769 Symbol functionSymbol { };
2772 *functionSymbol = *symbol;
2773 functionSymbol.string = CopyString(symbol.string);
2774 if(functionSymbol.type)
2775 functionSymbol.type.refCount++;
2778 excludedSymbols->Add(functionSymbol);
2780 symbol.pointerExternal.symbol = functionSymbol;
2783 external = MkExternalDeclaration(decl);
2785 external.symbol = symbol;
2786 symbol.pointerExternal = external;
2788 DeclareType(external, function.dataType, true, true);
2792 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2793 neededFor.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
2794 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2797 void DeclareGlobalData(External neededFor, GlobalData data)
2799 Symbol symbol = data.symbol;
2800 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2801 if(!symbol || !symbol.pointerExternal)
2806 symbol = data.symbol = Symbol { };
2809 data.dataType = ProcessTypeString(data.dataTypeString, false);
2813 // We need a declaration here :)
2815 OldList * specifiers, * declarators;
2819 specifiers = MkList();
2820 declarators = MkList();
2822 ListAdd(specifiers, MkSpecifier(EXTERN));
2823 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2824 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2826 ListAdd(declarators, MkInitDeclarator(d, null));
2828 decl = MkDeclaration(specifiers, declarators);
2829 external = MkExternalDeclaration(decl);
2831 ast->Insert(curExternal.prev, external);
2832 external.symbol = symbol;
2833 symbol.pointerExternal = external;
2835 DeclareType(external, data.dataType, true, true);
2838 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2839 neededFor.CreateUniqueEdge(symbol.pointerExternal, false);
2842 class Conversion : struct
2844 Conversion prev, next;
2850 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2853 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2854 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2856 Class sourceClass = source.kind == classType ? source._class.registered : null;
2857 Class destClass = dest.kind == classType ? dest._class.registered : null;
2858 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2859 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2861 Type sourceType = source, destType = dest;
2862 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2863 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2864 if(!destType.constant && sourceType.constant)
2868 Compiler_Warning($"discarding const qualifier\n");
2875 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2876 bool isConversionExploration, bool warnConst)
2881 CheckConstCompatibility(source, dest, true);
2882 // Property convert;
2884 if(source.kind == templateType && dest.kind != templateType)
2886 Type type = ProcessTemplateParameterType(source.templateParameter);
2887 if(type) source = type;
2890 if(dest.kind == templateType && source.kind != templateType)
2892 Type type = ProcessTemplateParameterType(dest.templateParameter);
2893 if(type) dest = type;
2896 if(dest.classObjectType == typedObject && dest.kind != functionType)
2898 if(source.classObjectType != anyObject)
2902 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2903 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2911 if(source.kind != functionType && source.classObjectType == anyObject)
2913 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2917 if((dest.kind == structType && source.kind == structType) ||
2918 (dest.kind == unionType && source.kind == unionType))
2920 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2921 (source.members.first && source.members.first == dest.members.first))
2925 if(dest.kind == ellipsisType && source.kind != voidType)
2928 if(dest.kind == pointerType && dest.type.kind == voidType &&
2929 ((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))
2930 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2932 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2934 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2936 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2937 ((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))
2938 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2939 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2941 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2944 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2946 if(source._class.registered && source._class.registered.type == unitClass)
2948 if(conversions != null)
2950 if(source._class.registered == dest._class.registered)
2955 Class sourceBase, destBase;
2956 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2957 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2958 if(sourceBase == destBase)
2962 // Don't match enum inheriting from other enum if resolving enumeration values
2963 // TESTING: !dest.classObjectType
2964 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2966 (!source._class.registered || source._class.registered.type != enumClass) ||
2967 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2971 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2973 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2974 ((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)
2976 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2984 // JUST ADDED THIS...
2985 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2990 // Just added this for Straight conversion of ColorAlpha => Color
2991 if(source.kind == classType)
2994 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2997 for(convert = _class.conversions.first; convert; convert = convert.next)
2999 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3001 Conversion after = (conversions != null) ? conversions.last : null;
3003 if(!convert.dataType)
3004 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3005 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3006 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3007 MatchTypes(convert.dataType, dest, conversions, null, null,
3008 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3009 convert.dataType.kind == classType, false, true, warnConst))
3011 if(!conversions && !convert.Get)
3013 else if(conversions != null)
3015 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3016 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3017 (dest.kind != classType || dest._class.registered != _class.base))
3021 Conversion conv { convert = convert, isGet = true };
3022 // conversions.Add(conv);
3023 conversions.Insert(after, conv);
3036 if(dest.kind == classType)
3039 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3042 for(convert = _class.conversions.first; convert; convert = convert.next)
3044 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3046 Type constType = null;
3047 bool success = false;
3048 // Conversion after = (conversions != null) ? conversions.last : null;
3050 if(!convert.dataType)
3051 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3053 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3056 constType = { kind = pointerType, refCount = 1, type = ptrType };
3057 CopyTypeInto(ptrType, convert.dataType.type);
3058 ptrType.constant = true;
3061 // Just added this equality check to prevent recursion.... Make it safer?
3062 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3063 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3065 if(!conversions && !convert.Set)
3067 else if(conversions != null)
3069 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3070 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3071 (source.kind != classType || source._class.registered != _class.base))
3075 // *** Testing this! ***
3076 Conversion conv { convert = convert };
3077 conversions.Add(conv);
3078 //conversions.Insert(after, conv);
3084 FreeType(constType);
3090 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3092 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3093 (source.kind != classType || source._class.registered.type != structClass))
3097 // TESTING THIS... IS THIS OK??
3098 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3100 if(!dest._class.registered.dataType)
3101 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3102 // Only support this for classes...
3103 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3104 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3106 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3115 if(source.kind == classType)
3118 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3121 for(convert = _class.conversions.first; convert; convert = convert.next)
3123 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3125 Conversion after = (conversions != null) ? conversions.last : null;
3127 if(!convert.dataType)
3128 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3129 if(convert.dataType != source &&
3130 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3131 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3133 if(!conversions && !convert.Get)
3135 else if(conversions != null)
3137 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3138 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3139 (dest.kind != classType || dest._class.registered != _class.base))
3143 Conversion conv { convert = convert, isGet = true };
3145 // conversions.Add(conv);
3146 conversions.Insert(after, conv);
3155 // TESTING THIS... IS THIS OK??
3156 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3158 if(!source._class.registered.dataType)
3159 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3160 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3162 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))
3164 // For bool to be accepted by byte, short, etc.
3165 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3172 if(source.kind == classType || source.kind == subClassType)
3174 else if(dest.kind == source.kind &&
3175 (dest.kind != structType && dest.kind != unionType &&
3176 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3178 // RECENTLY ADDED THESE
3179 else if(dest.kind == doubleType && source.kind == floatType)
3181 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3183 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3185 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3187 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3189 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3191 else if(source.kind == enumType &&
3192 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3194 else if(dest.kind == enumType && !isConversionExploration &&
3195 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3197 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3198 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3200 Type paramSource, paramDest;
3202 if(dest.kind == methodType)
3203 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3204 if(source.kind == methodType)
3205 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3207 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3208 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3209 if(dest.kind == methodType)
3210 dest = dest.method.dataType;
3211 if(source.kind == methodType)
3212 source = source.method.dataType;
3214 paramSource = source.params.first;
3215 if(paramSource && paramSource.kind == voidType) paramSource = null;
3216 paramDest = dest.params.first;
3217 if(paramDest && paramDest.kind == voidType) paramDest = null;
3220 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3221 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3223 // Source thisClass must be derived from destination thisClass
3224 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3225 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3227 if(paramDest && paramDest.kind == classType)
3228 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3230 Compiler_Error($"method class should not take an object\n");
3233 paramDest = paramDest.next;
3235 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3237 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3241 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3243 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3249 // THIS WAS BACKWARDS:
3250 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3251 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3254 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3256 Compiler_Error($"overriding class expected to be derived from method class\n");
3260 paramSource = paramSource.next;
3266 // Source thisClass must be derived from destination thisClass
3267 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3269 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3275 // THIS WAS BACKWARDS TOO??
3276 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3277 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3280 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3282 //Compiler_Error($"overriding class expected to be derived from method class\n");
3290 // Source return type must be derived from destination return type
3291 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3293 Compiler_Warning($"incompatible return type for function\n");
3296 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3298 CheckConstCompatibility(dest.returnType, source.returnType, true);
3302 for(; paramDest; paramDest = paramDest.next)
3306 //Compiler_Warning($"not enough parameters\n");
3307 Compiler_Error($"not enough parameters\n");
3311 Type paramDestType = paramDest;
3312 Type paramSourceType = paramSource;
3313 Type type = paramDestType;
3315 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3316 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3317 paramSource.kind != templateType)
3320 ClassTemplateParameter curParam = null;
3322 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3325 if(sClass.templateClass) sClass = sClass.templateClass;
3326 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3328 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3330 for(sClass = sClass.base; sClass; sClass = sClass.base)
3332 if(sClass.templateClass) sClass = sClass.templateClass;
3333 id += sClass.templateParams.count;
3344 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3345 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3349 // paramDest must be derived from paramSource
3350 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3351 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3355 PrintType(paramDest, type, false, true);
3356 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3358 if(paramDestType != paramDest)
3359 FreeType(paramDestType);
3362 if(paramDestType != paramDest)
3363 FreeType(paramDestType);
3366 paramSource = paramSource.next;
3370 Compiler_Error($"too many parameters\n");
3375 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3379 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3380 (source.kind == arrayType || source.kind == pointerType))
3382 // Pointers to pointer is incompatible with non normal/nohead classes
3383 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3384 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3386 ComputeTypeSize(source.type);
3387 ComputeTypeSize(dest.type);
3388 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3396 static void FreeConvert(Conversion convert)
3398 if(convert.resultType)
3399 FreeType(convert.resultType);
3402 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3403 char * string, OldList conversions)
3407 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3409 Class _class = link.data;
3410 if(_class.type == enumClass)
3412 OldList converts { };
3414 type.kind = classType;
3417 _class.symbol = FindClass(_class.fullName);
3418 type._class = _class.symbol;
3420 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3421 false, false, false, false))
3424 Class enumClass = eSystem_FindClass(privateModule, "enum");
3428 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3430 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3431 for(value = e.values.first; value; value = value.next)
3433 if(!strcmp(value.name, string))
3438 FreeType(sourceExp.expType);
3440 sourceExp.isConstant = true;
3441 sourceExp.expType = MkClassType(baseClass.fullName);
3442 if(inCompiler || inPreCompiler || inDebugger)
3445 FreeExpContents(sourceExp);
3447 sourceExp.type = constantExp;
3448 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3449 sprintf(constant, FORMAT64D, value.data);
3451 sprintf(constant, FORMAT64HEXLL, value.data);
3452 sourceExp.constant = CopyString(constant);
3453 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3456 while(converts.first)
3458 Conversion convert = converts.first;
3459 converts.Remove(convert);
3460 conversions.Add(convert);
3469 converts.Free(FreeConvert);
3473 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3474 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3479 public bool ModuleVisibility(Module searchIn, Module searchFor)
3481 SubModule subModule;
3483 if(searchFor == searchIn)
3486 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3488 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3490 if(ModuleVisibility(subModule.module, searchFor))
3497 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3501 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3503 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3505 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3508 for(module = mainModule.application.allModules.first; module; module = module.next)
3510 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3516 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3519 Type realDest = dest;
3520 Type backupSourceExpType = null;
3521 Expression nbExp = GetNonBracketsExp(sourceExp);
3522 Expression computedExp = nbExp;
3525 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3526 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3528 computedExp = CopyExpression(nbExp); // Keep the original expression, but compute for checking enum ranges
3529 ComputeExpression(computedExp /*sourceExp*/);
3532 source = sourceExp.expType;
3534 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3536 if(computedExp != nbExp)
3538 FreeExpression(computedExp);
3539 computedExp = nbExp;
3545 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3547 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3549 Class sourceBase, destBase;
3550 for(sourceBase = source._class.registered;
3551 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3552 sourceBase = sourceBase.base);
3553 for(destBase = dest._class.registered;
3554 destBase && destBase.base && destBase.base.type != systemClass;
3555 destBase = destBase.base);
3556 //if(source._class.registered == dest._class.registered)
3557 if(sourceBase == destBase)
3559 if(computedExp != nbExp)
3561 FreeExpression(computedExp);
3562 computedExp = nbExp;
3574 int64 value = MAXINT;
3578 if(computedExp.type == constantExp)
3581 value = strtoll(computedExp.constant, null, 0);
3583 value = strtoull(computedExp.constant, null, 0);
3585 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3588 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3590 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3592 if(computedExp != nbExp)
3594 FreeExpression(computedExp);
3595 computedExp = nbExp;
3598 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3599 !strcmp(source._class.registered.fullName, "unichar" /*"ecere::com::unichar"*/))
3602 source = Type { kind = intType, isSigned = false, refCount = 1 };
3605 if(dest.kind == classType)
3607 Class _class = dest._class ? dest._class.registered : null;
3609 if(_class && _class.type == unitClass)
3611 if(source.kind != classType)
3614 Type tempDest, tempSource;
3616 for(; _class.base.type != systemClass; _class = _class.base);
3618 tempDest = tempType;
3620 tempType.kind = classType;
3622 _class.symbol = FindClass(_class.fullName);
3624 tempType._class = _class.symbol;
3625 tempType.truth = dest.truth;
3627 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3629 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3630 backupSourceExpType = sourceExp.expType;
3631 if(dest.passAsTemplate)
3633 // Don't carry passAsTemplate
3634 sourceExp.expType = { };
3635 CopyTypeInto(sourceExp.expType, dest);
3636 sourceExp.expType.passAsTemplate = false;
3640 sourceExp.expType = dest;
3643 //sourceExp.expType = MkClassType(_class.fullName);
3651 // Why wasn't there something like this?
3652 if(_class && _class.type == bitClass && source.kind != classType)
3654 if(!dest._class.registered.dataType)
3655 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3656 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3659 FreeType(sourceExp.expType);
3660 source = sourceExp.expType = MkClassType(dest._class.string);
3663 //source.kind = classType;
3664 //source._class = dest._class;
3668 // Adding two enumerations
3670 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3672 if(!source._class.registered.dataType)
3673 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3674 if(!dest._class.registered.dataType)
3675 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3677 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3680 source = sourceExp.expType = MkClassType(dest._class.string);
3683 //source.kind = classType;
3684 //source._class = dest._class;
3688 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3690 OldList * specs = MkList();
3694 ReadString(string, sourceExp.string);
3695 decl = SpecDeclFromString(string, specs, null);
3697 FreeExpContents(sourceExp);
3698 FreeType(sourceExp.expType);
3700 sourceExp.type = classExp;
3701 sourceExp._classExp.specifiers = specs;
3702 sourceExp._classExp.decl = decl;
3703 sourceExp.expType = dest;
3708 if(backupSourceExpType) FreeType(backupSourceExpType);
3712 else if(source.kind == classType)
3714 Class _class = source._class ? source._class.registered : null;
3716 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || _class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3719 if(dest.kind != classType)
3721 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3722 if(!source._class.registered.dataType)
3723 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3726 dest = MkClassType(source._class.string);
3727 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3728 // dest = MkClassType(source._class.string);
3732 if(dest.kind != classType)
3735 Type tempDest, tempSource;
3737 if(!source._class.registered.dataType)
3738 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3740 for(; _class.base.type != systemClass; _class = _class.base);
3742 tempSource = tempType;
3743 tempType.kind = classType;
3744 tempType._class = FindClass(_class.fullName);
3745 tempType.truth = source.truth;
3746 tempType.classObjectType = source.classObjectType;
3749 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3751 // PUT THIS BACK TESTING UNITS?
3752 if(conversions && conversions.last)
3754 ((Conversion)(conversions.last)).resultType = dest;
3758 FreeType(sourceExp.expType);
3759 sourceExp.expType = MkClassType(_class.fullName);
3760 sourceExp.expType.truth = source.truth;
3761 sourceExp.expType.classObjectType = source.classObjectType;
3763 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3765 if(!sourceExp.destType)
3767 FreeType(sourceExp.destType);
3768 sourceExp.destType = sourceExp.expType;
3769 if(sourceExp.expType)
3770 sourceExp.expType.refCount++;
3773 //source = _class.dataType;
3776 // TOCHECK: TESTING THIS NEW CODE
3777 if(!_class.dataType)
3778 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3780 dest = MkClassType(source._class.string);
3781 dest.truth = source.truth;
3782 dest.classObjectType = source.classObjectType;
3785 source = _class.dataType;
3795 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3805 if(source.kind == classType)
3807 Class _class = source._class.registered;
3808 if(_class.type == unitClass)
3810 if(!_class.dataType)
3811 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3812 source = _class.dataType;
3816 if(dest.kind == classType)
3818 Class _class = dest._class ? dest._class.registered : null;
3819 bool fittingValue = false;
3820 if(_class && _class.type == enumClass)
3822 Class enumClass = eSystem_FindClass(privateModule, "enum");
3823 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3824 if(c && value >= 0 && value <= c.largest)
3825 fittingValue = true;
3828 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3829 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3831 if(_class.type == normalClass || _class.type == noHeadClass)
3833 Expression newExp { };
3834 *newExp = *sourceExp;
3835 if(sourceExp.destType) sourceExp.destType.refCount++;
3836 if(sourceExp.expType) sourceExp.expType.refCount++;
3837 sourceExp.type = castExp;
3838 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3839 sourceExp.cast.exp = newExp;
3840 FreeType(sourceExp.expType);
3841 sourceExp.expType = null;
3842 ProcessExpressionType(sourceExp);
3844 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3847 FreeType(sourceExp.expType);
3848 sourceExp.expType = dest;
3852 if(inCompiler) FreeType(dest);
3854 if(backupSourceExpType) FreeType(backupSourceExpType);
3858 if(!_class.dataType)
3859 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3861 dest = _class.dataType;
3865 // Accept lower precision types for units, since we want to keep the unit type
3866 if(dest.kind == doubleType &&
3867 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3868 source.kind == charType || source.kind == _BoolType))
3870 specs = MkListOne(MkSpecifier(DOUBLE));
3872 else if(dest.kind == floatType &&
3873 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3874 source.kind == _BoolType || source.kind == doubleType))
3876 specs = MkListOne(MkSpecifier(FLOAT));
3878 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3879 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3882 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3883 ListAdd(specs, MkSpecifier(INT64));
3885 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3886 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3889 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3890 ListAdd(specs, MkSpecifier(INT));
3892 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3893 source.kind == floatType || source.kind == doubleType))
3896 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3897 ListAdd(specs, MkSpecifier(SHORT));
3899 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3900 source.kind == floatType || source.kind == doubleType))
3903 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3904 ListAdd(specs, MkSpecifier(CHAR));
3910 if(backupSourceExpType)
3912 // Failed to convert: revert previous exp type
3913 if(sourceExp.expType) FreeType(sourceExp.expType);
3914 sourceExp.expType = backupSourceExpType;
3919 else if(dest.kind == doubleType &&
3920 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3921 source.kind == _BoolType || source.kind == charType))
3923 specs = MkListOne(MkSpecifier(DOUBLE));
3925 else if(dest.kind == floatType &&
3926 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3928 specs = MkListOne(MkSpecifier(FLOAT));
3930 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3931 (value == 1 || value == 0))
3934 ListAdd(specs, MkSpecifier(BOOL));
3936 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3937 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3939 if(source.kind == intType)
3943 if(backupSourceExpType) FreeType(backupSourceExpType);
3949 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3950 ListAdd(specs, MkSpecifier(CHAR));
3953 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3954 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3956 if(source.kind == intType)
3960 if(backupSourceExpType) FreeType(backupSourceExpType);
3966 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3967 ListAdd(specs, MkSpecifier(SHORT));
3970 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3973 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3974 ListAdd(specs, MkSpecifier(INT));
3976 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3979 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3980 ListAdd(specs, MkSpecifier(INT64));
3982 else if(dest.kind == enumType &&
3983 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3985 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3991 if(backupSourceExpType)
3993 // Failed to convert: revert previous exp type
3994 if(sourceExp.expType) FreeType(sourceExp.expType);
3995 sourceExp.expType = backupSourceExpType;
4000 if(!flag && !sourceExp.opDestType)
4002 Expression newExp { };
4003 *newExp = *sourceExp;
4006 if(sourceExp.destType) sourceExp.destType.refCount++;
4007 if(sourceExp.expType) sourceExp.expType.refCount++;
4009 sourceExp.type = castExp;
4010 if(realDest.kind == classType)
4012 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4013 FreeList(specs, FreeSpecifier);
4016 sourceExp.cast.typeName = MkTypeName(specs, null);
4017 if(newExp.type == opExp)
4019 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4022 sourceExp.cast.exp = newExp;
4024 FreeType(sourceExp.expType);
4025 sourceExp.expType = null;
4026 ProcessExpressionType(sourceExp);
4029 FreeList(specs, FreeSpecifier);
4033 if(backupSourceExpType) FreeType(backupSourceExpType);
4039 if(computedExp != nbExp)
4041 FreeExpression(computedExp);
4042 computedExp = nbExp;
4045 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4046 if(sourceExp.type == identifierExp)
4048 Identifier id = sourceExp.identifier;
4049 if(dest.kind == classType)
4051 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4053 Class _class = dest._class.registered;
4054 Class enumClass = eSystem_FindClass(privateModule, "enum");
4057 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4060 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4061 for(value = e.values.first; value; value = value.next)
4063 if(!strcmp(value.name, id.string))
4068 FreeType(sourceExp.expType);
4070 sourceExp.isConstant = true;
4071 sourceExp.expType = MkClassType(_class.fullName);
4072 if(inCompiler || inPreCompiler || inDebugger)
4074 FreeExpContents(sourceExp);
4076 sourceExp.type = constantExp;
4077 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4078 sourceExp.constant = PrintInt64(value.data);
4080 sourceExp.constant = PrintUInt64(value.data);
4081 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4091 // Loop through all enum classes
4092 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4103 #define TERTIARY(o, name, m, t, p) \
4104 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4106 exp.type = constantExp; \
4107 exp.string = p(op1.m ? op2.m : op3.m); \
4109 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4113 #define BINARY(o, name, m, t, p) \
4114 static bool name(Expression exp, Operand op1, Operand op2) \
4117 exp.type = constantExp; \
4118 exp.string = p((t)(op1.m o value2)); \
4120 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4124 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4125 static bool name(Expression exp, Operand op1, Operand op2) \
4128 exp.type = constantExp; \
4129 exp.string = p(value2 ? ((t)(op1.m o value2)) : 0); \
4131 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4135 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4136 static bool name(Expression exp, Operand op1, Operand op2) \
4139 exp.type = constantExp; \
4140 exp.string = p((t)(op1.m o value2)); \
4142 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4146 #define UNARY(o, name, m, t, p) \
4147 static bool name(Expression exp, Operand op1) \
4149 exp.type = constantExp; \
4150 exp.string = p((t)(o op1.m)); \
4152 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4156 #define OPERATOR_ALL(macro, o, name) \
4157 macro(o, Int##name, i, int, PrintInt) \
4158 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4159 macro(o, Int64##name, i64, int64, PrintInt64) \
4160 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4161 macro(o, Short##name, s, short, PrintShort) \
4162 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4163 macro(o, Char##name, c, char, PrintChar) \
4164 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4165 macro(o, Float##name, f, float, PrintFloat) \
4166 macro(o, Double##name, d, double, PrintDouble)
4168 #define OPERATOR_INTTYPES(macro, o, name) \
4169 macro(o, Int##name, i, int, PrintInt) \
4170 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4171 macro(o, Int64##name, i64, int64, PrintInt64) \
4172 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4173 macro(o, Short##name, s, short, PrintShort) \
4174 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4175 macro(o, Char##name, c, char, PrintChar) \
4176 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4178 #define OPERATOR_REALTYPES(macro, o, name) \
4179 macro(o, Float##name, f, float, PrintFloat) \
4180 macro(o, Double##name, d, double, PrintDouble)
4182 // binary arithmetic
4183 OPERATOR_ALL(BINARY, +, Add)
4184 OPERATOR_ALL(BINARY, -, Sub)
4185 OPERATOR_ALL(BINARY, *, Mul)
4186 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4187 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4188 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4191 OPERATOR_ALL(UNARY, -, Neg)
4193 // unary arithmetic increment and decrement
4194 OPERATOR_ALL(UNARY, ++, Inc)
4195 OPERATOR_ALL(UNARY, --, Dec)
4197 // binary arithmetic assignment
4198 OPERATOR_ALL(BINARY, =, Asign)
4199 OPERATOR_ALL(BINARY, +=, AddAsign)
4200 OPERATOR_ALL(BINARY, -=, SubAsign)
4201 OPERATOR_ALL(BINARY, *=, MulAsign)
4202 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4203 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4204 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4207 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4208 OPERATOR_INTTYPES(BINARY, |, BitOr)
4209 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4210 OPERATOR_INTTYPES(BINARY, <<, LShift)
4211 OPERATOR_INTTYPES(BINARY, >>, RShift)
4214 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4216 // binary bitwise assignment
4217 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4218 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4219 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4220 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4221 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4223 // unary logical negation
4224 OPERATOR_INTTYPES(UNARY, !, Not)
4226 // binary logical equality
4227 OPERATOR_ALL(BINARY, ==, Equ)
4228 OPERATOR_ALL(BINARY, !=, Nqu)
4231 OPERATOR_ALL(BINARY, &&, And)
4232 OPERATOR_ALL(BINARY, ||, Or)
4234 // binary logical relational
4235 OPERATOR_ALL(BINARY, >, Grt)
4236 OPERATOR_ALL(BINARY, <, Sma)
4237 OPERATOR_ALL(BINARY, >=, GrtEqu)
4238 OPERATOR_ALL(BINARY, <=, SmaEqu)
4240 // tertiary condition operator
4241 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4243 //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
4244 #define OPERATOR_TABLE_ALL(name, type) \
4245 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4247 type##Inc, type##Dec, \
4248 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4249 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4251 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4253 type##Equ, type##Nqu, \
4254 type##And, type##Or, \
4255 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4258 #define OPERATOR_TABLE_INTTYPES(name, type) \
4259 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4261 type##Inc, type##Dec, \
4262 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4263 null, null, null, null, null, \
4265 null, null, null, null, null, \
4267 type##Equ, type##Nqu, \
4268 type##And, type##Or, \
4269 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4272 OPERATOR_TABLE_ALL(int, Int)
4273 OPERATOR_TABLE_ALL(uint, UInt)
4274 OPERATOR_TABLE_ALL(int64, Int64)
4275 OPERATOR_TABLE_ALL(uint64, UInt64)
4276 OPERATOR_TABLE_ALL(short, Short)
4277 OPERATOR_TABLE_ALL(ushort, UShort)
4278 OPERATOR_TABLE_INTTYPES(float, Float)
4279 OPERATOR_TABLE_INTTYPES(double, Double)
4280 OPERATOR_TABLE_ALL(char, Char)
4281 OPERATOR_TABLE_ALL(uchar, UChar)
4283 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4284 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4285 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4286 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4287 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4288 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4289 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4290 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4292 public void ReadString(char * output, char * string)
4294 int len = strlen(string);
4296 bool quoted = false, escaped = false;
4297 for(c = 0; c<len; c++)
4299 char ch = string[c];
4304 case 'n': output[d] = '\n'; break;
4305 case 't': output[d] = '\t'; break;
4306 case 'a': output[d] = '\a'; break;
4307 case 'b': output[d] = '\b'; break;
4308 case 'f': output[d] = '\f'; break;
4309 case 'r': output[d] = '\r'; break;
4310 case 'v': output[d] = '\v'; break;
4311 case '\\': output[d] = '\\'; break;
4312 case '\"': output[d] = '\"'; break;
4313 case '\'': output[d] = '\''; break;
4314 default: output[d] = ch;
4335 // String Unescape Copy
4337 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4338 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4339 public int UnescapeString(char * d, char * s, int len)
4343 while(j < len && (ch = s[j]))
4348 switch((ch = s[++j]))
4350 case 'n': d[k] = '\n'; break;
4351 case 't': d[k] = '\t'; break;
4352 case 'a': d[k] = '\a'; break;
4353 case 'b': d[k] = '\b'; break;
4354 case 'f': d[k] = '\f'; break;
4355 case 'r': d[k] = '\r'; break;
4356 case 'v': d[k] = '\v'; break;
4357 case '\\': d[k] = '\\'; break;
4358 case '\"': d[k] = '\"'; break;
4359 case '\'': d[k] = '\''; break;
4360 default: d[k] = '\\'; d[k] = ch;
4372 public char * OffsetEscapedString(char * s, int len, int offset)
4376 while(j < len && k < offset && (ch = s[j]))
4381 return (k == offset) ? s + j : null;
4384 public Operand GetOperand(Expression exp)
4387 Type type = exp.expType;
4390 while(type.kind == classType &&
4391 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4393 if(!type._class.registered.dataType)
4394 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4395 type = type._class.registered.dataType;
4398 if(exp.type == stringExp && op.kind == pointerType)
4400 op.ui64 = (uint64)(uintptr)exp.string;
4401 op.kind = pointerType;
4404 else if(exp.isConstant && exp.type == constantExp)
4406 op.kind = type.kind;
4414 if(exp.constant[0] == '\'')
4416 op.c = exp.constant[1];
4419 else if(type.isSigned)
4421 op.c = (char)strtol(exp.constant, null, 0);
4426 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4432 if(exp.constant[0] == '\'')
4434 op.s = exp.constant[1];
4437 else if(type.isSigned)
4439 op.s = (short)strtol(exp.constant, null, 0);
4444 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4450 if(exp.constant[0] == '\'')
4452 op.i = exp.constant[1];
4455 else if(type.isSigned)
4457 op.i = (int)strtol(exp.constant, null, 0);
4462 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4470 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4475 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4478 op.kind = int64Type;
4483 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4488 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4491 op.kind = int64Type;
4496 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4501 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4504 op.kind = int64Type;
4507 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4508 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4509 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4510 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4512 op.f = (float)strtod(exp.constant, null);
4516 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4517 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4518 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4519 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4521 op.d = (double)strtod(exp.constant, null);
4524 //case classType: For when we have operator overloading...
4525 // Pointer additions
4526 //case functionType:
4530 op.ui64 = _strtoui64(exp.constant, null, 0);
4531 op.kind = pointerType;
4541 static int64 GetEnumValue(Class _class, void * ptr)
4544 switch(_class.typeSize)
4547 if(!strcmp(_class.dataTypeString, "uint64"))
4548 v = (int64)*(uint64 *)ptr;
4550 v = (int64)*(int64 *)ptr;
4553 if(!strcmp(_class.dataTypeString, "uint"))
4554 v = (int64)*(uint *)ptr;
4556 v = (int64)*(int *)ptr;
4559 if(!strcmp(_class.dataTypeString, "uint16"))
4560 v = (int64)*(uint16 *)ptr;
4562 v = (int64)*(short *)ptr;
4565 if(!strcmp(_class.dataTypeString, "byte"))
4566 v = (int64)*(byte *)ptr;
4568 v = (int64)*(char *)ptr;
4574 static __attribute__((unused)) void UnusedFunction()
4577 a.OnGetString(0,0,0);
4580 extern int __ecereVMethodID_class_OnGetString;
4583 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4585 DataMember dataMember;
4586 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4588 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4589 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4593 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4595 void * ptr = inst.data + dataMember.offset + offset;
4596 char * result = null;
4597 exp.loc = member.loc = inst.loc;
4598 ((Identifier)member.identifiers->first).loc = inst.loc;
4600 if(!dataMember.dataType)
4601 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4602 type = dataMember.dataType;
4603 if(type.kind == classType)
4605 Class _class = type._class.registered;
4606 if(_class.type == enumClass)
4608 Class enumClass = eSystem_FindClass(privateModule, "enum");
4611 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4613 for(item = e.values.first; item; item = item.next)
4615 if(item.data == GetEnumValue(_class, ptr))
4623 exp.identifier = MkIdentifier(result);
4624 exp.type = identifierExp;
4625 exp.destType = MkClassType(_class.fullName);
4626 ProcessExpressionType(exp);
4630 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4632 if(!_class.dataType)
4633 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4634 type = _class.dataType;
4643 FreeExpContents(exp);
4645 exp.constant = PrintFloat(*(float*)ptr);
4646 exp.type = constantExp;
4651 FreeExpContents(exp);
4653 exp.constant = PrintDouble(*(double*)ptr);
4654 exp.type = constantExp;
4659 FreeExpContents(exp);
4661 exp.constant = PrintInt(*(int*)ptr);
4662 exp.type = constantExp;
4667 FreeExpContents(exp);
4669 exp.constant = PrintInt64(*(int64*)ptr);
4670 exp.type = constantExp;
4675 FreeExpContents(exp);
4676 // TODO: This should probably use proper type
4677 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4678 exp.type = constantExp;
4683 FreeExpContents(exp);
4684 // TODO: This should probably use proper type
4685 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4686 exp.type = constantExp;
4690 Compiler_Error($"Unhandled type populating instance\n");
4693 ListAdd(memberList, member);
4696 if(parentDataMember.type == unionMember)
4701 void PopulateInstance(Instantiation inst)
4703 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4704 Class _class = classSym.registered;
4705 DataMember dataMember;
4706 OldList * memberList = MkList();
4707 // Added this check and ->Add to prevent memory leaks on bad code
4709 inst.members = MkListOne(MkMembersInitList(memberList));
4711 inst.members->Add(MkMembersInitList(memberList));
4712 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4714 if(!dataMember.isProperty)
4716 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4717 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4721 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4723 void * ptr = inst.data + dataMember.offset;
4724 char * result = null;
4726 exp.loc = member.loc = inst.loc;
4727 ((Identifier)member.identifiers->first).loc = inst.loc;
4729 if(!dataMember.dataType)
4730 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4731 type = dataMember.dataType;
4732 if(type.kind == classType)
4734 Class _class = type._class.registered;
4735 if(_class.type == enumClass)
4737 Class enumClass = eSystem_FindClass(privateModule, "enum");
4740 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4742 for(item = e.values.first; item; item = item.next)
4744 if(item.data == GetEnumValue(_class, ptr))
4753 exp.identifier = MkIdentifier(result);
4754 exp.type = identifierExp;
4755 exp.destType = MkClassType(_class.fullName);
4756 ProcessExpressionType(exp);
4759 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4761 if(!_class.dataType)
4762 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4763 type = _class.dataType;
4772 exp.constant = PrintFloat(*(float*)ptr);
4773 exp.type = constantExp;
4778 exp.constant = PrintDouble(*(double*)ptr);
4779 exp.type = constantExp;
4784 exp.constant = PrintInt(*(int*)ptr);
4785 exp.type = constantExp;
4790 exp.constant = PrintInt64(*(int64*)ptr);
4791 exp.type = constantExp;
4796 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4797 exp.type = constantExp;
4801 Compiler_Error($"Unhandled type populating instance\n");
4804 ListAdd(memberList, member);
4810 void ComputeInstantiation(Expression exp)
4812 Instantiation inst = exp.instance;
4813 MembersInit members;
4814 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4815 Class _class = classSym ? classSym.registered : null;
4816 DataMember curMember = null;
4817 Class curClass = null;
4818 DataMember subMemberStack[256];
4819 int subMemberStackPos = 0;
4822 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4824 // Don't recompute the instantiation...
4825 // Non Simple classes will have become constants by now
4829 if(_class.type == normalClass || _class.type == noHeadClass)
4831 inst.data = (byte *)eInstance_New(_class);
4832 if(_class.type == normalClass)
4833 ((Instance)inst.data)._refCount++;
4836 inst.data = new0 byte[_class.structSize];
4841 for(members = inst.members->first; members; members = members.next)
4843 switch(members.type)
4845 case dataMembersInit:
4847 if(members.dataMembers)
4850 for(member = members.dataMembers->first; member; member = member.next)
4852 Identifier ident = member.identifiers ? member.identifiers->first : null;
4855 Property prop = null;
4856 DataMember dataMember = null;
4857 uint dataMemberOffset;
4861 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4864 if(curMember.isProperty)
4865 prop = (Property)curMember;
4868 dataMember = curMember;
4870 // CHANGED THIS HERE
4871 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4873 // 2013/17/29 -- It seems that this was missing here!
4874 if(_class.type == normalClass)
4875 dataMemberOffset += _class.base.structSize;
4876 // dataMemberOffset = dataMember.offset;
4883 prop = eClass_FindProperty(_class, ident.string, privateModule);
4887 if(prop.memberAccess == publicAccess)
4889 curMember = (DataMember)prop;
4890 curClass = prop._class;
4895 DataMember _subMemberStack[256];
4896 int _subMemberStackPos = 0;
4898 // FILL MEMBER STACK
4899 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4904 if(dataMember.memberAccess == publicAccess)
4906 curMember = dataMember;
4907 curClass = dataMember._class;
4908 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4909 subMemberStackPos = _subMemberStackPos;
4915 if(found && member.initializer && member.initializer.type == expInitializer)
4917 Expression value = member.initializer.exp;
4919 bool deepMember = false;
4922 type = prop.dataType;
4926 if(!dataMember.dataType)
4927 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4929 type = dataMember.dataType;
4932 if(ident && ident.next)
4936 // for(; ident && type; ident = ident.next)
4937 for(ident = ident.next; ident && type; ident = ident.next)
4939 if(type.kind == classType)
4941 prop = eClass_FindProperty(type._class.registered,
4942 ident.string, privateModule);
4944 type = prop.dataType;
4947 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4948 ident.string, &dataMemberOffset, privateModule, null, null);
4950 type = dataMember.dataType;
4953 else if(type.kind == structType || type.kind == unionType)
4956 for(memberType = type.members.first; memberType; memberType = memberType.next)
4958 if(!strcmp(memberType.name, ident.string))
4969 FreeType(value.destType);
4970 value.destType = type;
4971 if(type) type.refCount++;
4972 ComputeExpression(value);
4974 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4976 if(type.kind == classType)
4978 Class _class = type._class.registered;
4979 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4981 if(!_class.dataType)
4982 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4983 type = _class.dataType;
4989 void * ptr = inst.data + dataMemberOffset;
4991 if(value.type == constantExp)
4997 GetInt(value, (int*)ptr);
5002 GetInt64(value, (int64*)ptr);
5007 GetIntPtr(value, (intptr*)ptr);
5012 GetIntSize(value, (intsize*)ptr);
5017 GetFloat(value, (float*)ptr);
5022 GetDouble(value, (double *)ptr);
5027 else if(value.type == instanceExp)
5029 if(type.kind == classType)
5031 Class _class = type._class.registered;
5032 if(_class.type == structClass)
5034 ComputeTypeSize(type);
5035 if(value.instance.data)
5036 memcpy(ptr, value.instance.data, type.size);
5041 else if(prop && prop.Set != (void *)(intptr)1)
5043 if(value.type == instanceExp && value.instance.data)
5045 if(type.kind == classType)
5047 Class _class = type._class.registered;
5048 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5050 void (*Set)(void *, void *) = (void *)prop.Set;
5051 Set(inst.data, value.instance.data);
5052 PopulateInstance(inst);
5056 else if(value.type == constantExp)
5062 void (*Set)(void *, double) = (void *)prop.Set;
5063 Set(inst.data, strtod(value.constant, null) );
5068 void (*Set)(void *, float) = (void *)prop.Set;
5069 Set(inst.data, (float)(strtod(value.constant, null)));
5074 void (*Set)(void *, int) = (void *)prop.Set;
5075 Set(inst.data, (int)strtol(value.constant, null, 0));
5080 void (*Set)(void *, int64) = (void *)prop.Set;
5081 Set(inst.data, _strtoi64(value.constant, null, 0));
5086 void (*Set)(void *, intptr) = (void *)prop.Set;
5087 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5092 void (*Set)(void *, intsize) = (void *)prop.Set;
5093 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5098 else if(value.type == stringExp)
5101 ReadString(temp, value.string);
5102 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5106 else if(!deepMember && type && _class.type == unitClass)
5110 // Only support converting units to units for now...
5111 if(value.type == constantExp)
5113 if(type.kind == classType)
5115 Class _class = type._class.registered;
5116 if(_class.type == unitClass)
5118 if(!_class.dataType)
5119 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5120 type = _class.dataType;
5123 // TODO: Assuming same base type for units...
5129 float (*Set)(float) = (void *)prop.Set;
5130 GetFloat(member.initializer.exp, &fValue);
5131 exp.constant = PrintFloat(Set(fValue));
5132 exp.type = constantExp;
5138 double (*Set)(double) = (void *)prop.Set;
5139 GetDouble(member.initializer.exp, &dValue);
5140 exp.constant = PrintDouble(Set(dValue));
5141 exp.type = constantExp;
5148 else if(!deepMember && type && _class.type == bitClass)
5152 if(value.type == instanceExp && value.instance.data)
5154 unsigned int (*Set)(void *) = (void *)prop.Set;
5155 bits = Set(value.instance.data);
5157 else if(value.type == constantExp)
5163 BitMember bitMember = (BitMember) dataMember;
5166 bits = (bits & ~bitMember.mask);
5167 if(!bitMember.dataType)
5168 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5169 type = bitMember.dataType;
5170 if(type.kind == classType && type._class && type._class.registered)
5172 if(!type._class.registered.dataType)
5173 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5174 type = type._class.registered.dataType;
5179 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5180 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5182 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5183 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5184 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5185 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5187 bits |= part << bitMember.pos;
5193 if(_class && _class.type == unitClass)
5195 ComputeExpression(member.initializer.exp);
5196 exp.constant = member.initializer.exp.constant;
5197 exp.type = constantExp;
5199 member.initializer.exp.constant = null;
5209 if(_class && _class.type == bitClass)
5211 exp.constant = PrintHexUInt(bits);
5212 exp.type = constantExp;
5214 if(exp.type != instanceExp)
5220 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5222 bool result = false;
5226 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5227 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5231 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5232 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5235 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5236 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5237 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5240 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5241 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5242 result = GetOpFloat(op, &op.f);
5245 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5246 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5247 result = GetOpDouble(op, &op.d);
5250 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5251 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5252 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5255 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5256 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5257 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5260 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5261 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5264 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5265 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5271 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5273 if(exp.op.op == SIZEOF)
5275 FreeExpContents(exp);
5276 exp.type = constantExp;
5277 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5288 // Provide default unary +
5289 Expression exp2 = exp.op.exp2;
5291 FreeExpContents(exp);
5292 FreeType(exp.expType);
5293 FreeType(exp.destType);
5299 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5301 // unary arithmetic increment and decrement
5302 //OPERATOR_ALL(UNARY, ++, Inc)
5303 //OPERATOR_ALL(UNARY, --, Dec)
5306 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5308 // unary logical negation
5310 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5316 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5318 if(Promote(op2, op1.kind, op1.type.isSigned))
5319 op2.kind = op1.kind, op2.ops = op1.ops;
5320 else if(Promote(op1, op2.kind, op2.type.isSigned))
5321 op1.kind = op2.kind, op1.ops = op2.ops;
5325 // binary arithmetic
5327 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5330 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5333 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5336 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5339 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5341 // binary arithmetic assignment
5342 //OPERATOR_ALL(BINARY, =, Asign)
5343 //OPERATOR_ALL(BINARY, +=, AddAsign)
5344 //OPERATOR_ALL(BINARY, -=, SubAsign)
5345 //OPERATOR_ALL(BINARY, *=, MulAsign)
5346 //OPERATOR_ALL(BINARY, /=, DivAsign)
5347 //OPERATOR_ALL(BINARY, %=, ModAsign)
5352 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5356 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5359 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5362 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5365 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5367 // binary bitwise assignment
5368 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5369 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5370 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5371 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5372 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5373 // binary logical equality
5375 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5378 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5382 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5385 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5387 // binary logical relational
5389 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5392 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5395 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5398 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5405 void ComputeExpression(Expression exp)
5408 char expString[10240];
5409 expString[0] = '\0';
5410 PrintExpression(exp, expString);
5417 Identifier id = exp.identifier;
5418 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5420 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5421 if(c && c.type == enumClass)
5423 Class enumClass = eSystem_FindClass(privateModule, "enum");
5427 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5428 for(value = e.values.first; value; value = value.next)
5430 if(!strcmp(value.name, id.string))
5435 const String dts = c.dataTypeString;
5436 FreeExpContents(exp);
5437 exp.type = constantExp;
5438 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5447 ComputeInstantiation(exp);
5456 Expression exp1, exp2 = null;
5460 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5463 Expression e = exp.op.exp2;
5465 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5467 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5469 if(e.type == extensionCompoundExp)
5470 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5475 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5477 if(e.type == stringExp && e.string)
5479 char * string = e.string;
5480 int len = strlen(string);
5481 char * tmp = new char[len-2+1];
5482 len = UnescapeString(tmp, string + 1, len - 2);
5484 FreeExpContents(exp);
5485 exp.type = constantExp;
5486 exp.constant = PrintUInt(len + 1);
5490 Type type = e.expType;
5492 FreeExpContents(exp);
5493 exp.type = constantExp;
5494 exp.constant = PrintUInt(ComputeTypeSize(type));
5500 ComputeExpression(exp.op.exp2);
5504 ComputeExpression(exp.op.exp1);
5507 op1 = GetOperand(exp1);
5508 if(op1.type) op1.type.refCount++;
5511 op2 = GetOperand(exp2);
5512 if(op2.type) op2.type.refCount++;
5518 op1 = GetOperand(exp1);
5519 if(op1.type) op1.type.refCount++;
5522 CallOperator(exp, exp1, exp2, op1, op2);
5529 if(exp.op.exp1 && exp.op.exp2)
5534 FreeExpContents(exp);
5535 op1.ops.BitAnd(exp, op1, op2);
5544 FreeExpContents(exp);
5545 op1.ops.Mul(exp, op1, op2);
5554 FreeExpContents(exp);
5555 op1.ops.Add(exp, op1, op2);
5560 // Provide default unary +
5561 Expression exp2 = exp.op.exp2;
5563 FreeExpContents(exp);
5564 FreeType(exp.expType);
5565 FreeType(exp.destType);
5576 FreeExpContents(exp);
5577 op1.ops.Sub(exp, op1, op2);
5584 FreeExpContents(exp);
5585 op1.ops.Neg(exp, op1);
5592 FreeExpContents(exp);
5593 op1.ops.BitNot(exp, op1);
5599 FreeExpContents(exp);
5600 op1.ops.Not(exp, op1);
5603 // Binary only operators
5607 FreeExpContents(exp);
5608 op1.ops.Div(exp, op1, op2);
5614 FreeExpContents(exp);
5615 op1.ops.Mod(exp, op1, op2);
5627 FreeExpContents(exp);
5628 op1.ops.Sma(exp, op1, op2);
5637 FreeExpContents(exp);
5638 op1.ops.Grt(exp, op1, op2);
5647 FreeExpContents(exp);
5648 op1.ops.SmaEqu(exp, op1, op2);
5657 FreeExpContents(exp);
5658 op1.ops.GrtEqu(exp, op1, op2);
5667 FreeExpContents(exp);
5668 op1.ops.Equ(exp, op1, op2);
5677 FreeExpContents(exp);
5678 op1.ops.Nqu(exp, op1, op2);
5685 FreeExpContents(exp);
5686 op1.ops.BitOr(exp, op1, op2);
5692 FreeExpContents(exp);
5693 op1.ops.BitXor(exp, op1, op2);
5701 FreeExpContents(exp);
5702 exp.type = constantExp;
5703 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5707 if(op1.type) FreeType(op1.type);
5708 if(op2.type) FreeType(op2.type);
5712 case extensionExpressionExp:
5715 for(e = exp.list->first; e; e = n)
5720 OldList * list = exp.list;
5721 Expression prev = exp.prev;
5722 Expression next = exp.next;
5723 ComputeExpression(e);
5724 //FreeExpContents(exp);
5725 FreeType(exp.expType);
5726 FreeType(exp.destType);
5745 exp.isConstant = true;
5747 ComputeExpression(exp.index.exp);
5748 if(!exp.index.exp.isConstant)
5749 exp.isConstant = false;
5751 for(e = exp.index.index->first; e; e = e.next)
5753 ComputeExpression(e);
5756 // Check if this type is int
5759 exp.isConstant = false;
5761 exp.expType = Dereference(exp.index.exp.expType);
5767 Expression memberExp = exp.member.exp;
5768 Identifier memberID = exp.member.member;
5771 ComputeExpression(exp.member.exp);
5772 type = exp.member.exp.expType;
5775 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);
5776 Property prop = null;
5777 DataMember member = null;
5778 Class convertTo = null;
5779 if(type.kind == subClassType && exp.member.exp.type == classExp)
5780 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5787 PrintTypeNoConst(type, string, false, true);
5788 classSym = FindClass(string);
5789 _class = classSym ? classSym.registered : null;
5792 if(exp.member.member)
5794 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5796 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5798 if(!prop && !member && _class && exp.member.member)
5800 Symbol classSym = FindClass(exp.member.member.string);
5802 _class = classSym ? classSym.registered : null;
5803 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5810 Type type = prop.dataType;
5811 // TODO: Assuming same base type for units...
5812 if(_class.type == unitClass)
5814 if(type.kind == classType)
5816 Class _class = type._class.registered;
5817 if(_class.type == unitClass)
5819 if(!_class.dataType)
5820 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5821 type = _class.dataType;
5829 float (*Get)(float) = (void *)prop.Get;
5830 GetFloat(exp.member.exp, &value);
5831 exp.constant = PrintFloat(Get ? Get(value) : value);
5832 exp.type = constantExp;
5838 double (*Get)(double);
5839 GetDouble(exp.member.exp, &value);
5842 Get = (void *)prop.Set;
5844 Get = (void *)prop.Get;
5845 exp.constant = PrintDouble(Get ? Get(value) : value);
5846 exp.type = constantExp;
5855 Expression value = exp.member.exp;
5858 ProcessPropertyType(prop);
5860 type = prop.dataType;
5863 // printf("Investigate this\n");
5865 else if(_class.type == structClass)
5871 Class propertyClass = type._class.registered;
5872 if(propertyClass.type == structClass && value.type == instanceExp)
5874 void (*Set)(void *, void *) = (void *)prop.Set;
5875 exp.instance = Instantiation { };
5876 exp.instance.data = new0 byte[_class.structSize];
5877 exp.instance._class = MkSpecifierName(_class.fullName);
5878 exp.instance.loc = exp.loc;
5879 exp.type = instanceExp;
5880 Set(exp.instance.data, value.instance.data);
5881 PopulateInstance(exp.instance);
5888 void (*Set)(void *, int) = (void *)prop.Set;
5890 exp.instance = Instantiation { };
5891 exp.instance.data = new0 byte[_class.structSize];
5892 exp.instance._class = MkSpecifierName(_class.fullName);
5893 exp.instance.loc = exp.loc;
5894 exp.type = instanceExp;
5896 GetInt(value, &intValue);
5898 Set(exp.instance.data, intValue);
5899 PopulateInstance(exp.instance);
5905 void (*Set)(void *, int64) = (void *)prop.Set;
5907 exp.instance = Instantiation { };
5908 exp.instance.data = new0 byte[_class.structSize];
5909 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5910 exp.instance.loc = exp.loc;
5911 exp.type = instanceExp;
5913 GetInt64(value, &intValue);
5915 Set(exp.instance.data, intValue);
5916 PopulateInstance(exp.instance);
5923 void (*Set)(void *, intptr) = (void *)prop.Set;
5925 exp.instance = Instantiation { };
5926 exp.instance.data = new0 byte[_class.structSize];
5927 exp.instance._class = MkSpecifierName(_class.fullName);
5928 exp.instance.loc = exp.loc;
5929 exp.type = instanceExp;
5931 GetIntPtr(value, &intValue);
5933 Set(exp.instance.data, intValue);
5934 PopulateInstance(exp.instance);
5941 void (*Set)(void *, intsize) = (void *)prop.Set;
5943 exp.instance = Instantiation { };
5944 exp.instance.data = new0 byte[_class.structSize];
5945 exp.instance._class = MkSpecifierName(_class.fullName);
5946 exp.instance.loc = exp.loc;
5947 exp.type = instanceExp;
5949 GetIntSize(value, &intValue);
5951 Set(exp.instance.data, intValue);
5952 PopulateInstance(exp.instance);
5958 void (*Set)(void *, float) = (void *)prop.Set;
5960 exp.instance = Instantiation { };
5961 exp.instance.data = new0 byte[_class.structSize];
5962 exp.instance._class = MkSpecifierName(_class.fullName);
5963 exp.instance.loc = exp.loc;
5964 exp.type = instanceExp;
5966 GetFloat(value, &floatValue);
5968 Set(exp.instance.data, floatValue);
5969 PopulateInstance(exp.instance);
5975 void (*Set)(void *, double) = (void *)prop.Set;
5977 exp.instance = Instantiation { };
5978 exp.instance.data = new0 byte[_class.structSize];
5979 exp.instance._class = MkSpecifierName(_class.fullName);
5980 exp.instance.loc = exp.loc;
5981 exp.type = instanceExp;
5983 GetDouble(value, &doubleValue);
5985 Set(exp.instance.data, doubleValue);
5986 PopulateInstance(exp.instance);
5991 else if(_class.type == bitClass)
5997 Class propertyClass = type._class.registered;
5998 if(propertyClass.type == structClass && value.instance.data)
6000 unsigned int (*Set)(void *) = (void *)prop.Set;
6001 unsigned int bits = Set(value.instance.data);
6002 exp.constant = PrintHexUInt(bits);
6003 exp.type = constantExp;
6006 else if(_class.type == bitClass)
6009 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6012 GetUInt(exp.member.exp, &value);
6014 exp.constant = PrintHexUInt(bits);
6015 exp.type = constantExp;
6023 if(_class.type == bitClass)
6026 GetUInt(exp.member.exp, &value);
6032 Class _class = type._class.registered;
6033 if(_class.type == structClass)
6035 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6037 exp.instance = Instantiation { };
6038 exp.instance.data = new0 byte[_class.structSize];
6039 exp.instance._class = MkSpecifierName(_class.fullName);
6040 exp.instance.loc = exp.loc;
6041 //exp.instance.fullSet = true;
6042 exp.type = instanceExp;
6043 Get(value, exp.instance.data);
6044 PopulateInstance(exp.instance);
6046 else if(_class.type == bitClass)
6048 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6049 uint64 bits = Get(value);
6050 exp.constant = PrintHexUInt64(bits);
6051 exp.type = constantExp;
6057 else if(_class.type == structClass)
6059 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6064 Class _class = type._class.registered;
6065 if(_class.type == structClass && value)
6067 void (*Get)(void *, void *) = (void *)prop.Get;
6069 exp.instance = Instantiation { };
6070 exp.instance.data = new0 byte[_class.structSize];
6071 exp.instance._class = MkSpecifierName(_class.fullName);
6072 exp.instance.loc = exp.loc;
6073 //exp.instance.fullSet = true;
6074 exp.type = instanceExp;
6075 Get(value, exp.instance.data);
6076 PopulateInstance(exp.instance);
6084 char * value = exp.member.exp.instance.data;
6089 Class _class = type._class.registered;
6090 if(_class.type == normalClass)
6092 void *(*Get)(void *) = (void *)prop.Get;
6094 exp.instance = Instantiation { };
6095 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6096 exp.type = instanceExp;
6097 exp.instance.data = Get(value, exp.instance.data);
6109 exp.isConstant = false;
6117 if(exp.type != ExpressionType::memberExp)
6119 FreeExpression(memberExp);
6120 FreeIdentifier(memberID);
6126 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6127 FreeExpContents(exp);
6128 exp.constant = PrintUInt(ComputeTypeSize(type));
6129 exp.type = constantExp;
6135 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6136 if(classSym && classSym.registered)
6138 if(classSym.registered.fixed)
6140 FreeSpecifier(exp._class);
6141 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6142 exp.type = constantExp;
6146 char className[1024];
6147 strcpy(className, "__ecereClass_");
6148 FullClassNameCat(className, classSym.string, true);
6150 DeclareClass(curExternal, classSym, className);
6152 FreeExpContents(exp);
6153 exp.type = pointerExp;
6154 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6155 exp.member.member = MkIdentifier("structSize");
6165 if(exp.type == castExp)
6168 ComputeExpression(exp.cast.exp);
6171 if(e && exp.expType)
6174 type = exp.destType;
6177 if(type.kind == classType)
6179 Class _class = type._class.registered;
6180 if(_class && (_class.type == unitClass || _class.type == bitClass))
6182 if(!_class.dataType)
6183 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6184 type = _class.dataType;
6195 if(GetChar(e, &value))
6197 FreeExpContents(exp);
6198 exp.constant = PrintChar(value);
6199 exp.type = constantExp;
6204 unsigned char value = 0;
6205 if(GetUChar(e, &value))
6207 FreeExpContents(exp);
6208 exp.constant = PrintUChar(value);
6209 exp.type = constantExp;
6217 if(GetShort(e, &value))
6219 FreeExpContents(exp);
6220 exp.constant = PrintShort(value);
6221 exp.type = constantExp;
6226 unsigned short value = 0;
6227 if(GetUShort(e, &value))
6229 FreeExpContents(exp);
6230 exp.constant = PrintUShort(value);
6231 exp.type = constantExp;
6239 if(GetInt(e, &value))
6241 FreeExpContents(exp);
6242 exp.constant = PrintInt(value);
6243 exp.type = constantExp;
6248 unsigned int value = 0;
6249 if(GetUInt(e, &value))
6251 FreeExpContents(exp);
6252 exp.constant = PrintUInt(value);
6253 exp.type = constantExp;
6261 if(GetInt64(e, &value))
6263 FreeExpContents(exp);
6264 exp.constant = PrintInt64(value);
6265 exp.type = constantExp;
6271 if(GetUInt64(e, &value))
6273 FreeExpContents(exp);
6274 exp.constant = PrintUInt64(value);
6275 exp.type = constantExp;
6283 if(GetIntPtr(e, &value))
6285 FreeExpContents(exp);
6286 exp.constant = PrintInt64((int64)value);
6287 exp.type = constantExp;
6293 if(GetUIntPtr(e, &value))
6295 FreeExpContents(exp);
6296 exp.constant = PrintUInt64((uint64)value);
6297 exp.type = constantExp;
6305 if(GetIntSize(e, &value))
6307 FreeExpContents(exp);
6308 exp.constant = PrintInt64((int64)value);
6309 exp.type = constantExp;
6315 if(GetUIntSize(e, &value))
6317 FreeExpContents(exp);
6318 exp.constant = PrintUInt64((uint64)value);
6319 exp.type = constantExp;
6326 if(GetFloat(e, &value))
6328 FreeExpContents(exp);
6329 exp.constant = PrintFloat(value);
6330 exp.type = constantExp;
6337 if(GetDouble(e, &value))
6339 FreeExpContents(exp);
6340 exp.constant = PrintDouble(value);
6341 exp.type = constantExp;
6356 // Caring only about last expression for now...
6357 ComputeExpression(exp.cond.exp->last);
6358 if(exp.cond.elseExp)
6359 ComputeExpression(exp.cond.elseExp);
6361 ComputeExpression(exp.cond.cond);
6363 op1 = GetOperand(exp.cond.cond);
6364 if(op1.type) op1.type.refCount++;
6365 op2 = GetOperand(exp.cond.exp->last);
6366 if(op2.type) op2.type.refCount++;
6367 op3 = GetOperand(exp.cond.elseExp);
6368 if(op3.type) op3.type.refCount++;
6370 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6371 if(op1.type) FreeType(op1.type);
6372 if(op2.type) FreeType(op2.type);
6373 if(op3.type) FreeType(op3.type);
6379 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6384 OldList converts { };
6387 if(destType.kind == voidType)
6390 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6394 // for(convert = converts.last; convert; convert = convert.prev)
6395 for(convert = converts.first; convert; convert = convert.next)
6397 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6400 Expression newExp { };
6401 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6403 // TODO: Check this...
6407 newExp.destType = null;
6412 exp.type = memberExp;
6413 exp.addedThis = true;
6414 exp.member.exp = newExp;
6415 FreeType(exp.member.exp.expType);
6417 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6418 exp.member.exp.expType.classObjectType = objectType;
6419 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6420 exp.member.memberType = propertyMember;
6421 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6422 // TESTING THIS... for (int)degrees
6423 exp.needCast = true;
6424 if(exp.expType) exp.expType.refCount++;
6425 ApplyAnyObjectLogic(exp.member.exp);
6430 /*if(exp.isConstant)
6432 // Color { ColorRGB = [exp] };
6433 exp.type = instanceExp;
6434 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6435 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6436 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6440 // If not constant, don't turn it yet into an instantiation
6441 // (Go through the deep members system first)
6442 exp.type = memberExp;
6443 exp.addedThis = true;
6444 exp.member.exp = newExp;
6446 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6447 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6448 newExp.expType._class.registered.type == noHeadClass)
6450 newExp.byReference = true;
6453 FreeType(exp.member.exp.expType);
6454 /*exp.member.exp.expType = convert.convert.dataType;
6455 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6456 exp.member.exp.expType = null;
6457 if(convert.convert.dataType)
6459 exp.member.exp.expType = { };
6460 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6461 exp.member.exp.expType.refCount = 1;
6462 exp.member.exp.expType.classObjectType = objectType;
6463 ApplyAnyObjectLogic(exp.member.exp);
6466 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6467 exp.member.memberType = reverseConversionMember;
6468 exp.expType = convert.resultType ? convert.resultType :
6469 MkClassType(convert.convert._class.fullName);
6470 exp.needCast = true;
6471 if(convert.resultType) convert.resultType.refCount++;
6477 FreeType(exp.expType);
6480 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6481 if(exp.destType.casted)
6482 exp.needCast = true;
6483 if(exp.expType) exp.expType.refCount++;
6487 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6488 if(exp.destType.casted)
6489 exp.needCast = true;
6490 if(convert.resultType)
6491 convert.resultType.refCount++;
6495 if(exp.isConstant && inCompiler)
6496 ComputeExpression(exp);
6498 converts.Free(FreeConvert);
6501 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6503 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6505 if(!result && exp.expType && exp.destType)
6507 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6508 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6509 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6510 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6514 // if(result) CheckTemplateTypes(exp);
6518 void CheckTemplateTypes(Expression exp)
6521 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6522 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6524 Expression nbExp = GetNonBracketsExp(exp);
6525 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6526 (nbExp == exp || nbExp.type != castExp))
6528 Expression newExp { };
6530 TypeKind kind = exp.expType.kind;
6532 if(exp.destType) exp.destType.refCount++;
6533 if(exp.expType) exp.expType.refCount++;
6537 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6539 Class c = exp.expType._class.registered;
6540 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6543 c.dataType = ProcessTypeString(c.dataTypeString, false);
6544 kind = c.dataType.kind;
6551 if(exp.destType.classObjectType)
6553 // We need to pass the address, just pass it along (Undo what was done above)
6554 if(exp.destType) exp.destType.refCount--;
6555 if(exp.expType) exp.expType.refCount--;
6560 // If we're looking for value:
6561 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6563 OldList * unionDefs = MkList();
6564 OldList * statements = MkList();
6565 context = PushContext();
6566 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6567 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6568 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6569 exp.type = extensionCompoundExp;
6570 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6571 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6572 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6573 exp.compound.compound.context = context;
6574 PopContext(context);
6579 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6580 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6581 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6583 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6584 exp.needCast = true;
6588 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6590 Expression newExp { };
6592 TypeKind kind = exp.expType.kind;
6594 if(exp.destType) exp.destType.refCount++;
6595 if(exp.expType) exp.expType.refCount++;
6599 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6601 Class c = exp.expType._class.registered;
6602 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6605 c.dataType = ProcessTypeString(c.dataTypeString, false);
6606 kind = c.dataType.kind;
6613 if(exp.destType.classObjectType)
6615 // We need to pass the address, just pass it along (Undo what was done above)
6616 if(exp.destType) exp.destType.refCount--;
6617 if(exp.expType) exp.expType.refCount--;
6622 // If we're looking for value:
6623 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6625 OldList * unionDefs = MkList();
6626 OldList * statements = MkList();
6627 context = PushContext();
6628 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6629 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6630 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6631 exp.type = extensionCompoundExp;
6632 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6633 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6634 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6635 exp.compound.compound.context = context;
6636 PopContext(context);
6641 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6643 exp.type = bracketsExp;
6645 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6646 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6647 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6648 ProcessExpressionType(exp.list->first);
6653 exp.type = bracketsExp;
6654 if(exp.expType.isPointerType)
6656 exp.needTemplateCast = 2;
6657 newExp.needCast = true;
6658 newExp.needTemplateCast = 2;
6659 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6662 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6663 exp.needTemplateCast = 2;
6664 newExp.needCast = true;
6665 newExp.needTemplateCast = 2;
6666 ProcessExpressionType(exp.list->first);
6672 if(exp.expType.kind == templateType)
6674 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6677 FreeType(exp.destType);
6678 FreeType(exp.expType);
6683 /*if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6685 // When was this required? Removed to address using templated values to pass to printf()
6689 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6690 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6694 char typeString[1024];
6696 OldList * specs = MkList();
6697 typeString[0] = '\0';
6698 PrintType(exp.expType, typeString, false, false);
6699 decl = SpecDeclFromString(typeString, specs, null);
6702 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6703 exp.cast.typeName = MkTypeName(specs, decl);
6704 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6705 exp.cast.exp.needCast = true;
6706 exp.needTemplateCast = 2;
6707 newExp.needTemplateCast = 2;
6714 // TODO: The Symbol tree should be reorganized by namespaces
6716 // - Tree of all symbols within (stored without namespace)
6717 // - Tree of sub-namespaces
6719 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6721 int nsLen = strlen(nameSpace);
6723 // Start at the name space prefix
6724 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6726 char * s = symbol.string;
6727 if(!strncmp(s, nameSpace, nsLen))
6729 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6732 for(c = strlen(s)-1; c >= 0; c--)
6737 if(!strcmp(namePart, name))
6739 // TODO: Error on ambiguity
6749 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6752 char nameSpace[1024];
6753 const char * namePart;
6754 bool gotColon = false;
6756 nameSpace[0] = '\0';
6757 for(c = strlen(name)-1; c >= 0; c--)
6764 namePart = name+c+1;
6765 while(c >= 0 && name[c] == ':') c--;
6768 // Try an exact match first
6769 Symbol symbol = (Symbol)tree.FindString(name);
6773 // Namespace specified
6774 memcpy(nameSpace, name, c + 1);
6777 return ScanWithNameSpace(tree, nameSpace, namePart);
6781 // Looking for a global symbol, e.g. ::Sleep()
6782 Symbol symbol = (Symbol)tree.FindString(namePart);
6787 // Name only (no namespace specified)
6788 Symbol symbol = (Symbol)tree.FindString(namePart);
6791 return ScanWithNameSpace(tree, "", namePart);
6796 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6799 //Time startTime = GetTime();
6801 // Optimize this later? Do this before/less?
6803 Symbol symbol = null;
6805 // First, check if the identifier is declared inside the function
6806 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6808 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6810 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6816 strcpy(curName, thisNameSpace);
6817 strcat(curName, "::");
6818 strcat(curName, name);
6819 // Try to resolve in current namespace first
6820 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6823 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6826 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6828 if(symbol || ctx == endContext) break;
6830 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6831 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6833 //findSymbolTotalTime += GetTime() - startTime;
6838 static void GetTypeSpecs(Type type, OldList * specs)
6840 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6845 if(type._class.registered)
6847 if(!type._class.registered.dataType)
6848 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6849 GetTypeSpecs(type._class.registered.dataType, specs);
6853 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6854 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6855 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6856 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6857 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6858 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6859 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6860 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6863 ListAdd(specs, MkSpecifier(INT)); break;
6867 static void PrintArraySize(Type arrayType, char * string)
6872 if(arrayType.enumClass)
6873 strcat(size, arrayType.enumClass.string);
6874 else if(arrayType.arraySizeExp)
6875 PrintExpression(arrayType.arraySizeExp, size);
6877 strcat(string, size);
6880 // WARNING : This function expects a null terminated string since it recursively concatenate...
6881 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6885 if(printConst && type.constant)
6886 strcat(string, "const ");
6891 Symbol c = type._class;
6892 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
6893 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6894 // look into merging with thisclass ?
6895 if(type.classObjectType == typedObject && isObjectBaseClass)
6896 strcat(string, "typed_object");
6897 else if(type.classObjectType == anyObject && isObjectBaseClass)
6898 strcat(string, "any_object");
6902 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6904 if(type.byReference)
6905 strcat(string, " &");
6908 case voidType: strcat(string, "void"); break;
6909 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6910 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6911 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6912 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6913 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6914 case _BoolType: strcat(string, "_Bool"); break;
6915 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6916 case floatType: strcat(string, "float"); break;
6917 case doubleType: strcat(string, "double"); break;
6921 strcat(string, "struct ");
6922 strcat(string, type.enumName);
6924 else if(type.typeName)
6925 strcat(string, type.typeName);
6929 strcat(string, "struct { ");
6930 for(member = type.members.first; member; member = member.next)
6932 PrintType(member, string, true, fullName);
6933 strcat(string,"; ");
6941 strcat(string, "union ");
6942 strcat(string, type.enumName);
6944 else if(type.typeName)
6945 strcat(string, type.typeName);
6948 strcat(string, "union ");
6949 strcat(string,"(unnamed)");
6955 strcat(string, "enum ");
6956 strcat(string, type.enumName);
6958 else if(type.typeName)
6959 strcat(string, type.typeName);
6961 strcat(string, "int"); // "enum");
6964 strcat(string, "...");
6967 strcat(string, "subclass(");
6968 strcat(string, type._class ? type._class.string : "int");
6969 strcat(string, ")");
6972 strcat(string, type.templateParameter.identifier.string);
6975 strcat(string, "thisclass");
6978 strcat(string, "__builtin_va_list");
6984 static void PrintName(Type type, char * string, bool fullName)
6986 if(type.name && type.name[0])
6989 strcat(string, type.name);
6992 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6993 if(name) name += 2; else name = type.name;
6994 strcat(string, name);
6999 static void PrintAttribs(Type type, char * string)
7003 if(type.dllExport) strcat(string, "dllexport ");
7004 if(type.attrStdcall) strcat(string, "stdcall ");
7008 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7010 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7012 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7013 PrintAttribs(type, string);
7014 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7015 strcat(string, " const");
7016 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7017 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7018 strcat(string, " (");
7019 if(type.kind == pointerType)
7021 if(type.type.kind == functionType || type.type.kind == methodType)
7022 PrintAttribs(type.type, string);
7024 if(type.kind == pointerType)
7026 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7027 strcat(string, "*");
7029 strcat(string, " *");
7031 if(printConst && type.constant && type.kind == pointerType)
7032 strcat(string, " const");
7035 PrintTypeSpecs(type, string, fullName, printConst);
7038 static void PostPrintType(Type type, char * string, bool fullName)
7040 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7041 strcat(string, ")");
7042 if(type.kind == arrayType)
7043 PrintArraySize(type, string);
7044 else if(type.kind == functionType)
7047 strcat(string, "(");
7048 for(param = type.params.first; param; param = param.next)
7050 PrintType(param, string, true, fullName);
7051 if(param.next) strcat(string, ", ");
7053 strcat(string, ")");
7055 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7056 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7060 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7062 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7064 PrePrintType(type, string, fullName, null, printConst);
7066 if(type.thisClass || (printName && type.name && type.name[0]))
7067 strcat(string, " ");
7068 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7070 Symbol _class = type.thisClass;
7071 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7073 if(type.classObjectType == classPointer)
7074 strcat(string, "class");
7076 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7078 else if(_class && _class.string)
7080 String s = _class.string;
7085 char * name = RSearchString(s, "::", strlen(s), true, false);
7086 if(name) name += 2; else name = s;
7087 strcat(string, name);
7090 strcat(string, "::");
7093 if(printName && type.name)
7094 PrintName(type, string, fullName);
7095 PostPrintType(type, string, fullName);
7096 if(type.bitFieldCount)
7099 sprintf(count, ":%d", type.bitFieldCount);
7100 strcat(string, count);
7104 void PrintType(Type type, char * string, bool printName, bool fullName)
7106 _PrintType(type, string, printName, fullName, true);
7109 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7111 _PrintType(type, string, printName, fullName, false);
7114 static Type FindMember(Type type, char * string)
7117 for(memberType = type.members.first; memberType; memberType = memberType.next)
7119 if(!memberType.name)
7121 Type subType = FindMember(memberType, string);
7125 else if(!strcmp(memberType.name, string))
7131 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7134 for(memberType = type.members.first; memberType; memberType = memberType.next)
7136 if(!memberType.name)
7138 Type subType = FindMember(memberType, string);
7141 *offset += memberType.offset;
7145 else if(!strcmp(memberType.name, string))
7147 *offset += memberType.offset;
7154 public bool GetParseError() { return parseError; }
7156 Expression ParseExpressionString(char * expression)
7160 fileInput = TempFile { };
7161 fileInput.Write(expression, 1, strlen(expression));
7162 fileInput.Seek(0, start);
7165 parsedExpression = null;
7167 expression_yyparse();
7170 return parsedExpression;
7173 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7175 Identifier id = exp.identifier;
7176 Method method = null;
7177 Property prop = null;
7178 DataMember member = null;
7179 ClassProperty classProp = null;
7181 if(_class && _class.type == enumClass)
7183 NamedLink64 value = null;
7184 Class enumClass = eSystem_FindClass(privateModule, "enum");
7188 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7190 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7191 for(value = e.values.first; value; value = value.next)
7193 if(!strcmp(value.name, id.string))
7198 exp.isConstant = true;
7199 if(inCompiler || inPreCompiler || inDebugger)
7202 FreeExpContents(exp);
7204 exp.type = constantExp;
7205 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7206 sprintf(constant, FORMAT64D, value.data);
7208 sprintf(constant, FORMAT64HEX, value.data);
7209 exp.constant = CopyString(constant);
7211 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7212 exp.expType = MkClassType(baseClass.fullName);
7220 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7222 ProcessMethodType(method);
7229 // TOCHECK: Put it back to what it was...
7230 // methodClass = _class;
7231 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7236 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7239 ProcessPropertyType(prop);
7240 exp.expType = prop.dataType;
7241 if(prop.dataType) prop.dataType.refCount++;
7244 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7246 if(!member.dataType)
7247 member.dataType = ProcessTypeString(member.dataTypeString, false);
7248 exp.expType = member.dataType;
7249 if(member.dataType) member.dataType.refCount++;
7252 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7254 if(!classProp.dataType)
7255 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7257 if(classProp.constant)
7259 FreeExpContents(exp);
7261 exp.isConstant = true;
7262 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7264 //char constant[256];
7265 exp.type = stringExp;
7266 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7271 exp.type = constantExp;
7272 sprintf(constant, "%d", (int)classProp.Get(_class));
7273 exp.constant = CopyString(constant);
7281 exp.expType = classProp.dataType;
7282 if(classProp.dataType) classProp.dataType.refCount++;
7288 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7290 BinaryTree * tree = &nameSpace.functions;
7291 GlobalData data = (GlobalData)tree->FindString(name);
7295 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7297 data = ScanGlobalData(child, name);
7305 static GlobalData FindGlobalData(char * name)
7308 NameSpace * nameSpace;
7309 nameSpace = globalData;
7310 for(c = 0; name[c]; c++)
7312 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7314 NameSpace * newSpace;
7315 char * spaceName = new char[c - start + 1];
7316 strncpy(spaceName, name + start, c - start);
7317 spaceName[c-start] = '\0';
7318 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7322 nameSpace = newSpace;
7323 if(name[c] == ':') c++;
7329 return ScanGlobalData(nameSpace, name + start);
7334 static int definedExpStackPos;
7335 static void * definedExpStack[512];
7337 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7338 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7340 Expression prev = checkedExp.prev, next = checkedExp.next;
7342 FreeExpContents(checkedExp);
7343 FreeType(checkedExp.expType);
7344 FreeType(checkedExp.destType);
7346 *checkedExp = *newExp;
7350 checkedExp.prev = prev;
7351 checkedExp.next = next;
7354 void ApplyAnyObjectLogic(Expression e)
7356 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7358 char debugExpString[4096];
7359 debugExpString[0] = '\0';
7360 PrintExpression(e, debugExpString);
7363 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7365 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7366 //ellipsisDestType = destType;
7369 Type type = e.expType;
7370 Class _class = null;
7371 //Type destType = e.destType;
7373 if(type.kind == classType && type._class && type._class.registered)
7375 _class = type._class.registered;
7377 else if(type.kind == subClassType)
7379 _class = FindClass("ecere::com::Class").registered;
7383 char string[1024] = "";
7386 PrintTypeNoConst(type, string, false, true);
7387 classSym = FindClass(string);
7388 if(classSym) _class = classSym.registered;
7391 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...
7392 (!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))) ||
7393 destType.byReference)))
7395 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7397 Expression checkedExp = e, newExp;
7399 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7401 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7403 if(checkedExp.type == extensionCompoundExp)
7405 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7408 checkedExp = checkedExp.list->last;
7410 else if(checkedExp.type == castExp)
7411 checkedExp = checkedExp.cast.exp;
7414 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7416 newExp = checkedExp.op.exp2;
7417 checkedExp.op.exp2 = null;
7418 FreeExpContents(checkedExp);
7420 if(e.expType && e.expType.passAsTemplate)
7423 ComputeTypeSize(e.expType);
7424 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7425 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7426 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7427 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7430 ReplaceExpContents(checkedExp, newExp);
7431 e.byReference = true;
7433 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7435 Expression checkedExp; //, newExp;
7438 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7440 e.type == identifierExp ||
7441 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7442 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7443 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7446 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7448 Context context = PushContext();
7450 OldList * specs = MkList();
7451 char typeString[1024];
7452 Expression newExp { };
7454 typeString[0] = '\0';
7457 //if(e.destType) e.destType.refCount++;
7458 // if(exp.expType) exp.expType.refCount++;
7461 newExp.expType = null;
7463 PrintTypeNoConst(e.expType, typeString, false, true);
7464 decl = SpecDeclFromString(typeString, specs, null);
7465 newExp.destType = ProcessType(specs, decl);
7467 curContext = context;
7469 // We need a current compound for this
7473 OldList * stmts = MkList();
7474 e.type = extensionCompoundExp;
7475 sprintf(name, "__internalValue%03X", internalValueCounter++);
7476 if(!curCompound.compound.declarations)
7477 curCompound.compound.declarations = MkList();
7478 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7479 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7480 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7481 e.compound = MkCompoundStmt(null, stmts);
7484 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7487 e.compound = MkCompoundStmt(
7488 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7489 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7491 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7495 Type type = e.destType;
7497 CopyTypeInto(e.destType, type);
7498 e.destType.refCount = 1;
7499 e.destType.classObjectType = none;
7503 e.compound.compound.context = context;
7504 PopContext(context);
7505 curContext = context.parent;
7509 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7511 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7513 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7515 if(checkedExp.type == extensionCompoundExp)
7517 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7520 checkedExp = checkedExp.list->last;
7522 else if(checkedExp.type == castExp)
7523 checkedExp = checkedExp.cast.exp;
7526 Expression operand { };
7527 operand = *checkedExp;
7529 checkedExp.destType = ProcessTypeString("void *", false);
7530 checkedExp.expType = checkedExp.destType;
7531 checkedExp.destType.refCount++;
7533 checkedExp.type = opExp;
7534 checkedExp.op.op = '&';
7535 checkedExp.op.exp1 = null;
7536 checkedExp.op.exp2 = operand;
7538 //newExp = MkExpOp(null, '&', checkedExp);
7540 //ReplaceExpContents(checkedExp, newExp);
7547 // If expression type is a simple class, make it an address
7548 // FixReference(e, true);
7551 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7552 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7553 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7555 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"))
7557 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7561 Expression thisExp { };
7564 thisExp.prev = null;
7565 thisExp.next = null;
7568 e.type = bracketsExp;
7569 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7570 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7571 ((Expression)e.list->first).byReference = true;
7573 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7575 e.expType = thisExp.expType;
7576 e.expType.refCount++;
7581 CopyTypeInto(e.expType, thisExp.expType);
7582 e.expType.byReference = false;
7583 e.expType.refCount = 1;
7585 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7586 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7588 e.expType.classObjectType = none;
7593 // TOFIX: Try this for a nice IDE crash!
7595 // The other way around
7598 if(destType && e.expType &&
7599 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7600 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7601 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7603 if(destType.kind == ellipsisType)
7605 Compiler_Error($"Unspecified type\n");
7607 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7609 bool byReference = e.expType.byReference;
7610 Expression thisExp { };
7612 OldList * specs = MkList();
7613 char typeString[1024]; // Watch buffer overruns
7615 ClassObjectType backupClassObjectType;
7616 bool backupByReference;
7618 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7623 backupClassObjectType = type.classObjectType;
7624 backupByReference = type.byReference;
7626 type.classObjectType = none;
7627 type.byReference = false;
7629 typeString[0] = '\0';
7630 PrintType(type, typeString, false, true);
7631 decl = SpecDeclFromString(typeString, specs, null);
7633 type.classObjectType = backupClassObjectType;
7634 type.byReference = backupByReference;
7637 thisExp.prev = null;
7638 thisExp.next = null;
7641 if( ( type.kind == classType && type._class && type._class.registered &&
7642 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7643 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7644 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7645 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7647 bool passAsTemplate = thisExp.destType.passAsTemplate;
7650 destType.refCount++;
7655 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7658 CopyTypeInto(t, thisExp.destType);
7659 t.passAsTemplate = false;
7660 FreeType(thisExp.destType);
7661 thisExp.destType = t;
7664 CopyTypeInto(t, destType);
7665 t.passAsTemplate = passAsTemplate;
7668 destType.refCount = 0;
7671 CopyTypeInto(e.expType, type);
7672 if(type.passAsTemplate)
7674 e.expType.classObjectType = none;
7675 e.expType.passAsTemplate = false;
7677 e.expType.byReference = false;
7678 e.expType.refCount = 1;
7683 e.cast.typeName = MkTypeName(specs, decl);
7684 e.cast.exp = thisExp;
7685 e.byReference = true;
7691 FreeType(e.destType);
7693 e.destType = destType;
7694 destType.refCount++;
7699 void ApplyLocation(Expression exp, Location loc)
7705 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7706 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7712 for(e = exp.list->first; e; e = e.next)
7713 ApplyLocation(e, loc);
7720 for(e = exp.index.index->first; e; e = e.next)
7721 ApplyLocation(e, loc);
7724 ApplyLocation(exp.index.exp, loc);
7727 if(exp.call.arguments)
7730 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7731 ApplyLocation(arg, loc);
7734 ApplyLocation(exp.call.exp, loc);
7739 ApplyLocation(exp.member.exp, loc);
7743 ApplyLocation(exp.cast.exp, loc);
7749 for(e = exp.cond.exp->first; e; e = e.next)
7750 ApplyLocation(e, loc);
7753 ApplyLocation(exp.cond.cond, loc);
7754 if(exp.cond.elseExp)
7755 ApplyLocation(exp.cond.elseExp, loc);
7759 ApplyLocation(exp.vaArg.exp, loc);
7766 void ProcessExpressionType(Expression exp)
7768 bool unresolved = false;
7769 Location oldyylloc = yylloc;
7770 bool notByReference = false;
7772 char debugExpString[4096];
7773 debugExpString[0] = '\0';
7774 PrintExpression(exp, debugExpString);
7776 if(!exp || exp.expType)
7779 //eSystem_Logf("%s\n", expString);
7781 // Testing this here
7787 Identifier id = exp.identifier;
7788 if(!id || !topContext) return;
7790 // DOING THIS LATER NOW...
7791 if(id._class && id._class.name)
7793 id.classSym = id._class.symbol; // FindClass(id._class.name);
7794 /* TODO: Name Space Fix ups
7796 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7800 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7802 exp.expType = ProcessTypeString("Module", true);
7806 if(!strcmp(id.string, "__runtimePlatform"))
7808 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7811 else if(strstr(id.string, "__ecereClass") == id.string)
7813 exp.expType = ProcessTypeString("ecere::com::Class", true);
7816 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7818 // Added this here as well
7819 ReplaceClassMembers(exp, thisClass);
7820 if(exp.type != identifierExp)
7822 ProcessExpressionType(exp);
7826 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7831 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7832 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7833 if(!symbol/* && exp.destType*/)
7835 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7841 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7842 if(exp.type != identifierExp)
7844 ProcessExpressionType(exp);
7848 // Static methods called from inside the _class
7849 else if(currentClass && !id._class)
7851 if(ResolveIdWithClass(exp, currentClass, true))
7854 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7858 // If we manage to resolve this symbol
7861 Type type = symbol.type;
7862 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7864 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7866 Context context = SetupTemplatesContext(_class);
7867 type = ReplaceThisClassType(_class);
7868 FinishTemplatesContext(context);
7869 if(type) type.refCount = 0; // We'll be incrementing it right below...
7872 FreeSpecifier(id._class);
7875 id.string = CopyString(symbol.string);
7882 // Commented this out, it was making non-constant enum parameters seen as constant
7883 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7884 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7885 // Add missing cases here... enum Classes...
7886 exp.isConstant = true;
7888 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7889 if(symbol.isParam || !strcmp(id.string, "this"))
7891 if(_class && _class.type == structClass && !type.declaredWithStruct)
7892 exp.byReference = true;
7894 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7895 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7896 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7897 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7899 Identifier id = exp.identifier;
7900 exp.type = bracketsExp;
7901 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7905 if(symbol.isIterator)
7907 if(symbol.isIterator == 3)
7909 exp.type = bracketsExp;
7910 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7911 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7913 ProcessExpressionType(exp);
7915 else if(symbol.isIterator != 4)
7917 exp.type = memberExp;
7918 exp.member.exp = MkExpIdentifier(exp.identifier);
7919 exp.member.exp.expType = exp.expType;
7920 /*if(symbol.isIterator == 6)
7921 exp.member.member = MkIdentifier("key");
7923 exp.member.member = MkIdentifier("data");
7925 ProcessExpressionType(exp);
7932 DefinedExpression definedExp = null;
7933 if(thisNameSpace && !(id._class && !id._class.name))
7936 strcpy(name, thisNameSpace);
7938 strcat(name, id.string);
7939 definedExp = eSystem_FindDefine(privateModule, name);
7942 definedExp = eSystem_FindDefine(privateModule, id.string);
7946 for(c = 0; c<definedExpStackPos; c++)
7947 if(definedExpStack[c] == definedExp)
7949 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7951 Location backupYylloc = yylloc;
7952 File backInput = fileInput;
7953 definedExpStack[definedExpStackPos++] = definedExp;
7955 fileInput = TempFile { };
7956 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7957 fileInput.Seek(0, start);
7960 parsedExpression = null;
7962 expression_yyparse();
7965 fileInput = backInput;
7967 yylloc = backupYylloc;
7969 if(parsedExpression)
7972 exp.type = bracketsExp;
7973 exp.list = MkListOne(parsedExpression);
7974 ApplyLocation(parsedExpression, yylloc);
7975 ProcessExpressionType(exp);
7976 definedExpStackPos--;
7979 definedExpStackPos--;
7985 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7991 GlobalData data = null;
7992 if(thisNameSpace && !(id._class && !id._class.name))
7995 strcpy(name, thisNameSpace);
7997 strcat(name, id.string);
7998 data = FindGlobalData(name);
8001 data = FindGlobalData(id.string);
8004 DeclareGlobalData(curExternal, data);
8005 exp.expType = data.dataType;
8006 if(data.dataType) data.dataType.refCount++;
8009 id.string = CopyString(data.fullName);
8010 FreeSpecifier(id._class);
8017 GlobalFunction function = null;
8018 if(thisNameSpace && !(id._class && !id._class.name))
8021 strcpy(name, thisNameSpace);
8023 strcat(name, id.string);
8024 function = eSystem_FindFunction(privateModule, name);
8027 function = eSystem_FindFunction(privateModule, id.string);
8032 id.string = CopyString(function.name);
8035 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8036 strcpy(name, "__ecereFunction_");
8037 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8038 if(DeclareFunction(curExternal, function, name))
8041 id.string = CopyString(name);
8043 exp.expType = function.dataType;
8044 if(function.dataType) function.dataType.refCount++;
8046 FreeSpecifier(id._class);
8063 if(!exp.instance._class)
8065 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8067 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8071 //classSym = FindClass(exp.instance._class.fullName);
8072 //_class = classSym ? classSym.registered : null;
8074 ProcessInstantiationType(exp.instance);
8076 exp.isConstant = exp.instance.isConstant;
8079 if(_class.type == unitClass && _class.base.type != systemClass)
8082 Type destType = exp.destType;
8084 exp.destType = MkClassType(_class.base.fullName);
8085 exp.expType = MkClassType(_class.fullName);
8086 CheckExpressionType(exp, exp.destType, true);
8088 exp.destType = destType;
8090 exp.expType = MkClassType(_class.fullName);
8093 if(exp.instance._class)
8095 exp.expType = MkClassType(exp.instance._class.name);
8096 /*if(exp.expType._class && exp.expType._class.registered &&
8097 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8098 exp.expType.byReference = true;*/
8106 char * constant = exp.constant;
8114 if(constant[0] == '\'')
8116 if((int)((byte *)constant)[1] > 127)
8119 unichar ch = UTF8GetChar(constant + 1, &nb);
8120 if(nb < 2) ch = constant[1];
8122 exp.constant = PrintUInt(ch);
8123 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8124 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8125 type._class = FindClass("unichar");
8127 type.isSigned = false;
8131 type.kind = charType;
8132 type.isSigned = true;
8137 char * dot = strchr(constant, '.');
8138 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8142 exponent = strchr(constant, 'p');
8143 if(!exponent) exponent = strchr(constant, 'P');
8147 exponent = strchr(constant, 'e');
8148 if(!exponent) exponent = strchr(constant, 'E');
8153 if(strchr(constant, 'f') || strchr(constant, 'F'))
8154 type.kind = floatType;
8156 type.kind = doubleType;
8157 type.isSigned = true;
8161 bool isSigned = constant[0] == '-';
8163 int64 i64 = strtoll(constant, &endP, 0);
8164 uint64 ui64 = strtoull(constant, &endP, 0);
8165 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8166 bool forceUnsigned = endP && (!strcmp(endP, "U") || !strcmp(endP, "u") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8179 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8183 else if(constant[0] != '0' || !constant[1])
8188 type.kind = is64Bit ? int64Type : intType;
8189 type.isSigned = isSigned;
8192 exp.isConstant = true;
8193 if(exp.destType && exp.destType.kind == doubleType)
8194 type.kind = doubleType;
8195 else if(exp.destType && exp.destType.kind == floatType)
8196 type.kind = floatType;
8197 else if(exp.destType && exp.destType.kind == int64Type)
8198 type.kind = int64Type;
8204 exp.isConstant = true; // Why wasn't this constant?
8212 kind = exp.wideString ? shortType : charType;
8214 isSigned = exp.wideString ? false : true;
8221 ProcessExpressionType(exp._new.size);
8226 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8228 DeclareType(curExternal, exp.expType.type, true, false);
8232 ProcessExpressionType(exp._renew.size);
8233 ProcessExpressionType(exp._renew.exp);
8238 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8240 DeclareType(curExternal, exp.expType.type, true, false);
8244 bool assign = false, boolResult = false, boolOps = false;
8245 Type type1 = null, type2 = null;
8246 bool useDestType = false, useSideType = false;
8247 Location oldyylloc = yylloc;
8248 bool useSideUnit = false;
8249 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8251 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8260 // Assignment Operators
8274 // boolean Operators
8276 // Expect boolean operators
8278 //boolResult = true;
8282 // Expect boolean operands
8293 // Gives boolean result
8306 // useSideType = true;
8307 // useDestType = true;
8325 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8331 /*// Implement speed etc.
8337 if(exp.op.op == '&')
8339 // Added this here earlier for Iterator address as key
8340 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8342 Identifier id = exp.op.exp2.identifier;
8343 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8344 if(symbol && symbol.isIterator == 2)
8346 exp.type = memberExp;
8347 exp.member.exp = exp.op.exp2;
8348 exp.member.member = MkIdentifier("key");
8350 exp.op.exp2.expType = symbol.type;
8351 symbol.type.refCount++;
8352 ProcessExpressionType(exp);
8356 // exp.op.exp2.usage.usageRef = true;
8360 //dummy.kind = TypeDummy;
8363 // Added this check here to use the dest type only for units derived from the base unit
8364 // So that untyped units will use the side unit as opposed to the untyped destination unit
8365 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8366 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8367 useDestType = false;
8369 if(destClass && useDestType &&
8370 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8372 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8374 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8375 exp.op.exp1.destType = exp.destType;
8376 exp.op.exp1.opDestType = true;
8378 exp.destType.refCount++;
8382 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8383 exp.op.exp1.destType = dummy;
8387 // TESTING THIS HERE...
8388 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8389 ProcessExpressionType(exp.op.exp1);
8390 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8392 exp.op.exp1.opDestType = false;
8394 // Fix for unit and ++ / --
8395 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8396 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8398 exp.op.exp2 = MkExpConstant("1");
8399 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8403 if(exp.op.exp1.destType == dummy)
8406 exp.op.exp1.destType = null;
8411 if(!assign && exp.op.exp1.expType && (exp.op.exp1.expType.kind == charType || exp.op.exp1.expType.kind == shortType))
8413 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 };
8414 FreeType(exp.op.exp1.expType);
8415 exp.op.exp1.expType = type;
8419 type1 = exp.op.exp1.expType;
8424 char expString[10240];
8425 expString[0] = '\0';
8426 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8430 exp.op.exp2.destType = exp.op.exp1.expType;
8431 if(exp.op.exp1.expType)
8432 exp.op.exp1.expType.refCount++;
8436 exp.op.exp2.destType = exp.destType;
8437 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8438 exp.op.exp2.opDestType = true;
8440 exp.destType.refCount++;
8443 if(type1) type1.refCount++;
8444 exp.expType = type1;
8449 PrintExpression(exp.op.exp2, expString);
8451 if(type1 && type1.kind == pointerType)
8453 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 ||
8454 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8455 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8456 else if(exp.op.op == '=')
8458 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8459 exp.op.exp2.destType = type1;
8466 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8467 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/* ||
8468 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8471 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8472 exp.op.exp2.destType = type1;
8477 if(type1) type1.refCount++;
8478 exp.expType = type1;
8480 else if(destClass &&
8481 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8482 (destClass.type == enumClass && useDestType)))
8484 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8485 exp.op.exp2.destType = exp.destType;
8486 if(exp.op.op != '&' && exp.op.op != '^')
8487 exp.op.exp2.opDestType = true;
8489 exp.destType.refCount++;
8493 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8494 exp.op.exp2.destType = dummy;
8498 // TESTING THIS HERE... (DANGEROUS)
8499 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8500 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8502 FreeType(exp.op.exp2.destType);
8503 exp.op.exp2.destType = type1;
8506 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8507 // Cannot lose the cast on a sizeof
8508 if(exp.op.op == SIZEOF)
8510 Expression e = exp.op.exp2;
8511 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8513 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8515 if(e.type == extensionCompoundExp)
8516 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8521 if(e.type == castExp && e.cast.exp)
8522 e.cast.exp.needCast = true;
8524 ProcessExpressionType(exp.op.exp2);
8525 exp.op.exp2.opDestType = false;
8526 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8528 if(!assign && (exp.op.exp1 || exp.op.op == '~'))
8530 if(exp.op.exp2.expType && (exp.op.exp2.expType.kind == charType || exp.op.exp2.expType.kind == shortType))
8532 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 };
8533 FreeType(exp.op.exp2.expType);
8534 exp.op.exp2.expType = type;
8538 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8540 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)
8542 if(exp.op.op != '=' && type1.type.kind == voidType)
8543 Compiler_Error($"void *: unknown size\n");
8545 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||
8546 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8547 (exp.op.exp2.expType._class.registered.type == normalClass ||
8548 exp.op.exp2.expType._class.registered.type == structClass ||
8549 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8551 if(exp.op.op == ADD_ASSIGN)
8552 Compiler_Error($"cannot add two pointers\n");
8554 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8555 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8557 if(exp.op.op == ADD_ASSIGN)
8558 Compiler_Error($"cannot add two pointers\n");
8562 char type1String[1024];
8563 char type2String[1024];
8564 type1String[0] = '\0';
8565 type2String[0] = '\0';
8567 PrintType(exp.op.exp2.expType, type1String, false, true);
8568 PrintType(type1, type2String, false, true);
8569 ChangeCh(expString, '\n', ' ');
8570 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8574 if(exp.op.exp2.destType == dummy)
8577 exp.op.exp2.destType = null;
8580 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8584 CopyTypeInto(type2, exp.op.exp2.expType);
8585 type2.isSigned = true;
8587 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8589 type2 = { kind = intType };
8591 type2.isSigned = true;
8595 type2 = exp.op.exp2.expType;
8596 if(type2) type2.refCount++;
8600 dummy.kind = voidType;
8602 if(exp.op.op == SIZEOF)
8609 exp.isConstant = true;
8611 // Get type of dereferenced pointer
8612 else if(exp.op.op == '*' && !exp.op.exp1)
8614 exp.expType = Dereference(type2);
8615 if(type2 && type2.kind == classType)
8616 notByReference = true;
8618 else if(exp.op.op == '&' && !exp.op.exp1)
8619 exp.expType = Reference(type2);
8620 else if(exp.op.op == LEFT_OP || exp.op.op == RIGHT_OP)
8622 if(exp.op.exp1.expType)
8624 exp.expType = exp.op.exp1.expType;
8625 exp.expType.refCount++;
8634 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8635 exp.op.exp1.destType = MkClassType("bool");
8636 exp.op.exp1.destType.truth = true;
8637 if(!exp.op.exp1.expType)
8638 ProcessExpressionType(exp.op.exp1);
8640 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8641 FreeType(exp.op.exp1.expType);
8642 exp.op.exp1.expType = MkClassType("bool");
8643 exp.op.exp1.expType.truth = true;
8647 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8648 exp.op.exp2.destType = MkClassType("bool");
8649 exp.op.exp2.destType.truth = true;
8650 if(!exp.op.exp2.expType)
8651 ProcessExpressionType(exp.op.exp2);
8653 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8654 FreeType(exp.op.exp2.expType);
8655 exp.op.exp2.expType = MkClassType("bool");
8656 exp.op.exp2.expType.truth = true;
8659 else if(exp.op.exp1 && exp.op.exp2 &&
8662 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8663 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8664 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8665 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8667 if(type1 && type2 &&
8668 // If either both are class or both are not class
8669 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8671 // Added this check for enum subtraction to result in an int type:
8672 if(exp.op.op == '-' &&
8673 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8674 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8677 if(!type1._class.registered.dataType)
8678 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8679 if(!type2._class.registered.dataType)
8680 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8682 intType = ProcessTypeString(
8683 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8685 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8686 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8687 exp.op.exp1.destType = intType;
8688 exp.op.exp2.destType = intType;
8693 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8694 exp.op.exp2.destType = type1;
8696 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8697 exp.op.exp1.destType = type2;
8701 // Warning here for adding Radians + Degrees with no destination type
8702 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8703 type1._class.registered && type1._class.registered.type == unitClass &&
8704 type2._class.registered && type2._class.registered.type == unitClass &&
8705 type1._class.registered != type2._class.registered)
8706 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8707 type1._class.string, type2._class.string, type1._class.string);
8709 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8711 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8714 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8716 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8717 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8720 ProcessExpressionType(exp.op.exp1);
8722 if(type2.kind != pointerType)
8724 ProcessExpressionType(classExp);
8726 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8728 if(!exp.op.exp2.expType)
8732 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8736 ProcessExpressionType(exp.op.exp2);
8741 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)))
8743 if(type1.kind != classType && type1.type.kind == voidType)
8744 Compiler_Error($"void *: unknown size\n");
8745 exp.expType = type1;
8746 if(type1) type1.refCount++;
8748 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)))
8750 if(type2.kind != classType && type2.type.kind == voidType)
8751 Compiler_Error($"void *: unknown size\n");
8752 exp.expType = type2;
8753 if(type2) type2.refCount++;
8755 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8756 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8758 Compiler_Warning($"different levels of indirection\n");
8762 bool success = false;
8763 if(type1.kind == pointerType && type2.kind == pointerType)
8765 if(exp.op.op == '+')
8766 Compiler_Error($"cannot add two pointers\n");
8767 else if(exp.op.op == '-')
8769 // Pointer Subtraction gives integer
8770 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8779 if(type1.type.kind == templateType)
8781 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8784 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8786 ProcessExpressionType(classExp);
8788 exp.type = bracketsExp;
8789 exp.list = MkListOne(MkExpOp(
8790 MkExpBrackets(MkListOne(MkExpOp(
8791 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8793 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8794 MkExpMember(classExp, MkIdentifier("typeSize"))));
8796 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8805 if(!success && exp.op.exp1.type == constantExp)
8807 // If first expression is constant, try to match that first
8808 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8810 if(exp.expType) FreeType(exp.expType);
8811 exp.expType = exp.op.exp1.destType;
8812 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8815 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8817 if(exp.expType) FreeType(exp.expType);
8818 exp.expType = exp.op.exp2.destType;
8819 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8825 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8827 if(exp.expType) FreeType(exp.expType);
8828 exp.expType = exp.op.exp2.destType;
8829 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8832 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8834 if(exp.expType) FreeType(exp.expType);
8835 exp.expType = exp.op.exp1.destType;
8836 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8842 char expString1[10240];
8843 char expString2[10240];
8846 expString1[0] = '\0';
8847 expString2[0] = '\0';
8852 PrintExpression(exp.op.exp1, expString1);
8853 ChangeCh(expString1, '\n', ' ');
8854 PrintExpression(exp.op.exp2, expString2);
8855 ChangeCh(expString2, '\n', ' ');
8856 PrintType(exp.op.exp1.expType, type1, false, true);
8857 PrintType(exp.op.exp2.expType, type2, false, true);
8860 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8864 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8865 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8867 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8868 // Convert e.g. / 4 into / 4.0
8869 exp.op.exp1.destType = type2._class.registered.dataType;
8870 if(type2._class.registered.dataType)
8871 type2._class.registered.dataType.refCount++;
8872 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8873 exp.expType = type2;
8874 if(type2) type2.refCount++;
8876 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8878 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8879 // Convert e.g. / 4 into / 4.0
8880 exp.op.exp2.destType = type1._class.registered.dataType;
8881 if(type1._class.registered.dataType)
8882 type1._class.registered.dataType.refCount++;
8883 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8884 exp.expType = type1;
8885 if(type1) type1.refCount++;
8891 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8893 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8895 if(!type1._class.registered.dataType)
8896 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8897 exp.op.exp2.destType = type1._class.registered.dataType;
8898 exp.op.exp2.destType.refCount++;
8900 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8903 type2 = exp.op.exp2.destType;
8904 if(type2) type2.refCount++;
8906 exp.expType = type2;
8910 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8912 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8914 if(!type2._class.registered.dataType)
8915 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8916 exp.op.exp1.destType = type2._class.registered.dataType;
8917 exp.op.exp1.destType.refCount++;
8919 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8920 type1 = exp.op.exp1.destType;
8921 exp.expType = type1;
8925 // TESTING THIS NEW CODE
8926 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8928 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8929 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8930 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8932 // Convert the enum to an int instead for these operators
8933 if(op1IsEnum && exp.op.exp2.expType)
8935 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8937 if(exp.expType) FreeType(exp.expType);
8938 exp.expType = exp.op.exp2.expType;
8939 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8943 else if(op2IsEnum && exp.op.exp1.expType)
8945 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8947 if(exp.expType) FreeType(exp.expType);
8948 exp.expType = exp.op.exp1.expType;
8949 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8956 if(op1IsEnum && exp.op.exp2.expType)
8958 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8960 if(exp.expType) FreeType(exp.expType);
8961 exp.expType = exp.op.exp1.expType;
8962 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8966 else if(op2IsEnum && exp.op.exp1.expType)
8968 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8970 if(exp.expType) FreeType(exp.expType);
8971 exp.expType = exp.op.exp2.expType;
8972 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8981 // 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
8982 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8983 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8985 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8986 exp.op.exp1.destType = type2;
8989 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8991 if(exp.expType) FreeType(exp.expType);
8992 exp.expType = exp.op.exp1.destType;
8993 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8998 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8999 exp.op.exp2.destType = type1;
9003 // Maybe this was meant to be an enum...
9004 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9006 Type oldType = exp.op.exp2.expType;
9007 exp.op.exp2.expType = null;
9008 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9011 exp.op.exp2.expType = oldType;
9016 // TESTING THIS HERE... LATEST ADDITION
9017 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9019 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9020 exp.op.exp2.destType = type2._class.registered.dataType;
9021 if(type2._class.registered.dataType)
9022 type2._class.registered.dataType.refCount++;
9023 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9025 //exp.expType = type2._class.registered.dataType; //type2;
9026 //if(type2) type2.refCount++;
9029 // TESTING THIS HERE... LATEST ADDITION
9030 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9032 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9033 exp.op.exp1.destType = type1._class.registered.dataType;
9034 if(type1._class.registered.dataType)
9035 type1._class.registered.dataType.refCount++;
9036 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9037 exp.expType = type1._class.registered.dataType; //type1;
9038 if(type1) type1.refCount++;
9042 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9044 if(exp.expType) FreeType(exp.expType);
9045 exp.expType = exp.op.exp2.destType;
9046 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9048 else if(type1 && type2)
9050 char expString1[10240];
9051 char expString2[10240];
9052 char type1String[1024];
9053 char type2String[1024];
9054 expString1[0] = '\0';
9055 expString2[0] = '\0';
9056 type1String[0] = '\0';
9057 type2String[0] = '\0';
9060 PrintExpression(exp.op.exp1, expString1);
9061 ChangeCh(expString1, '\n', ' ');
9062 PrintExpression(exp.op.exp2, expString2);
9063 ChangeCh(expString2, '\n', ' ');
9064 PrintType(exp.op.exp1.expType, type1String, false, true);
9065 PrintType(exp.op.exp2.expType, type2String, false, true);
9068 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9070 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9072 exp.expType = exp.op.exp1.expType;
9073 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9075 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9077 exp.expType = exp.op.exp2.expType;
9078 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9086 // Maybe this was meant to be an enum...
9087 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9089 Type oldType = exp.op.exp1.expType;
9090 exp.op.exp1.expType = null;
9091 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9094 exp.op.exp1.expType = oldType;
9097 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9098 exp.op.exp1.destType = type2;
9101 // TESTING THIS HERE... LATEST ADDITION
9102 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9104 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9105 exp.op.exp1.destType = type1._class.registered.dataType;
9106 if(type1._class.registered.dataType)
9107 type1._class.registered.dataType.refCount++;
9110 // TESTING THIS HERE... LATEST ADDITION
9111 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9113 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9114 exp.op.exp2.destType = type2._class.registered.dataType;
9115 if(type2._class.registered.dataType)
9116 type2._class.registered.dataType.refCount++;
9120 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9122 if(exp.expType) FreeType(exp.expType);
9123 exp.expType = exp.op.exp1.destType;
9124 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9128 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9130 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9132 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9133 // Convert e.g. / 4 into / 4.0
9134 exp.op.exp1.destType = type2._class.registered.dataType;
9135 if(type2._class.registered.dataType)
9136 type2._class.registered.dataType.refCount++;
9137 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9139 if(exp.op.op == '!')
9141 exp.expType = MkClassType("bool");
9142 exp.expType.truth = true;
9146 exp.expType = type2;
9147 if(type2) type2.refCount++;
9150 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9152 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9154 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9155 // Convert e.g. / 4 into / 4.0
9156 exp.op.exp2.destType = type1._class.registered.dataType;
9157 if(type1._class.registered.dataType)
9158 type1._class.registered.dataType.refCount++;
9159 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9161 exp.expType = type1;
9162 if(type1) type1.refCount++;
9167 if(exp.op.exp1 && !exp.op.exp1.expType)
9169 char expString[10000];
9170 expString[0] = '\0';
9173 PrintExpression(exp.op.exp1, expString);
9174 ChangeCh(expString, '\n', ' ');
9177 Compiler_Error($"couldn't determine type of %s\n", expString);
9179 if(exp.op.exp2 && !exp.op.exp2.expType)
9181 char expString[10240];
9182 expString[0] = '\0';
9185 PrintExpression(exp.op.exp2, expString);
9186 ChangeCh(expString, '\n', ' ');
9189 Compiler_Error($"couldn't determine type of %s\n", expString);
9194 FreeType(exp.expType);
9195 exp.expType = MkClassType("bool");
9196 exp.expType.truth = true;
9199 if(exp.op.op != SIZEOF)
9200 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9201 (!exp.op.exp2 || exp.op.exp2.isConstant);
9203 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9205 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9208 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9209 Compiler_Warning($"deleting const qualified object\n");
9219 case extensionExpressionExp:
9222 exp.isConstant = true;
9223 for(e = exp.list->first; e; e = e.next)
9225 //bool inced = false;
9228 FreeType(e.destType);
9229 e.opDestType = exp.opDestType;
9230 e.destType = exp.destType;
9231 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9233 ProcessExpressionType(e);
9235 exp.destType.count--;*/
9236 if(!exp.expType && !e.next)
9238 exp.expType = e.expType;
9239 if(e.expType) e.expType.refCount++;
9242 exp.isConstant = false;
9245 // In case a cast became a member...
9246 e = exp.list->first;
9247 if(!e.next && e.type == memberExp)
9249 // Preserve prev, next
9250 Expression next = exp.next, prev = exp.prev;
9253 FreeType(exp.expType);
9254 FreeType(exp.destType);
9264 ProcessExpressionType(exp);
9271 exp.isConstant = true;
9273 ProcessExpressionType(exp.index.exp);
9274 if(!exp.index.exp.isConstant)
9275 exp.isConstant = false;
9277 if(exp.index.exp.expType)
9279 Type source = exp.index.exp.expType;
9280 if(source.kind == classType && source._class && source._class.registered)
9282 Class _class = source._class.registered;
9283 Class c = _class.templateClass ? _class.templateClass : _class;
9284 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9286 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9288 if(exp.index.index && exp.index.index->last)
9290 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9292 if(type.kind == classType) type.constant = true;
9293 else if(type.kind == pointerType)
9296 while(t.kind == pointerType) t = t.type;
9300 ((Expression)exp.index.index->last).destType = type;
9306 for(e = exp.index.index->first; e; e = e.next)
9308 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9310 if(e.destType) FreeType(e.destType);
9311 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9313 ProcessExpressionType(e);
9316 // Check if this type is int
9319 exp.isConstant = false;
9323 exp.expType = Dereference(exp.index.exp.expType);
9325 DeclareType(curExternal, exp.expType, true, false);
9332 Type methodType = null;
9338 PrintExpression(exp.call.exp, name);
9339 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9341 //exp.call.exp.expType = null;
9342 PrintExpression(exp.call.exp, name);
9345 if(exp.call.exp.type == identifierExp)
9347 Expression idExp = exp.call.exp;
9348 Identifier id = idExp.identifier;
9349 if(!strcmp(id.string, "__builtin_frame_address"))
9351 exp.expType = ProcessTypeString("void *", true);
9352 if(exp.call.arguments && exp.call.arguments->first)
9353 ProcessExpressionType(exp.call.arguments->first);
9356 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9358 exp.expType = ProcessTypeString("int", true);
9359 if(exp.call.arguments && exp.call.arguments->first)
9360 ProcessExpressionType(exp.call.arguments->first);
9363 else if(!strcmp(id.string, "Max") ||
9364 !strcmp(id.string, "Min") ||
9365 !strcmp(id.string, "Sgn") ||
9366 !strcmp(id.string, "Abs"))
9368 Expression a = null;
9369 Expression b = null;
9370 Expression tempExp1 = null, tempExp2 = null;
9371 if((!strcmp(id.string, "Max") ||
9372 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9374 a = exp.call.arguments->first;
9375 b = exp.call.arguments->last;
9379 else if(exp.call.arguments->count == 1)
9381 a = exp.call.arguments->first;
9387 exp.call.arguments->Clear();
9388 idExp.identifier = null;
9390 FreeExpContents(exp);
9392 ProcessExpressionType(a);
9394 ProcessExpressionType(b);
9396 exp.type = bracketsExp;
9397 exp.list = MkList();
9399 if(a.expType && (!b || b.expType))
9401 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9403 // Use the simpleStruct name/ids for now...
9406 OldList * specs = MkList();
9407 OldList * decls = MkList();
9409 char temp1[1024], temp2[1024];
9411 GetTypeSpecs(a.expType, specs);
9413 if(a && !a.isConstant && a.type != identifierExp)
9415 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9416 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9417 tempExp1 = QMkExpId(temp1);
9418 tempExp1.expType = a.expType;
9420 a.expType.refCount++;
9421 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9423 if(b && !b.isConstant && b.type != identifierExp)
9425 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9426 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9427 tempExp2 = QMkExpId(temp2);
9428 tempExp2.expType = b.expType;
9430 b.expType.refCount++;
9431 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9434 decl = MkDeclaration(specs, decls);
9435 if(!curCompound.compound.declarations)
9436 curCompound.compound.declarations = MkList();
9437 curCompound.compound.declarations->Insert(null, decl);
9442 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9444 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9446 MkExpCondition(MkExpBrackets(MkListOne(
9447 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9448 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9449 exp.expType = a.expType;
9451 a.expType.refCount++;
9453 else if(!strcmp(id.string, "Abs"))
9456 MkExpCondition(MkExpBrackets(MkListOne(
9457 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9458 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9459 exp.expType = a.expType;
9461 a.expType.refCount++;
9463 else if(!strcmp(id.string, "Sgn"))
9465 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9467 MkExpCondition(MkExpBrackets(MkListOne(
9468 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9469 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9470 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9471 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9472 exp.expType = ProcessTypeString("int", false);
9475 FreeExpression(tempExp1);
9476 if(tempExp2) FreeExpression(tempExp2);
9490 if(!exp.call.exp.destType)
9492 exp.call.exp.destType = dummy;
9495 ProcessExpressionType(exp.call.exp);
9496 if(exp.call.exp.destType == dummy)
9499 exp.call.exp.destType = null;
9504 // Check argument types against parameter types
9505 functionType = exp.call.exp.expType;
9507 if(functionType && functionType.kind == TypeKind::methodType)
9509 methodType = functionType;
9510 functionType = methodType.method.dataType;
9512 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9513 // TOCHECK: Instead of doing this here could this be done per param?
9514 if(exp.call.exp.expType.usedClass)
9516 char typeString[1024];
9517 typeString[0] = '\0';
9519 Symbol back = functionType.thisClass;
9520 // Do not output class specifier here (thisclass was added to this)
9521 functionType.thisClass = null;
9522 PrintType(functionType, typeString, true, true);
9523 functionType.thisClass = back;
9525 if(strstr(typeString, "thisclass"))
9527 OldList * specs = MkList();
9530 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9532 decl = SpecDeclFromString(typeString, specs, null);
9534 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9535 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9536 exp.call.exp.expType.usedClass))
9537 thisClassParams = false;
9539 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9541 Class backupThisClass = thisClass;
9542 thisClass = exp.call.exp.expType.usedClass;
9543 ProcessDeclarator(decl, true);
9544 thisClass = backupThisClass;
9547 thisClassParams = true;
9549 functionType = ProcessType(specs, decl);
9550 functionType.refCount = 0;
9551 FinishTemplatesContext(context);
9553 // Mark parameters that were 'thisclass'
9556 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9558 //p.wasThisClass = op.kind == thisClassType;
9559 if(op.kind == thisClassType)
9560 p.thisClassFrom = methodType.method._class;
9563 if(methodType.method.dataType.returnType.kind == thisClassType)
9565 // functionType.returnType.wasThisClass = true;
9566 functionType.returnType.thisClassFrom = methodType.method._class;
9570 FreeList(specs, FreeSpecifier);
9571 FreeDeclarator(decl);
9575 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9577 Type type = functionType.type;
9578 if(!functionType.refCount)
9580 functionType.type = null;
9581 FreeType(functionType);
9583 //methodType = functionType;
9584 functionType = type;
9586 if(functionType && functionType.kind != TypeKind::functionType)
9588 Compiler_Error($"called object %s is not a function\n", name);
9590 else if(functionType)
9592 bool emptyParams = false, noParams = false;
9593 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9594 Type type = functionType.params.first;
9595 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9597 Location oldyylloc = yylloc;
9599 if(!type) emptyParams = true;
9602 if(functionType.extraParam && e && functionType.thisClass)
9604 e.destType = MkClassType(functionType.thisClass.string);
9608 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9609 // Fixed #141 by adding '&& !functionType.extraParam'
9610 if(!functionType.staticMethod && !functionType.extraParam)
9612 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9613 memberExp.member.exp.expType._class)
9615 type = MkClassType(memberExp.member.exp.expType._class.string);
9620 type = functionType.params.first;
9625 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9627 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9628 type.byReference = functionType.byReference;
9629 type.typedByReference = functionType.typedByReference;
9632 // Allow manually passing a class for typed object
9633 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9637 type = functionType.params.first;
9645 if(type && type.kind == voidType)
9648 if(!type.refCount) FreeType(type);
9652 for( ; e; e = e.next)
9654 if(!type && !emptyParams)
9657 if(methodType && methodType.methodClass)
9658 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9659 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9660 noParams ? 0 : functionType.params.count);
9662 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9663 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9664 noParams ? 0 : functionType.params.count);
9668 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9670 Type templatedType = null;
9671 Class _class = methodType.usedClass;
9672 ClassTemplateParameter curParam = null;
9674 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9677 for(sClass = _class; sClass; sClass = sClass.base)
9679 if(sClass.templateClass) sClass = sClass.templateClass;
9681 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9683 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9686 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9688 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9689 id += nextClass.templateParams.count;
9698 if(curParam && _class.templateArgs[id].dataTypeString)
9700 bool constant = type.constant;
9701 ClassTemplateArgument arg = _class.templateArgs[id];
9703 Context context = SetupTemplatesContext(_class);
9706 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9707 templatedType = ProcessTypeString(arg.dataTypeString, false);
9708 FinishTemplatesContext(context);
9711 if(templatedType.kind == classType && constant) templatedType.constant = true;
9712 else if(templatedType.kind == pointerType)
9714 Type t = templatedType.type;
9715 while(t.kind == pointerType) t = t.type;
9716 if(constant) t.constant = constant;
9719 e.destType = templatedType;
9722 templatedType.passAsTemplate = true;
9723 // templatedType.refCount++;
9729 if(type) type.refCount++;
9734 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9736 e.destType = type.prev;
9737 e.destType.refCount++;
9742 if(type) type.refCount++;
9745 // Don't reach the end for the ellipsis
9746 if(type && type.kind != ellipsisType)
9748 Type next = type.next;
9749 if(!type.refCount) FreeType(type);
9754 if(type && type.kind != ellipsisType)
9756 if(methodType && methodType.methodClass)
9757 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9758 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9759 functionType.params.count + extra);
9761 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9762 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9763 functionType.params.count + extra);
9766 if(type && !type.refCount) FreeType(type);
9773 kind = TypeKind::functionType;
9776 if(exp.call.exp.type == identifierExp)
9778 char * string = exp.call.exp.identifier.string;
9782 Location oldyylloc = yylloc;
9784 yylloc = exp.call.exp.identifier.loc;
9785 if(strstr(string, "__builtin_") == string)
9789 functionType.returnType = exp.destType;
9790 exp.destType.refCount++;
9794 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9795 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9796 globalContext.symbols.Add((BTNode)symbol);
9797 if(strstr(symbol.string, "::"))
9798 globalContext.hasNameSpace = true;
9803 else if(exp.call.exp.type == memberExp)
9805 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9806 exp.call.exp.member.member.string);*/
9809 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9811 if(!functionType.returnType)
9813 functionType.returnType = Type
9820 if(functionType && functionType.kind == TypeKind::functionType)
9822 exp.expType = functionType.returnType;
9824 if(functionType.returnType)
9825 functionType.returnType.refCount++;
9827 if(!functionType.refCount)
9828 FreeType(functionType);
9831 if(exp.call.arguments)
9833 for(e = exp.call.arguments->first; e; e = e.next)
9834 ProcessExpressionType(e);
9841 Location oldyylloc = yylloc;
9843 Expression checkExp = exp.member.exp;
9846 if(checkExp.type == castExp)
9847 checkExp = checkExp.cast.exp;
9848 else if(checkExp.type == bracketsExp)
9849 checkExp = checkExp.list ? checkExp.list->first : null;
9854 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9855 exp.thisPtr = thisPtr;
9857 // DOING THIS LATER NOW...
9858 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9860 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9861 /* TODO: Name Space Fix ups
9862 if(!exp.member.member.classSym)
9863 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9867 ProcessExpressionType(exp.member.exp);
9868 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9869 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9871 exp.isConstant = false;
9874 exp.isConstant = exp.member.exp.isConstant;
9875 type = exp.member.exp.expType;
9879 if(type && (type.kind == templateType))
9881 Class _class = thisClass ? thisClass : currentClass;
9882 ClassTemplateParameter param = null;
9885 for(param = _class.templateParams.first; param; param = param.next)
9887 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9891 if(param && param.defaultArg.member)
9893 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9896 Expression expMember = exp.member.exp;
9898 OldList * specs = MkList();
9899 char thisClassTypeString[1024];
9901 FreeIdentifier(exp.member.member);
9903 ProcessExpressionType(argExp);
9906 char * colon = strstr(param.defaultArg.memberString, "::");
9909 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9910 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9913 strcpy(thisClassTypeString, _class.fullName);
9916 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9918 exp.expType = ProcessType(specs, decl);
9919 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9921 Class expClass = exp.expType._class.registered;
9922 Class cClass = null;
9926 char templateString[1024];
9927 ClassTemplateParameter param;
9928 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9929 for(cClass = expClass; cClass; cClass = cClass.base)
9932 for(param = cClass.templateParams.first; param; param = param.next)
9936 ClassTemplateArgument arg;
9937 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9938 arg = expClass.templateArgs[id];
9940 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9942 ClassTemplateParameter cParam;
9943 //int p = numParams - sClass.templateParams.count;
9946 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9948 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9950 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9952 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9954 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9955 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9967 strcat(argument, arg.name.string);
9968 strcat(argument, " = ");
9974 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9975 char expString[1024];
9976 OldList * specs = MkList();
9977 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9979 char * string = PrintHexUInt64(arg.expression.ui64);
9980 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9983 ProcessExpressionType(exp);
9984 ComputeExpression(exp);
9985 expString[0] = '\0';
9986 PrintExpression(exp, expString);
9987 strcat(argument, expString);
9989 FreeExpression(exp);
9994 strcat(argument, arg.member.name);
9997 case TemplateParameterType::type:
9999 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10001 if(!strcmp(arg.dataTypeString, "thisclass"))
10002 strcat(argument, thisClassTypeString);
10004 strcat(argument, arg.dataTypeString);
10011 if(paramCount) strcat(templateString, ", ");
10012 if(lastParam != p - 1)
10014 strcat(templateString, param.name);
10015 strcat(templateString, " = ");
10017 strcat(templateString, argument);
10026 int len = strlen(templateString);
10027 if(templateString[len-1] == '>') templateString[len++] = ' ';
10028 templateString[len++] = '>';
10029 templateString[len++] = '\0';
10032 Context context = SetupTemplatesContext(_class);
10033 FreeType(exp.expType);
10034 exp.expType = ProcessTypeString(templateString, false);
10035 FinishTemplatesContext(context);
10039 if(!expMember.expType.isPointerType)
10040 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10041 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10042 exp.type = bracketsExp;
10043 exp.list = MkListOne(MkExpOp(null, '*',
10046 exp.op.exp1 = null;
10048 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10049 MkExpBrackets(MkListOne(
10050 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10053 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10055 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10060 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10061 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10063 type = ProcessTemplateParameterType(type.templateParameter);
10066 // TODO: *** This seems to be where we should add method support for all basic types ***
10067 if(type && (type.kind == templateType));
10068 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10069 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10070 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10071 (type.kind == pointerType && type.type.kind == charType)))
10073 Identifier id = exp.member.member;
10074 TypeKind typeKind = type.kind;
10075 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10076 if(typeKind == subClassType && exp.member.exp.type == classExp)
10078 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10079 typeKind = classType;
10084 if(typeKind == intType || typeKind == enumType)
10085 _class = eSystem_FindClass(privateModule, "int");
10088 if(type.kind == classType && type._class && type._class.registered)
10090 _class = type._class.registered;
10092 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10094 _class = FindClass("char *").registered;
10096 else if(type.kind == pointerType)
10098 _class = eSystem_FindClass(privateModule, "uintptr");
10099 FreeType(exp.expType);
10100 exp.expType = ProcessTypeString("uintptr", false);
10101 exp.byReference = true;
10105 char string[1024] = "";
10107 PrintTypeNoConst(type, string, false, true);
10108 classSym = FindClass(string);
10109 if(classSym) _class = classSym.registered;
10117 (exp.member.exp.type == identifierExp &&
10118 !strcmp(exp.member.exp.identifier.string, "this"));*/
10119 Property prop = null;
10120 Method method = null;
10121 DataMember member = null;
10122 Property revConvert = null;
10123 ClassProperty classProp = null;
10125 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10126 exp.member.memberType = propertyMember;
10128 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10129 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10131 if(typeKind != subClassType)
10133 // Prioritize data members over properties for "this"
10134 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10136 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10137 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10139 prop = eClass_FindProperty(_class, id.string, privateModule);
10143 if(!member && !prop)
10144 prop = eClass_FindProperty(_class, id.string, privateModule);
10145 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10146 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10147 exp.member.thisPtr = true;
10149 // Prioritize properties over data members otherwise
10152 bool useMemberForNonConst = false;
10153 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10156 prop = eClass_FindProperty(_class, id.string, null);
10158 useMemberForNonConst = prop && exp.destType &&
10159 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10160 !strncmp(prop.dataTypeString, "const ", 6);
10162 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10163 member = eClass_FindDataMember(_class, id.string, null, null, null);
10166 if((!prop || useMemberForNonConst) && !member)
10168 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10171 prop = eClass_FindProperty(_class, id.string, privateModule);
10173 useMemberForNonConst |= prop && exp.destType &&
10174 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10175 !strncmp(prop.dataTypeString, "const ", 6);
10177 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10178 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10184 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10191 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10192 method = eClass_FindMethod(_class, id.string, privateModule);
10193 if(!prop && !member && !method)
10195 if(typeKind == subClassType)
10197 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10200 exp.member.memberType = classPropertyMember;
10201 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10205 // Assume this is a class_data member
10206 char structName[1024];
10207 Identifier id = exp.member.member;
10208 Expression classExp = exp.member.exp;
10211 FreeType(classExp.expType);
10212 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10214 strcpy(structName, "__ecereClassData_");
10215 FullClassNameCat(structName, type._class.string, false);
10216 exp.type = pointerExp;
10217 exp.member.member = id;
10219 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10220 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10221 MkExpBrackets(MkListOne(MkExpOp(
10222 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10223 MkExpMember(classExp, MkIdentifier("data"))), '+',
10224 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10229 ProcessExpressionType(exp);
10235 // Check for reverse conversion
10236 // (Convert in an instantiation later, so that we can use
10237 // deep properties system)
10238 Symbol classSym = FindClass(id.string);
10241 Class convertClass = classSym.registered;
10243 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10248 //if(!exp.member.exp.destType)
10249 if(exp.member.exp.destType)
10250 FreeType(exp.member.exp.destType);
10252 if(method && !method._class.symbol)
10253 method._class.symbol = FindClass(method._class.fullName);
10254 if(prop && !prop._class.symbol)
10255 prop._class.symbol = FindClass(prop._class.fullName);
10257 exp.member.exp.destType = Type
10261 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10262 // wasThisClass = type ? type.wasThisClass : false;
10263 thisClassFrom = type ? type.thisClassFrom : null;
10269 exp.member.memberType = propertyMember;
10271 ProcessPropertyType(prop);
10272 exp.expType = prop.dataType;
10273 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10276 CopyTypeInto(type, exp.expType);
10278 type.constant = true;
10279 exp.expType = type;
10281 else if(prop.dataType)
10282 prop.dataType.refCount++;
10286 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10288 FreeExpContents(exp);
10289 exp.type = identifierExp;
10290 exp.identifier = MkIdentifier("class");
10291 ProcessExpressionType(exp);
10295 exp.member.memberType = dataMember;
10296 DeclareStruct(curExternal, _class.fullName, false, true);
10297 if(member._class != _class)
10298 DeclareStruct(curExternal, member._class.fullName, false, true);
10300 if(!member.dataType)
10302 Context context = SetupTemplatesContext(_class);
10303 member.dataType = ProcessTypeString(member.dataTypeString, false);
10304 FinishTemplatesContext(context);
10306 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)
10307 member.dataType.bitMemberSize = ((BitMember)member).size;
10308 exp.expType = member.dataType;
10309 if(member.dataType) member.dataType.refCount++;
10311 else if(revConvert)
10313 exp.member.memberType = reverseConversionMember;
10314 exp.expType = MkClassType(revConvert._class.fullName);
10322 exp.type = identifierExp;
10323 exp.identifier = exp.member.member;
10326 exp.member.memberType = methodMember;
10328 if(!method.dataType)
10329 ProcessMethodType(method);
10337 // Tricky spot here... To use instance versus class virtual table
10338 // Put it back to what it was... What did we break?
10340 // Had to put it back for overriding Main of Thread global instance
10342 //exp.expType.methodClass = _class;
10343 exp.expType.methodClass = (id && id._class) ? _class : null;
10345 // Need the actual class used for templated classes
10346 exp.expType.usedClass = _class;
10348 else if(!classProp)
10350 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10352 FreeExpContents(exp);
10353 exp.type = identifierExp;
10354 exp.identifier = MkIdentifier("class");
10355 FreeType(exp.expType);
10356 exp.expType = MkClassType("ecere::com::Class");
10359 yylloc = exp.member.member.loc;
10360 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10362 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10365 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10369 tClass = type._class && type._class.registered ? type._class.registered : _class;
10370 while(tClass && !tClass.templateClass) tClass = tClass.base;
10372 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10375 ClassTemplateParameter curParam = null;
10378 for(sClass = tClass; sClass; sClass = sClass.base)
10381 if(sClass.templateClass) sClass = sClass.templateClass;
10382 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10384 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10386 for(sClass = sClass.base; sClass; sClass = sClass.base)
10387 id += sClass.templateParams.count;
10392 if(curParam) break;
10395 if(curParam && tClass.templateArgs[id].dataTypeString)
10397 ClassTemplateArgument arg = tClass.templateArgs[id];
10398 Context context = SetupTemplatesContext(tClass);
10399 bool constant = exp.expType.constant;
10400 bool passAsTemplate = false;
10401 Class thisClassFrom = null;
10402 Type t = ProcessTypeString(exp.expType.templateParameter.dataTypeString, false);
10403 if(t && t.kind == classType && t._class)
10404 thisClassFrom = t._class.registered;
10406 // Mark that 'thisClassFrom' was set to something
10407 thisClassFrom = eSystem_FindClass(GetPrivateModule(), "class");
10411 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10412 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10414 /*if(!arg.dataType)
10415 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10416 FreeType(exp.expType);
10418 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10419 exp.expType.thisClassFrom = thisClassFrom;
10420 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10421 else if(exp.expType.kind == pointerType)
10423 Type t = exp.expType.type;
10424 while(t.kind == pointerType) t = t.type;
10425 if(constant) t.constant = constant;
10429 if(exp.expType.kind == thisClassType)
10431 FreeType(exp.expType);
10432 exp.expType = ReplaceThisClassType(_class);
10436 exp.expType.passAsTemplate = true;
10437 //exp.expType.refCount++;
10440 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10441 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10442 else if(exp.destType.kind == pointerType)
10444 Type t = exp.destType.type;
10445 while(t.kind == pointerType) t = t.type;
10446 if(constant) t.constant = constant;
10449 //exp.destType.refCount++;
10451 if(exp.destType.kind == thisClassType)
10453 FreeType(exp.destType);
10454 exp.destType = ReplaceThisClassType(_class);
10458 FinishTemplatesContext(context);
10461 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10462 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10465 ClassTemplateParameter curParam = null;
10468 for(sClass = tClass; sClass; sClass = sClass.base)
10471 if(sClass.templateClass) sClass = sClass.templateClass;
10472 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10474 if(curParam.type == TemplateParameterType::type &&
10475 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10477 for(sClass = sClass.base; sClass; sClass = sClass.base)
10478 id += sClass.templateParams.count;
10483 if(curParam) break;
10488 ClassTemplateArgument arg = tClass.templateArgs[id];
10489 Context context = SetupTemplatesContext(tClass);
10491 /*if(!arg.dataType)
10492 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10494 basicType = ProcessTypeString(arg.dataTypeString, false);
10497 if(basicType.kind == thisClassType)
10499 FreeType(basicType);
10500 basicType = ReplaceThisClassType(_class);
10503 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10504 if(tClass.templateClass)
10505 basicType.passAsTemplate = true;
10508 FreeType(exp.expType);
10510 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10511 //exp.expType.refCount++;
10514 exp.destType = exp.expType;
10515 exp.destType.refCount++;
10519 Expression newExp { };
10520 OldList * specs = MkList();
10522 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10524 if(exp.destType) exp.destType.refCount++;
10525 if(exp.expType) exp.expType.refCount++;
10526 exp.type = castExp;
10527 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10528 exp.cast.exp = newExp;
10529 //FreeType(exp.expType);
10530 //exp.expType = null;
10531 //ProcessExpressionType(sourceExp);
10534 FinishTemplatesContext(context);
10537 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10539 Class expClass = exp.expType._class.registered;
10542 Class cClass = null;
10544 int paramCount = 0;
10545 int lastParam = -1;
10546 char templateString[1024];
10547 ClassTemplateParameter param;
10548 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10549 while(cClass != expClass)
10552 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10555 for(param = cClass.templateParams.first; param; param = param.next)
10557 Class cClassCur = null;
10559 ClassTemplateParameter paramCur = null;
10560 ClassTemplateArgument arg;
10561 while(cClassCur != tClass && !paramCur)
10564 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10565 cClassCur = sClassCur;
10567 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10569 if(!strcmp(paramCur.name, param.name))
10577 if(paramCur && paramCur.type == TemplateParameterType::type)
10578 arg = tClass.templateArgs[cp];
10580 arg = expClass.templateArgs[p];
10583 char argument[256];
10584 argument[0] = '\0';
10587 strcat(argument, arg.name.string);
10588 strcat(argument, " = ");
10594 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10595 char expString[1024];
10596 OldList * specs = MkList();
10597 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10599 char * string = PrintHexUInt64(arg.expression.ui64);
10600 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10603 ProcessExpressionType(exp);
10604 ComputeExpression(exp);
10605 expString[0] = '\0';
10606 PrintExpression(exp, expString);
10607 strcat(argument, expString);
10609 FreeExpression(exp);
10614 strcat(argument, arg.member.name);
10617 case TemplateParameterType::type:
10619 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10620 strcat(argument, arg.dataTypeString);
10626 if(paramCount) strcat(templateString, ", ");
10627 if(lastParam != p - 1)
10629 strcat(templateString, param.name);
10630 strcat(templateString, " = ");
10632 strcat(templateString, argument);
10641 int len = strlen(templateString);
10642 if(templateString[len-1] == '>') templateString[len++] = ' ';
10643 templateString[len++] = '>';
10644 templateString[len++] = '\0';
10647 FreeType(exp.expType);
10649 Context context = SetupTemplatesContext(tClass);
10650 exp.expType = ProcessTypeString(templateString, false);
10651 FinishTemplatesContext(context);
10658 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10660 else if(type && (type.kind == structType || type.kind == unionType))
10662 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10665 exp.expType = memberType;
10667 memberType.refCount++;
10672 char expString[10240];
10673 expString[0] = '\0';
10674 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10675 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10678 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10680 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10682 Identifier id = exp.member.member;
10683 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10686 FreeType(exp.expType);
10687 exp.expType = ReplaceThisClassType(_class);
10691 yylloc = oldyylloc;
10694 // Convert x->y into (*x).y
10697 Type destType = exp.destType;
10699 // DOING THIS LATER NOW...
10700 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10702 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10703 /* TODO: Name Space Fix ups
10704 if(!exp.member.member.classSym)
10705 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10709 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10710 exp.type = memberExp;
10713 ProcessExpressionType(exp);
10720 //ComputeExpression(exp);
10722 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10723 if(classSym && classSym.registered)
10725 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10728 Class b = classSym.registered;
10730 DeclareStruct(curExternal, classSym.string, false, true);
10731 FreeSpecifier(exp._class);
10732 FullClassNameCat(name, classSym.string, false);
10736 exp.type = typeSizeExp;
10737 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10743 if(b.structSize == b.offset)
10744 exp.op.exp1 = MkExpConstant("0");
10746 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10749 while(b.offset != 0)
10752 Expression typeSize;
10755 sym = FindClass(b.fullName);
10758 DeclareStruct(curExternal, sym.string, false, true);
10759 FullClassNameCat(name, sym.string, false);
10761 if(b.structSize == b.offset)
10762 typeSize = MkExpConstant("0");
10764 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10765 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10772 if(classSym.registered.fixed && !classSym.registered.structSize)
10774 FreeSpecifier(exp._class);
10775 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10776 exp.type = constantExp;
10780 char className[1024];
10781 strcpy(className, "__ecereClass_");
10782 FullClassNameCat(className, classSym.string, true);
10784 DeclareClass(curExternal, classSym, className);
10786 FreeExpContents(exp);
10787 exp.type = pointerExp;
10788 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10789 exp.member.member = MkIdentifier("structSize");
10797 kind = intSizeType;
10799 // exp.isConstant = true;
10804 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10809 kind = intSizeType;
10811 exp.isConstant = true;
10813 DeclareType(curExternal, type, true, false);
10819 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10821 FreeType(exp.cast.exp.destType);
10822 exp.cast.exp.destType = type;
10824 type.casted = true;
10825 ProcessExpressionType(exp.cast.exp);
10826 type.casted = false;
10828 exp.expType = type;
10831 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10832 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10834 void * prev = exp.prev, * next = exp.next;
10835 Type expType = exp.cast.exp.destType;
10836 Expression castExp = exp.cast.exp;
10837 Type destType = exp.destType;
10839 if(expType) expType.refCount++;
10841 //FreeType(exp.destType);
10842 FreeType(exp.expType);
10843 FreeTypeName(exp.cast.typeName);
10846 FreeType(exp.expType);
10847 FreeType(exp.destType);
10849 exp.expType = expType;
10850 exp.destType = destType;
10860 exp.isConstant = exp.cast.exp.isConstant;
10865 case extensionInitializerExp:
10867 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10868 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10869 // ProcessInitializer(exp.initializer.initializer, type);
10870 exp.expType = type;
10875 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10876 ProcessExpressionType(exp.vaArg.exp);
10877 exp.expType = type;
10883 Type t = exp.destType;
10884 if(t && !exp.destType.casted)
10887 CopyTypeInto(t, exp.destType);
10893 exp.isConstant = true;
10895 FreeType(exp.cond.cond.destType);
10896 exp.cond.cond.destType = MkClassType("bool");
10897 exp.cond.cond.destType.truth = true;
10898 ProcessExpressionType(exp.cond.cond);
10899 if(!exp.cond.cond.isConstant)
10900 exp.isConstant = false;
10901 for(e = exp.cond.exp->first; e; e = e.next)
10905 FreeType(e.destType);
10907 if(e.destType) e.destType.refCount++;
10909 ProcessExpressionType(e);
10912 exp.expType = e.expType;
10913 if(e.expType) e.expType.refCount++;
10916 exp.isConstant = false;
10919 FreeType(exp.cond.elseExp.destType);
10920 // Added this check if we failed to find an expType
10921 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10924 exp.cond.elseExp.destType = t ? t : exp.expType;
10926 if(exp.cond.elseExp.destType)
10927 exp.cond.elseExp.destType.refCount++;
10928 ProcessExpressionType(exp.cond.elseExp);
10930 // FIXED THIS: Was done before calling process on elseExp
10931 if(!exp.cond.elseExp.isConstant)
10932 exp.isConstant = false;
10937 case extensionCompoundExp:
10939 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10941 Statement last = exp.compound.compound.statements->last;
10942 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10944 ((Expression)last.expressions->last).destType = exp.destType;
10946 exp.destType.refCount++;
10948 ProcessStatement(exp.compound);
10949 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10951 exp.expType.refCount++;
10957 Specifier spec = exp._classExp.specifiers->first;
10958 if(spec && spec.type == nameSpecifier)
10960 exp.expType = MkClassType(spec.name);
10961 exp.expType.kind = subClassType;
10962 exp.byReference = true;
10966 exp.expType = MkClassType("ecere::com::Class");
10967 exp.byReference = true;
10973 Class _class = thisClass ? thisClass : currentClass;
10976 Identifier id = exp.classData.id;
10977 char structName[1024];
10978 Expression classExp;
10979 strcpy(structName, "__ecereClassData_");
10980 FullClassNameCat(structName, _class.fullName, false);
10981 exp.type = pointerExp;
10982 exp.member.member = id;
10983 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10984 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10986 classExp = MkExpIdentifier(MkIdentifier("class"));
10988 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10989 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10990 MkExpBrackets(MkListOne(MkExpOp(
10991 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10992 MkExpMember(classExp, MkIdentifier("data"))), '+',
10993 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10996 ProcessExpressionType(exp);
11004 const char * typeString = null;
11005 char typeStringBuf[1024];
11006 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11007 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11009 Class templateClass = exp.destType._class.registered;
11010 typeString = templateClass.templateArgs[2].dataTypeString;
11014 // Guess type from expressions in the array
11016 for(e = exp.list->first; e; e = e.next)
11018 ProcessExpressionType(e);
11021 if(!type) { type = e.expType; type.refCount++; }
11024 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11025 if(!MatchTypeExpression(e, type, null, false, true))
11031 e = exp.list->first;
11032 ProcessExpressionType(e);
11035 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11036 if(!MatchTypeExpression(e, type, null, false, true))
11038 FreeType(e.expType);
11049 FreeType(e.expType);
11056 typeStringBuf[0] = '\0';
11057 PrintTypeNoConst(type, typeStringBuf, false, true);
11058 typeString = typeStringBuf;
11066 (Container)& (struct BuiltInContainer)
11068 ._vTbl = class(BuiltInContainer)._vTbl,
11069 ._class = class(BuiltInContainer),
11071 .data = (int[]){ 1, 7, 3, 4, 5 },
11073 .type = class(int),
11076 char templateString[1024];
11077 OldList * initializers = MkList();
11078 OldList * structInitializers = MkList();
11079 OldList * specs = MkList();
11081 Declarator decl = SpecDeclFromString(typeString, specs, null);
11082 sprintf(templateString, "Container<%s>", typeString);
11087 type = ProcessTypeString(typeString, false);
11088 while((e = exp.list->first))
11090 exp.list->Remove(e);
11093 ProcessExpressionType(e);
11094 ListAdd(initializers, MkInitializerAssignment(e));
11100 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11102 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11103 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11104 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11105 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11106 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11107 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11108 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11109 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11110 MkInitializerList(initializers))));
11111 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11112 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11113 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11114 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11115 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11116 exp.expType = ProcessTypeString(templateString, false);
11117 exp.type = bracketsExp;
11118 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11120 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11121 MkInitializerList(structInitializers)))));
11122 ProcessExpressionType(expExt);
11126 exp.expType = ProcessTypeString("Container", false);
11127 Compiler_Error($"Couldn't determine type of array elements\n");
11133 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11135 FreeType(exp.expType);
11136 exp.expType = ReplaceThisClassType(thisClass);
11139 // Resolve structures here
11140 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11142 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11143 // TODO: Fix members reference...
11146 if(exp.expType.kind != enumType)
11149 String enumName = CopyString(exp.expType.enumName);
11151 // Fixed a memory leak on self-referencing C structs typedefs
11152 // by instantiating a new type rather than simply copying members
11153 // into exp.expType
11154 FreeType(exp.expType);
11155 exp.expType = Type { };
11156 exp.expType.kind = symbol.type.kind;
11157 exp.expType.refCount++;
11158 exp.expType.enumName = enumName;
11160 exp.expType.members = symbol.type.members;
11161 for(member = symbol.type.members.first; member; member = member.next)
11166 NamedLink64 member;
11167 for(member = symbol.type.members.first; member; member = member.next)
11169 NamedLink64 value { name = CopyString(member.name) };
11170 exp.expType.members.Add(value);
11176 // Trying to do this here before conversion properties kick in and this becomes a new expression... (Fixing Class c; const char * a = c;)
11177 // Mark nohead classes as by reference, unless we're casting them to an integral type
11178 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11179 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11180 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11181 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11183 exp.byReference = true;
11187 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11188 else if(exp.destType && !exp.destType.keepCast)
11190 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11191 exp.needTemplateCast = 1;
11193 if(exp.destType.kind == voidType);
11194 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11196 // Warn for casting unrelated types to/from struct classes
11197 bool invalidCast = false;
11198 if(inCompiler && exp.destType.count && exp.expType)
11200 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11201 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11202 if(c1 && c1.type != structClass) c1 = null;
11203 if(c2 && c2.type != structClass) c2 = null;
11204 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11205 invalidCast = true;
11207 if(!exp.destType.count || unresolved || invalidCast)
11212 if(exp.destType.kind != ellipsisType)
11218 char expString[10240];
11219 expString[0] = '\0';
11221 PrintType(exp.destType, type2, false, true);
11223 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11225 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11226 else if(exp.type != dummyExp)
11227 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11232 char expString[10240] ;
11233 expString[0] = '\0';
11234 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11237 Compiler_Error($"unresolved identifier %s\n", expString);
11238 else if(exp.type != dummyExp)
11239 Compiler_Error($"couldn't determine type of %s\n", expString);
11250 PrintType(exp.expType, type1, false, true);
11251 PrintType(exp.destType, type2, false, true);
11254 //CheckExpressionType(exp, exp.destType, false);
11256 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11257 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11258 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11261 Expression nbExp = GetNonBracketsExp(exp);
11262 bool skipWarning = false;
11263 TypeKind kind = exp.destType.kind;
11264 if(nbExp.type == conditionExp && !nbExp.destType.casted && nbExp.destType.kind == exp.destType.kind)
11265 // The if/else operands have already been checked / warned about
11266 skipWarning = true;
11267 if((kind == charType || kind == shortType) && exp.destType.isSigned == exp.expType.signedBeforePromotion && nbExp.type == opExp && nbExp.op.exp1 && nbExp.op.exp2)
11269 int op = nbExp.op.op;
11270 Expression nbExp1, nbExp2;
11275 case '%': case '/':
11276 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11277 from = nbExp1.expType.promotedFrom;
11278 // Division and Modulo will not take more room than type before promotion
11279 if(from == charType || (kind == shortType && from == shortType))
11280 skipWarning = true;
11283 case LEFT_OP: case RIGHT_OP:
11284 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11285 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11286 from = nbExp1.expType.promotedFrom;
11287 // Right shift will not take more room than type before promotion
11288 if(op == RIGHT_OP && (from == charType || (kind == shortType && from == shortType)))
11289 skipWarning = true;
11290 else if(nbExp2.isConstant && nbExp2.type == constantExp && (nbExp.op.op == RIGHT_OP || nbExp1.expType.bitMemberSize))
11292 int n = (int)strtol(nbExp2.constant, null, 0);
11293 int s = from == charType ? 8 : 16;
11294 // Left shifting a bit member constrained in size may still fit in type before promotion
11295 if(nbExp1.expType.bitMemberSize && nbExp1.expType.bitMemberSize < s)
11296 s = nbExp1.expType.bitMemberSize;
11298 // If right shifted enough things will fit in smaller type
11299 if(nbExp.op.op == RIGHT_OP)
11303 if(s <= (kind == charType ? 8 : 16))
11304 skipWarning = true;
11308 if(!exp.destType.isSigned)
11310 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11311 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11312 from = nbExp2.expType.promotedFrom;
11313 // Max value of unsigned type before promotion minus the same will always fit
11314 if((from == charType || from == shortType) && nbExp1.isConstant && nbExp1.type == constantExp)
11316 int n = (int)strtol(nbExp1.constant, null, 0);
11317 if(n == (from == charType ? 255 : 65535))
11318 skipWarning = true;
11324 TypeKind kind1, kind2;
11325 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11326 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11327 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11328 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11329 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) &&
11330 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11331 skipWarning = true;
11336 TypeKind kind1, kind2;
11337 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11338 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11339 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11340 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11341 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) ||
11342 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11343 skipWarning = true;
11351 char expString[10240];
11352 expString[0] = '\0';
11353 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11356 CheckExpressionType(exp, exp.destType, false, true);
11359 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11360 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11361 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11362 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11363 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11366 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11368 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11372 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11375 FreeType(exp.expType);
11376 exp.destType.refCount++;
11377 exp.expType = exp.destType;
11383 // Cast function pointers to void * as eC already checked compatibility
11384 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11385 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11387 Expression nbExp = GetNonBracketsExp(exp);
11388 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11390 Expression e = MoveExpContents(exp);
11391 exp.cast.exp = MkExpBrackets(MkListOne(e));
11392 exp.type = castExp;
11393 exp.cast.exp.destType = exp.destType;
11394 if(exp.destType) exp.destType.refCount++;
11395 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11399 else if(unresolved)
11401 if(exp.identifier._class && exp.identifier._class.name)
11402 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11403 else if(exp.identifier.string && exp.identifier.string[0])
11404 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11406 else if(!exp.expType && exp.type != dummyExp)
11408 char expString[10240];
11409 expString[0] = '\0';
11410 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11411 Compiler_Error($"couldn't determine type of %s\n", expString);
11414 // Let's try to support any_object & typed_object here:
11416 ApplyAnyObjectLogic(exp);
11418 // Mark nohead classes as by reference, unless we're casting them to an integral type
11419 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11420 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11421 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11422 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11424 exp.byReference = true;
11426 yylloc = oldyylloc;
11429 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11431 // THIS CODE WILL FIND NEXT MEMBER...
11434 *curMember = (*curMember).next;
11436 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11438 *curMember = subMemberStack[--(*subMemberStackPos)];
11439 *curMember = (*curMember).next;
11442 // SKIP ALL PROPERTIES HERE...
11443 while((*curMember) && (*curMember).isProperty)
11444 *curMember = (*curMember).next;
11446 if(subMemberStackPos)
11448 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11450 subMemberStack[(*subMemberStackPos)++] = *curMember;
11452 *curMember = (*curMember).members.first;
11453 while(*curMember && (*curMember).isProperty)
11454 *curMember = (*curMember).next;
11462 if(subMemberStackPos && *subMemberStackPos)
11464 *curMember = subMemberStack[--(*subMemberStackPos)];
11465 *curMember = (*curMember).next;
11469 Class lastCurClass = *curClass;
11471 if(*curClass == _class) break; // REACHED THE END
11473 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11474 *curMember = (*curClass).membersAndProperties.first;
11477 while((*curMember) && (*curMember).isProperty)
11478 *curMember = (*curMember).next;
11479 if(subMemberStackPos)
11481 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11483 subMemberStack[(*subMemberStackPos)++] = *curMember;
11485 *curMember = (*curMember).members.first;
11486 while(*curMember && (*curMember).isProperty)
11487 *curMember = (*curMember).next;
11495 static void ProcessInitializer(Initializer init, Type type)
11499 case expInitializer:
11500 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11502 // TESTING THIS FOR SHUTTING = 0 WARNING
11503 if(init.exp && !init.exp.destType)
11505 FreeType(init.exp.destType);
11506 init.exp.destType = type;
11507 if(type) type.refCount++;
11511 ProcessExpressionType(init.exp);
11512 init.isConstant = init.exp.isConstant;
11518 Expression exp = init.exp;
11519 Instantiation inst = exp.instance;
11520 MembersInit members;
11522 init.type = listInitializer;
11523 init.list = MkList();
11527 for(members = inst.members->first; members; members = members.next)
11529 if(members.type == dataMembersInit)
11532 for(member = members.dataMembers->first; member; member = member.next)
11534 ListAdd(init.list, member.initializer);
11535 member.initializer = null;
11538 // Discard all MembersInitMethod
11541 FreeExpression(exp);
11543 case listInitializer:
11546 Type initializerType = null;
11547 Class curClass = null;
11548 DataMember curMember = null;
11549 DataMember subMemberStack[256];
11550 int subMemberStackPos = 0;
11552 if(type && type.kind == arrayType)
11553 initializerType = Dereference(type);
11554 else if(type && (type.kind == structType || type.kind == unionType))
11555 initializerType = type.members.first;
11557 for(i = init.list->first; i; i = i.next)
11559 if(type && type.kind == classType && type._class && type._class.registered)
11561 // 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)
11562 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11563 // TODO: Generate error on initializing a private data member this way from another module...
11566 if(!curMember.dataType)
11567 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11568 initializerType = curMember.dataType;
11571 ProcessInitializer(i, initializerType);
11572 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11573 initializerType = initializerType.next;
11575 init.isConstant = false;
11578 if(type && type.kind == arrayType)
11579 FreeType(initializerType);
11581 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11583 Compiler_Error($"Assigning list initializer to non list\n");
11590 static void ProcessSpecifier(Specifier spec, bool declareStruct, bool warnClasses)
11594 case baseSpecifier:
11596 if(spec.specifier == THISCLASS)
11600 spec.type = nameSpecifier;
11601 spec.name = ReplaceThisClass(thisClass);
11602 spec.symbol = FindClass(spec.name);
11603 ProcessSpecifier(spec, declareStruct, false);
11608 case nameSpecifier:
11610 Symbol symbol = FindType(curContext, spec.name);
11612 DeclareType(curExternal, symbol.type, true, true);
11613 else if(spec.symbol /*&& declareStruct*/)
11615 Class c = spec.symbol.registered;
11616 if(warnClasses && !c)
11617 Compiler_Warning("Undeclared class %s\n", spec.name);
11618 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11622 case enumSpecifier:
11627 for(e = spec.list->first; e; e = e.next)
11630 ProcessExpressionType(e.exp);
11633 // Fall through for IDE type processing
11637 case structSpecifier:
11638 case unionSpecifier:
11640 if(spec.definitions)
11643 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11645 ProcessClass(spec.definitions, symbol);
11648 for(def = spec.definitions->first; def; def = def.next)
11650 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11651 ProcessDeclaration(def.decl);
11658 case classSpecifier:
11660 Symbol classSym = FindClass(spec.name);
11661 if(classSym && classSym.registered && classSym.registered.type == structClass)
11662 DeclareStruct(spec.name, false, true);
11670 static void ProcessDeclarator(Declarator decl, bool isFunction)
11674 case identifierDeclarator:
11675 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11677 FreeSpecifier(decl.identifier._class);
11678 decl.identifier._class = null;
11681 case arrayDeclarator:
11683 ProcessExpressionType(decl.array.exp);
11684 case structDeclarator:
11685 case bracketsDeclarator:
11686 case functionDeclarator:
11687 case pointerDeclarator:
11688 case extendedDeclarator:
11689 case extendedDeclaratorEnd:
11691 Identifier id = null;
11692 Specifier classSpec = null;
11693 if(decl.type == functionDeclarator)
11695 id = GetDeclId(decl);
11696 if(id && id._class)
11698 classSpec = id._class;
11702 if(decl.declarator)
11703 ProcessDeclarator(decl.declarator, isFunction);
11704 if(decl.type == functionDeclarator)
11710 qualifiers = MkListOne(classSpec);
11713 if(!decl.function.parameters)
11714 decl.function.parameters = MkList();
11715 decl.function.parameters->Insert(null, param);
11717 if(decl.function.parameters)
11721 for(param = decl.function.parameters->first; param; param = param.next)
11723 if(param.qualifiers)
11726 for(spec = param.qualifiers->first; spec; spec = spec.next)
11728 if(spec.type == baseSpecifier)
11730 if(spec.specifier == TYPED_OBJECT)
11732 Declarator d = param.declarator;
11735 qualifiers = MkListOne(MkSpecifier(VOID));
11736 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11738 if(d.type != pointerDeclarator)
11739 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11741 FreeList(param.qualifiers, FreeSpecifier);
11743 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11744 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11746 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11748 decl.function.parameters->Insert(param, newParam);
11752 else if(spec.specifier == ANY_OBJECT)
11754 Declarator d = param.declarator;
11756 FreeList(param.qualifiers, FreeSpecifier);
11758 param.qualifiers = MkListOne(MkSpecifier(VOID));
11759 if(d.type != pointerDeclarator)
11760 param.qualifiers->Insert(null, MkSpecifier(CONST));
11761 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11764 else if(spec.specifier == THISCLASS)
11768 spec.type = nameSpecifier;
11769 spec.name = ReplaceThisClass(thisClass);
11770 spec.symbol = FindClass(spec.name);
11771 ProcessSpecifier(spec, false, false);
11776 else if(spec.type == nameSpecifier)
11778 ProcessSpecifier(spec, isFunction, true);
11783 if(param.declarator)
11784 ProcessDeclarator(param.declarator, false);
11793 static void ProcessDeclaration(Declaration decl, bool warnClasses)
11798 case initDeclaration:
11800 bool declareStruct = false;
11802 lineNum = decl.pos.line;
11803 column = decl.pos.col;
11806 if(decl.declarators)
11810 for(d = decl.declarators->first; d; d = d.next)
11812 Type type, subType;
11813 ProcessDeclarator(d.declarator, false);
11815 type = ProcessType(decl.specifiers, d.declarator);
11819 ProcessInitializer(d.initializer, type);
11821 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11823 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11824 d.initializer.exp.type == instanceExp)
11826 if(type.kind == classType && type._class ==
11827 d.initializer.exp.expType._class)
11829 Instantiation inst = d.initializer.exp.instance;
11830 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11832 d.initializer.exp.instance = null;
11833 if(decl.specifiers)
11834 FreeList(decl.specifiers, FreeSpecifier);
11835 FreeList(decl.declarators, FreeInitDeclarator);
11839 decl.type = instDeclaration;
11844 for(subType = type; subType;)
11846 if(subType.kind == classType)
11848 declareStruct = true;
11851 else if(subType.kind == pointerType)
11853 else if(subType.kind == arrayType)
11854 subType = subType.arrayType;
11864 if(decl.specifiers)
11867 for(s = decl.specifiers->first; s; s = s.next)
11869 ProcessSpecifier(s, declareStruct, true);
11874 case instDeclaration:
11876 ProcessInstantiationType(decl.inst);
11879 case structDeclaration:
11883 bool declareStruct = false;
11885 if(decl.declarators)
11887 for(d = decl.declarators->first; d; d = d.next)
11889 Type type = ProcessType(decl.specifiers, d.declarator);
11891 ProcessDeclarator(d, false);
11892 for(subType = type; subType;)
11894 if(subType.kind == classType)
11896 declareStruct = true;
11899 else if(subType.kind == pointerType)
11901 else if(subType.kind == arrayType)
11902 subType = subType.arrayType;
11909 if(decl.specifiers)
11911 for(spec = decl.specifiers->first; spec; spec = spec.next)
11912 ProcessSpecifier(spec, declareStruct, warnClasses);
11919 static FunctionDefinition curFunction;
11921 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11923 char propName[1024], propNameM[1024];
11924 char getName[1024], setName[1024];
11927 DeclareProperty(curExternal, prop, setName, getName);
11929 // eInstance_FireWatchers(object, prop);
11930 strcpy(propName, "__ecereProp_");
11931 FullClassNameCat(propName, prop._class.fullName, false);
11932 strcat(propName, "_");
11933 FullClassNameCat(propName, prop.name, true);
11935 strcpy(propNameM, "__ecerePropM_");
11936 FullClassNameCat(propNameM, prop._class.fullName, false);
11937 strcat(propNameM, "_");
11938 FullClassNameCat(propNameM, prop.name, true);
11940 if(prop.isWatchable)
11943 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11944 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11945 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11948 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11949 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11950 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11952 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
11957 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11958 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11959 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11962 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11963 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11964 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11966 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
11969 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11970 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11971 curFunction.propSet.fireWatchersDone = true;
11974 static void ProcessStatement(Statement stmt)
11978 lineNum = stmt.pos.line;
11979 column = stmt.pos.col;
11984 ProcessStatement(stmt.labeled.stmt);
11987 // This expression should be constant...
11988 if(stmt.caseStmt.exp)
11990 FreeType(stmt.caseStmt.exp.destType);
11991 stmt.caseStmt.exp.destType = curSwitchType;
11992 if(curSwitchType) curSwitchType.refCount++;
11993 ProcessExpressionType(stmt.caseStmt.exp);
11994 ComputeExpression(stmt.caseStmt.exp);
11996 if(stmt.caseStmt.stmt)
11997 ProcessStatement(stmt.caseStmt.stmt);
12001 if(stmt.compound.context)
12006 Statement prevCompound = curCompound;
12007 Context prevContext = curContext;
12009 if(!stmt.compound.isSwitch)
12010 curCompound = stmt;
12011 curContext = stmt.compound.context;
12013 if(stmt.compound.declarations)
12015 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
12016 ProcessDeclaration(decl, true);
12018 if(stmt.compound.statements)
12020 for(s = stmt.compound.statements->first; s; s = s.next)
12021 ProcessStatement(s);
12024 curContext = prevContext;
12025 curCompound = prevCompound;
12029 case expressionStmt:
12032 if(stmt.expressions)
12034 for(exp = stmt.expressions->first; exp; exp = exp.next)
12035 ProcessExpressionType(exp);
12043 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
12044 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
12045 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
12046 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
12048 ProcessExpressionType(exp);
12050 if(stmt.ifStmt.stmt)
12051 ProcessStatement(stmt.ifStmt.stmt);
12052 if(stmt.ifStmt.elseStmt)
12053 ProcessStatement(stmt.ifStmt.elseStmt);
12058 Type oldSwitchType = curSwitchType;
12059 if(stmt.switchStmt.exp)
12062 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12072 e.exp.destType = destType;
12075 ProcessExpressionType(exp);
12078 curSwitchType = exp.expType;
12081 ProcessStatement(stmt.switchStmt.stmt);
12082 curSwitchType = oldSwitchType;
12087 if(stmt.whileStmt.exp)
12091 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12092 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12093 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12094 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12096 ProcessExpressionType(exp);
12099 if(stmt.whileStmt.stmt)
12100 ProcessStatement(stmt.whileStmt.stmt);
12105 if(stmt.doWhile.exp)
12109 if(stmt.doWhile.exp->last)
12111 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12112 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12113 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12115 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12117 ProcessExpressionType(exp);
12120 if(stmt.doWhile.stmt)
12121 ProcessStatement(stmt.doWhile.stmt);
12127 if(stmt.forStmt.init)
12128 ProcessStatement(stmt.forStmt.init);
12130 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12132 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12133 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12134 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12137 if(stmt.forStmt.check)
12138 ProcessStatement(stmt.forStmt.check);
12139 if(stmt.forStmt.increment)
12141 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12142 ProcessExpressionType(exp);
12145 if(stmt.forStmt.stmt)
12146 ProcessStatement(stmt.forStmt.stmt);
12151 Identifier id = stmt.forEachStmt.id;
12152 OldList * exp = stmt.forEachStmt.exp;
12153 OldList * filter = stmt.forEachStmt.filter;
12154 Statement block = stmt.forEachStmt.stmt;
12155 char iteratorType[1024];
12158 bool isBuiltin = exp && exp->last &&
12159 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12160 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12161 Expression arrayExp;
12162 const char * typeString = null;
12163 int builtinCount = 0;
12165 for(e = exp ? exp->first : null; e; e = e.next)
12169 FreeType(e.destType);
12170 e.destType = ProcessTypeString("Container", false);
12172 if(!isBuiltin || e.next)
12173 ProcessExpressionType(e);
12176 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12177 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12178 eClass_IsDerived(source._class.registered, containerClass)))
12180 Class _class = source ? source._class.registered : null;
12182 Expression expIt = null;
12183 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12184 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12185 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12186 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12190 stmt.type = compoundStmt;
12192 stmt.compound.context = Context { };
12193 stmt.compound.context.parent = curContext;
12194 curContext = stmt.compound.context;
12197 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12199 Class mapClass = eSystem_FindClass(privateModule, "Map");
12200 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12201 isCustomAVLTree = true;
12202 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12204 else */if(eClass_IsDerived(source._class.registered, mapClass))
12207 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12208 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12210 Class listClass = eSystem_FindClass(privateModule, "List");
12212 isList = eClass_IsDerived(source._class.registered, listClass);
12215 if(inCompiler && isArray)
12218 OldList * specs = MkList();
12219 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12220 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12221 stmt.compound.declarations = MkListOne(
12222 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12223 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12224 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12225 MkInitializerAssignment(MkExpBrackets(exp))))));
12230 char typeStringBuf[1024];
12232 // TODO: Merge this code?
12233 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12234 if(((Expression)exp->last).type == castExp)
12236 TypeName typeName = ((Expression)exp->last).cast.typeName;
12238 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12241 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12242 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12243 arrayExp.destType._class.registered.templateArgs)
12245 Class templateClass = arrayExp.destType._class.registered;
12246 typeString = templateClass.templateArgs[2].dataTypeString;
12248 else if(arrayExp.list)
12250 // Guess type from expressions in the array
12252 for(e = arrayExp.list->first; e; e = e.next)
12254 ProcessExpressionType(e);
12257 if(!type) { type = e.expType; type.refCount++; }
12260 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12261 if(!MatchTypeExpression(e, type, null, false, true))
12267 e = arrayExp.list->first;
12268 ProcessExpressionType(e);
12271 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12272 if(!MatchTypeExpression(e, type, null, false, true))
12274 FreeType(e.expType);
12285 FreeType(e.expType);
12292 typeStringBuf[0] = '\0';
12293 PrintType(type, typeStringBuf, false, true);
12294 typeString = typeStringBuf;
12302 OldList * initializers = MkList();
12304 OldList * specs = MkList();
12309 builtinCount = arrayExp.list->count;
12310 type = ProcessTypeString(typeString, false);
12311 while((e = arrayExp.list->first))
12313 arrayExp.list->Remove(e);
12316 ProcessExpressionType(e);
12318 ListAdd(initializers, MkInitializerAssignment(e));
12321 delete arrayExp.list;
12323 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12325 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12326 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12328 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12330 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12331 ), MkInitializerList(initializers)))));
12332 FreeList(exp, FreeExpression);
12334 else if(arrayExp.list)
12337 type = ProcessTypeString(typeString, false);
12338 for(e = arrayExp.list->first; e; e = e.next)
12342 ProcessExpressionType(e);
12349 arrayExp.expType = ProcessTypeString("Container", false);
12350 Compiler_Error($"Couldn't determine type of array elements\n");
12355 OldList * specs = MkList();
12357 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12358 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12359 stmt.compound.declarations = MkListOne(
12360 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12361 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12362 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12363 MkInitializerAssignment(MkExpBrackets(exp))))));
12366 else if(inCompiler && isLinkList && !isList)
12369 OldList * specs = MkList();
12370 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12371 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12372 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12373 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12374 MkInitializerAssignment(MkExpBrackets(exp))))));
12376 /*else if(isCustomAVLTree)
12379 OldList * specs = MkList();
12380 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12381 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12382 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12383 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12384 MkInitializerAssignment(MkExpBrackets(exp))))));
12386 else if(inCompiler && _class.templateArgs)
12389 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12391 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12393 stmt.compound.declarations = MkListOne(
12394 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12395 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12396 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12400 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12404 // Reparent sub-contexts in this statement
12408 if(block.compound.context)
12409 block.compound.context.parent = stmt.compound.context;
12412 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12413 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12414 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12415 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12418 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12419 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12422 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12423 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12426 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12427 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12430 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12431 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12434 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12435 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12437 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12440 case expressionStmt:
12446 case badDeclarationStmt:
12447 case fireWatchersStmt:
12448 case stopWatchingStmt:
12456 block = MkIfStmt(filter, block, null);
12460 stmt.compound.statements = MkListOne(MkForStmt(
12461 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12462 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12463 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12464 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12466 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12467 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12468 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12473 //OldList * specs = MkList();
12474 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12476 sprintf(count, "%d", builtinCount);
12478 stmt.compound.statements = MkListOne(MkForStmt(
12479 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12480 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12481 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12482 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12486 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12487 stmt.compound.statements = MkListOne(MkForStmt(
12488 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12489 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12490 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12491 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12494 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12495 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12496 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12498 else if(isLinkList && !isList)
12500 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12501 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12502 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12503 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12505 stmt.compound.statements = MkListOne(MkForStmt(
12506 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12507 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12508 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12513 OldList * specs = MkList();
12514 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12515 stmt.compound.statements = MkListOne(MkForStmt(
12516 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12517 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12518 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12519 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12520 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12523 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12524 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12525 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12527 /*else if(isCustomAVLTree)
12529 stmt.compound.statements = MkListOne(MkForStmt(
12530 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12531 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12532 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12533 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12536 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12537 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12538 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12542 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12543 MkIdentifier("Next")), null)), block));
12545 ProcessExpressionType(expIt);
12546 if(stmt.compound.declarations->first)
12547 ProcessDeclaration(stmt.compound.declarations->first, true);
12550 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12552 ProcessStatement(stmt);
12555 ProcessStatement(stmt.forEachStmt.stmt);
12557 curContext = stmt.compound.context.parent;
12562 Compiler_Error($"Expression is not a container\n");
12575 if(stmt.expressions)
12577 for(exp = stmt.expressions->first; exp; exp = exp.next)
12581 if(curFunction && !curFunction.type)
12582 curFunction.type = ProcessType(
12583 curFunction.specifiers, curFunction.declarator);
12584 FreeType(exp.destType);
12585 // TODO: current property if not compiling
12586 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12587 if(exp.destType) exp.destType.refCount++;
12589 ProcessExpressionType(exp);
12594 case badDeclarationStmt:
12596 ProcessDeclaration(stmt.decl, true);
12602 if(stmt.asmStmt.inputFields)
12604 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12605 if(field.expression)
12606 ProcessExpressionType(field.expression);
12608 if(stmt.asmStmt.outputFields)
12610 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12611 if(field.expression)
12612 ProcessExpressionType(field.expression);
12614 if(stmt.asmStmt.clobberedFields)
12616 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12618 if(field.expression)
12619 ProcessExpressionType(field.expression);
12626 PropertyWatch propWatch;
12627 OldList * watches = stmt._watch.watches;
12628 Expression object = stmt._watch.object;
12629 Expression watcher = stmt._watch.watcher;
12631 ProcessExpressionType(watcher);
12633 ProcessExpressionType(object);
12637 if(watcher || thisClass)
12639 External external = curExternal;
12640 Context context = curContext;
12642 stmt.type = expressionStmt;
12643 stmt.expressions = MkList();
12645 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12647 ClassFunction func;
12648 char watcherName[1024];
12649 Class watcherClass = watcher ?
12650 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12651 External createdExternal;
12653 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12654 if(propWatch.deleteWatch)
12655 strcat(watcherName, "_delete");
12659 for(propID = propWatch.properties->first; propID; propID = propID.next)
12661 strcat(watcherName, "_");
12662 strcat(watcherName, propID.string);
12666 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12668 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12669 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12670 ProcessClassFunctionBody(func, propWatch.compound);
12671 propWatch.compound = null;
12673 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12675 FreeClassFunction(func);
12677 curExternal = createdExternal;
12678 ProcessFunction(createdExternal.function);
12680 if(propWatch.deleteWatch)
12682 OldList * args = MkList();
12683 ListAdd(args, CopyExpression(object));
12684 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12685 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12686 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12690 Class _class = object.expType._class.registered;
12693 for(propID = propWatch.properties->first; propID; propID = propID.next)
12695 char propName[1024];
12696 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12699 char getName[1024], setName[1024];
12700 OldList * args = MkList();
12702 DeclareProperty(createdExternal, prop, setName, getName);
12704 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12705 strcpy(propName, "__ecereProp_");
12706 FullClassNameCat(propName, prop._class.fullName, false);
12707 strcat(propName, "_");
12708 FullClassNameCat(propName, prop.name, true);
12710 ListAdd(args, CopyExpression(object));
12711 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12712 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12713 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12715 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12717 external.CreateUniqueEdge(createdExternal, true);
12720 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12725 Compiler_Error($"Invalid watched object\n");
12728 curExternal = external;
12729 curContext = context;
12732 FreeExpression(watcher);
12734 FreeExpression(object);
12735 FreeList(watches, FreePropertyWatch);
12738 Compiler_Error($"No observer specified and not inside a class\n");
12742 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12744 ProcessStatement(propWatch.compound);
12750 case fireWatchersStmt:
12752 OldList * watches = stmt._watch.watches;
12753 Expression object = stmt._watch.object;
12755 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12756 // printf("%X\n", watches);
12757 // printf("%X\n", stmt._watch.watches);
12759 ProcessExpressionType(object);
12764 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12770 stmt.type = expressionStmt;
12771 stmt.expressions = MkList();
12773 // Check if we're inside a property set
12774 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12776 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12780 //Compiler_Error($"No property specified and not inside a property set\n");
12784 for(propID = watches->first; propID; propID = propID.next)
12786 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12789 CreateFireWatcher(prop, object, stmt);
12792 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12797 // Fire all properties!
12800 for(base = _class; base; base = base.base)
12802 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12804 if(prop.isProperty && prop.isWatchable)
12806 CreateFireWatcher(prop, object, stmt);
12813 FreeExpression(object);
12814 FreeList(watches, FreeIdentifier);
12817 Compiler_Error($"Invalid object specified and not inside a class\n");
12821 case stopWatchingStmt:
12823 OldList * watches = stmt._watch.watches;
12824 Expression object = stmt._watch.object;
12825 Expression watcher = stmt._watch.watcher;
12828 ProcessExpressionType(object);
12830 ProcessExpressionType(watcher);
12833 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12835 if(watcher || thisClass)
12841 stmt.type = expressionStmt;
12842 stmt.expressions = MkList();
12847 // eInstance_StopWatching(object, null, watcher);
12849 ListAdd(args, CopyExpression(object));
12850 ListAdd(args, MkExpConstant("0"));
12851 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12852 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12856 for(propID = watches->first; propID; propID = propID.next)
12858 char propName[1024];
12859 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12862 char getName[1024], setName[1024];
12863 OldList * args = MkList();
12865 DeclareProperty(curExternal, prop, setName, getName);
12867 // eInstance_StopWatching(object, prop, watcher);
12868 strcpy(propName, "__ecereProp_");
12869 FullClassNameCat(propName, prop._class.fullName, false);
12870 strcat(propName, "_");
12871 FullClassNameCat(propName, prop.name, true);
12873 ListAdd(args, CopyExpression(object));
12874 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12875 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12876 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12879 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12884 FreeExpression(object);
12886 FreeExpression(watcher);
12887 FreeList(watches, FreeIdentifier);
12890 Compiler_Error($"Invalid object specified and not inside a class\n");
12893 Compiler_Error($"No observer specified and not inside a class\n");
12900 static void ProcessFunction(FunctionDefinition function)
12902 Identifier id = GetDeclId(function.declarator);
12903 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12904 Type type = symbol ? symbol.type : null;
12905 Class oldThisClass = thisClass;
12906 Context oldTopContext = topContext;
12908 yylloc = function.loc;
12909 // Process thisClass
12911 if(type && type.thisClass)
12913 Symbol classSym = type.thisClass;
12914 Class _class = type.thisClass.registered;
12915 char className[1024];
12916 char structName[1024];
12917 Declarator funcDecl;
12920 bool typedObject = false;
12922 if(_class && !_class.base)
12924 _class = currentClass;
12925 if(_class && !_class.symbol)
12926 _class.symbol = FindClass(_class.fullName);
12927 classSym = _class ? _class.symbol : null;
12928 typedObject = true;
12931 thisClass = _class;
12933 if(inCompiler && _class)
12935 if(type.kind == functionType)
12937 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12939 //TypeName param = symbol.type.params.first;
12940 Type param = symbol.type.params.first;
12941 symbol.type.params.Remove(param);
12942 //FreeTypeName(param);
12945 if(type.classObjectType != classPointer)
12947 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12948 symbol.type.staticMethod = true;
12949 symbol.type.thisClass = null;
12951 // HIGH DANGER: VERIFYING THIS...
12952 symbol.type.extraParam = false;
12956 strcpy(className, "__ecereClass_");
12957 FullClassNameCat(className, _class.fullName, true);
12960 FullClassNameCat(structName, _class.fullName, false);
12963 funcDecl = GetFuncDecl(function.declarator);
12966 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12968 TypeName param = funcDecl.function.parameters->first;
12969 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12971 funcDecl.function.parameters->Remove(param);
12972 FreeTypeName(param);
12976 if(!function.propertyNoThis)
12978 TypeName thisParam = null;
12980 if(type.classObjectType != classPointer)
12982 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12983 if(!funcDecl.function.parameters)
12984 funcDecl.function.parameters = MkList();
12985 funcDecl.function.parameters->Insert(null, thisParam);
12990 if(type.classObjectType != classPointer)
12992 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12993 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12996 thisParam = TypeName
12998 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12999 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
13001 DeclareStruct(curExternal, "ecere::com::Class", false, true);
13002 funcDecl.function.parameters->Insert(null, thisParam);
13007 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13009 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13010 funcDecl = GetFuncDecl(initDecl.declarator);
13013 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13015 TypeName param = funcDecl.function.parameters->first;
13016 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13018 funcDecl.function.parameters->Remove(param);
13019 FreeTypeName(param);
13023 if(type.classObjectType != classPointer)
13025 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
13027 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13029 if(!funcDecl.function.parameters)
13030 funcDecl.function.parameters = MkList();
13031 funcDecl.function.parameters->Insert(null, thisParam);
13038 // Add this to the context
13041 if(type.classObjectType != classPointer)
13043 thisSymbol = Symbol
13045 string = CopyString("this");
13046 type = classSym ? MkClassType(classSym.string) : null;
13048 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13050 if(typedObject && thisSymbol.type)
13052 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13053 thisSymbol.type.byReference = type.byReference;
13054 thisSymbol.type.typedByReference = type.byReference;
13059 // Pointer to class data
13060 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
13062 DataMember member = null;
13065 for(base = _class; base && base.type != systemClass; base = base.next)
13067 for(member = base.membersAndProperties.first; member; member = member.next)
13068 if(!member.isProperty)
13074 for(member = _class.membersAndProperties.first; member; member = member.next)
13075 if(!member.isProperty)
13079 char pointerName[1024];
13082 Initializer initializer;
13083 Expression exp, bytePtr;
13085 strcpy(pointerName, "__ecerePointer_");
13086 FullClassNameCat(pointerName, _class.fullName, false);
13088 char className[1024];
13089 strcpy(className, "__ecereClass_");
13090 FullClassNameCat(className, classSym.string, true);
13092 DeclareClass(curExternal, classSym, className);
13096 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13101 if(_class.offset && _class.offset == _class.base.structSize)
13103 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
13104 ProcessExpressionType(e);
13109 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
13110 e = MkExpConstant(string);
13112 exp = QBrackets(MkExpOp(bytePtr, '+', e));
13116 // ([bytePtr] + [className]->offset)
13117 exp = QBrackets(MkExpOp(bytePtr, '+',
13118 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13121 // (this ? [exp] : 0)
13122 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13126 kind = pointerType;
13127 type = Type { refCount = 1, kind = voidType };
13132 yylloc = function.body.loc;
13133 // ([structName] *) [exp]
13134 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13135 initializer = MkInitializerAssignment(
13136 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13138 // [structName] * [pointerName] = [initializer];
13139 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13142 Context prevContext = curContext;
13144 curContext = function.body.compound.context;
13146 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13147 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13148 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13150 curContext = prevContext;
13154 decl.symbol = null;
13156 if(!function.body.compound.declarations)
13157 function.body.compound.declarations = MkList();
13158 function.body.compound.declarations->Insert(null, decl);
13164 // Loop through the function and replace undeclared identifiers
13165 // which are a member of the class (methods, properties or data)
13166 // by "this.[member]"
13173 FreeSpecifier(id._class);
13176 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13178 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13179 id = GetDeclId(initDecl.declarator);
13181 FreeSpecifier(id._class);
13186 topContext = function.body.compound.context;
13188 FunctionDefinition oldFunction = curFunction;
13189 curFunction = function;
13191 ProcessStatement(function.body);
13193 // If this is a property set and no firewatchers has been done yet, add one here
13194 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13196 Statement prevCompound = curCompound;
13197 Context prevContext = curContext;
13199 Statement fireWatchers = MkFireWatchersStmt(null, null);
13200 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13201 ListAdd(function.body.compound.statements, fireWatchers);
13203 curCompound = function.body;
13204 curContext = function.body.compound.context;
13206 ProcessStatement(fireWatchers);
13208 curContext = prevContext;
13209 curCompound = prevCompound;
13213 curFunction = oldFunction;
13216 if(function.declarator)
13218 ProcessDeclarator(function.declarator, true);
13221 topContext = oldTopContext;
13222 thisClass = oldThisClass;
13225 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13226 static void ProcessClass(OldList definitions, Symbol symbol)
13229 External external = curExternal;
13230 Class regClass = symbol ? symbol.registered : null;
13232 // Process all functions
13233 for(def = definitions.first; def; def = def.next)
13235 if(def.type == functionClassDef)
13237 if(def.function.declarator)
13238 curExternal = def.function.declarator.symbol.pointerExternal;
13240 curExternal = external;
13242 ProcessFunction((FunctionDefinition)def.function);
13244 else if(def.type == declarationClassDef)
13246 if(def.decl.type == instDeclaration)
13248 thisClass = regClass;
13249 ProcessInstantiationType(def.decl.inst);
13255 Class backThisClass = thisClass;
13256 if(regClass) thisClass = regClass;
13257 ProcessDeclaration(def.decl, symbol ? true : false);
13258 thisClass = backThisClass;
13261 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13263 MemberInit defProperty;
13265 // Add this to the context
13266 Symbol thisSymbol = Symbol
13268 string = CopyString("this");
13269 type = regClass ? MkClassType(regClass.fullName) : null;
13271 globalContext.symbols.Add((BTNode)thisSymbol);
13273 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13275 thisClass = regClass;
13276 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13280 globalContext.symbols.Remove((BTNode)thisSymbol);
13281 FreeSymbol(thisSymbol);
13283 else if(def.type == propertyClassDef && def.propertyDef)
13285 PropertyDef prop = def.propertyDef;
13287 // Add this to the context
13288 thisClass = regClass;
13295 string = CopyString("this");
13296 type = MkClassType(regClass.fullName);
13298 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13301 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13302 ProcessStatement(prop.setStmt);
13310 string = CopyString("this");
13311 type = MkClassType(regClass.fullName);
13313 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13316 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13317 ProcessStatement(prop.getStmt);
13325 string = CopyString("this");
13326 type = MkClassType(regClass.fullName);
13328 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13331 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13332 ProcessStatement(prop.issetStmt);
13337 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13339 PropertyWatch propertyWatch = def.propertyWatch;
13341 thisClass = regClass;
13342 if(propertyWatch.compound)
13346 string = CopyString("this");
13347 type = regClass ? MkClassType(regClass.fullName) : null;
13350 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13352 curExternal = null;
13353 ProcessStatement(propertyWatch.compound);
13360 void DeclareFunctionUtil(External neededBy, const String s)
13362 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13367 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13368 strcpy(name, "__ecereFunction_");
13369 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13370 DeclareFunction(neededBy, function, name);
13373 FindSymbol(s, globalContext, globalContext, false, false);
13376 bool reachedPass15;
13378 void ComputeDataTypes()
13382 currentClass = null;
13384 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13386 DeclareStruct(null, "ecere::com::Class", false, true);
13387 DeclareStruct(null, "ecere::com::Instance", false, true);
13388 DeclareStruct(null, "ecere::com::Property", false, true);
13389 DeclareStruct(null, "ecere::com::DataMember", false, true);
13390 DeclareStruct(null, "ecere::com::Method", false, true);
13391 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13392 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13394 DeclareFunctionUtil(null, "eSystem_New");
13395 DeclareFunctionUtil(null, "eSystem_New0");
13396 DeclareFunctionUtil(null, "eSystem_Renew");
13397 DeclareFunctionUtil(null, "eSystem_Renew0");
13398 DeclareFunctionUtil(null, "eSystem_Delete");
13399 DeclareFunctionUtil(null, "eClass_GetProperty");
13400 DeclareFunctionUtil(null, "eClass_SetProperty");
13401 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13402 DeclareFunctionUtil(null, "eInstance_SetMethod");
13403 DeclareFunctionUtil(null, "eInstance_IncRef");
13404 DeclareFunctionUtil(null, "eInstance_StopWatching");
13405 DeclareFunctionUtil(null, "eInstance_Watch");
13406 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13407 reachedPass15 = true;
13409 for(external = ast->first; external; external = external.next)
13411 afterExternal = curExternal = external;
13412 if(external.type == functionExternal)
13416 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13417 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13420 currentClass = external.function._class;
13421 ProcessFunction(external.function);
13423 // There shouldn't be any _class member access here anyways...
13424 else if(external.type == declarationExternal)
13426 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13428 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13429 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13432 currentClass = null;
13433 if(external.declaration)
13434 ProcessDeclaration(external.declaration, true);
13436 else if(external.type == classExternal)
13438 ClassDefinition _class = external._class;
13439 currentClass = external.symbol.registered;
13442 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13443 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13445 if(_class.definitions)
13447 ProcessClass(_class.definitions, _class.symbol);
13451 // Free class data...
13452 ast->Remove(external);
13456 else if(external.type == nameSpaceExternal)
13458 thisNameSpace = external.id.string;
13461 currentClass = null;
13462 thisNameSpace = null;
13463 curExternal = null;