3 // UNTIL IMPLEMENTED IN GRAMMAR
4 #define ACCESS_CLASSDATA(_class, baseClass) \
5 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
7 #define YYLTYPE Location
11 extern int returnCode;
12 extern Expression parsedExpression;
14 public void SetYydebug(bool b) { yydebug = b; }
19 // TODO: Reset this to 0 on reinitialization
22 int expression_yyparse();
23 static Statement curCompound;
24 External curExternal, afterExternal;
25 static Type curSwitchType;
26 static Class currentClass;
28 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
29 static char * thisNameSpace;
30 /*static */Class containerClass;
31 bool thisClassParams = true;
33 uint internalValueCounter;
36 Time findSymbolTotalTime;
39 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
40 /*static */public void PrintExpression(Expression exp, char * string)
46 bool backOutputLineNumbers = outputLineNumbers;
47 outputLineNumbers = false;
50 OutputExpression(exp, f);
52 count = strlen(string);
53 count += f.Read(string + count, 1, 1023);
57 outputLineNumbers = backOutputLineNumbers;
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind && type1.isLong == type2.isLong)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
106 return true; //false; ????
112 static void ReplaceClassMembers(Expression exp, Class _class)
114 if(exp.type == identifierExp && exp.identifier)
116 Identifier id = exp.identifier;
118 Symbol symbol = null;
119 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
121 // First, check if the identifier is declared inside the function
122 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
124 symbol = (Symbol)ctx.symbols.FindString(id.string);
129 // If it is not, check if it is a member of the _class
130 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
132 Property prop = eClass_FindProperty(_class, id.string, privateModule);
133 Method method = null;
134 DataMember member = null;
135 ClassProperty classProp = null;
138 method = eClass_FindMethod(_class, id.string, privateModule);
141 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
142 if(!prop && !method && !member)
144 classProp = eClass_FindClassProperty(_class, id.string);
146 if(prop || method || member || classProp)
148 // Replace by this.[member]
149 exp.type = memberExp;
150 exp.member.member = id;
151 exp.member.memberType = unresolvedMember;
152 exp.member.exp = QMkExpId("this");
153 //exp.member.exp.loc = exp.loc;
154 exp.addedThis = true;
156 else if(_class && _class.templateParams.first)
159 for(sClass = _class; sClass; sClass = sClass.base)
161 if(sClass.templateParams.first)
163 ClassTemplateParameter param;
164 for(param = sClass.templateParams.first; param; param = param.next)
166 if(param.type == expression && !strcmp(param.name, id.string))
168 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
173 OldList * specs = MkList();
175 FreeIdentifier(exp.member.member);
177 ProcessExpressionType(argExp);
179 decl = SpecDeclFromString(param.dataTypeString, specs, null);
181 exp.expType = ProcessType(specs, decl);
183 // *[expType] *[argExp]
184 exp.type = bracketsExp;
185 exp.list = MkListOne(MkExpOp(null, '*',
186 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
197 ////////////////////////////////////////////////////////////////////////
198 // PRINTING ////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////
201 public char * PrintInt(int64 result)
205 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
207 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
208 if(result > MAXINT || result < MININT)
210 return CopyString(temp);
213 public char * PrintUInt(uint64 result)
216 if(result > MAXDWORD)
217 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
218 else if(result > MAXINT)
219 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
221 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
222 return CopyString(temp);
225 public char * PrintInt64(int64 result)
228 if(result > MAXINT || result < MININT)
229 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
231 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
232 return CopyString(temp);
235 public char * PrintUInt64(uint64 result)
238 if(result > MAXDWORD)
239 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
240 else if(result > MAXINT)
241 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
243 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
244 return CopyString(temp);
247 public char * PrintHexUInt(uint64 result)
250 if(result > MAXDWORD)
251 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
253 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
254 if(result > MAXDWORD)
256 return CopyString(temp);
259 public char * PrintHexUInt64(uint64 result)
262 if(result > MAXDWORD)
263 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
265 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
266 return CopyString(temp);
269 public char * PrintShort(short result)
272 sprintf(temp, "%d", (unsigned short)result);
273 return CopyString(temp);
276 public char * PrintUShort(unsigned short result)
280 sprintf(temp, "0x%X", (int)result);
282 sprintf(temp, "%d", (int)result);
283 return CopyString(temp);
286 public char * PrintChar(char result)
289 if(result > 0 && isprint(result))
290 sprintf(temp, "'%c'", result);
292 sprintf(temp, "%d", (int)result);
294 //sprintf(temp, "%#X", result);
295 sprintf(temp, "0x%X", (unsigned char)result);
296 return CopyString(temp);
299 public char * PrintUChar(unsigned char result)
302 sprintf(temp, "0x%X", result);
303 return CopyString(temp);
306 public char * PrintFloat(float result)
312 strcpy(temp, "-inf");
316 else if(result.isNan)
319 strcpy(temp, "-nan");
324 sprintf(temp, "%.16ff", result);
325 return CopyString(temp);
328 public char * PrintDouble(double result)
334 strcpy(temp, "-inf");
338 else if(result.isNan)
341 strcpy(temp, "-nan");
346 sprintf(temp, "%.16f", result);
347 return CopyString(temp);
350 ////////////////////////////////////////////////////////////////////////
351 ////////////////////////////////////////////////////////////////////////
353 //public Operand GetOperand(Expression exp);
355 #define GETVALUE(name, t) \
356 public bool GetOp##name(Operand op2, t * value2) \
358 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
359 else if(op2.kind == intType) *value2 = (t) op2.ui; \
360 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
361 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
362 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
363 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
364 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
365 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
366 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
367 else if(op2.kind == shortType) *value2 = (t) op2.us; \
368 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
369 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
370 else if(op2.kind == floatType) *value2 = (t) op2.f; \
371 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
372 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
377 public bool Get##name(Expression exp, t * value2) \
379 Operand op2 = GetOperand(exp); \
380 return GetOp##name(op2, value2); \
383 // To help the debugger currently not preprocessing...
386 GETVALUE(Int, HELP(int));
387 GETVALUE(UInt, HELP(unsigned int));
388 GETVALUE(Int64, HELP(int64));
389 GETVALUE(UInt64, HELP(uint64));
390 GETVALUE(IntPtr, HELP(intptr));
391 GETVALUE(UIntPtr, HELP(uintptr));
392 GETVALUE(IntSize, HELP(intsize));
393 GETVALUE(UIntSize, HELP(uintsize));
394 GETVALUE(Short, HELP(short));
395 GETVALUE(UShort, HELP(unsigned short));
396 GETVALUE(Char, HELP(char));
397 GETVALUE(UChar, HELP(unsigned char));
398 GETVALUE(Float, HELP(float));
399 GETVALUE(Double, HELP(double));
401 void ComputeExpression(Expression exp);
403 void ComputeClassMembers(Class _class, bool isMember)
405 DataMember member = isMember ? (DataMember) _class : null;
406 Context context = isMember ? null : SetupTemplatesContext(_class);
407 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
408 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
410 int unionMemberOffset = 0;
414 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
415 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
420 member.memberOffset = 0;
421 if(targetBits < sizeof(void *) * 8)
422 member.structAlignment = 0;
424 else if(targetBits < sizeof(void *) * 8)
425 _class.structAlignment = 0;
427 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
428 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
429 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
431 if(!member && _class.destructionWatchOffset)
432 _class.memberOffset += sizeof(OldList);
434 // To avoid reentrancy...
435 //_class.structSize = -1;
438 DataMember dataMember;
439 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
441 if(!dataMember.isProperty)
443 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
445 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
446 /*if(!dataMember.dataType)
447 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
455 DataMember dataMember;
456 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
458 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
460 if(!isMember && _class.type == bitClass && dataMember.dataType)
462 BitMember bitMember = (BitMember) dataMember;
466 ComputeTypeSize(dataMember.dataType);
468 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
469 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
471 _class.memberOffset = bitMember.pos + bitMember.size;
472 for(d = 0; d<bitMember.size; d++)
478 bitMember.mask = mask << bitMember.pos;
480 else if(dataMember.type == normalMember && dataMember.dataType)
485 // Prevent infinite recursion
486 if(dataMember.dataType.kind != classType ||
487 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
488 _class.type != structClass)))
489 ComputeTypeSize(dataMember.dataType);
491 if(dataMember.dataType.bitFieldCount)
493 bitFields += dataMember.dataType.bitFieldCount;
500 int size = (bitFields + 7) / 8;
504 // TESTING THIS PADDING CODE
507 member.structAlignment = Max(member.structAlignment, alignment);
509 if(member.memberOffset % alignment)
510 member.memberOffset += alignment - (member.memberOffset % alignment);
513 dataMember.offset = member.memberOffset;
514 if(member.type == unionMember)
515 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
518 member.memberOffset += size;
523 // TESTING THIS PADDING CODE
526 _class.structAlignment = Max(_class.structAlignment, alignment);
528 if(_class.memberOffset % alignment)
529 _class.memberOffset += alignment - (_class.memberOffset % alignment);
532 dataMember.offset = _class.memberOffset;
533 _class.memberOffset += size;
537 size = dataMember.dataType.size;
538 alignment = dataMember.dataType.alignment;
543 // TESTING THIS PADDING CODE
546 member.structAlignment = Max(member.structAlignment, alignment);
548 if(member.memberOffset % alignment)
549 member.memberOffset += alignment - (member.memberOffset % alignment);
552 dataMember.offset = member.memberOffset;
553 if(member.type == unionMember)
554 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
557 member.memberOffset += size;
562 // TESTING THIS PADDING CODE
565 _class.structAlignment = Max(_class.structAlignment, alignment);
567 if(_class.memberOffset % alignment)
568 _class.memberOffset += alignment - (_class.memberOffset % alignment);
571 dataMember.offset = _class.memberOffset;
572 _class.memberOffset += size;
579 ComputeClassMembers((Class)dataMember, true);
580 alignment = dataMember.structAlignment;
586 if(member.memberOffset % alignment)
587 member.memberOffset += alignment - (member.memberOffset % alignment);
589 member.structAlignment = Max(member.structAlignment, alignment);
591 dataMember.offset = member.memberOffset;
592 if(member.type == unionMember)
593 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
595 member.memberOffset += dataMember.memberOffset;
601 if(_class.memberOffset % alignment)
602 _class.memberOffset += alignment - (_class.memberOffset % alignment);
603 _class.structAlignment = Max(_class.structAlignment, alignment);
605 dataMember.offset = _class.memberOffset;
606 _class.memberOffset += dataMember.memberOffset;
614 int size = (bitFields + 7) / 8;
618 // TESTING THIS PADDING CODE
621 member.structAlignment = Max(member.structAlignment, alignment);
623 if(member.memberOffset % alignment)
624 member.memberOffset += alignment - (member.memberOffset % alignment);
627 if(member.type == unionMember)
628 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
631 member.memberOffset += size;
636 // TESTING THIS PADDING CODE
639 _class.structAlignment = Max(_class.structAlignment, alignment);
641 if(_class.memberOffset % alignment)
642 _class.memberOffset += alignment - (_class.memberOffset % alignment);
644 _class.memberOffset += size;
649 if(member && member.type == unionMember)
651 member.memberOffset = unionMemberOffset;
656 /*if(_class.type == structClass)
657 _class.size = _class.memberOffset;
661 if(_class.type != bitClass)
664 if(_class.structAlignment)
666 if(_class.memberOffset % _class.structAlignment)
667 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
669 _class.structSize = (_class.base ? (_class.base.templateClass ?
670 (_class.base.type == noHeadClass ? _class.base.templateClass.memberOffset : _class.base.templateClass.structSize) :
671 (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize) ) : 0) + _class.memberOffset + extra;
675 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
677 if(prop.isProperty && prop.isWatchable)
679 prop.watcherOffset = _class.structSize;
680 _class.structSize += sizeof(OldList);
688 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
690 Class deriv = derivative.data;
692 if(deriv.computeSize)
694 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
695 deriv.offset = /*_class.offset + */(_class.type == noHeadClass ? _class.memberOffset : _class.structSize);
696 deriv.memberOffset = 0;
697 // ----------------------
699 deriv.structSize = deriv.offset;
701 ComputeClassMembers(deriv, false);
709 FinishTemplatesContext(context);
712 public void ComputeModuleClasses(Module module)
717 for(subModule = module.modules.first; subModule; subModule = subModule.next)
718 ComputeModuleClasses(subModule.data);
719 for(_class = module.classes.first; _class; _class = _class.next)
720 ComputeClassMembers(_class, false);
724 public int ComputeTypeSize(Type type)
726 uint size = type ? type.size : 0;
727 if(!size && type && !type.computing)
729 type.computing = true;
732 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
733 case charType: type.alignment = size = sizeof(char); break;
734 case intType: type.alignment = size = sizeof(int); break;
735 case int64Type: type.alignment = size = sizeof(int64); break;
736 case intPtrType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
737 case intSizeType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
738 case longType: type.alignment = size = sizeof(long); break;
739 case shortType: type.alignment = size = sizeof(short); break;
740 case floatType: type.alignment = size = sizeof(float); break;
741 case doubleType: type.alignment = size = sizeof(double); break;
744 Class _class = type._class ? type._class.registered : null;
746 if(_class && _class.type == structClass)
748 // Ensure all members are properly registered
749 ComputeClassMembers(_class, false);
750 type.alignment = _class.structAlignment;
751 type.pointerAlignment = (bool)_class.pointerAlignment;
752 size = _class.structSize;
753 if(type.alignment && size % type.alignment)
754 size += type.alignment - (size % type.alignment);
757 else if(_class && (_class.type == unitClass ||
758 _class.type == enumClass ||
759 _class.type == bitClass))
762 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
763 size = type.alignment = ComputeTypeSize(_class.dataType);
767 size = type.alignment = targetBits / 8; // sizeof(Instance *);
768 type.pointerAlignment = true;
772 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */ type.pointerAlignment = true; break;
774 if(type.arraySizeExp)
776 ProcessExpressionType(type.arraySizeExp);
777 ComputeExpression(type.arraySizeExp);
778 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
779 type.arraySizeExp.expType.kind != shortType &&
780 type.arraySizeExp.expType.kind != charType &&
781 type.arraySizeExp.expType.kind != longType &&
782 type.arraySizeExp.expType.kind != int64Type &&
783 type.arraySizeExp.expType.kind != intSizeType &&
784 type.arraySizeExp.expType.kind != intPtrType &&
785 type.arraySizeExp.expType.kind != enumType &&
786 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
788 Location oldLoc = yylloc;
789 // bool isConstant = type.arraySizeExp.isConstant;
790 char expression[10240];
791 expression[0] = '\0';
792 type.arraySizeExp.expType = null;
793 yylloc = type.arraySizeExp.loc;
795 PrintExpression(type.arraySizeExp, expression);
796 Compiler_Error($"Array size not constant int (%s)\n", expression);
799 GetInt(type.arraySizeExp, &type.arraySize);
801 else if(type.enumClass)
803 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
805 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
812 // Unimplemented auto size
816 size = ComputeTypeSize(type.type) * type.arraySize;
819 type.alignment = type.type.alignment;
820 type.pointerAlignment = type.type.pointerAlignment;
826 if(!type.members.first && type.enumName)
828 Symbol symbol = FindStruct(curContext, type.enumName);
829 if(symbol && symbol.type)
831 ComputeTypeSize(symbol.type);
832 size = symbol.type.size;
838 for(member = type.members.first; member; member = member.next)
840 uint addSize = ComputeTypeSize(member);
842 member.offset = size;
843 if(member.alignment && size % member.alignment)
844 member.offset += member.alignment - (size % member.alignment);
845 size = member.offset;
847 if(member.pointerAlignment && type.size <= 4)
848 type.pointerAlignment = true;
849 else if(!member.pointerAlignment && member.alignment >= 8)
850 type.pointerAlignment = false;
852 type.alignment = Max(type.alignment, member.alignment);
855 if(type.alignment && size % type.alignment)
856 size += type.alignment - (size % type.alignment);
862 if(!type.members.first && type.enumName)
864 Symbol symbol = FindStruct(curContext, type.enumName);
865 if(symbol && symbol.type)
867 ComputeTypeSize(symbol.type);
868 size = symbol.type.size;
869 type.alignment = symbol.type.alignment;
875 for(member = type.members.first; member; member = member.next)
877 uint addSize = ComputeTypeSize(member);
879 member.offset = size;
880 if(member.alignment && size % member.alignment)
881 member.offset += member.alignment - (size % member.alignment);
882 size = member.offset;
884 if(member.pointerAlignment && type.size <= 4)
885 type.pointerAlignment = true;
886 else if(!member.pointerAlignment && member.alignment >= 8)
887 type.pointerAlignment = false;
889 type.alignment = Max(type.alignment, member.alignment);
891 size = Max(size, addSize);
893 if(type.alignment && size % type.alignment)
894 size += type.alignment - (size % type.alignment);
900 TemplateParameter param = type.templateParameter;
901 Type baseType = ProcessTemplateParameterType(param);
904 size = ComputeTypeSize(baseType);
905 type.alignment = baseType.alignment;
906 type.pointerAlignment = baseType.pointerAlignment;
909 type.alignment = size = sizeof(uint64);
914 type.alignment = size = sizeof(enum { test });
919 type.alignment = size = targetBits / 8; //sizeof(void *);
920 type.pointerAlignment = true;
925 type.computing = false;
931 /*static */int AddMembers(External neededBy, OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
933 // This function is in need of a major review when implementing private members etc.
934 DataMember topMember = isMember ? (DataMember) _class : null;
941 Context context = isMember ? null : SetupTemplatesContext(_class);
943 *addedPadding = false;
945 if(!isMember && _class.base)
947 maxSize = _class.structSize;
948 //if(_class.base.type != systemClass) // Commented out with new Instance _class
950 // DANGER: Testing this noHeadClass here...
951 if(_class.type == structClass || _class.type == noHeadClass)
952 /*totalSize = */AddMembers(neededBy, declarations, _class.base, false, &totalSize, topClass, null);
955 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
956 if(maxSize > baseSize)
964 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
966 if(!member.isProperty)
972 if(member.dataTypeString)
974 OldList * specs = MkList(), * decls = MkList();
977 decl = SpecDeclFromString(member.dataTypeString, specs,
978 MkDeclaratorIdentifier(MkIdentifier(member.name)));
979 ListAdd(decls, MkStructDeclarator(decl, null));
980 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
983 member.dataType = ProcessType(specs, decl);
985 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
988 Type type = ProcessType(specs, decl);
989 DeclareType(neededBy, member.dataType, true, false);
993 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
994 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
995 DeclareStruct(member.dataType._class.string, false);
998 ComputeTypeSize(member.dataType);
999 size = member.dataType.size;
1000 alignment = member.dataType.alignment;
1004 if(totalSize % alignment)
1005 totalSize += alignment - (totalSize % alignment);
1014 OldList * specs = MkList(), * list = MkList();
1016 sprintf(id, "__anon%d", anonID++);
1019 AddMembers(neededBy, list, (Class)member, true, &size, topClass, null);
1021 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1022 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1023 alignment = member.structAlignment;
1027 if(totalSize % alignment)
1028 totalSize += alignment - (totalSize % alignment);
1038 if(topMember && topMember.type == unionMember)
1039 *retSize = Max(*retSize, totalSize);
1041 *retSize += totalSize;
1043 else if(totalSize < maxSize && _class.type != systemClass)
1045 int autoPadding = 0;
1046 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1047 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1048 if(totalSize + autoPadding < maxSize)
1050 char sizeString[50];
1051 sprintf(sizeString, "%d", maxSize - totalSize);
1052 ListAdd(declarations,
1053 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1054 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1056 *addedPadding = true;
1060 FinishTemplatesContext(context);
1061 return topMember ? topMember.memberID : _class.memberID;
1064 static int DeclareMembers(External neededBy, Class _class, bool isMember)
1066 DataMember topMember = isMember ? (DataMember) _class : null;
1068 Context context = isMember ? null : SetupTemplatesContext(_class);
1070 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1071 DeclareMembers(neededBy, _class.base, false);
1073 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1075 if(!member.isProperty)
1081 if(!member.dataType && member.dataTypeString)
1082 member.dataType = ProcessTypeString(member.dataTypeString, false);
1084 DeclareType(neededBy, member.dataType, true, false);
1090 DeclareMembers(neededBy, (Class)member, true);
1097 FinishTemplatesContext(context);
1099 return topMember ? topMember.memberID : _class.memberID;
1102 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1106 for(def = definitions->first; def; def = def.next)
1108 if(def.type == declarationClassDef)
1110 Declaration decl = def.decl;
1111 if(decl && decl.specifiers)
1114 bool isStruct = false;
1115 for(spec = decl.specifiers->first; spec; spec = spec.next)
1117 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1119 if(spec.definitions)
1120 IdentifyAnonStructs(spec.definitions);
1126 Declarator d = null;
1127 if(decl.declarators)
1129 for(d = decl.declarators->first; d; d = d.next)
1131 Identifier idDecl = GetDeclId(d);
1139 sprintf(id, "__anon%d", anonID++);
1140 if(!decl.declarators)
1141 decl.declarators = MkList();
1142 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1150 External DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference)
1152 return _DeclareStruct(neededBy, name, skipNoHead, needDereference, false);
1155 External _DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference, bool fwdDecl)
1157 External external = null;
1158 Symbol classSym = FindClass(name);
1159 OldList * curDeclarations = null;
1161 if(!inCompiler || !classSym) return null;
1163 // We don't need any declaration for bit classes...
1164 if(classSym.registered &&
1165 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1168 if(!classSym.registered || (classSym.registered.type == normalClass && classSym.registered.structSize && classSym.registered.base && classSym.registered.base.base))
1169 _DeclareStruct(neededBy, "ecere::com::Instance", false, true, fwdDecl);
1171 external = classSym.structExternal;
1173 if(external && external.declaration)
1176 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1177 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1179 curDeclarations = spec.definitions;
1184 if(classSym.registered && !classSym.declaring && classSym.imported && (!classSym.declaredStructSym || (classSym.registered.type == noHeadClass && !skipNoHead && external && !curDeclarations)))
1186 OldList * specifiers, * declarators;
1187 OldList * declarations = null;
1188 char structName[1024];
1189 bool addedPadding = false;
1190 Specifier curSpec = null;
1192 classSym.declaring++;
1194 if(strchr(classSym.string, '<'))
1196 if(classSym.registered.templateClass)
1197 external = _DeclareStruct(neededBy, classSym.registered.templateClass.fullName, skipNoHead, needDereference, fwdDecl);
1198 classSym.declaring--;
1203 FullClassNameCat(structName, name, false);
1205 classSym.declaredStructSym = true;
1206 if(!external || (classSym.registered.type == noHeadClass && !skipNoHead && !curDeclarations))
1211 external = MkExternalDeclaration(null);
1212 classSym.structExternal = external;
1213 external.symbol = classSym;
1220 declarations = MkList();
1221 AddMembers(external, declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1224 if(external.declaration)
1227 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1228 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1231 curDeclarations = spec.definitions;
1236 if(declarations && (!declarations->count || (declarations->count == 1 && addedPadding)))
1238 FreeList(declarations, FreeClassDef);
1239 declarations = null;
1242 if(classSym.registered.type != noHeadClass && !declarations)
1244 FreeExternal(external);
1246 classSym.structExternal = null;
1251 curSpec.definitions = declarations;
1254 specifiers = MkList();
1255 declarators = MkList();
1256 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1257 external.declaration = MkDeclaration(specifiers, declarators);
1263 classSym.declaring--;
1265 else if(!classSym.declaredStructSym && classSym.structExternal)
1267 classSym.declaredStructSym = true;
1269 if(classSym.registered)
1270 DeclareMembers(classSym.structExternal, classSym.registered, false);
1272 if(classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1275 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1277 if(spec.definitions)
1278 IdentifyAnonStructs(spec.definitions);
1282 if(inCompiler && neededBy && (external || !classSym.imported))
1286 classSym.structExternal = external = MkExternalDeclaration(null);
1287 external.symbol = classSym;
1290 if(reachedPass15 && !external.declaration && classSym.registered && classSym.registered.type == noHeadClass)
1292 // Declare nohead classes without definitions here (e.g. IteratorPointer)
1293 char structName[1024];
1294 OldList * specifiers, * declarators;
1296 FullClassNameCat(structName, name, false);
1297 specifiers = MkList();
1298 declarators = MkList();
1299 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), null));
1300 external.declaration = MkDeclaration(specifiers, declarators);
1304 External e = external.fwdDecl ? external.fwdDecl : external;
1305 if(e.incoming.count)
1306 neededBy.CreateUniqueEdge(e, !needDereference && !external.fwdDecl);
1309 neededBy.CreateUniqueEdge(external, !needDereference);
1314 void DeclareProperty(External neededBy, Property prop, char * setName, char * getName)
1316 Symbol symbol = prop.symbol;
1317 bool imported = false;
1318 bool dllImport = false;
1319 External structExternal = null;
1320 External instExternal = null;
1322 strcpy(setName, "__ecereProp_");
1323 FullClassNameCat(setName, prop._class.fullName, false);
1324 strcat(setName, "_Set_");
1325 FullClassNameCat(setName, prop.name, true);
1327 strcpy(getName, "__ecereProp_");
1328 FullClassNameCat(getName, prop._class.fullName, false);
1329 strcat(getName, "_Get_");
1330 FullClassNameCat(getName, prop.name, true);
1332 if(!symbol || symbol._import)
1338 if(!prop._class.symbol)
1339 prop._class.symbol = FindClass(prop._class.fullName);
1340 classSym = prop._class.symbol;
1341 if(classSym && !classSym._import)
1343 ModuleImport module;
1345 if(prop._class.module)
1346 module = FindModule(prop._class.module);
1348 module = mainModule;
1350 classSym._import = ClassImport
1352 name = CopyString(prop._class.fullName);
1353 isRemote = prop._class.isRemote;
1355 module.classes.Add(classSym._import);
1357 symbol = prop.symbol = Symbol { };
1358 symbol._import = (ClassImport)PropertyImport
1360 name = CopyString(prop.name);
1361 isVirtual = false; //prop.isVirtual;
1362 hasSet = prop.Set ? true : false;
1363 hasGet = prop.Get ? true : false;
1366 classSym._import.properties.Add(symbol._import);
1369 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1370 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1371 prop._class.module.importType != staticImport)
1377 Context context = SetupTemplatesContext(prop._class);
1378 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1379 FinishTemplatesContext(context);
1382 if((prop.Get && !symbol.externalGet) || (prop.Set && !symbol.externalSet))
1384 if(prop._class.type == normalClass && prop._class.structSize)
1385 instExternal = DeclareStruct(null, "ecere::com::Instance", false, true);
1386 structExternal = DeclareStruct(null, prop._class.fullName, prop._class.type != structClass /*true*/, false);
1390 if(prop.Get && !symbol.externalGet)
1393 OldList * specifiers, * declarators;
1396 Specifier spec = null;
1398 Declarator typeDecl;
1399 bool simple = false;
1402 specifiers = MkList();
1403 declarators = MkList();
1406 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1407 MkDeclaratorIdentifier(MkIdentifier("this"))));
1409 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1412 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1415 Context context = SetupTemplatesContext(prop._class);
1416 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1417 FinishTemplatesContext(context);
1420 // Make sure the simple _class's type is declared
1421 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1422 for(spec = specifiers->first; spec; spec = spec.next)
1424 if(spec.type == nameSpecifier)
1426 Symbol classSym = spec.symbol;
1429 symbol._class = classSym.registered;
1430 if(classSym.registered && classSym.registered.type == structClass)
1438 d = PlugDeclarator(typeDecl, d);
1441 ListAdd(params, MkTypeName(specifiers,
1442 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1443 specifiers = MkList();
1446 d = MkDeclaratorFunction(d, params);
1450 specifiers->Insert(null, MkSpecifier(EXTERN));
1451 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1452 specifiers->Insert(null, MkSpecifier(STATIC));
1454 ListAdd(specifiers, MkSpecifier(VOID));
1456 ListAdd(declarators, MkInitDeclarator(d, null));
1458 decl = MkDeclaration(specifiers, declarators);
1460 external = MkExternalDeclaration(decl);
1463 external.CreateEdge(structExternal, false);
1465 external.CreateEdge(instExternal, false);
1468 DeclareStruct(external, spec.name, false, needReference);
1471 external.symbol = symbol;
1472 symbol.externalGet = external;
1474 ReplaceThisClassSpecifiers(specifiers, prop._class);
1477 FreeDeclarator(typeDecl);
1481 if(prop.Set && !symbol.externalSet)
1484 OldList * specifiers, * declarators;
1487 Specifier spec = null;
1489 Declarator typeDecl;
1492 declarators = MkList();
1495 if(!prop.conversion || prop._class.type == structClass)
1497 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1498 MkDeclaratorIdentifier(MkIdentifier("this"))));
1501 specifiers = MkList();
1504 Context context = SetupTemplatesContext(prop._class);
1505 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1506 MkDeclaratorIdentifier(MkIdentifier("value")));
1507 FinishTemplatesContext(context);
1509 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1510 specifiers->Insert(null, MkSpecifier(CONST));
1512 ListAdd(params, MkTypeName(specifiers, d));
1514 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1516 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1517 d = MkDeclaratorFunction(d, params);
1519 // Make sure the simple _class's type is declared
1520 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1521 for(spec = specifiers->first; spec; spec = spec.next)
1523 if(spec.type == nameSpecifier)
1525 Symbol classSym = spec.symbol;
1527 symbol._class = classSym.registered;
1532 ListAdd(declarators, MkInitDeclarator(d, null));
1534 specifiers = MkList();
1536 specifiers->Insert(null, MkSpecifier(EXTERN));
1537 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1538 specifiers->Insert(null, MkSpecifier(STATIC));
1540 if(!prop.conversion || prop._class.type == structClass)
1541 ListAdd(specifiers, MkSpecifier(VOID));
1543 ListAdd(specifiers, MkSpecifierName(prop._class.fullName));
1545 decl = MkDeclaration(specifiers, declarators);
1547 external = MkExternalDeclaration(decl);
1550 external.CreateEdge(structExternal, false);
1552 external.CreateEdge(instExternal, false);
1555 DeclareStruct(external, spec.name, false, needReference);
1558 external.symbol = symbol;
1559 symbol.externalSet = external;
1561 ReplaceThisClassSpecifiers(specifiers, prop._class);
1564 // Property (for Watchers)
1565 if(!symbol.externalPtr)
1569 OldList * specifiers = MkList();
1570 char propName[1024];
1573 specifiers->Insert(null, MkSpecifier(EXTERN));
1576 specifiers->Insert(null, MkSpecifier(STATIC));
1577 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1580 ListAdd(specifiers, MkSpecifierName("Property"));
1582 strcpy(propName, "__ecereProp_");
1583 FullClassNameCat(propName, prop._class.fullName, false);
1584 strcat(propName, "_");
1585 FullClassNameCat(propName, prop.name, true);
1588 OldList * list = MkList();
1589 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1593 strcpy(propName, "__ecerePropM_");
1594 FullClassNameCat(propName, prop._class.fullName, false);
1595 strcat(propName, "_");
1596 FullClassNameCat(propName, prop.name, true);
1598 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1600 decl = MkDeclaration(specifiers, list);
1603 external = MkExternalDeclaration(decl);
1604 ast->Insert(curExternal.prev, external);
1605 external.symbol = symbol;
1606 symbol.externalPtr = external;
1609 if(inCompiler && neededBy)
1611 // Could improve this to create edge on only what is needed...
1612 if(symbol.externalPtr)
1613 neededBy.CreateUniqueEdge(symbol.externalPtr, false);
1615 if(symbol.externalGet)
1616 neededBy.CreateUniqueEdge(symbol.externalGet, symbol.externalGet.type == functionExternal);
1618 if(symbol.externalSet)
1619 neededBy.CreateUniqueEdge(symbol.externalSet, symbol.externalSet.type == functionExternal);
1625 // ***************** EXPRESSION PROCESSING ***************************
1626 public Type Dereference(Type source)
1631 if(source.kind == pointerType || source.kind == arrayType)
1634 source.type.refCount++;
1636 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1644 // Support dereferencing of no head classes for now...
1645 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1651 Compiler_Error($"cannot dereference type\n");
1656 static Type Reference(Type source)
1672 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1674 Identifier ident = member.identifiers ? member.identifiers->first : null;
1676 DataMember dataMember = null;
1677 Method method = null;
1678 bool freeType = false;
1680 yylloc = member.loc;
1686 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1690 dataMember = *curMember;
1696 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1697 DataMember _subMemberStack[256];
1698 int _subMemberStackPos = 0;
1700 // FILL MEMBER STACK
1702 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1705 dataMember = thisMember;
1706 if(curMember && thisMember.memberAccess == publicAccess)
1708 *curMember = thisMember;
1709 *curClass = thisMember._class;
1710 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1711 *subMemberStackPos = _subMemberStackPos;
1718 method = eClass_FindMethod(_class, ident.string, privateModule);
1719 if(method && method.type == virtualMethod)
1731 if(!dataMember.dataType && dataMember.dataTypeString)
1733 //Context context = SetupTemplatesContext(dataMember._class);
1734 Context context = SetupTemplatesContext(_class);
1735 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1736 FinishTemplatesContext(context);
1738 type = dataMember.dataType;
1742 // This is for destination type...
1743 if(!method.dataType)
1744 ProcessMethodType(method);
1745 //DeclareMethod(method);
1746 // method.dataType = ((Symbol)method.symbol)->type;
1747 type = method.dataType;
1750 if(ident && ident.next)
1752 for(ident = ident.next; ident && type; ident = ident.next)
1754 if(type.kind == classType)
1756 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1758 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1760 type = dataMember.dataType;
1762 else if(type.kind == structType || type.kind == unionType)
1765 for(memberType = type.members.first; memberType; memberType = memberType.next)
1767 if(!strcmp(memberType.name, ident.string))
1777 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1778 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1781 ClassTemplateParameter curParam = null;
1783 for(sClass = _class; sClass; sClass = sClass.base)
1786 if(sClass.templateClass) sClass = sClass.templateClass;
1787 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1789 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1791 for(sClass = sClass.base; sClass; sClass = sClass.base)
1793 if(sClass.templateClass) sClass = sClass.templateClass;
1794 id += sClass.templateParams.count;
1805 ClassTemplateArgument arg = _class.templateArgs[id];
1806 if(arg.dataTypeString)
1808 bool constant = type.constant;
1810 type = ProcessTypeString(arg.dataTypeString, false);
1811 if(type.kind == classType && constant) type.constant = true;
1812 else if(type.kind == pointerType)
1815 while(t.kind == pointerType) t = t.type;
1816 if(constant) t.constant = constant;
1819 if(type && _class.templateClass)
1820 type.passAsTemplate = true;
1826 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1827 exp.destType.refCount++;
1833 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1835 Class expClass = type._class.registered;
1836 Class cClass = null;
1840 char templateString[1024];
1841 ClassTemplateParameter param;
1842 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1843 for(cClass = expClass; cClass; cClass = cClass.base)
1846 if(cClass.templateClass) cClass = cClass.templateClass;
1847 for(param = cClass.templateParams.first; param; param = param.next)
1851 ClassTemplateArgument arg;
1852 for(sClass = cClass.base; sClass; sClass = sClass.base)
1854 if(sClass.templateClass) sClass = sClass.templateClass;
1855 id += sClass.templateParams.count;
1857 arg = expClass.templateArgs[id];
1859 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1861 ClassTemplateParameter cParam;
1862 //int p = numParams - sClass.templateParams.count;
1865 if(sClass.templateClass) sClass = sClass.templateClass;
1867 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1869 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1870 p += nextClass.templateParams.count;
1873 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1875 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1877 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1879 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1880 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1892 strcat(argument, arg.name.string);
1893 strcat(argument, " = ");
1899 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1900 char expString[1024];
1901 OldList * specs = MkList();
1902 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1904 char * string = PrintHexUInt64(arg.expression.ui64);
1905 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1908 ProcessExpressionType(exp);
1909 ComputeExpression(exp);
1910 expString[0] = '\0';
1911 PrintExpression(exp, expString);
1912 strcat(argument, expString);
1914 FreeExpression(exp);
1919 strcat(argument, arg.member.name);
1922 case TemplateParameterType::type:
1924 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1925 strcat(argument, arg.dataTypeString);
1931 if(paramCount) strcat(templateString, ", ");
1932 if(lastParam != p - 1)
1934 strcat(templateString, param.name);
1935 strcat(templateString, " = ");
1937 strcat(templateString, argument);
1946 int len = strlen(templateString);
1947 if(templateString[len-1] == '<')
1951 if(templateString[len-1] == '>')
1952 templateString[len++] = ' ';
1953 templateString[len++] = '>';
1955 templateString[len++] = '\0';
1958 Context context = SetupTemplatesContext(_class);
1959 if(freeType) FreeType(type);
1960 type = ProcessTypeString(templateString, false);
1962 FinishTemplatesContext(context);
1966 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1968 ProcessExpressionType(member.initializer.exp);
1969 if(!member.initializer.exp.expType)
1973 char expString[10240];
1974 expString[0] = '\0';
1975 PrintExpression(member.initializer.exp, expString);
1976 ChangeCh(expString, '\n', ' ');
1977 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1980 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1981 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1983 Compiler_Error($"incompatible instance method %s\n", ident.string);
1986 else if(member.initializer)
1989 FreeType(member.exp.destType);
1990 member.exp.destType = type;
1991 if(member.exp.destType)
1992 member.exp.destType.refCount++;
1993 ProcessExpressionType(member.exp);
1996 ProcessInitializer(member.initializer, type);
1998 if(freeType) FreeType(type);
2002 if(_class && _class.type == unitClass)
2004 if(member.initializer)
2007 FreeType(member.exp.destType);
2008 member.exp.destType = MkClassType(_class.fullName);
2009 ProcessExpressionType(member.initializer, type);
2011 Type type = MkClassType(_class.fullName);
2012 ProcessInitializer(member.initializer, type);
2018 if(member.initializer)
2020 //ProcessExpressionType(member.exp);
2021 ProcessInitializer(member.initializer, null);
2027 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2031 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2033 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2037 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2042 void ProcessInstantiationType(Instantiation inst)
2047 MembersInit members;
2051 classSym = inst._class.symbol;
2052 _class = classSym ? classSym.registered : null;
2054 if(!_class || _class.type != noHeadClass)
2055 DeclareStruct(curExternal, inst._class.name, false, true);
2057 afterExternal = afterExternal ? afterExternal : curExternal;
2060 ProcessExpressionType(inst.exp);
2062 inst.isConstant = true;
2065 DataMember curMember = null;
2066 Class curClass = null;
2067 DataMember subMemberStack[256];
2068 int subMemberStackPos = 0;
2070 for(members = inst.members->first; members; members = members.next)
2072 switch(members.type)
2074 case methodMembersInit:
2077 static uint instMethodID = 0;
2078 External external = curExternal;
2079 Context context = curContext;
2080 Declarator declarator = members.function.declarator;
2081 Identifier nameID = GetDeclId(declarator);
2082 char * unmangled = nameID ? nameID.string : null;
2084 External createdExternal = null;
2089 strcpy(name, "__ecereInstMeth_");
2090 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2092 strcat(name, nameID.string);
2094 sprintf(number, "_%08d", instMethodID++);
2095 strcat(name, number);
2096 nameID.string = CopyString(name);
2099 // Do modifications here...
2102 Symbol symbol = declarator.symbol;
2103 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2105 if(method && method.type == virtualMethod)
2107 symbol.method = method;
2108 ProcessMethodType(method);
2110 if(!symbol.type.thisClass)
2112 if(method.dataType.thisClass && currentClass &&
2113 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2115 if(!currentClass.symbol)
2116 currentClass.symbol = FindClass(currentClass.fullName);
2117 symbol.type.thisClass = currentClass.symbol;
2122 _class.symbol = FindClass(_class.fullName);
2123 symbol.type.thisClass = _class.symbol;
2126 DeclareType(curExternal, symbol.type, true, true);
2131 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2132 unmangled, classSym.string);
2136 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2140 FreeSpecifier(nameID._class);
2141 nameID._class = null;
2144 curExternal = createdExternal;
2147 if(createdExternal.function)
2148 ProcessFunction(createdExternal.function);
2152 curExternal = declarator.symbol.pointerExternal;
2153 ProcessFunction((FunctionDefinition)members.function);
2155 curExternal = external;
2156 curContext = context;
2160 FreeClassFunction(members.function);
2162 // In this pass, turn this into a MemberInitData
2163 exp = QMkExpId(name);
2164 members.type = dataMembersInit;
2165 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2171 case dataMembersInit:
2173 if(members.dataMembers && classSym)
2176 Location oldyyloc = yylloc;
2177 for(member = members.dataMembers->first; member; member = member.next)
2179 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2180 if(member.initializer && !member.initializer.isConstant)
2181 inst.isConstant = false;
2193 void DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2195 _DeclareType(neededFor, type, needDereference, forFunctionDef, false);
2198 void DeclareTypeForwardDeclare(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2200 _DeclareType(neededFor, type, needDereference, forFunctionDef, true);
2203 static void _DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef, bool fwdDecl)
2207 if(type.kind == functionType)
2210 for(param = type.params.first; param; param = param.next)
2211 _DeclareType(neededFor, param, forFunctionDef, false, fwdDecl);
2212 _DeclareType(neededFor, type.returnType, forFunctionDef, false, fwdDecl);
2214 else if(type.kind == pointerType)
2215 _DeclareType(neededFor, type.type, false, false, fwdDecl);
2216 else if(type.kind == classType)
2218 Class c = type._class.registered;
2219 _DeclareStruct(neededFor, c ? c.fullName : "ecere::com::Instance", c ? c.type == noHeadClass : false, needDereference && c && c.type == structClass, fwdDecl);
2221 else if(type.kind == structType || type.kind == unionType)
2224 for(member = type.members.first; member; member = member.next)
2225 _DeclareType(neededFor, member, needDereference, forFunctionDef, fwdDecl);
2227 else if(type.kind == arrayType)
2228 _DeclareType(neededFor, type.arrayType, true, false, fwdDecl);
2232 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2234 ClassTemplateArgument * arg = null;
2236 ClassTemplateParameter curParam = null;
2238 for(sClass = _class; sClass; sClass = sClass.base)
2241 if(sClass.templateClass) sClass = sClass.templateClass;
2242 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2244 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2246 for(sClass = sClass.base; sClass; sClass = sClass.base)
2248 if(sClass.templateClass) sClass = sClass.templateClass;
2249 id += sClass.templateParams.count;
2259 arg = &_class.templateArgs[id];
2260 if(arg && param.type == type)
2261 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2266 public Context SetupTemplatesContext(Class _class)
2268 Context context = PushContext();
2269 context.templateTypesOnly = true;
2270 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2272 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2273 for(; param; param = param.next)
2275 if(param.type == type && param.identifier)
2277 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2278 curContext.templateTypes.Add((BTNode)type);
2285 for(sClass = _class; sClass; sClass = sClass.base)
2287 ClassTemplateParameter p;
2288 for(p = sClass.templateParams.first; p; p = p.next)
2290 //OldList * specs = MkList();
2291 //Declarator decl = null;
2292 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2295 TemplateParameter param = p.param;
2299 // ADD DATA TYPE HERE...
2300 p.param = param = TemplateParameter
2302 identifier = MkIdentifier(p.name), type = p.type,
2303 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2306 type = TemplatedType { key = (uintptr)p.name, param = param };
2307 curContext.templateTypes.Add((BTNode)type);
2315 public void FinishTemplatesContext(Context context)
2317 PopContext(context);
2318 FreeContext(context);
2322 public void ProcessMethodType(Method method)
2324 if(!method.dataType)
2326 Context context = SetupTemplatesContext(method._class);
2328 method.dataType = ProcessTypeString(method.dataTypeString, false);
2330 FinishTemplatesContext(context);
2332 if(method.type != virtualMethod && method.dataType)
2334 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2336 if(!method._class.symbol)
2337 method._class.symbol = FindClass(method._class.fullName);
2338 method.dataType.thisClass = method._class.symbol;
2342 // Why was this commented out? Working fine without now...
2345 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2346 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2353 char * par = strstr(type, "(");
2354 char * classOp = null;
2359 for(c = par-type-1; c >= 0; c++)
2361 if(type[c] == ':' && type[c+1] == ':')
2363 classOp = type + c - 1;
2364 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2371 else if(!isspace(type[c]))
2378 int typeLen = strlen(type);
2379 memcpy(temp, classOp, classOpLen);
2380 temp[classOpLen] = '\0';
2382 _class = eSystem_FindClass(module, temp);
2385 method.dataTypeString = new char[typeLen - classOpLen + 1];
2386 memcpy(method.dataTypeString, type, classOp - type);
2387 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2390 method.dataTypeString = type;
2396 public void ProcessPropertyType(Property prop)
2400 Context context = SetupTemplatesContext(prop._class);
2401 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2402 FinishTemplatesContext(context);
2406 public void DeclareMethod(External neededFor, Method method, const char * name)
2408 Symbol symbol = method.symbol;
2409 if(!symbol || (!symbol.pointerExternal && (!symbol.methodCodeExternal || method.type == virtualMethod)))
2411 bool dllImport = false;
2413 if(!method.dataType)
2414 method.dataType = ProcessTypeString(method.dataTypeString, false);
2416 //if(!symbol || symbol._import || method.type == virtualMethod)
2418 if(!symbol || method.type == virtualMethod)
2421 if(!method._class.symbol)
2422 method._class.symbol = FindClass(method._class.fullName);
2423 classSym = method._class.symbol;
2424 if(!classSym._import)
2426 ModuleImport module;
2428 if(method._class.module && method._class.module.name)
2429 module = FindModule(method._class.module);
2431 module = mainModule;
2432 classSym._import = ClassImport
2434 name = CopyString(method._class.fullName);
2435 isRemote = method._class.isRemote;
2437 module.classes.Add(classSym._import);
2441 symbol = method.symbol = Symbol { };
2445 symbol._import = (ClassImport)MethodImport
2447 name = CopyString(method.name);
2448 isVirtual = method.type == virtualMethod;
2450 classSym._import.methods.Add(symbol._import);
2454 symbol.type = method.dataType;
2455 if(symbol.type) symbol.type.refCount++;
2458 if(!method.dataType.dllExport)
2460 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2467 // We need a declaration here :)
2469 OldList * specifiers, * declarators;
2471 Declarator funcDecl;
2474 specifiers = MkList();
2475 declarators = MkList();
2478 ListAdd(specifiers, MkSpecifier(EXTERN));
2479 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2480 ListAdd(specifiers, MkSpecifier(STATIC));
2482 if(method.type == virtualMethod)
2484 ListAdd(specifiers, MkSpecifier(INT));
2485 d = MkDeclaratorIdentifier(MkIdentifier(name));
2489 d = MkDeclaratorIdentifier(MkIdentifier(name));
2491 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2493 Context context = SetupTemplatesContext(method._class);
2494 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2495 FinishTemplatesContext(context);
2497 funcDecl = GetFuncDecl(d);
2501 Specifier spec, next;
2502 for(spec = specifiers->first; spec; spec = next)
2505 if(spec.type == extendedSpecifier)
2507 specifiers->Remove(spec);
2508 FreeSpecifier(spec);
2513 // Add this parameter if not a static method
2514 if(method.dataType && !method.dataType.staticMethod)
2516 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2518 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2519 TypeName thisParam = MkTypeName(MkListOne(
2520 MkSpecifierName(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2521 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2522 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2523 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2525 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2527 TypeName param = funcDecl.function.parameters->first;
2528 funcDecl.function.parameters->Remove(param);
2529 FreeTypeName(param);
2532 if(!funcDecl.function.parameters)
2533 funcDecl.function.parameters = MkList();
2534 funcDecl.function.parameters->Insert(null, thisParam);
2538 ProcessDeclarator(d, true);
2540 ListAdd(declarators, MkInitDeclarator(d, null));
2542 decl = MkDeclaration(specifiers, declarators);
2544 ReplaceThisClassSpecifiers(specifiers, method._class);
2546 external = MkExternalDeclaration(decl);
2547 external.symbol = symbol;
2548 symbol.pointerExternal = external;
2550 DeclareStruct(external, method._class.fullName, true, true);
2552 DeclareType(external, method.dataType, true, true);
2555 if(inCompiler && neededFor)
2557 External external = symbol.pointerExternal ? symbol.pointerExternal : symbol.methodCodeExternal;
2558 neededFor.CreateUniqueEdge(external, external.type == functionExternal);
2562 char * ReplaceThisClass(Class _class)
2564 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2568 ClassTemplateParameter param;
2571 char className[1024];
2572 strcpy(className, _class.fullName);
2573 for(param = _class.templateParams.first; param; param = param.next)
2575 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2577 if(first) strcat(className, "<");
2578 if(!first) strcat(className, ", ");
2579 if(lastParam + 1 != p)
2581 strcat(className, param.name);
2582 strcat(className, " = ");
2584 strcat(className, param.name);
2592 int len = strlen(className);
2593 if(className[len-1] == '>') className[len++] = ' ';
2594 className[len++] = '>';
2595 className[len++] = '\0';
2597 return CopyString(className);
2600 return CopyString(_class.fullName);
2603 Type ReplaceThisClassType(Class _class)
2606 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2610 ClassTemplateParameter param;
2612 char className[1024];
2613 strcpy(className, _class.fullName);
2615 for(param = _class.templateParams.first; param; param = param.next)
2617 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2619 if(first) strcat(className, "<");
2620 if(!first) strcat(className, ", ");
2621 if(lastParam + 1 != p)
2623 strcat(className, param.name);
2624 strcat(className, " = ");
2626 strcat(className, param.name);
2634 int len = strlen(className);
2635 if(className[len-1] == '>') className[len++] = ' ';
2636 className[len++] = '>';
2637 className[len++] = '\0';
2639 type = MkClassType(className);
2640 //type = ProcessTypeString(className, false);
2644 type = MkClassType(_class.fullName);
2645 //type = ProcessTypeString(_class.fullName, false);
2647 //type.wasThisClass = true;
2651 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2653 if(specs != null && _class)
2656 for(spec = specs.first; spec; spec = spec.next)
2658 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2660 spec.type = nameSpecifier;
2661 spec.name = ReplaceThisClass(_class);
2662 spec.symbol = FindClass(spec.name); //_class.symbol;
2668 // Returns imported or not
2669 bool DeclareFunction(External neededFor, GlobalFunction function, char * name)
2671 Symbol symbol = function.symbol;
2672 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2673 if(!symbol || !symbol.pointerExternal)
2675 bool imported = false;
2676 bool dllImport = false;
2678 if(!function.dataType)
2680 function.dataType = ProcessTypeString(function.dataTypeString, false);
2681 if(!function.dataType.thisClass)
2682 function.dataType.staticMethod = true;
2689 ModuleImport module = FindModule(function.module);
2690 // WARNING: This is not added anywhere...
2691 symbol = function.symbol = Symbol { };
2695 if(!function.dataType.dllExport)
2697 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2698 module.functions.Add(symbol._import);
2701 // Set the symbol type
2703 symbol.type = ProcessTypeString(function.dataTypeString, false);
2704 if(!symbol.type.thisClass)
2705 symbol.type.staticMethod = true;
2708 imported = symbol._import ? true : false;
2709 if(imported && function.module != privateModule && function.module.importType != staticImport)
2715 // TOCHECK: What's with the functionExternal check here? Is it Edge breaking / forward declaration?
2716 //if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2718 // We need a declaration here :)
2720 OldList * specifiers, * declarators;
2722 Declarator funcDecl;
2725 specifiers = MkList();
2726 declarators = MkList();
2728 ListAdd(specifiers, MkSpecifier(EXTERN));
2730 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2732 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2734 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2735 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2736 if(function.module.importType == staticImport)
2739 for(spec = specifiers->first; spec; spec = spec.next)
2740 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2742 specifiers->Remove(spec);
2743 FreeSpecifier(spec);
2748 funcDecl = GetFuncDecl(d);
2750 // Make sure we don't have empty parameter declarations for static methods...
2751 if(funcDecl && !funcDecl.function.parameters)
2753 funcDecl.function.parameters = MkList();
2754 funcDecl.function.parameters->Insert(null,
2755 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2758 ListAdd(declarators, MkInitDeclarator(d, null));
2761 Context oldCtx = curContext;
2762 curContext = globalContext;
2763 decl = MkDeclaration(specifiers, declarators);
2764 curContext = oldCtx;
2767 // Keep a different symbol for the function definition than the declaration...
2768 /* Note: This should be handled by the edge breaking...
2769 if(symbol.pointerExternal && symbol.pointerExternal.type == functionExternal)
2771 Symbol functionSymbol { };
2774 *functionSymbol = *symbol;
2775 functionSymbol.string = CopyString(symbol.string);
2776 if(functionSymbol.type)
2777 functionSymbol.type.refCount++;
2780 excludedSymbols->Add(functionSymbol);
2782 symbol.pointerExternal.symbol = functionSymbol;
2785 external = MkExternalDeclaration(decl);
2787 external.symbol = symbol;
2788 symbol.pointerExternal = external;
2790 DeclareType(external, function.dataType, true, true);
2794 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2795 neededFor.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
2796 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2799 void DeclareGlobalData(External neededFor, GlobalData data)
2801 Symbol symbol = data.symbol;
2802 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2803 if(!symbol || !symbol.pointerExternal)
2808 symbol = data.symbol = Symbol { };
2811 data.dataType = ProcessTypeString(data.dataTypeString, false);
2815 // We need a declaration here :)
2817 OldList * specifiers, * declarators;
2821 specifiers = MkList();
2822 declarators = MkList();
2824 ListAdd(specifiers, MkSpecifier(EXTERN));
2825 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2826 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2828 ListAdd(declarators, MkInitDeclarator(d, null));
2830 decl = MkDeclaration(specifiers, declarators);
2831 external = MkExternalDeclaration(decl);
2833 ast->Insert(curExternal.prev, external);
2834 external.symbol = symbol;
2835 symbol.pointerExternal = external;
2837 DeclareType(external, data.dataType, true, true);
2840 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2841 neededFor.CreateUniqueEdge(symbol.pointerExternal, false);
2844 class Conversion : struct
2846 Conversion prev, next;
2852 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2855 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2856 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2858 Class sourceClass = source.kind == classType ? source._class.registered : null;
2859 Class destClass = dest.kind == classType ? dest._class.registered : null;
2860 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2861 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2863 Type sourceType = source, destType = dest;
2864 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2865 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2866 if(!destType.constant && sourceType.constant)
2870 Compiler_Warning($"discarding const qualifier\n");
2877 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2878 bool isConversionExploration, bool warnConst)
2883 CheckConstCompatibility(source, dest, true);
2884 // Property convert;
2886 if(source.kind == templateType && dest.kind != templateType)
2888 Type type = ProcessTemplateParameterType(source.templateParameter);
2889 if(type) source = type;
2892 if(dest.kind == templateType && source.kind != templateType)
2894 Type type = ProcessTemplateParameterType(dest.templateParameter);
2895 if(type) dest = type;
2898 if(dest.classObjectType == typedObject && dest.kind != functionType)
2900 if(source.classObjectType != anyObject)
2904 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2905 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2913 if(source.kind != functionType && source.classObjectType == anyObject)
2915 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2919 if((dest.kind == structType && source.kind == structType) ||
2920 (dest.kind == unionType && source.kind == unionType))
2922 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2923 (source.members.first && source.members.first == dest.members.first))
2927 if(dest.kind == ellipsisType && source.kind != voidType)
2930 if(dest.kind == pointerType && dest.type.kind == voidType &&
2931 ((source.kind == classType && (!source._class || !source._class.registered || source._class.registered.type == structClass || source._class.registered.type == normalClass || source._class.registered.type == noHeadClass || source._class.registered.type == systemClass))
2932 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2934 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2936 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2938 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2939 ((dest.kind == classType && (!dest._class || !dest._class.registered || dest._class.registered.type == structClass || dest._class.registered.type == normalClass || dest._class.registered.type == noHeadClass || dest._class.registered.type == systemClass))
2940 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2941 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2943 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2946 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2948 if(source._class.registered && source._class.registered.type == unitClass)
2950 if(conversions != null)
2952 if(source._class.registered == dest._class.registered)
2957 Class sourceBase, destBase;
2958 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2959 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2960 if(sourceBase == destBase)
2964 // Don't match enum inheriting from other enum if resolving enumeration values
2965 // TESTING: !dest.classObjectType
2966 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2968 (!source._class.registered || source._class.registered.type != enumClass) ||
2969 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2973 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2975 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2976 ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
2978 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2986 // JUST ADDED THIS...
2987 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2992 // Just added this for Straight conversion of ColorAlpha => Color
2993 if(source.kind == classType)
2996 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2999 for(convert = _class.conversions.first; convert; convert = convert.next)
3001 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3003 Conversion after = (conversions != null) ? conversions.last : null;
3005 if(!convert.dataType)
3006 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3007 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3008 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3009 MatchTypes(convert.dataType, dest, conversions, null, null,
3010 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3011 convert.dataType.kind == classType, false, true, warnConst))
3013 if(!conversions && !convert.Get)
3015 else if(conversions != null)
3017 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3018 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3019 (dest.kind != classType || dest._class.registered != _class.base))
3023 Conversion conv { convert = convert, isGet = true };
3024 // conversions.Add(conv);
3025 conversions.Insert(after, conv);
3038 if(dest.kind == classType)
3041 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3044 for(convert = _class.conversions.first; convert; convert = convert.next)
3046 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3048 Type constType = null;
3049 bool success = false;
3050 // Conversion after = (conversions != null) ? conversions.last : null;
3052 if(!convert.dataType)
3053 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3055 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3058 constType = { kind = pointerType, refCount = 1, type = ptrType };
3059 CopyTypeInto(ptrType, convert.dataType.type);
3060 ptrType.constant = true;
3063 // Just added this equality check to prevent recursion.... Make it safer?
3064 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3065 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3067 if(!conversions && !convert.Set)
3069 else if(conversions != null)
3071 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3072 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3073 (source.kind != classType || source._class.registered != _class.base))
3077 // *** Testing this! ***
3078 Conversion conv { convert = convert };
3079 conversions.Add(conv);
3080 //conversions.Insert(after, conv);
3086 FreeType(constType);
3092 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3094 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3095 (source.kind != classType || source._class.registered.type != structClass))
3099 // TESTING THIS... IS THIS OK??
3100 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3102 if(!dest._class.registered.dataType)
3103 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3104 // Only support this for classes...
3105 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3106 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3108 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3117 if(source.kind == classType)
3120 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3123 for(convert = _class.conversions.first; convert; convert = convert.next)
3125 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3127 Conversion after = (conversions != null) ? conversions.last : null;
3129 if(!convert.dataType)
3130 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3131 if(convert.dataType != source &&
3132 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3133 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3135 if(!conversions && !convert.Get)
3137 else if(conversions != null)
3139 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3140 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3141 (dest.kind != classType || dest._class.registered != _class.base))
3145 Conversion conv { convert = convert, isGet = true };
3147 // conversions.Add(conv);
3148 conversions.Insert(after, conv);
3157 // TESTING THIS... IS THIS OK??
3158 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3160 if(!source._class.registered.dataType)
3161 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3162 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3164 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3166 // For bool to be accepted by byte, short, etc.
3167 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3174 if(source.kind == classType || source.kind == subClassType)
3176 else if(dest.kind == source.kind &&
3177 (dest.kind != structType && dest.kind != unionType &&
3178 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3180 // RECENTLY ADDED THESE
3181 else if(dest.kind == doubleType && source.kind == floatType)
3183 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3185 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3187 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3189 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3191 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3193 else if(source.kind == enumType &&
3194 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3196 else if(dest.kind == enumType && !isConversionExploration &&
3197 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3199 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3200 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3202 Type paramSource, paramDest;
3204 if(dest.kind == methodType)
3205 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3206 if(source.kind == methodType)
3207 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3209 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3210 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3211 if(dest.kind == methodType)
3212 dest = dest.method.dataType;
3213 if(source.kind == methodType)
3214 source = source.method.dataType;
3216 paramSource = source.params.first;
3217 if(paramSource && paramSource.kind == voidType) paramSource = null;
3218 paramDest = dest.params.first;
3219 if(paramDest && paramDest.kind == voidType) paramDest = null;
3222 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3223 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3225 // Source thisClass must be derived from destination thisClass
3226 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3227 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3229 if(paramDest && paramDest.kind == classType)
3230 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3232 Compiler_Error($"method class should not take an object\n");
3235 paramDest = paramDest.next;
3237 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3239 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3243 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3245 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3251 // THIS WAS BACKWARDS:
3252 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3253 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3256 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3258 Compiler_Error($"overriding class expected to be derived from method class\n");
3262 paramSource = paramSource.next;
3268 // Source thisClass must be derived from destination thisClass
3269 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3271 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3277 // THIS WAS BACKWARDS TOO??
3278 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3279 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3282 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3284 //Compiler_Error($"overriding class expected to be derived from method class\n");
3292 // Source return type must be derived from destination return type
3293 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3295 Compiler_Warning($"incompatible return type for function\n");
3298 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3300 CheckConstCompatibility(dest.returnType, source.returnType, true);
3304 for(; paramDest; paramDest = paramDest.next)
3308 //Compiler_Warning($"not enough parameters\n");
3309 Compiler_Error($"not enough parameters\n");
3313 Type paramDestType = paramDest;
3314 Type paramSourceType = paramSource;
3315 Type type = paramDestType;
3317 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3318 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3319 paramSource.kind != templateType)
3322 ClassTemplateParameter curParam = null;
3324 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3327 if(sClass.templateClass) sClass = sClass.templateClass;
3328 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3330 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3332 for(sClass = sClass.base; sClass; sClass = sClass.base)
3334 if(sClass.templateClass) sClass = sClass.templateClass;
3335 id += sClass.templateParams.count;
3346 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3347 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3351 // paramDest must be derived from paramSource
3352 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3353 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3357 PrintType(paramDest, type, false, true);
3358 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3360 if(paramDestType != paramDest)
3361 FreeType(paramDestType);
3364 if(paramDestType != paramDest)
3365 FreeType(paramDestType);
3368 paramSource = paramSource.next;
3372 Compiler_Error($"too many parameters\n");
3377 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3381 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3382 (source.kind == arrayType || source.kind == pointerType))
3384 // Pointers to pointer is incompatible with non normal/nohead classes
3385 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3386 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3388 ComputeTypeSize(source.type);
3389 ComputeTypeSize(dest.type);
3390 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3398 static void FreeConvert(Conversion convert)
3400 if(convert.resultType)
3401 FreeType(convert.resultType);
3404 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3405 char * string, OldList conversions)
3409 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3411 Class _class = link.data;
3412 if(_class.type == enumClass)
3414 OldList converts { };
3416 type.kind = classType;
3419 _class.symbol = FindClass(_class.fullName);
3420 type._class = _class.symbol;
3422 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3423 false, false, false, false))
3426 Class enumClass = eSystem_FindClass(privateModule, "enum");
3430 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3432 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3433 for(value = e.values.first; value; value = value.next)
3435 if(!strcmp(value.name, string))
3440 FreeType(sourceExp.expType);
3442 sourceExp.isConstant = true;
3443 sourceExp.expType = MkClassType(baseClass.fullName);
3444 if(inCompiler || inPreCompiler || inDebugger)
3447 FreeExpContents(sourceExp);
3449 sourceExp.type = constantExp;
3450 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3451 sprintf(constant, FORMAT64D, value.data);
3453 sprintf(constant, FORMAT64HEXLL, value.data);
3454 sourceExp.constant = CopyString(constant);
3455 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3458 while(converts.first)
3460 Conversion convert = converts.first;
3461 converts.Remove(convert);
3462 conversions.Add(convert);
3471 converts.Free(FreeConvert);
3475 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3476 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3481 public bool ModuleVisibility(Module searchIn, Module searchFor)
3483 SubModule subModule;
3485 if(searchFor == searchIn)
3488 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3490 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3492 if(ModuleVisibility(subModule.module, searchFor))
3499 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3503 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3505 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3507 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3510 for(module = mainModule.application.allModules.first; module; module = module.next)
3512 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3518 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3521 Type realDest = dest;
3522 Type backupSourceExpType = null;
3523 Expression nbExp = GetNonBracketsExp(sourceExp);
3524 Expression computedExp = nbExp;
3527 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3528 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3530 computedExp = CopyExpression(nbExp); // Keep the original expression, but compute for checking enum ranges
3531 ComputeExpression(computedExp /*sourceExp*/);
3534 source = sourceExp.expType;
3536 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3538 if(computedExp != nbExp)
3540 FreeExpression(computedExp);
3541 computedExp = nbExp;
3547 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3549 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3551 Class sourceBase, destBase;
3552 for(sourceBase = source._class.registered;
3553 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3554 sourceBase = sourceBase.base);
3555 for(destBase = dest._class.registered;
3556 destBase && destBase.base && destBase.base.type != systemClass;
3557 destBase = destBase.base);
3558 //if(source._class.registered == dest._class.registered)
3559 if(sourceBase == destBase)
3561 if(computedExp != nbExp)
3563 FreeExpression(computedExp);
3564 computedExp = nbExp;
3576 int64 value = MAXINT;
3580 if(computedExp.type == constantExp)
3583 value = strtoll(computedExp.constant, null, 0);
3585 value = strtoull(computedExp.constant, null, 0);
3587 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3590 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3592 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3594 if(computedExp != nbExp)
3596 FreeExpression(computedExp);
3597 computedExp = nbExp;
3600 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3601 !strcmp(source._class.registered.fullName, "unichar" /*"ecere::com::unichar"*/))
3604 source = Type { kind = intType, isSigned = false, refCount = 1 };
3607 if(dest.kind == classType)
3609 Class _class = dest._class ? dest._class.registered : null;
3611 if(_class && _class.type == unitClass)
3613 if(source.kind != classType)
3616 Type tempDest, tempSource;
3618 for(; _class.base.type != systemClass; _class = _class.base);
3620 tempDest = tempType;
3622 tempType.kind = classType;
3624 _class.symbol = FindClass(_class.fullName);
3626 tempType._class = _class.symbol;
3627 tempType.truth = dest.truth;
3629 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3631 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3632 backupSourceExpType = sourceExp.expType;
3633 if(dest.passAsTemplate)
3635 // Don't carry passAsTemplate
3636 sourceExp.expType = { };
3637 CopyTypeInto(sourceExp.expType, dest);
3638 sourceExp.expType.passAsTemplate = false;
3642 sourceExp.expType = dest;
3645 //sourceExp.expType = MkClassType(_class.fullName);
3653 // Why wasn't there something like this?
3654 if(_class && _class.type == bitClass && source.kind != classType)
3656 if(!dest._class.registered.dataType)
3657 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3658 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3661 FreeType(sourceExp.expType);
3662 source = sourceExp.expType = MkClassType(dest._class.string);
3665 //source.kind = classType;
3666 //source._class = dest._class;
3670 // Adding two enumerations
3672 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3674 if(!source._class.registered.dataType)
3675 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3676 if(!dest._class.registered.dataType)
3677 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3679 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3682 source = sourceExp.expType = MkClassType(dest._class.string);
3685 //source.kind = classType;
3686 //source._class = dest._class;
3690 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3692 OldList * specs = MkList();
3696 ReadString(string, sourceExp.string);
3697 decl = SpecDeclFromString(string, specs, null);
3699 FreeExpContents(sourceExp);
3700 FreeType(sourceExp.expType);
3702 sourceExp.type = classExp;
3703 sourceExp._classExp.specifiers = specs;
3704 sourceExp._classExp.decl = decl;
3705 sourceExp.expType = dest;
3710 if(backupSourceExpType) FreeType(backupSourceExpType);
3714 else if(source.kind == classType)
3716 Class _class = source._class ? source._class.registered : null;
3718 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || _class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3721 if(dest.kind != classType)
3723 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3724 if(!source._class.registered.dataType)
3725 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3728 dest = MkClassType(source._class.string);
3729 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3730 // dest = MkClassType(source._class.string);
3734 if(dest.kind != classType)
3737 Type tempDest, tempSource;
3739 if(!source._class.registered.dataType)
3740 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3742 for(; _class.base.type != systemClass; _class = _class.base);
3744 tempSource = tempType;
3745 tempType.kind = classType;
3746 tempType._class = FindClass(_class.fullName);
3747 tempType.truth = source.truth;
3748 tempType.classObjectType = source.classObjectType;
3751 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3753 // PUT THIS BACK TESTING UNITS?
3754 if(conversions && conversions.last)
3756 ((Conversion)(conversions.last)).resultType = dest;
3760 FreeType(sourceExp.expType);
3761 sourceExp.expType = MkClassType(_class.fullName);
3762 sourceExp.expType.truth = source.truth;
3763 sourceExp.expType.classObjectType = source.classObjectType;
3765 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3767 if(!sourceExp.destType)
3769 FreeType(sourceExp.destType);
3770 sourceExp.destType = sourceExp.expType;
3771 if(sourceExp.expType)
3772 sourceExp.expType.refCount++;
3775 //source = _class.dataType;
3778 // TOCHECK: TESTING THIS NEW CODE
3779 if(!_class.dataType)
3780 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3782 dest = MkClassType(source._class.string);
3783 dest.truth = source.truth;
3784 dest.classObjectType = source.classObjectType;
3787 source = _class.dataType;
3797 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3807 if(source.kind == classType)
3809 Class _class = source._class.registered;
3810 if(_class.type == unitClass)
3812 if(!_class.dataType)
3813 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3814 source = _class.dataType;
3818 if(dest.kind == classType)
3820 Class _class = dest._class ? dest._class.registered : null;
3821 bool fittingValue = false;
3822 if(_class && _class.type == enumClass)
3824 Class enumClass = eSystem_FindClass(privateModule, "enum");
3825 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3826 if(c && value >= 0 && value <= c.largest)
3827 fittingValue = true;
3830 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3831 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3833 if(_class.type == normalClass || _class.type == noHeadClass)
3835 Expression newExp { };
3836 *newExp = *sourceExp;
3837 if(sourceExp.destType) sourceExp.destType.refCount++;
3838 if(sourceExp.expType) sourceExp.expType.refCount++;
3839 sourceExp.type = castExp;
3840 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3841 sourceExp.cast.exp = newExp;
3842 FreeType(sourceExp.expType);
3843 sourceExp.expType = null;
3844 ProcessExpressionType(sourceExp);
3846 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3849 FreeType(sourceExp.expType);
3850 sourceExp.expType = dest;
3854 if(inCompiler) FreeType(dest);
3856 if(backupSourceExpType) FreeType(backupSourceExpType);
3860 if(!_class.dataType)
3861 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3863 dest = _class.dataType;
3867 // Accept lower precision types for units, since we want to keep the unit type
3868 if(dest.kind == doubleType &&
3869 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3870 source.kind == charType || source.kind == _BoolType))
3872 specs = MkListOne(MkSpecifier(DOUBLE));
3874 else if(dest.kind == floatType &&
3875 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3876 source.kind == _BoolType || source.kind == doubleType))
3878 specs = MkListOne(MkSpecifier(FLOAT));
3880 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3881 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3884 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3885 ListAdd(specs, MkSpecifier(INT64));
3887 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3888 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3891 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3892 ListAdd(specs, MkSpecifier(INT));
3894 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3895 source.kind == floatType || source.kind == doubleType))
3898 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3899 ListAdd(specs, MkSpecifier(SHORT));
3901 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3902 source.kind == floatType || source.kind == doubleType))
3905 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3906 ListAdd(specs, MkSpecifier(CHAR));
3912 if(backupSourceExpType)
3914 // Failed to convert: revert previous exp type
3915 if(sourceExp.expType) FreeType(sourceExp.expType);
3916 sourceExp.expType = backupSourceExpType;
3921 else if(dest.kind == doubleType &&
3922 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3923 source.kind == _BoolType || source.kind == charType))
3925 specs = MkListOne(MkSpecifier(DOUBLE));
3927 else if(dest.kind == floatType &&
3928 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3930 specs = MkListOne(MkSpecifier(FLOAT));
3932 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3933 (value == 1 || value == 0))
3936 ListAdd(specs, MkSpecifier(BOOL));
3938 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3939 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3941 if(source.kind == intType)
3945 if(backupSourceExpType) FreeType(backupSourceExpType);
3951 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3952 ListAdd(specs, MkSpecifier(CHAR));
3955 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3956 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3958 if(source.kind == intType)
3962 if(backupSourceExpType) FreeType(backupSourceExpType);
3968 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3969 ListAdd(specs, MkSpecifier(SHORT));
3972 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3975 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3976 ListAdd(specs, MkSpecifier(INT));
3978 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3981 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3982 ListAdd(specs, MkSpecifier(INT64));
3984 else if(dest.kind == enumType &&
3985 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3987 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3993 if(backupSourceExpType)
3995 // Failed to convert: revert previous exp type
3996 if(sourceExp.expType) FreeType(sourceExp.expType);
3997 sourceExp.expType = backupSourceExpType;
4002 if(!flag && !sourceExp.opDestType)
4004 Expression newExp { };
4005 *newExp = *sourceExp;
4008 if(sourceExp.destType) sourceExp.destType.refCount++;
4009 if(sourceExp.expType) sourceExp.expType.refCount++;
4011 sourceExp.type = castExp;
4012 if(realDest.kind == classType)
4014 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4015 FreeList(specs, FreeSpecifier);
4018 sourceExp.cast.typeName = MkTypeName(specs, null);
4019 if(newExp.type == opExp)
4021 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4024 sourceExp.cast.exp = newExp;
4026 FreeType(sourceExp.expType);
4027 sourceExp.expType = null;
4028 ProcessExpressionType(sourceExp);
4031 FreeList(specs, FreeSpecifier);
4035 if(backupSourceExpType) FreeType(backupSourceExpType);
4041 if(computedExp != nbExp)
4043 FreeExpression(computedExp);
4044 computedExp = nbExp;
4047 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4048 if(sourceExp.type == identifierExp)
4050 Identifier id = sourceExp.identifier;
4051 if(dest.kind == classType)
4053 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4055 Class _class = dest._class.registered;
4056 Class enumClass = eSystem_FindClass(privateModule, "enum");
4059 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4062 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4063 for(value = e.values.first; value; value = value.next)
4065 if(!strcmp(value.name, id.string))
4070 FreeType(sourceExp.expType);
4072 sourceExp.isConstant = true;
4073 sourceExp.expType = MkClassType(_class.fullName);
4074 if(inCompiler || inPreCompiler || inDebugger)
4076 FreeExpContents(sourceExp);
4078 sourceExp.type = constantExp;
4079 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4080 sourceExp.constant = PrintInt64(value.data);
4082 sourceExp.constant = PrintUInt64(value.data);
4083 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4093 // Loop through all enum classes
4094 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4105 #define TERTIARY(o, name, m, t, p) \
4106 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4108 exp.type = constantExp; \
4109 exp.string = p(op1.m ? op2.m : op3.m); \
4111 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4115 #define BINARY(o, name, m, t, p) \
4116 static bool name(Expression exp, Operand op1, Operand op2) \
4119 exp.type = constantExp; \
4120 exp.string = p((t)(op1.m o value2)); \
4122 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4126 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4127 static bool name(Expression exp, Operand op1, Operand op2) \
4130 exp.type = constantExp; \
4131 exp.string = p(value2 ? ((t)(op1.m o value2)) : 0); \
4133 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4137 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4138 static bool name(Expression exp, Operand op1, Operand op2) \
4141 exp.type = constantExp; \
4142 exp.string = p((t)(op1.m o value2)); \
4144 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4148 #define UNARY(o, name, m, t, p) \
4149 static bool name(Expression exp, Operand op1) \
4151 exp.type = constantExp; \
4152 exp.string = p((t)(o op1.m)); \
4154 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4158 #define OPERATOR_ALL(macro, o, name) \
4159 macro(o, Int##name, i, int, PrintInt) \
4160 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4161 macro(o, Int64##name, i64, int64, PrintInt64) \
4162 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4163 macro(o, Short##name, s, short, PrintShort) \
4164 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4165 macro(o, Char##name, c, char, PrintChar) \
4166 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4167 macro(o, Float##name, f, float, PrintFloat) \
4168 macro(o, Double##name, d, double, PrintDouble)
4170 #define OPERATOR_INTTYPES(macro, o, name) \
4171 macro(o, Int##name, i, int, PrintInt) \
4172 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4173 macro(o, Int64##name, i64, int64, PrintInt64) \
4174 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4175 macro(o, Short##name, s, short, PrintShort) \
4176 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4177 macro(o, Char##name, c, char, PrintChar) \
4178 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4180 #define OPERATOR_REALTYPES(macro, o, name) \
4181 macro(o, Float##name, f, float, PrintFloat) \
4182 macro(o, Double##name, d, double, PrintDouble)
4184 // binary arithmetic
4185 OPERATOR_ALL(BINARY, +, Add)
4186 OPERATOR_ALL(BINARY, -, Sub)
4187 OPERATOR_ALL(BINARY, *, Mul)
4188 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4189 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4190 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4193 OPERATOR_ALL(UNARY, -, Neg)
4195 // unary arithmetic increment and decrement
4196 OPERATOR_ALL(UNARY, ++, Inc)
4197 OPERATOR_ALL(UNARY, --, Dec)
4199 // binary arithmetic assignment
4200 OPERATOR_ALL(BINARY, =, Asign)
4201 OPERATOR_ALL(BINARY, +=, AddAsign)
4202 OPERATOR_ALL(BINARY, -=, SubAsign)
4203 OPERATOR_ALL(BINARY, *=, MulAsign)
4204 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4205 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4206 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4209 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4210 OPERATOR_INTTYPES(BINARY, |, BitOr)
4211 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4212 OPERATOR_INTTYPES(BINARY, <<, LShift)
4213 OPERATOR_INTTYPES(BINARY, >>, RShift)
4216 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4218 // binary bitwise assignment
4219 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4220 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4221 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4222 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4223 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4225 // unary logical negation
4226 OPERATOR_INTTYPES(UNARY, !, Not)
4228 // binary logical equality
4229 OPERATOR_ALL(BINARY, ==, Equ)
4230 OPERATOR_ALL(BINARY, !=, Nqu)
4233 OPERATOR_ALL(BINARY, &&, And)
4234 OPERATOR_ALL(BINARY, ||, Or)
4236 // binary logical relational
4237 OPERATOR_ALL(BINARY, >, Grt)
4238 OPERATOR_ALL(BINARY, <, Sma)
4239 OPERATOR_ALL(BINARY, >=, GrtEqu)
4240 OPERATOR_ALL(BINARY, <=, SmaEqu)
4242 // tertiary condition operator
4243 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4245 //Add, Sub, Mul, Div, Mod, , Neg, Inc, Dec, Asign, AddAsign, SubAsign, MulAsign, DivAsign, ModAsign, BitAnd, BitOr, BitXor, LShift, RShift, BitNot, AndAsign, OrAsign, XorAsign, LShiftAsign, RShiftAsign, Not, Equ, Nqu, And, Or, Grt, Sma, GrtEqu, SmaEqu
4246 #define OPERATOR_TABLE_ALL(name, type) \
4247 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4249 type##Inc, type##Dec, \
4250 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4251 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4253 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4255 type##Equ, type##Nqu, \
4256 type##And, type##Or, \
4257 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4260 #define OPERATOR_TABLE_INTTYPES(name, type) \
4261 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4263 type##Inc, type##Dec, \
4264 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4265 null, null, null, null, null, \
4267 null, null, null, null, null, \
4269 type##Equ, type##Nqu, \
4270 type##And, type##Or, \
4271 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4274 OPERATOR_TABLE_ALL(int, Int)
4275 OPERATOR_TABLE_ALL(uint, UInt)
4276 OPERATOR_TABLE_ALL(int64, Int64)
4277 OPERATOR_TABLE_ALL(uint64, UInt64)
4278 OPERATOR_TABLE_ALL(short, Short)
4279 OPERATOR_TABLE_ALL(ushort, UShort)
4280 OPERATOR_TABLE_INTTYPES(float, Float)
4281 OPERATOR_TABLE_INTTYPES(double, Double)
4282 OPERATOR_TABLE_ALL(char, Char)
4283 OPERATOR_TABLE_ALL(uchar, UChar)
4285 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4286 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4287 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4288 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4289 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4290 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4291 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4292 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4294 public void ReadString(char * output, char * string)
4296 int len = strlen(string);
4298 bool quoted = false, escaped = false;
4299 for(c = 0; c<len; c++)
4301 char ch = string[c];
4306 case 'n': output[d] = '\n'; break;
4307 case 't': output[d] = '\t'; break;
4308 case 'a': output[d] = '\a'; break;
4309 case 'b': output[d] = '\b'; break;
4310 case 'f': output[d] = '\f'; break;
4311 case 'r': output[d] = '\r'; break;
4312 case 'v': output[d] = '\v'; break;
4313 case '\\': output[d] = '\\'; break;
4314 case '\"': output[d] = '\"'; break;
4315 case '\'': output[d] = '\''; break;
4316 default: output[d] = ch;
4337 // String Unescape Copy
4339 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4340 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4341 public int UnescapeString(char * d, char * s, int len)
4345 while(j < len && (ch = s[j]))
4350 switch((ch = s[++j]))
4352 case 'n': d[k] = '\n'; break;
4353 case 't': d[k] = '\t'; break;
4354 case 'a': d[k] = '\a'; break;
4355 case 'b': d[k] = '\b'; break;
4356 case 'f': d[k] = '\f'; break;
4357 case 'r': d[k] = '\r'; break;
4358 case 'v': d[k] = '\v'; break;
4359 case '\\': d[k] = '\\'; break;
4360 case '\"': d[k] = '\"'; break;
4361 case '\'': d[k] = '\''; break;
4362 default: d[k] = '\\'; d[k] = ch;
4374 public char * OffsetEscapedString(char * s, int len, int offset)
4378 while(j < len && k < offset && (ch = s[j]))
4383 return (k == offset) ? s + j : null;
4386 public Operand GetOperand(Expression exp)
4389 Type type = exp.expType;
4392 while(type.kind == classType &&
4393 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4395 if(!type._class.registered.dataType)
4396 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4397 type = type._class.registered.dataType;
4400 if(exp.type == stringExp && op.kind == pointerType)
4402 op.ui64 = (uint64)(uintptr)exp.string;
4403 op.kind = pointerType;
4406 else if(exp.isConstant && exp.type == constantExp)
4408 op.kind = type.kind;
4416 if(exp.constant[0] == '\'')
4418 op.c = exp.constant[1];
4421 else if(type.isSigned)
4423 op.c = (char)strtol(exp.constant, null, 0);
4428 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4434 if(exp.constant[0] == '\'')
4436 op.s = exp.constant[1];
4439 else if(type.isSigned)
4441 op.s = (short)strtol(exp.constant, null, 0);
4446 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4452 if(exp.constant[0] == '\'')
4454 op.i = exp.constant[1];
4457 else if(type.isSigned)
4459 op.i = (int)strtol(exp.constant, null, 0);
4464 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4472 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4477 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4480 op.kind = int64Type;
4485 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4490 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4493 op.kind = int64Type;
4498 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4503 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4506 op.kind = int64Type;
4509 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4510 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4511 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4512 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4514 op.f = (float)strtod(exp.constant, null);
4518 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4519 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4520 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4521 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4523 op.d = (double)strtod(exp.constant, null);
4526 //case classType: For when we have operator overloading...
4527 // Pointer additions
4528 //case functionType:
4532 op.ui64 = _strtoui64(exp.constant, null, 0);
4533 op.kind = pointerType;
4543 static int64 GetEnumValue(Class _class, void * ptr)
4546 switch(_class.typeSize)
4549 if(!strcmp(_class.dataTypeString, "uint64"))
4550 v = (int64)*(uint64 *)ptr;
4552 v = (int64)*(int64 *)ptr;
4555 if(!strcmp(_class.dataTypeString, "uint"))
4556 v = (int64)*(uint *)ptr;
4558 v = (int64)*(int *)ptr;
4561 if(!strcmp(_class.dataTypeString, "uint16"))
4562 v = (int64)*(uint16 *)ptr;
4564 v = (int64)*(short *)ptr;
4567 if(!strcmp(_class.dataTypeString, "byte"))
4568 v = (int64)*(byte *)ptr;
4570 v = (int64)*(char *)ptr;
4576 static __attribute__((unused)) void UnusedFunction()
4579 a.OnGetString(0,0,0);
4582 extern int __ecereVMethodID_class_OnGetString;
4585 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4587 DataMember dataMember;
4588 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4590 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4591 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4595 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4597 void * ptr = inst.data + dataMember.offset + offset;
4598 char * result = null;
4599 exp.loc = member.loc = inst.loc;
4600 ((Identifier)member.identifiers->first).loc = inst.loc;
4602 if(!dataMember.dataType)
4603 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4604 type = dataMember.dataType;
4605 if(type.kind == classType)
4607 Class _class = type._class.registered;
4608 if(_class.type == enumClass)
4610 Class enumClass = eSystem_FindClass(privateModule, "enum");
4613 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4615 for(item = e.values.first; item; item = item.next)
4617 if(item.data == GetEnumValue(_class, ptr))
4625 exp.identifier = MkIdentifier(result);
4626 exp.type = identifierExp;
4627 exp.destType = MkClassType(_class.fullName);
4628 ProcessExpressionType(exp);
4632 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4634 if(!_class.dataType)
4635 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4636 type = _class.dataType;
4645 FreeExpContents(exp);
4647 exp.constant = PrintFloat(*(float*)ptr);
4648 exp.type = constantExp;
4653 FreeExpContents(exp);
4655 exp.constant = PrintDouble(*(double*)ptr);
4656 exp.type = constantExp;
4661 FreeExpContents(exp);
4663 exp.constant = PrintInt(*(int*)ptr);
4664 exp.type = constantExp;
4669 FreeExpContents(exp);
4671 exp.constant = PrintInt64(*(int64*)ptr);
4672 exp.type = constantExp;
4677 FreeExpContents(exp);
4678 // TODO: This should probably use proper type
4679 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4680 exp.type = constantExp;
4685 FreeExpContents(exp);
4686 // TODO: This should probably use proper type
4687 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4688 exp.type = constantExp;
4692 Compiler_Error($"Unhandled type populating instance\n");
4695 ListAdd(memberList, member);
4698 if(parentDataMember.type == unionMember)
4703 void PopulateInstance(Instantiation inst)
4705 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4706 Class _class = classSym.registered;
4707 DataMember dataMember;
4708 OldList * memberList = MkList();
4709 // Added this check and ->Add to prevent memory leaks on bad code
4711 inst.members = MkListOne(MkMembersInitList(memberList));
4713 inst.members->Add(MkMembersInitList(memberList));
4714 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4716 if(!dataMember.isProperty)
4718 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4719 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4723 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4725 void * ptr = inst.data + dataMember.offset;
4726 char * result = null;
4728 exp.loc = member.loc = inst.loc;
4729 ((Identifier)member.identifiers->first).loc = inst.loc;
4731 if(!dataMember.dataType)
4732 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4733 type = dataMember.dataType;
4734 if(type.kind == classType)
4736 Class _class = type._class.registered;
4737 if(_class.type == enumClass)
4739 Class enumClass = eSystem_FindClass(privateModule, "enum");
4742 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4744 for(item = e.values.first; item; item = item.next)
4746 if(item.data == GetEnumValue(_class, ptr))
4755 exp.identifier = MkIdentifier(result);
4756 exp.type = identifierExp;
4757 exp.destType = MkClassType(_class.fullName);
4758 ProcessExpressionType(exp);
4761 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4763 if(!_class.dataType)
4764 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4765 type = _class.dataType;
4774 exp.constant = PrintFloat(*(float*)ptr);
4775 exp.type = constantExp;
4780 exp.constant = PrintDouble(*(double*)ptr);
4781 exp.type = constantExp;
4786 exp.constant = PrintInt(*(int*)ptr);
4787 exp.type = constantExp;
4792 exp.constant = PrintInt64(*(int64*)ptr);
4793 exp.type = constantExp;
4798 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4799 exp.type = constantExp;
4803 Compiler_Error($"Unhandled type populating instance\n");
4806 ListAdd(memberList, member);
4812 void ComputeInstantiation(Expression exp)
4814 Instantiation inst = exp.instance;
4815 MembersInit members;
4816 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4817 Class _class = classSym ? classSym.registered : null;
4818 DataMember curMember = null;
4819 Class curClass = null;
4820 DataMember subMemberStack[256];
4821 int subMemberStackPos = 0;
4824 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4826 // Don't recompute the instantiation...
4827 // Non Simple classes will have become constants by now
4831 if(_class.type == normalClass || _class.type == noHeadClass)
4833 inst.data = (byte *)eInstance_New(_class);
4834 if(_class.type == normalClass)
4835 ((Instance)inst.data)._refCount++;
4838 inst.data = new0 byte[_class.structSize];
4843 for(members = inst.members->first; members; members = members.next)
4845 switch(members.type)
4847 case dataMembersInit:
4849 if(members.dataMembers)
4852 for(member = members.dataMembers->first; member; member = member.next)
4854 Identifier ident = member.identifiers ? member.identifiers->first : null;
4857 Property prop = null;
4858 DataMember dataMember = null;
4859 uint dataMemberOffset;
4863 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4866 if(curMember.isProperty)
4867 prop = (Property)curMember;
4870 dataMember = curMember;
4872 // CHANGED THIS HERE
4873 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4875 // 2013/17/29 -- It seems that this was missing here!
4876 if(_class.type == normalClass)
4877 dataMemberOffset += _class.base.structSize;
4878 // dataMemberOffset = dataMember.offset;
4885 prop = eClass_FindProperty(_class, ident.string, privateModule);
4889 if(prop.memberAccess == publicAccess)
4891 curMember = (DataMember)prop;
4892 curClass = prop._class;
4897 DataMember _subMemberStack[256];
4898 int _subMemberStackPos = 0;
4900 // FILL MEMBER STACK
4901 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4906 if(dataMember.memberAccess == publicAccess)
4908 curMember = dataMember;
4909 curClass = dataMember._class;
4910 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4911 subMemberStackPos = _subMemberStackPos;
4917 if(found && member.initializer && member.initializer.type == expInitializer)
4919 Expression value = member.initializer.exp;
4921 bool deepMember = false;
4924 type = prop.dataType;
4928 if(!dataMember.dataType)
4929 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4931 type = dataMember.dataType;
4934 if(ident && ident.next)
4938 // for(; ident && type; ident = ident.next)
4939 for(ident = ident.next; ident && type; ident = ident.next)
4941 if(type.kind == classType)
4943 prop = eClass_FindProperty(type._class.registered,
4944 ident.string, privateModule);
4946 type = prop.dataType;
4949 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4950 ident.string, &dataMemberOffset, privateModule, null, null);
4952 type = dataMember.dataType;
4955 else if(type.kind == structType || type.kind == unionType)
4958 for(memberType = type.members.first; memberType; memberType = memberType.next)
4960 if(!strcmp(memberType.name, ident.string))
4971 FreeType(value.destType);
4972 value.destType = type;
4973 if(type) type.refCount++;
4974 ComputeExpression(value);
4976 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4978 if(type.kind == classType)
4980 Class _class = type._class.registered;
4981 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4983 if(!_class.dataType)
4984 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4985 type = _class.dataType;
4991 void * ptr = inst.data + dataMemberOffset;
4993 if(value.type == constantExp)
4999 GetInt(value, (int*)ptr);
5004 GetInt64(value, (int64*)ptr);
5009 GetIntPtr(value, (intptr*)ptr);
5014 GetIntSize(value, (intsize*)ptr);
5019 GetFloat(value, (float*)ptr);
5024 GetDouble(value, (double *)ptr);
5029 else if(value.type == instanceExp)
5031 if(type.kind == classType)
5033 Class _class = type._class.registered;
5034 if(_class.type == structClass)
5036 ComputeTypeSize(type);
5037 if(value.instance.data)
5038 memcpy(ptr, value.instance.data, type.size);
5043 else if(prop && prop.Set != (void *)(intptr)1)
5045 if(value.type == instanceExp && value.instance.data)
5047 if(type.kind == classType)
5049 Class _class = type._class.registered;
5050 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5052 void (*Set)(void *, void *) = (void *)prop.Set;
5053 Set(inst.data, value.instance.data);
5054 PopulateInstance(inst);
5058 else if(value.type == constantExp)
5064 void (*Set)(void *, double) = (void *)prop.Set;
5065 Set(inst.data, strtod(value.constant, null) );
5070 void (*Set)(void *, float) = (void *)prop.Set;
5071 Set(inst.data, (float)(strtod(value.constant, null)));
5076 void (*Set)(void *, int) = (void *)prop.Set;
5077 Set(inst.data, (int)strtol(value.constant, null, 0));
5082 void (*Set)(void *, int64) = (void *)prop.Set;
5083 Set(inst.data, _strtoi64(value.constant, null, 0));
5088 void (*Set)(void *, intptr) = (void *)prop.Set;
5089 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5094 void (*Set)(void *, intsize) = (void *)prop.Set;
5095 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5100 else if(value.type == stringExp)
5103 ReadString(temp, value.string);
5104 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5108 else if(!deepMember && type && _class.type == unitClass)
5112 // Only support converting units to units for now...
5113 if(value.type == constantExp)
5115 if(type.kind == classType)
5117 Class _class = type._class.registered;
5118 if(_class.type == unitClass)
5120 if(!_class.dataType)
5121 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5122 type = _class.dataType;
5125 // TODO: Assuming same base type for units...
5131 float (*Set)(float) = (void *)prop.Set;
5132 GetFloat(member.initializer.exp, &fValue);
5133 exp.constant = PrintFloat(Set(fValue));
5134 exp.type = constantExp;
5140 double (*Set)(double) = (void *)prop.Set;
5141 GetDouble(member.initializer.exp, &dValue);
5142 exp.constant = PrintDouble(Set(dValue));
5143 exp.type = constantExp;
5150 else if(!deepMember && type && _class.type == bitClass)
5154 if(value.type == instanceExp && value.instance.data)
5156 unsigned int (*Set)(void *) = (void *)prop.Set;
5157 bits = Set(value.instance.data);
5159 else if(value.type == constantExp)
5165 BitMember bitMember = (BitMember) dataMember;
5168 bits = (bits & ~bitMember.mask);
5169 if(!bitMember.dataType)
5170 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5171 type = bitMember.dataType;
5172 if(type.kind == classType && type._class && type._class.registered)
5174 if(!type._class.registered.dataType)
5175 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5176 type = type._class.registered.dataType;
5181 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5182 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5184 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5185 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5186 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5187 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5189 bits |= part << bitMember.pos;
5195 if(_class && _class.type == unitClass)
5197 ComputeExpression(member.initializer.exp);
5198 exp.constant = member.initializer.exp.constant;
5199 exp.type = constantExp;
5201 member.initializer.exp.constant = null;
5211 if(_class && _class.type == bitClass)
5213 exp.constant = PrintHexUInt(bits);
5214 exp.type = constantExp;
5216 if(exp.type != instanceExp)
5222 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5224 bool result = false;
5228 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5229 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5233 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5234 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5237 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5238 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5239 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5242 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5243 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5244 result = GetOpFloat(op, &op.f);
5247 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5248 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5249 result = GetOpDouble(op, &op.d);
5252 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5253 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5254 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5257 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5258 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5259 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5262 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5263 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5266 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5267 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5273 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5275 if(exp.op.op == SIZEOF)
5277 FreeExpContents(exp);
5278 exp.type = constantExp;
5279 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5290 // Provide default unary +
5291 Expression exp2 = exp.op.exp2;
5293 FreeExpContents(exp);
5294 FreeType(exp.expType);
5295 FreeType(exp.destType);
5301 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5303 // unary arithmetic increment and decrement
5304 //OPERATOR_ALL(UNARY, ++, Inc)
5305 //OPERATOR_ALL(UNARY, --, Dec)
5308 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5310 // unary logical negation
5312 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5318 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5320 if(Promote(op2, op1.kind, op1.type.isSigned))
5321 op2.kind = op1.kind, op2.ops = op1.ops;
5322 else if(Promote(op1, op2.kind, op2.type.isSigned))
5323 op1.kind = op2.kind, op1.ops = op2.ops;
5327 // binary arithmetic
5329 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5332 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5335 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5338 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5341 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5343 // binary arithmetic assignment
5344 //OPERATOR_ALL(BINARY, =, Asign)
5345 //OPERATOR_ALL(BINARY, +=, AddAsign)
5346 //OPERATOR_ALL(BINARY, -=, SubAsign)
5347 //OPERATOR_ALL(BINARY, *=, MulAsign)
5348 //OPERATOR_ALL(BINARY, /=, DivAsign)
5349 //OPERATOR_ALL(BINARY, %=, ModAsign)
5354 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5358 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5361 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5364 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5367 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5369 // binary bitwise assignment
5370 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5371 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5372 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5373 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5374 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5375 // binary logical equality
5377 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5380 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5384 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5387 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5389 // binary logical relational
5391 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5394 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5397 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5400 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5407 void ComputeExpression(Expression exp)
5410 char expString[10240];
5411 expString[0] = '\0';
5412 PrintExpression(exp, expString);
5419 Identifier id = exp.identifier;
5420 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5422 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5423 if(c && c.type == enumClass)
5425 Class enumClass = eSystem_FindClass(privateModule, "enum");
5429 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5430 for(value = e.values.first; value; value = value.next)
5432 if(!strcmp(value.name, id.string))
5437 const String dts = c.dataTypeString;
5438 FreeExpContents(exp);
5439 exp.type = constantExp;
5440 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5449 ComputeInstantiation(exp);
5458 Expression exp1, exp2 = null;
5462 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5465 Expression e = exp.op.exp2;
5467 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5469 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5471 if(e.type == extensionCompoundExp)
5472 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5477 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5479 if(e.type == stringExp && e.string)
5481 char * string = e.string;
5482 int len = strlen(string);
5483 char * tmp = new char[len-2+1];
5484 len = UnescapeString(tmp, string + 1, len - 2);
5486 FreeExpContents(exp);
5487 exp.type = constantExp;
5488 exp.constant = PrintUInt(len + 1);
5492 Type type = e.expType;
5494 FreeExpContents(exp);
5495 exp.type = constantExp;
5496 exp.constant = PrintUInt(ComputeTypeSize(type));
5502 ComputeExpression(exp.op.exp2);
5506 ComputeExpression(exp.op.exp1);
5509 op1 = GetOperand(exp1);
5510 if(op1.type) op1.type.refCount++;
5513 op2 = GetOperand(exp2);
5514 if(op2.type) op2.type.refCount++;
5520 op1 = GetOperand(exp1);
5521 if(op1.type) op1.type.refCount++;
5524 CallOperator(exp, exp1, exp2, op1, op2);
5531 if(exp.op.exp1 && exp.op.exp2)
5536 FreeExpContents(exp);
5537 op1.ops.BitAnd(exp, op1, op2);
5546 FreeExpContents(exp);
5547 op1.ops.Mul(exp, op1, op2);
5556 FreeExpContents(exp);
5557 op1.ops.Add(exp, op1, op2);
5562 // Provide default unary +
5563 Expression exp2 = exp.op.exp2;
5565 FreeExpContents(exp);
5566 FreeType(exp.expType);
5567 FreeType(exp.destType);
5578 FreeExpContents(exp);
5579 op1.ops.Sub(exp, op1, op2);
5586 FreeExpContents(exp);
5587 op1.ops.Neg(exp, op1);
5594 FreeExpContents(exp);
5595 op1.ops.BitNot(exp, op1);
5601 FreeExpContents(exp);
5602 op1.ops.Not(exp, op1);
5605 // Binary only operators
5609 FreeExpContents(exp);
5610 op1.ops.Div(exp, op1, op2);
5616 FreeExpContents(exp);
5617 op1.ops.Mod(exp, op1, op2);
5629 FreeExpContents(exp);
5630 op1.ops.Sma(exp, op1, op2);
5639 FreeExpContents(exp);
5640 op1.ops.Grt(exp, op1, op2);
5649 FreeExpContents(exp);
5650 op1.ops.SmaEqu(exp, op1, op2);
5659 FreeExpContents(exp);
5660 op1.ops.GrtEqu(exp, op1, op2);
5669 FreeExpContents(exp);
5670 op1.ops.Equ(exp, op1, op2);
5679 FreeExpContents(exp);
5680 op1.ops.Nqu(exp, op1, op2);
5687 FreeExpContents(exp);
5688 op1.ops.BitOr(exp, op1, op2);
5694 FreeExpContents(exp);
5695 op1.ops.BitXor(exp, op1, op2);
5703 FreeExpContents(exp);
5704 exp.type = constantExp;
5705 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5709 if(op1.type) FreeType(op1.type);
5710 if(op2.type) FreeType(op2.type);
5714 case extensionExpressionExp:
5717 for(e = exp.list->first; e; e = n)
5722 OldList * list = exp.list;
5723 Expression prev = exp.prev;
5724 Expression next = exp.next;
5725 ComputeExpression(e);
5726 //FreeExpContents(exp);
5727 FreeType(exp.expType);
5728 FreeType(exp.destType);
5747 exp.isConstant = true;
5749 ComputeExpression(exp.index.exp);
5750 if(!exp.index.exp.isConstant)
5751 exp.isConstant = false;
5753 for(e = exp.index.index->first; e; e = e.next)
5755 ComputeExpression(e);
5758 // Check if this type is int
5761 exp.isConstant = false;
5763 exp.expType = Dereference(exp.index.exp.expType);
5769 Expression memberExp = exp.member.exp;
5770 Identifier memberID = exp.member.member;
5773 ComputeExpression(exp.member.exp);
5774 type = exp.member.exp.expType;
5777 Class _class = (exp.member.member && exp.member.member.classSym) ? exp.member.member.classSym.registered : (((type.kind == classType || type.kind == subClassType) && type._class) ? type._class.registered : null);
5778 Property prop = null;
5779 DataMember member = null;
5780 Class convertTo = null;
5781 if(type.kind == subClassType && exp.member.exp.type == classExp)
5782 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5789 PrintTypeNoConst(type, string, false, true);
5790 classSym = FindClass(string);
5791 _class = classSym ? classSym.registered : null;
5794 if(exp.member.member)
5796 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5798 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5800 if(!prop && !member && _class && exp.member.member)
5802 Symbol classSym = FindClass(exp.member.member.string);
5804 _class = classSym ? classSym.registered : null;
5805 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5812 Type type = prop.dataType;
5813 // TODO: Assuming same base type for units...
5814 if(_class.type == unitClass)
5816 if(type.kind == classType)
5818 Class _class = type._class.registered;
5819 if(_class.type == unitClass)
5821 if(!_class.dataType)
5822 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5823 type = _class.dataType;
5831 float (*Get)(float) = (void *)prop.Get;
5832 GetFloat(exp.member.exp, &value);
5833 exp.constant = PrintFloat(Get ? Get(value) : value);
5834 exp.type = constantExp;
5840 double (*Get)(double);
5841 GetDouble(exp.member.exp, &value);
5844 Get = (void *)prop.Set;
5846 Get = (void *)prop.Get;
5847 exp.constant = PrintDouble(Get ? Get(value) : value);
5848 exp.type = constantExp;
5857 Expression value = exp.member.exp;
5860 ProcessPropertyType(prop);
5862 type = prop.dataType;
5865 // printf("Investigate this\n");
5867 else if(_class.type == structClass)
5873 Class propertyClass = type._class.registered;
5874 if(propertyClass.type == structClass && value.type == instanceExp)
5876 void (*Set)(void *, void *) = (void *)prop.Set;
5877 exp.instance = Instantiation { };
5878 exp.instance.data = new0 byte[_class.structSize];
5879 exp.instance._class = MkSpecifierName(_class.fullName);
5880 exp.instance.loc = exp.loc;
5881 exp.type = instanceExp;
5882 Set(exp.instance.data, value.instance.data);
5883 PopulateInstance(exp.instance);
5890 void (*Set)(void *, int) = (void *)prop.Set;
5892 exp.instance = Instantiation { };
5893 exp.instance.data = new0 byte[_class.structSize];
5894 exp.instance._class = MkSpecifierName(_class.fullName);
5895 exp.instance.loc = exp.loc;
5896 exp.type = instanceExp;
5898 GetInt(value, &intValue);
5900 Set(exp.instance.data, intValue);
5901 PopulateInstance(exp.instance);
5907 void (*Set)(void *, int64) = (void *)prop.Set;
5909 exp.instance = Instantiation { };
5910 exp.instance.data = new0 byte[_class.structSize];
5911 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5912 exp.instance.loc = exp.loc;
5913 exp.type = instanceExp;
5915 GetInt64(value, &intValue);
5917 Set(exp.instance.data, intValue);
5918 PopulateInstance(exp.instance);
5925 void (*Set)(void *, intptr) = (void *)prop.Set;
5927 exp.instance = Instantiation { };
5928 exp.instance.data = new0 byte[_class.structSize];
5929 exp.instance._class = MkSpecifierName(_class.fullName);
5930 exp.instance.loc = exp.loc;
5931 exp.type = instanceExp;
5933 GetIntPtr(value, &intValue);
5935 Set(exp.instance.data, intValue);
5936 PopulateInstance(exp.instance);
5943 void (*Set)(void *, intsize) = (void *)prop.Set;
5945 exp.instance = Instantiation { };
5946 exp.instance.data = new0 byte[_class.structSize];
5947 exp.instance._class = MkSpecifierName(_class.fullName);
5948 exp.instance.loc = exp.loc;
5949 exp.type = instanceExp;
5951 GetIntSize(value, &intValue);
5953 Set(exp.instance.data, intValue);
5954 PopulateInstance(exp.instance);
5960 void (*Set)(void *, float) = (void *)prop.Set;
5962 exp.instance = Instantiation { };
5963 exp.instance.data = new0 byte[_class.structSize];
5964 exp.instance._class = MkSpecifierName(_class.fullName);
5965 exp.instance.loc = exp.loc;
5966 exp.type = instanceExp;
5968 GetFloat(value, &floatValue);
5970 Set(exp.instance.data, floatValue);
5971 PopulateInstance(exp.instance);
5977 void (*Set)(void *, double) = (void *)prop.Set;
5979 exp.instance = Instantiation { };
5980 exp.instance.data = new0 byte[_class.structSize];
5981 exp.instance._class = MkSpecifierName(_class.fullName);
5982 exp.instance.loc = exp.loc;
5983 exp.type = instanceExp;
5985 GetDouble(value, &doubleValue);
5987 Set(exp.instance.data, doubleValue);
5988 PopulateInstance(exp.instance);
5993 else if(_class.type == bitClass)
5999 Class propertyClass = type._class.registered;
6000 if(propertyClass.type == structClass && value.instance.data)
6002 unsigned int (*Set)(void *) = (void *)prop.Set;
6003 unsigned int bits = Set(value.instance.data);
6004 exp.constant = PrintHexUInt(bits);
6005 exp.type = constantExp;
6008 else if(_class.type == bitClass)
6011 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6014 GetUInt(exp.member.exp, &value);
6016 exp.constant = PrintHexUInt(bits);
6017 exp.type = constantExp;
6025 if(_class.type == bitClass)
6028 GetUInt(exp.member.exp, &value);
6034 Class _class = type._class.registered;
6035 if(_class.type == structClass)
6037 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6039 exp.instance = Instantiation { };
6040 exp.instance.data = new0 byte[_class.structSize];
6041 exp.instance._class = MkSpecifierName(_class.fullName);
6042 exp.instance.loc = exp.loc;
6043 //exp.instance.fullSet = true;
6044 exp.type = instanceExp;
6045 Get(value, exp.instance.data);
6046 PopulateInstance(exp.instance);
6048 else if(_class.type == bitClass)
6050 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6051 uint64 bits = Get(value);
6052 exp.constant = PrintHexUInt64(bits);
6053 exp.type = constantExp;
6059 else if(_class.type == structClass)
6061 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6066 Class _class = type._class.registered;
6067 if(_class.type == structClass && value)
6069 void (*Get)(void *, void *) = (void *)prop.Get;
6071 exp.instance = Instantiation { };
6072 exp.instance.data = new0 byte[_class.structSize];
6073 exp.instance._class = MkSpecifierName(_class.fullName);
6074 exp.instance.loc = exp.loc;
6075 //exp.instance.fullSet = true;
6076 exp.type = instanceExp;
6077 Get(value, exp.instance.data);
6078 PopulateInstance(exp.instance);
6086 char * value = exp.member.exp.instance.data;
6091 Class _class = type._class.registered;
6092 if(_class.type == normalClass)
6094 void *(*Get)(void *) = (void *)prop.Get;
6096 exp.instance = Instantiation { };
6097 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6098 exp.type = instanceExp;
6099 exp.instance.data = Get(value, exp.instance.data);
6111 exp.isConstant = false;
6119 if(exp.type != ExpressionType::memberExp)
6121 FreeExpression(memberExp);
6122 FreeIdentifier(memberID);
6128 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6129 FreeExpContents(exp);
6130 exp.constant = PrintUInt(ComputeTypeSize(type));
6131 exp.type = constantExp;
6137 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6138 if(classSym && classSym.registered)
6140 if(classSym.registered.fixed)
6142 FreeSpecifier(exp._class);
6143 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6144 exp.type = constantExp;
6148 char className[1024];
6149 strcpy(className, "__ecereClass_");
6150 FullClassNameCat(className, classSym.string, true);
6152 DeclareClass(curExternal, classSym, className);
6154 FreeExpContents(exp);
6155 exp.type = pointerExp;
6156 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6157 exp.member.member = MkIdentifier("structSize");
6167 if(exp.type == castExp)
6170 ComputeExpression(exp.cast.exp);
6173 if(e && exp.expType)
6176 type = exp.destType;
6179 if(type.kind == classType)
6181 Class _class = type._class.registered;
6182 if(_class && (_class.type == unitClass || _class.type == bitClass))
6184 if(!_class.dataType)
6185 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6186 type = _class.dataType;
6197 if(GetChar(e, &value))
6199 FreeExpContents(exp);
6200 exp.constant = PrintChar(value);
6201 exp.type = constantExp;
6206 unsigned char value = 0;
6207 if(GetUChar(e, &value))
6209 FreeExpContents(exp);
6210 exp.constant = PrintUChar(value);
6211 exp.type = constantExp;
6219 if(GetShort(e, &value))
6221 FreeExpContents(exp);
6222 exp.constant = PrintShort(value);
6223 exp.type = constantExp;
6228 unsigned short value = 0;
6229 if(GetUShort(e, &value))
6231 FreeExpContents(exp);
6232 exp.constant = PrintUShort(value);
6233 exp.type = constantExp;
6241 if(GetInt(e, &value))
6243 FreeExpContents(exp);
6244 exp.constant = PrintInt(value);
6245 exp.type = constantExp;
6250 unsigned int value = 0;
6251 if(GetUInt(e, &value))
6253 FreeExpContents(exp);
6254 exp.constant = PrintUInt(value);
6255 exp.type = constantExp;
6263 if(GetInt64(e, &value))
6265 FreeExpContents(exp);
6266 exp.constant = PrintInt64(value);
6267 exp.type = constantExp;
6273 if(GetUInt64(e, &value))
6275 FreeExpContents(exp);
6276 exp.constant = PrintUInt64(value);
6277 exp.type = constantExp;
6285 if(GetIntPtr(e, &value))
6287 FreeExpContents(exp);
6288 exp.constant = PrintInt64((int64)value);
6289 exp.type = constantExp;
6295 if(GetUIntPtr(e, &value))
6297 FreeExpContents(exp);
6298 exp.constant = PrintUInt64((uint64)value);
6299 exp.type = constantExp;
6307 if(GetIntSize(e, &value))
6309 FreeExpContents(exp);
6310 exp.constant = PrintInt64((int64)value);
6311 exp.type = constantExp;
6317 if(GetUIntSize(e, &value))
6319 FreeExpContents(exp);
6320 exp.constant = PrintUInt64((uint64)value);
6321 exp.type = constantExp;
6328 if(GetFloat(e, &value))
6330 FreeExpContents(exp);
6331 exp.constant = PrintFloat(value);
6332 exp.type = constantExp;
6339 if(GetDouble(e, &value))
6341 FreeExpContents(exp);
6342 exp.constant = PrintDouble(value);
6343 exp.type = constantExp;
6358 // Caring only about last expression for now...
6359 ComputeExpression(exp.cond.exp->last);
6360 if(exp.cond.elseExp)
6361 ComputeExpression(exp.cond.elseExp);
6363 ComputeExpression(exp.cond.cond);
6365 op1 = GetOperand(exp.cond.cond);
6366 if(op1.type) op1.type.refCount++;
6367 op2 = GetOperand(exp.cond.exp->last);
6368 if(op2.type) op2.type.refCount++;
6369 op3 = GetOperand(exp.cond.elseExp);
6370 if(op3.type) op3.type.refCount++;
6372 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6373 if(op1.type) FreeType(op1.type);
6374 if(op2.type) FreeType(op2.type);
6375 if(op3.type) FreeType(op3.type);
6381 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6386 OldList converts { };
6389 if(destType.kind == voidType)
6392 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6396 // for(convert = converts.last; convert; convert = convert.prev)
6397 for(convert = converts.first; convert; convert = convert.next)
6399 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6402 Expression newExp { };
6403 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6405 // TODO: Check this...
6409 newExp.destType = null;
6414 exp.type = memberExp;
6415 exp.addedThis = true;
6416 exp.member.exp = newExp;
6417 FreeType(exp.member.exp.expType);
6419 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6420 exp.member.exp.expType.classObjectType = objectType;
6421 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6422 exp.member.memberType = propertyMember;
6423 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6424 // TESTING THIS... for (int)degrees
6425 exp.needCast = true;
6426 if(exp.expType) exp.expType.refCount++;
6427 ApplyAnyObjectLogic(exp.member.exp);
6432 /*if(exp.isConstant)
6434 // Color { ColorRGB = [exp] };
6435 exp.type = instanceExp;
6436 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6437 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6438 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6442 // If not constant, don't turn it yet into an instantiation
6443 // (Go through the deep members system first)
6444 exp.type = memberExp;
6445 exp.addedThis = true;
6446 exp.member.exp = newExp;
6448 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6449 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6450 newExp.expType._class.registered.type == noHeadClass)
6452 newExp.byReference = true;
6455 FreeType(exp.member.exp.expType);
6456 /*exp.member.exp.expType = convert.convert.dataType;
6457 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6458 exp.member.exp.expType = null;
6459 if(convert.convert.dataType)
6461 exp.member.exp.expType = { };
6462 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6463 exp.member.exp.expType.refCount = 1;
6464 exp.member.exp.expType.classObjectType = objectType;
6465 ApplyAnyObjectLogic(exp.member.exp);
6468 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6469 exp.member.memberType = reverseConversionMember;
6470 exp.expType = convert.resultType ? convert.resultType :
6471 MkClassType(convert.convert._class.fullName);
6472 exp.needCast = true;
6473 if(convert.resultType) convert.resultType.refCount++;
6479 FreeType(exp.expType);
6482 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6483 if(exp.destType.casted)
6484 exp.needCast = true;
6485 if(exp.expType) exp.expType.refCount++;
6489 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6490 if(exp.destType.casted)
6491 exp.needCast = true;
6492 if(convert.resultType)
6493 convert.resultType.refCount++;
6497 if(exp.isConstant && inCompiler)
6498 ComputeExpression(exp);
6500 converts.Free(FreeConvert);
6503 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6505 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6507 if(!result && exp.expType && exp.destType)
6509 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6510 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6511 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6512 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6516 // if(result) CheckTemplateTypes(exp);
6520 void CheckTemplateTypes(Expression exp)
6523 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6524 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6526 Expression nbExp = GetNonBracketsExp(exp);
6527 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6528 (nbExp == exp || nbExp.type != castExp))
6530 Expression newExp { };
6532 TypeKind kind = exp.expType.kind;
6534 if(exp.destType) exp.destType.refCount++;
6535 if(exp.expType) exp.expType.refCount++;
6539 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6541 Class c = exp.expType._class.registered;
6542 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6545 c.dataType = ProcessTypeString(c.dataTypeString, false);
6546 kind = c.dataType.kind;
6553 if(exp.destType.classObjectType)
6555 // We need to pass the address, just pass it along (Undo what was done above)
6556 if(exp.destType) exp.destType.refCount--;
6557 if(exp.expType) exp.expType.refCount--;
6562 // If we're looking for value:
6563 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6565 OldList * unionDefs = MkList();
6566 OldList * statements = MkList();
6567 context = PushContext();
6568 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6569 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6570 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6571 exp.type = extensionCompoundExp;
6572 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6573 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6574 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6575 exp.compound.compound.context = context;
6576 PopContext(context);
6581 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6582 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6583 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6585 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6586 exp.needCast = true;
6590 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6592 Expression newExp { };
6594 TypeKind kind = exp.expType.kind;
6596 if(exp.destType) exp.destType.refCount++;
6597 if(exp.expType) exp.expType.refCount++;
6601 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6603 Class c = exp.expType._class.registered;
6604 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6607 c.dataType = ProcessTypeString(c.dataTypeString, false);
6608 kind = c.dataType.kind;
6615 if(exp.destType.classObjectType)
6617 // We need to pass the address, just pass it along (Undo what was done above)
6618 if(exp.destType) exp.destType.refCount--;
6619 if(exp.expType) exp.expType.refCount--;
6624 // If we're looking for value:
6625 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6627 OldList * unionDefs = MkList();
6628 OldList * statements = MkList();
6629 context = PushContext();
6630 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6631 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6632 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6633 exp.type = extensionCompoundExp;
6634 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6635 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6636 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6637 exp.compound.compound.context = context;
6638 PopContext(context);
6643 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6645 exp.type = bracketsExp;
6647 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6648 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6649 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6650 ProcessExpressionType(exp.list->first);
6655 exp.type = bracketsExp;
6656 if(exp.expType.isPointerType)
6658 exp.needTemplateCast = 2;
6659 newExp.needCast = true;
6660 newExp.needTemplateCast = 2;
6661 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6664 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6665 exp.needTemplateCast = 2;
6666 newExp.needCast = true;
6667 newExp.needTemplateCast = 2;
6668 ProcessExpressionType(exp.list->first);
6674 if(exp.expType.kind == templateType)
6676 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6679 FreeType(exp.destType);
6680 FreeType(exp.expType);
6685 /*if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6687 // When was this required? Removed to address using templated values to pass to printf()
6691 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6692 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6696 char typeString[1024];
6698 OldList * specs = MkList();
6699 typeString[0] = '\0';
6700 PrintType(exp.expType, typeString, false, false);
6701 decl = SpecDeclFromString(typeString, specs, null);
6704 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6705 exp.cast.typeName = MkTypeName(specs, decl);
6706 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6707 exp.cast.exp.needCast = true;
6708 exp.needTemplateCast = 2;
6709 newExp.needTemplateCast = 2;
6716 // TODO: The Symbol tree should be reorganized by namespaces
6718 // - Tree of all symbols within (stored without namespace)
6719 // - Tree of sub-namespaces
6721 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6723 int nsLen = strlen(nameSpace);
6725 // Start at the name space prefix
6726 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6728 char * s = symbol.string;
6729 if(!strncmp(s, nameSpace, nsLen))
6731 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6734 for(c = strlen(s)-1; c >= 0; c--)
6739 if(!strcmp(namePart, name))
6741 // TODO: Error on ambiguity
6751 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6754 char nameSpace[1024];
6755 const char * namePart;
6756 bool gotColon = false;
6758 nameSpace[0] = '\0';
6759 for(c = strlen(name)-1; c >= 0; c--)
6766 namePart = name+c+1;
6767 while(c >= 0 && name[c] == ':') c--;
6770 // Try an exact match first
6771 Symbol symbol = (Symbol)tree.FindString(name);
6775 // Namespace specified
6776 memcpy(nameSpace, name, c + 1);
6779 return ScanWithNameSpace(tree, nameSpace, namePart);
6783 // Looking for a global symbol, e.g. ::Sleep()
6784 Symbol symbol = (Symbol)tree.FindString(namePart);
6789 // Name only (no namespace specified)
6790 Symbol symbol = (Symbol)tree.FindString(namePart);
6793 return ScanWithNameSpace(tree, "", namePart);
6798 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6801 //Time startTime = GetTime();
6803 // Optimize this later? Do this before/less?
6805 Symbol symbol = null;
6807 // First, check if the identifier is declared inside the function
6808 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6810 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6812 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6818 strcpy(curName, thisNameSpace);
6819 strcat(curName, "::");
6820 strcat(curName, name);
6821 // Try to resolve in current namespace first
6822 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6825 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6828 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6830 if(symbol || ctx == endContext) break;
6832 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6833 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6835 //findSymbolTotalTime += GetTime() - startTime;
6840 static void GetTypeSpecs(Type type, OldList * specs)
6842 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6847 if(type._class.registered)
6849 if(!type._class.registered.dataType)
6850 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6851 GetTypeSpecs(type._class.registered.dataType, specs);
6855 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6856 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6857 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6858 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6859 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6860 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6861 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6862 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6865 ListAdd(specs, MkSpecifier(INT)); break;
6869 static void PrintArraySize(Type arrayType, char * string)
6874 if(arrayType.enumClass)
6875 strcat(size, arrayType.enumClass.string);
6876 else if(arrayType.arraySizeExp)
6877 PrintExpression(arrayType.arraySizeExp, size);
6879 strcat(string, size);
6882 // WARNING : This function expects a null terminated string since it recursively concatenate...
6883 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6887 if(printConst && type.constant)
6888 strcat(string, "const ");
6893 Symbol c = type._class;
6894 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
6895 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6896 // look into merging with thisclass ?
6897 if(type.classObjectType == typedObject && isObjectBaseClass)
6898 strcat(string, "typed_object");
6899 else if(type.classObjectType == anyObject && isObjectBaseClass)
6900 strcat(string, "any_object");
6904 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6906 if(type.byReference)
6907 strcat(string, " &");
6910 case voidType: strcat(string, "void"); break;
6911 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6912 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6913 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6914 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6915 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6916 case _BoolType: strcat(string, "_Bool"); break;
6917 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6918 case floatType: strcat(string, "float"); break;
6919 case doubleType: strcat(string, "double"); break;
6923 strcat(string, "struct ");
6924 strcat(string, type.enumName);
6926 else if(type.typeName)
6927 strcat(string, type.typeName);
6931 strcat(string, "struct { ");
6932 for(member = type.members.first; member; member = member.next)
6934 PrintType(member, string, true, fullName);
6935 strcat(string,"; ");
6943 strcat(string, "union ");
6944 strcat(string, type.enumName);
6946 else if(type.typeName)
6947 strcat(string, type.typeName);
6950 strcat(string, "union ");
6951 strcat(string,"(unnamed)");
6957 strcat(string, "enum ");
6958 strcat(string, type.enumName);
6960 else if(type.typeName)
6961 strcat(string, type.typeName);
6963 strcat(string, "int"); // "enum");
6966 strcat(string, "...");
6969 strcat(string, "subclass(");
6970 strcat(string, type._class ? type._class.string : "int");
6971 strcat(string, ")");
6974 strcat(string, type.templateParameter.identifier.string);
6977 strcat(string, "thisclass");
6980 strcat(string, "__builtin_va_list");
6986 static void PrintName(Type type, char * string, bool fullName)
6988 if(type.name && type.name[0])
6991 strcat(string, type.name);
6994 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6995 if(name) name += 2; else name = type.name;
6996 strcat(string, name);
7001 static void PrintAttribs(Type type, char * string)
7005 if(type.dllExport) strcat(string, "dllexport ");
7006 if(type.attrStdcall) strcat(string, "stdcall ");
7010 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7012 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7014 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7015 PrintAttribs(type, string);
7016 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7017 strcat(string, " const");
7018 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7019 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7020 strcat(string, " (");
7021 if(type.kind == pointerType)
7023 if(type.type.kind == functionType || type.type.kind == methodType)
7024 PrintAttribs(type.type, string);
7026 if(type.kind == pointerType)
7028 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7029 strcat(string, "*");
7031 strcat(string, " *");
7033 if(printConst && type.constant && type.kind == pointerType)
7034 strcat(string, " const");
7037 PrintTypeSpecs(type, string, fullName, printConst);
7040 static void PostPrintType(Type type, char * string, bool fullName)
7042 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7043 strcat(string, ")");
7044 if(type.kind == arrayType)
7045 PrintArraySize(type, string);
7046 else if(type.kind == functionType)
7049 strcat(string, "(");
7050 for(param = type.params.first; param; param = param.next)
7052 PrintType(param, string, true, fullName);
7053 if(param.next) strcat(string, ", ");
7055 strcat(string, ")");
7057 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7058 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7062 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7064 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7066 PrePrintType(type, string, fullName, null, printConst);
7068 if(type.thisClass || (printName && type.name && type.name[0]))
7069 strcat(string, " ");
7070 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7072 Symbol _class = type.thisClass;
7073 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7075 if(type.classObjectType == classPointer)
7076 strcat(string, "class");
7078 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7080 else if(_class && _class.string)
7082 String s = _class.string;
7087 char * name = RSearchString(s, "::", strlen(s), true, false);
7088 if(name) name += 2; else name = s;
7089 strcat(string, name);
7092 strcat(string, "::");
7095 if(printName && type.name)
7096 PrintName(type, string, fullName);
7097 PostPrintType(type, string, fullName);
7098 if(type.bitFieldCount)
7101 sprintf(count, ":%d", type.bitFieldCount);
7102 strcat(string, count);
7106 void PrintType(Type type, char * string, bool printName, bool fullName)
7108 _PrintType(type, string, printName, fullName, true);
7111 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7113 _PrintType(type, string, printName, fullName, false);
7116 static Type FindMember(Type type, char * string)
7119 for(memberType = type.members.first; memberType; memberType = memberType.next)
7121 if(!memberType.name)
7123 Type subType = FindMember(memberType, string);
7127 else if(!strcmp(memberType.name, string))
7133 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7136 for(memberType = type.members.first; memberType; memberType = memberType.next)
7138 if(!memberType.name)
7140 Type subType = FindMember(memberType, string);
7143 *offset += memberType.offset;
7147 else if(!strcmp(memberType.name, string))
7149 *offset += memberType.offset;
7156 public bool GetParseError() { return parseError; }
7158 Expression ParseExpressionString(char * expression)
7162 fileInput = TempFile { };
7163 fileInput.Write(expression, 1, strlen(expression));
7164 fileInput.Seek(0, start);
7167 parsedExpression = null;
7169 expression_yyparse();
7172 return parsedExpression;
7175 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7177 Identifier id = exp.identifier;
7178 Method method = null;
7179 Property prop = null;
7180 DataMember member = null;
7181 ClassProperty classProp = null;
7183 if(_class && _class.type == enumClass)
7185 NamedLink64 value = null;
7186 Class enumClass = eSystem_FindClass(privateModule, "enum");
7190 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7192 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7193 for(value = e.values.first; value; value = value.next)
7195 if(!strcmp(value.name, id.string))
7200 exp.isConstant = true;
7201 if(inCompiler || inPreCompiler || inDebugger)
7204 FreeExpContents(exp);
7206 exp.type = constantExp;
7207 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7208 sprintf(constant, FORMAT64D, value.data);
7210 sprintf(constant, FORMAT64HEX, value.data);
7211 exp.constant = CopyString(constant);
7213 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7214 exp.expType = MkClassType(baseClass.fullName);
7222 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7224 ProcessMethodType(method);
7231 // TOCHECK: Put it back to what it was...
7232 // methodClass = _class;
7233 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7238 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7241 ProcessPropertyType(prop);
7242 exp.expType = prop.dataType;
7243 if(prop.dataType) prop.dataType.refCount++;
7246 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7248 if(!member.dataType)
7249 member.dataType = ProcessTypeString(member.dataTypeString, false);
7250 exp.expType = member.dataType;
7251 if(member.dataType) member.dataType.refCount++;
7254 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7256 if(!classProp.dataType)
7257 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7259 if(classProp.constant)
7261 FreeExpContents(exp);
7263 exp.isConstant = true;
7264 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7266 //char constant[256];
7267 exp.type = stringExp;
7268 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7273 exp.type = constantExp;
7274 sprintf(constant, "%d", (int)classProp.Get(_class));
7275 exp.constant = CopyString(constant);
7283 exp.expType = classProp.dataType;
7284 if(classProp.dataType) classProp.dataType.refCount++;
7290 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7292 BinaryTree * tree = &nameSpace.functions;
7293 GlobalData data = (GlobalData)tree->FindString(name);
7297 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7299 data = ScanGlobalData(child, name);
7307 static GlobalData FindGlobalData(char * name)
7310 NameSpace * nameSpace;
7311 nameSpace = globalData;
7312 for(c = 0; name[c]; c++)
7314 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7316 NameSpace * newSpace;
7317 char * spaceName = new char[c - start + 1];
7318 strncpy(spaceName, name + start, c - start);
7319 spaceName[c-start] = '\0';
7320 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7324 nameSpace = newSpace;
7325 if(name[c] == ':') c++;
7331 return ScanGlobalData(nameSpace, name + start);
7336 static int definedExpStackPos;
7337 static void * definedExpStack[512];
7339 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7340 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7342 Expression prev = checkedExp.prev, next = checkedExp.next;
7344 FreeExpContents(checkedExp);
7345 FreeType(checkedExp.expType);
7346 FreeType(checkedExp.destType);
7348 *checkedExp = *newExp;
7352 checkedExp.prev = prev;
7353 checkedExp.next = next;
7356 void ApplyAnyObjectLogic(Expression e)
7358 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7360 char debugExpString[4096];
7361 debugExpString[0] = '\0';
7362 PrintExpression(e, debugExpString);
7365 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7367 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7368 //ellipsisDestType = destType;
7371 Type type = e.expType;
7372 Class _class = null;
7373 //Type destType = e.destType;
7375 if(type.kind == classType && type._class && type._class.registered)
7377 _class = type._class.registered;
7379 else if(type.kind == subClassType)
7381 _class = FindClass("ecere::com::Class").registered;
7385 char string[1024] = "";
7388 PrintTypeNoConst(type, string, false, true);
7389 classSym = FindClass(string);
7390 if(classSym) _class = classSym.registered;
7393 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "uintptr") && strcmp(_class.fullName, "intptr")) || // Patched so that class isn't considered SYSTEM...
7394 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != intPtrType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
7395 destType.byReference)))
7397 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7399 Expression checkedExp = e, newExp;
7401 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7403 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7405 if(checkedExp.type == extensionCompoundExp)
7407 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7410 checkedExp = checkedExp.list->last;
7412 else if(checkedExp.type == castExp)
7413 checkedExp = checkedExp.cast.exp;
7416 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7418 newExp = checkedExp.op.exp2;
7419 checkedExp.op.exp2 = null;
7420 FreeExpContents(checkedExp);
7422 if(e.expType && e.expType.passAsTemplate)
7425 ComputeTypeSize(e.expType);
7426 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7427 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7428 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7429 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7432 ReplaceExpContents(checkedExp, newExp);
7433 e.byReference = true;
7435 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7437 Expression checkedExp; //, newExp;
7440 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7442 e.type == identifierExp ||
7443 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7444 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7445 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7448 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7450 Context context = PushContext();
7452 OldList * specs = MkList();
7453 char typeString[1024];
7454 Expression newExp { };
7456 typeString[0] = '\0';
7459 //if(e.destType) e.destType.refCount++;
7460 // if(exp.expType) exp.expType.refCount++;
7463 newExp.expType = null;
7465 PrintTypeNoConst(e.expType, typeString, false, true);
7466 decl = SpecDeclFromString(typeString, specs, null);
7467 newExp.destType = ProcessType(specs, decl);
7469 curContext = context;
7471 // We need a current compound for this
7475 OldList * stmts = MkList();
7476 e.type = extensionCompoundExp;
7477 sprintf(name, "__internalValue%03X", internalValueCounter++);
7478 if(!curCompound.compound.declarations)
7479 curCompound.compound.declarations = MkList();
7480 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7481 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7482 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7483 e.compound = MkCompoundStmt(null, stmts);
7486 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7489 e.compound = MkCompoundStmt(
7490 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7491 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7493 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7497 Type type = e.destType;
7499 CopyTypeInto(e.destType, type);
7500 e.destType.refCount = 1;
7501 e.destType.classObjectType = none;
7505 e.compound.compound.context = context;
7506 PopContext(context);
7507 curContext = context.parent;
7511 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7513 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7515 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7517 if(checkedExp.type == extensionCompoundExp)
7519 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7522 checkedExp = checkedExp.list->last;
7524 else if(checkedExp.type == castExp)
7525 checkedExp = checkedExp.cast.exp;
7528 Expression operand { };
7529 operand = *checkedExp;
7531 checkedExp.destType = ProcessTypeString("void *", false);
7532 checkedExp.expType = checkedExp.destType;
7533 checkedExp.destType.refCount++;
7535 checkedExp.type = opExp;
7536 checkedExp.op.op = '&';
7537 checkedExp.op.exp1 = null;
7538 checkedExp.op.exp2 = operand;
7540 //newExp = MkExpOp(null, '&', checkedExp);
7542 //ReplaceExpContents(checkedExp, newExp);
7549 // If expression type is a simple class, make it an address
7550 // FixReference(e, true);
7553 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7554 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7555 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7557 if(e.expType.classObjectType && destType && destType.classObjectType) //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7559 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7563 Expression thisExp { };
7566 thisExp.prev = null;
7567 thisExp.next = null;
7570 e.type = bracketsExp;
7571 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7572 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7573 ((Expression)e.list->first).byReference = true;
7575 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7577 e.expType = thisExp.expType;
7578 e.expType.refCount++;
7583 CopyTypeInto(e.expType, thisExp.expType);
7584 e.expType.byReference = false;
7585 e.expType.refCount = 1;
7587 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7588 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7590 e.expType.classObjectType = none;
7595 // TOFIX: Try this for a nice IDE crash!
7597 // The other way around
7600 if(destType && e.expType &&
7601 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7602 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7603 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7605 if(destType.kind == ellipsisType)
7607 Compiler_Error($"Unspecified type\n");
7609 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7611 bool byReference = e.expType.byReference;
7612 Expression thisExp { };
7614 OldList * specs = MkList();
7615 char typeString[1024]; // Watch buffer overruns
7617 ClassObjectType backupClassObjectType;
7618 bool backupByReference;
7620 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7625 backupClassObjectType = type.classObjectType;
7626 backupByReference = type.byReference;
7628 type.classObjectType = none;
7629 type.byReference = false;
7631 typeString[0] = '\0';
7632 PrintType(type, typeString, false, true);
7633 decl = SpecDeclFromString(typeString, specs, null);
7635 type.classObjectType = backupClassObjectType;
7636 type.byReference = backupByReference;
7639 thisExp.prev = null;
7640 thisExp.next = null;
7643 if( ( type.kind == classType && type._class && type._class.registered &&
7644 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7645 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7646 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7647 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7649 bool passAsTemplate = thisExp.destType.passAsTemplate;
7652 destType.refCount++;
7657 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7660 CopyTypeInto(t, thisExp.destType);
7661 t.passAsTemplate = false;
7662 FreeType(thisExp.destType);
7663 thisExp.destType = t;
7666 CopyTypeInto(t, destType);
7667 t.passAsTemplate = passAsTemplate;
7670 destType.refCount = 0;
7673 CopyTypeInto(e.expType, type);
7674 if(type.passAsTemplate)
7676 e.expType.classObjectType = none;
7677 e.expType.passAsTemplate = false;
7679 e.expType.byReference = false;
7680 e.expType.refCount = 1;
7685 e.cast.typeName = MkTypeName(specs, decl);
7686 e.cast.exp = thisExp;
7687 e.byReference = true;
7693 FreeType(e.destType);
7695 e.destType = destType;
7696 destType.refCount++;
7701 void ApplyLocation(Expression exp, Location loc)
7707 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7708 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7714 for(e = exp.list->first; e; e = e.next)
7715 ApplyLocation(e, loc);
7722 for(e = exp.index.index->first; e; e = e.next)
7723 ApplyLocation(e, loc);
7726 ApplyLocation(exp.index.exp, loc);
7729 if(exp.call.arguments)
7732 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7733 ApplyLocation(arg, loc);
7736 ApplyLocation(exp.call.exp, loc);
7741 ApplyLocation(exp.member.exp, loc);
7745 ApplyLocation(exp.cast.exp, loc);
7751 for(e = exp.cond.exp->first; e; e = e.next)
7752 ApplyLocation(e, loc);
7755 ApplyLocation(exp.cond.cond, loc);
7756 if(exp.cond.elseExp)
7757 ApplyLocation(exp.cond.elseExp, loc);
7761 ApplyLocation(exp.vaArg.exp, loc);
7768 void ProcessExpressionType(Expression exp)
7770 bool unresolved = false;
7771 Location oldyylloc = yylloc;
7772 bool notByReference = false;
7774 char debugExpString[4096];
7775 debugExpString[0] = '\0';
7776 PrintExpression(exp, debugExpString);
7778 if(!exp || exp.expType)
7781 //eSystem_Logf("%s\n", expString);
7783 // Testing this here
7789 Identifier id = exp.identifier;
7790 if(!id || !topContext) return;
7792 // DOING THIS LATER NOW...
7793 if(id._class && id._class.name)
7795 id.classSym = id._class.symbol; // FindClass(id._class.name);
7796 /* TODO: Name Space Fix ups
7798 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7802 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7804 exp.expType = ProcessTypeString("Module", true);
7808 if(!strcmp(id.string, "__runtimePlatform"))
7810 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7813 else if(strstr(id.string, "__ecereClass") == id.string)
7815 exp.expType = ProcessTypeString("ecere::com::Class", true);
7818 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7820 // Added this here as well
7821 ReplaceClassMembers(exp, thisClass);
7822 if(exp.type != identifierExp)
7824 ProcessExpressionType(exp);
7828 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7833 Symbol symbol = null;
7834 bool findInGlobal = false;
7835 if(!topContext.parent && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == enumClass)
7836 findInGlobal = true; // In global context, look at enum values first
7838 symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7840 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7841 if(!symbol/* && exp.destType*/)
7843 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7849 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7850 if(exp.type != identifierExp)
7852 ProcessExpressionType(exp);
7856 // Static methods called from inside the _class
7857 else if(currentClass && !id._class)
7859 if(ResolveIdWithClass(exp, currentClass, true))
7862 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7866 symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7868 // If we manage to resolve this symbol
7871 Type type = symbol.type;
7872 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7874 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7876 Context context = SetupTemplatesContext(_class);
7877 type = ReplaceThisClassType(_class);
7878 FinishTemplatesContext(context);
7879 if(type) type.refCount = 0; // We'll be incrementing it right below...
7882 FreeSpecifier(id._class);
7885 id.string = CopyString(symbol.string);
7892 // Commented this out, it was making non-constant enum parameters seen as constant
7893 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7894 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7895 // Add missing cases here... enum Classes...
7896 exp.isConstant = true;
7898 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7899 if(symbol.isParam || !strcmp(id.string, "this"))
7901 if(_class && _class.type == structClass && !type.declaredWithStruct)
7902 exp.byReference = true;
7904 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7905 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7906 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7907 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7909 Identifier id = exp.identifier;
7910 exp.type = bracketsExp;
7911 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7915 if(symbol.isIterator)
7917 if(symbol.isIterator == 3)
7919 exp.type = bracketsExp;
7920 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7921 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7923 ProcessExpressionType(exp);
7925 else if(symbol.isIterator != 4)
7927 exp.type = memberExp;
7928 exp.member.exp = MkExpIdentifier(exp.identifier);
7929 exp.member.exp.expType = exp.expType;
7930 /*if(symbol.isIterator == 6)
7931 exp.member.member = MkIdentifier("key");
7933 exp.member.member = MkIdentifier("data");
7935 ProcessExpressionType(exp);
7942 DefinedExpression definedExp = null;
7943 if(thisNameSpace && !(id._class && !id._class.name))
7946 strcpy(name, thisNameSpace);
7948 strcat(name, id.string);
7949 definedExp = eSystem_FindDefine(privateModule, name);
7952 definedExp = eSystem_FindDefine(privateModule, id.string);
7956 for(c = 0; c<definedExpStackPos; c++)
7957 if(definedExpStack[c] == definedExp)
7959 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7961 Location backupYylloc = yylloc;
7962 File backInput = fileInput;
7963 definedExpStack[definedExpStackPos++] = definedExp;
7965 fileInput = TempFile { };
7966 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7967 fileInput.Seek(0, start);
7970 parsedExpression = null;
7972 expression_yyparse();
7975 fileInput = backInput;
7977 yylloc = backupYylloc;
7979 if(parsedExpression)
7982 exp.type = bracketsExp;
7983 exp.list = MkListOne(parsedExpression);
7984 ApplyLocation(parsedExpression, yylloc);
7985 ProcessExpressionType(exp);
7986 definedExpStackPos--;
7989 definedExpStackPos--;
7995 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8001 GlobalData data = null;
8002 if(thisNameSpace && !(id._class && !id._class.name))
8005 strcpy(name, thisNameSpace);
8007 strcat(name, id.string);
8008 data = FindGlobalData(name);
8011 data = FindGlobalData(id.string);
8014 DeclareGlobalData(curExternal, data);
8015 exp.expType = data.dataType;
8016 if(data.dataType) data.dataType.refCount++;
8019 id.string = CopyString(data.fullName);
8020 FreeSpecifier(id._class);
8027 GlobalFunction function = null;
8028 if(thisNameSpace && !(id._class && !id._class.name))
8031 strcpy(name, thisNameSpace);
8033 strcat(name, id.string);
8034 function = eSystem_FindFunction(privateModule, name);
8037 function = eSystem_FindFunction(privateModule, id.string);
8042 id.string = CopyString(function.name);
8045 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8046 strcpy(name, "__ecereFunction_");
8047 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8048 if(DeclareFunction(curExternal, function, name))
8051 id.string = CopyString(name);
8053 exp.expType = function.dataType;
8054 if(function.dataType) function.dataType.refCount++;
8056 FreeSpecifier(id._class);
8073 if(!exp.instance._class)
8075 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8077 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8081 //classSym = FindClass(exp.instance._class.fullName);
8082 //_class = classSym ? classSym.registered : null;
8084 ProcessInstantiationType(exp.instance);
8086 exp.isConstant = exp.instance.isConstant;
8089 if(_class.type == unitClass && _class.base.type != systemClass)
8092 Type destType = exp.destType;
8094 exp.destType = MkClassType(_class.base.fullName);
8095 exp.expType = MkClassType(_class.fullName);
8096 CheckExpressionType(exp, exp.destType, true);
8098 exp.destType = destType;
8100 exp.expType = MkClassType(_class.fullName);
8103 if(exp.instance._class)
8105 exp.expType = MkClassType(exp.instance._class.name);
8106 /*if(exp.expType._class && exp.expType._class.registered &&
8107 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8108 exp.expType.byReference = true;*/
8116 char * constant = exp.constant;
8124 if(constant[0] == '\'')
8126 if((int)((byte *)constant)[1] > 127)
8129 unichar ch = UTF8GetChar(constant + 1, &nb);
8130 if(nb < 2) ch = constant[1];
8132 exp.constant = PrintUInt(ch);
8133 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8134 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8135 type._class = FindClass("unichar");
8137 type.isSigned = false;
8141 type.kind = charType;
8142 type.isSigned = true;
8147 char * dot = strchr(constant, '.');
8148 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8152 exponent = strchr(constant, 'p');
8153 if(!exponent) exponent = strchr(constant, 'P');
8157 exponent = strchr(constant, 'e');
8158 if(!exponent) exponent = strchr(constant, 'E');
8163 if(strchr(constant, 'f') || strchr(constant, 'F'))
8164 type.kind = floatType;
8166 type.kind = doubleType;
8167 type.isSigned = true;
8171 bool isSigned = constant[0] == '-';
8173 int64 i64 = strtoll(constant, &endP, 0);
8174 uint64 ui64 = strtoull(constant, &endP, 0);
8175 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8176 bool forceUnsigned = endP && (!strcmp(endP, "U") || !strcmp(endP, "u") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8189 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8193 else if(constant[0] != '0' || !constant[1])
8198 type.kind = is64Bit ? int64Type : intType;
8199 type.isSigned = isSigned;
8202 exp.isConstant = true;
8203 if(exp.destType && exp.destType.kind == doubleType)
8204 type.kind = doubleType;
8205 else if(exp.destType && exp.destType.kind == floatType)
8206 type.kind = floatType;
8207 else if(exp.destType && exp.destType.kind == int64Type)
8208 type.kind = int64Type;
8214 exp.isConstant = true; // Why wasn't this constant?
8222 kind = exp.wideString ? shortType : charType;
8224 isSigned = exp.wideString ? false : true;
8231 ProcessExpressionType(exp._new.size);
8236 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8238 DeclareType(curExternal, exp.expType.type, true, false);
8242 ProcessExpressionType(exp._renew.size);
8243 ProcessExpressionType(exp._renew.exp);
8248 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8250 DeclareType(curExternal, exp.expType.type, true, false);
8254 bool assign = false, boolResult = false, boolOps = false;
8255 Type type1 = null, type2 = null;
8256 bool useDestType = false, useSideType = false;
8257 Location oldyylloc = yylloc;
8258 bool useSideUnit = false;
8259 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8261 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8270 // Assignment Operators
8284 // boolean Operators
8286 // Expect boolean operators
8288 //boolResult = true;
8292 // Expect boolean operands
8303 // Gives boolean result
8316 // useSideType = true;
8317 // useDestType = true;
8335 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8341 /*// Implement speed etc.
8347 if(exp.op.op == '&')
8349 // Added this here earlier for Iterator address as key
8350 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8352 Identifier id = exp.op.exp2.identifier;
8353 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8354 if(symbol && symbol.isIterator == 2)
8356 exp.type = memberExp;
8357 exp.member.exp = exp.op.exp2;
8358 exp.member.member = MkIdentifier("key");
8360 exp.op.exp2.expType = symbol.type;
8361 symbol.type.refCount++;
8362 ProcessExpressionType(exp);
8366 // exp.op.exp2.usage.usageRef = true;
8370 //dummy.kind = TypeDummy;
8373 // Added this check here to use the dest type only for units derived from the base unit
8374 // So that untyped units will use the side unit as opposed to the untyped destination unit
8375 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8376 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8377 useDestType = false;
8379 if(destClass && useDestType &&
8380 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8382 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8384 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8385 exp.op.exp1.destType = exp.destType;
8386 exp.op.exp1.opDestType = true;
8388 exp.destType.refCount++;
8392 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8393 exp.op.exp1.destType = dummy;
8397 // TESTING THIS HERE...
8398 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8399 ProcessExpressionType(exp.op.exp1);
8400 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8402 exp.op.exp1.opDestType = false;
8404 // Fix for unit and ++ / --
8405 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8406 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8408 exp.op.exp2 = MkExpConstant("1");
8409 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8413 if(exp.op.exp1.destType == dummy)
8416 exp.op.exp1.destType = null;
8421 if(!assign && exp.op.exp1.expType && (exp.op.exp1.expType.kind == charType || exp.op.exp1.expType.kind == shortType))
8423 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 };
8424 FreeType(exp.op.exp1.expType);
8425 exp.op.exp1.expType = type;
8429 type1 = exp.op.exp1.expType;
8434 char expString[10240];
8435 expString[0] = '\0';
8436 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8440 exp.op.exp2.destType = exp.op.exp1.expType;
8441 if(exp.op.exp1.expType)
8442 exp.op.exp1.expType.refCount++;
8446 exp.op.exp2.destType = exp.destType;
8447 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8448 exp.op.exp2.opDestType = true;
8450 exp.destType.refCount++;
8453 if(type1) type1.refCount++;
8454 exp.expType = type1;
8459 PrintExpression(exp.op.exp2, expString);
8461 if(type1 && type1.kind == pointerType)
8463 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 ||
8464 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8465 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8466 else if(exp.op.op == '=')
8468 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8469 exp.op.exp2.destType = type1;
8476 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8477 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/* ||
8478 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8481 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8482 exp.op.exp2.destType = type1;
8487 if(type1) type1.refCount++;
8488 exp.expType = type1;
8490 else if(destClass &&
8491 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8492 (destClass.type == enumClass && useDestType)))
8494 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8495 exp.op.exp2.destType = exp.destType;
8496 if(exp.op.op != '&' && exp.op.op != '^')
8497 exp.op.exp2.opDestType = true;
8499 exp.destType.refCount++;
8503 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8504 exp.op.exp2.destType = dummy;
8508 // TESTING THIS HERE... (DANGEROUS)
8509 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8510 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8512 FreeType(exp.op.exp2.destType);
8513 exp.op.exp2.destType = type1;
8516 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8517 // Cannot lose the cast on a sizeof
8518 if(exp.op.op == SIZEOF)
8520 Expression e = exp.op.exp2;
8521 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8523 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8525 if(e.type == extensionCompoundExp)
8526 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8531 if(e.type == castExp && e.cast.exp)
8532 e.cast.exp.needCast = true;
8534 ProcessExpressionType(exp.op.exp2);
8535 exp.op.exp2.opDestType = false;
8536 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8538 if(!assign && (exp.op.exp1 || exp.op.op == '~'))
8540 if(exp.op.exp2.expType && (exp.op.exp2.expType.kind == charType || exp.op.exp2.expType.kind == shortType))
8542 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 };
8543 FreeType(exp.op.exp2.expType);
8544 exp.op.exp2.expType = type;
8548 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8550 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)
8552 if(exp.op.op != '=' && type1.type.kind == voidType)
8553 Compiler_Error($"void *: unknown size\n");
8555 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||
8556 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8557 (exp.op.exp2.expType._class.registered.type == normalClass ||
8558 exp.op.exp2.expType._class.registered.type == structClass ||
8559 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8561 if(exp.op.op == ADD_ASSIGN)
8562 Compiler_Error($"cannot add two pointers\n");
8564 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8565 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8567 if(exp.op.op == ADD_ASSIGN)
8568 Compiler_Error($"cannot add two pointers\n");
8572 char type1String[1024];
8573 char type2String[1024];
8574 type1String[0] = '\0';
8575 type2String[0] = '\0';
8577 PrintType(exp.op.exp2.expType, type1String, false, true);
8578 PrintType(type1, type2String, false, true);
8579 ChangeCh(expString, '\n', ' ');
8580 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8584 if(exp.op.exp2.destType == dummy)
8587 exp.op.exp2.destType = null;
8590 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8594 CopyTypeInto(type2, exp.op.exp2.expType);
8595 type2.isSigned = true;
8597 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8599 type2 = { kind = intType };
8601 type2.isSigned = true;
8605 type2 = exp.op.exp2.expType;
8606 if(type2) type2.refCount++;
8610 dummy.kind = voidType;
8612 if(exp.op.op == SIZEOF)
8619 exp.isConstant = true;
8621 // Get type of dereferenced pointer
8622 else if(exp.op.op == '*' && !exp.op.exp1)
8624 exp.expType = Dereference(type2);
8625 if(type2 && type2.kind == classType)
8626 notByReference = true;
8628 else if(exp.op.op == '&' && !exp.op.exp1)
8629 exp.expType = Reference(type2);
8630 else if(exp.op.op == LEFT_OP || exp.op.op == RIGHT_OP)
8632 if(exp.op.exp1.expType)
8634 exp.expType = exp.op.exp1.expType;
8635 exp.expType.refCount++;
8644 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8645 exp.op.exp1.destType = MkClassType("bool");
8646 exp.op.exp1.destType.truth = true;
8647 if(!exp.op.exp1.expType)
8648 ProcessExpressionType(exp.op.exp1);
8650 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8651 FreeType(exp.op.exp1.expType);
8652 exp.op.exp1.expType = MkClassType("bool");
8653 exp.op.exp1.expType.truth = true;
8657 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8658 exp.op.exp2.destType = MkClassType("bool");
8659 exp.op.exp2.destType.truth = true;
8660 if(!exp.op.exp2.expType)
8661 ProcessExpressionType(exp.op.exp2);
8663 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8664 FreeType(exp.op.exp2.expType);
8665 exp.op.exp2.expType = MkClassType("bool");
8666 exp.op.exp2.expType.truth = true;
8669 else if(exp.op.exp1 && exp.op.exp2 &&
8672 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8673 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8674 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8675 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8677 if(type1 && type2 &&
8678 // If either both are class or both are not class
8679 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8681 // Added this check for enum subtraction to result in an int type:
8682 if(exp.op.op == '-' &&
8683 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8684 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8687 if(!type1._class.registered.dataType)
8688 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8689 if(!type2._class.registered.dataType)
8690 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8692 intType = ProcessTypeString(
8693 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8695 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8696 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8697 exp.op.exp1.destType = intType;
8698 exp.op.exp2.destType = intType;
8703 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8704 exp.op.exp2.destType = type1;
8706 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8707 exp.op.exp1.destType = type2;
8711 // Warning here for adding Radians + Degrees with no destination type
8712 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8713 type1._class.registered && type1._class.registered.type == unitClass &&
8714 type2._class.registered && type2._class.registered.type == unitClass &&
8715 type1._class.registered != type2._class.registered)
8716 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8717 type1._class.string, type2._class.string, type1._class.string);
8719 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8721 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8724 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8726 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8727 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8730 ProcessExpressionType(exp.op.exp1);
8732 if(type2.kind != pointerType)
8734 ProcessExpressionType(classExp);
8736 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8738 if(!exp.op.exp2.expType)
8742 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8746 ProcessExpressionType(exp.op.exp2);
8751 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)))
8753 if(type1.kind != classType && type1.type.kind == voidType)
8754 Compiler_Error($"void *: unknown size\n");
8755 exp.expType = type1;
8756 if(type1) type1.refCount++;
8758 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)))
8760 if(type2.kind != classType && type2.type.kind == voidType)
8761 Compiler_Error($"void *: unknown size\n");
8762 exp.expType = type2;
8763 if(type2) type2.refCount++;
8765 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8766 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8768 Compiler_Warning($"different levels of indirection\n");
8772 bool success = false;
8773 if(type1.kind == pointerType && type2.kind == pointerType)
8775 if(exp.op.op == '+')
8776 Compiler_Error($"cannot add two pointers\n");
8777 else if(exp.op.op == '-')
8779 // Pointer Subtraction gives integer
8780 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8789 if(type1.type.kind == templateType)
8791 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8794 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8796 ProcessExpressionType(classExp);
8798 exp.type = bracketsExp;
8799 exp.list = MkListOne(MkExpOp(
8800 MkExpBrackets(MkListOne(MkExpOp(
8801 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8803 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8804 MkExpMember(classExp, MkIdentifier("typeSize"))));
8806 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8815 if(!success && exp.op.exp1.type == constantExp)
8817 // If first expression is constant, try to match that first
8818 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8820 if(exp.expType) FreeType(exp.expType);
8821 exp.expType = exp.op.exp1.destType;
8822 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8825 else 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++;
8835 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8837 if(exp.expType) FreeType(exp.expType);
8838 exp.expType = exp.op.exp2.destType;
8839 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8842 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8844 if(exp.expType) FreeType(exp.expType);
8845 exp.expType = exp.op.exp1.destType;
8846 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8852 char expString1[10240];
8853 char expString2[10240];
8856 expString1[0] = '\0';
8857 expString2[0] = '\0';
8862 PrintExpression(exp.op.exp1, expString1);
8863 ChangeCh(expString1, '\n', ' ');
8864 PrintExpression(exp.op.exp2, expString2);
8865 ChangeCh(expString2, '\n', ' ');
8866 PrintType(exp.op.exp1.expType, type1, false, true);
8867 PrintType(exp.op.exp2.expType, type2, false, true);
8870 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8874 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8875 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8877 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8878 // Convert e.g. / 4 into / 4.0
8879 exp.op.exp1.destType = type2._class.registered.dataType;
8880 if(type2._class.registered.dataType)
8881 type2._class.registered.dataType.refCount++;
8882 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8883 exp.expType = type2;
8884 if(type2) type2.refCount++;
8886 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8888 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8889 // Convert e.g. / 4 into / 4.0
8890 exp.op.exp2.destType = type1._class.registered.dataType;
8891 if(type1._class.registered.dataType)
8892 type1._class.registered.dataType.refCount++;
8893 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8894 exp.expType = type1;
8895 if(type1) type1.refCount++;
8901 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8903 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8905 if(!type1._class.registered.dataType)
8906 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8907 exp.op.exp2.destType = type1._class.registered.dataType;
8908 exp.op.exp2.destType.refCount++;
8910 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8913 type2 = exp.op.exp2.destType;
8914 if(type2) type2.refCount++;
8916 exp.expType = type2;
8920 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8922 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8924 if(!type2._class.registered.dataType)
8925 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8926 exp.op.exp1.destType = type2._class.registered.dataType;
8927 exp.op.exp1.destType.refCount++;
8929 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8930 type1 = exp.op.exp1.destType;
8931 exp.expType = type1;
8935 // TESTING THIS NEW CODE
8936 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8938 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8939 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8940 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8942 // Convert the enum to an int instead for these operators
8943 if(op1IsEnum && exp.op.exp2.expType)
8945 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8947 if(exp.expType) FreeType(exp.expType);
8948 exp.expType = exp.op.exp2.expType;
8949 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8953 else if(op2IsEnum && exp.op.exp1.expType)
8955 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8957 if(exp.expType) FreeType(exp.expType);
8958 exp.expType = exp.op.exp1.expType;
8959 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8966 if(op1IsEnum && exp.op.exp2.expType)
8968 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8970 if(exp.expType) FreeType(exp.expType);
8971 exp.expType = exp.op.exp1.expType;
8972 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8976 else if(op2IsEnum && exp.op.exp1.expType)
8978 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8980 if(exp.expType) FreeType(exp.expType);
8981 exp.expType = exp.op.exp2.expType;
8982 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8991 // 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
8992 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8993 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8995 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8996 exp.op.exp1.destType = type2;
8999 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9001 if(exp.expType) FreeType(exp.expType);
9002 exp.expType = exp.op.exp1.destType;
9003 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9008 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9009 exp.op.exp2.destType = type1;
9013 // Maybe this was meant to be an enum...
9014 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9016 Type oldType = exp.op.exp2.expType;
9017 exp.op.exp2.expType = null;
9018 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9021 exp.op.exp2.expType = oldType;
9026 // TESTING THIS HERE... LATEST ADDITION
9027 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9029 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9030 exp.op.exp2.destType = type2._class.registered.dataType;
9031 if(type2._class.registered.dataType)
9032 type2._class.registered.dataType.refCount++;
9033 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9035 //exp.expType = type2._class.registered.dataType; //type2;
9036 //if(type2) type2.refCount++;
9039 // TESTING THIS HERE... LATEST ADDITION
9040 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9042 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9043 exp.op.exp1.destType = type1._class.registered.dataType;
9044 if(type1._class.registered.dataType)
9045 type1._class.registered.dataType.refCount++;
9046 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9047 exp.expType = type1._class.registered.dataType; //type1;
9048 if(type1) type1.refCount++;
9052 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9054 if(exp.expType) FreeType(exp.expType);
9055 exp.expType = exp.op.exp2.destType;
9056 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9058 else if(type1 && type2)
9060 char expString1[10240];
9061 char expString2[10240];
9062 char type1String[1024];
9063 char type2String[1024];
9064 expString1[0] = '\0';
9065 expString2[0] = '\0';
9066 type1String[0] = '\0';
9067 type2String[0] = '\0';
9070 PrintExpression(exp.op.exp1, expString1);
9071 ChangeCh(expString1, '\n', ' ');
9072 PrintExpression(exp.op.exp2, expString2);
9073 ChangeCh(expString2, '\n', ' ');
9074 PrintType(exp.op.exp1.expType, type1String, false, true);
9075 PrintType(exp.op.exp2.expType, type2String, false, true);
9078 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9080 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9082 exp.expType = exp.op.exp1.expType;
9083 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9085 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9087 exp.expType = exp.op.exp2.expType;
9088 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9096 // Maybe this was meant to be an enum...
9097 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9099 Type oldType = exp.op.exp1.expType;
9100 exp.op.exp1.expType = null;
9101 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9104 exp.op.exp1.expType = oldType;
9107 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9108 exp.op.exp1.destType = type2;
9111 // TESTING THIS HERE... LATEST ADDITION
9112 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9114 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9115 exp.op.exp1.destType = type1._class.registered.dataType;
9116 if(type1._class.registered.dataType)
9117 type1._class.registered.dataType.refCount++;
9120 // TESTING THIS HERE... LATEST ADDITION
9121 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9123 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9124 exp.op.exp2.destType = type2._class.registered.dataType;
9125 if(type2._class.registered.dataType)
9126 type2._class.registered.dataType.refCount++;
9130 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9132 if(exp.expType) FreeType(exp.expType);
9133 exp.expType = exp.op.exp1.destType;
9134 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9138 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9140 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9142 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9143 // Convert e.g. / 4 into / 4.0
9144 exp.op.exp1.destType = type2._class.registered.dataType;
9145 if(type2._class.registered.dataType)
9146 type2._class.registered.dataType.refCount++;
9147 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9149 if(exp.op.op == '!')
9151 exp.expType = MkClassType("bool");
9152 exp.expType.truth = true;
9156 exp.expType = type2;
9157 if(type2) type2.refCount++;
9160 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9162 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9164 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9165 // Convert e.g. / 4 into / 4.0
9166 exp.op.exp2.destType = type1._class.registered.dataType;
9167 if(type1._class.registered.dataType)
9168 type1._class.registered.dataType.refCount++;
9169 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9171 exp.expType = type1;
9172 if(type1) type1.refCount++;
9177 if(exp.op.exp1 && !exp.op.exp1.expType)
9179 char expString[10000];
9180 expString[0] = '\0';
9183 PrintExpression(exp.op.exp1, expString);
9184 ChangeCh(expString, '\n', ' ');
9187 Compiler_Error($"couldn't determine type of %s\n", expString);
9189 if(exp.op.exp2 && !exp.op.exp2.expType)
9191 char expString[10240];
9192 expString[0] = '\0';
9195 PrintExpression(exp.op.exp2, expString);
9196 ChangeCh(expString, '\n', ' ');
9199 Compiler_Error($"couldn't determine type of %s\n", expString);
9204 FreeType(exp.expType);
9205 exp.expType = MkClassType("bool");
9206 exp.expType.truth = true;
9209 if(exp.op.op != SIZEOF)
9210 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9211 (!exp.op.exp2 || exp.op.exp2.isConstant);
9213 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9215 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9218 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9219 Compiler_Warning($"deleting const qualified object\n");
9229 case extensionExpressionExp:
9232 exp.isConstant = true;
9233 for(e = exp.list->first; e; e = e.next)
9235 //bool inced = false;
9238 FreeType(e.destType);
9239 e.opDestType = exp.opDestType;
9240 e.destType = exp.destType;
9241 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9243 ProcessExpressionType(e);
9245 exp.destType.count--;*/
9246 if(!exp.expType && !e.next)
9248 exp.expType = e.expType;
9249 if(e.expType) e.expType.refCount++;
9252 exp.isConstant = false;
9255 // In case a cast became a member...
9256 e = exp.list->first;
9257 if(!e.next && e.type == memberExp)
9259 // Preserve prev, next
9260 Expression next = exp.next, prev = exp.prev;
9263 FreeType(exp.expType);
9264 FreeType(exp.destType);
9274 ProcessExpressionType(exp);
9281 exp.isConstant = true;
9283 ProcessExpressionType(exp.index.exp);
9284 if(!exp.index.exp.isConstant)
9285 exp.isConstant = false;
9287 if(exp.index.exp.expType)
9289 Type source = exp.index.exp.expType;
9290 if(source.kind == classType && source._class && source._class.registered)
9292 Class _class = source._class.registered;
9293 Class c = _class.templateClass ? _class.templateClass : _class;
9294 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9296 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9298 if(exp.index.index && exp.index.index->last)
9300 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9302 if(type.kind == classType) type.constant = true;
9303 else if(type.kind == pointerType)
9306 while(t.kind == pointerType) t = t.type;
9310 ((Expression)exp.index.index->last).destType = type;
9316 for(e = exp.index.index->first; e; e = e.next)
9318 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9320 if(e.destType) FreeType(e.destType);
9321 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9323 ProcessExpressionType(e);
9326 // Check if this type is int
9329 exp.isConstant = false;
9333 exp.expType = Dereference(exp.index.exp.expType);
9335 DeclareType(curExternal, exp.expType, true, false);
9342 Type methodType = null;
9348 PrintExpression(exp.call.exp, name);
9349 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9351 //exp.call.exp.expType = null;
9352 PrintExpression(exp.call.exp, name);
9355 if(exp.call.exp.type == identifierExp)
9357 Expression idExp = exp.call.exp;
9358 Identifier id = idExp.identifier;
9359 if(!strcmp(id.string, "__builtin_frame_address"))
9361 exp.expType = ProcessTypeString("void *", true);
9362 if(exp.call.arguments && exp.call.arguments->first)
9363 ProcessExpressionType(exp.call.arguments->first);
9366 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9368 exp.expType = ProcessTypeString("int", true);
9369 if(exp.call.arguments && exp.call.arguments->first)
9370 ProcessExpressionType(exp.call.arguments->first);
9373 else if(!strcmp(id.string, "Max") ||
9374 !strcmp(id.string, "Min") ||
9375 !strcmp(id.string, "Sgn") ||
9376 !strcmp(id.string, "Abs"))
9378 Expression a = null;
9379 Expression b = null;
9380 Expression tempExp1 = null, tempExp2 = null;
9381 if((!strcmp(id.string, "Max") ||
9382 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9384 a = exp.call.arguments->first;
9385 b = exp.call.arguments->last;
9389 else if(exp.call.arguments->count == 1)
9391 a = exp.call.arguments->first;
9397 exp.call.arguments->Clear();
9398 idExp.identifier = null;
9400 FreeExpContents(exp);
9402 ProcessExpressionType(a);
9404 ProcessExpressionType(b);
9406 exp.type = bracketsExp;
9407 exp.list = MkList();
9409 if(a.expType && (!b || b.expType))
9411 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9413 // Use the simpleStruct name/ids for now...
9416 OldList * specs = MkList();
9417 OldList * decls = MkList();
9419 char temp1[1024], temp2[1024];
9421 GetTypeSpecs(a.expType, specs);
9423 if(a && !a.isConstant && a.type != identifierExp)
9425 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9426 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9427 tempExp1 = QMkExpId(temp1);
9428 tempExp1.expType = a.expType;
9430 a.expType.refCount++;
9431 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9433 if(b && !b.isConstant && b.type != identifierExp)
9435 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9436 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9437 tempExp2 = QMkExpId(temp2);
9438 tempExp2.expType = b.expType;
9440 b.expType.refCount++;
9441 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9444 decl = MkDeclaration(specs, decls);
9445 if(!curCompound.compound.declarations)
9446 curCompound.compound.declarations = MkList();
9447 curCompound.compound.declarations->Insert(null, decl);
9452 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9454 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9456 MkExpCondition(MkExpBrackets(MkListOne(
9457 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9458 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9459 exp.expType = a.expType;
9461 a.expType.refCount++;
9463 else if(!strcmp(id.string, "Abs"))
9466 MkExpCondition(MkExpBrackets(MkListOne(
9467 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9468 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9469 exp.expType = a.expType;
9471 a.expType.refCount++;
9473 else if(!strcmp(id.string, "Sgn"))
9475 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9477 MkExpCondition(MkExpBrackets(MkListOne(
9478 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9479 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9480 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9481 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9482 exp.expType = ProcessTypeString("int", false);
9485 FreeExpression(tempExp1);
9486 if(tempExp2) FreeExpression(tempExp2);
9500 if(!exp.call.exp.destType)
9502 exp.call.exp.destType = dummy;
9505 ProcessExpressionType(exp.call.exp);
9506 if(exp.call.exp.destType == dummy)
9509 exp.call.exp.destType = null;
9514 // Check argument types against parameter types
9515 functionType = exp.call.exp.expType;
9517 if(functionType && functionType.kind == TypeKind::methodType)
9519 methodType = functionType;
9520 functionType = methodType.method.dataType;
9522 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9523 // TOCHECK: Instead of doing this here could this be done per param?
9524 if(exp.call.exp.expType.usedClass)
9526 char typeString[1024];
9527 typeString[0] = '\0';
9529 Symbol back = functionType.thisClass;
9530 // Do not output class specifier here (thisclass was added to this)
9531 functionType.thisClass = null;
9532 PrintType(functionType, typeString, true, true);
9533 functionType.thisClass = back;
9535 if(strstr(typeString, "thisclass"))
9537 OldList * specs = MkList();
9540 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9542 decl = SpecDeclFromString(typeString, specs, null);
9544 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9545 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9546 exp.call.exp.expType.usedClass))
9547 thisClassParams = false;
9549 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9551 Class backupThisClass = thisClass;
9552 thisClass = exp.call.exp.expType.usedClass;
9553 ProcessDeclarator(decl, true);
9554 thisClass = backupThisClass;
9557 thisClassParams = true;
9559 functionType = ProcessType(specs, decl);
9560 functionType.refCount = 0;
9561 FinishTemplatesContext(context);
9563 // Mark parameters that were 'thisclass'
9566 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9568 //p.wasThisClass = op.kind == thisClassType;
9569 if(op.kind == thisClassType)
9570 p.thisClassFrom = methodType.method._class;
9573 if(methodType.method.dataType.returnType.kind == thisClassType)
9575 // functionType.returnType.wasThisClass = true;
9576 functionType.returnType.thisClassFrom = methodType.method._class;
9580 FreeList(specs, FreeSpecifier);
9581 FreeDeclarator(decl);
9585 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9587 Type type = functionType.type;
9588 if(!functionType.refCount)
9590 functionType.type = null;
9591 FreeType(functionType);
9593 //methodType = functionType;
9594 functionType = type;
9596 if(functionType && functionType.kind != TypeKind::functionType)
9598 Compiler_Error($"called object %s is not a function\n", name);
9600 else if(functionType)
9602 bool emptyParams = false, noParams = false;
9603 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9604 Type type = functionType.params.first;
9605 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9607 Location oldyylloc = yylloc;
9609 if(!type) emptyParams = true;
9612 if(functionType.extraParam && e && functionType.thisClass)
9614 e.destType = MkClassType(functionType.thisClass.string);
9618 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9619 // Fixed #141 by adding '&& !functionType.extraParam'
9620 if(!functionType.staticMethod && !functionType.extraParam)
9622 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9623 memberExp.member.exp.expType._class)
9625 type = MkClassType(memberExp.member.exp.expType._class.string);
9630 type = functionType.params.first;
9635 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9637 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9638 type.byReference = functionType.byReference;
9639 type.typedByReference = functionType.typedByReference;
9642 // Allow manually passing a class for typed object
9643 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9647 type = functionType.params.first;
9655 if(type && type.kind == voidType)
9658 if(!type.refCount) FreeType(type);
9662 for( ; e; e = e.next)
9664 if(!type && !emptyParams)
9667 if(methodType && methodType.methodClass)
9668 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9669 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9670 noParams ? 0 : functionType.params.count);
9672 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9673 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9674 noParams ? 0 : functionType.params.count);
9678 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9680 Type templatedType = null;
9681 Class _class = methodType.usedClass;
9682 ClassTemplateParameter curParam = null;
9684 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9687 for(sClass = _class; sClass; sClass = sClass.base)
9689 if(sClass.templateClass) sClass = sClass.templateClass;
9691 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9693 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9696 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9698 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9699 id += nextClass.templateParams.count;
9708 if(curParam && _class.templateArgs[id].dataTypeString)
9710 bool constant = type.constant;
9711 ClassTemplateArgument arg = _class.templateArgs[id];
9713 Context context = SetupTemplatesContext(_class);
9716 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9717 templatedType = ProcessTypeString(arg.dataTypeString, false);
9718 FinishTemplatesContext(context);
9721 if(templatedType.kind == classType && constant) templatedType.constant = true;
9722 else if(templatedType.kind == pointerType)
9724 Type t = templatedType.type;
9725 while(t.kind == pointerType) t = t.type;
9726 if(constant) t.constant = constant;
9729 e.destType = templatedType;
9732 templatedType.passAsTemplate = true;
9733 // templatedType.refCount++;
9739 if(type) type.refCount++;
9744 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9746 e.destType = type.prev;
9747 e.destType.refCount++;
9752 if(type) type.refCount++;
9755 // Don't reach the end for the ellipsis
9756 if(type && type.kind != ellipsisType)
9758 Type next = type.next;
9759 if(!type.refCount) FreeType(type);
9764 if(type && type.kind != ellipsisType)
9766 if(methodType && methodType.methodClass)
9767 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9768 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9769 functionType.params.count + extra);
9771 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9772 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9773 functionType.params.count + extra);
9776 if(type && !type.refCount) FreeType(type);
9783 kind = TypeKind::functionType;
9786 if(exp.call.exp.type == identifierExp)
9788 char * string = exp.call.exp.identifier.string;
9792 Location oldyylloc = yylloc;
9794 yylloc = exp.call.exp.identifier.loc;
9795 if(strstr(string, "__builtin_") == string)
9799 functionType.returnType = exp.destType;
9800 exp.destType.refCount++;
9804 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9805 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9806 globalContext.symbols.Add((BTNode)symbol);
9807 if(strstr(symbol.string, "::"))
9808 globalContext.hasNameSpace = true;
9813 else if(exp.call.exp.type == memberExp)
9815 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9816 exp.call.exp.member.member.string);*/
9819 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9821 if(!functionType.returnType)
9823 functionType.returnType = Type
9830 if(functionType && functionType.kind == TypeKind::functionType)
9832 exp.expType = functionType.returnType;
9834 if(functionType.returnType)
9835 functionType.returnType.refCount++;
9837 if(!functionType.refCount)
9838 FreeType(functionType);
9841 if(exp.call.arguments)
9843 for(e = exp.call.arguments->first; e; e = e.next)
9844 ProcessExpressionType(e);
9851 Location oldyylloc = yylloc;
9853 Expression checkExp = exp.member.exp;
9856 if(checkExp.type == castExp)
9857 checkExp = checkExp.cast.exp;
9858 else if(checkExp.type == bracketsExp)
9859 checkExp = checkExp.list ? checkExp.list->first : null;
9864 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9865 exp.thisPtr = thisPtr;
9867 // DOING THIS LATER NOW...
9868 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9870 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9871 /* TODO: Name Space Fix ups
9872 if(!exp.member.member.classSym)
9873 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9877 ProcessExpressionType(exp.member.exp);
9878 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9879 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9881 exp.isConstant = false;
9884 exp.isConstant = exp.member.exp.isConstant;
9885 type = exp.member.exp.expType;
9889 if(type && (type.kind == templateType))
9891 Class _class = thisClass ? thisClass : currentClass;
9892 ClassTemplateParameter param = null;
9895 for(param = _class.templateParams.first; param; param = param.next)
9897 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9901 if(param && param.defaultArg.member)
9903 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9906 Expression expMember = exp.member.exp;
9908 OldList * specs = MkList();
9909 char thisClassTypeString[1024];
9911 FreeIdentifier(exp.member.member);
9913 ProcessExpressionType(argExp);
9916 char * colon = strstr(param.defaultArg.memberString, "::");
9919 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9920 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9923 strcpy(thisClassTypeString, _class.fullName);
9926 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9928 exp.expType = ProcessType(specs, decl);
9929 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9931 Class expClass = exp.expType._class.registered;
9932 Class cClass = null;
9936 char templateString[1024];
9937 ClassTemplateParameter param;
9938 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9939 for(cClass = expClass; cClass; cClass = cClass.base)
9942 for(param = cClass.templateParams.first; param; param = param.next)
9946 ClassTemplateArgument arg;
9947 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9948 arg = expClass.templateArgs[id];
9950 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9952 ClassTemplateParameter cParam;
9953 //int p = numParams - sClass.templateParams.count;
9956 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9958 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9960 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9962 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9964 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9965 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9977 strcat(argument, arg.name.string);
9978 strcat(argument, " = ");
9984 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9985 char expString[1024];
9986 OldList * specs = MkList();
9987 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9989 char * string = PrintHexUInt64(arg.expression.ui64);
9990 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9993 ProcessExpressionType(exp);
9994 ComputeExpression(exp);
9995 expString[0] = '\0';
9996 PrintExpression(exp, expString);
9997 strcat(argument, expString);
9999 FreeExpression(exp);
10004 strcat(argument, arg.member.name);
10007 case TemplateParameterType::type:
10009 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10011 if(!strcmp(arg.dataTypeString, "thisclass"))
10012 strcat(argument, thisClassTypeString);
10014 strcat(argument, arg.dataTypeString);
10021 if(paramCount) strcat(templateString, ", ");
10022 if(lastParam != p - 1)
10024 strcat(templateString, param.name);
10025 strcat(templateString, " = ");
10027 strcat(templateString, argument);
10036 int len = strlen(templateString);
10037 if(templateString[len-1] == '>') templateString[len++] = ' ';
10038 templateString[len++] = '>';
10039 templateString[len++] = '\0';
10042 Context context = SetupTemplatesContext(_class);
10043 FreeType(exp.expType);
10044 exp.expType = ProcessTypeString(templateString, false);
10045 FinishTemplatesContext(context);
10049 if(!expMember.expType.isPointerType)
10050 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10051 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10052 exp.type = bracketsExp;
10053 exp.list = MkListOne(MkExpOp(null, '*',
10056 exp.op.exp1 = null;
10058 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10059 MkExpBrackets(MkListOne(
10060 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10063 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10065 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10070 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10071 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10073 type = ProcessTemplateParameterType(type.templateParameter);
10076 // TODO: *** This seems to be where we should add method support for all basic types ***
10077 if(type && (type.kind == templateType));
10078 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10079 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10080 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10081 (type.kind == pointerType && type.type.kind == charType)))
10083 Identifier id = exp.member.member;
10084 TypeKind typeKind = type.kind;
10085 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10086 if(typeKind == subClassType && exp.member.exp.type == classExp)
10088 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10089 typeKind = classType;
10094 if(typeKind == intType || typeKind == enumType)
10095 _class = eSystem_FindClass(privateModule, "int");
10098 if(type.kind == classType && type._class && type._class.registered)
10100 _class = type._class.registered;
10102 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10104 _class = FindClass("char *").registered;
10106 else if(type.kind == pointerType)
10108 _class = eSystem_FindClass(privateModule, "uintptr");
10109 FreeType(exp.expType);
10110 exp.expType = ProcessTypeString("uintptr", false);
10111 exp.byReference = true;
10115 char string[1024] = "";
10117 PrintTypeNoConst(type, string, false, true);
10118 classSym = FindClass(string);
10119 if(classSym) _class = classSym.registered;
10127 (exp.member.exp.type == identifierExp &&
10128 !strcmp(exp.member.exp.identifier.string, "this"));*/
10129 Property prop = null;
10130 Method method = null;
10131 DataMember member = null;
10132 Property revConvert = null;
10133 ClassProperty classProp = null;
10135 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10136 exp.member.memberType = propertyMember;
10138 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10139 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10141 if(typeKind != subClassType)
10143 // Prioritize data members over properties for "this"
10144 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10146 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10147 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10149 prop = eClass_FindProperty(_class, id.string, privateModule);
10153 if(!member && !prop)
10154 prop = eClass_FindProperty(_class, id.string, privateModule);
10155 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10156 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10157 exp.member.thisPtr = true;
10159 // Prioritize properties over data members otherwise
10162 bool useMemberForNonConst = false;
10163 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10166 prop = eClass_FindProperty(_class, id.string, null);
10168 useMemberForNonConst = prop && exp.destType &&
10169 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10170 !strncmp(prop.dataTypeString, "const ", 6);
10172 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10173 member = eClass_FindDataMember(_class, id.string, null, null, null);
10176 if((!prop || useMemberForNonConst) && !member)
10178 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10181 prop = eClass_FindProperty(_class, id.string, privateModule);
10183 useMemberForNonConst |= prop && exp.destType &&
10184 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10185 !strncmp(prop.dataTypeString, "const ", 6);
10187 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10188 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10194 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10201 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10202 method = eClass_FindMethod(_class, id.string, privateModule);
10203 if(!prop && !member && !method)
10205 if(typeKind == subClassType)
10207 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10210 exp.member.memberType = classPropertyMember;
10211 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10215 // Assume this is a class_data member
10216 char structName[1024];
10217 Identifier id = exp.member.member;
10218 Expression classExp = exp.member.exp;
10221 FreeType(classExp.expType);
10222 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10224 strcpy(structName, "__ecereClassData_");
10225 FullClassNameCat(structName, type._class.string, false);
10226 exp.type = pointerExp;
10227 exp.member.member = id;
10229 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10230 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10231 MkExpBrackets(MkListOne(MkExpOp(
10232 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10233 MkExpMember(classExp, MkIdentifier("data"))), '+',
10234 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10239 ProcessExpressionType(exp);
10245 // Check for reverse conversion
10246 // (Convert in an instantiation later, so that we can use
10247 // deep properties system)
10248 Symbol classSym = FindClass(id.string);
10251 Class convertClass = classSym.registered;
10253 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10258 //if(!exp.member.exp.destType)
10259 if(exp.member.exp.destType)
10260 FreeType(exp.member.exp.destType);
10262 if(method && !method._class.symbol)
10263 method._class.symbol = FindClass(method._class.fullName);
10264 if(prop && !prop._class.symbol)
10265 prop._class.symbol = FindClass(prop._class.fullName);
10267 exp.member.exp.destType = Type
10271 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10272 // wasThisClass = type ? type.wasThisClass : false;
10273 thisClassFrom = type ? type.thisClassFrom : null;
10279 exp.member.memberType = propertyMember;
10281 ProcessPropertyType(prop);
10282 exp.expType = prop.dataType;
10283 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10286 CopyTypeInto(type, exp.expType);
10288 type.constant = true;
10289 exp.expType = type;
10291 else if(prop.dataType)
10292 prop.dataType.refCount++;
10296 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10298 FreeExpContents(exp);
10299 exp.type = identifierExp;
10300 exp.identifier = MkIdentifier("class");
10301 ProcessExpressionType(exp);
10305 exp.member.memberType = dataMember;
10306 DeclareStruct(curExternal, _class.fullName, false, true);
10307 if(member._class != _class)
10308 DeclareStruct(curExternal, member._class.fullName, false, true);
10310 if(!member.dataType)
10312 Context context = SetupTemplatesContext(_class);
10313 member.dataType = ProcessTypeString(member.dataTypeString, false);
10314 FinishTemplatesContext(context);
10316 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)
10317 member.dataType.bitMemberSize = ((BitMember)member).size;
10318 exp.expType = member.dataType;
10319 if(member.dataType) member.dataType.refCount++;
10321 else if(revConvert)
10323 exp.member.memberType = reverseConversionMember;
10324 exp.expType = MkClassType(revConvert._class.fullName);
10332 exp.type = identifierExp;
10333 exp.identifier = exp.member.member;
10336 exp.member.memberType = methodMember;
10338 if(!method.dataType)
10339 ProcessMethodType(method);
10347 // Tricky spot here... To use instance versus class virtual table
10348 // Put it back to what it was... What did we break?
10350 // Had to put it back for overriding Main of Thread global instance
10352 //exp.expType.methodClass = _class;
10353 exp.expType.methodClass = (id && id._class) ? _class : null;
10355 // Need the actual class used for templated classes
10356 exp.expType.usedClass = _class;
10358 else if(!classProp)
10360 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10362 FreeExpContents(exp);
10363 exp.type = identifierExp;
10364 exp.identifier = MkIdentifier("class");
10365 FreeType(exp.expType);
10366 exp.expType = MkClassType("ecere::com::Class");
10369 yylloc = exp.member.member.loc;
10370 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10372 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10375 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10379 tClass = type._class && type._class.registered ? type._class.registered : _class;
10380 while(tClass && !tClass.templateClass) tClass = tClass.base;
10382 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10385 ClassTemplateParameter curParam = null;
10388 for(sClass = tClass; sClass; sClass = sClass.base)
10391 if(sClass.templateClass) sClass = sClass.templateClass;
10392 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10394 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10396 for(sClass = sClass.base; sClass; sClass = sClass.base)
10397 id += sClass.templateParams.count;
10402 if(curParam) break;
10405 if(curParam && tClass.templateArgs[id].dataTypeString)
10407 ClassTemplateArgument arg = tClass.templateArgs[id];
10408 Context context = SetupTemplatesContext(tClass);
10409 bool constant = exp.expType.constant;
10410 bool passAsTemplate = false;
10411 Class thisClassFrom = null;
10412 Type t = ProcessTypeString(exp.expType.templateParameter.dataTypeString, false);
10413 if(t && t.kind == classType && t._class)
10414 thisClassFrom = t._class.registered;
10416 // Mark that 'thisClassFrom' was set to something
10417 thisClassFrom = eSystem_FindClass(GetPrivateModule(), "class");
10421 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10422 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10424 /*if(!arg.dataType)
10425 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10426 FreeType(exp.expType);
10428 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10429 exp.expType.thisClassFrom = thisClassFrom;
10430 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10431 else if(exp.expType.kind == pointerType)
10433 Type t = exp.expType.type;
10434 while(t.kind == pointerType) t = t.type;
10435 if(constant) t.constant = constant;
10439 if(exp.expType.kind == thisClassType)
10441 FreeType(exp.expType);
10442 exp.expType = ReplaceThisClassType(_class);
10446 exp.expType.passAsTemplate = true;
10447 //exp.expType.refCount++;
10450 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10451 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10452 else if(exp.destType.kind == pointerType)
10454 Type t = exp.destType.type;
10455 while(t.kind == pointerType) t = t.type;
10456 if(constant) t.constant = constant;
10459 //exp.destType.refCount++;
10461 if(exp.destType.kind == thisClassType)
10463 FreeType(exp.destType);
10464 exp.destType = ReplaceThisClassType(_class);
10468 FinishTemplatesContext(context);
10471 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10472 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10475 ClassTemplateParameter curParam = null;
10478 for(sClass = tClass; sClass; sClass = sClass.base)
10481 if(sClass.templateClass) sClass = sClass.templateClass;
10482 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10484 if(curParam.type == TemplateParameterType::type &&
10485 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10487 for(sClass = sClass.base; sClass; sClass = sClass.base)
10488 id += sClass.templateParams.count;
10493 if(curParam) break;
10498 ClassTemplateArgument arg = tClass.templateArgs[id];
10499 Context context = SetupTemplatesContext(tClass);
10501 /*if(!arg.dataType)
10502 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10504 basicType = ProcessTypeString(arg.dataTypeString, false);
10507 if(basicType.kind == thisClassType)
10509 FreeType(basicType);
10510 basicType = ReplaceThisClassType(_class);
10513 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10514 if(tClass.templateClass)
10515 basicType.passAsTemplate = true;
10518 FreeType(exp.expType);
10520 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10521 //exp.expType.refCount++;
10524 exp.destType = exp.expType;
10525 exp.destType.refCount++;
10529 Expression newExp { };
10530 OldList * specs = MkList();
10532 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10534 if(exp.destType) exp.destType.refCount++;
10535 if(exp.expType) exp.expType.refCount++;
10536 exp.type = castExp;
10537 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10538 exp.cast.exp = newExp;
10539 //FreeType(exp.expType);
10540 //exp.expType = null;
10541 //ProcessExpressionType(sourceExp);
10544 FinishTemplatesContext(context);
10547 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10549 Class expClass = exp.expType._class.registered;
10552 Class cClass = null;
10554 int paramCount = 0;
10555 int lastParam = -1;
10556 char templateString[1024];
10557 ClassTemplateParameter param;
10558 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10559 while(cClass != expClass)
10562 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10565 for(param = cClass.templateParams.first; param; param = param.next)
10567 Class cClassCur = null;
10569 ClassTemplateParameter paramCur = null;
10570 ClassTemplateArgument arg;
10571 while(cClassCur != tClass && !paramCur)
10574 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10575 cClassCur = sClassCur;
10577 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10579 if(!strcmp(paramCur.name, param.name))
10587 if(paramCur && paramCur.type == TemplateParameterType::type)
10588 arg = tClass.templateArgs[cp];
10590 arg = expClass.templateArgs[p];
10593 char argument[256];
10594 argument[0] = '\0';
10597 strcat(argument, arg.name.string);
10598 strcat(argument, " = ");
10604 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10605 char expString[1024];
10606 OldList * specs = MkList();
10607 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10609 char * string = PrintHexUInt64(arg.expression.ui64);
10610 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10613 ProcessExpressionType(exp);
10614 ComputeExpression(exp);
10615 expString[0] = '\0';
10616 PrintExpression(exp, expString);
10617 strcat(argument, expString);
10619 FreeExpression(exp);
10624 strcat(argument, arg.member.name);
10627 case TemplateParameterType::type:
10629 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10630 strcat(argument, arg.dataTypeString);
10636 if(paramCount) strcat(templateString, ", ");
10637 if(lastParam != p - 1)
10639 strcat(templateString, param.name);
10640 strcat(templateString, " = ");
10642 strcat(templateString, argument);
10651 int len = strlen(templateString);
10652 if(templateString[len-1] == '>') templateString[len++] = ' ';
10653 templateString[len++] = '>';
10654 templateString[len++] = '\0';
10657 FreeType(exp.expType);
10659 Context context = SetupTemplatesContext(tClass);
10660 exp.expType = ProcessTypeString(templateString, false);
10661 FinishTemplatesContext(context);
10668 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10670 else if(type && (type.kind == structType || type.kind == unionType))
10672 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10675 exp.expType = memberType;
10677 memberType.refCount++;
10682 char expString[10240];
10683 expString[0] = '\0';
10684 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10685 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10688 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10690 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10692 Identifier id = exp.member.member;
10693 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10696 FreeType(exp.expType);
10697 exp.expType = ReplaceThisClassType(_class);
10701 yylloc = oldyylloc;
10704 // Convert x->y into (*x).y
10707 Type destType = exp.destType;
10709 // DOING THIS LATER NOW...
10710 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10712 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10713 /* TODO: Name Space Fix ups
10714 if(!exp.member.member.classSym)
10715 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10719 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10720 exp.type = memberExp;
10723 ProcessExpressionType(exp);
10730 //ComputeExpression(exp);
10732 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10733 if(classSym && classSym.registered)
10735 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10738 Class b = classSym.registered;
10740 DeclareStruct(curExternal, classSym.string, false, true);
10741 FreeSpecifier(exp._class);
10742 FullClassNameCat(name, classSym.string, false);
10746 exp.type = typeSizeExp;
10747 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10753 if(b.structSize == b.offset)
10754 exp.op.exp1 = MkExpConstant("0");
10756 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10759 while(b.offset != 0)
10762 Expression typeSize;
10765 sym = FindClass(b.fullName);
10768 DeclareStruct(curExternal, sym.string, false, true);
10769 FullClassNameCat(name, sym.string, false);
10771 if(b.structSize == b.offset)
10772 typeSize = MkExpConstant("0");
10774 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10775 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10782 if(classSym.registered.fixed && !classSym.registered.structSize)
10784 FreeSpecifier(exp._class);
10785 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10786 exp.type = constantExp;
10790 char className[1024];
10791 strcpy(className, "__ecereClass_");
10792 FullClassNameCat(className, classSym.string, true);
10794 DeclareClass(curExternal, classSym, className);
10796 FreeExpContents(exp);
10797 exp.type = pointerExp;
10798 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10799 exp.member.member = MkIdentifier("structSize");
10807 kind = intSizeType;
10809 // exp.isConstant = true;
10814 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10819 kind = intSizeType;
10821 exp.isConstant = true;
10823 DeclareType(curExternal, type, true, false);
10829 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10831 FreeType(exp.cast.exp.destType);
10832 exp.cast.exp.destType = type;
10834 type.casted = true;
10835 ProcessExpressionType(exp.cast.exp);
10836 type.casted = false;
10838 exp.expType = type;
10841 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10842 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10844 void * prev = exp.prev, * next = exp.next;
10845 Type expType = exp.cast.exp.destType;
10846 Expression castExp = exp.cast.exp;
10847 Type destType = exp.destType;
10849 if(expType) expType.refCount++;
10851 //FreeType(exp.destType);
10852 FreeType(exp.expType);
10853 FreeTypeName(exp.cast.typeName);
10856 FreeType(exp.expType);
10857 FreeType(exp.destType);
10859 exp.expType = expType;
10860 exp.destType = destType;
10870 exp.isConstant = exp.cast.exp.isConstant;
10875 case extensionInitializerExp:
10877 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10878 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10879 // ProcessInitializer(exp.initializer.initializer, type);
10880 exp.expType = type;
10885 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10886 ProcessExpressionType(exp.vaArg.exp);
10887 exp.expType = type;
10893 Type t = exp.destType;
10894 if(t && !exp.destType.casted)
10897 CopyTypeInto(t, exp.destType);
10903 exp.isConstant = true;
10905 FreeType(exp.cond.cond.destType);
10906 exp.cond.cond.destType = MkClassType("bool");
10907 exp.cond.cond.destType.truth = true;
10908 ProcessExpressionType(exp.cond.cond);
10909 if(!exp.cond.cond.isConstant)
10910 exp.isConstant = false;
10911 for(e = exp.cond.exp->first; e; e = e.next)
10915 FreeType(e.destType);
10917 if(e.destType) e.destType.refCount++;
10919 ProcessExpressionType(e);
10922 exp.expType = e.expType;
10923 if(e.expType) e.expType.refCount++;
10926 exp.isConstant = false;
10929 FreeType(exp.cond.elseExp.destType);
10930 // Added this check if we failed to find an expType
10931 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10934 exp.cond.elseExp.destType = t ? t : exp.expType;
10936 if(exp.cond.elseExp.destType)
10937 exp.cond.elseExp.destType.refCount++;
10938 ProcessExpressionType(exp.cond.elseExp);
10940 // FIXED THIS: Was done before calling process on elseExp
10941 if(!exp.cond.elseExp.isConstant)
10942 exp.isConstant = false;
10947 case extensionCompoundExp:
10949 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10951 Statement last = exp.compound.compound.statements->last;
10952 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10954 ((Expression)last.expressions->last).destType = exp.destType;
10956 exp.destType.refCount++;
10958 ProcessStatement(exp.compound);
10959 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10961 exp.expType.refCount++;
10967 Specifier spec = exp._classExp.specifiers->first;
10968 if(spec && spec.type == nameSpecifier)
10970 exp.expType = MkClassType(spec.name);
10971 exp.expType.kind = subClassType;
10972 exp.byReference = true;
10976 exp.expType = MkClassType("ecere::com::Class");
10977 exp.byReference = true;
10983 Class _class = thisClass ? thisClass : currentClass;
10986 Identifier id = exp.classData.id;
10987 char structName[1024];
10988 Expression classExp;
10989 strcpy(structName, "__ecereClassData_");
10990 FullClassNameCat(structName, _class.fullName, false);
10991 exp.type = pointerExp;
10992 exp.member.member = id;
10993 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10994 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10996 classExp = MkExpIdentifier(MkIdentifier("class"));
10998 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10999 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
11000 MkExpBrackets(MkListOne(MkExpOp(
11001 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
11002 MkExpMember(classExp, MkIdentifier("data"))), '+',
11003 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
11006 ProcessExpressionType(exp);
11014 const char * typeString = null;
11015 char typeStringBuf[1024];
11016 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11017 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11019 Class templateClass = exp.destType._class.registered;
11020 typeString = templateClass.templateArgs[2].dataTypeString;
11024 // Guess type from expressions in the array
11026 for(e = exp.list->first; e; e = e.next)
11028 ProcessExpressionType(e);
11031 if(!type) { type = e.expType; type.refCount++; }
11034 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11035 if(!MatchTypeExpression(e, type, null, false, true))
11041 e = exp.list->first;
11042 ProcessExpressionType(e);
11045 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11046 if(!MatchTypeExpression(e, type, null, false, true))
11048 FreeType(e.expType);
11059 FreeType(e.expType);
11066 typeStringBuf[0] = '\0';
11067 PrintTypeNoConst(type, typeStringBuf, false, true);
11068 typeString = typeStringBuf;
11076 (Container)& (struct BuiltInContainer)
11078 ._vTbl = class(BuiltInContainer)._vTbl,
11079 ._class = class(BuiltInContainer),
11081 .data = (int[]){ 1, 7, 3, 4, 5 },
11083 .type = class(int),
11086 char templateString[1024];
11087 OldList * initializers = MkList();
11088 OldList * structInitializers = MkList();
11089 OldList * specs = MkList();
11091 Declarator decl = SpecDeclFromString(typeString, specs, null);
11092 sprintf(templateString, "Container<%s>", typeString);
11097 type = ProcessTypeString(typeString, false);
11098 while((e = exp.list->first))
11100 exp.list->Remove(e);
11103 ProcessExpressionType(e);
11104 ListAdd(initializers, MkInitializerAssignment(e));
11110 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11112 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11113 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11114 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11115 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11116 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11117 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11118 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11119 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11120 MkInitializerList(initializers))));
11121 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11122 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11123 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11124 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11125 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11126 exp.expType = ProcessTypeString(templateString, false);
11127 exp.type = bracketsExp;
11128 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11130 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11131 MkInitializerList(structInitializers)))));
11132 ProcessExpressionType(expExt);
11136 exp.expType = ProcessTypeString("Container", false);
11137 Compiler_Error($"Couldn't determine type of array elements\n");
11143 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11145 FreeType(exp.expType);
11146 exp.expType = ReplaceThisClassType(thisClass);
11149 // Resolve structures here
11150 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11152 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11153 // TODO: Fix members reference...
11156 if(exp.expType.kind != enumType)
11159 String enumName = CopyString(exp.expType.enumName);
11161 // Fixed a memory leak on self-referencing C structs typedefs
11162 // by instantiating a new type rather than simply copying members
11163 // into exp.expType
11164 FreeType(exp.expType);
11165 exp.expType = Type { };
11166 exp.expType.kind = symbol.type.kind;
11167 exp.expType.refCount++;
11168 exp.expType.enumName = enumName;
11170 exp.expType.members = symbol.type.members;
11171 for(member = symbol.type.members.first; member; member = member.next)
11176 NamedLink64 member;
11177 for(member = symbol.type.members.first; member; member = member.next)
11179 NamedLink64 value { name = CopyString(member.name) };
11180 exp.expType.members.Add(value);
11186 // Trying to do this here before conversion properties kick in and this becomes a new expression... (Fixing Class c; const char * a = c;)
11187 // Mark nohead classes as by reference, unless we're casting them to an integral type
11188 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11189 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11190 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11191 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11193 exp.byReference = true;
11197 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11198 else if(exp.destType && !exp.destType.keepCast)
11200 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11201 exp.needTemplateCast = 1;
11203 if(exp.destType.kind == voidType);
11204 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11206 // Warn for casting unrelated types to/from struct classes
11207 bool invalidCast = false;
11208 if(inCompiler && exp.destType.count && exp.expType)
11210 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11211 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11212 if(c1 && c1.type != structClass) c1 = null;
11213 if(c2 && c2.type != structClass) c2 = null;
11214 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11215 invalidCast = true;
11217 if(!exp.destType.count || unresolved || invalidCast)
11222 if(exp.destType.kind != ellipsisType)
11228 char expString[10240];
11229 expString[0] = '\0';
11231 PrintType(exp.destType, type2, false, true);
11233 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11235 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11236 else if(exp.type != dummyExp)
11237 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11242 char expString[10240] ;
11243 expString[0] = '\0';
11244 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11247 Compiler_Error($"unresolved identifier %s\n", expString);
11248 else if(exp.type != dummyExp)
11249 Compiler_Error($"couldn't determine type of %s\n", expString);
11260 PrintType(exp.expType, type1, false, true);
11261 PrintType(exp.destType, type2, false, true);
11264 //CheckExpressionType(exp, exp.destType, false);
11266 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11267 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11268 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11271 Expression nbExp = GetNonBracketsExp(exp);
11272 bool skipWarning = false;
11273 TypeKind kind = exp.destType.kind;
11274 if(nbExp.type == conditionExp && nbExp.destType && !nbExp.destType.casted && nbExp.destType.kind == exp.destType.kind)
11275 // The if/else operands have already been checked / warned about
11276 skipWarning = true;
11277 if((kind == charType || kind == shortType) && exp.destType.isSigned == exp.expType.signedBeforePromotion && nbExp.type == opExp && nbExp.op.exp1 && nbExp.op.exp2)
11279 int op = nbExp.op.op;
11280 Expression nbExp1, nbExp2;
11285 case '%': case '/':
11286 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11287 from = nbExp1.expType.promotedFrom;
11288 // Division and Modulo will not take more room than type before promotion
11289 if(from == charType || (kind == shortType && from == shortType))
11290 skipWarning = true;
11293 case LEFT_OP: case RIGHT_OP:
11294 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11295 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11296 from = nbExp1.expType.promotedFrom;
11297 // Right shift will not take more room than type before promotion
11298 if(op == RIGHT_OP && (from == charType || (kind == shortType && from == shortType)))
11299 skipWarning = true;
11300 else if(nbExp2.isConstant && nbExp2.type == constantExp && (nbExp.op.op == RIGHT_OP || nbExp1.expType.bitMemberSize))
11302 int n = (int)strtol(nbExp2.constant, null, 0);
11303 int s = from == charType ? 8 : 16;
11304 // Left shifting a bit member constrained in size may still fit in type before promotion
11305 if(nbExp1.expType.bitMemberSize && nbExp1.expType.bitMemberSize < s)
11306 s = nbExp1.expType.bitMemberSize;
11308 // If right shifted enough things will fit in smaller type
11309 if(nbExp.op.op == RIGHT_OP)
11313 if(s <= (kind == charType ? 8 : 16))
11314 skipWarning = true;
11318 if(!exp.destType.isSigned)
11320 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11321 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11322 from = nbExp2.expType.promotedFrom;
11323 // Max value of unsigned type before promotion minus the same will always fit
11324 if((from == charType || from == shortType) && nbExp1.isConstant && nbExp1.type == constantExp)
11326 int n = (int)strtol(nbExp1.constant, null, 0);
11327 if(n == (from == charType ? 255 : 65535))
11328 skipWarning = true;
11334 TypeKind kind1, kind2;
11335 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11336 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11337 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11338 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11339 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) &&
11340 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11341 skipWarning = true;
11346 TypeKind kind1, kind2;
11347 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11348 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11349 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11350 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11351 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) ||
11352 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11353 skipWarning = true;
11361 char expString[10240];
11362 expString[0] = '\0';
11363 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11366 CheckExpressionType(exp, exp.destType, false, true);
11369 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11370 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11371 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11372 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11373 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11376 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11378 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11382 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11385 FreeType(exp.expType);
11386 exp.destType.refCount++;
11387 exp.expType = exp.destType;
11393 // Cast function pointers to void * as eC already checked compatibility
11394 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11395 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11397 Expression nbExp = GetNonBracketsExp(exp);
11398 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11400 Expression e = MoveExpContents(exp);
11401 exp.cast.exp = MkExpBrackets(MkListOne(e));
11402 exp.type = castExp;
11403 exp.cast.exp.destType = exp.destType;
11404 if(exp.destType) exp.destType.refCount++;
11405 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11409 else if(unresolved)
11411 if(exp.identifier._class && exp.identifier._class.name)
11412 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11413 else if(exp.identifier.string && exp.identifier.string[0])
11414 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11416 else if(!exp.expType && exp.type != dummyExp)
11418 char expString[10240];
11419 expString[0] = '\0';
11420 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11421 Compiler_Error($"couldn't determine type of %s\n", expString);
11424 // Let's try to support any_object & typed_object here:
11426 ApplyAnyObjectLogic(exp);
11428 // Mark nohead classes as by reference, unless we're casting them to an integral type
11429 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11430 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11431 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11432 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11434 exp.byReference = true;
11436 yylloc = oldyylloc;
11439 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11441 // THIS CODE WILL FIND NEXT MEMBER...
11444 *curMember = (*curMember).next;
11446 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11448 *curMember = subMemberStack[--(*subMemberStackPos)];
11449 *curMember = (*curMember).next;
11452 // SKIP ALL PROPERTIES HERE...
11453 while((*curMember) && (*curMember).isProperty)
11454 *curMember = (*curMember).next;
11456 if(subMemberStackPos)
11458 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11460 subMemberStack[(*subMemberStackPos)++] = *curMember;
11462 *curMember = (*curMember).members.first;
11463 while(*curMember && (*curMember).isProperty)
11464 *curMember = (*curMember).next;
11472 if(subMemberStackPos && *subMemberStackPos)
11474 *curMember = subMemberStack[--(*subMemberStackPos)];
11475 *curMember = (*curMember).next;
11479 Class lastCurClass = *curClass;
11481 if(*curClass == _class) break; // REACHED THE END
11483 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11484 *curMember = (*curClass).membersAndProperties.first;
11487 while((*curMember) && (*curMember).isProperty)
11488 *curMember = (*curMember).next;
11489 if(subMemberStackPos)
11491 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11493 subMemberStack[(*subMemberStackPos)++] = *curMember;
11495 *curMember = (*curMember).members.first;
11496 while(*curMember && (*curMember).isProperty)
11497 *curMember = (*curMember).next;
11505 static void ProcessInitializer(Initializer init, Type type)
11509 case expInitializer:
11510 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11512 // TESTING THIS FOR SHUTTING = 0 WARNING
11513 if(init.exp && !init.exp.destType)
11515 FreeType(init.exp.destType);
11516 init.exp.destType = type;
11517 if(type) type.refCount++;
11521 ProcessExpressionType(init.exp);
11522 init.isConstant = init.exp.isConstant;
11528 Expression exp = init.exp;
11529 Instantiation inst = exp.instance;
11530 MembersInit members;
11532 init.type = listInitializer;
11533 init.list = MkList();
11537 for(members = inst.members->first; members; members = members.next)
11539 if(members.type == dataMembersInit)
11542 for(member = members.dataMembers->first; member; member = member.next)
11544 ListAdd(init.list, member.initializer);
11545 member.initializer = null;
11548 // Discard all MembersInitMethod
11551 FreeExpression(exp);
11553 case listInitializer:
11556 Type initializerType = null;
11557 Class curClass = null;
11558 DataMember curMember = null;
11559 DataMember subMemberStack[256];
11560 int subMemberStackPos = 0;
11562 if(type && type.kind == arrayType)
11563 initializerType = Dereference(type);
11564 else if(type && (type.kind == structType || type.kind == unionType))
11565 initializerType = type.members.first;
11567 for(i = init.list->first; i; i = i.next)
11569 if(type && type.kind == classType && type._class && type._class.registered)
11571 // 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)
11572 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11573 // TODO: Generate error on initializing a private data member this way from another module...
11576 if(!curMember.dataType)
11577 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11578 initializerType = curMember.dataType;
11581 ProcessInitializer(i, initializerType);
11582 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11583 initializerType = initializerType.next;
11585 init.isConstant = false;
11588 if(type && type.kind == arrayType)
11589 FreeType(initializerType);
11591 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11593 Compiler_Error($"Assigning list initializer to non list\n");
11600 static void ProcessSpecifier(Specifier spec, bool declareStruct, bool warnClasses)
11604 case baseSpecifier:
11606 if(spec.specifier == THISCLASS)
11610 spec.type = nameSpecifier;
11611 spec.name = ReplaceThisClass(thisClass);
11612 spec.symbol = FindClass(spec.name);
11613 ProcessSpecifier(spec, declareStruct, false);
11618 case nameSpecifier:
11620 Symbol symbol = FindType(curContext, spec.name);
11622 DeclareType(curExternal, symbol.type, true, true);
11623 else if(spec.symbol /*&& declareStruct*/)
11625 Class c = spec.symbol.registered;
11626 if(warnClasses && !c)
11627 Compiler_Warning("Undeclared class %s\n", spec.name);
11628 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11632 case enumSpecifier:
11637 for(e = spec.list->first; e; e = e.next)
11640 ProcessExpressionType(e.exp);
11643 // Fall through for IDE type processing
11647 case structSpecifier:
11648 case unionSpecifier:
11650 if(spec.definitions)
11653 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11655 ProcessClass(spec.definitions, symbol);
11658 for(def = spec.definitions->first; def; def = def.next)
11660 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11661 ProcessDeclaration(def.decl);
11668 case classSpecifier:
11670 Symbol classSym = FindClass(spec.name);
11671 if(classSym && classSym.registered && classSym.registered.type == structClass)
11672 DeclareStruct(spec.name, false, true);
11680 static void ProcessDeclarator(Declarator decl, bool isFunction)
11684 case identifierDeclarator:
11685 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11687 FreeSpecifier(decl.identifier._class);
11688 decl.identifier._class = null;
11691 case arrayDeclarator:
11693 ProcessExpressionType(decl.array.exp);
11694 case structDeclarator:
11695 case bracketsDeclarator:
11696 case functionDeclarator:
11697 case pointerDeclarator:
11698 case extendedDeclarator:
11699 case extendedDeclaratorEnd:
11701 Identifier id = null;
11702 Specifier classSpec = null;
11703 if(decl.type == functionDeclarator)
11705 id = GetDeclId(decl);
11706 if(id && id._class)
11708 classSpec = id._class;
11712 if(decl.declarator)
11713 ProcessDeclarator(decl.declarator, isFunction);
11714 if(decl.type == functionDeclarator)
11720 qualifiers = MkListOne(classSpec);
11723 if(!decl.function.parameters)
11724 decl.function.parameters = MkList();
11725 decl.function.parameters->Insert(null, param);
11727 if(decl.function.parameters)
11731 for(param = decl.function.parameters->first; param; param = param.next)
11733 if(param.qualifiers)
11736 for(spec = param.qualifiers->first; spec; spec = spec.next)
11738 if(spec.type == baseSpecifier)
11740 if(spec.specifier == TYPED_OBJECT)
11742 Declarator d = param.declarator;
11745 qualifiers = MkListOne(MkSpecifier(VOID));
11746 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11748 if(!d || d.type != pointerDeclarator)
11749 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11751 FreeList(param.qualifiers, FreeSpecifier);
11753 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11754 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11756 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11758 decl.function.parameters->Insert(param, newParam);
11762 else if(spec.specifier == ANY_OBJECT)
11764 Declarator d = param.declarator;
11766 FreeList(param.qualifiers, FreeSpecifier);
11768 param.qualifiers = MkListOne(MkSpecifier(VOID));
11769 if(!d || d.type != pointerDeclarator)
11770 param.qualifiers->Insert(null, MkSpecifier(CONST));
11771 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11774 else if(spec.specifier == THISCLASS)
11778 spec.type = nameSpecifier;
11779 spec.name = ReplaceThisClass(thisClass);
11780 spec.symbol = FindClass(spec.name);
11781 ProcessSpecifier(spec, false, false);
11786 else if(spec.type == nameSpecifier)
11788 ProcessSpecifier(spec, isFunction, true);
11790 else if((spec.type == structSpecifier || spec.type == unionSpecifier) && !spec.definitions && spec.id && spec.id.string)
11792 Declarator d = param.declarator;
11793 if(!d || d.type != pointerDeclarator)
11794 DeclareStruct(curExternal, spec.id.string, false, true);
11799 if(param.declarator)
11800 ProcessDeclarator(param.declarator, false);
11809 static void ProcessDeclaration(Declaration decl, bool warnClasses)
11814 case initDeclaration:
11816 bool declareStruct = false;
11818 lineNum = decl.pos.line;
11819 column = decl.pos.col;
11822 if(decl.declarators)
11826 for(d = decl.declarators->first; d; d = d.next)
11828 Type type, subType;
11829 ProcessDeclarator(d.declarator, false);
11831 type = ProcessType(decl.specifiers, d.declarator);
11835 ProcessInitializer(d.initializer, type);
11837 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11839 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11840 d.initializer.exp.type == instanceExp)
11842 if(type.kind == classType && type._class ==
11843 d.initializer.exp.expType._class)
11845 Instantiation inst = d.initializer.exp.instance;
11846 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11848 d.initializer.exp.instance = null;
11849 if(decl.specifiers)
11850 FreeList(decl.specifiers, FreeSpecifier);
11851 FreeList(decl.declarators, FreeInitDeclarator);
11855 decl.type = instDeclaration;
11860 for(subType = type; subType;)
11862 if(subType.kind == classType)
11864 declareStruct = true;
11867 else if(subType.kind == pointerType)
11869 else if(subType.kind == arrayType)
11870 subType = subType.arrayType;
11880 if(decl.specifiers)
11883 for(s = decl.specifiers->first; s; s = s.next)
11885 ProcessSpecifier(s, declareStruct, true);
11890 case instDeclaration:
11892 ProcessInstantiationType(decl.inst);
11895 case structDeclaration:
11899 bool declareStruct = false;
11901 if(decl.declarators)
11903 for(d = decl.declarators->first; d; d = d.next)
11905 Type type = ProcessType(decl.specifiers, d.declarator);
11907 ProcessDeclarator(d, false);
11908 for(subType = type; subType;)
11910 if(subType.kind == classType)
11912 declareStruct = true;
11915 else if(subType.kind == pointerType)
11917 else if(subType.kind == arrayType)
11918 subType = subType.arrayType;
11925 if(decl.specifiers)
11927 for(spec = decl.specifiers->first; spec; spec = spec.next)
11928 ProcessSpecifier(spec, declareStruct, warnClasses);
11935 static FunctionDefinition curFunction;
11937 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11939 char propName[1024], propNameM[1024];
11940 char getName[1024], setName[1024];
11943 DeclareProperty(curExternal, prop, setName, getName);
11945 // eInstance_FireWatchers(object, prop);
11946 strcpy(propName, "__ecereProp_");
11947 FullClassNameCat(propName, prop._class.fullName, false);
11948 strcat(propName, "_");
11949 FullClassNameCat(propName, prop.name, true);
11951 strcpy(propNameM, "__ecerePropM_");
11952 FullClassNameCat(propNameM, prop._class.fullName, false);
11953 strcat(propNameM, "_");
11954 FullClassNameCat(propNameM, prop.name, true);
11956 if(prop.isWatchable)
11959 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11960 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11961 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11964 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11965 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11966 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11968 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
11973 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11974 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11975 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11978 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11979 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11980 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11982 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
11985 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11986 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11987 curFunction.propSet.fireWatchersDone = true;
11990 static void ProcessStatement(Statement stmt)
11994 lineNum = stmt.pos.line;
11995 column = stmt.pos.col;
12000 ProcessStatement(stmt.labeled.stmt);
12003 // This expression should be constant...
12004 if(stmt.caseStmt.exp)
12006 FreeType(stmt.caseStmt.exp.destType);
12007 stmt.caseStmt.exp.destType = curSwitchType;
12008 if(curSwitchType) curSwitchType.refCount++;
12009 ProcessExpressionType(stmt.caseStmt.exp);
12010 ComputeExpression(stmt.caseStmt.exp);
12012 if(stmt.caseStmt.stmt)
12013 ProcessStatement(stmt.caseStmt.stmt);
12017 if(stmt.compound.context)
12022 Statement prevCompound = curCompound;
12023 Context prevContext = curContext;
12025 if(!stmt.compound.isSwitch)
12026 curCompound = stmt;
12027 curContext = stmt.compound.context;
12029 if(stmt.compound.declarations)
12031 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
12032 ProcessDeclaration(decl, true);
12034 if(stmt.compound.statements)
12036 for(s = stmt.compound.statements->first; s; s = s.next)
12037 ProcessStatement(s);
12040 curContext = prevContext;
12041 curCompound = prevCompound;
12045 case expressionStmt:
12048 if(stmt.expressions)
12050 for(exp = stmt.expressions->first; exp; exp = exp.next)
12051 ProcessExpressionType(exp);
12059 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
12060 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
12061 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
12062 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
12064 ProcessExpressionType(exp);
12066 if(stmt.ifStmt.stmt)
12067 ProcessStatement(stmt.ifStmt.stmt);
12068 if(stmt.ifStmt.elseStmt)
12069 ProcessStatement(stmt.ifStmt.elseStmt);
12074 Type oldSwitchType = curSwitchType;
12075 if(stmt.switchStmt.exp)
12078 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12088 e.exp.destType = destType;
12091 ProcessExpressionType(exp);
12094 curSwitchType = exp.expType;
12097 ProcessStatement(stmt.switchStmt.stmt);
12098 curSwitchType = oldSwitchType;
12103 if(stmt.whileStmt.exp)
12107 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12108 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12109 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12110 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12112 ProcessExpressionType(exp);
12115 if(stmt.whileStmt.stmt)
12116 ProcessStatement(stmt.whileStmt.stmt);
12121 if(stmt.doWhile.exp)
12125 if(stmt.doWhile.exp->last)
12127 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12128 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12129 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12131 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12133 ProcessExpressionType(exp);
12136 if(stmt.doWhile.stmt)
12137 ProcessStatement(stmt.doWhile.stmt);
12143 if(stmt.forStmt.init)
12144 ProcessStatement(stmt.forStmt.init);
12146 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12148 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12149 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12150 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12153 if(stmt.forStmt.check)
12154 ProcessStatement(stmt.forStmt.check);
12155 if(stmt.forStmt.increment)
12157 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12158 ProcessExpressionType(exp);
12161 if(stmt.forStmt.stmt)
12162 ProcessStatement(stmt.forStmt.stmt);
12167 Identifier id = stmt.forEachStmt.id;
12168 OldList * exp = stmt.forEachStmt.exp;
12169 OldList * filter = stmt.forEachStmt.filter;
12170 Statement block = stmt.forEachStmt.stmt;
12171 char iteratorType[1024];
12174 bool isBuiltin = exp && exp->last &&
12175 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12176 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12177 Expression arrayExp;
12178 const char * typeString = null;
12179 int builtinCount = 0;
12181 for(e = exp ? exp->first : null; e; e = e.next)
12185 FreeType(e.destType);
12186 e.destType = ProcessTypeString("Container", false);
12188 if(!isBuiltin || e.next)
12189 ProcessExpressionType(e);
12192 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12193 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12194 eClass_IsDerived(source._class.registered, containerClass)))
12196 Class _class = source ? source._class.registered : null;
12198 Expression expIt = null;
12199 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12200 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12201 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12202 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12206 stmt.type = compoundStmt;
12208 stmt.compound.context = Context { };
12209 stmt.compound.context.parent = curContext;
12210 curContext = stmt.compound.context;
12213 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12215 Class mapClass = eSystem_FindClass(privateModule, "Map");
12216 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12217 isCustomAVLTree = true;
12218 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12220 else */if(eClass_IsDerived(source._class.registered, mapClass))
12223 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12224 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12226 Class listClass = eSystem_FindClass(privateModule, "List");
12228 isList = eClass_IsDerived(source._class.registered, listClass);
12231 if(inCompiler && isArray)
12234 OldList * specs = MkList();
12235 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12236 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12237 stmt.compound.declarations = MkListOne(
12238 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12239 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12240 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12241 MkInitializerAssignment(MkExpBrackets(exp))))));
12246 char typeStringBuf[1024];
12248 // TODO: Merge this code?
12249 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12250 if(((Expression)exp->last).type == castExp)
12252 TypeName typeName = ((Expression)exp->last).cast.typeName;
12254 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12257 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12258 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12259 arrayExp.destType._class.registered.templateArgs)
12261 Class templateClass = arrayExp.destType._class.registered;
12262 typeString = templateClass.templateArgs[2].dataTypeString;
12264 else if(arrayExp.list)
12266 // Guess type from expressions in the array
12268 for(e = arrayExp.list->first; e; e = e.next)
12270 ProcessExpressionType(e);
12273 if(!type) { type = e.expType; type.refCount++; }
12276 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12277 if(!MatchTypeExpression(e, type, null, false, true))
12283 e = arrayExp.list->first;
12284 ProcessExpressionType(e);
12287 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12288 if(!MatchTypeExpression(e, type, null, false, true))
12290 FreeType(e.expType);
12301 FreeType(e.expType);
12308 typeStringBuf[0] = '\0';
12309 PrintType(type, typeStringBuf, false, true);
12310 typeString = typeStringBuf;
12318 OldList * initializers = MkList();
12320 OldList * specs = MkList();
12325 builtinCount = arrayExp.list->count;
12326 type = ProcessTypeString(typeString, false);
12327 while((e = arrayExp.list->first))
12329 arrayExp.list->Remove(e);
12332 ProcessExpressionType(e);
12334 ListAdd(initializers, MkInitializerAssignment(e));
12337 delete arrayExp.list;
12339 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12341 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12342 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12344 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12346 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12347 ), MkInitializerList(initializers)))));
12348 FreeList(exp, FreeExpression);
12350 else if(arrayExp.list)
12353 type = ProcessTypeString(typeString, false);
12354 for(e = arrayExp.list->first; e; e = e.next)
12358 ProcessExpressionType(e);
12365 arrayExp.expType = ProcessTypeString("Container", false);
12366 Compiler_Error($"Couldn't determine type of array elements\n");
12371 OldList * specs = MkList();
12373 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12374 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12375 stmt.compound.declarations = MkListOne(
12376 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12377 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12378 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12379 MkInitializerAssignment(MkExpBrackets(exp))))));
12382 else if(inCompiler && isLinkList && !isList)
12385 OldList * specs = MkList();
12386 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12387 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12388 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12389 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12390 MkInitializerAssignment(MkExpBrackets(exp))))));
12392 /*else if(isCustomAVLTree)
12395 OldList * specs = MkList();
12396 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12397 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12398 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12399 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12400 MkInitializerAssignment(MkExpBrackets(exp))))));
12402 else if(inCompiler && _class.templateArgs)
12405 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12407 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12409 stmt.compound.declarations = MkListOne(
12410 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12411 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12412 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12416 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12420 // Reparent sub-contexts in this statement
12424 if(block.compound.context)
12425 block.compound.context.parent = stmt.compound.context;
12428 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12429 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12430 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12431 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12434 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12435 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12438 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12439 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12442 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12443 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12446 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12447 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12450 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12451 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12453 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12456 case expressionStmt:
12462 case badDeclarationStmt:
12463 case fireWatchersStmt:
12464 case stopWatchingStmt:
12472 block = MkIfStmt(filter, block, null);
12476 stmt.compound.statements = MkListOne(MkForStmt(
12477 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12478 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12479 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12480 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12482 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12483 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12484 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12489 //OldList * specs = MkList();
12490 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12492 sprintf(count, "%d", builtinCount);
12494 stmt.compound.statements = MkListOne(MkForStmt(
12495 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12496 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12497 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12498 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12502 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12503 stmt.compound.statements = MkListOne(MkForStmt(
12504 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12505 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12506 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12507 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12510 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12511 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12512 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12514 else if(isLinkList && !isList)
12516 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12517 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12518 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12519 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12521 stmt.compound.statements = MkListOne(MkForStmt(
12522 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12523 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12524 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12529 OldList * specs = MkList();
12530 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12531 stmt.compound.statements = MkListOne(MkForStmt(
12532 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12533 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12534 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12535 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12536 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12539 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12540 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12541 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12543 /*else if(isCustomAVLTree)
12545 stmt.compound.statements = MkListOne(MkForStmt(
12546 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12547 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12548 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12549 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12552 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12553 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12554 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12558 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12559 MkIdentifier("Next")), null)), block));
12561 ProcessExpressionType(expIt);
12562 if(stmt.compound.declarations->first)
12563 ProcessDeclaration(stmt.compound.declarations->first, true);
12566 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12568 ProcessStatement(stmt);
12571 ProcessStatement(stmt.forEachStmt.stmt);
12573 curContext = stmt.compound.context.parent;
12578 Compiler_Error($"Expression is not a container\n");
12591 if(stmt.expressions)
12593 for(exp = stmt.expressions->first; exp; exp = exp.next)
12597 if(curFunction && !curFunction.type)
12598 curFunction.type = ProcessType(
12599 curFunction.specifiers, curFunction.declarator);
12600 FreeType(exp.destType);
12601 // TODO: current property if not compiling
12602 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12603 if(exp.destType) exp.destType.refCount++;
12605 ProcessExpressionType(exp);
12610 case badDeclarationStmt:
12612 ProcessDeclaration(stmt.decl, true);
12618 if(stmt.asmStmt.inputFields)
12620 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12621 if(field.expression)
12622 ProcessExpressionType(field.expression);
12624 if(stmt.asmStmt.outputFields)
12626 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12627 if(field.expression)
12628 ProcessExpressionType(field.expression);
12630 if(stmt.asmStmt.clobberedFields)
12632 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12634 if(field.expression)
12635 ProcessExpressionType(field.expression);
12642 PropertyWatch propWatch;
12643 OldList * watches = stmt._watch.watches;
12644 Expression object = stmt._watch.object;
12645 Expression watcher = stmt._watch.watcher;
12647 ProcessExpressionType(watcher);
12649 ProcessExpressionType(object);
12653 if(watcher || thisClass)
12655 External external = curExternal;
12656 Context context = curContext;
12658 stmt.type = expressionStmt;
12659 stmt.expressions = MkList();
12661 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12663 ClassFunction func;
12664 char watcherName[1024];
12665 Class watcherClass = watcher ?
12666 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12667 External createdExternal;
12669 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12670 if(propWatch.deleteWatch)
12671 strcat(watcherName, "_delete");
12675 for(propID = propWatch.properties->first; propID; propID = propID.next)
12677 strcat(watcherName, "_");
12678 strcat(watcherName, propID.string);
12682 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12684 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12685 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12686 ProcessClassFunctionBody(func, propWatch.compound);
12687 propWatch.compound = null;
12689 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12691 FreeClassFunction(func);
12693 curExternal = createdExternal;
12694 ProcessFunction(createdExternal.function);
12696 if(propWatch.deleteWatch)
12698 OldList * args = MkList();
12699 ListAdd(args, CopyExpression(object));
12700 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12701 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12702 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12706 Class _class = object.expType._class.registered;
12709 for(propID = propWatch.properties->first; propID; propID = propID.next)
12711 char propName[1024];
12712 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12715 char getName[1024], setName[1024];
12716 OldList * args = MkList();
12718 DeclareProperty(createdExternal, prop, setName, getName);
12720 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12721 strcpy(propName, "__ecereProp_");
12722 FullClassNameCat(propName, prop._class.fullName, false);
12723 strcat(propName, "_");
12724 FullClassNameCat(propName, prop.name, true);
12726 ListAdd(args, CopyExpression(object));
12727 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12728 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12729 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12731 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12733 external.CreateUniqueEdge(createdExternal, true);
12736 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12741 Compiler_Error($"Invalid watched object\n");
12744 curExternal = external;
12745 curContext = context;
12748 FreeExpression(watcher);
12750 FreeExpression(object);
12751 FreeList(watches, FreePropertyWatch);
12754 Compiler_Error($"No observer specified and not inside a class\n");
12758 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12760 ProcessStatement(propWatch.compound);
12766 case fireWatchersStmt:
12768 OldList * watches = stmt._watch.watches;
12769 Expression object = stmt._watch.object;
12771 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12772 // printf("%X\n", watches);
12773 // printf("%X\n", stmt._watch.watches);
12775 ProcessExpressionType(object);
12780 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12786 stmt.type = expressionStmt;
12787 stmt.expressions = MkList();
12789 // Check if we're inside a property set
12790 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12792 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12796 //Compiler_Error($"No property specified and not inside a property set\n");
12800 for(propID = watches->first; propID; propID = propID.next)
12802 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12805 CreateFireWatcher(prop, object, stmt);
12808 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12813 // Fire all properties!
12816 for(base = _class; base; base = base.base)
12818 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12820 if(prop.isProperty && prop.isWatchable)
12822 CreateFireWatcher(prop, object, stmt);
12829 FreeExpression(object);
12830 FreeList(watches, FreeIdentifier);
12833 Compiler_Error($"Invalid object specified and not inside a class\n");
12837 case stopWatchingStmt:
12839 OldList * watches = stmt._watch.watches;
12840 Expression object = stmt._watch.object;
12841 Expression watcher = stmt._watch.watcher;
12844 ProcessExpressionType(object);
12846 ProcessExpressionType(watcher);
12849 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12851 if(watcher || thisClass)
12857 stmt.type = expressionStmt;
12858 stmt.expressions = MkList();
12863 // eInstance_StopWatching(object, null, watcher);
12865 ListAdd(args, CopyExpression(object));
12866 ListAdd(args, MkExpConstant("0"));
12867 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12868 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12872 for(propID = watches->first; propID; propID = propID.next)
12874 char propName[1024];
12875 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12878 char getName[1024], setName[1024];
12879 OldList * args = MkList();
12881 DeclareProperty(curExternal, prop, setName, getName);
12883 // eInstance_StopWatching(object, prop, watcher);
12884 strcpy(propName, "__ecereProp_");
12885 FullClassNameCat(propName, prop._class.fullName, false);
12886 strcat(propName, "_");
12887 FullClassNameCat(propName, prop.name, true);
12889 ListAdd(args, CopyExpression(object));
12890 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12891 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12892 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12895 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12900 FreeExpression(object);
12902 FreeExpression(watcher);
12903 FreeList(watches, FreeIdentifier);
12906 Compiler_Error($"Invalid object specified and not inside a class\n");
12909 Compiler_Error($"No observer specified and not inside a class\n");
12916 static void ProcessFunction(FunctionDefinition function)
12918 Identifier id = GetDeclId(function.declarator);
12919 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12920 Type type = symbol ? symbol.type : null;
12921 Class oldThisClass = thisClass;
12922 Context oldTopContext = topContext;
12924 yylloc = function.loc;
12925 // Process thisClass
12927 if(type && type.thisClass)
12929 Symbol classSym = type.thisClass;
12930 Class _class = type.thisClass.registered;
12931 char className[1024];
12932 char structName[1024];
12933 Declarator funcDecl;
12936 bool typedObject = false;
12938 if(_class && !_class.base)
12940 _class = currentClass;
12941 if(_class && !_class.symbol)
12942 _class.symbol = FindClass(_class.fullName);
12943 classSym = _class ? _class.symbol : null;
12944 typedObject = true;
12947 thisClass = _class;
12949 if(inCompiler && _class)
12951 if(type.kind == functionType)
12953 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12955 //TypeName param = symbol.type.params.first;
12956 Type param = symbol.type.params.first;
12957 symbol.type.params.Remove(param);
12958 //FreeTypeName(param);
12961 if(type.classObjectType != classPointer)
12963 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12964 symbol.type.staticMethod = true;
12965 symbol.type.thisClass = null;
12967 // HIGH DANGER: VERIFYING THIS...
12968 symbol.type.extraParam = false;
12972 strcpy(className, "__ecereClass_");
12973 FullClassNameCat(className, _class.fullName, true);
12976 FullClassNameCat(structName, _class.fullName, false);
12979 funcDecl = GetFuncDecl(function.declarator);
12982 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12984 TypeName param = funcDecl.function.parameters->first;
12985 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12987 funcDecl.function.parameters->Remove(param);
12988 FreeTypeName(param);
12992 if(!function.propertyNoThis)
12994 TypeName thisParam = null;
12996 if(type.classObjectType != classPointer)
12998 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12999 if(!funcDecl.function.parameters)
13000 funcDecl.function.parameters = MkList();
13001 funcDecl.function.parameters->Insert(null, thisParam);
13006 if(type.classObjectType != classPointer)
13008 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
13009 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
13012 thisParam = TypeName
13014 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
13015 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
13017 DeclareStruct(curExternal, "ecere::com::Class", false, true);
13018 funcDecl.function.parameters->Insert(null, thisParam);
13023 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13025 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13026 funcDecl = GetFuncDecl(initDecl.declarator);
13029 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13031 TypeName param = funcDecl.function.parameters->first;
13032 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13034 funcDecl.function.parameters->Remove(param);
13035 FreeTypeName(param);
13039 if(type.classObjectType != classPointer)
13041 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
13043 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13045 if(!funcDecl.function.parameters)
13046 funcDecl.function.parameters = MkList();
13047 funcDecl.function.parameters->Insert(null, thisParam);
13054 // Add this to the context
13057 if(type.classObjectType != classPointer)
13059 thisSymbol = Symbol
13061 string = CopyString("this");
13062 type = classSym ? MkClassType(classSym.string) : null;
13064 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13066 if(typedObject && thisSymbol.type)
13068 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13069 thisSymbol.type.byReference = type.byReference;
13070 thisSymbol.type.typedByReference = type.byReference;
13075 // Pointer to class data
13076 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
13078 DataMember member = null;
13081 for(base = _class; base && base.type != systemClass; base = base.next)
13083 for(member = base.membersAndProperties.first; member; member = member.next)
13084 if(!member.isProperty)
13090 for(member = _class.membersAndProperties.first; member; member = member.next)
13091 if(!member.isProperty)
13095 char pointerName[1024];
13098 Initializer initializer;
13099 Expression exp, bytePtr;
13101 strcpy(pointerName, "__ecerePointer_");
13102 FullClassNameCat(pointerName, _class.fullName, false);
13104 char className[1024];
13105 strcpy(className, "__ecereClass_");
13106 FullClassNameCat(className, classSym.string, true);
13108 DeclareClass(curExternal, classSym, className);
13112 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13117 if(_class.offset && _class.offset == (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize))
13119 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
13120 ProcessExpressionType(e);
13125 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
13126 e = MkExpConstant(string);
13128 exp = QBrackets(MkExpOp(bytePtr, '+', e));
13132 // ([bytePtr] + [className]->offset)
13133 exp = QBrackets(MkExpOp(bytePtr, '+',
13134 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13137 // (this ? [exp] : 0)
13138 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13142 kind = pointerType;
13143 type = Type { refCount = 1, kind = voidType };
13148 yylloc = function.body.loc;
13149 // ([structName] *) [exp]
13150 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13151 initializer = MkInitializerAssignment(
13152 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13154 // [structName] * [pointerName] = [initializer];
13155 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13158 Context prevContext = curContext;
13160 curContext = function.body.compound.context;
13162 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13163 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13164 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13166 curContext = prevContext;
13170 decl.symbol = null;
13172 if(!function.body.compound.declarations)
13173 function.body.compound.declarations = MkList();
13174 function.body.compound.declarations->Insert(null, decl);
13180 // Loop through the function and replace undeclared identifiers
13181 // which are a member of the class (methods, properties or data)
13182 // by "this.[member]"
13189 FreeSpecifier(id._class);
13192 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13194 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13195 id = GetDeclId(initDecl.declarator);
13197 FreeSpecifier(id._class);
13202 topContext = function.body.compound.context;
13204 FunctionDefinition oldFunction = curFunction;
13205 curFunction = function;
13207 ProcessStatement(function.body);
13209 // If this is a property set and no firewatchers has been done yet, add one here
13210 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13212 Statement prevCompound = curCompound;
13213 Context prevContext = curContext;
13215 Statement fireWatchers = MkFireWatchersStmt(null, null);
13216 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13217 ListAdd(function.body.compound.statements, fireWatchers);
13219 curCompound = function.body;
13220 curContext = function.body.compound.context;
13222 ProcessStatement(fireWatchers);
13224 curContext = prevContext;
13225 curCompound = prevCompound;
13229 curFunction = oldFunction;
13232 if(function.declarator)
13234 ProcessDeclarator(function.declarator, true);
13237 topContext = oldTopContext;
13238 thisClass = oldThisClass;
13241 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13242 static void ProcessClass(OldList definitions, Symbol symbol)
13245 External external = curExternal;
13246 Class regClass = symbol ? symbol.registered : null;
13248 // Process all functions
13249 for(def = definitions.first; def; def = def.next)
13251 if(def.type == functionClassDef)
13253 if(def.function.declarator)
13254 curExternal = def.function.declarator.symbol.pointerExternal;
13256 curExternal = external;
13258 ProcessFunction((FunctionDefinition)def.function);
13260 else if(def.type == declarationClassDef)
13262 if(def.decl.type == instDeclaration)
13264 thisClass = regClass;
13265 ProcessInstantiationType(def.decl.inst);
13271 Class backThisClass = thisClass;
13272 if(regClass) thisClass = regClass;
13273 ProcessDeclaration(def.decl, symbol ? true : false);
13274 thisClass = backThisClass;
13277 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13279 MemberInit defProperty;
13281 // Add this to the context
13282 Symbol thisSymbol = Symbol
13284 string = CopyString("this");
13285 type = regClass ? MkClassType(regClass.fullName) : null;
13287 globalContext.symbols.Add((BTNode)thisSymbol);
13289 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13291 thisClass = regClass;
13292 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13296 globalContext.symbols.Remove((BTNode)thisSymbol);
13297 FreeSymbol(thisSymbol);
13299 else if(def.type == propertyClassDef && def.propertyDef)
13301 PropertyDef prop = def.propertyDef;
13303 // Add this to the context
13304 thisClass = regClass;
13311 string = CopyString("this");
13312 type = MkClassType(regClass.fullName);
13314 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13317 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13318 ProcessStatement(prop.setStmt);
13326 string = CopyString("this");
13327 type = MkClassType(regClass.fullName);
13329 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13332 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13333 ProcessStatement(prop.getStmt);
13341 string = CopyString("this");
13342 type = MkClassType(regClass.fullName);
13344 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13347 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13348 ProcessStatement(prop.issetStmt);
13353 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13355 PropertyWatch propertyWatch = def.propertyWatch;
13357 thisClass = regClass;
13358 if(propertyWatch.compound)
13362 string = CopyString("this");
13363 type = regClass ? MkClassType(regClass.fullName) : null;
13366 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13368 curExternal = null;
13369 ProcessStatement(propertyWatch.compound);
13376 void DeclareFunctionUtil(External neededBy, const String s)
13378 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13383 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13384 strcpy(name, "__ecereFunction_");
13385 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13386 DeclareFunction(neededBy, function, name);
13389 FindSymbol(s, globalContext, globalContext, false, false);
13392 bool reachedPass15;
13394 void ComputeDataTypes()
13398 currentClass = null;
13400 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13402 DeclareStruct(null, "ecere::com::Class", false, true);
13403 DeclareStruct(null, "ecere::com::Instance", false, true);
13404 DeclareStruct(null, "ecere::com::Property", false, true);
13405 DeclareStruct(null, "ecere::com::DataMember", false, true);
13406 DeclareStruct(null, "ecere::com::Method", false, true);
13407 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13408 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13410 DeclareFunctionUtil(null, "eSystem_New");
13411 DeclareFunctionUtil(null, "eSystem_New0");
13412 DeclareFunctionUtil(null, "eSystem_Renew");
13413 DeclareFunctionUtil(null, "eSystem_Renew0");
13414 DeclareFunctionUtil(null, "eSystem_Delete");
13415 DeclareFunctionUtil(null, "eClass_GetProperty");
13416 DeclareFunctionUtil(null, "eClass_SetProperty");
13417 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13418 DeclareFunctionUtil(null, "eInstance_SetMethod");
13419 DeclareFunctionUtil(null, "eInstance_IncRef");
13420 DeclareFunctionUtil(null, "eInstance_StopWatching");
13421 DeclareFunctionUtil(null, "eInstance_Watch");
13422 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13423 reachedPass15 = true;
13425 for(external = ast->first; external; external = external.next)
13427 afterExternal = curExternal = external;
13428 if(external.type == functionExternal)
13432 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13433 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13436 currentClass = external.function._class;
13437 ProcessFunction(external.function);
13439 // There shouldn't be any _class member access here anyways...
13440 else if(external.type == declarationExternal)
13442 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13444 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13445 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13448 currentClass = null;
13449 if(external.declaration)
13450 ProcessDeclaration(external.declaration, true);
13452 else if(external.type == classExternal)
13454 ClassDefinition _class = external._class;
13455 currentClass = external.symbol.registered;
13458 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13459 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13461 if(_class.definitions)
13463 ProcessClass(_class.definitions, _class.symbol);
13467 // Free class data...
13468 ast->Remove(external);
13472 else if(external.type == nameSpaceExternal)
13474 thisNameSpace = external.id.string;
13477 currentClass = null;
13478 thisNameSpace = null;
13479 curExternal = null;