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 if(!ctx) break; // This happened opening old mapTileCache.ec from archives?
125 symbol = (Symbol)ctx.symbols.FindString(id.string);
130 // If it is not, check if it is a member of the _class
131 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
133 Property prop = eClass_FindProperty(_class, id.string, privateModule);
134 Method method = null;
135 DataMember member = null;
136 ClassProperty classProp = null;
139 method = eClass_FindMethod(_class, id.string, privateModule);
142 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
143 if(!prop && !method && !member)
145 classProp = eClass_FindClassProperty(_class, id.string);
147 if(prop || method || member || classProp)
149 // Replace by this.[member]
150 exp.type = memberExp;
151 exp.member.member = id;
152 exp.member.memberType = unresolvedMember;
153 exp.member.exp = QMkExpId("this");
154 //exp.member.exp.loc = exp.loc;
155 exp.addedThis = true;
157 else if(_class && _class.templateParams.first)
160 for(sClass = _class; sClass; sClass = sClass.base)
162 if(sClass.templateParams.first)
164 ClassTemplateParameter param;
165 for(param = sClass.templateParams.first; param; param = param.next)
167 if(param.type == expression && !strcmp(param.name, id.string))
169 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
174 OldList * specs = MkList();
176 FreeIdentifier(exp.member.member);
178 ProcessExpressionType(argExp);
180 decl = SpecDeclFromString(param.dataTypeString, specs, null);
182 exp.expType = ProcessType(specs, decl);
184 // *[expType] *[argExp]
185 exp.type = bracketsExp;
186 exp.list = MkListOne(MkExpOp(null, '*',
187 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
198 ////////////////////////////////////////////////////////////////////////
199 // PRINTING ////////////////////////////////////////////////////////////
200 ////////////////////////////////////////////////////////////////////////
202 public char * PrintInt(int64 result)
206 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
208 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
209 if(result > MAXINT || result < MININT)
211 return CopyString(temp);
214 public char * PrintUInt(uint64 result)
217 if(result > MAXDWORD)
218 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
219 else if(result > MAXINT)
220 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
222 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
223 return CopyString(temp);
226 public char * PrintInt64(int64 result)
229 if(result > MAXINT || result < MININT)
230 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
232 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
233 return CopyString(temp);
236 public char * PrintUInt64(uint64 result)
239 if(result > MAXDWORD)
240 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
241 else if(result > MAXINT)
242 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
244 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
245 return CopyString(temp);
248 public char * PrintHexUInt(uint64 result)
251 if(result > MAXDWORD)
252 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
254 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
255 if(result > MAXDWORD)
257 return CopyString(temp);
260 public char * PrintHexUInt64(uint64 result)
263 if(result > MAXDWORD)
264 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
266 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
267 return CopyString(temp);
270 public char * PrintShort(short result)
273 sprintf(temp, "%d", (unsigned short)result);
274 return CopyString(temp);
277 public char * PrintUShort(unsigned short result)
281 sprintf(temp, "0x%X", (int)result);
283 sprintf(temp, "%d", (int)result);
284 return CopyString(temp);
287 public char * PrintChar(char result)
290 if(result > 0 && isprint(result))
291 sprintf(temp, "'%c'", result);
293 sprintf(temp, "%d", (int)result);
295 //sprintf(temp, "%#X", result);
296 sprintf(temp, "0x%X", (unsigned char)result);
297 return CopyString(temp);
300 public char * PrintUChar(unsigned char result)
303 sprintf(temp, "0x%X", result);
304 return CopyString(temp);
307 public char * PrintFloat(float result)
313 strcpy(temp, "-inf");
317 else if(result.isNan)
320 strcpy(temp, "-nan");
325 sprintf(temp, "%.16ff", result);
326 return CopyString(temp);
329 public char * PrintDouble(double result)
335 strcpy(temp, "-inf");
339 else if(result.isNan)
342 strcpy(temp, "-nan");
347 sprintf(temp, "%.16f", result);
348 return CopyString(temp);
351 ////////////////////////////////////////////////////////////////////////
352 ////////////////////////////////////////////////////////////////////////
354 //public Operand GetOperand(Expression exp);
356 #define GETVALUE(name, t) \
357 public bool GetOp##name(Operand op2, t * value2) \
359 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
360 else if(op2.kind == intType) *value2 = (t) op2.ui; \
361 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
362 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
363 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
364 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
365 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
366 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
367 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
368 else if(op2.kind == shortType) *value2 = (t) op2.us; \
369 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
370 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
371 else if(op2.kind == floatType) *value2 = (t) op2.f; \
372 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
373 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
378 public bool Get##name(Expression exp, t * value2) \
380 Operand op2 = GetOperand(exp); \
381 return GetOp##name(op2, value2); \
384 // To help the debugger currently not preprocessing...
387 GETVALUE(Int, HELP(int));
388 GETVALUE(UInt, HELP(unsigned int));
389 GETVALUE(Int64, HELP(int64));
390 GETVALUE(UInt64, HELP(uint64));
391 GETVALUE(IntPtr, HELP(intptr));
392 GETVALUE(UIntPtr, HELP(uintptr));
393 GETVALUE(IntSize, HELP(intsize));
394 GETVALUE(UIntSize, HELP(uintsize));
395 GETVALUE(Short, HELP(short));
396 GETVALUE(UShort, HELP(unsigned short));
397 GETVALUE(Char, HELP(char));
398 GETVALUE(UChar, HELP(unsigned char));
399 GETVALUE(Float, HELP(float));
400 GETVALUE(Double, HELP(double));
402 void ComputeExpression(Expression exp);
404 void ComputeClassMembers(Class _class, bool isMember)
406 DataMember member = isMember ? (DataMember) _class : null;
407 Context context = isMember ? null : SetupTemplatesContext(_class);
408 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
409 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
411 int unionMemberOffset = 0;
415 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
416 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
421 member.memberOffset = 0;
422 if(targetBits < sizeof(void *) * 8)
423 member.structAlignment = 0;
425 else if(targetBits < sizeof(void *) * 8)
426 _class.structAlignment = 0;
428 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
429 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
430 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
432 if(!member && _class.destructionWatchOffset)
433 _class.memberOffset += sizeof(OldList);
435 // To avoid reentrancy...
436 //_class.structSize = -1;
439 DataMember dataMember;
440 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
442 if(!dataMember.isProperty)
444 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
446 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
447 /*if(!dataMember.dataType)
448 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
456 DataMember dataMember;
457 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
459 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
461 if(!isMember && _class.type == bitClass && dataMember.dataType)
463 BitMember bitMember = (BitMember) dataMember;
467 ComputeTypeSize(dataMember.dataType);
469 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
470 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
472 _class.memberOffset = bitMember.pos + bitMember.size;
473 for(d = 0; d<bitMember.size; d++)
479 bitMember.mask = mask << bitMember.pos;
481 else if(dataMember.type == normalMember && dataMember.dataType)
486 // Prevent infinite recursion
487 if(dataMember.dataType.kind != classType ||
488 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
489 _class.type != structClass)))
490 ComputeTypeSize(dataMember.dataType);
492 if(dataMember.dataType.bitFieldCount)
494 bitFields += dataMember.dataType.bitFieldCount;
501 int size = (bitFields + 7) / 8;
505 // TESTING THIS PADDING CODE
508 member.structAlignment = Max(member.structAlignment, alignment);
510 if(member.memberOffset % alignment)
511 member.memberOffset += alignment - (member.memberOffset % alignment);
514 dataMember.offset = member.memberOffset;
515 if(member.type == unionMember)
516 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
519 member.memberOffset += size;
524 // TESTING THIS PADDING CODE
527 _class.structAlignment = Max(_class.structAlignment, alignment);
529 if(_class.memberOffset % alignment)
530 _class.memberOffset += alignment - (_class.memberOffset % alignment);
533 dataMember.offset = _class.memberOffset;
534 _class.memberOffset += size;
538 size = dataMember.dataType.size;
539 alignment = dataMember.dataType.alignment;
544 // TESTING THIS PADDING CODE
547 member.structAlignment = Max(member.structAlignment, alignment);
549 if(member.memberOffset % alignment)
550 member.memberOffset += alignment - (member.memberOffset % alignment);
553 dataMember.offset = member.memberOffset;
554 if(member.type == unionMember)
555 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
558 member.memberOffset += size;
563 // TESTING THIS PADDING CODE
566 _class.structAlignment = Max(_class.structAlignment, alignment);
568 if(_class.memberOffset % alignment)
569 _class.memberOffset += alignment - (_class.memberOffset % alignment);
572 dataMember.offset = _class.memberOffset;
573 _class.memberOffset += size;
580 ComputeClassMembers((Class)dataMember, true);
581 alignment = dataMember.structAlignment;
587 if(member.memberOffset % alignment)
588 member.memberOffset += alignment - (member.memberOffset % alignment);
590 member.structAlignment = Max(member.structAlignment, alignment);
592 dataMember.offset = member.memberOffset;
593 if(member.type == unionMember)
594 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
596 member.memberOffset += dataMember.memberOffset;
602 if(_class.memberOffset % alignment)
603 _class.memberOffset += alignment - (_class.memberOffset % alignment);
604 _class.structAlignment = Max(_class.structAlignment, alignment);
606 dataMember.offset = _class.memberOffset;
607 _class.memberOffset += dataMember.memberOffset;
615 int size = (bitFields + 7) / 8;
619 // TESTING THIS PADDING CODE
622 member.structAlignment = Max(member.structAlignment, alignment);
624 if(member.memberOffset % alignment)
625 member.memberOffset += alignment - (member.memberOffset % alignment);
628 if(member.type == unionMember)
629 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
632 member.memberOffset += size;
637 // TESTING THIS PADDING CODE
640 _class.structAlignment = Max(_class.structAlignment, alignment);
642 if(_class.memberOffset % alignment)
643 _class.memberOffset += alignment - (_class.memberOffset % alignment);
645 _class.memberOffset += size;
650 if(member && member.type == unionMember)
652 member.memberOffset = unionMemberOffset;
657 /*if(_class.type == structClass)
658 _class.size = _class.memberOffset;
662 if(_class.type != bitClass)
665 if(_class.structAlignment)
667 if(_class.memberOffset % _class.structAlignment)
668 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
670 _class.structSize = (_class.base ? (_class.base.templateClass ?
671 (_class.base.type == noHeadClass ? _class.base.templateClass.memberOffset : _class.base.templateClass.structSize) :
672 (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize) ) : 0) + _class.memberOffset + extra;
676 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
678 if(prop.isProperty && prop.isWatchable)
680 prop.watcherOffset = _class.structSize;
681 _class.structSize += sizeof(OldList);
689 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
691 Class deriv = derivative.data;
693 if(deriv.computeSize)
695 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
696 deriv.offset = /*_class.offset + */(_class.type == noHeadClass ? _class.memberOffset : _class.structSize);
697 deriv.memberOffset = 0;
698 // ----------------------
700 deriv.structSize = deriv.offset;
702 ComputeClassMembers(deriv, false);
710 FinishTemplatesContext(context);
713 public void ComputeModuleClasses(Module module)
718 for(subModule = module.modules.first; subModule; subModule = subModule.next)
719 ComputeModuleClasses(subModule.data);
720 for(_class = module.classes.first; _class; _class = _class.next)
721 ComputeClassMembers(_class, false);
725 public int ComputeTypeSize(Type type)
727 uint size = type ? type.size : 0;
728 if(!size && type && !type.computing)
730 type.computing = true;
733 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
734 case charType: type.alignment = size = sizeof(char); break;
735 case intType: type.alignment = size = sizeof(int); break;
736 case int64Type: type.alignment = size = sizeof(int64); break;
737 case intPtrType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
738 case intSizeType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
739 case longType: type.alignment = size = sizeof(long); break;
740 case shortType: type.alignment = size = sizeof(short); break;
741 case floatType: type.alignment = size = sizeof(float); break;
742 case doubleType: type.alignment = size = sizeof(double); break;
745 Class _class = type._class ? type._class.registered : null;
747 if(_class && _class.type == structClass)
749 // Ensure all members are properly registered
750 ComputeClassMembers(_class, false);
751 type.alignment = _class.structAlignment;
752 type.pointerAlignment = (bool)_class.pointerAlignment;
753 size = _class.structSize;
754 if(type.alignment && size % type.alignment)
755 size += type.alignment - (size % type.alignment);
758 else if(_class && (_class.type == unitClass ||
759 _class.type == enumClass ||
760 _class.type == bitClass))
763 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
764 size = type.alignment = ComputeTypeSize(_class.dataType);
768 size = type.alignment = targetBits / 8; // sizeof(Instance *);
769 type.pointerAlignment = true;
773 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */ type.pointerAlignment = true; break;
775 if(type.arraySizeExp)
777 ProcessExpressionType(type.arraySizeExp);
778 ComputeExpression(type.arraySizeExp);
779 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
780 type.arraySizeExp.expType.kind != shortType &&
781 type.arraySizeExp.expType.kind != charType &&
782 type.arraySizeExp.expType.kind != longType &&
783 type.arraySizeExp.expType.kind != int64Type &&
784 type.arraySizeExp.expType.kind != intSizeType &&
785 type.arraySizeExp.expType.kind != intPtrType &&
786 type.arraySizeExp.expType.kind != enumType &&
787 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
789 Location oldLoc = yylloc;
790 // bool isConstant = type.arraySizeExp.isConstant;
791 char expression[10240];
792 expression[0] = '\0';
793 type.arraySizeExp.expType = null;
794 yylloc = type.arraySizeExp.loc;
796 PrintExpression(type.arraySizeExp, expression);
797 Compiler_Error($"Array size not constant int (%s)\n", expression);
800 GetInt(type.arraySizeExp, &type.arraySize);
802 else if(type.enumClass)
804 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
806 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
813 // Unimplemented auto size
817 size = ComputeTypeSize(type.type) * type.arraySize;
820 type.alignment = type.type.alignment;
821 type.pointerAlignment = type.type.pointerAlignment;
827 if(!type.members.first && type.enumName)
829 Symbol symbol = FindStruct(curContext, type.enumName);
830 if(symbol && symbol.type)
832 ComputeTypeSize(symbol.type);
833 size = symbol.type.size;
839 for(member = type.members.first; member; member = member.next)
841 uint addSize = ComputeTypeSize(member);
843 member.offset = size;
844 if(member.alignment && size % member.alignment)
845 member.offset += member.alignment - (size % member.alignment);
846 size = member.offset;
848 if(member.pointerAlignment && type.size <= 4)
849 type.pointerAlignment = true;
850 else if(!member.pointerAlignment && member.alignment >= 8)
851 type.pointerAlignment = false;
853 type.alignment = Max(type.alignment, member.alignment);
856 if(type.alignment && size % type.alignment)
857 size += type.alignment - (size % type.alignment);
863 if(!type.members.first && type.enumName)
865 Symbol symbol = FindStruct(curContext, type.enumName);
866 if(symbol && symbol.type)
868 ComputeTypeSize(symbol.type);
869 size = symbol.type.size;
870 type.alignment = symbol.type.alignment;
876 for(member = type.members.first; member; member = member.next)
878 uint addSize = ComputeTypeSize(member);
880 member.offset = size;
881 if(member.alignment && size % member.alignment)
882 member.offset += member.alignment - (size % member.alignment);
883 size = member.offset;
885 if(member.pointerAlignment && type.size <= 4)
886 type.pointerAlignment = true;
887 else if(!member.pointerAlignment && member.alignment >= 8)
888 type.pointerAlignment = false;
890 type.alignment = Max(type.alignment, member.alignment);
892 size = Max(size, addSize);
894 if(type.alignment && size % type.alignment)
895 size += type.alignment - (size % type.alignment);
901 TemplateParameter param = type.templateParameter;
902 Type baseType = ProcessTemplateParameterType(param);
905 size = ComputeTypeSize(baseType);
906 type.alignment = baseType.alignment;
907 type.pointerAlignment = baseType.pointerAlignment;
910 type.alignment = size = sizeof(uint64);
915 type.alignment = size = sizeof(enum { test });
920 type.alignment = size = targetBits / 8; //sizeof(void *);
921 type.pointerAlignment = true;
926 type.computing = false;
932 /*static */int AddMembers(External neededBy, OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
934 // This function is in need of a major review when implementing private members etc.
935 DataMember topMember = isMember ? (DataMember) _class : null;
942 Context context = isMember ? null : SetupTemplatesContext(_class);
944 *addedPadding = false;
946 if(!isMember && _class.base)
948 maxSize = _class.structSize;
949 //if(_class.base.type != systemClass) // Commented out with new Instance _class
951 // DANGER: Testing this noHeadClass here...
952 if(_class.type == structClass || _class.type == noHeadClass)
953 /*totalSize = */AddMembers(neededBy, declarations, _class.base, false, &totalSize, topClass, null);
956 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
957 if(maxSize > baseSize)
965 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
967 if(!member.isProperty)
973 if(member.dataTypeString)
975 OldList * specs = MkList(), * decls = MkList();
978 decl = SpecDeclFromString(member.dataTypeString, specs,
979 MkDeclaratorIdentifier(MkIdentifier(member.name)));
980 ListAdd(decls, MkStructDeclarator(decl, null));
981 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
984 member.dataType = ProcessType(specs, decl);
986 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
989 Type type = ProcessType(specs, decl);
990 DeclareType(neededBy, member.dataType, true, false);
994 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
995 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
996 DeclareStruct(member.dataType._class.string, false);
999 ComputeTypeSize(member.dataType);
1000 size = member.dataType.size;
1001 alignment = member.dataType.alignment;
1005 if(totalSize % alignment)
1006 totalSize += alignment - (totalSize % alignment);
1015 OldList * specs = MkList(), * list = MkList();
1017 sprintf(id, "__anon%d", anonID++);
1020 AddMembers(neededBy, list, (Class)member, true, &size, topClass, null);
1022 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1023 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1024 alignment = member.structAlignment;
1028 if(totalSize % alignment)
1029 totalSize += alignment - (totalSize % alignment);
1039 if(topMember && topMember.type == unionMember)
1040 *retSize = Max(*retSize, totalSize);
1042 *retSize += totalSize;
1044 else if(totalSize < maxSize && _class.type != systemClass)
1046 int autoPadding = 0;
1047 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1048 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1049 if(totalSize + autoPadding < maxSize)
1051 char sizeString[50];
1052 sprintf(sizeString, "%d", maxSize - totalSize);
1053 ListAdd(declarations,
1054 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1055 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1057 *addedPadding = true;
1061 FinishTemplatesContext(context);
1062 return topMember ? topMember.memberID : _class.memberID;
1065 static int DeclareMembers(External neededBy, Class _class, bool isMember)
1067 DataMember topMember = isMember ? (DataMember) _class : null;
1069 Context context = isMember ? null : SetupTemplatesContext(_class);
1071 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1072 DeclareMembers(neededBy, _class.base, false);
1074 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1076 if(!member.isProperty)
1082 if(!member.dataType && member.dataTypeString)
1083 member.dataType = ProcessTypeString(member.dataTypeString, false);
1085 DeclareType(neededBy, member.dataType, true, false);
1091 DeclareMembers(neededBy, (Class)member, true);
1098 FinishTemplatesContext(context);
1100 return topMember ? topMember.memberID : _class.memberID;
1103 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1107 for(def = definitions->first; def; def = def.next)
1109 if(def.type == declarationClassDef)
1111 Declaration decl = def.decl;
1112 if(decl && decl.specifiers)
1115 bool isStruct = false;
1116 for(spec = decl.specifiers->first; spec; spec = spec.next)
1118 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1120 if(spec.definitions)
1121 IdentifyAnonStructs(spec.definitions);
1127 Declarator d = null;
1128 if(decl.declarators)
1130 for(d = decl.declarators->first; d; d = d.next)
1132 Identifier idDecl = GetDeclId(d);
1140 sprintf(id, "__anon%d", anonID++);
1141 if(!decl.declarators)
1142 decl.declarators = MkList();
1143 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1151 External DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference)
1153 return _DeclareStruct(neededBy, name, skipNoHead, needDereference, false);
1156 External _DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference, bool fwdDecl)
1158 External external = null;
1159 Symbol classSym = FindClass(name);
1160 OldList * curDeclarations = null;
1162 if(!inCompiler || !classSym) return null;
1164 // We don't need any declaration for bit classes...
1165 if(classSym.registered &&
1166 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1169 if(!classSym.registered || (classSym.registered.type == normalClass && classSym.registered.structSize && classSym.registered.base && classSym.registered.base.base))
1170 _DeclareStruct(neededBy, "ecere::com::Instance", false, true, fwdDecl);
1172 external = classSym.structExternal;
1174 if(external && external.declaration)
1177 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1178 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1180 curDeclarations = spec.definitions;
1185 if(classSym.registered && !classSym.declaring && classSym.imported && (!classSym.declaredStructSym || (classSym.registered.type == noHeadClass && !skipNoHead && external && !curDeclarations)))
1187 OldList * specifiers, * declarators;
1188 OldList * declarations = null;
1189 char structName[1024];
1190 bool addedPadding = false;
1191 Specifier curSpec = null;
1193 classSym.declaring++;
1195 if(strchr(classSym.string, '<'))
1197 if(classSym.registered.templateClass)
1198 external = _DeclareStruct(neededBy, classSym.registered.templateClass.fullName, skipNoHead, needDereference, fwdDecl);
1199 classSym.declaring--;
1204 FullClassNameCat(structName, name, false);
1206 classSym.declaredStructSym = true;
1207 if(!external || (classSym.registered.type == noHeadClass && !skipNoHead && !curDeclarations))
1212 external = MkExternalDeclaration(null);
1213 classSym.structExternal = external;
1214 external.symbol = classSym;
1221 declarations = MkList();
1222 AddMembers(external, declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1225 if(external.declaration)
1228 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1229 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1232 curDeclarations = spec.definitions;
1237 if(declarations && (!declarations->count || (declarations->count == 1 && addedPadding)))
1239 FreeList(declarations, FreeClassDef);
1240 declarations = null;
1243 if(classSym.registered.type != noHeadClass && !declarations)
1245 FreeExternal(external);
1247 classSym.structExternal = null;
1252 curSpec.definitions = declarations;
1255 specifiers = MkList();
1256 declarators = MkList();
1257 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1258 external.declaration = MkDeclaration(specifiers, declarators);
1264 classSym.declaring--;
1266 else if(!classSym.declaredStructSym && classSym.structExternal)
1268 classSym.declaredStructSym = true;
1270 if(classSym.registered)
1271 DeclareMembers(classSym.structExternal, classSym.registered, false);
1273 if(classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1276 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1278 if(spec.definitions)
1279 IdentifyAnonStructs(spec.definitions);
1283 if(inCompiler && neededBy && (external || !classSym.imported))
1287 classSym.structExternal = external = MkExternalDeclaration(null);
1288 external.symbol = classSym;
1291 if(reachedPass15 && !external.declaration && classSym.registered && classSym.registered.type == noHeadClass)
1293 // Declare nohead classes without definitions here (e.g. IteratorPointer)
1294 char structName[1024];
1295 OldList * specifiers, * declarators;
1297 FullClassNameCat(structName, name, false);
1298 specifiers = MkList();
1299 declarators = MkList();
1300 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), null));
1301 external.declaration = MkDeclaration(specifiers, declarators);
1305 External e = external.fwdDecl ? external.fwdDecl : external;
1306 if(e.incoming.count)
1307 neededBy.CreateUniqueEdge(e, !needDereference && !external.fwdDecl);
1310 neededBy.CreateUniqueEdge(external, !needDereference);
1315 void DeclareProperty(External neededBy, Property prop, char * setName, char * getName)
1317 Symbol symbol = prop.symbol;
1318 bool imported = false;
1319 bool dllImport = false;
1320 External structExternal = null;
1321 External instExternal = null;
1323 strcpy(setName, "__ecereProp_");
1324 FullClassNameCat(setName, prop._class.fullName, false);
1325 strcat(setName, "_Set_");
1326 FullClassNameCat(setName, prop.name, true);
1328 strcpy(getName, "__ecereProp_");
1329 FullClassNameCat(getName, prop._class.fullName, false);
1330 strcat(getName, "_Get_");
1331 FullClassNameCat(getName, prop.name, true);
1333 if(!symbol || symbol._import)
1339 if(!prop._class.symbol)
1340 prop._class.symbol = FindClass(prop._class.fullName);
1341 classSym = prop._class.symbol;
1342 if(classSym && !classSym._import)
1344 ModuleImport module;
1346 if(prop._class.module)
1347 module = FindModule(prop._class.module);
1349 module = mainModule;
1351 classSym._import = ClassImport
1353 name = CopyString(prop._class.fullName);
1354 isRemote = prop._class.isRemote;
1356 module.classes.Add(classSym._import);
1358 symbol = prop.symbol = Symbol { };
1359 symbol._import = (ClassImport)PropertyImport
1361 name = CopyString(prop.name);
1362 isVirtual = false; //prop.isVirtual;
1363 hasSet = prop.Set ? true : false;
1364 hasGet = prop.Get ? true : false;
1367 classSym._import.properties.Add(symbol._import);
1370 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1371 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1372 prop._class.module.importType != staticImport)
1378 Context context = SetupTemplatesContext(prop._class);
1379 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1380 FinishTemplatesContext(context);
1383 if((prop.Get && !symbol.externalGet) || (prop.Set && !symbol.externalSet))
1385 if(prop._class.type == normalClass && prop._class.structSize)
1386 instExternal = DeclareStruct(null, "ecere::com::Instance", false, true);
1387 structExternal = DeclareStruct(null, prop._class.fullName, prop._class.type != structClass /*true*/, false);
1391 if(prop.Get && !symbol.externalGet)
1394 OldList * specifiers, * declarators;
1397 Specifier spec = null;
1399 Declarator typeDecl;
1400 bool simple = false;
1403 specifiers = MkList();
1404 declarators = MkList();
1407 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1408 MkDeclaratorIdentifier(MkIdentifier("this"))));
1410 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1413 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1416 Context context = SetupTemplatesContext(prop._class);
1417 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1418 FinishTemplatesContext(context);
1421 // Make sure the simple _class's type is declared
1422 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1423 for(spec = specifiers->first; spec; spec = spec.next)
1425 if(spec.type == nameSpecifier)
1427 Symbol classSym = spec.symbol;
1430 symbol._class = classSym.registered;
1431 if(classSym.registered && classSym.registered.type == structClass)
1439 d = PlugDeclarator(typeDecl, d);
1442 ListAdd(params, MkTypeName(specifiers,
1443 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1444 specifiers = MkList();
1447 d = MkDeclaratorFunction(d, params);
1451 specifiers->Insert(null, MkSpecifier(EXTERN));
1452 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1453 specifiers->Insert(null, MkSpecifier(STATIC));
1455 ListAdd(specifiers, MkSpecifier(VOID));
1457 ListAdd(declarators, MkInitDeclarator(d, null));
1459 decl = MkDeclaration(specifiers, declarators);
1461 external = MkExternalDeclaration(decl);
1464 external.CreateEdge(structExternal, false);
1466 external.CreateEdge(instExternal, false);
1469 DeclareStruct(external, spec.name, false, needReference);
1472 external.symbol = symbol;
1473 symbol.externalGet = external;
1475 ReplaceThisClassSpecifiers(specifiers, prop._class);
1478 FreeDeclarator(typeDecl);
1482 if(prop.Set && !symbol.externalSet)
1485 OldList * specifiers, * declarators;
1488 Specifier spec = null;
1490 Declarator typeDecl;
1493 declarators = MkList();
1496 if(!prop.conversion || prop._class.type == structClass)
1498 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1499 MkDeclaratorIdentifier(MkIdentifier("this"))));
1502 specifiers = MkList();
1505 Context context = SetupTemplatesContext(prop._class);
1506 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1507 MkDeclaratorIdentifier(MkIdentifier("value")));
1508 FinishTemplatesContext(context);
1510 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1511 specifiers->Insert(null, MkSpecifier(CONST));
1513 ListAdd(params, MkTypeName(specifiers, d));
1515 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1517 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1518 d = MkDeclaratorFunction(d, params);
1520 // Make sure the simple _class's type is declared
1521 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1522 for(spec = specifiers->first; spec; spec = spec.next)
1524 if(spec.type == nameSpecifier)
1526 Symbol classSym = spec.symbol;
1528 symbol._class = classSym.registered;
1533 ListAdd(declarators, MkInitDeclarator(d, null));
1535 specifiers = MkList();
1537 specifiers->Insert(null, MkSpecifier(EXTERN));
1538 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1539 specifiers->Insert(null, MkSpecifier(STATIC));
1541 if(!prop.conversion || prop._class.type == structClass)
1542 ListAdd(specifiers, MkSpecifier(VOID));
1544 ListAdd(specifiers, MkSpecifierName(prop._class.fullName));
1546 decl = MkDeclaration(specifiers, declarators);
1548 external = MkExternalDeclaration(decl);
1551 external.CreateEdge(structExternal, false);
1553 external.CreateEdge(instExternal, false);
1556 DeclareStruct(external, spec.name, false, needReference);
1559 external.symbol = symbol;
1560 symbol.externalSet = external;
1562 ReplaceThisClassSpecifiers(specifiers, prop._class);
1565 // Property (for Watchers)
1566 if(!symbol.externalPtr)
1570 OldList * specifiers = MkList();
1571 char propName[1024];
1574 specifiers->Insert(null, MkSpecifier(EXTERN));
1577 specifiers->Insert(null, MkSpecifier(STATIC));
1578 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1581 ListAdd(specifiers, MkSpecifierName("Property"));
1583 strcpy(propName, "__ecereProp_");
1584 FullClassNameCat(propName, prop._class.fullName, false);
1585 strcat(propName, "_");
1586 FullClassNameCat(propName, prop.name, true);
1589 OldList * list = MkList();
1590 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1594 strcpy(propName, "__ecerePropM_");
1595 FullClassNameCat(propName, prop._class.fullName, false);
1596 strcat(propName, "_");
1597 FullClassNameCat(propName, prop.name, true);
1599 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1601 decl = MkDeclaration(specifiers, list);
1604 external = MkExternalDeclaration(decl);
1605 ast->Insert(curExternal.prev, external);
1606 external.symbol = symbol;
1607 symbol.externalPtr = external;
1610 if(inCompiler && neededBy)
1612 // Could improve this to create edge on only what is needed...
1613 if(symbol.externalPtr)
1614 neededBy.CreateUniqueEdge(symbol.externalPtr, false);
1616 if(symbol.externalGet)
1617 neededBy.CreateUniqueEdge(symbol.externalGet, symbol.externalGet.type == functionExternal);
1619 if(symbol.externalSet)
1620 neededBy.CreateUniqueEdge(symbol.externalSet, symbol.externalSet.type == functionExternal);
1626 // ***************** EXPRESSION PROCESSING ***************************
1627 public Type Dereference(Type source)
1632 if(source.kind == pointerType || source.kind == arrayType)
1635 source.type.refCount++;
1637 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1645 // Support dereferencing of no head classes for now...
1646 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1652 Compiler_Error($"cannot dereference type\n");
1657 static Type Reference(Type source)
1673 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1675 Identifier ident = member.identifiers ? member.identifiers->first : null;
1677 DataMember dataMember = null;
1678 Method method = null;
1679 bool freeType = false;
1681 yylloc = member.loc;
1687 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1691 dataMember = *curMember;
1697 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1698 DataMember _subMemberStack[256];
1699 int _subMemberStackPos = 0;
1701 // FILL MEMBER STACK
1703 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1706 dataMember = thisMember;
1707 if(curMember && thisMember.memberAccess == publicAccess)
1709 *curMember = thisMember;
1710 *curClass = thisMember._class;
1711 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1712 *subMemberStackPos = _subMemberStackPos;
1719 method = eClass_FindMethod(_class, ident.string, privateModule);
1720 if(method && method.type == virtualMethod)
1732 if(!dataMember.dataType && dataMember.dataTypeString)
1734 //Context context = SetupTemplatesContext(dataMember._class);
1735 Context context = SetupTemplatesContext(_class);
1736 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1737 FinishTemplatesContext(context);
1739 type = dataMember.dataType;
1743 // This is for destination type...
1744 if(!method.dataType)
1745 ProcessMethodType(method);
1746 //DeclareMethod(method);
1747 // method.dataType = ((Symbol)method.symbol)->type;
1748 type = method.dataType;
1751 if(ident && ident.next)
1753 for(ident = ident.next; ident && type; ident = ident.next)
1755 if(type.kind == classType)
1757 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1759 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1761 type = dataMember.dataType;
1763 else if(type.kind == structType || type.kind == unionType)
1766 for(memberType = type.members.first; memberType; memberType = memberType.next)
1768 if(!strcmp(memberType.name, ident.string))
1778 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1779 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1782 ClassTemplateParameter curParam = null;
1784 for(sClass = _class; sClass; sClass = sClass.base)
1787 if(sClass.templateClass) sClass = sClass.templateClass;
1788 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1790 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1792 for(sClass = sClass.base; sClass; sClass = sClass.base)
1794 if(sClass.templateClass) sClass = sClass.templateClass;
1795 id += sClass.templateParams.count;
1806 ClassTemplateArgument arg = _class.templateArgs[id];
1807 if(arg.dataTypeString)
1809 bool constant = type.constant;
1811 type = ProcessTypeString(arg.dataTypeString, false);
1812 if(type.kind == classType && constant) type.constant = true;
1813 else if(type.kind == pointerType)
1816 while(t.kind == pointerType) t = t.type;
1817 if(constant) t.constant = constant;
1820 if(type && _class.templateClass)
1821 type.passAsTemplate = true;
1827 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1828 exp.destType.refCount++;
1834 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1836 Class expClass = type._class.registered;
1837 Class cClass = null;
1841 char templateString[1024];
1842 ClassTemplateParameter param;
1843 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1844 for(cClass = expClass; cClass; cClass = cClass.base)
1847 if(cClass.templateClass) cClass = cClass.templateClass;
1848 for(param = cClass.templateParams.first; param; param = param.next)
1852 ClassTemplateArgument arg;
1853 for(sClass = cClass.base; sClass; sClass = sClass.base)
1855 if(sClass.templateClass) sClass = sClass.templateClass;
1856 id += sClass.templateParams.count;
1858 arg = expClass.templateArgs[id];
1860 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1862 ClassTemplateParameter cParam;
1863 //int p = numParams - sClass.templateParams.count;
1866 if(sClass.templateClass) sClass = sClass.templateClass;
1868 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1870 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1871 p += nextClass.templateParams.count;
1874 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1876 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1878 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1880 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1881 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1893 strcat(argument, arg.name.string);
1894 strcat(argument, " = ");
1900 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1901 char expString[1024];
1902 OldList * specs = MkList();
1903 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1905 char * string = PrintHexUInt64(arg.expression.ui64);
1906 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1909 ProcessExpressionType(exp);
1910 ComputeExpression(exp);
1911 expString[0] = '\0';
1912 PrintExpression(exp, expString);
1913 strcat(argument, expString);
1915 FreeExpression(exp);
1920 strcat(argument, arg.member.name);
1923 case TemplateParameterType::type:
1925 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1926 strcat(argument, arg.dataTypeString);
1932 if(paramCount) strcat(templateString, ", ");
1933 if(lastParam != p - 1)
1935 strcat(templateString, param.name);
1936 strcat(templateString, " = ");
1938 strcat(templateString, argument);
1947 int len = strlen(templateString);
1948 if(templateString[len-1] == '<')
1952 if(templateString[len-1] == '>')
1953 templateString[len++] = ' ';
1954 templateString[len++] = '>';
1956 templateString[len++] = '\0';
1959 Context context = SetupTemplatesContext(_class);
1960 if(freeType) FreeType(type);
1961 type = ProcessTypeString(templateString, false);
1963 FinishTemplatesContext(context);
1967 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1969 ProcessExpressionType(member.initializer.exp);
1970 if(!member.initializer.exp.expType)
1974 char expString[10240];
1975 expString[0] = '\0';
1976 PrintExpression(member.initializer.exp, expString);
1977 ChangeCh(expString, '\n', ' ');
1978 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1981 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1982 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1984 Compiler_Error($"incompatible instance method %s\n", ident.string);
1987 else if(member.initializer)
1990 FreeType(member.exp.destType);
1991 member.exp.destType = type;
1992 if(member.exp.destType)
1993 member.exp.destType.refCount++;
1994 ProcessExpressionType(member.exp);
1997 ProcessInitializer(member.initializer, type);
1999 if(freeType) FreeType(type);
2003 if(_class && _class.type == unitClass)
2005 if(member.initializer)
2008 FreeType(member.exp.destType);
2009 member.exp.destType = MkClassType(_class.fullName);
2010 ProcessExpressionType(member.initializer, type);
2012 Type type = MkClassType(_class.fullName);
2013 ProcessInitializer(member.initializer, type);
2019 if(member.initializer)
2021 //ProcessExpressionType(member.exp);
2022 ProcessInitializer(member.initializer, null);
2028 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2032 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2034 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2038 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2043 void ProcessInstantiationType(Instantiation inst)
2048 MembersInit members;
2052 classSym = inst._class.symbol;
2053 _class = classSym ? classSym.registered : null;
2055 if(!_class || _class.type != noHeadClass)
2056 DeclareStruct(curExternal, inst._class.name, false, true);
2058 afterExternal = afterExternal ? afterExternal : curExternal;
2061 ProcessExpressionType(inst.exp);
2063 inst.isConstant = true;
2066 DataMember curMember = null;
2067 Class curClass = null;
2068 DataMember subMemberStack[256];
2069 int subMemberStackPos = 0;
2071 for(members = inst.members->first; members; members = members.next)
2073 switch(members.type)
2075 case methodMembersInit:
2078 static uint instMethodID = 0;
2079 External external = curExternal;
2080 Context context = curContext;
2081 Declarator declarator = members.function.declarator;
2082 Identifier nameID = GetDeclId(declarator);
2083 char * unmangled = nameID ? nameID.string : null;
2085 External createdExternal = null;
2090 strcpy(name, "__ecereInstMeth_");
2091 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2093 strcat(name, nameID.string);
2095 sprintf(number, "_%08d", instMethodID++);
2096 strcat(name, number);
2097 nameID.string = CopyString(name);
2100 // Do modifications here...
2103 Symbol symbol = declarator.symbol;
2104 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2106 if(method && method.type == virtualMethod)
2108 symbol.method = method;
2109 ProcessMethodType(method);
2111 if(!symbol.type.thisClass)
2113 if(method.dataType.thisClass && currentClass &&
2114 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2116 if(!currentClass.symbol)
2117 currentClass.symbol = FindClass(currentClass.fullName);
2118 symbol.type.thisClass = currentClass.symbol;
2123 _class.symbol = FindClass(_class.fullName);
2124 symbol.type.thisClass = _class.symbol;
2127 DeclareType(curExternal, symbol.type, true, true);
2132 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2133 unmangled, classSym.string);
2137 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2141 FreeSpecifier(nameID._class);
2142 nameID._class = null;
2145 curExternal = createdExternal;
2148 if(createdExternal.function)
2149 ProcessFunction(createdExternal.function);
2153 curExternal = declarator.symbol.pointerExternal;
2154 ProcessFunction((FunctionDefinition)members.function);
2156 curExternal = external;
2157 curContext = context;
2161 FreeClassFunction(members.function);
2163 // In this pass, turn this into a MemberInitData
2164 exp = QMkExpId(name);
2165 members.type = dataMembersInit;
2166 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2172 case dataMembersInit:
2174 if(members.dataMembers && classSym)
2177 Location oldyyloc = yylloc;
2178 for(member = members.dataMembers->first; member; member = member.next)
2180 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2181 if(member.initializer && !member.initializer.isConstant)
2182 inst.isConstant = false;
2194 void DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2196 _DeclareType(neededFor, type, needDereference, forFunctionDef, false);
2199 void DeclareTypeForwardDeclare(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2201 _DeclareType(neededFor, type, needDereference, forFunctionDef, true);
2204 static void _DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef, bool fwdDecl)
2208 if(type.kind == functionType)
2211 for(param = type.params.first; param; param = param.next)
2212 _DeclareType(neededFor, param, forFunctionDef, false, fwdDecl);
2213 _DeclareType(neededFor, type.returnType, forFunctionDef, false, fwdDecl);
2215 else if(type.kind == pointerType)
2216 _DeclareType(neededFor, type.type, false, false, fwdDecl);
2217 else if(type.kind == classType)
2219 Class c = type._class.registered;
2220 _DeclareStruct(neededFor, c ? c.fullName : "ecere::com::Instance", c ? c.type == noHeadClass : false, needDereference && c && c.type == structClass, fwdDecl);
2222 else if(type.kind == structType || type.kind == unionType)
2225 for(member = type.members.first; member; member = member.next)
2226 _DeclareType(neededFor, member, needDereference, forFunctionDef, fwdDecl);
2228 else if(type.kind == arrayType)
2229 _DeclareType(neededFor, type.arrayType, true, false, fwdDecl);
2233 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2235 ClassTemplateArgument * arg = null;
2237 ClassTemplateParameter curParam = null;
2239 for(sClass = _class; sClass; sClass = sClass.base)
2242 if(sClass.templateClass) sClass = sClass.templateClass;
2243 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2245 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2247 for(sClass = sClass.base; sClass; sClass = sClass.base)
2249 if(sClass.templateClass) sClass = sClass.templateClass;
2250 id += sClass.templateParams.count;
2260 arg = &_class.templateArgs[id];
2261 if(arg && param.type == type)
2262 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2267 public Context SetupTemplatesContext(Class _class)
2269 Context context = PushContext();
2270 context.templateTypesOnly = true;
2271 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2273 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2274 for(; param; param = param.next)
2276 if(param.type == type && param.identifier)
2278 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2279 curContext.templateTypes.Add((BTNode)type);
2286 for(sClass = _class; sClass; sClass = sClass.base)
2288 ClassTemplateParameter p;
2289 for(p = sClass.templateParams.first; p; p = p.next)
2291 //OldList * specs = MkList();
2292 //Declarator decl = null;
2293 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2296 TemplateParameter param = p.param;
2300 // ADD DATA TYPE HERE...
2301 p.param = param = TemplateParameter
2303 identifier = MkIdentifier(p.name), type = p.type,
2304 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2307 type = TemplatedType { key = (uintptr)p.name, param = param };
2308 curContext.templateTypes.Add((BTNode)type);
2316 public void FinishTemplatesContext(Context context)
2318 PopContext(context);
2319 FreeContext(context);
2323 public void ProcessMethodType(Method method)
2325 if(!method.dataType)
2327 Context context = SetupTemplatesContext(method._class);
2329 method.dataType = ProcessTypeString(method.dataTypeString, false);
2331 FinishTemplatesContext(context);
2333 if(method.type != virtualMethod && method.dataType)
2335 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2337 if(!method._class.symbol)
2338 method._class.symbol = FindClass(method._class.fullName);
2339 method.dataType.thisClass = method._class.symbol;
2343 // Why was this commented out? Working fine without now...
2346 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2347 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2354 char * par = strstr(type, "(");
2355 char * classOp = null;
2360 for(c = par-type-1; c >= 0; c++)
2362 if(type[c] == ':' && type[c+1] == ':')
2364 classOp = type + c - 1;
2365 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2372 else if(!isspace(type[c]))
2379 int typeLen = strlen(type);
2380 memcpy(temp, classOp, classOpLen);
2381 temp[classOpLen] = '\0';
2383 _class = eSystem_FindClass(module, temp);
2386 method.dataTypeString = new char[typeLen - classOpLen + 1];
2387 memcpy(method.dataTypeString, type, classOp - type);
2388 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2391 method.dataTypeString = type;
2397 public void ProcessPropertyType(Property prop)
2401 Context context = SetupTemplatesContext(prop._class);
2402 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2403 FinishTemplatesContext(context);
2407 public void DeclareMethod(External neededFor, Method method, const char * name)
2409 Symbol symbol = method.symbol;
2410 if(!symbol || (!symbol.pointerExternal && (!symbol.methodCodeExternal || method.type == virtualMethod)))
2412 bool dllImport = false;
2414 if(!method.dataType)
2415 method.dataType = ProcessTypeString(method.dataTypeString, false);
2417 //if(!symbol || symbol._import || method.type == virtualMethod)
2419 if(!symbol || method.type == virtualMethod)
2422 if(!method._class.symbol)
2423 method._class.symbol = FindClass(method._class.fullName);
2424 classSym = method._class.symbol;
2425 if(!classSym._import)
2427 ModuleImport module;
2429 if(method._class.module && method._class.module.name)
2430 module = FindModule(method._class.module);
2432 module = mainModule;
2433 classSym._import = ClassImport
2435 name = CopyString(method._class.fullName);
2436 isRemote = method._class.isRemote;
2438 module.classes.Add(classSym._import);
2442 symbol = method.symbol = Symbol { };
2446 symbol._import = (ClassImport)MethodImport
2448 name = CopyString(method.name);
2449 isVirtual = method.type == virtualMethod;
2451 classSym._import.methods.Add(symbol._import);
2455 symbol.type = method.dataType;
2456 if(symbol.type) symbol.type.refCount++;
2459 if(!method.dataType.dllExport)
2461 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2468 // We need a declaration here :)
2470 OldList * specifiers, * declarators;
2472 Declarator funcDecl;
2475 specifiers = MkList();
2476 declarators = MkList();
2479 ListAdd(specifiers, MkSpecifier(EXTERN));
2480 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2481 ListAdd(specifiers, MkSpecifier(STATIC));
2483 if(method.type == virtualMethod)
2485 ListAdd(specifiers, MkSpecifier(INT));
2486 d = MkDeclaratorIdentifier(MkIdentifier(name));
2490 d = MkDeclaratorIdentifier(MkIdentifier(name));
2492 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2494 Context context = SetupTemplatesContext(method._class);
2495 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2496 FinishTemplatesContext(context);
2498 funcDecl = GetFuncDecl(d);
2502 Specifier spec, next;
2503 for(spec = specifiers->first; spec; spec = next)
2506 if(spec.type == extendedSpecifier)
2508 specifiers->Remove(spec);
2509 FreeSpecifier(spec);
2514 // Add this parameter if not a static method
2515 if(method.dataType && !method.dataType.staticMethod)
2517 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2519 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2520 TypeName thisParam = MkTypeName(MkListOne(
2521 MkSpecifierName(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2522 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2523 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2524 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2526 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2528 TypeName param = funcDecl.function.parameters->first;
2529 funcDecl.function.parameters->Remove(param);
2530 FreeTypeName(param);
2533 if(!funcDecl.function.parameters)
2534 funcDecl.function.parameters = MkList();
2535 funcDecl.function.parameters->Insert(null, thisParam);
2539 ProcessDeclarator(d, true);
2541 ListAdd(declarators, MkInitDeclarator(d, null));
2543 decl = MkDeclaration(specifiers, declarators);
2545 ReplaceThisClassSpecifiers(specifiers, method._class);
2547 external = MkExternalDeclaration(decl);
2548 external.symbol = symbol;
2549 symbol.pointerExternal = external;
2551 DeclareStruct(external, method._class.fullName, true, true);
2553 DeclareType(external, method.dataType, true, true);
2556 if(inCompiler && neededFor)
2558 External external = symbol.pointerExternal ? symbol.pointerExternal : symbol.methodCodeExternal;
2559 neededFor.CreateUniqueEdge(external, external.type == functionExternal);
2563 char * ReplaceThisClass(Class _class)
2565 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2569 ClassTemplateParameter param;
2572 char className[1024];
2573 strcpy(className, _class.fullName);
2574 for(param = _class.templateParams.first; param; param = param.next)
2576 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2578 if(first) strcat(className, "<");
2579 if(!first) strcat(className, ", ");
2580 if(lastParam + 1 != p)
2582 strcat(className, param.name);
2583 strcat(className, " = ");
2585 strcat(className, param.name);
2593 int len = strlen(className);
2594 if(className[len-1] == '>') className[len++] = ' ';
2595 className[len++] = '>';
2596 className[len++] = '\0';
2598 return CopyString(className);
2601 return CopyString(_class.fullName);
2604 Type ReplaceThisClassType(Class _class)
2607 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2611 ClassTemplateParameter param;
2613 char className[1024];
2614 strcpy(className, _class.fullName);
2616 for(param = _class.templateParams.first; param; param = param.next)
2618 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2620 if(first) strcat(className, "<");
2621 if(!first) strcat(className, ", ");
2622 if(lastParam + 1 != p)
2624 strcat(className, param.name);
2625 strcat(className, " = ");
2627 strcat(className, param.name);
2635 int len = strlen(className);
2636 if(className[len-1] == '>') className[len++] = ' ';
2637 className[len++] = '>';
2638 className[len++] = '\0';
2640 type = MkClassType(className);
2641 //type = ProcessTypeString(className, false);
2645 type = MkClassType(_class.fullName);
2646 //type = ProcessTypeString(_class.fullName, false);
2648 //type.wasThisClass = true;
2652 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2654 if(specs != null && _class)
2657 for(spec = specs.first; spec; spec = spec.next)
2659 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2661 spec.type = nameSpecifier;
2662 spec.name = ReplaceThisClass(_class);
2663 spec.symbol = FindClass(spec.name); //_class.symbol;
2669 // Returns imported or not
2670 bool DeclareFunction(External neededFor, GlobalFunction function, char * name)
2672 Symbol symbol = function.symbol;
2673 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2674 if(!symbol || !symbol.pointerExternal)
2676 bool imported = false;
2677 bool dllImport = false;
2679 if(!function.dataType)
2681 function.dataType = ProcessTypeString(function.dataTypeString, false);
2682 if(!function.dataType.thisClass)
2683 function.dataType.staticMethod = true;
2690 ModuleImport module = FindModule(function.module);
2691 // WARNING: This is not added anywhere...
2692 symbol = function.symbol = Symbol { };
2696 if(!function.dataType.dllExport)
2698 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2699 module.functions.Add(symbol._import);
2702 // Set the symbol type
2704 symbol.type = ProcessTypeString(function.dataTypeString, false);
2705 if(!symbol.type.thisClass)
2706 symbol.type.staticMethod = true;
2709 imported = symbol._import ? true : false;
2710 if(imported && function.module != privateModule && function.module.importType != staticImport)
2716 // TOCHECK: What's with the functionExternal check here? Is it Edge breaking / forward declaration?
2717 //if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2719 // We need a declaration here :)
2721 OldList * specifiers, * declarators;
2723 Declarator funcDecl;
2726 specifiers = MkList();
2727 declarators = MkList();
2729 ListAdd(specifiers, MkSpecifier(EXTERN));
2731 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2733 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2735 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2736 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2737 if(function.module.importType == staticImport)
2740 for(spec = specifiers->first; spec; spec = spec.next)
2741 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2743 specifiers->Remove(spec);
2744 FreeSpecifier(spec);
2749 funcDecl = GetFuncDecl(d);
2751 // Make sure we don't have empty parameter declarations for static methods...
2752 if(funcDecl && !funcDecl.function.parameters)
2754 funcDecl.function.parameters = MkList();
2755 funcDecl.function.parameters->Insert(null,
2756 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2759 ListAdd(declarators, MkInitDeclarator(d, null));
2762 Context oldCtx = curContext;
2763 curContext = globalContext;
2764 decl = MkDeclaration(specifiers, declarators);
2765 curContext = oldCtx;
2768 // Keep a different symbol for the function definition than the declaration...
2769 /* Note: This should be handled by the edge breaking...
2770 if(symbol.pointerExternal && symbol.pointerExternal.type == functionExternal)
2772 Symbol functionSymbol { };
2775 *functionSymbol = *symbol;
2776 functionSymbol.string = CopyString(symbol.string);
2777 if(functionSymbol.type)
2778 functionSymbol.type.refCount++;
2781 excludedSymbols->Add(functionSymbol);
2783 symbol.pointerExternal.symbol = functionSymbol;
2786 external = MkExternalDeclaration(decl);
2788 external.symbol = symbol;
2789 symbol.pointerExternal = external;
2791 DeclareType(external, function.dataType, true, true);
2795 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2796 neededFor.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
2797 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2800 void DeclareGlobalData(External neededFor, GlobalData data)
2802 Symbol symbol = data.symbol;
2803 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2804 if(!symbol || !symbol.pointerExternal)
2809 symbol = data.symbol = Symbol { };
2812 data.dataType = ProcessTypeString(data.dataTypeString, false);
2816 // We need a declaration here :)
2818 OldList * specifiers, * declarators;
2822 specifiers = MkList();
2823 declarators = MkList();
2825 ListAdd(specifiers, MkSpecifier(EXTERN));
2826 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2827 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2829 ListAdd(declarators, MkInitDeclarator(d, null));
2831 decl = MkDeclaration(specifiers, declarators);
2832 external = MkExternalDeclaration(decl);
2834 ast->Insert(curExternal.prev, external);
2835 external.symbol = symbol;
2836 symbol.pointerExternal = external;
2838 DeclareType(external, data.dataType, true, true);
2841 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2842 neededFor.CreateUniqueEdge(symbol.pointerExternal, false);
2845 class Conversion : struct
2847 Conversion prev, next;
2853 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2856 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2857 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2859 Class sourceClass = source.kind == classType ? source._class.registered : null;
2860 Class destClass = dest.kind == classType ? dest._class.registered : null;
2861 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2862 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2864 Type sourceType = source, destType = dest;
2865 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2866 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2867 if(!destType.constant && sourceType.constant)
2871 Compiler_Warning($"discarding const qualifier\n");
2878 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2879 bool isConversionExploration, bool warnConst)
2884 CheckConstCompatibility(source, dest, true);
2885 // Property convert;
2887 if(source.kind == templateType && dest.kind != templateType)
2889 Type type = ProcessTemplateParameterType(source.templateParameter);
2890 if(type) source = type;
2893 if(dest.kind == templateType && source.kind != templateType)
2895 Type type = ProcessTemplateParameterType(dest.templateParameter);
2896 if(type) dest = type;
2899 if(dest.classObjectType == typedObject && dest.kind != functionType)
2901 if(source.classObjectType != anyObject)
2905 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2906 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2914 if(source.kind != functionType && source.classObjectType == anyObject)
2916 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2920 if((dest.kind == structType && source.kind == structType) ||
2921 (dest.kind == unionType && source.kind == unionType))
2923 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2924 (source.members.first && source.members.first == dest.members.first))
2928 if(dest.kind == ellipsisType && source.kind != voidType)
2931 if(dest.kind == pointerType && dest.type.kind == voidType &&
2932 ((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))
2933 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2935 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2937 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2939 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2940 ((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))
2941 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2942 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2944 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2947 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2949 if(source._class.registered && source._class.registered.type == unitClass)
2951 if(conversions != null)
2953 if(source._class.registered == dest._class.registered)
2958 Class sourceBase, destBase;
2959 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2960 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2961 if(sourceBase == destBase)
2965 // Don't match enum inheriting from other enum if resolving enumeration values
2966 // TESTING: !dest.classObjectType
2967 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2969 (!source._class.registered || source._class.registered.type != enumClass) ||
2970 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2974 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2975 if(dest._class && dest._class.registered && source._class && source._class.registered &&
2976 (dest.casted || (enumBaseType && dest._class.registered.type == enumClass &&
2977 (source.kind == classType || // Added this here for a base enum to be acceptable for a derived enum (#139)
2978 source._class.registered.type != enumClass)
2981 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2989 // JUST ADDED THIS...
2990 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2995 // Just added this for Straight conversion of ColorAlpha => Color
2996 if(source.kind == classType)
2999 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3002 for(convert = _class.conversions.first; convert; convert = convert.next)
3004 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3006 Conversion after = (conversions != null) ? conversions.last : null;
3008 if(!convert.dataType)
3009 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3010 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3011 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3012 MatchTypes(convert.dataType, dest, conversions, null, null,
3013 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3014 convert.dataType.kind == classType, false, true, warnConst))
3016 if(!conversions && !convert.Get)
3018 else if(conversions != null)
3020 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3021 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3022 (dest.kind != classType || dest._class.registered != _class.base))
3026 Conversion conv { convert = convert, isGet = true };
3027 // conversions.Add(conv);
3028 conversions.Insert(after, conv);
3041 if(dest.kind == classType)
3044 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3047 for(convert = _class.conversions.first; convert; convert = convert.next)
3049 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3051 Type constType = null;
3052 bool success = false;
3053 // Conversion after = (conversions != null) ? conversions.last : null;
3055 if(!convert.dataType)
3056 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3058 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3061 constType = { kind = pointerType, refCount = 1, type = ptrType };
3062 CopyTypeInto(ptrType, convert.dataType.type);
3063 ptrType.constant = true;
3066 // Just added this equality check to prevent recursion.... Make it safer?
3067 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3068 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3070 if(!conversions && !convert.Set)
3072 else if(conversions != null)
3074 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3075 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3076 (source.kind != classType || source._class.registered != _class.base))
3080 // *** Testing this! ***
3081 Conversion conv { convert = convert };
3082 conversions.Add(conv);
3083 //conversions.Insert(after, conv);
3089 FreeType(constType);
3095 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3097 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3098 (source.kind != classType || source._class.registered.type != structClass))
3102 // TESTING THIS... IS THIS OK??
3103 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3105 if(!dest._class.registered.dataType)
3106 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3107 // Only support this for classes...
3108 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3109 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3111 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3120 if(source.kind == classType)
3123 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3126 for(convert = _class.conversions.first; convert; convert = convert.next)
3128 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3130 Conversion after = (conversions != null) ? conversions.last : null;
3132 if(!convert.dataType)
3133 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3134 if(convert.dataType != source &&
3135 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3136 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3138 if(!conversions && !convert.Get)
3140 else if(conversions != null)
3142 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3143 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3144 (dest.kind != classType || dest._class.registered != _class.base))
3148 Conversion conv { convert = convert, isGet = true };
3150 // conversions.Add(conv);
3151 conversions.Insert(after, conv);
3160 // TESTING THIS... IS THIS OK??
3161 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3163 if(!source._class.registered.dataType)
3164 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3165 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3167 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))
3169 // For bool to be accepted by byte, short, etc.
3170 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3177 if(source.kind == classType || source.kind == subClassType)
3179 else if(dest.kind == source.kind &&
3180 (dest.kind != structType && dest.kind != unionType &&
3181 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3183 // RECENTLY ADDED THESE
3184 else if(dest.kind == doubleType && source.kind == floatType)
3186 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3188 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3190 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3192 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3194 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3196 else if(source.kind == enumType &&
3197 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3199 else if(dest.kind == enumType && !isConversionExploration &&
3200 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3202 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3203 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3205 Type paramSource, paramDest;
3207 if(dest.kind == methodType)
3208 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3209 if(source.kind == methodType)
3210 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3212 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3213 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3214 if(dest.kind == methodType)
3215 dest = dest.method.dataType;
3216 if(source.kind == methodType)
3217 source = source.method.dataType;
3219 paramSource = source.params.first;
3220 if(paramSource && paramSource.kind == voidType) paramSource = null;
3221 paramDest = dest.params.first;
3222 if(paramDest && paramDest.kind == voidType) paramDest = null;
3225 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3226 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3228 // Source thisClass must be derived from destination thisClass
3229 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3230 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3232 if(paramDest && paramDest.kind == classType)
3233 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3235 Compiler_Error($"method class should not take an object\n");
3238 paramDest = paramDest.next;
3240 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3242 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3246 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3248 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3254 // THIS WAS BACKWARDS:
3255 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3256 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3259 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3261 Compiler_Error($"overriding class expected to be derived from method class\n");
3265 paramSource = paramSource.next;
3271 // Source thisClass must be derived from destination thisClass
3272 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3274 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3280 // THIS WAS BACKWARDS TOO??
3281 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3282 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3285 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3287 //Compiler_Error($"overriding class expected to be derived from method class\n");
3295 // Source return type must be derived from destination return type
3296 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3298 Compiler_Warning($"incompatible return type for function\n");
3301 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3303 CheckConstCompatibility(dest.returnType, source.returnType, true);
3307 for(; paramDest; paramDest = paramDest.next)
3311 //Compiler_Warning($"not enough parameters\n");
3312 Compiler_Error($"not enough parameters\n");
3316 Type paramDestType = paramDest;
3317 Type paramSourceType = paramSource;
3318 Type type = paramDestType;
3320 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3321 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3322 paramSource.kind != templateType)
3325 ClassTemplateParameter curParam = null;
3327 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3330 if(sClass.templateClass) sClass = sClass.templateClass;
3331 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3333 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3335 for(sClass = sClass.base; sClass; sClass = sClass.base)
3337 if(sClass.templateClass) sClass = sClass.templateClass;
3338 id += sClass.templateParams.count;
3349 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3350 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3354 // paramDest must be derived from paramSource
3355 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3356 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3360 PrintType(paramDest, type, false, true);
3361 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3363 if(paramDestType != paramDest)
3364 FreeType(paramDestType);
3367 if(paramDestType != paramDest)
3368 FreeType(paramDestType);
3371 paramSource = paramSource.next;
3375 Compiler_Error($"too many parameters\n");
3380 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3384 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3385 (source.kind == arrayType || source.kind == pointerType))
3387 // Pointers to pointer is incompatible with non normal/nohead classes
3388 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3389 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3391 ComputeTypeSize(source.type);
3392 ComputeTypeSize(dest.type);
3393 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3401 static void FreeConvert(Conversion convert)
3403 if(convert.resultType)
3404 FreeType(convert.resultType);
3407 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3408 char * string, OldList conversions)
3412 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3414 Class _class = link.data;
3415 if(_class.type == enumClass)
3417 OldList converts { };
3419 type.kind = classType;
3422 _class.symbol = FindClass(_class.fullName);
3423 type._class = _class.symbol;
3425 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3426 false, false, false, false))
3429 Class enumClass = eSystem_FindClass(privateModule, "enum");
3433 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3435 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3436 for(value = e.values.first; value; value = value.next)
3438 if(!strcmp(value.name, string))
3443 FreeType(sourceExp.expType);
3445 sourceExp.isConstant = true;
3446 sourceExp.expType = MkClassType(baseClass.fullName);
3447 if(inCompiler || inPreCompiler || inDebugger)
3450 FreeExpContents(sourceExp);
3452 sourceExp.type = constantExp;
3453 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3454 sprintf(constant, FORMAT64D, value.data);
3456 sprintf(constant, FORMAT64HEXLL, value.data);
3457 sourceExp.constant = CopyString(constant);
3458 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3461 while(converts.first)
3463 Conversion convert = converts.first;
3464 converts.Remove(convert);
3465 conversions.Add(convert);
3474 converts.Free(FreeConvert);
3478 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3479 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3484 public bool ModuleVisibility(Module searchIn, Module searchFor)
3486 SubModule subModule;
3488 if(searchFor == searchIn)
3491 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3493 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3495 if(ModuleVisibility(subModule.module, searchFor))
3502 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3506 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3508 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3510 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3513 for(module = mainModule.application.allModules.first; module; module = module.next)
3515 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3521 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3524 Type realDest = dest;
3525 Type backupSourceExpType = null;
3526 Expression nbExp = GetNonBracketsExp(sourceExp);
3527 Expression computedExp = nbExp;
3530 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3531 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3533 computedExp = CopyExpression(nbExp); // Keep the original expression, but compute for checking enum ranges
3534 ComputeExpression(computedExp /*sourceExp*/);
3537 source = sourceExp.expType;
3539 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3541 if(computedExp != nbExp)
3543 FreeExpression(computedExp);
3544 computedExp = nbExp;
3550 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3552 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3554 Class sourceBase, destBase;
3555 for(sourceBase = source._class.registered;
3556 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3557 sourceBase = sourceBase.base);
3558 for(destBase = dest._class.registered;
3559 destBase && destBase.base && destBase.base.type != systemClass;
3560 destBase = destBase.base);
3561 //if(source._class.registered == dest._class.registered)
3562 if(sourceBase == destBase)
3564 if(computedExp != nbExp)
3566 FreeExpression(computedExp);
3567 computedExp = nbExp;
3579 int64 value = MAXINT;
3583 if(computedExp.type == constantExp)
3586 value = strtoll(computedExp.constant, null, 0);
3588 value = strtoull(computedExp.constant, null, 0);
3590 else if(computedExp.type == opExp && computedExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3593 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3595 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3597 if(computedExp != nbExp)
3599 FreeExpression(computedExp);
3600 computedExp = nbExp;
3603 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3604 !strcmp(source._class.registered.fullName, "unichar" /*"ecere::com::unichar"*/))
3607 source = Type { kind = intType, isSigned = false, refCount = 1 };
3610 if(dest.kind == classType)
3612 Class _class = dest._class ? dest._class.registered : null;
3614 if(_class && _class.type == unitClass)
3616 if(source.kind != classType)
3619 Type tempDest, tempSource;
3621 for(; _class.base.type != systemClass; _class = _class.base);
3623 tempDest = tempType;
3625 tempType.kind = classType;
3627 _class.symbol = FindClass(_class.fullName);
3629 tempType._class = _class.symbol;
3630 tempType.truth = dest.truth;
3632 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3634 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3635 backupSourceExpType = sourceExp.expType;
3636 if(dest.passAsTemplate)
3638 // Don't carry passAsTemplate
3639 sourceExp.expType = { };
3640 CopyTypeInto(sourceExp.expType, dest);
3641 sourceExp.expType.passAsTemplate = false;
3645 sourceExp.expType = dest;
3648 //sourceExp.expType = MkClassType(_class.fullName);
3656 // Why wasn't there something like this?
3657 if(_class && _class.type == bitClass && source.kind != classType)
3659 if(!dest._class.registered.dataType)
3660 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3661 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3664 FreeType(sourceExp.expType);
3665 source = sourceExp.expType = MkClassType(dest._class.string);
3668 //source.kind = classType;
3669 //source._class = dest._class;
3673 // Adding two enumerations
3675 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3677 if(!source._class.registered.dataType)
3678 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3679 if(!dest._class.registered.dataType)
3680 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3682 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3685 source = sourceExp.expType = MkClassType(dest._class.string);
3688 //source.kind = classType;
3689 //source._class = dest._class;
3693 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3695 OldList * specs = MkList();
3699 ReadString(string, sourceExp.string);
3700 decl = SpecDeclFromString(string, specs, null);
3702 FreeExpContents(sourceExp);
3703 FreeType(sourceExp.expType);
3705 sourceExp.type = classExp;
3706 sourceExp._classExp.specifiers = specs;
3707 sourceExp._classExp.decl = decl;
3708 sourceExp.expType = dest;
3713 if(backupSourceExpType) FreeType(backupSourceExpType);
3717 else if(source.kind == classType)
3719 Class _class = source._class ? source._class.registered : null;
3721 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || _class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3724 if(dest.kind != classType)
3726 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3727 if(!source._class.registered.dataType)
3728 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3731 dest = MkClassType(source._class.string);
3732 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3733 // dest = MkClassType(source._class.string);
3737 if(dest.kind != classType)
3740 Type tempDest, tempSource;
3742 if(!source._class.registered.dataType)
3743 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3745 for(; _class.base.type != systemClass; _class = _class.base);
3747 tempSource = tempType;
3748 tempType.kind = classType;
3749 tempType._class = FindClass(_class.fullName);
3750 tempType.truth = source.truth;
3751 tempType.classObjectType = source.classObjectType;
3754 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3756 // PUT THIS BACK TESTING UNITS?
3757 if(conversions && conversions.last)
3759 ((Conversion)(conversions.last)).resultType = dest;
3763 FreeType(sourceExp.expType);
3764 sourceExp.expType = MkClassType(_class.fullName);
3765 sourceExp.expType.truth = source.truth;
3766 sourceExp.expType.classObjectType = source.classObjectType;
3768 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3770 if(!sourceExp.destType)
3772 FreeType(sourceExp.destType);
3773 sourceExp.destType = sourceExp.expType;
3774 if(sourceExp.expType)
3775 sourceExp.expType.refCount++;
3778 //source = _class.dataType;
3781 // TOCHECK: TESTING THIS NEW CODE
3782 if(!_class.dataType)
3783 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3785 dest = MkClassType(source._class.string);
3786 dest.truth = source.truth;
3787 dest.classObjectType = source.classObjectType;
3790 source = _class.dataType;
3800 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3810 if(source.kind == classType)
3812 Class _class = source._class.registered;
3813 if(_class.type == unitClass)
3815 if(!_class.dataType)
3816 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3817 source = _class.dataType;
3821 if(dest.kind == classType)
3823 Class _class = dest._class ? dest._class.registered : null;
3824 bool fittingValue = false;
3825 if(_class && _class.type == enumClass)
3827 Class enumClass = eSystem_FindClass(privateModule, "enum");
3828 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3829 if(c && value >= 0 && value <= c.largest)
3830 fittingValue = true;
3833 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3834 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3836 if(_class.type == normalClass || _class.type == noHeadClass)
3838 Expression newExp { };
3839 *newExp = *sourceExp;
3840 if(sourceExp.destType) sourceExp.destType.refCount++;
3841 if(sourceExp.expType) sourceExp.expType.refCount++;
3842 sourceExp.type = castExp;
3843 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3844 sourceExp.cast.exp = newExp;
3845 FreeType(sourceExp.expType);
3846 sourceExp.expType = null;
3847 ProcessExpressionType(sourceExp);
3849 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3852 FreeType(sourceExp.expType);
3853 sourceExp.expType = dest;
3857 if(inCompiler) FreeType(dest);
3859 if(backupSourceExpType) FreeType(backupSourceExpType);
3863 if(!_class.dataType)
3864 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3866 dest = _class.dataType;
3870 // Accept lower precision types for units, since we want to keep the unit type
3871 if(dest.kind == doubleType &&
3872 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3873 source.kind == charType || source.kind == _BoolType))
3875 specs = MkListOne(MkSpecifier(DOUBLE));
3877 else if(dest.kind == floatType &&
3878 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3879 source.kind == _BoolType || source.kind == doubleType))
3881 specs = MkListOne(MkSpecifier(FLOAT));
3883 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3884 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3887 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3888 ListAdd(specs, MkSpecifier(INT64));
3890 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3891 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3894 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3895 ListAdd(specs, MkSpecifier(INT));
3897 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3898 source.kind == floatType || source.kind == doubleType))
3901 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3902 ListAdd(specs, MkSpecifier(SHORT));
3904 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3905 source.kind == floatType || source.kind == doubleType))
3908 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3909 ListAdd(specs, MkSpecifier(CHAR));
3915 if(backupSourceExpType)
3917 // Failed to convert: revert previous exp type
3918 if(sourceExp.expType) FreeType(sourceExp.expType);
3919 sourceExp.expType = backupSourceExpType;
3924 else if(dest.kind == doubleType &&
3925 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3926 source.kind == _BoolType || source.kind == charType))
3928 specs = MkListOne(MkSpecifier(DOUBLE));
3930 else if(dest.kind == floatType &&
3931 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3933 specs = MkListOne(MkSpecifier(FLOAT));
3935 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3936 (value == 1 || value == 0))
3939 ListAdd(specs, MkSpecifier(BOOL));
3941 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3942 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3944 if(source.kind == intType)
3948 if(backupSourceExpType) FreeType(backupSourceExpType);
3954 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3955 ListAdd(specs, MkSpecifier(CHAR));
3958 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3959 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3961 if(source.kind == intType)
3965 if(backupSourceExpType) FreeType(backupSourceExpType);
3971 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3972 ListAdd(specs, MkSpecifier(SHORT));
3975 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3978 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3979 ListAdd(specs, MkSpecifier(INT));
3981 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3984 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3985 ListAdd(specs, MkSpecifier(INT64));
3987 else if(dest.kind == enumType &&
3988 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3990 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3996 if(backupSourceExpType)
3998 // Failed to convert: revert previous exp type
3999 if(sourceExp.expType) FreeType(sourceExp.expType);
4000 sourceExp.expType = backupSourceExpType;
4005 if(!flag && !sourceExp.opDestType)
4007 Expression newExp { };
4008 *newExp = *sourceExp;
4011 if(sourceExp.destType) sourceExp.destType.refCount++;
4012 if(sourceExp.expType) sourceExp.expType.refCount++;
4014 sourceExp.type = castExp;
4015 if(realDest.kind == classType)
4017 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4018 FreeList(specs, FreeSpecifier);
4021 sourceExp.cast.typeName = MkTypeName(specs, null);
4022 if(newExp.type == opExp)
4024 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4027 sourceExp.cast.exp = newExp;
4029 FreeType(sourceExp.expType);
4030 sourceExp.expType = null;
4031 ProcessExpressionType(sourceExp);
4034 FreeList(specs, FreeSpecifier);
4038 if(backupSourceExpType) FreeType(backupSourceExpType);
4044 if(computedExp != nbExp)
4046 FreeExpression(computedExp);
4047 computedExp = nbExp;
4050 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4051 if(sourceExp.type == identifierExp)
4053 Identifier id = sourceExp.identifier;
4054 if(dest.kind == classType)
4056 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4058 Class _class = dest._class.registered;
4059 Class enumClass = eSystem_FindClass(privateModule, "enum");
4062 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4065 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4066 for(value = e.values.first; value; value = value.next)
4068 if(!strcmp(value.name, id.string))
4073 FreeType(sourceExp.expType);
4075 sourceExp.isConstant = true;
4076 sourceExp.expType = MkClassType(_class.fullName);
4077 if(inCompiler || inPreCompiler || inDebugger)
4079 FreeExpContents(sourceExp);
4081 sourceExp.type = constantExp;
4082 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4083 sourceExp.constant = PrintInt64(value.data);
4085 sourceExp.constant = PrintUInt64(value.data);
4086 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4096 // Loop through all enum classes
4097 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4108 #define TERTIARY(o, name, m, t, p) \
4109 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4111 exp.type = constantExp; \
4112 exp.string = p(op1.m ? op2.m : op3.m); \
4114 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4118 #define BINARY(o, name, m, t, p) \
4119 static bool name(Expression exp, Operand op1, Operand op2) \
4122 exp.type = constantExp; \
4123 exp.string = p((t)(op1.m o value2)); \
4125 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4129 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4130 static bool name(Expression exp, Operand op1, Operand op2) \
4133 exp.type = constantExp; \
4134 exp.string = p(value2 ? ((t)(op1.m o value2)) : 0); \
4136 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4140 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4141 static bool name(Expression exp, Operand op1, Operand op2) \
4144 exp.type = constantExp; \
4145 exp.string = p((t)(op1.m o value2)); \
4147 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4151 #define UNARY(o, name, m, t, p) \
4152 static bool name(Expression exp, Operand op1) \
4154 exp.type = constantExp; \
4155 exp.string = p((t)(o op1.m)); \
4157 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4161 #define OPERATOR_ALL(macro, o, name) \
4162 macro(o, Int##name, i, int, PrintInt) \
4163 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4164 macro(o, Int64##name, i64, int64, PrintInt64) \
4165 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4166 macro(o, Short##name, s, short, PrintShort) \
4167 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4168 macro(o, Char##name, c, char, PrintChar) \
4169 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4170 macro(o, Float##name, f, float, PrintFloat) \
4171 macro(o, Double##name, d, double, PrintDouble)
4173 #define OPERATOR_INTTYPES(macro, o, name) \
4174 macro(o, Int##name, i, int, PrintInt) \
4175 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4176 macro(o, Int64##name, i64, int64, PrintInt64) \
4177 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4178 macro(o, Short##name, s, short, PrintShort) \
4179 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4180 macro(o, Char##name, c, char, PrintChar) \
4181 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4183 #define OPERATOR_REALTYPES(macro, o, name) \
4184 macro(o, Float##name, f, float, PrintFloat) \
4185 macro(o, Double##name, d, double, PrintDouble)
4187 // binary arithmetic
4188 OPERATOR_ALL(BINARY, +, Add)
4189 OPERATOR_ALL(BINARY, -, Sub)
4190 OPERATOR_ALL(BINARY, *, Mul)
4191 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4192 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4193 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4196 OPERATOR_ALL(UNARY, -, Neg)
4198 // unary arithmetic increment and decrement
4199 OPERATOR_ALL(UNARY, ++, Inc)
4200 OPERATOR_ALL(UNARY, --, Dec)
4202 // binary arithmetic assignment
4203 OPERATOR_ALL(BINARY, =, Asign)
4204 OPERATOR_ALL(BINARY, +=, AddAsign)
4205 OPERATOR_ALL(BINARY, -=, SubAsign)
4206 OPERATOR_ALL(BINARY, *=, MulAsign)
4207 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4208 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4209 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4212 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4213 OPERATOR_INTTYPES(BINARY, |, BitOr)
4214 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4215 OPERATOR_INTTYPES(BINARY, <<, LShift)
4216 OPERATOR_INTTYPES(BINARY, >>, RShift)
4219 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4221 // binary bitwise assignment
4222 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4223 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4224 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4225 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4226 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4228 // unary logical negation
4229 OPERATOR_INTTYPES(UNARY, !, Not)
4231 // binary logical equality
4232 OPERATOR_ALL(BINARY, ==, Equ)
4233 OPERATOR_ALL(BINARY, !=, Nqu)
4236 OPERATOR_ALL(BINARY, &&, And)
4237 OPERATOR_ALL(BINARY, ||, Or)
4239 // binary logical relational
4240 OPERATOR_ALL(BINARY, >, Grt)
4241 OPERATOR_ALL(BINARY, <, Sma)
4242 OPERATOR_ALL(BINARY, >=, GrtEqu)
4243 OPERATOR_ALL(BINARY, <=, SmaEqu)
4245 // tertiary condition operator
4246 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4248 //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
4249 #define OPERATOR_TABLE_ALL(name, type) \
4250 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4252 type##Inc, type##Dec, \
4253 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4254 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4256 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4258 type##Equ, type##Nqu, \
4259 type##And, type##Or, \
4260 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4263 #define OPERATOR_TABLE_INTTYPES(name, type) \
4264 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4266 type##Inc, type##Dec, \
4267 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4268 null, null, null, null, null, \
4270 null, null, null, null, null, \
4272 type##Equ, type##Nqu, \
4273 type##And, type##Or, \
4274 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4277 OPERATOR_TABLE_ALL(int, Int)
4278 OPERATOR_TABLE_ALL(uint, UInt)
4279 OPERATOR_TABLE_ALL(int64, Int64)
4280 OPERATOR_TABLE_ALL(uint64, UInt64)
4281 OPERATOR_TABLE_ALL(short, Short)
4282 OPERATOR_TABLE_ALL(ushort, UShort)
4283 OPERATOR_TABLE_INTTYPES(float, Float)
4284 OPERATOR_TABLE_INTTYPES(double, Double)
4285 OPERATOR_TABLE_ALL(char, Char)
4286 OPERATOR_TABLE_ALL(uchar, UChar)
4288 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4289 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4290 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4291 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4292 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4293 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4294 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4295 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4297 public void ReadString(char * output, char * string)
4299 int len = strlen(string);
4301 bool quoted = false, escaped = false;
4302 for(c = 0; c<len; c++)
4304 char ch = string[c];
4309 case 'n': output[d] = '\n'; break;
4310 case 't': output[d] = '\t'; break;
4311 case 'a': output[d] = '\a'; break;
4312 case 'b': output[d] = '\b'; break;
4313 case 'f': output[d] = '\f'; break;
4314 case 'r': output[d] = '\r'; break;
4315 case 'v': output[d] = '\v'; break;
4316 case '\\': output[d] = '\\'; break;
4317 case '\"': output[d] = '\"'; break;
4318 case '\'': output[d] = '\''; break;
4319 default: output[d] = ch;
4340 // String Unescape Copy
4342 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4343 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4344 public int UnescapeString(char * d, char * s, int len)
4348 while(j < len && (ch = s[j]))
4353 switch((ch = s[++j]))
4355 case 'n': d[k] = '\n'; break;
4356 case 't': d[k] = '\t'; break;
4357 case 'a': d[k] = '\a'; break;
4358 case 'b': d[k] = '\b'; break;
4359 case 'f': d[k] = '\f'; break;
4360 case 'r': d[k] = '\r'; break;
4361 case 'v': d[k] = '\v'; break;
4362 case '\\': d[k] = '\\'; break;
4363 case '\"': d[k] = '\"'; break;
4364 case '\'': d[k] = '\''; break;
4365 default: d[k] = '\\'; d[k] = ch;
4377 public char * OffsetEscapedString(char * s, int len, int offset)
4381 while(j < len && k < offset && (ch = s[j]))
4386 return (k == offset) ? s + j : null;
4389 public Operand GetOperand(Expression exp)
4392 Type type = exp.expType;
4395 while(type.kind == classType && type._class &&
4396 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4398 if(!type._class.registered.dataType)
4399 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4400 type = type._class.registered.dataType;
4403 if(exp.type == stringExp && op.kind == pointerType)
4405 op.ui64 = (uint64)(uintptr)exp.string;
4406 op.kind = pointerType;
4409 else if(exp.isConstant && exp.type == constantExp)
4411 op.kind = type.kind;
4419 if(exp.constant[0] == '\'')
4421 op.c = exp.constant[1];
4424 else if(type.isSigned)
4426 op.c = (char)strtol(exp.constant, null, 0);
4431 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4437 if(exp.constant[0] == '\'')
4439 op.s = exp.constant[1];
4442 else if(type.isSigned)
4444 op.s = (short)strtol(exp.constant, null, 0);
4449 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4455 if(exp.constant[0] == '\'')
4457 op.i = exp.constant[1];
4460 else if(type.isSigned)
4462 op.i = (int)strtol(exp.constant, null, 0);
4467 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4475 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4480 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4483 op.kind = int64Type;
4488 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4493 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4496 op.kind = int64Type;
4501 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4506 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4509 op.kind = int64Type;
4512 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4513 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4514 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4515 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4517 op.f = (float)strtod(exp.constant, null);
4521 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4522 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4523 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4524 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4526 op.d = (double)strtod(exp.constant, null);
4529 //case classType: For when we have operator overloading...
4530 // Pointer additions
4531 //case functionType:
4535 op.ui64 = _strtoui64(exp.constant, null, 0);
4536 op.kind = pointerType;
4546 static int64 GetEnumValue(Class _class, void * ptr)
4549 switch(_class.typeSize)
4552 if(!strcmp(_class.dataTypeString, "uint64"))
4553 v = (int64)*(uint64 *)ptr;
4555 v = (int64)*(int64 *)ptr;
4558 if(!strcmp(_class.dataTypeString, "uint"))
4559 v = (int64)*(uint *)ptr;
4561 v = (int64)*(int *)ptr;
4564 if(!strcmp(_class.dataTypeString, "uint16"))
4565 v = (int64)*(uint16 *)ptr;
4567 v = (int64)*(short *)ptr;
4570 if(!strcmp(_class.dataTypeString, "byte"))
4571 v = (int64)*(byte *)ptr;
4573 v = (int64)*(char *)ptr;
4579 static __attribute__((unused)) void UnusedFunction()
4582 a.OnGetString(0,0,0);
4585 extern int __ecereVMethodID_class_OnGetString;
4588 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4590 DataMember dataMember;
4591 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4593 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4594 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4598 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4600 void * ptr = inst.data + dataMember.offset + offset;
4601 char * result = null;
4602 exp.loc = member.loc = inst.loc;
4603 ((Identifier)member.identifiers->first).loc = inst.loc;
4605 if(!dataMember.dataType)
4606 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4607 type = dataMember.dataType;
4608 if(type.kind == classType)
4610 Class _class = type._class.registered;
4611 if(_class.type == enumClass)
4613 Class enumClass = eSystem_FindClass(privateModule, "enum");
4616 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4618 for(item = e.values.first; item; item = item.next)
4620 if(item.data == GetEnumValue(_class, ptr))
4628 exp.identifier = MkIdentifier(result);
4629 exp.type = identifierExp;
4630 exp.destType = MkClassType(_class.fullName);
4631 ProcessExpressionType(exp);
4635 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4637 if(!_class.dataType)
4638 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4639 type = _class.dataType;
4648 FreeExpContents(exp);
4650 exp.constant = PrintFloat(*(float*)ptr);
4651 exp.type = constantExp;
4656 FreeExpContents(exp);
4658 exp.constant = PrintDouble(*(double*)ptr);
4659 exp.type = constantExp;
4664 FreeExpContents(exp);
4666 exp.constant = PrintInt(*(int*)ptr);
4667 exp.type = constantExp;
4672 FreeExpContents(exp);
4674 exp.constant = PrintInt64(*(int64*)ptr);
4675 exp.type = constantExp;
4680 FreeExpContents(exp);
4681 // TODO: This should probably use proper type
4682 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4683 exp.type = constantExp;
4688 FreeExpContents(exp);
4689 // TODO: This should probably use proper type
4690 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4691 exp.type = constantExp;
4695 Compiler_Error($"Unhandled type populating instance\n");
4698 ListAdd(memberList, member);
4701 if(parentDataMember.type == unionMember)
4706 void PopulateInstance(Instantiation inst)
4708 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4709 Class _class = classSym.registered;
4710 DataMember dataMember;
4711 OldList * memberList = MkList();
4712 // Added this check and ->Add to prevent memory leaks on bad code
4714 inst.members = MkListOne(MkMembersInitList(memberList));
4716 inst.members->Add(MkMembersInitList(memberList));
4717 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4719 if(!dataMember.isProperty)
4721 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4722 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4726 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4728 void * ptr = inst.data + dataMember.offset;
4729 char * result = null;
4731 exp.loc = member.loc = inst.loc;
4732 ((Identifier)member.identifiers->first).loc = inst.loc;
4734 if(!dataMember.dataType)
4735 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4736 type = dataMember.dataType;
4737 if(type.kind == classType)
4739 Class _class = type._class.registered;
4740 if(_class.type == enumClass)
4742 Class enumClass = eSystem_FindClass(privateModule, "enum");
4745 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4747 for(item = e.values.first; item; item = item.next)
4749 if(item.data == GetEnumValue(_class, ptr))
4758 exp.identifier = MkIdentifier(result);
4759 exp.type = identifierExp;
4760 exp.destType = MkClassType(_class.fullName);
4761 ProcessExpressionType(exp);
4764 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4766 if(!_class.dataType)
4767 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4768 type = _class.dataType;
4777 exp.constant = PrintFloat(*(float*)ptr);
4778 exp.type = constantExp;
4783 exp.constant = PrintDouble(*(double*)ptr);
4784 exp.type = constantExp;
4789 exp.constant = PrintInt(*(int*)ptr);
4790 exp.type = constantExp;
4795 exp.constant = PrintInt64(*(int64*)ptr);
4796 exp.type = constantExp;
4801 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4802 exp.type = constantExp;
4806 Compiler_Error($"Unhandled type populating instance\n");
4809 ListAdd(memberList, member);
4815 void ComputeInstantiation(Expression exp)
4817 Instantiation inst = exp.instance;
4818 MembersInit members;
4819 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4820 Class _class = classSym ? classSym.registered : null;
4821 DataMember curMember = null;
4822 Class curClass = null;
4823 DataMember subMemberStack[256];
4824 int subMemberStackPos = 0;
4827 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4829 // Don't recompute the instantiation...
4830 // Non Simple classes will have become constants by now
4834 if(_class.type == normalClass || _class.type == noHeadClass)
4836 inst.data = (byte *)eInstance_New(_class);
4837 if(_class.type == normalClass)
4838 ((Instance)inst.data)._refCount++;
4841 inst.data = new0 byte[_class.structSize];
4846 for(members = inst.members->first; members; members = members.next)
4848 switch(members.type)
4850 case dataMembersInit:
4852 if(members.dataMembers)
4855 for(member = members.dataMembers->first; member; member = member.next)
4857 Identifier ident = member.identifiers ? member.identifiers->first : null;
4860 Property prop = null;
4861 DataMember dataMember = null;
4862 uint dataMemberOffset;
4866 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4869 if(curMember.isProperty)
4870 prop = (Property)curMember;
4873 dataMember = curMember;
4875 // CHANGED THIS HERE
4876 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4878 // 2013/17/29 -- It seems that this was missing here!
4879 if(_class.type == normalClass)
4880 dataMemberOffset += _class.base.structSize;
4881 // dataMemberOffset = dataMember.offset;
4888 prop = eClass_FindProperty(_class, ident.string, privateModule);
4892 if(prop.memberAccess == publicAccess)
4894 curMember = (DataMember)prop;
4895 curClass = prop._class;
4900 DataMember _subMemberStack[256];
4901 int _subMemberStackPos = 0;
4903 // FILL MEMBER STACK
4904 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4909 if(dataMember.memberAccess == publicAccess)
4911 curMember = dataMember;
4912 curClass = dataMember._class;
4913 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4914 subMemberStackPos = _subMemberStackPos;
4920 if(found && member.initializer && member.initializer.type == expInitializer)
4922 Expression value = member.initializer.exp;
4924 bool deepMember = false;
4927 type = prop.dataType;
4931 if(!dataMember.dataType)
4932 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4934 type = dataMember.dataType;
4937 if(ident && ident.next)
4941 // for(; ident && type; ident = ident.next)
4942 for(ident = ident.next; ident && type; ident = ident.next)
4944 if(type.kind == classType)
4946 prop = eClass_FindProperty(type._class.registered,
4947 ident.string, privateModule);
4949 type = prop.dataType;
4952 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4953 ident.string, &dataMemberOffset, privateModule, null, null);
4955 type = dataMember.dataType;
4958 else if(type.kind == structType || type.kind == unionType)
4961 for(memberType = type.members.first; memberType; memberType = memberType.next)
4963 if(!strcmp(memberType.name, ident.string))
4974 FreeType(value.destType);
4975 value.destType = type;
4976 if(type) type.refCount++;
4977 ComputeExpression(value);
4979 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4981 if(type.kind == classType)
4983 Class _class = type._class.registered;
4984 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4986 if(!_class.dataType)
4987 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4988 type = _class.dataType;
4994 void * ptr = inst.data + dataMemberOffset;
4996 if(value.type == constantExp)
5002 GetInt(value, (int*)ptr);
5007 GetInt64(value, (int64*)ptr);
5012 GetIntPtr(value, (intptr*)ptr);
5017 GetIntSize(value, (intsize*)ptr);
5022 GetFloat(value, (float*)ptr);
5027 GetDouble(value, (double *)ptr);
5032 else if(value.type == instanceExp)
5034 if(type.kind == classType)
5036 Class _class = type._class.registered;
5037 if(_class.type == structClass)
5039 ComputeTypeSize(type);
5040 if(value.instance.data)
5041 memcpy(ptr, value.instance.data, type.size);
5046 else if(prop && prop.Set != (void *)(intptr)1)
5048 if(value.type == instanceExp && value.instance.data)
5050 if(type.kind == classType)
5052 Class _class = type._class.registered;
5053 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5055 void (*Set)(void *, void *) = (void *)prop.Set;
5056 Set(inst.data, value.instance.data);
5057 PopulateInstance(inst);
5061 else if(value.type == constantExp)
5067 void (*Set)(void *, double) = (void *)prop.Set;
5068 Set(inst.data, strtod(value.constant, null) );
5073 void (*Set)(void *, float) = (void *)prop.Set;
5074 Set(inst.data, (float)(strtod(value.constant, null)));
5079 void (*Set)(void *, int) = (void *)prop.Set;
5080 Set(inst.data, (int)strtol(value.constant, null, 0));
5085 void (*Set)(void *, int64) = (void *)prop.Set;
5086 Set(inst.data, _strtoi64(value.constant, null, 0));
5091 void (*Set)(void *, intptr) = (void *)prop.Set;
5092 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5097 void (*Set)(void *, intsize) = (void *)prop.Set;
5098 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5103 else if(value.type == stringExp)
5106 ReadString(temp, value.string);
5107 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5111 else if(!deepMember && type && _class.type == unitClass)
5115 // Only support converting units to units for now...
5116 if(value.type == constantExp)
5118 if(type.kind == classType)
5120 Class _class = type._class.registered;
5121 if(_class.type == unitClass)
5123 if(!_class.dataType)
5124 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5125 type = _class.dataType;
5128 // TODO: Assuming same base type for units...
5134 float (*Set)(float) = (void *)prop.Set;
5135 GetFloat(member.initializer.exp, &fValue);
5136 exp.constant = PrintFloat(Set(fValue));
5137 exp.type = constantExp;
5143 double (*Set)(double) = (void *)prop.Set;
5144 GetDouble(member.initializer.exp, &dValue);
5145 exp.constant = PrintDouble(Set(dValue));
5146 exp.type = constantExp;
5153 else if(!deepMember && type && _class.type == bitClass)
5157 if(value.type == instanceExp && value.instance.data)
5159 unsigned int (*Set)(void *) = (void *)prop.Set;
5160 bits = Set(value.instance.data);
5162 else if(value.type == constantExp)
5168 BitMember bitMember = (BitMember) dataMember;
5171 bits = (bits & ~bitMember.mask);
5172 if(!bitMember.dataType)
5173 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5174 type = bitMember.dataType;
5175 if(type.kind == classType && type._class && type._class.registered)
5177 if(!type._class.registered.dataType)
5178 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5179 type = type._class.registered.dataType;
5184 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5185 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5187 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5188 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5189 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5190 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5192 bits |= part << bitMember.pos;
5198 if(_class && _class.type == unitClass)
5200 ComputeExpression(member.initializer.exp);
5201 exp.constant = member.initializer.exp.constant;
5202 exp.type = constantExp;
5204 member.initializer.exp.constant = null;
5214 if(_class && _class.type == bitClass)
5216 exp.constant = PrintHexUInt(bits);
5217 exp.type = constantExp;
5219 if(exp.type != instanceExp)
5225 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5227 bool result = false;
5231 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5232 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5236 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5237 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5240 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5241 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5242 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5245 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5246 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5247 result = GetOpFloat(op, &op.f);
5250 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5251 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5252 result = GetOpDouble(op, &op.d);
5255 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5256 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5257 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5260 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5261 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5262 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5265 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5266 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5269 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5270 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5276 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5278 if(exp.op.op == SIZEOF)
5280 FreeExpContents(exp);
5281 exp.type = constantExp;
5282 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5293 // Provide default unary +
5294 Expression exp2 = exp.op.exp2;
5296 FreeExpContents(exp);
5297 FreeType(exp.expType);
5298 FreeType(exp.destType);
5304 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5306 // unary arithmetic increment and decrement
5307 //OPERATOR_ALL(UNARY, ++, Inc)
5308 //OPERATOR_ALL(UNARY, --, Dec)
5311 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5313 // unary logical negation
5315 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5321 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5323 if(Promote(op2, op1.kind, op1.type.isSigned))
5324 op2.kind = op1.kind, op2.ops = op1.ops;
5325 else if(Promote(op1, op2.kind, op2.type.isSigned))
5326 op1.kind = op2.kind, op1.ops = op2.ops;
5330 // binary arithmetic
5332 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5335 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5338 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5341 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5344 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5346 // binary arithmetic assignment
5347 //OPERATOR_ALL(BINARY, =, Asign)
5348 //OPERATOR_ALL(BINARY, +=, AddAsign)
5349 //OPERATOR_ALL(BINARY, -=, SubAsign)
5350 //OPERATOR_ALL(BINARY, *=, MulAsign)
5351 //OPERATOR_ALL(BINARY, /=, DivAsign)
5352 //OPERATOR_ALL(BINARY, %=, ModAsign)
5357 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5361 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5364 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5367 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5370 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5372 // binary bitwise assignment
5373 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5374 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5375 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5376 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5377 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5378 // binary logical equality
5380 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5383 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5387 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5390 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5392 // binary logical relational
5394 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5397 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5400 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5403 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5410 void ComputeExpression(Expression exp)
5413 char expString[10240];
5414 expString[0] = '\0';
5415 PrintExpression(exp, expString);
5422 Identifier id = exp.identifier;
5423 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5425 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5426 if(c && c.type == enumClass)
5428 Class enumClass = eSystem_FindClass(privateModule, "enum");
5432 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5433 for(value = e.values.first; value; value = value.next)
5435 if(!strcmp(value.name, id.string))
5440 const String dts = c.dataTypeString;
5441 FreeExpContents(exp);
5442 exp.type = constantExp;
5443 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5452 ComputeInstantiation(exp);
5461 Expression exp1, exp2 = null;
5465 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5468 Expression e = exp.op.exp2;
5470 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5472 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5474 if(e.type == extensionCompoundExp)
5475 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5480 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5482 if(e.type == stringExp && e.string)
5484 char * string = e.string;
5485 int len = strlen(string);
5486 char * tmp = new char[len-2+1];
5487 len = UnescapeString(tmp, string + 1, len - 2);
5489 FreeExpContents(exp);
5490 exp.type = constantExp;
5491 exp.constant = PrintUInt(len + 1);
5495 Type type = e.expType;
5497 FreeExpContents(exp);
5498 exp.type = constantExp;
5499 exp.constant = PrintUInt(ComputeTypeSize(type));
5505 ComputeExpression(exp.op.exp2);
5509 ComputeExpression(exp.op.exp1);
5512 op1 = GetOperand(exp1);
5513 if(op1.type) op1.type.refCount++;
5516 op2 = GetOperand(exp2);
5517 if(op2.type) op2.type.refCount++;
5523 op1 = GetOperand(exp1);
5524 if(op1.type) op1.type.refCount++;
5527 CallOperator(exp, exp1, exp2, op1, op2);
5534 if(exp.op.exp1 && exp.op.exp2)
5539 FreeExpContents(exp);
5540 op1.ops.BitAnd(exp, op1, op2);
5549 FreeExpContents(exp);
5550 op1.ops.Mul(exp, op1, op2);
5559 FreeExpContents(exp);
5560 op1.ops.Add(exp, op1, op2);
5565 // Provide default unary +
5566 Expression exp2 = exp.op.exp2;
5568 FreeExpContents(exp);
5569 FreeType(exp.expType);
5570 FreeType(exp.destType);
5581 FreeExpContents(exp);
5582 op1.ops.Sub(exp, op1, op2);
5589 FreeExpContents(exp);
5590 op1.ops.Neg(exp, op1);
5597 FreeExpContents(exp);
5598 op1.ops.BitNot(exp, op1);
5604 FreeExpContents(exp);
5605 op1.ops.Not(exp, op1);
5608 // Binary only operators
5612 FreeExpContents(exp);
5613 op1.ops.Div(exp, op1, op2);
5619 FreeExpContents(exp);
5620 op1.ops.Mod(exp, op1, op2);
5632 FreeExpContents(exp);
5633 op1.ops.Sma(exp, op1, op2);
5642 FreeExpContents(exp);
5643 op1.ops.Grt(exp, op1, op2);
5652 FreeExpContents(exp);
5653 op1.ops.SmaEqu(exp, op1, op2);
5662 FreeExpContents(exp);
5663 op1.ops.GrtEqu(exp, op1, op2);
5672 FreeExpContents(exp);
5673 op1.ops.Equ(exp, op1, op2);
5682 FreeExpContents(exp);
5683 op1.ops.Nqu(exp, op1, op2);
5690 FreeExpContents(exp);
5691 op1.ops.BitOr(exp, op1, op2);
5697 FreeExpContents(exp);
5698 op1.ops.BitXor(exp, op1, op2);
5706 FreeExpContents(exp);
5707 exp.type = constantExp;
5708 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5712 if(op1.type) FreeType(op1.type);
5713 if(op2.type) FreeType(op2.type);
5717 case extensionExpressionExp:
5720 for(e = exp.list->first; e; e = n)
5725 OldList * list = exp.list;
5726 Expression prev = exp.prev;
5727 Expression next = exp.next;
5728 ComputeExpression(e);
5729 //FreeExpContents(exp);
5730 FreeType(exp.expType);
5731 FreeType(exp.destType);
5750 exp.isConstant = true;
5752 ComputeExpression(exp.index.exp);
5753 if(!exp.index.exp.isConstant)
5754 exp.isConstant = false;
5756 for(e = exp.index.index->first; e; e = e.next)
5758 ComputeExpression(e);
5761 // Check if this type is int
5764 exp.isConstant = false;
5766 exp.expType = Dereference(exp.index.exp.expType);
5772 Expression memberExp = exp.member.exp;
5773 Identifier memberID = exp.member.member;
5776 ComputeExpression(exp.member.exp);
5777 type = exp.member.exp.expType;
5780 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);
5781 Property prop = null;
5782 DataMember member = null;
5783 Class convertTo = null;
5784 if(type.kind == subClassType && exp.member.exp.type == classExp)
5785 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5792 PrintTypeNoConst(type, string, false, true);
5793 classSym = FindClass(string);
5794 _class = classSym ? classSym.registered : null;
5797 if(exp.member.member)
5799 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5801 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5803 if(!prop && !member && _class && exp.member.member)
5805 Symbol classSym = FindClass(exp.member.member.string);
5807 _class = classSym ? classSym.registered : null;
5808 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5815 Type type = prop.dataType;
5816 // TODO: Assuming same base type for units...
5817 if(_class.type == unitClass)
5819 if(type.kind == classType)
5821 Class _class = type._class.registered;
5822 if(_class.type == unitClass)
5824 if(!_class.dataType)
5825 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5826 type = _class.dataType;
5834 float (*Get)(float) = (void *)prop.Get;
5835 GetFloat(exp.member.exp, &value);
5836 exp.constant = PrintFloat(Get ? Get(value) : value);
5837 exp.type = constantExp;
5843 double (*Get)(double);
5844 GetDouble(exp.member.exp, &value);
5847 Get = (void *)prop.Set;
5849 Get = (void *)prop.Get;
5850 exp.constant = PrintDouble(Get ? Get(value) : value);
5851 exp.type = constantExp;
5860 Expression value = exp.member.exp;
5863 ProcessPropertyType(prop);
5865 type = prop.dataType;
5868 // printf("Investigate this\n");
5870 else if(_class.type == structClass)
5876 Class propertyClass = type._class.registered;
5877 if(propertyClass.type == structClass && value.type == instanceExp)
5879 void (*Set)(void *, void *) = (void *)prop.Set;
5880 exp.instance = Instantiation { };
5881 exp.instance.data = new0 byte[_class.structSize];
5882 exp.instance._class = MkSpecifierName(_class.fullName);
5883 exp.instance.loc = exp.loc;
5884 exp.type = instanceExp;
5885 Set(exp.instance.data, value.instance.data);
5886 PopulateInstance(exp.instance);
5893 void (*Set)(void *, int) = (void *)prop.Set;
5895 exp.instance = Instantiation { };
5896 exp.instance.data = new0 byte[_class.structSize];
5897 exp.instance._class = MkSpecifierName(_class.fullName);
5898 exp.instance.loc = exp.loc;
5899 exp.type = instanceExp;
5901 GetInt(value, &intValue);
5903 Set(exp.instance.data, intValue);
5904 PopulateInstance(exp.instance);
5910 void (*Set)(void *, int64) = (void *)prop.Set;
5912 exp.instance = Instantiation { };
5913 exp.instance.data = new0 byte[_class.structSize];
5914 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5915 exp.instance.loc = exp.loc;
5916 exp.type = instanceExp;
5918 GetInt64(value, &intValue);
5920 Set(exp.instance.data, intValue);
5921 PopulateInstance(exp.instance);
5928 void (*Set)(void *, intptr) = (void *)prop.Set;
5930 exp.instance = Instantiation { };
5931 exp.instance.data = new0 byte[_class.structSize];
5932 exp.instance._class = MkSpecifierName(_class.fullName);
5933 exp.instance.loc = exp.loc;
5934 exp.type = instanceExp;
5936 GetIntPtr(value, &intValue);
5938 Set(exp.instance.data, intValue);
5939 PopulateInstance(exp.instance);
5946 void (*Set)(void *, intsize) = (void *)prop.Set;
5948 exp.instance = Instantiation { };
5949 exp.instance.data = new0 byte[_class.structSize];
5950 exp.instance._class = MkSpecifierName(_class.fullName);
5951 exp.instance.loc = exp.loc;
5952 exp.type = instanceExp;
5954 GetIntSize(value, &intValue);
5956 Set(exp.instance.data, intValue);
5957 PopulateInstance(exp.instance);
5963 void (*Set)(void *, float) = (void *)prop.Set;
5965 exp.instance = Instantiation { };
5966 exp.instance.data = new0 byte[_class.structSize];
5967 exp.instance._class = MkSpecifierName(_class.fullName);
5968 exp.instance.loc = exp.loc;
5969 exp.type = instanceExp;
5971 GetFloat(value, &floatValue);
5973 Set(exp.instance.data, floatValue);
5974 PopulateInstance(exp.instance);
5980 void (*Set)(void *, double) = (void *)prop.Set;
5982 exp.instance = Instantiation { };
5983 exp.instance.data = new0 byte[_class.structSize];
5984 exp.instance._class = MkSpecifierName(_class.fullName);
5985 exp.instance.loc = exp.loc;
5986 exp.type = instanceExp;
5988 GetDouble(value, &doubleValue);
5990 Set(exp.instance.data, doubleValue);
5991 PopulateInstance(exp.instance);
5996 else if(_class.type == bitClass)
6002 Class propertyClass = type._class.registered;
6003 if(propertyClass.type == structClass && value.instance.data)
6005 unsigned int (*Set)(void *) = (void *)prop.Set;
6006 unsigned int bits = Set(value.instance.data);
6007 exp.constant = PrintHexUInt(bits);
6008 exp.type = constantExp;
6011 else if(_class.type == bitClass)
6014 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6017 GetUInt(exp.member.exp, &value);
6019 exp.constant = PrintHexUInt(bits);
6020 exp.type = constantExp;
6028 if(_class.type == bitClass)
6031 GetUInt(exp.member.exp, &value);
6037 Class _class = type._class.registered;
6038 if(_class.type == structClass)
6040 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6042 exp.instance = Instantiation { };
6043 exp.instance.data = new0 byte[_class.structSize];
6044 exp.instance._class = MkSpecifierName(_class.fullName);
6045 exp.instance.loc = exp.loc;
6046 //exp.instance.fullSet = true;
6047 exp.type = instanceExp;
6048 Get(value, exp.instance.data);
6049 PopulateInstance(exp.instance);
6051 else if(_class.type == bitClass)
6053 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6054 uint64 bits = Get(value);
6055 exp.constant = PrintHexUInt64(bits);
6056 exp.type = constantExp;
6062 else if(_class.type == structClass)
6064 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6069 Class _class = type._class.registered;
6070 if(_class.type == structClass && value)
6072 void (*Get)(void *, void *) = (void *)prop.Get;
6074 exp.instance = Instantiation { };
6075 exp.instance.data = new0 byte[_class.structSize];
6076 exp.instance._class = MkSpecifierName(_class.fullName);
6077 exp.instance.loc = exp.loc;
6078 //exp.instance.fullSet = true;
6079 exp.type = instanceExp;
6080 Get(value, exp.instance.data);
6081 PopulateInstance(exp.instance);
6089 char * value = exp.member.exp.instance.data;
6094 Class _class = type._class.registered;
6095 if(_class.type == normalClass)
6097 void *(*Get)(void *) = (void *)prop.Get;
6099 exp.instance = Instantiation { };
6100 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6101 exp.type = instanceExp;
6102 exp.instance.data = Get(value, exp.instance.data);
6114 exp.isConstant = false;
6122 if(exp.type != ExpressionType::memberExp)
6124 FreeExpression(memberExp);
6125 FreeIdentifier(memberID);
6131 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6132 FreeExpContents(exp);
6133 exp.constant = PrintUInt(ComputeTypeSize(type));
6134 exp.type = constantExp;
6140 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6141 if(classSym && classSym.registered)
6143 if(classSym.registered.fixed)
6145 FreeSpecifier(exp._class);
6146 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6147 exp.type = constantExp;
6151 char className[1024];
6152 strcpy(className, "__ecereClass_");
6153 FullClassNameCat(className, classSym.string, true);
6155 DeclareClass(curExternal, classSym, className);
6157 FreeExpContents(exp);
6158 exp.type = pointerExp;
6159 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6160 exp.member.member = MkIdentifier("structSize");
6170 if(exp.type == castExp)
6173 ComputeExpression(exp.cast.exp);
6176 if(e && exp.expType)
6179 type = exp.destType;
6182 if(type.kind == classType)
6184 Class _class = type._class.registered;
6185 if(_class && (_class.type == unitClass || _class.type == bitClass))
6187 if(!_class.dataType)
6188 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6189 type = _class.dataType;
6200 if(GetChar(e, &value))
6202 FreeExpContents(exp);
6203 exp.constant = PrintChar(value);
6204 exp.type = constantExp;
6209 unsigned char value = 0;
6210 if(GetUChar(e, &value))
6212 FreeExpContents(exp);
6213 exp.constant = PrintUChar(value);
6214 exp.type = constantExp;
6222 if(GetShort(e, &value))
6224 FreeExpContents(exp);
6225 exp.constant = PrintShort(value);
6226 exp.type = constantExp;
6231 unsigned short value = 0;
6232 if(GetUShort(e, &value))
6234 FreeExpContents(exp);
6235 exp.constant = PrintUShort(value);
6236 exp.type = constantExp;
6244 if(GetInt(e, &value))
6246 FreeExpContents(exp);
6247 exp.constant = PrintInt(value);
6248 exp.type = constantExp;
6253 unsigned int value = 0;
6254 if(GetUInt(e, &value))
6256 FreeExpContents(exp);
6257 exp.constant = PrintUInt(value);
6258 exp.type = constantExp;
6266 if(GetInt64(e, &value))
6268 FreeExpContents(exp);
6269 exp.constant = PrintInt64(value);
6270 exp.type = constantExp;
6276 if(GetUInt64(e, &value))
6278 FreeExpContents(exp);
6279 exp.constant = PrintUInt64(value);
6280 exp.type = constantExp;
6288 if(GetIntPtr(e, &value))
6290 FreeExpContents(exp);
6291 exp.constant = PrintInt64((int64)value);
6292 exp.type = constantExp;
6298 if(GetUIntPtr(e, &value))
6300 FreeExpContents(exp);
6301 exp.constant = PrintUInt64((uint64)value);
6302 exp.type = constantExp;
6310 if(GetIntSize(e, &value))
6312 FreeExpContents(exp);
6313 exp.constant = PrintInt64((int64)value);
6314 exp.type = constantExp;
6320 if(GetUIntSize(e, &value))
6322 FreeExpContents(exp);
6323 exp.constant = PrintUInt64((uint64)value);
6324 exp.type = constantExp;
6331 if(GetFloat(e, &value))
6333 FreeExpContents(exp);
6334 exp.constant = PrintFloat(value);
6335 exp.type = constantExp;
6342 if(GetDouble(e, &value))
6344 FreeExpContents(exp);
6345 exp.constant = PrintDouble(value);
6346 exp.type = constantExp;
6361 // Caring only about last expression for now...
6362 ComputeExpression(exp.cond.exp->last);
6363 if(exp.cond.elseExp)
6364 ComputeExpression(exp.cond.elseExp);
6366 ComputeExpression(exp.cond.cond);
6368 op1 = GetOperand(exp.cond.cond);
6369 if(op1.type) op1.type.refCount++;
6370 op2 = GetOperand(exp.cond.exp->last);
6371 if(op2.type) op2.type.refCount++;
6372 op3 = GetOperand(exp.cond.elseExp);
6373 if(op3.type) op3.type.refCount++;
6375 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6376 if(op1.type) FreeType(op1.type);
6377 if(op2.type) FreeType(op2.type);
6378 if(op3.type) FreeType(op3.type);
6384 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6389 OldList converts { };
6392 if(destType.kind == voidType)
6395 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6399 // for(convert = converts.last; convert; convert = convert.prev)
6400 for(convert = converts.first; convert; convert = convert.next)
6402 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6405 Expression newExp { };
6406 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6408 // TODO: Check this...
6412 newExp.destType = null;
6417 exp.type = memberExp;
6418 exp.addedThis = true;
6419 exp.member.exp = newExp;
6420 FreeType(exp.member.exp.expType);
6422 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6423 exp.member.exp.expType.classObjectType = objectType;
6424 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6425 exp.member.memberType = propertyMember;
6426 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6427 // TESTING THIS... for (int)degrees
6428 exp.needCast = true;
6429 if(exp.expType) exp.expType.refCount++;
6430 ApplyAnyObjectLogic(exp.member.exp);
6435 /*if(exp.isConstant)
6437 // Color { ColorRGB = [exp] };
6438 exp.type = instanceExp;
6439 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6440 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6441 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6445 // If not constant, don't turn it yet into an instantiation
6446 // (Go through the deep members system first)
6447 exp.type = memberExp;
6448 exp.addedThis = true;
6449 exp.member.exp = newExp;
6451 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6452 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6453 newExp.expType._class.registered.type == noHeadClass)
6455 newExp.byReference = true;
6458 FreeType(exp.member.exp.expType);
6459 /*exp.member.exp.expType = convert.convert.dataType;
6460 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6461 exp.member.exp.expType = null;
6462 if(convert.convert.dataType)
6464 exp.member.exp.expType = { };
6465 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6466 exp.member.exp.expType.refCount = 1;
6467 exp.member.exp.expType.classObjectType = objectType;
6468 ApplyAnyObjectLogic(exp.member.exp);
6471 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6472 exp.member.memberType = reverseConversionMember;
6473 exp.expType = convert.resultType ? convert.resultType :
6474 MkClassType(convert.convert._class.fullName);
6475 exp.needCast = true;
6476 if(convert.resultType) convert.resultType.refCount++;
6482 FreeType(exp.expType);
6485 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6486 if(exp.destType.casted)
6487 exp.needCast = true;
6488 if(exp.expType) exp.expType.refCount++;
6492 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6493 if(exp.destType.casted)
6494 exp.needCast = true;
6495 if(convert.resultType)
6496 convert.resultType.refCount++;
6500 if(exp.isConstant && inCompiler)
6501 ComputeExpression(exp);
6503 converts.Free(FreeConvert);
6506 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6508 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6510 if(!result && exp.expType && exp.destType)
6512 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6513 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6514 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6515 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6519 // if(result) CheckTemplateTypes(exp);
6523 void CheckTemplateTypes(Expression exp)
6526 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6527 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6529 Expression nbExp = GetNonBracketsExp(exp);
6530 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6531 (nbExp == exp || nbExp.type != castExp))
6533 Expression newExp { };
6535 TypeKind kind = exp.expType.kind;
6537 if(exp.destType) exp.destType.refCount++;
6538 if(exp.expType) exp.expType.refCount++;
6542 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6544 Class c = exp.expType._class.registered;
6545 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6548 c.dataType = ProcessTypeString(c.dataTypeString, false);
6549 kind = c.dataType.kind;
6556 if(exp.destType.classObjectType)
6558 // We need to pass the address, just pass it along (Undo what was done above)
6559 if(exp.destType) exp.destType.refCount--;
6560 if(exp.expType) exp.expType.refCount--;
6565 // If we're looking for value:
6566 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6568 OldList * unionDefs = MkList();
6569 OldList * statements = MkList();
6570 context = PushContext();
6571 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6572 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6573 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6574 exp.type = extensionCompoundExp;
6575 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6576 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6577 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6578 exp.compound.compound.context = context;
6579 PopContext(context);
6584 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6585 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6586 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6588 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6589 exp.needCast = true;
6593 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6595 Expression newExp { };
6597 TypeKind kind = exp.expType.kind;
6599 if(exp.destType) exp.destType.refCount++;
6600 if(exp.expType) exp.expType.refCount++;
6604 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6606 Class c = exp.expType._class.registered;
6607 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6610 c.dataType = ProcessTypeString(c.dataTypeString, false);
6611 kind = c.dataType.kind;
6618 if(exp.destType.classObjectType)
6620 // We need to pass the address, just pass it along (Undo what was done above)
6621 if(exp.destType) exp.destType.refCount--;
6622 if(exp.expType) exp.expType.refCount--;
6627 // If we're looking for value:
6628 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6630 OldList * unionDefs = MkList();
6631 OldList * statements = MkList();
6632 context = PushContext();
6633 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6634 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6635 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6636 exp.type = extensionCompoundExp;
6637 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6638 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6639 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6640 exp.compound.compound.context = context;
6641 PopContext(context);
6646 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6648 exp.type = bracketsExp;
6650 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6651 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6652 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6653 ProcessExpressionType(exp.list->first);
6658 exp.type = bracketsExp;
6659 if(exp.expType.isPointerType)
6661 exp.needTemplateCast = 2;
6662 newExp.needCast = true;
6663 newExp.needTemplateCast = 2;
6664 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6667 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6668 exp.needTemplateCast = 2;
6669 newExp.needCast = true;
6670 newExp.needTemplateCast = 2;
6671 ProcessExpressionType(exp.list->first);
6677 if(exp.expType.kind == templateType)
6679 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6682 FreeType(exp.destType);
6683 FreeType(exp.expType);
6688 /*if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6690 // When was this required? Removed to address using templated values to pass to printf()
6694 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6695 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6699 char typeString[1024];
6701 OldList * specs = MkList();
6702 typeString[0] = '\0';
6703 PrintType(exp.expType, typeString, false, false);
6704 decl = SpecDeclFromString(typeString, specs, null);
6707 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6708 exp.cast.typeName = MkTypeName(specs, decl);
6709 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6710 exp.cast.exp.needCast = true;
6711 exp.needTemplateCast = 2;
6712 newExp.needTemplateCast = 2;
6719 // TODO: The Symbol tree should be reorganized by namespaces
6721 // - Tree of all symbols within (stored without namespace)
6722 // - Tree of sub-namespaces
6724 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6726 int nsLen = strlen(nameSpace);
6728 // Start at the name space prefix
6729 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6731 char * s = symbol.string;
6732 if(!strncmp(s, nameSpace, nsLen))
6734 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6737 for(c = strlen(s)-1; c >= 0; c--)
6742 if(!strcmp(namePart, name))
6744 // TODO: Error on ambiguity
6754 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6757 char nameSpace[1024];
6758 const char * namePart;
6759 bool gotColon = false;
6761 nameSpace[0] = '\0';
6762 for(c = strlen(name)-1; c >= 0; c--)
6769 namePart = name+c+1;
6770 while(c >= 0 && name[c] == ':') c--;
6773 // Try an exact match first
6774 Symbol symbol = (Symbol)tree.FindString(name);
6778 // Namespace specified
6779 memcpy(nameSpace, name, c + 1);
6782 return ScanWithNameSpace(tree, nameSpace, namePart);
6786 // Looking for a global symbol, e.g. ::Sleep()
6787 Symbol symbol = (Symbol)tree.FindString(namePart);
6792 // Name only (no namespace specified)
6793 Symbol symbol = (Symbol)tree.FindString(namePart);
6796 return ScanWithNameSpace(tree, "", namePart);
6801 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6804 //Time startTime = GetTime();
6806 // Optimize this later? Do this before/less?
6808 Symbol symbol = null;
6810 // First, check if the identifier is declared inside the function
6811 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6813 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6815 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6821 strcpy(curName, thisNameSpace);
6822 strcat(curName, "::");
6823 strcat(curName, name);
6824 // Try to resolve in current namespace first
6825 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6828 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6831 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6833 if(symbol || ctx == endContext) break;
6835 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6836 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6838 //findSymbolTotalTime += GetTime() - startTime;
6843 static void GetTypeSpecs(Type type, OldList * specs)
6845 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6850 if(type._class.registered)
6852 if(!type._class.registered.dataType)
6853 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6854 GetTypeSpecs(type._class.registered.dataType, specs);
6858 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6859 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6860 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6861 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6862 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6863 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6864 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6865 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6868 ListAdd(specs, MkSpecifier(INT)); break;
6872 static void PrintArraySize(Type arrayType, char * string)
6877 if(arrayType.enumClass)
6878 strcat(size, arrayType.enumClass.string);
6879 else if(arrayType.arraySizeExp)
6880 PrintExpression(arrayType.arraySizeExp, size);
6882 strcat(string, size);
6885 // WARNING : This function expects a null terminated string since it recursively concatenate...
6886 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6890 if(printConst && type.constant)
6891 strcat(string, "const ");
6896 Symbol c = type._class;
6897 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
6898 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6899 // look into merging with thisclass ?
6900 if(type.classObjectType == typedObject && isObjectBaseClass)
6901 strcat(string, "typed_object");
6902 else if(type.classObjectType == anyObject && isObjectBaseClass)
6903 strcat(string, "any_object");
6907 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6909 if(type.byReference)
6910 strcat(string, " &");
6913 case voidType: strcat(string, "void"); break;
6914 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6915 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6916 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6917 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6918 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6919 case _BoolType: strcat(string, "_Bool"); break;
6920 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6921 case floatType: strcat(string, "float"); break;
6922 case doubleType: strcat(string, "double"); break;
6926 strcat(string, "struct ");
6927 strcat(string, type.enumName);
6929 else if(type.typeName)
6930 strcat(string, type.typeName);
6934 strcat(string, "struct { ");
6935 for(member = type.members.first; member; member = member.next)
6937 PrintType(member, string, true, fullName);
6938 strcat(string,"; ");
6946 strcat(string, "union ");
6947 strcat(string, type.enumName);
6949 else if(type.typeName)
6950 strcat(string, type.typeName);
6953 strcat(string, "union ");
6954 strcat(string,"(unnamed)");
6960 strcat(string, "enum ");
6961 strcat(string, type.enumName);
6963 else if(type.typeName)
6964 strcat(string, type.typeName);
6966 strcat(string, "int"); // "enum");
6969 strcat(string, "...");
6972 strcat(string, "subclass(");
6973 strcat(string, type._class ? type._class.string : "int");
6974 strcat(string, ")");
6977 strcat(string, type.templateParameter.identifier.string);
6980 strcat(string, "thisclass");
6983 strcat(string, "__builtin_va_list");
6989 static void PrintName(Type type, char * string, bool fullName)
6991 if(type.name && type.name[0])
6994 strcat(string, type.name);
6997 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6998 if(name) name += 2; else name = type.name;
6999 strcat(string, name);
7004 static void PrintAttribs(Type type, char * string)
7008 if(type.dllExport) strcat(string, "dllexport ");
7009 if(type.attrStdcall) strcat(string, "stdcall ");
7013 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7015 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7017 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7018 PrintAttribs(type, string);
7019 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7020 strcat(string, " const");
7021 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7022 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7023 strcat(string, " (");
7024 if(type.kind == pointerType)
7026 if(type.type.kind == functionType || type.type.kind == methodType)
7027 PrintAttribs(type.type, string);
7029 if(type.kind == pointerType)
7031 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7032 strcat(string, "*");
7034 strcat(string, " *");
7036 if(printConst && type.constant && type.kind == pointerType)
7037 strcat(string, " const");
7040 PrintTypeSpecs(type, string, fullName, printConst);
7043 static void PostPrintType(Type type, char * string, bool fullName)
7045 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7046 strcat(string, ")");
7047 if(type.kind == arrayType)
7048 PrintArraySize(type, string);
7049 else if(type.kind == functionType)
7052 strcat(string, "(");
7053 for(param = type.params.first; param; param = param.next)
7055 PrintType(param, string, true, fullName);
7056 if(param.next) strcat(string, ", ");
7058 strcat(string, ")");
7060 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7061 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7065 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7067 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7069 PrePrintType(type, string, fullName, null, printConst);
7071 if(type.thisClass || (printName && type.name && type.name[0]))
7072 strcat(string, " ");
7073 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7075 Symbol _class = type.thisClass;
7076 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7078 if(type.classObjectType == classPointer)
7079 strcat(string, "class");
7081 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7083 else if(_class && _class.string)
7085 String s = _class.string;
7090 char * name = RSearchString(s, "::", strlen(s), true, false);
7091 if(name) name += 2; else name = s;
7092 strcat(string, name);
7095 strcat(string, "::");
7098 if(printName && type.name)
7099 PrintName(type, string, fullName);
7100 PostPrintType(type, string, fullName);
7101 if(type.bitFieldCount)
7104 sprintf(count, ":%d", type.bitFieldCount);
7105 strcat(string, count);
7109 void PrintType(Type type, char * string, bool printName, bool fullName)
7111 _PrintType(type, string, printName, fullName, true);
7114 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7116 _PrintType(type, string, printName, fullName, false);
7119 static Type FindMember(Type type, char * string)
7122 for(memberType = type.members.first; memberType; memberType = memberType.next)
7124 if(!memberType.name)
7126 Type subType = FindMember(memberType, string);
7130 else if(!strcmp(memberType.name, string))
7136 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7139 for(memberType = type.members.first; memberType; memberType = memberType.next)
7141 if(!memberType.name)
7143 Type subType = FindMember(memberType, string);
7146 *offset += memberType.offset;
7150 else if(!strcmp(memberType.name, string))
7152 *offset += memberType.offset;
7159 public bool GetParseError() { return parseError; }
7161 Expression ParseExpressionString(char * expression)
7165 fileInput = TempFile { };
7166 fileInput.Write(expression, 1, strlen(expression));
7167 fileInput.Seek(0, start);
7170 parsedExpression = null;
7172 expression_yyparse();
7175 return parsedExpression;
7178 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7180 Identifier id = exp.identifier;
7181 Method method = null;
7182 Property prop = null;
7183 DataMember member = null;
7184 ClassProperty classProp = null;
7186 if(_class && _class.type == enumClass)
7188 NamedLink64 value = null;
7189 Class enumClass = eSystem_FindClass(privateModule, "enum");
7193 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7195 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7196 for(value = e.values.first; value; value = value.next)
7198 if(!strcmp(value.name, id.string))
7203 exp.isConstant = true;
7204 if(inCompiler || inPreCompiler || inDebugger)
7207 FreeExpContents(exp);
7209 exp.type = constantExp;
7210 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7211 sprintf(constant, FORMAT64D, value.data);
7213 sprintf(constant, FORMAT64HEX, value.data);
7214 exp.constant = CopyString(constant);
7216 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7217 exp.expType = MkClassType(baseClass.fullName);
7225 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7227 ProcessMethodType(method);
7234 // TOCHECK: Put it back to what it was...
7235 // methodClass = _class;
7236 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7241 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7244 ProcessPropertyType(prop);
7245 exp.expType = prop.dataType;
7246 if(prop.dataType) prop.dataType.refCount++;
7249 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7251 if(!member.dataType)
7252 member.dataType = ProcessTypeString(member.dataTypeString, false);
7253 exp.expType = member.dataType;
7254 if(member.dataType) member.dataType.refCount++;
7257 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7259 if(!classProp.dataType)
7260 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7262 if(classProp.constant)
7264 FreeExpContents(exp);
7266 exp.isConstant = true;
7267 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7269 //char constant[256];
7270 exp.type = stringExp;
7271 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7276 exp.type = constantExp;
7277 sprintf(constant, "%d", (int)classProp.Get(_class));
7278 exp.constant = CopyString(constant);
7286 exp.expType = classProp.dataType;
7287 if(classProp.dataType) classProp.dataType.refCount++;
7293 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7295 BinaryTree * tree = &nameSpace.functions;
7296 GlobalData data = (GlobalData)tree->FindString(name);
7300 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7302 data = ScanGlobalData(child, name);
7310 static GlobalData FindGlobalData(char * name)
7313 NameSpace * nameSpace;
7314 nameSpace = globalData;
7315 for(c = 0; name[c]; c++)
7317 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7319 NameSpace * newSpace;
7320 char * spaceName = new char[c - start + 1];
7321 strncpy(spaceName, name + start, c - start);
7322 spaceName[c-start] = '\0';
7323 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7327 nameSpace = newSpace;
7328 if(name[c] == ':') c++;
7334 return ScanGlobalData(nameSpace, name + start);
7339 static int definedExpStackPos;
7340 static void * definedExpStack[512];
7342 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7343 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7345 Expression prev = checkedExp.prev, next = checkedExp.next;
7347 FreeExpContents(checkedExp);
7348 FreeType(checkedExp.expType);
7349 FreeType(checkedExp.destType);
7351 *checkedExp = *newExp;
7355 checkedExp.prev = prev;
7356 checkedExp.next = next;
7359 void ApplyAnyObjectLogic(Expression e)
7361 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7363 char debugExpString[4096];
7364 debugExpString[0] = '\0';
7365 PrintExpression(e, debugExpString);
7368 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7370 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7371 //ellipsisDestType = destType;
7374 Type type = e.expType;
7375 Class _class = null;
7376 //Type destType = e.destType;
7378 if(type.kind == classType && type._class && type._class.registered)
7380 _class = type._class.registered;
7382 else if(type.kind == subClassType)
7384 _class = FindClass("ecere::com::Class").registered;
7388 char string[1024] = "";
7391 PrintTypeNoConst(type, string, false, true);
7392 classSym = FindClass(string);
7393 if(classSym) _class = classSym.registered;
7396 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...
7397 (!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))) ||
7398 destType.byReference)))
7400 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7402 Expression checkedExp = e, newExp;
7404 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7406 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7408 if(checkedExp.type == extensionCompoundExp)
7410 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7413 checkedExp = checkedExp.list->last;
7415 else if(checkedExp.type == castExp)
7416 checkedExp = checkedExp.cast.exp;
7419 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7421 newExp = checkedExp.op.exp2;
7422 checkedExp.op.exp2 = null;
7423 FreeExpContents(checkedExp);
7425 if(e.expType && e.expType.passAsTemplate)
7428 ComputeTypeSize(e.expType);
7429 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7430 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7431 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7432 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7435 ReplaceExpContents(checkedExp, newExp);
7436 e.byReference = true;
7438 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7440 Expression checkedExp; //, newExp;
7443 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7445 e.type == identifierExp ||
7446 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7447 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7448 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7451 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7453 Context context = PushContext();
7455 OldList * specs = MkList();
7456 char typeString[1024];
7457 Expression newExp { };
7459 typeString[0] = '\0';
7462 //if(e.destType) e.destType.refCount++;
7463 // if(exp.expType) exp.expType.refCount++;
7466 newExp.expType = null;
7468 PrintTypeNoConst(e.expType, typeString, false, true);
7469 decl = SpecDeclFromString(typeString, specs, null);
7470 newExp.destType = ProcessType(specs, decl);
7472 curContext = context;
7474 // We need a current compound for this
7478 OldList * stmts = MkList();
7479 e.type = extensionCompoundExp;
7480 sprintf(name, "__internalValue%03X", internalValueCounter++);
7481 if(!curCompound.compound.declarations)
7482 curCompound.compound.declarations = MkList();
7483 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7484 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7485 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7486 e.compound = MkCompoundStmt(null, stmts);
7489 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7492 e.compound = MkCompoundStmt(
7493 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7494 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7496 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7500 Type type = e.destType;
7502 CopyTypeInto(e.destType, type);
7503 e.destType.refCount = 1;
7504 e.destType.classObjectType = none;
7508 e.compound.compound.context = context;
7509 PopContext(context);
7510 curContext = context.parent;
7514 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7516 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7518 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7520 if(checkedExp.type == extensionCompoundExp)
7522 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7525 checkedExp = checkedExp.list->last;
7527 else if(checkedExp.type == castExp)
7528 checkedExp = checkedExp.cast.exp;
7531 Expression operand { };
7532 operand = *checkedExp;
7534 checkedExp.destType = ProcessTypeString("void *", false);
7535 checkedExp.expType = checkedExp.destType;
7536 checkedExp.destType.refCount++;
7538 checkedExp.type = opExp;
7539 checkedExp.op.op = '&';
7540 checkedExp.op.exp1 = null;
7541 checkedExp.op.exp2 = operand;
7543 //newExp = MkExpOp(null, '&', checkedExp);
7545 //ReplaceExpContents(checkedExp, newExp);
7552 // If expression type is a simple class, make it an address
7553 // FixReference(e, true);
7556 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7557 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7558 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7560 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"))
7562 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7566 Expression thisExp { };
7569 thisExp.prev = null;
7570 thisExp.next = null;
7573 e.type = bracketsExp;
7574 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7575 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7576 ((Expression)e.list->first).byReference = true;
7578 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7580 e.expType = thisExp.expType;
7581 e.expType.refCount++;
7586 CopyTypeInto(e.expType, thisExp.expType);
7587 e.expType.byReference = false;
7588 e.expType.refCount = 1;
7590 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7591 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7593 e.expType.classObjectType = none;
7598 // TOFIX: Try this for a nice IDE crash!
7600 // The other way around
7603 if(destType && e.expType &&
7604 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7605 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7606 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7608 if(destType.kind == ellipsisType)
7610 Compiler_Error($"Unspecified type\n");
7612 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7614 bool byReference = e.expType.byReference;
7615 Expression thisExp { };
7617 OldList * specs = MkList();
7618 char typeString[1024]; // Watch buffer overruns
7620 ClassObjectType backupClassObjectType;
7621 bool backupByReference;
7623 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7628 backupClassObjectType = type.classObjectType;
7629 backupByReference = type.byReference;
7631 type.classObjectType = none;
7632 type.byReference = false;
7634 typeString[0] = '\0';
7635 PrintType(type, typeString, false, true);
7636 decl = SpecDeclFromString(typeString, specs, null);
7638 type.classObjectType = backupClassObjectType;
7639 type.byReference = backupByReference;
7642 thisExp.prev = null;
7643 thisExp.next = null;
7646 if( ( type.kind == classType && type._class && type._class.registered &&
7647 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7648 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7649 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7650 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7652 bool passAsTemplate = thisExp.destType.passAsTemplate;
7655 destType.refCount++;
7660 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7663 CopyTypeInto(t, thisExp.destType);
7664 t.passAsTemplate = false;
7665 FreeType(thisExp.destType);
7666 thisExp.destType = t;
7669 CopyTypeInto(t, destType);
7670 t.passAsTemplate = passAsTemplate;
7673 destType.refCount = 0;
7676 CopyTypeInto(e.expType, type);
7677 if(type.passAsTemplate)
7679 e.expType.classObjectType = none;
7680 e.expType.passAsTemplate = false;
7682 e.expType.byReference = false;
7683 e.expType.refCount = 1;
7688 e.cast.typeName = MkTypeName(specs, decl);
7689 e.cast.exp = thisExp;
7690 e.byReference = true;
7696 FreeType(e.destType);
7698 e.destType = destType;
7699 destType.refCount++;
7704 void ApplyLocation(Expression exp, Location loc)
7710 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7711 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7717 for(e = exp.list->first; e; e = e.next)
7718 ApplyLocation(e, loc);
7725 for(e = exp.index.index->first; e; e = e.next)
7726 ApplyLocation(e, loc);
7729 ApplyLocation(exp.index.exp, loc);
7732 if(exp.call.arguments)
7735 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7736 ApplyLocation(arg, loc);
7739 ApplyLocation(exp.call.exp, loc);
7744 ApplyLocation(exp.member.exp, loc);
7748 ApplyLocation(exp.cast.exp, loc);
7754 for(e = exp.cond.exp->first; e; e = e.next)
7755 ApplyLocation(e, loc);
7758 ApplyLocation(exp.cond.cond, loc);
7759 if(exp.cond.elseExp)
7760 ApplyLocation(exp.cond.elseExp, loc);
7764 ApplyLocation(exp.vaArg.exp, loc);
7771 void ProcessExpressionType(Expression exp)
7773 bool unresolved = false;
7774 Location oldyylloc = yylloc;
7775 bool notByReference = false;
7777 char debugExpString[4096];
7778 debugExpString[0] = '\0';
7779 PrintExpression(exp, debugExpString);
7781 if(!exp || exp.expType)
7784 //eSystem_Logf("%s\n", expString);
7786 // Testing this here
7792 Identifier id = exp.identifier;
7793 if(!id || !topContext) return;
7795 // DOING THIS LATER NOW...
7796 if(id._class && id._class.name)
7798 id.classSym = id._class.symbol; // FindClass(id._class.name);
7799 /* TODO: Name Space Fix ups
7801 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7805 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7807 exp.expType = ProcessTypeString("Module", true);
7811 if(!strcmp(id.string, "__runtimePlatform"))
7813 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7816 else if(strstr(id.string, "__ecereClass") == id.string)
7818 exp.expType = ProcessTypeString("ecere::com::Class", true);
7821 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7823 // Added this here as well
7824 ReplaceClassMembers(exp, thisClass);
7825 if(exp.type != identifierExp)
7827 ProcessExpressionType(exp);
7831 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7836 Symbol symbol = null;
7837 bool findInGlobal = false;
7838 if(!topContext.parent && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == enumClass)
7839 findInGlobal = true; // In global context, look at enum values first
7841 symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7843 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7844 if(!symbol/* && exp.destType*/)
7846 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7852 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7853 if(exp.type != identifierExp)
7855 ProcessExpressionType(exp);
7859 // Static methods called from inside the _class
7860 else if(currentClass && !id._class)
7862 if(ResolveIdWithClass(exp, currentClass, true))
7865 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7869 symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7871 // If we manage to resolve this symbol
7874 Type type = symbol.type;
7875 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7877 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7879 Context context = SetupTemplatesContext(_class);
7880 type = ReplaceThisClassType(_class);
7881 FinishTemplatesContext(context);
7882 if(type) type.refCount = 0; // We'll be incrementing it right below...
7885 FreeSpecifier(id._class);
7888 id.string = CopyString(symbol.string);
7895 // Commented this out, it was making non-constant enum parameters seen as constant
7896 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7897 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7898 // Add missing cases here... enum Classes...
7899 exp.isConstant = true;
7901 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7902 if(symbol.isParam || !strcmp(id.string, "this"))
7904 if(_class && _class.type == structClass && !type.declaredWithStruct)
7905 exp.byReference = true;
7907 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7908 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7909 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7910 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7912 Identifier id = exp.identifier;
7913 exp.type = bracketsExp;
7914 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7918 if(symbol.isIterator)
7920 if(symbol.isIterator == 3)
7922 exp.type = bracketsExp;
7923 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7924 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7926 ProcessExpressionType(exp);
7928 else if(symbol.isIterator != 4)
7930 exp.type = memberExp;
7931 exp.member.exp = MkExpIdentifier(exp.identifier);
7932 exp.member.exp.expType = exp.expType;
7933 /*if(symbol.isIterator == 6)
7934 exp.member.member = MkIdentifier("key");
7936 exp.member.member = MkIdentifier("data");
7938 ProcessExpressionType(exp);
7945 DefinedExpression definedExp = null;
7946 if(thisNameSpace && !(id._class && !id._class.name))
7949 strcpy(name, thisNameSpace);
7951 strcat(name, id.string);
7952 definedExp = eSystem_FindDefine(privateModule, name);
7955 definedExp = eSystem_FindDefine(privateModule, id.string);
7959 for(c = 0; c<definedExpStackPos; c++)
7960 if(definedExpStack[c] == definedExp)
7962 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7964 Location backupYylloc = yylloc;
7965 File backInput = fileInput;
7966 definedExpStack[definedExpStackPos++] = definedExp;
7968 fileInput = TempFile { };
7969 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7970 fileInput.Seek(0, start);
7973 parsedExpression = null;
7975 expression_yyparse();
7978 fileInput = backInput;
7980 yylloc = backupYylloc;
7982 if(parsedExpression)
7985 exp.type = bracketsExp;
7986 exp.list = MkListOne(parsedExpression);
7987 ApplyLocation(parsedExpression, yylloc);
7988 ProcessExpressionType(exp);
7989 definedExpStackPos--;
7992 definedExpStackPos--;
7998 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8004 GlobalData data = null;
8005 if(thisNameSpace && !(id._class && !id._class.name))
8008 strcpy(name, thisNameSpace);
8010 strcat(name, id.string);
8011 data = FindGlobalData(name);
8014 data = FindGlobalData(id.string);
8017 DeclareGlobalData(curExternal, data);
8018 exp.expType = data.dataType;
8019 if(data.dataType) data.dataType.refCount++;
8022 id.string = CopyString(data.fullName);
8023 FreeSpecifier(id._class);
8030 GlobalFunction function = null;
8031 if(thisNameSpace && !(id._class && !id._class.name))
8034 strcpy(name, thisNameSpace);
8036 strcat(name, id.string);
8037 function = eSystem_FindFunction(privateModule, name);
8040 function = eSystem_FindFunction(privateModule, id.string);
8045 id.string = CopyString(function.name);
8048 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8049 strcpy(name, "__ecereFunction_");
8050 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8051 if(DeclareFunction(curExternal, function, name))
8054 id.string = CopyString(name);
8056 exp.expType = function.dataType;
8057 if(function.dataType) function.dataType.refCount++;
8059 FreeSpecifier(id._class);
8076 if(!exp.instance._class)
8078 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8080 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8084 //classSym = FindClass(exp.instance._class.fullName);
8085 //_class = classSym ? classSym.registered : null;
8087 ProcessInstantiationType(exp.instance);
8089 exp.isConstant = exp.instance.isConstant;
8092 if(_class.type == unitClass && _class.base.type != systemClass)
8095 Type destType = exp.destType;
8097 exp.destType = MkClassType(_class.base.fullName);
8098 exp.expType = MkClassType(_class.fullName);
8099 CheckExpressionType(exp, exp.destType, true);
8101 exp.destType = destType;
8103 exp.expType = MkClassType(_class.fullName);
8106 if(exp.instance._class)
8108 exp.expType = MkClassType(exp.instance._class.name);
8109 /*if(exp.expType._class && exp.expType._class.registered &&
8110 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8111 exp.expType.byReference = true;*/
8119 char * constant = exp.constant;
8127 if(constant[0] == '\'')
8129 if((int)((byte *)constant)[1] > 127)
8132 unichar ch = UTF8GetChar(constant + 1, &nb);
8133 if(nb < 2) ch = constant[1];
8135 exp.constant = PrintUInt(ch);
8136 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8137 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8138 type._class = FindClass("unichar");
8140 type.isSigned = false;
8144 type.kind = charType;
8145 type.isSigned = true;
8150 char * dot = strchr(constant, '.');
8151 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8155 exponent = strchr(constant, 'p');
8156 if(!exponent) exponent = strchr(constant, 'P');
8160 exponent = strchr(constant, 'e');
8161 if(!exponent) exponent = strchr(constant, 'E');
8166 if(strchr(constant, 'f') || strchr(constant, 'F'))
8167 type.kind = floatType;
8169 type.kind = doubleType;
8170 type.isSigned = true;
8174 bool isSigned = constant[0] == '-';
8176 int64 i64 = strtoll(constant, &endP, 0);
8177 uint64 ui64 = strtoull(constant, &endP, 0);
8178 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8179 bool forceUnsigned = endP && (!strcmp(endP, "U") || !strcmp(endP, "u") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8192 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8196 else if(constant[0] != '0' || !constant[1])
8201 type.kind = is64Bit ? int64Type : intType;
8202 type.isSigned = isSigned;
8205 exp.isConstant = true;
8206 if(exp.destType && exp.destType.kind == doubleType)
8207 type.kind = doubleType;
8208 else if(exp.destType && exp.destType.kind == floatType)
8209 type.kind = floatType;
8210 else if(exp.destType && exp.destType.kind == int64Type)
8211 type.kind = int64Type;
8217 exp.isConstant = true; // Why wasn't this constant?
8225 kind = exp.wideString ? shortType : charType;
8227 isSigned = exp.wideString ? false : true;
8234 ProcessExpressionType(exp._new.size);
8239 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8241 DeclareType(curExternal, exp.expType.type, true, false);
8245 ProcessExpressionType(exp._renew.size);
8246 ProcessExpressionType(exp._renew.exp);
8251 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8253 DeclareType(curExternal, exp.expType.type, true, false);
8257 bool assign = false, boolResult = false, boolOps = false;
8258 Type type1 = null, type2 = null;
8259 bool useDestType = false, useSideType = false;
8260 Location oldyylloc = yylloc;
8261 bool useSideUnit = false;
8262 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8264 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8273 // Assignment Operators
8287 // boolean Operators
8289 // Expect boolean operators
8291 //boolResult = true;
8295 // Expect boolean operands
8306 // Gives boolean result
8319 // useSideType = true;
8320 // useDestType = true;
8338 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8344 /*// Implement speed etc.
8350 if(exp.op.op == '&')
8352 // Added this here earlier for Iterator address as key
8353 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8355 Identifier id = exp.op.exp2.identifier;
8356 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8357 if(symbol && symbol.isIterator == 2)
8359 exp.type = memberExp;
8360 exp.member.exp = exp.op.exp2;
8361 exp.member.member = MkIdentifier("key");
8363 exp.op.exp2.expType = symbol.type;
8364 symbol.type.refCount++;
8365 ProcessExpressionType(exp);
8369 // exp.op.exp2.usage.usageRef = true;
8373 //dummy.kind = TypeDummy;
8376 // Added this check here to use the dest type only for units derived from the base unit
8377 // So that untyped units will use the side unit as opposed to the untyped destination unit
8378 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8379 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8380 useDestType = false;
8382 if(destClass && useDestType &&
8383 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8385 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8387 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8388 exp.op.exp1.destType = exp.destType;
8389 exp.op.exp1.opDestType = true;
8391 exp.destType.refCount++;
8395 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8396 exp.op.exp1.destType = dummy;
8400 // TESTING THIS HERE...
8401 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8402 ProcessExpressionType(exp.op.exp1);
8403 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8405 exp.op.exp1.opDestType = false;
8407 // Fix for unit and ++ / --
8408 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8409 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8411 exp.op.exp2 = MkExpConstant("1");
8412 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8416 if(exp.op.exp1.destType == dummy)
8419 exp.op.exp1.destType = null;
8424 if(!assign && exp.op.exp1.expType && (exp.op.exp1.expType.kind == charType || exp.op.exp1.expType.kind == shortType))
8426 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 };
8427 FreeType(exp.op.exp1.expType);
8428 exp.op.exp1.expType = type;
8432 type1 = exp.op.exp1.expType;
8437 char expString[10240];
8438 expString[0] = '\0';
8439 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8443 exp.op.exp2.destType = exp.op.exp1.expType;
8444 if(exp.op.exp1.expType)
8445 exp.op.exp1.expType.refCount++;
8449 exp.op.exp2.destType = exp.destType;
8450 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8451 exp.op.exp2.opDestType = true;
8453 exp.destType.refCount++;
8456 if(type1) type1.refCount++;
8457 exp.expType = type1;
8462 PrintExpression(exp.op.exp2, expString);
8464 if(type1 && type1.kind == pointerType)
8466 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 ||
8467 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8468 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8469 else if(exp.op.op == '=')
8471 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8472 exp.op.exp2.destType = type1;
8479 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8480 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/* ||
8481 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8484 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8485 exp.op.exp2.destType = type1;
8490 if(type1) type1.refCount++;
8491 exp.expType = type1;
8493 else if(destClass &&
8494 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8495 (destClass.type == enumClass && useDestType)))
8497 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8498 exp.op.exp2.destType = exp.destType;
8499 if(exp.op.op != '&' && exp.op.op != '^')
8500 exp.op.exp2.opDestType = true;
8502 exp.destType.refCount++;
8506 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8507 exp.op.exp2.destType = dummy;
8511 // TESTING THIS HERE... (DANGEROUS)
8512 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8513 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8515 FreeType(exp.op.exp2.destType);
8516 exp.op.exp2.destType = type1;
8519 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8520 // Cannot lose the cast on a sizeof
8521 if(exp.op.op == SIZEOF)
8523 Expression e = exp.op.exp2;
8524 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8526 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8528 if(e.type == extensionCompoundExp)
8529 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8534 if(e.type == castExp && e.cast.exp)
8535 e.cast.exp.needCast = true;
8537 ProcessExpressionType(exp.op.exp2);
8538 exp.op.exp2.opDestType = false;
8539 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8541 if(!assign && (exp.op.exp1 || exp.op.op == '~'))
8543 if(exp.op.exp2.expType && (exp.op.exp2.expType.kind == charType || exp.op.exp2.expType.kind == shortType))
8545 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 };
8546 FreeType(exp.op.exp2.expType);
8547 exp.op.exp2.expType = type;
8551 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8553 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)
8555 if(exp.op.op != '=' && type1.type.kind == voidType)
8556 Compiler_Error($"void *: unknown size\n");
8558 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||
8559 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8560 (exp.op.exp2.expType._class.registered.type == normalClass ||
8561 exp.op.exp2.expType._class.registered.type == structClass ||
8562 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8564 if(exp.op.op == ADD_ASSIGN)
8565 Compiler_Error($"cannot add two pointers\n");
8567 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8568 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8570 if(exp.op.op == ADD_ASSIGN)
8571 Compiler_Error($"cannot add two pointers\n");
8575 char type1String[1024];
8576 char type2String[1024];
8577 type1String[0] = '\0';
8578 type2String[0] = '\0';
8580 PrintType(exp.op.exp2.expType, type1String, false, true);
8581 PrintType(type1, type2String, false, true);
8582 ChangeCh(expString, '\n', ' ');
8583 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8587 if(exp.op.exp2.destType == dummy)
8590 exp.op.exp2.destType = null;
8593 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8597 CopyTypeInto(type2, exp.op.exp2.expType);
8598 type2.isSigned = true;
8600 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8602 type2 = { kind = intType };
8604 type2.isSigned = true;
8608 type2 = exp.op.exp2.expType;
8609 if(type2) type2.refCount++;
8613 dummy.kind = voidType;
8615 if(exp.op.op == SIZEOF)
8622 exp.isConstant = true;
8624 // Get type of dereferenced pointer
8625 else if(exp.op.op == '*' && !exp.op.exp1)
8627 exp.expType = Dereference(type2);
8628 if(type2 && type2.kind == classType)
8629 notByReference = true;
8631 else if(exp.op.op == '&' && !exp.op.exp1)
8632 exp.expType = Reference(type2);
8633 else if(exp.op.op == LEFT_OP || exp.op.op == RIGHT_OP)
8635 if(exp.op.exp1.expType)
8637 exp.expType = exp.op.exp1.expType;
8638 exp.expType.refCount++;
8647 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8648 exp.op.exp1.destType = MkClassType("bool");
8649 exp.op.exp1.destType.truth = true;
8650 if(!exp.op.exp1.expType)
8651 ProcessExpressionType(exp.op.exp1);
8653 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8654 FreeType(exp.op.exp1.expType);
8655 exp.op.exp1.expType = MkClassType("bool");
8656 exp.op.exp1.expType.truth = true;
8660 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8661 exp.op.exp2.destType = MkClassType("bool");
8662 exp.op.exp2.destType.truth = true;
8663 if(!exp.op.exp2.expType)
8664 ProcessExpressionType(exp.op.exp2);
8666 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8667 FreeType(exp.op.exp2.expType);
8668 exp.op.exp2.expType = MkClassType("bool");
8669 exp.op.exp2.expType.truth = true;
8672 else if(exp.op.exp1 && exp.op.exp2 &&
8675 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8676 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8677 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8678 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8680 if(type1 && type2 &&
8681 // If either both are class or both are not class
8682 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8684 // Added this check for enum subtraction to result in an int type:
8685 if(exp.op.op == '-' &&
8686 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8687 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8690 if(!type1._class.registered.dataType)
8691 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8692 if(!type2._class.registered.dataType)
8693 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8695 intType = ProcessTypeString(
8696 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8698 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8699 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8700 exp.op.exp1.destType = intType;
8701 exp.op.exp2.destType = intType;
8706 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8707 exp.op.exp2.destType = type1;
8709 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8710 exp.op.exp1.destType = type2;
8714 // Warning here for adding Radians + Degrees with no destination type
8715 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8716 type1._class.registered && type1._class.registered.type == unitClass &&
8717 type2._class.registered && type2._class.registered.type == unitClass &&
8718 type1._class.registered != type2._class.registered)
8719 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8720 type1._class.string, type2._class.string, type1._class.string);
8722 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8724 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8727 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8729 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8730 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8733 ProcessExpressionType(exp.op.exp1);
8735 if(type2.kind != pointerType)
8737 ProcessExpressionType(classExp);
8739 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8741 if(!exp.op.exp2.expType)
8745 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8749 ProcessExpressionType(exp.op.exp2);
8754 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)))
8756 if(type1.kind != classType && type1.type.kind == voidType)
8757 Compiler_Error($"void *: unknown size\n");
8758 exp.expType = type1;
8759 if(type1) type1.refCount++;
8761 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)))
8763 if(type2.kind != classType && type2.type.kind == voidType)
8764 Compiler_Error($"void *: unknown size\n");
8765 exp.expType = type2;
8766 if(type2) type2.refCount++;
8768 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8769 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8771 Compiler_Warning($"different levels of indirection\n");
8775 bool success = false;
8776 if(type1.kind == pointerType && type2.kind == pointerType)
8778 if(exp.op.op == '+')
8779 Compiler_Error($"cannot add two pointers\n");
8780 else if(exp.op.op == '-')
8782 // Pointer Subtraction gives integer
8783 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8792 if(type1.type.kind == templateType)
8794 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8797 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8799 ProcessExpressionType(classExp);
8801 exp.type = bracketsExp;
8802 exp.list = MkListOne(MkExpOp(
8803 MkExpBrackets(MkListOne(MkExpOp(
8804 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8806 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8807 MkExpMember(classExp, MkIdentifier("typeSize"))));
8809 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8818 if(!success && exp.op.exp1.type == constantExp)
8820 // If first expression is constant, try to match that first
8821 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8823 if(exp.expType) FreeType(exp.expType);
8824 exp.expType = exp.op.exp1.destType;
8825 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8828 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8830 if(exp.expType) FreeType(exp.expType);
8831 exp.expType = exp.op.exp2.destType;
8832 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8838 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8840 if(exp.expType) FreeType(exp.expType);
8841 exp.expType = exp.op.exp2.destType;
8842 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8845 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8847 if(exp.expType) FreeType(exp.expType);
8848 exp.expType = exp.op.exp1.destType;
8849 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8855 char expString1[10240];
8856 char expString2[10240];
8859 expString1[0] = '\0';
8860 expString2[0] = '\0';
8865 PrintExpression(exp.op.exp1, expString1);
8866 ChangeCh(expString1, '\n', ' ');
8867 PrintExpression(exp.op.exp2, expString2);
8868 ChangeCh(expString2, '\n', ' ');
8869 PrintType(exp.op.exp1.expType, type1, false, true);
8870 PrintType(exp.op.exp2.expType, type2, false, true);
8873 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8877 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8878 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8880 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8881 // Convert e.g. / 4 into / 4.0
8882 exp.op.exp1.destType = type2._class.registered.dataType;
8883 if(type2._class.registered.dataType)
8884 type2._class.registered.dataType.refCount++;
8885 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8886 exp.expType = type2;
8887 if(type2) type2.refCount++;
8889 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8891 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8892 // Convert e.g. / 4 into / 4.0
8893 exp.op.exp2.destType = type1._class.registered.dataType;
8894 if(type1._class.registered.dataType)
8895 type1._class.registered.dataType.refCount++;
8896 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8897 exp.expType = type1;
8898 if(type1) type1.refCount++;
8904 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8906 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8908 if(!type1._class.registered.dataType)
8909 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8910 exp.op.exp2.destType = type1._class.registered.dataType;
8911 exp.op.exp2.destType.refCount++;
8913 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8916 type2 = exp.op.exp2.destType;
8917 if(type2) type2.refCount++;
8919 exp.expType = type2;
8923 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8925 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8927 if(!type2._class.registered.dataType)
8928 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8929 exp.op.exp1.destType = type2._class.registered.dataType;
8930 exp.op.exp1.destType.refCount++;
8932 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8933 type1 = exp.op.exp1.destType;
8934 exp.expType = type1;
8938 // TESTING THIS NEW CODE
8939 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8941 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8942 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8943 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8945 // Convert the enum to an int instead for these operators
8946 if(op1IsEnum && exp.op.exp2.expType)
8948 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8950 if(exp.expType) FreeType(exp.expType);
8951 exp.expType = exp.op.exp2.expType;
8952 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8956 else if(op2IsEnum && exp.op.exp1.expType)
8958 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8960 if(exp.expType) FreeType(exp.expType);
8961 exp.expType = exp.op.exp1.expType;
8962 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8969 if(op1IsEnum && exp.op.exp2.expType)
8971 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8973 if(exp.expType) FreeType(exp.expType);
8974 exp.expType = exp.op.exp1.expType;
8975 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8979 else if(op2IsEnum && exp.op.exp1.expType)
8981 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8983 if(exp.expType) FreeType(exp.expType);
8984 exp.expType = exp.op.exp2.expType;
8985 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8994 // 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
8995 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8996 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8998 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8999 exp.op.exp1.destType = type2;
9002 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9004 if(exp.expType) FreeType(exp.expType);
9005 exp.expType = exp.op.exp1.destType;
9006 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9011 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9012 exp.op.exp2.destType = type1;
9016 // Maybe this was meant to be an enum...
9017 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9019 Type oldType = exp.op.exp2.expType;
9020 exp.op.exp2.expType = null;
9021 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9024 exp.op.exp2.expType = oldType;
9029 // TESTING THIS HERE... LATEST ADDITION
9030 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9032 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9033 exp.op.exp2.destType = type2._class.registered.dataType;
9034 if(type2._class.registered.dataType)
9035 type2._class.registered.dataType.refCount++;
9036 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9038 //exp.expType = type2._class.registered.dataType; //type2;
9039 //if(type2) type2.refCount++;
9042 // TESTING THIS HERE... LATEST ADDITION
9043 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9045 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9046 exp.op.exp1.destType = type1._class.registered.dataType;
9047 if(type1._class.registered.dataType)
9048 type1._class.registered.dataType.refCount++;
9049 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9050 exp.expType = type1._class.registered.dataType; //type1;
9051 if(type1) type1.refCount++;
9055 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9057 if(exp.expType) FreeType(exp.expType);
9058 exp.expType = exp.op.exp2.destType;
9059 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9061 else if(type1 && type2)
9063 char expString1[10240];
9064 char expString2[10240];
9065 char type1String[1024];
9066 char type2String[1024];
9067 expString1[0] = '\0';
9068 expString2[0] = '\0';
9069 type1String[0] = '\0';
9070 type2String[0] = '\0';
9073 PrintExpression(exp.op.exp1, expString1);
9074 ChangeCh(expString1, '\n', ' ');
9075 PrintExpression(exp.op.exp2, expString2);
9076 ChangeCh(expString2, '\n', ' ');
9077 PrintType(exp.op.exp1.expType, type1String, false, true);
9078 PrintType(exp.op.exp2.expType, type2String, false, true);
9081 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9083 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9085 exp.expType = exp.op.exp1.expType;
9086 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9088 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9090 exp.expType = exp.op.exp2.expType;
9091 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9099 // Maybe this was meant to be an enum...
9100 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9102 Type oldType = exp.op.exp1.expType;
9103 exp.op.exp1.expType = null;
9104 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9107 exp.op.exp1.expType = oldType;
9110 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9111 exp.op.exp1.destType = type2;
9114 // TESTING THIS HERE... LATEST ADDITION
9115 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9117 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9118 exp.op.exp1.destType = type1._class.registered.dataType;
9119 if(type1._class.registered.dataType)
9120 type1._class.registered.dataType.refCount++;
9123 // TESTING THIS HERE... LATEST ADDITION
9124 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9126 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9127 exp.op.exp2.destType = type2._class.registered.dataType;
9128 if(type2._class.registered.dataType)
9129 type2._class.registered.dataType.refCount++;
9133 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9135 if(exp.expType) FreeType(exp.expType);
9136 exp.expType = exp.op.exp1.destType;
9137 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9141 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9143 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9145 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9146 // Convert e.g. / 4 into / 4.0
9147 exp.op.exp1.destType = type2._class.registered.dataType;
9148 if(type2._class.registered.dataType)
9149 type2._class.registered.dataType.refCount++;
9150 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9152 if(exp.op.op == '!')
9154 exp.expType = MkClassType("bool");
9155 exp.expType.truth = true;
9159 exp.expType = type2;
9160 if(type2) type2.refCount++;
9163 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9165 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9167 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9168 // Convert e.g. / 4 into / 4.0
9169 exp.op.exp2.destType = type1._class.registered.dataType;
9170 if(type1._class.registered.dataType)
9171 type1._class.registered.dataType.refCount++;
9172 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9174 exp.expType = type1;
9175 if(type1) type1.refCount++;
9180 if(exp.op.exp1 && !exp.op.exp1.expType)
9182 char expString[10000];
9183 expString[0] = '\0';
9186 PrintExpression(exp.op.exp1, expString);
9187 ChangeCh(expString, '\n', ' ');
9190 Compiler_Error($"couldn't determine type of %s\n", expString);
9192 if(exp.op.exp2 && !exp.op.exp2.expType)
9194 char expString[10240];
9195 expString[0] = '\0';
9198 PrintExpression(exp.op.exp2, expString);
9199 ChangeCh(expString, '\n', ' ');
9202 Compiler_Error($"couldn't determine type of %s\n", expString);
9207 FreeType(exp.expType);
9208 exp.expType = MkClassType("bool");
9209 exp.expType.truth = true;
9212 if(exp.op.op != SIZEOF)
9213 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9214 (!exp.op.exp2 || exp.op.exp2.isConstant);
9216 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9218 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9221 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9222 Compiler_Warning($"deleting const qualified object\n");
9232 case extensionExpressionExp:
9235 exp.isConstant = true;
9236 for(e = exp.list->first; e; e = e.next)
9238 //bool inced = false;
9241 FreeType(e.destType);
9242 e.opDestType = exp.opDestType;
9243 e.destType = exp.destType;
9244 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9246 ProcessExpressionType(e);
9248 exp.destType.count--;*/
9249 if(!exp.expType && !e.next)
9251 exp.expType = e.expType;
9252 if(e.expType) e.expType.refCount++;
9253 exp.needCast = e.needCast;
9256 exp.isConstant = false;
9259 // In case a cast became a member...
9260 e = exp.list->first;
9261 if(!e.next && e.type == memberExp)
9263 // Preserve prev, next
9264 Expression next = exp.next, prev = exp.prev;
9267 FreeType(exp.expType);
9268 FreeType(exp.destType);
9278 ProcessExpressionType(exp);
9285 exp.isConstant = true;
9287 ProcessExpressionType(exp.index.exp);
9288 if(!exp.index.exp.isConstant)
9289 exp.isConstant = false;
9291 if(exp.index.exp.expType)
9293 Type source = exp.index.exp.expType;
9294 if(source.kind == classType && source._class && source._class.registered)
9296 Class _class = source._class.registered;
9297 Class c = _class.templateClass ? _class.templateClass : _class;
9298 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9300 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9302 if(exp.index.index && exp.index.index->last)
9304 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9306 if(type.kind == classType) type.constant = true;
9307 else if(type.kind == pointerType)
9310 while(t.kind == pointerType) t = t.type;
9314 ((Expression)exp.index.index->last).destType = type;
9320 for(e = exp.index.index->first; e; e = e.next)
9322 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9324 if(e.destType) FreeType(e.destType);
9325 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9327 ProcessExpressionType(e);
9330 // Check if this type is int
9333 exp.isConstant = false;
9337 exp.expType = Dereference(exp.index.exp.expType);
9339 DeclareType(curExternal, exp.expType, true, false);
9346 Type methodType = null;
9352 PrintExpression(exp.call.exp, name);
9353 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9355 //exp.call.exp.expType = null;
9356 PrintExpression(exp.call.exp, name);
9359 if(exp.call.exp.type == identifierExp)
9361 Expression idExp = exp.call.exp;
9362 Identifier id = idExp.identifier;
9363 if(!strcmp(id.string, "__builtin_frame_address"))
9365 exp.expType = ProcessTypeString("void *", true);
9366 if(exp.call.arguments && exp.call.arguments->first)
9367 ProcessExpressionType(exp.call.arguments->first);
9370 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9372 exp.expType = ProcessTypeString("int", true);
9373 if(exp.call.arguments && exp.call.arguments->first)
9374 ProcessExpressionType(exp.call.arguments->first);
9377 else if(!strcmp(id.string, "Max") ||
9378 !strcmp(id.string, "Min") ||
9379 !strcmp(id.string, "Sgn") ||
9380 !strcmp(id.string, "Abs"))
9382 Expression a = null;
9383 Expression b = null;
9384 Expression tempExp1 = null, tempExp2 = null;
9385 if((!strcmp(id.string, "Max") ||
9386 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9388 a = exp.call.arguments->first;
9389 b = exp.call.arguments->last;
9393 else if(exp.call.arguments->count == 1)
9395 a = exp.call.arguments->first;
9401 exp.call.arguments->Clear();
9402 idExp.identifier = null;
9404 FreeExpContents(exp);
9406 ProcessExpressionType(a);
9408 ProcessExpressionType(b);
9410 exp.type = bracketsExp;
9411 exp.list = MkList();
9413 if(a.expType && (!b || b.expType))
9415 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9417 // Use the simpleStruct name/ids for now...
9420 OldList * specs = MkList();
9421 OldList * decls = MkList();
9423 char temp1[1024], temp2[1024];
9425 GetTypeSpecs(a.expType, specs);
9427 if(a && !a.isConstant && a.type != identifierExp)
9429 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9430 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9431 tempExp1 = QMkExpId(temp1);
9432 tempExp1.expType = a.expType;
9434 a.expType.refCount++;
9435 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9437 if(b && !b.isConstant && b.type != identifierExp)
9439 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9440 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9441 tempExp2 = QMkExpId(temp2);
9442 tempExp2.expType = b.expType;
9444 b.expType.refCount++;
9445 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9448 decl = MkDeclaration(specs, decls);
9449 if(!curCompound.compound.declarations)
9450 curCompound.compound.declarations = MkList();
9451 curCompound.compound.declarations->Insert(null, decl);
9456 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9458 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9460 MkExpCondition(MkExpBrackets(MkListOne(
9461 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9462 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9463 exp.expType = a.expType;
9465 a.expType.refCount++;
9467 else if(!strcmp(id.string, "Abs"))
9470 MkExpCondition(MkExpBrackets(MkListOne(
9471 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9472 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9473 exp.expType = a.expType;
9475 a.expType.refCount++;
9477 else if(!strcmp(id.string, "Sgn"))
9479 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9481 MkExpCondition(MkExpBrackets(MkListOne(
9482 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9483 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9484 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9485 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9486 exp.expType = ProcessTypeString("int", false);
9489 FreeExpression(tempExp1);
9490 if(tempExp2) FreeExpression(tempExp2);
9504 if(!exp.call.exp.destType)
9506 exp.call.exp.destType = dummy;
9509 ProcessExpressionType(exp.call.exp);
9510 if(exp.call.exp.destType == dummy)
9513 exp.call.exp.destType = null;
9518 // Check argument types against parameter types
9519 functionType = exp.call.exp.expType;
9521 if(functionType && functionType.kind == TypeKind::methodType)
9523 methodType = functionType;
9524 functionType = methodType.method.dataType;
9526 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9527 // TOCHECK: Instead of doing this here could this be done per param?
9528 if(exp.call.exp.expType.usedClass)
9530 char typeString[1024];
9531 typeString[0] = '\0';
9533 Symbol back = functionType.thisClass;
9534 // Do not output class specifier here (thisclass was added to this)
9535 functionType.thisClass = null;
9536 PrintType(functionType, typeString, true, true);
9537 functionType.thisClass = back;
9539 if(strstr(typeString, "thisclass"))
9541 OldList * specs = MkList();
9544 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9546 decl = SpecDeclFromString(typeString, specs, null);
9548 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9549 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9550 exp.call.exp.expType.usedClass))
9551 thisClassParams = false;
9553 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9555 Class backupThisClass = thisClass;
9556 thisClass = exp.call.exp.expType.usedClass;
9557 ProcessDeclarator(decl, true);
9558 thisClass = backupThisClass;
9561 thisClassParams = true;
9563 functionType = ProcessType(specs, decl);
9564 functionType.refCount = 0;
9565 FinishTemplatesContext(context);
9567 // Mark parameters that were 'thisclass'
9570 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9572 //p.wasThisClass = op.kind == thisClassType;
9573 if(op.kind == thisClassType)
9574 p.thisClassFrom = methodType.method._class;
9577 if(methodType.method.dataType.returnType.kind == thisClassType)
9579 // functionType.returnType.wasThisClass = true;
9580 functionType.returnType.thisClassFrom = methodType.method._class;
9584 FreeList(specs, FreeSpecifier);
9585 FreeDeclarator(decl);
9589 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9591 Type type = functionType.type;
9592 if(!functionType.refCount)
9594 functionType.type = null;
9595 FreeType(functionType);
9597 //methodType = functionType;
9598 functionType = type;
9600 if(functionType && functionType.kind != TypeKind::functionType)
9602 Compiler_Error($"called object %s is not a function\n", name);
9604 else if(functionType)
9606 bool emptyParams = false, noParams = false;
9607 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9608 Type type = functionType.params.first;
9609 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9611 Location oldyylloc = yylloc;
9613 if(!type) emptyParams = true;
9616 if(functionType.extraParam && e && functionType.thisClass)
9618 e.destType = MkClassType(functionType.thisClass.string);
9622 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9623 // Fixed #141 by adding '&& !functionType.extraParam'
9624 if(!functionType.staticMethod && !functionType.extraParam)
9626 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9627 memberExp.member.exp.expType._class)
9629 type = MkClassType(memberExp.member.exp.expType._class.string);
9634 type = functionType.params.first;
9639 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9641 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9642 type.byReference = functionType.byReference;
9643 type.typedByReference = functionType.typedByReference;
9646 // Allow manually passing a class for typed object
9647 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9651 type = functionType.params.first;
9659 if(type && type.kind == voidType)
9662 if(!type.refCount) FreeType(type);
9666 for( ; e; e = e.next)
9668 if(!type && !emptyParams)
9671 if(methodType && methodType.methodClass)
9672 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9673 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9674 noParams ? 0 : functionType.params.count);
9676 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9677 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9678 noParams ? 0 : functionType.params.count);
9682 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9684 Type templatedType = null;
9685 Class _class = methodType.usedClass;
9686 ClassTemplateParameter curParam = null;
9688 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9691 for(sClass = _class; sClass; sClass = sClass.base)
9693 if(sClass.templateClass) sClass = sClass.templateClass;
9695 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9697 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9700 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9702 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9703 id += nextClass.templateParams.count;
9712 if(curParam && _class.templateArgs[id].dataTypeString)
9714 bool constant = type.constant;
9715 ClassTemplateArgument arg = _class.templateArgs[id];
9717 Context context = SetupTemplatesContext(_class);
9720 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9721 templatedType = ProcessTypeString(arg.dataTypeString, false);
9722 FinishTemplatesContext(context);
9725 if(templatedType.kind == classType && constant) templatedType.constant = true;
9726 else if(templatedType.kind == pointerType)
9728 Type t = templatedType.type;
9729 while(t.kind == pointerType) t = t.type;
9730 if(constant) t.constant = constant;
9733 e.destType = templatedType;
9736 templatedType.passAsTemplate = true;
9737 // templatedType.refCount++;
9743 if(type) type.refCount++;
9748 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9750 e.destType = type.prev;
9751 e.destType.refCount++;
9756 if(type) type.refCount++;
9759 // Don't reach the end for the ellipsis
9760 if(type && type.kind != ellipsisType)
9762 Type next = type.next;
9763 if(!type.refCount) FreeType(type);
9768 if(type && type.kind != ellipsisType)
9770 if(methodType && methodType.methodClass)
9771 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9772 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9773 functionType.params.count + extra);
9775 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9776 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9777 functionType.params.count + extra);
9780 if(type && !type.refCount) FreeType(type);
9787 kind = TypeKind::functionType;
9790 if(exp.call.exp.type == identifierExp)
9792 char * string = exp.call.exp.identifier.string;
9796 Location oldyylloc = yylloc;
9798 yylloc = exp.call.exp.identifier.loc;
9799 if(strstr(string, "__builtin_") == string)
9803 functionType.returnType = exp.destType;
9804 exp.destType.refCount++;
9808 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9809 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9810 globalContext.symbols.Add((BTNode)symbol);
9811 if(strstr(symbol.string, "::"))
9812 globalContext.hasNameSpace = true;
9817 else if(exp.call.exp.type == memberExp)
9819 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9820 exp.call.exp.member.member.string);*/
9823 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9825 if(!functionType.returnType)
9827 functionType.returnType = Type
9834 if(functionType && functionType.kind == TypeKind::functionType)
9836 exp.expType = functionType.returnType;
9838 if(functionType.returnType)
9839 functionType.returnType.refCount++;
9841 if(!functionType.refCount)
9842 FreeType(functionType);
9845 if(exp.call.arguments)
9847 for(e = exp.call.arguments->first; e; e = e.next)
9848 ProcessExpressionType(e);
9855 Location oldyylloc = yylloc;
9857 Expression checkExp = exp.member.exp;
9860 if(checkExp.type == castExp)
9861 checkExp = checkExp.cast.exp;
9862 else if(checkExp.type == bracketsExp)
9863 checkExp = checkExp.list ? checkExp.list->first : null;
9868 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9869 exp.thisPtr = thisPtr;
9871 // DOING THIS LATER NOW...
9872 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9874 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9875 /* TODO: Name Space Fix ups
9876 if(!exp.member.member.classSym)
9877 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9881 ProcessExpressionType(exp.member.exp);
9882 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9883 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9885 exp.isConstant = false;
9888 exp.isConstant = exp.member.exp.isConstant;
9889 type = exp.member.exp.expType;
9893 if(type && (type.kind == templateType))
9895 Class _class = thisClass ? thisClass : currentClass;
9896 ClassTemplateParameter param = null;
9899 for(param = _class.templateParams.first; param; param = param.next)
9901 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9905 if(param && param.defaultArg.member)
9907 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9910 Expression expMember = exp.member.exp;
9912 OldList * specs = MkList();
9913 char thisClassTypeString[1024];
9915 FreeIdentifier(exp.member.member);
9917 ProcessExpressionType(argExp);
9920 char * colon = strstr(param.defaultArg.memberString, "::");
9923 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9924 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9927 strcpy(thisClassTypeString, _class.fullName);
9930 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9932 exp.expType = ProcessType(specs, decl);
9933 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9935 Class expClass = exp.expType._class.registered;
9936 Class cClass = null;
9940 char templateString[1024];
9941 ClassTemplateParameter param;
9942 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9943 for(cClass = expClass; cClass; cClass = cClass.base)
9946 for(param = cClass.templateParams.first; param; param = param.next)
9950 ClassTemplateArgument arg;
9951 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9952 arg = expClass.templateArgs[id];
9954 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9956 ClassTemplateParameter cParam;
9957 //int p = numParams - sClass.templateParams.count;
9960 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9962 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9964 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9966 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9968 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9969 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9981 strcat(argument, arg.name.string);
9982 strcat(argument, " = ");
9988 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9989 char expString[1024];
9990 OldList * specs = MkList();
9991 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9993 char * string = PrintHexUInt64(arg.expression.ui64);
9994 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9997 ProcessExpressionType(exp);
9998 ComputeExpression(exp);
9999 expString[0] = '\0';
10000 PrintExpression(exp, expString);
10001 strcat(argument, expString);
10003 FreeExpression(exp);
10008 strcat(argument, arg.member.name);
10011 case TemplateParameterType::type:
10013 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10015 if(!strcmp(arg.dataTypeString, "thisclass"))
10016 strcat(argument, thisClassTypeString);
10018 strcat(argument, arg.dataTypeString);
10025 if(paramCount) strcat(templateString, ", ");
10026 if(lastParam != p - 1)
10028 strcat(templateString, param.name);
10029 strcat(templateString, " = ");
10031 strcat(templateString, argument);
10040 int len = strlen(templateString);
10041 if(templateString[len-1] == '>') templateString[len++] = ' ';
10042 templateString[len++] = '>';
10043 templateString[len++] = '\0';
10046 Context context = SetupTemplatesContext(_class);
10047 FreeType(exp.expType);
10048 exp.expType = ProcessTypeString(templateString, false);
10049 FinishTemplatesContext(context);
10053 if(!expMember.expType.isPointerType)
10054 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10055 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10056 exp.type = bracketsExp;
10057 exp.list = MkListOne(MkExpOp(null, '*',
10060 exp.op.exp1 = null;
10062 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10063 MkExpBrackets(MkListOne(
10064 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10067 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10069 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10074 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10075 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10077 type = ProcessTemplateParameterType(type.templateParameter);
10080 // TODO: *** This seems to be where we should add method support for all basic types ***
10081 if(type && (type.kind == templateType));
10082 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10083 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10084 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10085 (type.kind == pointerType && type.type.kind == charType)))
10087 Identifier id = exp.member.member;
10088 TypeKind typeKind = type.kind;
10089 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10090 if(typeKind == subClassType && exp.member.exp.type == classExp)
10092 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10093 typeKind = classType;
10098 if(typeKind == intType || typeKind == enumType)
10099 _class = eSystem_FindClass(privateModule, "int");
10102 if(type.kind == classType && type._class && type._class.registered)
10104 _class = type._class.registered;
10106 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10108 _class = FindClass("char *").registered;
10110 else if(type.kind == pointerType)
10112 _class = eSystem_FindClass(privateModule, "uintptr");
10113 FreeType(exp.expType);
10114 exp.expType = ProcessTypeString("uintptr", false);
10115 exp.byReference = true;
10119 char string[1024] = "";
10121 PrintTypeNoConst(type, string, false, true);
10122 classSym = FindClass(string);
10123 if(classSym) _class = classSym.registered;
10131 (exp.member.exp.type == identifierExp &&
10132 !strcmp(exp.member.exp.identifier.string, "this"));*/
10133 Property prop = null;
10134 Method method = null;
10135 DataMember member = null;
10136 Property revConvert = null;
10137 ClassProperty classProp = null;
10139 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10140 exp.member.memberType = propertyMember;
10142 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10143 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10145 if(typeKind != subClassType)
10147 // Prioritize data members over properties for "this"
10148 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10150 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10151 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10153 prop = eClass_FindProperty(_class, id.string, privateModule);
10157 if(!member && !prop)
10158 prop = eClass_FindProperty(_class, id.string, privateModule);
10159 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10160 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10161 exp.member.thisPtr = true;
10163 // Prioritize properties over data members otherwise
10166 bool useMemberForNonConst = false;
10167 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10170 prop = eClass_FindProperty(_class, id.string, null);
10172 useMemberForNonConst = prop && exp.destType &&
10173 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10174 !strncmp(prop.dataTypeString, "const ", 6);
10176 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10177 member = eClass_FindDataMember(_class, id.string, null, null, null);
10180 if((!prop || useMemberForNonConst) && !member)
10182 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10185 prop = eClass_FindProperty(_class, id.string, privateModule);
10187 useMemberForNonConst |= prop && exp.destType &&
10188 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10189 !strncmp(prop.dataTypeString, "const ", 6);
10191 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10192 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10198 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10205 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10206 method = eClass_FindMethod(_class, id.string, privateModule);
10207 if(!prop && !member && !method)
10209 if(typeKind == subClassType)
10211 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10214 exp.member.memberType = classPropertyMember;
10215 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10219 // Assume this is a class_data member
10220 char structName[1024];
10221 Identifier id = exp.member.member;
10222 Expression classExp = exp.member.exp;
10225 FreeType(classExp.expType);
10226 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10228 strcpy(structName, "__ecereClassData_");
10229 FullClassNameCat(structName, type._class.string, false);
10230 exp.type = pointerExp;
10231 exp.member.member = id;
10233 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10234 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10235 MkExpBrackets(MkListOne(MkExpOp(
10236 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10237 MkExpMember(classExp, MkIdentifier("data"))), '+',
10238 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10243 ProcessExpressionType(exp);
10249 // Check for reverse conversion
10250 // (Convert in an instantiation later, so that we can use
10251 // deep properties system)
10252 Symbol classSym = FindClass(id.string);
10255 Class convertClass = classSym.registered;
10257 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10262 //if(!exp.member.exp.destType)
10263 if(exp.member.exp.destType)
10264 FreeType(exp.member.exp.destType);
10266 if(method && !method._class.symbol)
10267 method._class.symbol = FindClass(method._class.fullName);
10268 if(prop && !prop._class.symbol)
10269 prop._class.symbol = FindClass(prop._class.fullName);
10271 exp.member.exp.destType = Type
10275 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10276 // wasThisClass = type ? type.wasThisClass : false;
10277 thisClassFrom = type ? type.thisClassFrom : null;
10283 exp.member.memberType = propertyMember;
10285 ProcessPropertyType(prop);
10286 exp.expType = prop.dataType;
10287 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10290 CopyTypeInto(type, exp.expType);
10292 type.constant = true;
10293 exp.expType = type;
10295 else if(prop.dataType)
10296 prop.dataType.refCount++;
10300 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10302 FreeExpContents(exp);
10303 exp.type = identifierExp;
10304 exp.identifier = MkIdentifier("class");
10305 ProcessExpressionType(exp);
10309 exp.member.memberType = dataMember;
10310 DeclareStruct(curExternal, _class.fullName, false, true);
10311 if(member._class != _class)
10312 DeclareStruct(curExternal, member._class.fullName, false, true);
10314 if(!member.dataType)
10316 Context context = SetupTemplatesContext(_class);
10317 member.dataType = ProcessTypeString(member.dataTypeString, false);
10318 FinishTemplatesContext(context);
10320 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)
10321 member.dataType.bitMemberSize = ((BitMember)member).size;
10322 exp.expType = member.dataType;
10323 if(member.dataType) member.dataType.refCount++;
10325 else if(revConvert)
10327 exp.member.memberType = reverseConversionMember;
10328 exp.expType = MkClassType(revConvert._class.fullName);
10336 exp.type = identifierExp;
10337 exp.identifier = exp.member.member;
10340 exp.member.memberType = methodMember;
10342 if(!method.dataType)
10343 ProcessMethodType(method);
10351 // Tricky spot here... To use instance versus class virtual table
10352 // Put it back to what it was... What did we break?
10354 // Had to put it back for overriding Main of Thread global instance
10356 //exp.expType.methodClass = _class;
10357 exp.expType.methodClass = (id && id._class) ? _class : null;
10359 // Need the actual class used for templated classes
10360 exp.expType.usedClass = _class;
10362 else if(!classProp)
10364 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10366 FreeExpContents(exp);
10367 exp.type = identifierExp;
10368 exp.identifier = MkIdentifier("class");
10369 FreeType(exp.expType);
10370 exp.expType = MkClassType("ecere::com::Class");
10373 yylloc = exp.member.member.loc;
10374 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10376 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10379 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10383 tClass = type._class && type._class.registered ? type._class.registered : _class;
10384 while(tClass && !tClass.templateClass) tClass = tClass.base;
10386 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10389 ClassTemplateParameter curParam = null;
10392 for(sClass = tClass; sClass; sClass = sClass.base)
10395 if(sClass.templateClass) sClass = sClass.templateClass;
10396 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10398 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10400 for(sClass = sClass.base; sClass; sClass = sClass.base)
10401 id += sClass.templateParams.count;
10406 if(curParam) break;
10409 if(curParam && tClass.templateArgs[id].dataTypeString)
10411 ClassTemplateArgument arg = tClass.templateArgs[id];
10412 Context context = SetupTemplatesContext(tClass);
10413 bool constant = exp.expType.constant;
10414 bool passAsTemplate = false;
10415 Class thisClassFrom = null;
10416 Type t = ProcessTypeString(exp.expType.templateParameter.dataTypeString, false);
10417 if(t && t.kind == classType && t._class)
10418 thisClassFrom = t._class.registered;
10420 // Mark that 'thisClassFrom' was set to something
10421 thisClassFrom = eSystem_FindClass(GetPrivateModule(), "class");
10425 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10426 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10428 /*if(!arg.dataType)
10429 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10430 FreeType(exp.expType);
10432 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10433 exp.expType.thisClassFrom = thisClassFrom;
10434 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10435 else if(exp.expType.kind == pointerType)
10437 Type t = exp.expType.type;
10438 while(t.kind == pointerType) t = t.type;
10439 if(constant) t.constant = constant;
10443 if(exp.expType.kind == thisClassType)
10445 FreeType(exp.expType);
10446 exp.expType = ReplaceThisClassType(_class);
10450 exp.expType.passAsTemplate = true;
10451 //exp.expType.refCount++;
10454 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10455 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10456 else if(exp.destType.kind == pointerType)
10458 Type t = exp.destType.type;
10459 while(t.kind == pointerType) t = t.type;
10460 if(constant) t.constant = constant;
10463 //exp.destType.refCount++;
10465 if(exp.destType.kind == thisClassType)
10467 FreeType(exp.destType);
10468 exp.destType = ReplaceThisClassType(_class);
10472 FinishTemplatesContext(context);
10475 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10476 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10479 ClassTemplateParameter curParam = null;
10482 for(sClass = tClass; sClass; sClass = sClass.base)
10485 if(sClass.templateClass) sClass = sClass.templateClass;
10486 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10488 if(curParam.type == TemplateParameterType::type &&
10489 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10491 for(sClass = sClass.base; sClass; sClass = sClass.base)
10492 id += sClass.templateParams.count;
10497 if(curParam) break;
10502 ClassTemplateArgument arg = tClass.templateArgs[id];
10503 Context context = SetupTemplatesContext(tClass);
10505 /*if(!arg.dataType)
10506 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10508 basicType = ProcessTypeString(arg.dataTypeString, false);
10511 if(basicType.kind == thisClassType)
10513 FreeType(basicType);
10514 basicType = ReplaceThisClassType(_class);
10517 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10518 if(tClass.templateClass)
10519 basicType.passAsTemplate = true;
10522 FreeType(exp.expType);
10524 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10525 //exp.expType.refCount++;
10528 exp.destType = exp.expType;
10529 exp.destType.refCount++;
10533 Expression newExp { };
10534 OldList * specs = MkList();
10536 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10538 if(exp.destType) exp.destType.refCount++;
10539 if(exp.expType) exp.expType.refCount++;
10540 exp.type = castExp;
10541 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10542 exp.cast.exp = newExp;
10543 //FreeType(exp.expType);
10544 //exp.expType = null;
10545 //ProcessExpressionType(sourceExp);
10548 FinishTemplatesContext(context);
10551 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10553 Class expClass = exp.expType._class.registered;
10556 Class cClass = null;
10558 int paramCount = 0;
10559 int lastParam = -1;
10560 char templateString[1024];
10561 ClassTemplateParameter param;
10562 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10563 while(cClass != expClass)
10566 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10569 for(param = cClass.templateParams.first; param; param = param.next)
10571 Class cClassCur = null;
10573 ClassTemplateParameter paramCur = null;
10574 ClassTemplateArgument arg;
10575 while(cClassCur != tClass && !paramCur)
10578 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10579 cClassCur = sClassCur;
10581 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10583 if(!strcmp(paramCur.name, param.name))
10591 if(paramCur && paramCur.type == TemplateParameterType::type)
10592 arg = tClass.templateArgs[cp];
10594 arg = expClass.templateArgs[p];
10597 char argument[256];
10598 argument[0] = '\0';
10601 strcat(argument, arg.name.string);
10602 strcat(argument, " = ");
10608 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10609 char expString[1024];
10610 OldList * specs = MkList();
10611 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10613 char * string = PrintHexUInt64(arg.expression.ui64);
10614 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10617 ProcessExpressionType(exp);
10618 ComputeExpression(exp);
10619 expString[0] = '\0';
10620 PrintExpression(exp, expString);
10621 strcat(argument, expString);
10623 FreeExpression(exp);
10628 strcat(argument, arg.member.name);
10631 case TemplateParameterType::type:
10633 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10634 strcat(argument, arg.dataTypeString);
10640 if(paramCount) strcat(templateString, ", ");
10641 if(lastParam != p - 1)
10643 strcat(templateString, param.name);
10644 strcat(templateString, " = ");
10646 strcat(templateString, argument);
10655 int len = strlen(templateString);
10656 if(templateString[len-1] == '>') templateString[len++] = ' ';
10657 templateString[len++] = '>';
10658 templateString[len++] = '\0';
10661 FreeType(exp.expType);
10663 Context context = SetupTemplatesContext(tClass);
10664 exp.expType = ProcessTypeString(templateString, false);
10665 FinishTemplatesContext(context);
10672 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10674 else if(type && (type.kind == structType || type.kind == unionType))
10676 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10679 exp.expType = memberType;
10681 memberType.refCount++;
10686 char expString[10240];
10687 expString[0] = '\0';
10688 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10689 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10692 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10694 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10696 Identifier id = exp.member.member;
10697 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10700 FreeType(exp.expType);
10701 exp.expType = ReplaceThisClassType(_class);
10705 yylloc = oldyylloc;
10708 // Convert x->y into (*x).y
10711 Type destType = exp.destType;
10713 // DOING THIS LATER NOW...
10714 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10716 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10717 /* TODO: Name Space Fix ups
10718 if(!exp.member.member.classSym)
10719 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10723 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10724 exp.type = memberExp;
10727 ProcessExpressionType(exp);
10734 //ComputeExpression(exp);
10736 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10737 if(classSym && classSym.registered)
10739 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10742 Class b = classSym.registered;
10744 DeclareStruct(curExternal, classSym.string, false, true);
10745 FreeSpecifier(exp._class);
10746 FullClassNameCat(name, classSym.string, false);
10750 exp.type = typeSizeExp;
10751 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10757 if(b.structSize == b.offset)
10758 exp.op.exp1 = MkExpConstant("0");
10760 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10763 while(b.offset != 0)
10766 Expression typeSize;
10769 sym = FindClass(b.fullName);
10772 DeclareStruct(curExternal, sym.string, false, true);
10773 FullClassNameCat(name, sym.string, false);
10775 if(b.structSize == b.offset)
10776 typeSize = MkExpConstant("0");
10778 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10779 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10786 if(classSym.registered.fixed && !classSym.registered.structSize)
10788 FreeSpecifier(exp._class);
10789 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10790 exp.type = constantExp;
10794 char className[1024];
10795 strcpy(className, "__ecereClass_");
10796 FullClassNameCat(className, classSym.string, true);
10798 DeclareClass(curExternal, classSym, className);
10800 FreeExpContents(exp);
10801 exp.type = pointerExp;
10802 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10803 exp.member.member = MkIdentifier("structSize");
10811 kind = intSizeType;
10813 // exp.isConstant = true;
10818 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10823 kind = intSizeType;
10825 exp.isConstant = true;
10827 DeclareType(curExternal, type, true, false);
10833 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10835 FreeType(exp.cast.exp.destType);
10836 exp.cast.exp.destType = type;
10838 type.casted = true;
10839 ProcessExpressionType(exp.cast.exp);
10840 type.casted = false;
10842 exp.expType = type;
10845 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10846 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10848 void * prev = exp.prev, * next = exp.next;
10849 Type expType = exp.cast.exp.destType;
10850 Expression castExp = exp.cast.exp;
10851 Type destType = exp.destType;
10853 if(expType) expType.refCount++;
10855 //FreeType(exp.destType);
10856 FreeType(exp.expType);
10857 FreeTypeName(exp.cast.typeName);
10860 FreeType(exp.expType);
10861 FreeType(exp.destType);
10863 exp.expType = expType;
10864 exp.destType = destType;
10874 exp.isConstant = exp.cast.exp.isConstant;
10879 case extensionInitializerExp:
10881 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10882 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10883 // ProcessInitializer(exp.initializer.initializer, type);
10884 exp.expType = type;
10889 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10890 ProcessExpressionType(exp.vaArg.exp);
10891 exp.expType = type;
10897 Type t = exp.destType;
10898 if(t && !exp.destType.casted)
10901 CopyTypeInto(t, exp.destType);
10907 exp.isConstant = true;
10909 FreeType(exp.cond.cond.destType);
10910 exp.cond.cond.destType = MkClassType("bool");
10911 exp.cond.cond.destType.truth = true;
10912 ProcessExpressionType(exp.cond.cond);
10913 if(!exp.cond.cond.isConstant)
10914 exp.isConstant = false;
10915 for(e = exp.cond.exp->first; e; e = e.next)
10919 FreeType(e.destType);
10921 if(e.destType) e.destType.refCount++;
10923 ProcessExpressionType(e);
10926 exp.expType = e.expType;
10927 if(e.expType) e.expType.refCount++;
10930 exp.isConstant = false;
10933 FreeType(exp.cond.elseExp.destType);
10934 // Added this check if we failed to find an expType
10935 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10938 exp.cond.elseExp.destType = t ? t : exp.expType;
10940 if(exp.cond.elseExp.destType)
10941 exp.cond.elseExp.destType.refCount++;
10942 ProcessExpressionType(exp.cond.elseExp);
10944 // FIXED THIS: Was done before calling process on elseExp
10945 if(!exp.cond.elseExp.isConstant)
10946 exp.isConstant = false;
10951 case extensionCompoundExp:
10953 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10955 Statement last = exp.compound.compound.statements->last;
10956 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10958 ((Expression)last.expressions->last).destType = exp.destType;
10960 exp.destType.refCount++;
10962 ProcessStatement(exp.compound);
10963 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10965 exp.expType.refCount++;
10971 Specifier spec = exp._classExp.specifiers->first;
10972 if(spec && spec.type == nameSpecifier)
10974 exp.expType = MkClassType(spec.name);
10975 exp.expType.kind = subClassType;
10976 exp.byReference = true;
10980 exp.expType = MkClassType("ecere::com::Class");
10981 exp.byReference = true;
10987 Class _class = thisClass ? thisClass : currentClass;
10990 Identifier id = exp.classData.id;
10991 char structName[1024];
10992 Expression classExp;
10993 strcpy(structName, "__ecereClassData_");
10994 FullClassNameCat(structName, _class.fullName, false);
10995 exp.type = pointerExp;
10996 exp.member.member = id;
10997 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10998 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
11000 classExp = MkExpIdentifier(MkIdentifier("class"));
11002 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
11003 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
11004 MkExpBrackets(MkListOne(MkExpOp(
11005 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
11006 MkExpMember(classExp, MkIdentifier("data"))), '+',
11007 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
11010 ProcessExpressionType(exp);
11018 const char * typeString = null;
11019 char typeStringBuf[1024];
11020 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11021 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11023 Class templateClass = exp.destType._class.registered;
11024 typeString = templateClass.templateArgs[2].dataTypeString;
11028 // Guess type from expressions in the array
11030 for(e = exp.list->first; e; e = e.next)
11032 ProcessExpressionType(e);
11035 if(!type) { type = e.expType; type.refCount++; }
11038 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11039 if(!MatchTypeExpression(e, type, null, false, true))
11045 e = exp.list->first;
11046 ProcessExpressionType(e);
11049 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11050 if(!MatchTypeExpression(e, type, null, false, true))
11052 FreeType(e.expType);
11063 FreeType(e.expType);
11070 typeStringBuf[0] = '\0';
11071 PrintTypeNoConst(type, typeStringBuf, false, true);
11072 typeString = typeStringBuf;
11080 (Container)& (struct BuiltInContainer)
11082 ._vTbl = class(BuiltInContainer)._vTbl,
11083 ._class = class(BuiltInContainer),
11085 .data = (int[]){ 1, 7, 3, 4, 5 },
11087 .type = class(int),
11090 char templateString[1024];
11091 OldList * initializers = MkList();
11092 OldList * structInitializers = MkList();
11093 OldList * specs = MkList();
11095 Declarator decl = SpecDeclFromString(typeString, specs, null);
11096 sprintf(templateString, "Container<%s>", typeString);
11101 type = ProcessTypeString(typeString, false);
11102 while((e = exp.list->first))
11104 exp.list->Remove(e);
11107 ProcessExpressionType(e);
11108 ListAdd(initializers, MkInitializerAssignment(e));
11114 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11116 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11117 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11118 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11119 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11120 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11121 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11122 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11123 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11124 MkInitializerList(initializers))));
11125 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11126 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11127 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11128 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11129 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11130 exp.expType = ProcessTypeString(templateString, false);
11131 exp.type = bracketsExp;
11132 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11134 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11135 MkInitializerList(structInitializers)))));
11136 ProcessExpressionType(expExt);
11140 exp.expType = ProcessTypeString("Container", false);
11141 Compiler_Error($"Couldn't determine type of array elements\n");
11147 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11149 FreeType(exp.expType);
11150 exp.expType = ReplaceThisClassType(thisClass);
11153 // Resolve structures here
11154 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11156 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11157 // TODO: Fix members reference...
11160 if(exp.expType.kind != enumType)
11163 String enumName = CopyString(exp.expType.enumName);
11165 // Fixed a memory leak on self-referencing C structs typedefs
11166 // by instantiating a new type rather than simply copying members
11167 // into exp.expType
11168 FreeType(exp.expType);
11169 exp.expType = Type { };
11170 exp.expType.kind = symbol.type.kind;
11171 exp.expType.refCount++;
11172 exp.expType.enumName = enumName;
11174 exp.expType.members = symbol.type.members;
11175 for(member = symbol.type.members.first; member; member = member.next)
11180 NamedLink64 member;
11181 for(member = symbol.type.members.first; member; member = member.next)
11183 NamedLink64 value { name = CopyString(member.name) };
11184 exp.expType.members.Add(value);
11190 // Trying to do this here before conversion properties kick in and this becomes a new expression... (Fixing Class c; const char * a = c;)
11191 // Mark nohead classes as by reference, unless we're casting them to an integral type
11192 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11193 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11194 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11195 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11197 exp.byReference = true;
11201 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11202 else if(exp.destType && !exp.destType.keepCast)
11204 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11205 exp.needTemplateCast = 1;
11207 if(exp.destType.kind == voidType);
11208 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11210 // Warn for casting unrelated types to/from struct classes
11211 bool invalidCast = false;
11212 if(inCompiler && exp.destType.count && exp.expType)
11214 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11215 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11216 if(c1 && c1.type != structClass) c1 = null;
11217 if(c2 && c2.type != structClass) c2 = null;
11218 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11219 invalidCast = true;
11221 if(!exp.destType.count || unresolved || invalidCast)
11226 if(exp.destType.kind != ellipsisType)
11232 char expString[10240];
11233 expString[0] = '\0';
11235 PrintType(exp.destType, type2, false, true);
11237 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11239 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11240 else if(exp.type != dummyExp)
11241 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11246 char expString[10240] ;
11247 expString[0] = '\0';
11248 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11251 Compiler_Error($"unresolved identifier %s\n", expString);
11252 else if(exp.type != dummyExp)
11253 Compiler_Error($"couldn't determine type of %s\n", expString);
11264 PrintType(exp.expType, type1, false, true);
11265 PrintType(exp.destType, type2, false, true);
11268 //CheckExpressionType(exp, exp.destType, false);
11270 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11271 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11272 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11275 Expression nbExp = GetNonBracketsExp(exp);
11276 bool skipWarning = false;
11277 TypeKind kind = exp.destType.kind;
11278 if(nbExp.type == conditionExp && nbExp.destType && !nbExp.destType.casted && nbExp.destType.kind == exp.destType.kind)
11279 // The if/else operands have already been checked / warned about
11280 skipWarning = true;
11281 if((kind == charType || kind == shortType) && exp.destType.isSigned == exp.expType.signedBeforePromotion && nbExp.type == opExp && nbExp.op.exp1 && nbExp.op.exp2)
11283 int op = nbExp.op.op;
11284 Expression nbExp1, nbExp2;
11289 case '%': case '/':
11290 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11291 from = nbExp1.expType.promotedFrom;
11292 // Division and Modulo will not take more room than type before promotion
11293 if(from == charType || (kind == shortType && from == shortType))
11294 skipWarning = true;
11297 case LEFT_OP: case RIGHT_OP:
11298 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11299 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11300 from = nbExp1.expType.promotedFrom;
11301 // Right shift will not take more room than type before promotion
11302 if(op == RIGHT_OP && (from == charType || (kind == shortType && from == shortType)))
11303 skipWarning = true;
11304 else if(nbExp2.isConstant && nbExp2.type == constantExp && (nbExp.op.op == RIGHT_OP || nbExp1.expType.bitMemberSize))
11306 int n = (int)strtol(nbExp2.constant, null, 0);
11307 int s = from == charType ? 8 : 16;
11308 // Left shifting a bit member constrained in size may still fit in type before promotion
11309 if(nbExp1.expType.bitMemberSize && nbExp1.expType.bitMemberSize < s)
11310 s = nbExp1.expType.bitMemberSize;
11312 // If right shifted enough things will fit in smaller type
11313 if(nbExp.op.op == RIGHT_OP)
11317 if(s <= (kind == charType ? 8 : 16))
11318 skipWarning = true;
11322 if(!exp.destType.isSigned)
11324 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11325 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11326 from = nbExp2.expType.promotedFrom;
11327 // Max value of unsigned type before promotion minus the same will always fit
11328 if((from == charType || from == shortType) && nbExp1.isConstant && nbExp1.type == constantExp)
11330 int n = (int)strtol(nbExp1.constant, null, 0);
11331 if(n == (from == charType ? 255 : 65535))
11332 skipWarning = true;
11338 TypeKind kind1, kind2;
11339 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11340 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11341 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11342 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11343 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) &&
11344 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11345 skipWarning = true;
11350 TypeKind kind1, kind2;
11351 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11352 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11353 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11354 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11355 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) ||
11356 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11357 skipWarning = true;
11365 char expString[10240];
11366 expString[0] = '\0';
11367 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11370 CheckExpressionType(exp, exp.destType, false, true);
11373 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11374 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11375 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11376 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11377 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11380 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11382 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11386 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11389 FreeType(exp.expType);
11390 exp.destType.refCount++;
11391 exp.expType = exp.destType;
11397 // Cast function pointers to void * as eC already checked compatibility
11398 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11399 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11401 Expression nbExp = GetNonBracketsExp(exp);
11402 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11404 Expression e = MoveExpContents(exp);
11405 exp.cast.exp = MkExpBrackets(MkListOne(e));
11406 exp.type = castExp;
11407 exp.cast.exp.destType = exp.destType;
11408 if(exp.destType) exp.destType.refCount++;
11409 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11413 else if(unresolved)
11415 if(exp.identifier._class && exp.identifier._class.name)
11416 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11417 else if(exp.identifier.string && exp.identifier.string[0])
11418 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11420 else if(!exp.expType && exp.type != dummyExp)
11422 char expString[10240];
11423 expString[0] = '\0';
11424 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11425 Compiler_Error($"couldn't determine type of %s\n", expString);
11428 // Let's try to support any_object & typed_object here:
11430 ApplyAnyObjectLogic(exp);
11432 // Mark nohead classes as by reference, unless we're casting them to an integral type
11433 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11434 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11435 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11436 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11438 exp.byReference = true;
11440 yylloc = oldyylloc;
11443 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11445 // THIS CODE WILL FIND NEXT MEMBER...
11448 *curMember = (*curMember).next;
11450 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11452 *curMember = subMemberStack[--(*subMemberStackPos)];
11453 *curMember = (*curMember).next;
11456 // SKIP ALL PROPERTIES HERE...
11457 while((*curMember) && (*curMember).isProperty)
11458 *curMember = (*curMember).next;
11460 if(subMemberStackPos)
11462 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11464 subMemberStack[(*subMemberStackPos)++] = *curMember;
11466 *curMember = (*curMember).members.first;
11467 while(*curMember && (*curMember).isProperty)
11468 *curMember = (*curMember).next;
11476 if(subMemberStackPos && *subMemberStackPos)
11478 *curMember = subMemberStack[--(*subMemberStackPos)];
11479 *curMember = (*curMember).next;
11483 Class lastCurClass = *curClass;
11485 if(*curClass == _class) break; // REACHED THE END
11487 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11488 *curMember = (*curClass).membersAndProperties.first;
11491 while((*curMember) && (*curMember).isProperty)
11492 *curMember = (*curMember).next;
11493 if(subMemberStackPos)
11495 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11497 subMemberStack[(*subMemberStackPos)++] = *curMember;
11499 *curMember = (*curMember).members.first;
11500 while(*curMember && (*curMember).isProperty)
11501 *curMember = (*curMember).next;
11509 static void ProcessInitializer(Initializer init, Type type)
11513 case expInitializer:
11514 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11516 // TESTING THIS FOR SHUTTING = 0 WARNING
11517 if(init.exp && !init.exp.destType)
11519 FreeType(init.exp.destType);
11520 init.exp.destType = type;
11521 if(type) type.refCount++;
11525 ProcessExpressionType(init.exp);
11526 init.isConstant = init.exp.isConstant;
11532 Expression exp = init.exp;
11533 Instantiation inst = exp.instance;
11534 MembersInit members;
11536 init.type = listInitializer;
11537 init.list = MkList();
11541 for(members = inst.members->first; members; members = members.next)
11543 if(members.type == dataMembersInit)
11546 for(member = members.dataMembers->first; member; member = member.next)
11548 ListAdd(init.list, member.initializer);
11549 member.initializer = null;
11552 // Discard all MembersInitMethod
11555 FreeExpression(exp);
11557 case listInitializer:
11560 Type initializerType = null;
11561 Class curClass = null;
11562 DataMember curMember = null;
11563 DataMember subMemberStack[256];
11564 int subMemberStackPos = 0;
11566 if(type && type.kind == arrayType)
11567 initializerType = Dereference(type);
11568 else if(type && (type.kind == structType || type.kind == unionType))
11569 initializerType = type.members.first;
11571 for(i = init.list->first; i; i = i.next)
11573 if(type && type.kind == classType && type._class && type._class.registered)
11575 // 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)
11576 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11577 // TODO: Generate error on initializing a private data member this way from another module...
11580 if(!curMember.dataType)
11581 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11582 initializerType = curMember.dataType;
11585 ProcessInitializer(i, initializerType);
11586 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11587 initializerType = initializerType.next;
11589 init.isConstant = false;
11592 if(type && type.kind == arrayType)
11593 FreeType(initializerType);
11595 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11597 Compiler_Error($"Assigning list initializer to non list\n");
11604 static void ProcessSpecifier(Specifier spec, bool declareStruct, bool warnClasses)
11608 case baseSpecifier:
11610 if(spec.specifier == THISCLASS)
11614 spec.type = nameSpecifier;
11615 spec.name = ReplaceThisClass(thisClass);
11616 spec.symbol = FindClass(spec.name);
11617 ProcessSpecifier(spec, declareStruct, false);
11622 case nameSpecifier:
11624 Symbol symbol = FindType(curContext, spec.name);
11626 DeclareType(curExternal, symbol.type, true, true);
11627 else if(spec.symbol /*&& declareStruct*/)
11629 Class c = spec.symbol.registered;
11630 if(warnClasses && !c)
11631 Compiler_Warning("Undeclared class %s\n", spec.name);
11632 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11636 case enumSpecifier:
11641 for(e = spec.list->first; e; e = e.next)
11644 ProcessExpressionType(e.exp);
11647 // Fall through for IDE type processing
11651 case structSpecifier:
11652 case unionSpecifier:
11654 if(spec.definitions)
11657 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11659 ProcessClass(spec.definitions, symbol);
11662 for(def = spec.definitions->first; def; def = def.next)
11664 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11665 ProcessDeclaration(def.decl);
11672 case classSpecifier:
11674 Symbol classSym = FindClass(spec.name);
11675 if(classSym && classSym.registered && classSym.registered.type == structClass)
11676 DeclareStruct(spec.name, false, true);
11684 static void ProcessDeclarator(Declarator decl, bool isFunction)
11688 case identifierDeclarator:
11689 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11691 FreeSpecifier(decl.identifier._class);
11692 decl.identifier._class = null;
11695 case arrayDeclarator:
11697 ProcessExpressionType(decl.array.exp);
11698 case structDeclarator:
11699 case bracketsDeclarator:
11700 case functionDeclarator:
11701 case pointerDeclarator:
11702 case extendedDeclarator:
11703 case extendedDeclaratorEnd:
11705 Identifier id = null;
11706 Specifier classSpec = null;
11707 if(decl.type == functionDeclarator)
11709 id = GetDeclId(decl);
11710 if(id && id._class)
11712 classSpec = id._class;
11716 if(decl.declarator)
11717 ProcessDeclarator(decl.declarator, isFunction);
11718 if(decl.type == functionDeclarator)
11724 qualifiers = MkListOne(classSpec);
11727 if(!decl.function.parameters)
11728 decl.function.parameters = MkList();
11729 decl.function.parameters->Insert(null, param);
11731 if(decl.function.parameters)
11735 for(param = decl.function.parameters->first; param; param = param.next)
11737 if(param.qualifiers)
11740 for(spec = param.qualifiers->first; spec; spec = spec.next)
11742 if(spec.type == baseSpecifier)
11744 if(spec.specifier == TYPED_OBJECT)
11746 Declarator d = param.declarator;
11749 qualifiers = MkListOne(MkSpecifier(VOID));
11750 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11752 if(!d || d.type != pointerDeclarator)
11753 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11755 FreeList(param.qualifiers, FreeSpecifier);
11757 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11758 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11760 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11762 decl.function.parameters->Insert(param, newParam);
11766 else if(spec.specifier == ANY_OBJECT)
11768 Declarator d = param.declarator;
11770 FreeList(param.qualifiers, FreeSpecifier);
11772 param.qualifiers = MkListOne(MkSpecifier(VOID));
11773 if(!d || d.type != pointerDeclarator)
11774 param.qualifiers->Insert(null, MkSpecifier(CONST));
11775 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11778 else if(spec.specifier == THISCLASS)
11782 spec.type = nameSpecifier;
11783 spec.name = ReplaceThisClass(thisClass);
11784 spec.symbol = FindClass(spec.name);
11785 ProcessSpecifier(spec, false, false);
11790 else if(spec.type == nameSpecifier)
11792 ProcessSpecifier(spec, isFunction, true);
11794 else if((spec.type == structSpecifier || spec.type == unionSpecifier) && !spec.definitions && spec.id && spec.id.string)
11796 Declarator d = param.declarator;
11797 if(!d || d.type != pointerDeclarator)
11798 DeclareStruct(curExternal, spec.id.string, false, true);
11803 if(param.declarator)
11804 ProcessDeclarator(param.declarator, false);
11813 static void ProcessDeclaration(Declaration decl, bool warnClasses)
11818 case initDeclaration:
11820 bool declareStruct = false;
11822 lineNum = decl.pos.line;
11823 column = decl.pos.col;
11826 if(decl.declarators)
11830 for(d = decl.declarators->first; d; d = d.next)
11832 Type type, subType;
11833 ProcessDeclarator(d.declarator, false);
11835 type = ProcessType(decl.specifiers, d.declarator);
11839 ProcessInitializer(d.initializer, type);
11841 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11843 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11844 d.initializer.exp.type == instanceExp)
11846 if(type.kind == classType && type._class ==
11847 d.initializer.exp.expType._class)
11849 Instantiation inst = d.initializer.exp.instance;
11850 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11852 d.initializer.exp.instance = null;
11853 if(decl.specifiers)
11854 FreeList(decl.specifiers, FreeSpecifier);
11855 FreeList(decl.declarators, FreeInitDeclarator);
11859 decl.type = instDeclaration;
11864 for(subType = type; subType;)
11866 if(subType.kind == classType)
11868 declareStruct = true;
11871 else if(subType.kind == pointerType)
11873 else if(subType.kind == arrayType)
11874 subType = subType.arrayType;
11884 if(decl.specifiers)
11887 for(s = decl.specifiers->first; s; s = s.next)
11889 ProcessSpecifier(s, declareStruct, true);
11894 case instDeclaration:
11896 ProcessInstantiationType(decl.inst);
11899 case structDeclaration:
11903 bool declareStruct = false;
11905 if(decl.declarators)
11907 for(d = decl.declarators->first; d; d = d.next)
11909 Type type = ProcessType(decl.specifiers, d.declarator);
11911 ProcessDeclarator(d, false);
11912 for(subType = type; subType;)
11914 if(subType.kind == classType)
11916 declareStruct = true;
11919 else if(subType.kind == pointerType)
11921 else if(subType.kind == arrayType)
11922 subType = subType.arrayType;
11929 if(decl.specifiers)
11931 for(spec = decl.specifiers->first; spec; spec = spec.next)
11932 ProcessSpecifier(spec, declareStruct, warnClasses);
11939 static FunctionDefinition curFunction;
11941 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11943 char propName[1024], propNameM[1024];
11944 char getName[1024], setName[1024];
11947 DeclareProperty(curExternal, prop, setName, getName);
11949 // eInstance_FireWatchers(object, prop);
11950 strcpy(propName, "__ecereProp_");
11951 FullClassNameCat(propName, prop._class.fullName, false);
11952 strcat(propName, "_");
11953 FullClassNameCat(propName, prop.name, true);
11955 strcpy(propNameM, "__ecerePropM_");
11956 FullClassNameCat(propNameM, prop._class.fullName, false);
11957 strcat(propNameM, "_");
11958 FullClassNameCat(propNameM, prop.name, true);
11960 if(prop.isWatchable)
11963 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11964 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11965 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11968 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11969 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11970 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11972 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
11977 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11978 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11979 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11982 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11983 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11984 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11986 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
11989 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11990 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11991 curFunction.propSet.fireWatchersDone = true;
11994 static void ProcessStatement(Statement stmt)
11998 lineNum = stmt.pos.line;
11999 column = stmt.pos.col;
12004 ProcessStatement(stmt.labeled.stmt);
12007 // This expression should be constant...
12008 if(stmt.caseStmt.exp)
12010 FreeType(stmt.caseStmt.exp.destType);
12011 stmt.caseStmt.exp.destType = curSwitchType;
12012 if(curSwitchType) curSwitchType.refCount++;
12013 ProcessExpressionType(stmt.caseStmt.exp);
12014 ComputeExpression(stmt.caseStmt.exp);
12016 if(stmt.caseStmt.stmt)
12017 ProcessStatement(stmt.caseStmt.stmt);
12021 if(stmt.compound.context)
12026 Statement prevCompound = curCompound;
12027 Context prevContext = curContext;
12029 if(!stmt.compound.isSwitch)
12030 curCompound = stmt;
12031 curContext = stmt.compound.context;
12033 if(stmt.compound.declarations)
12035 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
12036 ProcessDeclaration(decl, true);
12038 if(stmt.compound.statements)
12040 for(s = stmt.compound.statements->first; s; s = s.next)
12041 ProcessStatement(s);
12044 curContext = prevContext;
12045 curCompound = prevCompound;
12049 case expressionStmt:
12052 if(stmt.expressions)
12054 for(exp = stmt.expressions->first; exp; exp = exp.next)
12055 ProcessExpressionType(exp);
12063 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
12064 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
12065 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
12066 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
12068 ProcessExpressionType(exp);
12070 if(stmt.ifStmt.stmt)
12071 ProcessStatement(stmt.ifStmt.stmt);
12072 if(stmt.ifStmt.elseStmt)
12073 ProcessStatement(stmt.ifStmt.elseStmt);
12078 Type oldSwitchType = curSwitchType;
12079 if(stmt.switchStmt.exp)
12082 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12092 e.exp.destType = destType;
12095 ProcessExpressionType(exp);
12098 curSwitchType = exp.expType;
12101 ProcessStatement(stmt.switchStmt.stmt);
12102 curSwitchType = oldSwitchType;
12107 if(stmt.whileStmt.exp)
12111 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12112 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12113 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12114 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12116 ProcessExpressionType(exp);
12119 if(stmt.whileStmt.stmt)
12120 ProcessStatement(stmt.whileStmt.stmt);
12125 if(stmt.doWhile.exp)
12129 if(stmt.doWhile.exp->last)
12131 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12132 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12133 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12135 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12137 ProcessExpressionType(exp);
12140 if(stmt.doWhile.stmt)
12141 ProcessStatement(stmt.doWhile.stmt);
12147 if(stmt.forStmt.init)
12148 ProcessStatement(stmt.forStmt.init);
12150 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12152 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12153 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12154 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12157 if(stmt.forStmt.check)
12158 ProcessStatement(stmt.forStmt.check);
12159 if(stmt.forStmt.increment)
12161 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12162 ProcessExpressionType(exp);
12165 if(stmt.forStmt.stmt)
12166 ProcessStatement(stmt.forStmt.stmt);
12171 Identifier id = stmt.forEachStmt.id;
12172 OldList * exp = stmt.forEachStmt.exp;
12173 OldList * filter = stmt.forEachStmt.filter;
12174 Statement block = stmt.forEachStmt.stmt;
12175 char iteratorType[1024];
12178 bool isBuiltin = exp && exp->last &&
12179 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12180 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12181 Expression arrayExp;
12182 const char * typeString = null;
12183 int builtinCount = 0;
12185 for(e = exp ? exp->first : null; e; e = e.next)
12189 FreeType(e.destType);
12190 e.destType = ProcessTypeString("Container", false);
12192 if(!isBuiltin || e.next)
12193 ProcessExpressionType(e);
12196 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12197 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12198 eClass_IsDerived(source._class.registered, containerClass)))
12200 Class _class = source ? source._class.registered : null;
12202 Expression expIt = null;
12203 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12204 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12205 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12206 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12210 stmt.type = compoundStmt;
12212 stmt.compound.context = Context { };
12213 stmt.compound.context.parent = curContext;
12214 curContext = stmt.compound.context;
12217 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12219 Class mapClass = eSystem_FindClass(privateModule, "Map");
12220 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12221 isCustomAVLTree = true;
12222 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12224 else */if(eClass_IsDerived(source._class.registered, mapClass))
12227 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12228 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12230 Class listClass = eSystem_FindClass(privateModule, "List");
12232 isList = eClass_IsDerived(source._class.registered, listClass);
12235 if(inCompiler && isArray)
12238 OldList * specs = MkList();
12239 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12240 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12241 stmt.compound.declarations = MkListOne(
12242 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12243 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12244 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12245 MkInitializerAssignment(MkExpBrackets(exp))))));
12250 char typeStringBuf[1024];
12252 // TODO: Merge this code?
12253 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12254 if(((Expression)exp->last).type == castExp)
12256 TypeName typeName = ((Expression)exp->last).cast.typeName;
12258 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12261 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12262 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12263 arrayExp.destType._class.registered.templateArgs)
12265 Class templateClass = arrayExp.destType._class.registered;
12266 typeString = templateClass.templateArgs[2].dataTypeString;
12268 else if(arrayExp.list)
12270 // Guess type from expressions in the array
12272 for(e = arrayExp.list->first; e; e = e.next)
12274 ProcessExpressionType(e);
12277 if(!type) { type = e.expType; type.refCount++; }
12280 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12281 if(!MatchTypeExpression(e, type, null, false, true))
12287 e = arrayExp.list->first;
12288 ProcessExpressionType(e);
12291 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12292 if(!MatchTypeExpression(e, type, null, false, true))
12294 FreeType(e.expType);
12305 FreeType(e.expType);
12312 typeStringBuf[0] = '\0';
12313 PrintType(type, typeStringBuf, false, true);
12314 typeString = typeStringBuf;
12322 OldList * initializers = MkList();
12324 OldList * specs = MkList();
12329 builtinCount = arrayExp.list->count;
12330 type = ProcessTypeString(typeString, false);
12331 while((e = arrayExp.list->first))
12333 arrayExp.list->Remove(e);
12336 ProcessExpressionType(e);
12338 ListAdd(initializers, MkInitializerAssignment(e));
12341 delete arrayExp.list;
12343 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12345 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12346 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12348 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12350 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12351 ), MkInitializerList(initializers)))));
12352 FreeList(exp, FreeExpression);
12354 else if(arrayExp.list)
12357 type = ProcessTypeString(typeString, false);
12358 for(e = arrayExp.list->first; e; e = e.next)
12362 ProcessExpressionType(e);
12369 arrayExp.expType = ProcessTypeString("Container", false);
12370 Compiler_Error($"Couldn't determine type of array elements\n");
12375 OldList * specs = MkList();
12377 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12378 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12379 stmt.compound.declarations = MkListOne(
12380 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12381 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12382 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12383 MkInitializerAssignment(MkExpBrackets(exp))))));
12386 else if(inCompiler && isLinkList && !isList)
12389 OldList * specs = MkList();
12390 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12391 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12392 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12393 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12394 MkInitializerAssignment(MkExpBrackets(exp))))));
12396 /*else if(isCustomAVLTree)
12399 OldList * specs = MkList();
12400 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12401 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12402 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12403 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12404 MkInitializerAssignment(MkExpBrackets(exp))))));
12406 else if(inCompiler && _class.templateArgs)
12409 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12411 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12413 stmt.compound.declarations = MkListOne(
12414 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12415 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12416 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12420 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12424 // Reparent sub-contexts in this statement
12428 if(block.compound.context)
12429 block.compound.context.parent = stmt.compound.context;
12432 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12433 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12434 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12435 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12438 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12439 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12442 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12443 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12446 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12447 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12450 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12451 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12454 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12455 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12457 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12460 case expressionStmt:
12466 case badDeclarationStmt:
12467 case fireWatchersStmt:
12468 case stopWatchingStmt:
12476 block = MkIfStmt(filter, block, null);
12480 stmt.compound.statements = MkListOne(MkForStmt(
12481 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12482 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12483 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12484 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12486 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12487 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12488 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12493 //OldList * specs = MkList();
12494 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12496 sprintf(count, "%d", builtinCount);
12498 stmt.compound.statements = MkListOne(MkForStmt(
12499 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12500 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12501 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12502 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12506 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12507 stmt.compound.statements = MkListOne(MkForStmt(
12508 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12509 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12510 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12511 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12514 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12515 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12516 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12518 else if(isLinkList && !isList)
12520 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12521 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12522 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12523 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12525 stmt.compound.statements = MkListOne(MkForStmt(
12526 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12527 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12528 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12533 OldList * specs = MkList();
12534 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12535 stmt.compound.statements = MkListOne(MkForStmt(
12536 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12537 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12538 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12539 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12540 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12543 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12544 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12545 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12547 /*else if(isCustomAVLTree)
12549 stmt.compound.statements = MkListOne(MkForStmt(
12550 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12551 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12552 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12553 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12556 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12557 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12558 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12562 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12563 MkIdentifier("Next")), null)), block));
12565 ProcessExpressionType(expIt);
12566 if(stmt.compound.declarations->first)
12567 ProcessDeclaration(stmt.compound.declarations->first, true);
12570 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12572 ProcessStatement(stmt);
12575 ProcessStatement(stmt.forEachStmt.stmt);
12577 curContext = stmt.compound.context.parent;
12582 Compiler_Error($"Expression is not a container\n");
12595 if(stmt.expressions)
12597 for(exp = stmt.expressions->first; exp; exp = exp.next)
12601 if(curFunction && !curFunction.type)
12602 curFunction.type = ProcessType(
12603 curFunction.specifiers, curFunction.declarator);
12604 FreeType(exp.destType);
12605 // TODO: current property if not compiling
12606 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12607 if(exp.destType) exp.destType.refCount++;
12609 ProcessExpressionType(exp);
12614 case badDeclarationStmt:
12616 ProcessDeclaration(stmt.decl, true);
12622 if(stmt.asmStmt.inputFields)
12624 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12625 if(field.expression)
12626 ProcessExpressionType(field.expression);
12628 if(stmt.asmStmt.outputFields)
12630 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12631 if(field.expression)
12632 ProcessExpressionType(field.expression);
12634 if(stmt.asmStmt.clobberedFields)
12636 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12638 if(field.expression)
12639 ProcessExpressionType(field.expression);
12646 PropertyWatch propWatch;
12647 OldList * watches = stmt._watch.watches;
12648 Expression object = stmt._watch.object;
12649 Expression watcher = stmt._watch.watcher;
12651 ProcessExpressionType(watcher);
12653 ProcessExpressionType(object);
12657 if(watcher || thisClass)
12659 External external = curExternal;
12660 Context context = curContext;
12662 stmt.type = expressionStmt;
12663 stmt.expressions = MkList();
12665 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12667 ClassFunction func;
12668 char watcherName[1024];
12669 Class watcherClass = watcher ?
12670 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12671 External createdExternal;
12673 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12674 if(propWatch.deleteWatch)
12675 strcat(watcherName, "_delete");
12679 for(propID = propWatch.properties->first; propID; propID = propID.next)
12681 strcat(watcherName, "_");
12682 strcat(watcherName, propID.string);
12686 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12688 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12689 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12690 ProcessClassFunctionBody(func, propWatch.compound);
12691 propWatch.compound = null;
12693 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12695 FreeClassFunction(func);
12697 curExternal = createdExternal;
12698 ProcessFunction(createdExternal.function);
12700 if(propWatch.deleteWatch)
12702 OldList * args = MkList();
12703 ListAdd(args, CopyExpression(object));
12704 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12705 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12706 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12710 Class _class = object.expType._class.registered;
12713 for(propID = propWatch.properties->first; propID; propID = propID.next)
12715 char propName[1024];
12716 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12719 char getName[1024], setName[1024];
12720 OldList * args = MkList();
12722 DeclareProperty(createdExternal, prop, setName, getName);
12724 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12725 strcpy(propName, "__ecereProp_");
12726 FullClassNameCat(propName, prop._class.fullName, false);
12727 strcat(propName, "_");
12728 FullClassNameCat(propName, prop.name, true);
12730 ListAdd(args, CopyExpression(object));
12731 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12732 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12733 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12735 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12737 external.CreateUniqueEdge(createdExternal, true);
12740 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12745 Compiler_Error($"Invalid watched object\n");
12748 curExternal = external;
12749 curContext = context;
12752 FreeExpression(watcher);
12754 FreeExpression(object);
12755 FreeList(watches, FreePropertyWatch);
12758 Compiler_Error($"No observer specified and not inside a class\n");
12762 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12764 ProcessStatement(propWatch.compound);
12770 case fireWatchersStmt:
12772 OldList * watches = stmt._watch.watches;
12773 Expression object = stmt._watch.object;
12775 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12776 // printf("%X\n", watches);
12777 // printf("%X\n", stmt._watch.watches);
12779 ProcessExpressionType(object);
12784 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12790 stmt.type = expressionStmt;
12791 stmt.expressions = MkList();
12793 // Check if we're inside a property set
12794 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12796 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12800 //Compiler_Error($"No property specified and not inside a property set\n");
12804 for(propID = watches->first; propID; propID = propID.next)
12806 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12809 CreateFireWatcher(prop, object, stmt);
12812 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12817 // Fire all properties!
12820 for(base = _class; base; base = base.base)
12822 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12824 if(prop.isProperty && prop.isWatchable)
12826 CreateFireWatcher(prop, object, stmt);
12833 FreeExpression(object);
12834 FreeList(watches, FreeIdentifier);
12837 Compiler_Error($"Invalid object specified and not inside a class\n");
12841 case stopWatchingStmt:
12843 OldList * watches = stmt._watch.watches;
12844 Expression object = stmt._watch.object;
12845 Expression watcher = stmt._watch.watcher;
12848 ProcessExpressionType(object);
12850 ProcessExpressionType(watcher);
12853 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12855 if(watcher || thisClass)
12861 stmt.type = expressionStmt;
12862 stmt.expressions = MkList();
12867 // eInstance_StopWatching(object, null, watcher);
12869 ListAdd(args, CopyExpression(object));
12870 ListAdd(args, MkExpConstant("0"));
12871 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12872 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12876 for(propID = watches->first; propID; propID = propID.next)
12878 char propName[1024];
12879 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12882 char getName[1024], setName[1024];
12883 OldList * args = MkList();
12885 DeclareProperty(curExternal, prop, setName, getName);
12887 // eInstance_StopWatching(object, prop, watcher);
12888 strcpy(propName, "__ecereProp_");
12889 FullClassNameCat(propName, prop._class.fullName, false);
12890 strcat(propName, "_");
12891 FullClassNameCat(propName, prop.name, true);
12893 ListAdd(args, CopyExpression(object));
12894 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12895 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12896 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12899 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12904 FreeExpression(object);
12906 FreeExpression(watcher);
12907 FreeList(watches, FreeIdentifier);
12910 Compiler_Error($"Invalid object specified and not inside a class\n");
12913 Compiler_Error($"No observer specified and not inside a class\n");
12920 static void ProcessFunction(FunctionDefinition function)
12922 Identifier id = GetDeclId(function.declarator);
12923 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12924 Type type = symbol ? symbol.type : null;
12925 Class oldThisClass = thisClass;
12926 Context oldTopContext = topContext;
12928 yylloc = function.loc;
12929 // Process thisClass
12931 if(type && type.thisClass)
12933 Symbol classSym = type.thisClass;
12934 Class _class = type.thisClass.registered;
12935 char className[1024];
12936 char structName[1024];
12937 Declarator funcDecl;
12940 bool typedObject = false;
12942 if(_class && !_class.base)
12944 _class = currentClass;
12945 if(_class && !_class.symbol)
12946 _class.symbol = FindClass(_class.fullName);
12947 classSym = _class ? _class.symbol : null;
12948 typedObject = true;
12951 thisClass = _class;
12953 if(inCompiler && _class)
12955 if(type.kind == functionType)
12957 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12959 //TypeName param = symbol.type.params.first;
12960 Type param = symbol.type.params.first;
12961 symbol.type.params.Remove(param);
12962 //FreeTypeName(param);
12965 if(type.classObjectType != classPointer)
12967 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12968 symbol.type.staticMethod = true;
12969 symbol.type.thisClass = null;
12971 // HIGH DANGER: VERIFYING THIS...
12972 symbol.type.extraParam = false;
12976 strcpy(className, "__ecereClass_");
12977 FullClassNameCat(className, _class.fullName, true);
12980 FullClassNameCat(structName, _class.fullName, false);
12983 funcDecl = GetFuncDecl(function.declarator);
12986 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12988 TypeName param = funcDecl.function.parameters->first;
12989 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12991 funcDecl.function.parameters->Remove(param);
12992 FreeTypeName(param);
12996 if(!function.propertyNoThis)
12998 TypeName thisParam = null;
13000 if(type.classObjectType != classPointer)
13002 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13003 if(!funcDecl.function.parameters)
13004 funcDecl.function.parameters = MkList();
13005 funcDecl.function.parameters->Insert(null, thisParam);
13010 if(type.classObjectType != classPointer)
13012 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
13013 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
13016 thisParam = TypeName
13018 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
13019 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
13021 DeclareStruct(curExternal, "ecere::com::Class", false, true);
13022 funcDecl.function.parameters->Insert(null, thisParam);
13027 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13029 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13030 funcDecl = GetFuncDecl(initDecl.declarator);
13033 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13035 TypeName param = funcDecl.function.parameters->first;
13036 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13038 funcDecl.function.parameters->Remove(param);
13039 FreeTypeName(param);
13043 if(type.classObjectType != classPointer)
13045 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
13047 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13049 if(!funcDecl.function.parameters)
13050 funcDecl.function.parameters = MkList();
13051 funcDecl.function.parameters->Insert(null, thisParam);
13058 // Add this to the context
13061 if(type.classObjectType != classPointer)
13063 thisSymbol = Symbol
13065 string = CopyString("this");
13066 type = classSym ? MkClassType(classSym.string) : null;
13068 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13070 if(typedObject && thisSymbol.type)
13072 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13073 thisSymbol.type.byReference = type.byReference;
13074 thisSymbol.type.typedByReference = type.byReference;
13079 // Pointer to class data
13080 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
13082 DataMember member = null;
13085 for(base = _class; base && base.type != systemClass; base = base.next)
13087 for(member = base.membersAndProperties.first; member; member = member.next)
13088 if(!member.isProperty)
13094 for(member = _class.membersAndProperties.first; member; member = member.next)
13095 if(!member.isProperty)
13099 char pointerName[1024];
13102 Initializer initializer;
13103 Expression exp, bytePtr;
13105 strcpy(pointerName, "__ecerePointer_");
13106 FullClassNameCat(pointerName, _class.fullName, false);
13108 char className[1024];
13109 strcpy(className, "__ecereClass_");
13110 FullClassNameCat(className, classSym.string, true);
13112 DeclareClass(curExternal, classSym, className);
13116 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13121 if(_class.offset && _class.offset == (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize))
13123 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
13124 ProcessExpressionType(e);
13129 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
13130 e = MkExpConstant(string);
13132 exp = QBrackets(MkExpOp(bytePtr, '+', e));
13136 // ([bytePtr] + [className]->offset)
13137 exp = QBrackets(MkExpOp(bytePtr, '+',
13138 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13141 // (this ? [exp] : 0)
13142 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13146 kind = pointerType;
13147 type = Type { refCount = 1, kind = voidType };
13152 yylloc = function.body.loc;
13153 // ([structName] *) [exp]
13154 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13155 initializer = MkInitializerAssignment(
13156 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13158 // [structName] * [pointerName] = [initializer];
13159 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13162 Context prevContext = curContext;
13164 curContext = function.body.compound.context;
13166 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13167 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13168 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13170 curContext = prevContext;
13174 decl.symbol = null;
13176 if(!function.body.compound.declarations)
13177 function.body.compound.declarations = MkList();
13178 function.body.compound.declarations->Insert(null, decl);
13184 // Loop through the function and replace undeclared identifiers
13185 // which are a member of the class (methods, properties or data)
13186 // by "this.[member]"
13193 FreeSpecifier(id._class);
13196 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13198 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13199 id = GetDeclId(initDecl.declarator);
13201 FreeSpecifier(id._class);
13206 topContext = function.body.compound.context;
13208 FunctionDefinition oldFunction = curFunction;
13209 curFunction = function;
13211 ProcessStatement(function.body);
13213 // If this is a property set and no firewatchers has been done yet, add one here
13214 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13216 Statement prevCompound = curCompound;
13217 Context prevContext = curContext;
13219 Statement fireWatchers = MkFireWatchersStmt(null, null);
13220 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13221 ListAdd(function.body.compound.statements, fireWatchers);
13223 curCompound = function.body;
13224 curContext = function.body.compound.context;
13226 ProcessStatement(fireWatchers);
13228 curContext = prevContext;
13229 curCompound = prevCompound;
13233 curFunction = oldFunction;
13236 if(function.declarator)
13238 ProcessDeclarator(function.declarator, true);
13241 topContext = oldTopContext;
13242 thisClass = oldThisClass;
13245 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13246 static void ProcessClass(OldList definitions, Symbol symbol)
13249 External external = curExternal;
13250 Class regClass = symbol ? symbol.registered : null;
13252 // Process all functions
13253 for(def = definitions.first; def; def = def.next)
13255 if(def.type == functionClassDef)
13257 if(def.function.declarator)
13258 curExternal = def.function.declarator.symbol.pointerExternal;
13260 curExternal = external;
13262 ProcessFunction((FunctionDefinition)def.function);
13264 else if(def.type == declarationClassDef)
13266 if(def.decl.type == instDeclaration)
13268 thisClass = regClass;
13269 ProcessInstantiationType(def.decl.inst);
13275 Class backThisClass = thisClass;
13276 if(regClass) thisClass = regClass;
13277 ProcessDeclaration(def.decl, symbol ? true : false);
13278 thisClass = backThisClass;
13281 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13283 MemberInit defProperty;
13285 // Add this to the context
13286 Symbol thisSymbol = Symbol
13288 string = CopyString("this");
13289 type = regClass ? MkClassType(regClass.fullName) : null;
13291 globalContext.symbols.Add((BTNode)thisSymbol);
13293 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13295 thisClass = regClass;
13296 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13300 globalContext.symbols.Remove((BTNode)thisSymbol);
13301 FreeSymbol(thisSymbol);
13303 else if(def.type == propertyClassDef && def.propertyDef)
13305 PropertyDef prop = def.propertyDef;
13307 // Add this to the context
13308 thisClass = regClass;
13315 string = CopyString("this");
13316 type = MkClassType(regClass.fullName);
13318 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13321 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13322 ProcessStatement(prop.setStmt);
13330 string = CopyString("this");
13331 type = MkClassType(regClass.fullName);
13333 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13336 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13337 ProcessStatement(prop.getStmt);
13345 string = CopyString("this");
13346 type = MkClassType(regClass.fullName);
13348 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13351 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13352 ProcessStatement(prop.issetStmt);
13357 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13359 PropertyWatch propertyWatch = def.propertyWatch;
13361 thisClass = regClass;
13362 if(propertyWatch.compound)
13366 string = CopyString("this");
13367 type = regClass ? MkClassType(regClass.fullName) : null;
13370 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13372 curExternal = null;
13373 ProcessStatement(propertyWatch.compound);
13380 void DeclareFunctionUtil(External neededBy, const String s)
13382 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13387 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13388 strcpy(name, "__ecereFunction_");
13389 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13390 DeclareFunction(neededBy, function, name);
13393 FindSymbol(s, globalContext, globalContext, false, false);
13396 bool reachedPass15;
13398 void ComputeDataTypes()
13402 currentClass = null;
13404 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13406 DeclareStruct(null, "ecere::com::Class", false, true);
13407 DeclareStruct(null, "ecere::com::Instance", false, true);
13408 DeclareStruct(null, "ecere::com::Property", false, true);
13409 DeclareStruct(null, "ecere::com::DataMember", false, true);
13410 DeclareStruct(null, "ecere::com::Method", false, true);
13411 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13412 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13414 DeclareFunctionUtil(null, "eSystem_New");
13415 DeclareFunctionUtil(null, "eSystem_New0");
13416 DeclareFunctionUtil(null, "eSystem_Renew");
13417 DeclareFunctionUtil(null, "eSystem_Renew0");
13418 DeclareFunctionUtil(null, "eSystem_Delete");
13419 DeclareFunctionUtil(null, "eClass_GetProperty");
13420 DeclareFunctionUtil(null, "eClass_SetProperty");
13421 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13422 DeclareFunctionUtil(null, "eInstance_SetMethod");
13423 DeclareFunctionUtil(null, "eInstance_IncRef");
13424 DeclareFunctionUtil(null, "eInstance_StopWatching");
13425 DeclareFunctionUtil(null, "eInstance_Watch");
13426 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13427 reachedPass15 = true;
13429 for(external = ast->first; external; external = external.next)
13431 afterExternal = curExternal = external;
13432 if(external.type == functionExternal)
13436 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13437 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13440 currentClass = external.function._class;
13441 ProcessFunction(external.function);
13443 // There shouldn't be any _class member access here anyways...
13444 else if(external.type == declarationExternal)
13446 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13448 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13449 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13452 currentClass = null;
13453 if(external.declaration)
13454 ProcessDeclaration(external.declaration, true);
13456 else if(external.type == classExternal)
13458 ClassDefinition _class = external._class;
13459 currentClass = external.symbol.registered;
13462 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13463 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13465 if(_class.definitions)
13467 ProcessClass(_class.definitions, _class.symbol);
13471 // Free class data...
13472 ast->Remove(external);
13476 else if(external.type == nameSpaceExternal)
13478 thisNameSpace = external.id.string;
13481 currentClass = null;
13482 thisNameSpace = null;
13483 curExternal = null;